Changeset 1175


Ignore:
Timestamp:
Feb 16, 2007, 2:15:30 PM (12 years ago)
Author:
bruno
Message:

Merge trunk memory management for libmondo-stream.c

File:
1 edited

Legend:

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

    r1174 r1175  
    130130    }
    131131    sleep(1);
    132     paranoid_system("sync");
     132    sync();
    133133    sleep(1);
    134134    paranoid_pclose(g_tape_stream);
    135135    log_it("closein_tape() -- leaving");
    136 /*
    137   for(i=0; i < g_tapecatalog->entries; i++)
    138     {
    139       log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);
    140     }
    141 */
    142136    if (!bkpinfo->please_dont_eject) {
    143137        eject_device(bkpinfo->media_device);
     
    161155    /*@ int's ******************************************************* */
    162156    int retval = 0;
    163 //  int res = 0;
    164 //  int ctrl_chr = '\0';
    165 
    166     /*@ buffers ***************************************************** */
    167 //  char fname[MAX_STR_LEN];
    168157
    169158    /*@ long long's ************************************************* */
    170 //  long long size;
    171     int i;
    172     char *blk;
     159    int i = 0;
     160    char *blk = NULL;
    173161
    174162    blk = (char *) mr_malloc(256 * 1024);
    175163
    176164    sleep(1);
    177     paranoid_system("sync");
     165    sync();
    178166    sleep(1);
    179167    log_it("closeout_tape() -- entering");
     
    182170                                     BLK_END_OF_BACKUP);
    183171    retval += write_header_block_to_stream((off_t)0, "end-of-tape", BLK_END_OF_TAPE);   /* just in case */
    184 /* write 1MB of crap */
     172    /* write 1MB of crap */
    185173    for (i = 0; i < 256 * 1024; i++) {
    186174        blk[i] = (int) (random() & 0xFF);
     
    193181        }
    194182    }
    195 /* write 1MB of zeroes */
    196 /*
    197     for (i = 0; i < 256*1024; i++)
    198       {
    199         blk[i] = 0;
    200       }
    201     for (i = 0; i < 4; i++)
    202       {
    203         fwrite (blk, 1, 256*1024, g_tape_stream);
    204         if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024))
    205           {
    206             start_to_write_to_next_tape (bkpinfo);
    207           }
    208       }
    209 */
    210183    sleep(2);
    211184    paranoid_pclose(g_tape_stream);
     
    218191               g_tapecatalog->el[i].tape_posK);
    219192    }
    220     //  if (!bkpinfo->please_dont_eject)
    221     //    { eject_device(bkpinfo->media_device); }
    222193    mr_free(blk);
    223194    mr_free(g_tapecatalog);
     
    232203    int res;
    233204
    234     malloc_string(command);
    235     sprintf(command, "mt -f %s status", dev);
     205    mr_asprintf(&command, "mt -f %s status", dev);
    236206    res = run_program_and_log_output(command, 1);
    237207    mr_free(command);
     
    255225{
    256226    char tmp[MAX_STR_LEN];
    257     char command[MAX_STR_LEN * 2];
     227    char *command = NULL;
    258228    char cdr_exe[MAX_STR_LEN];
    259 //  char tape_description_[MAX_STR_LEN];
    260 //  char tape_manufacturer_cdr[MAX_STR_LEN];
    261 //  FILE*fin;
    262229    int res;
    263230
     
    269236        strcpy(cdr_exe, "dvdrecord");
    270237    }
    271     sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
     238    mr_asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    272239            cdr_exe);
    273240    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     241    mr_free(command);
    274242    if (atoi(tmp) != 1) {
    275243        log_it
     
    278246        return 1;
    279247    }
    280     sprintf(command,
     248    mr_asprintf(&command,
    281249            "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",
    282250            cdr_exe);
    283251    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     252    mr_free(command);
    284253    if (strlen(tmp) < 2) {
    285254        log_it("Could not find tape device");
    286255        return 1;
    287256    }
    288     sprintf(command,
     257    mr_asprintf(&command,
    289258            "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1",
    290259            cdr_exe);
    291260    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     261    mr_free(command);
     262
    292263    strcpy(dev, VANILLA_SCSI_TAPE);
    293264    dev[strlen(dev) - 1] = '\0';
     
    350321
    351322
    352 
    353 
    354 
    355 
    356323int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
    357324                              long long *ptmp_size, char *tmp_fname,
     
    379346        mr_msg(1, "Got xattr");
    380347    }
    381 // acl
     348    // acl
    382349    if (g_getfacl) {
    383350        res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
     
    399366        mr_msg(1, "Got acl");
    400367    }
    401 // tarball itself
     368    // tarball itself
    402369    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    403370    mr_msg(1, "now looking for afioball");
     
    443410{
    444411    int i;
    445     char tmp[MAX_STR_LEN];
     412    char *tmp = NULL;
    446413
    447414    log_it("Insisting on tape #%d", tapeno);
    448415    if (g_current_media_number != tapeno) {
    449416        //      log_it("g_current_media_number = %d", g_current_media_number);
    450         sprintf(tmp,
    451                 "When the tape drive goes quiet, please insert volume %d in this series.",
    452                 tapeno);
     417        mr_asprintf(&tmp,
     418                 _("When the tape drive goes quiet, please insert volume %d in this series."),
     419                 tapeno);
    453420        popup_and_OK(tmp);
    454         open_evalcall_form("Waiting while the tape drive settles");
    455     } else {
    456         open_evalcall_form("Waiting while the tape drive rewinds");
     421        mr_free(tmp);
     422        open_evalcall_form(_("Waiting while the tape drive settles"));
     423    } else {
     424        open_evalcall_form(_("Waiting while the tape drive rewinds"));
    457425    }
    458426
     
    470438
    471439
    472 
    473 
    474440/**
    475441 * Debugging aid - log the offset we're at on the tape (reading or writing).
     
    477443void log_tape_pos(void)
    478444{
    479     /*@ buffers ***************************************************** */
    480 
    481 
    482     /*@ end vars *************************************************** */
    483 
    484445    log_it("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK,
    485446           (long) g_tape_posK >> 10);
    486447}
    487 
    488 
    489448
    490449
     
    506465    int last, curr, i;
    507466    t_archtype type = other;
    508     char command[MAX_STR_LEN];
    509     char tmpdir[MAX_STR_LEN];
    510     char old_fname[MAX_STR_LEN];
    511     char *p;
    512     char suffix[16];
     467    char *command = NULL;
     468    char *tmpdir = NULL;
     469    char *old_fname = NULL;
    513470
    514471    bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB));
    515     sprintf(tmpdir, "%s/tmpfs/backcatalog", td);
    516     if ((p = strrchr(latest_fname, '.'))) {
    517         strcpy(suffix, ++p);
    518     } else {
    519         suffix[0] = '\0';
    520     }
    521472    if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) {
    522473        type = fileset;
     
    528479            ("Unknown type. Internal error in maintain_collection_of_recent_archives()");
    529480    }
     481
     482    mr_asprintf(&tmpdir, "%s/tmpfs/backcatalog", td);
    530483    mkdir(tmpdir, 0x700);
    531     sprintf(command, "cp -f %s %s", latest_fname, tmpdir);
     484    mr_asprintf(&command, "cp -f %s %s", latest_fname, tmpdir);
    532485    if (run_program_and_log_output(command, 6)) {
    533486        log_it("Warning - failed to copy %s to backcatalog at %s",
    534487               latest_fname, tmpdir);
    535488    }
     489    mr_free(command);
     490
    536491    last = g_tapecatalog->entries - 1;
    537492    if (last <= 0) {
     
    556511
    557512    for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
    558         sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
     513        mr_asprintf(&old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
    559514        unlink(old_fname);
    560     }
     515        mr_free(old_fname);
     516    }
     517    mr_free(tmpdir);
    561518    return (0);
    562519}
    563 
    564 
    565520
    566521
     
    575530    return (openin_tape(bkpinfo));
    576531}
    577 
    578 /**
    579  * FIFO used to read/write to the tape device.
    580  * @bug This seems obsolete now that we call an external @c buffer program. Please look onto this.
    581  */
    582 char g_tape_fifo[MAX_STR_LEN];
    583 
    584532
    585533
     
    595543        return (0);
    596544    }
    597     malloc_string(tmp);
    598     sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
     545    mr_asprintf(&tmp, "mt -f %s setblk %ld", tapedev,
     546            internal_tape_block_size);
    599547    res = run_program_and_log_output(tmp, 3);
    600548    mr_free(tmp);
    601549    return (res);
    602550}
    603 
    604551
    605552
     
    616563    /*@ buffer ***************************************************** */
    617564    char fname[MAX_STR_LEN];
    618     char *datablock;
    619     char tmp[MAX_STR_LEN];
     565    char *datablock = NULL;
     566    char *tmp = NULL;
    620567    char old_cwd[MAX_STR_LEN];
    621     char outfname[MAX_STR_LEN];
     568    char *outfname = NULL;
    622569    /*@ int ******************************************************* */
    623570    int i;
     
    646593    }
    647594    insist_on_this_tape_number(1);
    648     sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
     595    mr_asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
    649596    make_hole_for_file(outfname);
    650597
     
    652599                                bkpinfo->internal_tape_block_size);
    653600
    654 //  start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
    655601    log_it("Opening IN tape");
    656602    if (!
     
    658604         open_device_via_buffer(bkpinfo->media_device, 'r',
    659605                                bkpinfo->internal_tape_block_size))) {
    660         log_OS_error(g_tape_fifo);
    661         log_to_screen("Cannot openin stream device");
     606        log_to_screen(_("Cannot openin stream device"));
    662607        return (1);
    663608    }
    664     log_to_screen("Reading stream");
     609    log_to_screen(_("Reading stream"));
    665610    log_it("stream device = '%s'", bkpinfo->media_device);
    666 /* skip data disks */
     611    /* skip data disks */
    667612    open_evalcall_form("Skipping data disks on stream");
    668     log_to_screen("Skipping data disks on stream");
     613    log_to_screen(_("Skipping data disks on stream"));
    669614    if (!(fout = fopen(outfname, "w"))) {
    670615        log_OS_error(outfname);
    671         log_to_screen("Cannot openout datadisk all.tar.gz file");
     616        log_to_screen(_("Cannot openout datadisk all.tar.gz file"));
    672617        return (-1);
    673618    }
     
    690635    paranoid_fclose(fout);
    691636    mr_free(datablock);
    692 /* find initial blocks */
     637    /* find initial blocks */
    693638    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
    694639    retval += res;
     
    705650    (void) getcwd(old_cwd, MAX_STR_LEN);
    706651    chdir(bkpinfo->tmpdir);
    707     sprintf(tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
    708             outfname);
     652    mr_asprintf(&tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
     653             outfname);
    709654    paranoid_system(tmp);
     655    mr_free(tmp);
    710656    paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null");
    711657    chdir(old_cwd);
    712658    unlink(outfname);
     659    mr_free(outfname);
    713660    return (retval);
    714661}
     
    725672{
    726673    /*@ buffers ***************************************************** */
    727     char command[MAX_STR_LEN * 2];
     674    char *command = NULL;
    728675
    729676    /*@ end vars *************************************************** */
    730677
    731 /*  add 'dummy' if testing */
    732     sprintf(command,
    733             "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    734             cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
    735 /*  initialise the catalog */
     678    /*  add 'dummy' if testing */
     679    mr_asprintf(&command,
     680             "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
     681             cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
     682    /*  initialise the catalog */
    736683    g_current_media_number = 1;
    737684    g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
    738685    g_tapecatalog->entries = 0;
    739 /* log stuff */
     686    /* log stuff */
    740687    log_it("Opening OUT cdstream with the command");
    741688    log_it(command);
    742 /*  log_it("Let's see what happens, shall we?"); */
     689    /*  log_it("Let's see what happens, shall we?"); */
    743690    g_tape_stream = popen(command, "w");
     691    mr_free(command);
    744692    if (g_tape_stream) {
    745693        return (0);
    746694    } else {
    747         log_to_screen("Failed to openout to cdstream (fifo)");
     695        log_to_screen(_("Failed to openout to cdstream (fifo)"));
    748696        return (1);
    749697    }
    750698}
     699
    751700
    752701/**
     
    759708int openout_tape(char *tapedev, long internal_tape_block_size)
    760709{
    761 //  char sz_call_to_buffer[MAX_STR_LEN];
    762 
    763710    g_current_media_number = 1;
    764711    if (g_tape_stream) {
     
    775722        (g_tape_stream =
    776723         open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) {
    777         log_OS_error(g_tape_fifo);
    778         log_to_screen("Cannot openin stream device");
     724        log_to_screen(_("Cannot openin stream device"));
    779725        return (1);
    780726    }
    781727    return (0);
    782728}
    783 
    784 
    785729
    786730
     
    806750    return (res);
    807751}
    808 
    809752
    810753
     
    828771
    829772    res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size);
    830 /*  fflush(g_tape_stream);
    831   fflush(fout);*/
    832773    return (res);
    833774}
    834 
    835775
    836776
     
    852792{
    853793    /*@ buffers ***************************************************** */
    854     char *tmp;
    855     char *datablock;
     794    char *tmp = NULL;
     795    char *datablock = NULL;
    856796    char *temp_fname;
    857797    char *temp_cksum;
    858     char *actual_cksum;
    859 //  char *pA, *pB;
     798    char *actual_cksum = NULL;
    860799
    861800    /*@ int ********************************************************* */
     
    871810
    872811    /*@ long    ***************************************************** */
    873     long bytes_to_write = 0 /*,i */ ;
    874 //  long bytes_successfully_read_in_this_time = 0;
     812    long bytes_to_write = 0;
    875813
    876814    /*@ long long *************************************************** */
     
    880818    long long where_I_was_before_tape_change = 0;
    881819    /*@ unsigned int ************************************************ */
    882     /*  unsigned int ch; */
    883820    unsigned int crc16;
    884821    unsigned int crctt;
     
    887824
    888825    /*@ init  ******************************************************* */
    889     malloc_string(tmp);
    890826    malloc_string(temp_fname);
    891827    malloc_string(temp_cksum);
    892     malloc_string(actual_cksum);
    893828    datablock = mr_malloc(TAPE_BLOCK_SIZE);
    894829    crc16 = 0;
     
    900835    res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr);
    901836    if (orig_size != temp_size && orig_size != -1) {
    902         sprintf(tmp,
    903                 "output file's size should be %ld K but is apparently %ld K",
    904                 (long) size >> 10, (long) temp_size >> 10);
     837        mr_asprintf(&tmp,
     838                 "output file's size should be %ld K but is apparently %ld K",
     839                 (long) size >> 10, (long) temp_size >> 10);
    905840        log_to_screen(tmp);
     841        mr_free(tmp);
    906842    }
    907843    if (ctrl_chr != BLK_START_FILE) {
     
    909845        return (1);
    910846    }
    911     sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB",
    912             outfname, (long) size >> 10);
     847    mr_asprintf(&tmp, "Reading file from tape; writing to '%s'; %ld KB",
     848             outfname, (long) size >> 10);
     849    log_to_screen(tmp);
     850    mr_free(tmp);
    913851
    914852    if (foutstream) {
     
    919857    if (!fout) {
    920858        log_OS_error(outfname);
    921         log_to_screen("Cannot openout file");
     859        log_to_screen(_("Cannot openout file"));
    922860        return (1);
    923861    }
     
    966904    mr_msg(6, ".......................... Should be %lld", orig_size);
    967905    g_tape_posK += total_read_from_tape_for_this_file / 1024;
    968     sprintf(actual_cksum, "%04x%04x", crc16, crctt);
     906    mr_asprintf(&actual_cksum, "%04x%04x", crc16, crctt);
    969907    if (foutstream) {           /*log_it("Finished writing to foutstream"); */
    970908    } else {
     
    977915    }
    978916    if (strcmp(temp_cksum, actual_cksum)) {
    979         sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
    980                 temp_cksum);
     917        mr_asprintf(&tmp, _("actual cksum=%s; recorded cksum=%s"), actual_cksum,
     918                 temp_cksum);
    981919        log_to_screen(tmp);
    982         sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
    983                 (long) orig_size >> 10);
     920        mr_free(tmp);
     921
     922        mr_asprintf(&tmp, _("%s (%ld K) is corrupt on tape"), temp_fname,
     923                 (long) orig_size >> 10);
    984924        log_to_screen(tmp);
     925        mr_free(tmp);
    985926        retval++;
    986     } else {
    987         sprintf(tmp, "%s is GOOD on tape", temp_fname);
    988         /*      log_it(tmp); */
    989     }
     927    }
     928    mr_free(actual_cksum);
    990929    mr_free(datablock);
    991     mr_free(tmp);
    992930    mr_free(temp_fname);
    993931    mr_free(temp_cksum);
    994     mr_free(actual_cksum);
    995932    return (retval);
    996933}
    997 
    998934
    999935
     
    1031967                  g_tape_stream) / 1024;
    1032968    }
    1033 /*  memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */
    1034 /*  for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */
    1035969    memcpy((char *) plen, tempblock + 7001, sizeof(long long));
    1036970    if (strcmp(tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) {
     
    1038972    }
    1039973    strcpy(filename, tempblock + 1000);
    1040 /*  strcpy(cksum,tempblock+5555);*/
    1041 /*  log_it( "%s  (reading) fname=%s, filesize=%ld K",
    1042        marker_to_string (*pcontrol_char), filename,
    1043        (long) ((*plen) >> 10));
    1044 */
    1045974    if (*pcontrol_char == BLK_ABORTED_BACKUP) {
    1046975        log_to_screen("I can't verify an aborted backup.");
     
    1061990    return (retval);
    1062991}
    1063 
    1064992
    1065993
     
    11071035
    11081036
    1109 
    1110 
    11111037/**
    11121038 * Decide whether we should start a new tape. This is TRUE if we've run out of tape
     
    11341060        log_it("mediasize = %ld", mediasize);
    11351061        we_need_a_new_tape = TRUE;
    1136         log_to_screen("Should have started a new tape/CD already");
     1062        log_to_screen(_("Should have started a new tape/CD already"));
    11371063    }
    11381064    if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >=
     
    12801206
    12811207    paranoid_pclose(g_tape_stream);
    1282     system("sync");
    1283     system("sync");
    1284     system("sync");
     1208    sync();
     1209    sync();
     1210    sync();
    12851211    log_it("Next tape requested.");
    12861212    insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
     
    12901216         open_device_via_buffer(bkpinfo->media_device, 'r',
    12911217                                bkpinfo->internal_tape_block_size))) {
    1292         log_OS_error(g_tape_fifo);
    1293         log_to_screen("Cannot openin stream device");
     1218        log_to_screen(_("Cannot openin stream device"));
    12941219        return (1);
    12951220    }
     
    13111236
    13121237
    1313 
    13141238/**
    13151239 * Start to write to the next tape. Assume the user has already inserted it.
     
    13201244{
    13211245    int res = 0;
    1322     char command[MAX_STR_LEN * 2];
     1246    char *command = NULL;
     1247
    13231248    paranoid_pclose(g_tape_stream);
    1324     system("sync");
    1325     system("sync");
    1326     system("sync");
     1249    sync();
     1250    sync();
     1251    sync();
    13271252    log_it("New tape requested.");
    13281253    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
    13291254    if (g_current_media_number > MAX_NOOF_MEDIA) {
    13301255        res++;
    1331         log_to_screen("Too many tapes. Man, you need to use nfs!");
     1256        log_to_screen(_("Too many tapes. Man, you need to use nfs!"));
    13321257    }
    13331258    if (bkpinfo->backup_media_type == cdstream) {
    1334         sprintf(command,
    1335                 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    1336                 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
    1337                 MONDO_LOGFILE);
     1259        mr_asprintf(&command,
     1260                 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
     1261                 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
     1262                 MONDO_LOGFILE);
    13381263        log_it("Opening OUT to next CD with the command");
    13391264        log_it(command);
    13401265        log_it("Let's see what happens, shall we?");
    13411266        g_tape_stream = popen(command, "w");
     1267        mr_free(command);
    13421268        if (!g_tape_stream) {
    1343             log_to_screen("Failed to openout to cdstream (fifo)");
     1269            log_to_screen(_("Failed to openout to cdstream (fifo)"));
    13441270            return (1);
    13451271        }
     
    13501276             open_device_via_buffer(bkpinfo->media_device, 'w',
    13511277                                    bkpinfo->internal_tape_block_size))) {
    1352             log_OS_error(g_tape_fifo);
    1353             log_to_screen("Cannot openin stream device");
     1278            log_to_screen(_("Cannot openin stream device"));
    13541279            return (1);
    13551280        }
     
    13611286    return (res);
    13621287}
    1363 
    1364 
    13651288
    13661289
     
    13801303{
    13811304    int i, last, res = 0;
    1382     char *fname;
     1305    char *fname = NULL;
    13831306
    13841307    mr_msg(2, "I am now writing back catalog to tape");
    1385     malloc_string(fname);
    13861308    last = g_tapecatalog->entries - 1;
    13871309    for (i = 0; i <= last; i++) {
    1388         sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
    1389                 g_tapecatalog->el[i].fname);
     1310        mr_asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
     1311                 g_tapecatalog->el[i].fname);
    13901312        if (!does_file_exist(fname)) {
    13911313            mr_msg(6, "Can't write %s - it doesn't exist.", fname);
     
    14051327            }
    14061328        }
    1407     }
    1408     mr_free(fname);
     1329        mr_free(fname);
     1330    }
    14091331    mr_msg(2, "Finished writing back catalog to tape");
    14101332    return (res);
     
    14121334
    14131335
    1414 
    14151336/**
    14161337 * Write all.tar.gz (produced by Mindi) to the first 32M of the first tape.
     
    14211342{
    14221343    /*@ pointers *************************************************** */
    1423     FILE *fin;
    1424     char tmp[MAX_STR_LEN];
     1344    FILE *fin = NULL;
     1345    char *tmp = NULL;
    14251346
    14261347    /*@ long ******************************************************* */
     
    14361357    /*@ end vars *************************************************** */
    14371358
    1438     open_evalcall_form("Writing data disks to tape");
    1439     log_to_screen("Writing data disks to tape");
     1359    open_evalcall_form(_("Writing data disks to tape"));
     1360    log_to_screen(_("Writing data disks to tape"));
    14401361    log_it("Data disks = %s", fname);
    14411362    if (!does_file_exist(fname)) {
    1442         sprintf(tmp, "Cannot find %s", fname);
     1363        mr_asprintf(&tmp, _("Cannot find %s"), fname);
    14431364        log_to_screen(tmp);
     1365        mr_free(tmp);
    14441366        return (1);
    14451367    }
     
    14731395
    14741396
    1475 
    1476 
    14771397/**
    14781398 * Copy @p infile to the opened stream (CD or tape).
     
    14841404{
    14851405    /*@ buffers **************************************************** */
    1486     char tmp[MAX_STR_LEN];
     1406    char *tmp = NULL;
    14871407    char datablock[TAPE_BLOCK_SIZE];
    1488     char checksum[MAX_STR_LEN];
    1489     char *infile_basename;
     1408    char *checksum = NULL;
     1409    char *infile_basename = NULL;
    14901410
    14911411    /*@ int ******************************************************** */
     
    15141434    crc16 = 0;
    15151435    crctt = 0;
    1516 
    1517 
    15181436
    15191437    /*@ end vars *************************************************** */
     
    15371455        p++;
    15381456    }
    1539     sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
    1540             (long) filesize >> 10);
     1457    mr_asprintf(&tmp, "Writing file '%s' to tape (%ld KB)", p,
     1458             (long) filesize >> 10);
    15411459    log_it(tmp);
     1460    mr_free(tmp);
     1461
    15421462    write_header_block_to_stream(filesize, infile_basename,
    15431463                                 BLK_START_FILE);
     
    15581478        }
    15591479        (void) fread(datablock, 1, (size_t) bytes_to_read, fin);
    1560         g_tape_posK +=
    1561             fwrite(datablock, 1, /*bytes_to_read */
    1562                    (size_t) TAPE_BLOCK_SIZE,
    1563                    g_tape_stream) / 1024;
     1480        g_tape_posK += fwrite(datablock, 1, /*bytes_to_read */
     1481                              (size_t) TAPE_BLOCK_SIZE,
     1482                              g_tape_stream) / 1024;
    15641483        if (g_sigpipe) {
    15651484            iamhere("Sigpipe occurred recently. I'll start a new tape.");
     
    15791498    }
    15801499    paranoid_fclose(fin);
    1581     sprintf(checksum, "%04x%04x", crc16, crctt);
     1500    mr_asprintf(&checksum, "%04x%04x", crc16, crctt);
    15821501    /* BERLIOS: what does it do ??? */
    15831502    write_header_block_to_stream((off_t)g_current_media_number, checksum,
    15841503                                 BLK_STOP_FILE);
     1504    mr_free(checksum);
    15851505//  log_it("File '%s' written to tape.", infile);
    15861506    return (retval);
    15871507}
    1588 
    1589 
    1590 
    15911508
    15921509
     
    16081525    /*@ buffers **************************************************** */
    16091526    char tempblock[TAPE_BLOCK_SIZE];
    1610     char tmp[MAX_STR_LEN];
    16111527    char *p;
    16121528
     
    16281544    if (!g_tape_stream) {
    16291545        log_to_screen
    1630             ("You're not backing up to tape. Why write a tape header?");
     1546            (_("You're not backing up to tape. Why write a tape header?"));
    16311547        return (1);
    16321548    }
     
    16361552    sprintf(tempblock + 6000 + control_char, "Mondolicious, baby");
    16371553    tempblock[7000] = control_char;
    1638 /*  for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */
    16391554    memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t));
    1640 /*  if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */
    16411555    strcpy(tempblock + 1000, filename);
    1642 /*  strcpy(tempblock+5555,cksum); */
    16431556    g_tape_posK +=
    16441557        fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
    16451558               g_tape_stream) / 1024;
    1646     sprintf(tmp, "%s (fname=%s, size=%ld K)",
     1559    mr_msg(6, "%s (fname=%s, size=%ld K)",
    16471560            marker_to_string(control_char), p,
    16481561            (long) length_of_incoming_file >> 10);
    1649     mr_msg(6, tmp);
    1650 /*  log_tape_pos(); */
    16511562    return (0);
    16521563}
    1653 
    1654 
    1655 
    1656 
    1657 
    1658 
    1659 
    1660 
    16611564
    16621565
     
    16691572{
    16701573    /*@ buffer ***************************************************** */
    1671     char tmp[MAX_STR_LEN];
     1574    char *tmp = NULL;
    16721575
    16731576
    16741577    /*@ end vars *************************************************** */
    1675     sprintf(tmp, "Wrong marker! (Should be %s, ",
    1676             marker_to_string(should_be));
    1677     sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is));
     1578    mr_asprintf(&tmp, _("Wrong marker! (Should be %s, is actually %s)"),
     1579             marker_to_string(should_be), marker_to_string(it_is));
    16781580    log_to_screen(tmp);
     1581    mr_free(tmp);
    16791582}
    16801583
Note: See TracChangeset for help on using the changeset viewer.