Changeset 1954


Ignore:
Timestamp:
May 27, 2008, 1:13:52 PM (11 years ago)
Author:
bruno
Message:
  • Simplify some function interface with bkpinfo global
  • Modify bkpinfo->media_device when OBDR to force using non-rewionding dev and improve backup
Location:
branches/2.2.6/mondo/src/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.6/mondo/src/common/libmondo-archive.c

    r1948 r1954  
    12501250            openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
    12511251        } else {
    1252             openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
     1252            openout_tape(); /* sets g_tape_stream */
    12531253        }
    12541254        if (!g_tape_stream) {
  • branches/2.2.6/mondo/src/common/libmondo-stream-EXT.h

    r1647 r1954  
    1313extern int openin_tape();
    1414extern int openout_cdstream(char *cddev, int speed);
    15 extern int openout_tape(char *tapedev, long internal_tape_block_size);
     15extern int openout_tape();
    1616extern int read_file_from_stream_to_file(
    1717                                         char *outfile, long long size);
  • branches/2.2.6/mondo/src/common/libmondo-stream.c

    r1953 r1954  
    605605
    606606
    607 int set_tape_block_size_with_mt(char *tapedev,
    608                                 long internal_tape_block_size)
     607int set_tape_block_size_with_mt(long internal_tape_block_size)
    609608{
    610609    char *tmp;
    611610    int res;
    612611
    613     if (strncmp(tapedev, "/dev/", 5)) {
     612    if (strncmp(bkpinfo->media_device, "/dev/", 5)) {
    614613        log_msg(1,
    615614                "Not using 'mt setblk'. This isn't an actual /dev entry.");
     
    617616    }
    618617    malloc_string(tmp);
    619     sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
     618    sprintf(tmp, "mt -f %s setblk %ld", bkpinfo->media_device, internal_tape_block_size);
    620619    res = run_program_and_log_output(tmp, 3);
    621620    paranoid_free(tmp);
     
    678677/**
    679678 * Handle OBDR if we were asked to do so
     679 * @param tapedev The tape device to open for reading.
     680 */
     681void skip_obdr()
     682{
     683    char *command = NULL;
     684
     685    asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device);
     686    run_program_and_log_output(command, 1);
     687    paranoid_free(command);
     688
     689    set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     690
     691}
     692
     693/**
     694 * Handle OBDR if we were asked to do so
    680695 * @param tapedev The tape device to open for writing.
    681696 * @return 0 for success, nonzero for failure.
     
    683698 * EXISTING DATA on the tape!
    684699 */
    685 void skip_obdr(char *tapedev)
    686 {
    687     char *command = NULL;
    688     char *ntapedev = NULL;
    689 
    690     ntapedev = get_non_rewind_dev(tapedev);
    691     if (ntapedev == NULL) {
    692         log_it("Not skipping OBDR");
    693     }
    694 
    695     asprintf(&command, "mt -f %s fsf 2",ntapedev);
    696     run_program_and_log_output(command, 1);
    697     paranoid_free(command);
    698 
    699     set_tape_block_size_with_mt(ntapedev, bkpinfo->internal_tape_block_size);
    700 
    701     paranoid_free(ntapedev);
    702 }
    703 
    704 int create_obdr(char *tapedev)
    705 {
    706 
    707     char *ntapedev = NULL;
     700int create_obdr()
     701{
     702
    708703    char *command = NULL;
    709704    int res = 0;
    710705
    711     ntapedev = get_non_rewind_dev(tapedev);
    712     if (ntapedev == NULL) {
    713         log_it("Skipping OBDR");
    714         return(1);
    715     }
    716 
    717706    /* OBDR: First block 10 kB of zero bs = 512 */
    718     asprintf(&command, "mt -f %s compression off",tapedev);
     707    asprintf(&command, "mt -f %s compression off",bkpinfo->media_device);
    719708    res = run_program_and_log_output(command, 1);
    720709    paranoid_free(command);
    721710
    722     asprintf(&command, "mt -f %s rewind",tapedev);
     711    asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
    723712    res = run_program_and_log_output(command, 1);
    724713    paranoid_free(command);
    725714
    726     set_tape_block_size_with_mt(ntapedev, 512);
    727 
    728     asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",ntapedev);
     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);
    729718    res = run_program_and_log_output(command, 1);
    730719    paranoid_free(command);
    731720
    732721    /* OBDR: then ISO boot image bs = 2048 */
    733     set_tape_block_size_with_mt(ntapedev, 2048);
    734 
    735     asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",ntapedev);
     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);
    736725    res = run_program_and_log_output(command, 1);
    737726    paranoid_free(command);
    738727
    739     set_tape_block_size_with_mt(ntapedev, bkpinfo->internal_tape_block_size);
    740 
    741     paranoid_free(ntapedev);
     728    set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
    742729}
    743730
     
    756743    char fname[MAX_STR_LEN];
    757744    char *datablock;
     745    char *ntapedev = NULL;
    758746    char tmp[MAX_STR_LEN];
    759747    char old_cwd[MAX_STR_LEN];
     
    786774        return (0);
    787775    }
    788     if (bkpinfo->use_obdr) {
    789         skip_obdr(bkpinfo->media_device);
    790     } else {
    791         set_tape_block_size_with_mt(bkpinfo->media_device,
    792                                 bkpinfo->internal_tape_block_size);
    793     }
    794 
     776    ntapedev = get_non_rewind_dev(bkpinfo->media_device);
     777    if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
     778        strncpy(bkpinfo->media_device,ntapedev,(size_t)(MAX_STR_LEN / 4));
     779        skip_obdr();
     780    } else {
     781        if (ntapedev == 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    paranoid_free(ntapedev);
    795787
    796788    insist_on_this_tape_number(1);
     
    909901 * EXISTING DATA on the tape!
    910902 */
    911 int openout_tape(char *tapedev, long internal_tape_block_size)
    912 {
    913 
    914     g_current_media_number = 1;
    915     if (g_tape_stream) {
    916         log_it("FYI - I won't 'openout' the tape. It's already open.");
    917         return (0);
    918     }
    919     if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
    920         fatal_error("Cannot alloc mem for tape catalog");
    921     }
    922     g_tapecatalog->entries = 0;
    923     g_tape_posK = 0;
    924 
    925     if (bkpinfo->use_obdr) {
    926         create_obdr(tapedev);
    927     } else {
    928         set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
    929     }
    930     log_it("Opening OUT tape");
    931     if (!
    932         (g_tape_stream =
    933          open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) {
    934         log_OS_error(g_tape_fifo);
    935         log_to_screen("Cannot openin stream device");
    936         return (1);
    937     }
     903int openout_tape() {
     904
     905char *ntapedev = NULL;
     906
     907g_current_media_number = 1;
     908if (g_tape_stream) {
     909    log_it("FYI - I won't 'openout' the tape. It's already open.");
    938910    return (0);
     911}
     912if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
     913    fatal_error("Cannot alloc mem for tape catalog");
     914}
     915g_tapecatalog->entries = 0;
     916g_tape_posK = 0;
     917
     918ntapedev = get_non_rewind_dev(bkpinfo->media_device);
     919if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
     920    strncpy(bkpinfo->media_device,ntapedev,(size_t)(MAX_STR_LEN / 4));
     921    create_obdr();
     922} else {
     923    if (ntapedev == NULL) {
     924        log_it("Not able to create OBDR - Restore will have to be done manually");
     925    }
     926    set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     927}
     928paranoid_free(ntapedev);
     929log_it("Opening OUT tape");
     930if (!
     931    (g_tape_stream =
     932     open_device_via_buffer(tapedev, 'w', bkpinfo->internal_tape_block_size))) {
     933    log_OS_error(g_tape_fifo);
     934    log_to_screen("Cannot openin stream device");
     935    return (1);
     936}
     937return (0);
    939938}
    940939
  • branches/2.2.6/mondo/src/common/libmondo-stream.h

    r1647 r1954  
    1414int openin_tape();
    1515int openout_cdstream(char *cddev, int speed);
    16 int openout_tape(char *tapedev, long internal_tape_block_size);
     16int openout_tape();
    1717int read_file_from_stream_to_file(char *outfile,
    1818                                  long long size);
Note: See TracChangeset for help on using the changeset viewer.