Changeset 41 in MondoRescue


Ignore:
Timestamp:
Oct 3, 2005, 11:55:50 AM (19 years ago)
Author:
bcornec
Message:

asprintf introduction in libmondo-archive.c for 2.05 version
+ memory management revisions in that file

Location:
trunk/mondo
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/ChangeLog

    r30 r41  
    11MONDO CHANGES          Hugo Rabson <hugorabson@msn.com>             2005-09-09
    22
     3
     4v2.05_berlios (Bruno Cornec <bcornec@users.berlios.de)
     5- indent on source files
     6- asprintf used instead of malloc_string + sprintf/strcpy/strcat without
     7  verifications. Optimisations on memory consumption (allocate only size
     8  needed + remove memory leaks)
    39
    410v2.04_berlios (Bruno Cornec <bcornec@users.berlios.de)
  • trunk/mondo/configure.in

    r30 r41  
    55dnl Process this file with autoconf >=2.53 to produce a configure script.
    66dnl
    7 dnl $Id: configure.in,v 1.3 2004/06/18 18:40:30 oremanj Exp $
     7dnl $Id$
    88dnl
    9 AC_INIT([Mondo Rescue],[2.04_berlios],[mondo-devel@lists.sourceforge.net])
     9AC_INIT([Mondo Rescue],[2.05_berlios],[mondo-devel@lists.sourceforge.net])
    1010AC_CONFIG_SRCDIR([mondo/mondoarchive/main.c])
    1111AM_CONFIG_HEADER(config.h)
     
    1515AC_ARG_PROGRAM
    1616
    17 AM_INIT_AUTOMAKE([mondo], [2.04_berlios])
     17AM_INIT_AUTOMAKE([mondo], [2.05_berlios])
    1818AM_MAINTAINER_MODE
    1919
  • trunk/mondo/mondo.spec

    r35 r41  
    1111Summary(sp):    Un programa para los usuarios de Linux por crear una CD/cinta de restoracion/rescate
    1212Name:       mondo
    13 Version:    2.04_berlios
     13Version:    2.05_berlios
    1414Release:    1
    1515License:    GPL
     
    161161
    162162%changelog
     163* Tue Oct 06 2005 Bruno Cornec <bcornec@users.berlios.de> 2.05_berlios
     164- Memory management revision
     165
    163166* Tue Sep 06 2005 Bruno Cornec <bcornec@users.berlios.de> 2.04_berlios
    164167- Merge of patches mentionned on mondo ML + ia64 updates
     168- Option -p added
    165169
    166170* Tue May 03 2005 Hugo Rabson <hugorabson@msn.com> 2.04_cvs_20050503
  • trunk/mondo/mondo/common/libmondo-archive.c

    r30 r41  
    11/* libmondo-archive.c
    2    $Id: libmondo-archive.c,v 1.19 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33
    44subroutines to handle the archiving of files
     
    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@*/
    222 //static char cvsid[] = "$Id: libmondo-archive.c,v 1.19 2004/06/21 20:20:36 hugo Exp $";
     222//static char cvsid[] = "$Id$";
    223223
    224224/* *************************** external global vars ******************/
     
    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 *tmp;
     361    char *p;
     362
     363    if (!does_file_exist(filelist)) {
     364        asprintf(&tmp,
     365                 "(archive_this_fileset) - filelist %s does not exist",
     366                 filelist);
     367        log_to_screen(tmp);
     368        paranoid_free(tmp);
     369        return (1);
     370    }
     371
     372    asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
     373    if (system(tmp)) {
     374        fatal_error("Unable to write tarball to scratchdir");
     375    }
     376    paranoid_free(tmp);
     377
     378    asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
     379             filelist, fname);
     380    if (bkpinfo->use_lzo) {
     381        fatal_error("Can't use lzop");
     382    }
     383    if (bkpinfo->compression_level > 0) {
     384        asprintf(&tmp, "%s -bz", command);
     385        paranoid_free(command);
     386        command = tmp;
     387    }
     388    asprintf(&tmp, "%s 2>> %s", command, MONDO_LOGFILE);
     389    paranoid_free(command);
     390    command = tmp;
     391    log_msg(4, "command = '%s'", command);
     392
     393    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     394        log_msg(5, "command='%s'", command);
     395        res = system(command);
     396        asprintf(&tmp, "%s", last_line_of_file(MONDO_LOGFILE));
     397        log_msg(1, "res=%d; tmp='%s'", res, tmp);
     398        paranoid_free(tmp);
     399        if (bkpinfo->use_star && (res == 254 || res == 65024)
     400            && strstr(tmp, "star: Processed all possible files")
     401            && tries > 0) {
     402            log_msg(1, "Star returned nonfatal error");
     403            res = 0;
     404        }
     405        if (res) {
     406            log_OS_error(command);
     407            p = strstr(command, "-acl ");
     408            if (p) {
     409                p[0] = p[1] = p[2] = p[3] = ' ';
     410                log_msg(1, "new command = '%s'", command);
     411            } else {
     412                log_msg(3,
     413                        "Attempt #%d failed. Pausing 3 seconds and retrying...",
     414                        tries + 1);
     415                sleep(3);
     416            }
     417        }
     418    }
     419    retval += res;
     420    if (retval) {
     421        log_msg(3, "Failed to write set %d", setno);
     422    } else if (tries > 1) {
     423        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     424                tries);
     425    }
     426
     427    paranoid_free(command);
     428    paranoid_free(tmp);
     429    return (retval);
    418430}
    419431
     
    436448 */
    437449int
    438 archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    439           int setno)
     450archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
     451                     char *fname, int setno)
    440452{
    441453
    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     }
     454    /*@ int ************************************************************ */
     455    int retval = 0;
     456    int res = 0;
     457    int i = 0;
     458    int tries = 0;
     459    static int free_ramdisk_space = 9999;
     460
     461    /*@ buffers ******************************************************** */
     462    char *command;
     463    char *zipparams;
     464    char *tmp, *tmp1;
     465
     466    assert(bkpinfo != NULL);
     467    assert_string_is_neither_NULL_nor_zerolength(filelist);
     468    assert_string_is_neither_NULL_nor_zerolength(fname);
     469
     470    if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
     471        return (archive_this_fileset_with_star
     472                (bkpinfo, filelist, fname, setno));
     473    }
     474
     475    if (!does_file_exist(filelist)) {
     476        asprintf(&tmp,
     477             "(archive_this_fileset) - filelist %s does not exist",
     478             filelist);
     479        log_to_screen(tmp);
     480        paranoid_free(tmp)
     481        return (1);
     482    }
     483    asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
     484    if (system(tmp)) {
     485        fatal_error("Unable to write tarball to scratchdir");
     486    }
     487    paranoid_free(tmp)
     488
     489
     490    if (bkpinfo->compression_level > 0) {
     491        asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
     492        //       -b %ld, TAPE_BLOCK_SIZE
     493        asprintf(&zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
     494                 bkpinfo->compression_level);
     495        if (does_file_exist(tmp)) {
     496            asprintf(&tmp1, "%s -E %s", zipparams, tmp);
     497            paranoid_free(zipparams)
     498            zipparams = tmp1;
     499        } else {
     500            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
     501        }
     502        paranoid_free(tmp)
     503    } else {
     504        asprintf(&zipparams, "");
     505    }
    494506
    495507//  make_hole_for_file(fname);
    496508
    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, "cat %s | afio -o -b %ld -M 16m %s %s 2>> %s", filelist, TAPE_BLOCK_SIZE, zipparams, fname, 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);
     509    if (!does_file_exist(bkpinfo->tmpdir)) {
     510        log_OS_error("tmpdir not found");
     511        fatal_error("tmpdir not found");
     512    }
     513    if (!does_file_exist(bkpinfo->scratchdir)) {
     514        log_OS_error("scratchdir not found");
     515        fatal_error("scratchdir not found");
     516    }
     517    asprintf(&command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
     518             fname, bkpinfo->zip_suffix);
     519    paranoid_system(command);
     520    paranoid_free(command);
     521
     522    asprintf(&command, "cat %s | afio -o -b %ld -M 16m %s %s 2>> %s",
     523             filelist, TAPE_BLOCK_SIZE, zipparams, fname, MONDO_LOGFILE);
     524    paranoid_free(zipparams);
     525
     526    asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
     527    if (system(tmp)) {
     528        fatal_error("Unable to write tarball to scratchdir");
     529    }
     530    paranoid_free(tmp);
     531
     532    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     533        log_msg(5, "command='%s'", command);
     534        res = system(command);
     535        if (res) {
     536            log_OS_error(command);
     537            log_msg(3,
     538                    "Attempt #%d failed. Pausing 3 seconds and retrying...",
     539                    tries + 1);
     540            sleep(3);
     541        }
     542    }
     543    retval += res;
     544    if (retval) {
     545        log_msg(3, "Failed to write set %d", setno);
     546    } else if (tries > 1) {
     547        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     548                tries);
     549    }
     550
     551    if (g_tmpfs_mountpt[0] != '\0') {
     552        i = atoi(call_program_and_get_last_line_of_output
     553                 ("df -m | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
     554        if (i > 0) {
     555            if (free_ramdisk_space > i) {
     556                free_ramdisk_space = i;
     557                log_msg(2, "min(free_ramdisk_space) is now %d",
     558                        free_ramdisk_space);
     559                if (free_ramdisk_space < 10) {
     560                    fatal_error
     561                        ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
     562                }
     563            }
     564        }
     565    }
     566    paranoid_free(command);
     567    return (retval);
    545568}
    546569
     
    564587int backup_data(struct s_bkpinfo *bkpinfo)
    565588{
    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         {
     589    int retval = 0, res = 0;
     590    char *tmp;
     591
     592    assert(bkpinfo != NULL);
     593    set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
     594    if (bkpinfo->backup_media_type == dvd) {
    574595#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."); }
     596        if (!find_home_of_exe("dvd+rw-format")) {
     597            fatal_error
     598                ("Cannot find dvd+rw-format. Please install it or fix your PATH.");
     599        }
    576600#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"); }
     601        if (!find_home_of_exe("growisofs")) {
     602            fatal_error
     603                ("Cannot find growisofs. Please install it or fix your PATH.");
     604        }
     605    }
     606
     607    if ((res = prepare_filelist(bkpinfo))) {    /* generate scratchdir/filelist.full */
     608        fatal_error("Failed to generate filelist catalog");
     609    }
     610    if (call_filelist_chopper(bkpinfo)) {
     611        fatal_error("Failed to run filelist chopper");
     612    }
    583613
    584614/*
    585       sprintf(tmp, "wc -l %s/archives/filelist.full > %s/archives/filelist.count",bkpinfo->scratchdir, bkpinfo->scratchdir);
     615      asprintf(&tmp, "wc -l %s/archives/filelist.full > %s/archives/filelist.count",bkpinfo->scratchdir, bkpinfo->scratchdir);
    586616      if (run_program_and_log_output(tmp, 2))
    587617        { fatal_error("Failed to count filelist.full"); }
    588618*/
    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
     619    asprintf(&tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
     620    if (run_program_and_log_output(tmp, 2)) {
     621        fatal_error("Failed to gzip filelist.full");
     622    }
     623    paranoid_free(tmp);
     624    asprintf(&tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
     625            bkpinfo->tmpdir);
     626    if (run_program_and_log_output(tmp, 2)) {
     627        fatal_error("Failed to copy to tmpdir");
     628    }
     629    paranoid_free(tmp);
     630
     631    copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo);  // payload, too, if it exists
    597632#if __FreeBSD__ == 5
    598       strcpy (bkpinfo->kernel_path, "/boot/kernel/kernel");
     633    strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
    599634#elif __FreeBSD__ == 4
    600       strcpy (bkpinfo->kernel_path, "/kernel");
     635    strcpy(bkpinfo->kernel_path, "/kernel");
    601636#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."); }
     637    if (figure_out_kernel_path_interactively_if_necessary
     638        (bkpinfo->kernel_path)) {
     639        fatal_error
     640            ("Kernel not found. Please specify manually with the '-k' switch.");
     641    }
    604642#else
    605643#error "I don't know about this system!"
    606644#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);
     645    if ((res = call_mindi_to_supply_boot_disks(bkpinfo))) {
     646        fatal_error("Failed to generate boot+data disks");
     647    }
     648    retval += do_that_initial_phase(bkpinfo);   // prepare
     649    asprintf(&tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
     650    run_program_and_log_output(tmp, 1);
     651    paranoid_free(tmp);
     652    retval += make_those_afios_phase(bkpinfo);  // backup regular files
     653    retval += make_those_slices_phase(bkpinfo); // backup BIG files
     654    retval += do_that_final_phase(bkpinfo); // clean up
     655    log_msg(1, "Creation of archives... complete.");
     656    if (bkpinfo->verify_data) {
     657        sleep(2);
     658    }
     659    return (retval);
    619660}
    620661
     
    648689 * @ingroup MLarchiveGroup
    649690 */
    650 int
    651 call_mindi_to_supply_boot_disks (struct s_bkpinfo *bkpinfo)
     691int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo)
    652692{
    653     /*@ buffer *************************************************************/
    654   char *tmp;
    655         char *scratchdir;
     693    /*@ buffer ************************************************************ */
     694    char *tmp;
     695    char *scratchdir;
    656696    char *command;
    657697    char *use_lzo_sz;
    658         char *use_comp_sz;
     698    char *use_comp_sz;
    659699    char *use_star_sz;
    660700    char *bootldr_str;
     
    665705    char *tape_size_sz;
    666706    char *devs_to_exclude;
    667         char *use_lilo_sz;
    668         char *value;
     707    char *use_lilo_sz;
     708    char *value;
    669709    char *bootdev;
    670710
    671711
    672712
    673     /*@ char ***************************************************************/
     713    /*@ char ************************************************************** */
    674714    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     {
     715
     716    /*@ long     ********************************************************** */
     717    long lines_in_filelist = 0;
     718
     719    /*@ int         ************************************************************* */
     720    int res = 0;
     721    long estimated_total_noof_slices = 0;
     722
     723    assert(bkpinfo != NULL);
     724
     725    asprintf(&tmp,
     726            "echo \"%s\" | tr -s ' ' '\n' | grep -x \"/dev/.*\" | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
     727            bkpinfo->exclude_paths);
     728    asprintf(&devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
     729    paranoid_free(tmp);
     730    asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     731    log_msg(2, tmp);
     732    paranoid_free(tmp);
     733    mvaddstr_and_log_it(g_currentY, 0,
     734                "Calling MINDI to create boot+data disks");
     735    asprintf(&tmp, "%s/filelist.full", bkpinfo->tmpdir);
     736    if (!does_file_exist(tmp)) {
     737        paranoid_free(tmp);
     738        asprintf(&tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
     739        if (!does_file_exist(tmp)) {
     740            fatal_error
     741                ("Cannot find filelist.full, so I cannot count its lines");
     742        }
     743    }
     744    lines_in_filelist = count_lines_in_file(tmp);
     745    paranoid_free(tmp);
     746    asprintf(&tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
     747    asprintf(&last_filelist_number, last_line_of_file(tmp));
     748    paranoid_free(tmp);
     749    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     750        asprintf(&tape_size_sz, "%ld", bkpinfo->media_size[1]);
     751        asprintf(&tape_device, "%s", bkpinfo->media_device);
     752    } else {
     753        asprintf(&tape_size_sz, "");
     754        asprintf(&tape_device, "");
     755    }
     756    if (bkpinfo->use_lzo) {
     757        asprintf(&use_lzo_sz, "yes");
     758    } else {
     759        asprintf(&use_lzo_sz, "no");
     760    }
     761    if (bkpinfo->use_star) {
     762        asprintf(&use_star_sz, "yes");
     763    } else {
     764        asprintf(&use_star_sz, "no");
     765    }
     766
     767    if (bkpinfo->compression_level > 0) {
     768        asprintf(&use_comp_sz, "yes");
     769    } else {
     770        asprintf(&use_comp_sz, "no");
     771    }
     772
     773    asprintf(&broken_bios_sz, "yes");   /* assume so */
     774    if (g_cd_recovery) {
     775        asprintf(&cd_recovery_sz, "yes");
     776    } else {
     777        asprintf(&cd_recovery_sz, "no");
     778    }
     779    /* BCO: shared between LILO/ELILO */
     780    if (bkpinfo->make_cd_use_lilo) {
     781        asprintf(&use_lilo_sz, "yes");
     782    } else {
     783        asprintf(&use_lilo_sz, "no");
     784    }
     785
     786    if (!bkpinfo->nonbootable_backup
     787        && (bkpinfo->boot_loader == '\0'
     788            || bkpinfo->boot_device[0] == '\0')) {
    772789
    773790#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       }
     791        asprintf(&bootdev, call_program_and_get_last_line_of_output
     792               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     793        if (!bootdev[0]) {
     794            paranoid_free(bootdev);
     795            asprintf(&bootdev, call_program_and_get_last_line_of_output
     796                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     797        }
    781798#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       }
     799        asprintf(&bootdev, call_program_and_get_last_line_of_output
     800               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     801        if (strstr(bootdev, "/dev/cciss/")) {
     802            paranoid_free(bootdev);
     803            asprintf(&bootdev, call_program_and_get_last_line_of_output
     804                   ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     805        }
     806        if (!bootdev[0]) {
     807            paranoid_free(bootdev);
     808            asprintf(&bootdev, call_program_and_get_last_line_of_output
     809                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     810            if (strstr(bootdev, "/dev/cciss/")) {
     811                paranoid_free(bootdev);
     812                asprintf(&bootdev, call_program_and_get_last_line_of_output
     813                       ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     814            }
     815        }
    797816#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 (
     817        if (bootdev[0])
     818            ch = which_boot_loader(bootdev);
     819        else
     820            ch = 'U';
     821        if (bkpinfo->boot_loader != '\0') {
     822            asprintf(&tmp, "User specified boot loader. It is '%c'.",
     823                    bkpinfo->boot_loader);
     824            log_msg(2, tmp);
     825            paranoid_free(tmp);
     826        } else {
     827            bkpinfo->boot_loader = ch;
     828        }
     829        if (bkpinfo->boot_device[0] != '\0') {
     830            asprintf(&tmp, "User specified boot device. It is '%s'.",
     831                    bkpinfo->boot_device);
     832            log_msg(2, tmp);
     833            paranoid_free(tmp);
     834        } else {
     835            strcpy(bkpinfo->boot_device, bootdev);
     836        }
     837    }
     838    paranoid_free(bootdev);
     839
     840    if (
    825841#ifdef __FreeBSD__
    826       bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
     842           bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
    827843#endif
    828844#ifdef __IA64__
    829       bkpinfo->boot_loader != 'E' &&
     845           bkpinfo->boot_loader != 'E' &&
    830846#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"))
     847           bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G'
     848           && bkpinfo->boot_loader != 'R' && !bkpinfo->nonbootable_backup)
    846849    {
    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     }
     850        fatal_error
     851            ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
     852    }
     853    if (bkpinfo->boot_loader == 'L') {
     854        asprintf(&bootldr_str, "LILO");
     855        if (!does_file_exist("/etc/lilo.conf")) {
     856            fatal_error
     857                ("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?");
     858        }
     859    } else if (bkpinfo->boot_loader == 'G') {
     860        asprintf(&bootldr_str, "GRUB");
     861        if (!does_file_exist("/etc/grub.conf")
     862            && does_file_exist("/boot/grub/grub.conf")) {
     863            run_program_and_log_output
     864                ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
     865        }
     866        /* Detect Debian's grub config file */
     867        else if (!does_file_exist("/etc/grub.conf")
     868                 && does_file_exist("/boot/grub/menu.lst")) {
     869            run_program_and_log_output
     870                ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
     871        }
     872        if (!does_file_exist("/etc/grub.conf")) {
     873            fatal_error
     874                ("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'...");
     875        }
     876    } else if (bkpinfo->boot_loader == 'E') {
     877        asprintf(&bootldr_str, "ELILO");
     878        /* BCO: fix it for SuSE, Debian, Mandrake, ... */
     879        if (!does_file_exist("/etc/elilo.conf")
     880            && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
     881            run_program_and_log_output
     882                ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
     883                 5);
     884        }
     885        if (!does_file_exist("/etc/elilo.conf")) {
     886            fatal_error
     887                ("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'");
     888        }
     889    } else if (bkpinfo->boot_loader == 'R') {
     890        asprintf(&bootldr_str, "RAW");
     891    }
    872892#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       }
     893    else if (bkpinfo->boot_loader == 'D') {
     894        asprintf(&bootldr_str, "DD");
     895    }
     896
     897    else if (bkpinfo->boot_loader == 'B') {
     898        asprintf(&bootldr_str, "BOOT0");
     899    }
    882900#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;
     901    else {
     902        asprintf(&bootldr_str, "unknown");
     903    }
     904    asprintf(&tmp, "Your boot loader is %s and it boots from %s",
     905            bootldr_str, bkpinfo->boot_device);
     906    log_to_screen(tmp);
     907    paranoid_free(tmp);
     908    asprintf(&tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
     909    if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
     910        log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
     911    }
     912    paranoid_free(tmp);
     913    switch (bkpinfo->backup_media_type) {
     914    case cdr:
     915        asprintf(&value, "cdr");
     916        break;
     917    case cdrw:
     918        asprintf(&value, "cdrw");
     919        break;
     920    case cdstream:
     921        asprintf(&value, "cdstream");
     922        break;
     923    case tape:
     924        asprintf(&value, "tape");
     925        break;
     926    case udev:
     927        asprintf(&value, "udev");
     928        break;
     929    case iso:
     930        asprintf(&value, "iso");
     931        break;
     932    case nfs:
     933        asprintf(&value, "nfs");
     934        break;
     935    case dvd:
     936        asprintf(&value, "dvd");
     937        break;
     938    default:
     939        fatal_error("Unknown backup_media_type");
     940    }
     941    asprintf(&tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
     942    if (write_one_liner_data_file(tmp, value)) {
     943        res++;
     944        log_msg(1, "%ld: Unable to write one-liner backup-media-type",
     945                __LINE__);
     946    }
     947    paranoid_free(value);
     948    paranoid_free(tmp);
     949    log_to_screen(bkpinfo->tmpdir);
     950    asprintf(&tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
     951    if (write_one_liner_data_file(tmp, bootldr_str)) {
     952        res++;
     953        log_msg(1, "%ld: Unable to write one-liner bootloader.name",
     954                __LINE__);
     955    }
     956    paranoid_free(bootldr_str);
     957    paranoid_free(tmp);
     958    asprintf(&tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
     959    if (bkpinfo->differential) {
     960        res += write_one_liner_data_file(tmp, "1");
     961    } else {
     962        res += write_one_liner_data_file(tmp, "0");
     963    }
     964    paranoid_free(tmp);
     965
     966    estimated_total_noof_slices =
     967        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    921968/* 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,
     969    asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir);
     970    if (system(command)) {
     971        res++;
     972        log_OS_error("Unable to make images directory");
     973    }
     974    paranoid_free(command);
     975
     976    asprintf(&command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
     977    if (system(command)) {
     978        res++;
     979        log_OS_error("Unable to make mnt floppy directory");
     980    }
     981    paranoid_free(command);
     982
     983    asprintf(&tmp, "BTW, I'm telling Mindi your kernel is '%s'",
     984            bkpinfo->kernel_path);
     985    log_to_screen(tmp);
     986    paranoid_free(tmp);
     987
     988    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
     989   
     990    // Watch it! This next line adds a parameter...
     991    if (bkpinfo->nonbootable_backup) {
     992        asprintf(&tmp, " NONBOOTABLE");
     993    } else {
     994        asprintf(&tmp, "");
     995    }
     996
     997    asprintf(&command,
    932998/*     "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
    9339996=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
    934100011=\"%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\" \
     1001            "mindi --custom %s %s/images \"%s\" \"%s\" \
    9381002\"%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      
    960 // Watch it! This next line adds a parameter...
    961   if (bkpinfo->nonbootable_backup) { strcat(command, " NONBOOTABLE"); }
    962   log_msg (2, command);
    963 
    964 //  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, "cat %s | grep \"Fatal error\"", "/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);
     1003\"%s\" %s %ld \"%s\" \"%s\" \"%s\" \"%s\" %ld %d %s",
     1004            bkpinfo->tmpdir,    // parameter #2
     1005            bkpinfo->scratchdir,    // parameter #3
     1006            bkpinfo->kernel_path,   // parameter #4
     1007            tape_device,        // parameter #5
     1008            tape_size_sz,       // parameter #6
     1009            lines_in_filelist,  // parameter #7 (INT)
     1010            use_lzo_sz,         // parameter #8
     1011            cd_recovery_sz,     // parameter #9
     1012            bkpinfo->image_devs,    // parameter #10
     1013            broken_bios_sz,     // parameter #11
     1014            last_filelist_number,   // parameter #12 (STRING)
     1015            estimated_total_noof_slices,    // parameter #13 (INT)
     1016            devs_to_exclude,    // parameter #14
     1017            use_comp_sz,        // parameter #15
     1018            use_lilo_sz,        // parameter #16
     1019            use_star_sz,        // parameter #17
     1020            bkpinfo->internal_tape_block_size,  // parameter #18 (LONG)
     1021            bkpinfo->differential,  // parameter #19 (INT)
     1022            tmp);   
     1023    paranoid_free(tmp);
     1024    paranoid_free(tape_size_sz);
     1025    paranoid_free(use_lzo_sz);
     1026    paranoid_free(tape_device);
     1027    paranoid_free(use_star_sz);
     1028    paranoid_free(use_comp_sz);
     1029    paranoid_free(broken_bios_sz);
     1030    paranoid_free(cd_recovery_sz);
     1031    paranoid_free(last_filelist_number);
     1032    paranoid_free(devs_to_exclude);
     1033    paranoid_free(use_lilo_sz);
     1034
     1035    log_msg(2, command);
     1036
     1037    //  popup_and_OK("Pausing");
     1038
     1039    res = run_program_and_log_to_screen(command,
     1040                      "Generating boot+data disks");
     1041    paranoid_free(command);
     1042
     1043    if (bkpinfo->nonbootable_backup) {
     1044        res = 0;
     1045    }                           // hack
     1046    if (!res) {
     1047        log_to_screen("Boot+data disks were created OK");
     1048        asprintf(&command, "mkdir -p /root/images/mindi/");
     1049        log_msg(2, command);
     1050        run_program_and_log_output(command, FALSE);
     1051        paranoid_free(command);
     1052
     1053        asprintf(&command,
     1054            "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
     1055                bkpinfo->scratchdir);
     1056        log_msg(2, command);
     1057        run_program_and_log_output(command, FALSE);
     1058        paranoid_free(command);
     1059
     1060        if (bkpinfo->nonbootable_backup) {
     1061            asprintf(&command, "cp -f %s/all.tar.gz %s/images",
     1062                    bkpinfo->tmpdir, bkpinfo->scratchdir);
     1063            if (system(command)) {
     1064                fatal_error("Unable to create temporary duff tarball");
     1065            paranoid_free(command);
     1066            }
     1067        }
     1068        asprintf(&command, "cp -f %s/mindi-*oot*.img %s/images",
     1069                bkpinfo->tmpdir, bkpinfo->scratchdir);
     1070        log_msg(2, command);
     1071        run_program_and_log_output(command, FALSE);
     1072        paranoid_free(command);
     1073
     1074        asprintf(&tmp, "cp -f %s/images/all.tar.gz %s",
     1075                bkpinfo->scratchdir, bkpinfo->tmpdir);
     1076        if (system(tmp)) {
     1077            fatal_error("Cannot find all.tar.gz in tmpdir");
     1078        }
     1079        paranoid_free(tmp);
     1080
     1081        if (res) {
     1082            mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1083        } else {
     1084            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1085        }
     1086    } else {
     1087        log_to_screen("Mindi failed to create your boot+data disks.");
     1088        asprintf(&command, "cat %s | grep \"Fatal error\"",
     1089                "/var/log/mindi.log");
     1090        asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     1091        paranoid_free(command);
     1092        if (strlen(tmp) > 1) {
     1093            log_to_screen(tmp);
     1094        }
     1095        paranoid_free(tmp);
     1096    }
     1097    return (res);
    10051098}
    10061099
     
    10431136 * @ingroup LLarchiveGroup
    10441137 */
    1045 void *create_afio_files_in_background(void*inbuf)
     1138void *create_afio_files_in_background(void *inbuf)
    10461139{
    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);
     1140    long int archiving_set_no;
     1141    char *archiving_filelist_fname;
     1142    char *archiving_afioball_fname;
     1143    char *curr_xattr_list_fname;
     1144    char *curr_acl_list_fname;
     1145
     1146    struct s_bkpinfo *bkpinfo;
     1147    char *tmp;
     1148    int res = 0, retval = 0;
     1149    int *p_archival_threads_running;
     1150    int *p_last_set_archived;
     1151    int *p_next_set_to_archive;
     1152    char *p_list_of_fileset_flags;
     1153    int this_thread_no = g_current_thread_no++;
     1154
     1155    p_last_set_archived = (int *) inbuf;
     1156    p_archival_threads_running = (int *) (inbuf + 4);
     1157    p_next_set_to_archive = (int *) (inbuf + 8);
     1158    p_list_of_fileset_flags = (char *) (inbuf + 12);
     1159    bkpinfo = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
     1160
     1161    asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1162            bkpinfo->tmpdir, 0L);
     1163    archiving_set_no = 0;
     1164    while (does_file_exist(archiving_filelist_fname)) {
     1165        paranoid_free(archiving_filelist_fname);
     1166        if (g_exiting) {
     1167            fatal_error("Execution run aborted (pthread)");
     1168        }
     1169        if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
     1170            fatal_error
     1171                ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
     1172        }
     1173        if (!semaphore_p()) {
     1174            log_msg(3, "P sem failed (pid=%d)", (int) getpid());
     1175            fatal_error("Cannot get semaphore P");
     1176        }
     1177        if (archiving_set_no < *p_next_set_to_archive) {
     1178            archiving_set_no = *p_next_set_to_archive;
     1179        }
     1180        *p_next_set_to_archive = *p_next_set_to_archive + 1;
     1181        if (!semaphore_v()) {
     1182            fatal_error("Cannot get semaphore V");
     1183        }
     1184
     1185        /* backup this set of files */
     1186        asprintf(&archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1187                bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
     1188        asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1189                bkpinfo->tmpdir, archiving_set_no);
     1190        if (!does_file_exist(archiving_filelist_fname)) {
     1191            log_msg(3,
     1192                "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
     1193                FORTY_SPACES, getpid(), this_thread_no,
     1194                archiving_set_no);
     1195            paranoid_free(archiving_filelist_fname);
     1196            paranoid_free(archiving_afioball_fname);
     1197            break;
     1198        }
     1199
     1200        asprintf(&tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
     1201                archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
     1202        if (does_file_exist(tmp)) {
     1203            log_msg(4, "%s[%d:%d] - waiting for storer",
     1204                    FORTY_SPACES, getpid(), this_thread_no);
     1205            while (does_file_exist(tmp)) {
     1206                sleep(1);
     1207            }
     1208            log_msg(4, "[%d] - continuing", getpid());
     1209        }
     1210        paranoid_free(tmp);
     1211
     1212        log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
     1213                this_thread_no, archiving_set_no);
     1214        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1215                bkpinfo->tmpdir, archiving_set_no);
     1216        asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1217                bkpinfo->tmpdir, archiving_set_no);
     1218        get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
     1219        paranoid_free(curr_xattr_list_fname);
     1220        get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
     1221        paranoid_free(curr_acl_list_fname);
     1222
     1223        log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
     1224                this_thread_no, archiving_set_no);
     1225        res = archive_this_fileset(bkpinfo, archiving_filelist_fname,
     1226                         archiving_afioball_fname,
     1227                         archiving_set_no);
     1228        paranoid_free(archiving_afioball_fname);
     1229        paranoid_free(archiving_filelist_fname);
     1230        retval += res;
     1231
     1232        if (res) {
     1233            asprintf(&tmp,
     1234                    "Errors occurred while archiving set %ld. Please review logs.",
     1235                    archiving_set_no);
     1236            log_to_screen(tmp);
     1237            paranoid_free(tmp);
     1238        }
     1239        if (!semaphore_p()) {
     1240            fatal_error("Cannot get semaphore P");
     1241        }
     1242
     1243        set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
     1244
     1245        if (*p_last_set_archived < archiving_set_no) {
     1246            *p_last_set_archived = archiving_set_no;
     1247        }                       // finished archiving this one
     1248
     1249        if (!semaphore_v()) {
     1250            fatal_error("Cannot get semaphore V");
     1251        }
     1252        log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
     1253                this_thread_no, archiving_set_no);
     1254        archiving_set_no++;
     1255        asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1256                 bkpinfo->tmpdir, archiving_set_no);
     1257    }
     1258    if (!semaphore_p()) {
     1259        fatal_error("Cannot get semaphore P");
     1260    }
     1261    (*p_archival_threads_running)--;
     1262    if (!semaphore_v()) {
     1263        fatal_error("Cannot get semaphore V");
     1264    }
     1265    log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
     1266            this_thread_no);
     1267    paranoid_free(archiving_filelist_fname);
     1268    pthread_exit(NULL);
    11521269}
    11531270
     
    11651282 * @ingroup MLarchiveGroup
    11661283 */
    1167 int
    1168 do_that_final_phase (struct s_bkpinfo *bkpinfo)
     1284int do_that_final_phase(struct s_bkpinfo *bkpinfo)
    11691285{
    11701286
    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)
     1287    /*@ int ************************************** */
     1288    int res = 0;
     1289    int retval = 0;
     1290
     1291    /*@ buffers ********************************** */
     1292
     1293    assert(bkpinfo != NULL);
     1294    mvaddstr_and_log_it(g_currentY, 0,
     1295                        "Writing any remaining data to media         ");
     1296
     1297    log_msg(1, "Closing tape/CD ... ");
     1298    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     1299        /* write tape/cdstream */
    11921300    {
    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);
     1301        closeout_tape(bkpinfo);
     1302    } else
     1303        /* write final ISO */
     1304    {
     1305        res = write_final_iso_if_necessary(bkpinfo);
     1306        retval += res;
     1307        if (res) {
     1308            log_msg(1, "write_final_iso_if_necessary returned an error");
     1309        }
     1310    }
     1311    log_msg(2, "Fork is exiting ... ");
     1312
     1313    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1314
     1315    /* final stuff */
     1316    if (retval) {
     1317        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1318    } else {
     1319        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1320    }
     1321
     1322    return (retval);
    12111323}
    12121324
     
    12311343 * @ingroup MLarchiveGroup
    12321344 */
    1233 int
    1234 do_that_initial_phase (struct s_bkpinfo *bkpinfo)
     1345int do_that_initial_phase(struct s_bkpinfo *bkpinfo)
    12351346{
    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 \
     1347    /*@ int *************************************** */
     1348    int retval = 0;
     1349
     1350    /*@ buffers *********************************** */
     1351    char *command, *tmpfile, *data_disks_file, *tmp;
     1352
     1353    assert(bkpinfo != NULL);
     1354    asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
     1355
     1356    asprintf(&g_serial_string,
     1357             call_program_and_get_last_line_of_output("dd \
    12501358if=/dev/urandom bs=16 count=1 2> /dev/null | \
    12511359hexdump | 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-[1-9]*.iso", bkpinfo->prefix, bkpinfo->isodir);
    1284   paranoid_system (command);
    1285   wipe_archives (bkpinfo->scratchdir);
    1286   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1287   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1288     {
    1289       write_header_block_to_stream (0, "start-of-tape", BLK_START_OF_TAPE);
    1290       write_header_block_to_stream (0, "start-of-backup", BLK_START_OF_BACKUP);
    1291     }
    1292   paranoid_free(command);
    1293   paranoid_free(tmpfile);
    1294   paranoid_free(data_disks_file);
    1295   return (retval);
     1360    strip_spaces(g_serial_string);
     1361    asprintf(&tmp, "%s...word.",g_serial_string);
     1362    paranoid_free(g_serial_string);
     1363    g_serial_string = tmp;
     1364    log_msg(2, "g_serial_string = '%s'", g_serial_string);
     1365
     1366    asprintf(&tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
     1367    if (write_one_liner_data_file(tmpfile, g_serial_string)) {
     1368        log_msg(1, "%ld: Failed to write serial string", __LINE__);
     1369    }
     1370    paranoid_free(g_serial_string);
     1371    paranoid_free(tmpfile);
     1372
     1373    mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
     1374    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1375        if (bkpinfo->backup_media_type == cdstream) {
     1376            openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
     1377        } else {
     1378            openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
     1379        }
     1380        if (!g_tape_stream) {
     1381            fatal_error("Cannot open backup (streaming) device");
     1382        }
     1383        log_msg(1, "Backup (stream) opened OK");
     1384        write_data_disks_to_stream(data_disks_file);
     1385    } else {
     1386        log_msg(1, "Backing up to CD's");
     1387    }
     1388    paranoid_free(data_disks_file);
     1389
     1390    asprintf(&command, "rm -f %s/%s-[1-9]*.iso", bkpinfo->prefix,
     1391            bkpinfo->isodir);
     1392    paranoid_system(command);
     1393    paranoid_free(command);
     1394    wipe_archives(bkpinfo->scratchdir);
     1395    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1396    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1397        write_header_block_to_stream(0, "start-of-tape",
     1398                         BLK_START_OF_TAPE);
     1399        write_header_block_to_stream(0, "start-of-backup",
     1400                         BLK_START_OF_BACKUP);
     1401    }
     1402    return (retval);
    12961403}
    12971404
     
    13071414 * @return The exit code of fdformat/superformat.
    13081415 */
    1309 int
    1310 format_disk_SUB (char *cmd, char *title)
     1416int format_disk_SUB(char *cmd, char *title)
    13111417{
    13121418
    1313     /*@ int ****************************************************************/
    1314   int res = 0;
     1419    /*@ int *************************************************************** */
     1420    int res = 0;
    13151421    int percentage = 0;
    13161422    int maxtracks = 0;
     
    13181424    int last_trkno = 0;
    13191425
    1320     /*@ buffers ************************************************************/
    1321   char *command;
    1322   char *tempfile;
    1323 
    1324     /*@ pointers ***********************************************************/
    1325   FILE *pin;
    1326 
    1327   assert_string_is_neither_NULL_nor_zerolength(cmd);
    1328   assert_string_is_neither_NULL_nor_zerolength(title);
    1329 
    1330   malloc_string(command);
    1331   malloc_string(tempfile);
     1426    /*@ buffers *********************************************************** */
     1427    char *command;
     1428    char *tempfile;
     1429
     1430    /*@ pointers ********************************************************** */
     1431    FILE *pin;
     1432
     1433    assert_string_is_neither_NULL_nor_zerolength(cmd);
     1434    assert_string_is_neither_NULL_nor_zerolength(title);
     1435
     1436    malloc_string(command);
    13321437#ifdef __FreeBSD__
    13331438/* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
     
    13371442   not done yet.
    13381443*/
    1339     return (run_program_and_log_to_screen (cmd, title));
     1444    return (run_program_and_log_to_screen(cmd, title));
    13401445#endif
    13411446
    13421447/* if Debian then do bog-standard superformat; don't be pretty */
    1343   if (strstr (cmd, "superformat"))
    1344     {
    1345       return (run_program_and_log_to_screen (cmd, title));
    1346     }
     1448    if (strstr(cmd, "superformat")) {
     1449        return (run_program_and_log_to_screen(cmd, title));
     1450    }
    13471451/* if not Debian then go ahead & use fdformat */
    1348   strcpy (tempfile,
    1349       call_program_and_get_last_line_of_output
    1350       ("mktemp -q /tmp/mondo.XXXXXXXX"));
    1351   sprintf (command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    1352        tempfile);
    1353   log_msg (3, command);
    1354   open_evalcall_form (title);
    1355   if (!(pin = popen (command, "r")))
    1356     {
    1357       log_OS_error ("fmt err");
    1358       return (1);
    1359     }
    1360   if (strstr (command, "1722"))
    1361     {
    1362       maxtracks = 82;
    1363     }
    1364   else
    1365     {
    1366       maxtracks = 80;
    1367     }
    1368   for (sleep (1); does_file_exist (tempfile); sleep (1))
    1369     {
    1370       trackno = get_trackno_from_logfile (tempfile);
    1371       if (trackno < 0 || trackno > 80)
    1372     {
    1373       log_msg (1, "Weird track#");
    1374       continue;
    1375     }
    1376       percentage = trackno * 100 / maxtracks;
    1377       if (trackno <= 5 && last_trkno > 40)
    1378     {
    1379       close_evalcall_form ();
    1380       strcpy (title, "Verifying format");
    1381       open_evalcall_form (title);
    1382     }
    1383       last_trkno = trackno;
    1384       update_evalcall_form (percentage);
    1385     }
    1386   close_evalcall_form ();
    1387   if (pclose (pin)) { res++; log_OS_error("Unable to pclose"); }
    1388   unlink (tempfile);
    1389   paranoid_free(command);
    1390   paranoid_free(tempfile);
    1391   return (res);
     1452    asprintf(&tempfile,"%s",
     1453           call_program_and_get_last_line_of_output
     1454           ("mktemp -q /tmp/mondo.XXXXXXXX"));
     1455    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     1456            tempfile);
     1457    log_msg(3, command);
     1458    open_evalcall_form(title);
     1459    if (!(pin = popen(command, "r"))) {
     1460        log_OS_error("fmt err");
     1461        return (1);
     1462    }
     1463    if (strstr(command, "1722")) {
     1464        maxtracks = 82;
     1465    } else {
     1466        maxtracks = 80;
     1467    }
     1468    for (sleep(1); does_file_exist(tempfile); sleep(1)) {
     1469        trackno = get_trackno_from_logfile(tempfile);
     1470        if (trackno < 0 || trackno > 80) {
     1471            log_msg(1, "Weird track#");
     1472            continue;
     1473        }
     1474        percentage = trackno * 100 / maxtracks;
     1475        if (trackno <= 5 && last_trkno > 40) {
     1476            close_evalcall_form();
     1477            strcpy(title, "Verifying format");
     1478            open_evalcall_form(title);
     1479        }
     1480        last_trkno = trackno;
     1481        update_evalcall_form(percentage);
     1482    }
     1483    close_evalcall_form();
     1484    if (pclose(pin)) {
     1485        res++;
     1486        log_OS_error("Unable to pclose");
     1487    }
     1488    unlink(tempfile);
     1489    paranoid_free(command);
     1490    paranoid_free(tempfile);
     1491    return (res);
    13921492}
    13931493
     
    14031503 * @ingroup deviceGroup
    14041504 */
    1405 int
    1406 format_disk (char *device)
     1505int format_disk(char *device)
    14071506{
    1408    
    1409     /*@ int ***************************************************************/
    1410   int res = 0;
    1411 
    1412     /*@ buffer ************************************************************/
    1413   char *command;
    1414   char *title;
    1415  
    1416 
    1417   assert_string_is_neither_NULL_nor_zerolength(device);
    1418   malloc_string(title);
    1419   command = malloc(1000);
    1420   if (!system ("which superformat > /dev/null 2> /dev/null"))
    1421     {
    1422       sprintf (command, "superformat %s", device);
    1423     }
    1424   else
    1425     {
     1507
     1508    /*@ int ************************************************************** */
     1509    int res = 0;
     1510
     1511    /*@ buffer *********************************************************** */
     1512    char *command;
     1513    char *title;
     1514
     1515
     1516    assert_string_is_neither_NULL_nor_zerolength(device);
     1517    if (!system("which superformat > /dev/null 2> /dev/null")) {
     1518        asprintf(&command, "superformat %s", device);
     1519    } else {
    14261520#ifdef __FreeBSD__
    1427       sprintf (command, "fdformat -y %s", device);
     1521        asprintf(&command, "fdformat -y %s", device);
    14281522#else
    1429       sprintf (command, "fdformat %s", device);
     1523        asprintf(&command, "fdformat %s", device);
    14301524#endif
    1431     }
    1432   sprintf (title, "Formatting disk %s", device);
    1433   while ((res = format_disk_SUB (command, title)))
    1434     {
    1435       if (!ask_me_yes_or_no ("Failed to format disk. Retry?"))
    1436     {
    1437       return (res);
    1438     }
    1439     }
    1440   paranoid_free(title);
    1441   paranoid_free(command);
    1442   return (res);
     1525    }
     1526    asprintf(&title, "Formatting disk %s", device);
     1527    while ((res = format_disk_SUB(command, title))) {
     1528        if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
     1529            return (res);
     1530        }
     1531    }
     1532    paranoid_free(title);
     1533    paranoid_free(command);
     1534    return (res);
    14431535}
    14441536
     
    14511543 * @ingroup utilityGroup
    14521544 */
    1453 bool get_bit_N_of_array(char*array, int N)
     1545bool get_bit_N_of_array(char *array, int N)
    14541546{
    1455   int element_number;
    1456   int bit_number;
    1457   int mask;
    1458  
    1459   element_number = N / 8;
    1460   bit_number = N % 8;
    1461   mask = 1 << bit_number;
    1462   if (array[element_number] & mask)
    1463     { return(TRUE); }
    1464   else
    1465     { return(FALSE); }
     1547    int element_number;
     1548    int bit_number;
     1549    int mask;
     1550
     1551    element_number = N / 8;
     1552    bit_number = N % 8;
     1553    mask = 1 << bit_number;
     1554    if (array[element_number] & mask) {
     1555        return (TRUE);
     1556    } else {
     1557        return (FALSE);
     1558    }
    14661559}
    1467 
    1468 
    1469 
    1470 
    1471 
    1472 
    1473 
    1474 
    14751560
    14761561/**
     
    14961581 * @return The number of errors encountered (0 for success)
    14971582 */
    1498 int
    1499 make_afioballs_and_images (struct s_bkpinfo *bkpinfo)
     1583int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
    15001584{
    15011585
    1502     /*@ int ***************************************************/
    1503   int retval = 0;
    1504   long int storing_set_no = 0;
    1505   int res = 0;
    1506   bool done_storing=FALSE;
    1507   char *result_str;
    1508   char *transfer_block;
    1509   void*vp;
    1510   void**pvp;
    1511 
    1512     /*@ buffers ***********************************************/
    1513   char *storing_filelist_fname;
    1514   char *storing_afioball_fname;
    1515   char *tmp;
    1516   char *media_usage_comment;
    1517   pthread_t archival_thread[ARCH_THREADS];
    1518   char *p_list_of_fileset_flags;
    1519   int *p_archival_threads_running;
    1520   int *p_last_set_archived;
    1521   int *p_next_set_to_archive;
    1522   int noof_threads;
    1523   int i;
    1524   char *curr_xattr_list_fname;
    1525   char *curr_acl_list_fname;
    1526   int misc_counter_that_is_not_important=0; 
    1527  
    1528   log_msg(8, "here");
    1529   assert(bkpinfo!=NULL);
    1530   tmp = malloc(MAX_STR_LEN*2);
    1531   malloc_string(result_str);
    1532   malloc_string(curr_xattr_list_fname);
    1533   malloc_string(curr_acl_list_fname);
    1534   malloc_string(storing_filelist_fname);
    1535   malloc_string(media_usage_comment);
    1536   malloc_string(storing_afioball_fname);
    1537   transfer_block = malloc(sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1538   memset((void*)transfer_block, 0, sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1539   p_last_set_archived = (int*)transfer_block;
    1540   p_archival_threads_running = (int*)(transfer_block+4);
    1541   p_next_set_to_archive = (int*)(transfer_block+8);
    1542   p_list_of_fileset_flags = (char*)(transfer_block+12);
    1543   memcpy((void*)(transfer_block+BKPINFO_LOC_OFFSET), (void*)bkpinfo, sizeof(struct s_bkpinfo));
    1544   pvp=&vp;
    1545   vp=(void*)result_str;
    1546   *p_archival_threads_running = 0;
    1547   *p_last_set_archived = -1;
    1548   *p_next_set_to_archive = 0;
    1549   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    1550   log_to_screen ("Archiving regular files");
    1551   log_msg (5, "Go, Shorty. It's your birthday.");
    1552   open_progress_form ("Backing up filesystem",
    1553               "I am backing up your live filesystem now.",
    1554               "Please wait. This may take a couple of hours.",
    1555               "Working...", get_last_filelist_number (bkpinfo) + 1);
    1556 
    1557   log_msg (5, "We're gonna party like it's your birthday.");
    1558 
    1559   srand((unsigned int)getpid());
    1560   g_sem_key = 1234+random()%30000;
    1561   if ((g_sem_id = semget((key_t)g_sem_key, 1, IPC_CREAT|S_IREAD|S_IWRITE))==-1)
    1562     { fatal_error("MABAI - unable to semget"); }
    1563   if (!set_semvalue())
    1564     { fatal_error("Unable to init semaphore"); } // initialize semaphore
    1565   for(noof_threads=0; noof_threads<ARCH_THREADS; noof_threads++)
    1566     {
    1567       log_msg(8, "Creating thread #%d", noof_threads);
    1568       (*p_archival_threads_running) ++;
    1569       if ((res = pthread_create(&archival_thread[noof_threads], NULL, create_afio_files_in_background, (void*)transfer_block)))
    1570     { fatal_error("Unable to create an archival thread"); }
    1571     }
    1572 
    1573   log_msg(8, "About to enter while() loop");
    1574   while(!done_storing)
    1575     {
    1576       if (g_exiting) { fatal_error("Execution run aborted (main loop)"); }
    1577       if (*p_archival_threads_running == 0 && *p_last_set_archived == storing_set_no-1)
    1578     {
    1579       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);
    1580       done_storing = TRUE;
    1581     }
    1582       else if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no))
    1583     {
    1584       misc_counter_that_is_not_important = (misc_counter_that_is_not_important+1) % 5;
    1585       if (!misc_counter_that_is_not_important)
    1586         { update_progress_form (media_usage_comment); }
    1587       sleep(1);
    1588     }
    1589       else
    1590     // store set N
    1591     {
    1592       sprintf (storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1593            storing_set_no);
    1594       sprintf (storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1595            storing_set_no, bkpinfo->zip_suffix);
    1596           sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1597           sprintf (curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1598 
    1599       log_msg (2, "Storing set %d", storing_set_no);
    1600       while(!does_file_exist(storing_filelist_fname) || !does_file_exist(storing_afioball_fname))
    1601         {
    1602           log_msg (2, "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.", storing_filelist_fname, storing_afioball_fname);
    1603           sleep(5);
    1604         }
    1605       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    1606       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    1607       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1608         {
    1609               register_in_tape_catalog(fileset, storing_set_no, -1, storing_afioball_fname);
    1610           maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname);
    1611           iamhere("Writing EXAT files");
    1612               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
    1613 // archives themselves
    1614           res += move_files_to_stream (bkpinfo, storing_afioball_fname, NULL);
    1615         }
    1616       else
    1617         {
    1618           res = move_files_to_cd (bkpinfo, storing_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, storing_afioball_fname, NULL);
    1619         }
    1620       retval += res;
    1621       g_current_progress++;
    1622       update_progress_form (media_usage_comment);
    1623       if (res)
    1624         {
    1625           sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    1626                storing_set_no);
    1627           log_to_screen (tmp);
    1628           fatal_error
    1629         ("Is your hard disk full? If not, please send the author the logfile.");
    1630         }
    1631       storing_set_no++;
    1632       //      sleep(2);
    1633     }
    1634     }
    1635   close_progress_form ();
    1636 
    1637   sprintf (tmp, "Your regular files have been archived ");
    1638   log_msg(2, "Joining background threads to foreground thread");
    1639   for(i=0; i<noof_threads; i++)
    1640     {
    1641       pthread_join(archival_thread[i], pvp);
    1642       log_msg(3, "Thread %d of %d: closed OK", i+1, noof_threads);
    1643     }
    1644   del_semvalue();
    1645   log_msg (2, "Done.");
    1646   if (retval)
    1647     {
    1648       strcat (tmp, "(with errors).");
    1649     }
    1650   else
    1651     {
    1652       strcat (tmp, "successfully.");
    1653     }
    1654   log_to_screen (tmp);
    1655   paranoid_free(transfer_block);
    1656   paranoid_free(result_str);
    1657   paranoid_free(storing_filelist_fname);
    1658   paranoid_free(media_usage_comment);
    1659   paranoid_free(storing_afioball_fname);
    1660   paranoid_free(curr_xattr_list_fname);
    1661   paranoid_free(curr_acl_list_fname);
    1662   return (retval);
     1586    /*@ int ************************************************** */
     1587    int retval = 0;
     1588    long int storing_set_no = 0;
     1589    int res = 0;
     1590    bool done_storing = FALSE;
     1591    char *result_str;
     1592    char *transfer_block;
     1593    void *vp;
     1594    void **pvp;
     1595
     1596    /*@ buffers ********************************************** */
     1597    char *storing_filelist_fname;
     1598    char *storing_afioball_fname;
     1599    char *tmp;
     1600    char *media_usage_comment;
     1601    pthread_t archival_thread[ARCH_THREADS];
     1602    char *p_list_of_fileset_flags;
     1603    int *p_archival_threads_running;
     1604    int *p_last_set_archived;
     1605    int *p_next_set_to_archive;
     1606    int noof_threads;
     1607    int i;
     1608    char *curr_xattr_list_fname;
     1609    char *curr_acl_list_fname;
     1610    int misc_counter_that_is_not_important = 0;
     1611
     1612    log_msg(8, "here");
     1613    assert(bkpinfo != NULL);
     1614    /* BERLIOS: To be removed */
     1615    malloc_string(result_str);
     1616    transfer_block =
     1617        malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1618    memset((void *) transfer_block, 0,
     1619           sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1620    p_last_set_archived = (int *) transfer_block;
     1621    p_archival_threads_running = (int *) (transfer_block + 4);
     1622    p_next_set_to_archive = (int *) (transfer_block + 8);
     1623    p_list_of_fileset_flags = (char *) (transfer_block + 12);
     1624    memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
     1625           (void *) bkpinfo, sizeof(struct s_bkpinfo));
     1626    pvp = &vp;
     1627    vp = (void *) result_str;
     1628    *p_archival_threads_running = 0;
     1629    *p_last_set_archived = -1;
     1630    *p_next_set_to_archive = 0;
     1631    log_to_screen("Archiving regular files");
     1632    log_msg(5, "Go, Shorty. It's your birthday.");
     1633    open_progress_form("Backing up filesystem",
     1634               "I am backing up your live filesystem now.",
     1635               "Please wait. This may take a couple of hours.",
     1636               "Working...",
     1637               get_last_filelist_number(bkpinfo) + 1);
     1638
     1639    log_msg(5, "We're gonna party like it's your birthday.");
     1640
     1641    srand((unsigned int) getpid());
     1642    g_sem_key = 1234 + random() % 30000;
     1643    if ((g_sem_id =
     1644         semget((key_t) g_sem_key, 1,
     1645                IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
     1646        fatal_error("MABAI - unable to semget");
     1647    }
     1648    if (!set_semvalue()) {
     1649        fatal_error("Unable to init semaphore");
     1650    }                           // initialize semaphore
     1651    for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
     1652        log_msg(8, "Creating thread #%d", noof_threads);
     1653        (*p_archival_threads_running)++;
     1654        if ((res =
     1655             pthread_create(&archival_thread[noof_threads], NULL,
     1656                    create_afio_files_in_background,
     1657                    (void *) transfer_block))) {
     1658            fatal_error("Unable to create an archival thread");
     1659        }
     1660    }
     1661
     1662    log_msg(8, "About to enter while() loop");
     1663    while (!done_storing) {
     1664        if (g_exiting) {
     1665            fatal_error("Execution run aborted (main loop)");
     1666        }
     1667        if (*p_archival_threads_running == 0
     1668            && *p_last_set_archived == storing_set_no - 1) {
     1669            log_msg(2,
     1670                "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... :-)",
     1671                *p_last_set_archived, storing_set_no);
     1672            done_storing = TRUE;
     1673        } else if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no)) {
     1674            misc_counter_that_is_not_important =
     1675                (misc_counter_that_is_not_important + 1) % 5;
     1676            /* BERLIOS: media_usage_comment was NOT initialized !!! */
     1677            /* maybe : */
     1678            asprintf(&media_usage_comment, "%s",
     1679                   percent_media_full_comment(bkpinfo));
     1680            if (!misc_counter_that_is_not_important) {
     1681                update_progress_form(media_usage_comment);
     1682            }
     1683            paranoid_free(media_usage_comment);
     1684            sleep(1);
     1685        } else {
     1686            // store set N
     1687            asprintf(&storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1688                    bkpinfo->tmpdir, storing_set_no);
     1689            asprintf(&storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1690                    bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
     1691            asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1692                    bkpinfo->tmpdir, storing_set_no);
     1693            asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1694                    bkpinfo->tmpdir, storing_set_no);
     1695
     1696            log_msg(2, "Storing set %d", storing_set_no);
     1697            while (!does_file_exist(storing_filelist_fname)
     1698                   || !does_file_exist(storing_afioball_fname)) {
     1699                log_msg(2,
     1700                        "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
     1701                        storing_filelist_fname, storing_afioball_fname);
     1702                sleep(5);
     1703            }
     1704            asprintf(&media_usage_comment, "%s",
     1705                   percent_media_full_comment(bkpinfo));
     1706            /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     1707            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1708                register_in_tape_catalog(fileset, storing_set_no, -1,
     1709                             storing_afioball_fname);
     1710                maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     1711                                       storing_afioball_fname);
     1712                iamhere("Writing EXAT files");
     1713                res +=
     1714                    write_EXAT_files_to_tape(bkpinfo,
     1715                                 curr_xattr_list_fname,
     1716                                 curr_acl_list_fname);
     1717                // archives themselves
     1718                res +=
     1719                    move_files_to_stream(bkpinfo, storing_afioball_fname,
     1720                                 NULL);
     1721            } else {
     1722                res =
     1723                    move_files_to_cd(bkpinfo, storing_filelist_fname,
     1724                             curr_xattr_list_fname,
     1725                             curr_acl_list_fname,
     1726                             storing_afioball_fname, NULL);
     1727            }
     1728            paranoid_free(storing_filelist_fname);
     1729            paranoid_free(storing_afioball_fname);
     1730            paranoid_free(curr_xattr_list_fname);
     1731            paranoid_free(curr_acl_list_fname);
     1732            retval += res;
     1733            g_current_progress++;
     1734            update_progress_form(media_usage_comment);
     1735            paranoid_free(media_usage_comment);
     1736
     1737            if (res) {
     1738                asprintf(&tmp,
     1739                        "Failed to add archive %ld's files to CD dir\n",
     1740                        storing_set_no);
     1741                log_to_screen(tmp);
     1742                paranoid_free(tmp);
     1743                fatal_error("Is your hard disk full? If not, please send the author the logfile.");
     1744            }
     1745            storing_set_no++;
     1746            //      sleep(2);
     1747        }
     1748    }
     1749    close_progress_form();
     1750
     1751    log_msg(2, "Joining background threads to foreground thread");
     1752    for (i = 0; i < noof_threads; i++) {
     1753        pthread_join(archival_thread[i], pvp);
     1754        log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
     1755    }
     1756    del_semvalue();
     1757    log_msg(2, "Done.");
     1758    if (retval) {
     1759        asprintf(&tmp, "Your regular files have been archived (with errors).");
     1760    } else {
     1761        asprintf(&tmp, "Your regular files have been archived successfully");
     1762    }
     1763    log_to_screen(tmp);
     1764    paranoid_free(tmp);
     1765    paranoid_free(transfer_block);
     1766    paranoid_free(result_str);
     1767    return (retval);
    16631768}
    16641769
    16651770
    1666 void pause_for_N_seconds(int how_long, char*msg)
     1771void pause_for_N_seconds(int how_long, char *msg)
    16671772{
    1668   int i;
    1669   open_evalcall_form(msg);
    1670   for(i=0; i<how_long; i++)
    1671     {
    1672       update_evalcall_form((int) ( (100.0/(float)(how_long)*i) ) );
    1673       sleep(1);
    1674     }
    1675   close_evalcall_form();
     1773    int i;
     1774    open_evalcall_form(msg);
     1775    for (i = 0; i < how_long; i++) {
     1776        update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
     1777        sleep(1);
     1778    }
     1779    close_evalcall_form();
    16761780}
    16771781
     
    16961800 * @return The number of errors encountered (0 for success)
    16971801 */
    1698 int
    1699 make_iso_fs (struct s_bkpinfo *bkpinfo, char *destfile)
     1802int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
    17001803{
    1701     /*@ int ***********************************************/
    1702   int retval = 0;
    1703   int res;
    1704 
    1705     /*@ buffers *******************************************/
    1706   char *tmp;
    1707   char *old_pwd;
    1708   char *result_sz;
    1709   char *message_to_screen;
    1710   char *sz_blank_disk;
    1711   char *fnam;
    1712   char *tmp2;
    1713   char *tmp3;
    1714   bool cd_is_mountable;
    1715 
    1716   malloc_string(old_pwd);
    1717   malloc_string(result_sz);
    1718   malloc_string(message_to_screen);
    1719   malloc_string(sz_blank_disk);
    1720   malloc_string(fnam);
    1721   tmp = malloc(1200);
    1722   tmp2 =malloc(1200);
    1723   tmp3 =malloc(1200);
    1724   assert(bkpinfo!=NULL);
    1725   assert_string_is_neither_NULL_nor_zerolength(destfile);
    1726 
    1727   sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
    1728   sprintf(tmp2,"%s/isolinux.bin", bkpinfo->tmpdir);
    1729   if (does_file_exist(tmp))
    1730     {
    1731       sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
    1732       paranoid_system(tmp3);
    1733     }
    1734   if (!does_file_exist(tmp) && does_file_exist(tmp2))
    1735     {
    1736       sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
    1737       paranoid_system(tmp3);
    1738     }
    1739   /*
    1740   if (!does_file_exist(tmp))
    1741     {
    1742       log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
    1743       strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
    1744       if (strlen(fnam)>0 && does_file_exist(fnam))
    1745         {
    1746           sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
    1747           res = run_program_and_log_output(tmp, FALSE);
    1748         }
    1749       else
    1750         {
    1751       res = 1;
    1752     }
    1753       if (res)
    1754     {
    1755       log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
    1756     }
    1757     }
    1758   */
    1759   free(tmp2);
    1760   free(tmp3);
    1761   tmp2 = NULL;
    1762   tmp3 = NULL;
    1763   if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray)
    1764     {
    1765       popup_and_OK("Please insert new media and press Enter.");
    1766     }
    1767 
    1768   log_msg (2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
    1769        bkpinfo->scratchdir, destfile);
    1770   (void) getcwd (old_pwd, MAX_STR_LEN - 1);
    1771   sprintf (tmp, "chmod 744 %s", bkpinfo->scratchdir);
    1772   run_program_and_log_output(tmp, FALSE);
    1773   chdir (bkpinfo->scratchdir);
    1774 
    1775   if (bkpinfo->call_before_iso[0] != '\0')
    1776     {
    1777       sprintf (message_to_screen, "Running pre-ISO call for CD#%d",
    1778            g_current_media_number);
    1779       res =
    1780     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_before_iso, destfile,
    1781            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1782       if (res)
    1783     {
    1784       strcat (message_to_screen, "...failed");
    1785     }
    1786       else
    1787     {
    1788       strcat (message_to_screen, "...OK");
    1789     }
    1790       log_to_screen (message_to_screen);
    1791       retval += res;
    1792     }
    1793 
    1794   if (bkpinfo->call_make_iso[0] != '\0')
    1795     {
    1796       log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    1797       sprintf (tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    1798       sprintf (message_to_screen, "Making an ISO (%s #%d)",
    1799                media_descriptor_string(bkpinfo->backup_media_type),
    1800            g_current_media_number);
    1801 
    1802       pause_and_ask_for_cdr (2, &cd_is_mountable);  /* if g_current_media_number >= 2 then pause & ask */
    1803       if (retval)
    1804          {
    1805        log_to_screen("Serious error(s) occurred already. I shan't try to write to media.");
    1806          }
    1807       else
    1808          {
    1809        res =
    1810         eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1811            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1812           if (res)
    1813             {
    1814               log_to_screen ("%s...failed to write", message_to_screen);
    1815            }
    1816           else
    1817             {
    1818               log_to_screen ("%s...OK", message_to_screen);
    1819           if (!run_program_and_log_output("tail -n10 /var/log/mondo-archive.log | fgrep \":-(\"", 1))
    1820             {
    1821           log_to_screen("Despite nonfatal errors, growisofs confirms the write was successful.");
    1822         }
    1823             }
    1824           retval += res;
     1804    /*@ int ********************************************** */
     1805    int retval = 0;
     1806    int res;
     1807
     1808    /*@ buffers ****************************************** */
     1809    char *tmp;
     1810    char *old_pwd;
     1811    char *result_sz;
     1812    char *message_to_screen;
     1813    char *sz_blank_disk;
     1814    char *fnam;
     1815    char *tmp2;
     1816    char *tmp3;
     1817    bool cd_is_mountable;
     1818
     1819    malloc_string(old_pwd);
     1820    assert(bkpinfo != NULL);
     1821    assert_string_is_neither_NULL_nor_zerolength(destfile);
     1822
     1823    asprintf(&tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
     1824    asprintf(&tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
     1825    if (does_file_exist(tmp)) {
     1826        asprintf(&tmp3, "cp -f %s %s", tmp, tmp2);
     1827        paranoid_system(tmp3);
     1828        paranoid_free(tmp3);
     1829    }
     1830    if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
     1831        asprintf(&tmp3, "cp -f %s %s", tmp2, tmp);
     1832        paranoid_system(tmp3);
     1833        paranoid_free(tmp3);
     1834    }
     1835    paranoid_free(tmp2);
     1836    paranoid_free(tmp);
     1837
     1838    if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
     1839        popup_and_OK("Please insert new media and press Enter.");
     1840    }
     1841
     1842    log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
     1843            bkpinfo->scratchdir, destfile);
     1844    /* BERLIOS: Do not ignore getcwd result */
     1845    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
     1846    asprintf(&tmp, "chmod 744 %s", bkpinfo->scratchdir);
     1847    run_program_and_log_output(tmp, FALSE);
     1848    paranoid_free(tmp);
     1849    chdir(bkpinfo->scratchdir);
     1850
     1851    if (bkpinfo->call_before_iso[0] != '\0') {
     1852        asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
     1853                g_current_media_number);
     1854        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
     1855                          destfile, g_current_media_number,
     1856                          MONDO_LOGFILE, message_to_screen);
     1857        if (res) {
     1858            log_to_screen("%s...failed", message_to_screen);
     1859        } else {
     1860            log_to_screen("%s...OK", message_to_screen);
     1861        }
     1862        paranoid_free(message_to_screen);
     1863        retval += res;
     1864    }
     1865
     1866    if (bkpinfo->call_make_iso[0] != '\0') {
     1867        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
     1868        asprintf(&tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     1869        asprintf(&message_to_screen, "Making an ISO (%s #%d)",
     1870                media_descriptor_string(bkpinfo->backup_media_type),
     1871                g_current_media_number);
     1872
     1873        /* if g_current_media_number >= 2 then pause & ask */
     1874        pause_and_ask_for_cdr(2, &cd_is_mountable);
     1875        if (retval) {
     1876            log_to_screen
     1877                ("Serious error(s) occurred already. I shan't try to write to media.");
     1878        } else {
     1879            res =
     1880                eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1881                              bkpinfo->scratchdir,
     1882                              g_current_media_number,
     1883                              MONDO_LOGFILE, message_to_screen);
     1884            if (res) {
     1885                log_to_screen("%s...failed to write", message_to_screen);
     1886            } else {
     1887                log_to_screen("%s...OK", message_to_screen);
     1888                if (!run_program_and_log_output
     1889                    ("tail -n10 /var/log/mondo-archive.log | fgrep \":-(\"",
     1890                     1)) {
     1891                    log_to_screen
     1892                        ("Despite nonfatal errors, growisofs confirms the write was successful.");
     1893                }
     1894            }
     1895            retval += res;
    18251896#ifdef DVDRWFORMAT
    1826           sprintf(tmp, "cat %s | tail -n8 | grep \"blank=full.*dvd-compat.*DAO\"", MONDO_LOGFILE);
    1827       if (g_backup_media_type == dvd && (res || !run_program_and_log_output(tmp, 1)))
    1828             {
    1829           log_to_screen("Failed to write to disk. I shall blank it and then try again.");
    1830           sleep(5);
    1831           system("sync");
    1832               pause_for_N_seconds(5, "Letting DVD drive settle");
    1833 
    1834 // dvd+rw-format --- OPTION 2
    1835           if (!bkpinfo->please_dont_eject)
    1836         {
    1837           log_to_screen("Ejecting media to clear drive status.");
    1838           eject_device(bkpinfo->media_device);
    1839           inject_device(bkpinfo->media_device);
    1840         }
    1841               pause_for_N_seconds(5, "Letting DVD drive settle");
    1842           sprintf(sz_blank_disk, "dvd+rw-format %s", bkpinfo->media_device);
    1843           log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
    1844               res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1845           if (res)
    1846             {
    1847           log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
    1848                   pause_for_N_seconds(5, "Letting DVD drive settle... and trying again.");
    1849                   res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1850                   if (res) { log_to_screen("Format failed a second time."); }
    1851         }
    1852           else { log_to_screen("Format succeeded. Sleeping for 5 seconds to take a breath..."); }
    1853               pause_for_N_seconds(5, "Letting DVD drive settle");
    1854           if (!bkpinfo->please_dont_eject)
    1855         {
    1856           log_to_screen("Ejecting media to clear drive status.");
    1857           eject_device(bkpinfo->media_device);
    1858           inject_device(bkpinfo->media_device);
    1859         }
    1860               pause_for_N_seconds(5, "Letting DVD drive settle");
    1861           res = eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1862            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1863           retval += res;
    1864           if (!bkpinfo->please_dont_eject)
    1865         {
    1866           log_to_screen("Ejecting media.");
    1867           eject_device(bkpinfo->media_device);
    1868         }
    1869           if (res)
    1870             { log_to_screen("Dagnabbit. It still failed."); }
    1871           else
    1872             { log_to_screen("OK, this time I successfully backed up to DVD."); }
    1873         }
     1897            asprintf(&tmp,
     1898                    "cat %s | tail -n8 | grep \"blank=full.*dvd-compat.*DAO\"",
     1899                    MONDO_LOGFILE);
     1900            if (g_backup_media_type == dvd
     1901                && (res || !run_program_and_log_output(tmp, 1))) {
     1902                log_to_screen
     1903                    ("Failed to write to disk. I shall blank it and then try again.");
     1904                sleep(5);
     1905                system("sync");
     1906                pause_for_N_seconds(5, "Letting DVD drive settle");
     1907
     1908                // dvd+rw-format --- OPTION 2
     1909                if (!bkpinfo->please_dont_eject) {
     1910                    log_to_screen("Ejecting media to clear drive status.");
     1911                    eject_device(bkpinfo->media_device);
     1912                    inject_device(bkpinfo->media_device);
     1913                }
     1914                pause_for_N_seconds(5, "Letting DVD drive settle");
     1915                asprintf(&sz_blank_disk, "dvd+rw-format %s", bkpinfo->media_device);
     1916                log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
     1917                res =
     1918                    run_external_binary_with_percentage_indicator_NEW
     1919                    ("Blanking DVD disk", sz_blank_disk);
     1920                if (res) {
     1921                    log_to_screen
     1922                        ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
     1923                    pause_for_N_seconds(5,
     1924                                        "Letting DVD drive settle... and trying again.");
     1925                    res =
     1926                        run_external_binary_with_percentage_indicator_NEW
     1927                        ("Blanking DVD disk", sz_blank_disk);
     1928                    if (res) {
     1929                        log_to_screen("Format failed a second time.");
     1930                    }
     1931                } else {
     1932                    log_to_screen
     1933                        ("Format succeeded. Sleeping for 5 seconds to take a breath...");
     1934                }
     1935                paranoid_free(sz_blank_disk);
     1936                pause_for_N_seconds(5, "Letting DVD drive settle");
     1937                if (!bkpinfo->please_dont_eject) {
     1938                    log_to_screen("Ejecting media to clear drive status.");
     1939                    eject_device(bkpinfo->media_device);
     1940                    inject_device(bkpinfo->media_device);
     1941                }
     1942                pause_for_N_seconds(5, "Letting DVD drive settle");
     1943                res =
     1944                    eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1945                                          bkpinfo->scratchdir,
     1946                                          g_current_media_number,
     1947                                          MONDO_LOGFILE,
     1948                                          message_to_screen);
     1949                retval += res;
     1950                if (!bkpinfo->please_dont_eject) {
     1951                    log_to_screen("Ejecting media.");
     1952                    eject_device(bkpinfo->media_device);
     1953                }
     1954                if (res) {
     1955                    log_to_screen("Dagnabbit. It still failed.");
     1956                } else {
     1957                    log_to_screen
     1958                        ("OK, this time I successfully backed up to DVD.");
     1959                }
     1960            }
     1961            paranoid_free(tmp);
    18741962#endif
    1875       if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject)
    1876         { eject_device(bkpinfo->media_device); }
    1877      }
    1878     }
    1879   else
    1880     {
    1881       sprintf (message_to_screen, "Running mkisofs to make %s #%d",
    1882            media_descriptor_string(bkpinfo->backup_media_type),
    1883            g_current_media_number);
    1884       log_msg (1, message_to_screen);
    1885       sprintf (result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    1886             media_descriptor_string(bkpinfo->backup_media_type),
    1887             g_current_media_number);
    1888       if (bkpinfo->nonbootable_backup)
    1889         {
    1890           log_msg (1, "Making nonbootable backup");
     1963            if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
     1964                eject_device(bkpinfo->media_device);
     1965            }
     1966        }
     1967        paranoid_free(message_to_screen);
     1968    } else {
     1969        asprintf(&message_to_screen, "Running mkisofs to make %s #%d",
     1970                media_descriptor_string(bkpinfo->backup_media_type),
     1971                g_current_media_number);
     1972        log_msg(1, message_to_screen);
     1973        asprintf(&result_sz, "Call to mkisofs to make ISO (%s #%d) ",
     1974                media_descriptor_string(bkpinfo->backup_media_type),
     1975                g_current_media_number);
     1976        if (bkpinfo->nonbootable_backup) {
     1977            log_msg(1, "Making nonbootable backup");
    18911978// FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
    1892           res =
    1893         eval_call_to_make_ISO (bkpinfo,
    1894            "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1895            destfile, g_current_media_number, MONDO_LOGFILE,
    1896            message_to_screen);
    1897         }
    1898       else
    1899         {
    1900           log_msg (1, "Making bootable backup");
     1979            res =
     1980                eval_call_to_make_ISO(bkpinfo,
     1981                                      "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1982                                      destfile, g_current_media_number,
     1983                                      MONDO_LOGFILE, message_to_screen);
     1984        } else {
     1985            log_msg(1, "Making bootable backup");
    19011986
    19021987#ifdef __FreeBSD__
    1903           bkpinfo->make_cd_use_lilo = TRUE;
     1988            bkpinfo->make_cd_use_lilo = TRUE;
    19041989#endif
    19051990
    19061991
    1907           log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo);
    1908           if (bkpinfo->make_cd_use_lilo)
    1909             {
    1910               log_msg(1, "make_cd_use_lilo = TRUE");
     1992            log_msg(1, "make_cd_use_lilo is actually %d",
     1993                    bkpinfo->make_cd_use_lilo);
     1994            if (bkpinfo->make_cd_use_lilo) {
     1995                log_msg(1, "make_cd_use_lilo = TRUE");
    19111996// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19121997// and add ' .' at end
    19131998#ifdef __IA64__
    1914               log_msg(1, "IA64 --> elilo");
    1915               res =
    1916                 eval_call_to_make_ISO (bkpinfo,
    1917                     //-b images/mindi-boot.2880.img
    1918             "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#_ .",
    1919                     destfile, g_current_media_number, MONDO_LOGFILE,
    1920                     message_to_screen);
     1999                log_msg(1, "IA64 --> elilo");
     2000                res = eval_call_to_make_ISO(bkpinfo,
     2001                                            "mkisofs -no-emul-boot -b images/mindi-bootroot."
     2002                                            IA64_BOOT_SIZE
     2003                                            ".img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2004                                            destfile,
     2005                                            g_current_media_number,
     2006                                            MONDO_LOGFILE,
     2007                                            message_to_screen);
    19212008#else
    19222009// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19232010// and add ' .' at end
    1924           log_msg(1, "Non-ia64 --> lilo");
    1925               res =
    1926                 eval_call_to_make_ISO (bkpinfo,
    1927                     "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#_ .",
    1928                     destfile, g_current_media_number, MONDO_LOGFILE,
    1929                     message_to_screen);
     2011                log_msg(1, "Non-ia64 --> lilo");
     2012                res =
     2013                    eval_call_to_make_ISO(bkpinfo,
     2014                                          "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#_ .",
     2015                                          destfile, g_current_media_number,
     2016                                          MONDO_LOGFILE,
     2017                                          message_to_screen);
    19302018#endif
    1931             }
    1932           else
    1933             {
    1934               log_msg(1, "make_cd_use_lilo = FALSE");
    1935           log_msg(1, "Isolinux");
    1936               res =
    1937             eval_call_to_make_ISO (bkpinfo,
    1938                    "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#_ .",
    1939            destfile, g_current_media_number, MONDO_LOGFILE,
    1940            message_to_screen);
    1941             }
    1942         }
    1943       if (res)
    1944     {
    1945       strcat (result_sz, "...failed");
    1946     }
    1947       else
    1948     {
    1949       strcat (result_sz, "...OK");
    1950     }
    1951       log_to_screen (result_sz);
    1952       retval += res;
    1953     }
    1954 
    1955   if (bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw)
    1956     {
    1957       if (is_this_device_mounted(bkpinfo->media_device))
    1958         {
    1959           log_msg (2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device);
    1960           sprintf(tmp, "umount %s", bkpinfo->media_device);
    1961           run_program_and_log_output(tmp, FALSE);
    1962         }
    1963     }
    1964 
    1965   if (bkpinfo->call_burn_iso[0] != '\0')
    1966     {
    1967       log_msg (2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    1968       sprintf (message_to_screen, "Burning %s #%d",
    1969             media_descriptor_string(bkpinfo->backup_media_type),
    1970            g_current_media_number);
    1971       pause_and_ask_for_cdr (2, &cd_is_mountable);
    1972       res =
    1973     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_burn_iso, destfile,
    1974            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1975       if (res)
    1976     {
    1977       strcat (message_to_screen, "...failed");
    1978     }
    1979       else
    1980     {
    1981       strcat (message_to_screen, "...OK");
    1982     }
    1983       log_to_screen (message_to_screen);
    1984       retval += res;
    1985     }
    1986 
    1987   if (bkpinfo->call_after_iso[0] != '\0')
    1988     {
    1989       sprintf (message_to_screen, "Running post-ISO call (%s #%d)",
    1990             media_descriptor_string(bkpinfo->backup_media_type),
    1991            g_current_media_number);
    1992       res =
    1993     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_after_iso, destfile,
    1994            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1995       if (res)
    1996     {
    1997       strcat (message_to_screen, "...failed");
    1998     }
    1999       else
    2000     {
    2001       strcat (message_to_screen, "...OK");
    2002     }
    2003       log_to_screen (message_to_screen);
    2004       retval += res;
    2005     }
    2006 
    2007   chdir (old_pwd);
    2008   if (retval)
    2009     {
    2010       log_msg (1, "WARNING - make_iso_fs returned an error");
    2011     }
    2012   paranoid_free(old_pwd);
    2013   paranoid_free(result_sz);
    2014   paranoid_free(message_to_screen);
    2015   paranoid_free(sz_blank_disk);
    2016   paranoid_free(fnam);
    2017   paranoid_free(tmp);
    2018   return (retval);
     2019            } else {
     2020                log_msg(1, "make_cd_use_lilo = FALSE");
     2021                log_msg(1, "Isolinux");
     2022                res = eval_call_to_make_ISO(bkpinfo,
     2023                                          "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#_ .",
     2024                                          destfile, g_current_media_number,
     2025                                          MONDO_LOGFILE,
     2026                                          message_to_screen);
     2027            }
     2028        }
     2029        if (res) {
     2030            log_to_screen("%s...failed", result_sz);
     2031        } else {
     2032            log_to_screen("%s...OK", result_sz);
     2033        }
     2034        retval += res;
     2035        paranoid_free(message_to_screen);
     2036        paranoid_free(result_sz);
     2037    }
     2038
     2039    if (bkpinfo->backup_media_type == cdr
     2040        || bkpinfo->backup_media_type == cdrw) {
     2041        if (is_this_device_mounted(bkpinfo->media_device)) {
     2042            log_msg(2,
     2043                    "Warning - %s mounted. I'm unmounting it before I burn to it.",
     2044                    bkpinfo->media_device);
     2045            asprintf(&tmp, "umount %s", bkpinfo->media_device);
     2046            run_program_and_log_output(tmp, FALSE);
     2047            paranoid_free(tmp);
     2048        }
     2049    }
     2050
     2051    if (bkpinfo->call_burn_iso[0] != '\0') {
     2052        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
     2053        asprintf(&message_to_screen, "Burning %s #%d",
     2054                media_descriptor_string(bkpinfo->backup_media_type),
     2055                g_current_media_number);
     2056        pause_and_ask_for_cdr(2, &cd_is_mountable);
     2057        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
     2058                                  destfile, g_current_media_number,
     2059                                  MONDO_LOGFILE, message_to_screen);
     2060        if (res) {
     2061            log_to_screen("%s...failed", message_to_screen);
     2062        } else {
     2063            log_to_screen("%s...OK", message_to_screen);
     2064        }
     2065        paranoid_free(message_to_screen);
     2066        retval += res;
     2067    }
     2068
     2069    if (bkpinfo->call_after_iso[0] != '\0') {
     2070        asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
     2071                media_descriptor_string(bkpinfo->backup_media_type),
     2072                g_current_media_number);
     2073        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
     2074                                  destfile, g_current_media_number,
     2075                                  MONDO_LOGFILE, message_to_screen);
     2076        if (res) {
     2077            log_to_screen("%s...failed", message_to_screen);
     2078        } else {
     2079            log_to_screen("%s...OK", message_to_screen);
     2080        }
     2081        paranoid_free(message_to_screen);
     2082        retval += res;
     2083    }
     2084
     2085    chdir(old_pwd);
     2086    if (retval) {
     2087        log_msg(1, "WARNING - make_iso_fs returned an error");
     2088    }
     2089    paranoid_free(old_pwd);
     2090    return (retval);
    20192091}
    2020 
    2021 
    2022 
    2023 
    2024 
    2025 
    2026 
    20272092
    20282093
    20292094bool is_dev_an_NTFS_dev(char *bigfile_fname)
    20302095{
    2031   char *tmp;
    2032   char *command;
    2033   malloc_string(tmp);
    2034   malloc_string(command);
    2035   sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", bigfile_fname);
    2036   log_msg(1, "command = '%s'", command);
    2037   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2038   log_msg(1, "--> tmp = '%s'", tmp);
    2039   if (strstr(tmp, "NTFS"))
    2040     { iamhere("TRUE"); return(TRUE); }
    2041   else
    2042     { iamhere("FALSE"); return(FALSE); }
     2096    char *tmp;
     2097    char *command;
     2098    asprintf(&command,
     2099            "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
     2100            bigfile_fname);
     2101    log_msg(1, "command = '%s'", command);
     2102    asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     2103    log_msg(1, "--> tmp = '%s'", tmp);
     2104    paranoid_free(command);
     2105    if (strstr(tmp, "NTFS")) {
     2106        iamhere("TRUE");
     2107        paranoid_free(tmp);
     2108        return (TRUE);
     2109    } else {
     2110        iamhere("FALSE");
     2111        paranoid_free(tmp);
     2112        return (FALSE);
     2113    }
    20432114}
    20442115
     
    20592130 */
    20602131int
    2061 make_slices_and_images (struct s_bkpinfo *bkpinfo, char *biggielist_fname)
     2132make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
    20622133{
    20632134
    2064     /*@ pointers ********************************************/
    2065   FILE *fin;
    2066   char *p;
    2067 
    2068     /*@ buffers *********************************************/
    2069   char *tmp;
    2070   char *bigfile_fname;
    2071   char *sz_devfile;
    2072   char *partimagehack_fifo = NULL;
    2073     /*@ long ************************************************/
    2074   long biggie_file_number = 0;
    2075   long noof_biggie_files = 0;
    2076   long estimated_total_noof_slices = 0;
    2077 
    2078     /*@ int *************************************************/
    2079   int retval = 0;
    2080   int res = 0;
    2081   pid_t pid;
    2082   FILE*ftmp=NULL;
    2083   bool delete_when_done; 
    2084   bool use_partimagehack;
    2085     /*@ long long *******************************************/
    2086   long long biggie_fsize;
    2087 
    2088   assert(bkpinfo!=NULL);
    2089   assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
    2090 
    2091   malloc_string(tmp);
    2092   malloc_string(bigfile_fname);
    2093   malloc_string(sz_devfile);
    2094   estimated_total_noof_slices =
    2095     size_of_all_biggiefiles_K (bkpinfo) / bkpinfo->optimal_set_size + 1;
    2096 
    2097   log_msg (1, "size of all biggiefiles = %ld",
    2098        size_of_all_biggiefiles_K (bkpinfo));
    2099   log_msg (1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
    2100        size_of_all_biggiefiles_K (bkpinfo), bkpinfo->optimal_set_size,
    2101        estimated_total_noof_slices);
    2102 
    2103   if (length_of_file (biggielist_fname) < 6)
    2104     {
    2105       log_msg (1, "No biggiefiles; fair enough...");
    2106       return (0);
    2107     }
    2108   sprintf (tmp, "I am now backing up all large files.");
    2109   log_to_screen (tmp);
    2110   noof_biggie_files = count_lines_in_file (biggielist_fname);
    2111   open_progress_form ("Backing up big files", tmp,
    2112               "Please wait. This may take some time.", "",
    2113               estimated_total_noof_slices);
    2114   if (!(fin = fopen (biggielist_fname, "r"))) { log_OS_error("Unable to openin biggielist"); return(1); }
    2115   for (fgets (bigfile_fname, MAX_STR_LEN, fin); !feof (fin);
    2116        fgets (bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++)
    2117     {
    2118       use_partimagehack = FALSE;
    2119       if (bigfile_fname[strlen (bigfile_fname) - 1] < 32)
    2120     {
    2121       bigfile_fname[strlen (bigfile_fname) - 1] = '\0';
    2122     }
    2123       biggie_fsize = length_of_file (bigfile_fname);
    2124       delete_when_done = FALSE;
    2125      
    2126       if (!does_file_exist (bigfile_fname))
    2127     {
    2128           ftmp = fopen(bigfile_fname, "w");
    2129       paranoid_fclose(ftmp);
    2130       sprintf (tmp, "bigfile %s was deleted - creating a dummy", bigfile_fname);
    2131       delete_when_done = TRUE;
    2132     }
    2133       else
    2134         {
    2135 // Call partimagehack if it's a /dev entry (i.e. a partition to be imaged)
    2136           log_msg (2, "bigfile_fname = %s", bigfile_fname);
    2137       use_partimagehack = FALSE;
    2138       if (!strncmp ( bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname))
    2139             {
    2140           use_partimagehack = TRUE;
    2141           log_msg (2, "Calling partimagehack in background because %s is an NTFS partition", bigfile_fname);
    2142               sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    2143           mkfifo(sz_devfile, 0x770);
    2144           partimagehack_fifo = sz_devfile;
    2145               switch(pid=fork())
    2146                 {
    2147                   case -1: fatal_error("Fork failure");
    2148               case 0:
    2149             log_msg (2, "CHILD - fip - calling feed_into_partimage(%s, %s)", bigfile_fname, sz_devfile);
    2150             res=feed_into_partimage(bigfile_fname, sz_devfile);
    2151             exit(res);
    2152             break;
    2153                   default:
    2154             log_msg (2, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    2155                 }
    2156         }
    2157 // Otherwise, use good old 'dd' and 'bzip2'
    2158           else
    2159         {
    2160           sz_devfile[0] = '\0';
    2161           partimagehack_fifo = NULL;
    2162         }
    2163 
    2164 // Whether partition or biggiefile, just do your thang :-)
    2165       sprintf (tmp, "Bigfile #%ld is '%s' (%ld KB)", biggie_file_number+1,
    2166            bigfile_fname, (long) biggie_fsize >> 10);
    2167           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2168         {
    2169           write_header_block_to_stream (biggie_fsize, bigfile_fname,
    2170                       use_partimagehack?BLK_START_A_PIHBIGGIE:BLK_START_A_NORMBIGGIE);
    2171         }
    2172       res =
    2173         slice_up_file_etc (bkpinfo, bigfile_fname, partimagehack_fifo,
    2174             biggie_file_number, noof_biggie_files, use_partimagehack);
    2175           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2176         {
    2177           write_header_block_to_stream (0,
    2178                       calc_checksum_of_file
    2179                       (bigfile_fname), BLK_STOP_A_BIGGIE);
    2180         }
    2181       retval += res;
    2182       p = strrchr (bigfile_fname, '/');
    2183       if (p)
    2184         {
    2185           p++;
    2186         }
    2187       else
    2188         {
    2189           p = bigfile_fname;
    2190         }
    2191       sprintf (tmp, "Archiving %s ... ", bigfile_fname);
    2192       if (res)
    2193         {
    2194           strcat (tmp, "Failed!");
    2195         }
    2196       else
    2197         {
    2198           strcat (tmp, "OK");
    2199         }
    2200       if (delete_when_done)
    2201         { unlink(bigfile_fname); delete_when_done=FALSE; }
    2202     }
     2135    /*@ pointers ******************************************* */
     2136    FILE *fin;
     2137    char *p;
     2138
     2139    /*@ buffers ******************************************** */
     2140    char *tmp;
     2141    char *bigfile_fname;
     2142    char *sz_devfile;
     2143    char *partimagehack_fifo = NULL;
     2144    /*@ long *********************************************** */
     2145    long biggie_file_number = 0;
     2146    long noof_biggie_files = 0;
     2147    long estimated_total_noof_slices = 0;
     2148
     2149    /*@ int ************************************************ */
     2150    int retval = 0;
     2151    int res = 0;
     2152    pid_t pid;
     2153    FILE *ftmp = NULL;
     2154    bool delete_when_done;
     2155    bool use_partimagehack;
     2156    /*@ long long ****************************************** */
     2157    long long biggie_fsize;
     2158
     2159    assert(bkpinfo != NULL);
     2160    assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
     2161
     2162    malloc_string(bigfile_fname);
     2163    estimated_total_noof_slices =
     2164        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
     2165
     2166    log_msg(1, "size of all biggiefiles = %ld",
     2167            size_of_all_biggiefiles_K(bkpinfo));
     2168    log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
     2169            size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
     2170            estimated_total_noof_slices);
     2171
     2172    if (length_of_file(biggielist_fname) < 6) {
     2173        log_msg(1, "No biggiefiles; fair enough...");
     2174        return (0);
     2175    }
     2176    asprintf(&tmp, "I am now backing up all large files.");
     2177    log_to_screen(tmp);
     2178    noof_biggie_files = count_lines_in_file(biggielist_fname);
     2179    open_progress_form("Backing up big files", tmp,
     2180                       "Please wait. This may take some time.", "",
     2181                       estimated_total_noof_slices);
     2182    if (!(fin = fopen(biggielist_fname, "r"))) {
     2183        log_OS_error("Unable to openin biggielist");
     2184        return (1);
     2185    }
     2186    for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
     2187         fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
     2188        use_partimagehack = FALSE;
     2189        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
     2190            bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
     2191        }
     2192        biggie_fsize = length_of_file(bigfile_fname);
     2193        delete_when_done = FALSE;
     2194
     2195        if (!does_file_exist(bigfile_fname)) {
     2196            ftmp = fopen(bigfile_fname, "w");
     2197            paranoid_fclose(ftmp);
     2198            asprintf(&tmp, "bigfile %s was deleted - creating a dummy",
     2199                    bigfile_fname);
     2200            delete_when_done = TRUE;
     2201        } else {
     2202            // Call partimagehack if it's a /dev entry (i.e. a partition to be imaged)
     2203            log_msg(2, "bigfile_fname = %s", bigfile_fname);
     2204            use_partimagehack = FALSE;
     2205            if (!strncmp(bigfile_fname, "/dev/", 5)
     2206                && is_dev_an_NTFS_dev(bigfile_fname)) {
     2207                use_partimagehack = TRUE;
     2208                log_msg(2,
     2209                        "Calling partimagehack in background because %s is an NTFS partition",
     2210                        bigfile_fname);
     2211                asprintf(&sz_devfile, "/tmp/%d.%d.000",
     2212                        (int) (random() % 32768),
     2213                        (int) (random() % 32768));
     2214                mkfifo(sz_devfile, 0x770);
     2215                partimagehack_fifo = sz_devfile;
     2216                switch (pid = fork()) {
     2217                case -1:
     2218                    fatal_error("Fork failure");
     2219                case 0:
     2220                    log_msg(2,
     2221                            "CHILD - fip - calling feed_into_partimage(%s, %s)",
     2222                            bigfile_fname, sz_devfile);
     2223                    res = feed_into_partimage(bigfile_fname, sz_devfile);
     2224                    exit(res);
     2225                    break;
     2226                default:
     2227                    log_msg(2,
     2228                            "feed_into_partimage() called in background --- pid=%ld",
     2229                            (long int) (pid));
     2230
     2231                paranoid_free(sz_devfile);
     2232                }
     2233            }
     2234            // Otherwise, use good old 'dd' and 'bzip2'
     2235            else {
     2236                partimagehack_fifo = NULL;
     2237            }
     2238
     2239            // Whether partition or biggiefile, just do your thang :-)
     2240            log_msg(2, "Bigfile #%ld is '%s' (%ld KB)",
     2241                    biggie_file_number + 1, bigfile_fname,
     2242                    (long) biggie_fsize >> 10);
     2243            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2244                write_header_block_to_stream(biggie_fsize, bigfile_fname,
     2245                                             use_partimagehack ?
     2246                                             BLK_START_A_PIHBIGGIE :
     2247                                             BLK_START_A_NORMBIGGIE);
     2248            }
     2249            res = slice_up_file_etc(bkpinfo, bigfile_fname,
     2250                                  partimagehack_fifo, biggie_file_number,
     2251                                  noof_biggie_files, use_partimagehack);
     2252            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2253                write_header_block_to_stream(0,
     2254                                             calc_checksum_of_file
     2255                                             (bigfile_fname),
     2256                                             BLK_STOP_A_BIGGIE);
     2257            }
     2258            retval += res;
     2259            p = strrchr(bigfile_fname, '/');
     2260            if (p) {
     2261                p++;
     2262            } else {
     2263                p = bigfile_fname;
     2264            }
     2265            paranoid_free(tmp);
     2266            if (res) {
     2267                asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
     2268            } else {
     2269                asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname);
     2270            }
     2271
     2272            if (delete_when_done) {
     2273                unlink(bigfile_fname);
     2274                delete_when_done = FALSE;
     2275            }
     2276        }
    22032277#ifndef _XWIN
    2204       if (!g_text_mode) { newtDrawRootText (0, g_noof_rows - 2, tmp); newtRefresh (); }
     2278        if (!g_text_mode) {
     2279            newtDrawRootText(0, g_noof_rows - 2, tmp);
     2280            newtRefresh();
     2281        }
    22052282#endif
    2206     }
    2207   log_msg (1, "Finished backing up bigfiles");
    2208   log_msg (1, "estimated slices = %ld; actual slices = %ld",
    2209        estimated_total_noof_slices, g_current_progress);
    2210   close_progress_form ();
    2211   paranoid_fclose(fin);
    2212   paranoid_free(tmp);
    2213   paranoid_free(bigfile_fname);
    2214   paranoid_free(sz_devfile);
    2215   return (retval);
     2283    }
     2284    paranoid_free(tmp);
     2285    log_msg(1, "Finished backing up bigfiles");
     2286    log_msg(1, "estimated slices = %ld; actual slices = %ld",
     2287            estimated_total_noof_slices, g_current_progress);
     2288    close_progress_form();
     2289    paranoid_fclose(fin);
     2290    paranoid_free(bigfile_fname);
     2291    return (retval);
    22162292}
    22172293
     
    22232299 * @see make_afioballs_and_images
    22242300 */
    2225 int
    2226 make_afioballs_and_images_OLD (struct s_bkpinfo *bkpinfo)
     2301int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
    22272302{
    22282303
    2229     /*@ int ***************************************************/
    2230   int retval = 0;
    2231   long int curr_set_no = 0;
    2232   int res = 0;
    2233  
    2234     /*@ buffers ***********************************************/
    2235   char *curr_filelist_fname;
    2236   char *curr_afioball_fname;
    2237   char *curr_xattr_list_fname;
    2238   char *curr_acl_list_fname;
    2239   char *tmp;
    2240   char *media_usage_comment;
    2241  
    2242   malloc_string(curr_afioball_fname);
    2243   malloc_string(media_usage_comment);
    2244   malloc_string(curr_filelist_fname);
    2245   malloc_string(curr_xattr_list_fname);
    2246   malloc_string(curr_acl_list_fname);
    2247  
    2248   tmp = malloc(MAX_STR_LEN*2);
    2249  
    2250   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    2251 
    2252   log_to_screen ("Archiving regular files");
    2253 
    2254   open_progress_form ("Backing up filesystem",
    2255               "I am backing up your live filesystem now.",
    2256               "Please wait. This may take a couple of hours.",
    2257               "Working...", get_last_filelist_number (bkpinfo) + 1);
    2258 
    2259   sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
    2260 
    2261   for (curr_set_no = 0; does_file_exist (curr_filelist_fname);
    2262        sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    2263         ++curr_set_no))
    2264     {
    2265       /* backup this set of files */
    2266       sprintf (curr_filelist_fname,  FILELIST_FNAME_RAW_SZ,  bkpinfo->tmpdir, curr_set_no);
    2267       sprintf (curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,bkpinfo->tmpdir,
    2268                curr_set_no, bkpinfo->zip_suffix);
    2269      
    2270       log_msg (1, "EXAT'g set %ld", curr_set_no);
    2271       sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
    2272       sprintf (curr_acl_list_fname,   ACL_LIST_FNAME_RAW_SZ,   bkpinfo->tmpdir, curr_set_no);
    2273       get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
    2274       get_acl_list(curr_filelist_fname, curr_acl_list_fname);
    2275      
    2276       log_msg (1, "Archiving set %ld", curr_set_no);
    2277       res =
    2278     archive_this_fileset (bkpinfo, curr_filelist_fname, curr_afioball_fname, curr_set_no);
    2279       retval += res;
    2280       if (res)
    2281     {
    2282       sprintf (tmp,
    2283            "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
    2284            curr_set_no);
    2285       log_to_screen (tmp);
    2286     }
    2287 
    2288       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    2289 
    2290       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    2291       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2292         {
    2293               register_in_tape_catalog(fileset, curr_set_no, -1, curr_afioball_fname);
    2294               maintain_collection_of_recent_archives(bkpinfo->tmpdir, curr_afioball_fname);
    2295           iamhere("Writing EXAT files");
    2296               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
    2297 // archives themselves
    2298               res = move_files_to_stream (bkpinfo, curr_afioball_fname, NULL);
    2299         }
    2300       else
    2301         {
    2302           res = move_files_to_cd (bkpinfo, curr_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, curr_afioball_fname, NULL);
    2303         }
    2304       retval += res;
    2305       g_current_progress++;
    2306       update_progress_form (media_usage_comment);
    2307 
    2308       if (res)
    2309     {
    2310       sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    2311            curr_set_no);
    2312       log_to_screen (tmp);
    2313       fatal_error
    2314         ("Is your hard disk is full? If not, please send the author the logfile.");
    2315     }
    2316     }
    2317   close_progress_form ();
    2318   sprintf (tmp, "Your regular files have been archived ");
    2319   if (retval)
    2320     {
    2321       strcat (tmp, "(with errors).");
    2322     }
    2323   else
    2324     {
    2325       strcat (tmp, "successfully.");
    2326     }
    2327   log_to_screen (tmp);
    2328   paranoid_free(tmp);
    2329   paranoid_free(curr_filelist_fname);
    2330   paranoid_free(curr_afioball_fname);
    2331   paranoid_free(media_usage_comment);
    2332   paranoid_free(curr_xattr_list_fname);
    2333   paranoid_free(curr_acl_list_fname);
    2334   return (retval);
     2304    /*@ int ************************************************** */
     2305    int retval = 0;
     2306    long int curr_set_no = 0;
     2307    int res = 0;
     2308
     2309    /*@ buffers ********************************************** */
     2310    char *curr_filelist_fname;
     2311    char *curr_afioball_fname;
     2312    char *curr_xattr_list_fname;
     2313    char *curr_acl_list_fname;
     2314    char *tmp;
     2315    char *media_usage_comment;
     2316
     2317    /* BERLIOS: Useless ?
     2318    asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     2319    */
     2320
     2321    log_to_screen("Archiving regular files");
     2322
     2323    open_progress_form("Backing up filesystem",
     2324                       "I am backing up your live filesystem now.",
     2325                       "Please wait. This may take a couple of hours.",
     2326                       "Working...",
     2327                       get_last_filelist_number(bkpinfo) + 1);
     2328
     2329    asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
     2330            0L);
     2331
     2332    curr_set_no = 0;
     2333    while (does_file_exist(curr_filelist_fname)) {
     2334        /* backup this set of files */
     2335        asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     2336                bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
     2337
     2338        log_msg(1, "EXAT'g set %ld", curr_set_no);
     2339        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     2340                bkpinfo->tmpdir, curr_set_no);
     2341        asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     2342                bkpinfo->tmpdir, curr_set_no);
     2343        get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
     2344        get_acl_list(curr_filelist_fname, curr_acl_list_fname);
     2345
     2346        log_msg(1, "Archiving set %ld", curr_set_no);
     2347        res = archive_this_fileset(bkpinfo, curr_filelist_fname,
     2348                                 curr_afioball_fname, curr_set_no);
     2349        retval += res;
     2350        if (res) {
     2351            asprintf(&tmp,
     2352                    "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
     2353                    curr_set_no);
     2354            log_to_screen(tmp);
     2355            paranoid_free(tmp);
     2356        }
     2357
     2358        asprintf(&media_usage_comment, "%s", percent_media_full_comment(bkpinfo));
     2359
     2360        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     2361        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2362            register_in_tape_catalog(fileset, curr_set_no, -1,
     2363                                     curr_afioball_fname);
     2364            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     2365                                                   curr_afioball_fname);
     2366            iamhere("Writing EXAT files");
     2367            res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
     2368                                         curr_acl_list_fname);
     2369            // archives themselves
     2370            res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
     2371        } else {
     2372            res = move_files_to_cd(bkpinfo, curr_filelist_fname,
     2373                                 curr_xattr_list_fname,
     2374                                 curr_acl_list_fname, curr_afioball_fname,
     2375                                 NULL);
     2376        }
     2377        retval += res;
     2378        g_current_progress++;
     2379        update_progress_form(media_usage_comment);
     2380        paranoid_free(media_usage_comment);
     2381
     2382        if (res) {
     2383            asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
     2384                    curr_set_no);
     2385            log_to_screen(tmp);
     2386            paranoid_free(tmp);
     2387            fatal_error
     2388                ("Is your hard disk is full? If not, please send the author the logfile.");
     2389        }
     2390        paranoid_free(curr_filelist_fname);
     2391        paranoid_free(curr_afioball_fname);
     2392        paranoid_free(curr_xattr_list_fname);
     2393        paranoid_free(curr_acl_list_fname);
     2394        asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
     2395                 bkpinfo->tmpdir, ++curr_set_no);
     2396    }
     2397    paranoid_free(curr_filelist_fname);
     2398    close_progress_form();
     2399    if (retval) {
     2400        log_to_screen("Your regular files have been archived (with errors).");
     2401    } else {
     2402        log_to_screen("Your regular files have been archived successfully.");
     2403    }
     2404    return(retval);
    23352405}
    23362406
    2337 /* @} - end of LLarchiveGroup */ 
    2338  
    2339  
     2407/* @} - end of LLarchiveGroup */
     2408
     2409
    23402410/**
    23412411 * Wrapper around @c make_afioballs_and_images().
     
    23462416 * @ingroup MLarchiveGroup
    23472417 */
    2348 int
    2349 make_those_afios_phase (struct s_bkpinfo *bkpinfo)
     2418int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
    23502419{
    2351     /*@ int ********************************************/
    2352   int res = 0;
    2353   int retval = 0;
    2354 
    2355   assert(bkpinfo!=NULL);
    2356 
    2357   mvaddstr_and_log_it (g_currentY, 0, "Archiving regular files to media          ");
    2358 
    2359   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2360     {
    2361       write_header_block_to_stream (0, "start-of-afioballs",
    2362                   BLK_START_AFIOBALLS);
     2420    /*@ int ******************************************* */
     2421    int res = 0;
     2422    int retval = 0;
     2423
     2424    assert(bkpinfo != NULL);
     2425
     2426    mvaddstr_and_log_it(g_currentY, 0,
     2427                        "Archiving regular files to media          ");
     2428
     2429    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2430        write_header_block_to_stream(0, "start-of-afioballs",
     2431                                    BLK_START_AFIOBALLS);
    23632432#if __FreeBSD__ == 5
    2364       log_msg (1, "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
    2365       res = make_afioballs_and_images_OLD (bkpinfo);
     2433        log_msg(1,
     2434                "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
     2435        res = make_afioballs_and_images_OLD(bkpinfo);
    23662436#else
    2367       res = make_afioballs_and_images_OLD (bkpinfo);
     2437        res = make_afioballs_and_images_OLD(bkpinfo);
    23682438#endif
    2369       write_header_block_to_stream (0, "stop-afioballs", BLK_STOP_AFIOBALLS);
    2370     }
    2371   else
    2372     {
    2373       res = make_afioballs_and_images (bkpinfo);
    2374     }
    2375 
    2376   retval += res;
    2377   if (res)
    2378     {
    2379       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2380       log_msg (1, "make_afioballs_and_images returned an error");
    2381     }
    2382   else
    2383     {
    2384       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2385     }
    2386   return (retval);
     2439        write_header_block_to_stream(0, "stop-afioballs",
     2440                                     BLK_STOP_AFIOBALLS);
     2441    } else {
     2442        res = make_afioballs_and_images(bkpinfo);
     2443    }
     2444
     2445    retval += res;
     2446    if (res) {
     2447        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2448        log_msg(1, "make_afioballs_and_images returned an error");
     2449    } else {
     2450        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2451    }
     2452    return (retval);
    23872453}
    23882454
     
    23962462 * @ingroup MLarchiveGroup
    23972463 */
    2398 int
    2399 make_those_slices_phase (struct s_bkpinfo *bkpinfo)
     2464int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
    24002465{
    24012466
    2402     /*@ int ******************************************************/
    2403   int res = 0;
    2404   int retval = 0;
    2405 
    2406     /*@ buffers ***************************************************/
    2407   char *biggielist;
    2408   char *command;
    2409   char *blah;
    2410   char *xattr_fname;
    2411   char *acl_fname;
    2412  
    2413   assert(bkpinfo!=NULL);
    2414   /* slice big files */
    2415   malloc_string(blah);
    2416   malloc_string(biggielist);
    2417   malloc_string(xattr_fname);
    2418   malloc_string(acl_fname);
    2419   command = malloc(1200);
    2420   mvaddstr_and_log_it (g_currentY, 0, "Archiving large files to media           ");
    2421   sprintf (biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
    2422   sprintf (xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2423   sprintf (acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2424  
    2425   sprintf (command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
    2426   paranoid_system(command);
    2427   sprintf (blah, "biggielist = %s", biggielist);
    2428   log_msg (2, blah);
    2429  
    2430   if (!does_file_exist (biggielist))
    2431     {
    2432       log_msg (1, "BTW, the biggielist does not exist");
    2433     }
    2434 
    2435   get_fattr_list(biggielist, xattr_fname);
    2436   get_acl_list(biggielist, acl_fname);
    2437   sprintf (command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
    2438   paranoid_system(command);
    2439   sprintf (command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
    2440   paranoid_system(command);
    2441 
    2442   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2443     {
    2444       res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
    2445       sprintf (blah, "%ld", count_lines_in_file (biggielist));
    2446       write_header_block_to_stream (0, blah, BLK_START_BIGGIEFILES);
    2447     }
    2448   res = make_slices_and_images (bkpinfo, biggielist);
    2449   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2450     {
    2451       write_header_block_to_stream (0, "end-of-biggiefiles",
    2452                   BLK_STOP_BIGGIEFILES);
    2453     }
    2454   retval += res;
    2455   if (res)
    2456     {
    2457       log_msg (1, "make_slices_and_images returned an error");
    2458       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2459     }
    2460   else
    2461     {
    2462       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2463     }
    2464   paranoid_free(blah);
    2465   paranoid_free(biggielist);
    2466   paranoid_free(command);
    2467   paranoid_free(xattr_fname);
    2468   paranoid_free(acl_fname);
    2469   return (retval);
     2467    /*@ int ***************************************************** */
     2468    int res = 0;
     2469    int retval = 0;
     2470
     2471    /*@ buffers ************************************************** */
     2472    char *biggielist;
     2473    char *command;
     2474    char *blah;
     2475    char *xattr_fname;
     2476    char *acl_fname;
     2477
     2478    assert(bkpinfo != NULL);
     2479    /* slice big files */
     2480    mvaddstr_and_log_it(g_currentY, 0,
     2481                        "Archiving large files to media           ");
     2482    asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
     2483    asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2484    asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2485
     2486    asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
     2487            biggielist);
     2488    paranoid_system(command);
     2489    paranoid_free(command);
     2490    asprintf(&blah, "biggielist = %s", biggielist);
     2491    log_msg(2, blah);
     2492    paranoid_free(blah);
     2493
     2494    if (!does_file_exist(biggielist)) {
     2495        log_msg(1, "BTW, the biggielist does not exist");
     2496    }
     2497
     2498    get_fattr_list(biggielist, xattr_fname);
     2499    get_acl_list(biggielist, acl_fname);
     2500    asprintf(&command, "cp %s %s/archives/", xattr_fname,
     2501            bkpinfo->scratchdir);
     2502    paranoid_system(command);
     2503    paranoid_free(command);
     2504    asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
     2505    paranoid_system(command);
     2506    paranoid_free(command);
     2507
     2508    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2509        res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
     2510        asprintf(&blah, "%ld", count_lines_in_file(biggielist));
     2511        write_header_block_to_stream(0, blah, BLK_START_BIGGIEFILES);
     2512        paranoid_free(blah);
     2513    }
     2514    paranoid_free(xattr_fname);
     2515    paranoid_free(acl_fname);
     2516    res = make_slices_and_images(bkpinfo, biggielist);
     2517    paranoid_free(biggielist);
     2518    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2519        write_header_block_to_stream(0, "end-of-biggiefiles",
     2520                                     BLK_STOP_BIGGIEFILES);
     2521    }
     2522    retval += res;
     2523    if (res) {
     2524        log_msg(1, "make_slices_and_images returned an error");
     2525        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2526    } else {
     2527        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2528    }
     2529    return (retval);
    24702530}
    24712531
     
    24812541 * transfer files over the network) or leave it as is.
    24822542 */
    2483 int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) = _move_files_to_cd;
     2543int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
     2544    _move_files_to_cd;
    24842545
    24852546/**
     
    25012562 * @return The number of errors encountered (0 for success)
    25022563 */
    2503 int
    2504 _move_files_to_cd (struct s_bkpinfo *bkpinfo,
    2505          char *files_to_add, ...)
     2564int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    25062565{
    25072566
    2508     /*@ int *************************************************************/
    2509   int retval = 0;
     2567    /*@ int ************************************************************ */
     2568    int retval = 0;
    25102569    int res = 0;
    25112570
    2512     /*@ buffers *********************************************************/
    2513   char *tmp,
    2514        *curr_file, *cf;
    2515 
    2516     /*@ long *************************************************************/
    2517   va_list ap;
    2518   long long would_occupy;
    2519 
    2520   assert(bkpinfo!=NULL);
    2521   malloc_string(curr_file);
    2522   tmp = malloc(1200);
    2523   would_occupy = space_occupied_by_cd (bkpinfo->scratchdir);
    2524   va_start(ap, files_to_add); // initialize the variable arguments
    2525   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2526     {
    2527       if (!cf) {continue;}
    2528       strcpy(curr_file, cf);
    2529       if (!does_file_exist (curr_file))
    2530     {
    2531       log_msg (1, "Warning - you're trying to add a non-existent file - '%s' to the CD", curr_file);
    2532     }
    2533       else
    2534         {
    2535       log_msg (8, "Trying to add file %s to CD", curr_file);
    2536           would_occupy += length_of_file (curr_file) / 1024;
    2537         }
    2538     }
    2539   va_end(ap);
    2540 
    2541   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "move_files_to_cd() - unknown media size"); }
    2542   if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number])
    2543     {
    2544       res = write_iso_and_go_on (bkpinfo, FALSE);   /* FALSE because this is not the last CD we'll write */
    2545       retval += res;
    2546       if (res)
    2547     {
    2548       log_msg (1, "WARNING - write_iso_and_go_on returned an error");
    2549     }
    2550     }
    2551 
    2552   va_start(ap, files_to_add); // initialize the variable arguments
    2553   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2554     {
    2555       if (!cf) {continue;}
    2556       strcpy(curr_file, cf);
    2557 
    2558       sprintf (tmp, "mv -f %s %s/archives/", curr_file,
    2559            bkpinfo->scratchdir);
    2560       res = run_program_and_log_output (tmp, 5);
    2561       retval += res;
    2562       if (res)
    2563     {
    2564       log_msg (1, "(move_files_to_cd) '%s' failed", tmp);
    2565     }
    2566       else
    2567         {
    2568       log_msg (8, "Moved %s to CD OK", tmp);
    2569     }
    2570       //      unlink (curr_file);
    2571     }
    2572   va_end(ap);
    2573 
    2574   if (retval)
    2575     {
    2576       log_msg (1, "Warning - errors occurred while I was adding files to CD dir");
    2577     }
    2578   paranoid_free(tmp);
    2579   paranoid_free(curr_file);
    2580   return (retval);
     2571    /*@ buffers ******************************************************** */
     2572    char *tmp, *curr_file, *cf;
     2573
     2574    /*@ long ************************************************************ */
     2575    va_list ap;
     2576    long long would_occupy;
     2577
     2578    assert(bkpinfo != NULL);
     2579    tmp = malloc(1200);
     2580    would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
     2581    va_start(ap, files_to_add); // initialize the variable arguments
     2582    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2583        if (!cf) {
     2584            continue;
     2585        }
     2586        asprintf(&curr_file, "%s", cf);
     2587        if (!does_file_exist(curr_file)) {
     2588            log_msg(1,
     2589                    "Warning - you're trying to add a non-existent file - '%s' to the CD",
     2590                    curr_file);
     2591        } else {
     2592            log_msg(8, "Trying to add file %s to CD", curr_file);
     2593            would_occupy += length_of_file(curr_file) / 1024;
     2594        }
     2595        paranoid_free(curr_file);
     2596    }
     2597    va_end(ap);
     2598
     2599    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     2600        fatal_error("move_files_to_cd() - unknown media size");
     2601    }
     2602    if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
     2603        /* FALSE because this is not the last CD we'll write */
     2604        res = write_iso_and_go_on(bkpinfo, FALSE); 
     2605        retval += res;
     2606        if (res) {
     2607            log_msg(1, "WARNING - write_iso_and_go_on returned an error");
     2608        }
     2609    }
     2610
     2611    va_start(ap, files_to_add); // initialize the variable arguments
     2612    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2613        if (!cf) {
     2614            continue;
     2615        }
     2616        asprintf(&curr_file, "%s", cf);
     2617
     2618        asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
     2619                bkpinfo->scratchdir);
     2620        res = run_program_and_log_output(tmp, 5);
     2621        retval += res;
     2622        if (res) {
     2623            log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
     2624        } else {
     2625            log_msg(8, "Moved %s to CD OK", tmp);
     2626        }
     2627        paranoid_free(tmp);
     2628        paranoid_free(curr_file);
     2629        //      unlink (curr_file);
     2630    }
     2631    va_end(ap);
     2632
     2633    if (retval) {
     2634        log_msg(1,
     2635                "Warning - errors occurred while I was adding files to CD dir");
     2636    }
     2637    return (retval);
    25812638}
    25822639
     
    26022659 * @ingroup MLarchiveGroup
    26032660 */
    2604 int
    2605 offer_to_write_floppies (struct s_bkpinfo *bkpinfo, char *imagesdir)
     2661int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
    26062662{
    2607     /*@ buffer *************************************************************/
    2608   char *tmp;
     2663    /*@ buffer ************************************************************ */
     2664    char *tmp;
    26092665    char *comment;
    26102666    char *bootdisk_dev;
     
    26132669    char *rootdisk_file;
    26142670
    2615     /*@ int ****************************************************************/
    2616   int i = 0;
     2671    /*@ int *************************************************************** */
     2672    int i = 0;
    26172673    int res = 0;
    26182674
    2619     /*@ bool ***************************************************************/
    2620   bool format_first;
    2621   bool root_disk_exists=FALSE;
    2622 
    2623   malloc_string(tmp);
    2624   malloc_string(comment);
    2625   malloc_string(bootdisk_dev);
    2626   malloc_string(datadisk_dev);
    2627   malloc_string(rootdisk_file);
    2628   malloc_string(bootdisk_file);
    2629   assert(bkpinfo!=NULL);
    2630   assert_string_is_neither_NULL_nor_zerolength(imagesdir);
    2631 
    2632 
    2633   if (!ask_me_yes_or_no
    2634       ("Write boot and data disk images to 3.5\" floppy disks?"))
    2635     {
    2636       return (0);
    2637     }
    2638   if (does_device_exist (DEFAULT_1722MB_DISK))
    2639     {
     2675    /*@ bool ************************************************************** */
     2676    bool format_first;
     2677    bool root_disk_exists = FALSE;
     2678
     2679    assert(bkpinfo != NULL);
     2680    assert_string_is_neither_NULL_nor_zerolength(imagesdir);
     2681
     2682
     2683    if (!ask_me_yes_or_no
     2684        ("Write boot and data disk images to 3.5\" floppy disks?")) {
     2685        return (0);
     2686    }
     2687    if (does_device_exist(DEFAULT_1722MB_DISK)) {
    26402688#ifdef __FreeBSD__
    2641  // tell the system that this is a 1.72m floppy
    2642       system ("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
     2689        // tell the system that this is a 1.72m floppy
     2690        system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
    26432691#endif
    2644       strcpy (bootdisk_dev, DEFAULT_1722MB_DISK);
    2645     }
    2646   else if (does_device_exist (BACKUP_1722MB_DISK))
    2647     {
    2648       sprintf (bootdisk_dev, "/dev/fd0H1722");
    2649     }
    2650   else
    2651     {
    2652       log_msg( 1, "Warning - can't find a 1.72MB floppy device *sigh*" );
    2653       strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
    2654 //      return (1);
    2655     }
    2656   strcpy (datadisk_dev, "/dev/fd0");
    2657   if (!does_device_exist (datadisk_dev))
    2658     {
    2659       log_msg( 1, "Warning - can't find a 1.44MB floppy device *sigh*" );
    2660       strcpy(datadisk_dev, "/dev/fd0");
    2661 //      return (1);
    2662     }
    2663   format_first =
    2664     ask_me_yes_or_no
    2665     ("Do you want me to format the disks before I write to them?");
     2692        asprintf(&bootdisk_dev, "%s", DEFAULT_1722MB_DISK);
     2693    } else if (does_device_exist(BACKUP_1722MB_DISK)) {
     2694        asprintf(&bootdisk_dev, "/dev/fd0H1722");
     2695    } else {
     2696        log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
     2697        asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
     2698    }
     2699    asprintf(&datadisk_dev, "%s", "/dev/fd0");
     2700    if (!does_device_exist(datadisk_dev)) {
     2701        log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
     2702        paranoid_free(datadisk_dev);
     2703        asprintf(&datadisk_dev, "%s", "/dev/fd0");
     2704    }
     2705    format_first = ask_me_yes_or_no
     2706        ("Do you want me to format the disks before I write to them?");
    26662707
    26672708/* boot disk */
    2668   if (ask_me_OK_or_cancel ("About to write boot disk"))
    2669     {
    2670       log_to_screen ("Writing boot floppy");
     2709    if (ask_me_OK_or_cancel("About to write boot disk")) {
     2710        log_to_screen("Writing boot floppy");
    26712711#ifdef __FreeBSD__
    2672       sprintf (tmp, "%s/mindi-kern.1722.img", imagesdir);
    2673       if (format_first) { format_disk (bootdisk_dev); }
    2674       res += write_image_to_floppy (bootdisk_dev, tmp);
    2675       if (ask_me_OK_or_cancel ("About to write 1.44MB mfsroot disk"))
    2676         {
    2677           log_to_screen ("Writing mfsroot floppy");
    2678           if (format_first) { format_disk (datadisk_dev); }
    2679           sprintf (tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
    2680           write_image_to_floppy (datadisk_dev, tmp);
    2681         }
     2712        asprintf(&tmp, "%s/mindi-kern.1722.img", imagesdir);
     2713        if (format_first) {
     2714            format_disk(bootdisk_dev);
     2715        }
     2716        res += write_image_to_floppy(bootdisk_dev, tmp);
     2717        paranoid_free(tmp);
     2718        if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
     2719            log_to_screen("Writing mfsroot floppy");
     2720            if (format_first) {
     2721                format_disk(datadisk_dev);
     2722            }
     2723            asprintf(&tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
     2724            write_image_to_floppy(datadisk_dev, tmp);
     2725            paranoid_free(tmp);
     2726        }
    26822727#else
    2683       sprintf (bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
    2684       if (does_file_exist(bootdisk_file))
    2685         {
    2686           if (format_first) { format_disk (bootdisk_dev); }
    2687       res += write_image_to_floppy (bootdisk_dev, bootdisk_file);
    2688         }
    2689       else
    2690         {
    2691       sprintf (bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
    2692       sprintf (rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
    2693       root_disk_exists = TRUE;
    2694       if (!does_file_exist(rootdisk_file) || !does_file_exist(bootdisk_file))
    2695         {
    2696           popup_and_OK("Cannot write boot/root floppies. Files not found.");
    2697           log_to_screen("Failed to find boot/root floppy images. Oh dear.");
    2698           return(1);
    2699         }
    2700       if (format_first) { format_disk (datadisk_dev); }
    2701         /*
    2702           sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
    2703           res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
    2704         */
    2705       res += write_image_to_floppy (datadisk_dev, bootdisk_file);
    2706       if (ask_me_OK_or_cancel ("About to write root disk"))
    2707         {
    2708           log_to_screen ("Writing root floppy");
    2709           if (format_first) { format_disk (datadisk_dev); }
    2710           sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
    2711           log_msg(1, "tmp = '%s'", tmp);
    2712           res += run_external_binary_with_percentage_indicator_NEW("Writing root floppy", tmp);
     2728        asprintf(&bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
     2729        if (does_file_exist(bootdisk_file)) {
     2730            if (format_first) {
     2731                format_disk(bootdisk_dev);
     2732            }
     2733            res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
     2734        } else {
     2735            paranoid_free(bootdisk_file);
     2736            asprintf(&bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
     2737            asprintf(&rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
     2738            root_disk_exists = TRUE;
     2739            if (!does_file_exist(rootdisk_file)
     2740                || !does_file_exist(bootdisk_file)) {
     2741                popup_and_OK
     2742                    ("Cannot write boot/root floppies. Files not found.");
     2743                log_to_screen
     2744                    ("Failed to find boot/root floppy images. Oh dear.");
     2745                paranoid_free(bootdisk_file);
     2746                paranoid_free(rootdisk_file);
     2747                paranoid_free(bootdisk_dev);
     2748                return (1);
     2749            }
     2750            if (format_first) {
     2751                format_disk(datadisk_dev);
     2752            }
     2753            /*
     2754               asprintf(&tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
     2755               res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
     2756             */
     2757            res += write_image_to_floppy(datadisk_dev, bootdisk_file);
     2758            if (ask_me_OK_or_cancel("About to write root disk")) {
     2759                log_to_screen("Writing root floppy");
     2760                if (format_first) {
     2761                    format_disk(datadisk_dev);
     2762                }
     2763                asprintf(&tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
     2764                log_msg(1, "tmp = '%s'", tmp);
     2765                res +=
     2766                    run_external_binary_with_percentage_indicator_NEW
     2767                    ("Writing root floppy", tmp);
    27132768//              res += write_image_to_floppy (datadisk_dev, rootdisk_file);
    2714         }
    2715         }
     2769                paranoid_free(tmp);
     2770            }
     2771            paranoid_free(rootdisk_file);
     2772            paranoid_free(bootdisk_file);
     2773        }
    27162774#endif
    2717     }
    2718   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2719     {
    2720       log_to_screen
    2721     ("FYI, the data disks are stored on tape/CD for your convenience.");
    2722       return (0);
    2723     }
    2724   for (i = 1; i < 99; i++)
    2725     {
    2726       sprintf (tmp, "%s/mindi-data-%d.img", imagesdir, i);
    2727       log_msg (3, tmp);
    2728       if (!does_file_exist (tmp))
    2729     {
    2730       log_msg (3, "...not found");
    2731       break;
    2732     }
    2733       sprintf (comment, "About to write data disk #%d", i);
    2734       if (ask_me_OK_or_cancel (comment))
    2735     {
    2736       sprintf (comment, "Writing data disk #%3d", i);
    2737       log_to_screen (comment);
    2738       if (format_first)
    2739         {
    2740           res += format_disk (datadisk_dev);
    2741         }
    2742       res += write_image_to_floppy (datadisk_dev, tmp);
    2743     }
    2744     }
    2745   paranoid_free(tmp);
    2746   paranoid_free(comment);
    2747   paranoid_free(bootdisk_dev);
    2748   paranoid_free(datadisk_dev);
    2749   return (res);
     2775    }
     2776    paranoid_free(bootdisk_dev);
     2777
     2778    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2779        log_to_screen
     2780            ("FYI, the data disks are stored on tape/CD for your convenience.");
     2781        return (0);
     2782    }
     2783    for (i = 1; i < 99; i++) {
     2784        asprintf(&tmp, "%s/mindi-data-%d.img", imagesdir, i);
     2785        log_msg(3, tmp);
     2786        if (!does_file_exist(tmp)) {
     2787            log_msg(3, "...not found");
     2788            break;
     2789        }
     2790        asprintf(&comment, "About to write data disk #%d", i);
     2791        if (ask_me_OK_or_cancel(comment)) {
     2792            paranoid_free(comment);
     2793            asprintf(&comment, "Writing data disk #%3d", i);
     2794            log_to_screen(comment);
     2795            paranoid_free(comment);
     2796            if (format_first) {
     2797                res += format_disk(datadisk_dev);
     2798            }
     2799            res += write_image_to_floppy(datadisk_dev, tmp);
     2800        }
     2801    }
     2802    paranoid_free(tmp);
     2803    paranoid_free(datadisk_dev);
     2804    return (res);
    27502805}
    2751 
    2752 
    2753 
    2754 
    27552806
    27562807
     
    27672818 */
    27682819
    2769 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo)
     2820int
     2821offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo)
    27702822{
    2771 int res=0;
    2772 
    2773   assert(bkpinfo!=NULL);
    2774 
    2775       mvaddstr_and_log_it (g_currentY, 0,
    2776                "Writing boot+data floppy images to disk");
    2777 
    2778       if (!bkpinfo->nonbootable_backup) {
     2823    int res = 0;
     2824
     2825    assert(bkpinfo != NULL);
     2826
     2827    mvaddstr_and_log_it(g_currentY, 0,
     2828                        "Writing boot+data floppy images to disk");
     2829
     2830    if (!bkpinfo->nonbootable_backup) {
    27792831#ifdef __FreeBSD__
    2780       if (!does_file_exist ("/root/images/mindi/mindi-kern.1722.img"))
     2832        if (!does_file_exist("/root/images/mindi/mindi-kern.1722.img"))
    27812833#else
    2782       if (!does_file_exist ("/root/images/mindi/mindi-bootroot.1722.img") &&
    2783           !does_file_exist ("/root/images/mindi/mindi-boot.1440.img"))
     2834        if (!does_file_exist("/root/images/mindi/mindi-bootroot.1722.img")
     2835            && !does_file_exist("/root/images/mindi/mindi-boot.1440.img"))
    27842836#endif
    2785       {
    2786           mvaddstr_and_log_it (g_currentY++, 74, "No Imgs");
    2787           if (does_file_exist ("/root/images/mindi/mondorescue.iso"))
    2788           {
    2789               popup_and_OK
    2790               ("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.");
    2791               res++;
    2792           }
    2793       }
    2794       else
    2795       {
    2796           offer_to_write_floppies (bkpinfo, "/root/images/mindi");
    2797           mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2798       }
    2799       } else {
    2800       popup_and_OK ("Since you opted for a nonbootable backup, no boot floppies were created.");
    2801       }
    2802      
    2803   return(res);
     2837        {
     2838            mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
     2839            if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
     2840                popup_and_OK
     2841                    ("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.");
     2842                res++;
     2843            }
     2844        } else {
     2845            offer_to_write_floppies(bkpinfo, "/root/images/mindi");
     2846            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2847        }
     2848    } else {
     2849        popup_and_OK
     2850            ("Since you opted for a nonbootable backup, no boot floppies were created.");
     2851    }
     2852
     2853    return (res);
    28042854}
    28052855
     
    28162866 * transfer files over the network) or leave it as is.
    28172867 */
    2818 int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) = _move_files_to_stream;
     2868int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
     2869    _move_files_to_stream;
    28192870
    28202871/**
     
    28322883 */
    28332884int
    2834 _move_files_to_stream (struct s_bkpinfo *bkpinfo,
    2835          char *files_to_add, ...)
     2885_move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    28362886{
    28372887
    2838     /*@ int *************************************************************/
    2839   int retval = 0;
     2888    /*@ int ************************************************************ */
     2889    int retval = 0;
    28402890    int res = 0;
    2841     /*@ buffers *********************************************************/
    2842 
    2843     /*@ char ************************************************************/
     2891    /*@ buffers ******************************************************** */
     2892
     2893    /*@ char *********************************************************** */
    28442894    char start_chr;
    28452895    char stop_chr;
    2846         char *curr_file, *cf;
    2847     /*@ long long *******************************************************/
    2848   long long length_of_incoming_file = 0;
    2849   t_archtype type;
    2850   va_list ap;
    2851 
    2852   assert(bkpinfo!=NULL);
    2853   malloc_string(curr_file);
    2854   va_start(ap, files_to_add);
    2855   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2856     {
    2857       if (!cf) {continue;}
    2858       strcpy(curr_file, cf);
    2859       if (!does_file_exist (curr_file))
    2860         {
    2861           log_msg (1,
    2862            "Warning - you're trying to add a non-existent file - '%s' to the tape",
    2863            curr_file);
    2864         }
    2865 /* create header chars */
    2866       start_chr = BLK_START_AN_AFIO_OR_SLICE;
    2867       stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
    2868 /* ask for new tape if necessary */
    2869       length_of_incoming_file = length_of_file (curr_file);
    2870       write_header_block_to_stream (length_of_incoming_file, curr_file,
    2871                   start_chr);
    2872       if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star."))
    2873     { type = fileset; }
    2874       else if (strstr(curr_file, "slice"))
    2875     { type = biggieslice; }
    2876       else
    2877     { type = other; }
    2878       res = write_file_to_stream_from_file (bkpinfo, curr_file);
    2879       retval += res;
    2880       unlink (curr_file);
    2881 /* write closing header */
    2882       write_header_block_to_stream (0, "finished-writing-file", stop_chr);
    2883     }
    2884   va_end(ap);
    2885 
    2886   if (retval)
    2887     {
    2888       log_msg (1, "Warning - errors occurred while I was adding file to tape");
    2889     }
    2890   paranoid_free(curr_file);
    2891   return (retval);
     2896    char *curr_file, *cf;
     2897    /*@ long long ****************************************************** */
     2898    long long length_of_incoming_file = 0;
     2899    t_archtype type;
     2900    va_list ap;
     2901
     2902    assert(bkpinfo != NULL);
     2903    va_start(ap, files_to_add);
     2904    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2905        if (!cf) {
     2906            continue;
     2907        }
     2908        asprintf(&curr_file, "%s", cf);
     2909        if (!does_file_exist(curr_file)) {
     2910            log_msg(1,
     2911                    "Warning - you're trying to add a non-existent file - '%s' to the tape",
     2912                    curr_file);
     2913        }
     2914        /* create header chars */
     2915        start_chr = BLK_START_AN_AFIO_OR_SLICE;
     2916        stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
     2917        /* ask for new tape if necessary */
     2918        length_of_incoming_file = length_of_file(curr_file);
     2919        write_header_block_to_stream(length_of_incoming_file, curr_file,
     2920                                     start_chr);
     2921        if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
     2922            type = fileset;
     2923        } else if (strstr(curr_file, "slice")) {
     2924            type = biggieslice;
     2925        } else {
     2926            type = other;
     2927        }
     2928        res = write_file_to_stream_from_file(bkpinfo, curr_file);
     2929        retval += res;
     2930        unlink(curr_file);
     2931        paranoid_free(curr_file);
     2932        /* write closing header */
     2933        write_header_block_to_stream(0, "finished-writing-file", stop_chr);
     2934    }
     2935    va_end(ap);
     2936
     2937    if (retval) {
     2938        log_msg(1,
     2939                "Warning - errors occurred while I was adding file to tape");
     2940    }
     2941    return (retval);
    28922942}
    28932943
     
    29072957 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
    29082958 */
    2909 int interrogate_disk_currently_in_cdrw_drive(char*cdrw_dev, bool keep_looping)
     2959int
     2960interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev, bool keep_looping)
    29102961{
    2911   char *tmp;
    2912   int res=0;
    2913   char *bkp;
    2914   char *cdrecord;
    2915 
    2916   malloc_string(tmp);
    2917   malloc_string(bkp);
    2918   malloc_string(cdrecord);
    2919   strcpy(bkp, cdrw_dev);
    2920   if (find_cdrw_device(cdrw_dev))
    2921     {
    2922       strcpy(cdrw_dev, bkp);
    2923     }
    2924   else
    2925     {
    2926       if (!system("which cdrecord > /dev/null 2> /dev/null"))
    2927         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2928       else if (!system("which dvdrecord > /dev/null 2> /dev/null"))
    2929         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2930       else
    2931         { cdrecord[0] = '\0'; log_msg(2, "Oh well. I guess I'll just pray then."); }
    2932       if (cdrecord[0])
    2933         {
    2934          if (!keep_looping)
    2935            {
    2936              retract_CD_tray_and_defeat_autorun();
    2937              res = run_program_and_log_output(cdrecord, 5);
    2938            }
    2939          else
    2940            {
    2941              while((res=run_program_and_log_output(cdrecord, 5)))
    2942                {
    2943                  retract_CD_tray_and_defeat_autorun();
    2944                  if (ask_me_yes_or_no("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
    2945                    { log_msg(1, "Well, he insisted..."); break; }
    2946                }
    2947             }
    2948         }
    2949     }
     2962    int res = 0;
     2963    char *bkp;
     2964    char *cdrecord;
     2965
     2966    asprintf(&bkp, "%s", cdrw_dev);
     2967    if (find_cdrw_device(cdrw_dev)) {
     2968        strcpy(cdrw_dev, bkp);
     2969    } else {
     2970        if (!system("which cdrecord > /dev/null 2> /dev/null")) {
     2971            asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     2972        } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
     2973            asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     2974        } else {
     2975            asprintf(&cdrecord, "%s", "");
     2976            log_msg(2, "Oh well. I guess I'll just pray then.");
     2977        }
     2978        if (cdrecord[0]) {
     2979            if (!keep_looping) {
     2980                retract_CD_tray_and_defeat_autorun();
     2981                res = run_program_and_log_output(cdrecord, 5);
     2982            } else {
     2983                while ((res = run_program_and_log_output(cdrecord, 5))) {
     2984                    retract_CD_tray_and_defeat_autorun();
     2985                    if (ask_me_yes_or_no
     2986                        ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
     2987                    {
     2988                        log_msg(1, "Well, he insisted...");
     2989                        break;
     2990                    }
     2991                }
     2992            }
     2993        }
     2994        paranoid_free(cdrecord);
     2995    }
     2996    paranoid_free(bkp);
    29502997//  retract_CD_tray_and_defeat_autorun();
    2951   paranoid_free(tmp);
    2952   paranoid_free(cdrecord);
    2953   paranoid_free(bkp);
    2954   return(res);
     2998    return (res);
    29552999}
    2956 
    2957 
    2958 
    2959 
    2960 
    2961 
    29623000
    29633001
     
    29693007 */
    29703008void
    2971 pause_and_ask_for_cdr (int ask_for_one_if_more_than_this, bool*pmountable)
     3009pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
    29723010{
    29733011
    2974     /*@ buffers **********************************************/
    2975   char *tmp;
    2976   char *szmsg;
    2977   char *cdrom_dev;
    2978   char *cdrw_dev;
    2979   char *our_serial_str;
    2980   bool ok_go_ahead_burn_it;
    2981   int cd_number = -1;
    2982   int attempt_to_mount_returned_this=999;
    2983   char *mtpt;
    2984   char *szcdno;
    2985   char *szserfname;
    2986   char *szunmount;
    2987 
    2988   malloc_string(tmp);
    2989   malloc_string(szmsg);
    2990   malloc_string(cdrom_dev);
    2991   malloc_string(cdrw_dev);
    2992   malloc_string(mtpt);
    2993   malloc_string(szcdno);
    2994   malloc_string(szserfname);
    2995   malloc_string(our_serial_str);
    2996   malloc_string(szunmount);
    2997 
    2998   sprintf(szmsg, "I am about to burn %s #%d", media_descriptor_string(g_backup_media_type), g_current_media_number);
    2999   log_to_screen(szmsg);
    3000   if (g_current_media_number < ask_for_one_if_more_than_this)
    3001     { return; }
    3002  log_to_screen("Scanning CD-ROM drive...");
    3003   sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int)random(), (long int)random());
    3004   make_hole_for_dir(mtpt);
    3005 
    3006 gotos_make_me_puke:
    3007   ok_go_ahead_burn_it = TRUE;
    3008   if (!find_cdrom_device(cdrom_dev, FALSE))
    3009     {
     3012    /*@ buffers ********************************************* */
     3013    char *tmp;
     3014    char *tmp1;
     3015    char *szmsg;
     3016    char *cdrom_dev;
     3017    char *cdrw_dev;
     3018    char *our_serial_str;
     3019    bool ok_go_ahead_burn_it;
     3020    int cd_number = -1;
     3021    int attempt_to_mount_returned_this = 999;
     3022    char *mtpt;
     3023    char *szcdno;
     3024    char *szserfname;
     3025    char *szunmount;
     3026
     3027    malloc_string(cdrom_dev);
     3028    malloc_string(cdrw_dev);
     3029
     3030    asprintf(&szmsg, "I am about to burn %s #%d",
     3031            media_descriptor_string(g_backup_media_type),
     3032            g_current_media_number);
     3033    log_to_screen(szmsg);
     3034    paranoid_free(szmsg);
     3035    if (g_current_media_number < ask_for_one_if_more_than_this) {
     3036        return;
     3037    }
     3038    log_to_screen("Scanning CD-ROM drive...");
     3039    asprintf(&mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
     3040            (long int) random());
     3041    make_hole_for_dir(mtpt);
     3042
     3043  gotos_make_me_puke:
     3044    ok_go_ahead_burn_it = TRUE;
     3045    if (!find_cdrom_device(cdrom_dev, FALSE)) {
    30103046/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    30113047      log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
    30123048      retract_CD_tray_and_defeat_autorun();
    30133049*/
    3014       sprintf(tmp, "umount %s", cdrom_dev);
    3015       run_program_and_log_output(tmp, 1);
    3016       sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
    3017       sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
    3018       sprintf(szunmount, "umount %s", mtpt);
    3019       cd_number = -1;
    3020       our_serial_str[0] = '\0';
    3021       sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
    3022       if ((attempt_to_mount_returned_this=run_program_and_log_output(tmp, 1)))
    3023         {
    3024       log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
    3025       log_to_screen("If there's a CD/DVD in the drive, it's blank.");
    3026      /*
    3027       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3028         {
    3029               ok_go_ahead_burn_it = FALSE;
    3030               log_to_screen("There isn't a writable CD/DVD in the drive.");
    3031         }
    3032       else
    3033         {
    3034           log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
    3035         }
    3036      */
    3037         }
    3038       else if (!does_file_exist(szcdno) || !does_file_exist(szserfname))
    3039         {
    3040       log_to_screen("%s has data on it but it's probably not a Mondo CD.", media_descriptor_string(g_backup_media_type));
    3041         }
    3042       else
    3043     {
    3044       log_to_screen("%s found in drive. It's a Mondo disk.", media_descriptor_string(g_backup_media_type));
    3045           cd_number = atoi(last_line_of_file(szcdno));
    3046           sprintf(tmp, "cat %s 2> /dev/null", szserfname);
    3047           strcpy(our_serial_str, call_program_and_get_last_line_of_output(tmp));
    3048       // FIXME - should be able to use last_line_of_file(), surely?
    3049         }
    3050       run_program_and_log_output(szunmount, 1);
    3051       log_msg(2, "paafcd: cd_number = %d", cd_number);
    3052       log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string);
    3053       if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string))
    3054         {
    3055       log_msg(2, "This %s is part of this backup set!", media_descriptor_string(g_backup_media_type));
    3056           ok_go_ahead_burn_it = FALSE;
    3057           if (cd_number == g_current_media_number-1)
    3058             { log_to_screen("I think you've left the previous %s in the drive.", media_descriptor_string(g_backup_media_type)); }
    3059           else
    3060             { 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)); }
    3061         }
    3062       else
    3063         {
    3064       log_to_screen("...but not part of _our_ backup set.");
    3065     }
    3066     }
    3067   else
    3068     {
    3069       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));
    3070       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3071         {
    3072           ok_go_ahead_burn_it = FALSE;
    3073           log_to_screen("There isn't a writable %s in the drive.", media_descriptor_string(g_backup_media_type));
    3074         }
    3075     }
     3050        asprintf(&tmp, "umount %s", cdrom_dev);
     3051        run_program_and_log_output(tmp, 1);
     3052        paranoid_free(tmp);
     3053        asprintf(&szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
     3054        asprintf(&szserfname, "%s/archives/SERIAL-STRING", mtpt);
     3055        asprintf(&szunmount, "umount %s", mtpt);
     3056        cd_number = -1;
     3057        asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt);
     3058        if ((attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1))) {
     3059            log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
     3060            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
     3061            asprintf(&our_serial_str, "%s", "");
     3062            /*
     3063               if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
     3064               {
     3065               ok_go_ahead_burn_it = FALSE;
     3066               log_to_screen("There isn't a writable CD/DVD in the drive.");
     3067               }
     3068               else
     3069               {
     3070               log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
     3071               }
     3072             */
     3073        } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) {
     3074            log_to_screen("%s has data on it but it's probably not a Mondo CD.",
     3075                 media_descriptor_string(g_backup_media_type));
     3076            asprintf(&our_serial_str, "%s", "");
     3077        } else {
     3078            log_to_screen("%s found in drive. It's a Mondo disk.",
     3079                          media_descriptor_string(g_backup_media_type));
     3080            cd_number = atoi(last_line_of_file(szcdno));
     3081            asprintf(&tmp1, "cat %s 2> /dev/null", szserfname);
     3082            asprintf(&our_serial_str, "%s",
     3083                   call_program_and_get_last_line_of_output(tmp1));
     3084            paranoid_free(tmp1);
     3085            // FIXME - should be able to use last_line_of_file(), surely?
     3086        }
     3087        paranoid_free(szcdno);
     3088        paranoid_free(szserfname);
     3089        paranoid_free(tmp);
     3090
     3091        run_program_and_log_output(szunmount, 1);
     3092        paranoid_free(szunmount);
     3093
     3094        log_msg(2, "paafcd: cd_number = %d", cd_number);
     3095        log_msg(2, "our serial str = %s; g_serial_string = %s",
     3096                our_serial_str, g_serial_string);
     3097        if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
     3098            log_msg(2, "This %s is part of this backup set!",
     3099                    media_descriptor_string(g_backup_media_type));
     3100            ok_go_ahead_burn_it = FALSE;
     3101            if (cd_number == g_current_media_number - 1) {
     3102                log_to_screen
     3103                    ("I think you've left the previous %s in the drive.",
     3104                     media_descriptor_string(g_backup_media_type));
     3105            } else {
     3106                log_to_screen
     3107                    ("Please remove this %s. It is part of the backup set you're making now.",
     3108                     media_descriptor_string(g_backup_media_type));
     3109            }
     3110        } else {
     3111            log_to_screen("...but not part of _our_ backup set.");
     3112        }
     3113        paranoid_free(our_serial_str);
     3114    } else {
     3115        log_msg(2,
     3116                "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
     3117                media_descriptor_string(g_backup_media_type));
     3118        if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
     3119            ok_go_ahead_burn_it = FALSE;
     3120            log_to_screen("There isn't a writable %s in the drive.",
     3121                          media_descriptor_string(g_backup_media_type));
     3122        }
     3123    }
     3124    paranoid_free(mtpt);
    30763125
    30773126/*
     
    30833132*/
    30843133
    3085   if (!ok_go_ahead_burn_it)
    3086     {
    3087       eject_device(cdrom_dev);
    3088       sprintf (tmp,
    3089            "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    3090             media_descriptor_string(g_backup_media_type),
    3091            g_current_media_number,
    3092            media_descriptor_string(g_backup_media_type));
    3093       popup_and_OK (tmp);
    3094       goto gotos_make_me_puke;
    3095     }
    3096   else
    3097     {
    3098       log_msg(2, "paafcd: OK, going ahead and burning it.");
    3099     }
    3100 
    3101   log_msg (2,"paafcd: OK, I assume I have a blank/reusable %s in the drive...", media_descriptor_string(g_backup_media_type));
    3102 
    3103   //  if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
    3104 
    3105   log_to_screen ("Proceeding w/ %s in drive.", media_descriptor_string(g_backup_media_type));
    3106   paranoid_free(tmp);
    3107   paranoid_free(szmsg);
    3108   paranoid_free(cdrom_dev);
    3109   paranoid_free(cdrw_dev);
    3110   paranoid_free(mtpt);
    3111   paranoid_free(szcdno);
    3112   paranoid_free(szserfname);
    3113   paranoid_free(our_serial_str);
    3114   paranoid_free(szunmount);
    3115   if (pmountable)
    3116     {
    3117       if (attempt_to_mount_returned_this)
    3118         { *pmountable = FALSE; }
    3119       else
    3120         { *pmountable = TRUE; }
    3121     }
     3134    if (!ok_go_ahead_burn_it) {
     3135        eject_device(cdrom_dev);
     3136        asprintf(&tmp,
     3137                "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
     3138                media_descriptor_string(g_backup_media_type),
     3139                g_current_media_number,
     3140                media_descriptor_string(g_backup_media_type));
     3141        popup_and_OK(tmp);
     3142        paranoid_free(tmp);
     3143        goto gotos_make_me_puke;
     3144    } else {
     3145        log_msg(2, "paafcd: OK, going ahead and burning it.");
     3146    }
     3147
     3148    log_msg(2,
     3149            "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
     3150            media_descriptor_string(g_backup_media_type));
     3151
     3152    log_to_screen("Proceeding w/ %s in drive.",
     3153                  media_descriptor_string(g_backup_media_type));
     3154    paranoid_free(cdrom_dev);
     3155    paranoid_free(cdrw_dev);
     3156    if (pmountable) {
     3157        if (attempt_to_mount_returned_this) {
     3158            *pmountable = FALSE;
     3159        } else {
     3160            *pmountable = TRUE;
     3161        }
     3162    }
    31223163
    31233164}
    3124 
    3125 
    3126 
    3127 
    3128 
    31293165
    31303166
     
    31373173 * @see get_bit_N_of_array
    31383174 */
    3139 void set_bit_N_of_array(char*array, int N, bool true_or_false)
     3175void set_bit_N_of_array(char *array, int N, bool true_or_false)
    31403176{
    3141   int bit_number;
    3142   int mask, orig_val, to_add;
    3143   int element_number;
    3144 
    3145   assert(array!=NULL);
    3146 
    3147   element_number = N / 8;
    3148   bit_number = N % 8;
    3149   to_add = (1 << bit_number);
    3150   mask = 255 - to_add;
    3151   orig_val = array[element_number] & mask;
    3152   //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
    3153   if (true_or_false) { array[element_number] = orig_val | to_add; }
     3177    int bit_number;
     3178    int mask, orig_val, to_add;
     3179    int element_number;
     3180
     3181    assert(array != NULL);
     3182
     3183    element_number = N / 8;
     3184    bit_number = N % 8;
     3185    to_add = (1 << bit_number);
     3186    mask = 255 - to_add;
     3187    orig_val = array[element_number] & mask;
     3188    //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
     3189    if (true_or_false) {
     3190        array[element_number] = orig_val | to_add;
     3191    }
    31543192}
    31553193
    31563194/* @} - end of utilityGroup */
    3157 
    3158 
    3159 
    3160 
    3161 
    31623195
    31633196
     
    31833216 */
    31843217int
    3185 slice_up_file_etc (struct s_bkpinfo *bkpinfo, char *biggie_filename, char *partimagehack_fifo,
    3186            long biggie_file_number, long noof_biggie_files, bool use_partimagehack)
     3218slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
     3219                  char *partimagehack_fifo, long biggie_file_number,
     3220                  long noof_biggie_files, bool use_partimagehack)
    31873221{
    31883222
    3189     /*@ buffers ***************************************************/
    3190   char *tmp, *checksum_line, *command;
    3191   char *tempblock;
    3192   char *curr_slice_fname_uncompressed;
    3193   char *curr_slice_fname_compressed;
    3194   char *file_to_archive;
    3195   char *file_to_openin;
    3196     /*@ pointers ***************************************************/
    3197   char *pB;
    3198   FILE *fin, *fout;
    3199 
    3200     /*@ bool *******************************************************/
    3201   bool finished = FALSE;
    3202 
    3203     /*@ long *******************************************************/
    3204   size_t blksize = 0;
    3205   long slice_num = 0;
    3206   long i;
    3207   long optimal_set_size;
    3208   bool should_I_compress_slices;
    3209   char *suffix; // for compressed slices
    3210 
    3211     /*@ long long ***************************************************/
    3212   long long totalread = 0;
    3213   long long totallength = 0;
    3214   long long length;
    3215 
    3216   /*@ int *********************************************************/
    3217   int retval = 0;
    3218   int res = 0;
    3219 
    3220     /*@ structures ***************************************************/
    3221   struct s_filename_and_lstat_info biggiestruct;
     3223    /*@ buffers ************************************************** */
     3224    char *tmp, *checksum_line, *command;
     3225    char *tempblock;
     3226    char *curr_slice_fname_uncompressed;
     3227    char *curr_slice_fname_compressed;
     3228    char *file_to_archive;
     3229    char *file_to_openin;
     3230    /*@ pointers ************************************************** */
     3231    char *pB;
     3232    FILE *fin, *fout;
     3233
     3234    /*@ bool ****************************************************** */
     3235    bool finished = FALSE;
     3236
     3237    /*@ long ****************************************************** */
     3238    size_t blksize = 0;
     3239    long slice_num = 0;
     3240    long i;
     3241    long optimal_set_size;
     3242    bool should_I_compress_slices;
     3243    char *suffix;               // for compressed slices
     3244
     3245    /*@ long long ************************************************** */
     3246    long long totalread = 0;
     3247    long long totallength = 0;
     3248    long long length;
     3249
     3250    /*@ int ******************************************************** */
     3251    int retval = 0;
     3252    int res = 0;
     3253
     3254    /*@ structures ************************************************** */
     3255    struct s_filename_and_lstat_info biggiestruct;
    32223256//  struct stat statbuf;
    32233257
    3224   assert(bkpinfo!=NULL);
    3225   assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    3226   malloc_string(tmp);
    3227   malloc_string(checksum_line);
    3228   malloc_string(curr_slice_fname_uncompressed);
    3229   malloc_string(curr_slice_fname_compressed);
    3230   malloc_string(file_to_archive);
    3231   malloc_string(suffix);
    3232   command = malloc(MAX_STR_LEN*8);
    3233 
    3234   biggiestruct.for_backward_compatibility = '\n';
    3235   biggiestruct.use_partimagehack = use_partimagehack;
    3236   if (!(tempblock = (char*)malloc(256*1024))) { fatal_error("malloc error 256*1024"); }
    3237   optimal_set_size = bkpinfo->optimal_set_size;
    3238   if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0)
    3239     {
    3240       suffix[0] = '\0';
    3241       //      log_it("%s is indeed compressed :-)", filename);
    3242       should_I_compress_slices = FALSE;
    3243     }
    3244   else
    3245     {
    3246       strcpy(suffix, bkpinfo->zip_suffix);
    3247       should_I_compress_slices = TRUE;
    3248     }
    3249 
    3250   if (optimal_set_size < 999)
    3251     {
    3252       fatal_error ("bkpinfo->optimal_set_size is insanely small");
    3253     }
    3254   if (partimagehack_fifo)
    3255     {
    3256       file_to_openin = partimagehack_fifo;
    3257       strcpy (checksum_line, "IGNORE");
    3258       log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    3259     }
    3260   else
    3261     {
    3262       file_to_openin = biggie_filename;
    3263       sprintf (command, "md5sum \"%s\"", biggie_filename);
    3264       if (!(fin = popen (command, "r"))) { log_OS_error("Unable to popen-in command"); return(1); }
    3265       (void) fgets (checksum_line, MAX_STR_LEN, fin);
    3266       pclose (fin);
    3267     }
    3268   lstat (biggie_filename, &biggiestruct.properties);
    3269   strcpy (biggiestruct.filename, biggie_filename);
    3270   pB = strchr(checksum_line, ' ');
    3271   if (!pB) { pB = strchr(checksum_line, '\t'); }
    3272   if (pB) { *pB='\0'; }
    3273   strcpy (biggiestruct.checksum, checksum_line);
    3274 
    3275   strcpy (tmp, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""));
    3276   fout = fopen (tmp, "w");
    3277   (void) fwrite((void*)&biggiestruct, 1, sizeof(biggiestruct), fout);
    3278   paranoid_fclose (fout);
    3279   totallength = length_of_file (biggie_filename);
    3280   length      = totallength / optimal_set_size / 1024;
    3281   log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin);
    3282   if (!(fin = fopen(file_to_openin, "r")))
    3283     {
    3284       log_OS_error("Unable to openin biggie_filename");
    3285       sprintf (tmp, "Cannot archive bigfile '%s': not found", biggie_filename);
    3286       log_to_screen (tmp);
    3287       paranoid_free(tempblock);
    3288       paranoid_free(tmp);
    3289       paranoid_free(checksum_line);
    3290       paranoid_free(command);
    3291       return (1);
    3292     }
    3293   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3294     { res = move_files_to_stream (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3295   else
    3296     { res = move_files_to_cd (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3297   i = bkpinfo->optimal_set_size / 256;
    3298   for (slice_num = 1; !finished; slice_num++)
    3299     {
    3300       strcpy (curr_slice_fname_uncompressed,
    3301           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir,
    3302                ""));
    3303       strcpy (curr_slice_fname_compressed,
    3304           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
    3305 
    3306       strcpy (tmp, percent_media_full_comment (bkpinfo));
    3307       update_progress_form (tmp);
    3308       if (!(fout = fopen (curr_slice_fname_uncompressed, "w"))) { log_OS_error(curr_slice_fname_uncompressed); return(1); }
    3309       if ( (i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength) )
    3310     {
    3311       for (i = 0; i < bkpinfo->optimal_set_size / 256; i++)
    3312         {
    3313           blksize = fread (tempblock, 1, 256 * 1024, fin);
    3314           if (blksize > 0)
     3258    assert(bkpinfo != NULL);
     3259    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
     3260
     3261    malloc_string(checksum_line);
     3262
     3263    biggiestruct.for_backward_compatibility = '\n';
     3264    biggiestruct.use_partimagehack = use_partimagehack;
     3265    optimal_set_size = bkpinfo->optimal_set_size;
     3266    if (is_this_file_compressed(biggie_filename)
     3267        || bkpinfo->compression_level == 0) {
     3268        asprintf(&suffix, "%s", "");
     3269        //      log_it("%s is indeed compressed :-)", filename);
     3270        should_I_compress_slices = FALSE;
     3271    } else {
     3272        asprintf(&suffix, "%s", bkpinfo->zip_suffix);
     3273        should_I_compress_slices = TRUE;
     3274    }
     3275
     3276    if (optimal_set_size < 999) {
     3277        fatal_error("bkpinfo->optimal_set_size is insanely small");
     3278    }
     3279    if (partimagehack_fifo) {
     3280        file_to_openin = partimagehack_fifo;
     3281        strcpy(checksum_line, "IGNORE");
     3282        log_msg(2,
     3283                "Not calculating checksum for %s: it would take too long",
     3284                biggie_filename);
     3285    } else {
     3286        file_to_openin = biggie_filename;
     3287        asprintf(&command, "md5sum \"%s\"", biggie_filename);
     3288        if (!(fin = popen(command, "r"))) {
     3289            log_OS_error("Unable to popen-in command");
     3290            paranoid_free(command);
     3291            return (1);
     3292        }
     3293        paranoid_free(command);
     3294        (void) fgets(checksum_line, MAX_STR_LEN, fin);
     3295        pclose(fin);
     3296    }
     3297    lstat(biggie_filename, &biggiestruct.properties);
     3298    strcpy(biggiestruct.filename, biggie_filename);
     3299    pB = strchr(checksum_line, ' ');
     3300    if (!pB) {
     3301        pB = strchr(checksum_line, '\t');
     3302    }
     3303    if (pB) {
     3304        *pB = '\0';
     3305    }
     3306    strcpy(biggiestruct.checksum, checksum_line);
     3307    paranoid_free(checksum_line);
     3308
     3309    asprintf(&tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3310    fout = fopen(tmp, "w");
     3311    paranoid_free(tmp);
     3312    (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
     3313    paranoid_fclose(fout);
     3314    totallength = length_of_file(biggie_filename);
     3315    length = totallength / optimal_set_size / 1024;
     3316    log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
     3317            file_to_openin);
     3318    if (!(fin = fopen(file_to_openin, "r"))) {
     3319        log_OS_error("Unable to openin biggie_filename");
     3320        asprintf(&tmp, "Cannot archive bigfile '%s': not found",
     3321                biggie_filename);
     3322        log_to_screen(tmp);
     3323        paranoid_free(tmp);
     3324
     3325        paranoid_free(suffix);
     3326        return (1);
     3327    }
     3328    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3329        res = move_files_to_stream(bkpinfo,
     3330                                 slice_fname(biggie_file_number, 0,
     3331                                             bkpinfo->tmpdir, ""), NULL);
     3332    } else {
     3333        res = move_files_to_cd(bkpinfo,
     3334                             slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""),
     3335                             NULL);
     3336    }
     3337    i = bkpinfo->optimal_set_size / 256;
     3338    for (slice_num = 1; !finished; slice_num++) {
     3339        asprintf(&curr_slice_fname_uncompressed, "%s",
     3340               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, ""));
     3341        asprintf(&curr_slice_fname_compressed, "%s",
     3342               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
     3343
     3344        asprintf(&tmp, "%s", percent_media_full_comment(bkpinfo));
     3345        update_progress_form(tmp);
     3346        paranoid_free(tmp);
     3347
     3348        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
     3349            log_OS_error(curr_slice_fname_uncompressed);
     3350
     3351            paranoid_free(curr_slice_fname_uncompressed);
     3352            paranoid_free(curr_slice_fname_compressed);
     3353            paranoid_free(suffix);
     3354            return (1);
     3355        }
     3356        if (!(tempblock = (char *) malloc(256 * 1024))) {
     3357            fatal_error("malloc error 256*1024");
     3358        }
     3359        if ((i == bkpinfo->optimal_set_size / 256)
     3360            && (totalread < 1.1 * totallength)) {
     3361            for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
     3362                blksize = fread(tempblock, 1, 256 * 1024, fin);
     3363                if (blksize > 0) {
     3364                    totalread = totalread + blksize;
     3365                    (void) fwrite(tempblock, 1, blksize, fout);
     3366                } else {
     3367                    break;
     3368                }
     3369            }
     3370        } else {
     3371            i = 0;
     3372        }
     3373        paranoid_free(tempblock);
     3374        paranoid_fclose(fout);
     3375        if (i > 0)              // length_of_file (curr_slice_fname_uncompressed)
    33153376        {
    3316           totalread = totalread + blksize;
    3317           (void) fwrite (tempblock, 1, blksize, fout);
    3318         }
    3319           else
    3320         {
    3321           break;
    3322         }
    3323         }
    3324     }
    3325       else
    3326     {
    3327       i = 0;
    3328     }
    3329       paranoid_fclose (fout);
    3330       if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
    3331     {
    3332       if (!does_file_exist (curr_slice_fname_uncompressed))
    3333         {
    3334           log_msg (2,
    3335                "Warning - '%s' doesn't exist. How can I compress slice?",
    3336                curr_slice_fname_uncompressed);
    3337         }
    3338           if (should_I_compress_slices && bkpinfo->compression_level>0)
    3339             {
    3340           sprintf (command, "%s -%d %s", bkpinfo->zip_exe,
    3341            bkpinfo->compression_level, curr_slice_fname_uncompressed);
    3342               log_msg (2, command);
    3343           if ((res = system (command))) { log_OS_error(command); }
    3344           //          did_I_compress_slice = TRUE;
    3345             }
    3346           else
    3347             {
    3348               sprintf (command, "mv %s %s 2>> %s", curr_slice_fname_uncompressed, curr_slice_fname_compressed, MONDO_LOGFILE);
    3349               res=0; // don't do it :)
    3350           //          did_I_compress_slice = FALSE;
    3351             }
    3352       retval += res;
    3353       if (res)
    3354         {
    3355           log_msg (2, "Failed to compress the slice");
    3356         }
    3357       if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed))
    3358         {
    3359           unlink (curr_slice_fname_uncompressed);
    3360         }
    3361       if (res)
    3362         {
    3363           sprintf (tmp, "Problem with slice # %ld", slice_num);
    3364         }
    3365       else
    3366         {
    3367           sprintf (tmp,
    3368                "%s - Bigfile #%ld, slice #%ld compressed OK          ",
    3369                biggie_filename, biggie_file_number + 1, slice_num);
    3370         }
     3377            if (!does_file_exist(curr_slice_fname_uncompressed)) {
     3378                log_msg(2,
     3379                        "Warning - '%s' doesn't exist. How can I compress slice?",
     3380                        curr_slice_fname_uncompressed);
     3381            }
     3382            if (should_I_compress_slices && bkpinfo->compression_level > 0) {
     3383                asprintf(&command, "%s -%d %s", bkpinfo->zip_exe,
     3384                        bkpinfo->compression_level,
     3385                        curr_slice_fname_uncompressed);
     3386                log_msg(2, command);
     3387                if ((res = system(command))) {
     3388                    log_OS_error(command);
     3389                }
     3390                //              did_I_compress_slice = TRUE;
     3391            } else {
     3392                /* BERLIOS: Useless
     3393                asprintf(&command, "mv %s %s 2>> %s",
     3394                        curr_slice_fname_uncompressed,
     3395                        curr_slice_fname_compressed, MONDO_LOGFILE);
     3396                */
     3397                res = 0;        // don't do it :)
     3398                //              did_I_compress_slice = FALSE;
     3399            }
     3400            retval += res;
     3401            if (res) {
     3402                log_msg(2, "Failed to compress the slice");
     3403            }
     3404            if (bkpinfo->use_lzo
     3405                && strcmp(curr_slice_fname_compressed,
     3406                          curr_slice_fname_uncompressed)) {
     3407                unlink(curr_slice_fname_uncompressed);
     3408            }
     3409            if (res) {
     3410                asprintf(&tmp, "Problem with slice # %ld", slice_num);
     3411            } else {
     3412                asprintf(&tmp,
     3413                        "%s - Bigfile #%ld, slice #%ld compressed OK          ",
     3414                        biggie_filename, biggie_file_number + 1,
     3415                        slice_num);
     3416            }
    33713417#ifndef _XWIN
    3372       if (!g_text_mode)
    3373         {
    3374           newtDrawRootText (0, g_noof_rows - 2, tmp);
    3375           newtRefresh ();
    3376         }
    3377       else
    3378         {
    3379           log_msg (2, tmp);
    3380         }
     3418            if (!g_text_mode) {
     3419                newtDrawRootText(0, g_noof_rows - 2, tmp);
     3420                newtRefresh();
     3421            } else {
     3422                log_msg(2, tmp);
     3423            }
    33813424#else
    3382         log_msg(2, tmp);
     3425            log_msg(2, tmp);
    33833426#endif
    3384         strcpy(file_to_archive, curr_slice_fname_compressed);
    3385       g_current_progress++;
    3386     }
    3387       else /* if i==0 then ... */
    3388     {
    3389       finished = TRUE;
    3390       strcpy (file_to_archive, curr_slice_fname_uncompressed);
    3391           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3392         {
    3393           break;
    3394         }
    3395     }
    3396 
    3397       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3398         {
    3399           register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive);
    3400           maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive);
    3401       res = move_files_to_stream (bkpinfo, file_to_archive, NULL);
    3402     }
    3403       else
    3404         {
    3405       res = move_files_to_cd (bkpinfo, file_to_archive, NULL);
    3406     }
    3407       retval += res;
    3408       if (res)
    3409     {
    3410       sprintf (tmp,
    3411            "Failed to add slice %ld of bigfile %ld to scratchdir",
    3412            slice_num, biggie_file_number+1);
    3413       log_to_screen (tmp);
    3414       fatal_error
    3415         ("Hard disk full. You should have bought a bigger one.");
    3416     }
    3417     }
    3418   paranoid_fclose (fin);
    3419   sprintf (tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
    3420   if (retval)
    3421     {
    3422       strcat (tmp, "...FAILED");
    3423     }
    3424   else
    3425     {
    3426       strcat (tmp, "...OK!");
    3427     }
    3428   log_msg (1, tmp);
    3429   paranoid_free(tempblock);
    3430   paranoid_free(tmp);
    3431   paranoid_free(checksum_line);
    3432   paranoid_free(command);
    3433   paranoid_free(curr_slice_fname_uncompressed);
    3434   paranoid_free(curr_slice_fname_compressed);
    3435   paranoid_free(file_to_archive);
    3436   paranoid_free(suffix);
    3437   return (retval);
     3427            paranoid_free(tmp);
     3428            asprintf(&file_to_archive, "%s", curr_slice_fname_compressed);
     3429            g_current_progress++;
     3430        } else {                /* if i==0 then ... */
     3431
     3432            finished = TRUE;
     3433            asprintf(&file_to_archive, "%s", curr_slice_fname_uncompressed);
     3434            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3435                break;
     3436            }
     3437        }
     3438
     3439        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3440            register_in_tape_catalog(biggieslice, biggie_file_number,
     3441                                     slice_num, file_to_archive);
     3442            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     3443                                                   file_to_archive);
     3444            res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
     3445        } else {
     3446            res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
     3447        }
     3448        paranoid_free(file_to_archive);
     3449        retval += res;
     3450        if (res) {
     3451            asprintf(&tmp,
     3452                    "Failed to add slice %ld of bigfile %ld to scratchdir",
     3453                    slice_num, biggie_file_number + 1);
     3454            log_to_screen(tmp);
     3455            paranoid_free(tmp);
     3456            fatal_error
     3457                ("Hard disk full. You should have bought a bigger one.");
     3458        }
     3459        paranoid_free(curr_slice_fname_uncompressed);
     3460        paranoid_free(curr_slice_fname_compressed);
     3461    }
     3462    paranoid_free(suffix);
     3463    paranoid_fclose(fin);
     3464    if (retval) {
     3465        asprintf(&tmp, "Sliced bigfile #%ld...FAILED", biggie_file_number + 1);
     3466    } else {
     3467        asprintf(&tmp, "Sliced bigfile #%ld...OK!", biggie_file_number + 1);
     3468    }
     3469    log_msg(1, tmp);
     3470    paranoid_free(tmp);
     3471    return (retval);
    34383472}
    3439 
    3440 
    3441 
    3442 
    34433473
    34443474
     
    34553485 * @ingroup utilityGroup
    34563486 */
    3457 void
    3458 wipe_archives (char *d)
     3487void wipe_archives(char *d)
    34593488{
    3460     /*@ buffers **********************************************/
    3461   char *tmp;
    3462   char *dir;
    3463 
    3464   malloc_string(tmp);
    3465   malloc_string(dir);
    3466   assert_string_is_neither_NULL_nor_zerolength(d);
    3467 
    3468   sprintf (dir, "%s/archives", d);
    3469   sprintf (tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
    3470   run_program_and_log_output(tmp, FALSE);
    3471   sprintf (tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
    3472   run_program_and_log_output(tmp, FALSE);
    3473   sprintf (tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
    3474   run_program_and_log_output(tmp, FALSE);
    3475   sprintf (tmp, "rm -f %s/cklist*", dir);
    3476   run_program_and_log_output(tmp, FALSE);
    3477   sprintf (tmp, "rm -f %s/zero", dir);
    3478   run_program_and_log_output(tmp, FALSE);
    3479   log_msg(1, "Wiped %s's archives", dir);
    3480   sprintf (tmp, "ls -l %s", dir);
    3481   run_program_and_log_output (tmp, FALSE);
    3482   paranoid_free(tmp);
    3483   paranoid_free(dir);
     3489    /*@ buffers ********************************************* */
     3490    char *tmp;
     3491    char *dir;
     3492
     3493    assert_string_is_neither_NULL_nor_zerolength(d);
     3494
     3495    asprintf(&dir, "%s/archives", d);
     3496    asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
     3497    run_program_and_log_output(tmp, FALSE);
     3498    paranoid_free(tmp);
     3499
     3500    asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
     3501    run_program_and_log_output(tmp, FALSE);
     3502    paranoid_free(tmp);
     3503
     3504    asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
     3505    run_program_and_log_output(tmp, FALSE);
     3506    paranoid_free(tmp);
     3507
     3508    asprintf(&tmp, "rm -f %s/cklist*", dir);
     3509    run_program_and_log_output(tmp, FALSE);
     3510    paranoid_free(tmp);
     3511
     3512    asprintf(&tmp, "rm -f %s/zero", dir);
     3513    run_program_and_log_output(tmp, FALSE);
     3514    paranoid_free(tmp);
     3515
     3516    log_msg(1, "Wiped %s's archives", dir);
     3517    asprintf(&tmp, "ls -l %s", dir);
     3518    run_program_and_log_output(tmp, FALSE);
     3519    paranoid_free(tmp);
     3520
     3521    paranoid_free(dir);
    34843522}
    3485 
    34863523
    34873524
     
    35003537 * however, this occurs rarely.
    35013538 */
    3502 int
    3503 write_final_iso_if_necessary (struct s_bkpinfo *bkpinfo)
     3539int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
    35043540{
    3505     /*@ int ******************************************************/
    3506   int res;
    3507 
    3508     /*@ buffers ***************************************************/
    3509   char *tmp;
    3510 
    3511   malloc_string(tmp);
    3512   assert(bkpinfo!=NULL);
     3541    /*@ int ***************************************************** */
     3542    int res;
     3543
     3544    /*@ buffers ************************************************** */
     3545    char *tmp;
     3546
     3547    assert(bkpinfo != NULL);
    35133548
    35143549// 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
    35153550
    3516   sprintf(tmp, "Writing the final ISO");
    3517   log_msg(2, tmp);
    3518   center_string (tmp, 80);
     3551    asprintf(&tmp, "Writing the final ISO");
     3552    log_msg(2, tmp);
     3553    /* BERLIOS: that function seems strange to me
     3554    center_string(tmp, 80);
     3555    */
    35193556#ifndef _XWIN
    3520   if (!g_text_mode)
    3521     {
    3522       newtPushHelpLine (tmp);
    3523     }
     3557    if (!g_text_mode) {
     3558        newtPushHelpLine(tmp);
     3559    }
    35243560#endif
    3525   res = write_iso_and_go_on (bkpinfo, TRUE);
     3561    paranoid_free(tmp);
     3562    res = write_iso_and_go_on(bkpinfo, TRUE);
    35263563#ifndef _XWIN
    3527   if (!g_text_mode)
    3528     {
    3529       newtPopHelpLine ();
    3530     }
     3564    if (!g_text_mode) {
     3565        newtPopHelpLine();
     3566    }
    35313567#endif
    3532   log_msg (2, "Returning from writing final ISO (res=%d)", res);
    3533   paranoid_free(tmp);
    3534   return (res);
     3568    log_msg(2, "Returning from writing final ISO (res=%d)", res);
     3569    return (res);
    35353570}
    35363571
     
    35533588 * @see make_iso_fs
    35543589 */
    3555 int
    3556 write_iso_and_go_on (struct s_bkpinfo *bkpinfo, bool last_cd)
     3590int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
    35573591{
    3558     /*@ pointers *****************************************************/
    3559   FILE *fout;
    3560 
    3561     /*@ buffers ******************************************************/
    3562   char *tmp;
    3563   char *cdno_fname;
    3564   char *lastcd_fname;
    3565   char *isofile;
    3566 
    3567     /*@ bool *********************************************************/
    3568   bool that_one_was_ok;
    3569   bool using_nfs;
    3570   bool orig_vfy_flag_val;
    3571 
    3572     /*@ int ************************************************************/
    3573   int res = 0;
    3574 
    3575   malloc_string(tmp);
    3576   malloc_string(cdno_fname);
    3577   malloc_string(lastcd_fname);
    3578   malloc_string(isofile);
    3579  
    3580   assert(bkpinfo!=NULL);
    3581   orig_vfy_flag_val = bkpinfo->verify_data;
    3582   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "write_iso_and_go_on() - unknown media size"); }
    3583 
    3584   if (strlen (bkpinfo->nfs_mount) > 1)
    3585     {
    3586       using_nfs = TRUE;
    3587     }
    3588   else
    3589     {
    3590       using_nfs = FALSE;
    3591     }
    3592   log_msg (1, "OK, time to make %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    3593 
    3594   /* label the ISO with its number */
    3595 
    3596   sprintf (cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
    3597   fout = fopen (cdno_fname, "w");
    3598   fprintf (fout, "%d", g_current_media_number);
    3599   paranoid_fclose (fout);
    3600 
    3601   sprintf (tmp, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir);
    3602   if (run_program_and_log_output(tmp, FALSE))
    3603     { log_msg(2, "Warning - unable to copy autorun to scratchdir"); }
    3604 
    3605   /* last CD or not? Label accordingly */
    3606   sprintf (lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    3607   if (last_cd)
    3608     {
    3609       unlink (lastcd_fname);
    3610       log_msg (2, "OK, you're telling me this is the last CD. Fair enough.");
    3611     }
    3612   else
    3613     {
    3614       fout = fopen (lastcd_fname, "w");
    3615       fprintf (fout,
    3616            "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
    3617       paranoid_fclose (fout);
    3618     }
    3619   if (space_occupied_by_cd (bkpinfo->scratchdir) / 1024 > bkpinfo->media_size[g_current_media_number])
    3620     {
    3621       sprintf (tmp,
    3622            "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
    3623            (long) space_occupied_by_cd (bkpinfo->scratchdir),
    3624            (long) bkpinfo->media_size[g_current_media_number]);
    3625       log_to_screen (tmp);
    3626     }
    3627   sprintf (isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
    3628            bkpinfo->prefix, g_current_media_number);
    3629   for (that_one_was_ok = FALSE; !that_one_was_ok;)
    3630     {
    3631       res = make_iso_fs (bkpinfo, isofile);
    3632       if (g_current_media_number==1 && !res && ( bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw) )
    3633         {
    3634           if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
    3635             { log_msg(3, "*Sigh* Mike, I hate your computer."); bkpinfo->manual_cd_tray = TRUE; } // if it can't be found then force pausing
    3636           else
    3637             { log_msg(3, "Great. Found Mike's CD-ROM drive."); }
    3638         }
    3639       if (bkpinfo->verify_data && !res)
    3640     {
    3641       log_to_screen
    3642         ("Please reboot from the 1st CD in Compare Mode, as a precaution.");
    3643       chdir ("/");
    3644       iamhere("Before calling verify_cd_image()");
    3645       res += verify_cd_image (bkpinfo);
    3646       iamhere("After calling verify_cd_image()");
    3647     }
    3648       if (!res)
    3649     {
    3650       that_one_was_ok = TRUE;
    3651     }
    3652       else
    3653     {
    3654       sprintf (tmp, "Failed to burn %s #%d. Retry?",
    3655             media_descriptor_string(bkpinfo->backup_media_type),
    3656            g_current_media_number);
    3657       res = ask_me_yes_or_no (tmp);
    3658       if (!res)
    3659         {
    3660           if (ask_me_yes_or_no ("Abort the backup?"))
    3661         {
    3662           fatal_error ("FAILED TO BACKUP");
    3663         }
    3664           else
    3665         {
    3666           break;
    3667         }
    3668         }
    3669       else
    3670         {
    3671           log_msg (2, "Retrying, at user's request...");
    3672           res = 0;
    3673         }
    3674     }
    3675     }
     3592    /*@ pointers **************************************************** */
     3593    FILE *fout;
     3594
     3595    /*@ buffers ***************************************************** */
     3596    char *tmp;
     3597    char *cdno_fname;
     3598    char *lastcd_fname;
     3599    char *isofile;
     3600
     3601    /*@ bool ******************************************************** */
     3602    bool that_one_was_ok;
     3603    bool using_nfs;
     3604    bool orig_vfy_flag_val;
     3605
     3606    /*@ int *********************************************************** */
     3607    int res = 0;
     3608
     3609    assert(bkpinfo != NULL);
     3610    orig_vfy_flag_val = bkpinfo->verify_data;
     3611    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     3612        fatal_error("write_iso_and_go_on() - unknown media size");
     3613    }
     3614
     3615    if (strlen(bkpinfo->nfs_mount) > 1) {
     3616        using_nfs = TRUE;
     3617    } else {
     3618        using_nfs = FALSE;
     3619    }
     3620    log_msg(1, "OK, time to make %s #%d",
     3621            media_descriptor_string(bkpinfo->backup_media_type),
     3622            g_current_media_number);
     3623
     3624    /* label the ISO with its number */
     3625
     3626    asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
     3627    fout = fopen(cdno_fname, "w");
     3628    fprintf(fout, "%d", g_current_media_number);
     3629    paranoid_fclose(fout);
     3630    paranoid_free(cdno_fname);
     3631
     3632    asprintf(&tmp, "cp -f %s/autorun %s/", g_mondo_home,
     3633            bkpinfo->scratchdir);
     3634    if (run_program_and_log_output(tmp, FALSE)) {
     3635        log_msg(2, "Warning - unable to copy autorun to scratchdir");
     3636    }
     3637    paranoid_free(tmp);
     3638
     3639    /* last CD or not? Label accordingly */
     3640    asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     3641    if (last_cd) {
     3642        unlink(lastcd_fname);
     3643        log_msg(2,
     3644                "OK, you're telling me this is the last CD. Fair enough.");
     3645    } else {
     3646        fout = fopen(lastcd_fname, "w");
     3647        fprintf(fout,
     3648                "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
     3649        paranoid_fclose(fout);
     3650    }
     3651    paranoid_free(lastcd_fname);
     3652
     3653    if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
     3654        bkpinfo->media_size[g_current_media_number]) {
     3655        asprintf(&tmp,
     3656                "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
     3657                (long) space_occupied_by_cd(bkpinfo->scratchdir),
     3658                (long) bkpinfo->media_size[g_current_media_number]);
     3659        log_to_screen(tmp);
     3660        paranoid_free(tmp);
     3661    }
     3662    asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     3663            bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     3664            g_current_media_number);
     3665    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
     3666        res = make_iso_fs(bkpinfo, isofile);
     3667        if (g_current_media_number == 1 && !res
     3668            && (bkpinfo->backup_media_type == cdr
     3669                || bkpinfo->backup_media_type == cdrw)) {
     3670            if (find_cdrom_device(tmp, FALSE))  // make sure find_cdrom_device() finds, records CD-R's loc
     3671            {
     3672                log_msg(3, "*Sigh* Mike, I hate your computer.");
     3673                bkpinfo->manual_cd_tray = TRUE;
     3674            }                   // if it can't be found then force pausing
     3675            else {
     3676                log_msg(3, "Great. Found Mike's CD-ROM drive.");
     3677            }
     3678        }
     3679        if (bkpinfo->verify_data && !res) {
     3680            log_to_screen
     3681                ("Please reboot from the 1st CD in Compare Mode, as a precaution.");
     3682            chdir("/");
     3683            iamhere("Before calling verify_cd_image()");
     3684            res += verify_cd_image(bkpinfo);
     3685            iamhere("After calling verify_cd_image()");
     3686        }
     3687        if (!res) {
     3688            that_one_was_ok = TRUE;
     3689        } else {
     3690            asprintf(&tmp, "Failed to burn %s #%d. Retry?",
     3691                    media_descriptor_string(bkpinfo->backup_media_type),
     3692                    g_current_media_number);
     3693            res = ask_me_yes_or_no(tmp);
     3694            paranoid_free(tmp);
     3695            if (!res) {
     3696                if (ask_me_yes_or_no("Abort the backup?")) {
     3697                    fatal_error("FAILED TO BACKUP");
     3698                } else {
     3699                    break;
     3700                }
     3701            } else {
     3702                log_msg(2, "Retrying, at user's request...");
     3703                res = 0;
     3704            }
     3705        }
     3706    }
    36763707/*
    36773708  if (using_nfs)
    36783709    {
    3679       sprintf(tmp,"mv -f %s %s/%s/", isofile, bkpinfo->isodir, bkpinfo->nfs_remote_dir);
     3710      asprintf(&tmp,"mv -f %s %s/%s/", isofile, bkpinfo->isodir, bkpinfo->nfs_remote_dir);
    36803711      if (run_program_and_log_output(tmp, FALSE))
    36813712        { log_to_screen("Unable to move ISO to NFS dir"); }
    36823713    }
    36833714*/
    3684   g_current_media_number++;
    3685   if (g_current_media_number > MAX_NOOF_MEDIA) { fatal_error("Too many CD-R(W)'s. Use tape or net."); }
    3686   wipe_archives (bkpinfo->scratchdir);
    3687   sprintf (tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
    3688        bkpinfo->scratchdir, bkpinfo->scratchdir);
    3689   if (system (tmp))
    3690     {
    3691       log_msg
    3692     (2, "Error occurred when I tried to delete the redundant IMGs and GZs");
    3693     }
    3694 
    3695   if (last_cd)
    3696     {
    3697       log_msg (2, "This was your last CD.");
    3698     }
    3699   else
    3700     {
    3701       log_msg (2, "Continuing to backup your data...");
    3702     }
    3703 
    3704   bkpinfo->verify_data = orig_vfy_flag_val;
    3705   paranoid_free(tmp);
    3706   paranoid_free(cdno_fname);
    3707   paranoid_free(lastcd_fname);
    3708   paranoid_free(isofile);
    3709   return (0);
     3715    paranoid_free(isofile);
     3716
     3717    g_current_media_number++;
     3718    if (g_current_media_number > MAX_NOOF_MEDIA) {
     3719        fatal_error("Too many CD-R(W)'s. Use tape or net.");
     3720    }
     3721    wipe_archives(bkpinfo->scratchdir);
     3722    asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
     3723            bkpinfo->scratchdir, bkpinfo->scratchdir);
     3724    if (system(tmp)) {
     3725        log_msg(2,
     3726             "Error occurred when I tried to delete the redundant IMGs and GZs");
     3727    }
     3728    paranoid_free(tmp);
     3729
     3730    if (last_cd) {
     3731        log_msg(2, "This was your last CD.");
     3732    } else {
     3733        log_msg(2, "Continuing to backup your data...");
     3734    }
     3735
     3736    bkpinfo->verify_data = orig_vfy_flag_val;
     3737    return (0);
    37103738}
    37113739
    37123740/* @} - end of LLarchiveGroup */
    3713 
    3714 
    37153741
    37163742
     
    37283754int verify_data(struct s_bkpinfo *bkpinfo)
    37293755{
    3730     int res=0, retval=0, cdno=0;
    3731     char *tmp;
    3732     long diffs=0;
    3733 
    3734   malloc_string(tmp);
    3735   assert(bkpinfo!=NULL); 
    3736       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     3756    int res = 0, retval = 0, cdno = 0;
     3757    char *tmp;
     3758    long diffs = 0;
     3759
     3760    assert(bkpinfo != NULL);
     3761    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3762        chdir("/");
     3763        mvaddstr_and_log_it(g_currentY, 0,
     3764                            "Verifying archives against live filesystem");
     3765        if (bkpinfo->backup_media_type == cdstream) {
     3766            strcpy(bkpinfo->media_device, "/dev/cdrom");
     3767        }
     3768        verify_tape_backups(bkpinfo);
     3769        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     3770    } else if (bkpinfo->backup_data)
     3771        //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    37373772    {
    3738       chdir ("/");
    3739       mvaddstr_and_log_it (g_currentY, 0,
    3740                    "Verifying archives against live filesystem");
    3741       if (bkpinfo->backup_media_type == cdstream)
    3742         {
    3743           strcpy (bkpinfo->media_device, "/dev/cdrom");
    3744         }
    3745       verify_tape_backups (bkpinfo);
    3746       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    3747     }
    3748       else if (bkpinfo->backup_data)
    3749     //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    3750         {
    3751           log_msg (2, "Not verifying again. Per-CD/ISO verification already carried out.");
    3752           paranoid_system("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
    3753         }
    3754       else
    3755     {
    3756           g_current_media_number = cdno;
    3757       if (bkpinfo->backup_media_type != iso)
    3758         {
    3759           find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
    3760         }
    3761       chdir ("/");
    3762       for (cdno = 1;
    3763            cdno < 99 && bkpinfo->verify_data;
    3764            cdno++)
    3765         {
    3766           if (cdno != g_current_media_number)
    3767             {
    3768           log_msg (2, "Warning - had to change g_current_media_number from %d to %d", g_current_media_number, cdno);
    3769           g_current_media_number = cdno;
    3770         }       
    3771           if (bkpinfo->backup_media_type != iso)
    3772         {
    3773           insist_on_this_cd_number (bkpinfo, cdno);
    3774         }
    3775           res = verify_cd_image (bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
    3776           retval += res;
    3777           if (res)
    3778         {
    3779           sprintf (tmp,
    3780                "Warnings/errors were reported while checking %s #%d",
    3781                media_descriptor_string(bkpinfo->backup_media_type),
    3782                g_current_media_number);
    3783           log_to_screen (tmp);
    3784 
    3785         }
    3786         }
     3773        log_msg(2,
     3774                "Not verifying again. Per-CD/ISO verification already carried out.");
     3775        paranoid_system
     3776            ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
     3777    } else {
     3778        g_current_media_number = cdno;
     3779        if (bkpinfo->backup_media_type != iso) {
     3780            find_cdrom_device(bkpinfo->media_device, FALSE);    // replace 0,0,0 with /dev/cdrom
     3781        }
     3782        chdir("/");
     3783        for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
     3784            if (cdno != g_current_media_number) {
     3785                log_msg(2,
     3786                        "Warning - had to change g_current_media_number from %d to %d",
     3787                        g_current_media_number, cdno);
     3788                g_current_media_number = cdno;
     3789            }
     3790            if (bkpinfo->backup_media_type != iso) {
     3791                insist_on_this_cd_number(bkpinfo, cdno);
     3792            }
     3793            res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
     3794            retval += res;
     3795            if (res) {
     3796                asprintf(&tmp,
     3797                        "Warnings/errors were reported while checking %s #%d",
     3798                        media_descriptor_string(bkpinfo->backup_media_type),
     3799                        g_current_media_number);
     3800                log_to_screen(tmp);
     3801                paranoid_free(tmp);
     3802
     3803            }
     3804        }
    37873805/*
    37883806      sprintf (tmp,
     
    37913809      system (tmp);
    37923810*/
    3793           sprintf (tmp,
    3794        "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
    3795        MONDO_LOGFILE);
    3796       system (tmp);
    3797          
    3798       sprintf (tmp,
    3799        "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
    3800        MONDO_LOGFILE);
    3801       system (tmp);
    3802           run_program_and_log_output("umount "MNT_CDROM, FALSE);
    3803 //    if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
     3811        asprintf(&tmp,
     3812                "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
     3813                MONDO_LOGFILE);
     3814        system(tmp);
     3815        paranoid_free(tmp);
     3816
     3817        asprintf(&tmp,
     3818                "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
     3819                MONDO_LOGFILE);
     3820        system(tmp);
     3821        paranoid_free(tmp);
     3822
     3823        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3824//        if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
    38043825//{
    3805           eject_device(bkpinfo->media_device);
     3826        eject_device(bkpinfo->media_device);
    38063827//}
    38073828    }
    3808       diffs = count_lines_in_file ("/tmp/changed.files");
    3809 
    3810       if (diffs > 0)
    3811     {
    3812           if (retval==0) { retval=(int)(-diffs); }
    3813     }
    3814   paranoid_free(tmp);
    3815  return(retval);
     3829    diffs = count_lines_in_file("/tmp/changed.files");
     3830
     3831    if (diffs > 0) {
     3832        if (retval == 0) {
     3833            retval = (int) (-diffs);
     3834        }
     3835    }
     3836    return (retval);
    38163837}
    3817 
    3818 
    3819 
    38203838
    38213839
     
    38313849 * @see write_image_to_floppy
    38323850 */
    3833 int
    3834 write_image_to_floppy_SUB (char *device, char *datafile)
     3851int write_image_to_floppy_SUB(char *device, char *datafile)
    38353852{
    3836     /*@ int ****************************************************************/
    3837   int res = 0;
     3853    /*@ int *************************************************************** */
     3854    int res = 0;
    38383855    int percentage = 0;
    38393856    int blockno = 0;
    3840     int maxblocks =0;
    3841 
    3842     /*@ buffers*************************************************************/
    3843   char *tmp;
     3857    int maxblocks = 0;
     3858
     3859    /*@ buffers************************************************************ */
     3860    char *tmp;
    38443861    char blk[1024];
    38453862    char *title;
    38463863
    3847     /*@ pointers ***********************************************************/
     3864    /*@ pointers ********************************************************** */
    38483865    char *p;
    3849   FILE *fout, *fin;
    3850 
    3851 
    3852   malloc_string(tmp);
    3853   malloc_string(title);
    3854   /* pretty stuff */
    3855   if (!(p = strrchr (datafile, '/')))
    3856     {
    3857       p = datafile;
    3858     }
    3859   else
    3860     {
    3861       p++;
    3862     }
    3863   sprintf (title, "Writing %s to floppy", p);
    3864   open_evalcall_form (title);
    3865   /* functional stuff */
    3866   for (p = device + strlen (device); p != device && isdigit (*(p - 1)); p--);
    3867   maxblocks = atoi (p);
    3868   if (!maxblocks) { maxblocks = 1440; }
    3869   sprintf (tmp, "maxblocks = %d; p=%s", maxblocks, p);
    3870   log_msg (2, tmp);
    3871   /* copy data from image to floppy */
    3872   if (!(fin = fopen (datafile, "r")))
    3873     {
    3874       log_OS_error ("Cannot open img");
    3875       return (1);
    3876     }
    3877   if (!(fout = fopen (device, "w")))
    3878     {
    3879       log_OS_error ("Cannot open fdd");
    3880       return (1);
    3881     }
    3882   for (blockno = 0; blockno < maxblocks; blockno++)
    3883     {
    3884       percentage = blockno * 100 / maxblocks;
    3885       if (fread (blk, 1, 1024, fin) != 1024)
    3886     {
    3887       if (feof(fin))
    3888         {
    3889           log_msg(1, "img read err - img ended prematurely - non-fatal error");
    3890           sleep(3);
    3891           return(res);
    3892         }
    3893       res++;
    3894       log_to_screen ("img read err");
    3895     }
    3896       if (fwrite (blk, 1, 1024, fout) != 1024)
    3897     {
    3898       res++;
    3899       log_to_screen ("fdd write err");
    3900     }
    3901       if (((blockno + 1) % 128) == 0)
    3902     {
    3903       paranoid_system ("sync"); /* fflush doesn't work; dunno why */
    3904       update_evalcall_form (percentage);
    3905     }
    3906     }
    3907   paranoid_fclose (fin);
    3908   paranoid_fclose(fout);
    3909   paranoid_free(tmp);
    3910   paranoid_free(title);
    3911   close_evalcall_form ();
    3912   return (res);
     3866    FILE *fout, *fin;
     3867
     3868
     3869    /* pretty stuff */
     3870    if (!(p = strrchr(datafile, '/'))) {
     3871        p = datafile;
     3872    } else {
     3873        p++;
     3874    }
     3875    asprintf(&title, "Writing %s to floppy", p);
     3876    open_evalcall_form(title);
     3877    paranoid_free(title);
     3878
     3879    /* functional stuff */
     3880    for (p = device + strlen(device); p != device && isdigit(*(p - 1));
     3881         p--);
     3882    maxblocks = atoi(p);
     3883    if (!maxblocks) {
     3884        maxblocks = 1440;
     3885    }
     3886    asprintf(&tmp, "maxblocks = %d; p=%s", maxblocks, p);
     3887    log_msg(2, tmp);
     3888    paranoid_free(tmp);
     3889
     3890    /* copy data from image to floppy */
     3891    if (!(fin = fopen(datafile, "r"))) {
     3892        log_OS_error("Cannot open img");
     3893        return (1);
     3894    }
     3895    if (!(fout = fopen(device, "w"))) {
     3896        log_OS_error("Cannot open fdd");
     3897        return (1);
     3898    }
     3899    for (blockno = 0; blockno < maxblocks; blockno++) {
     3900        percentage = blockno * 100 / maxblocks;
     3901        if (fread(blk, 1, 1024, fin) != 1024) {
     3902            if (feof(fin)) {
     3903                log_msg(1,
     3904                        "img read err - img ended prematurely - non-fatal error");
     3905                sleep(3);
     3906                return (res);
     3907            }
     3908            res++;
     3909            log_to_screen("img read err");
     3910        }
     3911        if (fwrite(blk, 1, 1024, fout) != 1024) {
     3912            res++;
     3913            log_to_screen("fdd write err");
     3914        }
     3915        if (((blockno + 1) % 128) == 0) {
     3916            paranoid_system("sync");    /* fflush doesn't work; dunno why */
     3917            update_evalcall_form(percentage);
     3918        }
     3919    }
     3920    paranoid_fclose(fin);
     3921    paranoid_fclose(fout);
     3922    close_evalcall_form();
     3923    return (res);
    39133924}
    3914 
    3915 
    3916 
    3917 
    3918 
    3919 
    39203925
    39213926
     
    39273932 * @see write_image_to_floppy_SUB
    39283933 */
    3929 int
    3930 write_image_to_floppy (char *device, char *datafile)
     3934int write_image_to_floppy(char *device, char *datafile)
    39313935{
    3932     /*@ int ***************************************************************/
    3933   int res   = 0;
    3934 
    3935   assert_string_is_neither_NULL_nor_zerolength(device);
    3936   assert_string_is_neither_NULL_nor_zerolength(datafile);
    3937 
    3938   while ((res = write_image_to_floppy_SUB (device, datafile)))
    3939     {
    3940       if (!ask_me_yes_or_no ("Failed to write image to floppy. Retry?"))
    3941     {
    3942       return (res);
    3943     }
    3944     }
    3945   return (res);
     3936    /*@ int ************************************************************** */
     3937    int res = 0;
     3938
     3939    assert_string_is_neither_NULL_nor_zerolength(device);
     3940    assert_string_is_neither_NULL_nor_zerolength(datafile);
     3941
     3942    while ((res = write_image_to_floppy_SUB(device, datafile))) {
     3943        if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
     3944            return (res);
     3945        }
     3946    }
     3947    return (res);
    39463948}
    39473949
    39483950/* @} - end of utilityGroup */
    3949 
  • trunk/mondo/mondo/common/my-stuff.h

    r31 r41  
    140140*/
    141141
    142 #define AUX_VER "2.04_berlios"
     142#define AUX_VER "2.05_berlios"
    143143
    144144#define HAVE_MALLOC 1
     
    527527#define DEFAULT_MR_LOGLEVEL 4
    528528
     529/* Required for the use of asprintf */
     530#define _GNU_SOURCE
     531
    529532#endif /* _MY_STUFF_H_ */
Note: See TracChangeset for help on using the changeset viewer.