Ignore:
Timestamp:
Jun 2, 2008, 10:49:01 AM (12 years ago)
Author:
Bruno Cornec
Message:

svn merge -r 1938:1976 $SVN_M/branches/2.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-stream.c

    r1939 r1977  
    22
    33...tools for talking to tapes, Monitas streams, etc.
     4
    45*/
    56
     
    364365    int res = 0;
    365366    char *fname = (char *)&res;                 /* Should NOT be NULL */
     367    char *tmp = NULL;
    366368
    367369    // xattr
     
    371373            wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
    372374        }
    373         if (!strstr(fname, "xattr")) {
    374             fatal_error("Wrong order for xattr, sunshine.");
     375        if (strstr(fname, "xattr") == NULL) {
     376            asprintf(&tmp,"Wrong order expected xattr, got %s, sunshine.", fname);
     377            fatal_error(tmp);
    375378        }
    376379        read_file_from_stream_to_file(xattr_fname, *ptmp_size);
    377         res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     380        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    378381        if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
    379382            wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
    380383        }
    381384        mr_msg(1, "Got xattr");
    382         res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     385        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    383386        if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) {
    384387            wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr);
    385388        }
    386         res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    387         if (pctrl_chr == BLK_START_AN_AFIO_OR_SLICE) {
     389        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
     390        if (*pctrl_chr == BLK_START_AN_AFIO_OR_SLICE) {
    388391            log_msg(1, "No acl attributes found, skipping to afio files");
    389392            return(0);
    390393        } else {
    391             if (pctrl_chr != BLK_START_EXTENDED_ATTRIBUTES) {
     394            if (*pctrl_chr != BLK_START_EXTENDED_ATTRIBUTES) {
    392395                wrong_marker(BLK_START_EXTENDED_ATTRIBUTES, *pctrl_chr);
    393396            }
     
    397400    if (g_getfacl) {
    398401        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    399         if (!strstr(fname, "acl")) {
    400             fatal_error("Wrong order for acl, sunshine.");
    401         }
    402402        if (*pctrl_chr != BLK_START_EXAT_FILE) {
    403403            wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
    404404        }
     405        if (strstr(fname, "acl") == NULL) {
     406            asprintf(&tmp,"Wrong order expected acl, got %s, sunshine.", fname);
     407            fatal_error(tmp);
     408        }
    405409        read_file_from_stream_to_file(acl_fname, *ptmp_size);
    406         res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     410        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    407411        if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
    408412            wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
    409413        }
    410         res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     414        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    411415        if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) {
    412416            wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr);
     
    595599
    596600
    597 int set_tape_block_size_with_mt(char *tapedev,
    598                                 long internal_tape_block_size)
     601int set_tape_block_size_with_mt(long internal_tape_block_size)
    599602{
    600603    char *tmp;
    601604    int res;
    602605
    603     if (strncmp(tapedev, "/dev/", 5)) {
     606    if (strncmp(bkpinfo->media_device, "/dev/", 5)) {
    604607        mr_msg(1,
    605608                "Not using 'mt setblk'. This isn't an actual /dev entry.");
    606609        return (0);
    607610    }
    608     mr_asprintf(&tmp, "mt -f %s setblk %ld", tapedev,
    609              internal_tape_block_size);
     611    mr_asprintf(&tmp, "mt -f %s setblk %ld",bkpinfo->media_device,internal_tape_block_size);
    610612    res = run_program_and_log_output(tmp, 3);
    611613    mr_free(tmp);
    612614    return (res);
     615}
     616
     617/**
     618 * Return the non-rewinding device when passed the normal one
     619 * @param tapedev The tape device to open for writing.
     620 * @note the caller needs to free the string returned
     621 */
     622char *get_non_rewind_dev(char *tapedev)
     623{
     624
     625    char *ntapedev = NULL;
     626    char *p = NULL;
     627    char *q = NULL;
     628    char *r = NULL;
     629
     630    ntapedev = (char *)malloc(strlen(tapedev)+sizeof(char));
     631    p = strrchr(tapedev,'/');
     632    if (p == NULL) {
     633        log_it("Didn't find a '/' in %s",tapedev);
     634        return(NULL);
     635    }
     636
     637    /* Copy tapedev content up to the last / */
     638    q = tapedev;
     639    r = ntapedev;
     640    while (q != p) {
     641        *r = *q;
     642        r++;
     643        q++;
     644    }
     645    /* Copy the '/' */
     646    *r = *q;
     647    r++;
     648    q++;
     649    /* Adds a 'n' - non-rewinding */
     650    *r = 'n';
     651    r++;
     652    /* Copy the rest of tapedev */
     653    while (*q != '\0') {
     654        *r = *q;
     655        r++;
     656        q++;
     657    }
     658    *r = '\0';
     659    if (mt_says_tape_exists(ntapedev)) {
     660        log_it("Non-rewinding tape device is %s",ntapedev);
     661    } else {
     662        log_it("Unable to find non-rewinding tape device.");
     663        ntapedev = NULL;
     664    }
     665    return(ntapedev);
     666}
     667
     668
     669
     670/**
     671 * Handle OBDR if we were asked to do so
     672 * @param tapedev The tape device to open for reading.
     673 */
     674int skip_obdr(void)
     675{
     676    char *command = NULL;
     677    int res = 0;
     678
     679    log_it("Skipping OBDR headers");
     680    asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     681    res = run_program_and_log_output(command, 1);
     682    paranoid_free(command);
     683
     684    asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device);
     685    res = run_program_and_log_output(command, 1);
     686    paranoid_free(command);
     687
     688    set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     689    return(res);
     690}
     691
     692/**
     693 * Handle OBDR if we were asked to do so
     694 * @param tapedev The tape device to open for writing.
     695 * @return 0 for success, nonzero for failure.
     696 * @note This should be called ONLY from backup processes. It will OVERWRITE ANY
     697 * EXISTING DATA on the tape!
     698 */
     699int create_obdr(void)
     700{
     701
     702    char *command = NULL;
     703    int res = 0;
     704
     705    log_it("Creating OBDR headers");
     706    /* OBDR: First block 10 kB of zero bs = 512 */
     707    asprintf(&command, "mt -f %s compression off",bkpinfo->media_device);
     708    res = run_program_and_log_output(command, 1);
     709    paranoid_free(command);
     710
     711    asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     712    res += run_program_and_log_output(command, 1);
     713    paranoid_free(command);
     714
     715    set_tape_block_size_with_mt(512);
     716
     717    asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device);
     718    res += run_program_and_log_output(command, 1);
     719    paranoid_free(command);
     720
     721    /* OBDR: then ISO boot image bs = 2048 */
     722    set_tape_block_size_with_mt(2048);
     723
     724    asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device);
     725    res += run_program_and_log_output(command, 1);
     726    paranoid_free(command);
     727
     728    set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     729    return(res);
    613730}
    614731
     
    633750    int i;
    634751    int j;
    635     int res;
     752    int res = 0;
    636753    long length, templong;
    637754    size_t k;
     
    654771        return (0);
    655772    }
     773
     774    // mondoarchive should have configured everything to give the right non-rew device
     775    if ((bkpinfo->use_obdr) && (bkpinfo->media_device != NULL)) {
     776        res = skip_obdr();
     777        if (res != 0) {
     778            log_it("Not able to skip OBDR - Restore will have to be done manually");
     779        }
     780    } else {
     781        if (bkpinfo->media_device == NULL) {
     782            log_it("Not able to skip OBDR - Restore will have to be done manually");
     783        }
     784        set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     785    }
     786
    656787    insist_on_this_tape_number(1);
    657788    mr_asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
    658789    make_hole_for_file(outfname);
    659 
    660     set_tape_block_size_with_mt(bkpinfo->media_device,
    661                                 bkpinfo->internal_tape_block_size);
    662790
    663791    log_it("Opening IN tape");
     
    762890/**
    763891 * Start writing to a tape device for the backup.
     892 * Handle OBDR if we were asked to do so
    764893 * @param tapedev The tape device to open for writing.
    765894 * @return 0 for success, nonzero for failure.
     
    767896 * EXISTING DATA on the tape!
    768897 */
    769 int openout_tape(char *tapedev, long internal_tape_block_size)
    770 {
     898int openout_tape() {
     899
    771900    g_current_media_number = 1;
    772901    if (g_tape_stream) {
     
    777906    g_tape_posK = 0;
    778907
    779     set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
     908    if (bkpinfo->use_obdr) {
     909        create_obdr();
     910    } else {
     911        set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     912    }
    780913    log_it("Opening OUT tape");
    781914    if (!
    782915        (g_tape_stream =
    783          open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) {
     916         open_device_via_buffer(bkpinfo->media_device, 'w', internal_tape_block_size))) {
    784917        log_to_screen(_("Cannot openin stream device"));
    785918        return (1);
Note: See TracChangeset for help on using the changeset viewer.