Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

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

    r126 r128  
    199199
    200200#ifdef __FreeBSD__
    201     #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
    202     #define BACKUP_1722MB_DISK "/dev/fd0.1722"
     201#define DEFAULT_1722MB_DISK "/dev/fd0.1722"
     202#define BACKUP_1722MB_DISK "/dev/fd0.1722"
    203203#else
    204     #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
    205     #define BACKUP_1722MB_DISK "/dev/fd0H1722"
     204#define DEFAULT_1722MB_DISK "/dev/fd0u1722"
     205#define BACKUP_1722MB_DISK "/dev/fd0H1722"
    206206#ifndef _SEMUN_H
    207     #define _SEMUN_H
     207#define _SEMUN_H
    208208
    209209    /**
    210210     * The semaphore union, provided only in case the user's system doesn't.
    211211     */
    212     union semun {
    213       int val;
    214       struct semid_ds *buf;
    215       unsigned short int *array;
    216       struct seminfo *__buf;
    217     };
     212union semun {
     213    int val;
     214    struct semid_ds *buf;
     215    unsigned short int *array;
     216    struct seminfo *__buf;
     217};
    218218#endif
    219 #endif /* __FreeBSD__ */
     219#endif                          /* __FreeBSD__ */
    220220
    221221/*@unused@*/
     
    228228extern bool g_exiting;
    229229extern long g_current_progress;
    230 extern FILE*g_tape_stream;
     230extern FILE *g_tape_stream;
    231231extern long long g_tape_posK;
    232232extern char *g_mondo_home;
     
    242242 * The current backup media type in use.
    243243 */
    244 t_bkptype g_backup_media_type=none;
     244t_bkptype g_backup_media_type = none;
    245245
    246246/**
     
    274274 * @return 1 for success, 0 for failure.
    275275 */
    276 static int set_semvalue(void) // initializes semaphore
     276static int set_semvalue(void)   // initializes semaphore
    277277{
    278   union semun sem_union;
    279   sem_union.val = 1;
    280   if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) { return(0); }
    281   return(1);
     278    union semun sem_union;
     279    sem_union.val = 1;
     280    if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
     281        return (0);
     282    }
     283    return (1);
    282284}
    283285
     
    287289 * @see set_semvalue
    288290 */
    289 static void del_semvalue(void) // deletes semaphore
     291static void del_semvalue(void)  // deletes semaphore
    290292{
    291   union semun sem_union;
    292 
    293   if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1)
    294     { log_msg (3, "Failed to delete semaphore"); }
     293    union semun sem_union;
     294
     295    if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
     296        log_msg(3, "Failed to delete semaphore");
     297    }
    295298}
    296299
     
    300303 * @see semaphore_v
    301304 */
    302 static int semaphore_p(void) // changes status to 'P' (waiting)
     305static int semaphore_p(void)    // changes status to 'P' (waiting)
    303306{
    304   struct sembuf sem_b;
    305 
    306   sem_b.sem_num = 0;
    307   sem_b.sem_op = -1; // P()
    308   sem_b.sem_flg = SEM_UNDO;
    309   if (semop(g_sem_id, &sem_b, 1) == -1)
    310     { log_msg(3, "semaphore_p failed"); return(0); }
    311   return(1);
     307    struct sembuf sem_b;
     308
     309    sem_b.sem_num = 0;
     310    sem_b.sem_op = -1;          // P()
     311    sem_b.sem_flg = SEM_UNDO;
     312    if (semop(g_sem_id, &sem_b, 1) == -1) {
     313        log_msg(3, "semaphore_p failed");
     314        return (0);
     315    }
     316    return (1);
    312317}
    313318
     
    316321 * @return 1 for success, 0 for failure.
    317322 */
    318 static int semaphore_v(void) // changes status to 'V' (free)
     323static int semaphore_v(void)    // changes status to 'V' (free)
    319324{
    320   struct sembuf sem_b;
    321 
    322   sem_b.sem_num = 0;
    323   sem_b.sem_op = 1; // V()
    324   sem_b.sem_flg = SEM_UNDO;
    325   if (semop(g_sem_id, &sem_b, 1) == -1)
    326     { log_msg(3, "semaphore_v failed"); return(0); }
    327   return(1);
     325    struct sembuf sem_b;
     326
     327    sem_b.sem_num = 0;
     328    sem_b.sem_op = 1;           // V()
     329    sem_b.sem_flg = SEM_UNDO;
     330    if (semop(g_sem_id, &sem_b, 1) == -1) {
     331        log_msg(3, "semaphore_v failed");
     332        return (0);
     333    }
     334    return (1);
    328335}
    329336
     
    344351
    345352int
    346 archive_this_fileset_with_star (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    347           int setno)
     353archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, char *filelist,
     354                               char *fname, int setno)
    348355{
    349   int retval = 0;
    350   unsigned int res = 0;
    351   int tries = 0;
    352   char *command;
    353   char *zipparams;
    354   char *tmp;
    355   char *p;
    356  
    357   malloc_string(command);
    358   malloc_string(zipparams);
    359   malloc_string(tmp);
    360 
    361   if (!does_file_exist (filelist))
    362     {
    363       sprintf (tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    364       log_to_screen (tmp);
    365       return (1);
    366     }
    367 
    368   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    369   if (system(tmp))
    370     {
    371       fatal_error("Unable to write tarball to scratchdir");
    372     }
    373  
    374   sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s", filelist, fname);
    375   if (bkpinfo->use_lzo) { fatal_error("Can't use lzop"); }
    376   if (bkpinfo->compression_level > 0)
    377     {
    378       strcat(command, " -bz");
    379     }
    380   sprintf(command+strlen(command), " 2>> %s", MONDO_LOGFILE);
    381   log_msg(4, "command = '%s'", command);
    382    
    383   for(res=99,tries=0; tries<3 && res!=0; tries++)
    384     {
    385       log_msg(5, "command='%s'", command);
    386       res = system (command);
    387       strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
    388       log_msg(1, "res=%d; tmp='%s'", res, tmp);
    389       if (bkpinfo->use_star && (res==254 || res==65024) && strstr(tmp, "star: Processed all possible files") && tries>0)
    390     {
    391       log_msg(1, "Star returned nonfatal error");
    392       res=0;
    393     }
    394       if (res)
    395         {
    396           log_OS_error (command);
    397       p = strstr(command, "-acl ");
    398       if (p)
    399         {
    400           p[0]=p[1]=p[2]=p[3]=' ';
    401               log_msg(1,"new command = '%s'", command);
    402         }
    403       else
    404         {
    405               log_msg (3, "Attempt #%d failed. Pausing 3 seconds and retrying...", tries+1);
    406           sleep(3);
    407         }
    408         }
    409     }
    410   retval += res;
    411   if (retval) { log_msg (3, "Failed to write set %d", setno); }
    412   else if (tries>1) { log_msg( 3,"Succeeded in writing set %d, on try #%d", setno, tries); }
    413 
    414   paranoid_free(command);
    415   paranoid_free(zipparams);
    416   paranoid_free(tmp);
    417   return (retval);
     356    int retval = 0;
     357    unsigned int res = 0;
     358    int tries = 0;
     359    char *command;
     360    char *zipparams;
     361    char *tmp;
     362    char *p;
     363
     364    malloc_string(command);
     365    malloc_string(zipparams);
     366    malloc_string(tmp);
     367
     368    if (!does_file_exist(filelist)) {
     369        sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
     370                filelist);
     371        log_to_screen(tmp);
     372        return (1);
     373    }
     374
     375    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     376    if (system(tmp)) {
     377        fatal_error("Unable to write tarball to scratchdir");
     378    }
     379
     380    sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
     381            filelist, fname);
     382    if (bkpinfo->use_lzo) {
     383        fatal_error("Can't use lzop");
     384    }
     385    if (bkpinfo->compression_level > 0) {
     386        strcat(command, " -bz");
     387    }
     388    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
     389    log_msg(4, "command = '%s'", command);
     390
     391    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     392        log_msg(5, "command='%s'", command);
     393        res = system(command);
     394        strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
     395        log_msg(1, "res=%d; tmp='%s'", res, tmp);
     396        if (bkpinfo->use_star && (res == 254 || res == 65024)
     397            && strstr(tmp, "star: Processed all possible files")
     398            && tries > 0) {
     399            log_msg(1, "Star returned nonfatal error");
     400            res = 0;
     401        }
     402        if (res) {
     403            log_OS_error(command);
     404            p = strstr(command, "-acl ");
     405            if (p) {
     406                p[0] = p[1] = p[2] = p[3] = ' ';
     407                log_msg(1, "new command = '%s'", command);
     408            } else {
     409                log_msg(3,
     410                        "Attempt #%d failed. Pausing 3 seconds and retrying...",
     411                        tries + 1);
     412                sleep(3);
     413            }
     414        }
     415    }
     416    retval += res;
     417    if (retval) {
     418        log_msg(3, "Failed to write set %d", setno);
     419    } else if (tries > 1) {
     420        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     421                tries);
     422    }
     423
     424    paranoid_free(command);
     425    paranoid_free(zipparams);
     426    paranoid_free(tmp);
     427    return (retval);
    418428}
    419429
     
    436446 */
    437447int
    438 archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    439           int setno)
     448archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
     449                     char *fname, int setno)
    440450{
    441451
    442         /*@ int ****************************************************************/
    443   int retval = 0;
    444   int res = 0;
    445   int i = 0;
    446   int tries = 0;
    447   static int free_ramdisk_space = 9999;
    448 
    449     /*@ buffers *************************************************************/
    450   char *command;
    451   char *zipparams;
    452   char *tmp;
    453 
    454   assert(bkpinfo!=NULL);
    455   assert_string_is_neither_NULL_nor_zerolength(filelist);
    456   assert_string_is_neither_NULL_nor_zerolength(fname);
    457  
    458   if (bkpinfo->compression_level > 0 && bkpinfo->use_star)
    459     {
    460       return(archive_this_fileset_with_star(bkpinfo, filelist, fname, setno));
    461     }
    462  
    463   malloc_string(command);
    464   malloc_string(zipparams);
    465   malloc_string(tmp);
    466  
    467   if (!does_file_exist (filelist))
    468     {
    469       sprintf (tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    470       log_to_screen (tmp);
    471       return (1);
    472     }
    473   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    474   if (system(tmp))
    475     {
    476       fatal_error("Unable to write tarball to scratchdir");
    477     }
    478 
    479  
    480   if (bkpinfo->compression_level > 0)
    481     {
    482       sprintf (tmp, "%s/do-not-compress-these", g_mondo_home);
    483       //       -b %ld, TAPE_BLOCK_SIZE
    484       sprintf (zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level);
    485       if (does_file_exist(tmp))
    486     { strcat (zipparams, " -E "); strcat (zipparams, tmp); }
    487       else
    488     { log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); }
    489     }
    490   else
    491     {
    492       zipparams[0] = '\0';
    493     }
     452    /*@ int *************************************************************** */
     453    int retval = 0;
     454    int res = 0;
     455    int i = 0;
     456    int tries = 0;
     457    static int free_ramdisk_space = 9999;
     458
     459    /*@ buffers ************************************************************ */
     460    char *command;
     461    char *zipparams;
     462    char *tmp;
     463
     464    assert(bkpinfo != NULL);
     465    assert_string_is_neither_NULL_nor_zerolength(filelist);
     466    assert_string_is_neither_NULL_nor_zerolength(fname);
     467
     468    if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
     469        return (archive_this_fileset_with_star
     470                (bkpinfo, filelist, fname, setno));
     471    }
     472
     473    malloc_string(command);
     474    malloc_string(zipparams);
     475    malloc_string(tmp);
     476
     477    if (!does_file_exist(filelist)) {
     478        sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
     479                filelist);
     480        log_to_screen(tmp);
     481        return (1);
     482    }
     483    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     484    if (system(tmp)) {
     485        fatal_error("Unable to write tarball to scratchdir");
     486    }
     487
     488
     489    if (bkpinfo->compression_level > 0) {
     490        sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     491        //       -b %ld, TAPE_BLOCK_SIZE
     492        sprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
     493                bkpinfo->compression_level);
     494        if (does_file_exist(tmp)) {
     495            strcat(zipparams, " -E ");
     496            strcat(zipparams, tmp);
     497        } else {
     498            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
     499        }
     500    } else {
     501        zipparams[0] = '\0';
     502    }
    494503
    495504//  make_hole_for_file(fname);
    496505
    497   if (!does_file_exist(bkpinfo->tmpdir)) { log_OS_error("tmpdir not found"); fatal_error("tmpdir not found"); }
    498   if (!does_file_exist(bkpinfo->scratchdir)) { log_OS_error("scratchdir not found"); fatal_error("scratchdir not found"); }
    499   sprintf (command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname,
    500        bkpinfo->zip_suffix);
    501   paranoid_system (command);
    502 
    503   sprintf (command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
    504 
    505   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    506   if (system(tmp))
    507     {
    508       fatal_error("Unable to write tarball to scratchdir");
    509     }
    510 
    511   for(res=99,tries=0; tries<3 && res!=0; tries++)
    512     {
    513       log_msg(5, "command='%s'", command);
    514       res = system (command);
    515       if (res)
    516         {
    517           log_OS_error (command);
    518           log_msg (3, "Attempt #%d failed. Pausing 3 seconds and retrying...", tries+1);
    519           sleep(3);
    520         }
    521     }
    522   retval += res;
    523   if (retval) { log_msg (3, "Failed to write set %d", setno); }
    524   else if (tries>1) { log_msg( 3,"Succeeded in writing set %d, on try #%d", setno, tries); }
    525 
    526   if (g_tmpfs_mountpt[0] != '\0') {
    527       i = atoi( call_program_and_get_last_line_of_output ("df -m | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
    528       if (i>0)
    529       {
    530           if (free_ramdisk_space > i)
    531           {
    532               free_ramdisk_space = i;
    533               log_msg (2, "min(free_ramdisk_space) is now %d", free_ramdisk_space);
    534               if (free_ramdisk_space < 10)
    535               {
    536                   fatal_error ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
    537               }
    538           }
    539       }
    540   }
    541   paranoid_free(command);
    542   paranoid_free(zipparams);
    543   paranoid_free(tmp);
    544   return (retval);
     506    if (!does_file_exist(bkpinfo->tmpdir)) {
     507        log_OS_error("tmpdir not found");
     508        fatal_error("tmpdir not found");
     509    }
     510    if (!does_file_exist(bkpinfo->scratchdir)) {
     511        log_OS_error("scratchdir not found");
     512        fatal_error("scratchdir not found");
     513    }
     514    sprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
     515            fname, bkpinfo->zip_suffix);
     516    paranoid_system(command);
     517
     518    sprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
     519            TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
     520
     521    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     522    if (system(tmp)) {
     523        fatal_error("Unable to write tarball to scratchdir");
     524    }
     525
     526    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     527        log_msg(5, "command='%s'", command);
     528        res = system(command);
     529        if (res) {
     530            log_OS_error(command);
     531            log_msg(3,
     532                    "Attempt #%d failed. Pausing 3 seconds and retrying...",
     533                    tries + 1);
     534            sleep(3);
     535        }
     536    }
     537    retval += res;
     538    if (retval) {
     539        log_msg(3, "Failed to write set %d", setno);
     540    } else if (tries > 1) {
     541        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     542                tries);
     543    }
     544
     545    if (g_tmpfs_mountpt[0] != '\0') {
     546        i = atoi(call_program_and_get_last_line_of_output
     547                 ("df -m | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
     548        if (i > 0) {
     549            if (free_ramdisk_space > i) {
     550                free_ramdisk_space = i;
     551                log_msg(2, "min(free_ramdisk_space) is now %d",
     552                        free_ramdisk_space);
     553                if (free_ramdisk_space < 10) {
     554                    fatal_error
     555                        ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
     556                }
     557            }
     558        }
     559    }
     560    paranoid_free(command);
     561    paranoid_free(zipparams);
     562    paranoid_free(tmp);
     563    return (retval);
    545564}
    546565
     
    564583int backup_data(struct s_bkpinfo *bkpinfo)
    565584{
    566 int retval=0, res=0;
    567 char *tmp;
    568 
    569   assert(bkpinfo!=NULL);
    570   set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
    571    malloc_string(tmp);
    572       if (bkpinfo->backup_media_type == dvd)
    573         {
     585    int retval = 0, res = 0;
     586    char *tmp;
     587
     588    assert(bkpinfo != NULL);
     589    set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
     590    malloc_string(tmp);
     591    if (bkpinfo->backup_media_type == dvd) {
    574592#ifdef DVDRWFORMAT
    575       if (!find_home_of_exe("dvd+rw-format")) { fatal_error("Cannot find dvd+rw-format. Please install it or fix your PATH."); }
     593        if (!find_home_of_exe("dvd+rw-format")) {
     594            fatal_error
     595                ("Cannot find dvd+rw-format. Please install it or fix your PATH.");
     596        }
    576597#endif
    577       if (!find_home_of_exe("growisofs")) { fatal_error("Cannot find growisofs. Please install it or fix your PATH."); }
    578     }
    579 
    580       if ((res=prepare_filelist (bkpinfo))) /* generate scratchdir/filelist.full */
    581         { fatal_error ("Failed to generate filelist catalog"); }
    582       if (call_filelist_chopper (bkpinfo)) { fatal_error("Failed to run filelist chopper"); }
     598        if (!find_home_of_exe("growisofs")) {
     599            fatal_error
     600                ("Cannot find growisofs. Please install it or fix your PATH.");
     601        }
     602    }
     603
     604    if ((res = prepare_filelist(bkpinfo))) {    /* generate scratchdir/filelist.full */
     605        fatal_error("Failed to generate filelist catalog");
     606    }
     607    if (call_filelist_chopper(bkpinfo)) {
     608        fatal_error("Failed to run filelist chopper");
     609    }
    583610
    584611/*
     
    587614        { fatal_error("Failed to count filelist.full"); }
    588615*/
    589       sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
    590       if (run_program_and_log_output(tmp, 2))
    591         { fatal_error("Failed to gzip filelist.full"); }
    592       sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    593       if (run_program_and_log_output(tmp, 2))
    594         { fatal_error("Failed to copy to tmpdir"); }
    595 
    596       copy_mondo_and_mindi_stuff_to_scratchdir (bkpinfo); // payload, too, if it exists
     616    sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
     617    if (run_program_and_log_output(tmp, 2)) {
     618        fatal_error("Failed to gzip filelist.full");
     619    }
     620    sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
     621            bkpinfo->tmpdir);
     622    if (run_program_and_log_output(tmp, 2)) {
     623        fatal_error("Failed to copy to tmpdir");
     624    }
     625
     626    copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo);  // payload, too, if it exists
    597627#if __FreeBSD__ == 5
    598       strcpy (bkpinfo->kernel_path, "/boot/kernel/kernel");
     628    strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
    599629#elif __FreeBSD__ == 4
    600       strcpy (bkpinfo->kernel_path, "/kernel");
     630    strcpy(bkpinfo->kernel_path, "/kernel");
    601631#elif linux
    602       if (figure_out_kernel_path_interactively_if_necessary(bkpinfo->kernel_path))
    603         { fatal_error ("Kernel not found. Please specify manually with the '-k' switch."); }
     632    if (figure_out_kernel_path_interactively_if_necessary
     633        (bkpinfo->kernel_path)) {
     634        fatal_error
     635            ("Kernel not found. Please specify manually with the '-k' switch.");
     636    }
    604637#else
    605638#error "I don't know about this system!"
    606639#endif
    607       if ((res = call_mindi_to_supply_boot_disks (bkpinfo)))
    608     { fatal_error ("Failed to generate boot+data disks"); }
    609       retval += do_that_initial_phase (bkpinfo); // prepare
    610       sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
    611       run_program_and_log_output(tmp, 1);
    612       retval += make_those_afios_phase (bkpinfo); // backup regular files
    613       retval += make_those_slices_phase (bkpinfo); // backup BIG files
    614       retval += do_that_final_phase (bkpinfo); // clean up
    615       log_msg (1, "Creation of archives... complete.");
    616       if (bkpinfo->verify_data) { sleep(2); }
    617       paranoid_free(tmp);
    618       return(retval);
     640    if ((res = call_mindi_to_supply_boot_disks(bkpinfo))) {
     641        fatal_error("Failed to generate boot+data disks");
     642    }
     643    retval += do_that_initial_phase(bkpinfo);   // prepare
     644    sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
     645    run_program_and_log_output(tmp, 1);
     646    retval += make_those_afios_phase(bkpinfo);  // backup regular files
     647    retval += make_those_slices_phase(bkpinfo); // backup BIG files
     648    retval += do_that_final_phase(bkpinfo); // clean up
     649    log_msg(1, "Creation of archives... complete.");
     650    if (bkpinfo->verify_data) {
     651        sleep(2);
     652    }
     653    paranoid_free(tmp);
     654    return (retval);
    619655}
    620656
     
    648684 * @ingroup MLarchiveGroup
    649685 */
    650 int
    651 call_mindi_to_supply_boot_disks (struct s_bkpinfo *bkpinfo)
     686int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo)
    652687{
    653     /*@ buffer *************************************************************/
    654   char *tmp;
    655         char *scratchdir;
     688    /*@ buffer ************************************************************ */
     689    char *tmp;
     690    char *scratchdir;
    656691    char *command;
    657692    char *use_lzo_sz;
    658         char *use_comp_sz;
     693    char *use_comp_sz;
    659694    char *use_star_sz;
    660695    char *bootldr_str;
     
    665700    char *tape_size_sz;
    666701    char *devs_to_exclude;
    667         char *use_lilo_sz;
    668         char *value;
     702    char *use_lilo_sz;
     703    char *value;
    669704    char *bootdev;
    670705
    671706
    672707
    673     /*@ char ***************************************************************/
     708    /*@ char ************************************************************** */
    674709    char ch = '\0';
    675    
    676     /*@ long     ***********************************************************/
    677   long lines_in_filelist = 0;
    678 
    679     /*@ int     **************************************************************/
    680   int res   = 0;
    681   long estimated_total_noof_slices = 0;
    682 
    683   assert(bkpinfo!=NULL);
    684   command = malloc(1200);
    685 malloc_string ( tmp );
    686 malloc_string ( scratchdir );
    687 malloc_string ( use_lzo_sz );
    688 malloc_string ( use_star_sz );
    689 malloc_string ( use_comp_sz );
    690 malloc_string ( bootldr_str );
    691 malloc_string ( tape_device );
    692 malloc_string ( last_filelist_number );
    693 malloc_string ( broken_bios_sz );
    694 malloc_string ( cd_recovery_sz );
    695 malloc_string ( tape_size_sz );
    696 malloc_string ( devs_to_exclude );
    697 malloc_string ( use_lilo_sz ); /* BCO: shared between LILO/ELILO */
    698 malloc_string ( value );
    699 malloc_string ( bootdev );
    700 
    701   strcpy( scratchdir, bkpinfo->scratchdir);
    702   sprintf (tmp,
    703        "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    704        bkpinfo->exclude_paths);
    705   strcpy (devs_to_exclude, call_program_and_get_last_line_of_output (tmp));
    706   sprintf (tmp, "devs_to_exclude = '%s'", devs_to_exclude);
    707   log_msg (2, tmp);
    708   mvaddstr_and_log_it (g_currentY, 0,
    709                "Calling MINDI to create boot+data disks");
    710   sprintf (tmp, "%s/filelist.full", bkpinfo->tmpdir);
    711   if (!does_file_exist(tmp))
    712     {
    713       sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
    714       if (!does_file_exist(tmp))
    715         { fatal_error("Cannot find filelist.full, so I cannot count its lines"); }
    716     }
    717   lines_in_filelist = count_lines_in_file (tmp);
    718   sprintf (tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
    719   strcpy (last_filelist_number, last_line_of_file (tmp));
    720   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    721     {
    722       sprintf (tape_size_sz, "%ld", bkpinfo->media_size[1]);
    723       strcpy (tape_device, bkpinfo->media_device);
    724     }
    725   else
    726     {
    727       tape_size_sz[0] = '\0';
    728       tape_device[0] = '\0';
    729     }
    730   if (bkpinfo->use_lzo)
    731     {
    732       strcpy (use_lzo_sz, "yes");
    733     }
    734   else
    735     {
    736       strcpy (use_lzo_sz, "no");
    737     }
    738   if (bkpinfo->use_star)
    739     { strcpy( use_star_sz, "yes"); }
    740   else
    741     { strcpy( use_star_sz, "no"); }
    742    
    743   if (bkpinfo->compression_level>0)
    744     {
    745       strcpy (use_comp_sz, "yes");
    746     }
    747   else
    748     {
    749       strcpy (use_comp_sz, "no");
    750     }
    751 
    752   strcpy (broken_bios_sz, "yes");   /* assume so */
    753   if (g_cd_recovery)
    754     {
    755       strcpy (cd_recovery_sz, "yes");
    756     }
    757   else
    758     {
    759       strcpy (cd_recovery_sz, "no");
    760     }
    761   if (bkpinfo->make_cd_use_lilo)
    762     {
    763       strcpy (use_lilo_sz, "yes");
    764     }
    765   else
    766     {
    767       strcpy (use_lilo_sz, "no");
    768     }
    769 
    770   if (!bkpinfo->nonbootable_backup && (bkpinfo->boot_loader == '\0' || bkpinfo->boot_device[0] == '\0'))
    771     {
     710
     711    /*@ long     ********************************************************** */
     712    long lines_in_filelist = 0;
     713
     714    /*@ int     ************************************************************* */
     715    int res = 0;
     716    long estimated_total_noof_slices = 0;
     717
     718    assert(bkpinfo != NULL);
     719    command = malloc(1200);
     720    malloc_string(tmp);
     721    malloc_string(scratchdir);
     722    malloc_string(use_lzo_sz);
     723    malloc_string(use_star_sz);
     724    malloc_string(use_comp_sz);
     725    malloc_string(bootldr_str);
     726    malloc_string(tape_device);
     727    malloc_string(last_filelist_number);
     728    malloc_string(broken_bios_sz);
     729    malloc_string(cd_recovery_sz);
     730    malloc_string(tape_size_sz);
     731    malloc_string(devs_to_exclude);
     732    malloc_string(use_lilo_sz); /* BCO: shared between LILO/ELILO */
     733    malloc_string(value);
     734    malloc_string(bootdev);
     735
     736    strcpy(scratchdir, bkpinfo->scratchdir);
     737    sprintf(tmp,
     738            "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
     739            bkpinfo->exclude_paths);
     740    strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
     741    sprintf(tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     742    log_msg(2, tmp);
     743    mvaddstr_and_log_it(g_currentY, 0,
     744                        "Calling MINDI to create boot+data disks");
     745    sprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
     746    if (!does_file_exist(tmp)) {
     747        sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
     748        if (!does_file_exist(tmp)) {
     749            fatal_error
     750                ("Cannot find filelist.full, so I cannot count its lines");
     751        }
     752    }
     753    lines_in_filelist = count_lines_in_file(tmp);
     754    sprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
     755    strcpy(last_filelist_number, last_line_of_file(tmp));
     756    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     757        sprintf(tape_size_sz, "%ld", bkpinfo->media_size[1]);
     758        strcpy(tape_device, bkpinfo->media_device);
     759    } else {
     760        tape_size_sz[0] = '\0';
     761        tape_device[0] = '\0';
     762    }
     763    if (bkpinfo->use_lzo) {
     764        strcpy(use_lzo_sz, "yes");
     765    } else {
     766        strcpy(use_lzo_sz, "no");
     767    }
     768    if (bkpinfo->use_star) {
     769        strcpy(use_star_sz, "yes");
     770    } else {
     771        strcpy(use_star_sz, "no");
     772    }
     773
     774    if (bkpinfo->compression_level > 0) {
     775        strcpy(use_comp_sz, "yes");
     776    } else {
     777        strcpy(use_comp_sz, "no");
     778    }
     779
     780    strcpy(broken_bios_sz, "yes");  /* assume so */
     781    if (g_cd_recovery) {
     782        strcpy(cd_recovery_sz, "yes");
     783    } else {
     784        strcpy(cd_recovery_sz, "no");
     785    }
     786    if (bkpinfo->make_cd_use_lilo) {
     787        strcpy(use_lilo_sz, "yes");
     788    } else {
     789        strcpy(use_lilo_sz, "no");
     790    }
     791
     792    if (!bkpinfo->nonbootable_backup
     793        && (bkpinfo->boot_loader == '\0'
     794            || bkpinfo->boot_device[0] == '\0')) {
    772795
    773796#ifdef __FreeBSD__
    774     strcpy (bootdev, call_program_and_get_last_line_of_output
    775         ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    776     if (!bootdev[0])
    777       {
    778         strcpy (bootdev, call_program_and_get_last_line_of_output
    779         ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    780       }
     797        strcpy(bootdev, call_program_and_get_last_line_of_output
     798               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     799        if (!bootdev[0]) {
     800            strcpy(bootdev, call_program_and_get_last_line_of_output
     801                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     802        }
    781803#else
    782     strcpy (bootdev, call_program_and_get_last_line_of_output
    783             ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    784     if (strstr(bootdev, "/dev/cciss/")) {
    785          strcpy (bootdev, call_program_and_get_last_line_of_output
    786             ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    787          }
    788     if (!bootdev[0])
    789       {
    790         strcpy (bootdev, call_program_and_get_last_line_of_output
    791             ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    792        if (strstr(bootdev, "/dev/cciss/")) {
    793             strcpy (bootdev, call_program_and_get_last_line_of_output
    794                ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    795             }
    796       }
     804        strcpy(bootdev, call_program_and_get_last_line_of_output
     805               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     806        if (strstr(bootdev, "/dev/cciss/")) {
     807            strcpy(bootdev, call_program_and_get_last_line_of_output
     808                   ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     809        }
     810        if (!bootdev[0]) {
     811            strcpy(bootdev, call_program_and_get_last_line_of_output
     812                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     813            if (strstr(bootdev, "/dev/cciss/")) {
     814                strcpy(bootdev, call_program_and_get_last_line_of_output
     815                       ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     816            }
     817        }
    797818#endif
    798     if (bootdev[0])
    799         ch = which_boot_loader (bootdev);
    800     else
    801         ch = 'U';
    802       if (bkpinfo->boot_loader != '\0')
    803         {
    804           sprintf (tmp, "User specified boot loader. It is '%c'.",
    805                bkpinfo->boot_loader);
    806           log_msg (2, tmp);
    807         }
    808       else
    809         {
    810           bkpinfo->boot_loader = ch;
    811         }
    812       if (bkpinfo->boot_device[0] != '\0')
    813         {
    814           sprintf (tmp, "User specified boot device. It is '%s'.",
    815                bkpinfo->boot_device);
    816           log_msg (2, tmp);
    817         }
    818       else
    819         {
    820           strcpy (bkpinfo->boot_device, bootdev);
    821         }
    822     }
    823 
    824   if (
     819        if (bootdev[0])
     820            ch = which_boot_loader(bootdev);
     821        else
     822            ch = 'U';
     823        if (bkpinfo->boot_loader != '\0') {
     824            sprintf(tmp, "User specified boot loader. It is '%c'.",
     825                    bkpinfo->boot_loader);
     826            log_msg(2, tmp);
     827        } else {
     828            bkpinfo->boot_loader = ch;
     829        }
     830        if (bkpinfo->boot_device[0] != '\0') {
     831            sprintf(tmp, "User specified boot device. It is '%s'.",
     832                    bkpinfo->boot_device);
     833            log_msg(2, tmp);
     834        } else {
     835            strcpy(bkpinfo->boot_device, bootdev);
     836        }
     837    }
     838
     839    if (
    825840#ifdef __FreeBSD__
    826       bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
     841           bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
    827842#endif
    828843#ifdef __IA64__
    829       bkpinfo->boot_loader != 'E' &&
     844           bkpinfo->boot_loader != 'E' &&
    830845#endif
    831       bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G' && bkpinfo->boot_loader != 'R' && !bkpinfo->nonbootable_backup)
    832     {
    833       fatal_error
    834     ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
    835     }
    836   if (bkpinfo->boot_loader == 'L')
    837     {
    838       strcpy (bootldr_str, "LILO");
    839       if (!does_file_exist("/etc/lilo.conf"))
    840         { fatal_error("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?"); }
    841     }
    842   else if (bkpinfo->boot_loader == 'G')
    843     {
    844       strcpy (bootldr_str, "GRUB");
    845       if (!does_file_exist("/etc/grub.conf") && does_file_exist("/boot/grub/grub.conf"))
    846     {
    847       run_program_and_log_output("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
    848     }
    849       /* Detect Debian's grub config file */
    850       else if (!does_file_exist("/etc/grub.conf") && does_file_exist("/boot/grub/menu.lst"))
    851         {
    852           run_program_and_log_output("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
    853         }
    854       if (!does_file_exist("/etc/grub.conf"))
    855     { fatal_error("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'..."); }
    856     }
    857   else if (bkpinfo->boot_loader == 'E')
    858     {
    859       strcpy (bootldr_str, "ELILO");
    860       /* BCO: fix it for SuSE, Debian, Mandrake, ... */
    861       if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/redhat/elilo.conf"))
    862     {
    863       run_program_and_log_output("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", 5);
    864     }
    865       if (!does_file_exist("/etc/elilo.conf"))
    866     { fatal_error("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'"); }
    867     }
    868   else if (bkpinfo->boot_loader == 'R')
    869     {
    870       strcpy (bootldr_str, "RAW");
    871     }
     846           bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G'
     847           && bkpinfo->boot_loader != 'R'
     848           && !bkpinfo->nonbootable_backup) {
     849        fatal_error
     850            ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
     851    }
     852    if (bkpinfo->boot_loader == 'L') {
     853        strcpy(bootldr_str, "LILO");
     854        if (!does_file_exist("/etc/lilo.conf")) {
     855            fatal_error
     856                ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
     857        }
     858    } else if (bkpinfo->boot_loader == 'G') {
     859        strcpy(bootldr_str, "GRUB");
     860        if (!does_file_exist("/etc/grub.conf")
     861            && does_file_exist("/boot/grub/grub.conf")) {
     862            run_program_and_log_output
     863                ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
     864        }
     865        /* Detect Debian's grub config file */
     866        else if (!does_file_exist("/etc/grub.conf")
     867                 && does_file_exist("/boot/grub/menu.lst")) {
     868            run_program_and_log_output
     869                ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
     870        }
     871        if (!does_file_exist("/etc/grub.conf")) {
     872            fatal_error
     873                ("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
     874        }
     875    } else if (bkpinfo->boot_loader == 'E') {
     876        strcpy(bootldr_str, "ELILO");
     877        /* BCO: fix it for SuSE, Debian, Mandrake, ... */
     878        if (!does_file_exist("/etc/elilo.conf")
     879            && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
     880            run_program_and_log_output
     881                ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
     882                 5);
     883        }
     884        if (!does_file_exist("/etc/elilo.conf")) {
     885            fatal_error
     886                ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
     887        }
     888    } else if (bkpinfo->boot_loader == 'R') {
     889        strcpy(bootldr_str, "RAW");
     890    }
    872891#ifdef __FreeBSD__
    873   else if (bkpinfo->boot_loader == 'D')
    874       {
    875       strcpy (bootldr_str, "DD");
    876       }
    877 
    878   else if (bkpinfo->boot_loader == 'B')
    879       {
    880       strcpy (bootldr_str, "BOOT0");
    881       }
     892    else if (bkpinfo->boot_loader == 'D') {
     893        strcpy(bootldr_str, "DD");
     894    }
     895
     896    else if (bkpinfo->boot_loader == 'B') {
     897        strcpy(bootldr_str, "BOOT0");
     898    }
    882899#endif
    883   else
    884     {
    885       strcpy (bootldr_str, "unknown");
    886     }
    887   sprintf (tmp, "Your boot loader is %s and it boots from %s", bootldr_str,
    888        bkpinfo->boot_device);
    889   log_to_screen (tmp);
    890   sprintf (tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
    891   if (write_one_liner_data_file (tmp, bkpinfo->boot_device)) { log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__); }
    892   switch(bkpinfo->backup_media_type)
    893     {
    894       case cdr: strcpy(value, "cdr"); break;
    895       case cdrw: strcpy(value, "cdrw"); break;
    896       case cdstream: strcpy(value, "cdstream"); break;
    897       case tape: strcpy(value, "tape"); break;
    898       case udev: strcpy(value, "udev"); break;
    899       case iso: strcpy(value, "iso"); break;
    900       case nfs: strcpy(value, "nfs"); break;
    901       case dvd: strcpy(value, "dvd"); break;
    902       default: fatal_error("Unknown backup_media_type");
    903     }
    904   sprintf (tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
    905   if (write_one_liner_data_file (tmp, value)) { res++; log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__); }
    906   log_to_screen(bkpinfo->tmpdir);
    907   sprintf (tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
    908   if (write_one_liner_data_file (tmp, bootldr_str)) { res++; log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__); }
    909   sprintf (tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
    910   if (bkpinfo->differential)
    911     {
    912       res+=write_one_liner_data_file (tmp, "1");
    913     }
    914   else
    915     {
    916       res+=write_one_liner_data_file (tmp, "0");
    917     }
    918 
    919   estimated_total_noof_slices =
    920     size_of_all_biggiefiles_K (bkpinfo) / bkpinfo->optimal_set_size + 1;
     900    else {
     901        strcpy(bootldr_str, "unknown");
     902    }
     903    sprintf(tmp, "Your boot loader is %s and it boots from %s",
     904            bootldr_str, bkpinfo->boot_device);
     905    log_to_screen(tmp);
     906    sprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
     907    if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
     908        log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
     909    }
     910    switch (bkpinfo->backup_media_type) {
     911    case cdr:
     912        strcpy(value, "cdr");
     913        break;
     914    case cdrw:
     915        strcpy(value, "cdrw");
     916        break;
     917    case cdstream:
     918        strcpy(value, "cdstream");
     919        break;
     920    case tape:
     921        strcpy(value, "tape");
     922        break;
     923    case udev:
     924        strcpy(value, "udev");
     925        break;
     926    case iso:
     927        strcpy(value, "iso");
     928        break;
     929    case nfs:
     930        strcpy(value, "nfs");
     931        break;
     932    case dvd:
     933        strcpy(value, "dvd");
     934        break;
     935    default:
     936        fatal_error("Unknown backup_media_type");
     937    }
     938    sprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
     939    if (write_one_liner_data_file(tmp, value)) {
     940        res++;
     941        log_msg(1, "%ld: Unable to write one-liner backup-media-type",
     942                __LINE__);
     943    }
     944    log_to_screen(bkpinfo->tmpdir);
     945    sprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
     946    if (write_one_liner_data_file(tmp, bootldr_str)) {
     947        res++;
     948        log_msg(1, "%ld: Unable to write one-liner bootloader.name",
     949                __LINE__);
     950    }
     951    sprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
     952    if (bkpinfo->differential) {
     953        res += write_one_liner_data_file(tmp, "1");
     954    } else {
     955        res += write_one_liner_data_file(tmp, "0");
     956    }
     957
     958    estimated_total_noof_slices =
     959        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    921960/* add nfs stuff here? */
    922   sprintf (command, "mkdir -p %s/images", bkpinfo->scratchdir);
    923   if (system (command)) { res++; log_OS_error("Unable to make images directory"); }
    924   sprintf (command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
    925   if (system (command)) { res++; log_OS_error("Unable to make mnt floppy directory"); }
    926   sprintf (tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    927        bkpinfo->kernel_path);
    928 
    929   log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    930 
    931   sprintf (command,
     961    sprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
     962    if (system(command)) {
     963        res++;
     964        log_OS_error("Unable to make images directory");
     965    }
     966    sprintf(command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
     967    if (system(command)) {
     968        res++;
     969        log_OS_error("Unable to make mnt floppy directory");
     970    }
     971    sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
     972            bkpinfo->kernel_path);
     973
     974    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
     975
     976    sprintf(command,
    932977/*     "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
    9339786=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
    93497911=\"%s\" 12=%s 13=%ld 14=\"%s\" 15=\"%s\" 16=\"%s\" 17=\"%s\" 18=%ld 19=%d",*/
    935        
    936        
    937     "mindi --custom %s %s/images '%s' '%s' \
     980            "mindi --custom %s %s/images '%s' '%s' \
    938981'%s' %ld '%s' '%s' '%s' \
    939 '%s' %s %ld '%s' '%s' '%s' '%s' %ld %d",
    940 
    941        bkpinfo->tmpdir,         // parameter #2
    942        bkpinfo->scratchdir,     // parameter #3
    943        bkpinfo->kernel_path,    // parameter #4
    944        tape_device,         // parameter #5
    945        tape_size_sz,        // parameter #6
    946        lines_in_filelist,       // parameter #7 (INT)
    947        use_lzo_sz,          // parameter #8
    948        cd_recovery_sz,      // parameter #9
    949        bkpinfo->image_devs,     // parameter #10
    950        broken_bios_sz,      // parameter #11
    951        last_filelist_number,    // parameter #12 (STRING)
    952        estimated_total_noof_slices, // parameter #13 (INT)
    953        devs_to_exclude,         // parameter #14
    954        use_comp_sz,         // parameter #15
    955        use_lilo_sz,         // parameter #16
    956        use_star_sz,         // parameter #17
    957        bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
    958        bkpinfo->differential);  // parameter #19 (INT)
    959      
     982'%s' %s %ld '%s' '%s' '%s' '%s' %ld %d", bkpinfo->tmpdir,   // parameter #2
     983            bkpinfo->scratchdir,    // parameter #3
     984            bkpinfo->kernel_path,   // parameter #4
     985            tape_device,        // parameter #5
     986            tape_size_sz,       // parameter #6
     987            lines_in_filelist,  // parameter #7 (INT)
     988            use_lzo_sz,         // parameter #8
     989            cd_recovery_sz,     // parameter #9
     990            bkpinfo->image_devs,    // parameter #10
     991            broken_bios_sz,     // parameter #11
     992            last_filelist_number,   // parameter #12 (STRING)
     993            estimated_total_noof_slices,    // parameter #13 (INT)
     994            devs_to_exclude,    // parameter #14
     995            use_comp_sz,        // parameter #15
     996            use_lilo_sz,        // parameter #16
     997            use_star_sz,        // parameter #17
     998            bkpinfo->internal_tape_block_size,  // parameter #18 (LONG)
     999            bkpinfo->differential); // parameter #19 (INT)
     1000
    9601001// Watch it! This next line adds a parameter...
    961   if (bkpinfo->nonbootable_backup) { strcat(command, " NONBOOTABLE"); }
    962   log_msg (2, command);
     1002    if (bkpinfo->nonbootable_backup) {
     1003        strcat(command, " NONBOOTABLE");
     1004    }
     1005    log_msg(2, command);
    9631006
    9641007//  popup_and_OK("Pausing");
    965  
    966   res = run_program_and_log_to_screen (command, "Generating boot+data disks");
    967   if (bkpinfo->nonbootable_backup) { res=0; } // hack
    968   if (!res)
    969     {
    970       log_to_screen ("Boot+data disks were created OK");
    971       sprintf (command, "mkdir -p /root/images/mindi/");
    972       log_msg (2, command);
    973       run_program_and_log_output (command, FALSE);
    974       sprintf (command, "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
    975            bkpinfo->scratchdir);
    976       log_msg (2, command);
    977       run_program_and_log_output (command, FALSE);
    978       if (bkpinfo->nonbootable_backup)
    979         {
    980           sprintf(command, "cp -f %s/all.tar.gz %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir);
    981           if (system(command)) { fatal_error("Unable to create temporary duff tarball"); }
    982         }
    983       sprintf(command, "cp -f %s/mindi-*oot*.img %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir);
    984       sprintf (tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    985       if (system (tmp)) { fatal_error ("Cannot find all.tar.gz in tmpdir"); }
    986       if (res) { mvaddstr_and_log_it (g_currentY++, 74, "Errors."); }
    987       else {  mvaddstr_and_log_it (g_currentY++, 74, "Done."); }
    988     }
    989   else
    990     {
    991       log_to_screen ("Mindi failed to create your boot+data disks.");
    992       sprintf (command, "grep 'Fatal error' %s", "/var/log/mindi.log");
    993       strcpy (tmp, call_program_and_get_last_line_of_output (command));
    994       if (strlen (tmp) > 1)
    995         {
    996           log_to_screen (tmp);
    997         }
    998     }
    999   paranoid_free(tmp); paranoid_free(use_lzo_sz); paranoid_free(scratchdir);
    1000   paranoid_free(use_comp_sz); paranoid_free(bootldr_str); paranoid_free(tape_device);
    1001   paranoid_free(last_filelist_number); paranoid_free(broken_bios_sz); paranoid_free(cd_recovery_sz);
    1002   paranoid_free(tape_size_sz); paranoid_free(devs_to_exclude); paranoid_free(use_lilo_sz); paranoid_free(value);
    1003   paranoid_free(bootdev); paranoid_free(command); paranoid_free(use_star_sz);
    1004   return (res);
     1008
     1009    res =
     1010        run_program_and_log_to_screen(command,
     1011                                      "Generating boot+data disks");
     1012    if (bkpinfo->nonbootable_backup) {
     1013        res = 0;
     1014    }                           // hack
     1015    if (!res) {
     1016        log_to_screen("Boot+data disks were created OK");
     1017        sprintf(command, "mkdir -p /root/images/mindi/");
     1018        log_msg(2, command);
     1019        run_program_and_log_output(command, FALSE);
     1020        sprintf(command,
     1021                "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
     1022                bkpinfo->scratchdir);
     1023        log_msg(2, command);
     1024        run_program_and_log_output(command, FALSE);
     1025        if (bkpinfo->nonbootable_backup) {
     1026            sprintf(command, "cp -f %s/all.tar.gz %s/images",
     1027                    bkpinfo->tmpdir, bkpinfo->scratchdir);
     1028            if (system(command)) {
     1029                fatal_error("Unable to create temporary duff tarball");
     1030            }
     1031        }
     1032        sprintf(command, "cp -f %s/mindi-*oot*.img %s/images",
     1033                bkpinfo->tmpdir, bkpinfo->scratchdir);
     1034        sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
     1035                bkpinfo->tmpdir);
     1036        if (system(tmp)) {
     1037            fatal_error("Cannot find all.tar.gz in tmpdir");
     1038        }
     1039        if (res) {
     1040            mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1041        } else {
     1042            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1043        }
     1044    } else {
     1045        log_to_screen("Mindi failed to create your boot+data disks.");
     1046        sprintf(command, "grep 'Fatal error' %s", "/var/log/mindi.log");
     1047        strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1048        if (strlen(tmp) > 1) {
     1049            log_to_screen(tmp);
     1050        }
     1051    }
     1052    paranoid_free(tmp);
     1053    paranoid_free(use_lzo_sz);
     1054    paranoid_free(scratchdir);
     1055    paranoid_free(use_comp_sz);
     1056    paranoid_free(bootldr_str);
     1057    paranoid_free(tape_device);
     1058    paranoid_free(last_filelist_number);
     1059    paranoid_free(broken_bios_sz);
     1060    paranoid_free(cd_recovery_sz);
     1061    paranoid_free(tape_size_sz);
     1062    paranoid_free(devs_to_exclude);
     1063    paranoid_free(use_lilo_sz);
     1064    paranoid_free(value);
     1065    paranoid_free(bootdev);
     1066    paranoid_free(command);
     1067    paranoid_free(use_star_sz);
     1068    return (res);
    10051069}
    10061070
     
    10431107 * @ingroup LLarchiveGroup
    10441108 */
    1045 void *create_afio_files_in_background(void*inbuf)
     1109void *create_afio_files_in_background(void *inbuf)
    10461110{
    1047   long int archiving_set_no;
    1048   char *archiving_filelist_fname;
    1049   char * archiving_afioball_fname;
    1050   char *curr_xattr_list_fname;
    1051   char *curr_acl_list_fname;
    1052    
    1053   struct s_bkpinfo*bkpinfo;
    1054   char *tmp;
    1055   int res=0, retval=0;
    1056   int *p_archival_threads_running;
    1057   int *p_last_set_archived;
    1058   int *p_next_set_to_archive;
    1059   char *p_list_of_fileset_flags;
    1060   int this_thread_no = g_current_thread_no++;
    1061 
    1062   malloc_string(curr_xattr_list_fname);
    1063   malloc_string(curr_acl_list_fname);
    1064   malloc_string(archiving_filelist_fname);
    1065   malloc_string(archiving_afioball_fname);
    1066   malloc_string(tmp);
    1067   p_last_set_archived = (int*)inbuf;
    1068   p_archival_threads_running = (int*)(inbuf+4);
    1069   p_next_set_to_archive = (int*)(inbuf+8);
    1070   p_list_of_fileset_flags = (char*)(inbuf+12);
    1071   bkpinfo = (struct s_bkpinfo*)(inbuf+BKPINFO_LOC_OFFSET);
    1072 
    1073   sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
    1074   for (archiving_set_no = 0; does_file_exist (archiving_filelist_fname);
    1075        sprintf (archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1076         archiving_set_no))
    1077     {
    1078       if (g_exiting)
    1079     { fatal_error("Execution run aborted (pthread)"); }
    1080       if (archiving_set_no >= MAX_NOOF_SETS_HERE)
    1081     { fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please."); }
    1082       if (!semaphore_p()) { log_msg(3, "P sem failed (pid=%d)", (int)getpid()); fatal_error("Cannot get semaphore P"); }
    1083       if (archiving_set_no < *p_next_set_to_archive)
    1084     {
    1085       archiving_set_no= *p_next_set_to_archive;
    1086     }
    1087       *p_next_set_to_archive = *p_next_set_to_archive + 1;
    1088       if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1089 
    1090       /* backup this set of files */
    1091       sprintf (archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,bkpinfo->tmpdir,
    1092                archiving_set_no, bkpinfo->zip_suffix);
    1093       sprintf (archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,bkpinfo->tmpdir,
    1094            archiving_set_no);
    1095       if (!does_file_exist(archiving_filelist_fname))
    1096     {
    1097       log_msg (3, "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1098       break;
    1099     }
    1100 
    1101       sprintf (tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no-ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
    1102       if (does_file_exist(tmp))
    1103     {
    1104       log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no);
    1105       while (does_file_exist(tmp))
    1106         {
    1107           sleep(1);
    1108         }
    1109       log_msg(4, "[%d] - continuing", getpid());
    1110     }
    1111    
    1112       log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1113       sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    1114       sprintf (curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    1115       get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
    1116       get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
    1117      
    1118       log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1119       res = archive_this_fileset (bkpinfo, archiving_filelist_fname,
    1120                   archiving_afioball_fname,
    1121                   archiving_set_no);
    1122       retval += res;
    1123 
    1124       if (res)
    1125     {
    1126       sprintf (tmp,
    1127            "Errors occurred while archiving set %ld. Please review logs.",
    1128            archiving_set_no);
    1129       log_to_screen (tmp);
    1130     }
    1131       if (!semaphore_p()) { fatal_error("Cannot get semaphore P"); }
    1132 
    1133       set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
    1134 
    1135       if (*p_last_set_archived < archiving_set_no)
    1136     { *p_last_set_archived = archiving_set_no; } // finished archiving this one
    1137 
    1138       if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1139       log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1140       archiving_set_no ++;
    1141     }
    1142   if (!semaphore_p()) { fatal_error("Cannot get semaphore P"); }
    1143   (*p_archival_threads_running) --;
    1144   if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1145   log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no);
    1146   paranoid_free(archiving_filelist_fname);
    1147   paranoid_free(archiving_afioball_fname);
    1148   paranoid_free(curr_xattr_list_fname);
    1149   paranoid_free(curr_acl_list_fname);
    1150   paranoid_free(tmp);
    1151   pthread_exit(NULL);
     1111    long int archiving_set_no;
     1112    char *archiving_filelist_fname;
     1113    char *archiving_afioball_fname;
     1114    char *curr_xattr_list_fname;
     1115    char *curr_acl_list_fname;
     1116
     1117    struct s_bkpinfo *bkpinfo;
     1118    char *tmp;
     1119    int res = 0, retval = 0;
     1120    int *p_archival_threads_running;
     1121    int *p_last_set_archived;
     1122    int *p_next_set_to_archive;
     1123    char *p_list_of_fileset_flags;
     1124    int this_thread_no = g_current_thread_no++;
     1125
     1126    malloc_string(curr_xattr_list_fname);
     1127    malloc_string(curr_acl_list_fname);
     1128    malloc_string(archiving_filelist_fname);
     1129    malloc_string(archiving_afioball_fname);
     1130    malloc_string(tmp);
     1131    p_last_set_archived = (int *) inbuf;
     1132    p_archival_threads_running = (int *) (inbuf + 4);
     1133    p_next_set_to_archive = (int *) (inbuf + 8);
     1134    p_list_of_fileset_flags = (char *) (inbuf + 12);
     1135    bkpinfo = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
     1136
     1137    sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1138            bkpinfo->tmpdir, 0L);
     1139    for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname);
     1140         sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1141                 bkpinfo->tmpdir, archiving_set_no)) {
     1142        if (g_exiting) {
     1143            fatal_error("Execution run aborted (pthread)");
     1144        }
     1145        if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
     1146            fatal_error
     1147                ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
     1148        }
     1149        if (!semaphore_p()) {
     1150            log_msg(3, "P sem failed (pid=%d)", (int) getpid());
     1151            fatal_error("Cannot get semaphore P");
     1152        }
     1153        if (archiving_set_no < *p_next_set_to_archive) {
     1154            archiving_set_no = *p_next_set_to_archive;
     1155        }
     1156        *p_next_set_to_archive = *p_next_set_to_archive + 1;
     1157        if (!semaphore_v()) {
     1158            fatal_error("Cannot get semaphore V");
     1159        }
     1160
     1161        /* backup this set of files */
     1162        sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1163                bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
     1164        sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1165                bkpinfo->tmpdir, archiving_set_no);
     1166        if (!does_file_exist(archiving_filelist_fname)) {
     1167            log_msg(3,
     1168                    "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
     1169                    FORTY_SPACES, getpid(), this_thread_no,
     1170                    archiving_set_no);
     1171            break;
     1172        }
     1173
     1174        sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
     1175                archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
     1176        if (does_file_exist(tmp)) {
     1177            log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES,
     1178                    getpid(), this_thread_no);
     1179            while (does_file_exist(tmp)) {
     1180                sleep(1);
     1181            }
     1182            log_msg(4, "[%d] - continuing", getpid());
     1183        }
     1184
     1185        log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
     1186                this_thread_no, archiving_set_no);
     1187        sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1188                bkpinfo->tmpdir, archiving_set_no);
     1189        sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1190                bkpinfo->tmpdir, archiving_set_no);
     1191        get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
     1192        get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
     1193
     1194        log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
     1195                this_thread_no, archiving_set_no);
     1196        res =
     1197            archive_this_fileset(bkpinfo, archiving_filelist_fname,
     1198                                 archiving_afioball_fname,
     1199                                 archiving_set_no);
     1200        retval += res;
     1201
     1202        if (res) {
     1203            sprintf(tmp,
     1204                    "Errors occurred while archiving set %ld. Please review logs.",
     1205                    archiving_set_no);
     1206            log_to_screen(tmp);
     1207        }
     1208        if (!semaphore_p()) {
     1209            fatal_error("Cannot get semaphore P");
     1210        }
     1211
     1212        set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
     1213
     1214        if (*p_last_set_archived < archiving_set_no) {
     1215            *p_last_set_archived = archiving_set_no;
     1216        }                       // finished archiving this one
     1217
     1218        if (!semaphore_v()) {
     1219            fatal_error("Cannot get semaphore V");
     1220        }
     1221        log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
     1222                this_thread_no, archiving_set_no);
     1223        archiving_set_no++;
     1224    }
     1225    if (!semaphore_p()) {
     1226        fatal_error("Cannot get semaphore P");
     1227    }
     1228    (*p_archival_threads_running)--;
     1229    if (!semaphore_v()) {
     1230        fatal_error("Cannot get semaphore V");
     1231    }
     1232    log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
     1233            this_thread_no);
     1234    paranoid_free(archiving_filelist_fname);
     1235    paranoid_free(archiving_afioball_fname);
     1236    paranoid_free(curr_xattr_list_fname);
     1237    paranoid_free(curr_acl_list_fname);
     1238    paranoid_free(tmp);
     1239    pthread_exit(NULL);
    11521240}
    11531241
     
    11651253 * @ingroup MLarchiveGroup
    11661254 */
    1167 int
    1168 do_that_final_phase (struct s_bkpinfo *bkpinfo)
     1255int do_that_final_phase(struct s_bkpinfo *bkpinfo)
    11691256{
    11701257
    1171     /*@ int ***************************************/
    1172   int res = 0;
    1173   int retval = 0;
    1174 
    1175     /*@ buffers ***********************************/
    1176 
    1177   assert(bkpinfo!=NULL);
    1178   mvaddstr_and_log_it (g_currentY, 0, "Writing any remaining data to media         ");
    1179 
    1180   log_msg (1, "Closing tape/CD ... ");
    1181   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1182     /* write tape/cdstream */
    1183     {
    1184       closeout_tape(bkpinfo);
    1185     }
    1186   else
    1187     /* write final ISO */
    1188     {
    1189       res = write_final_iso_if_necessary (bkpinfo);
    1190       retval += res;
    1191       if (res)
     1258    /*@ int ************************************** */
     1259    int res = 0;
     1260    int retval = 0;
     1261
     1262    /*@ buffers ********************************** */
     1263
     1264    assert(bkpinfo != NULL);
     1265    mvaddstr_and_log_it(g_currentY, 0,
     1266                        "Writing any remaining data to media         ");
     1267
     1268    log_msg(1, "Closing tape/CD ... ");
     1269    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     1270        /* write tape/cdstream */
    11921271    {
    1193       log_msg (1, "write_final_iso_if_necessary returned an error");
    1194     }
    1195     }
    1196   log_msg (2, "Fork is exiting ... ");
    1197 
    1198   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1199 
    1200   /* final stuff */
    1201   if (retval)
    1202     {
    1203       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    1204     }
    1205   else
    1206     {
    1207       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1208     }
    1209 
    1210   return (retval);
     1272        closeout_tape(bkpinfo);
     1273    } else
     1274        /* write final ISO */
     1275    {
     1276        res = write_final_iso_if_necessary(bkpinfo);
     1277        retval += res;
     1278        if (res) {
     1279            log_msg(1, "write_final_iso_if_necessary returned an error");
     1280        }
     1281    }
     1282    log_msg(2, "Fork is exiting ... ");
     1283
     1284    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1285
     1286    /* final stuff */
     1287    if (retval) {
     1288        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1289    } else {
     1290        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1291    }
     1292
     1293    return (retval);
    12111294}
    12121295
     
    12311314 * @ingroup MLarchiveGroup
    12321315 */
    1233 int
    1234 do_that_initial_phase (struct s_bkpinfo *bkpinfo)
     1316int do_that_initial_phase(struct s_bkpinfo *bkpinfo)
    12351317{
    1236     /*@ int ****************************************/
    1237   int retval = 0;
    1238 
    1239     /*@ buffers ************************************/
    1240   char*command, *tmpfile, *data_disks_file;
    1241    
    1242   assert(bkpinfo!=NULL);
    1243   malloc_string(command);
    1244   malloc_string(tmpfile);
    1245   malloc_string(data_disks_file);
    1246   sprintf (data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
    1247 
    1248   snprintf (g_serial_string, MAX_STR_LEN-1,
    1249         call_program_and_get_last_line_of_output("dd \
     1318    /*@ int *************************************** */
     1319    int retval = 0;
     1320
     1321    /*@ buffers *********************************** */
     1322    char *command, *tmpfile, *data_disks_file;
     1323
     1324    assert(bkpinfo != NULL);
     1325    malloc_string(command);
     1326    malloc_string(tmpfile);
     1327    malloc_string(data_disks_file);
     1328    sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
     1329
     1330    snprintf(g_serial_string, MAX_STR_LEN - 1,
     1331            call_program_and_get_last_line_of_output("dd \
    12501332if=/dev/urandom bs=16 count=1 2> /dev/null | \
    12511333hexdump | tr -s ' ' '0' | head -n1"));
    1252   strip_spaces(g_serial_string);
    1253   strcat(g_serial_string, "...word.");
    1254   log_msg(2, "g_serial_string = '%s'", g_serial_string);
    1255   assert(strlen(g_serial_string) < MAX_STR_LEN);
    1256 
    1257   sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
    1258   if (write_one_liner_data_file (tmpfile, g_serial_string)) { log_msg(1, "%ld: Failed to write serial string", __LINE__); }
    1259 
    1260   mvaddstr_and_log_it (g_currentY, 0, "Preparing to archive your data");
    1261   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1262     {
    1263       if (bkpinfo->backup_media_type == cdstream)
    1264         {
    1265           openout_cdstream (bkpinfo->media_device, bkpinfo->cdrw_speed);
    1266         }
    1267       else
    1268         {
    1269           openout_tape (bkpinfo->media_device, bkpinfo->internal_tape_block_size);  /* sets g_tape_stream */
    1270         }
    1271       if (!g_tape_stream)
    1272     {
    1273       fatal_error ("Cannot open backup (streaming) device");
    1274     }
    1275       log_msg (1, "Backup (stream) opened OK");
    1276       write_data_disks_to_stream (data_disks_file);
    1277     }
    1278   else
    1279     {
    1280       log_msg (1, "Backing up to CD's");
    1281     }
    1282 
    1283   sprintf (command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
    1284                         bkpinfo->nfs_remote_dir, bkpinfo->prefix);
    1285   paranoid_system (command);
    1286   wipe_archives (bkpinfo->scratchdir);
    1287   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1288   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1289     {
    1290       write_header_block_to_stream (0, "start-of-tape", BLK_START_OF_TAPE);
    1291       write_header_block_to_stream (0, "start-of-backup", BLK_START_OF_BACKUP);
    1292     }
    1293   paranoid_free(command);
    1294   paranoid_free(tmpfile);
    1295   paranoid_free(data_disks_file);
    1296   return (retval);
     1334    strip_spaces(g_serial_string);
     1335    strcat(g_serial_string, "...word.");
     1336    log_msg(2, "g_serial_string = '%s'", g_serial_string);
     1337    assert(strlen(g_serial_string) < MAX_STR_LEN);
     1338
     1339    sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
     1340    if (write_one_liner_data_file(tmpfile, g_serial_string)) {
     1341        log_msg(1, "%ld: Failed to write serial string", __LINE__);
     1342    }
     1343
     1344    mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
     1345    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1346        if (bkpinfo->backup_media_type == cdstream) {
     1347            openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
     1348        } else {
     1349            openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
     1350        }
     1351        if (!g_tape_stream) {
     1352            fatal_error("Cannot open backup (streaming) device");
     1353        }
     1354        log_msg(1, "Backup (stream) opened OK");
     1355        write_data_disks_to_stream(data_disks_file);
     1356    } else {
     1357        log_msg(1, "Backing up to CD's");
     1358    }
     1359
     1360    sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
     1361            bkpinfo->nfs_remote_dir, bkpinfo->prefix);
     1362    paranoid_system(command);
     1363    wipe_archives(bkpinfo->scratchdir);
     1364    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1365    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1366        write_header_block_to_stream(0, "start-of-tape",
     1367                                     BLK_START_OF_TAPE);
     1368        write_header_block_to_stream(0, "start-of-backup",
     1369                                     BLK_START_OF_BACKUP);
     1370    }
     1371    paranoid_free(command);
     1372    paranoid_free(tmpfile);
     1373    paranoid_free(data_disks_file);
     1374    return (retval);
    12971375}
    12981376
     
    13081386 * @return The exit code of fdformat/superformat.
    13091387 */
    1310 int
    1311 format_disk_SUB (char *cmd, char *title)
     1388int format_disk_SUB(char *cmd, char *title)
    13121389{
    13131390
    1314     /*@ int ****************************************************************/
    1315   int res = 0;
     1391    /*@ int *************************************************************** */
     1392    int res = 0;
    13161393    int percentage = 0;
    13171394    int maxtracks = 0;
     
    13191396    int last_trkno = 0;
    13201397
    1321     /*@ buffers ************************************************************/
    1322   char *command;
    1323   char *tempfile;
    1324 
    1325     /*@ pointers ***********************************************************/
    1326   FILE *pin;
    1327 
    1328   assert_string_is_neither_NULL_nor_zerolength(cmd);
    1329   assert_string_is_neither_NULL_nor_zerolength(title);
    1330 
    1331   malloc_string(command);
    1332   malloc_string(tempfile);
     1398    /*@ buffers *********************************************************** */
     1399    char *command;
     1400    char *tempfile;
     1401
     1402    /*@ pointers ********************************************************** */
     1403    FILE *pin;
     1404
     1405    assert_string_is_neither_NULL_nor_zerolength(cmd);
     1406    assert_string_is_neither_NULL_nor_zerolength(title);
     1407
     1408    malloc_string(command);
     1409    malloc_string(tempfile);
    13331410#ifdef __FreeBSD__
    13341411/* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
     
    13381415   not done yet.
    13391416*/
    1340     return (run_program_and_log_to_screen (cmd, title));
     1417    return (run_program_and_log_to_screen(cmd, title));
    13411418#endif
    13421419
    13431420/* if Debian then do bog-standard superformat; don't be pretty */
    1344   if (strstr (cmd, "superformat"))
    1345     {
    1346       return (run_program_and_log_to_screen (cmd, title));
    1347     }
     1421    if (strstr(cmd, "superformat")) {
     1422        return (run_program_and_log_to_screen(cmd, title));
     1423    }
    13481424/* if not Debian then go ahead & use fdformat */
    1349   strcpy (tempfile,
    1350       call_program_and_get_last_line_of_output
    1351       ("mktemp -q /tmp/mondo.XXXXXXXX"));
    1352   sprintf (command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    1353        tempfile);
    1354   log_msg (3, command);
    1355   open_evalcall_form (title);
    1356   if (!(pin = popen (command, "r")))
    1357     {
    1358       log_OS_error ("fmt err");
    1359       return (1);
    1360     }
    1361   if (strstr (command, "1722"))
    1362     {
    1363       maxtracks = 82;
    1364     }
    1365   else
    1366     {
    1367       maxtracks = 80;
    1368     }
    1369   for (sleep (1); does_file_exist (tempfile); sleep (1))
    1370     {
    1371       trackno = get_trackno_from_logfile (tempfile);
    1372       if (trackno < 0 || trackno > 80)
    1373     {
    1374       log_msg (1, "Weird track#");
    1375       continue;
    1376     }
    1377       percentage = trackno * 100 / maxtracks;
    1378       if (trackno <= 5 && last_trkno > 40)
    1379     {
    1380       close_evalcall_form ();
    1381       strcpy (title, "Verifying format");
    1382       open_evalcall_form (title);
    1383     }
    1384       last_trkno = trackno;
    1385       update_evalcall_form (percentage);
    1386     }
    1387   close_evalcall_form ();
    1388   if (pclose (pin)) { res++; log_OS_error("Unable to pclose"); }
    1389   unlink (tempfile);
    1390   paranoid_free(command);
    1391   paranoid_free(tempfile);
    1392   return (res);
     1425    strcpy(tempfile,
     1426           call_program_and_get_last_line_of_output
     1427           ("mktemp -q /tmp/mondo.XXXXXXXX"));
     1428    sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     1429            tempfile);
     1430    log_msg(3, command);
     1431    open_evalcall_form(title);
     1432    if (!(pin = popen(command, "r"))) {
     1433        log_OS_error("fmt err");
     1434        return (1);
     1435    }
     1436    if (strstr(command, "1722")) {
     1437        maxtracks = 82;
     1438    } else {
     1439        maxtracks = 80;
     1440    }
     1441    for (sleep(1); does_file_exist(tempfile); sleep(1)) {
     1442        trackno = get_trackno_from_logfile(tempfile);
     1443        if (trackno < 0 || trackno > 80) {
     1444            log_msg(1, "Weird track#");
     1445            continue;
     1446        }
     1447        percentage = trackno * 100 / maxtracks;
     1448        if (trackno <= 5 && last_trkno > 40) {
     1449            close_evalcall_form();
     1450            strcpy(title, "Verifying format");
     1451            open_evalcall_form(title);
     1452        }
     1453        last_trkno = trackno;
     1454        update_evalcall_form(percentage);
     1455    }
     1456    close_evalcall_form();
     1457    if (pclose(pin)) {
     1458        res++;
     1459        log_OS_error("Unable to pclose");
     1460    }
     1461    unlink(tempfile);
     1462    paranoid_free(command);
     1463    paranoid_free(tempfile);
     1464    return (res);
    13931465}
    13941466
     
    14041476 * @ingroup deviceGroup
    14051477 */
    1406 int
    1407 format_disk (char *device)
     1478int format_disk(char *device)
    14081479{
    1409    
    1410     /*@ int ***************************************************************/
    1411   int res = 0;
    1412 
    1413     /*@ buffer ************************************************************/
    1414   char *command;
    1415   char *title;
    1416  
    1417 
    1418   assert_string_is_neither_NULL_nor_zerolength(device);
    1419   malloc_string(title);
    1420   command = malloc(1000);
    1421   if (!system ("which superformat > /dev/null 2> /dev/null"))
    1422     {
    1423       sprintf (command, "superformat %s", device);
    1424     }
    1425   else
    1426     {
     1480
     1481    /*@ int ************************************************************** */
     1482    int res = 0;
     1483
     1484    /*@ buffer *********************************************************** */
     1485    char *command;
     1486    char *title;
     1487
     1488
     1489    assert_string_is_neither_NULL_nor_zerolength(device);
     1490    malloc_string(title);
     1491    command = malloc(1000);
     1492    if (!system("which superformat > /dev/null 2> /dev/null")) {
     1493        sprintf(command, "superformat %s", device);
     1494    } else {
    14271495#ifdef __FreeBSD__
    1428       sprintf (command, "fdformat -y %s", device);
     1496        sprintf(command, "fdformat -y %s", device);
    14291497#else
    1430       sprintf (command, "fdformat %s", device);
     1498        sprintf(command, "fdformat %s", device);
    14311499#endif
    1432     }
    1433   sprintf (title, "Formatting disk %s", device);
    1434   while ((res = format_disk_SUB (command, title)))
    1435     {
    1436       if (!ask_me_yes_or_no ("Failed to format disk. Retry?"))
    1437     {
    1438       return (res);
    1439     }
    1440     }
    1441   paranoid_free(title);
    1442   paranoid_free(command);
    1443   return (res);
     1500    }
     1501    sprintf(title, "Formatting disk %s", device);
     1502    while ((res = format_disk_SUB(command, title))) {
     1503        if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
     1504            return (res);
     1505        }
     1506    }
     1507    paranoid_free(title);
     1508    paranoid_free(command);
     1509    return (res);
    14441510}
    14451511
     
    14521518 * @ingroup utilityGroup
    14531519 */
    1454 bool get_bit_N_of_array(char*array, int N)
     1520bool get_bit_N_of_array(char *array, int N)
    14551521{
    1456   int element_number;
    1457   int bit_number;
    1458   int mask;
    1459  
    1460   element_number = N / 8;
    1461   bit_number = N % 8;
    1462   mask = 1 << bit_number;
    1463   if (array[element_number] & mask)
    1464     { return(TRUE); }
    1465   else
    1466     { return(FALSE); }
     1522    int element_number;
     1523    int bit_number;
     1524    int mask;
     1525
     1526    element_number = N / 8;
     1527    bit_number = N % 8;
     1528    mask = 1 << bit_number;
     1529    if (array[element_number] & mask) {
     1530        return (TRUE);
     1531    } else {
     1532        return (FALSE);
     1533    }
    14671534}
    14681535
     
    14971564 * @return The number of errors encountered (0 for success)
    14981565 */
    1499 int
    1500 make_afioballs_and_images (struct s_bkpinfo *bkpinfo)
     1566int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
    15011567{
    15021568
    1503     /*@ int ***************************************************/
    1504   int retval = 0;
    1505   long int storing_set_no = 0;
    1506   int res = 0;
    1507   bool done_storing=FALSE;
    1508   char *result_str;
    1509   char *transfer_block;
    1510   void*vp;
    1511   void**pvp;
    1512 
    1513     /*@ buffers ***********************************************/
    1514   char *storing_filelist_fname;
    1515   char *storing_afioball_fname;
    1516   char *tmp;
    1517   char *media_usage_comment;
    1518   pthread_t archival_thread[ARCH_THREADS];
    1519   char *p_list_of_fileset_flags;
    1520   int *p_archival_threads_running;
    1521   int *p_last_set_archived;
    1522   int *p_next_set_to_archive;
    1523   int noof_threads;
    1524   int i;
    1525   char *curr_xattr_list_fname;
    1526   char *curr_acl_list_fname;
    1527   int misc_counter_that_is_not_important=0; 
    1528  
    1529   log_msg(8, "here");
    1530   assert(bkpinfo!=NULL);
    1531   tmp = malloc(MAX_STR_LEN*2);
    1532   malloc_string(result_str);
    1533   malloc_string(curr_xattr_list_fname);
    1534   malloc_string(curr_acl_list_fname);
    1535   malloc_string(storing_filelist_fname);
    1536   malloc_string(media_usage_comment);
    1537   malloc_string(storing_afioball_fname);
    1538   transfer_block = malloc(sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1539   memset((void*)transfer_block, 0, sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1540   p_last_set_archived = (int*)transfer_block;
    1541   p_archival_threads_running = (int*)(transfer_block+4);
    1542   p_next_set_to_archive = (int*)(transfer_block+8);
    1543   p_list_of_fileset_flags = (char*)(transfer_block+12);
    1544   memcpy((void*)(transfer_block+BKPINFO_LOC_OFFSET), (void*)bkpinfo, sizeof(struct s_bkpinfo));
    1545   pvp=&vp;
    1546   vp=(void*)result_str;
    1547   *p_archival_threads_running = 0;
    1548   *p_last_set_archived = -1;
    1549   *p_next_set_to_archive = 0;
    1550   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    1551   log_to_screen ("Archiving regular files");
    1552   log_msg (5, "Go, Shorty. It's your birthday.");
    1553   open_progress_form ("Backing up filesystem",
    1554               "I am backing up your live filesystem now.",
    1555               "Please wait. This may take a couple of hours.",
    1556               "Working...", get_last_filelist_number (bkpinfo) + 1);
    1557 
    1558   log_msg (5, "We're gonna party like it's your birthday.");
    1559 
    1560   srand((unsigned int)getpid());
    1561   g_sem_key = 1234+random()%30000;
    1562   if ((g_sem_id = semget((key_t)g_sem_key, 1, IPC_CREAT|S_IREAD|S_IWRITE))==-1)
    1563     { fatal_error("MABAI - unable to semget"); }
    1564   if (!set_semvalue())
    1565     { fatal_error("Unable to init semaphore"); } // initialize semaphore
    1566   for(noof_threads=0; noof_threads<ARCH_THREADS; noof_threads++)
    1567     {
    1568       log_msg(8, "Creating thread #%d", noof_threads);
    1569       (*p_archival_threads_running) ++;
    1570       if ((res = pthread_create(&archival_thread[noof_threads], NULL, create_afio_files_in_background, (void*)transfer_block)))
    1571     { fatal_error("Unable to create an archival thread"); }
    1572     }
    1573 
    1574   log_msg(8, "About to enter while() loop");
    1575   while(!done_storing)
    1576     {
    1577       if (g_exiting) { fatal_error("Execution run aborted (main loop)"); }
    1578       if (*p_archival_threads_running == 0 && *p_last_set_archived == storing_set_no-1)
    1579     {
    1580       log_msg(2, "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)", *p_last_set_archived, storing_set_no);
    1581       done_storing = TRUE;
    1582     }
    1583       else if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no))
    1584     {
    1585       misc_counter_that_is_not_important = (misc_counter_that_is_not_important+1) % 5;
    1586       if (!misc_counter_that_is_not_important)
    1587         { update_progress_form (media_usage_comment); }
    1588       sleep(1);
    1589     }
    1590       else
    1591     // store set N
    1592     {
    1593       sprintf (storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1594            storing_set_no);
    1595       sprintf (storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1596            storing_set_no, bkpinfo->zip_suffix);
    1597           sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1598           sprintf (curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1599 
    1600       log_msg (2, "Storing set %d", storing_set_no);
    1601       while(!does_file_exist(storing_filelist_fname) || !does_file_exist(storing_afioball_fname))
    1602         {
    1603           log_msg (2, "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.", storing_filelist_fname, storing_afioball_fname);
    1604           sleep(5);
    1605         }
    1606       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    1607       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    1608       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1609         {
    1610               register_in_tape_catalog(fileset, storing_set_no, -1, storing_afioball_fname);
    1611           maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname);
    1612           iamhere("Writing EXAT files");
    1613               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
     1569    /*@ int ************************************************** */
     1570    int retval = 0;
     1571    long int storing_set_no = 0;
     1572    int res = 0;
     1573    bool done_storing = FALSE;
     1574    char *result_str;
     1575    char *transfer_block;
     1576    void *vp;
     1577    void **pvp;
     1578
     1579    /*@ buffers ********************************************** */
     1580    char *storing_filelist_fname;
     1581    char *storing_afioball_fname;
     1582    char *tmp;
     1583    char *media_usage_comment;
     1584    pthread_t archival_thread[ARCH_THREADS];
     1585    char *p_list_of_fileset_flags;
     1586    int *p_archival_threads_running;
     1587    int *p_last_set_archived;
     1588    int *p_next_set_to_archive;
     1589    int noof_threads;
     1590    int i;
     1591    char *curr_xattr_list_fname;
     1592    char *curr_acl_list_fname;
     1593    int misc_counter_that_is_not_important = 0;
     1594
     1595    log_msg(8, "here");
     1596    assert(bkpinfo != NULL);
     1597    tmp = malloc(MAX_STR_LEN * 2);
     1598    malloc_string(result_str);
     1599    malloc_string(curr_xattr_list_fname);
     1600    malloc_string(curr_acl_list_fname);
     1601    malloc_string(storing_filelist_fname);
     1602    malloc_string(media_usage_comment);
     1603    malloc_string(storing_afioball_fname);
     1604    transfer_block =
     1605        malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1606    memset((void *) transfer_block, 0,
     1607           sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1608    p_last_set_archived = (int *) transfer_block;
     1609    p_archival_threads_running = (int *) (transfer_block + 4);
     1610    p_next_set_to_archive = (int *) (transfer_block + 8);
     1611    p_list_of_fileset_flags = (char *) (transfer_block + 12);
     1612    memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
     1613           (void *) bkpinfo, sizeof(struct s_bkpinfo));
     1614    pvp = &vp;
     1615    vp = (void *) result_str;
     1616    *p_archival_threads_running = 0;
     1617    *p_last_set_archived = -1;
     1618    *p_next_set_to_archive = 0;
     1619    sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     1620    log_to_screen("Archiving regular files");
     1621    log_msg(5, "Go, Shorty. It's your birthday.");
     1622    open_progress_form("Backing up filesystem",
     1623                       "I am backing up your live filesystem now.",
     1624                       "Please wait. This may take a couple of hours.",
     1625                       "Working...",
     1626                       get_last_filelist_number(bkpinfo) + 1);
     1627
     1628    log_msg(5, "We're gonna party like it's your birthday.");
     1629
     1630    srand((unsigned int) getpid());
     1631    g_sem_key = 1234 + random() % 30000;
     1632    if ((g_sem_id =
     1633         semget((key_t) g_sem_key, 1,
     1634                IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
     1635        fatal_error("MABAI - unable to semget");
     1636    }
     1637    if (!set_semvalue()) {
     1638        fatal_error("Unable to init semaphore");
     1639    }                           // initialize semaphore
     1640    for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
     1641        log_msg(8, "Creating thread #%d", noof_threads);
     1642        (*p_archival_threads_running)++;
     1643        if ((res =
     1644             pthread_create(&archival_thread[noof_threads], NULL,
     1645                            create_afio_files_in_background,
     1646                            (void *) transfer_block))) {
     1647            fatal_error("Unable to create an archival thread");
     1648        }
     1649    }
     1650
     1651    log_msg(8, "About to enter while() loop");
     1652    while (!done_storing) {
     1653        if (g_exiting) {
     1654            fatal_error("Execution run aborted (main loop)");
     1655        }
     1656        if (*p_archival_threads_running == 0
     1657            && *p_last_set_archived == storing_set_no - 1) {
     1658            log_msg(2,
     1659                    "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
     1660                    *p_last_set_archived, storing_set_no);
     1661            done_storing = TRUE;
     1662        } else
     1663            if (!get_bit_N_of_array
     1664                (p_list_of_fileset_flags, storing_set_no)) {
     1665            misc_counter_that_is_not_important =
     1666                (misc_counter_that_is_not_important + 1) % 5;
     1667            if (!misc_counter_that_is_not_important) {
     1668                update_progress_form(media_usage_comment);
     1669            }
     1670            sleep(1);
     1671        } else
     1672            // store set N
     1673        {
     1674            sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1675                    bkpinfo->tmpdir, storing_set_no);
     1676            sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1677                    bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
     1678            sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1679                    bkpinfo->tmpdir, storing_set_no);
     1680            sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1681                    bkpinfo->tmpdir, storing_set_no);
     1682
     1683            log_msg(2, "Storing set %d", storing_set_no);
     1684            while (!does_file_exist(storing_filelist_fname)
     1685                   || !does_file_exist(storing_afioball_fname)) {
     1686                log_msg(2,
     1687                        "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
     1688                        storing_filelist_fname, storing_afioball_fname);
     1689                sleep(5);
     1690            }
     1691            strcpy(media_usage_comment,
     1692                   percent_media_full_comment(bkpinfo));
     1693            /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     1694            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1695                register_in_tape_catalog(fileset, storing_set_no, -1,
     1696                                         storing_afioball_fname);
     1697                maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     1698                                                       storing_afioball_fname);
     1699                iamhere("Writing EXAT files");
     1700                res +=
     1701                    write_EXAT_files_to_tape(bkpinfo,
     1702                                             curr_xattr_list_fname,
     1703                                             curr_acl_list_fname);
    16141704// archives themselves
    1615           res += move_files_to_stream (bkpinfo, storing_afioball_fname, NULL);
    1616         }
    1617       else
    1618         {
    1619           res = move_files_to_cd (bkpinfo, storing_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, storing_afioball_fname, NULL);
    1620         }
    1621       retval += res;
    1622       g_current_progress++;
    1623       update_progress_form (media_usage_comment);
    1624       if (res)
    1625         {
    1626           sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    1627                storing_set_no);
    1628           log_to_screen (tmp);
    1629           fatal_error
    1630         ("Is your hard disk full? If not, please send the author the logfile.");
    1631         }
    1632       storing_set_no++;
    1633       //      sleep(2);
    1634     }
    1635     }
    1636   close_progress_form ();
    1637 
    1638   sprintf (tmp, "Your regular files have been archived ");
    1639   log_msg(2, "Joining background threads to foreground thread");
    1640   for(i=0; i<noof_threads; i++)
    1641     {
    1642       pthread_join(archival_thread[i], pvp);
    1643       log_msg(3, "Thread %d of %d: closed OK", i+1, noof_threads);
    1644     }
    1645   del_semvalue();
    1646   log_msg (2, "Done.");
    1647   if (retval)
    1648     {
    1649       strcat (tmp, "(with errors).");
    1650     }
    1651   else
    1652     {
    1653       strcat (tmp, "successfully.");
    1654     }
    1655   log_to_screen (tmp);
    1656   paranoid_free(transfer_block);
    1657   paranoid_free(result_str);
    1658   paranoid_free(storing_filelist_fname);
    1659   paranoid_free(media_usage_comment);
    1660   paranoid_free(storing_afioball_fname);
    1661   paranoid_free(curr_xattr_list_fname);
    1662   paranoid_free(curr_acl_list_fname);
    1663   return (retval);
     1705                res +=
     1706                    move_files_to_stream(bkpinfo, storing_afioball_fname,
     1707                                         NULL);
     1708            } else {
     1709                res =
     1710                    move_files_to_cd(bkpinfo, storing_filelist_fname,
     1711                                     curr_xattr_list_fname,
     1712                                     curr_acl_list_fname,
     1713                                     storing_afioball_fname, NULL);
     1714            }
     1715            retval += res;
     1716            g_current_progress++;
     1717            update_progress_form(media_usage_comment);
     1718            if (res) {
     1719                sprintf(tmp,
     1720                        "Failed to add archive %ld's files to CD dir\n",
     1721                        storing_set_no);
     1722                log_to_screen(tmp);
     1723                fatal_error
     1724                    ("Is your hard disk full? If not, please send the author the logfile.");
     1725            }
     1726            storing_set_no++;
     1727            //      sleep(2);
     1728        }
     1729    }
     1730    close_progress_form();
     1731
     1732    sprintf(tmp, "Your regular files have been archived ");
     1733    log_msg(2, "Joining background threads to foreground thread");
     1734    for (i = 0; i < noof_threads; i++) {
     1735        pthread_join(archival_thread[i], pvp);
     1736        log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
     1737    }
     1738    del_semvalue();
     1739    log_msg(2, "Done.");
     1740    if (retval) {
     1741        strcat(tmp, "(with errors).");
     1742    } else {
     1743        strcat(tmp, "successfully.");
     1744    }
     1745    log_to_screen(tmp);
     1746    paranoid_free(transfer_block);
     1747    paranoid_free(result_str);
     1748    paranoid_free(storing_filelist_fname);
     1749    paranoid_free(media_usage_comment);
     1750    paranoid_free(storing_afioball_fname);
     1751    paranoid_free(curr_xattr_list_fname);
     1752    paranoid_free(curr_acl_list_fname);
     1753    return (retval);
    16641754}
    16651755
    16661756
    1667 void pause_for_N_seconds(int how_long, char*msg)
     1757void pause_for_N_seconds(int how_long, char *msg)
    16681758{
    1669   int i;
    1670   open_evalcall_form(msg);
    1671   for(i=0; i<how_long; i++)
    1672     {
    1673       update_evalcall_form((int) ( (100.0/(float)(how_long)*i) ) );
    1674       sleep(1);
    1675     }
    1676   close_evalcall_form();
     1759    int i;
     1760    open_evalcall_form(msg);
     1761    for (i = 0; i < how_long; i++) {
     1762        update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
     1763        sleep(1);
     1764    }
     1765    close_evalcall_form();
    16771766}
    16781767
     
    16971786 * @return The number of errors encountered (0 for success)
    16981787 */
    1699 int
    1700 make_iso_fs (struct s_bkpinfo *bkpinfo, char *destfile)
     1788int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
    17011789{
    1702     /*@ int ***********************************************/
    1703   int retval = 0;
    1704   int res;
    1705 
    1706     /*@ buffers *******************************************/
    1707   char *tmp;
    1708   char *old_pwd;
    1709   char *result_sz;
    1710   char *message_to_screen;
    1711   char *sz_blank_disk;
    1712   char *fnam;
    1713   char *tmp2;
    1714   char *tmp3;
    1715   bool cd_is_mountable;
    1716 
    1717   malloc_string(old_pwd);
    1718   malloc_string(result_sz);
    1719   malloc_string(message_to_screen);
    1720   malloc_string(sz_blank_disk);
    1721   malloc_string(fnam);
    1722   tmp = malloc(1200);
    1723   tmp2 =malloc(1200);
    1724   tmp3 =malloc(1200);
    1725   assert(bkpinfo!=NULL);
    1726   assert_string_is_neither_NULL_nor_zerolength(destfile);
    1727 
    1728   sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
    1729   sprintf(tmp2,"%s/isolinux.bin", bkpinfo->tmpdir);
    1730   if (does_file_exist(tmp))
    1731     {
    1732       sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
    1733       paranoid_system(tmp3);
    1734     }
    1735   if (!does_file_exist(tmp) && does_file_exist(tmp2))
    1736     {
    1737       sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
    1738       paranoid_system(tmp3);
    1739     }
    1740   /*
    1741   if (!does_file_exist(tmp))
    1742     {
    1743       log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
    1744       strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
    1745       if (strlen(fnam)>0 && does_file_exist(fnam))
    1746         {
    1747           sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
    1748           res = run_program_and_log_output(tmp, FALSE);
    1749         }
    1750       else
    1751         {
    1752       res = 1;
    1753     }
    1754       if (res)
    1755     {
    1756       log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
    1757     }
    1758     }
    1759   */
    1760   free(tmp2);
    1761   free(tmp3);
    1762   tmp2 = NULL;
    1763   tmp3 = NULL;
    1764   if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray)
    1765     {
    1766       popup_and_OK("Please insert new media and press Enter.");
    1767     }
    1768 
    1769   log_msg (2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
    1770        bkpinfo->scratchdir, destfile);
    1771   (void) getcwd (old_pwd, MAX_STR_LEN - 1);
    1772   sprintf (tmp, "chmod 744 %s", bkpinfo->scratchdir);
    1773   run_program_and_log_output(tmp, FALSE);
    1774   chdir (bkpinfo->scratchdir);
    1775 
    1776   if (bkpinfo->call_before_iso[0] != '\0')
    1777     {
    1778       sprintf (message_to_screen, "Running pre-ISO call for CD#%d",
    1779            g_current_media_number);
    1780       res =
    1781     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_before_iso, destfile,
    1782            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1783       if (res)
    1784     {
    1785       strcat (message_to_screen, "...failed");
    1786     }
    1787       else
    1788     {
    1789       strcat (message_to_screen, "...OK");
    1790     }
    1791       log_to_screen (message_to_screen);
    1792       retval += res;
    1793     }
    1794 
    1795   if (bkpinfo->call_make_iso[0] != '\0')
    1796     {
    1797       log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    1798       sprintf (tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    1799       sprintf (message_to_screen, "Making an ISO (%s #%d)",
    1800                media_descriptor_string(bkpinfo->backup_media_type),
    1801            g_current_media_number);
    1802 
    1803       pause_and_ask_for_cdr (2, &cd_is_mountable);  /* if g_current_media_number >= 2 then pause & ask */
    1804       if (retval)
    1805          {
    1806        log_to_screen("Serious error(s) occurred already. I shan't try to write to media.");
    1807          }
    1808       else
    1809          {
    1810        res =
    1811         eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1812            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1813           if (res)
    1814             {
    1815               log_to_screen ("%s...failed to write", message_to_screen);
    1816            }
    1817           else
    1818             {
    1819               log_to_screen ("%s...OK", message_to_screen);
    1820           if (!run_program_and_log_output("tail -n10 /var/log/mondo-archive.log | fgrep ':-('", 1))
    1821             {
    1822           log_to_screen("Despite nonfatal errors, growisofs confirms the write was successful.");
    1823         }
    1824             }
    1825           retval += res;
     1790    /*@ int ********************************************** */
     1791    int retval = 0;
     1792    int res;
     1793
     1794    /*@ buffers ****************************************** */
     1795    char *tmp;
     1796    char *old_pwd;
     1797    char *result_sz;
     1798    char *message_to_screen;
     1799    char *sz_blank_disk;
     1800    char *fnam;
     1801    char *tmp2;
     1802    char *tmp3;
     1803    bool cd_is_mountable;
     1804
     1805    malloc_string(old_pwd);
     1806    malloc_string(result_sz);
     1807    malloc_string(message_to_screen);
     1808    malloc_string(sz_blank_disk);
     1809    malloc_string(fnam);
     1810    tmp = malloc(1200);
     1811    tmp2 = malloc(1200);
     1812    tmp3 = malloc(1200);
     1813    assert(bkpinfo != NULL);
     1814    assert_string_is_neither_NULL_nor_zerolength(destfile);
     1815
     1816    sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
     1817    sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
     1818    if (does_file_exist(tmp)) {
     1819        sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
     1820        paranoid_system(tmp3);
     1821    }
     1822    if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
     1823        sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
     1824        paranoid_system(tmp3);
     1825    }
     1826    /*
     1827       if (!does_file_exist(tmp))
     1828       {
     1829       log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
     1830       strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
     1831       if (strlen(fnam)>0 && does_file_exist(fnam))
     1832       {
     1833       sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
     1834       res = run_program_and_log_output(tmp, FALSE);
     1835       }
     1836       else
     1837       {
     1838       res = 1;
     1839       }
     1840       if (res)
     1841       {
     1842       log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
     1843       }
     1844       }
     1845     */
     1846    free(tmp2);
     1847    free(tmp3);
     1848    tmp2 = NULL;
     1849    tmp3 = NULL;
     1850    if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
     1851        popup_and_OK("Please insert new media and press Enter.");
     1852    }
     1853
     1854    log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
     1855            bkpinfo->scratchdir, destfile);
     1856    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
     1857    sprintf(tmp, "chmod 744 %s", bkpinfo->scratchdir);
     1858    run_program_and_log_output(tmp, FALSE);
     1859    chdir(bkpinfo->scratchdir);
     1860
     1861    if (bkpinfo->call_before_iso[0] != '\0') {
     1862        sprintf(message_to_screen, "Running pre-ISO call for CD#%d",
     1863                g_current_media_number);
     1864        res =
     1865            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
     1866                                  destfile, g_current_media_number,
     1867                                  MONDO_LOGFILE, message_to_screen);
     1868        if (res) {
     1869            strcat(message_to_screen, "...failed");
     1870        } else {
     1871            strcat(message_to_screen, "...OK");
     1872        }
     1873        log_to_screen(message_to_screen);
     1874        retval += res;
     1875    }
     1876
     1877    if (bkpinfo->call_make_iso[0] != '\0') {
     1878        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
     1879        sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     1880        sprintf(message_to_screen, "Making an ISO (%s #%d)",
     1881                media_descriptor_string(bkpinfo->backup_media_type),
     1882                g_current_media_number);
     1883
     1884        pause_and_ask_for_cdr(2, &cd_is_mountable); /* if g_current_media_number >= 2 then pause & ask */
     1885        if (retval) {
     1886            log_to_screen
     1887                ("Serious error(s) occurred already. I shan't try to write to media.");
     1888        } else {
     1889            res =
     1890                eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1891                                      bkpinfo->scratchdir,
     1892                                      g_current_media_number,
     1893                                      MONDO_LOGFILE, message_to_screen);
     1894            if (res) {
     1895                log_to_screen("%s...failed to write", message_to_screen);
     1896            } else {
     1897                log_to_screen("%s...OK", message_to_screen);
     1898                if (!run_program_and_log_output
     1899                    ("tail -n10 /var/log/mondo-archive.log | fgrep ':-('",
     1900                     1)) {
     1901                    log_to_screen
     1902                        ("Despite nonfatal errors, growisofs confirms the write was successful.");
     1903                }
     1904            }
     1905            retval += res;
    18261906#ifdef DVDRWFORMAT
    1827           sprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE);
    1828       if (g_backup_media_type == dvd && (res || !run_program_and_log_output(tmp, 1)))
    1829             {
    1830           log_to_screen("Failed to write to disk. I shall blank it and then try again.");
    1831           sleep(5);
    1832           system("sync");
    1833               pause_for_N_seconds(5, "Letting DVD drive settle");
     1907            sprintf(tmp,
     1908                    "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
     1909                    MONDO_LOGFILE);
     1910            if (g_backup_media_type == dvd
     1911                && (res || !run_program_and_log_output(tmp, 1))) {
     1912                log_to_screen
     1913                    ("Failed to write to disk. I shall blank it and then try again.");
     1914                sleep(5);
     1915                system("sync");
     1916                pause_for_N_seconds(5, "Letting DVD drive settle");
    18341917
    18351918// dvd+rw-format --- OPTION 2
    1836           if (!bkpinfo->please_dont_eject)
    1837         {
    1838           log_to_screen("Ejecting media to clear drive status.");
    1839           eject_device(bkpinfo->media_device);
    1840           inject_device(bkpinfo->media_device);
    1841         }
    1842               pause_for_N_seconds(5, "Letting DVD drive settle");
    1843           sprintf(sz_blank_disk, "dvd+rw-format %s", bkpinfo->media_device);
    1844           log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
    1845               res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1846           if (res)
    1847             {
    1848           log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
    1849                   pause_for_N_seconds(5, "Letting DVD drive settle... and trying again.");
    1850                   res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1851                   if (res) { log_to_screen("Format failed a second time."); }
    1852         }
    1853           else { log_to_screen("Format succeeded. Sleeping for 5 seconds to take a breath..."); }
    1854               pause_for_N_seconds(5, "Letting DVD drive settle");
    1855           if (!bkpinfo->please_dont_eject)
    1856         {
    1857           log_to_screen("Ejecting media to clear drive status.");
    1858           eject_device(bkpinfo->media_device);
    1859           inject_device(bkpinfo->media_device);
    1860         }
    1861               pause_for_N_seconds(5, "Letting DVD drive settle");
    1862           res = eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1863            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1864           retval += res;
    1865           if (!bkpinfo->please_dont_eject)
    1866         {
    1867           log_to_screen("Ejecting media.");
    1868           eject_device(bkpinfo->media_device);
    1869         }
    1870           if (res)
    1871             { log_to_screen("Dagnabbit. It still failed."); }
    1872           else
    1873             { log_to_screen("OK, this time I successfully backed up to DVD."); }
    1874         }
     1919                if (!bkpinfo->please_dont_eject) {
     1920                    log_to_screen("Ejecting media to clear drive status.");
     1921                    eject_device(bkpinfo->media_device);
     1922                    inject_device(bkpinfo->media_device);
     1923                }
     1924                pause_for_N_seconds(5, "Letting DVD drive settle");
     1925                sprintf(sz_blank_disk, "dvd+rw-format %s",
     1926                        bkpinfo->media_device);
     1927                log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
     1928                res =
     1929                    run_external_binary_with_percentage_indicator_NEW
     1930                    ("Blanking DVD disk", sz_blank_disk);
     1931                if (res) {
     1932                    log_to_screen
     1933                        ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
     1934                    pause_for_N_seconds(5,
     1935                                        "Letting DVD drive settle... and trying again.");
     1936                    res =
     1937                        run_external_binary_with_percentage_indicator_NEW
     1938                        ("Blanking DVD disk", sz_blank_disk);
     1939                    if (res) {
     1940                        log_to_screen("Format failed a second time.");
     1941                    }
     1942                } else {
     1943                    log_to_screen
     1944                        ("Format succeeded. Sleeping for 5 seconds to take a breath...");
     1945                }
     1946                pause_for_N_seconds(5, "Letting DVD drive settle");
     1947                if (!bkpinfo->please_dont_eject) {
     1948                    log_to_screen("Ejecting media to clear drive status.");
     1949                    eject_device(bkpinfo->media_device);
     1950                    inject_device(bkpinfo->media_device);
     1951                }
     1952                pause_for_N_seconds(5, "Letting DVD drive settle");
     1953                res =
     1954                    eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1955                                          bkpinfo->scratchdir,
     1956                                          g_current_media_number,
     1957                                          MONDO_LOGFILE,
     1958                                          message_to_screen);
     1959                retval += res;
     1960                if (!bkpinfo->please_dont_eject) {
     1961                    log_to_screen("Ejecting media.");
     1962                    eject_device(bkpinfo->media_device);
     1963                }
     1964                if (res) {
     1965                    log_to_screen("Dagnabbit. It still failed.");
     1966                } else {
     1967                    log_to_screen
     1968                        ("OK, this time I successfully backed up to DVD.");
     1969                }
     1970            }
    18751971#endif
    1876       if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject)
    1877         { eject_device(bkpinfo->media_device); }
    1878      }
    1879     }
    1880   else
    1881     {
    1882       sprintf (message_to_screen, "Running mkisofs to make %s #%d",
    1883            media_descriptor_string(bkpinfo->backup_media_type),
    1884            g_current_media_number);
    1885       log_msg (1, message_to_screen);
    1886       sprintf (result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    1887             media_descriptor_string(bkpinfo->backup_media_type),
    1888             g_current_media_number);
    1889       if (bkpinfo->nonbootable_backup)
    1890         {
    1891           log_msg (1, "Making nonbootable backup");
     1972            if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
     1973                eject_device(bkpinfo->media_device);
     1974            }
     1975        }
     1976    } else {
     1977        sprintf(message_to_screen, "Running mkisofs to make %s #%d",
     1978                media_descriptor_string(bkpinfo->backup_media_type),
     1979                g_current_media_number);
     1980        log_msg(1, message_to_screen);
     1981        sprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ",
     1982                media_descriptor_string(bkpinfo->backup_media_type),
     1983                g_current_media_number);
     1984        if (bkpinfo->nonbootable_backup) {
     1985            log_msg(1, "Making nonbootable backup");
    18921986// FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
    1893           res =
    1894         eval_call_to_make_ISO (bkpinfo,
    1895            "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1896            destfile, g_current_media_number, MONDO_LOGFILE,
    1897            message_to_screen);
    1898         }
    1899       else
    1900         {
    1901           log_msg (1, "Making bootable backup");
     1987            res =
     1988                eval_call_to_make_ISO(bkpinfo,
     1989                                      "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1990                                      destfile, g_current_media_number,
     1991                                      MONDO_LOGFILE, message_to_screen);
     1992        } else {
     1993            log_msg(1, "Making bootable backup");
    19021994
    19031995#ifdef __FreeBSD__
    1904           bkpinfo->make_cd_use_lilo = TRUE;
     1996            bkpinfo->make_cd_use_lilo = TRUE;
    19051997#endif
    19061998
    19071999
    1908           log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo);
    1909           if (bkpinfo->make_cd_use_lilo)
    1910             {
    1911               log_msg(1, "make_cd_use_lilo = TRUE");
     2000            log_msg(1, "make_cd_use_lilo is actually %d",
     2001                    bkpinfo->make_cd_use_lilo);
     2002            if (bkpinfo->make_cd_use_lilo) {
     2003                log_msg(1, "make_cd_use_lilo = TRUE");
    19122004// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19132005// and add ' .' at end
    19142006#ifdef __IA64__
    1915               log_msg(1, "IA64 --> elilo");
    1916               res =
    1917                 eval_call_to_make_ISO (bkpinfo,
    1918                     //-b images/mindi-boot.2880.img
    1919             "mkisofs -no-emul-boot -b images/mindi-bootroot."IA64_BOOT_SIZE".img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1920                     destfile, g_current_media_number, MONDO_LOGFILE,
    1921                     message_to_screen);
     2007                log_msg(1, "IA64 --> elilo");
     2008                res = eval_call_to_make_ISO(bkpinfo,
     2009                                            //-b images/mindi-boot.2880.img
     2010                                            "mkisofs -no-emul-boot -b images/mindi-bootroot."
     2011                                            IA64_BOOT_SIZE
     2012                                            ".img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2013                                            destfile,
     2014                                            g_current_media_number,
     2015                                            MONDO_LOGFILE,
     2016                                            message_to_screen);
    19222017#else
    19232018// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19242019// and add ' .' at end
    1925           log_msg(1, "Non-ia64 --> lilo");
    1926               res =
    1927                 eval_call_to_make_ISO (bkpinfo,
    1928                     "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1929                     destfile, g_current_media_number, MONDO_LOGFILE,
    1930                     message_to_screen);
     2020                log_msg(1, "Non-ia64 --> lilo");
     2021                res =
     2022                    eval_call_to_make_ISO(bkpinfo,
     2023                                          "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2024                                          destfile, g_current_media_number,
     2025                                          MONDO_LOGFILE,
     2026                                          message_to_screen);
    19312027#endif
    1932             }
    1933           else
    1934             {
    1935               log_msg(1, "make_cd_use_lilo = FALSE");
    1936           log_msg(1, "Isolinux");
    1937               res =
    1938             eval_call_to_make_ISO (bkpinfo,
    1939                    "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1940            destfile, g_current_media_number, MONDO_LOGFILE,
    1941            message_to_screen);
    1942             }
    1943         }
    1944       if (res)
    1945     {
    1946       strcat (result_sz, "...failed");
    1947     }
    1948       else
    1949     {
    1950       strcat (result_sz, "...OK");
    1951     }
    1952       log_to_screen (result_sz);
    1953       retval += res;
    1954     }
    1955 
    1956   if (bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw)
    1957     {
    1958       if (is_this_device_mounted(bkpinfo->media_device))
    1959         {
    1960           log_msg (2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device);
    1961           sprintf(tmp, "umount %s", bkpinfo->media_device);
    1962           run_program_and_log_output(tmp, FALSE);
    1963         }
    1964     }
    1965 
    1966   if (bkpinfo->call_burn_iso[0] != '\0')
    1967     {
    1968       log_msg (2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    1969       sprintf (message_to_screen, "Burning %s #%d",
    1970             media_descriptor_string(bkpinfo->backup_media_type),
    1971            g_current_media_number);
    1972       pause_and_ask_for_cdr (2, &cd_is_mountable);
    1973       res =
    1974     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_burn_iso, destfile,
    1975            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1976       if (res)
    1977     {
    1978       strcat (message_to_screen, "...failed");
    1979     }
    1980       else
    1981     {
    1982       strcat (message_to_screen, "...OK");
    1983     }
    1984       log_to_screen (message_to_screen);
    1985       retval += res;
    1986     }
    1987 
    1988   if (bkpinfo->call_after_iso[0] != '\0')
    1989     {
    1990       sprintf (message_to_screen, "Running post-ISO call (%s #%d)",
    1991             media_descriptor_string(bkpinfo->backup_media_type),
    1992            g_current_media_number);
    1993       res =
    1994     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_after_iso, destfile,
    1995            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1996       if (res)
    1997     {
    1998       strcat (message_to_screen, "...failed");
    1999     }
    2000       else
    2001     {
    2002       strcat (message_to_screen, "...OK");
    2003     }
    2004       log_to_screen (message_to_screen);
    2005       retval += res;
    2006     }
    2007 
    2008   chdir (old_pwd);
    2009   if (retval)
    2010     {
    2011       log_msg (1, "WARNING - make_iso_fs returned an error");
    2012     }
    2013   paranoid_free(old_pwd);
    2014   paranoid_free(result_sz);
    2015   paranoid_free(message_to_screen);
    2016   paranoid_free(sz_blank_disk);
    2017   paranoid_free(fnam);
    2018   paranoid_free(tmp);
    2019   return (retval);
     2028            } else {
     2029                log_msg(1, "make_cd_use_lilo = FALSE");
     2030                log_msg(1, "Isolinux");
     2031                res =
     2032                    eval_call_to_make_ISO(bkpinfo,
     2033                                          "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2034                                          destfile, g_current_media_number,
     2035                                          MONDO_LOGFILE,
     2036                                          message_to_screen);
     2037            }
     2038        }
     2039        if (res) {
     2040            strcat(result_sz, "...failed");
     2041        } else {
     2042            strcat(result_sz, "...OK");
     2043        }
     2044        log_to_screen(result_sz);
     2045        retval += res;
     2046    }
     2047
     2048    if (bkpinfo->backup_media_type == cdr
     2049        || bkpinfo->backup_media_type == cdrw) {
     2050        if (is_this_device_mounted(bkpinfo->media_device)) {
     2051            log_msg(2,
     2052                    "Warning - %s mounted. I'm unmounting it before I burn to it.",
     2053                    bkpinfo->media_device);
     2054            sprintf(tmp, "umount %s", bkpinfo->media_device);
     2055            run_program_and_log_output(tmp, FALSE);
     2056        }
     2057    }
     2058
     2059    if (bkpinfo->call_burn_iso[0] != '\0') {
     2060        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
     2061        sprintf(message_to_screen, "Burning %s #%d",
     2062                media_descriptor_string(bkpinfo->backup_media_type),
     2063                g_current_media_number);
     2064        pause_and_ask_for_cdr(2, &cd_is_mountable);
     2065        res =
     2066            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
     2067                                  destfile, g_current_media_number,
     2068                                  MONDO_LOGFILE, message_to_screen);
     2069        if (res) {
     2070            strcat(message_to_screen, "...failed");
     2071        } else {
     2072            strcat(message_to_screen, "...OK");
     2073        }
     2074        log_to_screen(message_to_screen);
     2075        retval += res;
     2076    }
     2077
     2078    if (bkpinfo->call_after_iso[0] != '\0') {
     2079        sprintf(message_to_screen, "Running post-ISO call (%s #%d)",
     2080                media_descriptor_string(bkpinfo->backup_media_type),
     2081                g_current_media_number);
     2082        res =
     2083            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
     2084                                  destfile, g_current_media_number,
     2085                                  MONDO_LOGFILE, message_to_screen);
     2086        if (res) {
     2087            strcat(message_to_screen, "...failed");
     2088        } else {
     2089            strcat(message_to_screen, "...OK");
     2090        }
     2091        log_to_screen(message_to_screen);
     2092        retval += res;
     2093    }
     2094
     2095    chdir(old_pwd);
     2096    if (retval) {
     2097        log_msg(1, "WARNING - make_iso_fs returned an error");
     2098    }
     2099    paranoid_free(old_pwd);
     2100    paranoid_free(result_sz);
     2101    paranoid_free(message_to_screen);
     2102    paranoid_free(sz_blank_disk);
     2103    paranoid_free(fnam);
     2104    paranoid_free(tmp);
     2105    return (retval);
    20202106}
    20212107
     
    20302116bool is_dev_an_NTFS_dev(char *bigfile_fname)
    20312117{
    2032   char *tmp;
    2033   char *command;
    2034   malloc_string(tmp);
    2035   malloc_string(command);
    2036   sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", bigfile_fname);
    2037   log_msg(1, "command = '%s'", command);
    2038   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2039   log_msg(1, "--> tmp = '%s'", tmp);
    2040   if (strstr(tmp, "NTFS"))
    2041     { iamhere("TRUE"); return(TRUE); }
    2042   else
    2043     { iamhere("FALSE"); return(FALSE); }
     2118    char *tmp;
     2119    char *command;
     2120    malloc_string(tmp);
     2121    malloc_string(command);
     2122    sprintf(command,
     2123            "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
     2124            bigfile_fname);
     2125    log_msg(1, "command = '%s'", command);
     2126    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2127    log_msg(1, "--> tmp = '%s'", tmp);
     2128    if (strstr(tmp, "NTFS")) {
     2129        iamhere("TRUE");
     2130        return (TRUE);
     2131    } else {
     2132        iamhere("FALSE");
     2133        return (FALSE);
     2134    }
    20442135}
    20452136
     
    20602151 */
    20612152int
    2062 make_slices_and_images (struct s_bkpinfo *bkpinfo, char *biggielist_fname)
     2153make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
    20632154{
    20642155
    2065     /*@ pointers ********************************************/
    2066   FILE *fin;
    2067   char *p;
    2068 
    2069     /*@ buffers *********************************************/
    2070   char *tmp;
    2071   char *bigfile_fname;
    2072   char *sz_devfile;
    2073   char *partimagehack_fifo = NULL;
    2074     /*@ long ************************************************/
    2075   long biggie_file_number = 0;
    2076   long noof_biggie_files = 0;
    2077   long estimated_total_noof_slices = 0;
    2078 
    2079     /*@ int *************************************************/
    2080   int retval = 0;
    2081   int res = 0;
    2082   pid_t pid;
    2083   FILE*ftmp=NULL;
    2084   bool delete_when_done; 
    2085   bool use_partimagehack;
    2086     /*@ long long *******************************************/
    2087   long long biggie_fsize;
    2088 
    2089   assert(bkpinfo!=NULL);
    2090   assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
    2091 
    2092   malloc_string(tmp);
    2093   malloc_string(bigfile_fname);
    2094   malloc_string(sz_devfile);
    2095   estimated_total_noof_slices =
    2096     size_of_all_biggiefiles_K (bkpinfo) / bkpinfo->optimal_set_size + 1;
    2097 
    2098   log_msg (1, "size of all biggiefiles = %ld",
    2099        size_of_all_biggiefiles_K (bkpinfo));
    2100   log_msg (1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
    2101        size_of_all_biggiefiles_K (bkpinfo), bkpinfo->optimal_set_size,
    2102        estimated_total_noof_slices);
    2103 
    2104   if (length_of_file (biggielist_fname) < 6)
    2105     {
    2106       log_msg (1, "No biggiefiles; fair enough...");
    2107       return (0);
    2108     }
    2109   sprintf (tmp, "I am now backing up all large files.");
    2110   log_to_screen (tmp);
    2111   noof_biggie_files = count_lines_in_file (biggielist_fname);
    2112   open_progress_form ("Backing up big files", tmp,
    2113               "Please wait. This may take some time.", "",
    2114               estimated_total_noof_slices);
    2115   if (!(fin = fopen (biggielist_fname, "r"))) { log_OS_error("Unable to openin biggielist"); return(1); }
    2116   for (fgets (bigfile_fname, MAX_STR_LEN, fin); !feof (fin);
    2117        fgets (bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++)
    2118     {
    2119       use_partimagehack = FALSE;
    2120       if (bigfile_fname[strlen (bigfile_fname) - 1] < 32)
    2121     {
    2122       bigfile_fname[strlen (bigfile_fname) - 1] = '\0';
    2123     }
    2124       biggie_fsize = length_of_file (bigfile_fname);
    2125       delete_when_done = FALSE;
    2126      
    2127       if (!does_file_exist (bigfile_fname))
    2128     {
    2129           ftmp = fopen(bigfile_fname, "w");
    2130       paranoid_fclose(ftmp);
    2131       sprintf (tmp, "bigfile %s was deleted - creating a dummy", bigfile_fname);
    2132       delete_when_done = TRUE;
    2133     }
    2134       else
    2135         {
     2156    /*@ pointers ******************************************* */
     2157    FILE *fin;
     2158    char *p;
     2159
     2160    /*@ buffers ******************************************** */
     2161    char *tmp;
     2162    char *bigfile_fname;
     2163    char *sz_devfile;
     2164    char *partimagehack_fifo = NULL;
     2165    /*@ long *********************************************** */
     2166    long biggie_file_number = 0;
     2167    long noof_biggie_files = 0;
     2168    long estimated_total_noof_slices = 0;
     2169
     2170    /*@ int ************************************************ */
     2171    int retval = 0;
     2172    int res = 0;
     2173    pid_t pid;
     2174    FILE *ftmp = NULL;
     2175    bool delete_when_done;
     2176    bool use_partimagehack;
     2177    /*@ long long ****************************************** */
     2178    long long biggie_fsize;
     2179
     2180    assert(bkpinfo != NULL);
     2181    assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
     2182
     2183    malloc_string(tmp);
     2184    malloc_string(bigfile_fname);
     2185    malloc_string(sz_devfile);
     2186    estimated_total_noof_slices =
     2187        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
     2188
     2189    log_msg(1, "size of all biggiefiles = %ld",
     2190            size_of_all_biggiefiles_K(bkpinfo));
     2191    log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
     2192            size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
     2193            estimated_total_noof_slices);
     2194
     2195    if (length_of_file(biggielist_fname) < 6) {
     2196        log_msg(1, "No biggiefiles; fair enough...");
     2197        return (0);
     2198    }
     2199    sprintf(tmp, "I am now backing up all large files.");
     2200    log_to_screen(tmp);
     2201    noof_biggie_files = count_lines_in_file(biggielist_fname);
     2202    open_progress_form("Backing up big files", tmp,
     2203                       "Please wait. This may take some time.", "",
     2204                       estimated_total_noof_slices);
     2205    if (!(fin = fopen(biggielist_fname, "r"))) {
     2206        log_OS_error("Unable to openin biggielist");
     2207        return (1);
     2208    }
     2209    for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
     2210         fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
     2211        use_partimagehack = FALSE;
     2212        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
     2213            bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
     2214        }
     2215        biggie_fsize = length_of_file(bigfile_fname);
     2216        delete_when_done = FALSE;
     2217
     2218        if (!does_file_exist(bigfile_fname)) {
     2219            ftmp = fopen(bigfile_fname, "w");
     2220            paranoid_fclose(ftmp);
     2221            sprintf(tmp, "bigfile %s was deleted - creating a dummy",
     2222                    bigfile_fname);
     2223            delete_when_done = TRUE;
     2224        } else {
    21362225// Call partimagehack if it's a /dev entry (i.e. a partition to be imaged)
    2137           log_msg (2, "bigfile_fname = %s", bigfile_fname);
    2138       use_partimagehack = FALSE;
    2139       if (!strncmp ( bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname))
    2140             {
    2141           use_partimagehack = TRUE;
    2142           log_msg (2, "Calling partimagehack in background because %s is an NTFS partition", bigfile_fname);
    2143               sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    2144           mkfifo(sz_devfile, 0x770);
    2145           partimagehack_fifo = sz_devfile;
    2146               switch(pid=fork())
    2147                 {
    2148                   case -1: fatal_error("Fork failure");
    2149               case 0:
    2150             log_msg (2, "CHILD - fip - calling feed_into_partimage(%s, %s)", bigfile_fname, sz_devfile);
    2151             res=feed_into_partimage(bigfile_fname, sz_devfile);
    2152             exit(res);
    2153             break;
    2154                   default:
    2155             log_msg (2, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    2156                 }
    2157         }
     2226            log_msg(2, "bigfile_fname = %s", bigfile_fname);
     2227            use_partimagehack = FALSE;
     2228            if (!strncmp(bigfile_fname, "/dev/", 5)
     2229                && is_dev_an_NTFS_dev(bigfile_fname)) {
     2230                use_partimagehack = TRUE;
     2231                log_msg(2,
     2232                        "Calling partimagehack in background because %s is an NTFS partition",
     2233                        bigfile_fname);
     2234                sprintf(sz_devfile, "/tmp/%d.%d.000",
     2235                        (int) (random() % 32768),
     2236                        (int) (random() % 32768));
     2237                mkfifo(sz_devfile, 0x770);
     2238                partimagehack_fifo = sz_devfile;
     2239                switch (pid = fork()) {
     2240                case -1:
     2241                    fatal_error("Fork failure");
     2242                case 0:
     2243                    log_msg(2,
     2244                            "CHILD - fip - calling feed_into_partimage(%s, %s)",
     2245                            bigfile_fname, sz_devfile);
     2246                    res = feed_into_partimage(bigfile_fname, sz_devfile);
     2247                    exit(res);
     2248                    break;
     2249                default:
     2250                    log_msg(2,
     2251                            "feed_into_partimage() called in background --- pid=%ld",
     2252                            (long int) (pid));
     2253                }
     2254            }
    21582255// Otherwise, use good old 'dd' and 'bzip2'
    2159           else
    2160         {
    2161           sz_devfile[0] = '\0';
    2162           partimagehack_fifo = NULL;
    2163         }
     2256            else {
     2257                sz_devfile[0] = '\0';
     2258                partimagehack_fifo = NULL;
     2259            }
    21642260
    21652261// Whether partition or biggiefile, just do your thang :-)
    2166       sprintf (tmp, "Bigfile #%ld is '%s' (%ld KB)", biggie_file_number+1,
    2167            bigfile_fname, (long) biggie_fsize >> 10);
    2168           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2169         {
    2170           write_header_block_to_stream (biggie_fsize, bigfile_fname,
    2171                       use_partimagehack?BLK_START_A_PIHBIGGIE:BLK_START_A_NORMBIGGIE);
    2172         }
    2173       res =
    2174         slice_up_file_etc (bkpinfo, bigfile_fname, partimagehack_fifo,
    2175             biggie_file_number, noof_biggie_files, use_partimagehack);
    2176           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2177         {
    2178           write_header_block_to_stream (0,
    2179                       calc_checksum_of_file
    2180                       (bigfile_fname), BLK_STOP_A_BIGGIE);
    2181         }
    2182       retval += res;
    2183       p = strrchr (bigfile_fname, '/');
    2184       if (p)
    2185         {
    2186           p++;
    2187         }
    2188       else
    2189         {
    2190           p = bigfile_fname;
    2191         }
    2192       sprintf (tmp, "Archiving %s ... ", bigfile_fname);
    2193       if (res)
    2194         {
    2195           strcat (tmp, "Failed!");
    2196         }
    2197       else
    2198         {
    2199           strcat (tmp, "OK");
    2200         }
    2201       if (delete_when_done)
    2202         { unlink(bigfile_fname); delete_when_done=FALSE; }
    2203     }
     2262            sprintf(tmp, "Bigfile #%ld is '%s' (%ld KB)",
     2263                    biggie_file_number + 1, bigfile_fname,
     2264                    (long) biggie_fsize >> 10);
     2265            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2266                write_header_block_to_stream(biggie_fsize, bigfile_fname,
     2267                                             use_partimagehack ?
     2268                                             BLK_START_A_PIHBIGGIE :
     2269                                             BLK_START_A_NORMBIGGIE);
     2270            }
     2271            res =
     2272                slice_up_file_etc(bkpinfo, bigfile_fname,
     2273                                  partimagehack_fifo, biggie_file_number,
     2274                                  noof_biggie_files, use_partimagehack);
     2275            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2276                write_header_block_to_stream(0,
     2277                                             calc_checksum_of_file
     2278                                             (bigfile_fname),
     2279                                             BLK_STOP_A_BIGGIE);
     2280            }
     2281            retval += res;
     2282            p = strrchr(bigfile_fname, '/');
     2283            if (p) {
     2284                p++;
     2285            } else {
     2286                p = bigfile_fname;
     2287            }
     2288            sprintf(tmp, "Archiving %s ... ", bigfile_fname);
     2289            if (res) {
     2290                strcat(tmp, "Failed!");
     2291            } else {
     2292                strcat(tmp, "OK");
     2293            }
     2294            if (delete_when_done) {
     2295                unlink(bigfile_fname);
     2296                delete_when_done = FALSE;
     2297            }
     2298        }
    22042299#ifndef _XWIN
    2205       if (!g_text_mode) { newtDrawRootText (0, g_noof_rows - 2, tmp); newtRefresh (); }
     2300        if (!g_text_mode) {
     2301            newtDrawRootText(0, g_noof_rows - 2, tmp);
     2302            newtRefresh();
     2303        }
    22062304#endif
    2207     }
    2208   log_msg (1, "Finished backing up bigfiles");
    2209   log_msg (1, "estimated slices = %ld; actual slices = %ld",
    2210        estimated_total_noof_slices, g_current_progress);
    2211   close_progress_form ();
    2212   paranoid_fclose(fin);
    2213   paranoid_free(tmp);
    2214   paranoid_free(bigfile_fname);
    2215   paranoid_free(sz_devfile);
    2216   return (retval);
     2305    }
     2306    log_msg(1, "Finished backing up bigfiles");
     2307    log_msg(1, "estimated slices = %ld; actual slices = %ld",
     2308            estimated_total_noof_slices, g_current_progress);
     2309    close_progress_form();
     2310    paranoid_fclose(fin);
     2311    paranoid_free(tmp);
     2312    paranoid_free(bigfile_fname);
     2313    paranoid_free(sz_devfile);
     2314    return (retval);
    22172315}
    22182316
     
    22242322 * @see make_afioballs_and_images
    22252323 */
    2226 int
    2227 make_afioballs_and_images_OLD (struct s_bkpinfo *bkpinfo)
     2324int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
    22282325{
    22292326
    2230     /*@ int ***************************************************/
    2231   int retval = 0;
    2232   long int curr_set_no = 0;
    2233   int res = 0;
    2234  
    2235     /*@ buffers ***********************************************/
    2236   char *curr_filelist_fname;
    2237   char *curr_afioball_fname;
    2238   char *curr_xattr_list_fname;
    2239   char *curr_acl_list_fname;
    2240   char *tmp;
    2241   char *media_usage_comment;
    2242  
    2243   malloc_string(curr_afioball_fname);
    2244   malloc_string(media_usage_comment);
    2245   malloc_string(curr_filelist_fname);
    2246   malloc_string(curr_xattr_list_fname);
    2247   malloc_string(curr_acl_list_fname);
    2248  
    2249   tmp = malloc(MAX_STR_LEN*2);
    2250  
    2251   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    2252 
    2253   log_to_screen ("Archiving regular files");
    2254 
    2255   open_progress_form ("Backing up filesystem",
    2256               "I am backing up your live filesystem now.",
    2257               "Please wait. This may take a couple of hours.",
    2258               "Working...", get_last_filelist_number (bkpinfo) + 1);
    2259 
    2260   sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
    2261 
    2262   for (curr_set_no = 0; does_file_exist (curr_filelist_fname);
    2263        sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    2264         ++curr_set_no))
    2265     {
    2266       /* backup this set of files */
    2267       sprintf (curr_filelist_fname,  FILELIST_FNAME_RAW_SZ,  bkpinfo->tmpdir, curr_set_no);
    2268       sprintf (curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,bkpinfo->tmpdir,
    2269                curr_set_no, bkpinfo->zip_suffix);
    2270      
    2271       log_msg (1, "EXAT'g set %ld", curr_set_no);
    2272       sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
    2273       sprintf (curr_acl_list_fname,   ACL_LIST_FNAME_RAW_SZ,   bkpinfo->tmpdir, curr_set_no);
    2274       get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
    2275       get_acl_list(curr_filelist_fname, curr_acl_list_fname);
    2276      
    2277       log_msg (1, "Archiving set %ld", curr_set_no);
    2278       res =
    2279     archive_this_fileset (bkpinfo, curr_filelist_fname, curr_afioball_fname, curr_set_no);
    2280       retval += res;
    2281       if (res)
    2282     {
    2283       sprintf (tmp,
    2284            "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
    2285            curr_set_no);
    2286       log_to_screen (tmp);
    2287     }
    2288 
    2289       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    2290 
    2291       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    2292       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2293         {
    2294               register_in_tape_catalog(fileset, curr_set_no, -1, curr_afioball_fname);
    2295               maintain_collection_of_recent_archives(bkpinfo->tmpdir, curr_afioball_fname);
    2296           iamhere("Writing EXAT files");
    2297               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
     2327    /*@ int ************************************************** */
     2328    int retval = 0;
     2329    long int curr_set_no = 0;
     2330    int res = 0;
     2331
     2332    /*@ buffers ********************************************** */
     2333    char *curr_filelist_fname;
     2334    char *curr_afioball_fname;
     2335    char *curr_xattr_list_fname;
     2336    char *curr_acl_list_fname;
     2337    char *tmp;
     2338    char *media_usage_comment;
     2339
     2340    malloc_string(curr_afioball_fname);
     2341    malloc_string(media_usage_comment);
     2342    malloc_string(curr_filelist_fname);
     2343    malloc_string(curr_xattr_list_fname);
     2344    malloc_string(curr_acl_list_fname);
     2345
     2346    tmp = malloc(MAX_STR_LEN * 2);
     2347
     2348    sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     2349
     2350    log_to_screen("Archiving regular files");
     2351
     2352    open_progress_form("Backing up filesystem",
     2353                       "I am backing up your live filesystem now.",
     2354                       "Please wait. This may take a couple of hours.",
     2355                       "Working...",
     2356                       get_last_filelist_number(bkpinfo) + 1);
     2357
     2358    sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
     2359            0L);
     2360
     2361    for (curr_set_no = 0; does_file_exist(curr_filelist_fname);
     2362         sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
     2363                 bkpinfo->tmpdir, ++curr_set_no)) {
     2364        /* backup this set of files */
     2365        sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
     2366                bkpinfo->tmpdir, curr_set_no);
     2367        sprintf(curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     2368                bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
     2369
     2370        log_msg(1, "EXAT'g set %ld", curr_set_no);
     2371        sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     2372                bkpinfo->tmpdir, curr_set_no);
     2373        sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     2374                bkpinfo->tmpdir, curr_set_no);
     2375        get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
     2376        get_acl_list(curr_filelist_fname, curr_acl_list_fname);
     2377
     2378        log_msg(1, "Archiving set %ld", curr_set_no);
     2379        res =
     2380            archive_this_fileset(bkpinfo, curr_filelist_fname,
     2381                                 curr_afioball_fname, curr_set_no);
     2382        retval += res;
     2383        if (res) {
     2384            sprintf(tmp,
     2385                    "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
     2386                    curr_set_no);
     2387            log_to_screen(tmp);
     2388        }
     2389
     2390        strcpy(media_usage_comment, percent_media_full_comment(bkpinfo));
     2391
     2392        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     2393        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2394            register_in_tape_catalog(fileset, curr_set_no, -1,
     2395                                     curr_afioball_fname);
     2396            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     2397                                                   curr_afioball_fname);
     2398            iamhere("Writing EXAT files");
     2399            res +=
     2400                write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
     2401                                         curr_acl_list_fname);
    22982402// archives themselves
    2299               res = move_files_to_stream (bkpinfo, curr_afioball_fname, NULL);
    2300         }
    2301       else
    2302         {
    2303           res = move_files_to_cd (bkpinfo, curr_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, curr_afioball_fname, NULL);
    2304         }
    2305       retval += res;
    2306       g_current_progress++;
    2307       update_progress_form (media_usage_comment);
    2308 
    2309       if (res)
    2310     {
    2311       sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    2312            curr_set_no);
    2313       log_to_screen (tmp);
    2314       fatal_error
    2315         ("Is your hard disk is full? If not, please send the author the logfile.");
    2316     }
    2317     }
    2318   close_progress_form ();
    2319   sprintf (tmp, "Your regular files have been archived ");
    2320   if (retval)
    2321     {
    2322       strcat (tmp, "(with errors).");
    2323     }
    2324   else
    2325     {
    2326       strcat (tmp, "successfully.");
    2327     }
    2328   log_to_screen (tmp);
    2329   paranoid_free(tmp);
    2330   paranoid_free(curr_filelist_fname);
    2331   paranoid_free(curr_afioball_fname);
    2332   paranoid_free(media_usage_comment);
    2333   paranoid_free(curr_xattr_list_fname);
    2334   paranoid_free(curr_acl_list_fname);
    2335   return (retval);
     2403            res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
     2404        } else {
     2405            res =
     2406                move_files_to_cd(bkpinfo, curr_filelist_fname,
     2407                                 curr_xattr_list_fname,
     2408                                 curr_acl_list_fname, curr_afioball_fname,
     2409                                 NULL);
     2410        }
     2411        retval += res;
     2412        g_current_progress++;
     2413        update_progress_form(media_usage_comment);
     2414
     2415        if (res) {
     2416            sprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
     2417                    curr_set_no);
     2418            log_to_screen(tmp);
     2419            fatal_error
     2420                ("Is your hard disk is full? If not, please send the author the logfile.");
     2421        }
     2422    }
     2423    close_progress_form();
     2424    sprintf(tmp, "Your regular files have been archived ");
     2425    if (retval) {
     2426        strcat(tmp, "(with errors).");
     2427    } else {
     2428        strcat(tmp, "successfully.");
     2429    }
     2430    log_to_screen(tmp);
     2431    paranoid_free(tmp);
     2432    paranoid_free(curr_filelist_fname);
     2433    paranoid_free(curr_afioball_fname);
     2434    paranoid_free(media_usage_comment);
     2435    paranoid_free(curr_xattr_list_fname);
     2436    paranoid_free(curr_acl_list_fname);
     2437    return (retval);
    23362438}
    23372439
    2338 /* @} - end of LLarchiveGroup */ 
    2339  
    2340  
     2440/* @} - end of LLarchiveGroup */
     2441
     2442
    23412443/**
    23422444 * Wrapper around @c make_afioballs_and_images().
     
    23472449 * @ingroup MLarchiveGroup
    23482450 */
    2349 int
    2350 make_those_afios_phase (struct s_bkpinfo *bkpinfo)
     2451int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
    23512452{
    2352     /*@ int ********************************************/
    2353   int res = 0;
    2354   int retval = 0;
    2355 
    2356   assert(bkpinfo!=NULL);
    2357 
    2358   mvaddstr_and_log_it (g_currentY, 0, "Archiving regular files to media          ");
    2359 
    2360   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2361     {
    2362       write_header_block_to_stream (0, "start-of-afioballs",
    2363                   BLK_START_AFIOBALLS);
     2453    /*@ int ******************************************* */
     2454    int res = 0;
     2455    int retval = 0;
     2456
     2457    assert(bkpinfo != NULL);
     2458
     2459    mvaddstr_and_log_it(g_currentY, 0,
     2460                        "Archiving regular files to media          ");
     2461
     2462    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2463        write_header_block_to_stream(0, "start-of-afioballs",
     2464                                    BLK_START_AFIOBALLS);
    23642465#if __FreeBSD__ == 5
    2365       log_msg (1, "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
    2366       res = make_afioballs_and_images_OLD (bkpinfo);
     2466        log_msg(1,
     2467                "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
     2468        res = make_afioballs_and_images_OLD(bkpinfo);
    23672469#else
    2368       res = make_afioballs_and_images_OLD (bkpinfo);
     2470        res = make_afioballs_and_images_OLD(bkpinfo);
    23692471#endif
    2370       write_header_block_to_stream (0, "stop-afioballs", BLK_STOP_AFIOBALLS);
    2371     }
    2372   else
    2373     {
    2374       res = make_afioballs_and_images (bkpinfo);
    2375     }
    2376 
    2377   retval += res;
    2378   if (res)
    2379     {
    2380       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2381       log_msg (1, "make_afioballs_and_images returned an error");
    2382     }
    2383   else
    2384     {
    2385       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2386     }
    2387   return (retval);
     2472        write_header_block_to_stream(0, "stop-afioballs",
     2473                                     BLK_STOP_AFIOBALLS);
     2474    } else {
     2475        res = make_afioballs_and_images(bkpinfo);
     2476    }
     2477
     2478    retval += res;
     2479    if (res) {
     2480        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2481        log_msg(1, "make_afioballs_and_images returned an error");
     2482    } else {
     2483        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2484    }
     2485    return (retval);
    23882486}
    23892487
     
    23972495 * @ingroup MLarchiveGroup
    23982496 */
    2399 int
    2400 make_those_slices_phase (struct s_bkpinfo *bkpinfo)
     2497int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
    24012498{
    24022499
    2403     /*@ int ******************************************************/
    2404   int res = 0;
    2405   int retval = 0;
    2406 
    2407     /*@ buffers ***************************************************/
    2408   char *biggielist;
    2409   char *command;
    2410   char *blah;
    2411   char *xattr_fname;
    2412   char *acl_fname;
    2413  
    2414   assert(bkpinfo!=NULL);
    2415   /* slice big files */
    2416   malloc_string(blah);
    2417   malloc_string(biggielist);
    2418   malloc_string(xattr_fname);
    2419   malloc_string(acl_fname);
    2420   command = malloc(1200);
    2421   mvaddstr_and_log_it (g_currentY, 0, "Archiving large files to media           ");
    2422   sprintf (biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
    2423   sprintf (xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2424   sprintf (acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2425  
    2426   sprintf (command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
    2427   paranoid_system(command);
    2428   sprintf (blah, "biggielist = %s", biggielist);
    2429   log_msg (2, blah);
    2430  
    2431   if (!does_file_exist (biggielist))
    2432     {
    2433       log_msg (1, "BTW, the biggielist does not exist");
    2434     }
    2435 
    2436   get_fattr_list(biggielist, xattr_fname);
    2437   get_acl_list(biggielist, acl_fname);
    2438   sprintf (command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
    2439   paranoid_system(command);
    2440   sprintf (command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
    2441   paranoid_system(command);
    2442 
    2443   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2444     {
    2445       res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
    2446       sprintf (blah, "%ld", count_lines_in_file (biggielist));
    2447       write_header_block_to_stream (0, blah, BLK_START_BIGGIEFILES);
    2448     }
    2449   res = make_slices_and_images (bkpinfo, biggielist);
    2450   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2451     {
    2452       write_header_block_to_stream (0, "end-of-biggiefiles",
    2453                   BLK_STOP_BIGGIEFILES);
    2454     }
    2455   retval += res;
    2456   if (res)
    2457     {
    2458       log_msg (1, "make_slices_and_images returned an error");
    2459       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2460     }
    2461   else
    2462     {
    2463       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2464     }
    2465   paranoid_free(blah);
    2466   paranoid_free(biggielist);
    2467   paranoid_free(command);
    2468   paranoid_free(xattr_fname);
    2469   paranoid_free(acl_fname);
    2470   return (retval);
     2500    /*@ int ***************************************************** */
     2501    int res = 0;
     2502    int retval = 0;
     2503
     2504    /*@ buffers ************************************************** */
     2505    char *biggielist;
     2506    char *command;
     2507    char *blah;
     2508    char *xattr_fname;
     2509    char *acl_fname;
     2510
     2511    assert(bkpinfo != NULL);
     2512    /* slice big files */
     2513    malloc_string(blah);
     2514    malloc_string(biggielist);
     2515    malloc_string(xattr_fname);
     2516    malloc_string(acl_fname);
     2517    command = malloc(1200);
     2518    mvaddstr_and_log_it(g_currentY, 0,
     2519                        "Archiving large files to media           ");
     2520    sprintf(biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
     2521    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2522    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2523
     2524    sprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
     2525            biggielist);
     2526    paranoid_system(command);
     2527    sprintf(blah, "biggielist = %s", biggielist);
     2528    log_msg(2, blah);
     2529
     2530    if (!does_file_exist(biggielist)) {
     2531        log_msg(1, "BTW, the biggielist does not exist");
     2532    }
     2533
     2534    get_fattr_list(biggielist, xattr_fname);
     2535    get_acl_list(biggielist, acl_fname);
     2536    sprintf(command, "cp %s %s/archives/", xattr_fname,
     2537            bkpinfo->scratchdir);
     2538    paranoid_system(command);
     2539    sprintf(command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
     2540    paranoid_system(command);
     2541
     2542    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2543        res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
     2544        sprintf(blah, "%ld", count_lines_in_file(biggielist));
     2545        write_header_block_to_stream(0, blah, BLK_START_BIGGIEFILES);
     2546    }
     2547    res = make_slices_and_images(bkpinfo, biggielist);
     2548    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2549        write_header_block_to_stream(0, "end-of-biggiefiles",
     2550                                     BLK_STOP_BIGGIEFILES);
     2551    }
     2552    retval += res;
     2553    if (res) {
     2554        log_msg(1, "make_slices_and_images returned an error");
     2555        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2556    } else {
     2557        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2558    }
     2559    paranoid_free(blah);
     2560    paranoid_free(biggielist);
     2561    paranoid_free(command);
     2562    paranoid_free(xattr_fname);
     2563    paranoid_free(acl_fname);
     2564    return (retval);
    24712565}
    24722566
     
    24822576 * transfer files over the network) or leave it as is.
    24832577 */
    2484 int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) = _move_files_to_cd;
     2578int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
     2579    _move_files_to_cd;
    24852580
    24862581/**
     
    25022597 * @return The number of errors encountered (0 for success)
    25032598 */
    2504 int
    2505 _move_files_to_cd (struct s_bkpinfo *bkpinfo,
    2506          char *files_to_add, ...)
     2599int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    25072600{
    25082601
    2509     /*@ int *************************************************************/
    2510   int retval = 0;
     2602    /*@ int ************************************************************ */
     2603    int retval = 0;
    25112604    int res = 0;
    25122605
    2513     /*@ buffers *********************************************************/
    2514   char *tmp,
    2515        *curr_file, *cf;
    2516 
    2517     /*@ long *************************************************************/
    2518   va_list ap;
    2519   long long would_occupy;
    2520 
    2521   assert(bkpinfo!=NULL);
    2522   malloc_string(curr_file);
    2523   tmp = malloc(1200);
    2524   would_occupy = space_occupied_by_cd (bkpinfo->scratchdir);
    2525   va_start(ap, files_to_add); // initialize the variable arguments
    2526   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2527     {
    2528       if (!cf) {continue;}
    2529       strcpy(curr_file, cf);
    2530       if (!does_file_exist (curr_file))
    2531     {
    2532       log_msg (1, "Warning - you're trying to add a non-existent file - '%s' to the CD", curr_file);
    2533     }
    2534       else
    2535         {
    2536       log_msg (8, "Trying to add file %s to CD", curr_file);
    2537           would_occupy += length_of_file (curr_file) / 1024;
    2538         }
    2539     }
    2540   va_end(ap);
    2541 
    2542   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "move_files_to_cd() - unknown media size"); }
    2543   if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number])
    2544     {
    2545       res = write_iso_and_go_on (bkpinfo, FALSE);   /* FALSE because this is not the last CD we'll write */
    2546       retval += res;
    2547       if (res)
    2548     {
    2549       log_msg (1, "WARNING - write_iso_and_go_on returned an error");
    2550     }
    2551     }
    2552 
    2553   va_start(ap, files_to_add); // initialize the variable arguments
    2554   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2555     {
    2556       if (!cf) {continue;}
    2557       strcpy(curr_file, cf);
    2558 
    2559       sprintf (tmp, "mv -f %s %s/archives/", curr_file,
    2560            bkpinfo->scratchdir);
    2561       res = run_program_and_log_output (tmp, 5);
    2562       retval += res;
    2563       if (res)
    2564     {
    2565       log_msg (1, "(move_files_to_cd) '%s' failed", tmp);
    2566     }
    2567       else
    2568         {
    2569       log_msg (8, "Moved %s to CD OK", tmp);
    2570     }
    2571       //      unlink (curr_file);
    2572     }
    2573   va_end(ap);
    2574 
    2575   if (retval)
    2576     {
    2577       log_msg (1, "Warning - errors occurred while I was adding files to CD dir");
    2578     }
    2579   paranoid_free(tmp);
    2580   paranoid_free(curr_file);
    2581   return (retval);
     2606    /*@ buffers ******************************************************** */
     2607    char *tmp, *curr_file, *cf;
     2608
     2609    /*@ long ************************************************************ */
     2610    va_list ap;
     2611    long long would_occupy;
     2612
     2613    assert(bkpinfo != NULL);
     2614    malloc_string(curr_file);
     2615    tmp = malloc(1200);
     2616    would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
     2617    va_start(ap, files_to_add); // initialize the variable arguments
     2618    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2619        if (!cf) {
     2620            continue;
     2621        }
     2622        strcpy(curr_file, cf);
     2623        if (!does_file_exist(curr_file)) {
     2624            log_msg(1,
     2625                    "Warning - you're trying to add a non-existent file - '%s' to the CD",
     2626                    curr_file);
     2627        } else {
     2628            log_msg(8, "Trying to add file %s to CD", curr_file);
     2629            would_occupy += length_of_file(curr_file) / 1024;
     2630        }
     2631    }
     2632    va_end(ap);
     2633
     2634    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     2635        fatal_error("move_files_to_cd() - unknown media size");
     2636    }
     2637    if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
     2638        res = write_iso_and_go_on(bkpinfo, FALSE);  /* FALSE because this is not the last CD we'll write */
     2639        retval += res;
     2640        if (res) {
     2641            log_msg(1, "WARNING - write_iso_and_go_on returned an error");
     2642        }
     2643    }
     2644
     2645    va_start(ap, files_to_add); // initialize the variable arguments
     2646    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2647        if (!cf) {
     2648            continue;
     2649        }
     2650        strcpy(curr_file, cf);
     2651
     2652        sprintf(tmp, "mv -f %s %s/archives/", curr_file,
     2653                bkpinfo->scratchdir);
     2654        res = run_program_and_log_output(tmp, 5);
     2655        retval += res;
     2656        if (res) {
     2657            log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
     2658        } else {
     2659            log_msg(8, "Moved %s to CD OK", tmp);
     2660        }
     2661        //      unlink (curr_file);
     2662    }
     2663    va_end(ap);
     2664
     2665    if (retval) {
     2666        log_msg(1,
     2667                "Warning - errors occurred while I was adding files to CD dir");
     2668    }
     2669    paranoid_free(tmp);
     2670    paranoid_free(curr_file);
     2671    return (retval);
    25822672}
    25832673
     
    26032693 * @ingroup MLarchiveGroup
    26042694 */
    2605 int
    2606 offer_to_write_floppies (struct s_bkpinfo *bkpinfo, char *imagesdir)
     2695int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
    26072696{
    2608     /*@ buffer *************************************************************/
    2609   char *tmp;
     2697    /*@ buffer ************************************************************ */
     2698    char *tmp;
    26102699    char *comment;
    26112700    char *bootdisk_dev;
     
    26142703    char *rootdisk_file;
    26152704
    2616     /*@ int ****************************************************************/
    2617   int i = 0;
     2705    /*@ int *************************************************************** */
     2706    int i = 0;
    26182707    int res = 0;
    26192708
    2620     /*@ bool ***************************************************************/
    2621   bool format_first;
    2622   bool root_disk_exists=FALSE;
    2623 
    2624   malloc_string(tmp);
    2625   malloc_string(comment);
    2626   malloc_string(bootdisk_dev);
    2627   malloc_string(datadisk_dev);
    2628   malloc_string(rootdisk_file);
    2629   malloc_string(bootdisk_file);
    2630   assert(bkpinfo!=NULL);
    2631   assert_string_is_neither_NULL_nor_zerolength(imagesdir);
    2632 
    2633 
    2634   if (!ask_me_yes_or_no
    2635       ("Write boot and data disk images to 3.5\" floppy disks?"))
    2636     {
    2637       return (0);
    2638     }
    2639   if (does_device_exist (DEFAULT_1722MB_DISK))
    2640     {
     2709    /*@ bool ************************************************************** */
     2710    bool format_first;
     2711    bool root_disk_exists = FALSE;
     2712
     2713    malloc_string(tmp);
     2714    malloc_string(comment);
     2715    malloc_string(bootdisk_dev);
     2716    malloc_string(datadisk_dev);
     2717    malloc_string(rootdisk_file);
     2718    malloc_string(bootdisk_file);
     2719    assert(bkpinfo != NULL);
     2720    assert_string_is_neither_NULL_nor_zerolength(imagesdir);
     2721
     2722
     2723    if (!ask_me_yes_or_no
     2724        ("Write boot and data disk images to 3.5\" floppy disks?")) {
     2725        return (0);
     2726    }
     2727    if (does_device_exist(DEFAULT_1722MB_DISK)) {
    26412728#ifdef __FreeBSD__
    2642  // tell the system that this is a 1.72m floppy
    2643       system ("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
     2729        // tell the system that this is a 1.72m floppy
     2730        system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
    26442731#endif
    2645       strcpy (bootdisk_dev, DEFAULT_1722MB_DISK);
    2646     }
    2647   else if (does_device_exist (BACKUP_1722MB_DISK))
    2648     {
    2649       sprintf (bootdisk_dev, "/dev/fd0H1722");
    2650     }
    2651   else
    2652     {
    2653       log_msg( 1, "Warning - can't find a 1.72MB floppy device *sigh*" );
    2654       strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
     2732        strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
     2733    } else if (does_device_exist(BACKUP_1722MB_DISK)) {
     2734        sprintf(bootdisk_dev, "/dev/fd0H1722");
     2735    } else {
     2736        log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
     2737        strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
    26552738//      return (1);
    2656     }
    2657   strcpy (datadisk_dev, "/dev/fd0");
    2658   if (!does_device_exist (datadisk_dev))
    2659     {
    2660       log_msg( 1, "Warning - can't find a 1.44MB floppy device *sigh*" );
    2661       strcpy(datadisk_dev, "/dev/fd0");
     2739    }
     2740    strcpy(datadisk_dev, "/dev/fd0");
     2741    if (!does_device_exist(datadisk_dev)) {
     2742        log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
     2743        strcpy(datadisk_dev, "/dev/fd0");
    26622744//      return (1);
    2663     }
    2664   format_first =
    2665     ask_me_yes_or_no
    2666     ("Do you want me to format the disks before I write to them?");
     2745    }
     2746    format_first =
     2747        ask_me_yes_or_no
     2748        ("Do you want me to format the disks before I write to them?");
    26672749
    26682750/* boot disk */
    2669   if (ask_me_OK_or_cancel ("About to write boot disk"))
    2670     {
    2671       log_to_screen ("Writing boot floppy");
     2751    if (ask_me_OK_or_cancel("About to write boot disk")) {
     2752        log_to_screen("Writing boot floppy");
    26722753#ifdef __FreeBSD__
    2673       sprintf (tmp, "%s/mindi-kern.1722.img", imagesdir);
    2674       if (format_first) { format_disk (bootdisk_dev); }
    2675       res += write_image_to_floppy (bootdisk_dev, tmp);
    2676       if (ask_me_OK_or_cancel ("About to write 1.44MB mfsroot disk"))
    2677         {
    2678           log_to_screen ("Writing mfsroot floppy");
    2679           if (format_first) { format_disk (datadisk_dev); }
    2680           sprintf (tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
    2681           write_image_to_floppy (datadisk_dev, tmp);
    2682         }
     2754        sprintf(tmp, "%s/mindi-kern.1722.img", imagesdir);
     2755        if (format_first) {
     2756            format_disk(bootdisk_dev);
     2757        }
     2758        res += write_image_to_floppy(bootdisk_dev, tmp);
     2759        if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
     2760            log_to_screen("Writing mfsroot floppy");
     2761            if (format_first) {
     2762                format_disk(datadisk_dev);
     2763            }
     2764            sprintf(tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
     2765            write_image_to_floppy(datadisk_dev, tmp);
     2766        }
    26832767#else
    2684       sprintf (bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
    2685       if (does_file_exist(bootdisk_file))
    2686         {
    2687           if (format_first) { format_disk (bootdisk_dev); }
    2688       res += write_image_to_floppy (bootdisk_dev, bootdisk_file);
    2689         }
    2690       else
    2691         {
    2692       sprintf (bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
    2693       sprintf (rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
    2694       root_disk_exists = TRUE;
    2695       if (!does_file_exist(rootdisk_file) || !does_file_exist(bootdisk_file))
    2696         {
    2697           popup_and_OK("Cannot write boot/root floppies. Files not found.");
    2698           log_to_screen("Failed to find boot/root floppy images. Oh dear.");
    2699           return(1);
    2700         }
    2701       if (format_first) { format_disk (datadisk_dev); }
    2702         /*
    2703           sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
    2704           res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
    2705         */
    2706       res += write_image_to_floppy (datadisk_dev, bootdisk_file);
    2707       if (ask_me_OK_or_cancel ("About to write root disk"))
    2708         {
    2709           log_to_screen ("Writing root floppy");
    2710           if (format_first) { format_disk (datadisk_dev); }
    2711           sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
    2712           log_msg(1, "tmp = '%s'", tmp);
    2713           res += run_external_binary_with_percentage_indicator_NEW("Writing root floppy", tmp);
     2768        sprintf(bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
     2769        if (does_file_exist(bootdisk_file)) {
     2770            if (format_first) {
     2771                format_disk(bootdisk_dev);
     2772            }
     2773            res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
     2774        } else {
     2775            sprintf(bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
     2776            sprintf(rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
     2777            root_disk_exists = TRUE;
     2778            if (!does_file_exist(rootdisk_file)
     2779                || !does_file_exist(bootdisk_file)) {
     2780                popup_and_OK
     2781                    ("Cannot write boot/root floppies. Files not found.");
     2782                log_to_screen
     2783                    ("Failed to find boot/root floppy images. Oh dear.");
     2784                return (1);
     2785            }
     2786            if (format_first) {
     2787                format_disk(datadisk_dev);
     2788            }
     2789            /*
     2790               sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
     2791               res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
     2792             */
     2793            res += write_image_to_floppy(datadisk_dev, bootdisk_file);
     2794            if (ask_me_OK_or_cancel("About to write root disk")) {
     2795                log_to_screen("Writing root floppy");
     2796                if (format_first) {
     2797                    format_disk(datadisk_dev);
     2798                }
     2799                sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
     2800                log_msg(1, "tmp = '%s'", tmp);
     2801                res +=
     2802                    run_external_binary_with_percentage_indicator_NEW
     2803                    ("Writing root floppy", tmp);
    27142804//              res += write_image_to_floppy (datadisk_dev, rootdisk_file);
    2715         }
    2716         }
     2805            }
     2806        }
    27172807#endif
    2718     }
    2719   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2720     {
    2721       log_to_screen
    2722     ("FYI, the data disks are stored on tape/CD for your convenience.");
    2723       return (0);
    2724     }
    2725   for (i = 1; i < 99; i++)
    2726     {
    2727       sprintf (tmp, "%s/mindi-data-%d.img", imagesdir, i);
    2728       log_msg (3, tmp);
    2729       if (!does_file_exist (tmp))
    2730     {
    2731       log_msg (3, "...not found");
    2732       break;
    2733     }
    2734       sprintf (comment, "About to write data disk #%d", i);
    2735       if (ask_me_OK_or_cancel (comment))
    2736     {
    2737       sprintf (comment, "Writing data disk #%3d", i);
    2738       log_to_screen (comment);
    2739       if (format_first)
    2740         {
    2741           res += format_disk (datadisk_dev);
    2742         }
    2743       res += write_image_to_floppy (datadisk_dev, tmp);
    2744     }
    2745     }
    2746   paranoid_free(tmp);
    2747   paranoid_free(comment);
    2748   paranoid_free(bootdisk_dev);
    2749   paranoid_free(datadisk_dev);
    2750   return (res);
     2808    }
     2809    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2810        log_to_screen
     2811            ("FYI, the data disks are stored on tape/CD for your convenience.");
     2812        return (0);
     2813    }
     2814    for (i = 1; i < 99; i++) {
     2815        sprintf(tmp, "%s/mindi-data-%d.img", imagesdir, i);
     2816        log_msg(3, tmp);
     2817        if (!does_file_exist(tmp)) {
     2818            log_msg(3, "...not found");
     2819            break;
     2820        }
     2821        sprintf(comment, "About to write data disk #%d", i);
     2822        if (ask_me_OK_or_cancel(comment)) {
     2823            sprintf(comment, "Writing data disk #%3d", i);
     2824            log_to_screen(comment);
     2825            if (format_first) {
     2826                res += format_disk(datadisk_dev);
     2827            }
     2828            res += write_image_to_floppy(datadisk_dev, tmp);
     2829        }
     2830    }
     2831    paranoid_free(tmp);
     2832    paranoid_free(comment);
     2833    paranoid_free(bootdisk_dev);
     2834    paranoid_free(datadisk_dev);
     2835    return (res);
    27512836}
    27522837
     
    27682853 */
    27692854
    2770 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo)
     2855int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
     2856                                                   *bkpinfo)
    27712857{
    2772 int res=0;
    2773 
    2774   assert(bkpinfo!=NULL);
    2775 
    2776       mvaddstr_and_log_it (g_currentY, 0,
    2777                "Writing boot+data floppy images to disk");
    2778 
    2779       if (!bkpinfo->nonbootable_backup) {
     2858    int res = 0;
     2859
     2860    assert(bkpinfo != NULL);
     2861
     2862    mvaddstr_and_log_it(g_currentY, 0,
     2863                        "Writing boot+data floppy images to disk");
     2864
     2865    if (!bkpinfo->nonbootable_backup) {
    27802866#ifdef __FreeBSD__
    2781       if (!does_file_exist ("/root/images/mindi/mindi-kern.1722.img"))
     2867        if (!does_file_exist("/root/images/mindi/mindi-kern.1722.img"))
    27822868#else
    2783       if (!does_file_exist ("/root/images/mindi/mindi-bootroot.1722.img") &&
    2784           !does_file_exist ("/root/images/mindi/mindi-boot.1440.img"))
     2869        if (!does_file_exist("/root/images/mindi/mindi-bootroot.1722.img")
     2870            && !does_file_exist("/root/images/mindi/mindi-boot.1440.img"))
    27852871#endif
    2786       {
    2787           mvaddstr_and_log_it (g_currentY++, 74, "No Imgs");
    2788           if (does_file_exist ("/root/images/mindi/mondorescue.iso"))
    2789           {
    2790               popup_and_OK
    2791               ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
    2792               res++;
    2793           }
    2794       }
    2795       else
    2796       {
    2797           offer_to_write_floppies (bkpinfo, "/root/images/mindi");
    2798           mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2799       }
    2800       } else {
    2801       popup_and_OK ("Since you opted for a nonbootable backup, no boot floppies were created.");
    2802       }
    2803      
    2804   return(res);
     2872        {
     2873            mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
     2874            if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
     2875                popup_and_OK
     2876                    ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
     2877                res++;
     2878            }
     2879        } else {
     2880            offer_to_write_floppies(bkpinfo, "/root/images/mindi");
     2881            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2882        }
     2883    } else {
     2884        popup_and_OK
     2885            ("Since you opted for a nonbootable backup, no boot floppies were created.");
     2886    }
     2887
     2888    return (res);
    28052889}
    28062890
     
    28172901 * transfer files over the network) or leave it as is.
    28182902 */
    2819 int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) = _move_files_to_stream;
     2903int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
     2904    _move_files_to_stream;
    28202905
    28212906/**
     
    28332918 */
    28342919int
    2835 _move_files_to_stream (struct s_bkpinfo *bkpinfo,
    2836          char *files_to_add, ...)
     2920_move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    28372921{
    28382922
    2839     /*@ int *************************************************************/
    2840   int retval = 0;
     2923    /*@ int ************************************************************ */
     2924    int retval = 0;
    28412925    int res = 0;
    2842     /*@ buffers *********************************************************/
    2843 
    2844     /*@ char ************************************************************/
     2926    /*@ buffers ******************************************************** */
     2927
     2928    /*@ char *********************************************************** */
    28452929    char start_chr;
    28462930    char stop_chr;
    2847         char *curr_file, *cf;
    2848     /*@ long long *******************************************************/
    2849   long long length_of_incoming_file = 0;
    2850   t_archtype type;
    2851   va_list ap;
    2852 
    2853   assert(bkpinfo!=NULL);
    2854   malloc_string(curr_file);
    2855   va_start(ap, files_to_add);
    2856   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2857     {
    2858       if (!cf) {continue;}
    2859       strcpy(curr_file, cf);
    2860       if (!does_file_exist (curr_file))
    2861         {
    2862           log_msg (1,
    2863            "Warning - you're trying to add a non-existent file - '%s' to the tape",
    2864            curr_file);
    2865         }
     2931    char *curr_file, *cf;
     2932    /*@ long long ****************************************************** */
     2933    long long length_of_incoming_file = 0;
     2934    t_archtype type;
     2935    va_list ap;
     2936
     2937    assert(bkpinfo != NULL);
     2938    malloc_string(curr_file);
     2939    va_start(ap, files_to_add);
     2940    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2941        if (!cf) {
     2942            continue;
     2943        }
     2944        strcpy(curr_file, cf);
     2945        if (!does_file_exist(curr_file)) {
     2946            log_msg(1,
     2947                    "Warning - you're trying to add a non-existent file - '%s' to the tape",
     2948                    curr_file);
     2949        }
    28662950/* create header chars */
    2867       start_chr = BLK_START_AN_AFIO_OR_SLICE;
    2868       stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
     2951        start_chr = BLK_START_AN_AFIO_OR_SLICE;
     2952        stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
    28692953/* ask for new tape if necessary */
    2870       length_of_incoming_file = length_of_file (curr_file);
    2871       write_header_block_to_stream (length_of_incoming_file, curr_file,
    2872                   start_chr);
    2873       if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star."))
    2874     { type = fileset; }
    2875       else if (strstr(curr_file, "slice"))
    2876     { type = biggieslice; }
    2877       else
    2878     { type = other; }
    2879       res = write_file_to_stream_from_file (bkpinfo, curr_file);
    2880       retval += res;
    2881       unlink (curr_file);
     2954        length_of_incoming_file = length_of_file(curr_file);
     2955        write_header_block_to_stream(length_of_incoming_file, curr_file,
     2956                                     start_chr);
     2957        if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
     2958            type = fileset;
     2959        } else if (strstr(curr_file, "slice")) {
     2960            type = biggieslice;
     2961        } else {
     2962            type = other;
     2963        }
     2964        res = write_file_to_stream_from_file(bkpinfo, curr_file);
     2965        retval += res;
     2966        unlink(curr_file);
    28822967/* write closing header */
    2883       write_header_block_to_stream (0, "finished-writing-file", stop_chr);
    2884     }
    2885   va_end(ap);
    2886 
    2887   if (retval)
    2888     {
    2889       log_msg (1, "Warning - errors occurred while I was adding file to tape");
    2890     }
    2891   paranoid_free(curr_file);
    2892   return (retval);
     2968        write_header_block_to_stream(0, "finished-writing-file", stop_chr);
     2969    }
     2970    va_end(ap);
     2971
     2972    if (retval) {
     2973        log_msg(1,
     2974                "Warning - errors occurred while I was adding file to tape");
     2975    }
     2976    paranoid_free(curr_file);
     2977    return (retval);
    28932978}
    28942979
     
    29082993 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
    29092994 */
    2910 int interrogate_disk_currently_in_cdrw_drive(char*cdrw_dev, bool keep_looping)
     2995int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
     2996                                             bool keep_looping)
    29112997{
    2912   char *tmp;
    2913   int res=0;
    2914   char *bkp;
    2915   char *cdrecord;
    2916 
    2917   malloc_string(tmp);
    2918   malloc_string(bkp);
    2919   malloc_string(cdrecord);
    2920   strcpy(bkp, cdrw_dev);
    2921   if (find_cdrw_device(cdrw_dev))
    2922     {
    2923       strcpy(cdrw_dev, bkp);
    2924     }
    2925   else
    2926     {
    2927       if (!system("which cdrecord > /dev/null 2> /dev/null"))
    2928         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2929       else if (!system("which dvdrecord > /dev/null 2> /dev/null"))
    2930         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2931       else
    2932         { cdrecord[0] = '\0'; log_msg(2, "Oh well. I guess I'll just pray then."); }
    2933       if (cdrecord[0])
    2934         {
    2935          if (!keep_looping)
    2936            {
    2937              retract_CD_tray_and_defeat_autorun();
    2938              res = run_program_and_log_output(cdrecord, 5);
    2939            }
    2940          else
    2941            {
    2942              while((res=run_program_and_log_output(cdrecord, 5)))
    2943                {
    2944                  retract_CD_tray_and_defeat_autorun();
    2945                  if (ask_me_yes_or_no("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
    2946                    { log_msg(1, "Well, he insisted..."); break; }
    2947                }
    2948             }
    2949         }
    2950     }
     2998    char *tmp;
     2999    int res = 0;
     3000    char *bkp;
     3001    char *cdrecord;
     3002
     3003    malloc_string(tmp);
     3004    malloc_string(bkp);
     3005    malloc_string(cdrecord);
     3006    strcpy(bkp, cdrw_dev);
     3007    if (find_cdrw_device(cdrw_dev)) {
     3008        strcpy(cdrw_dev, bkp);
     3009    } else {
     3010        if (!system("which cdrecord > /dev/null 2> /dev/null")) {
     3011            sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     3012        } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
     3013            sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     3014        } else {
     3015            cdrecord[0] = '\0';
     3016            log_msg(2, "Oh well. I guess I'll just pray then.");
     3017        }
     3018        if (cdrecord[0]) {
     3019            if (!keep_looping) {
     3020                retract_CD_tray_and_defeat_autorun();
     3021                res = run_program_and_log_output(cdrecord, 5);
     3022            } else {
     3023                while ((res = run_program_and_log_output(cdrecord, 5))) {
     3024                    retract_CD_tray_and_defeat_autorun();
     3025                    if (ask_me_yes_or_no
     3026                        ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
     3027                    {
     3028                        log_msg(1, "Well, he insisted...");
     3029                        break;
     3030                    }
     3031                }
     3032            }
     3033        }
     3034    }
    29513035//  retract_CD_tray_and_defeat_autorun();
    2952   paranoid_free(tmp);
    2953   paranoid_free(cdrecord);
    2954   paranoid_free(bkp);
    2955   return(res);
     3036    paranoid_free(tmp);
     3037    paranoid_free(cdrecord);
     3038    paranoid_free(bkp);
     3039    return (res);
    29563040}
    29573041
     
    29703054 */
    29713055void
    2972 pause_and_ask_for_cdr (int ask_for_one_if_more_than_this, bool*pmountable)
     3056pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
    29733057{
    29743058
    2975     /*@ buffers **********************************************/
    2976   char *tmp;
    2977   char *szmsg;
    2978   char *cdrom_dev;
    2979   char *cdrw_dev;
    2980   char *our_serial_str;
    2981   bool ok_go_ahead_burn_it;
    2982   int cd_number = -1;
    2983   int attempt_to_mount_returned_this=999;
    2984   char *mtpt;
    2985   char *szcdno;
    2986   char *szserfname;
    2987   char *szunmount;
    2988 
    2989   malloc_string(tmp);
    2990   malloc_string(szmsg);
    2991   malloc_string(cdrom_dev);
    2992   malloc_string(cdrw_dev);
    2993   malloc_string(mtpt);
    2994   malloc_string(szcdno);
    2995   malloc_string(szserfname);
    2996   malloc_string(our_serial_str);
    2997   malloc_string(szunmount);
    2998 
    2999   sprintf(szmsg, "I am about to burn %s #%d", media_descriptor_string(g_backup_media_type), g_current_media_number);
    3000   log_to_screen(szmsg);
    3001   if (g_current_media_number < ask_for_one_if_more_than_this)
    3002     { return; }
    3003  log_to_screen("Scanning CD-ROM drive...");
    3004   sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int)random(), (long int)random());
    3005   make_hole_for_dir(mtpt);
    3006 
    3007 gotos_make_me_puke:
    3008   ok_go_ahead_burn_it = TRUE;
    3009   if (!find_cdrom_device(cdrom_dev, FALSE))
    3010     {
     3059    /*@ buffers ********************************************* */
     3060    char *tmp;
     3061    char *szmsg;
     3062    char *cdrom_dev;
     3063    char *cdrw_dev;
     3064    char *our_serial_str;
     3065    bool ok_go_ahead_burn_it;
     3066    int cd_number = -1;
     3067    int attempt_to_mount_returned_this = 999;
     3068    char *mtpt;
     3069    char *szcdno;
     3070    char *szserfname;
     3071    char *szunmount;
     3072
     3073    malloc_string(tmp);
     3074    malloc_string(szmsg);
     3075    malloc_string(cdrom_dev);
     3076    malloc_string(cdrw_dev);
     3077    malloc_string(mtpt);
     3078    malloc_string(szcdno);
     3079    malloc_string(szserfname);
     3080    malloc_string(our_serial_str);
     3081    malloc_string(szunmount);
     3082
     3083    sprintf(szmsg, "I am about to burn %s #%d",
     3084            media_descriptor_string(g_backup_media_type),
     3085            g_current_media_number);
     3086    log_to_screen(szmsg);
     3087    if (g_current_media_number < ask_for_one_if_more_than_this) {
     3088        return;
     3089    }
     3090    log_to_screen("Scanning CD-ROM drive...");
     3091    sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
     3092            (long int) random());
     3093    make_hole_for_dir(mtpt);
     3094
     3095  gotos_make_me_puke:
     3096    ok_go_ahead_burn_it = TRUE;
     3097    if (!find_cdrom_device(cdrom_dev, FALSE)) {
    30113098/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    30123099      log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
    30133100      retract_CD_tray_and_defeat_autorun();
    30143101*/
    3015       sprintf(tmp, "umount %s", cdrom_dev);
    3016       run_program_and_log_output(tmp, 1);
    3017       sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
    3018       sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
    3019       sprintf(szunmount, "umount %s", mtpt);
    3020       cd_number = -1;
    3021       our_serial_str[0] = '\0';
    3022       sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
    3023       if ((attempt_to_mount_returned_this=run_program_and_log_output(tmp, 1)))
    3024         {
    3025       log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
    3026       log_to_screen("If there's a CD/DVD in the drive, it's blank.");
    3027      /*
    3028       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3029         {
    3030               ok_go_ahead_burn_it = FALSE;
    3031               log_to_screen("There isn't a writable CD/DVD in the drive.");
    3032         }
    3033       else
    3034         {
    3035           log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
    3036         }
    3037      */
    3038         }
    3039       else if (!does_file_exist(szcdno) || !does_file_exist(szserfname))
    3040         {
    3041       log_to_screen("%s has data on it but it's probably not a Mondo CD.", media_descriptor_string(g_backup_media_type));
    3042         }
    3043       else
    3044     {
    3045       log_to_screen("%s found in drive. It's a Mondo disk.", media_descriptor_string(g_backup_media_type));
    3046           cd_number = atoi(last_line_of_file(szcdno));
    3047           sprintf(tmp, "cat %s 2> /dev/null", szserfname);
    3048           strcpy(our_serial_str, call_program_and_get_last_line_of_output(tmp));
    3049       // FIXME - should be able to use last_line_of_file(), surely?
    3050         }
    3051       run_program_and_log_output(szunmount, 1);
    3052       log_msg(2, "paafcd: cd_number = %d", cd_number);
    3053       log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string);
    3054       if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string))
    3055         {
    3056       log_msg(2, "This %s is part of this backup set!", media_descriptor_string(g_backup_media_type));
    3057           ok_go_ahead_burn_it = FALSE;
    3058           if (cd_number == g_current_media_number-1)
    3059             { log_to_screen("I think you've left the previous %s in the drive.", media_descriptor_string(g_backup_media_type)); }
    3060           else
    3061             { log_to_screen("Please remove this %s. It is part of the backup set you're making now.", media_descriptor_string(g_backup_media_type)); }
    3062         }
    3063       else
    3064         {
    3065       log_to_screen("...but not part of _our_ backup set.");
    3066     }
    3067     }
    3068   else
    3069     {
    3070       log_msg(2, "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?", media_descriptor_string(g_backup_media_type));
    3071       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3072         {
    3073           ok_go_ahead_burn_it = FALSE;
    3074           log_to_screen("There isn't a writable %s in the drive.", media_descriptor_string(g_backup_media_type));
    3075         }
    3076     }
     3102        sprintf(tmp, "umount %s", cdrom_dev);
     3103        run_program_and_log_output(tmp, 1);
     3104        sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
     3105        sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
     3106        sprintf(szunmount, "umount %s", mtpt);
     3107        cd_number = -1;
     3108        our_serial_str[0] = '\0';
     3109        sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
     3110        if ((attempt_to_mount_returned_this =
     3111             run_program_and_log_output(tmp, 1))) {
     3112            log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
     3113            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
     3114            /*
     3115               if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
     3116               {
     3117               ok_go_ahead_burn_it = FALSE;
     3118               log_to_screen("There isn't a writable CD/DVD in the drive.");
     3119               }
     3120               else
     3121               {
     3122               log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
     3123               }
     3124             */
     3125        } else if (!does_file_exist(szcdno)
     3126                   || !does_file_exist(szserfname)) {
     3127            log_to_screen
     3128                ("%s has data on it but it's probably not a Mondo CD.",
     3129                 media_descriptor_string(g_backup_media_type));
     3130        } else {
     3131            log_to_screen("%s found in drive. It's a Mondo disk.",
     3132                          media_descriptor_string(g_backup_media_type));
     3133            cd_number = atoi(last_line_of_file(szcdno));
     3134            sprintf(tmp, "cat %s 2> /dev/null", szserfname);
     3135            strcpy(our_serial_str,
     3136                   call_program_and_get_last_line_of_output(tmp));
     3137            // FIXME - should be able to use last_line_of_file(), surely?
     3138        }
     3139        run_program_and_log_output(szunmount, 1);
     3140        log_msg(2, "paafcd: cd_number = %d", cd_number);
     3141        log_msg(2, "our serial str = %s; g_serial_string = %s",
     3142                our_serial_str, g_serial_string);
     3143        if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
     3144            log_msg(2, "This %s is part of this backup set!",
     3145                    media_descriptor_string(g_backup_media_type));
     3146            ok_go_ahead_burn_it = FALSE;
     3147            if (cd_number == g_current_media_number - 1) {
     3148                log_to_screen
     3149                    ("I think you've left the previous %s in the drive.",
     3150                     media_descriptor_string(g_backup_media_type));
     3151            } else {
     3152                log_to_screen
     3153                    ("Please remove this %s. It is part of the backup set you're making now.",
     3154                     media_descriptor_string(g_backup_media_type));
     3155            }
     3156        } else {
     3157            log_to_screen("...but not part of _our_ backup set.");
     3158        }
     3159    } else {
     3160        log_msg(2,
     3161                "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
     3162                media_descriptor_string(g_backup_media_type));
     3163        if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
     3164            ok_go_ahead_burn_it = FALSE;
     3165            log_to_screen("There isn't a writable %s in the drive.",
     3166                          media_descriptor_string(g_backup_media_type));
     3167        }
     3168    }
    30773169
    30783170/*
     
    30843176*/
    30853177
    3086   if (!ok_go_ahead_burn_it)
    3087     {
    3088       eject_device(cdrom_dev);
    3089       sprintf (tmp,
    3090            "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    3091             media_descriptor_string(g_backup_media_type),
    3092            g_current_media_number,
    3093            media_descriptor_string(g_backup_media_type));
    3094       popup_and_OK (tmp);
    3095       goto gotos_make_me_puke;
    3096     }
    3097   else
    3098     {
    3099       log_msg(2, "paafcd: OK, going ahead and burning it.");
    3100     }
    3101 
    3102   log_msg (2,"paafcd: OK, I assume I have a blank/reusable %s in the drive...", media_descriptor_string(g_backup_media_type));
    3103 
    3104   //  if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
    3105 
    3106   log_to_screen ("Proceeding w/ %s in drive.", media_descriptor_string(g_backup_media_type));
    3107   paranoid_free(tmp);
    3108   paranoid_free(szmsg);
    3109   paranoid_free(cdrom_dev);
    3110   paranoid_free(cdrw_dev);
    3111   paranoid_free(mtpt);
    3112   paranoid_free(szcdno);
    3113   paranoid_free(szserfname);
    3114   paranoid_free(our_serial_str);
    3115   paranoid_free(szunmount);
    3116   if (pmountable)
    3117     {
    3118       if (attempt_to_mount_returned_this)
    3119         { *pmountable = FALSE; }
    3120       else
    3121         { *pmountable = TRUE; }
    3122     }
     3178    if (!ok_go_ahead_burn_it) {
     3179        eject_device(cdrom_dev);
     3180        sprintf(tmp,
     3181                "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
     3182                media_descriptor_string(g_backup_media_type),
     3183                g_current_media_number,
     3184                media_descriptor_string(g_backup_media_type));
     3185        popup_and_OK(tmp);
     3186        goto gotos_make_me_puke;
     3187    } else {
     3188        log_msg(2, "paafcd: OK, going ahead and burning it.");
     3189    }
     3190
     3191    log_msg(2,
     3192            "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
     3193            media_descriptor_string(g_backup_media_type));
     3194
     3195    //  if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
     3196
     3197    log_to_screen("Proceeding w/ %s in drive.",
     3198                  media_descriptor_string(g_backup_media_type));
     3199    paranoid_free(tmp);
     3200    paranoid_free(szmsg);
     3201    paranoid_free(cdrom_dev);
     3202    paranoid_free(cdrw_dev);
     3203    paranoid_free(mtpt);
     3204    paranoid_free(szcdno);
     3205    paranoid_free(szserfname);
     3206    paranoid_free(our_serial_str);
     3207    paranoid_free(szunmount);
     3208    if (pmountable) {
     3209        if (attempt_to_mount_returned_this) {
     3210            *pmountable = FALSE;
     3211        } else {
     3212            *pmountable = TRUE;
     3213        }
     3214    }
    31233215
    31243216}
     
    31383230 * @see get_bit_N_of_array
    31393231 */
    3140 void set_bit_N_of_array(char*array, int N, bool true_or_false)
     3232void set_bit_N_of_array(char *array, int N, bool true_or_false)
    31413233{
    3142   int bit_number;
    3143   int mask, orig_val, to_add;
    3144   int element_number;
    3145 
    3146   assert(array!=NULL);
    3147 
    3148   element_number = N / 8;
    3149   bit_number = N % 8;
    3150   to_add = (1 << bit_number);
    3151   mask = 255 - to_add;
    3152   orig_val = array[element_number] & mask;
    3153   //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
    3154   if (true_or_false) { array[element_number] = orig_val | to_add; }
     3234    int bit_number;
     3235    int mask, orig_val, to_add;
     3236    int element_number;
     3237
     3238    assert(array != NULL);
     3239
     3240    element_number = N / 8;
     3241    bit_number = N % 8;
     3242    to_add = (1 << bit_number);
     3243    mask = 255 - to_add;
     3244    orig_val = array[element_number] & mask;
     3245    //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
     3246    if (true_or_false) {
     3247        array[element_number] = orig_val | to_add;
     3248    }
    31553249}
    31563250
     
    31843278 */
    31853279int
    3186 slice_up_file_etc (struct s_bkpinfo *bkpinfo, char *biggie_filename, char *partimagehack_fifo,
    3187            long biggie_file_number, long noof_biggie_files, bool use_partimagehack)
     3280slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
     3281                  char *partimagehack_fifo, long biggie_file_number,
     3282                  long noof_biggie_files, bool use_partimagehack)
    31883283{
    31893284
    3190     /*@ buffers ***************************************************/
    3191   char *tmp, *checksum_line, *command;
    3192   char *tempblock;
    3193   char *curr_slice_fname_uncompressed;
    3194   char *curr_slice_fname_compressed;
    3195   char *file_to_archive;
    3196   char *file_to_openin;
    3197     /*@ pointers ***************************************************/
    3198   char *pB;
    3199   FILE *fin, *fout;
    3200 
    3201     /*@ bool *******************************************************/
    3202   bool finished = FALSE;
    3203 
    3204     /*@ long *******************************************************/
    3205   size_t blksize = 0;
    3206   long slice_num = 0;
    3207   long i;
    3208   long optimal_set_size;
    3209   bool should_I_compress_slices;
    3210   char *suffix; // for compressed slices
    3211 
    3212     /*@ long long ***************************************************/
    3213   long long totalread = 0;
    3214   long long totallength = 0;
    3215   long long length;
    3216 
    3217   /*@ int *********************************************************/
    3218   int retval = 0;
    3219   int res = 0;
    3220 
    3221     /*@ structures ***************************************************/
    3222   struct s_filename_and_lstat_info biggiestruct;
     3285    /*@ buffers ************************************************** */
     3286    char *tmp, *checksum_line, *command;
     3287    char *tempblock;
     3288    char *curr_slice_fname_uncompressed;
     3289    char *curr_slice_fname_compressed;
     3290    char *file_to_archive;
     3291    char *file_to_openin;
     3292    /*@ pointers ************************************************** */
     3293    char *pB;
     3294    FILE *fin, *fout;
     3295
     3296    /*@ bool ****************************************************** */
     3297    bool finished = FALSE;
     3298
     3299    /*@ long ****************************************************** */
     3300    size_t blksize = 0;
     3301    long slice_num = 0;
     3302    long i;
     3303    long optimal_set_size;
     3304    bool should_I_compress_slices;
     3305    char *suffix;               // for compressed slices
     3306
     3307    /*@ long long ************************************************** */
     3308    long long totalread = 0;
     3309    long long totallength = 0;
     3310    long long length;
     3311
     3312    /*@ int ******************************************************** */
     3313    int retval = 0;
     3314    int res = 0;
     3315
     3316    /*@ structures ************************************************** */
     3317    struct s_filename_and_lstat_info biggiestruct;
    32233318//  struct stat statbuf;
    32243319
    3225   assert(bkpinfo!=NULL);
    3226   assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    3227   malloc_string(tmp);
    3228   malloc_string(checksum_line);
    3229   malloc_string(curr_slice_fname_uncompressed);
    3230   malloc_string(curr_slice_fname_compressed);
    3231   malloc_string(file_to_archive);
    3232   malloc_string(suffix);
    3233   command = malloc(MAX_STR_LEN*8);
    3234 
    3235   biggiestruct.for_backward_compatibility = '\n';
    3236   biggiestruct.use_partimagehack = use_partimagehack;
    3237   if (!(tempblock = (char*)malloc(256*1024))) { fatal_error("malloc error 256*1024"); }
    3238   optimal_set_size = bkpinfo->optimal_set_size;
    3239   if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0)
    3240     {
    3241       suffix[0] = '\0';
    3242       //      log_it("%s is indeed compressed :-)", filename);
    3243       should_I_compress_slices = FALSE;
    3244     }
    3245   else
    3246     {
    3247       strcpy(suffix, bkpinfo->zip_suffix);
    3248       should_I_compress_slices = TRUE;
    3249     }
    3250 
    3251   if (optimal_set_size < 999)
    3252     {
    3253       fatal_error ("bkpinfo->optimal_set_size is insanely small");
    3254     }
    3255   if (partimagehack_fifo)
    3256     {
    3257       file_to_openin = partimagehack_fifo;
    3258       strcpy (checksum_line, "IGNORE");
    3259       log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    3260     }
    3261   else
    3262     {
    3263       file_to_openin = biggie_filename;
    3264       sprintf (command, "md5sum '%s'", biggie_filename);
    3265       if (!(fin = popen (command, "r"))) { log_OS_error("Unable to popen-in command"); return(1); }
    3266       (void) fgets (checksum_line, MAX_STR_LEN, fin);
    3267       pclose (fin);
    3268     }
    3269   lstat (biggie_filename, &biggiestruct.properties);
    3270   strcpy (biggiestruct.filename, biggie_filename);
    3271   pB = strchr(checksum_line, ' ');
    3272   if (!pB) { pB = strchr(checksum_line, '\t'); }
    3273   if (pB) { *pB='\0'; }
    3274   strcpy (biggiestruct.checksum, checksum_line);
    3275 
    3276   strcpy (tmp, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""));
    3277   fout = fopen (tmp, "w");
    3278   (void) fwrite((void*)&biggiestruct, 1, sizeof(biggiestruct), fout);
    3279   paranoid_fclose (fout);
    3280   totallength = length_of_file (biggie_filename);
    3281   length      = totallength / optimal_set_size / 1024;
    3282   log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin);
    3283   if (!(fin = fopen(file_to_openin, "r")))
    3284     {
    3285       log_OS_error("Unable to openin biggie_filename");
    3286       sprintf (tmp, "Cannot archive bigfile '%s': not found", biggie_filename);
    3287       log_to_screen (tmp);
    3288       paranoid_free(tempblock);
    3289       paranoid_free(tmp);
    3290       paranoid_free(checksum_line);
    3291       paranoid_free(command);
    3292       return (1);
    3293     }
    3294   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3295     { res = move_files_to_stream (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3296   else
    3297     { res = move_files_to_cd (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3298   i = bkpinfo->optimal_set_size / 256;
    3299   for (slice_num = 1; !finished; slice_num++)
    3300     {
    3301       strcpy (curr_slice_fname_uncompressed,
    3302           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir,
    3303                ""));
    3304       strcpy (curr_slice_fname_compressed,
    3305           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
    3306 
    3307       strcpy (tmp, percent_media_full_comment (bkpinfo));
    3308       update_progress_form (tmp);
    3309       if (!(fout = fopen (curr_slice_fname_uncompressed, "w"))) { log_OS_error(curr_slice_fname_uncompressed); return(1); }
    3310       if ( (i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength) )
    3311     {
    3312       for (i = 0; i < bkpinfo->optimal_set_size / 256; i++)
    3313         {
    3314           blksize = fread (tempblock, 1, 256 * 1024, fin);
    3315           if (blksize > 0)
     3320    assert(bkpinfo != NULL);
     3321    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
     3322    malloc_string(tmp);
     3323    malloc_string(checksum_line);
     3324    malloc_string(curr_slice_fname_uncompressed);
     3325    malloc_string(curr_slice_fname_compressed);
     3326    malloc_string(file_to_archive);
     3327    malloc_string(suffix);
     3328    command = malloc(MAX_STR_LEN * 8);
     3329
     3330    biggiestruct.for_backward_compatibility = '\n';
     3331    biggiestruct.use_partimagehack = use_partimagehack;
     3332    if (!(tempblock = (char *) malloc(256 * 1024))) {
     3333        fatal_error("malloc error 256*1024");
     3334    }
     3335    optimal_set_size = bkpinfo->optimal_set_size;
     3336    if (is_this_file_compressed(biggie_filename)
     3337        || bkpinfo->compression_level == 0) {
     3338        suffix[0] = '\0';
     3339        //      log_it("%s is indeed compressed :-)", filename);
     3340        should_I_compress_slices = FALSE;
     3341    } else {
     3342        strcpy(suffix, bkpinfo->zip_suffix);
     3343        should_I_compress_slices = TRUE;
     3344    }
     3345
     3346    if (optimal_set_size < 999) {
     3347        fatal_error("bkpinfo->optimal_set_size is insanely small");
     3348    }
     3349    if (partimagehack_fifo) {
     3350        file_to_openin = partimagehack_fifo;
     3351        strcpy(checksum_line, "IGNORE");
     3352        log_msg(2,
     3353                "Not calculating checksum for %s: it would take too long",
     3354                biggie_filename);
     3355    } else {
     3356        file_to_openin = biggie_filename;
     3357        sprintf(command, "md5sum '%s'", biggie_filename);
     3358        if (!(fin = popen(command, "r"))) {
     3359            log_OS_error("Unable to popen-in command");
     3360            return (1);
     3361        }
     3362        (void) fgets(checksum_line, MAX_STR_LEN, fin);
     3363        pclose(fin);
     3364    }
     3365    lstat(biggie_filename, &biggiestruct.properties);
     3366    strcpy(biggiestruct.filename, biggie_filename);
     3367    pB = strchr(checksum_line, ' ');
     3368    if (!pB) {
     3369        pB = strchr(checksum_line, '\t');
     3370    }
     3371    if (pB) {
     3372        *pB = '\0';
     3373    }
     3374    strcpy(biggiestruct.checksum, checksum_line);
     3375
     3376    strcpy(tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3377    fout = fopen(tmp, "w");
     3378    (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
     3379    paranoid_fclose(fout);
     3380    totallength = length_of_file(biggie_filename);
     3381    length = totallength / optimal_set_size / 1024;
     3382    log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
     3383            file_to_openin);
     3384    if (!(fin = fopen(file_to_openin, "r"))) {
     3385        log_OS_error("Unable to openin biggie_filename");
     3386        sprintf(tmp, "Cannot archive bigfile '%s': not found",
     3387                biggie_filename);
     3388        log_to_screen(tmp);
     3389        paranoid_free(tempblock);
     3390        paranoid_free(tmp);
     3391        paranoid_free(checksum_line);
     3392        paranoid_free(command);
     3393        return (1);
     3394    }
     3395    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3396        res =
     3397            move_files_to_stream(bkpinfo,
     3398                                 slice_fname(biggie_file_number, 0,
     3399                                             bkpinfo->tmpdir, ""), NULL);
     3400    } else {
     3401        res =
     3402            move_files_to_cd(bkpinfo,
     3403                             slice_fname(biggie_file_number, 0,
     3404                                         bkpinfo->tmpdir, ""), NULL);
     3405    }
     3406    i = bkpinfo->optimal_set_size / 256;
     3407    for (slice_num = 1; !finished; slice_num++) {
     3408        strcpy(curr_slice_fname_uncompressed,
     3409               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
     3410                           ""));
     3411        strcpy(curr_slice_fname_compressed,
     3412               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
     3413                           suffix));
     3414
     3415        strcpy(tmp, percent_media_full_comment(bkpinfo));
     3416        update_progress_form(tmp);
     3417        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
     3418            log_OS_error(curr_slice_fname_uncompressed);
     3419            return (1);
     3420        }
     3421        if ((i == bkpinfo->optimal_set_size / 256)
     3422            && (totalread < 1.1 * totallength)) {
     3423            for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
     3424                blksize = fread(tempblock, 1, 256 * 1024, fin);
     3425                if (blksize > 0) {
     3426                    totalread = totalread + blksize;
     3427                    (void) fwrite(tempblock, 1, blksize, fout);
     3428                } else {
     3429                    break;
     3430                }
     3431            }
     3432        } else {
     3433            i = 0;
     3434        }
     3435        paranoid_fclose(fout);
     3436        if (i > 0)              // length_of_file (curr_slice_fname_uncompressed)
    33163437        {
    3317           totalread = totalread + blksize;
    3318           (void) fwrite (tempblock, 1, blksize, fout);
    3319         }
    3320           else
    3321         {
    3322           break;
    3323         }
    3324         }
    3325     }
    3326       else
    3327     {
    3328       i = 0;
    3329     }
    3330       paranoid_fclose (fout);
    3331       if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
    3332     {
    3333       if (!does_file_exist (curr_slice_fname_uncompressed))
    3334         {
    3335           log_msg (2,
    3336                "Warning - '%s' doesn't exist. How can I compress slice?",
    3337                curr_slice_fname_uncompressed);
    3338         }
    3339           if (should_I_compress_slices && bkpinfo->compression_level>0)
    3340             {
    3341           sprintf (command, "%s -%d %s", bkpinfo->zip_exe,
    3342            bkpinfo->compression_level, curr_slice_fname_uncompressed);
    3343               log_msg (2, command);
    3344           if ((res = system (command))) { log_OS_error(command); }
    3345           //          did_I_compress_slice = TRUE;
    3346             }
    3347           else
    3348             {
    3349               sprintf (command, "mv %s %s 2>> %s", curr_slice_fname_uncompressed, curr_slice_fname_compressed, MONDO_LOGFILE);
    3350               res=0; // don't do it :)
    3351           //          did_I_compress_slice = FALSE;
    3352             }
    3353       retval += res;
    3354       if (res)
    3355         {
    3356           log_msg (2, "Failed to compress the slice");
    3357         }
    3358       if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed))
    3359         {
    3360           unlink (curr_slice_fname_uncompressed);
    3361         }
    3362       if (res)
    3363         {
    3364           sprintf (tmp, "Problem with slice # %ld", slice_num);
    3365         }
    3366       else
    3367         {
    3368           sprintf (tmp,
    3369                "%s - Bigfile #%ld, slice #%ld compressed OK          ",
    3370                biggie_filename, biggie_file_number + 1, slice_num);
    3371         }
     3438            if (!does_file_exist(curr_slice_fname_uncompressed)) {
     3439                log_msg(2,
     3440                        "Warning - '%s' doesn't exist. How can I compress slice?",
     3441                        curr_slice_fname_uncompressed);
     3442            }
     3443            if (should_I_compress_slices && bkpinfo->compression_level > 0) {
     3444                sprintf(command, "%s -%d %s", bkpinfo->zip_exe,
     3445                        bkpinfo->compression_level,
     3446                        curr_slice_fname_uncompressed);
     3447                log_msg(2, command);
     3448                if ((res = system(command))) {
     3449                    log_OS_error(command);
     3450                }
     3451                //          did_I_compress_slice = TRUE;
     3452            } else {
     3453                sprintf(command, "mv %s %s 2>> %s",
     3454                        curr_slice_fname_uncompressed,
     3455                        curr_slice_fname_compressed, MONDO_LOGFILE);
     3456                res = 0;        // don't do it :)
     3457                //          did_I_compress_slice = FALSE;
     3458            }
     3459            retval += res;
     3460            if (res) {
     3461                log_msg(2, "Failed to compress the slice");
     3462            }
     3463            if (bkpinfo->use_lzo
     3464                && strcmp(curr_slice_fname_compressed,
     3465                          curr_slice_fname_uncompressed)) {
     3466                unlink(curr_slice_fname_uncompressed);
     3467            }
     3468            if (res) {
     3469                sprintf(tmp, "Problem with slice # %ld", slice_num);
     3470            } else {
     3471                sprintf(tmp,
     3472                        "%s - Bigfile #%ld, slice #%ld compressed OK          ",
     3473                        biggie_filename, biggie_file_number + 1,
     3474                        slice_num);
     3475            }
    33723476#ifndef _XWIN
    3373       if (!g_text_mode)
    3374         {
    3375           newtDrawRootText (0, g_noof_rows - 2, tmp);
    3376           newtRefresh ();
    3377         }
    3378       else
    3379         {
    3380           log_msg (2, tmp);
    3381         }
     3477            if (!g_text_mode) {
     3478                newtDrawRootText(0, g_noof_rows - 2, tmp);
     3479                newtRefresh();
     3480            } else {
     3481                log_msg(2, tmp);
     3482            }
    33823483#else
    3383         log_msg(2, tmp);
     3484            log_msg(2, tmp);
    33843485#endif
    3385         strcpy(file_to_archive, curr_slice_fname_compressed);
    3386       g_current_progress++;
    3387     }
    3388       else /* if i==0 then ... */
    3389     {
    3390       finished = TRUE;
    3391       strcpy (file_to_archive, curr_slice_fname_uncompressed);
    3392           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3393         {
    3394           break;
    3395         }
    3396     }
    3397 
    3398       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3399         {
    3400           register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive);
    3401           maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive);
    3402       res = move_files_to_stream (bkpinfo, file_to_archive, NULL);
    3403     }
    3404       else
    3405         {
    3406       res = move_files_to_cd (bkpinfo, file_to_archive, NULL);
    3407     }
    3408       retval += res;
    3409       if (res)
    3410     {
    3411       sprintf (tmp,
    3412            "Failed to add slice %ld of bigfile %ld to scratchdir",
    3413            slice_num, biggie_file_number+1);
    3414       log_to_screen (tmp);
    3415       fatal_error
    3416         ("Hard disk full. You should have bought a bigger one.");
    3417     }
    3418     }
    3419   paranoid_fclose (fin);
    3420   sprintf (tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
    3421   if (retval)
    3422     {
    3423       strcat (tmp, "...FAILED");
    3424     }
    3425   else
    3426     {
    3427       strcat (tmp, "...OK!");
    3428     }
    3429   log_msg (1, tmp);
    3430   paranoid_free(tempblock);
    3431   paranoid_free(tmp);
    3432   paranoid_free(checksum_line);
    3433   paranoid_free(command);
    3434   paranoid_free(curr_slice_fname_uncompressed);
    3435   paranoid_free(curr_slice_fname_compressed);
    3436   paranoid_free(file_to_archive);
    3437   paranoid_free(suffix);
    3438   return (retval);
     3486            strcpy(file_to_archive, curr_slice_fname_compressed);
     3487            g_current_progress++;
     3488        } else {                /* if i==0 then ... */
     3489
     3490            finished = TRUE;
     3491            strcpy(file_to_archive, curr_slice_fname_uncompressed);
     3492            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3493                break;
     3494            }
     3495        }
     3496
     3497        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3498            register_in_tape_catalog(biggieslice, biggie_file_number,
     3499                                     slice_num, file_to_archive);
     3500            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     3501                                                   file_to_archive);
     3502            res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
     3503        } else {
     3504            res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
     3505        }
     3506        retval += res;
     3507        if (res) {
     3508            sprintf(tmp,
     3509                    "Failed to add slice %ld of bigfile %ld to scratchdir",
     3510                    slice_num, biggie_file_number + 1);
     3511            log_to_screen(tmp);
     3512            fatal_error
     3513                ("Hard disk full. You should have bought a bigger one.");
     3514        }
     3515    }
     3516    paranoid_fclose(fin);
     3517    sprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
     3518    if (retval) {
     3519        strcat(tmp, "...FAILED");
     3520    } else {
     3521        strcat(tmp, "...OK!");
     3522    }
     3523    log_msg(1, tmp);
     3524    paranoid_free(tempblock);
     3525    paranoid_free(tmp);
     3526    paranoid_free(checksum_line);
     3527    paranoid_free(command);
     3528    paranoid_free(curr_slice_fname_uncompressed);
     3529    paranoid_free(curr_slice_fname_compressed);
     3530    paranoid_free(file_to_archive);
     3531    paranoid_free(suffix);
     3532    return (retval);
    34393533}
    34403534
     
    34563550 * @ingroup utilityGroup
    34573551 */
    3458 void
    3459 wipe_archives (char *d)
     3552void wipe_archives(char *d)
    34603553{
    3461     /*@ buffers **********************************************/
    3462   char *tmp;
    3463   char *dir;
    3464 
    3465   malloc_string(tmp);
    3466   malloc_string(dir);
    3467   assert_string_is_neither_NULL_nor_zerolength(d);
    3468 
    3469   sprintf (dir, "%s/archives", d);
    3470   sprintf (tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
    3471   run_program_and_log_output(tmp, FALSE);
    3472   sprintf (tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
    3473   run_program_and_log_output(tmp, FALSE);
    3474   sprintf (tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
    3475   run_program_and_log_output(tmp, FALSE);
    3476   sprintf (tmp, "rm -f %s/cklist*", dir);
    3477   run_program_and_log_output(tmp, FALSE);
    3478   sprintf (tmp, "rm -f %s/zero", dir);
    3479   run_program_and_log_output(tmp, FALSE);
    3480   log_msg(1, "Wiped %s's archives", dir);
    3481   sprintf (tmp, "ls -l %s", dir);
    3482   run_program_and_log_output (tmp, FALSE);
    3483   paranoid_free(tmp);
    3484   paranoid_free(dir);
     3554    /*@ buffers ********************************************* */
     3555    char *tmp;
     3556    char *dir;
     3557
     3558    malloc_string(tmp);
     3559    malloc_string(dir);
     3560    assert_string_is_neither_NULL_nor_zerolength(d);
     3561
     3562    sprintf(dir, "%s/archives", d);
     3563    sprintf(tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
     3564    run_program_and_log_output(tmp, FALSE);
     3565    sprintf(tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
     3566    run_program_and_log_output(tmp, FALSE);
     3567    sprintf(tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
     3568    run_program_and_log_output(tmp, FALSE);
     3569    sprintf(tmp, "rm -f %s/cklist*", dir);
     3570    run_program_and_log_output(tmp, FALSE);
     3571    sprintf(tmp, "rm -f %s/zero", dir);
     3572    run_program_and_log_output(tmp, FALSE);
     3573    log_msg(1, "Wiped %s's archives", dir);
     3574    sprintf(tmp, "ls -l %s", dir);
     3575    run_program_and_log_output(tmp, FALSE);
     3576    paranoid_free(tmp);
     3577    paranoid_free(dir);
    34853578}
    34863579
     
    35013594 * however, this occurs rarely.
    35023595 */
    3503 int
    3504 write_final_iso_if_necessary (struct s_bkpinfo *bkpinfo)
     3596int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
    35053597{
    3506     /*@ int ******************************************************/
    3507   int res;
    3508 
    3509     /*@ buffers ***************************************************/
    3510   char *tmp;
    3511 
    3512   malloc_string(tmp);
    3513   assert(bkpinfo!=NULL);
     3598    /*@ int ***************************************************** */
     3599    int res;
     3600
     3601    /*@ buffers ************************************************** */
     3602    char *tmp;
     3603
     3604    malloc_string(tmp);
     3605    assert(bkpinfo != NULL);
    35143606
    35153607// I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway
    35163608
    3517   sprintf(tmp, "Writing the final ISO");
    3518   log_msg(2, tmp);
    3519   center_string (tmp, 80);
     3609    sprintf(tmp, "Writing the final ISO");
     3610    log_msg(2, tmp);
     3611    center_string(tmp, 80);
    35203612#ifndef _XWIN
    3521   if (!g_text_mode)
    3522     {
    3523       newtPushHelpLine (tmp);
    3524     }
     3613    if (!g_text_mode) {
     3614        newtPushHelpLine(tmp);
     3615    }
    35253616#endif
    3526   res = write_iso_and_go_on (bkpinfo, TRUE);
     3617    res = write_iso_and_go_on(bkpinfo, TRUE);
    35273618#ifndef _XWIN
    3528   if (!g_text_mode)
    3529     {
    3530       newtPopHelpLine ();
    3531     }
     3619    if (!g_text_mode) {
     3620        newtPopHelpLine();
     3621    }
    35323622#endif
    3533   log_msg (2, "Returning from writing final ISO (res=%d)", res);
    3534   paranoid_free(tmp);
    3535   return (res);
     3623    log_msg(2, "Returning from writing final ISO (res=%d)", res);
     3624    paranoid_free(tmp);
     3625    return (res);
    35363626}
    35373627
     
    35543644 * @see make_iso_fs
    35553645 */
    3556 int
    3557 write_iso_and_go_on (struct s_bkpinfo *bkpinfo, bool last_cd)
     3646int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
    35583647{
    3559     /*@ pointers *****************************************************/
    3560   FILE *fout;
    3561 
    3562     /*@ buffers ******************************************************/
    3563   char *tmp;
    3564   char *cdno_fname;
    3565   char *lastcd_fname;
    3566   char *isofile;
    3567 
    3568     /*@ bool *********************************************************/
    3569   bool that_one_was_ok;
    3570   bool using_nfs;
    3571   bool orig_vfy_flag_val;
    3572 
    3573     /*@ int ************************************************************/
    3574   int res = 0;
    3575 
    3576   malloc_string(tmp);
    3577   malloc_string(cdno_fname);
    3578   malloc_string(lastcd_fname);
    3579   malloc_string(isofile);
    3580  
    3581   assert(bkpinfo!=NULL);
    3582   orig_vfy_flag_val = bkpinfo->verify_data;
    3583   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "write_iso_and_go_on() - unknown media size"); }
    3584 
    3585   if (strlen (bkpinfo->nfs_mount) > 1)
    3586     {
    3587       using_nfs = TRUE;
    3588     }
    3589   else
    3590     {
    3591       using_nfs = FALSE;
    3592     }
    3593   log_msg (1, "OK, time to make %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    3594 
    3595   /* label the ISO with its number */
    3596 
    3597   sprintf (cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
    3598   fout = fopen (cdno_fname, "w");
    3599   fprintf (fout, "%d", g_current_media_number);
    3600   paranoid_fclose (fout);
    3601 
    3602   sprintf (tmp, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir);
    3603   if (run_program_and_log_output(tmp, FALSE))
    3604     { log_msg(2, "Warning - unable to copy autorun to scratchdir"); }
    3605 
    3606   /* last CD or not? Label accordingly */
    3607   sprintf (lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    3608   if (last_cd)
    3609     {
    3610       unlink (lastcd_fname);
    3611       log_msg (2, "OK, you're telling me this is the last CD. Fair enough.");
    3612     }
    3613   else
    3614     {
    3615       fout = fopen (lastcd_fname, "w");
    3616       fprintf (fout,
    3617            "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
    3618       paranoid_fclose (fout);
    3619     }
    3620   if (space_occupied_by_cd (bkpinfo->scratchdir) / 1024 > bkpinfo->media_size[g_current_media_number])
    3621     {
    3622       sprintf (tmp,
    3623            "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
    3624            (long) space_occupied_by_cd (bkpinfo->scratchdir),
    3625            (long) bkpinfo->media_size[g_current_media_number]);
    3626       log_to_screen (tmp);
    3627     }
    3628   sprintf (isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
    3629            bkpinfo->prefix, g_current_media_number);
    3630   for (that_one_was_ok = FALSE; !that_one_was_ok;)
    3631     {
    3632       res = make_iso_fs (bkpinfo, isofile);
    3633       if (g_current_media_number==1 && !res && ( bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw) )
    3634         {
    3635           if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
    3636             { log_msg(3, "*Sigh* Mike, I hate your computer."); bkpinfo->manual_cd_tray = TRUE; } // if it can't be found then force pausing
    3637           else
    3638             { log_msg(3, "Great. Found Mike's CD-ROM drive."); }
    3639         }
    3640       if (bkpinfo->verify_data && !res)
    3641     {
    3642       log_to_screen
    3643         ("Please reboot from the 1st %s in Compare Mode, as a precaution.", media_descriptor_string(g_backup_media_type));
    3644       chdir ("/");
    3645       iamhere("Before calling verify_cd_image()");
    3646       res += verify_cd_image (bkpinfo);
    3647       iamhere("After calling verify_cd_image()");
    3648     }
    3649       if (!res)
    3650     {
    3651       that_one_was_ok = TRUE;
    3652     }
    3653       else
    3654     {
    3655       sprintf (tmp, "Failed to burn %s #%d. Retry?",
    3656             media_descriptor_string(bkpinfo->backup_media_type),
    3657            g_current_media_number);
    3658       res = ask_me_yes_or_no (tmp);
    3659       if (!res)
    3660         {
    3661           if (ask_me_yes_or_no ("Abort the backup?"))
    3662         {
    3663           fatal_error ("FAILED TO BACKUP");
    3664         }
    3665           else
    3666         {
    3667           break;
    3668         }
    3669         }
    3670       else
    3671         {
    3672           log_msg (2, "Retrying, at user's request...");
    3673           res = 0;
    3674         }
    3675     }
    3676     }
     3648    /*@ pointers **************************************************** */
     3649    FILE *fout;
     3650
     3651    /*@ buffers ***************************************************** */
     3652    char *tmp;
     3653    char *cdno_fname;
     3654    char *lastcd_fname;
     3655    char *isofile;
     3656
     3657    /*@ bool ******************************************************** */
     3658    bool that_one_was_ok;
     3659    bool using_nfs;
     3660    bool orig_vfy_flag_val;
     3661
     3662    /*@ int *********************************************************** */
     3663    int res = 0;
     3664
     3665    malloc_string(tmp);
     3666    malloc_string(cdno_fname);
     3667    malloc_string(lastcd_fname);
     3668    malloc_string(isofile);
     3669
     3670    assert(bkpinfo != NULL);
     3671    orig_vfy_flag_val = bkpinfo->verify_data;
     3672    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     3673        fatal_error("write_iso_and_go_on() - unknown media size");
     3674    }
     3675
     3676    if (strlen(bkpinfo->nfs_mount) > 1) {
     3677        using_nfs = TRUE;
     3678    } else {
     3679        using_nfs = FALSE;
     3680    }
     3681    log_msg(1, "OK, time to make %s #%d",
     3682            media_descriptor_string(bkpinfo->backup_media_type),
     3683            g_current_media_number);
     3684
     3685    /* label the ISO with its number */
     3686
     3687    sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
     3688    fout = fopen(cdno_fname, "w");
     3689    fprintf(fout, "%d", g_current_media_number);
     3690    paranoid_fclose(fout);
     3691
     3692    sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home,
     3693            bkpinfo->scratchdir);
     3694    if (run_program_and_log_output(tmp, FALSE)) {
     3695        log_msg(2, "Warning - unable to copy autorun to scratchdir");
     3696    }
     3697
     3698    /* last CD or not? Label accordingly */
     3699    sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     3700    if (last_cd) {
     3701        unlink(lastcd_fname);
     3702        log_msg(2,
     3703                "OK, you're telling me this is the last CD. Fair enough.");
     3704    } else {
     3705        fout = fopen(lastcd_fname, "w");
     3706        fprintf(fout,
     3707                "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
     3708        paranoid_fclose(fout);
     3709    }
     3710    if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
     3711        bkpinfo->media_size[g_current_media_number]) {
     3712        sprintf(tmp,
     3713                "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
     3714                (long) space_occupied_by_cd(bkpinfo->scratchdir),
     3715                (long) bkpinfo->media_size[g_current_media_number]);
     3716        log_to_screen(tmp);
     3717    }
     3718    sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     3719            bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     3720            g_current_media_number);
     3721    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
     3722        res = make_iso_fs(bkpinfo, isofile);
     3723        if (g_current_media_number == 1 && !res
     3724            && (bkpinfo->backup_media_type == cdr
     3725                || bkpinfo->backup_media_type == cdrw)) {
     3726            if (find_cdrom_device(tmp, FALSE))  // make sure find_cdrom_device() finds, records CD-R's loc
     3727            {
     3728                log_msg(3, "*Sigh* Mike, I hate your computer.");
     3729                bkpinfo->manual_cd_tray = TRUE;
     3730            }                   // if it can't be found then force pausing
     3731            else {
     3732                log_msg(3, "Great. Found Mike's CD-ROM drive.");
     3733            }
     3734        }
     3735        if (bkpinfo->verify_data && !res) {
     3736            log_to_screen
     3737                ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
     3738                 media_descriptor_string(g_backup_media_type));
     3739            chdir("/");
     3740            iamhere("Before calling verify_cd_image()");
     3741            res += verify_cd_image(bkpinfo);
     3742            iamhere("After calling verify_cd_image()");
     3743        }
     3744        if (!res) {
     3745            that_one_was_ok = TRUE;
     3746        } else {
     3747            sprintf(tmp, "Failed to burn %s #%d. Retry?",
     3748                    media_descriptor_string(bkpinfo->backup_media_type),
     3749                    g_current_media_number);
     3750            res = ask_me_yes_or_no(tmp);
     3751            if (!res) {
     3752                if (ask_me_yes_or_no("Abort the backup?")) {
     3753                    fatal_error("FAILED TO BACKUP");
     3754                } else {
     3755                    break;
     3756                }
     3757            } else {
     3758                log_msg(2, "Retrying, at user's request...");
     3759                res = 0;
     3760            }
     3761        }
     3762    }
    36773763/*
    36783764  if (using_nfs)
     
    36833769    }
    36843770*/
    3685   g_current_media_number++;
    3686   if (g_current_media_number > MAX_NOOF_MEDIA) { fatal_error("Too many CD-R(W)'s. Use tape or net."); }
    3687   wipe_archives (bkpinfo->scratchdir);
    3688   sprintf (tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
    3689        bkpinfo->scratchdir, bkpinfo->scratchdir);
    3690   if (system (tmp))
    3691     {
    3692       log_msg
    3693     (2, "Error occurred when I tried to delete the redundant IMGs and GZs");
    3694     }
    3695 
    3696   if (last_cd)
    3697     {
    3698       log_msg (2, "This was your last CD.");
    3699     }
    3700   else
    3701     {
    3702       log_msg (2, "Continuing to backup your data...");
    3703     }
    3704 
    3705   bkpinfo->verify_data = orig_vfy_flag_val;
    3706   paranoid_free(tmp);
    3707   paranoid_free(cdno_fname);
    3708   paranoid_free(lastcd_fname);
    3709   paranoid_free(isofile);
    3710   return (0);
     3771    g_current_media_number++;
     3772    if (g_current_media_number > MAX_NOOF_MEDIA) {
     3773        fatal_error("Too many CD-R(W)'s. Use tape or net.");
     3774    }
     3775    wipe_archives(bkpinfo->scratchdir);
     3776    sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
     3777            bkpinfo->scratchdir, bkpinfo->scratchdir);
     3778    if (system(tmp)) {
     3779        log_msg
     3780            (2,
     3781             "Error occurred when I tried to delete the redundant IMGs and GZs");
     3782    }
     3783
     3784    if (last_cd) {
     3785        log_msg(2, "This was your last CD.");
     3786    } else {
     3787        log_msg(2, "Continuing to backup your data...");
     3788    }
     3789
     3790    bkpinfo->verify_data = orig_vfy_flag_val;
     3791    paranoid_free(tmp);
     3792    paranoid_free(cdno_fname);
     3793    paranoid_free(lastcd_fname);
     3794    paranoid_free(isofile);
     3795    return (0);
    37113796}
    37123797
     
    37293814int verify_data(struct s_bkpinfo *bkpinfo)
    37303815{
    3731     int res=0, retval=0, cdno=0;
    3732     char *tmp;
    3733     long diffs=0;
    3734 
    3735   malloc_string(tmp);
    3736   assert(bkpinfo!=NULL); 
    3737       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     3816    int res = 0, retval = 0, cdno = 0;
     3817    char *tmp;
     3818    long diffs = 0;
     3819
     3820    malloc_string(tmp);
     3821    assert(bkpinfo != NULL);
     3822    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3823        chdir("/");
     3824        mvaddstr_and_log_it(g_currentY, 0,
     3825                            "Verifying archives against live filesystem");
     3826        if (bkpinfo->backup_media_type == cdstream) {
     3827            strcpy(bkpinfo->media_device, "/dev/cdrom");
     3828        }
     3829        verify_tape_backups(bkpinfo);
     3830        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     3831    } else if (bkpinfo->backup_data)
     3832        //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    37383833    {
    3739       chdir ("/");
    3740       mvaddstr_and_log_it (g_currentY, 0,
    3741                    "Verifying archives against live filesystem");
    3742       if (bkpinfo->backup_media_type == cdstream)
    3743         {
    3744           strcpy (bkpinfo->media_device, "/dev/cdrom");
    3745         }
    3746       verify_tape_backups (bkpinfo);
    3747       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    3748     }
    3749       else if (bkpinfo->backup_data)
    3750     //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    3751         {
    3752           log_msg (2, "Not verifying again. Per-CD/ISO verification already carried out.");
    3753           paranoid_system("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
    3754         }
    3755       else
    3756     {
    3757           g_current_media_number = cdno;
    3758       if (bkpinfo->backup_media_type != iso)
    3759         {
    3760           find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
    3761         }
    3762       chdir ("/");
    3763       for (cdno = 1;
    3764            cdno < 99 && bkpinfo->verify_data;
    3765            cdno++)
    3766         {
    3767           if (cdno != g_current_media_number)
    3768             {
    3769           log_msg (2, "Warning - had to change g_current_media_number from %d to %d", g_current_media_number, cdno);
    3770           g_current_media_number = cdno;
    3771         }       
    3772           if (bkpinfo->backup_media_type != iso)
    3773         {
    3774           insist_on_this_cd_number (bkpinfo, cdno);
    3775         }
    3776           res = verify_cd_image (bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
    3777           retval += res;
    3778           if (res)
    3779         {
    3780           sprintf (tmp,
    3781                "Warnings/errors were reported while checking %s #%d",
    3782                media_descriptor_string(bkpinfo->backup_media_type),
    3783                g_current_media_number);
    3784           log_to_screen (tmp);
    3785 
    3786         }
    3787         }
     3834        log_msg(2,
     3835                "Not verifying again. Per-CD/ISO verification already carried out.");
     3836        paranoid_system
     3837            ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
     3838    } else {
     3839        g_current_media_number = cdno;
     3840        if (bkpinfo->backup_media_type != iso) {
     3841            find_cdrom_device(bkpinfo->media_device, FALSE);    // replace 0,0,0 with /dev/cdrom
     3842        }
     3843        chdir("/");
     3844        for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
     3845            if (cdno != g_current_media_number) {
     3846                log_msg(2,
     3847                        "Warning - had to change g_current_media_number from %d to %d",
     3848                        g_current_media_number, cdno);
     3849                g_current_media_number = cdno;
     3850            }
     3851            if (bkpinfo->backup_media_type != iso) {
     3852                insist_on_this_cd_number(bkpinfo, cdno);
     3853            }
     3854            res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
     3855            retval += res;
     3856            if (res) {
     3857                sprintf(tmp,
     3858                        "Warnings/errors were reported while checking %s #%d",
     3859                        media_descriptor_string(bkpinfo->
     3860                                                backup_media_type),
     3861                        g_current_media_number);
     3862                log_to_screen(tmp);
     3863
     3864            }
     3865        }
    37883866/*
    37893867      sprintf (tmp,
     
    37923870      system (tmp);
    37933871*/
    3794           sprintf (tmp,
    3795        "sed -n -e 's/afio: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
    3796        MONDO_LOGFILE);
    3797       system (tmp);
    3798          
    3799       sprintf (tmp,
    3800        "sed -n -e 's/star: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
    3801        MONDO_LOGFILE);
    3802       system (tmp);
    3803           run_program_and_log_output("umount "MNT_CDROM, FALSE);
    3804 //    if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
     3872        sprintf(tmp,
     3873                "sed -n -e 's/afio: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
     3874                MONDO_LOGFILE);
     3875        system(tmp);
     3876
     3877        sprintf(tmp,
     3878                "sed -n -e 's/star: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
     3879                MONDO_LOGFILE);
     3880        system(tmp);
     3881        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3882//    if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
    38053883//{
    3806           eject_device(bkpinfo->media_device);
     3884        eject_device(bkpinfo->media_device);
    38073885//}
    38083886    }
    3809       diffs = count_lines_in_file ("/tmp/changed.files");
    3810 
    3811       if (diffs > 0)
    3812     {
    3813           if (retval==0) { retval=(int)(-diffs); }
    3814     }
    3815   paranoid_free(tmp);
    3816  return(retval);
     3887    diffs = count_lines_in_file("/tmp/changed.files");
     3888
     3889    if (diffs > 0) {
     3890        if (retval == 0) {
     3891            retval = (int) (-diffs);
     3892        }
     3893    }
     3894    paranoid_free(tmp);
     3895    return (retval);
    38173896}
    38183897
     
    38323911 * @see write_image_to_floppy
    38333912 */
    3834 int
    3835 write_image_to_floppy_SUB (char *device, char *datafile)
     3913int write_image_to_floppy_SUB(char *device, char *datafile)
    38363914{
    3837     /*@ int ****************************************************************/
    3838   int res = 0;
     3915    /*@ int *************************************************************** */
     3916    int res = 0;
    38393917    int percentage = 0;
    38403918    int blockno = 0;
    3841     int maxblocks =0;
    3842 
    3843     /*@ buffers*************************************************************/
    3844   char *tmp;
     3919    int maxblocks = 0;
     3920
     3921    /*@ buffers************************************************************ */
     3922    char *tmp;
    38453923    char blk[1024];
    38463924    char *title;
    38473925
    3848     /*@ pointers ***********************************************************/
     3926    /*@ pointers ********************************************************** */
    38493927    char *p;
    3850   FILE *fout, *fin;
    3851 
    3852 
    3853   malloc_string(tmp);
    3854   malloc_string(title);
    3855   /* pretty stuff */
    3856   if (!(p = strrchr (datafile, '/')))
    3857     {
    3858       p = datafile;
    3859     }
    3860   else
    3861     {
    3862       p++;
    3863     }
    3864   sprintf (title, "Writing %s to floppy", p);
    3865   open_evalcall_form (title);
    3866   /* functional stuff */
    3867   for (p = device + strlen (device); p != device && isdigit (*(p - 1)); p--);
    3868   maxblocks = atoi (p);
    3869   if (!maxblocks) { maxblocks = 1440; }
    3870   sprintf (tmp, "maxblocks = %d; p=%s", maxblocks, p);
    3871   log_msg (2, tmp);
    3872   /* copy data from image to floppy */
    3873   if (!(fin = fopen (datafile, "r")))
    3874     {
    3875       log_OS_error ("Cannot open img");
    3876       return (1);
    3877     }
    3878   if (!(fout = fopen (device, "w")))
    3879     {
    3880       log_OS_error ("Cannot open fdd");
    3881       return (1);
    3882     }
    3883   for (blockno = 0; blockno < maxblocks; blockno++)
    3884     {
    3885       percentage = blockno * 100 / maxblocks;
    3886       if (fread (blk, 1, 1024, fin) != 1024)
    3887     {
    3888       if (feof(fin))
    3889         {
    3890           log_msg(1, "img read err - img ended prematurely - non-fatal error");
    3891           sleep(3);
    3892           return(res);
    3893         }
    3894       res++;
    3895       log_to_screen ("img read err");
    3896     }
    3897       if (fwrite (blk, 1, 1024, fout) != 1024)
    3898     {
    3899       res++;
    3900       log_to_screen ("fdd write err");
    3901     }
    3902       if (((blockno + 1) % 128) == 0)
    3903     {
    3904       paranoid_system ("sync"); /* fflush doesn't work; dunno why */
    3905       update_evalcall_form (percentage);
    3906     }
    3907     }
    3908   paranoid_fclose (fin);
    3909   paranoid_fclose(fout);
    3910   paranoid_free(tmp);
    3911   paranoid_free(title);
    3912   close_evalcall_form ();
    3913   return (res);
     3928    FILE *fout, *fin;
     3929
     3930
     3931    malloc_string(tmp);
     3932    malloc_string(title);
     3933    /* pretty stuff */
     3934    if (!(p = strrchr(datafile, '/'))) {
     3935        p = datafile;
     3936    } else {
     3937        p++;
     3938    }
     3939    sprintf(title, "Writing %s to floppy", p);
     3940    open_evalcall_form(title);
     3941    /* functional stuff */
     3942    for (p = device + strlen(device); p != device && isdigit(*(p - 1));
     3943         p--);
     3944    maxblocks = atoi(p);
     3945    if (!maxblocks) {
     3946        maxblocks = 1440;
     3947    }
     3948    sprintf(tmp, "maxblocks = %d; p=%s", maxblocks, p);
     3949    log_msg(2, tmp);
     3950    /* copy data from image to floppy */
     3951    if (!(fin = fopen(datafile, "r"))) {
     3952        log_OS_error("Cannot open img");
     3953        return (1);
     3954    }
     3955    if (!(fout = fopen(device, "w"))) {
     3956        log_OS_error("Cannot open fdd");
     3957        return (1);
     3958    }
     3959    for (blockno = 0; blockno < maxblocks; blockno++) {
     3960        percentage = blockno * 100 / maxblocks;
     3961        if (fread(blk, 1, 1024, fin) != 1024) {
     3962            if (feof(fin)) {
     3963                log_msg(1,
     3964                        "img read err - img ended prematurely - non-fatal error");
     3965                sleep(3);
     3966                return (res);
     3967            }
     3968            res++;
     3969            log_to_screen("img read err");
     3970        }
     3971        if (fwrite(blk, 1, 1024, fout) != 1024) {
     3972            res++;
     3973            log_to_screen("fdd write err");
     3974        }
     3975        if (((blockno + 1) % 128) == 0) {
     3976            paranoid_system("sync");    /* fflush doesn't work; dunno why */
     3977            update_evalcall_form(percentage);
     3978        }
     3979    }
     3980    paranoid_fclose(fin);
     3981    paranoid_fclose(fout);
     3982    paranoid_free(tmp);
     3983    paranoid_free(title);
     3984    close_evalcall_form();
     3985    return (res);
    39143986}
    39153987
     
    39284000 * @see write_image_to_floppy_SUB
    39294001 */
    3930 int
    3931 write_image_to_floppy (char *device, char *datafile)
     4002int write_image_to_floppy(char *device, char *datafile)
    39324003{
    3933     /*@ int ***************************************************************/
    3934   int res   = 0;
    3935 
    3936   assert_string_is_neither_NULL_nor_zerolength(device);
    3937   assert_string_is_neither_NULL_nor_zerolength(datafile);
    3938 
    3939   while ((res = write_image_to_floppy_SUB (device, datafile)))
    3940     {
    3941       if (!ask_me_yes_or_no ("Failed to write image to floppy. Retry?"))
    3942     {
    3943       return (res);
    3944     }
    3945     }
    3946   return (res);
     4004    /*@ int ************************************************************** */
     4005    int res = 0;
     4006
     4007    assert_string_is_neither_NULL_nor_zerolength(device);
     4008    assert_string_is_neither_NULL_nor_zerolength(datafile);
     4009
     4010    while ((res = write_image_to_floppy_SUB(device, datafile))) {
     4011        if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
     4012            return (res);
     4013        }
     4014    }
     4015    return (res);
    39474016}
    39484017
    39494018/* @} - end of utilityGroup */
    3950 
Note: See TracChangeset for help on using the changeset viewer.