Changeset 128 in MondoRescue for branches/2.05/mondo/mondo/mondorestore


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

indent on all the C code

Location:
branches/2.05/mondo/mondo/mondorestore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/2.05/mondo/mondo/mondorestore/mondo-prep.c

    r126 r128  
    188188extern bool g_text_mode;
    189189
    190 extern void pause_for_N_seconds(int, char*);
    191 
    192 
    193 FILE *g_fprep=NULL;
    194 
    195 
    196 
    197 int g_partition_table_locked_up=0;
     190extern void pause_for_N_seconds(int, char *);
     191
     192
     193FILE *g_fprep = NULL;
     194
     195
     196
     197int g_partition_table_locked_up = 0;
    198198
    199199
     
    208208void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist)
    209209{
    210     char *command;
    211     char *tmp;
    212     int lino;
    213     int i;
    214     FILE*fout;
    215     char *buf;
    216     const int blocksize=512;       
    217         struct list_of_disks *drivelist=NULL;
     210    char *command;
     211    char *tmp;
     212    int lino;
     213    int i;
     214    FILE *fout;
     215    char *buf;
     216    const int blocksize = 512;
     217    struct list_of_disks *drivelist = NULL;
    218218// If LVMs are present and a zero-and-reboot wasn't recently undertaken
    219219// then zero & insist on reboot.
    220     malloc_string(command);
    221     malloc_string(tmp);
    222     buf = malloc(blocksize);
    223         if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :)
    224       {
    225         drivelist = malloc(sizeof(struct list_of_disks));
    226         make_list_of_drives_in_mountlist(mountlist, drivelist);
    227         for (lino = 0; lino < drivelist->entries; lino++)
    228           {
    229             sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", drivelist->el[lino].device, MONDO_WAS_HERE);
    230             if (!run_program_and_log_output(command, 1))
    231           {
    232             log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", lino, drivelist->el[lino].device);
    233             break;
    234           }
    235               }
    236        
    237         if (lino==drivelist->entries)
    238           {
     220    malloc_string(command);
     221    malloc_string(tmp);
     222    buf = malloc(blocksize);
     223    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
     224    {
     225        drivelist = malloc(sizeof(struct list_of_disks));
     226        make_list_of_drives_in_mountlist(mountlist, drivelist);
     227        for (lino = 0; lino < drivelist->entries; lino++) {
     228            sprintf(command,
     229                    "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
     230                    drivelist->el[lino].device, MONDO_WAS_HERE);
     231            if (!run_program_and_log_output(command, 1)) {
     232                log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)",
     233                        lino, drivelist->el[lino].device);
     234                break;
     235            }
     236        }
     237
     238        if (lino == drivelist->entries) {
    239239// zero & reboot
    240             log_to_screen("I am sorry for the inconvenience but I must ask you to reboot.");
    241         log_to_screen("I need to reset the Master Boot Record; in order to be");
    242         log_to_screen("sure the kernel notices, I must reboot after doing it.");
    243         log_to_screen("Please hit 'Enter' to reboot.");
    244             for (lino = 0; lino < drivelist->entries; lino++)
    245               {
    246             for(i=0;i<blocksize; i++)
    247               { buf[i] = 0; }
    248             sprintf(buf, "%s\n", MONDO_WAS_HERE);
    249             fout = fopen(drivelist->el[lino].device, "w+");
    250             if (!fout)
    251               {
    252                 log_msg(1, "Unable to open+wipe %s", drivelist->el[lino].device);
    253               }
    254             else
    255               {
    256                 if (1!=fwrite(buf, blocksize, 1, fout))
    257               {
    258                 log_msg(1, "Failed to wipe %s", drivelist->el[lino].device);
    259               }
    260             else
    261               {
    262                 log_msg(1, "Successfully wiped %s", drivelist->el[lino].device);
    263               }
    264                 fclose(fout);
    265                   }
    266           }
    267                 system("sync"); system("sync"); system("sync");
    268         popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
    269                 system("reboot");
    270           }
    271           }
    272      
     240            log_to_screen
     241                ("I am sorry for the inconvenience but I must ask you to reboot.");
     242            log_to_screen
     243                ("I need to reset the Master Boot Record; in order to be");
     244            log_to_screen
     245                ("sure the kernel notices, I must reboot after doing it.");
     246            log_to_screen("Please hit 'Enter' to reboot.");
     247            for (lino = 0; lino < drivelist->entries; lino++) {
     248                for (i = 0; i < blocksize; i++) {
     249                    buf[i] = 0;
     250                }
     251                sprintf(buf, "%s\n", MONDO_WAS_HERE);
     252                fout = fopen(drivelist->el[lino].device, "w+");
     253                if (!fout) {
     254                    log_msg(1, "Unable to open+wipe %s",
     255                            drivelist->el[lino].device);
     256                } else {
     257                    if (1 != fwrite(buf, blocksize, 1, fout)) {
     258                        log_msg(1, "Failed to wipe %s",
     259                                drivelist->el[lino].device);
     260                    } else {
     261                        log_msg(1, "Successfully wiped %s",
     262                                drivelist->el[lino].device);
     263                    }
     264                    fclose(fout);
     265                }
     266            }
     267            system("sync");
     268            system("sync");
     269            system("sync");
     270            popup_and_OK
     271                ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
     272            system("reboot");
     273        }
     274    }
    273275// Still here? Cool!
    274   paranoid_free(command);
    275   paranoid_free(tmp);
    276   log_msg(1, "Cool. I didn't have to wipe anything.");
     276    paranoid_free(command);
     277    paranoid_free(tmp);
     278    log_msg(1, "Cool. I didn't have to wipe anything.");
    277279}
    278280
     
    282284
    283285
    284 int fput_string_one_char_at_a_time(FILE*fout, char*str)
     286int fput_string_one_char_at_a_time(FILE * fout, char *str)
    285287{
    286   int i, j;
    287   FILE*fq;
    288 
    289   if (ferror(fout))
    290     {
    291     return(-1);
    292     }
    293   log_msg(5, "Writing string '%s', one char at a time", str);
    294   j = strlen(str);
    295   for(i=0; i<j; i++)
    296     {
    297       log_msg(6, "Writing %d ('%c')", str[i], str[i]);
    298       if ((fq = fopen(FDISK_LOG, "a+"))) { fputc(str[i], fq);fclose(fq); }
    299       fputc(str[i], fout);
    300       fflush(fout);
    301       usleep(1000L*100L);
    302       if (str[i]<32) { usleep(1000L*10L); }
    303     }
    304   log_msg(5, "Returning");
    305    
    306    return(i);
     288    int i, j;
     289    FILE *fq;
     290
     291    if (ferror(fout)) {
     292        return (-1);
     293    }
     294    log_msg(5, "Writing string '%s', one char at a time", str);
     295    j = strlen(str);
     296    for (i = 0; i < j; i++) {
     297        log_msg(6, "Writing %d ('%c')", str[i], str[i]);
     298        if ((fq = fopen(FDISK_LOG, "a+"))) {
     299            fputc(str[i], fq);
     300            fclose(fq);
     301        }
     302        fputc(str[i], fout);
     303        fflush(fout);
     304        usleep(1000L * 100L);
     305        if (str[i] < 32) {
     306            usleep(1000L * 10L);
     307        }
     308    }
     309    log_msg(5, "Returning");
     310
     311    return (i);
    307312}
    308313
     
    325330 * @return The number of errors encountered (0 for success).
    326331 */
    327  
    328 
    329 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, bool vacuum_pack)
     332
     333
     334int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
     335                          bool vacuum_pack)
    330336{
    331337    /**  buffers **********************************************/
     
    340346    char *vgchange_sz;
    341347    char *vgremove_sz;
    342 //  char *do_this_last;
     348//  char *do_this_last;
    343349
    344350    /** char **************************************************/
     
    353359    long extents;
    354360    fpos_t orig_pos;
    355    
     361
    356362    /** pointers **********************************************/
    357363    FILE *fin;
     
    377383    malloc_string(vgchange_sz);
    378384    malloc_string(vgremove_sz);
    379 //  malloc_string(do_this_last); // postpone lvcreate call if necessary
     385//  malloc_string(do_this_last); // postpone lvcreate call if necessary
    380386    command = malloc(512);
    381387
    382 //  do_this_last[0] = '\0';
    383 iamhere("STARTING");
     388//  do_this_last[0] = '\0';
     389    iamhere("STARTING");
    384390    log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
    385     if (find_home_of_exe("lvm")) // found it :) cool
    386       {
    387         strcpy(lvscan_sz,   "lvm lvscan");
    388         strcpy(lvremove_sz, "lvm lvremove");
    389         strcpy(vgscan_sz,   "lvm vgscan");
    390         strcpy(pvscan_sz,   "lvm pvscan");
    391         strcpy(vgcreate_sz, "lvm vgcreate");
    392         strcpy(vgchange_sz, "lvm vgchange");
    393         strcpy(vgremove_sz, "lvm vgremove");
    394       }
    395     else
    396       {
    397         strcpy(lvscan_sz,   "lvscan");
    398         strcpy(lvremove_sz, "lvremove");
    399         strcpy(vgscan_sz,   "vgscan");
    400         strcpy(pvscan_sz,   "pvscan");
    401         strcpy(vgcreate_sz, "vgcreate");
    402         strcpy(vgchange_sz, "vgchange");
    403         strcpy(vgremove_sz, "vgremove");
    404       }
    405     sprintf(command, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " MONDO_LOGFILE "; %s -f $i; done",
    406                     lvscan_sz, lvremove_sz);
     391    if (find_home_of_exe("lvm"))    // found it :) cool
     392    {
     393        strcpy(lvscan_sz, "lvm lvscan");
     394        strcpy(lvremove_sz, "lvm lvremove");
     395        strcpy(vgscan_sz, "lvm vgscan");
     396        strcpy(pvscan_sz, "lvm pvscan");
     397        strcpy(vgcreate_sz, "lvm vgcreate");
     398        strcpy(vgchange_sz, "lvm vgchange");
     399        strcpy(vgremove_sz, "lvm vgremove");
     400    } else {
     401        strcpy(lvscan_sz, "lvscan");
     402        strcpy(lvremove_sz, "lvremove");
     403        strcpy(vgscan_sz, "vgscan");
     404        strcpy(pvscan_sz, "pvscan");
     405        strcpy(vgcreate_sz, "vgcreate");
     406        strcpy(vgchange_sz, "vgchange");
     407        strcpy(vgremove_sz, "vgremove");
     408    }
     409    sprintf(command,
     410            "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> "
     411            MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz);
    407412    run_program_and_log_output(command, 5);
    408413    sleep(1);
    409     sprintf(command, "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz);
     414    sprintf(command,
     415            "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> "
     416            MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz,
     417            vgremove_sz, vgremove_sz);
    410418    run_program_and_log_output(command, 5);
    411419    if (just_erase_existing_volumes) {
    412420        paranoid_fclose(fin);
    413421        log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs.");
    414         retval=0;
     422        retval = 0;
    415423        goto end_of_i_want_my_lvm;
    416424    }
     
    423431            continue;
    424432        }
    425         if (res && strstr(command, "create") && vacuum_pack)
    426           {
    427             sleep(2);
    428             system("sync"); system("sync"); system("sync");
    429           }
    430         if ((p=strstr(incoming, "vgcreate")))
    431           {
     433        if (res && strstr(command, "create") && vacuum_pack) {
     434            sleep(2);
     435            system("sync");
     436            system("sync");
     437            system("sync");
     438        }
     439        if ((p = strstr(incoming, "vgcreate"))) {
    432440// include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    433             for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
    434             if (tmp[0] == '#') {
    435                 fsetpos(fin, &orig_pos);
    436                 break;
    437             } else {
    438                 fgetpos(fin, &orig_pos);
    439                 strcat(incoming, tmp);
    440             }
    441             }
    442             for(q=incoming; *q!='\0'; q++)
    443               {
    444                 if (*q<32) { *q=' '; }
    445               }
    446             strcpy(tmp, p+strlen("vgcreate")+1);
    447             for(q=tmp; *q>32; q++);
    448             *q = '\0';
    449                log_msg(1, "Deleting old entries at /dev/%s", tmp);
    450 //             sprintf(command, "%s -f %s", vgremove_sz, tmp);
    451 //             run_program_and_log_output(command, 1);
    452                sprintf(command, "rm -Rf /dev/%s", tmp);
    453                run_program_and_log_output(command, 1);
    454             run_program_and_log_output(vgscan_sz, 1);
    455             run_program_and_log_output(pvscan_sz, 1);
    456             log_msg(3, "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", incoming);
    457           }
     441            for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
     442                if (tmp[0] == '#') {
     443                    fsetpos(fin, &orig_pos);
     444                    break;
     445                } else {
     446                    fgetpos(fin, &orig_pos);
     447                    strcat(incoming, tmp);
     448                }
     449            }
     450            for (q = incoming; *q != '\0'; q++) {
     451                if (*q < 32) {
     452                    *q = ' ';
     453                }
     454            }
     455            strcpy(tmp, p + strlen("vgcreate") + 1);
     456            for (q = tmp; *q > 32; q++);
     457            *q = '\0';
     458            log_msg(1, "Deleting old entries at /dev/%s", tmp);
     459//             sprintf(command, "%s -f %s", vgremove_sz, tmp);
     460//             run_program_and_log_output(command, 1);
     461            sprintf(command, "rm -Rf /dev/%s", tmp);
     462            run_program_and_log_output(command, 1);
     463            run_program_and_log_output(vgscan_sz, 1);
     464            run_program_and_log_output(pvscan_sz, 1);
     465            log_msg(3,
     466                    "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'",
     467                    incoming);
     468        }
    458469        for (p = incoming + 1; *p == ' '; p++);
    459470        strcpy(command, p);
     
    462473        *p = '\0';
    463474        res = run_program_and_log_output(command, 5);
    464         if (res>0 && (p=strstr(command, "lvm ")))
    465           {
    466             *p = *(p+1) = *(p+2) = ' ';
    467             res = run_program_and_log_output(command, 5);
    468           }
     475        if (res > 0 && (p = strstr(command, "lvm "))) {
     476            *p = *(p + 1) = *(p + 2) = ' ';
     477            res = run_program_and_log_output(command, 5);
     478        }
    469479        log_msg(0, "%s --> %d", command, res);
    470                 if (res>0) {res=1;}
    471         if (res && strstr(command, "lvcreate") && vacuum_pack)
    472           {
    473             res=0;
    474             if (strstr(command, "lvm lvcreate"))
    475             lvmversion = 2;
    476             log_it("%s... so I'll get creative.", tmp);
    477             if (lvmversion == 2)
    478               {
    479                 strcpy(tmp, call_program_and_get_last_line_of_output
    480                     ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1"));
    481               }
    482             else
    483               {
    484                 strcpy(tmp, call_program_and_get_last_line_of_output
    485                     ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1"));
    486               }
    487             for(p=tmp; *p!='\0' && !isdigit(*p); p++);
    488             extents = atol(p);
    489             log_msg(5, "p='%s' --> extents=%ld", p, extents);
    490             p = strstr(command, "-L");
    491             if (!p)
    492               {
    493                 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res);
    494               }
    495             else
    496               {
    497             if (lvmversion == 2)
    498               {
    499                 *p++ = '-'; *p++ = 'l'; *p++ = ' ';
    500                 for(q=p; *q!=' '; q++) { *q = ' '; }
    501                 sprintf(p, "%ld", extents);
    502                 i = strlen(p);
    503                 *(p+i) = ' ';
    504               }
    505             else
    506               {
    507                 p++; p++; p++;
    508                 for(q=p; *q!=' '; q++) { *(q-1) = ' '; }
    509                 sprintf(p, "%ld%c", extents, 'm');
    510                 i = strlen(p);
    511                 *(p+i) = ' ';
    512               }
    513                 log_msg(5, "Retrying with '%s'", command);
    514                 res = run_program_and_log_output(command, 5);
    515             if (res>0) { res=1; }
    516             if (g_fprep) { fprintf(g_fprep, "%s\n", command); }
    517                 log_msg(0, "%s --> %d", command, res);
    518             if (!res)
    519               {
    520                 log_msg(5, "YAY! This time, it succeeded.");
    521               }
    522               }
    523           }
    524         if (strstr(command, "vgcreate"))
    525           {
    526             log_msg(0, "In case you're interested...");
    527             run_program_and_log_output(vgscan_sz, 1);
    528             run_program_and_log_output(pvscan_sz, 1);
    529           }
    530                 if (res!=0 && !strstr(command, "insmod")) {
    531             retval ++;
     480        if (res > 0) {
     481            res = 1;
     482        }
     483        if (res && strstr(command, "lvcreate") && vacuum_pack) {
     484            res = 0;
     485            if (strstr(command, "lvm lvcreate"))
     486                lvmversion = 2;
     487            log_it("%s... so I'll get creative.", tmp);
     488            if (lvmversion == 2) {
     489                strcpy(tmp, call_program_and_get_last_line_of_output
     490                       ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1"));
     491            } else {
     492                strcpy(tmp, call_program_and_get_last_line_of_output
     493                       ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1"));
     494            }
     495            for (p = tmp; *p != '\0' && !isdigit(*p); p++);
     496            extents = atol(p);
     497            log_msg(5, "p='%s' --> extents=%ld", p, extents);
     498            p = strstr(command, "-L");
     499            if (!p) {
     500                log_msg(0, "Fiddlesticks. '%s' returned %d", command, res);
     501            } else {
     502                if (lvmversion == 2) {
     503                    *p++ = '-';
     504                    *p++ = 'l';
     505                    *p++ = ' ';
     506                    for (q = p; *q != ' '; q++) {
     507                        *q = ' ';
     508                    }
     509                    sprintf(p, "%ld", extents);
     510                    i = strlen(p);
     511                    *(p + i) = ' ';
     512                } else {
     513                    p++;
     514                    p++;
     515                    p++;
     516                    for (q = p; *q != ' '; q++) {
     517                        *(q - 1) = ' ';
     518                    }
     519                    sprintf(p, "%ld%c", extents, 'm');
     520                    i = strlen(p);
     521                    *(p + i) = ' ';
     522                }
     523                log_msg(5, "Retrying with '%s'", command);
     524                res = run_program_and_log_output(command, 5);
     525                if (res > 0) {
     526                    res = 1;
     527                }
     528                if (g_fprep) {
     529                    fprintf(g_fprep, "%s\n", command);
     530                }
     531                log_msg(0, "%s --> %d", command, res);
     532                if (!res) {
     533                    log_msg(5, "YAY! This time, it succeeded.");
     534                }
     535            }
     536        }
     537        if (strstr(command, "vgcreate")) {
     538            log_msg(0, "In case you're interested...");
     539            run_program_and_log_output(vgscan_sz, 1);
     540            run_program_and_log_output(pvscan_sz, 1);
     541        }
     542        if (res != 0 && !strstr(command, "insmod")) {
     543            retval++;
    532544        }
    533545        sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);
     
    537549    paranoid_fclose(fin);
    538550    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    539 end_of_i_want_my_lvm:
     551  end_of_i_want_my_lvm:
    540552    paranoid_free(tmp);
    541553    paranoid_free(incoming);
     
    548560    paranoid_free(vgchange_sz);
    549561    paranoid_free(vgremove_sz);
    550 //  paranoid_free(do_this_last);
    551     system("sync"); system("sync"); system("sync");
     562//  paranoid_free(do_this_last);
     563    system("sync");
     564    system("sync");
     565    system("sync");
    552566    sleep(1);
    553 iamhere("ENDING");
    554     if (retval>2)
    555       {
    556         log_msg(1, "%d errors. I'm reporting this.", retval);
    557         return(retval);
    558       }
    559     else
    560       {
    561         log_msg(1, "Not many errors. Returning 0.");
    562         return(0);
    563       }
     567    iamhere("ENDING");
     568    if (retval > 2) {
     569        log_msg(1, "%d errors. I'm reporting this.", retval);
     570        return (retval);
     571    } else {
     572        log_msg(1, "Not many errors. Returning 0.");
     573        return (0);
     574    }
    564575}
    565576
     
    574585 * @return 0 for success, nonzero for failure.
    575586 */
    576     int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
    577                             *new_mountlist, struct mountlist_itself
    578                             *old_mountlist)
     587int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
     588                                                    *new_mountlist, struct mountlist_itself
     589                                                    *old_mountlist)
    579590{
    580591    /** pointers *********************************************************/
     
    603614
    604615#ifdef __FreeBSD__
    605     log_to_screen ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
    606     return(1);
     616    log_to_screen
     617        ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
     618    return (1);
    607619#endif
    608620
     
    611623        {
    612624            if (!does_file_exist("/etc/raidtab")) {
    613                 log_to_screen("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries");
     625                log_to_screen
     626                    ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries");
    614627                finish(1);
    615628            }
     
    619632            }
    620633            for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    621                  && !strstr(incoming, old_mountlist->el[lino].device); fgets(incoming, MAX_STR_LEN - 1, fin));
     634                 && !strstr(incoming, old_mountlist->el[lino].device);
     635                 fgets(incoming, MAX_STR_LEN - 1, fin));
    622636            if (!feof(fin)) {
    623                 sprintf(tmp, "Investigating %s", old_mountlist->el[lino].device);
     637                sprintf(tmp, "Investigating %s",
     638                        old_mountlist->el[lino].device);
    624639                log_it(tmp);
    625640                for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    626                      && !strstr(incoming, "raiddev"); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     641                     && !strstr(incoming, "raiddev");
     642                     fgets(incoming, MAX_STR_LEN - 1, fin)) {
    627643                    if (strstr(incoming, OSSWAP("device", "drive"))
    628                         && !strchr(incoming, '#')) {
    629                         for (p = incoming + strlen(incoming); *(p - 1) <= 32; p--);
     644                        && !strchr(incoming, '#')) {
     645                        for (p = incoming + strlen(incoming);
     646                             *(p - 1) <= 32; p--);
    630647                        *p = '\0';
    631648                        for (p--; p > incoming && *(p - 1) > 32; p--);
    632649                        sprintf(tmp, "Extrapolating %s", p);
    633650                        log_it(tmp);
    634                         for (j = 0; j < new_mountlist->entries && strcmp(new_mountlist->el[j].device, p);
    635                              j++);
     651                        for (j = 0;
     652                             j < new_mountlist->entries
     653                             && strcmp(new_mountlist->el[j].device, p);
     654                             j++);
    636655                        if (j >= new_mountlist->entries) {
    637                             strcpy(new_mountlist->el[new_mountlist->entries].device, p);
    638                             strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, "raid");
    639                             strcpy(new_mountlist->el[new_mountlist->entries].format, "raid");
    640                             new_mountlist->el[new_mountlist->entries].size =
    641                                 old_mountlist->el[lino].size;
     656                            strcpy(new_mountlist->
     657                                   el[new_mountlist->entries].device, p);
     658                            strcpy(new_mountlist->
     659                                   el[new_mountlist->entries].mountpoint,
     660                                   "raid");
     661                            strcpy(new_mountlist->
     662                                   el[new_mountlist->entries].format,
     663                                   "raid");
     664                            new_mountlist->el[new_mountlist->entries].
     665                                size = old_mountlist->el[lino].size;
    642666                            new_mountlist->entries++;
    643667                        } else {
    644                             sprintf(tmp, "Not adding %s to mountlist: it's already there", p);
     668                            sprintf(tmp,
     669                                    "Not adding %s to mountlist: it's already there",
     670                                    p);
    645671                            log_it(tmp);
    646672                        }
     
    650676            paranoid_fclose(fin);
    651677        } else {
    652             strcpy(new_mountlist->el[new_mountlist->entries].device, old_mountlist->el[lino].device);
    653             strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, old_mountlist->el[lino].mountpoint);
    654             strcpy(new_mountlist->el[new_mountlist->entries].format, old_mountlist->el[lino].format);
    655             new_mountlist->el[new_mountlist->entries].size = old_mountlist->el[lino].size;
     678            strcpy(new_mountlist->el[new_mountlist->entries].device,
     679                   old_mountlist->el[lino].device);
     680            strcpy(new_mountlist->el[new_mountlist->entries].mountpoint,
     681                   old_mountlist->el[lino].mountpoint);
     682            strcpy(new_mountlist->el[new_mountlist->entries].format,
     683                   old_mountlist->el[lino].format);
     684            new_mountlist->el[new_mountlist->entries].size =
     685                old_mountlist->el[lino].size;
    656686            new_mountlist->entries++;
    657687        }
     
    697727        sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
    698728        log_it(tmp);
    699         paranoid_free(program); paranoid_free(tmp);
     729        paranoid_free(program);
     730        paranoid_free(tmp);
    700731        return (0);
    701732    }
     
    703734    if (strcmp(format, "swap") == 0) {
    704735        log_it("Not formatting %s - it's swap", device);
    705         paranoid_free(program); paranoid_free(tmp);
     736        paranoid_free(program);
     737        paranoid_free(tmp);
    706738        return (0);
    707739    }
     
    709741    if (strlen(format) <= 2) {
    710742        sprintf(tmp,
    711             "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
    712             device, format);
     743                "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
     744                device, format);
    713745        log_it(tmp);
    714         paranoid_free(program); paranoid_free(tmp);
     746        paranoid_free(program);
     747        paranoid_free(tmp);
    715748        return (0);
    716749    }
     
    718751        sprintf(tmp, "%s is mounted - cannot format it       ", device);
    719752        log_to_screen(tmp);
    720         paranoid_free(program); paranoid_free(tmp);
     753        paranoid_free(program);
     754        paranoid_free(tmp);
    721755        return (1);
    722756    }
     
    726760        if (!vinum_started_yet) {
    727761            if (!does_file_exist("/tmp/raidconf.txt")) {
    728                 log_to_screen("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.");
     762                log_to_screen
     763                    ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.");
    729764            } else {
    730765                int res;
    731                 res = run_program_and_log_output("vinum create /tmp/raidconf.txt", TRUE);
     766                res =
     767                    run_program_and_log_output
     768                    ("vinum create /tmp/raidconf.txt", TRUE);
    732769                if (res) {
    733770                    log_to_screen
    734                         ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.");
     771                        ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.");
    735772                    finish(1);
    736773                }
     
    742779            FILE *fin;
    743780            char line[MAX_STR_LEN];
    744             sprintf(tmp, "Initializing Vinum device %s (this may take a *long* time)", device);
     781            sprintf(tmp,
     782                    "Initializing Vinum device %s (this may take a *long* time)",
     783                    device);
    745784            log_to_screen(tmp);
    746785            /* format raid partition */
    747786            //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
    748787            sprintf(program,
    749                 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
    750                 basename(device));
     788                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
     789                    basename(device));
    751790            system(program);
    752             if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     791            if (g_fprep) {
     792                fprintf(g_fprep, "%s\n", program);
     793            }
    753794            fin = fopen("/tmp/plexes", "r");
    754795            while (fgets(line, MAX_STR_LEN - 1, fin)) {
     
    762803                while (1) {
    763804                    sprintf(tmp,
    764                         "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    765                         line);
     805                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
     806                            line);
    766807                    FILE *pin = popen(tmp, "r");
    767808                    char status[MAX_STR_LEN / 4];
     
    788829        log_to_screen("Stopping %s", device);
    789830        stop_raid_device(device);
    790         system("sync"); sleep(1);
    791         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     831        system("sync");
     832        sleep(1);
     833        if (g_fprep) {
     834            fprintf(g_fprep, "%s\n", program);
     835        }
    792836
    793837        log_msg(1, "Making %s", device);
     
    795839        res = run_program_and_log_output(program, 1);
    796840        log_msg(1, "%s returned %d", program, res);
    797         system("sync"); sleep(3);
     841        system("sync");
     842        sleep(3);
    798843        start_raid_device(device);
    799         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    800         system("sync"); sleep(2);
    801        
    802 //      log_to_screen("Starting %s", device);
    803 //      sprintf(program, "raidstart %s", device);
    804 //      res = run_program_and_log_output(program, 1);
    805 //      log_msg(1, "%s returned %d", program, res);
    806 //      system("sync"); sleep(1);
    807         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    808 
    809 #endif
    810         system("sync"); sleep(1);
     844        if (g_fprep) {
     845            fprintf(g_fprep, "%s\n", program);
     846        }
     847        system("sync");
     848        sleep(2);
     849
     850//      log_to_screen("Starting %s", device);
     851//      sprintf(program, "raidstart %s", device);
     852//      res = run_program_and_log_output(program, 1);
     853//      log_msg(1, "%s returned %d", program, res);
     854//      system("sync"); sleep(1);
     855        if (g_fprep) {
     856            fprintf(g_fprep, "%s\n", program);
     857        }
     858#endif
     859        system("sync");
     860        sleep(1);
    811861        newtResume();
    812862    }
     
    814864//#endif
    815865
    816     if (!strcmp(format, "lvm"))
    817       {
    818         log_msg(1, "Don't format %s - it's part of an lvm volume", device);
    819         paranoid_free(program); paranoid_free(tmp);
    820         return(0);
    821       }
     866    if (!strcmp(format, "lvm")) {
     867        log_msg(1, "Don't format %s - it's part of an lvm volume", device);
     868        paranoid_free(program);
     869        paranoid_free(tmp);
     870        return (0);
     871    }
    822872    res = which_format_command_do_i_need(format, program);
    823873    sprintf(tmp, "%s %s", program, device);
     
    830880    res = run_program_and_log_output(program, FALSE);
    831881    if (res && strstr(program, "kludge")) {
    832         sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device);
     882        sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
     883                format, device);
    833884#ifdef __FreeBSD__
    834885        sprintf(program, "newfs_msdos -F 32 %s", device);
     
    843894#endif
    844895        res = run_program_and_log_output(program, FALSE);
    845         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     896        if (g_fprep) {
     897            fprintf(g_fprep, "%s\n", program);
     898        }
    846899    }
    847900    retval += res;
     
    853906
    854907    log_to_screen(tmp);
    855     paranoid_free(program); paranoid_free(tmp);
    856     system("sync"); sleep(1);
     908    paranoid_free(program);
     909    paranoid_free(tmp);
     910    system("sync");
     911    sleep(1);
    857912    return (retval);
    858913}
     
    868923 * @return The number of errors encountered (0 for success).
    869924 */
    870 int format_everything(struct mountlist_itself *mountlist, bool interactively)
     925int format_everything(struct mountlist_itself *mountlist,
     926                      bool interactively)
    871927{
    872928    /** int **************************************************************/
     
    874930    int lino;
    875931    int res;
    876 //  int i;
    877 //  struct list_of_disks *drivelist;
     932//  int i;
     933//  struct list_of_disks *drivelist;
    878934
    879935    /** long *************************************************************/
     
    890946    /** end **************************************************************/
    891947
    892     assert(mountlist!=NULL);
     948    assert(mountlist != NULL);
    893949    malloc_string(tmp);
    894     sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
     950    sprintf(tmp, "format_everything (mountlist, interactively = %s",
     951            (interactively) ? "true" : "false");
    895952    log_it(tmp);
    896953    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
    897     open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.",
    898                "This may take up to five minutes.", "", mountlist->entries + 1);
    899 
    900     progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1;
     954    open_progress_form("Formatting partitions",
     955                       "I am now formatting your hard disk partitions.",
     956                       "This may take up to five minutes.", "",
     957                       mountlist->entries + 1);
     958
     959    progress_step =
     960        (mountlist->entries >
     961         0) ? g_maximum_progress / mountlist->entries : 1;
    901962// start soft-raids now (because LVM might depend on them)
    902963// ...and for simplicity's sake, let's format them at the same time :)
    903964    log_msg(1, "Stopping all RAID devices");
    904965    stop_all_raid_devices(mountlist);
    905     system("sync"); system("sync"); system("sync");
     966    system("sync");
     967    system("sync");
     968    system("sync");
    906969    sleep(2);
    907     log_msg(1, "Prepare soft-RAIDs"); // prep and format too
     970    log_msg(1, "Prepare soft-RAIDs");   // prep and format too
    908971    for (lino = 0; lino < mountlist->entries; lino++) {
    909972        me = &mountlist->el[lino];  // the current mountlist entry
     
    912975            if (interactively) {
    913976                // ask user if we should format the current device
    914                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     977                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     978                        me->mountpoint);
    915979                do_it = ask_me_yes_or_no(tmp);
    916980            } else {
     
    918982            }
    919983            if (do_it) {
    920             // NB: format_device() also stops/starts RAID device if necessary
     984                // NB: format_device() also stops/starts RAID device if necessary
    921985                retval += format_device(me->device, me->format);
    922986            }
     
    924988        }
    925989    }
    926     system("sync"); system("sync"); system("sync");
     990    system("sync");
     991    system("sync");
     992    system("sync");
    927993    sleep(2);
    928994// This last step is probably necessary
    929 //  log_to_screen("Re-starting software RAIDs...");
    930 //  start_all_raid_devices(mountlist);
    931 //  system("sync"); system("sync"); system("sync");
    932 //  sleep(5);
     995//  log_to_screen("Re-starting software RAIDs...");
     996//  start_all_raid_devices(mountlist);
     997//  system("sync"); system("sync"); system("sync");
     998//  sleep(5);
    933999// do LVMs now
    9341000    log_msg(1, "Creating LVMs");
     
    9361002        wait_until_software_raids_are_prepped("/proc/mdstat", 10);
    9371003        log_to_screen("Configuring LVM");
    938                 if (!g_text_mode) { newtSuspend(); }
     1004        if (!g_text_mode) {
     1005            newtSuspend();
     1006        }
    9391007/*
    9401008        for(i=0; i<3; i++)
     
    9491017            log_msg(1, "Vacuum-packing...");
    9501018*/
    951             res = do_my_funky_lvm_stuff(FALSE, TRUE);
     1019        res = do_my_funky_lvm_stuff(FALSE, TRUE);
    9521020/*
    9531021        }
    9541022*/
    955                 if (!g_text_mode) { newtResume(); }
    956         if (!res) { log_to_screen("LVM initialized OK"); }
    957         else { log_to_screen("Failed to initialize LVM"); }
     1023        if (!g_text_mode) {
     1024            newtResume();
     1025        }
     1026        if (!res) {
     1027            log_to_screen("LVM initialized OK");
     1028        } else {
     1029            log_to_screen("Failed to initialize LVM");
     1030        }
    9581031        // retval += res;
    9591032        if (res) {
    960             retval ++;
    961         }
    962         sleep(3);
    963     }
    964 
     1033            retval++;
     1034        }
     1035        sleep(3);
     1036    }
    9651037// do regulars at last
    966     sleep(2); // woo!
    967         log_msg(1, "Formatting regulars");
     1038    sleep(2);                   // woo!
     1039    log_msg(1, "Formatting regulars");
    9681040    for (lino = 0; lino < mountlist->entries; lino++) {
    9691041        me = &mountlist->el[lino];  // the current mountlist entry
     
    9721044            log_it(tmp);
    9731045        } else if (!strcmp(me->format, "raid")) {
    974             sprintf(tmp, "Not formatting %s - it's a raid-let", me->device);
     1046            sprintf(tmp, "Not formatting %s - it's a raid-let",
     1047                    me->device);
    9751048            log_it(tmp);
    9761049            continue;
     
    9801053            continue;
    9811054        } else if (!strncmp(me->device, "/dev/md", 7)) {
    982             sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device);
     1055            sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",
     1056                    me->device);
    9831057            log_it(tmp);
    9841058            continue;
    9851059        } else if (!does_file_exist(me->device)
    986                     && strncmp(me->device, "/dev/hd", 7)
    987                     && strncmp(me->device, "/dev/sd", 7)) {
    988             sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device);
     1060                   && strncmp(me->device, "/dev/hd", 7)
     1061                   && strncmp(me->device, "/dev/sd", 7)) {
     1062            sprintf(tmp,
     1063                    "Not formatting %s yet - doesn't exist - probably an LVM",
     1064                    me->device);
    9891065            log_it(tmp);
    9901066            continue;
     
    9921068            if (interactively) {
    9931069                // ask user if we should format the current device
    994                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     1070                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     1071                        me->mountpoint);
    9951072                do_it = ask_me_yes_or_no(tmp);
    9961073            } else {
     
    10161093    if (retval) {
    10171094        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1018         log_to_screen("Errors occurred during the formatting of your hard drives.");
     1095        log_to_screen
     1096            ("Errors occurred during the formatting of your hard drives.");
    10191097    } else {
    10201098        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    10211099    }
    10221100
    1023     sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully");
     1101    sprintf(tmp, "format_everything () - %s",
     1102            (retval) ? "failed!" : "finished successfully");
    10241103    log_it(tmp);
    10251104
    1026     if (g_partition_table_locked_up > 0)
    1027       {
    1028         if (retval > 0 && !interactively)
    1029               {
     1105    if (g_partition_table_locked_up > 0) {
     1106        if (retval > 0 && !interactively) {
    10301107//123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    1031                 log_to_screen(
    1032   "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up);
    1033                 log_to_screen(
    1034   "failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
    1035                 log_to_screen(
    1036   "to refresh its copy of the partition table causes the kernel to lock the ");
    1037                 log_to_screen(
    1038   "partition table. I believe this has just happened.");
    1039                 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
    1040                   {
    1041             system("sync");
    1042             system("sync");
    1043             system("sync");
    1044             system("reboot");
    1045           }
    1046           }
    1047         else
    1048           {
    1049             log_to_screen(
    1050 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s');
    1051           }
    1052       }
    1053         newtSuspend();
     1108            log_to_screen
     1109                ("Partition table locked up %d times. At least one 'mkfs' (format) command",
     1110                 g_partition_table_locked_up);
     1111            log_to_screen
     1112                ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
     1113            log_to_screen
     1114                ("to refresh its copy of the partition table causes the kernel to lock the ");
     1115            log_to_screen
     1116                ("partition table. I believe this has just happened.");
     1117            if (ask_me_yes_or_no
     1118                ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
     1119            {
     1120                system("sync");
     1121                system("sync");
     1122                system("sync");
     1123                system("reboot");
     1124            }
     1125        } else {
     1126            log_to_screen
     1127                ("Partition table locked up %d time%c. However, disk formatting succeeded.",
     1128                 g_partition_table_locked_up,
     1129                 (g_partition_table_locked_up == 1) ? '.' : 's');
     1130        }
     1131    }
     1132    newtSuspend();
    10541133    system("clear");
    10551134    newtResume();
     
    10671146 * @return The number of errors encountered (0 for success).
    10681147 */
    1069 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for)
     1148int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename,
     1149                          int devno_we_must_allow_for)
    10701150{
    10711151    /** int **************************************************************/
     
    10871167        log_it(tmp);
    10881168        g_maximum_progress++;
    1089         res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000);
     1169        res =
     1170            partition_device(pout_to_fdisk, drivename, 1, 0, "ext2",
     1171                             32000);
    10901172        retval += res;
    10911173        previous_devno = 1;
     
    10961178    }
    10971179    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1098         sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno);
     1180        sprintf(tmp, "Creating dummy partition %s%d", drivename,
     1181                current_devno);
    10991182        log_it(tmp);
    11001183        g_maximum_progress++;
    1101         res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000);
     1184        res =
     1185            partition_device(pout_to_fdisk, drivename, current_devno,
     1186                             previous_devno, OSSWAP("ext2", "ufs"), 32000);
    11021187        retval += res;
    11031188        previous_devno = current_devno;
     
    11471232    else
    11481233        fprintf(f, "type: %u\n", lp->d_type);
    1149     fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
    1150     fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
     1234    fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
     1235            lp->d_typename);
     1236    fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
     1237            lp->d_packname);
    11511238    fprintf(f, "flags:");
    11521239    if (lp->d_flags & D_REMOVABLE)
     
    11671254    fprintf(f, "trackskew: %u\n", lp->d_trackskew);
    11681255    fprintf(f, "cylinderskew: %u\n", lp->d_cylskew);
    1169     fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch);
    1170     fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek);
     1256    fprintf(f, "headswitch: %lu\t\t# milliseconds\n",
     1257            (u_long) lp->d_headswitch);
     1258    fprintf(f, "track-to-track seek: %ld\t# milliseconds\n",
     1259            (u_long) lp->d_trkseek);
    11711260    fprintf(f, "drivedata: ");
    11721261    for (i = NDDATA - 1; i >= 0; i--)
     
    11781267        fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]);
    11791268    fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
    1180     fprintf(f, "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
     1269    fprintf(f,
     1270            "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
    11811271    pp = lp->d_partitions;
    11821272    for (i = 0; i < lp->d_npartitions; i++, pp++) {
    11831273        if (pp->p_size) {
    1184             fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset);
     1274            fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
     1275                    (u_long) pp->p_offset);
    11851276            if (pp->p_fstype < FSMAXTYPES)
    11861277                fprintf(f, "%8.8s", fstypenames[pp->p_fstype]);
     
    11901281
    11911282            case FS_UNUSED: /* XXX */
    1192                 fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), "");
     1283                fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
     1284                        (u_long) (pp->p_fsize * pp->p_frag), "");
    11931285                break;
    11941286
    11951287            case FS_BSDFFS:
    1196                 fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1197                     pp->p_cpg);
     1288                fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize,
     1289                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    11981290                break;
    11991291
    12001292            case FS_BSDLFS:
    1201                 fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1202                     pp->p_cpg);
     1293                fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize,
     1294                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    12031295                break;
    12041296
     
    12071299                break;
    12081300            }
    1209             fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl));
     1301            fprintf(f, "\t# (Cyl. %4lu",
     1302                    (u_long) (pp->p_offset / lp->d_secpercyl));
    12101303            if (pp->p_offset % lp->d_secpercyl)
    12111304                putc('*', f);
    12121305            else
    12131306                putc(' ', f);
    1214             fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1));
     1307            fprintf(f, "- %lu",
     1308                    (u_long) ((pp->p_offset + pp->p_size +
     1309                               lp->d_secpercyl - 1) / lp->d_secpercyl -
     1310                              1));
    12151311            if (pp->p_size % lp->d_secpercyl)
    12161312                putc('*', f);
     
    12381334    /* New world order */
    12391335    if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0)
    1240         || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
     1336        || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
    12411337        close(f);
    12421338        return (NULL);
     
    12821378    return (&loclab);
    12831379}
     1380
    12841381/* End stolen from /usr/src/sbin/disklabel/disklabel.c. */
    12851382
     
    13011398 * @return The number of errors encountered (0 for success).
    13021399 */
    1303 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret)
     1400int label_drive_or_slice(struct mountlist_itself *mountlist,
     1401                         char *drivename, struct disklabel *ret)
    13041402{
    13051403    char subdev_str[MAX_STR_LEN];
     
    13251423            lp->d_partitions[c - 'a'].p_cpg = 0;
    13261424            if (!strcmp(mountlist->el[idx].format, "ufs")
    1327                 || !strcmp(mountlist->el[idx].format, "ffs")
    1328                 || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
     1425                || !strcmp(mountlist->el[idx].format, "ffs")
     1426                || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
    13291427                lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS;
    13301428                lp->d_partitions[c - 'a'].p_fsize = 2048;
     
    13321430                lp->d_partitions[c - 'a'].p_cpg = 64;
    13331431            } else if (!strcasecmp(mountlist->el[idx].format, "raid")
    1334                    || !strcasecmp(mountlist->el[idx].format, "vinum")) {
     1432                       || !strcasecmp(mountlist->el[idx].format, "vinum")) {
    13351433                lp->d_partitions[c - 'a'].p_fstype = FS_VINUM;
    13361434            } else if (!strcmp(mountlist->el[idx].format, "swap")) {
     
    13531451        for (lastone = i - 1; lastone >= 0; lastone--) {
    13541452            if ((lp->d_partitions[lastone].p_size)
    1355                 && (lastone != RAW_PART))
     1453                && (lastone != RAW_PART))
    13561454                break;
    13571455        }
    1358         lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size;
    1359     }
    1360     if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) {
    1361         lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset;
     1456        lp->d_partitions[i].p_offset =
     1457            lp->d_partitions[lastone].p_offset +
     1458            lp->d_partitions[lastone].p_size;
     1459    }
     1460    if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size >
     1461        lp->d_secperunit) {
     1462        lp->d_partitions[lo].p_size =
     1463            lp->d_secperunit - lp->d_partitions[lo].p_offset;
    13621464    }
    13631465
     
    13671469    sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));
    13681470    retval += run_program_and_log_output(command, TRUE);
    1369     sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename));
     1471    sprintf(command, "disklabel -R %s /tmp/disklabel",
     1472            canonical_name(drivename));
    13701473    retval += run_program_and_log_output(command, TRUE);
    13711474    if (ret)
     
    13901493    int retval = 0;
    13911494    int i;
    1392     FILE*pout_to_fdisk=NULL;
    1393    
     1495    FILE *pout_to_fdisk = NULL;
     1496
    13941497#ifdef __FreeBSD__
    13951498    bool fbsd_part = FALSE;
     
    14131516    malloc_string(format);
    14141517    malloc_string(tmp);
    1415    
     1518
    14161519    sprintf(tmp, "Partitioning drive %s", drivename);
    14171520    log_it(tmp);
    14181521
    1419 #if __FreeBSD__ 
    1420         log_it("(Not opening fdisk now; that's the Linux guy's job)");
     1522#if __FreeBSD__
     1523    log_it("(Not opening fdisk now; that's the Linux guy's job)");
    14211524    pout_to_fdisk = NULL;
    14221525#else
    14231526    make_hole_for_file(FDISK_LOG);
    14241527#ifdef __IA64__
    1425     sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1528    sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1529            FDISK_LOG);
    14261530#else
    14271531    sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
    14281532#endif
    14291533    pout_to_fdisk = popen(tmp, "w");
    1430     if (!pout_to_fdisk) { 
    1431         log_to_screen("Cannot call fdisk to configure %s", drivename); 
     1534    if (!pout_to_fdisk) {
     1535        log_to_screen("Cannot call fdisk to configure %s", drivename);
    14321536        paranoid_free(device_str);
    14331537        paranoid_free(format);
    14341538        paranoid_free(tmp);
    1435         return(1);
     1539        return (1);
    14361540    }
    14371541#endif
     
    14511555                for (c = 'a'; c <= 'z'; c++) {
    14521556                    sprintf(subdev_str, "%s%c", drivename, c);
    1453                     if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
     1557                    if (find_device_in_mountlist(mountlist, subdev_str) >
     1558                        0) {
    14541559                        fbsd_part = TRUE;
    14551560                    }
     
    14571562                if (fbsd_part) {
    14581563                    int r = label_drive_or_slice(mountlist,
    1459                                     drivename,
    1460                                     0);
     1564                                                drivename,
     1565                                                0);
    14611566                    char command[MAX_STR_LEN];
    1462                     sprintf(command, "disklabel -B %s", basename(drivename));
     1567                    sprintf(command, "disklabel -B %s",
     1568                            basename(drivename));
    14631569                    if (system(command)) {
    1464                         log_to_screen("Warning! Unable to make the drive bootable.");
     1570                        log_to_screen
     1571                            ("Warning! Unable to make the drive bootable.");
    14651572                    }
    14661573                    paranoid_free(device_str);
     
    15071614#if __FreeBSD__
    15081615            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1509 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1510 //          if (run_program_and_log_output(tmp, TRUE)) {
     1616//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1617//          if (run_program_and_log_output(tmp, TRUE)) {
    15111618            file = open(drivename, O_WRONLY);
    15121619            if (!file) {
    1513                 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename);
     1620                sprintf(tmp,
     1621                        "Warning - unable to open %s for wiping it's partition table",
     1622                        drivename);
    15141623                log_to_screen(tmp);
    15151624            }
    15161625
    1517             for (i=0; i<512; i++) {
    1518                 if ( !write(file, "\0", 1) ) {
    1519                     sprintf(tmp, "Warning - unable to write to %s", drivename);
     1626            for (i = 0; i < 512; i++) {
     1627                if (!write(file, "\0", 1)) {
     1628                    sprintf(tmp, "Warning - unable to write to %s",
     1629                            drivename);
    15201630                    log_to_screen(tmp);
    15211631                }
     
    15241634#else
    15251635            iamhere("New, kernel-friendly partition remover");
    1526             for(i=20;i>0;i--)
    1527               {
    1528                 fprintf(pout_to_fdisk, "d\n%d\n", i);
    1529                 fflush(pout_to_fdisk);
    1530               }
    1531 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1532 //          run_program_and_log_output(tmp, 1);
    1533 #endif 
     1636            for (i = 20; i > 0; i--) {
     1637                fprintf(pout_to_fdisk, "d\n%d\n", i);
     1638                fflush(pout_to_fdisk);
     1639            }
     1640//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1641//          run_program_and_log_output(tmp, 1);
     1642#endif
    15341643            if (current_devno > 1) {
    1535                 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno);
     1644                previous_devno =
     1645                    make_dummy_partitions(pout_to_fdisk, drivename,
     1646                                          current_devno);
    15361647            }
    15371648        }
     
    15401651#endif
    15411652
    1542         strcpy(format, mountlist->el[lino].format);
    1543         partsize = mountlist->el[lino].size;
     1653            strcpy(format, mountlist->el[lino].format);
     1654            partsize = mountlist->el[lino].size;
    15441655
    15451656#ifdef __FreeBSD__
     
    15491660#ifndef __IA64__
    15501661        if (current_devno == 5 && previous_devno == 4) {
    1551             log_to_screen("You must leave at least one partition spare as the Extended partition.");
     1662            log_to_screen
     1663                ("You must leave at least one partition spare as the Extended partition.");
    15521664            paranoid_free(device_str);
    15531665            paranoid_free(format);
     
    15571669#endif
    15581670
    1559         retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize);
     1671        retval +=
     1672            partition_device(pout_to_fdisk, drivename, current_devno,
     1673                             previous_devno, format, partsize);
    15601674
    15611675#ifdef __FreeBSD__
     
    15641678            retval += label_drive_or_slice(mountlist, device_str, 0);
    15651679            if (system(tmp)) {
    1566                 log_to_screen("Warning! Unable to make the slice bootable.");
     1680                log_to_screen
     1681                    ("Warning! Unable to make the slice bootable.");
    15671682            }
    15681683        }
     
    15721687    }
    15731688
    1574     if (pout_to_fdisk)
    1575     {
     1689    if (pout_to_fdisk) {
    15761690// mark relevant partition as bootable
    1577         sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy"));
     1691        sprintf(tmp, "a\n%s\n",
     1692                call_program_and_get_last_line_of_output
     1693                ("make-me-bootable /tmp/mountlist.txt dummy"));
    15781694        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    15791695// close fdisk
    15801696        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    15811697        system("sync");
    1582         paranoid_pclose(pout_to_fdisk);
    1583         log_msg(0, "------------------- fdisk.log looks like this ------------------");
     1698        paranoid_pclose(pout_to_fdisk);
     1699        log_msg(0,
     1700                "------------------- fdisk.log looks like this ------------------");
    15841701        sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    15851702        system(tmp);
    1586         log_msg(0, "------------------- end of fdisk.log... word! ------------------");
     1703        log_msg(0,
     1704                "------------------- end of fdisk.log... word! ------------------");
    15871705        sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG);
    1588         if (!run_program_and_log_output(tmp, 5))
    1589           {
    1590             g_partition_table_locked_up++;
    1591             log_to_screen("A flaw in the Linux kernel has locked the partition table.");
    1592           }
     1706        if (!run_program_and_log_output(tmp, 5)) {
     1707            g_partition_table_locked_up++;
     1708            log_to_screen
     1709                ("A flaw in the Linux kernel has locked the partition table.");
     1710        }
    15931711    }
    15941712    paranoid_free(device_str);
     
    16071725 * @return 0 for success, nonzero for failure.
    16081726 */
    1609 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize)
     1727int partition_device(FILE * pout_to_fdisk, const char *drive, int partno,
     1728                     int prev_partno, const char *format,
     1729                     long long partsize)
    16101730{
    16111731    /** int **************************************************************/
     
    16321752    malloc_string(logfile);
    16331753    malloc_string(output);
    1634    
     1754
    16351755    assert_string_is_neither_NULL_nor_zerolength(drive);
    16361756    assert(format != NULL);
    16371757
    1638     log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize);
     1758    log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting",
     1759           drive, partno, prev_partno, format, partsize);
    16391760
    16401761    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     
    16521773        sprintf(tmp, "Partitioning device %s (max size)", partition_name);
    16531774    } else {
    1654         sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024);
     1775        sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,
     1776                (long long) partsize / 1024);
    16551777    }
    16561778    update_progress_form(tmp);
     
    16581780
    16591781    if (is_this_device_mounted(partition_name)) {
    1660         sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name);
     1782        sprintf(tmp, "%s is mounted, and should not be partitioned",
     1783                partition_name);
    16611784        log_to_screen(tmp);
    16621785        paranoid_free(program);
     
    16791802    p = (char *) strrchr(partition_name, '/');
    16801803    sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
    1681     sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     1804    sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1805            MONDO_LOGFILE);
    16821806
    16831807    /* BERLIOS: shoould not be called each time */
     
    16891813    } else {
    16901814        /* MBR needs an extended partition if more than 4 partitions */
    1691         if (strcmp(part_table_fmt,"MBR") == 0) {
     1815        if (strcmp(part_table_fmt, "MBR") == 0) {
    16921816            if (partno == 5) {
    16931817                if (prev_partno >= 4) {
    1694                     log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
     1818                    log_to_screen
     1819                        ("You need to leave at least one partition free, for 'extended/logical'");
    16951820                    paranoid_free(program);
    16961821                    paranoid_free(partition_name);
     
    17001825                    return (1);
    17011826                } else {
    1702                     sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1);
     1827                    sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
     1828                            prev_partno + 1);
    17031829                }
    17041830            }
     
    17111837    strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
    17121838    if (partsize > 0) {
    1713                 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; }
     1839        if (!strcmp(format, "7")) {
     1840            log_msg(1, "Adding 512K, just in case");
     1841            partsize += 512;
     1842        }
    17141843        sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    17151844    }
     
    17281857
    17291858
    1730     if (pout_to_fdisk)
    1731     {
     1859    if (pout_to_fdisk) {
    17321860        log_msg(1, "Doing the new all-in-one fdisk thing");
    17331861        log_msg(1, "output = '%s'", output);
     
    17351863        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    17361864        strcpy(tmp, last_line_of_file(FDISK_LOG));
    1737         if (strstr(tmp, " (m "))
    1738         {
     1865        if (strstr(tmp, " (m ")) {
    17391866            log_msg(1, "Successfully created %s%d", drive, partno);
    1740         }
    1741         else
    1742         {
     1867        } else {
    17431868            log_msg(1, "last line = %s", tmp);
    1744             log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno);
    1745         }
    1746         if (!retval)
    1747         {
    1748             log_msg(1, "Trying to set %s%d's partition type now", drive, partno);
    1749             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1750             if (retval)
    1751             {
     1869            log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive,
     1870                    partno);
     1871        }
     1872        if (!retval) {
     1873            log_msg(1, "Trying to set %s%d's partition type now", drive,
     1874                    partno);
     1875            retval =
     1876                set_partition_type(pout_to_fdisk, drive, partno, format,
     1877                                   partsize);
     1878            if (retval) {
    17521879                log_msg(1, "Failed. Trying again...");
    1753                     retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1754             }
    1755           }
    1756         if (retval) { log_msg(1, "...but failed to set type"); }
    1757     }
    1758     else
    1759     {
     1880                retval =
     1881                    set_partition_type(pout_to_fdisk, drive, partno,
     1882                                       format, partsize);
     1883            }
     1884        }
     1885        if (retval) {
     1886            log_msg(1, "...but failed to set type");
     1887        }
     1888    } else {
    17601889        strcat(output, "w\n\n");
    1761             if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); }
     1890        if (g_fprep) {
     1891            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     1892        }
    17621893        /* write to disk; close fdisk's stream */
    17631894        if (!(fout = popen(program, "w"))) {
     
    17701901            log_it("Vaccum-packing");
    17711902            g_current_progress--;
    1772             res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1);
     1903            res =
     1904                partition_device(pout_to_fdisk, drive, partno, prev_partno,
     1905                                 format, -1);
    17731906            if (res) {
    17741907                sprintf(tmp, "Failed to vacuum-pack %s", partition_name);
     
    17801913        }
    17811914        if (does_partition_exist(drive, partno)) {
    1782             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
     1915            retval =
     1916                set_partition_type(pout_to_fdisk, drive, partno, format,
     1917                                   partsize);
    17831918            if (retval) {
    1784                 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name);
     1919                sprintf(tmp, "Partitioned %s but failed to set its type",
     1920                        partition_name);
    17851921                log_it(tmp);
    17861922            } else {
    17871923                if (partsize > 0) {
    1788                     sprintf(tmp, "Partition %s created+configured OK", partition_name);
     1924                    sprintf(tmp, "Partition %s created+configured OK",
     1925                            partition_name);
    17891926                    log_to_screen(tmp);
    17901927                } else {
     
    17921929                }
    17931930            }
    1794             } else {
     1931        } else {
    17951932            sprintf(tmp, "Failed to partition %s", partition_name);
    17961933            if (partsize > 0) {
     
    18441981        /*      mountlist=&new_mtlist; */
    18451982        /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
    1846         log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-");
     1983        log_msg(0,
     1984                "Mountlist, including the partitions incorporated in RAID devices:-");
    18471985        for (i = 0; i < mountlist->entries; i++) {
    18481986            log_it(mountlist->el[i].device);
     
    18511989    }
    18521990    log_msg(0, "Stopping all LVMs, just in case");
    1853         if (!g_text_mode) { newtSuspend(); }
    1854     do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
    1855         if (!g_text_mode) { newtResume(); }
     1991    if (!g_text_mode) {
     1992        newtSuspend();
     1993    }
     1994    do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
     1995    if (!g_text_mode) {
     1996        newtResume();
     1997    }
    18561998    log_msg(0, "Stopping all software RAID devices, just in case");
    18571999    stop_all_raid_devices(mountlist);
    18582000    log_msg(0, "Done.");
    1859    
     2001
    18602002/* 
    18612003    if (does_file_exist("/tmp/i-want-my-lvm"))
     
    18652007*/
    18662008
    1867     open_progress_form("Partitioning devices", "I am now going to partition all your drives.",
    1868                "This should not take more than five minutes.", "", mountlist->entries);
     2009    open_progress_form("Partitioning devices",
     2010                       "I am now going to partition all your drives.",
     2011                       "This should not take more than five minutes.", "",
     2012                       mountlist->entries);
    18692013
    18702014    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    18782022    if (retval) {
    18792023        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1880         log_to_screen("Errors occurred during the partitioning of your hard drives.");
     2024        log_to_screen
     2025            ("Errors occurred during the partitioning of your hard drives.");
    18812026    } else {
    18822027        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    19042049 * @return 0 for success, nonzero for failure.
    19052050 */
    1906 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize)
     2051int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno,
     2052                       const char *format, long long partsize)
    19072053{
    19082054    /** buffers *********************************************************/
    1909   char *partition;
    1910   char *command;
    1911   char *output;
    1912   char *tmp;
    1913   char *partcode;
    1914   char *logfile;
     2055    char *partition;
     2056    char *command;
     2057    char *output;
     2058    char *tmp;
     2059    char *partcode;
     2060    char *logfile;
    19152061
    19162062    /** pointers *********************************************************/
     
    19262072    assert(format != NULL);
    19272073
    1928   malloc_string(partition);
    1929   malloc_string(command);
    1930   malloc_string(output);
    1931   malloc_string(tmp);
    1932   malloc_string(partcode);
    1933   malloc_string(logfile);
     2074    malloc_string(partition);
     2075    malloc_string(command);
     2076    malloc_string(output);
     2077    malloc_string(tmp);
     2078    malloc_string(partcode);
     2079    malloc_string(logfile);
    19342080
    19352081    build_partition_name(partition, drive, partno);
     
    19442090            strcpy(partcode, "b");
    19452091        }
    1946     } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0
    1947            || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) {
     2092    } else if (strcmp(format, "ext2") == 0
     2093               || strcmp(format, "reiserfs") == 0
     2094               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
     2095               || strcmp(format, "jfs") == 0) {
    19482096        strcpy(partcode, "83");
    19492097    } else if (strcmp(format, "minix") == 0) {
     
    19522100        strcpy(partcode, "fd");
    19532101    } else if ((strcmp(format, "ufs") == 0)
    1954            || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
     2102               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    19552103        strcpy(partcode, "a5");
    19562104    } else if (strcmp(format, "lvm") == 0) {
     
    19622110    } else {
    19632111        /* probably an image */
    1964         sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format);
     2112        sprintf(tmp,
     2113                "Unknown format ('%s') - using supplied string anyway",
     2114                format);
    19652115        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    19662116#ifdef __FreeBSD__
    1967         strcpy(partcode, format); // was a5
     2117        strcpy(partcode, format);   // was a5
    19682118#else
    1969         strcpy(partcode, format); // was 83
    1970 #endif
    1971     }
    1972     sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode);
     2119        strcpy(partcode, format);   // was 83
     2120#endif
     2121    }
     2122    sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,
     2123            partcode);
    19732124    log_msg(1, tmp);
    19742125    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    1975        
    1976         if (pout_to_fdisk)
    1977         {
     2126
     2127        if (pout_to_fdisk) {
    19782128            res = 0;
    19792129            fput_string_one_char_at_a_time(pout_to_fdisk, "t\n");
    1980             if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))
    1981             {
     2130            if (partno > 1
     2131                || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
    19822132                log_msg(5, "Specifying partno (%d) - yay", partno);
    19832133                sprintf(tmp, "%d\n", partno);
    19842134                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1985                 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG));
    1986             }
    1987            
     2135                log_msg(5, "A - last line = '%s'",
     2136                        last_line_of_file(FDISK_LOG));
     2137            }
     2138
    19882139            sprintf(tmp, "%s\n", partcode);
    19892140            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1990             log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG));
     2141            log_msg(5, "B - last line = '%s'",
     2142                    last_line_of_file(FDISK_LOG));
    19912143            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    1992             log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG));
    1993            
     2144            log_msg(5, "C - last line = '%s'",
     2145                    last_line_of_file(FDISK_LOG));
     2146
    19942147            strcpy(tmp, last_line_of_file(FDISK_LOG));
    1995             if (!strstr(tmp, " (m "))
    1996               {
    1997                 log_msg(1, "last line = '%s'; part type set failed", tmp);
    1998                 res++;
    1999                 fput_string_one_char_at_a_time(pout_to_fdisk,"\n");
    2000               }
    2001             fput_string_one_char_at_a_time(pout_to_fdisk,"p\n");
    2002         }
    2003         else
    2004         {
     2148            if (!strstr(tmp, " (m ")) {
     2149                log_msg(1, "last line = '%s'; part type set failed", tmp);
     2150                res++;
     2151                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
     2152            }
     2153            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
     2154        } else {
    20052155            sprintf(output, "t\n%d\n%s\n", partno, partcode);
    20062156            strcat(output, "w\n");
    2007             sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     2157            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
     2158                    MONDO_LOGFILE, MONDO_LOGFILE);
    20082159            log_msg(5, "output = '%s'", output);
    20092160            log_msg(5, "partno=%d; partcode=%s", partno, partcode);
     
    20192170            }
    20202171        }
    2021     if (res)
    2022       {
    2023         log_OS_error(command);
    2024       }
    2025     }
    2026 
    2027   paranoid_free(partition);
    2028   paranoid_free(command);
    2029   paranoid_free(output);
    2030   paranoid_free(tmp);
    2031   paranoid_free(partcode);
    2032   paranoid_free(logfile);
    2033 
    2034   return (res);
     2172        if (res) {
     2173            log_OS_error(command);
     2174        }
     2175    }
     2176
     2177    paranoid_free(partition);
     2178    paranoid_free(command);
     2179    paranoid_free(output);
     2180    paranoid_free(tmp);
     2181    paranoid_free(partcode);
     2182    paranoid_free(logfile);
     2183
     2184    return (res);
    20352185}
    20362186
     
    20492199    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20502200    malloc_string(program);
    2051    
     2201
    20522202#ifdef __FreeBSD__
    20532203    if (is_this_device_mounted(raid_device)) {
     
    20622212    log_msg(1, "program = %s", program);
    20632213    res = run_program_and_log_output(program, 1);
    2064     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2065     if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); }
     2214    if (g_fprep) {
     2215        fprintf(g_fprep, "%s\n", program);
     2216    }
     2217    if (res) {
     2218        log_msg(1, "Warning - failed to start RAID device %s",
     2219                raid_device);
     2220    }
    20662221    retval += res;
    20672222    sleep(1);
     
    20892244    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20902245    malloc_string(program);
    2091    
     2246
    20922247#ifdef __FreeBSD__
    20932248    if (is_this_device_mounted(raid_device)) {
     
    21022257    log_msg(1, "program = %s", program);
    21032258    res = run_program_and_log_output(program, 1);
    2104     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2105     if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); }
     2259    if (g_fprep) {
     2260        fprintf(g_fprep, "%s\n", program);
     2261    }
     2262    if (res) {
     2263        log_msg(1, "Warning - failed to stop RAID device %s", raid_device);
     2264    }
    21062265    retval += res;
    21072266    return (retval);
     
    21122271{
    21132272    int i;
    2114     int retval=0;
     2273    int retval = 0;
    21152274    int res;
    2116    
    2117     for(i=0; i<mountlist->entries; i++)
    2118       {
    2119         if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)))
    2120           {
    2121             log_msg(1, "Starting %s", mountlist->el[i].device);
    2122         res = start_raid_device(mountlist->el[i].device);
    2123         retval += res;
    2124           }
    2125       }
    2126     if (retval) { log_msg(1, "Started all s/w raid devices OK"); }
    2127     else { log_msg(1, "Failed to start some/all s/w raid devices"); }
    2128     return(retval);
     2275
     2276    for (i = 0; i < mountlist->entries; i++) {
     2277        if (!strncmp
     2278            (mountlist->el[i].device, RAID_DEVICE_STUB,
     2279             strlen(RAID_DEVICE_STUB))) {
     2280            log_msg(1, "Starting %s", mountlist->el[i].device);
     2281            res = start_raid_device(mountlist->el[i].device);
     2282            retval += res;
     2283        }
     2284    }
     2285    if (retval) {
     2286        log_msg(1, "Started all s/w raid devices OK");
     2287    } else {
     2288        log_msg(1, "Failed to start some/all s/w raid devices");
     2289    }
     2290    return (retval);
    21292291}
    21302292
     
    21632325    for (i = 0; i < 3; i++) {
    21642326#ifdef __FreeBSD__
    2165         fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r");
     2327        fin =
     2328            popen
     2329            ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2",
     2330             "r");
    21662331        if (!fin) {
    21672332            paranoid_free(dev);
     
    21692334            return (1);
    21702335        }
    2171         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2336        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2337             fgets(incoming, MAX_STR_LEN - 1, fin)) {
    21722338            retval += stop_raid_device(incoming);
    21732339        }
     
    21802346            return (1);
    21812347        }
    2182         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
    2183             for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++);
     2348        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2349             fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2350            for (p = incoming;
     2351                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
     2352                                || !isdigit(*(p + 2))); p++);
    21842353            if (*p != '\0') {
    21852354                sprintf(dev, "/dev/%s", p);
     
    21922361    }
    21932362    paranoid_fclose(fin);
    2194     if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); }
     2363    if (retval) {
     2364        log_msg(1, "Warning - unable to stop some RAID devices");
     2365    }
    21952366    paranoid_free(dev);
    21962367    paranoid_free(incoming);
    2197     system("sync"); system("sync"); system("sync");
     2368    system("sync");
     2369    system("sync");
     2370    system("sync");
    21982371    sleep(1);
    21992372    return (retval);
     
    22502423        sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    22512424#endif
    2252         sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program);
     2425        sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2426                program);
    22532427        log_it(tmp);
    22542428        res = 0;
     
    22672441 */
    22682442long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself
    2269                         *mountlist, char *drive_name)
     2443                                            *mountlist, char *drive_name)
    22702444{
    22712445    /** long ************************************************************/
     
    22842458    assert_string_is_neither_NULL_nor_zerolength(drive_name);
    22852459
    2286     for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) {
    2287         if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) {
     2460    for (original_size_of_drive = 0, partno = 0;
     2461         partno < mountlist->entries; partno++) {
     2462        if (strncmp
     2463            (mountlist->el[partno].device, drive_name,
     2464             strlen(drive_name)) == 0) {
    22882465            original_size_of_drive += mountlist->el[partno].size;
    22892466        } else {
     
    23102487 */
    23112488void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself
    2312                              *mountlist, char *drive_name)
     2489                                                     *mountlist,
     2490                                                     char *drive_name)
    23132491{
    23142492    /**buffers **********************************************************/
     
    23172495    /** int *************************************************************/
    23182496    int partno, lastpart;
    2319                /** remove driveno, noof_drives stan benoit apr 2002**/
     2497               /** remove driveno, noof_drives stan benoit apr 2002**/
    23202498
    23212499    /** float ***********************************************************/
    23222500    float factor;
    23232501    float new_size;
    2324 //  float newcylinderno;
     2502//  float newcylinderno;
    23252503
    23262504    /** long *************************************************************/
     
    23282506    long current_size_of_drive = 0;
    23292507    long original_size_of_drive = 0;
    2330     long final_size;    /* all in Megabytes */
     2508    long final_size;            /* all in Megabytes */
    23312509    struct mountlist_reference *drivemntlist;
    23322510
     
    23402518
    23412519    if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) {
    2342         if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) {
     2520        if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))
     2521            == 0) {
    23432522            paranoid_free(tmp);
    23442523            return;
     
    23522531
    23532532    current_size_of_drive = get_phys_size_of_drive(drive_name);
    2354    
     2533
    23552534    if (current_size_of_drive <= 0) {
    23562535        log_it("Not resizing to match %s - can't find drive", drive_name);
     
    23582537        return;
    23592538    }
    2360     sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive);
     2539    sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name,
     2540            current_size_of_drive);
    23612541    log_to_screen(tmp);
    23622542
    2363     drivemntlist = malloc(sizeof (struct mountlist_reference));
    2364     drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
     2543    drivemntlist = malloc(sizeof(struct mountlist_reference));
     2544    drivemntlist->el =
     2545        malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
    23652546
    23662547    if (!drivemntlist) {
     
    23752556
    23762557    if (original_size_of_drive <= 0) {
    2377         sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name);
     2558        sprintf(tmp, "Cannot resize %s's entries. Drive not found.",
     2559                drive_name);
    23782560        log_to_screen(tmp);
    23792561        paranoid_free(tmp);
    23802562        return;
    23812563    }
    2382     factor = (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2383     sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive,
    2384         factor);
     2564    factor =
     2565        (float) (current_size_of_drive) / (float) (original_size_of_drive);
     2566    sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2567            drive_name, original_size_of_drive, current_size_of_drive,
     2568            factor);
    23852569    log_to_screen(tmp);
    23862570
    2387     lastpart = drivemntlist->entries-1;
     2571    lastpart = drivemntlist->entries - 1;
    23882572    for (partno = 0; partno < drivemntlist->entries; partno++) {
    23892573        /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */
    2390         if ( !atoi(drivemntlist->el[partno]->format) ) {
     2574        if (!atoi(drivemntlist->el[partno]->format)) {
    23912575            new_size = (float) (drivemntlist->el[partno]->size) * factor;
    23922576        } else {
    23932577            new_size = drivemntlist->el[partno]->size;
    23942578        }
    2395        
     2579
    23962580        if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) {
    23972581            log_msg(1, "Skipping %s (%s) because it's an image",
    2398                             drivemntlist->el[partno]->device,
    2399                             drivemntlist->el[partno]->mountpoint);
    2400             newsizL = (long) new_size; // It looks wrong but it's not
     2582                    drivemntlist->el[partno]->device,
     2583                    drivemntlist->el[partno]->mountpoint);
     2584            newsizL = (long) new_size;  // It looks wrong but it's not
    24012585        } else {
    24022586            newsizL = (long) new_size;
    24032587        }
    2404         sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL);
     2588        sprintf(tmp, "Changing %s from %lld KB to %ld KB",
     2589                drivemntlist->el[partno]->device,
     2590                drivemntlist->el[partno]->size, newsizL);
    24052591        log_to_screen(tmp);
    24062592        drivemntlist->el[partno]->size = newsizL;
     
    24202606 */
    24212607void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself
    2422                             *mountlist)
     2608                                                        *mountlist)
    24232609{
    24242610    /** buffers *********************************************************/
     
    24342620
    24352621    if (g_mountlist_fname[0] == '\0') {
    2436         log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank");
    2437         log_it ("That does NOT affect the functioning of this subroutine.");
    2438         log_it ("--- Hugo, 2002/11/20");
     2622        log_it
     2623            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
     2624        log_it("That does NOT affect the functioning of this subroutine.");
     2625        log_it("--- Hugo, 2002/11/20");
    24392626    }
    24402627    iamhere("Resizing mountlist");
     
    24422629    iamhere("Back from MLoDiM");
    24432630    for (driveno = 0; driveno < drivelist->entries; driveno++) {
    2444         resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device);
     2631        resize_drive_proportionately_to_suit_new_drives(mountlist,
     2632                                                        drivelist->
     2633                                                        el[driveno].
     2634                                                        device);
    24452635    }
    24462636    log_to_screen("Mountlist adjusted to suit current hard drive(s)");
     
    24562646 * @author Ralph Grewe
    24572647 */
    2458 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) {
     2648void create_mountlist_for_drive(struct mountlist_itself *mountlist,
     2649                                char *drive_name,
     2650                                struct mountlist_reference *drivemntlist)
     2651{
    24592652    int partno;
    24602653    char *tmp_drive_name, *c;
     
    24642657    assert(drivemntlist != NULL);
    24652658
    2466     log_msg (1, "Creating list of partitions for drive %s",drive_name);
    2467 
    2468     tmp_drive_name = strdup (drive_name);
    2469     if (!tmp_drive_name) fatal_error ("Out of memory");
    2470    
     2659    log_msg(1, "Creating list of partitions for drive %s", drive_name);
     2660
     2661    tmp_drive_name = strdup(drive_name);
     2662    if (!tmp_drive_name)
     2663        fatal_error("Out of memory");
     2664
    24712665    /* devfs devices? */
    2472     c = strrchr (tmp_drive_name, '/');
    2473     if (c && strncmp (c, "/disc", 5) == 0) {
    2474         /* yup its devfs, change the "disc" to "part" so the existing code works */
    2475         strcpy (c + 1, "part");
    2476     }
    2477     drivemntlist->entries=0;
     2666    c = strrchr(tmp_drive_name, '/');
     2667    if (c && strncmp(c, "/disc", 5) == 0) {
     2668        /* yup its devfs, change the "disc" to "part" so the existing code works */
     2669        strcpy(c + 1, "part");
     2670    }
     2671    drivemntlist->entries = 0;
    24782672    for (partno = 0; partno < mountlist->entries; partno++) {
    2479         if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) {
    2480             drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno];
     2673        if (strncmp
     2674            (mountlist->el[partno].device, tmp_drive_name,
     2675             strlen(tmp_drive_name)) == 0) {
     2676            drivemntlist->el[drivemntlist->entries] =
     2677                &mountlist->el[partno];
    24812678            drivemntlist->entries++;
    24822679        }
    24832680    }
    24842681    if (tmp_drive_name)
    2485         free (tmp_drive_name);
     2682        free(tmp_drive_name);
    24862683}
    24872684
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore-EXT.h

    r30 r128  
    66
    77extern bool g_sigpipe_caught;
    8 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
     8extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
    99extern bool g_I_have_just_nuked;
    1010extern char *g_tmpfs_mountpt;
     
    1313
    1414extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
    15 extern char  *g_biggielist_txt;
    16 extern char  *g_filelist_full;
    17 extern char  *g_biggielist_pot;
    18 extern char  *g_filelist_potential;
    19 extern char  *g_filelist_imagedevs;
    20 extern char  *g_filelist_restthese;
    21 extern char  *g_biggielist_restthese;
    22 extern char  *g_imagedevs_restthese;
    23 extern char  *g_mondo_cfg_file;
    24 extern char  *g_mountlist_fname;
    25 extern char  *g_mondo_home;
     15extern char *g_biggielist_txt;
     16extern char *g_filelist_full;
     17extern char *g_biggielist_pot;
     18extern char *g_filelist_potential;
     19extern char *g_filelist_imagedevs;
     20extern char *g_filelist_restthese;
     21extern char *g_biggielist_restthese;
     22extern char *g_imagedevs_restthese;
     23extern char *g_mondo_cfg_file;
     24extern char *g_mountlist_fname;
     25extern char *g_mondo_home;
    2626
    2727
    28 extern void ask_about_these_imagedevs(char*,char*);
    29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*);
    30 extern void sort_mountlist_by_device(struct mountlist_itself*);
    31 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*);
    32 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    33 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    34 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
     28extern void ask_about_these_imagedevs(char *, char *);
     29extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *,
     30                         struct raidlist_itself *);
     31extern void sort_mountlist_by_device(struct mountlist_itself *);
     32extern void find_pathname_of_executable_preferably_in_RESTORING(char *,
     33                                                                char *,
     34                                                                char *);
     35extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
     36                            struct raidlist_itself *);
     37extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *,
     38                     struct raidlist_itself *);
     39extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *,
     40                        struct raidlist_itself *);
    3541extern int iso_mode(struct s_bkpinfo *bkpinfo,
    36      struct mountlist_itself *mountlist,
    37      struct raidlist_itself *raidlist,
    38      bool nuke_me_please);
    39 extern int load_mountlist(struct mountlist_itself*,char*);
    40 extern int load_raidtab_into_raidlist(struct raidlist_itself*,char*);
    41 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    42 extern int save_raidlist_to_raidtab(struct raidlist_itself*,char*);
    43 extern void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*);
    44 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*);
    45 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*);
    46 extern int restore_a_tarball_from_CD(char *, int, struct s_node*);
    47 extern int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, int, struct s_node*, long long);
    48 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*);
    49 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*);
    50 extern int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*);
    51 extern int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*);
    52 extern int restore_everything(struct s_bkpinfo*, struct s_node*);
    53 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*);
    54 extern int restore_to_live_filesystem(struct s_bkpinfo*);
    55 extern void swap_mountlist_entries(struct mountlist_itself*,int,int);
    56 extern void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool);
    57 extern void sort_mountlist_by_device(struct mountlist_itself*);
     42                    struct mountlist_itself *mountlist,
     43                    struct raidlist_itself *raidlist, bool nuke_me_please);
     44extern int load_mountlist(struct mountlist_itself *, char *);
     45extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *);
     46extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
     47                        struct raidlist_itself *);
     48extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *);
     49extern void process_raidtab_line(FILE *, struct raid_device_record *,
     50                                 char *, char *);
     51extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long,
     52                                        struct s_node *);
     53extern int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *,
     54                                            long, char *, long long,
     55                                            struct s_node *);
     56extern int restore_a_tarball_from_CD(char *, int, struct s_node *);
     57extern int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, int,
     58                                         struct s_node *, long long);
     59extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo *,
     60                                           struct s_node *);
     61extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo *,
     62                                               struct s_node *);
     63extern int restore_all_tarballs_from_CD(struct s_bkpinfo *,
     64                                        struct s_node *);
     65extern int restore_all_tarballs_from_stream(struct s_bkpinfo *,
     66                                            struct s_node *);
     67extern int restore_everything(struct s_bkpinfo *, struct s_node *);
     68extern int restore_live_from_monitas_server(struct s_bkpinfo *, char *,
     69                                            char *, char *);
     70extern int restore_to_live_filesystem(struct s_bkpinfo *);
     71extern void swap_mountlist_entries(struct mountlist_itself *, int, int);
     72extern void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool);
     73extern void sort_mountlist_by_device(struct mountlist_itself *);
    5874extern void success_message(void);
    5975extern void twenty_seconds_til_yikes(void);
    60 extern int run_raw_mbr(bool offer_to_hack_scripts, char*bd);
    61 extern int save_mountlist_to_disk(struct mountlist_itself*, char*);
    62 extern void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout);
    63 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname);
    64 extern int what_number_cd_is_this(struct s_bkpinfo*);
     76extern int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
     77extern int save_mountlist_to_disk(struct mountlist_itself *, char *);
     78extern void save_raidrec_to_file(struct raid_device_record *raidrec,
     79                                 FILE * fout);
     80extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist,
     81                                    char *fname);
     82extern int what_number_cd_is_this(struct s_bkpinfo *);
    6583
    6684#ifdef __FreeBSD__
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore.c

    r30 r128  
    55    copyright            : (C) 2000 by Hugo Rabson
    66    email                : Hugo Rabson <hugorabson@msn.com>
    7     cvsid                : $Id: mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp $
     7    cvsid                : $Id$
    88***************************************************************************/
    99
     
    407407
    408408
    409 //static char cvsid[] = "$Id: mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp $";
     409//static char cvsid[] = "$Id$";
    410410
    411411/**************************************************************************
    412412 * Globals                                                                *
    413413 **************************************************************************/
    414 extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
    415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
    416                                                 // up global bkpinfo struct
     414extern char *g_tmpfs_mountpt;   // declared in libmondo-tools.c
     415extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
     416                                                // up global bkpinfo struct
    417417extern bool g_text_mode;
    418418extern FILE *g_fprep;
     
    433433 * Set by the signal handler; cleared after it's handled.
    434434 */
    435 bool    g_sigpipe_caught=FALSE;
     435bool g_sigpipe_caught = FALSE;
    436436
    437437/**
     
    439439 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
    440440 */
    441 bool    g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
     441bool g_ISO_restore_mode = FALSE;    /* are we in Iso Mode? */
    442442
    443443/**
    444444 * If TRUE, then we have had a successful "nuke" restore.
    445445 */
    446 bool    g_I_have_just_nuked = FALSE;
     446bool g_I_have_just_nuked = FALSE;
    447447
    448448/**
    449449 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
    450450 */
    451 char    *g_isodir_device;
     451char *g_isodir_device;
    452452
    453453/**
    454454 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
    455455 */
    456 char    *g_isodir_format;
     456char *g_isodir_format;
    457457
    458458/**
    459459 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
    460460 */
    461 char    *g_biggielist_txt;
     461char *g_biggielist_txt;
    462462
    463463/**
     
    465465 * the current archive set.
    466466 */
    467 char    *g_filelist_full;
     467char *g_filelist_full;
    468468
    469469/**
     
    471471 * as images, not as individual files.
    472472 */
    473 char  *g_filelist_imagedevs;
     473char *g_filelist_imagedevs;
    474474
    475475/**
     
    477477 * @see g_filelist_imagedevs
    478478 */
    479 char  *g_imagedevs_restthese;
     479char *g_imagedevs_restthese;
    480480
    481481/**
     
    483483 * information for this backup.
    484484 */
    485 char  *g_mondo_cfg_file;
     485char *g_mondo_cfg_file;
    486486
    487487/**
     
    489489 * user's partitions and hard drives.
    490490 */
    491 char  *g_mountlist_fname;
     491char *g_mountlist_fname;
    492492
    493493/**
     
    495495 * to avoid link errors.
    496496 */
    497 char  *g_mondo_home;
     497char *g_mondo_home;
    498498
    499499/* @} - end of "Restore-Time Globals" in globalGroup */
     
    501501
    502502
    503 extern int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction);
     503extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
     504                                 char direction);
    504505
    505506
     
    525526 * @ingroup restoreGuiGroup
    526527 */
    527 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
     528int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
     529                                struct mountlist_itself *mountlist,
     530                                struct raidlist_itself *raidlist)
    528531{
    529   int retval=0, res=0;
    530 
    531   log_msg(2, "let_user_edit_the_mountlist() --- starting");
    532 
    533   assert(bkpinfo!=NULL);
    534   assert(mountlist!=NULL);
    535   assert(raidlist!=NULL);
    536       if ( !bkpinfo->disaster_recovery )
    537         {
    538           strcpy( g_mountlist_fname, "/tmp/mountlist.txt" );
    539           log_msg(2,  "I guess you're testing edit_mountlist()" );
    540         }
    541       if (!does_file_exist(g_mountlist_fname))
    542         {
    543           log_to_screen(g_mountlist_fname);
    544           log_to_screen("does not exist");
    545           return(1);
    546         }
    547      
    548       retval = load_mountlist( mountlist, g_mountlist_fname );
    549       load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    550       if ( retval ) { log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); }
    551       res = edit_mountlist( g_mountlist_fname, mountlist, raidlist );
    552       if ( res )
    553     {
    554       return( 1 );
    555     }
    556 
    557       save_mountlist_to_disk( mountlist, g_mountlist_fname );
    558       save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME );
    559      
    560       log_to_screen("I have finished editing the mountlist for you.");
    561      
    562       return( retval );
    563     }
     532    int retval = 0, res = 0;
     533
     534    log_msg(2, "let_user_edit_the_mountlist() --- starting");
     535
     536    assert(bkpinfo != NULL);
     537    assert(mountlist != NULL);
     538    assert(raidlist != NULL);
     539    if (!bkpinfo->disaster_recovery) {
     540        strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     541        log_msg(2, "I guess you're testing edit_mountlist()");
     542    }
     543    if (!does_file_exist(g_mountlist_fname)) {
     544        log_to_screen(g_mountlist_fname);
     545        log_to_screen("does not exist");
     546        return (1);
     547    }
     548
     549    retval = load_mountlist(mountlist, g_mountlist_fname);
     550    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     551    if (retval) {
     552        log_to_screen
     553            ("Warning - load_raidtab_into_raidlist returned an error");
     554    }
     555    res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
     556    if (res) {
     557        return (1);
     558    }
     559
     560    save_mountlist_to_disk(mountlist, g_mountlist_fname);
     561    save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
     562
     563    log_to_screen("I have finished editing the mountlist for you.");
     564
     565    return (retval);
     566}
    564567
    565568
     
    573576 * @ingroup restoreUtilityGroup
    574577 */
    575 bool
    576 partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself *mountlist)
     578bool
     579partition_table_contains_Compaq_diagnostic_partition(struct
     580                                                     mountlist_itself *
     581                                                     mountlist)
    577582{
    578   int i;
    579 
    580   assert(mountlist!=NULL);
    581 
    582   for( i = 0; i < mountlist->entries; i++ )
    583     {
    584       if ( strstr( mountlist->el[i].format, "ompaq" ) )
    585     {
    586       log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
    587           i,
    588           mountlist->el[i].device,
    589           mountlist->el[i].format );
    590      
    591       return( TRUE );
    592     }
    593     }
    594   return( FALSE );
     583    int i;
     584
     585    assert(mountlist != NULL);
     586
     587    for (i = 0; i < mountlist->entries; i++) {
     588        if (strstr(mountlist->el[i].format, "ompaq")) {
     589            log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
     590                    i, mountlist->el[i].device, mountlist->el[i].format);
     591
     592            return (TRUE);
     593        }
     594    }
     595    return (FALSE);
    595596}
     597
    596598/**************************************************************************
    597599 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION                *
     
    604606 * @ingroup restoreUtilityGroup
    605607 */
    606 void
    607 offer_to_abort_because_Compaq_Proliants_suck(void)
     608void offer_to_abort_because_Compaq_Proliants_suck(void)
    608609{
    609   popup_and_OK( COMPAQ_PROLIANTS_SUCK );
    610   if ( ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?") )
    611     {
    612       fatal_error( "Aborting. Please reboot and prep your hard drive with your Compaq CD." );
    613     }
     610    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
     611    if (ask_me_yes_or_no
     612        ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
     613    {
     614        fatal_error
     615            ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
     616    }
    614617}
     618
    615619/**************************************************************************
    616620 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
     
    627631 * @ingroup restoreGroup
    628632 */
    629 int 
    630 catchall_mode( struct s_bkpinfo *bkpinfo,
    631            struct mountlist_itself *mountlist,
    632            struct raidlist_itself*raidlist)
     633int
     634catchall_mode(struct s_bkpinfo *bkpinfo,
     635              struct mountlist_itself *mountlist,
     636              struct raidlist_itself *raidlist)
    633637{
    634   char c, *tmp;
    635   int retval = 0;
    636 
    637   iamhere("inside catchall");
    638   assert(bkpinfo!=NULL);
    639   assert(mountlist!=NULL);
    640   assert(raidlist!=NULL);
    641   malloc_string(tmp);
    642   iamhere("pre wrm");
    643   c = which_restore_mode();
    644   iamhere("post wrm");
    645   if ( c == 'I' || c == 'N' || c == 'C')
    646     {
    647       interactively_obtain_media_parameters_from_user( bkpinfo, FALSE);
    648     }
    649   else
    650     {
    651       popup_and_OK( "No restoring or comparing will take place today." );
    652       if ( is_this_device_mounted( "/mnt/cdrom" ) )
    653     {
    654       run_program_and_log_output( "umount /mnt/cdrom", FALSE);
    655     }
    656       if ( g_ISO_restore_mode )
    657     {
    658           sprintf(tmp, "umount %s", bkpinfo->isodir);
    659       run_program_and_log_output( tmp, FALSE);
    660     }
    661       paranoid_MR_finish( 0 );
    662     }
    663 
    664   iamhere("post int");
    665 
    666   if (bkpinfo->backup_media_type == iso)
    667     {
    668       if (iso_fiddly_bits(bkpinfo, (c=='N')?TRUE:FALSE))
    669         { log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); return(1); }
    670       else
    671         { log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); }
    672     }
    673 
    674   if (c == 'I' )
    675     {
    676       log_msg(2, "IM selected" );
    677       retval += interactive_mode( bkpinfo,mountlist,raidlist );
    678     }
    679   else if
    680     ( c == 'N' )
    681     {
    682       log_msg(2, "NM selected");
    683       retval += nuke_mode( bkpinfo, mountlist, raidlist ); }
    684   else if
    685     ( c == 'C' )
    686     {
    687       log_msg(2, "CM selected" );
    688       retval += compare_mode( bkpinfo, mountlist, raidlist);
    689     }
    690   paranoid_free(tmp);
    691   return( retval );
     638    char c, *tmp;
     639    int retval = 0;
     640
     641    iamhere("inside catchall");
     642    assert(bkpinfo != NULL);
     643    assert(mountlist != NULL);
     644    assert(raidlist != NULL);
     645    malloc_string(tmp);
     646    iamhere("pre wrm");
     647    c = which_restore_mode();
     648    iamhere("post wrm");
     649    if (c == 'I' || c == 'N' || c == 'C') {
     650        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     651    } else {
     652        popup_and_OK("No restoring or comparing will take place today.");
     653        if (is_this_device_mounted("/mnt/cdrom")) {
     654            run_program_and_log_output("umount /mnt/cdrom", FALSE);
     655        }
     656        if (g_ISO_restore_mode) {
     657            sprintf(tmp, "umount %s", bkpinfo->isodir);
     658            run_program_and_log_output(tmp, FALSE);
     659        }
     660        paranoid_MR_finish(0);
     661    }
     662
     663    iamhere("post int");
     664
     665    if (bkpinfo->backup_media_type == iso) {
     666        if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
     667            log_msg(2,
     668                    "catchall_mode --- iso_fiddly_bits returned w/ error");
     669            return (1);
     670        } else {
     671            log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
     672        }
     673    }
     674
     675    if (c == 'I') {
     676        log_msg(2, "IM selected");
     677        retval += interactive_mode(bkpinfo, mountlist, raidlist);
     678    } else if (c == 'N') {
     679        log_msg(2, "NM selected");
     680        retval += nuke_mode(bkpinfo, mountlist, raidlist);
     681    } else if (c == 'C') {
     682        log_msg(2, "CM selected");
     683        retval += compare_mode(bkpinfo, mountlist, raidlist);
     684    }
     685    paranoid_free(tmp);
     686    return (retval);
    692687}
     688
    693689/**************************************************************************
    694690 *END_CATCHALL_MODE                                                      *
     
    709705 */
    710706void
    711 find_pathname_of_executable_preferably_in_RESTORING( char *out_path, char *fname, char*restg )
     707find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
     708                                                    char *fname,
     709                                                    char *restg)
    712710{
    713   assert(out_path!=NULL);
    714   assert_string_is_neither_NULL_nor_zerolength(fname);
    715 
    716   sprintf( out_path, "%s/sbin/%s", restg, fname );
    717   if ( does_file_exist(out_path) )
    718     {
    719       sprintf( out_path, "%s/usr/sbin/%s", restg, fname );
    720       if ( does_file_exist( out_path ) )
    721         {
    722           sprintf( out_path, "%s/bin/%s", restg, fname );
    723           if ( does_file_exist( out_path ) )
    724             {
    725               sprintf( out_path, "%s/usr/bin/%s", restg, fname );
    726               if ( does_file_exist( out_path ) )
    727                 {
    728                   strcpy( out_path, fname );
    729                 }
    730             }
    731         }
    732     }
     711    assert(out_path != NULL);
     712    assert_string_is_neither_NULL_nor_zerolength(fname);
     713
     714    sprintf(out_path, "%s/sbin/%s", restg, fname);
     715    if (does_file_exist(out_path)) {
     716        sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
     717        if (does_file_exist(out_path)) {
     718            sprintf(out_path, "%s/bin/%s", restg, fname);
     719            if (does_file_exist(out_path)) {
     720                sprintf(out_path, "%s/usr/bin/%s", restg, fname);
     721                if (does_file_exist(out_path)) {
     722                    strcpy(out_path, fname);
     723                }
     724            }
     725        }
     726    }
    733727}
    734728
     
    753747 * @return 0 for success, or the number of errors encountered.
    754748 */
    755 int 
    756 interactive_mode( struct s_bkpinfo *bkpinfo,
    757           struct mountlist_itself *mountlist,
    758           struct raidlist_itself *raidlist)
     749int
     750interactive_mode(struct s_bkpinfo *bkpinfo,
     751                 struct mountlist_itself *mountlist,
     752                struct raidlist_itself *raidlist)
    759753{
    760   int retval = 0;
    761   int res;
    762   int ptn_errs = 0;
    763   int fmt_errs = 0;
    764 
    765   bool done;
    766   bool restore_all;
     754    int retval = 0;
     755    int res;
     756    int ptn_errs = 0;
     757    int fmt_errs = 0;
     758
     759    bool done;
     760    bool restore_all;
    767761
    768762  /** needs malloc **********/
    769   char *tmp;
    770   char *fstab_fname;
    771   char *old_restpath;
    772  
    773   struct s_node *filelist;
    774 
    775   /* try to partition and format */
    776 
    777   log_msg(2,"interactive_mode --- starting (great, assertions OK)");
    778 
    779   malloc_string(tmp);
    780   malloc_string(fstab_fname);
    781   malloc_string(old_restpath);
    782   assert(bkpinfo!=NULL);
    783   assert(mountlist!=NULL);
    784   assert(raidlist!=NULL);
    785 
    786   log_msg(2,"interactive_mode --- assertions OK");
    787 
    788   if (g_text_mode)
    789     {
    790       if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?"))
    791         { fatal_error("Wise move."); }
    792     }
    793 
    794   iamhere("About to load config file");
    795   get_cfg_file_from_archive_or_bust(bkpinfo);
    796   read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    797   iamhere("Done loading config file; resizing ML");
     763    char *tmp;
     764    char *fstab_fname;
     765    char *old_restpath;
     766
     767    struct s_node *filelist;
     768
     769    /* try to partition and format */
     770
     771    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
     772
     773    malloc_string(tmp);
     774    malloc_string(fstab_fname);
     775    malloc_string(old_restpath);
     776    assert(bkpinfo != NULL);
     777    assert(mountlist != NULL);
     778    assert(raidlist != NULL);
     779
     780    log_msg(2, "interactive_mode --- assertions OK");
     781
     782    if (g_text_mode) {
     783        if (!ask_me_yes_or_no
     784            ("Interactive Mode + textonly = experimental! Proceed anyway?"))
     785        {
     786            fatal_error("Wise move.");
     787        }
     788    }
     789
     790    iamhere("About to load config file");
     791    get_cfg_file_from_archive_or_bust(bkpinfo);
     792    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     793    iamhere("Done loading config file; resizing ML");
    798794#ifdef __FreeBSD__
    799   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
     795    if (strstr
     796        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     797         "noresize"))
    800798#else
    801   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
     799    if (strstr
     800        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     801         "noresize"))
    802802#endif
    803     { log_msg(1,"Not resizing mountlist."); }
    804   else
    805     { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }
    806   for( done = FALSE; !done; )
    807     {
    808       iamhere("About to edit mountlist");
    809       if (g_text_mode)
    810         {
    811           save_mountlist_to_disk (mountlist, g_mountlist_fname);
    812       sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
    813           res = system(tmp);
    814           load_mountlist (mountlist, g_mountlist_fname);
    815         }
    816       else
    817         {
    818           res = edit_mountlist( g_mountlist_fname, mountlist, raidlist );
    819         }
    820       iamhere("Finished editing mountlist");
    821       if ( res )
    822     {
    823       paranoid_MR_finish( 1 );
    824     }
    825       log_msg(2, "Proceeding..." );
    826       save_mountlist_to_disk( mountlist, g_mountlist_fname );
    827       save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME );
    828       mvaddstr_and_log_it( 1, 30, "Restoring Interactively" );
    829       if ( bkpinfo->differential )
    830         {
    831           log_to_screen( "Because this is a differential backup, disk" );
    832       log_to_screen(" partitioning and formatting will not take place." );
    833           done=TRUE;
    834         }
    835       else
    836         {
    837           if ( ask_me_yes_or_no( "Do you want to erase and partition your hard drives?" ) )
    838             {
    839           if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) )
    840         { offer_to_abort_because_Compaq_Proliants_suck(); done=TRUE; }
    841           else
    842         {
    843           twenty_seconds_til_yikes();
    844           g_fprep = fopen("/tmp/prep.sh", "w");
    845           ptn_errs = partition_everything( mountlist );
    846           if (ptn_errs)
    847             {
    848               log_to_screen("Warning. Errors occurred during disk partitioning.");
    849             }
    850          
    851           fmt_errs = format_everything( mountlist, FALSE );
    852           if (!fmt_errs)
    853             {
    854               log_to_screen("Errors during disk partitioning were handled OK.");
    855               log_to_screen("Partitions were formatted OK despite those errors.");
    856               ptn_errs = 0;
    857             }
    858           if ( !ptn_errs && !fmt_errs)
    859             {
    860               done = TRUE;
    861             }
    862         }
    863               paranoid_fclose(g_fprep);
    864         }
    865           else
    866             {
    867               mvaddstr_and_log_it( g_currentY++, 0, "User opted not to partition the devices" );
    868               if ( ask_me_yes_or_no( "Do you want to format your hard drives?" ) )
    869                 {
    870                   fmt_errs = format_everything( mountlist, TRUE );
    871                   if (!fmt_errs)
    872             {
    873               done = TRUE;
    874             }
    875             }
    876               else
    877                 {
    878                   ptn_errs = fmt_errs = 0;
    879                   done = TRUE;
    880                 }
    881             }
    882           if (fmt_errs)
    883             {
    884               mvaddstr_and_log_it( g_currentY++,
    885                    0,
    886                    "Errors occurred. Please repartition and format drives manually.");
    887               done = FALSE;
    888             }
    889           if ( ptn_errs & !fmt_errs )
    890             {
    891               mvaddstr_and_log_it( g_currentY++,
    892                    0,
    893                    "Errors occurred during partitioning. Formatting, however, went OK.");
    894               done = TRUE;
    895             }
    896           if ( !done )
    897             {
    898               if ( !ask_me_yes_or_no( "Re-edit the mountlist?" ) )
    899         {
    900           retval++;
    901           goto end_of_func;
    902         }
    903             }
    904         }
    905     }
    906 
    907   /* mount */
    908   if ( mount_all_devices( mountlist, TRUE ) )
    909     {
    910       unmount_all_devices( mountlist );
    911       retval++;
    912       goto end_of_func;
    913     }
    914   /* restore */
    915   if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore all of your data?" ) ) )
    916     {
    917       log_msg(1, "Restoring all data");
    918       retval += restore_everything( bkpinfo, NULL );
    919     }
    920   else if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore _some_ of your data?") ) )
    921     {
    922       strcpy( old_restpath, bkpinfo->restore_path );
    923       for( done = FALSE; !done; )
    924         {
    925       unlink("/tmp/filelist.full");
    926           filelist = process_filelist_and_biggielist( bkpinfo );
    927       /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
    928          the former is a list of regular files; the latter, biggiefiles and imagedevs.
    929       */       
    930       if ( filelist )
    931             {
    932 gotos_suck:
    933               strcpy( tmp, old_restpath );
     803    {
     804        log_msg(1, "Not resizing mountlist.");
     805    } else {
     806        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
     807    }
     808    for (done = FALSE; !done;) {
     809        iamhere("About to edit mountlist");
     810        if (g_text_mode) {
     811            save_mountlist_to_disk(mountlist, g_mountlist_fname);
     812            sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
     813            res = system(tmp);
     814            load_mountlist(mountlist, g_mountlist_fname);
     815        } else {
     816            res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
     817        }
     818        iamhere("Finished editing mountlist");
     819        if (res) {
     820            paranoid_MR_finish(1);
     821        }
     822        log_msg(2, "Proceeding...");
     823        save_mountlist_to_disk(mountlist, g_mountlist_fname);
     824        save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
     825        mvaddstr_and_log_it(1, 30, "Restoring Interactively");
     826        if (bkpinfo->differential) {
     827            log_to_screen("Because this is a differential backup, disk");
     828            log_to_screen
     829                (" partitioning and formatting will not take place.");
     830            done = TRUE;
     831        } else {
     832            if (ask_me_yes_or_no
     833                ("Do you want to erase and partition your hard drives?")) {
     834                if (partition_table_contains_Compaq_diagnostic_partition
     835                    (mountlist)) {
     836                    offer_to_abort_because_Compaq_Proliants_suck();
     837                    done = TRUE;
     838                } else {
     839                    twenty_seconds_til_yikes();
     840                    g_fprep = fopen("/tmp/prep.sh", "w");
     841                    ptn_errs = partition_everything(mountlist);
     842                    if (ptn_errs) {
     843                        log_to_screen
     844                            ("Warning. Errors occurred during disk partitioning.");
     845                    }
     846
     847                    fmt_errs = format_everything(mountlist, FALSE);
     848                    if (!fmt_errs) {
     849                        log_to_screen
     850                            ("Errors during disk partitioning were handled OK.");
     851                        log_to_screen
     852                            ("Partitions were formatted OK despite those errors.");
     853                        ptn_errs = 0;
     854                    }
     855                    if (!ptn_errs && !fmt_errs) {
     856                        done = TRUE;
     857                    }
     858                }
     859                paranoid_fclose(g_fprep);
     860            } else {
     861                mvaddstr_and_log_it(g_currentY++, 0,
     862                                    "User opted not to partition the devices");
     863                if (ask_me_yes_or_no
     864                    ("Do you want to format your hard drives?")) {
     865                    fmt_errs = format_everything(mountlist, TRUE);
     866                    if (!fmt_errs) {
     867                        done = TRUE;
     868                    }
     869                } else {
     870                    ptn_errs = fmt_errs = 0;
     871                    done = TRUE;
     872                }
     873            }
     874            if (fmt_errs) {
     875                mvaddstr_and_log_it(g_currentY++,
     876                                    0,
     877                                    "Errors occurred. Please repartition and format drives manually.");
     878                done = FALSE;
     879            }
     880            if (ptn_errs & !fmt_errs) {
     881                mvaddstr_and_log_it(g_currentY++,
     882                                    0,
     883                                    "Errors occurred during partitioning. Formatting, however, went OK.");
     884                done = TRUE;
     885            }
     886            if (!done) {
     887                if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
     888                    retval++;
     889                    goto end_of_func;
     890                }
     891            }
     892        }
     893    }
     894
     895    /* mount */
     896    if (mount_all_devices(mountlist, TRUE)) {
     897        unmount_all_devices(mountlist);
     898        retval++;
     899        goto end_of_func;
     900    }
     901    /* restore */
     902    if ((restore_all =
     903         ask_me_yes_or_no("Do you want me to restore all of your data?")))
     904    {
     905        log_msg(1, "Restoring all data");
     906        retval += restore_everything(bkpinfo, NULL);
     907    } else
     908        if ((restore_all =
     909             ask_me_yes_or_no
     910             ("Do you want me to restore _some_ of your data?"))) {
     911        strcpy(old_restpath, bkpinfo->restore_path);
     912        for (done = FALSE; !done;) {
     913            unlink("/tmp/filelist.full");
     914            filelist = process_filelist_and_biggielist(bkpinfo);
     915            /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
     916               the former is a list of regular files; the latter, biggiefiles and imagedevs.
     917             */
     918            if (filelist) {
     919              gotos_suck:
     920                strcpy(tmp, old_restpath);
    934921// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
    935               if ( popup_and_get_string( "Restore path", "Restore files to where?", tmp, MAX_STR_LEN/4 ) )
    936                 {
    937           if ( !strcmp( tmp, "/" ) )
    938             {
    939               if ( !ask_me_yes_or_no( "Are you sure?" ) )
    940             {
    941               goto gotos_suck;
    942             }
    943               tmp[0] = '\0'; // so we restore to [blank]/file/name :)
    944             }
    945                   strcpy( bkpinfo->restore_path, tmp );
    946           log_msg(1, "Restoring subset");
    947                   retval += restore_everything( bkpinfo, filelist );
    948                   free_filelist( filelist );
    949                 }
    950               else
    951                 {
    952                   strcpy( bkpinfo->restore_path, old_restpath );
    953                   free_filelist( filelist );
    954                 }
    955               if ( !ask_me_yes_or_no( "Restore another subset of your backup?" ) )
    956         {
    957           done = TRUE;
    958         }
    959             }
    960           else
    961             {
    962               done = TRUE;
    963             }
    964     }
    965       strcpy( old_restpath, bkpinfo->restore_path );
    966     }
    967   else
    968     {
    969       mvaddstr_and_log_it( g_currentY++,
    970                0,
    971                "User opted not to restore any data.                                  ");
    972     }
    973   if ( retval )
    974     {
    975       mvaddstr_and_log_it( g_currentY++,
    976                0,
    977                "Errors occurred during the restore phase.            ");
    978     }
    979  
    980   if (ask_me_yes_or_no( "Initialize the boot loader?" ) )
    981     {
    982       run_boot_loader( TRUE );
    983     }
    984   else
    985     {
    986       mvaddstr_and_log_it( g_currentY++,
    987                0,
    988                "User opted not to initialize the boot loader.");
    989     }
     922                if (popup_and_get_string
     923                    ("Restore path", "Restore files to where?", tmp,
     924                     MAX_STR_LEN / 4)) {
     925                    if (!strcmp(tmp, "/")) {
     926                        if (!ask_me_yes_or_no("Are you sure?")) {
     927                            goto gotos_suck;
     928                        }
     929                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
     930                    }
     931                    strcpy(bkpinfo->restore_path, tmp);
     932                    log_msg(1, "Restoring subset");
     933                    retval += restore_everything(bkpinfo, filelist);
     934                    free_filelist(filelist);
     935                } else {
     936                    strcpy(bkpinfo->restore_path, old_restpath);
     937                    free_filelist(filelist);
     938                }
     939                if (!ask_me_yes_or_no
     940                    ("Restore another subset of your backup?")) {
     941                    done = TRUE;
     942                }
     943            } else {
     944                done = TRUE;
     945            }
     946        }
     947        strcpy(old_restpath, bkpinfo->restore_path);
     948    } else {
     949        mvaddstr_and_log_it(g_currentY++,
     950                            0,
     951                            "User opted not to restore any data.                                  ");
     952    }
     953    if (retval) {
     954        mvaddstr_and_log_it(g_currentY++,
     955                            0,
     956                            "Errors occurred during the restore phase.            ");
     957    }
     958
     959    if (ask_me_yes_or_no("Initialize the boot loader?")) {
     960        run_boot_loader(TRUE);
     961    } else {
     962        mvaddstr_and_log_it(g_currentY++,
     963                            0,
     964                            "User opted not to initialize the boot loader.");
     965    }
    990966
    991967//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    992   protect_against_braindead_sysadmins();
    993   //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    994   retval += unmount_all_devices( mountlist );
    995   /*  if (restore_some || restore_all || */
    996   if ( ask_me_yes_or_no( "Label your ext2 and ext3 partitions if necessary?" ) )
    997     {
    998       mvaddstr_and_log_it( g_currentY,
    999                0,
    1000                "Using e2label to label your ext2,3 partitions" );
    1001       if ( does_file_exist( "/tmp/fstab.new" ) )
    1002         {
    1003       strcpy( fstab_fname, "/tmp/fstab.new");
    1004     }
    1005       else
    1006         {
    1007       strcpy( fstab_fname, "/tmp/fstab");
    1008     }
    1009       sprintf( tmp,
    1010            "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname,
    1011            fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
    1012       res=system( tmp );
    1013       if ( res )
    1014     {
    1015       log_to_screen("label-partitions-as-necessary returned an error");
    1016       mvaddstr_and_log_it( g_currentY++, 74, "Failed.");
    1017     }
    1018       else
    1019     {
    1020       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    1021     }
    1022       retval += res;
    1023     }
    1024 
    1025   iamhere("About to leave interactive_mode()");
    1026   if ( retval )
    1027     {
    1028       mvaddstr_and_log_it(g_currentY++,
    1029               0,
    1030               "Warning - errors occurred during the restore phase.");
    1031     }
    1032 end_of_func:
    1033   paranoid_free(tmp);
    1034   paranoid_free(fstab_fname);
    1035   paranoid_free(old_restpath);
    1036   iamhere("Leaving interactive_mode()");
    1037   return( retval );
     968    protect_against_braindead_sysadmins();
     969    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
     970    retval += unmount_all_devices(mountlist);
     971    /*  if (restore_some || restore_all || */
     972    if (ask_me_yes_or_no
     973        ("Label your ext2 and ext3 partitions if necessary?")) {
     974        mvaddstr_and_log_it(g_currentY, 0,
     975                            "Using e2label to label your ext2,3 partitions");
     976        if (does_file_exist("/tmp/fstab.new")) {
     977            strcpy(fstab_fname, "/tmp/fstab.new");
     978        } else {
     979            strcpy(fstab_fname, "/tmp/fstab");
     980        }
     981        sprintf(tmp,
     982                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
     983                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
     984                MONDO_LOGFILE);
     985        res = system(tmp);
     986        if (res) {
     987            log_to_screen
     988                ("label-partitions-as-necessary returned an error");
     989            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     990        } else {
     991            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     992        }
     993        retval += res;
     994    }
     995
     996    iamhere("About to leave interactive_mode()");
     997    if (retval) {
     998        mvaddstr_and_log_it(g_currentY++,
     999                            0,
     1000                            "Warning - errors occurred during the restore phase.");
     1001    }
     1002  end_of_func:
     1003    paranoid_free(tmp);
     1004    paranoid_free(fstab_fname);
     1005    paranoid_free(old_restpath);
     1006    iamhere("Leaving interactive_mode()");
     1007    return (retval);
    10381008}
     1009
    10391010/**************************************************************************
    10401011 *END_INTERACTIVE_MODE                                                    *
     
    10521023 * @return 0 for success, or the number of errors encountered.
    10531024 */
    1054 int
    1055 iso_mode(struct s_bkpinfo *bkpinfo,
    1056      struct mountlist_itself *mountlist,
    1057      struct raidlist_itself *raidlist,
    1058      bool nuke_me_please)
     1025int
     1026iso_mode(struct s_bkpinfo *bkpinfo,
     1027         struct mountlist_itself *mountlist,
     1028         struct raidlist_itself *raidlist, bool nuke_me_please)
    10591029{
    1060   char c;
    1061   int retval=0;
    1062 
    1063   assert(bkpinfo!=NULL);
    1064   assert(mountlist!=NULL);
    1065   assert(raidlist!=NULL);
    1066   if (iso_fiddly_bits(bkpinfo, nuke_me_please))
    1067     { log_msg(1,"iso_mode --- returning w/ error"); return(1); }
    1068   else
    1069     {
    1070       c=which_restore_mode();
    1071       if (c=='I' || c=='N' || c=='C')
    1072     { interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); }
    1073       if (c=='I') { retval+=interactive_mode(bkpinfo,mountlist,raidlist); }
    1074       else if (c=='N') { retval+=nuke_mode(bkpinfo,mountlist,raidlist); }
    1075       else if (c=='C') { retval+=compare_mode(bkpinfo,mountlist,raidlist); }
    1076       else
    1077     { log_to_screen("OK, I shan't restore/compare any files."); }
    1078     }
    1079   if (is_this_device_mounted(MNT_CDROM)) { paranoid_system("umount "MNT_CDROM); }
     1030    char c;
     1031    int retval = 0;
     1032
     1033    assert(bkpinfo != NULL);
     1034    assert(mountlist != NULL);
     1035    assert(raidlist != NULL);
     1036    if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
     1037        log_msg(1, "iso_mode --- returning w/ error");
     1038        return (1);
     1039    } else {
     1040        c = which_restore_mode();
     1041        if (c == 'I' || c == 'N' || c == 'C') {
     1042            interactively_obtain_media_parameters_from_user(bkpinfo,
     1043                                                            FALSE);
     1044        }
     1045        if (c == 'I') {
     1046            retval += interactive_mode(bkpinfo, mountlist, raidlist);
     1047        } else if (c == 'N') {
     1048            retval += nuke_mode(bkpinfo, mountlist, raidlist);
     1049        } else if (c == 'C') {
     1050            retval += compare_mode(bkpinfo, mountlist, raidlist);
     1051        } else {
     1052            log_to_screen("OK, I shan't restore/compare any files.");
     1053        }
     1054    }
     1055    if (is_this_device_mounted(MNT_CDROM)) {
     1056        paranoid_system("umount " MNT_CDROM);
     1057    }
    10801058//  if (! already_mounted)
    10811059//    {
    1082       if (system("umount /tmp/isodir 2> /dev/null")) { log_to_screen("WARNING - unable to unmount device where the ISO files are stored."); }
     1060    if (system("umount /tmp/isodir 2> /dev/null")) {
     1061        log_to_screen
     1062            ("WARNING - unable to unmount device where the ISO files are stored.");
     1063    }
    10831064//    }
    1084   return( retval );
     1065    return (retval);
    10851066}
     1067
    10861068/**************************************************************************
    10871069 *END_ISO_MODE                                                            *
     
    11031085 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
    11041086 */
    1105 int 
    1106 nuke_mode( struct s_bkpinfo *bkpinfo,
    1107        struct mountlist_itself *mountlist,
    1108        struct raidlist_itself *raidlist )
     1087int
     1088nuke_mode(struct s_bkpinfo *bkpinfo,
     1089          struct mountlist_itself *mountlist,
     1090          struct raidlist_itself *raidlist)
    11091091{
    1110   int retval = 0;
    1111   int res = 0;
    1112   bool boot_loader_installed = FALSE;
     1092    int retval = 0;
     1093    int res = 0;
     1094    bool boot_loader_installed = FALSE;
    11131095  /** malloc **/
    1114   char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], tmpC[MAX_STR_LEN];
    1115 
    1116   assert(bkpinfo!=NULL);
    1117   assert(mountlist!=NULL);
    1118   assert(raidlist!=NULL);
    1119 
    1120   log_msg(2, "nuke_mode --- starting");
    1121 
    1122   get_cfg_file_from_archive_or_bust(bkpinfo);
    1123   load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
     1096    char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
     1097        tmpC[MAX_STR_LEN];
     1098
     1099    assert(bkpinfo != NULL);
     1100    assert(mountlist != NULL);
     1101    assert(raidlist != NULL);
     1102
     1103    log_msg(2, "nuke_mode --- starting");
     1104
     1105    get_cfg_file_from_archive_or_bust(bkpinfo);
     1106    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
    11241107#ifdef __FreeBSD__
    1125   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
     1108    if (strstr
     1109        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     1110         "noresize"))
    11261111#else
    1127   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
     1112    if (strstr
     1113        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     1114         "noresize"))
    11281115#endif
    1129     { log_msg(2, "Not resizing mountlist."); }
    1130   else
    1131     { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }
    1132   if (!evaluate_mountlist( mountlist, tmpA, tmpB, tmpC ))
    1133     {
    1134       sprintf(tmp, "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", tmpA, tmpB, tmpC);
    1135       if (ask_me_yes_or_no(tmp) )
    11361116    {
    1137       retval = interactive_mode( bkpinfo, mountlist, raidlist );
    1138       finish(retval);
    1139     }
    1140       else
     1117        log_msg(2, "Not resizing mountlist.");
     1118    } else {
     1119        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
     1120    }
     1121    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
     1122        sprintf(tmp,
     1123                "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
     1124                tmpA, tmpB, tmpC);
     1125        if (ask_me_yes_or_no(tmp)) {
     1126            retval = interactive_mode(bkpinfo, mountlist, raidlist);
     1127            finish(retval);
     1128        } else {
     1129            fatal_error("Nuke Mode aborted. ");
     1130        }
     1131    }
     1132    save_mountlist_to_disk(mountlist, g_mountlist_fname);
     1133    mvaddstr_and_log_it(1, 30, "Restoring Automatically");
     1134    if (bkpinfo->differential) {
     1135        log_to_screen("Because this is a differential backup, disk");
     1136        log_to_screen("partitioning and formatting will not take place.");
     1137        res = 0;
     1138    } else {
     1139        if (partition_table_contains_Compaq_diagnostic_partition
     1140            (mountlist)) {
     1141            offer_to_abort_because_Compaq_Proliants_suck();
     1142        } else {
     1143            twenty_seconds_til_yikes();
     1144            g_fprep = fopen("/tmp/prep.sh", "w");
     1145#ifdef __FreeBSD__
     1146            if (strstr
     1147                (call_program_and_get_last_line_of_output
     1148                 ("cat /tmp/cmdline"), "nopart"))
     1149#else
     1150            if (strstr
     1151                (call_program_and_get_last_line_of_output
     1152                 ("cat /proc/cmdline"), "nopart"))
     1153#endif
     1154            {
     1155                log_msg(2,
     1156                        "Not partitioning drives due to 'nopart' option.");
     1157                res = 0;
     1158            } else {
     1159                res = partition_everything(mountlist);
     1160                if (res) {
     1161                    log_to_screen
     1162                        ("Warning. Errors occurred during partitioning.");
     1163                    res = 0;
     1164                }
     1165            }
     1166            retval += res;
     1167            if (!res) {
     1168                log_to_screen("Preparing to format your disk(s)");
     1169                sleep(1);
     1170                system("sync");
     1171                log_to_screen("Please wait. This may take a few minutes.");
     1172                res += format_everything(mountlist, FALSE);
     1173            }
     1174            paranoid_fclose(g_fprep);
     1175        }
     1176    }
     1177    retval += res;
     1178    if (res) {
     1179        mvaddstr_and_log_it(g_currentY++,
     1180                            0,
     1181                            "Failed to partition and/or format your hard drives.");
     1182
     1183        if (ask_me_yes_or_no("Try in interactive mode instead?")) {
     1184            retval = interactive_mode(bkpinfo, mountlist, raidlist);
     1185            goto after_the_nuke;
     1186        } else
     1187            if (!ask_me_yes_or_no
     1188                ("Would you like to try to proceed anyway?")) {
     1189            return (retval);
     1190        }
     1191    }
     1192    retval = mount_all_devices(mountlist, TRUE);
     1193    if (retval) {
     1194        unmount_all_devices(mountlist);
     1195        log_to_screen
     1196            ("Unable to mount all partitions. Sorry, I cannot proceed.");
     1197        return (retval);
     1198    }
     1199    iamhere("Restoring everything");
     1200    retval += restore_everything(bkpinfo, NULL);
     1201    if (!run_boot_loader(FALSE)) {
     1202        log_msg(1,
     1203                "Great! Boot loader was installed. No need for msg at end.");
     1204        boot_loader_installed = TRUE;
     1205    }
     1206    protect_against_braindead_sysadmins();
     1207//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
     1208    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
     1209    retval += unmount_all_devices(mountlist);
     1210    mvaddstr_and_log_it(g_currentY,
     1211                        0,
     1212                        "Using e2label to label your ext2,3 partitions");
     1213
     1214    sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
     1215            g_mountlist_fname);
     1216    res = run_program_and_log_output(tmp, TRUE);
     1217    if (res) {
     1218        log_to_screen("label-partitions-as-necessary returned an error");
     1219        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1220    } else {
     1221        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1222    }
     1223    retval += res;
     1224
     1225  after_the_nuke:
     1226    if (retval) {
     1227        log_to_screen("Errors occurred during the nuke phase.");
     1228    } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
    11411229    {
    1142       fatal_error( "Nuke Mode aborted. ");
    1143     }
    1144     }
    1145   save_mountlist_to_disk( mountlist, g_mountlist_fname );
    1146   mvaddstr_and_log_it( 1, 30, "Restoring Automatically" );
    1147   if ( bkpinfo->differential )
    1148     {
    1149       log_to_screen( "Because this is a differential backup, disk" );
    1150       log_to_screen( "partitioning and formatting will not take place." );
    1151       res = 0;
    1152     }
    1153   else
    1154     {     
    1155       if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) )
    1156     {
    1157       offer_to_abort_because_Compaq_Proliants_suck();
    1158     }
    1159       else
    1160     {
    1161       twenty_seconds_til_yikes();
    1162       g_fprep = fopen("/tmp/prep.sh", "w");
    1163 #ifdef __FreeBSD__
    1164       if (strstr (call_program_and_get_last_line_of_output ("cat /tmp/cmdline"), "nopart"))
     1230        log_to_screen
     1231            ("PC was restored successfully. Thank you for using Mondo Rescue.");
     1232        log_to_screen
     1233            ("Please visit http://www.mondorescue.org and thank the dev team.");
     1234    } else {
     1235#ifdef FREELOADER
     1236        success_message();
    11651237#else
    1166       if (strstr (call_program_and_get_last_line_of_output ("cat /proc/cmdline"), "nopart"))
     1238        log_to_screen("PC was restored successfully!");
    11671239#endif
    1168           {
    1169           log_msg (2, "Not partitioning drives due to 'nopart' option.");
    1170           res = 0;
    1171           }
    1172       else
    1173           {
    1174           res = partition_everything( mountlist );
    1175           if (res)
    1176             {
    1177               log_to_screen("Warning. Errors occurred during partitioning.");
    1178               res = 0;
    1179             }
    1180           }
    1181       retval += res;
    1182       if ( !res )
    1183         {
    1184           log_to_screen("Preparing to format your disk(s)");
    1185           sleep(1);
    1186           system("sync");
    1187           log_to_screen("Please wait. This may take a few minutes.");
    1188           res += format_everything( mountlist, FALSE );
    1189         }
    1190       paranoid_fclose(g_fprep);
    1191     }
    1192     }
    1193   retval += res;
    1194   if ( res )
    1195     {
    1196       mvaddstr_and_log_it( g_currentY++,
    1197                0,
    1198                "Failed to partition and/or format your hard drives.");
    1199      
    1200       if ( ask_me_yes_or_no( "Try in interactive mode instead?" ) )
    1201     {
    1202       retval = interactive_mode( bkpinfo, mountlist, raidlist );
    1203       goto after_the_nuke;
    1204     }
    1205       else if ( !ask_me_yes_or_no( "Would you like to try to proceed anyway?" ) )
    1206         {
    1207           return( retval );
    1208     }
    1209     }
    1210   retval = mount_all_devices( mountlist, TRUE );
    1211   if ( retval )
    1212     {
    1213       unmount_all_devices( mountlist );
    1214       log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed.");
    1215       return( retval );
    1216     }
    1217   iamhere("Restoring everything");
    1218   retval += restore_everything( bkpinfo, NULL );
    1219   if (!run_boot_loader( FALSE ))
    1220     {
    1221       log_msg(1, "Great! Boot loader was installed. No need for msg at end.");
    1222       boot_loader_installed = TRUE;
    1223     }
    1224   protect_against_braindead_sysadmins();
    1225 //  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    1226   //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    1227   retval += unmount_all_devices( mountlist );
    1228   mvaddstr_and_log_it( g_currentY,
    1229                0,
    1230                "Using e2label to label your ext2,3 partitions");
    1231 
    1232   sprintf( tmp, "label-partitions-as-necessary %s < /tmp/fstab", g_mountlist_fname );
    1233   res = run_program_and_log_output( tmp, TRUE );
    1234   if ( res )
    1235     {
    1236       log_to_screen( "label-partitions-as-necessary returned an error" );
    1237       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    1238     }
    1239   else
    1240     {
    1241       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    1242     }
    1243   retval += res;
    1244 
    1245 after_the_nuke:
    1246   if (retval)
    1247     {
    1248       log_to_screen("Errors occurred during the nuke phase.");
    1249     }
    1250   else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing
    1251     {
    1252       log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
    1253       log_to_screen("Please visit http://www.mondorescue.org and thank the dev team.");
    1254     }
    1255   else
    1256     {
    1257 #ifdef FREELOADER
    1258       success_message();
    1259 #else
    1260       log_to_screen("PC was restored successfully!");
    1261 #endif
    1262     }
    1263   g_I_have_just_nuked = TRUE;
     1240    }
     1241    g_I_have_just_nuked = TRUE;
    12641242/*
    12651243  if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
     
    12691247    }
    12701248*/
    1271   return( retval );
     1249    return (retval);
    12721250}
    12731251
     
    12841262 * @return 0 for success, or the number of errors encountered.
    12851263 */
    1286 int
    1287 restore_to_live_filesystem( struct s_bkpinfo *bkpinfo )
     1264int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
    12881265{
    1289   int retval = 0;
     1266    int retval = 0;
    12901267
    12911268  /** malloc **/
    1292   char *old_restpath;
    1293 
    1294   struct mountlist_itself *mountlist;
     1269    char *old_restpath;
     1270
     1271    struct mountlist_itself *mountlist;
    12951272//  static
    1296   struct raidlist_itself *raidlist;
    1297   struct s_node *filelist;
    1298 
    1299   log_msg(1, "restore_to_live_filesystem() - starting");
    1300   assert(bkpinfo!=NULL);
    1301   malloc_string(old_restpath);
    1302   mountlist = malloc(sizeof(struct mountlist_itself));
    1303   raidlist = malloc(sizeof(struct raidlist_itself));
    1304   if (!mountlist || !raidlist) { fatal_error("Cannot malloc() mountlist and/or raidlist"); }
    1305 
    1306   strcpy(bkpinfo->restore_path, "/");
    1307   if ( !g_restoring_live_from_cd)
    1308     {
    1309       popup_and_OK("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
    1310       sleep( 1 );
    1311     }
    1312   interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    1313   log_msg(2,  "bkpinfo->media_device = %s", bkpinfo->media_device );
    1314   if ( !bkpinfo->media_device[0] )
    1315     {
    1316       log_msg(2, "Warning - failed to find media dev");
    1317     }
    1318 
    1319 
    1320   log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
    1321 
    1322   open_evalcall_form("Thinking...");
    1323 
    1324   get_cfg_file_from_archive_or_bust ( bkpinfo );
    1325   read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    1326   load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
    1327  
    1328   close_evalcall_form();
    1329   retval = load_mountlist(mountlist, g_mountlist_fname );
    1330   load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME );
    1331   filelist = process_filelist_and_biggielist( bkpinfo );
    1332   if ( filelist )
    1333     {
    1334       save_filelist(filelist, "/tmp/selected-files.txt");
    1335       strcpy( old_restpath, bkpinfo->restore_path );
    1336       if ( popup_and_get_string( "Restore path",
    1337                  "Restore files to where? )",
    1338                  bkpinfo->restore_path, MAX_STR_LEN/4 ) )
    1339         {
    1340       iamhere("Restoring everything");
    1341           retval += restore_everything( bkpinfo, filelist );
    1342           free_filelist( filelist );
    1343           strcpy(bkpinfo->restore_path, old_restpath);
    1344         }
    1345       else
    1346         {
    1347           free_filelist(filelist);
    1348         }
    1349       strcpy(bkpinfo->restore_path, old_restpath);
    1350     }
    1351   if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) )
    1352     {
    1353       log_msg(2, "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
    1354     }
    1355   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    1356   if (!bkpinfo->please_dont_eject) { eject_device( bkpinfo->media_device ); }
    1357   paranoid_free(old_restpath);
    1358   free(mountlist);
    1359   free(raidlist);
    1360   return( retval );
     1273    struct raidlist_itself *raidlist;
     1274    struct s_node *filelist;
     1275
     1276    log_msg(1, "restore_to_live_filesystem() - starting");
     1277    assert(bkpinfo != NULL);
     1278    malloc_string(old_restpath);
     1279    mountlist = malloc(sizeof(struct mountlist_itself));
     1280    raidlist = malloc(sizeof(struct raidlist_itself));
     1281    if (!mountlist || !raidlist) {
     1282        fatal_error("Cannot malloc() mountlist and/or raidlist");
     1283    }
     1284
     1285    strcpy(bkpinfo->restore_path, "/");
     1286    if (!g_restoring_live_from_cd) {
     1287        popup_and_OK
     1288            ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
     1289        sleep(1);
     1290    }
     1291    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     1292    log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
     1293    if (!bkpinfo->media_device[0]) {
     1294        log_msg(2, "Warning - failed to find media dev");
     1295    }
     1296
     1297
     1298    log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
     1299
     1300    open_evalcall_form("Thinking...");
     1301
     1302    get_cfg_file_from_archive_or_bust(bkpinfo);
     1303    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     1304    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo
     1305
     1306    close_evalcall_form();
     1307    retval = load_mountlist(mountlist, g_mountlist_fname);
     1308    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     1309    filelist = process_filelist_and_biggielist(bkpinfo);
     1310    if (filelist) {
     1311        save_filelist(filelist, "/tmp/selected-files.txt");
     1312        strcpy(old_restpath, bkpinfo->restore_path);
     1313        if (popup_and_get_string("Restore path",
     1314                                 "Restore files to where? )",
     1315                                 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
     1316            iamhere("Restoring everything");
     1317            retval += restore_everything(bkpinfo, filelist);
     1318            free_filelist(filelist);
     1319            strcpy(bkpinfo->restore_path, old_restpath);
     1320        } else {
     1321            free_filelist(filelist);
     1322        }
     1323        strcpy(bkpinfo->restore_path, old_restpath);
     1324    }
     1325    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1326        log_msg(2,
     1327                "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
     1328    }
     1329    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1330    if (!bkpinfo->please_dont_eject) {
     1331        eject_device(bkpinfo->media_device);
     1332    }
     1333    paranoid_free(old_restpath);
     1334    free(mountlist);
     1335    free(raidlist);
     1336    return (retval);
    13611337}
    13621338
     
    13861362int
    13871363restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
    1388                  long bigfileno,
    1389                  struct s_node*filelist, char*pathname_of_last_file_restored)
     1364                             long bigfileno,
     1365                             struct s_node *filelist,
     1366                             char *pathname_of_last_file_restored)
    13901367{
    1391   FILE *fin;
    1392   FILE *fout;
    1393   FILE *fbzip2;
    1394  
     1368    FILE *fin;
     1369    FILE *fout;
     1370    FILE *fbzip2;
     1371
    13951372  /** malloc ***/
    1396   char *checksum, *outfile_fname, *tmp, *bzip2_command, *partimagehack_command, *suffix, *sz_devfile;
    1397   char *bigblk;
    1398   char *p;
    1399   int retval = 0;
    1400   int finished = FALSE;
    1401   long sliceno;
    1402   long siz;
    1403   char partimagehack_fifo[MAX_STR_LEN];
    1404   char *file_to_openout = NULL;
    1405   struct s_filename_and_lstat_info biggiestruct;
    1406   struct utimbuf the_utime_buf, *ubuf;
    1407   bool use_partimage_hack=FALSE;
    1408   pid_t pid;
    1409   int res=0;
    1410   int old_loglevel;
    1411   char sz_msg[MAX_STR_LEN];
    1412   struct s_node *node;
    1413 
    1414   old_loglevel = g_loglevel;
    1415   ubuf = &the_utime_buf;
    1416   assert(bkpinfo!=NULL);
    1417 
    1418   malloc_string(checksum);
    1419   malloc_string(outfile_fname);
    1420   malloc_string(tmp);
    1421   malloc_string(bzip2_command);
    1422   malloc_string(partimagehack_command);
    1423   malloc_string(suffix);
    1424   malloc_string(sz_devfile);
    1425 
    1426   pathname_of_last_file_restored[0] = '\0';
    1427   if( !(bigblk = malloc( TAPE_BLOCK_SIZE ) ) )
    1428     {
    1429       fatal_error("Cannot malloc bigblk");
    1430     }
    1431 
    1432   if ( !(fin = fopen( slice_fname( bigfileno, 0, ARCHIVES_PATH, ""), "r" ) ) )
    1433     {
    1434       log_to_screen( "Cannot even open bigfile's info file" );
    1435       return( 1 );
    1436     }
    1437 
    1438   memset((void*)&biggiestruct, 0, sizeof(biggiestruct));
    1439   if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct))
    1440     {
    1441       log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", bigfileno+1);
    1442     }
    1443   paranoid_fclose(fin);
    1444 
    1445   strcpy(checksum, biggiestruct.checksum);
    1446 
    1447   if ( !checksum[0])
    1448     {
    1449       sprintf(tmp,"Warning - bigfile %ld does not have a checksum",bigfileno+1);
    1450       log_msg(3, tmp);
    1451       p = checksum;
    1452     }
    1453 
    1454   if (!strncmp ( biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
    1455     { strcpy( outfile_fname, biggiestruct.filename); }
    1456   else
    1457     { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); }
    1458 
    1459   /* skip file if we have a selective restore subset & it doesn't match */
    1460   if (filelist != NULL)
    1461     {
    1462       node = find_string_at_node(filelist, biggiestruct.filename);
    1463       if (!node)
    1464         {
    1465           log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    1466           pathname_of_last_file_restored[0] = '\0';
    1467       return (0);
    1468         }
    1469       else if (!(node->selected))
    1470         {
    1471       log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    1472           pathname_of_last_file_restored[0] = '\0';
    1473           return( 0 );
    1474         }
    1475     }
    1476   /* otherwise, continue */
    1477  
    1478   log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    1479   if (biggiestruct.use_partimagehack)
    1480     {
    1481       if (strncmp ( biggiestruct.filename, "/dev/", 5))
    1482         {
    1483       log_msg(1, "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
    1484       log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    1485       biggiestruct.use_partimagehack = FALSE;
    1486     }
    1487     }
    1488 
    1489   if (biggiestruct.use_partimagehack) // if it's an NTFS device
     1373    char *checksum, *outfile_fname, *tmp, *bzip2_command,
     1374        *partimagehack_command, *suffix, *sz_devfile;
     1375    char *bigblk;
     1376    char *p;
     1377    int retval = 0;
     1378    int finished = FALSE;
     1379    long sliceno;
     1380    long siz;
     1381    char partimagehack_fifo[MAX_STR_LEN];
     1382    char *file_to_openout = NULL;
     1383    struct s_filename_and_lstat_info biggiestruct;
     1384    struct utimbuf the_utime_buf, *ubuf;
     1385    bool use_partimage_hack = FALSE;
     1386    pid_t pid;
     1387    int res = 0;
     1388    int old_loglevel;
     1389    char sz_msg[MAX_STR_LEN];
     1390    struct s_node *node;
     1391
     1392    old_loglevel = g_loglevel;
     1393    ubuf = &the_utime_buf;
     1394    assert(bkpinfo != NULL);
     1395
     1396    malloc_string(checksum);
     1397    malloc_string(outfile_fname);
     1398    malloc_string(tmp);
     1399    malloc_string(bzip2_command);
     1400    malloc_string(partimagehack_command);
     1401    malloc_string(suffix);
     1402    malloc_string(sz_devfile);
     1403
     1404    pathname_of_last_file_restored[0] = '\0';
     1405    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
     1406        fatal_error("Cannot malloc bigblk");
     1407    }
     1408
     1409    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
     1410        log_to_screen("Cannot even open bigfile's info file");
     1411        return (1);
     1412    }
     1413
     1414    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
     1415    if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
     1416        sizeof(biggiestruct)) {
     1417        log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
     1418                bigfileno + 1);
     1419    }
     1420    paranoid_fclose(fin);
     1421
     1422    strcpy(checksum, biggiestruct.checksum);
     1423
     1424    if (!checksum[0]) {
     1425        sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
     1426                bigfileno + 1);
     1427        log_msg(3, tmp);
     1428        p = checksum;
     1429    }
     1430
     1431    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
     1432    {
     1433        strcpy(outfile_fname, biggiestruct.filename);
     1434    } else {
     1435        sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1436                biggiestruct.filename);
     1437    }
     1438
     1439    /* skip file if we have a selective restore subset & it doesn't match */
     1440    if (filelist != NULL) {
     1441        node = find_string_at_node(filelist, biggiestruct.filename);
     1442        if (!node) {
     1443            log_msg(0, "Skipping %s (name isn't in filelist)",
     1444                    biggiestruct.filename);
     1445            pathname_of_last_file_restored[0] = '\0';
     1446            return (0);
     1447        } else if (!(node->selected)) {
     1448            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
     1449                    biggiestruct.filename);
     1450            pathname_of_last_file_restored[0] = '\0';
     1451            return (0);
     1452        }
     1453    }
     1454    /* otherwise, continue */
     1455
     1456    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
     1457    if (biggiestruct.use_partimagehack) {
     1458        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
     1459            log_msg(1,
     1460                    "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
     1461            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
     1462            biggiestruct.use_partimagehack = FALSE;
     1463        }
     1464    }
     1465
     1466    if (biggiestruct.use_partimagehack) // if it's an NTFS device
    14901467//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    1491     {
    1492       g_loglevel = 4;
    1493       use_partimage_hack = TRUE;
    1494       log_msg(2, "Calling partimagehack in background because %s is an NTFS /dev entry", outfile_fname);
    1495       sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    1496       mkfifo(sz_devfile, 0x770);
    1497       strcpy(partimagehack_fifo, sz_devfile);
    1498       file_to_openout = partimagehack_fifo;
    1499       switch(pid=fork())
    1500                 {
    1501                   case -1: fatal_error("Fork failure");
    1502               case 0:
    1503             log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", biggiestruct.filename, partimagehack_fifo);
    1504             res=feed_outfrom_partimage(biggiestruct.filename, partimagehack_fifo);
    1505 //          log_msg(3, "CHILD - fip - exiting");
    1506             exit(res);
    1507             break;
    1508                   default:
    1509             log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    1510                 }
    1511     }
    1512   else
    1513     {
    1514       use_partimage_hack = FALSE;
    1515       partimagehack_fifo[0] = '\0';
    1516       file_to_openout = outfile_fname;
    1517       if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way
    1518        { make_hole_for_file( outfile_fname ); }
    1519     }
    1520 
    1521   sprintf( tmp, "Reassembling big file %ld (%s)", bigfileno+1, outfile_fname );
    1522   log_msg(2, tmp );
    1523 
    1524   /*
    1525     last slice is zero-length and uncompressed; when we find it, we stop.
    1526     We DON'T wait until there are no more slices; if we did that,
    1527     We might stop at end of CD, not at last slice (which is 0-len and uncompd)
    1528   */
    1529 
    1530   strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN-1);
    1531   pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';
    1532 
    1533   log_msg(3, "file_to_openout = %s", file_to_openout);
    1534   if ( !(fout = fopen( file_to_openout, "w" ) ) )
    1535     {
    1536       log_to_screen( "Cannot openout outfile_fname - hard disk full?");
    1537       return(1);
    1538     }
    1539   log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
    1540 
    1541   for( sliceno = 1, finished = FALSE; !finished; )
    1542     {
    1543       if ( !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"lzo")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"bz2")))
    15441468    {
    1545       log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    1546       g_current_media_number++;
    1547       sprintf( tmp, "Asking for %s #%d so that I may read slice #%ld\n",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number,sliceno);
    1548       log_msg(2,  tmp );
    1549       sprintf( tmp, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    1550       log_to_screen( tmp );
    1551       insist_on_this_cd_number( bkpinfo, g_current_media_number );
    1552       log_to_screen( "Continuing to restore.");
    1553     }
    1554       else
    1555     {
    1556       strcpy(tmp, slice_fname(bigfileno,sliceno,ARCHIVES_PATH,""));
    1557       if (does_file_exist(tmp) && length_of_file(tmp) == 0)
    1558         {
    1559           log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno );
    1560           finished = TRUE;
    1561               continue;
    1562         }
    1563       else
    1564         {
    1565           if ( does_file_exist(slice_fname(bigfileno, sliceno,ARCHIVES_PATH, "lzo" ) ) )
     1469        g_loglevel = 4;
     1470        use_partimage_hack = TRUE;
     1471        log_msg(2,
     1472                "Calling partimagehack in background because %s is an NTFS /dev entry",
     1473                outfile_fname);
     1474        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1475                (int) (random() % 32768));
     1476        mkfifo(sz_devfile, 0x770);
     1477        strcpy(partimagehack_fifo, sz_devfile);
     1478        file_to_openout = partimagehack_fifo;
     1479        switch (pid = fork()) {
     1480        case -1:
     1481            fatal_error("Fork failure");
     1482        case 0:
     1483            log_msg(3,
     1484                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
     1485                    biggiestruct.filename, partimagehack_fifo);
     1486            res =
     1487                feed_outfrom_partimage(biggiestruct.filename,
     1488                                       partimagehack_fifo);
     1489//          log_msg(3, "CHILD - fip - exiting");
     1490            exit(res);
     1491            break;
     1492        default:
     1493            log_msg(3,
     1494                    "feed_into_partimage() called in background --- pid=%ld",
     1495                    (long int) (pid));
     1496        }
     1497    } else {
     1498        use_partimage_hack = FALSE;
     1499        partimagehack_fifo[0] = '\0';
     1500        file_to_openout = outfile_fname;
     1501        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
    15661502        {
    1567           strcpy( bzip2_command, "lzop" );
    1568           strcpy( suffix, "lzo");
    1569         }
    1570           else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "bz2" ) ) )
    1571         {
    1572           strcpy( bzip2_command, "bzip2" );
    1573           strcpy( suffix, "bz2");
    1574         }
    1575           else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "" ) ) )
    1576         {
    1577           strcpy( bzip2_command, "" );
    1578           strcpy( suffix, "");
    1579         }
    1580           else
    1581         {
    1582           log_to_screen( "OK, that's pretty fsck0red...");
    1583           return( 1 );
    1584         }
    1585         }
    1586           if ( bzip2_command[0] != '\0' )
    1587             {
    1588           sprintf( bzip2_command + strlen( bzip2_command ),
    1589                " -dc %s 2>> %s",
    1590                slice_fname( bigfileno, sliceno, ARCHIVES_PATH, suffix),
    1591                MONDO_LOGFILE);
    1592         }
    1593           else
    1594             {
    1595           sprintf( bzip2_command, "cat %s 2>> %s",
    1596                slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix ),
    1597                MONDO_LOGFILE );
    1598         }
    1599       sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number, bigfileno + 1, sliceno );
    1600           log_msg(2, tmp );
    1601 
    1602           if (!g_text_mode)
    1603             {
    1604               newtDrawRootText( 0, g_noof_rows - 2, tmp );
    1605               newtRefresh();
    1606               strip_spaces( tmp );
    1607               update_progress_form( tmp );
    1608             }
    1609       if ( !(fbzip2 = popen( bzip2_command, "r" ) ) )
    1610         {
    1611           fatal_error( "Can't run popen command");
    1612         }
    1613       while( !feof( fbzip2 ) )
    1614         {
    1615           siz = fread( bigblk, 1, TAPE_BLOCK_SIZE, fbzip2 );
    1616           if (siz > 0)
    1617         {
    1618                   sprintf(sz_msg, "Read %ld from fbzip2", siz);
    1619           siz = fwrite( bigblk, 1, siz, fout);
    1620                   sprintf(sz_msg + strlen(sz_msg), "; written %ld to fout", siz);
    1621 //        log_msg(2. sz_msg);
    1622         }
    1623         }
    1624       paranoid_pclose(fbzip2);
    1625 
    1626 
    1627           sliceno++;
    1628           g_current_progress++;
    1629         }
    1630     }
     1503            make_hole_for_file(outfile_fname);
     1504        }
     1505    }
     1506
     1507    sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
     1508            outfile_fname);
     1509    log_msg(2, tmp);
     1510
     1511    /*
     1512       last slice is zero-length and uncompressed; when we find it, we stop.
     1513       We DON'T wait until there are no more slices; if we did that,
     1514       We might stop at end of CD, not at last slice (which is 0-len and uncompd)
     1515     */
     1516
     1517    strncpy(pathname_of_last_file_restored, biggiestruct.filename,
     1518            MAX_STR_LEN - 1);
     1519    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1520
     1521    log_msg(3, "file_to_openout = %s", file_to_openout);
     1522    if (!(fout = fopen(file_to_openout, "w"))) {
     1523        log_to_screen("Cannot openout outfile_fname - hard disk full?");
     1524        return (1);
     1525    }
     1526    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
     1527
     1528    for (sliceno = 1, finished = FALSE; !finished;) {
     1529        if (!does_file_exist
     1530            (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
     1531            &&
     1532            !does_file_exist(slice_fname
     1533                             (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
     1534            &&
     1535            !does_file_exist(slice_fname
     1536                             (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1537            log_msg(3,
     1538                    "Cannot find a data slice or terminator slice on CD %d",
     1539                    g_current_media_number);
     1540            g_current_media_number++;
     1541            sprintf(tmp,
     1542                    "Asking for %s #%d so that I may read slice #%ld\n",
     1543                    media_descriptor_string(bkpinfo->backup_media_type),
     1544                    g_current_media_number, sliceno);
     1545            log_msg(2, tmp);
     1546            sprintf(tmp, "Restoring from %s #%d",
     1547                    media_descriptor_string(bkpinfo->backup_media_type),
     1548                    g_current_media_number);
     1549            log_to_screen(tmp);
     1550            insist_on_this_cd_number(bkpinfo, g_current_media_number);
     1551            log_to_screen("Continuing to restore.");
     1552        } else {
     1553            strcpy(tmp,
     1554                   slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
     1555            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
     1556                log_msg(2,
     1557                        "End of bigfile # %ld (slice %ld is the terminator)",
     1558                        bigfileno + 1, sliceno);
     1559                finished = TRUE;
     1560                continue;
     1561            } else {
     1562                if (does_file_exist
     1563                    (slice_fname
     1564                     (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1565                    strcpy(bzip2_command, "lzop");
     1566                    strcpy(suffix, "lzo");
     1567                } else
     1568                    if (does_file_exist
     1569                        (slice_fname
     1570                         (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1571                    strcpy(bzip2_command, "bzip2");
     1572                    strcpy(suffix, "bz2");
     1573                } else
     1574                    if (does_file_exist
     1575                        (slice_fname
     1576                         (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1577                    strcpy(bzip2_command, "");
     1578                    strcpy(suffix, "");
     1579                } else {
     1580                    log_to_screen("OK, that's pretty fsck0red...");
     1581                    return (1);
     1582                }
     1583            }
     1584            if (bzip2_command[0] != '\0') {
     1585                sprintf(bzip2_command + strlen(bzip2_command),
     1586                        " -dc %s 2>> %s",
     1587                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
     1588                                    suffix), MONDO_LOGFILE);
     1589            } else {
     1590                sprintf(bzip2_command, "cat %s 2>> %s",
     1591                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
     1592                                    suffix), MONDO_LOGFILE);
     1593            }
     1594            sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
     1595                    media_descriptor_string(bkpinfo->backup_media_type),
     1596                    g_current_media_number, bigfileno + 1, sliceno);
     1597            log_msg(2, tmp);
     1598
     1599            if (!g_text_mode) {
     1600                newtDrawRootText(0, g_noof_rows - 2, tmp);
     1601                newtRefresh();
     1602                strip_spaces(tmp);
     1603                update_progress_form(tmp);
     1604            }
     1605            if (!(fbzip2 = popen(bzip2_command, "r"))) {
     1606                fatal_error("Can't run popen command");
     1607            }
     1608            while (!feof(fbzip2)) {
     1609                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
     1610                if (siz > 0) {
     1611                    sprintf(sz_msg, "Read %ld from fbzip2", siz);
     1612                    siz = fwrite(bigblk, 1, siz, fout);
     1613                    sprintf(sz_msg + strlen(sz_msg),
     1614                            "; written %ld to fout", siz);
     1615//        log_msg(2. sz_msg);
     1616                }
     1617            }
     1618            paranoid_pclose(fbzip2);
     1619
     1620
     1621            sliceno++;
     1622            g_current_progress++;
     1623        }
     1624    }
    16311625/*
    16321626  memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
     
    16361630  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    16371631*/
    1638   paranoid_fclose( fout );
    1639   g_loglevel = old_loglevel;
    1640 
    1641   if (use_partimage_hack)
    1642     {
    1643       log_msg(3, "Waiting for partimage to finish");
    1644       sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
    1645       while(system(tmp) == 0)
    1646         { sleep(1); }
    1647       log_it("OK, partimage has really finished");
    1648     }
    1649 
    1650   if (strcmp(outfile_fname, "/dev/null"))
    1651     {
    1652       chown( outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid );
    1653       chmod( outfile_fname, biggiestruct.properties.st_mode );
    1654       ubuf->actime = biggiestruct.properties.st_atime;
    1655       ubuf->modtime= biggiestruct.properties.st_mtime;
    1656       utime( outfile_fname, ubuf );
    1657     }
    1658   paranoid_free( bigblk );
    1659   paranoid_free(checksum);
    1660   paranoid_free(outfile_fname);
    1661   paranoid_free(tmp);
    1662   paranoid_free(bzip2_command);
    1663   paranoid_free(partimagehack_command);
    1664   paranoid_free(suffix);
    1665   paranoid_free(sz_devfile);
    1666 
    1667   return( retval );
     1632    paranoid_fclose(fout);
     1633    g_loglevel = old_loglevel;
     1634
     1635    if (use_partimage_hack) {
     1636        log_msg(3, "Waiting for partimage to finish");
     1637        sprintf(tmp,
     1638                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1639        while (system(tmp) == 0) {
     1640            sleep(1);
     1641        }
     1642        log_it("OK, partimage has really finished");
     1643    }
     1644
     1645    if (strcmp(outfile_fname, "/dev/null")) {
     1646        chown(outfile_fname, biggiestruct.properties.st_uid,
     1647              biggiestruct.properties.st_gid);
     1648        chmod(outfile_fname, biggiestruct.properties.st_mode);
     1649        ubuf->actime = biggiestruct.properties.st_atime;
     1650        ubuf->modtime = biggiestruct.properties.st_mtime;
     1651        utime(outfile_fname, ubuf);
     1652    }
     1653    paranoid_free(bigblk);
     1654    paranoid_free(checksum);
     1655    paranoid_free(outfile_fname);
     1656    paranoid_free(tmp);
     1657    paranoid_free(bzip2_command);
     1658    paranoid_free(partimagehack_command);
     1659    paranoid_free(suffix);
     1660    paranoid_free(sz_devfile);
     1661
     1662    return (retval);
    16681663}
    16691664
     
    16881683 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
    16891684 */
    1690 int
    1691 restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
    1692                  char *orig_bf_fname,
    1693                  long biggiefile_number,
    1694                  char *orig_checksum, //UNUSED
    1695                  long long biggiefile_size, //UNUSED
    1696                  struct s_node *filelist, int use_partimagehack,
    1697                  char*pathname_of_last_file_restored)
     1685int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
     1686                                     long long biggiefile_size, //UNUSED
     1687                                     struct s_node *filelist,
     1688                                     int use_partimagehack,
     1689                                     char *pathname_of_last_file_restored)
    16981690{
    1699   FILE *pout;
    1700   FILE *fin;
     1691    FILE *pout;
     1692    FILE *fin;
    17011693
    17021694  /** mallocs ********/
    1703   char *tmp;
    1704   char *command;
    1705   char *outfile_fname;
    1706   char *partimagehack_command;
    1707   char *sz_devfile;
    1708   char *partimagehack_fifo;
    1709   char *file_to_openout = NULL;
    1710 
    1711   struct s_node *node;
    1712 
    1713   int old_loglevel;
    1714   long current_slice_number = 0;
    1715   int retval = 0;
    1716   int res = 0;
    1717   int ctrl_chr = '\0';
    1718   long long slice_siz;
    1719   bool dummy_restore = FALSE;
    1720   bool use_partimage_hack=FALSE;
    1721   pid_t pid;
    1722   struct s_filename_and_lstat_info biggiestruct;
    1723   struct utimbuf the_utime_buf, *ubuf;
    1724   ubuf = &the_utime_buf;
    1725 
    1726   malloc_string(tmp);
    1727   malloc_string(partimagehack_fifo);
    1728   malloc_string(outfile_fname);
    1729   malloc_string(command);
    1730   malloc_string(sz_devfile);
    1731   malloc_string(partimagehack_command);
    1732   old_loglevel = g_loglevel;
    1733   assert(bkpinfo!=NULL);
    1734   assert(orig_bf_fname!=NULL);
    1735   assert(orig_checksum!=NULL);
    1736 
    1737   pathname_of_last_file_restored[0] = '\0';
    1738   if (use_partimagehack == BLK_START_A_PIHBIGGIE)
    1739     {
    1740       use_partimagehack = 1;
    1741       log_msg(1, "%s --- pih=YES", orig_bf_fname);
    1742     }
    1743   else if (use_partimagehack == BLK_START_A_NORMBIGGIE)
    1744     {
    1745       use_partimagehack = 0;
    1746       log_msg(1, "%s --- pih=NO", orig_bf_fname);
    1747     }
    1748   else
    1749     {
    1750       use_partimagehack = 0;
    1751       log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
    1752     }
    1753  
    1754   strncpy(pathname_of_last_file_restored, orig_bf_fname, MAX_STR_LEN-1);
    1755   pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';
    1756  
    1757   /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
    1758 
    1759   if (filelist != NULL)
    1760     {
    1761       node = find_string_at_node(filelist, orig_bf_fname);
    1762       if (!node)
    1763         {
    1764           dummy_restore = TRUE;
    1765           log_msg(1, "Skipping big file %ld (%s) - not in biggielist subset", biggiefile_number+1, orig_bf_fname);
    1766           pathname_of_last_file_restored[0] = '\0';
    1767         }
    1768       else if (!(node->selected))
    1769         {
    1770           dummy_restore = TRUE;
    1771       log_msg(1, "Skipping %s (name isn't in biggielist subset)", orig_bf_fname);
    1772           pathname_of_last_file_restored[0] = '\0';
    1773         }
    1774     }
    1775 
    1776   if (use_partimagehack)
    1777     {
    1778       if (strncmp ( orig_bf_fname, "/dev/", 5))
    1779         {
    1780       log_msg(1, "I was in error when I set use_partimagehack to TRUE.");
    1781       log_msg(1, "%s isn't even in /dev", orig_bf_fname);
    1782       use_partimagehack = FALSE;
    1783     }
    1784     }
    1785 
    1786   if (use_partimagehack)
    1787     {
    1788       g_loglevel = 4;
    1789       strcpy(outfile_fname, orig_bf_fname);
    1790       use_partimage_hack = TRUE;
    1791       log_msg(2, "Calling partimagehack in background because %s is a /dev entry", outfile_fname);
    1792       sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    1793       mkfifo(sz_devfile, 0x770);
    1794       strcpy(partimagehack_fifo, sz_devfile);
    1795       file_to_openout = partimagehack_fifo;
    1796       switch(pid=fork())
    1797                 {
    1798                   case -1: fatal_error("Fork failure");
    1799               case 0:
    1800             log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", outfile_fname, partimagehack_fifo);
    1801             res=feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
    1802 //          log_msg(3, "CHILD - fip - exiting");
    1803             exit(res);
    1804             break;
    1805                   default:
    1806             log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    1807                 }
    1808     }
    1809   else
    1810     {
    1811       if (!strncmp ( orig_bf_fname, "/dev/", 5)) // non-NTFS partition
    1812         { strcpy(outfile_fname, orig_bf_fname); }
    1813       else // biggiefile
    1814         { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname ); }
    1815       use_partimage_hack = FALSE;
    1816       partimagehack_fifo[0] = '\0';
    1817       file_to_openout = outfile_fname;
    1818       if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way
    1819        { make_hole_for_file( outfile_fname ); }
    1820       sprintf(tmp, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname );
    1821       log_msg(2, tmp );
    1822     }
    1823  
    1824   if (dummy_restore)
    1825     { sprintf( outfile_fname, "/dev/null" ); }
    1826    
    1827   if ( !bkpinfo->zip_exe[0] )
    1828     {
    1829       sprintf(command, "cat > \"%s\"", file_to_openout);
    1830     }
    1831   else
    1832     {
    1833       sprintf(command,"%s -dc > \"%s\" 2>> %s",bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
    1834     }
    1835   sprintf(tmp,"Pipe command = '%s'",command);
    1836   log_msg(3, tmp);
    1837 
    1838   /* restore biggiefile, one slice at a time */
    1839   if ( !( pout = popen(command, "w" ) ) )
    1840     {
    1841       fatal_error( "Cannot pipe out" );
    1842     }
    1843   for( res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr); ctrl_chr!=BLK_STOP_A_BIGGIE; res=read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr ) )
    1844     {
    1845       if ( ctrl_chr != BLK_START_AN_AFIO_OR_SLICE )
    1846     {
    1847       wrong_marker( BLK_START_AN_AFIO_OR_SLICE,ctrl_chr );
    1848     }
    1849       sprintf( tmp,"Working on file #%ld, slice #%ld    ",
    1850            biggiefile_number + 1,
    1851            current_slice_number);
    1852       log_msg(2, tmp);
    1853       if (!g_text_mode)
    1854         {
    1855           newtDrawRootText( 0, g_noof_rows - 2, tmp);
    1856           newtRefresh();
    1857         }
    1858       strip_spaces( tmp );
    1859       update_progress_form( tmp );
    1860       if ( current_slice_number == 0 )
    1861         {
    1862           res = read_file_from_stream_to_file( bkpinfo,"/tmp/biggie-blah.txt",slice_siz);
    1863           if (!(fin = fopen("/tmp/biggie-blah.txt", "r")))
    1864             { log_OS_error("blah blah"); }
    1865           else
    1866             {
    1867               if ( fread( (void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct))
    1868                 {
    1869                   log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", biggiefile_number + 1);
    1870                 }
    1871               paranoid_fclose(fin);
    1872             }
    1873     }
    1874       else
    1875         {
    1876           res = read_file_from_stream_to_stream( bkpinfo, pout, slice_siz );
    1877         }
    1878       retval += res;
    1879       res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr );
    1880       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    1881     {
    1882       wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
    1883     }
    1884       current_slice_number++;
    1885       g_current_progress++;
    1886     }
    1887   paranoid_pclose(pout);
    1888  
    1889   log_msg(1, "pathname_of_last_file_restored is now %s", pathname_of_last_file_restored);
    1890 
    1891   if (use_partimage_hack)
    1892     {
    1893       log_msg(3, "Waiting for partimage to finish");
    1894       sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
    1895       while(system(tmp) == 0)
    1896         { sleep(1); }
    1897       log_msg(3, "OK, partimage has really finished");
    1898     }
    1899 
    1900   log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
    1901   log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
    1902   if (strcmp(outfile_fname, "/dev/null"))
    1903     {
    1904       chmod(outfile_fname, biggiestruct.properties.st_mode);
    1905       chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
    1906       ubuf->actime = biggiestruct.properties.st_atime;
    1907       ubuf->modtime= biggiestruct.properties.st_mtime;
    1908       utime( outfile_fname, ubuf );
    1909     }
    1910 
    1911   paranoid_free(tmp);
    1912   paranoid_free(outfile_fname);
    1913   paranoid_free(command);
    1914   paranoid_free(partimagehack_command);
    1915   paranoid_free(sz_devfile);
    1916   paranoid_free(partimagehack_fifo);
    1917   g_loglevel = old_loglevel;
    1918   return(retval);
     1695    char *tmp;
     1696    char *command;
     1697    char *outfile_fname;
     1698    char *partimagehack_command;
     1699    char *sz_devfile;
     1700    char *partimagehack_fifo;
     1701    char *file_to_openout = NULL;
     1702
     1703    struct s_node *node;
     1704
     1705    int old_loglevel;
     1706    long current_slice_number = 0;
     1707    int retval = 0;
     1708    int res = 0;
     1709    int ctrl_chr = '\0';
     1710    long long slice_siz;
     1711    bool dummy_restore = FALSE;
     1712    bool use_partimage_hack = FALSE;
     1713    pid_t pid;
     1714    struct s_filename_and_lstat_info biggiestruct;
     1715    struct utimbuf the_utime_buf, *ubuf;
     1716    ubuf = &the_utime_buf;
     1717
     1718    malloc_string(tmp);
     1719    malloc_string(partimagehack_fifo);
     1720    malloc_string(outfile_fname);
     1721    malloc_string(command);
     1722    malloc_string(sz_devfile);
     1723    malloc_string(partimagehack_command);
     1724    old_loglevel = g_loglevel;
     1725    assert(bkpinfo != NULL);
     1726    assert(orig_bf_fname != NULL);
     1727    assert(orig_checksum != NULL);
     1728
     1729    pathname_of_last_file_restored[0] = '\0';
     1730    if (use_partimagehack == BLK_START_A_PIHBIGGIE) {
     1731        use_partimagehack = 1;
     1732        log_msg(1, "%s --- pih=YES", orig_bf_fname);
     1733    } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) {
     1734        use_partimagehack = 0;
     1735        log_msg(1, "%s --- pih=NO", orig_bf_fname);
     1736    } else {
     1737        use_partimagehack = 0;
     1738        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
     1739    }
     1740
     1741    strncpy(pathname_of_last_file_restored, orig_bf_fname,
     1742            MAX_STR_LEN - 1);
     1743    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1744
     1745    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
     1746
     1747    if (filelist != NULL) {
     1748        node = find_string_at_node(filelist, orig_bf_fname);
     1749        if (!node) {
     1750            dummy_restore = TRUE;
     1751            log_msg(1,
     1752                    "Skipping big file %ld (%s) - not in biggielist subset",
     1753                    biggiefile_number + 1, orig_bf_fname);
     1754            pathname_of_last_file_restored[0] = '\0';
     1755        } else if (!(node->selected)) {
     1756            dummy_restore = TRUE;
     1757            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
     1758                    orig_bf_fname);
     1759            pathname_of_last_file_restored[0] = '\0';
     1760        }
     1761    }
     1762
     1763    if (use_partimagehack) {
     1764        if (strncmp(orig_bf_fname, "/dev/", 5)) {
     1765            log_msg(1,
     1766                    "I was in error when I set use_partimagehack to TRUE.");
     1767            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
     1768            use_partimagehack = FALSE;
     1769        }
     1770    }
     1771
     1772    if (use_partimagehack) {
     1773        g_loglevel = 4;
     1774        strcpy(outfile_fname, orig_bf_fname);
     1775        use_partimage_hack = TRUE;
     1776        log_msg(2,
     1777                "Calling partimagehack in background because %s is a /dev entry",
     1778                outfile_fname);
     1779        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1780                (int) (random() % 32768));
     1781        mkfifo(sz_devfile, 0x770);
     1782        strcpy(partimagehack_fifo, sz_devfile);
     1783        file_to_openout = partimagehack_fifo;
     1784        switch (pid = fork()) {
     1785        case -1:
     1786            fatal_error("Fork failure");
     1787        case 0:
     1788            log_msg(3,
     1789                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
     1790                    outfile_fname, partimagehack_fifo);
     1791            res =
     1792                feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
     1793//          log_msg(3, "CHILD - fip - exiting");
     1794            exit(res);
     1795            break;
     1796        default:
     1797            log_msg(3,
     1798                    "feed_into_partimage() called in background --- pid=%ld",
     1799                    (long int) (pid));
     1800        }
     1801    } else {
     1802        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
     1803        {
     1804            strcpy(outfile_fname, orig_bf_fname);
     1805        } else                  // biggiefile
     1806        {
     1807            sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1808                    orig_bf_fname);
     1809        }
     1810        use_partimage_hack = FALSE;
     1811        partimagehack_fifo[0] = '\0';
     1812        file_to_openout = outfile_fname;
     1813        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     1814        {
     1815            make_hole_for_file(outfile_fname);
     1816        }
     1817        sprintf(tmp, "Reassembling big file %ld (%s)",
     1818                biggiefile_number + 1, orig_bf_fname);
     1819        log_msg(2, tmp);
     1820    }
     1821
     1822    if (dummy_restore) {
     1823        sprintf(outfile_fname, "/dev/null");
     1824    }
     1825
     1826    if (!bkpinfo->zip_exe[0]) {
     1827        sprintf(command, "cat > \"%s\"", file_to_openout);
     1828    } else {
     1829        sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
     1830                file_to_openout, MONDO_LOGFILE);
     1831    }
     1832    sprintf(tmp, "Pipe command = '%s'", command);
     1833    log_msg(3, tmp);
     1834
     1835    /* restore biggiefile, one slice at a time */
     1836    if (!(pout = popen(command, "w"))) {
     1837        fatal_error("Cannot pipe out");
     1838    }
     1839    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
     1840         ctrl_chr != BLK_STOP_A_BIGGIE;
     1841         res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
     1842        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     1843            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     1844        }
     1845        sprintf(tmp, "Working on file #%ld, slice #%ld    ",
     1846                biggiefile_number + 1, current_slice_number);
     1847        log_msg(2, tmp);
     1848        if (!g_text_mode) {
     1849            newtDrawRootText(0, g_noof_rows - 2, tmp);
     1850            newtRefresh();
     1851        }
     1852        strip_spaces(tmp);
     1853        update_progress_form(tmp);
     1854        if (current_slice_number == 0) {
     1855            res =
     1856                read_file_from_stream_to_file(bkpinfo,
     1857                                              "/tmp/biggie-blah.txt",
     1858                                              slice_siz);
     1859            if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
     1860                log_OS_error("blah blah");
     1861            } else {
     1862                if (fread
     1863                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
     1864                     fin) < sizeof(biggiestruct)) {
     1865                    log_msg(2,
     1866                            "Warning - unable to get biggiestruct of bigfile #%d",
     1867                            biggiefile_number + 1);
     1868                }
     1869                paranoid_fclose(fin);
     1870            }
     1871        } else {
     1872            res =
     1873                read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
     1874        }
     1875        retval += res;
     1876        res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
     1877        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     1878            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     1879        }
     1880        current_slice_number++;
     1881        g_current_progress++;
     1882    }
     1883    paranoid_pclose(pout);
     1884
     1885    log_msg(1, "pathname_of_last_file_restored is now %s",
     1886            pathname_of_last_file_restored);
     1887
     1888    if (use_partimage_hack) {
     1889        log_msg(3, "Waiting for partimage to finish");
     1890        sprintf(tmp,
     1891                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1892        while (system(tmp) == 0) {
     1893            sleep(1);
     1894        }
     1895        log_msg(3, "OK, partimage has really finished");
     1896    }
     1897
     1898    log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
     1899    log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
     1900    if (strcmp(outfile_fname, "/dev/null")) {
     1901        chmod(outfile_fname, biggiestruct.properties.st_mode);
     1902        chown(outfile_fname, biggiestruct.properties.st_uid,
     1903              biggiestruct.properties.st_gid);
     1904        ubuf->actime = biggiestruct.properties.st_atime;
     1905        ubuf->modtime = biggiestruct.properties.st_mtime;
     1906        utime(outfile_fname, ubuf);
     1907    }
     1908
     1909    paranoid_free(tmp);
     1910    paranoid_free(outfile_fname);
     1911    paranoid_free(command);
     1912    paranoid_free(partimagehack_command);
     1913    paranoid_free(sz_devfile);
     1914    paranoid_free(partimagehack_fifo);
     1915    g_loglevel = old_loglevel;
     1916    return (retval);
    19191917}
    19201918
     
    19381936int
    19391937restore_a_tarball_from_CD(char *tarball_fname,
    1940               long current_tarball_number,
    1941               struct s_node*filelist)
     1938                          long current_tarball_number,
     1939                          struct s_node *filelist)
    19421940{
    1943   int retval = 0;
    1944   int res;
    1945   char *p;
     1941    int retval = 0;
     1942    int res;
     1943    char *p;
    19461944
    19471945  /** malloc **/
    1948   char *command;
    1949   char *tmp;
    1950   char *filelist_name;
    1951   char *filelist_subset_fname;
    1952   char *executable;
    1953   char *temp_log;
    1954   char screen_message[100];
    1955   long matches=0;
    1956   bool use_star;
    1957   char *xattr_fname;
    1958   char *acl_fname;
     1946    char *command;
     1947    char *tmp;
     1948    char *filelist_name;
     1949    char *filelist_subset_fname;
     1950    char *executable;
     1951    char *temp_log;
     1952    char screen_message[100];
     1953    long matches = 0;
     1954    bool use_star;
     1955    char *xattr_fname;
     1956    char *acl_fname;
    19591957//  char files_to_restore_this_time_fname[MAX_STR_LEN];
    19601958
    1961   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1962   malloc_string(command);
    1963   malloc_string(tmp);
    1964   malloc_string(filelist_name);
    1965   malloc_string(filelist_subset_fname);
    1966   malloc_string(executable);
    1967   malloc_string(temp_log);
    1968   malloc_string(xattr_fname);
    1969   malloc_string(acl_fname);
    1970  
    1971   log_msg(5, "Entering");
    1972   filelist_subset_fname[0] = '\0';
    1973   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
     1959    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     1960    malloc_string(command);
     1961    malloc_string(tmp);
     1962    malloc_string(filelist_name);
     1963    malloc_string(filelist_subset_fname);
     1964    malloc_string(executable);
     1965    malloc_string(temp_log);
     1966    malloc_string(xattr_fname);
     1967    malloc_string(acl_fname);
     1968
     1969    log_msg(5, "Entering");
     1970    filelist_subset_fname[0] = '\0';
     1971    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    19741972//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    1975   sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
    1976   run_program_and_log_output(command, 9);
    1977   sprintf(temp_log, "/tmp/%d.%d", (int)(random()%32768), (int)(random()%32768));
    1978  
    1979   sprintf(filelist_name, MNT_CDROM"/archives/filelist.%ld",current_tarball_number);
    1980   if ( length_of_file( filelist_name ) <= 2 )
    1981     {
    1982       log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
    1983       log_msg(2, "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
    1984       log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
    1985       retval=0;
    1986       goto leave_sub;
    1987     }
    1988   if ( count_lines_in_file(filelist_name) <= 0 || length_of_file( tarball_fname ) <= 0 )
    1989     {
    1990       log_msg(3, "length_of_file(%s) = %ld", tarball_fname, length_of_file(tarball_fname));
    1991       sprintf(tmp,"Unable to restore fileset #%ld (CD I/O error)",current_tarball_number);
    1992       log_to_screen(tmp);
    1993       retval=1;
    1994       goto leave_sub;
    1995     }
    1996 
    1997   if (filelist)
    1998     {
    1999       sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
    2000       if ((matches=save_filelist_entries_in_common
    2001                 (filelist_name, filelist, filelist_subset_fname, use_star))
    2002                 <= 0)
    2003     {
    2004       sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    2005       log_msg(1, tmp);
    2006     }
    2007       else
    2008         {
    2009       log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
    2010     }
    2011       sprintf(screen_message, "Tarball #%ld --- %ld matches", current_tarball_number, matches);
    2012       log_to_screen(screen_message);
    2013     }
    2014   else
    2015     {
    2016       filelist_subset_fname[0] = '\0';
    2017     }
    2018 
    2019   if (filelist == NULL || matches>0)
    2020     {
    2021       sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);
    2022       sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);
    2023       if ( strstr( tarball_fname, ".bz2" ) )
    2024         {
    2025           strcpy(executable,"bzip2");
    2026         }
    2027       else if ( strstr( tarball_fname, ".lzo") )
    2028         {
    2029           strcpy( executable,"lzop");
    2030         }
    2031       else
    2032         {
    2033           executable[0] = '\0';
    2034         }
    2035       if (executable[0])
    2036         {
    2037           sprintf( tmp, "which %s > /dev/null 2> /dev/null", executable );
    2038           if ( run_program_and_log_output( tmp, FALSE ) )
    2039             {
    2040              log_to_screen("(compare_a_tarball) Compression program not found - oh no!");
    2041              paranoid_MR_finish(1);
    2042             }
    2043           strcpy(tmp, executable);
    2044           sprintf(executable, "-P %s -Z", tmp);
    2045         }
     1973    sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
     1974    run_program_and_log_output(command, 9);
     1975    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
     1976            (int) (random() % 32768));
     1977
     1978    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
     1979            current_tarball_number);
     1980    if (length_of_file(filelist_name) <= 2) {
     1981        log_msg(2, "There are _zero_ files in filelist '%s'",
     1982                filelist_name);
     1983        log_msg(2,
     1984                "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
     1985        log_msg(2,
     1986                "but it's non-critical. It's cosmetic. Don't worry about it.");
     1987        retval = 0;
     1988        goto leave_sub;
     1989    }
     1990    if (count_lines_in_file(filelist_name) <= 0
     1991        || length_of_file(tarball_fname) <= 0) {
     1992        log_msg(3, "length_of_file(%s) = %ld", tarball_fname,
     1993                length_of_file(tarball_fname));
     1994        sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
     1995                current_tarball_number);
     1996        log_to_screen(tmp);
     1997        retval = 1;
     1998        goto leave_sub;
     1999    }
     2000
     2001    if (filelist) {
     2002        sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
     2003                current_tarball_number);
     2004        if ((matches =
     2005             save_filelist_entries_in_common(filelist_name, filelist,
     2006                                             filelist_subset_fname,
     2007                                             use_star))
     2008            <= 0) {
     2009            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     2010            log_msg(1, tmp);
     2011        } else {
     2012            log_msg(3, "Saved fileset %ld's subset to %s",
     2013                    current_tarball_number, filelist_subset_fname);
     2014        }
     2015        sprintf(screen_message, "Tarball #%ld --- %ld matches",
     2016                current_tarball_number, matches);
     2017        log_to_screen(screen_message);
     2018    } else {
     2019        filelist_subset_fname[0] = '\0';
     2020    }
     2021
     2022    if (filelist == NULL || matches > 0) {
     2023        sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
     2024                MNT_CDROM "/archives", current_tarball_number);
     2025        sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
     2026                current_tarball_number);
     2027        if (strstr(tarball_fname, ".bz2")) {
     2028            strcpy(executable, "bzip2");
     2029        } else if (strstr(tarball_fname, ".lzo")) {
     2030            strcpy(executable, "lzop");
     2031        } else {
     2032            executable[0] = '\0';
     2033        }
     2034        if (executable[0]) {
     2035            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
     2036            if (run_program_and_log_output(tmp, FALSE)) {
     2037                log_to_screen
     2038                    ("(compare_a_tarball) Compression program not found - oh no!");
     2039                paranoid_MR_finish(1);
     2040            }
     2041            strcpy(tmp, executable);
     2042            sprintf(executable, "-P %s -Z", tmp);
     2043        }
    20462044#ifdef __FreeBSD__
    20472045#define BUFSIZE 512
     
    20512049
    20522050//      if (strstr(tarball_fname, ".star."))
    2053       if (use_star)
    2054         {
    2055       sprintf( command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname);
    2056       if (strstr (tarball_fname, ".bz2"))
    2057         { strcat( command, " -bz"); }
    2058     }
    2059       else
    2060         {
    2061       if ( filelist_subset_fname[0] != '\0' )
    2062             {
    2063               sprintf( command,
    2064            "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
    2065            TAPE_BLOCK_SIZE,
    2066            BUFSIZE,
    2067            executable,
    2068            filelist_subset_fname,
    2069 //             files_to_restore_this_time_fname,
    2070            tarball_fname);
    2071         }
    2072           else
    2073             {
    2074               sprintf( command,
    2075            "afio -i -b %ld -c %ld -M 8m %s %s",
    2076            TAPE_BLOCK_SIZE,
    2077            BUFSIZE,
    2078            executable,
    2079            tarball_fname);
    2080             }
    2081     }
     2051        if (use_star) {
     2052            sprintf(command,
     2053                    "star -x -force-remove -U " STAR_ACL_SZ
     2054                    " errctl= file=%s", tarball_fname);
     2055            if (strstr(tarball_fname, ".bz2")) {
     2056                strcat(command, " -bz");
     2057            }
     2058        } else {
     2059            if (filelist_subset_fname[0] != '\0') {
     2060                sprintf(command,
     2061                        "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
     2062                        TAPE_BLOCK_SIZE,
     2063                        BUFSIZE, executable, filelist_subset_fname,
     2064//             files_to_restore_this_time_fname,
     2065                        tarball_fname);
     2066            } else {
     2067                sprintf(command,
     2068                        "afio -i -b %ld -c %ld -M 8m %s %s",
     2069                        TAPE_BLOCK_SIZE,
     2070                        BUFSIZE, executable, tarball_fname);
     2071            }
     2072        }
    20822073#undef BUFSIZE
    2083       sprintf(command+strlen(command), " 2>> %s >> %s", temp_log, temp_log);
    2084       log_msg(1,"command = '%s'", command);
    2085       unlink(temp_log);
    2086       res = system(command);
    2087       if (res)
    2088         {
    2089       p = strstr(command, "-acl ");
    2090       if (p)
    2091         {
    2092           p[0]=p[1]=p[2]=p[3]=' ';
    2093               log_msg(1,"new command = '%s'", command);
    2094               res = system(command);
    2095         }
    2096         }
    2097       if (res && length_of_file(temp_log)<5) { res=0; }
    2098      
    2099       log_msg(1, "Setting fattr list %s", xattr_fname);
    2100       if (length_of_file(xattr_fname)>0)
    2101         {
    2102           res=set_fattr_list(filelist_subset_fname, xattr_fname);
    2103           if (res) { log_to_screen("Errors occurred while setting extended attributes"); }
    2104           else { log_msg(1, "I set xattr OK"); }
    2105           retval += res;
    2106         }
    2107       if (length_of_file(acl_fname)>0)
    2108         {
    2109           log_msg(1, "Setting acl list %s", acl_fname);
    2110           res=set_acl_list(filelist_subset_fname, acl_fname);
    2111           if (res) { log_to_screen("Errors occurred while setting access control lists"); }
    2112           else { log_msg(1, "I set ACL OK"); }
    2113           retval += res;
    2114         }
    2115       if ( retval )
    2116         {
    2117           sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    2118           system(command);
    2119           log_msg(2, "Errors occurred while processing fileset #%d",current_tarball_number);
    2120         }
    2121       else
    2122         {
    2123           log_msg(2, "Fileset #%d processed OK", current_tarball_number);
    2124         }
    2125     }
    2126   if (does_file_exist("/PAUSE"))
    2127     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2128   unlink(filelist_subset_fname);
    2129   unlink(xattr_fname);
    2130   unlink(acl_fname);
    2131   unlink(temp_log);
    2132  
    2133 leave_sub:
    2134   paranoid_free(command); paranoid_free(tmp);
    2135   paranoid_free(filelist_name); paranoid_free(filelist_subset_fname);
    2136   paranoid_free(executable); paranoid_free(temp_log);
    2137   paranoid_free(xattr_fname); paranoid_free(acl_fname);
    2138   log_msg(5, "Leaving");
    2139   return(retval);
     2074        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
     2075                temp_log);
     2076        log_msg(1, "command = '%s'", command);
     2077        unlink(temp_log);
     2078        res = system(command);
     2079        if (res) {
     2080            p = strstr(command, "-acl ");
     2081            if (p) {
     2082                p[0] = p[1] = p[2] = p[3] = ' ';
     2083                log_msg(1, "new command = '%s'", command);
     2084                res = system(command);
     2085            }
     2086        }
     2087        if (res && length_of_file(temp_log) < 5) {
     2088            res = 0;
     2089        }
     2090
     2091        log_msg(1, "Setting fattr list %s", xattr_fname);
     2092        if (length_of_file(xattr_fname) > 0) {
     2093            res = set_fattr_list(filelist_subset_fname, xattr_fname);
     2094            if (res) {
     2095                log_to_screen
     2096                    ("Errors occurred while setting extended attributes");
     2097            } else {
     2098                log_msg(1, "I set xattr OK");
     2099            }
     2100            retval += res;
     2101        }
     2102        if (length_of_file(acl_fname) > 0) {
     2103            log_msg(1, "Setting acl list %s", acl_fname);
     2104            res = set_acl_list(filelist_subset_fname, acl_fname);
     2105            if (res) {
     2106                log_to_screen
     2107                    ("Errors occurred while setting access control lists");
     2108            } else {
     2109                log_msg(1, "I set ACL OK");
     2110            }
     2111            retval += res;
     2112        }
     2113        if (retval) {
     2114            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     2115            system(command);
     2116            log_msg(2, "Errors occurred while processing fileset #%d",
     2117                    current_tarball_number);
     2118        } else {
     2119            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
     2120        }
     2121    }
     2122    if (does_file_exist("/PAUSE")) {
     2123        popup_and_OK
     2124            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2125    }
     2126    unlink(filelist_subset_fname);
     2127    unlink(xattr_fname);
     2128    unlink(acl_fname);
     2129    unlink(temp_log);
     2130
     2131  leave_sub:
     2132    paranoid_free(command);
     2133    paranoid_free(tmp);
     2134    paranoid_free(filelist_name);
     2135    paranoid_free(filelist_subset_fname);
     2136    paranoid_free(executable);
     2137    paranoid_free(temp_log);
     2138    paranoid_free(xattr_fname);
     2139    paranoid_free(acl_fname);
     2140    log_msg(5, "Leaving");
     2141    return (retval);
    21402142}
    21412143
     
    21622164int
    21632165restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
    2164                   char *tarball_fname,
    2165                   long current_tarball_number,
    2166                   struct s_node*filelist,
    2167                   long long size, char*xattr_fname, char*acl_fname)
     2166                              char *tarball_fname,
     2167                              long current_tarball_number,
     2168                              struct s_node *filelist,
     2169                              long long size, char *xattr_fname,
     2170                              char *acl_fname)
    21682171{
    2169   int retval = 0;
    2170   int res = 0;
     2172    int retval = 0;
     2173    int res = 0;
    21712174
    21722175  /** malloc add ***/
    2173   char *tmp;
    2174   char *command;
    2175   char *afio_fname;
    2176   char *filelist_fname;
    2177   char *filelist_subset_fname;
    2178   char *executable;
    2179   long matches=0;
    2180   bool restore_this_fileset = FALSE;
    2181   bool use_star;
    2182  
    2183   assert(bkpinfo!=NULL);
    2184   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    2185   malloc_string(filelist_subset_fname);
    2186   malloc_string(filelist_fname);
    2187   malloc_string(afio_fname);
    2188   malloc_string(executable);
    2189   malloc_string(command);
    2190   malloc_string(tmp);
    2191   filelist_subset_fname[0] = '\0';
    2192   /* to do it with a file... */
    2193   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
    2194   sprintf( tmp,
    2195        "Restoring from fileset #%ld (%ld KB) on %s #%d",current_tarball_number,
    2196        (long) size>>10,
    2197        media_descriptor_string(bkpinfo->backup_media_type),
    2198        g_current_media_number );
    2199   log_msg(2, tmp );
    2200   run_program_and_log_output( "mkdir -p " MNT_RESTORING "/tmp", FALSE );
     2176    char *tmp;
     2177    char *command;
     2178    char *afio_fname;
     2179    char *filelist_fname;
     2180    char *filelist_subset_fname;
     2181    char *executable;
     2182    long matches = 0;
     2183    bool restore_this_fileset = FALSE;
     2184    bool use_star;
     2185
     2186    assert(bkpinfo != NULL);
     2187    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     2188    malloc_string(filelist_subset_fname);
     2189    malloc_string(filelist_fname);
     2190    malloc_string(afio_fname);
     2191    malloc_string(executable);
     2192    malloc_string(command);
     2193    malloc_string(tmp);
     2194    filelist_subset_fname[0] = '\0';
     2195    /* to do it with a file... */
     2196    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
     2197    sprintf(tmp,
     2198            "Restoring from fileset #%ld (%ld KB) on %s #%d",
     2199            current_tarball_number, (long) size >> 10,
     2200            media_descriptor_string(bkpinfo->backup_media_type),
     2201            g_current_media_number);
     2202    log_msg(2, tmp);
     2203    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
    22012204
    22022205  /****************************************************************************
     
    22052208   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
    22062209   ****************************************************************************/
    2207   filelist_fname[0] = filelist_subset_fname[0] = '\0';
    2208   sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
    2209   sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
    2210   sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
     2210    filelist_fname[0] = filelist_subset_fname[0] = '\0';
     2211    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
     2212            current_tarball_number);
     2213    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
     2214            current_tarball_number);
     2215    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
     2216            bkpinfo->tmpdir, current_tarball_number);
    22112217//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
    2212   res = read_file_from_stream_to_file( bkpinfo, afio_fname,size );
    2213   if (strstr(tarball_fname, ".star")) { bkpinfo->use_star = TRUE; }
    2214   if (res) { log_msg(1, "Warning - error reading afioball from tape"); }
    2215   if (bkpinfo->compression_level == 0)
    2216     {
    2217       executable[0] = '\0';
    2218     }
    2219   else
    2220     {
    2221       if (bkpinfo->use_star)
    2222         { strcpy(executable, " -bz"); }
    2223       else
    2224         { sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); }
    2225     }
    2226 
    2227   if (!filelist) // if unconditional restore then restore entire fileset
    2228     {
    2229       restore_this_fileset = TRUE;
    2230     }
    2231   else          // If restoring selectively then get TOC from tarball
    2232     {
    2233       if (strstr(tarball_fname, ".star."))
    2234         {
    2235       use_star = TRUE;
    2236       sprintf( command, "star -t file=%s %s", afio_fname, executable);
    2237     }
    2238       else
    2239         {
    2240       use_star = FALSE;
    2241           sprintf( command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
    2242                         executable, afio_fname);
    2243     }
    2244       sprintf(command+strlen(command), " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
    2245       log_msg(1, "command = %s", command);
    2246       if (system(command)) { log_msg(4, "Warning - error occurred while retrieving TOC"); }
    2247       if ((matches=save_filelist_entries_in_common(filelist_fname, filelist, filelist_subset_fname, use_star))
    2248                      <= 0
    2249                     || length_of_file(filelist_subset_fname)<2)
    2250         {
    2251       if (length_of_file(filelist_subset_fname)<2)
    2252         { log_msg(1, "No matches found in fileset %ld", current_tarball_number); }
    2253       sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    2254       log_msg(2, tmp);
    2255           restore_this_fileset = FALSE;
    2256         }
    2257       else
    2258         {
    2259       log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", matches, current_tarball_number, filelist_subset_fname);
    2260       restore_this_fileset = TRUE;
    2261     }
    2262     }
     2218    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
     2219    if (strstr(tarball_fname, ".star")) {
     2220        bkpinfo->use_star = TRUE;
     2221    }
     2222    if (res) {
     2223        log_msg(1, "Warning - error reading afioball from tape");
     2224    }
     2225    if (bkpinfo->compression_level == 0) {
     2226        executable[0] = '\0';
     2227    } else {
     2228        if (bkpinfo->use_star) {
     2229            strcpy(executable, " -bz");
     2230        } else {
     2231            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
     2232        }
     2233    }
     2234
     2235    if (!filelist)              // if unconditional restore then restore entire fileset
     2236    {
     2237        restore_this_fileset = TRUE;
     2238    } else                      // If restoring selectively then get TOC from tarball
     2239    {
     2240        if (strstr(tarball_fname, ".star.")) {
     2241            use_star = TRUE;
     2242            sprintf(command, "star -t file=%s %s", afio_fname, executable);
     2243        } else {
     2244            use_star = FALSE;
     2245            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
     2246                    executable, afio_fname);
     2247        }
     2248        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
     2249                MONDO_LOGFILE);
     2250        log_msg(1, "command = %s", command);
     2251        if (system(command)) {
     2252            log_msg(4, "Warning - error occurred while retrieving TOC");
     2253        }
     2254        if ((matches =
     2255             save_filelist_entries_in_common(filelist_fname, filelist,
     2256                                             filelist_subset_fname,
     2257                                             use_star))
     2258            <= 0 || length_of_file(filelist_subset_fname) < 2) {
     2259            if (length_of_file(filelist_subset_fname) < 2) {
     2260                log_msg(1, "No matches found in fileset %ld",
     2261                        current_tarball_number);
     2262            }
     2263            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     2264            log_msg(2, tmp);
     2265            restore_this_fileset = FALSE;
     2266        } else {
     2267            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
     2268                    matches, current_tarball_number,
     2269                    filelist_subset_fname);
     2270            restore_this_fileset = TRUE;
     2271        }
     2272    }
    22632273
    22642274// Concoct the call to star/afio to restore files
    2265   if (strstr(tarball_fname, ".star.")) // star
    2266     {
    2267       sprintf( command, "star -x file=%s %s", afio_fname, executable);
    2268       if (filelist)
    2269         { sprintf(command+strlen(command), " list=%s", filelist_subset_fname); }
    2270     }
    2271   else                                 // afio
    2272     {
    2273       sprintf( command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
    2274       if (filelist)
    2275         { sprintf(command+strlen(command), " -w %s", filelist_subset_fname); }
    2276       sprintf(command+strlen(command), " %s", afio_fname);
    2277     }
    2278   sprintf( command+strlen(command), " 2>> %s", MONDO_LOGFILE);
     2275    if (strstr(tarball_fname, ".star."))    // star
     2276    {
     2277        sprintf(command, "star -x file=%s %s", afio_fname, executable);
     2278        if (filelist) {
     2279            sprintf(command + strlen(command), " list=%s",
     2280                    filelist_subset_fname);
     2281        }
     2282    } else                      // afio
     2283    {
     2284        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
     2285                executable);
     2286        if (filelist) {
     2287            sprintf(command + strlen(command), " -w %s",
     2288                    filelist_subset_fname);
     2289        }
     2290        sprintf(command + strlen(command), " %s", afio_fname);
     2291    }
     2292    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
    22792293
    22802294// Call if IF there are files to restore (selectively/unconditionally)
    2281   if (restore_this_fileset)
    2282     {
    2283       log_msg(1, "Calling command='%s'", command);
    2284       paranoid_system(command);
    2285 
    2286       iamhere("Restoring xattr, acl stuff");
    2287       res=set_fattr_list(filelist_subset_fname, xattr_fname);
    2288       if (res) { log_msg(1, "Errors occurred while setting xattr"); }
    2289       else { log_msg(1, "I set xattr OK"); }
    2290       retval += res;
    2291      
    2292       res=set_acl_list(filelist_subset_fname, acl_fname);
    2293       if (res) { log_msg(1, "Errors occurred while setting ACL"); }
    2294       else { log_msg(1, "I set ACL OK"); }
    2295       retval += res;
    2296      
    2297     }
    2298   else
    2299     {
    2300       log_msg(1, "NOT CALLING '%s'", command);
    2301     }
    2302    
    2303   if (does_file_exist("/PAUSE") && current_tarball_number >= 50)
    2304     {
    2305       log_to_screen("Paused after set %ld", current_tarball_number);
    2306       popup_and_OK("Pausing. Press ENTER to continue.");
    2307     }
    2308    
    2309   unlink(filelist_subset_fname);
    2310   unlink(filelist_fname);
    2311   unlink(afio_fname);
    2312 
    2313   paranoid_free(filelist_subset_fname);
    2314   paranoid_free(filelist_fname);
    2315   paranoid_free(afio_fname);
    2316   paranoid_free(command);
    2317   paranoid_free(tmp);
    2318   return(retval);
     2295    if (restore_this_fileset) {
     2296        log_msg(1, "Calling command='%s'", command);
     2297        paranoid_system(command);
     2298
     2299        iamhere("Restoring xattr, acl stuff");
     2300        res = set_fattr_list(filelist_subset_fname, xattr_fname);
     2301        if (res) {
     2302            log_msg(1, "Errors occurred while setting xattr");
     2303        } else {
     2304            log_msg(1, "I set xattr OK");
     2305        }
     2306        retval += res;
     2307
     2308        res = set_acl_list(filelist_subset_fname, acl_fname);
     2309        if (res) {
     2310            log_msg(1, "Errors occurred while setting ACL");
     2311        } else {
     2312            log_msg(1, "I set ACL OK");
     2313        }
     2314        retval += res;
     2315
     2316    } else {
     2317        log_msg(1, "NOT CALLING '%s'", command);
     2318    }
     2319
     2320    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
     2321        log_to_screen("Paused after set %ld", current_tarball_number);
     2322        popup_and_OK("Pausing. Press ENTER to continue.");
     2323    }
     2324
     2325    unlink(filelist_subset_fname);
     2326    unlink(filelist_fname);
     2327    unlink(afio_fname);
     2328
     2329    paranoid_free(filelist_subset_fname);
     2330    paranoid_free(filelist_fname);
     2331    paranoid_free(afio_fname);
     2332    paranoid_free(command);
     2333    paranoid_free(tmp);
     2334    return (retval);
    23192335}
     2336
    23202337/**************************************************************************
    23212338 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
     
    23352352 */
    23362353int
    2337 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist)
     2354restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
     2355                                struct s_node *filelist)
    23382356{
    2339   int retval = 0;
    2340   int res;
    2341   long noof_biggiefiles, bigfileno = 0, total_slices;
     2357    int retval = 0;
     2358    int res;
     2359    long noof_biggiefiles, bigfileno = 0, total_slices;
    23422360  /** malloc **/
    2343   char *tmp;
    2344   bool just_changed_cds = FALSE, finished;
    2345   char *xattr_fname;
    2346   char *acl_fname;
    2347   char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
    2348   char *pathname_of_last_biggie_restored;
    2349   FILE *fbw = NULL;
    2350    
    2351   malloc_string(xattr_fname);
    2352   malloc_string(acl_fname);
    2353   malloc_string(tmp);
    2354   malloc_string(biggies_whose_EXATs_we_should_set);
    2355   malloc_string(pathname_of_last_biggie_restored);
    2356   assert(bkpinfo!=NULL);
    2357 
    2358   sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    2359   if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w")))
    2360    { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); }
    2361  
    2362   read_cfg_var( g_mondo_cfg_file, "total-slices", tmp);
    2363   total_slices = atol( tmp );
    2364   sprintf(tmp,"Reassembling large files      ");
    2365   mvaddstr_and_log_it( g_currentY, 0, tmp );
    2366   if (length_of_file(BIGGIELIST) < 6)
    2367     {
    2368       log_msg(1, "OK, no biggielist; not restoring biggiefiles");
    2369       return(0);
    2370     }
    2371   noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    2372   if ( noof_biggiefiles <= 0 )
    2373     {
    2374       log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
    2375       return(0);
    2376     }
    2377   sprintf( tmp,"OK, there are %ld biggiefiles in the archives",noof_biggiefiles);
    2378   log_msg(2, tmp );
    2379  
    2380   open_progress_form( "Reassembling large files",
    2381               "I am now reassembling all the large files." ,
    2382               "Please wait. This may take some time.",
    2383               "",
    2384               total_slices);
    2385   for( bigfileno = 0, finished = FALSE; !finished;)
    2386     {
    2387       log_msg( 2, "Thinking about restoring bigfile %ld", bigfileno + 1 );
    2388       if ( !does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) )
    2389     {
    2390       log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
    2391           log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno+1, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2392           log_msg(3, "Slicename would have been %s", slice_fname(bigfileno+1,0,ARCHIVES_PATH,""));
    2393       // I'm not positive 'just_changed_cds' is even necessary...
    2394       if (just_changed_cds)
    2395             {
    2396               just_changed_cds = FALSE;
    2397               log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
    2398             }
    2399       else if (does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST"))
    2400         {
    2401               insist_on_this_cd_number(bkpinfo, ++g_current_media_number);
    2402           sprintf(tmp,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2403           log_to_screen(tmp);
    2404               just_changed_cds = TRUE;
    2405         }
    2406           else
    2407         {
    2408           log_msg(2, "There was no bigfile #%ld. That's OK." ,bigfileno+1);
    2409           log_msg(2, "I'm going to stop restoring bigfiles now.");
    2410           finished = TRUE;
    2411         }
    2412     }
    2413       else
    2414     {
    2415           just_changed_cds = FALSE;
    2416       sprintf(tmp,"Restoring big file %ld",bigfileno + 1);
    2417       update_progress_form(tmp);
    2418       res = restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, pathname_of_last_biggie_restored);
    2419       iamhere(pathname_of_last_biggie_restored);
    2420       if (fbw && pathname_of_last_biggie_restored[0])
    2421         { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); }
    2422       retval += res;
    2423       bigfileno++;
    2424 
    2425     }
    2426     }
    2427 
    2428   if (fbw)
    2429     {
    2430       fclose(fbw);
    2431       sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    2432       sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    2433       if (length_of_file(acl_fname)  >0 && find_home_of_exe("setfacl"))
    2434         {
    2435       set_acl_list  (biggies_whose_EXATs_we_should_set, acl_fname);
    2436     }
    2437       if (length_of_file(xattr_fname)>0 && find_home_of_exe("setfattr"))
    2438         {
    2439       set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    2440     }
    2441     }
    2442   if (does_file_exist("/PAUSE"))
    2443     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2444   close_progress_form();
    2445   if (retval)
    2446     {
    2447       mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
    2448     }
    2449   else
    2450     {
    2451       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2452     }
    2453   paranoid_free(xattr_fname);
    2454   paranoid_free(acl_fname);
    2455   paranoid_free(tmp);
    2456   paranoid_free(biggies_whose_EXATs_we_should_set);
    2457   paranoid_free(pathname_of_last_biggie_restored);
    2458   return( retval );
     2361    char *tmp;
     2362    bool just_changed_cds = FALSE, finished;
     2363    char *xattr_fname;
     2364    char *acl_fname;
     2365    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2366    char *pathname_of_last_biggie_restored;
     2367    FILE *fbw = NULL;
     2368
     2369    malloc_string(xattr_fname);
     2370    malloc_string(acl_fname);
     2371    malloc_string(tmp);
     2372    malloc_string(biggies_whose_EXATs_we_should_set);
     2373    malloc_string(pathname_of_last_biggie_restored);
     2374    assert(bkpinfo != NULL);
     2375
     2376    sprintf(biggies_whose_EXATs_we_should_set,
     2377            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2378    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     2379        log_msg(1, "Warning - cannot openout %s",
     2380                biggies_whose_EXATs_we_should_set);
     2381    }
     2382
     2383    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
     2384    total_slices = atol(tmp);
     2385    sprintf(tmp, "Reassembling large files      ");
     2386    mvaddstr_and_log_it(g_currentY, 0, tmp);
     2387    if (length_of_file(BIGGIELIST) < 6) {
     2388        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
     2389        return (0);
     2390    }
     2391    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
     2392    if (noof_biggiefiles <= 0) {
     2393        log_msg(2,
     2394                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
     2395        return (0);
     2396    }
     2397    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     2398            noof_biggiefiles);
     2399    log_msg(2, tmp);
     2400
     2401    open_progress_form("Reassembling large files",
     2402                       "I am now reassembling all the large files.",
     2403                       "Please wait. This may take some time.",
     2404                       "", total_slices);
     2405    for (bigfileno = 0, finished = FALSE; !finished;) {
     2406        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
     2407        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     2408            log_msg(3,
     2409                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
     2410            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
     2411                    bigfileno + 1,
     2412                    media_descriptor_string(bkpinfo->backup_media_type),
     2413                    g_current_media_number);
     2414            log_msg(3, "Slicename would have been %s",
     2415                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
     2416            // I'm not positive 'just_changed_cds' is even necessary...
     2417            if (just_changed_cds) {
     2418                just_changed_cds = FALSE;
     2419                log_msg(3,
     2420                        "I'll continue to scan this CD for bigfiles to be restored.");
     2421            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
     2422                insist_on_this_cd_number(bkpinfo,
     2423                                         ++g_current_media_number);
     2424                sprintf(tmp, "Restoring from %s #%d",
     2425                        media_descriptor_string(bkpinfo->
     2426                                                backup_media_type),
     2427                        g_current_media_number);
     2428                log_to_screen(tmp);
     2429                just_changed_cds = TRUE;
     2430            } else {
     2431                log_msg(2, "There was no bigfile #%ld. That's OK.",
     2432                        bigfileno + 1);
     2433                log_msg(2, "I'm going to stop restoring bigfiles now.");
     2434                finished = TRUE;
     2435            }
     2436        } else {
     2437            just_changed_cds = FALSE;
     2438            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
     2439            update_progress_form(tmp);
     2440            res =
     2441                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
     2442                                             pathname_of_last_biggie_restored);
     2443            iamhere(pathname_of_last_biggie_restored);
     2444            if (fbw && pathname_of_last_biggie_restored[0]) {
     2445                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
     2446            }
     2447            retval += res;
     2448            bigfileno++;
     2449
     2450        }
     2451    }
     2452
     2453    if (fbw) {
     2454        fclose(fbw);
     2455        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2456        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2457        if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) {
     2458            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
     2459        }
     2460        if (length_of_file(xattr_fname) > 0
     2461            && find_home_of_exe("setfattr")) {
     2462            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
     2463        }
     2464    }
     2465    if (does_file_exist("/PAUSE")) {
     2466        popup_and_OK
     2467            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2468    }
     2469    close_progress_form();
     2470    if (retval) {
     2471        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2472    } else {
     2473        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2474    }
     2475    paranoid_free(xattr_fname);
     2476    paranoid_free(acl_fname);
     2477    paranoid_free(tmp);
     2478    paranoid_free(biggies_whose_EXATs_we_should_set);
     2479    paranoid_free(pathname_of_last_biggie_restored);
     2480    return (retval);
    24592481}
     2482
    24602483/**************************************************************************
    24612484 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
     
    24752498 */
    24762499int
    2477 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist)
     2500restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
     2501                             struct s_node *filelist)
    24782502{
    2479   int retval = 0;
    2480   int res;
    2481   int attempts;
    2482   long current_tarball_number = 0;
    2483   long max_val;
     2503    int retval = 0;
     2504    int res;
     2505    int attempts;
     2506    long current_tarball_number = 0;
     2507    long max_val;
    24842508  /**malloc ***/
    2485   char *tmp;
    2486   char *tarball_fname;
    2487   char *progress_str;
    2488   char *comment;
    2489 
    2490   malloc_string(tmp);
    2491   malloc_string(tarball_fname);
    2492   malloc_string(progress_str);
    2493   malloc_string(comment);
    2494  
    2495   assert(bkpinfo!=NULL);
    2496 
    2497   mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2498   log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
    2499   if ( g_current_media_number != 1)
    2500     {
    2501       log_msg(3, "OK, that's jacked up.");
    2502       g_current_media_number = 1;
    2503     }
    2504   insist_on_this_cd_number( bkpinfo, g_current_media_number);
    2505   read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    2506   max_val = atol(tmp) + 1;
    2507   sprintf(progress_str,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2508   log_to_screen(progress_str);
    2509   open_progress_form("Restoring from archives",
    2510              "Restoring data from the archives." ,
    2511              "Please wait. This may take some time.",
    2512              progress_str,max_val);
    2513   for(;;)
    2514     {
    2515       insist_on_this_cd_number(bkpinfo, g_current_media_number);
    2516       update_progress_form(progress_str);
    2517       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.bz2",current_tarball_number);
    2518       if (!does_file_exist(tarball_fname))
    2519     {
    2520       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.lzo",current_tarball_number);
    2521     }
    2522       if (!does_file_exist(tarball_fname))
    2523     {
    2524       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.",current_tarball_number);
    2525     }
    2526       if (!does_file_exist(tarball_fname))
    2527     {
    2528       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.bz2", current_tarball_number);
    2529     }
    2530       if (!does_file_exist(tarball_fname))
    2531     {
    2532       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.", current_tarball_number);
    2533     }
    2534       if (!does_file_exist(tarball_fname))
    2535     {
    2536       if (current_tarball_number == 0)
    2537         {
    2538           log_to_screen("No tarballs. Strange. Maybe you only backed up freakin' big files?");
    2539           return(0);
    2540         }
    2541       if (!does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST") || system("find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null") == 0 )
    2542         {
    2543           break;
    2544         }
    2545       g_current_media_number++;
    2546       sprintf(progress_str,"Restoring from %s #%d",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2547       log_to_screen(progress_str);
    2548     }
    2549       else
    2550         {
    2551           sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",
    2552                 current_tarball_number,
    2553                 media_descriptor_string(bkpinfo->backup_media_type),
    2554                 g_current_media_number);
    2555 //    log_msg(3, "progress_str = %s", progress_str);
    2556           for(res = 999, attempts = 0; attempts < 3 && res != 0; attempts++)
    2557             {
    2558           res = restore_a_tarball_from_CD(tarball_fname,current_tarball_number, filelist);
    2559         }
    2560           sprintf(tmp,"%s #%d, fileset #%ld - restore ",
    2561         media_descriptor_string(bkpinfo->backup_media_type),
    2562           g_current_media_number,
    2563           current_tarball_number);
    2564           if (res)
    2565         {
    2566           strcat(tmp,"reported errors");
    2567         }
    2568       else if (attempts > 1)
    2569         {
    2570           strcat(tmp,"succeeded");
    2571         }
    2572       else
    2573         {
    2574           strcat(tmp,"succeeded");
    2575         }
    2576           if (attempts > 1)
    2577         {
    2578           sprintf( tmp + strlen(tmp)," (%d attempts) - review logs",attempts);
    2579         }
    2580           strcpy(comment, tmp);
    2581           if (attempts > 1)
    2582         {
    2583           log_to_screen(comment);
    2584         }
    2585          
    2586           retval += res;
    2587           current_tarball_number++;
    2588           g_current_progress++;
    2589         }
    2590     }
    2591   close_progress_form();
    2592   if (retval)
    2593     {
    2594       mvaddstr_and_log_it(g_currentY++,74,"Errors.");
    2595     }
    2596   else
    2597     {
    2598       mvaddstr_and_log_it(g_currentY++,74,"Done.");
    2599     }
    2600   paranoid_free(tmp);
    2601   paranoid_free(tarball_fname);
    2602   paranoid_free(progress_str);
    2603   paranoid_free(comment);
    2604  
    2605   return(retval);
     2509    char *tmp;
     2510    char *tarball_fname;
     2511    char *progress_str;
     2512    char *comment;
     2513
     2514    malloc_string(tmp);
     2515    malloc_string(tarball_fname);
     2516    malloc_string(progress_str);
     2517    malloc_string(comment);
     2518
     2519    assert(bkpinfo != NULL);
     2520
     2521    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
     2522    log_msg(2,
     2523            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
     2524    if (g_current_media_number != 1) {
     2525        log_msg(3, "OK, that's jacked up.");
     2526        g_current_media_number = 1;
     2527    }
     2528    insist_on_this_cd_number(bkpinfo, g_current_media_number);
     2529    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     2530    max_val = atol(tmp) + 1;
     2531    sprintf(progress_str, "Restoring from %s #%d",
     2532            media_descriptor_string(bkpinfo->backup_media_type),
     2533            g_current_media_number);
     2534    log_to_screen(progress_str);
     2535    open_progress_form("Restoring from archives",
     2536                       "Restoring data from the archives.",
     2537                       "Please wait. This may take some time.",
     2538                       progress_str, max_val);
     2539    for (;;) {
     2540        insist_on_this_cd_number(bkpinfo, g_current_media_number);
     2541        update_progress_form(progress_str);
     2542        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
     2543                current_tarball_number);
     2544        if (!does_file_exist(tarball_fname)) {
     2545            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
     2546                    current_tarball_number);
     2547        }
     2548        if (!does_file_exist(tarball_fname)) {
     2549            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
     2550                    current_tarball_number);
     2551        }
     2552        if (!does_file_exist(tarball_fname)) {
     2553            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
     2554                    current_tarball_number);
     2555        }
     2556        if (!does_file_exist(tarball_fname)) {
     2557            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
     2558                    current_tarball_number);
     2559        }
     2560        if (!does_file_exist(tarball_fname)) {
     2561            if (current_tarball_number == 0) {
     2562                log_to_screen
     2563                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
     2564                return (0);
     2565            }
     2566            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
     2567                || system("find " MNT_CDROM
     2568                          "/archives/slice* > /dev/null 2> /dev/null") ==
     2569                0) {
     2570                break;
     2571            }
     2572            g_current_media_number++;
     2573            sprintf(progress_str, "Restoring from %s #%d",
     2574                    media_descriptor_string(bkpinfo->backup_media_type),
     2575                    g_current_media_number);
     2576            log_to_screen(progress_str);
     2577        } else {
     2578            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
     2579                    current_tarball_number,
     2580                    media_descriptor_string(bkpinfo->backup_media_type),
     2581                    g_current_media_number);
     2582//    log_msg(3, "progress_str = %s", progress_str);
     2583            for (res = 999, attempts = 0; attempts < 3 && res != 0;
     2584                 attempts++) {
     2585                res =
     2586                    restore_a_tarball_from_CD(tarball_fname,
     2587                                              current_tarball_number,
     2588                                              filelist);
     2589            }
     2590            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
     2591                    media_descriptor_string(bkpinfo->backup_media_type),
     2592                    g_current_media_number, current_tarball_number);
     2593            if (res) {
     2594                strcat(tmp, "reported errors");
     2595            } else if (attempts > 1) {
     2596                strcat(tmp, "succeeded");
     2597            } else {
     2598                strcat(tmp, "succeeded");
     2599            }
     2600            if (attempts > 1) {
     2601                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
     2602                        attempts);
     2603            }
     2604            strcpy(comment, tmp);
     2605            if (attempts > 1) {
     2606                log_to_screen(comment);
     2607            }
     2608
     2609            retval += res;
     2610            current_tarball_number++;
     2611            g_current_progress++;
     2612        }
     2613    }
     2614    close_progress_form();
     2615    if (retval) {
     2616        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2617    } else {
     2618        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2619    }
     2620    paranoid_free(tmp);
     2621    paranoid_free(tarball_fname);
     2622    paranoid_free(progress_str);
     2623    paranoid_free(comment);
     2624
     2625    return (retval);
    26062626}
    26072627
     
    26202640 */
    26212641int
    2622 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, struct s_node*filelist)
     2642restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
     2643                                    struct s_node *filelist)
    26232644{
    2624   long noof_biggiefiles;
    2625   long current_bigfile_number = 0;
    2626   long total_slices;
    2627 
    2628   int retval = 0;
    2629   int res = 0;
    2630   int ctrl_chr;
     2645    long noof_biggiefiles;
     2646    long current_bigfile_number = 0;
     2647    long total_slices;
     2648
     2649    int retval = 0;
     2650    int res = 0;
     2651    int ctrl_chr;
    26312652
    26322653  /** malloc add ****/
    2633   char *tmp;
    2634   char *biggie_fname;
    2635   char *biggie_cksum;
    2636   char *xattr_fname;
    2637   char *acl_fname;
    2638   char *p;
    2639   char *pathname_of_last_biggie_restored; 
    2640   char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
    2641   long long biggie_size;
    2642   FILE *fbw = NULL;
    2643 
    2644   malloc_string(tmp);
    2645   malloc_string(biggie_fname);
    2646   malloc_string(biggie_cksum);
    2647   malloc_string(xattr_fname);
    2648   malloc_string(acl_fname);
    2649   malloc_string(biggies_whose_EXATs_we_should_set);
    2650   malloc_string(pathname_of_last_biggie_restored);
    2651   assert(bkpinfo!=NULL);
    2652 
    2653   read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    2654 
    2655   total_slices = atol(tmp);
    2656   sprintf(tmp, "Reassembling large files      ");
    2657   sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2658   sprintf(acl_fname,   ACL_BIGGLST_FNAME_RAW_SZ,   bkpinfo->tmpdir);
    2659   mvaddstr_and_log_it( g_currentY, 0, tmp );
    2660   sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    2661   if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w")))
    2662    { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); }
    2663  
     2654    char *tmp;
     2655    char *biggie_fname;
     2656    char *biggie_cksum;
     2657    char *xattr_fname;
     2658    char *acl_fname;
     2659    char *p;
     2660    char *pathname_of_last_biggie_restored;
     2661    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2662    long long biggie_size;
     2663    FILE *fbw = NULL;
     2664
     2665    malloc_string(tmp);
     2666    malloc_string(biggie_fname);
     2667    malloc_string(biggie_cksum);
     2668    malloc_string(xattr_fname);
     2669    malloc_string(acl_fname);
     2670    malloc_string(biggies_whose_EXATs_we_should_set);
     2671    malloc_string(pathname_of_last_biggie_restored);
     2672    assert(bkpinfo != NULL);
     2673
     2674    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
     2675
     2676    total_slices = atol(tmp);
     2677    sprintf(tmp, "Reassembling large files      ");
     2678    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2679    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2680    mvaddstr_and_log_it(g_currentY, 0, tmp);
     2681    sprintf(biggies_whose_EXATs_we_should_set,
     2682            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2683    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     2684        log_msg(1, "Warning - cannot openout %s",
     2685                biggies_whose_EXATs_we_should_set);
     2686    }
    26642687// get xattr and acl files if they're there
    2665   res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr);
    2666   if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    2667     {
    2668       res = read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
    2669     }
    2670 
    2671   noof_biggiefiles = atol( biggie_fname );
    2672   sprintf( tmp, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles );
    2673   log_msg(2, tmp );
    2674   open_progress_form( "Reassembling large files",
    2675               "I am now reassembling all the large files." ,
    2676               "Please wait. This may take some time.",
    2677               "",
    2678               total_slices);
    2679 
    2680   for( res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); ctrl_chr!=BLK_STOP_BIGGIEFILES; res=read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr))
    2681     {
    2682       if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE)
    2683     {
    2684       wrong_marker(BLK_START_A_NORMBIGGIE,ctrl_chr);
    2685     }
    2686       p = strrchr(biggie_fname,'/');
    2687       if (!p)
    2688     {
    2689       p = biggie_fname;
    2690     }
    2691       else
    2692     {
    2693       p++;
    2694     }
    2695       sprintf(tmp,"Restoring big file %ld (%lld K)",current_bigfile_number+1, biggie_size/1024);
    2696       update_progress_form(tmp);
    2697       res = restore_a_biggiefile_from_stream(bkpinfo,biggie_fname,
    2698                          current_bigfile_number,
    2699                          biggie_cksum,
    2700                          biggie_size,
    2701                          filelist, ctrl_chr,
    2702                          pathname_of_last_biggie_restored);
    2703       log_msg(1, "I believe I have restored %s", pathname_of_last_biggie_restored);
    2704       if (fbw && pathname_of_last_biggie_restored[0])
    2705         { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); }
    2706       retval += res;
    2707       current_bigfile_number++;
    2708 
    2709     }
    2710   if (current_bigfile_number != noof_biggiefiles && noof_biggiefiles != 0 )
    2711     {
    2712       sprintf( tmp,
    2713            "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",current_bigfile_number,
    2714            noof_biggiefiles);
    2715     }
    2716   else
    2717     {
    2718       sprintf( tmp,"%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
    2719            noof_biggiefiles,
    2720            current_bigfile_number);
    2721     }
    2722   log_msg(1, tmp);
    2723 
    2724   if (fbw)
    2725     {
    2726       fclose(fbw);
    2727       if (length_of_file(biggies_whose_EXATs_we_should_set) >2)
    2728         {
    2729       iamhere("Setting biggie-EXATs");
    2730           if (length_of_file(acl_fname)  >0)
    2731             {
    2732           log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
    2733           set_acl_list  (biggies_whose_EXATs_we_should_set, acl_fname);
    2734         }
    2735           if (length_of_file(xattr_fname)>0)
    2736             {
    2737           log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
    2738           set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    2739         }
    2740     }
    2741       else
    2742         {
    2743       iamhere("No biggiefiles selected. So, no biggie-EXATs to set.");
    2744     }
    2745     }
    2746   if (does_file_exist("/PAUSE"))
    2747     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2748 
    2749   close_progress_form();
    2750   if (retval)
    2751     {
    2752       mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
    2753     }
    2754   else
    2755     {
    2756       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2757     }
    2758   paranoid_free(biggies_whose_EXATs_we_should_set);
    2759   paranoid_free(pathname_of_last_biggie_restored);
    2760   paranoid_free(biggie_fname);
    2761   paranoid_free(biggie_cksum);
    2762   paranoid_free(xattr_fname);
    2763   paranoid_free(acl_fname);
    2764   paranoid_free(tmp);
    2765   return(retval);
     2688    res =
     2689        read_header_block_from_stream(&biggie_size, biggie_fname,
     2690                                      &ctrl_chr);
     2691    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     2692        res =
     2693            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
     2694                                      &ctrl_chr, xattr_fname, acl_fname);
     2695    }
     2696
     2697    noof_biggiefiles = atol(biggie_fname);
     2698    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     2699            noof_biggiefiles);
     2700    log_msg(2, tmp);
     2701    open_progress_form("Reassembling large files",
     2702                       "I am now reassembling all the large files.",
     2703                       "Please wait. This may take some time.",
     2704                       "", total_slices);
     2705
     2706    for (res =
     2707         read_header_block_from_stream(&biggie_size, biggie_fname,
     2708                                       &ctrl_chr);
     2709         ctrl_chr != BLK_STOP_BIGGIEFILES;
     2710         res =
     2711         read_header_block_from_stream(&biggie_size, biggie_fname,
     2712                                       &ctrl_chr)) {
     2713        if (ctrl_chr != BLK_START_A_NORMBIGGIE
     2714            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
     2715            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
     2716        }
     2717        p = strrchr(biggie_fname, '/');
     2718        if (!p) {
     2719            p = biggie_fname;
     2720        } else {
     2721            p++;
     2722        }
     2723        sprintf(tmp, "Restoring big file %ld (%lld K)",
     2724                current_bigfile_number + 1, biggie_size / 1024);
     2725        update_progress_form(tmp);
     2726        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
     2727                                               current_bigfile_number,
     2728                                               biggie_cksum,
     2729                                               biggie_size,
     2730                                               filelist, ctrl_chr,
     2731                                               pathname_of_last_biggie_restored);
     2732        log_msg(1, "I believe I have restored %s",
     2733                pathname_of_last_biggie_restored);
     2734        if (fbw && pathname_of_last_biggie_restored[0]) {
     2735            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
     2736        }
     2737        retval += res;
     2738        current_bigfile_number++;
     2739
     2740    }
     2741    if (current_bigfile_number != noof_biggiefiles
     2742        && noof_biggiefiles != 0) {
     2743        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
     2744                current_bigfile_number, noof_biggiefiles);
     2745    } else {
     2746        sprintf(tmp,
     2747                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
     2748                noof_biggiefiles, current_bigfile_number);
     2749    }
     2750    log_msg(1, tmp);
     2751
     2752    if (fbw) {
     2753        fclose(fbw);
     2754        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
     2755            iamhere("Setting biggie-EXATs");
     2756            if (length_of_file(acl_fname) > 0) {
     2757                log_msg(1, "set_acl_list(%s,%s)",
     2758                        biggies_whose_EXATs_we_should_set, acl_fname);
     2759                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
     2760            }
     2761            if (length_of_file(xattr_fname) > 0) {
     2762                log_msg(1, "set_fattr_List(%s,%s)",
     2763                        biggies_whose_EXATs_we_should_set, xattr_fname);
     2764                set_fattr_list(biggies_whose_EXATs_we_should_set,
     2765                               xattr_fname);
     2766            }
     2767        } else {
     2768            iamhere
     2769                ("No biggiefiles selected. So, no biggie-EXATs to set.");
     2770        }
     2771    }
     2772    if (does_file_exist("/PAUSE")) {
     2773        popup_and_OK
     2774            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2775    }
     2776
     2777    close_progress_form();
     2778    if (retval) {
     2779        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2780    } else {
     2781        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2782    }
     2783    paranoid_free(biggies_whose_EXATs_we_should_set);
     2784    paranoid_free(pathname_of_last_biggie_restored);
     2785    paranoid_free(biggie_fname);
     2786    paranoid_free(biggie_cksum);
     2787    paranoid_free(xattr_fname);
     2788    paranoid_free(acl_fname);
     2789    paranoid_free(tmp);
     2790    return (retval);
    27662791}
     2792
    27672793/**************************************************************************
    27682794 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
     
    27852811 */
    27862812int
    2787 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
     2813restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
     2814                                 struct s_node *filelist)
    27882815{
    2789   int retval = 0;
    2790   int res;
    2791   long current_afioball_number = 0;
    2792   int ctrl_chr;
    2793   long max_val /*, total_noof_files */;
     2816    int retval = 0;
     2817    int res;
     2818    long current_afioball_number = 0;
     2819    int ctrl_chr;
     2820    long max_val /*, total_noof_files */ ;
    27942821
    27952822  /** malloc **/
    2796   char *tmp;
    2797   char *progress_str;
    2798   char *tmp_fname;
    2799   char *xattr_fname;
    2800   char *acl_fname;
    2801 
    2802   long long tmp_size;
    2803 
    2804   malloc_string(tmp);
    2805   malloc_string(progress_str);
    2806   malloc_string(tmp_fname);
    2807   assert(bkpinfo!=NULL);
    2808   malloc_string(xattr_fname);
    2809   malloc_string(acl_fname);
    2810   mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2811   read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    2812   max_val = atol(tmp) + 1;
    2813 
    2814   chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
    2815 
    2816   run_program_and_log_output("pwd", 5);
    2817 
    2818   sprintf(progress_str,"Restoring from media #%d",g_current_media_number);
    2819   log_to_screen(progress_str);
    2820   open_progress_form("Restoring from archives",
    2821              "Restoring data from the archives." ,
    2822              "Please wait. This may take some time.",
    2823              progress_str,max_val);
    2824 
    2825   log_msg(3, "hey");
    2826 
    2827   res = read_header_block_from_stream( &tmp_size, tmp_fname, &ctrl_chr);
    2828   if (res)
    2829     {
    2830       log_msg(2, "Warning - error reading afioball from tape");
    2831     }
    2832   retval += res;
    2833   if ( ctrl_chr != BLK_START_AFIOBALLS)
    2834     {
    2835       wrong_marker(BLK_START_AFIOBALLS,ctrl_chr);
    2836     }
    2837   log_msg(2, "ho");
    2838   res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2839   while(ctrl_chr!=BLK_STOP_AFIOBALLS)
    2840     {
    2841       update_progress_form(progress_str);
    2842       sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    2843       sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    2844       unlink(xattr_fname);
    2845       unlink(acl_fname);
    2846       if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    2847         {
    2848       iamhere("Reading EXAT files from tape");
    2849       res = read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
    2850         }
    2851       if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE)
    2852         { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); }
    2853       sprintf(tmp,
    2854           "Restoring from fileset #%ld (name=%s, size=%ld K)",
    2855           current_afioball_number,
    2856           tmp_fname,
    2857           (long) tmp_size>>10);
    2858       res = restore_a_tarball_from_stream(bkpinfo,tmp_fname,current_afioball_number,filelist,tmp_size, xattr_fname, acl_fname);
    2859       retval += res;
    2860       if ( res )
    2861         {
    2862       sprintf(tmp,"Fileset %ld - errors occurred",current_afioball_number);
    2863       log_to_screen(tmp);
    2864     }
    2865       res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2866       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    2867     {
    2868       wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE,ctrl_chr);
    2869     }
    2870 
    2871       current_afioball_number++;
    2872       g_current_progress++;
    2873       sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",current_afioball_number, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);     
    2874       res=read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2875       unlink(xattr_fname);
    2876       unlink(acl_fname);
    2877     } // next
    2878   log_msg(1, "All done with afioballs");
    2879   close_progress_form();
    2880   if (retval)
    2881     {
    2882       mvaddstr_and_log_it(g_currentY++,74,"Errors."); }
    2883   else
    2884     {
    2885       mvaddstr_and_log_it(g_currentY++,74,"Done."); }
    2886   paranoid_free(tmp);
    2887   paranoid_free(progress_str);
    2888   paranoid_free(tmp_fname);
    2889   paranoid_free(xattr_fname);
    2890   paranoid_free(acl_fname);
    2891   return(retval);
     2823    char *tmp;
     2824    char *progress_str;
     2825    char *tmp_fname;
     2826    char *xattr_fname;
     2827    char *acl_fname;
     2828
     2829    long long tmp_size;
     2830
     2831    malloc_string(tmp);
     2832    malloc_string(progress_str);
     2833    malloc_string(tmp_fname);
     2834    assert(bkpinfo != NULL);
     2835    malloc_string(xattr_fname);
     2836    malloc_string(acl_fname);
     2837    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
     2838    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     2839    max_val = atol(tmp) + 1;
     2840
     2841    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
     2842
     2843    run_program_and_log_output("pwd", 5);
     2844
     2845    sprintf(progress_str, "Restoring from media #%d",
     2846            g_current_media_number);
     2847    log_to_screen(progress_str);
     2848    open_progress_form("Restoring from archives",
     2849                       "Restoring data from the archives.",
     2850                       "Please wait. This may take some time.",
     2851                       progress_str, max_val);
     2852
     2853    log_msg(3, "hey");
     2854
     2855    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2856    if (res) {
     2857        log_msg(2, "Warning - error reading afioball from tape");
     2858    }
     2859    retval += res;
     2860    if (ctrl_chr != BLK_START_AFIOBALLS) {
     2861        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
     2862    }
     2863    log_msg(2, "ho");
     2864    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2865    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
     2866        update_progress_form(progress_str);
     2867        sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
     2868                current_afioball_number);
     2869        sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
     2870                current_afioball_number);
     2871        unlink(xattr_fname);
     2872        unlink(acl_fname);
     2873        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     2874            iamhere("Reading EXAT files from tape");
     2875            res =
     2876                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
     2877                                          &ctrl_chr, xattr_fname,
     2878                                          acl_fname);
     2879        }
     2880        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     2881            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     2882        }
     2883        sprintf(tmp,
     2884                "Restoring from fileset #%ld (name=%s, size=%ld K)",
     2885                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
     2886        res =
     2887            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
     2888                                          current_afioball_number,
     2889                                          filelist, tmp_size, xattr_fname,
     2890                                          acl_fname);
     2891        retval += res;
     2892        if (res) {
     2893            sprintf(tmp, "Fileset %ld - errors occurred",
     2894                    current_afioball_number);
     2895            log_to_screen(tmp);
     2896        }
     2897        res =
     2898            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2899        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     2900            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     2901        }
     2902
     2903        current_afioball_number++;
     2904        g_current_progress++;
     2905        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
     2906                current_afioball_number,
     2907                media_descriptor_string(bkpinfo->backup_media_type),
     2908                g_current_media_number);
     2909        res =
     2910            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2911        unlink(xattr_fname);
     2912        unlink(acl_fname);
     2913    }                           // next
     2914    log_msg(1, "All done with afioballs");
     2915    close_progress_form();
     2916    if (retval) {
     2917        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2918    } else {
     2919        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2920    }
     2921    paranoid_free(tmp);
     2922    paranoid_free(progress_str);
     2923    paranoid_free(tmp_fname);
     2924    paranoid_free(xattr_fname);
     2925    paranoid_free(acl_fname);
     2926    return (retval);
    28922927}
     2928
    28932929/**************************************************************************
    28942930 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
     
    29062942 * @ingroup restoreGroup
    29072943 */
    2908 int
    2909 restore_everything(struct s_bkpinfo*bkpinfo,
    2910            struct s_node *filelist)
     2944int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
    29112945{
    2912   int resA;
    2913   int resB;
     2946    int resA;
     2947    int resB;
    29142948
    29152949  /** mallco ***/
    2916   char *cwd;
    2917   char *newpath;
    2918   char *tmp;
    2919   assert(bkpinfo!=NULL);
    2920 
    2921   malloc_string(cwd);
    2922   malloc_string(newpath);
    2923   malloc_string(tmp);
    2924   log_msg(2, "restore_everything() --- starting");
    2925   g_current_media_number = 1;
    2926   getcwd(cwd, MAX_STR_LEN - 1);
    2927   sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
    2928   run_program_and_log_output(tmp, FALSE);
    2929   log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
    2930   chdir(bkpinfo->restore_path);
    2931   getcwd(newpath,MAX_STR_LEN-1);
    2932   log_msg(1, "path is now %s", newpath);
    2933   log_msg(1, "restoring everything");
    2934   if (!find_home_of_exe("petris") && !g_text_mode)
    2935     {
    2936       newtDrawRootText(0, g_noof_rows-2, "Press ALT-<left cursor> twice to play Petris :-) ");
    2937       newtRefresh();
    2938     }
    2939   mvaddstr_and_log_it (g_currentY, 0, "Preparing to read your archives");
    2940   if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) )
    2941     {
    2942       mount_cdrom( bkpinfo );
    2943       mvaddstr_and_log_it ( g_currentY++, 0, "Restoring OS and data from streaming media");
    2944       if (bkpinfo->backup_media_type == cdstream)
    2945         {
    2946       openin_cdstream( bkpinfo );
    2947     }
    2948       else
    2949         {
    2950       assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
    2951       openin_tape(bkpinfo);
    2952     }
    2953       resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
    2954       resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
    2955       if (bkpinfo->backup_media_type == cdstream)
    2956         {
    2957       closein_cdstream(bkpinfo);
    2958     }
    2959       else
    2960         {
    2961       closein_tape(bkpinfo);
    2962     }
    2963     }
    2964   else
    2965     {
    2966       mvaddstr_and_log_it (g_currentY++, 0, "Restoring OS and data from CD       ");
    2967       mount_cdrom(bkpinfo);
    2968       resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
    2969       resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
    2970     }
    2971   chdir(cwd);
    2972   if ( resA + resB )
    2973     {
    2974       log_to_screen("Errors occurred while data was being restored.");
    2975     }
    2976   if ( length_of_file("/etc/raidtab") > 0 )
    2977     {
    2978       log_msg(2, "Copying local raidtab to restored filesystem");
    2979       run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING "/etc/raidtab", FALSE);
    2980     }
    2981   kill_petris();
    2982   log_msg(2, "restore_everything() --- leaving");
    2983   paranoid_free(cwd);
    2984   paranoid_free(newpath);
    2985   paranoid_free(tmp);
    2986   return(resA+resB);
     2950    char *cwd;
     2951    char *newpath;
     2952    char *tmp;
     2953    assert(bkpinfo != NULL);
     2954
     2955    malloc_string(cwd);
     2956    malloc_string(newpath);
     2957    malloc_string(tmp);
     2958    log_msg(2, "restore_everything() --- starting");
     2959    g_current_media_number = 1;
     2960    getcwd(cwd, MAX_STR_LEN - 1);
     2961    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
     2962    run_program_and_log_output(tmp, FALSE);
     2963    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
     2964    chdir(bkpinfo->restore_path);
     2965    getcwd(newpath, MAX_STR_LEN - 1);
     2966    log_msg(1, "path is now %s", newpath);
     2967    log_msg(1, "restoring everything");
     2968    if (!find_home_of_exe("petris") && !g_text_mode) {
     2969        newtDrawRootText(0, g_noof_rows - 2,
     2970                         "Press ALT-<left cursor> twice to play Petris :-) ");
     2971        newtRefresh();
     2972    }
     2973    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
     2974    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2975        mount_cdrom(bkpinfo);
     2976        mvaddstr_and_log_it(g_currentY++, 0,
     2977                            "Restoring OS and data from streaming media");
     2978        if (bkpinfo->backup_media_type == cdstream) {
     2979            openin_cdstream(bkpinfo);
     2980        } else {
     2981            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
     2982                                                         media_device);
     2983            openin_tape(bkpinfo);
     2984        }
     2985        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
     2986        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
     2987        if (bkpinfo->backup_media_type == cdstream) {
     2988            closein_cdstream(bkpinfo);
     2989        } else {
     2990            closein_tape(bkpinfo);
     2991        }
     2992    } else {
     2993        mvaddstr_and_log_it(g_currentY++, 0,
     2994                            "Restoring OS and data from CD       ");
     2995        mount_cdrom(bkpinfo);
     2996        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
     2997        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
     2998    }
     2999    chdir(cwd);
     3000    if (resA + resB) {
     3001        log_to_screen("Errors occurred while data was being restored.");
     3002    }
     3003    if (length_of_file("/etc/raidtab") > 0) {
     3004        log_msg(2, "Copying local raidtab to restored filesystem");
     3005        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
     3006                                   "/etc/raidtab", FALSE);
     3007    }
     3008    kill_petris();
     3009    log_msg(2, "restore_everything() --- leaving");
     3010    paranoid_free(cwd);
     3011    paranoid_free(newpath);
     3012    paranoid_free(tmp);
     3013    return (resA + resB);
    29873014}
    29883015
     
    29973024 */
    29983025int
    2999 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 
    3000                 char *monitas_device,
    3001                  char *restore_this_directory,
    3002                 char *restore_here)
    3003     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
     3026restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
     3027                                char *monitas_device,
     3028                                 char *restore_this_directory,
     3029                                char *restore_here)
     3030    /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
    30043031{
    3005   FILE *fout;
    3006   int retval = 0;
    3007   int i;
    3008   int j;
    3009   struct mountlist_itself the_mountlist;
    3010   static struct raidlist_itself the_raidlist;
     3032    FILE *fout;
     3033    int retval = 0;
     3034    int i;
     3035    int j;
     3036    struct mountlist_itself the_mountlist;
     3037    static struct raidlist_itself the_raidlist;
    30113038  /** malloc **/
    3012   char tmp[ MAX_STR_LEN + 1 ];
    3013   char command[ MAX_STR_LEN + 1 ];
    3014   char datablock[ 256 * 1024 ];
    3015   char datadisks_fname[ MAX_STR_LEN + 1 ];
    3016   long k;
    3017   long length;
    3018   long long llt;
    3019   struct s_node *filelist = NULL;
    3020   assert(bkpinfo!=NULL);
    3021   assert_string_is_neither_NULL_nor_zerolength(monitas_device);
    3022   assert(restore_this_directory != NULL);
    3023   assert(restore_here != NULL);
    3024 
    3025   sprintf(tmp, "restore_here = '%s'", restore_here);
    3026 
    3027   log_msg(2, tmp);
    3028  
    3029   log_msg(2, "restore_live_from_monitas_server() - starting");
    3030   unlink("/tmp/mountlist.txt"); unlink("/tmp/filelist.full");
    3031   unlink("/tmp/biggielist.txt");
    3032   if ( restore_here[0] == '\0' )
    3033     {
    3034       strcpy(bkpinfo->restore_path, MNT_RESTORING);
    3035     }
    3036   else
    3037     {
    3038       strcpy(bkpinfo->restore_path, restore_here);
    3039     }
    3040   log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3041   sprintf(tmp, "FYI - data will be restored to %s", bkpinfo->restore_path);
    3042   log_msg(3, tmp);
    3043   log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3044   sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", (int)(random()%32768));
    3045   chdir(bkpinfo->tmpdir);
    3046 
    3047   sprintf(command, "cat %s", monitas_device);
    3048   g_tape_stream=popen(command, "r"); // for compatibility with openin_tape()
    3049   if (!(fout = fopen(datadisks_fname, "w"))) { log_OS_error(datadisks_fname); return(1); }
    3050   for (i = 0; i < 32; i++)
    3051     {
    3052       for (j = 0; j < 4; j++)
    3053         {
    3054           for( length = k = 0; length < 256 * 1024; length += k)
    3055             {
    3056               k = fread( datablock + length, 1, 256 * 1024 - length, g_tape_stream);
    3057             }
    3058           fwrite (datablock, 1, length, fout);
    3059           g_tape_posK += length;
    3060         }
    3061     }
    3062   paranoid_fclose(fout);
    3063   sprintf( command,
    3064        "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
    3065        datadisks_fname);
    3066   run_program_and_log_output(command, 4);
    3067   read_header_block_from_stream (&llt, tmp, &i);
    3068   read_header_block_from_stream (&llt, tmp, &i);
    3069 
    3070   unlink(datadisks_fname);
    3071   read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    3072   retval = load_mountlist( &the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
    3073  
    3074 
    3075   load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME );
    3076   iamhere("FIXME");
    3077   fatal_error("This will fail");
    3078   sprintf( command,
    3079        "cat %s | grep -x \"%s.*\" > %s",
    3080        g_filelist_full,
    3081        restore_this_directory,
    3082        g_filelist_full);
    3083   if (system(command))
    3084     {
    3085       retval++;
    3086       log_to_screen("Error(s) occurred while processing filelist and wildcard");
    3087     }
    3088   iamhere("FIXME");
    3089   fatal_error("This will fail");
    3090   sprintf(command,
    3091       "cat %s | grep -x \"%s.*\" > %s",
    3092       g_biggielist_txt,
    3093       restore_this_directory,
    3094       g_biggielist_txt);
    3095   if (system(command))
    3096     {
    3097       log_msg(1, "Error(s) occurred while processing biggielist and wildcard");
    3098     }
    3099   sprintf(command, "touch %s", g_biggielist_txt);
    3100   run_program_and_log_output(command, FALSE);
     3039    char tmp[MAX_STR_LEN + 1];
     3040    char command[MAX_STR_LEN + 1];
     3041    char datablock[256 * 1024];
     3042    char datadisks_fname[MAX_STR_LEN + 1];
     3043    long k;
     3044    long length;
     3045    long long llt;
     3046    struct s_node *filelist = NULL;
     3047    assert(bkpinfo != NULL);
     3048    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
     3049    assert(restore_this_directory != NULL);
     3050    assert(restore_here != NULL);
     3051
     3052    sprintf(tmp, "restore_here = '%s'", restore_here);
     3053
     3054    log_msg(2, tmp);
     3055
     3056    log_msg(2, "restore_live_from_monitas_server() - starting");
     3057    unlink("/tmp/mountlist.txt");
     3058    unlink("/tmp/filelist.full");
     3059    unlink("/tmp/biggielist.txt");
     3060    if (restore_here[0] == '\0') {
     3061        strcpy(bkpinfo->restore_path, MNT_RESTORING);
     3062    } else {
     3063        strcpy(bkpinfo->restore_path, restore_here);
     3064    }
     3065    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
     3066    sprintf(tmp, "FYI - data will be restored to %s",
     3067            bkpinfo->restore_path);
     3068    log_msg(3, tmp);
     3069    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
     3070    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
     3071            (int) (random() % 32768));
     3072    chdir(bkpinfo->tmpdir);
     3073
     3074    sprintf(command, "cat %s", monitas_device);
     3075    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
     3076    if (!(fout = fopen(datadisks_fname, "w"))) {
     3077        log_OS_error(datadisks_fname);
     3078        return (1);
     3079    }
     3080    for (i = 0; i < 32; i++) {
     3081        for (j = 0; j < 4; j++) {
     3082            for (length = k = 0; length < 256 * 1024; length += k) {
     3083                k = fread(datablock + length, 1, 256 * 1024 - length,
     3084                          g_tape_stream);
     3085            }
     3086            fwrite(datablock, 1, length, fout);
     3087            g_tape_posK += length;
     3088        }
     3089    }
     3090    paranoid_fclose(fout);
     3091    sprintf(command,
     3092            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
     3093            datadisks_fname);
     3094    run_program_and_log_output(command, 4);
     3095    read_header_block_from_stream(&llt, tmp, &i);
     3096    read_header_block_from_stream(&llt, tmp, &i);
     3097
     3098    unlink(datadisks_fname);
     3099    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     3100    retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
     3101
     3102
     3103    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
     3104    iamhere("FIXME");
     3105    fatal_error("This will fail");
     3106    sprintf(command,
     3107            "cat %s | grep -x \"%s.*\" > %s",
     3108            g_filelist_full, restore_this_directory, g_filelist_full);
     3109    if (system(command)) {
     3110        retval++;
     3111        log_to_screen
     3112            ("Error(s) occurred while processing filelist and wildcard");
     3113    }
     3114    iamhere("FIXME");
     3115    fatal_error("This will fail");
     3116    sprintf(command,
     3117            "cat %s | grep -x \"%s.*\" > %s",
     3118            g_biggielist_txt, restore_this_directory, g_biggielist_txt);
     3119    if (system(command)) {
     3120        log_msg(1,
     3121                "Error(s) occurred while processing biggielist and wildcard");
     3122    }
     3123    sprintf(command, "touch %s", g_biggielist_txt);
     3124    run_program_and_log_output(command, FALSE);
    31013125//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
    3102   retval += restore_everything(bkpinfo, filelist);
    3103   free_filelist(filelist);
    3104   log_msg(2, "--------End of restore_live_from_monitas_server--------");
    3105   return(retval);
     3126    retval += restore_everything(bkpinfo, filelist);
     3127    free_filelist(filelist);
     3128    log_msg(2, "--------End of restore_live_from_monitas_server--------");
     3129    return (retval);
    31063130}
     3131
    31073132/**************************************************************************
    31083133 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
     
    31123137
    31133138
    3114 extern void wait_until_software_raids_are_prepped(char*, int);
     3139extern void wait_until_software_raids_are_prepped(char *, int);
    31153140
    31163141
     
    31233148void welcome_to_mondorestore()
    31243149{
    3125   log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
    3126   log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please " );
    3127   log_msg(0, "don't break out in a cold sweat just because you see a few  " );
    3128   log_msg(0, "error messages in the log. Read them; analyze them; see if  " );
    3129   log_msg(0, "they are significant; above all, verify your backups! Please" );
    3130   log_msg(0, "attach a compressed copy of this log to any e-mail you send " );
    3131   log_msg(0, "to the Mondo mailing list when you are seeking technical    " );
    3132   log_msg(0, "support. Without it, we can't help you.               - Hugo" );
    3133   log_msg(0, "------------------------------------------------------------" );
    3134   log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages," );
    3135   log_msg(0, "some users are inclined to stop reading this log.  If Mondo " );
    3136   log_msg(0, "stopped for some reason, chances are it's detailed here.    " );
    3137   log_msg(0, "More than likely there's a message at the very end of this  " );
    3138   log_msg(0, "log that will tell you what is wrong.  Please read it!      " );
    3139   log_msg(0, "------------------------------------------------------------");
     3150    log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
     3151    log_msg(0,
     3152            "DON'T PANIC! Mondorestore logs almost everything, so please ");
     3153    log_msg(0,
     3154            "don't break out in a cold sweat just because you see a few  ");
     3155    log_msg(0,
     3156            "error messages in the log. Read them; analyze them; see if  ");
     3157    log_msg(0,
     3158            "they are significant; above all, verify your backups! Please");
     3159    log_msg(0,
     3160            "attach a compressed copy of this log to any e-mail you send ");
     3161    log_msg(0,
     3162            "to the Mondo mailing list when you are seeking technical    ");
     3163    log_msg(0,
     3164            "support. Without it, we can't help you.               - Hugo");
     3165    log_msg(0,
     3166            "------------------------------------------------------------");
     3167    log_msg(0,
     3168            "BTW, despite (or perhaps because of) the wealth of messages,");
     3169    log_msg(0,
     3170            "some users are inclined to stop reading this log.  If Mondo ");
     3171    log_msg(0,
     3172            "stopped for some reason, chances are it's detailed here.    ");
     3173    log_msg(0,
     3174            "More than likely there's a message at the very end of this  ");
     3175    log_msg(0,
     3176            "log that will tell you what is wrong.  Please read it!      ");
     3177    log_msg(0,
     3178            "------------------------------------------------------------");
    31403179}
    31413180
     
    31463185 * What did you think it did, anyway? :-)
    31473186 */
    3148 int
    3149 main(int argc, char*argv[])
     3187int main(int argc, char *argv[])
    31503188{
    3151       FILE*fin;
    3152       FILE*fout;
    3153   int retval = 0;
    3154   int res;
     3189    FILE *fin;
     3190    FILE *fout;
     3191    int retval = 0;
     3192    int res;
    31553193//  int c;
    3156   char *tmp;
     3194    char *tmp;
    31573195
    31583196#ifndef VERSION
     
    31603198#endif
    31613199
    3162   struct mountlist_itself    *mountlist;
    3163   struct raidlist_itself      *raidlist;
    3164   struct s_bkpinfo            *bkpinfo;
    3165   struct s_node *filelist;
    3166   char *a, *b;
     3200    struct mountlist_itself *mountlist;
     3201    struct raidlist_itself *raidlist;
     3202    struct s_bkpinfo *bkpinfo;
     3203    struct s_node *filelist;
     3204    char *a, *b;
    31673205
    31683206  /**************************************************************************
     
    31713209   *                                                                        *
    31723210   **************************************************************************/
    3173   if (getuid () != 0)
    3174     {
    3175       fprintf (stderr, "Please run as root.\r\n");
    3176       exit (127);
    3177     }
    3178 
    3179   g_loglevel = DEFAULT_MR_LOGLEVEL;
    3180   malloc_string(tmp);
    3181  
     3211    if (getuid() != 0) {
     3212        fprintf(stderr, "Please run as root.\r\n");
     3213        exit(127);
     3214    }
     3215
     3216    g_loglevel = DEFAULT_MR_LOGLEVEL;
     3217    malloc_string(tmp);
     3218
    31823219/* Configure global variables */
    31833220#ifdef __FreeBSD__
    3184   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly"))
     3221    if (strstr
     3222        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     3223         "textonly"))
    31853224#else
    3186   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly"))
     3225    if (strstr
     3226        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     3227         "textonly"))
    31873228#endif
    3188     { g_text_mode = TRUE; log_msg(1, "TEXTONLY MODE"); }
    3189   else
    3190     { g_text_mode = FALSE; }               // newt :-)
    3191   if ( ! ( bkpinfo = g_bkpinfo_DONTUSETHIS = malloc( sizeof(struct s_bkpinfo))))
    3192     { fatal_error( "Cannot malloc bkpinfo" ); }
    3193   if ( ! ( mountlist = malloc (sizeof(struct mountlist_itself))))
    3194     { fatal_error ("Cannot malloc mountlist" ); }
    3195   if ( ! ( raidlist = malloc (sizeof(struct raidlist_itself))))
    3196     { fatal_error ("Cannot malloc raidlist" ); }
    3197 
    3198   malloc_libmondo_global_strings();
    3199 
    3200   strcpy( g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore") );
    3201   sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
    3202   make_hole_for_dir(g_tmpfs_mountpt);
    3203   g_current_media_number = 1;        // precaution
    3204 
    3205   run_program_and_log_output ("mkdir -p " MNT_CDROM, FALSE);
    3206   run_program_and_log_output ("mkdir -p /mnt/floppy", FALSE);
    3207 
    3208   malloc_string(tmp);
    3209   malloc_string(a);
    3210   malloc_string(b);
    3211   setup_MR_global_filenames( bkpinfo ); // malloc() and set globals, using bkpinfo->tmpdir etc.
    3212   reset_bkpinfo( bkpinfo );
    3213   bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
    3214   bkpinfo->restore_data = TRUE;      // Well, yeah :-)
    3215   if (am_I_in_disaster_recovery_mode())
    3216     { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros
    3217   g_main_pid = getpid();
    3218   srandom( (int)(time(NULL)) );
    3219   register_pid( getpid(), "mondo" );
    3220   set_signals(TRUE);
    3221   g_kernel_version = get_kernel_version();
    3222 
    3223   log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
    3224   if (strlen(g_mountlist_fname) < 3)
    3225     { fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc."); }
    3226   mkdir(MNT_CDROM, 0x770);
    3227  
     3229    {
     3230        g_text_mode = TRUE;
     3231        log_msg(1, "TEXTONLY MODE");
     3232    } else {
     3233        g_text_mode = FALSE;
     3234    }                           // newt :-)
     3235    if (!
     3236        (bkpinfo = g_bkpinfo_DONTUSETHIS =
     3237         malloc(sizeof(struct s_bkpinfo)))) {
     3238        fatal_error("Cannot malloc bkpinfo");
     3239    }
     3240    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
     3241        fatal_error("Cannot malloc mountlist");
     3242    }
     3243    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
     3244        fatal_error("Cannot malloc raidlist");
     3245    }
     3246
     3247    malloc_libmondo_global_strings();
     3248
     3249    strcpy(g_mondo_home,
     3250           call_program_and_get_last_line_of_output("which mondorestore"));
     3251    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
     3252    make_hole_for_dir(g_tmpfs_mountpt);
     3253    g_current_media_number = 1; // precaution
     3254
     3255    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
     3256    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
     3257
     3258    malloc_string(tmp);
     3259    malloc_string(a);
     3260    malloc_string(b);
     3261    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
     3262    reset_bkpinfo(bkpinfo);
     3263    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     3264    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
     3265    if (am_I_in_disaster_recovery_mode()) {
     3266        run_program_and_log_output("mount / -o remount,rw", 2);
     3267    }                           // for b0rken distros
     3268    g_main_pid = getpid();
     3269    srandom((int) (time(NULL)));
     3270    register_pid(getpid(), "mondo");
     3271    set_signals(TRUE);
     3272    g_kernel_version = get_kernel_version();
     3273
     3274    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
     3275    if (strlen(g_mountlist_fname) < 3) {
     3276        fatal_error
     3277            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
     3278    }
     3279    mkdir(MNT_CDROM, 0x770);
     3280
    32283281/* Backup original mountlist.txt */
    3229   sprintf (tmp, "%s.orig", g_mountlist_fname);
    3230   if (!does_file_exist(g_mountlist_fname))
    3231     {
    3232       log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
    3233     }
    3234   else if ( !does_file_exist(tmp) )
    3235     {
    3236        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
    3237        run_program_and_log_output(tmp, FALSE);
    3238     }
     3282    sprintf(tmp, "%s.orig", g_mountlist_fname);
     3283    if (!does_file_exist(g_mountlist_fname)) {
     3284        log_msg(2,
     3285                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
     3286                __LINE__, g_mountlist_fname);
     3287    } else if (!does_file_exist(tmp)) {
     3288        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
     3289                g_mountlist_fname);
     3290        run_program_and_log_output(tmp, FALSE);
     3291    }
    32393292
    32403293/* Init directories */
    3241   make_hole_for_dir(bkpinfo->tmpdir);
    3242   sprintf( tmp, "mkdir -p %s", bkpinfo->tmpdir );
    3243   run_program_and_log_output( tmp, FALSE );
    3244   make_hole_for_dir( "/var/log");
    3245   make_hole_for_dir( "/tmp/tmpfs"); /* just in case... */
    3246   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    3247   run_program_and_log_output( "ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", FALSE );
    3248 
    3249   run_program_and_log_output( "rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
     3294    make_hole_for_dir(bkpinfo->tmpdir);
     3295    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
     3296    run_program_and_log_output(tmp, FALSE);
     3297    make_hole_for_dir("/var/log");
     3298    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
     3299    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3300    run_program_and_log_output
     3301        ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
     3302         FALSE);
     3303
     3304    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
    32503305
    32513306/* Init GUI */
    3252   malloc_libmondo_global_strings();
    3253   setup_newt_stuff();                       /* call newtInit and setup screen log */
    3254   welcome_to_mondorestore();
    3255   if ( bkpinfo->disaster_recovery )
    3256     { log_msg(1, "I am in disaster recovery mode" ); }
    3257   else
    3258     { log_msg(1, "I am in normal, live mode" ); }
    3259 
    3260   iamhere("what time is it");
     3307    malloc_libmondo_global_strings();
     3308    setup_newt_stuff();         /* call newtInit and setup screen log */
     3309    welcome_to_mondorestore();
     3310    if (bkpinfo->disaster_recovery) {
     3311        log_msg(1, "I am in disaster recovery mode");
     3312    } else {
     3313        log_msg(1, "I am in normal, live mode");
     3314    }
     3315
     3316    iamhere("what time is it");
    32613317
    32623318/* Process command-line parameters */
    3263   if (argc == 2 && strcmp( argv[1], "--edit-mountlist" ) == 0 )
    3264     {
     3319    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
    32653320#ifdef __FreeBSD__
    3266     system ("mv -f /tmp/raidconf.txt /etc/raidtab");
    3267     if (!does_file_exist ("/etc/raidtab"))
    3268         system ("vinum printconfig > /etc/raidtab");
     3321        system("mv -f /tmp/raidconf.txt /etc/raidtab");
     3322        if (!does_file_exist("/etc/raidtab"))
     3323            system("vinum printconfig > /etc/raidtab");
    32693324#endif
    3270       load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3271       if (!does_file_exist(g_mountlist_fname)) { strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); }
    3272       res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
     3325        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3326        if (!does_file_exist(g_mountlist_fname)) {
     3327            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3328        }
     3329        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
    32733330#ifdef __FreeBSD__
    3274       system ("mv -f /etc/raidtab /tmp/raidconf.txt");
     3331        system("mv -f /etc/raidtab /tmp/raidconf.txt");
    32753332#endif
    3276       paranoid_MR_finish(res);
    3277     }
    3278 
    3279   g_loglevel = DEFAULT_MR_LOGLEVEL;
    3280   if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0)
    3281     {
    3282       fout = fopen("/tmp/out.txt", "w");
    3283       fput_string_one_char_at_a_time(stderr, argv[2]);
    3284       finish(0);
    3285     }     
    3286 
    3287   if (argc == 3 && strcmp( argv[1], "--gendf" ) == 0 )
    3288     {
    3289       make_grub_install_scriptlet(argv[2]);
    3290       finish(0);
    3291     }
    3292 
    3293   if (argc >= 2 && strcmp(argv[1], "--pih" ) == 0 )
    3294     {
    3295       if (system("mount | grep cdrom 2> /dev/null > /dev/null"))
    3296         { system("mount "MNT_CDROM); }
    3297       bkpinfo->compression_level = 1;
    3298       g_current_media_number = 2;
    3299       strcpy(bkpinfo->restore_path, "/tmp/TESTING");
    3300       bkpinfo->backup_media_type = dvd;
    3301         open_progress_form( "Reassembling /dev/hda1",
    3302               "Shark is a bit of a silly person." ,
    3303               "Please wait. This may take some time.",
    3304               "",
    3305               1999);
    3306      system("rm -Rf /tmp/*pih*");
    3307 
    3308       restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
    3309     }
    3310 
    3311   if (argc == 5 && strcmp( argv[1], "--common") == 0 )
    3312     {
    3313       g_loglevel = 6;
    3314       filelist = load_filelist(argv[2]);
    3315       if (!filelist) { fatal_error("Failed to load filelist"); }
    3316       toggle_node_selection (filelist, FALSE);
    3317       toggle_all_root_dirs_on (filelist);
    3318       toggle_path_selection (filelist, "/usr/share", TRUE);
     3333        paranoid_MR_finish(res);
     3334    }
     3335
     3336    g_loglevel = DEFAULT_MR_LOGLEVEL;
     3337    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
     3338        fout = fopen("/tmp/out.txt", "w");
     3339        fput_string_one_char_at_a_time(stderr, argv[2]);
     3340        finish(0);
     3341    }
     3342
     3343    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
     3344        make_grub_install_scriptlet(argv[2]);
     3345        finish(0);
     3346    }
     3347
     3348    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
     3349        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
     3350            system("mount " MNT_CDROM);
     3351        }
     3352        bkpinfo->compression_level = 1;
     3353        g_current_media_number = 2;
     3354        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
     3355        bkpinfo->backup_media_type = dvd;
     3356        open_progress_form("Reassembling /dev/hda1",
     3357                           "Shark is a bit of a silly person.",
     3358                           "Please wait. This may take some time.",
     3359                           "", 1999);
     3360        system("rm -Rf /tmp/*pih*");
     3361
     3362        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
     3363    }
     3364
     3365    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
     3366        g_loglevel = 6;
     3367        filelist = load_filelist(argv[2]);
     3368        if (!filelist) {
     3369            fatal_error("Failed to load filelist");
     3370        }
     3371        toggle_node_selection(filelist, FALSE);
     3372        toggle_all_root_dirs_on(filelist);
     3373        toggle_path_selection(filelist, "/usr/share", TRUE);
    33193374//      show_filelist(filelist);
    3320       save_filelist(filelist, "/tmp/out.txt");
     3375        save_filelist(filelist, "/tmp/out.txt");
    33213376//      finish(0);
    33223377//      toggle_path_selection (filelist, "/root/stuff", TRUE);
    3323       strcpy(a, argv[3]);
    3324       strcpy(b, argv[4]);
    3325 
    3326       res = save_filelist_entries_in_common(
    3327                 a, filelist, b, FALSE);
    3328       free_filelist(filelist);
    3329       printf("res = %d", res);
    3330       finish(0);
    3331     }
    3332 
    3333   if (argc == 3 && strcmp( argv[1], "--popuplist" ) == 0 )
    3334     {
    3335       popup_changelist_from_file( argv[2] );
    3336       paranoid_MR_finish(0);
    3337     }
    3338 
    3339    if (argc == 5 && strcmp( argv[1], "--copy" ) == 0 )
    3340     {
    3341           log_msg(1, "SCORE");
    3342       g_loglevel = 10;
    3343           if (strstr(argv[2], "save"))
    3344         {
    3345           log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
    3346           fin = fopen(argv[3], "r");
    3347           fout = fopen(argv[4], "w");
    3348           copy_from_src_to_dest(fin, fout, 'w');
    3349           fclose(fin);
    3350           fin = fopen(argv[3], "r");
    3351           copy_from_src_to_dest(fin, fout, 'w');
    3352           fclose(fout);
    3353           fclose(fin);
    3354         }
    3355       else if (strstr(argv[2], "restore"))
    3356         {
    3357           fout = fopen(argv[3], "w");
    3358           fin = fopen(argv[4], "r");
    3359           copy_from_src_to_dest(fout, fin, 'r');
    3360           fclose(fin);
    3361           fin = fopen(argv[4], "r");
    3362           copy_from_src_to_dest(fout, fin, 'r');
    3363           fclose(fout);
    3364           fclose(fin);
    3365         }
    3366       else
    3367         { fatal_error("Unknown additional param"); }
    3368       finish(0);
    3369     }
    3370 
    3371   if (argc == 3 && strcmp(argv[1], "--mdstat") == 0)
    3372     {
    3373       wait_until_software_raids_are_prepped(argv[2], 100);
    3374       finish(0);
    3375     }
    3376  
    3377   if (argc == 4 && strcmp(argv[1], "--mdconv") == 0)
    3378     {
    3379       finish(create_raidtab_from_mdstat(argv[2], argv[3]));
    3380     }
    3381 
    3382 
    3383   if ( argc == 2 && strcmp( argv[1],"--live-grub" ) == 0 )
    3384     {
    3385               retval = run_grub( FALSE, "/dev/hda" );
    3386           if ( retval )
    3387             {
    3388               log_to_screen("Failed to write Master Boot Record");
    3389             }
    3390       paranoid_MR_finish(0);
    3391    }
    3392   if (argc == 3 && strcmp( argv[1], "--paa" ) == 0 )
    3393     {
    3394       g_current_media_number = atoi(argv[2]);
    3395       pause_and_ask_for_cdr(5, NULL);
    3396       paranoid_MR_finish(0);
    3397     }
    3398   else if ( !bkpinfo->disaster_recovery )
    3399     { // live!
    3400       if (argc!=1)
    3401         {
    3402       popup_and_OK("Live mode doesn't support command-line parameters yet.");
    3403       paranoid_MR_finish(1);
    3404 //    return(1);
    3405     }
    3406       log_msg (1, "I am in normal, live mode.");
    3407       log_msg (2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
    3408       mount_boot_if_necessary();  /* for Gentoo users */
    3409       log_msg (2, "Still here.");
    3410       if ( argc>1 && strcmp( argv[argc-1], "--live-from-cd" ) == 0 )
    3411         { g_restoring_live_from_cd = TRUE; }
    3412       if ( argc == 5 && strcmp(argv[1], "--monitas-live" ) == 0 )
    3413         {
    3414       retval =
    3415         restore_live_from_monitas_server( bkpinfo,
    3416                           argv[2],
    3417                           argv[3],
    3418                           argv[4] );
    3419     }
    3420       else
    3421         {
    3422       log_msg(2, "Calling restore_to_live_filesystem()");
    3423       retval = restore_to_live_filesystem( bkpinfo );
    3424     }
    3425       log_msg(2, "Still here. Yay.");
    3426       if (strlen(bkpinfo->tmpdir) > 0)
    3427         {
    3428           sprintf( tmp, "rm -Rf %s/*", bkpinfo->tmpdir );
    3429           run_program_and_log_output ( tmp, FALSE );
    3430         }
    3431       unmount_boot_if_necessary(); /* for Gentoo users */
    3432       paranoid_MR_finish( retval );
    3433     }
    3434   else
    3435     {
     3378        strcpy(a, argv[3]);
     3379        strcpy(b, argv[4]);
     3380
     3381        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     3382        free_filelist(filelist);
     3383        printf("res = %d", res);
     3384        finish(0);
     3385    }
     3386
     3387    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
     3388        popup_changelist_from_file(argv[2]);
     3389        paranoid_MR_finish(0);
     3390    }
     3391
     3392    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
     3393        log_msg(1, "SCORE");
     3394        g_loglevel = 10;
     3395        if (strstr(argv[2], "save")) {
     3396            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
     3397            fin = fopen(argv[3], "r");
     3398            fout = fopen(argv[4], "w");
     3399            copy_from_src_to_dest(fin, fout, 'w');
     3400            fclose(fin);
     3401            fin = fopen(argv[3], "r");
     3402            copy_from_src_to_dest(fin, fout, 'w');
     3403            fclose(fout);
     3404            fclose(fin);
     3405        } else if (strstr(argv[2], "restore")) {
     3406            fout = fopen(argv[3], "w");
     3407            fin = fopen(argv[4], "r");
     3408            copy_from_src_to_dest(fout, fin, 'r');
     3409            fclose(fin);
     3410            fin = fopen(argv[4], "r");
     3411            copy_from_src_to_dest(fout, fin, 'r');
     3412            fclose(fout);
     3413            fclose(fin);
     3414        } else {
     3415            fatal_error("Unknown additional param");
     3416        }
     3417        finish(0);
     3418    }
     3419
     3420    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
     3421        wait_until_software_raids_are_prepped(argv[2], 100);
     3422        finish(0);
     3423    }
     3424
     3425    if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) {
     3426        finish(create_raidtab_from_mdstat(argv[2], argv[3]));
     3427    }
     3428
     3429
     3430    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
     3431        retval = run_grub(FALSE, "/dev/hda");
     3432        if (retval) {
     3433            log_to_screen("Failed to write Master Boot Record");
     3434        }
     3435        paranoid_MR_finish(0);
     3436    }
     3437    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
     3438        g_current_media_number = atoi(argv[2]);
     3439        pause_and_ask_for_cdr(5, NULL);
     3440        paranoid_MR_finish(0);
     3441    } else if (!bkpinfo->disaster_recovery) {   // live!
     3442        if (argc != 1) {
     3443            popup_and_OK
     3444                ("Live mode doesn't support command-line parameters yet.");
     3445            paranoid_MR_finish(1);
     3446//    return(1);
     3447        }
     3448        log_msg(1, "I am in normal, live mode.");
     3449        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
     3450        mount_boot_if_necessary();  /* for Gentoo users */
     3451        log_msg(2, "Still here.");
     3452        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
     3453            g_restoring_live_from_cd = TRUE;
     3454        }
     3455        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
     3456            retval =
     3457                restore_live_from_monitas_server(bkpinfo,
     3458                                                 argv[2],
     3459                                                 argv[3], argv[4]);
     3460        } else {
     3461            log_msg(2, "Calling restore_to_live_filesystem()");
     3462            retval = restore_to_live_filesystem(bkpinfo);
     3463        }
     3464        log_msg(2, "Still here. Yay.");
     3465        if (strlen(bkpinfo->tmpdir) > 0) {
     3466            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
     3467            run_program_and_log_output(tmp, FALSE);
     3468        }
     3469        unmount_boot_if_necessary();    /* for Gentoo users */
     3470        paranoid_MR_finish(retval);
     3471    } else {
    34363472/* Disaster recovery mode (must be) */
    3437       log_msg(1, "I must be in disaster recovery mode.");
    3438       log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname );
    3439       if (argc == 3 && strcmp(argv[1], "--monitas-memorex" ) == 0 )
    3440         {
    3441           log_to_screen( "Uh, that hasn't been implemented yet." );
    3442           paranoid_MR_finish( 1 );
    3443         }
    3444 
    3445       iamhere("About to call load_mountlist and load_raidtab");
    3446       strcpy( bkpinfo->restore_path, MNT_RESTORING );
    3447       read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    3448       retval = load_mountlist( mountlist, g_mountlist_fname );
    3449       retval += load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3450       iamhere("Returned from calling load_mountlist and load_raidtab successfully");
    3451 
    3452       if (argc>1 && (strcmp( argv[1], "--compare" ) == 0 || strcmp( argv[1], "--nuke" ) == 0 ))
    3453         {
    3454           if (bkpinfo->backup_media_type == nfs && !is_this_device_mounted(bkpinfo->nfs_mount))
    3455             {
    3456           log_msg(1, "Mounting nfs dir");
    3457               sprintf(bkpinfo->isodir, "/tmp/isodir");
    3458           run_program_and_log_output("mkdir -p /tmp/isodir", 5);
    3459           sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount);
    3460           run_program_and_log_output(tmp, 1);
    3461            }
    3462         }
    3463 
    3464      
    3465       if ( retval )
    3466         {
    3467           log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" );
    3468         }
    3469    
    3470 
    3471       log_msg(1, "Send in the clowns.");
    3472 
    3473       if (argc == 2 && strcmp(argv[1], "--partition-only") == 0)
    3474         {
    3475       log_msg(0, "Partitioning only.");
    3476           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3477           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3478       load_mountlist( mountlist, g_mountlist_fname );
    3479           res = partition_everything(mountlist);
    3480           finish(res);
    3481         }
    3482 
    3483       if (argc == 2 && strcmp(argv[1], "--format-only") == 0)
    3484         {
    3485       log_msg(0, "Formatting only.");
    3486           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3487           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3488       load_mountlist( mountlist, g_mountlist_fname );
    3489           res = format_everything(mountlist, FALSE);
    3490           finish(res);
    3491         }
    3492 
    3493       if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0)
    3494         {
    3495       log_msg(0, "Stopping LVM and RAID");
    3496           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3497           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3498       load_mountlist( mountlist, g_mountlist_fname );
    3499           res = do_my_funky_lvm_stuff(TRUE, FALSE);
    3500       res += stop_all_raid_devices(mountlist);
    3501           finish(res);
    3502         }
    3503 
    3504       if (argc == 2 && strcmp( argv[1], "--nuke" ) == 0 )
    3505         {
    3506       iamhere("nuking");
    3507           retval += nuke_mode( bkpinfo, mountlist, raidlist);
    3508         }
    3509       else if (argc == 2 && strcmp( argv[1], "--interactive" ) == 0 )
    3510         {
    3511       iamhere("catchall");
    3512           retval += catchall_mode( bkpinfo, mountlist,raidlist );
    3513         }
    3514       else if (argc == 2 && strcmp( argv[1], "--compare" ) == 0 )
    3515         {
    3516       iamhere("compare");
    3517           retval += compare_mode( bkpinfo, mountlist, raidlist );
    3518         }
    3519       else if (argc == 2 && strcmp( argv[1], "--iso" ) == 0 )
    3520         {
    3521       iamhere("iso");
    3522       retval = iso_mode( bkpinfo, mountlist, raidlist, FALSE );
    3523         }
    3524       else if ( argc == 2 && strcmp( argv[1],"--mbr" ) == 0 )
    3525         {
    3526       iamhere("mbr");
    3527           retval = mount_all_devices( mountlist, TRUE );
    3528           if ( !retval )
    3529             {
    3530               retval += run_boot_loader( FALSE );
    3531               retval += unmount_all_devices( mountlist );
    3532             }
    3533           if ( retval )
    3534             {
    3535               log_to_screen("Failed to write Master Boot Record");
    3536             }
    3537         }
    3538       else if ( argc == 2 && strcmp( argv[1],"--isonuke") ==0 )
    3539         {
    3540       iamhere("isonuke");
    3541           retval = iso_mode( bkpinfo,
    3542              mountlist,
    3543              raidlist,
    3544              TRUE );
    3545         }
    3546       else if ( argc != 1 )
    3547         {
    3548           log_to_screen( "Invalid paremeters" );
    3549           paranoid_MR_finish( 1 );
    3550         }
    3551       else
    3552         {
    3553       iamhere("catchall (no mode specified in command-line call");
    3554           retval += catchall_mode( bkpinfo, mountlist, raidlist);
    3555         }
    3556     }
    3557 
    3558   /* clean up at the end */
    3559   if (retval)
    3560     {
    3561       if (does_file_exist("/tmp/changed.files"))
    3562     {
    3563           log_to_screen( "See /tmp/changed.files for list of files that have changed." );
    3564     }
    3565       mvaddstr_and_log_it ( g_currentY++,
    3566             0,
    3567             "Run complete. Errors were reported. Please review the logfile." );
    3568     }
    3569   else
    3570     {
    3571       if (IS_THIS_A_STREAMING_BACKUP ( bkpinfo->backup_media_type ) )
    3572         {
    3573       mvaddstr_and_log_it( g_currentY++,
    3574                    0,
    3575                    "Run complete. Please remove floppy/CD/media and reboot." );
    3576     }
    3577       else
    3578     {
    3579       run_program_and_log_output ( "sync", FALSE );
    3580       if ( is_this_device_mounted( MNT_CDROM ) )
    3581         {
    3582           res = run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    3583         }
    3584       else
    3585         {
    3586           res = 0;
    3587         }
    3588      
    3589           if ( !bkpinfo->please_dont_eject)
    3590             {
    3591               res = eject_device("/dev/cdrom");
     3473        log_msg(1, "I must be in disaster recovery mode.");
     3474        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
     3475        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
     3476            log_to_screen("Uh, that hasn't been implemented yet.");
     3477            paranoid_MR_finish(1);
     3478        }
     3479
     3480        iamhere("About to call load_mountlist and load_raidtab");
     3481        strcpy(bkpinfo->restore_path, MNT_RESTORING);
     3482        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     3483        retval = load_mountlist(mountlist, g_mountlist_fname);
     3484        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3485        iamhere
     3486            ("Returned from calling load_mountlist and load_raidtab successfully");
     3487
     3488        if (argc > 1
     3489            && (strcmp(argv[1], "--compare") == 0
     3490                || strcmp(argv[1], "--nuke") == 0)) {
     3491            if (bkpinfo->backup_media_type == nfs
     3492                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
     3493                log_msg(1, "Mounting nfs dir");
     3494                sprintf(bkpinfo->isodir, "/tmp/isodir");
     3495                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
     3496                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
     3497                        bkpinfo->nfs_mount);
     3498                run_program_and_log_output(tmp, 1);
     3499            }
     3500        }
     3501
     3502
     3503        if (retval) {
     3504            log_to_screen
     3505                ("Warning - load_raidtab_into_raidlist returned an error");
     3506        }
     3507
     3508
     3509        log_msg(1, "Send in the clowns.");
     3510
     3511        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
     3512            log_msg(0, "Partitioning only.");
     3513            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3514            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3515            load_mountlist(mountlist, g_mountlist_fname);
     3516            res = partition_everything(mountlist);
     3517            finish(res);
     3518        }
     3519
     3520        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
     3521            log_msg(0, "Formatting only.");
     3522            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3523            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3524            load_mountlist(mountlist, g_mountlist_fname);
     3525            res = format_everything(mountlist, FALSE);
     3526            finish(res);
     3527        }
     3528
     3529        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
     3530            log_msg(0, "Stopping LVM and RAID");
     3531            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3532            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3533            load_mountlist(mountlist, g_mountlist_fname);
     3534            res = do_my_funky_lvm_stuff(TRUE, FALSE);
     3535            res += stop_all_raid_devices(mountlist);
     3536            finish(res);
     3537        }
     3538
     3539        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
     3540            iamhere("nuking");
     3541            retval += nuke_mode(bkpinfo, mountlist, raidlist);
     3542        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
     3543            iamhere("catchall");
     3544            retval += catchall_mode(bkpinfo, mountlist, raidlist);
     3545        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
     3546            iamhere("compare");
     3547            retval += compare_mode(bkpinfo, mountlist, raidlist);
     3548        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
     3549            iamhere("iso");
     3550            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
     3551        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
     3552            iamhere("mbr");
     3553            retval = mount_all_devices(mountlist, TRUE);
     3554            if (!retval) {
     3555                retval += run_boot_loader(FALSE);
     3556                retval += unmount_all_devices(mountlist);
     3557            }
     3558            if (retval) {
     3559                log_to_screen("Failed to write Master Boot Record");
     3560            }
     3561        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
     3562            iamhere("isonuke");
     3563            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
     3564        } else if (argc != 1) {
     3565            log_to_screen("Invalid paremeters");
     3566            paranoid_MR_finish(1);
     3567        } else {
     3568            iamhere("catchall (no mode specified in command-line call");
     3569            retval += catchall_mode(bkpinfo, mountlist, raidlist);
     3570        }
     3571    }
     3572
     3573    /* clean up at the end */
     3574    if (retval) {
     3575        if (does_file_exist("/tmp/changed.files")) {
     3576            log_to_screen
     3577                ("See /tmp/changed.files for list of files that have changed.");
     3578        }
     3579        mvaddstr_and_log_it(g_currentY++,
     3580                            0,
     3581                            "Run complete. Errors were reported. Please review the logfile.");
     3582    } else {
     3583        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3584            mvaddstr_and_log_it(g_currentY++,
     3585                                0,
     3586                                "Run complete. Please remove floppy/CD/media and reboot.");
     3587        } else {
     3588            run_program_and_log_output("sync", FALSE);
     3589            if (is_this_device_mounted(MNT_CDROM)) {
     3590                res =
     3591                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3592            } else {
     3593                res = 0;
     3594            }
     3595
     3596            if (!bkpinfo->please_dont_eject) {
     3597                res = eject_device("/dev/cdrom");
    35923598/*
    35933599              if (res)
     
    35963602        }
    35973603*/
    3598             }
    3599       mvaddstr_and_log_it( g_currentY++,
    3600                    0,
    3601                    "Run complete. Please remove media and reboot." );
    3602     }
    3603     }
     3604            }
     3605            mvaddstr_and_log_it(g_currentY++,
     3606                                0,
     3607                                "Run complete. Please remove media and reboot.");
     3608        }
     3609    }
    36043610
    36053611// g_I_have_just_nuked is set true by nuke_mode() just before it returns
    3606   if ( g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY"))
    3607     {
    3608       if (!system("which post-nuke > /dev/null 2> /dev/null"))
    3609         {
    3610           log_msg(1, "post-nuke found; running...");
    3611           if (mount_all_devices(mountlist, TRUE))
    3612             {
    3613               log_to_screen("Unable to re-mount partitions for post-nuke stuff");
    3614             }
    3615           else
    3616             {
    3617               log_msg(1, "Re-mounted partitions for post-nuke stuff");
    3618               sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
    3619               if (!g_text_mode) { newtSuspend(); }
    3620               log_msg(2, "Calling '%s'", tmp);
    3621               if ((res=system(tmp))) { log_OS_error(tmp); }
    3622               if (!g_text_mode) { newtResume(); }
     3612    if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
     3613        if (!system("which post-nuke > /dev/null 2> /dev/null")) {
     3614            log_msg(1, "post-nuke found; running...");
     3615            if (mount_all_devices(mountlist, TRUE)) {
     3616                log_to_screen
     3617                    ("Unable to re-mount partitions for post-nuke stuff");
     3618            } else {
     3619                log_msg(1, "Re-mounted partitions for post-nuke stuff");
     3620                sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
     3621                        retval);
     3622                if (!g_text_mode) {
     3623                    newtSuspend();
     3624                }
     3625                log_msg(2, "Calling '%s'", tmp);
     3626                if ((res = system(tmp))) {
     3627                    log_OS_error(tmp);
     3628                }
     3629                if (!g_text_mode) {
     3630                    newtResume();
     3631                }
    36233632//              newtCls();
    3624               log_msg(1, "post-nuke returned w/ res=%d", res);
    3625             }
    3626           unmount_all_devices(mountlist);
    3627           log_msg(1, "I've finished post-nuking.");
    3628         }
    3629     }
     3633                log_msg(1, "post-nuke returned w/ res=%d", res);
     3634            }
     3635            unmount_all_devices(mountlist);
     3636            log_msg(1, "I've finished post-nuking.");
     3637        }
     3638    }
    36303639/* 
    36313640  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
     
    36333642  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
    36343643  log_to_screen("Thank you.");
    3635 */
    3636   unlink( "/tmp/mondo-run-prog.tmp" );
    3637   set_signals( FALSE );
    3638   sprintf( tmp, "rm -Rf %s", bkpinfo->tmpdir );
    3639   run_program_and_log_output ( tmp, FALSE );
    3640   log_to_screen( "Restore log copied to /tmp/mondo-restore.log on your hard disk" );
    3641   sprintf( tmp, "Mondo-restore is exiting (retval=%d)                                      ",retval);
    3642   log_to_screen( tmp );
    3643   sprintf(tmp, "umount %s", bkpinfo->isodir);
    3644   run_program_and_log_output(tmp, 5);
    3645   paranoid_free(mountlist);
    3646   paranoid_free(raidlist);
    3647   if (am_I_in_disaster_recovery_mode())
    3648     { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros
    3649   paranoid_MR_finish( retval ); // frees global stuff plus bkpinfo
    3650   free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3651   paranoid_free(a);
    3652   paranoid_free(b);
    3653   paranoid_free(tmp);
    3654  
    3655   unlink("/tmp/filelist.full");
    3656   unlink("/tmp/filelist.full.gz");
    3657 
    3658   exit( retval );
     3644*/
     3645    unlink("/tmp/mondo-run-prog.tmp");
     3646    set_signals(FALSE);
     3647    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
     3648    run_program_and_log_output(tmp, FALSE);
     3649    log_to_screen
     3650        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
     3651    sprintf(tmp,
     3652            "Mondo-restore is exiting (retval=%d)                                      ",
     3653            retval);
     3654    log_to_screen(tmp);
     3655    sprintf(tmp, "umount %s", bkpinfo->isodir);
     3656    run_program_and_log_output(tmp, 5);
     3657    paranoid_free(mountlist);
     3658    paranoid_free(raidlist);
     3659    if (am_I_in_disaster_recovery_mode()) {
     3660        run_program_and_log_output("mount / -o remount,rw", 2);
     3661    }                           // for b0rken distros
     3662    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
     3663    free_libmondo_global_strings(); // it's fine to have this here :) really :)
     3664    paranoid_free(a);
     3665    paranoid_free(b);
     3666    paranoid_free(tmp);
     3667
     3668    unlink("/tmp/filelist.full");
     3669    unlink("/tmp/filelist.full.gz");
     3670
     3671    exit(retval);
    36593672}
    36603673
     
    36703683 *END_MONDO-RESTORE.C                                                     *
    36713684 **************************************************************************/
    3672 
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore.h

    r30 r128  
    11/* mondo-restore.h
    2  * $Id: mondo-restore.h,v 1.3 2004/06/21 20:20:37 hugo Exp $
     2 * $Id$
    33 */
    44
     
    77 **************************************************************************/
    88
    9 void ask_about_these_imagedevs(char*,char*);
    10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*);
    11 void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*);
    12 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    13 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    14 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    15 int iso_mode(struct s_bkpinfo *bkpinfo,
    16      struct mountlist_itself *mountlist,
    17      struct raidlist_itself *raidlist,
    18      bool nuke_me_please);
    19 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    20 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*, char*);
    21 int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*, int, char*);
    22 int restore_a_tarball_from_CD(char *, long, struct s_node*);
    23 int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, long, struct s_node*, long long, char*, char*);
    24 int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*);
    25 int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*);
    26 int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*);
    27 int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*);
    28 int restore_everything(struct s_bkpinfo*,struct s_node*);
    29 int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*);
    30 int restore_to_live_filesystem(struct s_bkpinfo*);
    31 void swap_mountlist_entries(struct mountlist_itself*,int,int);
    32 void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool);
    33 void sort_mountlist_by_device(struct mountlist_itself*);
    34 int what_number_cd_is_this(struct s_bkpinfo*);
     9void ask_about_these_imagedevs(char *, char *);
     10int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *,
     11                  struct raidlist_itself *);
     12void find_pathname_of_executable_preferably_in_RESTORING(char *, char *,
     13                                                         char *);
     14int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
     15                     struct raidlist_itself *);
     16int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *,
     17              struct raidlist_itself *);
     18int compare_mode(struct s_bkpinfo *, struct mountlist_itself *,
     19                 struct raidlist_itself *);
     20int iso_mode(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist,
     21             struct raidlist_itself *raidlist, bool nuke_me_please);
     22int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
     23                 struct raidlist_itself *);
     24int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *,
     25                                 char *);
     26int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long,
     27                                     char *, long long, struct s_node *,
     28                                     int, char *);
     29int restore_a_tarball_from_CD(char *, long, struct s_node *);
     30int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, long,
     31                                  struct s_node *, long long, char *,
     32                                  char *);
     33int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, struct s_node *);
     34int restore_all_biggiefiles_from_stream(struct s_bkpinfo *,
     35                                        struct s_node *);
     36int restore_all_tarballs_from_CD(struct s_bkpinfo *, struct s_node *);
     37int restore_all_tarballs_from_stream(struct s_bkpinfo *, struct s_node *);
     38int restore_everything(struct s_bkpinfo *, struct s_node *);
     39int restore_live_from_monitas_server(struct s_bkpinfo *, char *, char *,
     40                                     char *);
     41int restore_to_live_filesystem(struct s_bkpinfo *);
     42void swap_mountlist_entries(struct mountlist_itself *, int, int);
     43void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool);
     44void sort_mountlist_by_device(struct mountlist_itself *);
     45int what_number_cd_is_this(struct s_bkpinfo *);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h

    r30 r128  
    22
    33
    4 extern int compare_to_CD(struct s_bkpinfo*);
    5 extern int compare_to_cdstream(struct s_bkpinfo*);
    6 extern int compare_to_tape(struct s_bkpinfo*);
    7 extern int compare_mode( struct s_bkpinfo *bkpinfo ,
    8           struct mountlist_itself *mountlist,
    9           struct raidlist_itself *raidlist);
     4extern int compare_to_CD(struct s_bkpinfo *);
     5extern int compare_to_cdstream(struct s_bkpinfo *);
     6extern int compare_to_tape(struct s_bkpinfo *);
     7extern int compare_mode(struct s_bkpinfo *bkpinfo,
     8                        struct mountlist_itself *mountlist,
     9                        struct raidlist_itself *raidlist);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare.c

    r30 r128  
    55    copyright            : (C) 2000 by Hugo Rabson
    66    email                : Hugo Rabson <hugorabson@msn.com>
    7     cvsid                : $Id: mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp $
     7    cvsid                : $Id$
    88***************************************************************************/
    99
     
    6565#include "mondo-rstr-tools-EXT.h"
    6666
    67 //static char cvsid[] = "$Id: mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp $";
    68 
    69 void popup_changelist_from_file(char*);
     67//static char cvsid[] = "$Id$";
     68
     69void popup_changelist_from_file(char *);
    7070
    7171
     
    8080 * @note This function uses an MD5 checksum.
    8181 */
    82 int
    83 compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
     82int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
    8483{
    8584
    86   FILE *fin;
    87   FILE *fout;
     85    FILE *fin;
     86    FILE *fout;
    8887
    8988  /** needs malloc *******/
    90   char *checksum_ptr;
    91   char *original_cksum_ptr;
    92   char *bigfile_fname_ptr;
    93   char *tmp_ptr;
    94   char *command_ptr;
    95 
    96   char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
    97  
    98   char *p;
    99   int i;
    100   int retval = 0;
    101 
    102   struct s_filename_and_lstat_info biggiestruct;
    103  
    104   malloc_string(checksum);
    105   malloc_string(original_cksum);
    106   malloc_string(bigfile_fname);
    107   malloc_string(tmp);
    108   malloc_string(command);
    109   malloc_string(checksum_ptr);
    110   malloc_string(original_cksum_ptr);
    111   malloc_string(bigfile_fname_ptr);
    112   malloc_string(command_ptr);
    113   malloc_string(tmp_ptr);
    114  
     89    char *checksum_ptr;
     90    char *original_cksum_ptr;
     91    char *bigfile_fname_ptr;
     92    char *tmp_ptr;
     93    char *command_ptr;
     94
     95    char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
     96
     97    char *p;
     98    int i;
     99    int retval = 0;
     100
     101    struct s_filename_and_lstat_info biggiestruct;
     102
     103    malloc_string(checksum);
     104    malloc_string(original_cksum);
     105    malloc_string(bigfile_fname);
     106    malloc_string(tmp);
     107    malloc_string(command);
     108    malloc_string(checksum_ptr);
     109    malloc_string(original_cksum_ptr);
     110    malloc_string(bigfile_fname_ptr);
     111    malloc_string(command_ptr);
     112    malloc_string(tmp_ptr);
     113
    115114  /*********************************************************************
    116115   * allocate memory clear test                sab 16 feb 2003         *
    117116   *********************************************************************/
    118   assert(bkpinfo!=NULL);
    119   memset( checksum_ptr, '\0', sizeof(checksum));
    120   memset ( original_cksum_ptr, '\0', sizeof(original_cksum));
    121   memset (bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    122   memset (tmp_ptr, '\0', sizeof(tmp));
    123   memset ( command_ptr, '\0', sizeof( command ) );
     117    assert(bkpinfo != NULL);
     118    memset(checksum_ptr, '\0', sizeof(checksum));
     119    memset(original_cksum_ptr, '\0', sizeof(original_cksum));
     120    memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
     121    memset(tmp_ptr, '\0', sizeof(tmp));
     122    memset(command_ptr, '\0', sizeof(command));
    124123  /** end **/
    125124
    126   if ( !does_file_exist( slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) )
    127     {
    128       if ( does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) )
    129     {
    130           insist_on_this_cd_number(bkpinfo, ( ++g_current_media_number ) );
    131         }
    132       else
    133     {
    134       sprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob." );
    135       log_msg(2,  tmp_ptr );
    136       return( 0 );
    137         }
    138     }
    139   if ( !( fin = fopen(slice_fname( bigfileno, 0, ARCHIVES_PATH, "" ), "r" ) ) )
    140     {
    141       sprintf( tmp_ptr,
    142            "Cannot open bigfile %ld (%s)'s info file",
    143            bigfileno + 1, bigfile_fname_ptr);
    144       log_to_screen( tmp_ptr );
    145       return( 1 );
    146     }
    147   fread( ( void* )&biggiestruct, 1, sizeof( biggiestruct ), fin);
    148   paranoid_fclose( fin );
    149  
    150   strcpy( checksum_ptr, biggiestruct.checksum );
    151   strcpy( bigfile_fname_ptr, biggiestruct.filename );
    152  
    153   log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename );
    154   log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum );
    155  
    156   sprintf( tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    157  
    158   if (!g_text_mode)
    159     {
    160       newtDrawRootText( 0, 22, tmp_ptr);
    161       newtRefresh();
    162     }
    163   if ( !checksum[0] ) {
    164     log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr );
    165   }
    166   if ( !strncmp( bigfile_fname_ptr, "/dev/", 5 ) )
    167     {
    168       strcpy( original_cksum_ptr, "IGNORE" );
    169     }
    170   else
    171     {
    172       sprintf( command_ptr,
    173            "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
    174            MNT_RESTORING, bigfile_fname_ptr);
    175     }
    176   log_msg(2, command_ptr );
    177   paranoid_system( "cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null" );
    178   if ( system( command_ptr ) )
    179     {
    180       log_OS_error( "Warning - command failed" );
    181       original_cksum[0] = '\0';
    182       return( 1 );
    183     }
    184   else
    185     {
    186       if ( !(fin = fopen( "/tmp/md5sum.txt", "r" ) ) )
    187     {
    188       log_msg(2,  "Unable to open /tmp/md5sum.txt; can't get live checksum" );
    189       original_cksum[0] = '\0';
    190       return( 1 );
    191     }
    192       else
    193     {
    194       fgets( original_cksum_ptr, MAX_STR_LEN - 1, fin );
    195       paranoid_fclose( fin );
    196       for(i = strlen( original_cksum_ptr ); i > 0 && original_cksum[i-1] < 32; i-- );
    197       original_cksum[i] = '\0';
    198       p = ( char* ) strchr( original_cksum_ptr, ' ' );
    199       if ( p )
    200         {
    201           *p = '\0';
    202         }
    203     }
    204     }
    205   sprintf( tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);
    206   if ( !strcmp(checksum_ptr, original_cksum_ptr ) != 0 )
    207     {
    208       strcat( tmp_ptr," ... OK");
    209     }
    210   else
    211     {
    212       strcat( tmp_ptr, "... changed" );
    213       retval++;
    214     }
    215   log_msg(1, tmp_ptr );
    216   if ( retval )
    217     {
    218       if ( !( fout = fopen("/tmp/changed.txt", "a") ) )
    219     {
    220       fatal_error( "Cannot openout changed.txt");
    221     }
    222       fprintf( fout, "%s\n", bigfile_fname_ptr );
    223       paranoid_fclose( fout );
    224     }
    225 
    226   paranoid_free (original_cksum_ptr);
    227   paranoid_free (original_cksum);
    228   paranoid_free (bigfile_fname_ptr);
    229   paranoid_free (bigfile_fname);
    230   paranoid_free (checksum_ptr);
    231   paranoid_free (checksum);
    232   paranoid_free (command_ptr);
    233   paranoid_free (command);
    234   paranoid_free (tmp_ptr);
    235   paranoid_free (tmp);
    236 
    237   return( retval );
     125    if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     126        if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
     127            insist_on_this_cd_number(bkpinfo, (++g_current_media_number));
     128        } else {
     129            sprintf(tmp_ptr,
     130                    "No CD's left. No biggiefiles left. No prob, Bob.");
     131            log_msg(2, tmp_ptr);
     132            return (0);
     133        }
     134    }
     135    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
     136        sprintf(tmp_ptr,
     137                "Cannot open bigfile %ld (%s)'s info file",
     138                bigfileno + 1, bigfile_fname_ptr);
     139        log_to_screen(tmp_ptr);
     140        return (1);
     141    }
     142    fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
     143    paranoid_fclose(fin);
     144
     145    strcpy(checksum_ptr, biggiestruct.checksum);
     146    strcpy(bigfile_fname_ptr, biggiestruct.filename);
     147
     148    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
     149    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
     150
     151    sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
     152
     153    if (!g_text_mode) {
     154        newtDrawRootText(0, 22, tmp_ptr);
     155        newtRefresh();
     156    }
     157    if (!checksum[0]) {
     158        log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
     159    }
     160    if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
     161        strcpy(original_cksum_ptr, "IGNORE");
     162    } else {
     163        sprintf(command_ptr,
     164                "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
     165                MNT_RESTORING, bigfile_fname_ptr);
     166    }
     167    log_msg(2, command_ptr);
     168    paranoid_system
     169        ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null");
     170    if (system(command_ptr)) {
     171        log_OS_error("Warning - command failed");
     172        original_cksum[0] = '\0';
     173        return (1);
     174    } else {
     175        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
     176            log_msg(2,
     177                    "Unable to open /tmp/md5sum.txt; can't get live checksum");
     178            original_cksum[0] = '\0';
     179            return (1);
     180        } else {
     181            fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
     182            paranoid_fclose(fin);
     183            for (i = strlen(original_cksum_ptr);
     184                 i > 0 && original_cksum[i - 1] < 32; i--);
     185            original_cksum[i] = '\0';
     186            p = (char *) strchr(original_cksum_ptr, ' ');
     187            if (p) {
     188                *p = '\0';
     189            }
     190        }
     191    }
     192    sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
     193            bigfile_fname_ptr);
     194    if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
     195        strcat(tmp_ptr, " ... OK");
     196    } else {
     197        strcat(tmp_ptr, "... changed");
     198        retval++;
     199    }
     200    log_msg(1, tmp_ptr);
     201    if (retval) {
     202        if (!(fout = fopen("/tmp/changed.txt", "a"))) {
     203            fatal_error("Cannot openout changed.txt");
     204        }
     205        fprintf(fout, "%s\n", bigfile_fname_ptr);
     206        paranoid_fclose(fout);
     207    }
     208
     209    paranoid_free(original_cksum_ptr);
     210    paranoid_free(original_cksum);
     211    paranoid_free(bigfile_fname_ptr);
     212    paranoid_free(bigfile_fname);
     213    paranoid_free(checksum_ptr);
     214    paranoid_free(checksum);
     215    paranoid_free(command_ptr);
     216    paranoid_free(command);
     217    paranoid_free(tmp_ptr);
     218    paranoid_free(tmp);
     219
     220    return (retval);
    238221}
    239222
     
    248231 * @return 0 for success, nonzero for failure.
    249232 */
    250 int
    251 compare_all_biggiefiles(struct s_bkpinfo*bkpinfo)
     233int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo)
    252234{
    253   int retval = 0;
    254   int res;
    255   long noof_biggiefiles,bigfileno = 0;
    256   char tmp[MAX_STR_LEN];
    257 
    258   assert(bkpinfo!=NULL);
    259   log_msg(1, "Comparing biggiefiles" );
    260  
    261   if ( length_of_file(BIGGIELIST) < 6 )
    262     {
    263       log_msg(1, "OK, really teeny-tiny biggielist; not comparing biggiefiles" );
    264       return( 0 );
    265     }
    266   noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    267   if (noof_biggiefiles <= 0 )
    268     {
    269       log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
    270       return( 0 );
    271     }
    272   mvaddstr_and_log_it( g_currentY, 0, "Comparing large files                                                  ");
    273   open_progress_form("Comparing large files", "I am now comparing the large files" , "against the filesystem. Please wait.",
    274              "",
    275              noof_biggiefiles );
    276   for( bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++ )
    277     {
    278       sprintf( tmp, "Comparing big file #%ld", bigfileno + 1 );
    279       log_msg(1, tmp );
    280       update_progress_form( tmp );
    281       res = compare_a_biggiefile( bkpinfo, bigfileno );
    282       retval += res;
    283       g_current_progress++;
    284     }
    285   close_progress_form();
    286   return( 0 );
    287   if ( retval )
    288     {
    289       mvaddstr_and_log_it( g_currentY++, 74, "Errors." );
    290     }
    291   else
    292     {
    293       mvaddstr_and_log_it( g_currentY++,74, "Done." );
    294     }
    295   return( retval );
     235    int retval = 0;
     236    int res;
     237    long noof_biggiefiles, bigfileno = 0;
     238    char tmp[MAX_STR_LEN];
     239
     240    assert(bkpinfo != NULL);
     241    log_msg(1, "Comparing biggiefiles");
     242
     243    if (length_of_file(BIGGIELIST) < 6) {
     244        log_msg(1,
     245                "OK, really teeny-tiny biggielist; not comparing biggiefiles");
     246        return (0);
     247    }
     248    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
     249    if (noof_biggiefiles <= 0) {
     250        log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
     251        return (0);
     252    }
     253    mvaddstr_and_log_it(g_currentY, 0,
     254                        "Comparing large files                                                  ");
     255    open_progress_form("Comparing large files",
     256                       "I am now comparing the large files",
     257                       "against the filesystem. Please wait.", "",
     258                       noof_biggiefiles);
     259    for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
     260        sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
     261        log_msg(1, tmp);
     262        update_progress_form(tmp);
     263        res = compare_a_biggiefile(bkpinfo, bigfileno);
     264        retval += res;
     265        g_current_progress++;
     266    }
     267    close_progress_form();
     268    return (0);
     269    if (retval) {
     270        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     271    } else {
     272        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     273    }
     274    return (retval);
    296275}
     276
    297277/**************************************************************************
    298278 *END_COMPARE_ALL_BIGGIEFILES                                             *
     
    308288 * @return 0 for success, nonzero for failure.
    309289 */
    310 int
    311 compare_a_tarball( char *tarball_fname, int current_tarball_number )
     290int compare_a_tarball(char *tarball_fname, int current_tarball_number)
    312291{
    313   int retval = 0;
    314   int res;
    315   long noof_lines;
    316   long archiver_errors;
    317   bool use_star;
    318  
     292    int retval = 0;
     293    int res;
     294    long noof_lines;
     295    long archiver_errors;
     296    bool use_star;
     297
    319298  /***  needs malloc *********/
    320   char *command, *tmp, *filelist_name, *logfile, *archiver_exe, *compressor_exe;
    321 
    322   malloc_string(command);
    323   malloc_string(tmp);
    324   malloc_string(filelist_name);
    325   malloc_string(logfile);
    326   malloc_string(archiver_exe);
    327   malloc_string(compressor_exe);
    328  
    329   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
    330   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    331   sprintf( logfile, "/tmp/afio.log.%d", current_tarball_number );
    332   sprintf( filelist_name, MNT_CDROM"/archives/filelist.%d", current_tarball_number );
    333 
    334   noof_lines = count_lines_in_file( filelist_name );
    335 
    336   if ( strstr( tarball_fname, ".bz2") )
    337     {
    338       strcpy( compressor_exe, "bzip2");
    339     }
    340   else if ( strstr (tarball_fname, ".lzo") )
    341     {
    342       strcpy( compressor_exe, "lzop" );
    343     }
    344   else
    345     {
    346       compressor_exe[0] = '\0';
    347     }
    348  
    349   if (use_star)
    350     { strcpy(archiver_exe, "star"); }
    351   else
    352     { strcpy(archiver_exe, "afio"); }
    353  
    354   if (compressor_exe[0])
    355     {
    356       strcpy(tmp, compressor_exe);
    357       if (!find_home_of_exe(tmp))
    358         { fatal_error("(compare_a_tarball) Compression program missing"); }
    359       if (use_star) // star
    360         {
    361       if (!strcmp(compressor_exe, "bzip2"))
    362         { strcat(archiver_exe, " -bz"); }
    363       else { fatal_error("(compare_a_tarball) Please use only bzip2 with star"); }
    364     }
    365       else      // afio
    366         {
    367       sprintf(compressor_exe, "-P %s -Z", tmp);
    368     }
    369     }
     299    char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
     300        *compressor_exe;
     301
     302    malloc_string(command);
     303    malloc_string(tmp);
     304    malloc_string(filelist_name);
     305    malloc_string(logfile);
     306    malloc_string(archiver_exe);
     307    malloc_string(compressor_exe);
     308
     309    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
     310    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     311    sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
     312    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d",
     313            current_tarball_number);
     314
     315    noof_lines = count_lines_in_file(filelist_name);
     316
     317    if (strstr(tarball_fname, ".bz2")) {
     318        strcpy(compressor_exe, "bzip2");
     319    } else if (strstr(tarball_fname, ".lzo")) {
     320        strcpy(compressor_exe, "lzop");
     321    } else {
     322        compressor_exe[0] = '\0';
     323    }
     324
     325    if (use_star) {
     326        strcpy(archiver_exe, "star");
     327    } else {
     328        strcpy(archiver_exe, "afio");
     329    }
     330
     331    if (compressor_exe[0]) {
     332        strcpy(tmp, compressor_exe);
     333        if (!find_home_of_exe(tmp)) {
     334            fatal_error("(compare_a_tarball) Compression program missing");
     335        }
     336        if (use_star)           // star
     337        {
     338            if (!strcmp(compressor_exe, "bzip2")) {
     339                strcat(archiver_exe, " -bz");
     340            } else {
     341                fatal_error
     342                    ("(compare_a_tarball) Please use only bzip2 with star");
     343            }
     344        } else                  // afio
     345        {
     346            sprintf(compressor_exe, "-P %s -Z", tmp);
     347        }
     348    }
    370349// star -diff H=star -bz file=....
    371350
     
    375354#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
    376355#endif
    377   if (use_star) // doesn't use compressor_exe
    378     {
    379       sprintf( command,
    380           "%s -diff H=star file=%s >> %s 2>> %s",
    381       archiver_exe, tarball_fname, logfile, logfile);
    382     }
    383   else
    384     {
    385       sprintf( command,
    386        "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
    387        archiver_exe,
    388        TAPE_BLOCK_SIZE,
    389        BUFSIZE,
    390        compressor_exe, tarball_fname,
    391        logfile,
    392        logfile);
    393     }
     356    if (use_star)               // doesn't use compressor_exe
     357    {
     358        sprintf(command,
     359                "%s -diff H=star file=%s >> %s 2>> %s",
     360                archiver_exe, tarball_fname, logfile, logfile);
     361    } else {
     362        sprintf(command,
     363                "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
     364                archiver_exe,
     365                TAPE_BLOCK_SIZE,
     366                BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
     367    }
    394368#undef BUFSIZE
    395369
    396   res = system( command );
    397   retval += res;
    398   if ( res )
    399     {
    400       log_OS_error( command );
    401       sprintf( tmp, "Warning - afio returned error = %d", res );
    402     }
    403   if (length_of_file(logfile)>5)
    404     {
    405       sprintf(command,
    406       "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt",
    407       logfile);
    408       system(command);
    409       archiver_errors = count_lines_in_file( logfile );
    410     }
    411   else
    412     {
    413       archiver_errors = 0;
    414     }
    415   sprintf(tmp, "%ld difference%c in fileset #%d          ",
    416       archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number);
    417   if (archiver_errors)
    418     {
    419       sprintf(tmp,
    420           "Differences found while processing fileset #%d       ",
    421           current_tarball_number);
    422       log_msg(1, tmp );
    423     }
    424   unlink( logfile );
    425   paranoid_free(command);
    426   paranoid_free(tmp);
    427   paranoid_free(filelist_name);
    428   paranoid_free(logfile);
    429   malloc_string(archiver_exe);
    430   malloc_string(compressor_exe);
    431   return( retval );
     370    res = system(command);
     371    retval += res;
     372    if (res) {
     373        log_OS_error(command);
     374        sprintf(tmp, "Warning - afio returned error = %d", res);
     375    }
     376    if (length_of_file(logfile) > 5) {
     377        sprintf(command,
     378                "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt",
     379                logfile);
     380        system(command);
     381        archiver_errors = count_lines_in_file(logfile);
     382    } else {
     383        archiver_errors = 0;
     384    }
     385    sprintf(tmp, "%ld difference%c in fileset #%d          ",
     386            archiver_errors, (archiver_errors != 1) ? 's' : ' ',
     387            current_tarball_number);
     388    if (archiver_errors) {
     389        sprintf(tmp,
     390                "Differences found while processing fileset #%d       ",
     391                current_tarball_number);
     392        log_msg(1, tmp);
     393    }
     394    unlink(logfile);
     395    paranoid_free(command);
     396    paranoid_free(tmp);
     397    paranoid_free(filelist_name);
     398    paranoid_free(logfile);
     399    malloc_string(archiver_exe);
     400    malloc_string(compressor_exe);
     401    return (retval);
    432402}
     403
    433404/**************************************************************************
    434405 *END_COMPARE_A_TARBALL                                                   *
     
    441412 * @return 0 for success, nonzero for failure.
    442413 */
    443 int
    444 compare_all_tarballs( struct s_bkpinfo *bkpinfo )
     414int compare_all_tarballs(struct s_bkpinfo *bkpinfo)
    445415{
    446   int retval = 0;
    447   int res;
    448   int current_tarball_number = 0;
     416    int retval = 0;
     417    int res;
     418    int current_tarball_number = 0;
    449419
    450420  /**  needs malloc **********/
    451  
    452   char *tarball_fname, *progress_str, *tmp;
    453   long max_val;
    454  
    455   malloc_string(tarball_fname);
    456   malloc_string(progress_str);
    457   malloc_string(tmp);
    458  
    459   assert(bkpinfo!=NULL);
    460   mvaddstr_and_log_it( g_currentY,0, "Comparing archives" );
    461   read_cfg_var( g_mondo_cfg_file, "last-filelist-number", tmp );
    462  
    463   max_val = atol( tmp );
    464   sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    465 
    466   open_progress_form("Comparing files",
    467              "Comparing tarballs against filesystem.",
    468              "Please wait. This may take some time.",
    469              progress_str,
    470              max_val);
    471 
    472   log_to_screen( progress_str );
    473  
    474   for( ;; )
    475     {
    476       insist_on_this_cd_number( bkpinfo, g_current_media_number );
    477       update_progress_form( progress_str );
    478       sprintf( tarball_fname,
    479            MNT_CDROM"/archives/%d.afio.bz2",
    480            current_tarball_number);
    481      
    482       if ( !does_file_exist( tarball_fname ) )
    483     {
    484       sprintf( tarball_fname, MNT_CDROM"/archives/%d.afio.lzo", current_tarball_number );
    485     }
    486       if (!does_file_exist ( tarball_fname ) )
    487     {
    488       sprintf(tarball_fname, MNT_CDROM"/archives/%d.afio.",
    489           current_tarball_number);
    490     }
    491       if (!does_file_exist ( tarball_fname ) )
    492     {
    493       sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.bz2",
    494           current_tarball_number);
    495     }
    496       if (!does_file_exist ( tarball_fname ) )
    497     {
    498       sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.",
    499           current_tarball_number);
    500     }
    501       if ( !does_file_exist( tarball_fname ) )
    502     {
    503       if ( !does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) ||
    504            system( "find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null" )
    505            == 0 )
    506         {
    507           log_msg(2, "OK, I think I'm done with tarballs..." );
    508           break;
    509         }
    510       log_msg(2, "OK, I think it's time for another CD..." );
    511       g_current_media_number++;
    512       sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    513       log_to_screen( progress_str );
    514     }
    515       else
    516     {
    517       res =
    518         compare_a_tarball( tarball_fname, current_tarball_number );
    519      
    520       g_current_progress++;
    521       current_tarball_number++;
    522     }
    523     }
    524   close_progress_form();
    525   if ( retval )
    526     {
    527       mvaddstr_and_log_it( g_currentY++,74, "Errors." );
    528     }
    529   else
    530     {
    531       mvaddstr_and_log_it( g_currentY++,
    532                74,
    533                "Done.");
    534     }
    535   paranoid_free(tarball_fname);
    536   paranoid_free(progress_str);
    537   paranoid_free(tmp);
    538   return(retval);
     421
     422    char *tarball_fname, *progress_str, *tmp;
     423    long max_val;
     424
     425    malloc_string(tarball_fname);
     426    malloc_string(progress_str);
     427    malloc_string(tmp);
     428
     429    assert(bkpinfo != NULL);
     430    mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
     431    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     432
     433    max_val = atol(tmp);
     434    sprintf(progress_str, "Comparing with %s #%d ",
     435            media_descriptor_string(bkpinfo->backup_media_type),
     436            g_current_media_number);
     437
     438    open_progress_form("Comparing files",
     439                       "Comparing tarballs against filesystem.",
     440                       "Please wait. This may take some time.",
     441                       progress_str, max_val);
     442
     443    log_to_screen(progress_str);
     444
     445    for (;;) {
     446        insist_on_this_cd_number(bkpinfo, g_current_media_number);
     447        update_progress_form(progress_str);
     448        sprintf(tarball_fname,
     449                MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
     450
     451        if (!does_file_exist(tarball_fname)) {
     452            sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
     453                    current_tarball_number);
     454        }
     455        if (!does_file_exist(tarball_fname)) {
     456            sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
     457                    current_tarball_number);
     458        }
     459        if (!does_file_exist(tarball_fname)) {
     460            sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
     461                    current_tarball_number);
     462        }
     463        if (!does_file_exist(tarball_fname)) {
     464            sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
     465                    current_tarball_number);
     466        }
     467        if (!does_file_exist(tarball_fname)) {
     468            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
     469                system("find " MNT_CDROM
     470                       "/archives/slice* > /dev/null 2> /dev/null")
     471                == 0) {
     472                log_msg(2, "OK, I think I'm done with tarballs...");
     473                break;
     474            }
     475            log_msg(2, "OK, I think it's time for another CD...");
     476            g_current_media_number++;
     477            sprintf(progress_str, "Comparing with %s #%d ",
     478                    media_descriptor_string(bkpinfo->backup_media_type),
     479                    g_current_media_number);
     480            log_to_screen(progress_str);
     481        } else {
     482            res = compare_a_tarball(tarball_fname, current_tarball_number);
     483
     484            g_current_progress++;
     485            current_tarball_number++;
     486        }
     487    }
     488    close_progress_form();
     489    if (retval) {
     490        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     491    } else {
     492        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     493    }
     494    paranoid_free(tarball_fname);
     495    paranoid_free(progress_str);
     496    paranoid_free(tmp);
     497    return (retval);
    539498}
     499
    540500/**************************************************************************
    541501 *END_COMPARE_ALL_TARBALLS                                                *
     
    554514 * @return 0 for success, nonzero for failure.
    555515 */
    556 int
    557 compare_to_CD( struct s_bkpinfo *bkpinfo )
     516int compare_to_CD(struct s_bkpinfo *bkpinfo)
    558517{
    559518  /** needs malloc *********/
    560   char *tmp, *cwd, *new, *command;
    561   int resA = 0;
    562   int resB = 0;
    563   long noof_changed_files;
    564  
    565   malloc_string(tmp);
    566   malloc_string(cwd);
    567   malloc_string(new);
    568   malloc_string(command);
    569  
    570   assert(bkpinfo!=NULL);
    571 
    572   getcwd( cwd, MAX_STR_LEN - 1 );
    573   chdir( bkpinfo->restore_path );
    574   getcwd( new, MAX_STR_LEN - 1 );
    575   sprintf( tmp, "new path is %s", new );
    576   insist_on_this_cd_number( bkpinfo, g_current_media_number );
    577   unlink( "/tmp/changed.txt" );
    578  
    579   resA = compare_all_tarballs( bkpinfo );
    580   resB = compare_all_biggiefiles( bkpinfo );
    581   chdir( cwd );
    582   noof_changed_files = count_lines_in_file( "/tmp/changed.txt" );
    583   if ( noof_changed_files )
    584     {
    585       sprintf( tmp, "%ld files do not match the backup            ",
    586            noof_changed_files );
    587       //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
    588       log_to_screen (tmp);
    589       sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE );
    590       paranoid_system( command );
    591     }
    592   else
    593     {
    594       sprintf( tmp, "All files match the backup                     ");
    595       mvaddstr_and_log_it( g_currentY++, 0, tmp );
    596       log_to_screen( tmp );
    597     }
    598  
    599   paranoid_free(tmp);
    600   paranoid_free(cwd);
    601   paranoid_free(new);
    602   paranoid_free(command);
    603 
    604   return( resA + resB );
     519    char *tmp, *cwd, *new, *command;
     520    int resA = 0;
     521    int resB = 0;
     522    long noof_changed_files;
     523
     524    malloc_string(tmp);
     525    malloc_string(cwd);
     526    malloc_string(new);
     527    malloc_string(command);
     528
     529    assert(bkpinfo != NULL);
     530
     531    getcwd(cwd, MAX_STR_LEN - 1);
     532    chdir(bkpinfo->restore_path);
     533    getcwd(new, MAX_STR_LEN - 1);
     534    sprintf(tmp, "new path is %s", new);
     535    insist_on_this_cd_number(bkpinfo, g_current_media_number);
     536    unlink("/tmp/changed.txt");
     537
     538    resA = compare_all_tarballs(bkpinfo);
     539    resB = compare_all_biggiefiles(bkpinfo);
     540    chdir(cwd);
     541    noof_changed_files = count_lines_in_file("/tmp/changed.txt");
     542    if (noof_changed_files) {
     543        sprintf(tmp, "%ld files do not match the backup            ",
     544                noof_changed_files);
     545        //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
     546        log_to_screen(tmp);
     547        sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
     548        paranoid_system(command);
     549    } else {
     550        sprintf(tmp, "All files match the backup                     ");
     551        mvaddstr_and_log_it(g_currentY++, 0, tmp);
     552        log_to_screen(tmp);
     553    }
     554
     555    paranoid_free(tmp);
     556    paranoid_free(cwd);
     557    paranoid_free(new);
     558    paranoid_free(command);
     559
     560    return (resA + resB);
    605561}
    606562
     
    622578 */
    623579int
    624 compare_mode( struct s_bkpinfo *bkpinfo ,
    625           struct mountlist_itself *mountlist,
    626           struct raidlist_itself *raidlist)
     580compare_mode(struct s_bkpinfo *bkpinfo,
     581             struct mountlist_itself *mountlist,
     582            struct raidlist_itself *raidlist)
    627583{
    628   int retval = 0;
    629   long q;
    630   char *tmp;
    631  
    632   malloc_string(tmp);
     584    int retval = 0;
     585    long q;
     586    char *tmp;
     587
     588    malloc_string(tmp);
    633589
    634590  /**************************************************************************
     
    636592   * restore them from start of tape, if available                          *
    637593   **************************************************************************/
    638   assert(bkpinfo!=NULL);
    639   assert(mountlist!=NULL);
    640   assert(raidlist!=NULL);
    641 
    642   while (get_cfg_file_from_archive( bkpinfo ))
    643     {
    644       if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?"))
    645         { fatal_error("Unable to find config file/archives. Aborting."); }
    646       interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    647     }
    648 
    649   read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    650   g_current_media_number = 1;
    651   mvaddstr_and_log_it( 1, 30, "Comparing Automatically" );
    652   iamhere("Pre-MAD");
    653   retval = mount_all_devices( mountlist, FALSE );
    654   iamhere("Post-MAD");
    655   if ( retval )
    656     {
    657       unmount_all_devices( mountlist );
    658       return( retval );
    659     }
    660   if ( bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    661     {
    662       retval += compare_to_tape( bkpinfo );
    663     }
    664   else if ( bkpinfo->backup_media_type == cdstream )
    665     {
    666       retval += compare_to_cdstream( bkpinfo );
    667     }
    668   else
    669     {
    670       retval += compare_to_CD( bkpinfo );
    671     }
    672   if ( retval )
    673     {
    674       mvaddstr_and_log_it( g_currentY++,
    675                0,
    676                "Warning - differences found during the compare phase");
    677     }
    678 
    679   retval += unmount_all_devices( mountlist );
    680 
    681   if ( count_lines_in_file("/tmp/changed.txt") > 0 )
    682     {
    683       mvaddstr_and_log_it( g_currentY++, 0,
    684                "Differences found while files were being compared." );
    685       streamline_changes_file( "/tmp/changed.files", "/tmp/changed.txt" );
    686       if (count_lines_in_file( "/tmp/changed.files" ) <= 0 )
    687         {
    688       mvaddstr_and_log_it( g_currentY++,0,
    689                    "...but they were logfiles and temporary files. Your archives are fine.");
    690       log_to_screen( "The differences were logfiles and temporary files. Your archives are fine.");
    691     }
    692       else
    693         {
    694       q = count_lines_in_file("/tmp/changed.files");
    695       sprintf( tmp, "%ld significant difference%s found.", q, (q!=1) ? "s" : "");
    696       mvaddstr_and_log_it( g_currentY++, 0, tmp);
    697       log_to_screen (tmp);
    698 
    699       strcpy( tmp, "Type 'less /tmp/changed.files' for a list of non-matching files" );
    700       mvaddstr_and_log_it( g_currentY++, 0, tmp );
    701       log_to_screen( tmp );
    702 
    703           log_msg(2, "calling popup_changelist_from_file()");
    704           popup_changelist_from_file("/tmp/changed.files");
    705           log_msg(2, "Returning from popup_changelist_from_file()");
    706     }
    707     }
    708   else
    709     {
    710       log_to_screen( "No significant differences were found. Your backup is perfect." );
    711     }
    712   kill_petris();
    713   paranoid_free(tmp);
    714   return( retval );
     594    assert(bkpinfo != NULL);
     595    assert(mountlist != NULL);
     596    assert(raidlist != NULL);
     597
     598    while (get_cfg_file_from_archive(bkpinfo)) {
     599        if (!ask_me_yes_or_no
     600            ("Failed to find config file/archives. Choose another source?"))
     601        {
     602            fatal_error("Unable to find config file/archives. Aborting.");
     603        }
     604        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     605    }
     606
     607    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     608    g_current_media_number = 1;
     609    mvaddstr_and_log_it(1, 30, "Comparing Automatically");
     610    iamhere("Pre-MAD");
     611    retval = mount_all_devices(mountlist, FALSE);
     612    iamhere("Post-MAD");
     613    if (retval) {
     614        unmount_all_devices(mountlist);
     615        return (retval);
     616    }
     617    if (bkpinfo->backup_media_type == tape
     618        || bkpinfo->backup_media_type == udev) {
     619        retval += compare_to_tape(bkpinfo);
     620    } else if (bkpinfo->backup_media_type == cdstream) {
     621        retval += compare_to_cdstream(bkpinfo);
     622    } else {
     623        retval += compare_to_CD(bkpinfo);
     624    }
     625    if (retval) {
     626        mvaddstr_and_log_it(g_currentY++,
     627                            0,
     628                            "Warning - differences found during the compare phase");
     629    }
     630
     631    retval += unmount_all_devices(mountlist);
     632
     633    if (count_lines_in_file("/tmp/changed.txt") > 0) {
     634        mvaddstr_and_log_it(g_currentY++, 0,
     635                            "Differences found while files were being compared.");
     636        streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt");
     637        if (count_lines_in_file("/tmp/changed.files") <= 0) {
     638            mvaddstr_and_log_it(g_currentY++, 0,
     639                                "...but they were logfiles and temporary files. Your archives are fine.");
     640            log_to_screen
     641                ("The differences were logfiles and temporary files. Your archives are fine.");
     642        } else {
     643            q = count_lines_in_file("/tmp/changed.files");
     644            sprintf(tmp, "%ld significant difference%s found.", q,
     645                    (q != 1) ? "s" : "");
     646            mvaddstr_and_log_it(g_currentY++, 0, tmp);
     647            log_to_screen(tmp);
     648
     649            strcpy(tmp,
     650                   "Type 'less /tmp/changed.files' for a list of non-matching files");
     651            mvaddstr_and_log_it(g_currentY++, 0, tmp);
     652            log_to_screen(tmp);
     653
     654            log_msg(2, "calling popup_changelist_from_file()");
     655            popup_changelist_from_file("/tmp/changed.files");
     656            log_msg(2, "Returning from popup_changelist_from_file()");
     657        }
     658    } else {
     659        log_to_screen
     660            ("No significant differences were found. Your backup is perfect.");
     661    }
     662    kill_petris();
     663    paranoid_free(tmp);
     664    return (retval);
    715665}
    716666
     
    727677 * @return 0 for success, nonzero for failure.
    728678 */
    729 int
    730 compare_to_cdstream(struct s_bkpinfo *bkpinfo)
     679int compare_to_cdstream(struct s_bkpinfo *bkpinfo)
    731680{
    732   int res;
     681    int res;
    733682
    734683  /** needs malloc **/
    735   char *dir, *command;
    736  
    737   assert(bkpinfo!=NULL);
    738   malloc_string(dir);
    739   malloc_string(command);
    740   getcwd( dir, MAX_STR_LEN );
    741   chdir( bkpinfo->restore_path );
    742 
    743   sprintf( command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path );
    744   run_program_and_log_output( command, FALSE );
    745   mvaddstr_and_log_it(g_currentY,
    746               0,
    747               "Verifying archives against filesystem" );
    748 
    749   if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE"))
    750     { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); }
    751   else
    752     { find_cdrom_device( bkpinfo->media_device, FALSE ); }
    753   res = verify_tape_backups( bkpinfo );
    754   chdir( dir );
    755   if ( length_of_file ( "/tmp/changed.txt" ) > 2 && length_of_file ( "/tmp/changed.files" ) > 2 )
    756     {
    757       log_msg(0, "Type 'less /tmp/changed.files' to see which files don't match the archives" );
    758       log_msg(2, "Calling popup_changelist_from_file()" );
    759       popup_changelist_from_file( "/tmp/changed.files" );
    760       log_msg(2, "Returned from popup_changelist_from_file()" );
    761     }
    762 
    763   mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    764   paranoid_free(dir);
    765   paranoid_free(command);
    766   return( res );
     684    char *dir, *command;
     685
     686    assert(bkpinfo != NULL);
     687    malloc_string(dir);
     688    malloc_string(command);
     689    getcwd(dir, MAX_STR_LEN);
     690    chdir(bkpinfo->restore_path);
     691
     692    sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     693            bkpinfo->restore_path);
     694    run_program_and_log_output(command, FALSE);
     695    mvaddstr_and_log_it(g_currentY,
     696                        0, "Verifying archives against filesystem");
     697
     698    if (bkpinfo->disaster_recovery
     699        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     700        strcpy(bkpinfo->media_device,
     701               last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     702    } else {
     703        find_cdrom_device(bkpinfo->media_device, FALSE);
     704    }
     705    res = verify_tape_backups(bkpinfo);
     706    chdir(dir);
     707    if (length_of_file("/tmp/changed.txt") > 2
     708        && length_of_file("/tmp/changed.files") > 2) {
     709        log_msg(0,
     710                "Type 'less /tmp/changed.files' to see which files don't match the archives");
     711        log_msg(2, "Calling popup_changelist_from_file()");
     712        popup_changelist_from_file("/tmp/changed.files");
     713        log_msg(2, "Returned from popup_changelist_from_file()");
     714    }
     715
     716    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     717    paranoid_free(dir);
     718    paranoid_free(command);
     719    return (res);
    767720}
     721
    768722/**************************************************************************
    769723 *END_COMPARE_CD_STREAM                                                   *
     
    782736 * returns: int                                                           *
    783737 **************************************************************************/
    784 int
    785 compare_to_tape( struct s_bkpinfo *bkpinfo )
     738int compare_to_tape(struct s_bkpinfo *bkpinfo)
    786739{
    787   int res;
    788   char *dir, *command;
    789    
    790   assert(bkpinfo!=NULL);
    791   malloc_string(dir);
    792   malloc_string(command);
    793 
    794   getcwd( dir, MAX_STR_LEN );
    795   chdir( bkpinfo->restore_path );
    796   sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path);
    797   run_program_and_log_output( command, FALSE );
    798   mvaddstr_and_log_it( g_currentY,
    799                0,
    800                "Verifying archives against filesystem");
    801   res = verify_tape_backups( bkpinfo );
    802   chdir( dir );
    803   if ( res )
    804     {
    805       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    806     }
    807   else
    808     {
    809       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    810     }
    811   paranoid_free(dir);
    812   paranoid_free(command);
    813   return( res );
     740    int res;
     741    char *dir, *command;
     742
     743    assert(bkpinfo != NULL);
     744    malloc_string(dir);
     745    malloc_string(command);
     746
     747    getcwd(dir, MAX_STR_LEN);
     748    chdir(bkpinfo->restore_path);
     749    sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     750            bkpinfo->restore_path);
     751    run_program_and_log_output(command, FALSE);
     752    mvaddstr_and_log_it(g_currentY,
     753                        0, "Verifying archives against filesystem");
     754    res = verify_tape_backups(bkpinfo);
     755    chdir(dir);
     756    if (res) {
     757        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     758    } else {
     759        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     760    }
     761    paranoid_free(dir);
     762    paranoid_free(command);
     763    return (res);
    814764}
    815765
     
    819769
    820770/* @} - end compareGroup */
    821 
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare.h

    r30 r128  
    11/* mondo-rstr-compare.h
    2  * $Id: mondo-rstr-compare.h,v 1.1 2004/06/10 15:29:13 hugo Exp $
     2 * $Id$
    33 */
    44
    55
    6 int compare_to_CD(struct s_bkpinfo*);
    7 int compare_to_cdstream(struct s_bkpinfo*);
    8 int compare_to_tape(struct s_bkpinfo*);
     6int compare_to_CD(struct s_bkpinfo *);
     7int compare_to_cdstream(struct s_bkpinfo *);
     8int compare_to_tape(struct s_bkpinfo *);
    99
    10 int 
    11 compare_mode( struct s_bkpinfo *bkpinfo ,
    12           struct mountlist_itself *mountlist,
    13           struct raidlist_itself *raidlist);
     10int
     11compare_mode(struct s_bkpinfo *bkpinfo,
     12             struct mountlist_itself *mountlist,
     13            struct raidlist_itself *raidlist);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-newt.c

    r30 r128  
    88edited by : by Stan Benoit 4/2002
    99email     : troff@nakedsoul.org
    10 cvsid     : $Id: mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp $
     10cvsid     : $Id$
    1111***************************************************************************/
    1212
     
    9292#include "mondo-rstr-newt.h"
    9393
    94 //static char cvsid[] = "$Id: mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp $";
     94//static char cvsid[] = "$Id$";
    9595
    9696extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
     
    127127 */
    128128void
    129 add_disklist_entry (struct list_of_disks *disklist, char *raid_device,
    130             struct mountlist_itself *unallocated_raid_partitions)
     129add_disklist_entry(struct list_of_disks *disklist, char *raid_device,
     130                   struct mountlist_itself *unallocated_raid_partitions)
    131131{
    132132    /** buffers ***********************************************************/
    133   char tmp[MAX_STR_LEN];
     133    char tmp[MAX_STR_LEN];
    134134
    135135    /** newt **************************************************************/
    136   newtComponent myForm;
     136    newtComponent myForm;
    137137    newtComponent bOK;
    138138    newtComponent bCancel;
     
    140140    newtComponent partitionsListbox;
    141141    newtComponent headerMsg;
    142    
     142
    143143  /** prototypes *********************************************************/
    144   void *keylist[ARBITRARY_MAXIMUM];
    145   void *curr_choice;
     144    void *keylist[ARBITRARY_MAXIMUM];
     145    void *curr_choice;
    146146
    147147    /** int ****************************************************************/
    148   int i = 0;
     148    int i = 0;
    149149    int index = 0;
    150150    int currline = 0;
    151151    int items = 0;
    152152
    153   assert(disklist!=NULL);
    154   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    155   assert(unallocated_raid_partitions!=NULL);
    156 
    157   newtPushHelpLine
    158     ("   Add one of the following unallocated RAID partitions to this RAID device.");
    159   sprintf (tmp, "%-26s %s", "Device", "Size");
    160   headerMsg = newtLabel (1, 1, tmp);
    161   partitionsListbox =
    162     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    163   redraw_unallocpartnslist (unallocated_raid_partitions, keylist,
    164                 partitionsListbox);
    165   i = 7;
    166   bOK = newtCompactButton (i, 9, "  OK  ");
    167   bCancel = newtCompactButton (i += 9, 9, "Cancel");
    168   newtOpenWindow (22, 6, 36, 10, "Unallocated RAID partitions");
    169   myForm = newtForm (NULL, NULL, 0);
    170   newtFormAddComponents (myForm, headerMsg, partitionsListbox, bOK, bCancel,
    171              NULL);
    172   b_res = newtRunForm (myForm);
    173   if (b_res != bCancel)
    174     {
    175       curr_choice = newtListboxGetCurrent (partitionsListbox);
    176       for (currline = 0;
    177        currline < unallocated_raid_partitions->entries
    178        && keylist[currline] != curr_choice; currline++);
    179       if (currline == unallocated_raid_partitions->entries
    180       && unallocated_raid_partitions->entries > 0)
    181     {
    182       log_it ("I don't know what this button does");
    183     }
    184       else
    185     {
    186       index = find_next_free_index_in_disklist (disklist);
    187    
    188       items = disklist->entries;
    189       strcpy (disklist->el[items].device,
    190           unallocated_raid_partitions->el[currline].device);
    191       disklist->el[items].index = index;
    192       disklist->entries = ++items;
    193    
    194     }
    195     }
    196   newtFormDestroy (myForm);
    197   newtPopWindow ();
    198   newtPopHelpLine ();
     153    assert(disklist != NULL);
     154    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     155    assert(unallocated_raid_partitions != NULL);
     156
     157    newtPushHelpLine
     158        ("   Add one of the following unallocated RAID partitions to this RAID device.");
     159    sprintf(tmp, "%-26s %s", "Device", "Size");
     160    headerMsg = newtLabel(1, 1, tmp);
     161    partitionsListbox =
     162        newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     163    redraw_unallocpartnslist(unallocated_raid_partitions, keylist,
     164                             partitionsListbox);
     165    i = 7;
     166    bOK = newtCompactButton(i, 9, "  OK  ");
     167    bCancel = newtCompactButton(i += 9, 9, "Cancel");
     168    newtOpenWindow(22, 6, 36, 10, "Unallocated RAID partitions");
     169    myForm = newtForm(NULL, NULL, 0);
     170    newtFormAddComponents(myForm, headerMsg, partitionsListbox, bOK,
     171                          bCancel, NULL);
     172    b_res = newtRunForm(myForm);
     173    if (b_res != bCancel) {
     174        curr_choice = newtListboxGetCurrent(partitionsListbox);
     175        for (currline = 0;
     176             currline < unallocated_raid_partitions->entries
     177             && keylist[currline] != curr_choice; currline++);
     178        if (currline == unallocated_raid_partitions->entries
     179            && unallocated_raid_partitions->entries > 0) {
     180            log_it("I don't know what this button does");
     181        } else {
     182            index = find_next_free_index_in_disklist(disklist);
     183
     184            items = disklist->entries;
     185            strcpy(disklist->el[items].device,
     186                   unallocated_raid_partitions->el[currline].device);
     187            disklist->el[items].index = index;
     188            disklist->entries = ++items;
     189
     190        }
     191    }
     192    newtFormDestroy(myForm);
     193    newtPopWindow();
     194    newtPopHelpLine();
    199195}
    200196
     
    212208 */
    213209void
    214 add_mountlist_entry (struct mountlist_itself *mountlist,
    215              struct raidlist_itself *raidlist, newtComponent listbox,
    216             int currline, void *keylist[])
     210add_mountlist_entry(struct mountlist_itself *mountlist,
     211                    struct raidlist_itself *raidlist,
     212                    newtComponent listbox, int currline, void *keylist[])
    217213{
    218214
    219215    /** int **************************************************************/
    220   int i = 0;
     216    int i = 0;
    221217    int num_to_add = 0;
    222218
    223219    /** newt *************************************************************/
    224   newtComponent myForm;
     220    newtComponent myForm;
    225221    newtComponent bOK;
    226222    newtComponent bCancel;
     
    236232
    237233    /** buffers **********************************************************/
    238   char drive_to_add[MAX_STR_LEN];
     234    char drive_to_add[MAX_STR_LEN];
    239235    char mountpoint_str[MAX_STR_LEN];
    240236    char size_str[MAX_STR_LEN];
    241   char device_str[MAX_STR_LEN];
     237    char device_str[MAX_STR_LEN];
    242238    char format_str[MAX_STR_LEN];
    243239
     
    248244    char *format_here;
    249245
    250   assert(mountlist!=NULL);
    251   assert(raidlist!=NULL);
    252   assert(listbox!=NULL);
    253   assert(keylist!=NULL);
    254 
    255     strcpy (device_str, "/dev/");
    256     strcpy (mountpoint_str, "/");
     246    assert(mountlist != NULL);
     247    assert(raidlist != NULL);
     248    assert(listbox != NULL);
     249    assert(keylist != NULL);
     250
     251    strcpy(device_str, "/dev/");
     252    strcpy(mountpoint_str, "/");
    257253#ifdef __FreeBSD__
    258     strcpy (format_str, "ufs");
     254    strcpy(format_str, "ufs");
    259255#else
    260   strcpy (format_str, "ext2");
     256    strcpy(format_str, "ext2");
    261257#endif
    262   size_str[0] = '\0';
    263   /* sprintf(size_str,""); */
    264   newtOpenWindow (20, 5, 48, 10, "Add entry");
    265   label0 = newtLabel (2, 1, "Device:    ");
    266   label1 = newtLabel (2, 2, "Mountpoint:");
    267   label2 = newtLabel (2, 3, "Size (MB): ");
    268   label3 = newtLabel (2, 4, "Format:    ");
    269   deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0);
    270   mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0);
    271   formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0);
    272   sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0);
    273   bOK = newtButton (5, 6, "  OK  ");
    274   bCancel = newtButton (17, 6, "Cancel");
    275   newtPushHelpLine
    276     ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'");
    277   myForm = newtForm (NULL, NULL, 0);
    278   newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp,
    279              formatComp, label0, label1, label2, label3, bOK,
    280              bCancel, NULL);
    281   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    282     {
    283       b_res = newtRunForm (myForm);
    284       strcpy (device_str, device_here);
    285       strcpy (mountpoint_str, mountpoint_here);
    286       strcpy (format_str, format_here);
    287       strcpy (size_str, size_here);
     258    size_str[0] = '\0';
     259    /* sprintf(size_str,""); */
     260    newtOpenWindow(20, 5, 48, 10, "Add entry");
     261    label0 = newtLabel(2, 1, "Device:    ");
     262    label1 = newtLabel(2, 2, "Mountpoint:");
     263    label2 = newtLabel(2, 3, "Size (MB): ");
     264    label3 = newtLabel(2, 4, "Format:    ");
     265    deviceComp =
     266        newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     267    mountpointComp =
     268        newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     269    formatComp =
     270        newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     271    sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
     272    bOK = newtButton(5, 6, "  OK  ");
     273    bCancel = newtButton(17, 6, "Cancel");
     274    newtPushHelpLine
     275        ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'");
     276    myForm = newtForm(NULL, NULL, 0);
     277    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     278                          formatComp, label0, label1, label2, label3, bOK,
     279                          bCancel, NULL);
     280    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     281        b_res = newtRunForm(myForm);
     282        strcpy(device_str, device_here);
     283        strcpy(mountpoint_str, mountpoint_here);
     284        strcpy(format_str, format_here);
     285        strcpy(size_str, size_here);
    288286//      log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    289       strip_spaces (device_str);
    290       strip_spaces (mountpoint_str);
    291       strip_spaces (format_str);
    292       strip_spaces (size_str);
     287        strip_spaces(device_str);
     288        strip_spaces(mountpoint_str);
     289        strip_spaces(format_str);
     290        strip_spaces(size_str);
    293291//      log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    294       if (b_res == bOK)
    295     {
    296       if (device_str[strlen (device_str) - 1] == '/')
    297         {
    298           popup_and_OK ("You left the device nearly blank!");
    299           b_res = NULL;
    300         }
    301       if (size_of_specific_device_in_mountlist (mountlist, device_str) >= 0)
    302         {
    303           popup_and_OK ("Can't add this - you've got one already!");
    304           b_res = NULL;
    305         }
    306     }
    307     }
    308   newtFormDestroy (myForm);
    309   newtPopHelpLine ();
    310   newtPopWindow ();
    311   if (b_res == bCancel)
    312     {
    313       return;
    314     }
    315   strcpy (drive_to_add, device_str);
    316   for (i = strlen (drive_to_add); isdigit (drive_to_add[i - 1]); i--);
    317   num_to_add = atoi (drive_to_add + i);
    318   drive_to_add[i] = '\0';
    319   currline = mountlist->entries;
    320   strcpy (mountlist->el[currline].device, device_str);
    321   strcpy (mountlist->el[currline].mountpoint, mountpoint_str);
    322   strcpy (mountlist->el[currline].format, format_str);
    323   mountlist->el[currline].size = atol (size_str) * 1024;
    324   mountlist->entries++;
    325   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    326     {
    327       initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str);
    328     }
    329   redraw_mountlist (mountlist, keylist, listbox);
     292        if (b_res == bOK) {
     293            if (device_str[strlen(device_str) - 1] == '/') {
     294                popup_and_OK("You left the device nearly blank!");
     295                b_res = NULL;
     296            }
     297            if (size_of_specific_device_in_mountlist(mountlist, device_str)
     298                >= 0) {
     299                popup_and_OK("Can't add this - you've got one already!");
     300                b_res = NULL;
     301            }
     302        }
     303    }
     304    newtFormDestroy(myForm);
     305    newtPopHelpLine();
     306    newtPopWindow();
     307    if (b_res == bCancel) {
     308        return;
     309    }
     310    strcpy(drive_to_add, device_str);
     311    for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--);
     312    num_to_add = atoi(drive_to_add + i);
     313    drive_to_add[i] = '\0';
     314    currline = mountlist->entries;
     315    strcpy(mountlist->el[currline].device, device_str);
     316    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     317    strcpy(mountlist->el[currline].format, format_str);
     318    mountlist->el[currline].size = atol(size_str) * 1024;
     319    mountlist->entries++;
     320    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     321        initiate_new_raidlist_entry(raidlist, mountlist, currline,
     322                                    device_str);
     323    }
     324    redraw_mountlist(mountlist, keylist, listbox);
    330325}
    331326
     
    337332 * @ingroup restoreGuiVarslist
    338333 */
    339 void
    340 add_varslist_entry (struct raid_device_record *raidrec)
     334void add_varslist_entry(struct raid_device_record *raidrec)
    341335{
    342336
    343337    /** buffers ***********************************************************/
    344   char sz_out[MAX_STR_LEN];
     338    char sz_out[MAX_STR_LEN];
    345339
    346340    /** int ****************************************************************/
    347   int items = 0;
     341    int items = 0;
    348342    int i = 0;
    349343
    350   assert(raidrec!=NULL);
    351 
    352   sz_out[0] = '\0';
    353   if (popup_and_get_string
    354       ("Add variable", "Enter the name of the variable to add", sz_out, MAX_STR_LEN))
    355     {
    356       strip_spaces (sz_out);
    357       items = raidrec->additional_vars.entries;
    358       for (i = 0;
    359        i < items && strcmp (raidrec->additional_vars.el[i].label, sz_out);
    360        i++);
    361       if (i < items)
    362     {
    363       popup_and_OK
    364         ("No need to add that variable. It is already listed here.");
    365     }
    366       else
    367     {
    368       strcpy (raidrec->additional_vars.el[items].label, sz_out);
    369       edit_varslist_entry (raidrec, items);
    370       raidrec->additional_vars.entries = ++items;
    371     }
    372     }
     344    assert(raidrec != NULL);
     345
     346    sz_out[0] = '\0';
     347    if (popup_and_get_string
     348        ("Add variable", "Enter the name of the variable to add", sz_out,
     349         MAX_STR_LEN)) {
     350        strip_spaces(sz_out);
     351        items = raidrec->additional_vars.entries;
     352        for (i = 0;
     353             i < items
     354             && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++);
     355        if (i < items) {
     356            popup_and_OK
     357                ("No need to add that variable. It is already listed here.");
     358        } else {
     359            strcpy(raidrec->additional_vars.el[items].label, sz_out);
     360            edit_varslist_entry(raidrec, items);
     361            raidrec->additional_vars.entries = ++items;
     362        }
     363    }
    373364}
    374365#endif
     
    383374 */
    384375long
    385 calculate_raid_device_size (struct mountlist_itself *mountlist,
    386                 struct raidlist_itself *raidlist,
    387                 char *raid_device)
     376calculate_raid_device_size(struct mountlist_itself *mountlist,
     377                           struct raidlist_itself *raidlist,
     378                           char *raid_device)
    388379{
    389380#ifdef __FreeBSD__
    390     /** FreeBSD-specific version of calculate_raid_device_size() **/
     381    /** FreeBSD-specific version of calculate_raid_device_size() **/
    391382
    392383    /** structures ********************************************************/
    393   struct vinum_volume *raidrec;
     384    struct vinum_volume *raidrec;
    394385
    395386    /** int ***************************************************************/
    396   int i = 0, j = 0;
     387    int i = 0, j = 0;
    397388    int noof_partitions = 0;
    398389
    399390    /** long **************************************************************/
    400   long total_size = 0;
    401   long plex_size = 0;
    402   long smallest_partition = 999999999;
    403   long smallest_plex      = 999999999;
     391    long total_size = 0;
     392    long plex_size = 0;
     393    long smallest_partition = 999999999;
     394    long smallest_plex = 999999999;
    404395    long sp = 0;
    405396
    406397    /** buffers ***********************************************************/
    407   char tmp[MAX_STR_LEN];
    408 
    409 
    410 
    411 
    412   for (i = 0;
    413        i < raidlist->entries
    414        && strcmp (raidlist->el[i].volname, basename (raid_device)); i++);
    415   if (i == raidlist->entries)
    416     {
    417       sprintf (tmp,
    418            "Cannot calc size of raid device %s - cannot find it in raidlist",
    419            raid_device);
    420       log_it (tmp);
    421       return (0); // Isn't this more sensible than 999999999? If the raid dev !exists,
    422                   // then it has no size, right?
    423     }
    424   raidrec = &raidlist->el[i];
    425   total_size = 0;
    426   if (raidrec->plexes == 0) return 0;
    427   for (j = 0; j < raidrec->plexes; j++) {
    428       plex_size = 0;
    429       int k = 0, l = 0;
    430       for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
    431       char devname[64];
    432       strcpy (devname, raidrec->plex[j].sd[k].which_device);
    433       for (l = 0; l < raidlist->disks.entries; ++l) {
    434           if (!strcmp (devname, raidlist->disks.el[l].name)) {
    435           switch (raidrec->plex[j].raidlevel) {
    436           case -1:
    437               plex_size +=
    438               size_of_specific_device_in_mountlist (mountlist,
    439                                 raidlist->disks.el[l].device);
    440               break;
    441           case 0:
    442           case 5:
    443               if (size_of_specific_device_in_mountlist (mountlist,
    444                                    raidlist->disks.el[l].device) < smallest_partition) {
    445               smallest_partition = size_of_specific_device_in_mountlist (mountlist,
    446                                             raidlist->disks.el[l].device);
    447               }
    448               break;
    449           }
    450           }
    451       }
    452       }
    453      
    454       if (!is_this_raid_personality_registered (raidrec->plex[j].raidlevel)) {
    455       log_it ("%s has a really weird RAID level - couldn't calc size :(", raid_device);
    456       return (999999999);
    457       }
    458       if (raidrec->plex[j].raidlevel != -1) {
    459       plex_size = smallest_partition * (raidrec->plex[j].subdisks -
    460                         (raidrec->plex[j].raidlevel == 5 ? 1 : 0));
    461       }
    462       if (plex_size < smallest_plex)
    463       smallest_plex = plex_size;
    464 
    465       smallest_partition = 999999999;
    466   }
    467 
    468   sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device,
    469        (long) smallest_plex);
    470   log_it (tmp);
    471   return (smallest_plex);
     398    char tmp[MAX_STR_LEN];
     399
     400
     401
     402
     403    for (i = 0;
     404         i < raidlist->entries
     405         && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
     406    if (i == raidlist->entries) {
     407        sprintf(tmp,
     408                "Cannot calc size of raid device %s - cannot find it in raidlist",
     409                raid_device);
     410        log_it(tmp);
     411        return (0);             // Isn't this more sensible than 999999999? If the raid dev !exists,
     412        // then it has no size, right?
     413    }
     414    raidrec = &raidlist->el[i];
     415    total_size = 0;
     416    if (raidrec->plexes == 0)
     417        return 0;
     418    for (j = 0; j < raidrec->plexes; j++) {
     419        plex_size = 0;
     420        int k = 0, l = 0;
     421        for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
     422            char devname[64];
     423            strcpy(devname, raidrec->plex[j].sd[k].which_device);
     424            for (l = 0; l < raidlist->disks.entries; ++l) {
     425                if (!strcmp(devname, raidlist->disks.el[l].name)) {
     426                    switch (raidrec->plex[j].raidlevel) {
     427                    case -1:
     428                        plex_size +=
     429                            size_of_specific_device_in_mountlist(mountlist,
     430                                                                 raidlist->
     431                                                                 disks.
     432                                                                 el[l].
     433                                                                 device);
     434                        break;
     435                    case 0:
     436                    case 5:
     437                        if (size_of_specific_device_in_mountlist(mountlist,
     438                                                                 raidlist->
     439                                                                 disks.
     440                                                                 el[l].
     441                                                                 device) <
     442                            smallest_partition) {
     443                            smallest_partition =
     444                                size_of_specific_device_in_mountlist
     445                                (mountlist, raidlist->disks.el[l].device);
     446                        }
     447                        break;
     448                    }
     449                }
     450            }
     451        }
     452
     453        if (!is_this_raid_personality_registered
     454            (raidrec->plex[j].raidlevel)) {
     455            log_it
     456                ("%s has a really weird RAID level - couldn't calc size :(",
     457                 raid_device);
     458            return (999999999);
     459        }
     460        if (raidrec->plex[j].raidlevel != -1) {
     461            plex_size = smallest_partition * (raidrec->plex[j].subdisks -
     462                                              (raidrec->plex[j].
     463                                               raidlevel == 5 ? 1 : 0));
     464        }
     465        if (plex_size < smallest_plex)
     466            smallest_plex = plex_size;
     467
     468        smallest_partition = 999999999;
     469    }
     470
     471    sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
     472            (long) smallest_plex);
     473    log_it(tmp);
     474    return (smallest_plex);
    472475#else
    473     /** Linux-specific version of calculate_raid_device_size() **/
     476    /** Linux-specific version of calculate_raid_device_size() **/
    474477
    475478    /** structures ********************************************************/
    476   struct raid_device_record *raidrec;
     479    struct raid_device_record *raidrec;
    477480
    478481    /** int ***************************************************************/
    479   int i = 0;
     482    int i = 0;
    480483    int noof_partitions = 0;
    481484
    482485    /** long **************************************************************/
    483   long total_size = 0;
     486    long total_size = 0;
    484487    long smallest_partition = 999999999;
    485488    long sp = 0;
    486489
    487490    /** buffers ***********************************************************/
    488   char tmp[MAX_STR_LEN];
    489 
    490   assert(mountlist!=NULL);
    491   assert(raidlist!=NULL);
    492   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    493 
    494   for (i = 0;
    495        i < raidlist->entries
    496        && strcmp (raidlist->el[i].raid_device, raid_device); i++);
    497   if (i == raidlist->entries)
    498     {
    499       sprintf (tmp,
    500            "Cannot calc size of raid device %s - cannot find it in raidlist",
    501            raid_device);
    502       log_it (tmp);
    503       return (999999999);
    504     }
    505   raidrec = &raidlist->el[i];
    506   noof_partitions = raidrec->data_disks.entries;
    507   if (raidrec->raid_level == -1 || raidrec->raid_level == 0)
    508     {
    509       for (total_size = 0, i = 0; i < noof_partitions; i++)
    510     {
    511       total_size +=
    512         size_of_specific_device_in_mountlist (mountlist,
    513                      raidrec->data_disks.el[i].device);
    514     }
    515     }
    516   else
    517     {
    518       for (i = 0; i < noof_partitions; i++)
    519     {
    520       sp =
    521         size_of_specific_device_in_mountlist (mountlist,
    522                      raidrec->data_disks.el[i].device);
    523       if (smallest_partition > sp)
    524         {
    525           smallest_partition = sp;
    526         }
    527     }
    528       total_size = smallest_partition * (noof_partitions - 1);
    529     }
    530   sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device,
    531        (long) total_size);
    532   log_it (tmp);
    533   return (total_size);
     491    char tmp[MAX_STR_LEN];
     492
     493    assert(mountlist != NULL);
     494    assert(raidlist != NULL);
     495    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     496
     497    for (i = 0;
     498         i < raidlist->entries
     499         && strcmp(raidlist->el[i].raid_device, raid_device); i++);
     500    if (i == raidlist->entries) {
     501        sprintf(tmp,
     502                "Cannot calc size of raid device %s - cannot find it in raidlist",
     503                raid_device);
     504        log_it(tmp);
     505        return (999999999);
     506    }
     507    raidrec = &raidlist->el[i];
     508    noof_partitions = raidrec->data_disks.entries;
     509    if (raidrec->raid_level == -1 || raidrec->raid_level == 0) {
     510        for (total_size = 0, i = 0; i < noof_partitions; i++) {
     511            total_size +=
     512                size_of_specific_device_in_mountlist(mountlist,
     513                                                     raidrec->data_disks.
     514                                                     el[i].device);
     515        }
     516    } else {
     517        for (i = 0; i < noof_partitions; i++) {
     518            sp = size_of_specific_device_in_mountlist(mountlist,
     519                                                      raidrec->data_disks.
     520                                                      el[i].device);
     521            if (smallest_partition > sp) {
     522                smallest_partition = sp;
     523            }
     524        }
     525        total_size = smallest_partition * (noof_partitions - 1);
     526    }
     527    sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
     528            (long) total_size);
     529    log_it(tmp);
     530    return (total_size);
    534531#endif
    535532}
     
    543540 */
    544541void
    545 choose_raid_level (struct OSSWAP (raid_device_record, vinum_plex) *raidrec)
     542choose_raid_level(struct OSSWAP (raid_device_record, vinum_plex) * raidrec)
    546543{
    547544
    548545#ifdef __FreeBSD__
    549    
     546
    550547    /** int ***************************************************************/
    551   int res = 0;
     548    int res = 0;
    552549    int out = 0;
    553550
    554551    /** buffers ***********************************************************/
    555   char tmp[MAX_STR_LEN];
    556   char prompt[MAX_STR_LEN];
    557   char sz[MAX_STR_LEN];
    558 
    559   sprintf (prompt, "Please enter the RAID level you want. (concat, striped, raid5)");
    560   if (raidrec->raidlevel == -1)
    561     {
    562       strcpy (tmp, "concat");
    563     }
    564   else if (raidrec->raidlevel == 0)
    565     {
    566       strcpy (tmp, "striped");
    567     } else {
    568     sprintf (tmp, "raid%i", raidrec->raidlevel);
    569     }
    570   for (out = 999; out == 999;)
    571     {
    572       res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10);
    573       if (!res)
    574     {
    575       return;
    576     }
    577       strip_spaces (tmp);
    578       if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']')
    579     {
    580       strcpy (sz, tmp);
    581       strncpy (tmp, sz + 1, strlen (sz) - 2);
    582       tmp[strlen (sz) - 2] = '\0';
    583     }
    584       if (!strcmp (tmp, "concat"))
    585     {
    586       out = -1;
    587     }
    588       else if (!strcmp (tmp, "striped"))
    589     {
    590         out = 0;
    591     }
    592       else if (!strcmp (tmp, "raid5"))
    593     {
    594       out = 5;
    595     }
    596       log_it (tmp);
    597       if (is_this_raid_personality_registered (out))
    598     {
    599       log_it
    600         ("Groovy. You've picked a RAID personality which is registered.");
    601     }
    602       else
    603     {
    604       if (ask_me_yes_or_no
    605           ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    606         {
    607           out = 999;
    608         }
    609     }
    610     }
    611   raidrec->raidlevel = out;
     552    char tmp[MAX_STR_LEN];
     553    char prompt[MAX_STR_LEN];
     554    char sz[MAX_STR_LEN];
     555
     556    sprintf(prompt,
     557            "Please enter the RAID level you want. (concat, striped, raid5)");
     558    if (raidrec->raidlevel == -1) {
     559        strcpy(tmp, "concat");
     560    } else if (raidrec->raidlevel == 0) {
     561        strcpy(tmp, "striped");
     562    } else {
     563        sprintf(tmp, "raid%i", raidrec->raidlevel);
     564    }
     565    for (out = 999; out == 999;) {
     566        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
     567        if (!res) {
     568            return;
     569        }
     570        strip_spaces(tmp);
     571        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
     572            strcpy(sz, tmp);
     573            strncpy(tmp, sz + 1, strlen(sz) - 2);
     574            tmp[strlen(sz) - 2] = '\0';
     575        }
     576        if (!strcmp(tmp, "concat")) {
     577            out = -1;
     578        } else if (!strcmp(tmp, "striped")) {
     579            out = 0;
     580        } else if (!strcmp(tmp, "raid5")) {
     581            out = 5;
     582        }
     583        log_it(tmp);
     584        if (is_this_raid_personality_registered(out)) {
     585            log_it
     586                ("Groovy. You've picked a RAID personality which is registered.");
     587        } else {
     588            if (ask_me_yes_or_no
     589                ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
     590            {
     591                out = 999;
     592            }
     593        }
     594    }
     595    raidrec->raidlevel = out;
    612596#else
    613597    /** buffers ***********************************************************/
    614   char tmp[MAX_STR_LEN];
     598    char tmp[MAX_STR_LEN];
    615599    char personalities[MAX_STR_LEN];
    616600    char prompt[MAX_STR_LEN];
    617601    char sz[MAX_STR_LEN];
    618     int out=0, res=0;
    619 
    620 
    621   assert(raidrec!=NULL);
    622   system
    623     ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null");
    624   strcpy (personalities, last_line_of_file ("/tmp/raid-personalities.txt"));
    625   sprintf (prompt, "Please enter the RAID level you want. %s", personalities);
    626   if (raidrec->raid_level == -1)
    627     {
    628       strcpy (tmp, "linear");
    629     }
    630   else
    631     {
    632       sprintf (tmp, "%d", raidrec->raid_level);
    633     }
    634   for (out = 999;
    635        out != -1 && out != 0 && out != 1 && out != 4 && out != 5
    636        && out != 10;)
    637     {
    638       res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10);
    639       if (!res)
    640     {
    641       return;
    642     }
    643       strip_spaces (tmp);
    644       if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']')
    645     {
    646       strcpy (sz, tmp);
    647       strncpy (tmp, sz + 1, strlen (sz) - 2);
    648       tmp[strlen (sz) - 2] = '\0';
    649     }
    650       if (!strcmp (tmp, "linear"))
    651     {
    652       out = -1;
    653     }
    654       else if (!strncmp (tmp, "raid", 4))
    655     {
    656       out = atoi (tmp + 4);
    657     }
    658       else
    659     {
    660       out = atoi (tmp);
    661     }
    662       log_it (tmp);
    663       if (is_this_raid_personality_registered (out))
    664     {
    665       log_it
    666         ("Groovy. You've picked a RAID personality which is registered.");
    667     }
    668       else
    669     {
    670       if (ask_me_yes_or_no
    671           ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    672         {
    673           out = 999;
    674         }
    675     }
    676     }
    677   raidrec->raid_level = out;
     602    int out = 0, res = 0;
     603
     604
     605    assert(raidrec != NULL);
     606    system
     607        ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null");
     608    strcpy(personalities,
     609           last_line_of_file("/tmp/raid-personalities.txt"));
     610    sprintf(prompt, "Please enter the RAID level you want. %s",
     611            personalities);
     612    if (raidrec->raid_level == -1) {
     613        strcpy(tmp, "linear");
     614    } else {
     615        sprintf(tmp, "%d", raidrec->raid_level);
     616    }
     617    for (out = 999;
     618         out != -1 && out != 0 && out != 1 && out != 4 && out != 5
     619         && out != 10;) {
     620        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
     621        if (!res) {
     622            return;
     623        }
     624        strip_spaces(tmp);
     625        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
     626            strcpy(sz, tmp);
     627            strncpy(tmp, sz + 1, strlen(sz) - 2);
     628            tmp[strlen(sz) - 2] = '\0';
     629        }
     630        if (!strcmp(tmp, "linear")) {
     631            out = -1;
     632        } else if (!strncmp(tmp, "raid", 4)) {
     633            out = atoi(tmp + 4);
     634        } else {
     635            out = atoi(tmp);
     636        }
     637        log_it(tmp);
     638        if (is_this_raid_personality_registered(out)) {
     639            log_it
     640                ("Groovy. You've picked a RAID personality which is registered.");
     641        } else {
     642            if (ask_me_yes_or_no
     643                ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
     644            {
     645                out = 999;
     646            }
     647        }
     648    }
     649    raidrec->raid_level = out;
    678650#endif
    679651}
     
    690662 */
    691663void
    692 del_partns_listed_in_disklist (struct mountlist_itself *mountlist,
    693                    struct raidlist_itself *raidlist,
    694                    struct list_of_disks *disklist)
     664del_partns_listed_in_disklist(struct mountlist_itself *mountlist,
     665                              struct raidlist_itself *raidlist,
     666                              struct list_of_disks *disklist)
    695667{
    696668
    697669    /** int ***************************************************************/
    698   int i = 0;
     670    int i = 0;
    699671    int pos = 0;
    700672
    701673    /** buffers ***********************************************************/
    702   char tmp[MAX_STR_LEN];
    703 
    704   assert(mountlist!=NULL);
    705   assert(raidlist!=NULL);
    706   assert(disklist!=NULL);
    707 
    708   for (i = 0; i < disklist->entries; i++)
    709     {
    710       for (pos = 0;
    711        pos < mountlist->entries
    712        && strcmp (mountlist->el[pos].device, disklist->el[i].device);
    713        pos++);
    714       if (pos < mountlist->entries)
    715     {
    716       sprintf (tmp,
    717            "Deleting partition %s cos it was part of a now-defunct RAID",
    718            mountlist->el[pos].device);
    719       log_it (tmp);
    720       memcpy ((void *) &mountlist->el[pos],
    721           (void *) &mountlist->el[mountlist->entries - 1],
    722           sizeof (struct mountlist_line));
    723       mountlist->entries--;
    724     }
    725     }
     674    char tmp[MAX_STR_LEN];
     675
     676    assert(mountlist != NULL);
     677    assert(raidlist != NULL);
     678    assert(disklist != NULL);
     679
     680    for (i = 0; i < disklist->entries; i++) {
     681        for (pos = 0;
     682             pos < mountlist->entries
     683             && strcmp(mountlist->el[pos].device, disklist->el[i].device);
     684             pos++);
     685        if (pos < mountlist->entries) {
     686            sprintf(tmp,
     687                    "Deleting partition %s cos it was part of a now-defunct RAID",
     688                    mountlist->el[pos].device);
     689            log_it(tmp);
     690            memcpy((void *) &mountlist->el[pos],
     691                   (void *) &mountlist->el[mountlist->entries - 1],
     692                   sizeof(struct mountlist_line));
     693            mountlist->entries--;
     694        }
     695    }
    726696}
    727697
     
    737707 */
    738708void
    739 delete_disklist_entry (struct list_of_disks *disklist, char *raid_device,
    740                int currline)
     709delete_disklist_entry(struct list_of_disks *disklist, char *raid_device,
     710                      int currline)
    741711{
    742712
    743713    /** int ***************************************************************/
    744   int pos = 0;
     714    int pos = 0;
    745715
    746716    /** buffers ***********************************************************/
    747   char tmp[MAX_STR_LEN];
    748 
    749   assert(disklist!=NULL);
    750   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    751 
    752   sprintf (tmp, "Delete %s from RAID device %s - are you sure?",
    753        disklist->el[currline].device, raid_device);
    754   if (!ask_me_yes_or_no (tmp))
    755     {
    756       return;
    757     }
    758   for (pos = currline; pos < disklist->entries - 1; pos++)
    759     {
    760       /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
    761       strcpy (disklist->el[pos].device, disklist->el[pos + 1].device);
    762     }
    763   disklist->entries--;
     717    char tmp[MAX_STR_LEN];
     718
     719    assert(disklist != NULL);
     720    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     721
     722    sprintf(tmp, "Delete %s from RAID device %s - are you sure?",
     723            disklist->el[currline].device, raid_device);
     724    if (!ask_me_yes_or_no(tmp)) {
     725        return;
     726    }
     727    for (pos = currline; pos < disklist->entries - 1; pos++) {
     728        /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
     729        strcpy(disklist->el[pos].device, disklist->el[pos + 1].device);
     730    }
     731    disklist->entries--;
    764732}
    765733
     
    776744 */
    777745void
    778 delete_mountlist_entry (struct mountlist_itself *mountlist,
    779             struct raidlist_itself *raidlist,
    780             newtComponent listbox, int currline, void *keylist[])
     746delete_mountlist_entry(struct mountlist_itself *mountlist,
     747                       struct raidlist_itself *raidlist,
     748                       newtComponent listbox, int currline,
     749                       void *keylist[])
    781750{
    782751
    783752    /** int ***************************************************************/
    784   int pos = 0;
     753    int pos = 0;
    785754
    786755    /** buffers ***********************************************************/
    787   char tmp[MAX_STR_LEN];
     756    char tmp[MAX_STR_LEN];
    788757    char device[MAX_STR_LEN];
    789758
    790759
    791   assert(mountlist!=NULL);
    792   assert(raidlist!=NULL);
    793   assert(listbox!=NULL);
    794   assert(keylist!=NULL);
    795 
    796   pos =
    797     which_raid_device_is_using_this_partition (raidlist,
    798                            mountlist->el[currline].
    799                            device);
    800   if (pos >= 0)
    801     {
    802       sprintf (tmp, "Cannot delete %s: it is in use by RAID device %s",
    803            mountlist->el[currline].device, raidlist->el[pos].OSSWAP (raid_device, volname));
    804       popup_and_OK (tmp);
    805       return;
    806     }
    807   sprintf (tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
    808   if (!ask_me_yes_or_no (tmp))
    809     {
    810       return;
    811     }
    812   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    813     {
    814       strcpy (device, mountlist->el[currline].device);
    815       delete_raidlist_entry (mountlist, raidlist, device);
    816       for (currline = 0;
    817        currline < mountlist->entries
    818        && strcmp (mountlist->el[currline].device, device); currline++);
    819       if (currline == mountlist->entries)
    820     {
    821       log_it ("Dev is gone. I can't delete it. Ho-hum");
    822       return;
    823     }
    824     }
    825   memcpy ((void *) &mountlist->el[currline],
    826       (void *) &mountlist->el[mountlist->entries - 1],
    827       sizeof (struct mountlist_line));
    828   mountlist->entries--;
    829   redraw_mountlist (mountlist, keylist, listbox);
     760    assert(mountlist != NULL);
     761    assert(raidlist != NULL);
     762    assert(listbox != NULL);
     763    assert(keylist != NULL);
     764
     765    pos =
     766        which_raid_device_is_using_this_partition(raidlist,
     767                                                  mountlist->el[currline].
     768                                                  device);
     769    if (pos >= 0) {
     770        sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s",
     771                mountlist->el[currline].device,
     772                raidlist->el[pos].OSSWAP(raid_device, volname));
     773        popup_and_OK(tmp);
     774        return;
     775    }
     776    sprintf(tmp, "Delete %s - are you sure?",
     777            mountlist->el[currline].device);
     778    if (!ask_me_yes_or_no(tmp)) {
     779        return;
     780    }
     781    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     782        strcpy(device, mountlist->el[currline].device);
     783        delete_raidlist_entry(mountlist, raidlist, device);
     784        for (currline = 0;
     785             currline < mountlist->entries
     786             && strcmp(mountlist->el[currline].device, device);
     787             currline++);
     788        if (currline == mountlist->entries) {
     789            log_it("Dev is gone. I can't delete it. Ho-hum");
     790            return;
     791        }
     792    }
     793    memcpy((void *) &mountlist->el[currline],
     794           (void *) &mountlist->el[mountlist->entries - 1],
     795           sizeof(struct mountlist_line));
     796    mountlist->entries--;
     797    redraw_mountlist(mountlist, keylist, listbox);
    830798}
    831799
     
    839807 */
    840808void
    841 delete_raidlist_entry (struct mountlist_itself *mountlist,
    842                struct raidlist_itself *raidlist, char *device)
    843 {
    844    
     809delete_raidlist_entry(struct mountlist_itself *mountlist,
     810                      struct raidlist_itself *raidlist, char *device)
     811{
     812
    845813    /** int ***************************************************************/
    846   int i = 0;
    847     int items =0;
     814    int i = 0;
     815    int items = 0;
    848816
    849817    /** bool **************************************************************/
    850   bool delete_partitions_too;
     818    bool delete_partitions_too;
    851819
    852820    /** buffers ***********************************************************/
    853   char tmp[MAX_STR_LEN];
    854 
    855   assert(mountlist!=NULL);
    856   assert(raidlist!=NULL);
    857   assert_string_is_neither_NULL_nor_zerolength(device);
    858 
    859   i = find_raid_device_in_raidlist (raidlist, device);
    860   if (i < 0)
    861     {
    862       return;
    863     }
    864   sprintf (tmp, "Do you want me to delete %s's partitions, too?", device);
    865   delete_partitions_too = ask_me_yes_or_no (tmp);
    866   if (delete_partitions_too)
    867     {
     821    char tmp[MAX_STR_LEN];
     822
     823    assert(mountlist != NULL);
     824    assert(raidlist != NULL);
     825    assert_string_is_neither_NULL_nor_zerolength(device);
     826
     827    i = find_raid_device_in_raidlist(raidlist, device);
     828    if (i < 0) {
     829        return;
     830    }
     831    sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
     832    delete_partitions_too = ask_me_yes_or_no(tmp);
     833    if (delete_partitions_too) {
    868834#ifdef __FreeBSD__
    869       // static so it's zeroed
    870       static struct list_of_disks d;
    871       int x, y, z;
    872      
    873       for (x = 0; x < raidlist->el[i].plexes; ++x) {
    874           for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) {
    875           for (z = 0; z < raidlist->disks.entries; ++z) {
    876               if (!strcmp (raidlist->el[i].plex[x].sd[y].which_device,
    877                    raidlist->disks.el[z].name)) {
    878               strcpy (d.el [d.entries  ].name, raidlist->disks.el[z].name);
    879               strcpy (d.el [d.entries++].device, raidlist->disks.el[z].device);
    880               }
    881           }
    882           }
    883       }
    884      
    885       del_partns_listed_in_disklist (mountlist, raidlist, &d);
     835        // static so it's zeroed
     836        static struct list_of_disks d;
     837        int x, y, z;
     838
     839        for (x = 0; x < raidlist->el[i].plexes; ++x) {
     840            for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) {
     841                for (z = 0; z < raidlist->disks.entries; ++z) {
     842                    if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device,
     843                                raidlist->disks.el[z].name)) {
     844                        strcpy(d.el[d.entries].name,
     845                               raidlist->disks.el[z].name);
     846                        strcpy(d.el[d.entries++].device,
     847                               raidlist->disks.el[z].device);
     848                    }
     849                }
     850            }
     851        }
     852
     853        del_partns_listed_in_disklist(mountlist, raidlist, &d);
    886854#else
    887       del_partns_listed_in_disklist (mountlist, raidlist,
    888                      &raidlist->el[i].data_disks);
    889       del_partns_listed_in_disklist (mountlist, raidlist,
    890                      &raidlist->el[i].spare_disks);
    891       del_partns_listed_in_disklist (mountlist, raidlist,
    892                      &raidlist->el[i].parity_disks);
    893       del_partns_listed_in_disklist (mountlist, raidlist,
    894                      &raidlist->el[i].failed_disks);
     855        del_partns_listed_in_disklist(mountlist, raidlist,
     856                                      &raidlist->el[i].data_disks);
     857        del_partns_listed_in_disklist(mountlist, raidlist,
     858                                      &raidlist->el[i].spare_disks);
     859        del_partns_listed_in_disklist(mountlist, raidlist,
     860                                      &raidlist->el[i].parity_disks);
     861        del_partns_listed_in_disklist(mountlist, raidlist,
     862                                      &raidlist->el[i].failed_disks);
    895863#endif
    896     }
    897   items = raidlist->entries;
    898   if (items == 1)
    899     {
    900       items = 0;
    901     }
    902   else
    903     {
    904       log_it (tmp);
    905       memcpy ((void *) &raidlist->el[i], (void *) &raidlist->el[items - 1],
    906           sizeof (struct OSSWAP(raid_device_record, vinum_volume)));
    907       items--;
    908     }
    909   raidlist->entries = items;
     864    }
     865    items = raidlist->entries;
     866    if (items == 1) {
     867        items = 0;
     868    } else {
     869        log_it(tmp);
     870        memcpy((void *) &raidlist->el[i],
     871               (void *) &raidlist->el[items - 1],
     872               sizeof(struct OSSWAP (raid_device_record, vinum_volume)));
     873        items--;
     874    }
     875    raidlist->entries = items;
    910876}
    911877
     
    918884 * @ingroup restoreGuiVarslist
    919885 */
    920 void
    921 delete_varslist_entry (struct raid_device_record *raidrec, int lino)
     886void delete_varslist_entry(struct raid_device_record *raidrec, int lino)
    922887{
    923888
    924889    /** buffers ************************************************************/
    925   char tmp[MAX_STR_LEN];
     890    char tmp[MAX_STR_LEN];
    926891
    927892    /** structures *********************************************************/
    928   struct additional_raid_variables *av;
    929 
    930   assert(raidrec!=NULL);
    931 
    932   av = &raidrec->additional_vars;
    933   sprintf (tmp, "Delete %s - are you sure?", av->el[lino].label);
    934   if (ask_me_yes_or_no (tmp))
    935     {
    936       if (!strcmp (av->el[lino].label, "persistent-superblock")
    937       || !strcmp (av->el[lino].label, "chunk-size"))
    938     {
    939       sprintf (tmp, "%s must not be deleted. It would be bad.",
    940            av->el[lino].label);
    941       popup_and_OK (tmp);
    942     }
    943       else
    944     {
    945       memcpy ((void *) &av->el[lino], (void *) &av->el[av->entries--],
    946           sizeof (struct raid_var_line));
    947     }
    948     }
     893    struct additional_raid_variables *av;
     894
     895    assert(raidrec != NULL);
     896
     897    av = &raidrec->additional_vars;
     898    sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
     899    if (ask_me_yes_or_no(tmp)) {
     900        if (!strcmp(av->el[lino].label, "persistent-superblock")
     901            || !strcmp(av->el[lino].label, "chunk-size")) {
     902            sprintf(tmp, "%s must not be deleted. It would be bad.",
     903                    av->el[lino].label);
     904            popup_and_OK(tmp);
     905        } else {
     906            memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
     907                   sizeof(struct raid_var_line));
     908        }
     909    }
    949910}
    950911#endif
     
    960921 */
    961922int
    962 redraw_filelist (struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM],
    963          newtComponent listbox)
     923redraw_filelist(struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM],
     924                newtComponent listbox)
    964925{
    965926
    966927    /** int ***************************************************************/
    967   static int lines_in_flist_window = 0;
    968   static int depth = 0;
    969   int i = 0;
     928    static int lines_in_flist_window = 0;
     929    static int depth = 0;
     930    int i = 0;
    970931
    971932    /** structures *******************************************************/
    972   struct s_node *node;
     933    struct s_node *node;
    973934
    974935    /** buffers **********************************************************/
    975   static char current_filename[MAX_STR_LEN];
    976   char tmp[MAX_STR_LEN + 2];
     936    static char current_filename[MAX_STR_LEN];
     937    char tmp[MAX_STR_LEN + 2];
    977938
    978939    /** bool *************************************************************/
    979940    /*  void*dummyptr; */
    980   bool dummybool;
    981   static bool warned_already;
    982 
    983   assert(filelist!=NULL);
    984   assert(keylist!=NULL);
    985   assert(listbox!=NULL);
    986 
    987 
    988   if (depth == 0)
    989     {
    990       lines_in_flist_window = 0;
    991       warned_already = FALSE;
    992       for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    993     {
    994       g_strings_of_flist_window[i][0] = '\0';
    995       g_is_path_selected[i] = FALSE;
    996     }
    997     }
    998   for (node = filelist; node != NULL; node = node->right)
    999     {
    1000       current_filename[depth] = node->ch;
    1001       if (node->down)
    1002     {
    1003       depth++;
    1004       i = redraw_filelist (node->down, keylist, listbox);
    1005       depth--;
    1006     }
    1007       if (node->ch == '\0' && node->expanded)
    1008     {
    1009       if (lines_in_flist_window == ARBITRARY_MAXIMUM)
    1010         {
    1011           if (!warned_already)
    1012         {
    1013           warned_already = TRUE;
    1014           sprintf (tmp,
    1015                "Too many lines. Displaying first %d entries only. Close a directory to see more.",
    1016                ARBITRARY_MAXIMUM);
    1017           popup_and_OK (tmp);
    1018         }
    1019         }
    1020       else
    1021         {
    1022           strcpy (g_strings_of_flist_window[lines_in_flist_window],
    1023               current_filename);
    1024           g_is_path_selected[lines_in_flist_window] = node->selected;
    1025           lines_in_flist_window++;
    1026         }
    1027     }
    1028     }
    1029   if (depth == 0)
    1030     {
    1031       if (lines_in_flist_window > ARBITRARY_MAXIMUM)
    1032     {
    1033       lines_in_flist_window = ARBITRARY_MAXIMUM;
    1034     }
     941    bool dummybool;
     942    static bool warned_already;
     943
     944    assert(filelist != NULL);
     945    assert(keylist != NULL);
     946    assert(listbox != NULL);
     947
     948
     949    if (depth == 0) {
     950        lines_in_flist_window = 0;
     951        warned_already = FALSE;
     952        for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     953            g_strings_of_flist_window[i][0] = '\0';
     954            g_is_path_selected[i] = FALSE;
     955        }
     956    }
     957    for (node = filelist; node != NULL; node = node->right) {
     958        current_filename[depth] = node->ch;
     959        if (node->down) {
     960            depth++;
     961            i = redraw_filelist(node->down, keylist, listbox);
     962            depth--;
     963        }
     964        if (node->ch == '\0' && node->expanded) {
     965            if (lines_in_flist_window == ARBITRARY_MAXIMUM) {
     966                if (!warned_already) {
     967                    warned_already = TRUE;
     968                    sprintf(tmp,
     969                            "Too many lines. Displaying first %d entries only. Close a directory to see more.",
     970                            ARBITRARY_MAXIMUM);
     971                    popup_and_OK(tmp);
     972                }
     973            } else {
     974                strcpy(g_strings_of_flist_window[lines_in_flist_window],
     975                       current_filename);
     976                g_is_path_selected[lines_in_flist_window] = node->selected;
     977                lines_in_flist_window++;
     978            }
     979        }
     980    }
     981    if (depth == 0) {
     982        if (lines_in_flist_window > ARBITRARY_MAXIMUM) {
     983            lines_in_flist_window = ARBITRARY_MAXIMUM;
     984        }
    1035985/* do an elementary sort */
    1036       for (i = 1; i < lines_in_flist_window; i++)
    1037     {
    1038       if (strcmp
    1039           (g_strings_of_flist_window[i],
    1040            g_strings_of_flist_window[i - 1]) < 0)
    1041         {
    1042           strcpy (tmp, g_strings_of_flist_window[i]);
    1043           strcpy (g_strings_of_flist_window[i],
    1044               g_strings_of_flist_window[i - 1]);
    1045           strcpy (g_strings_of_flist_window[i - 1], tmp);
    1046           dummybool = g_is_path_selected[i];
    1047           g_is_path_selected[i] = g_is_path_selected[i - 1];
    1048           g_is_path_selected[i - 1] = dummybool;
    1049           i = 0;
    1050         }
    1051     }
     986        for (i = 1; i < lines_in_flist_window; i++) {
     987            if (strcmp
     988                (g_strings_of_flist_window[i],
     989                 g_strings_of_flist_window[i - 1]) < 0) {
     990                strcpy(tmp, g_strings_of_flist_window[i]);
     991                strcpy(g_strings_of_flist_window[i],
     992                       g_strings_of_flist_window[i - 1]);
     993                strcpy(g_strings_of_flist_window[i - 1], tmp);
     994                dummybool = g_is_path_selected[i];
     995                g_is_path_selected[i] = g_is_path_selected[i - 1];
     996                g_is_path_selected[i - 1] = dummybool;
     997                i = 0;
     998            }
     999        }
    10521000/* write list to screen */
    1053       newtListboxClear (listbox);
    1054       for (i = 0; i < lines_in_flist_window; i++)
    1055     {
    1056       sprintf (tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
    1057            (g_is_path_expanded[i] ? '+' : '-'),
    1058            strip_path(g_strings_of_flist_window[i]));
    1059       tmp[70] = '\0';
    1060       keylist[i] = (void *) i;
    1061       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    1062     }
    1063       return (lines_in_flist_window);
    1064     }
    1065   else
    1066     {
    1067       return (0);
    1068     }
     1001        newtListboxClear(listbox);
     1002        for (i = 0; i < lines_in_flist_window; i++) {
     1003            sprintf(tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
     1004                    (g_is_path_expanded[i] ? '+' : '-'),
     1005                    strip_path(g_strings_of_flist_window[i]));
     1006            tmp[70] = '\0';
     1007            keylist[i] = (void *) i;
     1008            newtListboxAppendEntry(listbox, tmp, keylist[i]);
     1009        }
     1010        return (lines_in_flist_window);
     1011    } else {
     1012        return (0);
     1013    }
    10691014}
    10701015
     
    10771022 * @ingroup restoreUtilityGroup
    10781023 */
    1079 char *strip_path(char *tmp) 
     1024char *strip_path(char *tmp)
    10801025{
    10811026
     
    10831028    int slashloc = 0, lastslashloc = 0;
    10841029
    1085     while(tmp[i] != '\0')
    1086     { /* Count the slashes in tmp
    1087          1 slash per dir */
    1088       if( tmp[i] == '/')
    1089       {
    1090         slashcount++;
    1091         lastslashloc = slashloc;
    1092         slashloc = i;
    1093         if(tmp[i + 1] == '\0')
    1094         { /* if this slash is last char, back off */
    1095           slashcount--;
    1096           slashloc = lastslashloc;
    1097         }
    1098       }
    1099       i++;
    1100     }
    1101     if(slashcount > 0) slashcount--; /* Keep one slash 'cos Hugh does... */
    1102 
    1103     for(i=0; i<slashcount; i++)
    1104     { /* Replace each dir with a space char */
    1105       tmpnopath[i] = ' ';
     1030    while (tmp[i] != '\0') {    /* Count the slashes in tmp
     1031                                   1 slash per dir */
     1032        if (tmp[i] == '/') {
     1033            slashcount++;
     1034            lastslashloc = slashloc;
     1035            slashloc = i;
     1036            if (tmp[i + 1] == '\0') {   /* if this slash is last char, back off */
     1037                slashcount--;
     1038                slashloc = lastslashloc;
     1039            }
     1040        }
     1041        i++;
     1042    }
     1043    if (slashcount > 0)
     1044        slashcount--;           /* Keep one slash 'cos Hugh does... */
     1045
     1046    for (i = 0; i < slashcount; i++) {  /* Replace each dir with a space char */
     1047        tmpnopath[i] = ' ';
    11061048    }
    11071049
    11081050    i = slashloc;
    11091051    j = slashcount;
    1110     while(tmp[i] != '\0')
    1111     { /* Now add what's left of tmp */
    1112       if( (tmpprevpath[j] == ' ' || tmpprevpath[j] == '^')
    1113           && tmp[i] == '/'
    1114           && tmpnopath[j - 1] != '^'
    1115           && j != 0)
    1116       { /* Add a pointer upwards if this is not in the same dir as line above */
    1117           tmpnopath[j - 1] = '^';
    1118       } else {
    1119         tmpnopath[j++] = tmp[i++];
    1120       }
     1052    while (tmp[i] != '\0') {    /* Now add what's left of tmp */
     1053        if ((tmpprevpath[j] == ' ' || tmpprevpath[j] == '^')
     1054            && tmp[i] == '/' && tmpnopath[j - 1] != '^' && j != 0) {    /* Add a pointer upwards if this is not in the same dir as line above */
     1055            tmpnopath[j - 1] = '^';
     1056        } else {
     1057            tmpnopath[j++] = tmp[i++];
     1058        }
    11211059    }
    11221060    tmpnopath[j] = '\0';
    11231061
    1124     strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */
    1125    
    1126     return(tmpnopath);
     1062    strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */
     1063
     1064    return (tmpnopath);
    11271065}
    11281066
     
    11331071 * @return 0 if the user pressed OK, 1 if they pressed Cancel.
    11341072 */
    1135 int
    1136 edit_filelist (struct s_node *filelist)
     1073int edit_filelist(struct s_node *filelist)
    11371074{
    11381075
    11391076    /** newt **************************************************************/
    1140   newtComponent myForm;
    1141     newtComponent bLess=NULL;
    1142     newtComponent bMore=NULL;
    1143     newtComponent bToggle=NULL;
    1144     newtComponent bOK=NULL;
    1145     newtComponent bCancel=NULL;
    1146     newtComponent b_res=NULL;
    1147     newtComponent filelistListbox=NULL;
    1148     newtComponent bRegex=NULL;
     1077    newtComponent myForm;
     1078    newtComponent bLess = NULL;
     1079    newtComponent bMore = NULL;
     1080    newtComponent bToggle = NULL;
     1081    newtComponent bOK = NULL;
     1082    newtComponent bCancel = NULL;
     1083    newtComponent b_res = NULL;
     1084    newtComponent filelistListbox = NULL;
     1085    newtComponent bRegex = NULL;
    11491086
    11501087    /** int ***************************************************************/
     
    11551092
    11561093    /** ???? **************************************************************/
    1157   void *curr_choice;
    1158   void *keylist[ARBITRARY_MAXIMUM];
     1094    void *curr_choice;
     1095    void *keylist[ARBITRARY_MAXIMUM];
    11591096
    11601097    /** buffers ***********************************************************/
    1161   char tmp[MAX_STR_LEN];
     1098    char tmp[MAX_STR_LEN];
    11621099
    11631100    /** bool **************************************************************/
    1164   bool dummybool;
     1101    bool dummybool;
    11651102
    11661103/*  struct s_node *node; */
    11671104
    1168   assert(filelist!=NULL);
    1169 
    1170   log_to_screen ("Editing filelist");
    1171   newtPushHelpLine
    1172     ("   Please edit the filelist to your satisfaction, then click OK or Cancel.");
    1173   j = 4;
    1174   bLess = newtCompactButton (j, 17, " Less ");
    1175   bMore = newtCompactButton (j += 12, 17, " More ");
    1176   bToggle = newtCompactButton (j += 12, 17, "Toggle");
    1177   bRegex = newtCompactButton (j += 12, 17, "RegEx");
    1178   bCancel = newtCompactButton (j += 12, 17, "Cancel");
    1179   bOK = newtCompactButton (j += 12, 17, "  OK  ");
    1180   filelistListbox =
    1181     newtListbox (2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1182   toggle_all_root_dirs_on (filelist);
    1183   lines_in_flist_window =
    1184     redraw_filelist (filelist, keylist, filelistListbox);
    1185   newtOpenWindow (1, 3, 77, 18, "Editing filelist");
    1186   myForm = newtForm (NULL, NULL, 0);
    1187   newtFormAddComponents (myForm, filelistListbox, bLess, bMore, bToggle,
    1188              bRegex, bCancel, bOK, NULL);
    1189   while (!finished)
    1190     {
    1191       b_res = newtRunForm (myForm);
    1192       if (b_res == bOK)
    1193     {
    1194       finished =
    1195         ask_me_yes_or_no ("Are you happy with your file selection?");
    1196     }
    1197       else if (b_res == bCancel)
    1198     {
    1199       finished = TRUE;
    1200     }
    1201       else if (b_res == bRegex)
    1202     {
    1203       popup_and_OK ("I haven't implemented this yet...");
    1204     }
    1205       else
    1206     {
    1207       curr_choice = newtListboxGetCurrent (filelistListbox);
    1208       for (indexno = 0;
    1209            indexno < lines_in_flist_window
    1210            && keylist[indexno] != curr_choice; indexno++);
    1211       if (indexno == lines_in_flist_window)
    1212         {
    1213           log_it
    1214         ("I don't know what this button does; assuming I am to toggle 1st entry");
    1215           indexno = 0;
    1216         }
    1217       sprintf (tmp, "You selected '%s'",
    1218            g_strings_of_flist_window[indexno]);
    1219       log_it (tmp);
    1220       if (b_res == bMore)
    1221         {
    1222           g_is_path_expanded[indexno] = TRUE;
    1223           toggle_path_expandability (filelist,
    1224                      g_strings_of_flist_window[indexno],
    1225                      TRUE);
    1226           lines_in_flist_window =
    1227         redraw_filelist (filelist, keylist, filelistListbox);
    1228           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1229         }
    1230       else if (b_res == bLess)
    1231         {
    1232           g_is_path_expanded[indexno] = FALSE;
    1233           toggle_path_expandability (filelist,
    1234                      g_strings_of_flist_window[indexno],
    1235                      FALSE);
    1236           lines_in_flist_window =
    1237         redraw_filelist (filelist, keylist, filelistListbox);
    1238           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1239         }
    1240       else
    1241         {
    1242           if (!strcmp (g_strings_of_flist_window[indexno], "/"))
    1243         {
    1244           dummybool = !g_is_path_selected[indexno];
    1245           for (j = 1; j < lines_in_flist_window; j++)
    1246             {
    1247               toggle_path_selection (filelist,
    1248                          g_strings_of_flist_window[j],
    1249                          dummybool);
    1250             }
    1251         }
    1252           else
    1253         {
    1254           toggle_path_selection (filelist,
    1255                      g_strings_of_flist_window[indexno],
    1256                      !g_is_path_selected[indexno]);
    1257           lines_in_flist_window =
    1258             redraw_filelist (filelist, keylist, filelistListbox);
    1259         }
    1260           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1261         }
    1262       for (indexno = 0;
    1263            indexno < lines_in_flist_window
    1264            && keylist[indexno] != curr_choice; indexno++);
    1265       if (indexno == lines_in_flist_window)
    1266         {
    1267           log_it
    1268         ("Layout of table has changed. Y pointer is reverting to zero.");
    1269           indexno = 0;
    1270         }
    1271     }
    1272     }
    1273   newtFormDestroy (myForm);
    1274   newtPopWindow ();
    1275   newtPopHelpLine ();
    1276   if (b_res == bOK)
    1277     {
    1278       return (0);
    1279     }
    1280   else
    1281     {
     1105    assert(filelist != NULL);
     1106
     1107    log_to_screen("Editing filelist");
     1108    newtPushHelpLine
     1109        ("   Please edit the filelist to your satisfaction, then click OK or Cancel.");
     1110    j = 4;
     1111    bLess = newtCompactButton(j, 17, " Less ");
     1112    bMore = newtCompactButton(j += 12, 17, " More ");
     1113    bToggle = newtCompactButton(j += 12, 17, "Toggle");
     1114    bRegex = newtCompactButton(j += 12, 17, "RegEx");
     1115    bCancel = newtCompactButton(j += 12, 17, "Cancel");
     1116    bOK = newtCompactButton(j += 12, 17, "  OK  ");
     1117    filelistListbox =
     1118        newtListbox(2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1119    toggle_all_root_dirs_on(filelist);
     1120    lines_in_flist_window =
     1121        redraw_filelist(filelist, keylist, filelistListbox);
     1122    newtOpenWindow(1, 3, 77, 18, "Editing filelist");
     1123    myForm = newtForm(NULL, NULL, 0);
     1124    newtFormAddComponents(myForm, filelistListbox, bLess, bMore, bToggle,
     1125                          bRegex, bCancel, bOK, NULL);
     1126    while (!finished) {
     1127        b_res = newtRunForm(myForm);
     1128        if (b_res == bOK) {
     1129            finished =
     1130                ask_me_yes_or_no
     1131                ("Are you happy with your file selection?");
     1132        } else if (b_res == bCancel) {
     1133            finished = TRUE;
     1134        } else if (b_res == bRegex) {
     1135            popup_and_OK("I haven't implemented this yet...");
     1136        } else {
     1137            curr_choice = newtListboxGetCurrent(filelistListbox);
     1138            for (indexno = 0;
     1139                 indexno < lines_in_flist_window
     1140                 && keylist[indexno] != curr_choice; indexno++);
     1141            if (indexno == lines_in_flist_window) {
     1142                log_it
     1143                    ("I don't know what this button does; assuming I am to toggle 1st entry");
     1144                indexno = 0;
     1145            }
     1146            sprintf(tmp, "You selected '%s'",
     1147                    g_strings_of_flist_window[indexno]);
     1148            log_it(tmp);
     1149            if (b_res == bMore) {
     1150                g_is_path_expanded[indexno] = TRUE;
     1151                toggle_path_expandability(filelist,
     1152                                          g_strings_of_flist_window
     1153                                          [indexno], TRUE);
     1154                lines_in_flist_window =
     1155                    redraw_filelist(filelist, keylist, filelistListbox);
     1156                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1157            } else if (b_res == bLess) {
     1158                g_is_path_expanded[indexno] = FALSE;
     1159                toggle_path_expandability(filelist,
     1160                                          g_strings_of_flist_window
     1161                                          [indexno], FALSE);
     1162                lines_in_flist_window =
     1163                    redraw_filelist(filelist, keylist, filelistListbox);
     1164                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1165            } else {
     1166                if (!strcmp(g_strings_of_flist_window[indexno], "/")) {
     1167                    dummybool = !g_is_path_selected[indexno];
     1168                    for (j = 1; j < lines_in_flist_window; j++) {
     1169                        toggle_path_selection(filelist,
     1170                                              g_strings_of_flist_window[j],
     1171                                              dummybool);
     1172                    }
     1173                } else {
     1174                    toggle_path_selection(filelist,
     1175                                          g_strings_of_flist_window
     1176                                          [indexno],
     1177                                          !g_is_path_selected[indexno]);
     1178                    lines_in_flist_window =
     1179                        redraw_filelist(filelist, keylist,
     1180                                        filelistListbox);
     1181                }
     1182                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1183            }
     1184            for (indexno = 0;
     1185                 indexno < lines_in_flist_window
     1186                 && keylist[indexno] != curr_choice; indexno++);
     1187            if (indexno == lines_in_flist_window) {
     1188                log_it
     1189                    ("Layout of table has changed. Y pointer is reverting to zero.");
     1190                indexno = 0;
     1191            }
     1192        }
     1193    }
     1194    newtFormDestroy(myForm);
     1195    newtPopWindow();
     1196    newtPopHelpLine();
     1197    if (b_res == bOK) {
     1198        return (0);
     1199    } else {
    12821200/*    popup_and_OK("You pushed 'cancel'. I shall now abort."); */
    1283       return (1);
    1284     }
     1201        return (1);
     1202    }
    12851203}
    12861204
     
    12961214 */
    12971215void
    1298 edit_mountlist_entry (struct mountlist_itself *mountlist,
    1299               struct raidlist_itself *raidlist, newtComponent listbox,
    1300               int currline, void *keylist[])
     1216edit_mountlist_entry(struct mountlist_itself *mountlist,
     1217                     struct raidlist_itself *raidlist,
     1218                     newtComponent listbox, int currline, void *keylist[])
    13011219{
    13021220
    13031221    /** structures ********************************************************/
    1304   static struct raidlist_itself bkp_raidlist;
     1222    static struct raidlist_itself bkp_raidlist;
    13051223
    13061224    /** newt **************************************************************/
    1307   newtComponent myForm;
     1225    newtComponent myForm;
    13081226    newtComponent bOK;
    13091227    newtComponent bCancel;
     
    13241242    char size_str[MAX_STR_LEN];
    13251243    char format_str[MAX_STR_LEN];
    1326   char tmp[MAX_STR_LEN];
    1327   char device_used_to_be[MAX_STR_LEN];
     1244    char tmp[MAX_STR_LEN];
     1245    char device_used_to_be[MAX_STR_LEN];
    13281246    char mountpt_used_to_be[MAX_STR_LEN];
    13291247
     
    13351253
    13361254    /** int ***************************************************************/
    1337   int j = 0;
    1338 
    1339   assert(mountlist!=NULL);
    1340   assert(raidlist!=NULL);
    1341   assert(listbox!=NULL);
    1342   assert(keylist!=NULL);
    1343 
    1344   memcpy ((void *) &bkp_raidlist, (void *) raidlist,
    1345       sizeof (struct raidlist_itself));
    1346   strcpy (device_str, mountlist->el[currline].device);
    1347   strcpy (device_used_to_be, mountlist->el[currline].device);
    1348   strcpy (mountpoint_str, mountlist->el[currline].mountpoint);
    1349   strcpy (mountpt_used_to_be, mountlist->el[currline].mountpoint);
    1350   strcpy (format_str, mountlist->el[currline].format);
    1351   sprintf (size_str, "%lld", mountlist->el[currline].size / 1024);
    1352   newtOpenWindow (20, 5, 48, 10, "Edit entry");
    1353   label0 = newtLabel (2, 1, "Device:");
    1354   label1 = newtLabel (2, 2, "Mountpoint:");
    1355   label2 = newtLabel (2, 3, "Size (MB): ");
    1356   label3 = newtLabel (2, 4, "Format:    ");
    1357   deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0);
    1358   mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0);
    1359   formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0);
    1360   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1361       || !strcmp (mountlist->el[currline].mountpoint, "image"))
    1362     {
    1363       sizeComp = newtLabel (14, 3, size_str);
    1364     }
    1365   else
    1366     {
    1367       sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0);
    1368     }
    1369   bOK = newtButton (2, 6, "  OK  ");
    1370   bCancel = newtButton (14, 6, "Cancel");
    1371   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    1372     {
    1373       b_raid = newtButton (26, 6, "RAID..");
    1374     }
    1375   newtPushHelpLine
    1376     ("       Edit this partition's mountpoint, size and format; then click 'OK'.");
    1377   myForm = newtForm (NULL, NULL, 0);
    1378   newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp,
    1379              formatComp, label0, label1, label2, label3, bOK,
    1380              bCancel, b_raid, NULL);
    1381   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    1382     {
    1383       b_res = newtRunForm (myForm);
    1384       strcpy (device_str, device_here);
    1385       strip_spaces (device_str);
    1386       strcpy (mountpoint_str, mountpoint_here);
    1387       strip_spaces (mountpoint_str);
    1388       strcpy (format_str, format_here);
    1389       strip_spaces (format_str);
    1390       if (b_res == bOK && strstr (device_str, RAID_DEVICE_STUB)
    1391       && strstr (device_used_to_be, RAID_DEVICE_STUB)
    1392       && strcmp (device_str, device_used_to_be))
    1393     {
    1394       popup_and_OK ("You can't change /dev/mdX to /dev/mdY.");
    1395       b_res = NULL;
    1396       continue;
    1397     }
    1398       else if (b_res == bOK && !strcmp (mountpoint_str, "image")
    1399            && strcmp (mountpt_used_to_be, "image"))
    1400     {
    1401       popup_and_OK ("You can't change a regular device to an image.");
    1402       b_res = NULL;
    1403       continue;
    1404     }
    1405       if (!strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1406       && strcmp (mountlist->el[currline].mountpoint, "image"))
    1407     {
    1408       strcpy (size_str, size_here);
    1409       strip_spaces (size_str);
    1410     }
    1411       else
    1412     {
    1413       sprintf (size_str, "%ld",
    1414            calculate_raid_device_size (mountlist, raidlist,
    1415                            mountlist->el[currline].
    1416                            device) / 1024);
    1417       newtLabelSetText (sizeComp, size_str);
    1418     }
    1419       /* do not let user click RAID button if user has changed device_str */
    1420       if (b_res == b_raid)
    1421     {
    1422       if (strcmp (device_str, mountlist->el[currline].device))
    1423         {
    1424           /*
    1425              can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly
    1426              when you try to map the changes over to the raidtab list, trust me
    1427            */
    1428           popup_and_OK
    1429         ("You cannot edit the RAID settings until you have OK'd your change to the device node.");
    1430         }
    1431       else
    1432         {
    1433           j =
    1434         find_raid_device_in_raidlist (raidlist,
    1435                           mountlist->el[currline].device);
    1436           if (j < 0)
    1437         {
    1438           sprintf (tmp,
    1439                "/etc/raidtab does not have an entry for %s; please delete it and add it again",
    1440                mountlist->el[currline].device);
    1441           popup_and_OK (tmp);
    1442         }
    1443           else
    1444         {
    1445           log_it ("edit_raidlist_entry - calling");
    1446           edit_raidlist_entry (mountlist, raidlist, &raidlist->el[j],
    1447                        currline);
    1448         }
    1449         }
    1450     }
    1451     }
    1452   newtFormDestroy (myForm);
    1453   newtPopHelpLine ();
    1454   newtPopWindow ();
    1455   if (b_res == bCancel)
    1456     {
    1457       memcpy ((void *) raidlist, (void *) &bkp_raidlist,
    1458           sizeof (struct raidlist_itself));
    1459       return;
    1460     }
    1461   strcpy (mountlist->el[currline].device, device_str);
    1462   strcpy (mountlist->el[currline].mountpoint, mountpoint_str);
    1463   strcpy (mountlist->el[currline].format, format_str);
    1464   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1465       || !strcmp (mountlist->el[currline].mountpoint, "image"))
    1466     {
    1467       mountlist->el[currline].size =
    1468     calculate_raid_device_size (mountlist, raidlist,
    1469                     mountlist->el[currline].device);
    1470     }
    1471   else
    1472     {
    1473       mountlist->el[currline].size = atol (size_str) * 1024;
    1474     }
    1475   newtListboxSetEntry (listbox, (int) keylist[currline],
    1476                mountlist_entry_to_string (mountlist, currline));
    1477   /* if new /dev/md RAID device then do funky stuff */
    1478   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1479       && !strstr (device_used_to_be, RAID_DEVICE_STUB))
    1480     {
    1481       initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str);
    1482     }
    1483   /* if moving from RAID to non-RAID then do funky stuff */
    1484   else if (strstr (device_used_to_be, RAID_DEVICE_STUB)
    1485        && !strstr (device_str, RAID_DEVICE_STUB))
    1486     {
    1487       delete_raidlist_entry (mountlist, raidlist, device_str);
    1488     }
    1489   /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */
    1490   else if (!strstr (device_used_to_be, RAID_DEVICE_STUB)
    1491        && !strstr (device_str, RAID_DEVICE_STUB))
    1492     {
    1493       rejig_partition_name_in_raidlist_if_necessary (raidlist,
    1494                              device_used_to_be,
    1495                              device_str);
    1496     }
     1255    int j = 0;
     1256
     1257    assert(mountlist != NULL);
     1258    assert(raidlist != NULL);
     1259    assert(listbox != NULL);
     1260    assert(keylist != NULL);
     1261
     1262    memcpy((void *) &bkp_raidlist, (void *) raidlist,
     1263           sizeof(struct raidlist_itself));
     1264    strcpy(device_str, mountlist->el[currline].device);
     1265    strcpy(device_used_to_be, mountlist->el[currline].device);
     1266    strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
     1267    strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
     1268    strcpy(format_str, mountlist->el[currline].format);
     1269    sprintf(size_str, "%lld", mountlist->el[currline].size / 1024);
     1270    newtOpenWindow(20, 5, 48, 10, "Edit entry");
     1271    label0 = newtLabel(2, 1, "Device:");
     1272    label1 = newtLabel(2, 2, "Mountpoint:");
     1273    label2 = newtLabel(2, 3, "Size (MB): ");
     1274    label3 = newtLabel(2, 4, "Format:    ");
     1275    deviceComp =
     1276        newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     1277    mountpointComp =
     1278        newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     1279    formatComp =
     1280        newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     1281    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1282        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     1283        sizeComp = newtLabel(14, 3, size_str);
     1284    } else {
     1285        sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
     1286    }
     1287    bOK = newtButton(2, 6, "  OK  ");
     1288    bCancel = newtButton(14, 6, "Cancel");
     1289    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     1290        b_raid = newtButton(26, 6, "RAID..");
     1291    }
     1292    newtPushHelpLine
     1293        ("       Edit this partition's mountpoint, size and format; then click 'OK'.");
     1294    myForm = newtForm(NULL, NULL, 0);
     1295    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     1296                          formatComp, label0, label1, label2, label3, bOK,
     1297                          bCancel, b_raid, NULL);
     1298    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     1299        b_res = newtRunForm(myForm);
     1300        strcpy(device_str, device_here);
     1301        strip_spaces(device_str);
     1302        strcpy(mountpoint_str, mountpoint_here);
     1303        strip_spaces(mountpoint_str);
     1304        strcpy(format_str, format_here);
     1305        strip_spaces(format_str);
     1306        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
     1307            && strstr(device_used_to_be, RAID_DEVICE_STUB)
     1308            && strcmp(device_str, device_used_to_be)) {
     1309            popup_and_OK("You can't change /dev/mdX to /dev/mdY.");
     1310            b_res = NULL;
     1311            continue;
     1312        } else if (b_res == bOK && !strcmp(mountpoint_str, "image")
     1313                   && strcmp(mountpt_used_to_be, "image")) {
     1314            popup_and_OK("You can't change a regular device to an image.");
     1315            b_res = NULL;
     1316            continue;
     1317        }
     1318        if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1319            && strcmp(mountlist->el[currline].mountpoint, "image")) {
     1320            strcpy(size_str, size_here);
     1321            strip_spaces(size_str);
     1322        } else {
     1323            sprintf(size_str, "%ld",
     1324                    calculate_raid_device_size(mountlist, raidlist,
     1325                                               mountlist->el[currline].
     1326                                               device) / 1024);
     1327            newtLabelSetText(sizeComp, size_str);
     1328        }
     1329        /* do not let user click RAID button if user has changed device_str */
     1330        if (b_res == b_raid) {
     1331            if (strcmp(device_str, mountlist->el[currline].device)) {
     1332                /*
     1333                   can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly
     1334                   when you try to map the changes over to the raidtab list, trust me
     1335                 */
     1336                popup_and_OK
     1337                    ("You cannot edit the RAID settings until you have OK'd your change to the device node.");
     1338            } else {
     1339                j = find_raid_device_in_raidlist(raidlist,
     1340                                                 mountlist->el[currline].
     1341                                                 device);
     1342                if (j < 0) {
     1343                    sprintf(tmp,
     1344                            "/etc/raidtab does not have an entry for %s; please delete it and add it again",
     1345                            mountlist->el[currline].device);
     1346                    popup_and_OK(tmp);
     1347                } else {
     1348                    log_it("edit_raidlist_entry - calling");
     1349                    edit_raidlist_entry(mountlist, raidlist,
     1350                                        &raidlist->el[j], currline);
     1351                }
     1352            }
     1353        }
     1354    }
     1355    newtFormDestroy(myForm);
     1356    newtPopHelpLine();
     1357    newtPopWindow();
     1358    if (b_res == bCancel) {
     1359        memcpy((void *) raidlist, (void *) &bkp_raidlist,
     1360               sizeof(struct raidlist_itself));
     1361        return;
     1362    }
     1363    strcpy(mountlist->el[currline].device, device_str);
     1364    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     1365    strcpy(mountlist->el[currline].format, format_str);
     1366    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1367        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     1368        mountlist->el[currline].size =
     1369            calculate_raid_device_size(mountlist, raidlist,
     1370                                       mountlist->el[currline].device);
     1371    } else {
     1372        mountlist->el[currline].size = atol(size_str) * 1024;
     1373    }
     1374    newtListboxSetEntry(listbox, (int) keylist[currline],
     1375                        mountlist_entry_to_string(mountlist, currline));
     1376    /* if new /dev/md RAID device then do funky stuff */
     1377    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1378        && !strstr(device_used_to_be, RAID_DEVICE_STUB)) {
     1379        initiate_new_raidlist_entry(raidlist, mountlist, currline,
     1380                                    device_str);
     1381    }
     1382    /* if moving from RAID to non-RAID then do funky stuff */
     1383    else if (strstr(device_used_to_be, RAID_DEVICE_STUB)
     1384             && !strstr(device_str, RAID_DEVICE_STUB)) {
     1385        delete_raidlist_entry(mountlist, raidlist, device_str);
     1386    }
     1387    /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */
     1388    else if (!strstr(device_used_to_be, RAID_DEVICE_STUB)
     1389             && !strstr(device_str, RAID_DEVICE_STUB)) {
     1390        rejig_partition_name_in_raidlist_if_necessary(raidlist,
     1391                                                      device_used_to_be,
     1392                                                      device_str);
     1393    }
    14971394/* else, moving a RAID to another RAID; bad idea, or so I thought */
    1498 #ifndef __FreeBSD__ /* It works fine under FBSD. */
    1499   else if (strcmp (device_used_to_be, device_str))
    1500     {
    1501       popup_and_OK
    1502     ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
    1503     }
     1395#ifndef __FreeBSD__             /* It works fine under FBSD. */
     1396    else if (strcmp(device_used_to_be, device_str)) {
     1397        popup_and_OK
     1398            ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
     1399    }
    15041400#endif
    1505   redraw_mountlist (mountlist, keylist, listbox);
     1401    redraw_mountlist(mountlist, keylist, listbox);
    15061402}
    15071403
     
    15171413 */
    15181414void
    1519 add_raid_subdisk (struct raidlist_itself *raidlist, struct vinum_plex *raidrec, char *temp)
    1520 {
    1521     int i;
    1522     bool found = FALSE;
    1523    
    1524     for (i = 0; i < raidlist->disks.entries; ++i) {
    1525     if (!strcmp (raidlist->disks.el[i].device, temp)) {
    1526         strcpy (raidrec->sd [raidrec->subdisks].which_device,
    1527             raidlist->disks.el[i].name);
    1528         found = TRUE;
    1529     }
    1530     }
    1531     if (!found) {
    1532     sprintf (raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries);
    1533     sprintf (raidrec->sd [raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries);
    1534     strcpy (raidlist->disks.el[raidlist->disks.entries++].device, temp);
    1535     }
    1536     raidrec->subdisks++;
     1415add_raid_subdisk(struct raidlist_itself *raidlist,
     1416                 struct vinum_plex *raidrec, char *temp)
     1417{
     1418    int i;
     1419    bool found = FALSE;
     1420
     1421    for (i = 0; i < raidlist->disks.entries; ++i) {
     1422        if (!strcmp(raidlist->disks.el[i].device, temp)) {
     1423            strcpy(raidrec->sd[raidrec->subdisks].which_device,
     1424                   raidlist->disks.el[i].name);
     1425            found = TRUE;
     1426        }
     1427    }
     1428    if (!found) {
     1429        sprintf(raidlist->disks.el[raidlist->disks.entries].name,
     1430                "drive%i", raidlist->disks.entries);
     1431        sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i",
     1432                raidlist->disks.entries);
     1433        strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp);
     1434    }
     1435    raidrec->subdisks++;
    15371436}
    15381437
     
    15471446 * @ingroup restoreUtilityGroup
    15481447 */
    1549 char *
    1550 find_dev_entry_for_raid_device_name (struct raidlist_itself *raidlist, char *vinum_name)
    1551 {
    1552     int i;
    1553     for (i = 0; i < raidlist->disks.entries; ++i) {
    1554     if (!strcmp (raidlist->disks.el[i].name, vinum_name)) {
    1555         return raidlist->disks.el[i].device;
    1556     }
    1557     }
    1558     return NULL;
     1448char *find_dev_entry_for_raid_device_name(struct raidlist_itself *raidlist,
     1449                                          char *vinum_name)
     1450{
     1451    int i;
     1452    for (i = 0; i < raidlist->disks.entries; ++i) {
     1453        if (!strcmp(raidlist->disks.el[i].name, vinum_name)) {
     1454            return raidlist->disks.el[i].device;
     1455        }
     1456    }
     1457    return NULL;
    15591458}
    15601459
    15611460void
    1562 edit_raidlist_plex (struct mountlist_itself *mountlist,
    1563             struct raidlist_itself *raidlist,
    1564             struct vinum_plex *raidrec, int currline, int currline2);
     1461edit_raidlist_plex(struct mountlist_itself *mountlist,
     1462                   struct raidlist_itself *raidlist,
     1463                   struct vinum_plex *raidrec, int currline,
     1464                   int currline2);
    15651465
    15661466#endif
     
    15761476 */
    15771477void
    1578 edit_raidlist_entry (struct mountlist_itself *mountlist,
    1579              struct raidlist_itself *raidlist,
    1580              struct OSSWAP (raid_device_record, vinum_volume) *raidrec, int currline)
     1478edit_raidlist_entry(struct mountlist_itself *mountlist,
     1479                    struct raidlist_itself *raidlist,
     1480                    struct OSSWAP (raid_device_record,
     1481                                   vinum_volume) * raidrec, int currline)
    15811482{
    15821483
    15831484#ifdef __FreeBSD__
    15841485    /** structures ********************************************************/
    1585   struct vinum_volume bkp_raidrec;
     1486    struct vinum_volume bkp_raidrec;
    15861487
    15871488
    15881489    /** buffers ***********************************************************/
    1589   char title_of_editraidForm_window[MAX_STR_LEN];
     1490    char title_of_editraidForm_window[MAX_STR_LEN];
    15901491
    15911492    /** newt **************************************************************/
    1592   newtComponent editraidForm;
    1593   newtComponent bOK;
    1594   newtComponent bCancel;
    1595   newtComponent bEdit;
    1596   newtComponent bAdd;
    1597   newtComponent bDelete;
    1598   newtComponent b_res;
    1599   newtComponent plexesListbox;
    1600   newtComponent plexesHeader;
    1601 
    1602   void *keylist[10];
    1603   void *curr_choice;
    1604 
    1605   int currline2 = 0;
    1606 
    1607   log_it ("Started edit_raidlist_entry");
    1608   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    1609       sizeof (struct vinum_volume));
    1610   sprintf (title_of_editraidForm_window, "Plexes on %s", raidrec->volname);
    1611   newtPushHelpLine ("   Please select a plex to edit");
    1612   newtOpenWindow (13, 5, 54, 15, title_of_editraidForm_window);
    1613   for (;;)
    1614     {
    1615     int i;
    1616     char headerstr[MAX_STR_LEN];
    1617     snprintf (headerstr, MAX_STR_LEN, "%-14s %-8s  %11s  %8s",
    1618           "Plex", "Level", "Stripe Size", "Subdisks");
    1619 
    1620     bOK = newtCompactButton (2, 13, "  OK  ");
    1621     bCancel = newtCompactButton (12, 13, "Cancel");
    1622     bAdd  = newtCompactButton (22, 13, " Add ");
    1623     bEdit = newtCompactButton (32, 13, " Edit ");
    1624     bDelete = newtCompactButton (42, 13, "Delete");
    1625 
    1626     plexesListbox = newtListbox (2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1627     plexesHeader  = newtLabel (2, 2, headerstr);
    1628     editraidForm = newtForm (NULL, NULL, 0);
    1629 
    1630     newtListboxClear (plexesListbox);
    1631     for (i = 0; i < 10; ++i) {
    1632         keylist[i] = (void *) i;
    1633         if (i < raidrec->plexes) {
    1634         char pname[64], entry[MAX_STR_LEN], raidlevel[64], chunksize[64];
    1635         switch (raidrec->plex[i].raidlevel) {
    1636         case -1:
    1637             strcpy (raidlevel, "concat");
    1638             break;
    1639         case 0:
    1640             strcpy (raidlevel, "striped");
    1641             break;
    1642         case 5:
    1643             strcpy (raidlevel, "raid5");
    1644             break;
    1645         default:
    1646             sprintf (raidlevel, "raid%i", raidrec->plex[i].raidlevel);
    1647             break;
    1648         }
    1649 
    1650         if (raidrec->plex[i].raidlevel == -1) {
    1651             strcpy (chunksize, "N/A");
    1652         } else {
    1653             sprintf (chunksize, "%dk", raidrec->plex[i].stripesize);
    1654         }
    1655         snprintf (pname, 64, "%s.p%i", raidrec->volname, i);
    1656         snprintf (entry, MAX_STR_LEN, "%-14s %-8s  %11s  %8d", pname, raidlevel, chunksize,
    1657               raidrec->plex[i].subdisks);
    1658         newtListboxAppendEntry (plexesListbox, entry, keylist[i]);
    1659         }
    1660     }
    1661 
    1662     newtFormAddComponents (editraidForm, bOK, bCancel, bAdd, bEdit,
    1663                    bDelete, plexesListbox, plexesHeader, NULL);
    1664 
    1665     b_res = newtRunForm (editraidForm);
    1666       if (b_res == bOK || b_res == bCancel)
    1667     {
    1668       break;
    1669     }
    1670 
    1671       curr_choice = newtListboxGetCurrent (plexesListbox);
    1672       for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) {
    1673       if (currline2 > 9) break;
    1674       if (keylist[currline2] == curr_choice) break;
    1675       }
    1676 
    1677       if (b_res == bDelete) {
    1678       char msg[MAX_STR_LEN];
    1679       sprintf (msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
    1680       if (ask_me_yes_or_no (msg)) {
    1681           log_it ("Deleting RAID plex");
    1682           memcpy ((void *) &raidrec->plex[currline2],
    1683               (void *) &raidrec->plex[raidrec->plexes - 1],
    1684               sizeof (struct vinum_plex));
    1685           raidrec->plexes--;
    1686       }
    1687       continue;
    1688       }
    1689       if (b_res == bAdd) {
    1690       raidrec->plex[raidrec->plexes].raidlevel = 0;
    1691       raidrec->plex[raidrec->plexes].stripesize = 279;
    1692       raidrec->plex[raidrec->plexes].subdisks = 0;
    1693       currline2 = raidrec->plexes++;
    1694       }
    1695       edit_raidlist_plex (mountlist, raidlist, &raidrec->plex[currline2], currline, currline2);
    1696       newtFormDestroy (editraidForm);
    1697     }
    1698   if (b_res == bCancel)
    1699     {
    1700       memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    1701           sizeof (struct vinum_volume));
    1702     }
    1703   newtPopHelpLine ();
    1704   newtPopWindow ();
    1705   mountlist->el[currline].size =
    1706     calculate_raid_device_size (mountlist, raidlist, raidrec->volname);
     1493    newtComponent editraidForm;
     1494    newtComponent bOK;
     1495    newtComponent bCancel;
     1496    newtComponent bEdit;
     1497    newtComponent bAdd;
     1498    newtComponent bDelete;
     1499    newtComponent b_res;
     1500    newtComponent plexesListbox;
     1501    newtComponent plexesHeader;
     1502
     1503    void *keylist[10];
     1504    void *curr_choice;
     1505
     1506    int currline2 = 0;
     1507
     1508    log_it("Started edit_raidlist_entry");
     1509    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     1510           sizeof(struct vinum_volume));
     1511    sprintf(title_of_editraidForm_window, "Plexes on %s",
     1512            raidrec->volname);
     1513    newtPushHelpLine("   Please select a plex to edit");
     1514    newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window);
     1515    for (;;) {
     1516        int i;
     1517        char headerstr[MAX_STR_LEN];
     1518        snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s  %11s  %8s",
     1519                 "Plex", "Level", "Stripe Size", "Subdisks");
     1520
     1521        bOK = newtCompactButton(2, 13, "  OK  ");
     1522        bCancel = newtCompactButton(12, 13, "Cancel");
     1523        bAdd = newtCompactButton(22, 13, " Add ");
     1524        bEdit = newtCompactButton(32, 13, " Edit ");
     1525        bDelete = newtCompactButton(42, 13, "Delete");
     1526
     1527        plexesListbox =
     1528            newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1529        plexesHeader = newtLabel(2, 2, headerstr);
     1530        editraidForm = newtForm(NULL, NULL, 0);
     1531
     1532        newtListboxClear(plexesListbox);
     1533        for (i = 0; i < 10; ++i) {
     1534            keylist[i] = (void *) i;
     1535            if (i < raidrec->plexes) {
     1536                char pname[64], entry[MAX_STR_LEN], raidlevel[64],
     1537                    chunksize[64];
     1538                switch (raidrec->plex[i].raidlevel) {
     1539                case -1:
     1540                    strcpy(raidlevel, "concat");
     1541                    break;
     1542                case 0:
     1543                    strcpy(raidlevel, "striped");
     1544                    break;
     1545                case 5:
     1546                    strcpy(raidlevel, "raid5");
     1547                    break;
     1548                default:
     1549                    sprintf(raidlevel, "raid%i",
     1550                            raidrec->plex[i].raidlevel);
     1551                    break;
     1552                }
     1553
     1554                if (raidrec->plex[i].raidlevel == -1) {
     1555                    strcpy(chunksize, "N/A");
     1556                } else {
     1557                    sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
     1558                }
     1559                snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
     1560                snprintf(entry, MAX_STR_LEN, "%-14s %-8s  %11s  %8d",
     1561                         pname, raidlevel, chunksize,
     1562                         raidrec->plex[i].subdisks);
     1563                newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
     1564            }
     1565        }
     1566
     1567        newtFormAddComponents(editraidForm, bOK, bCancel, bAdd, bEdit,
     1568                              bDelete, plexesListbox, plexesHeader, NULL);
     1569
     1570        b_res = newtRunForm(editraidForm);
     1571        if (b_res == bOK || b_res == bCancel) {
     1572            break;
     1573        }
     1574
     1575        curr_choice = newtListboxGetCurrent(plexesListbox);
     1576        for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) {
     1577            if (currline2 > 9)
     1578                break;
     1579            if (keylist[currline2] == curr_choice)
     1580                break;
     1581        }
     1582
     1583        if (b_res == bDelete) {
     1584            char msg[MAX_STR_LEN];
     1585            sprintf(msg, "Are you sure you want to delete %s.p%i?",
     1586                    raidrec->volname, currline2);
     1587            if (ask_me_yes_or_no(msg)) {
     1588                log_it("Deleting RAID plex");
     1589                memcpy((void *) &raidrec->plex[currline2],
     1590                       (void *) &raidrec->plex[raidrec->plexes - 1],
     1591                       sizeof(struct vinum_plex));
     1592                raidrec->plexes--;
     1593            }
     1594            continue;
     1595        }
     1596        if (b_res == bAdd) {
     1597            raidrec->plex[raidrec->plexes].raidlevel = 0;
     1598            raidrec->plex[raidrec->plexes].stripesize = 279;
     1599            raidrec->plex[raidrec->plexes].subdisks = 0;
     1600            currline2 = raidrec->plexes++;
     1601        }
     1602        edit_raidlist_plex(mountlist, raidlist, &raidrec->plex[currline2],
     1603                           currline, currline2);
     1604        newtFormDestroy(editraidForm);
     1605    }
     1606    if (b_res == bCancel) {
     1607        memcpy((void *) raidrec, (void *) &bkp_raidrec,
     1608               sizeof(struct vinum_volume));
     1609    }
     1610    newtPopHelpLine();
     1611    newtPopWindow();
     1612    mountlist->el[currline].size =
     1613        calculate_raid_device_size(mountlist, raidlist, raidrec->volname);
    17071614#else
    17081615    /** structures ********************************************************/
    1709   struct raid_device_record *bkp_raidrec;
     1616    struct raid_device_record *bkp_raidrec;
    17101617
    17111618
    17121619    /** buffers ***********************************************************/
    1713     char *title_of_editraidForm_window;
     1620    char *title_of_editraidForm_window;
    17141621    char *sz_raid_level;
    17151622    char *sz_data_disks;
     
    17191626
    17201627    /** newt **************************************************************/
    1721   newtComponent editraidForm;
     1628    newtComponent editraidForm;
    17221629    newtComponent bOK;
    17231630    newtComponent bCancel;
     
    17301637    newtComponent b_res;
    17311638
    1732   assert(mountlist!=NULL);
    1733   assert(raidlist!=NULL);
    1734   assert(raidrec!=NULL);
    1735 
    1736   malloc_string(title_of_editraidForm_window);
    1737   malloc_string(sz_raid_level);
    1738   malloc_string(sz_data_disks);
    1739   malloc_string(sz_spare_disks);
    1740   malloc_string(sz_parity_disks);
    1741   malloc_string(sz_failed_disks);
    1742   if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record))))
    1743     { fatal_error("Cannot malloc space for raidrec"); }
    1744 
    1745   log_it ("Started edit_raidlist_entry");
    1746 
    1747   memcpy ((void *) bkp_raidrec, (void *) raidrec,
    1748       sizeof (struct raid_device_record));
    1749   sprintf (title_of_editraidForm_window, "%s", raidrec->raid_device);
    1750   log_msg(2, "Opening newt window");
    1751   newtOpenWindow (20, 5, 40, 14, title_of_editraidForm_window);
    1752   for (;;)
    1753     {
    1754       log_msg(2, "Main loop");
    1755       sprintf (title_of_editraidForm_window, "Edit %s", raidrec->raid_device);
    1756       strcpy (sz_raid_level,
    1757           turn_raid_level_number_to_string (raidrec->raid_level));
    1758       strcpy (sz_data_disks,
    1759           number_of_disks_as_string (raidrec->data_disks.entries,
    1760                      "data"));
    1761       strcpy (sz_spare_disks,
    1762           number_of_disks_as_string (raidrec->spare_disks.entries,
    1763                      "spare"));
    1764       strcpy (sz_parity_disks,
    1765           number_of_disks_as_string (raidrec->parity_disks.entries,
    1766                      "parity"));
    1767       strcpy (sz_failed_disks,
    1768           number_of_disks_as_string (raidrec->failed_disks.entries,
    1769                      "failed"));
    1770       bSelectData = newtButton (1, 1, sz_data_disks);
    1771       bSelectSpare = newtButton (20, 1, sz_spare_disks);
    1772       bSelectParity = newtButton (1, 5, sz_parity_disks);
    1773       bSelectFailed = newtButton (20, 5, sz_failed_disks);
    1774       bChangeRaid = newtButton (1, 9, sz_raid_level);
    1775       bOK = newtButton (16 + (raidrec->raid_level == -1), 9, "  OK  ");
    1776       bCancel = newtButton (28, 9, "Cancel");
    1777       bAdditional =
    1778     newtCompactButton (1, 13, "Additional settings and information");
    1779       newtPushHelpLine
    1780     ("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel.");
    1781       editraidForm = newtForm (NULL, NULL, 0);
    1782       newtFormAddComponents (editraidForm, bSelectData, bSelectParity,
    1783                  bChangeRaid, bSelectSpare, bSelectFailed, bOK,
    1784                  bCancel, bAdditional);
    1785       b_res = newtRunForm (editraidForm);
    1786       if (b_res == bChangeRaid)
    1787     {
    1788       choose_raid_level (raidrec);
    1789     }
    1790       else if (b_res == bSelectData)
    1791     {
    1792       select_raid_disks (mountlist, raidlist, raidrec, "data",
    1793                  &raidrec->data_disks);
    1794     }
    1795       else if (b_res == bSelectSpare)
    1796     {
    1797       select_raid_disks (mountlist, raidlist, raidrec, "spare",
    1798                  &raidrec->spare_disks);
    1799     }
    1800       else if (b_res == bSelectParity)
    1801     {
    1802       select_raid_disks (mountlist, raidlist, raidrec, "parity",
    1803                  &raidrec->parity_disks);
    1804     }
    1805       else if (b_res == bSelectFailed)
    1806     {
    1807       select_raid_disks (mountlist, raidlist, raidrec, "failed",
    1808                  &raidrec->failed_disks);
    1809     }
    1810       else if (b_res == bAdditional)
    1811     {
    1812       edit_raidrec_additional_vars (raidrec);
    1813     }
    1814       newtFormDestroy (editraidForm);
    1815       if (b_res == bOK || b_res == bCancel)
    1816     {
    1817       break;
    1818     }
    1819     }
    1820   if (b_res == bCancel)
    1821     {
    1822       memcpy ((void *) raidrec, (void *) bkp_raidrec,
    1823           sizeof (struct raid_device_record));
    1824     }
    1825   newtPopHelpLine ();
    1826   newtPopWindow ();
    1827   mountlist->el[currline].size =
    1828     calculate_raid_device_size (mountlist, raidlist, raidrec->raid_device);
    1829   paranoid_free(title_of_editraidForm_window);
    1830   paranoid_free(sz_raid_level);
    1831   paranoid_free(sz_data_disks);
    1832   paranoid_free(sz_spare_disks);
    1833   paranoid_free(sz_parity_disks);
    1834   paranoid_free(sz_failed_disks);
    1835   paranoid_free(bkp_raidrec);
     1639    assert(mountlist != NULL);
     1640    assert(raidlist != NULL);
     1641    assert(raidrec != NULL);
     1642
     1643    malloc_string(title_of_editraidForm_window);
     1644    malloc_string(sz_raid_level);
     1645    malloc_string(sz_data_disks);
     1646    malloc_string(sz_spare_disks);
     1647    malloc_string(sz_parity_disks);
     1648    malloc_string(sz_failed_disks);
     1649    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
     1650        fatal_error("Cannot malloc space for raidrec");
     1651    }
     1652
     1653    log_it("Started edit_raidlist_entry");
     1654
     1655    memcpy((void *) bkp_raidrec, (void *) raidrec,
     1656           sizeof(struct raid_device_record));
     1657    sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
     1658    log_msg(2, "Opening newt window");
     1659    newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
     1660    for (;;) {
     1661        log_msg(2, "Main loop");
     1662        sprintf(title_of_editraidForm_window, "Edit %s",
     1663                raidrec->raid_device);
     1664        strcpy(sz_raid_level,
     1665               turn_raid_level_number_to_string(raidrec->raid_level));
     1666        strcpy(sz_data_disks,
     1667               number_of_disks_as_string(raidrec->data_disks.entries,
     1668                                         "data"));
     1669        strcpy(sz_spare_disks,
     1670               number_of_disks_as_string(raidrec->spare_disks.entries,
     1671                                         "spare"));
     1672        strcpy(sz_parity_disks,
     1673               number_of_disks_as_string(raidrec->parity_disks.entries,
     1674                                         "parity"));
     1675        strcpy(sz_failed_disks,
     1676               number_of_disks_as_string(raidrec->failed_disks.entries,
     1677                                         "failed"));
     1678        bSelectData = newtButton(1, 1, sz_data_disks);
     1679        bSelectSpare = newtButton(20, 1, sz_spare_disks);
     1680        bSelectParity = newtButton(1, 5, sz_parity_disks);
     1681        bSelectFailed = newtButton(20, 5, sz_failed_disks);
     1682        bChangeRaid = newtButton(1, 9, sz_raid_level);
     1683        bOK = newtButton(16 + (raidrec->raid_level == -1), 9, "  OK  ");
     1684        bCancel = newtButton(28, 9, "Cancel");
     1685        bAdditional =
     1686            newtCompactButton(1, 13,
     1687                              "Additional settings and information");
     1688        newtPushHelpLine
     1689            ("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel.");
     1690        editraidForm = newtForm(NULL, NULL, 0);
     1691        newtFormAddComponents(editraidForm, bSelectData, bSelectParity,
     1692                              bChangeRaid, bSelectSpare, bSelectFailed,
     1693                              bOK, bCancel, bAdditional);
     1694        b_res = newtRunForm(editraidForm);
     1695        if (b_res == bChangeRaid) {
     1696            choose_raid_level(raidrec);
     1697        } else if (b_res == bSelectData) {
     1698            select_raid_disks(mountlist, raidlist, raidrec, "data",
     1699                              &raidrec->data_disks);
     1700        } else if (b_res == bSelectSpare) {
     1701            select_raid_disks(mountlist, raidlist, raidrec, "spare",
     1702                              &raidrec->spare_disks);
     1703        } else if (b_res == bSelectParity) {
     1704            select_raid_disks(mountlist, raidlist, raidrec, "parity",
     1705                              &raidrec->parity_disks);
     1706        } else if (b_res == bSelectFailed) {
     1707            select_raid_disks(mountlist, raidlist, raidrec, "failed",
     1708                              &raidrec->failed_disks);
     1709        } else if (b_res == bAdditional) {
     1710            edit_raidrec_additional_vars(raidrec);
     1711        }
     1712        newtFormDestroy(editraidForm);
     1713        if (b_res == bOK || b_res == bCancel) {
     1714            break;
     1715        }
     1716    }
     1717    if (b_res == bCancel) {
     1718        memcpy((void *) raidrec, (void *) bkp_raidrec,
     1719               sizeof(struct raid_device_record));
     1720    }
     1721    newtPopHelpLine();
     1722    newtPopWindow();
     1723    mountlist->el[currline].size =
     1724        calculate_raid_device_size(mountlist, raidlist,
     1725                                   raidrec->raid_device);
     1726    paranoid_free(title_of_editraidForm_window);
     1727    paranoid_free(sz_raid_level);
     1728    paranoid_free(sz_data_disks);
     1729    paranoid_free(sz_spare_disks);
     1730    paranoid_free(sz_parity_disks);
     1731    paranoid_free(sz_failed_disks);
     1732    paranoid_free(bkp_raidrec);
    18361733#endif
    18371734}
     
    18501747 */
    18511748void
    1852 edit_raidlist_plex (struct mountlist_itself *mountlist,
    1853             struct raidlist_itself *raidlist,
    1854             struct vinum_plex *raidrec, int currline, int currline2)
     1749edit_raidlist_plex(struct mountlist_itself *mountlist,
     1750                   struct raidlist_itself *raidlist,
     1751                   struct vinum_plex *raidrec, int currline, int currline2)
    18551752{
    18561753
    18571754    /** structures ********************************************************/
    1858   struct vinum_plex bkp_raidrec;
     1755    struct vinum_plex bkp_raidrec;
    18591756
    18601757
    18611758    /** buffers ***********************************************************/
    1862   char title_of_editraidForm_window[MAX_STR_LEN];
     1759    char title_of_editraidForm_window[MAX_STR_LEN];
    18631760
    18641761    /** newt **************************************************************/
    1865   newtComponent editraidForm;
    1866   newtComponent bOK;
    1867   newtComponent bCancel;
    1868   newtComponent bEdit;
    1869   newtComponent bAdd;
    1870   newtComponent bDelete;
    1871   newtComponent b_res;
    1872   newtComponent unallocListbox, allocListbox;
    1873   newtComponent bLevel, sLevel;
    1874   newtComponent bStripeSize, sStripeSize;
    1875   newtComponent bAlloc, bUnalloc;
    1876 
    1877   void *keylist[ARBITRARY_MAXIMUM];
    1878   void *curr_choice_a, *curr_choice_u;
    1879   int currline_a, currline_u;
    1880 
    1881   struct mountlist_itself *unallocparts;
    1882  
    1883   unallocparts = malloc (sizeof (struct mountlist_itself));
    1884 
    1885   log_it ("Started edit_raidlist_entry");
    1886   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    1887       sizeof (struct vinum_plex));
    1888   sprintf (title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2);
    1889   newtPushHelpLine ("   Please select a subdisk to edit, or edit this plex's parameters");
    1890   newtOpenWindow (13, 3, 54, 18, title_of_editraidForm_window);
    1891  for (;;)
    1892     {
    1893     int i;
    1894     char headerstr[MAX_STR_LEN];
    1895     char tmp[64];
    1896     snprintf (headerstr, MAX_STR_LEN, "%-24s %s",
    1897           "Subdisk", "Device");
    1898    
    1899    
    1900     switch (raidrec->raidlevel) {
    1901     case -1:
    1902         strcpy (tmp, "concat");
    1903         break;
    1904     case 0:
    1905         strcpy (tmp, "striped");
    1906         break;
    1907     case 5:
    1908         strcpy (tmp, "raid5");
    1909         break;
    1910     default:
    1911         sprintf (tmp, "unknown (%i)", raidrec->raidlevel);
    1912         break;
    1913     }
    1914     bLevel = newtCompactButton (2, 2, " RAID level ");
    1915     sLevel = newtLabel (19, 2, tmp);
    1916 
    1917     if (raidrec->raidlevel >= 0) {
    1918         sprintf (tmp, "%ik", raidrec->stripesize);
    1919         bStripeSize = newtCompactButton (2, 4, " Stripe size ");
    1920     } else {
    1921         strcpy (tmp, "N/A");
    1922         bStripeSize = newtLabel (2, 4, "Stripe size:");     
    1923     }
    1924     sStripeSize = newtLabel (19, 4, tmp);
    1925    
    1926     bOK = newtCompactButton (2, 16, "  OK  ");
    1927     bCancel = newtCompactButton (12, 16, "Cancel");
    1928     bAdd  = newtCompactButton (22, 16, " Add ");
    1929     bEdit = newtCompactButton (32, 16, " Edit ");
    1930     bDelete = newtCompactButton (42, 16, "Delete");
    1931    
    1932    
    1933     //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1934     //  plexesHeader  = newtLabel (2, 6, headerstr);
    1935     unallocListbox  = newtListbox (2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1936     allocListbox   = newtListbox (33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1937     bAlloc   = newtButton (23, 7, " -> ");
    1938     bUnalloc = newtButton (23, 11, " <- ");
    1939    
    1940     editraidForm = newtForm (NULL, NULL, 0);
    1941 
    1942     newtListboxClear (allocListbox);
    1943     newtListboxClear (unallocListbox);
    1944     bzero (unallocparts, sizeof (struct mountlist_itself));
    1945     make_list_of_unallocated_raid_partitions (unallocparts, mountlist, raidlist);
    1946     for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
    1947         char entry[MAX_STR_LEN];
    1948         keylist[i] = (void *) i;
    1949         if (i < raidrec->subdisks) {
    1950         snprintf (entry, MAX_STR_LEN, "%-17s", find_dev_entry_for_raid_device_name (raidlist, raidrec->sd[i].which_device));
    1951         newtListboxAppendEntry (allocListbox, entry, keylist[i]);
    1952         }
    1953         if (i < unallocparts->entries) {
    1954         snprintf (entry, MAX_STR_LEN, "%-17s", unallocparts->el[i].device);
    1955         newtListboxAppendEntry (unallocListbox, entry, keylist[i]);
    1956         }
    1957     }
    1958    
     1762    newtComponent editraidForm;
     1763    newtComponent bOK;
     1764    newtComponent bCancel;
     1765    newtComponent bEdit;
     1766    newtComponent bAdd;
     1767    newtComponent bDelete;
     1768    newtComponent b_res;
     1769    newtComponent unallocListbox, allocListbox;
     1770    newtComponent bLevel, sLevel;
     1771    newtComponent bStripeSize, sStripeSize;
     1772    newtComponent bAlloc, bUnalloc;
     1773
     1774    void *keylist[ARBITRARY_MAXIMUM];
     1775    void *curr_choice_a, *curr_choice_u;
     1776    int currline_a, currline_u;
     1777
     1778    struct mountlist_itself *unallocparts;
     1779
     1780    unallocparts = malloc(sizeof(struct mountlist_itself));
     1781
     1782    log_it("Started edit_raidlist_entry");
     1783    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     1784           sizeof(struct vinum_plex));
     1785    sprintf(title_of_editraidForm_window, "%s.p%i",
     1786            raidlist->el[currline].volname, currline2);
     1787    newtPushHelpLine
     1788        ("   Please select a subdisk to edit, or edit this plex's parameters");
     1789    newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
     1790    for (;;) {
     1791        int i;
     1792        char headerstr[MAX_STR_LEN];
     1793        char tmp[64];
     1794        snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");
     1795
     1796
     1797        switch (raidrec->raidlevel) {
     1798        case -1:
     1799            strcpy(tmp, "concat");
     1800            break;
     1801        case 0:
     1802            strcpy(tmp, "striped");
     1803            break;
     1804        case 5:
     1805            strcpy(tmp, "raid5");
     1806            break;
     1807        default:
     1808            sprintf(tmp, "unknown (%i)", raidrec->raidlevel);
     1809            break;
     1810        }
     1811        bLevel = newtCompactButton(2, 2, " RAID level ");
     1812        sLevel = newtLabel(19, 2, tmp);
     1813
     1814        if (raidrec->raidlevel >= 0) {
     1815            sprintf(tmp, "%ik", raidrec->stripesize);
     1816            bStripeSize = newtCompactButton(2, 4, " Stripe size ");
     1817        } else {
     1818            strcpy(tmp, "N/A");
     1819            bStripeSize = newtLabel(2, 4, "Stripe size:");
     1820        }
     1821        sStripeSize = newtLabel(19, 4, tmp);
     1822
     1823        bOK = newtCompactButton(2, 16, "  OK  ");
     1824        bCancel = newtCompactButton(12, 16, "Cancel");
     1825        bAdd = newtCompactButton(22, 16, " Add ");
     1826        bEdit = newtCompactButton(32, 16, " Edit ");
     1827        bDelete = newtCompactButton(42, 16, "Delete");
     1828
     1829
     1830        //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1831        //  plexesHeader  = newtLabel (2, 6, headerstr);
     1832        unallocListbox =
     1833            newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1834        allocListbox =
     1835            newtListbox(33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1836        bAlloc = newtButton(23, 7, " -> ");
     1837        bUnalloc = newtButton(23, 11, " <- ");
     1838
     1839        editraidForm = newtForm(NULL, NULL, 0);
     1840
     1841        newtListboxClear(allocListbox);
     1842        newtListboxClear(unallocListbox);
     1843        bzero(unallocparts, sizeof(struct mountlist_itself));
     1844        make_list_of_unallocated_raid_partitions(unallocparts, mountlist,
     1845                                                 raidlist);
     1846        for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
     1847            char entry[MAX_STR_LEN];
     1848            keylist[i] = (void *) i;
     1849            if (i < raidrec->subdisks) {
     1850                snprintf(entry, MAX_STR_LEN, "%-17s",
     1851                         find_dev_entry_for_raid_device_name(raidlist,
     1852                                                             raidrec->
     1853                                                             sd[i].
     1854                                                             which_device));
     1855                newtListboxAppendEntry(allocListbox, entry, keylist[i]);
     1856            }
     1857            if (i < unallocparts->entries) {
     1858                snprintf(entry, MAX_STR_LEN, "%-17s",
     1859                         unallocparts->el[i].device);
     1860                newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
     1861            }
     1862        }
     1863
    19591864#define COMP(x)  newtFormAddComponent (editraidForm, x)
    19601865#define UCOMP(x) if (unallocparts->entries > 0) COMP(x)
    19611866#define ACOMP(x) if (raidrec->subdisks > 0) COMP(x)
    1962     editraidForm = newtForm (NULL, NULL, 0);
    1963     UCOMP (unallocListbox);
    1964     UCOMP (bAlloc);
    1965     ACOMP (allocListbox);
    1966     ACOMP (bUnalloc);
    1967     COMP (bOK);
    1968     COMP (bCancel);
    1969     COMP (bLevel);
    1970     COMP (sLevel);
    1971     if (raidrec->raidlevel != -1) {
    1972         COMP (bStripeSize);
    1973         COMP (sStripeSize);
    1974     }
     1867        editraidForm = newtForm(NULL, NULL, 0);
     1868        UCOMP(unallocListbox);
     1869        UCOMP(bAlloc);
     1870        ACOMP(allocListbox);
     1871        ACOMP(bUnalloc);
     1872        COMP(bOK);
     1873        COMP(bCancel);
     1874        COMP(bLevel);
     1875        COMP(sLevel);
     1876        if (raidrec->raidlevel != -1) {
     1877            COMP(bStripeSize);
     1878            COMP(sStripeSize);
     1879        }
    19751880#undef COMP
    19761881#undef UCOMP
    19771882#undef ACOMP
    19781883
     1884        newtRefresh();
     1885        b_res = newtRunForm(editraidForm);
     1886        if (b_res == bOK || b_res == bCancel) {
     1887            break;
     1888        }
     1889
     1890        curr_choice_a = (raidrec->subdisks > 0) ?
     1891            newtListboxGetCurrent(allocListbox) : (void *) 1234;
     1892        curr_choice_u = (unallocparts->entries > 0) ?
     1893            newtListboxGetCurrent(unallocListbox) : (void *) 1234;
     1894        for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) {
     1895            if (currline_a > ARBITRARY_MAXIMUM)
     1896                break;
     1897            if (keylist[currline_a] == curr_choice_a)
     1898                break;
     1899        }
     1900        for (currline_u = 0; currline_u < unallocparts->entries;
     1901             ++currline_u) {
     1902            if (currline_u > ARBITRARY_MAXIMUM)
     1903                break;
     1904            if (keylist[currline_u] == curr_choice_u)
     1905                break;
     1906        }
     1907        if (b_res == bLevel) {
     1908            choose_raid_level(raidrec);
     1909        } else if (b_res == bStripeSize) {
     1910            char tmp[64];
     1911            sprintf(tmp, "%i", raidrec->stripesize);
     1912            if (popup_and_get_string
     1913                ("Stripe size",
     1914                 "Please enter the stripe size in kilobytes.", tmp, 20)) {
     1915                raidrec->stripesize = atoi(tmp);
     1916            }
     1917        } else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
     1918            if (currline_u <= unallocparts->entries)
     1919                add_raid_subdisk(raidlist, raidrec,
     1920                                 unallocparts->el[currline_u].device);
     1921        } else if ((b_res == bUnalloc) || (b_res == allocListbox)) {
     1922            if (currline_a <= raidrec->subdisks) {
     1923                memcpy((void *) &raidrec->sd[currline_a],
     1924                       (void *) &raidrec->sd[raidrec->subdisks - 1],
     1925                       sizeof(struct vinum_subdisk));
     1926                raidrec->subdisks--;
     1927            }
     1928        }
     1929#if 0
     1930    } else {
     1931        edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],
     1932                          currline3);
     1933    }
     1934#endif
     1935    newtFormDestroy(editraidForm);
    19791936    newtRefresh();
    1980     b_res = newtRunForm (editraidForm);
    1981       if (b_res == bOK || b_res == bCancel)
    1982     {
    1983       break;
    1984     }
    1985 
    1986       curr_choice_a = (raidrec->subdisks > 0)     ?
    1987       newtListboxGetCurrent (allocListbox)    : (void *)1234;
    1988       curr_choice_u = (unallocparts->entries > 0) ?
    1989       newtListboxGetCurrent (unallocListbox)  : (void *)1234;
    1990       for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) {
    1991       if (currline_a > ARBITRARY_MAXIMUM) break;
    1992       if (keylist[currline_a] == curr_choice_a) break;
    1993       }
    1994       for (currline_u = 0; currline_u < unallocparts->entries; ++currline_u) {
    1995       if (currline_u > ARBITRARY_MAXIMUM) break;
    1996       if (keylist[currline_u] == curr_choice_u) break;
    1997       }
    1998       if (b_res == bLevel) {
    1999       choose_raid_level (raidrec);
    2000       }
    2001       else if (b_res == bStripeSize) {
    2002       char tmp[64];
    2003       sprintf (tmp, "%i", raidrec->stripesize);
    2004       if (popup_and_get_string ("Stripe size", "Please enter the stripe size in kilobytes.",
    2005                     tmp, 20)) {
    2006           raidrec->stripesize = atoi (tmp);
    2007       }
    2008       }
    2009       else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
    2010       if (currline_u <= unallocparts->entries)
    2011           add_raid_subdisk (raidlist, raidrec, unallocparts->el[currline_u].device);
    2012       }
    2013       else if ((b_res == bUnalloc) || (b_res == allocListbox)) {
    2014       if (currline_a <= raidrec->subdisks) {
    2015           memcpy ((void *) &raidrec->sd[currline_a],
    2016               (void *) &raidrec->sd[raidrec->subdisks - 1],
    2017               sizeof (struct vinum_subdisk));
    2018           raidrec->subdisks--;
    2019       }
    2020       }
    2021 #if 0     
    2022       } else {
    2023       edit_raid_subdisk (raidlist, raidrec, &raidrec->sd[currline3], currline3);
    2024       }
    2025 #endif
    2026       newtFormDestroy (editraidForm);
    2027       newtRefresh();
    2028     }
    2029   if (b_res == bCancel)
    2030     {
    2031     memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    2032         sizeof (struct vinum_plex));
    2033     }
    2034   newtPopWindow();
    2035   newtPopHelpLine ();
     1937}
     1938
     1939if (b_res == bCancel) {
     1940    memcpy((void *) raidrec, (void *) &bkp_raidrec,
     1941           sizeof(struct vinum_plex));
     1942}
     1943newtPopWindow();
     1944newtPopHelpLine();
    20361945}
    20371946#else
     
    20421951 * @ingroup restoreGuiVarslist
    20431952 */
    2044 void
    2045 edit_varslist_entry (struct raid_device_record *raidrec, int lino)
     1953void edit_varslist_entry(struct raid_device_record *raidrec, int lino)
    20461954{
    20471955
    20481956    /** buffers ***********************************************************/
    2049   char header[MAX_STR_LEN];
     1957    char header[MAX_STR_LEN];
    20501958    char comment[MAX_STR_LEN];
    20511959    char sz_out[MAX_STR_LEN];
    20521960
    2053   assert(raidrec!=0);
    2054   assert(lino>=0);
    2055 
    2056   strcpy (sz_out, raidrec->additional_vars.el[lino].value);
    2057   sprintf (header, "Edit %s", raidrec->additional_vars.el[lino].label);
    2058   sprintf (comment, "Please set %s's value (currently '%s')",
    2059        raidrec->additional_vars.el[lino].label, sz_out);
    2060   if (popup_and_get_string (header, comment, sz_out, MAX_STR_LEN))
    2061     {
    2062       strip_spaces (sz_out);
    2063       strcpy (raidrec->additional_vars.el[lino].value, sz_out);
    2064     }
     1961    assert(raidrec != 0);
     1962    assert(lino >= 0);
     1963
     1964    strcpy(sz_out, raidrec->additional_vars.el[lino].value);
     1965    sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label);
     1966    sprintf(comment, "Please set %s's value (currently '%s')",
     1967            raidrec->additional_vars.el[lino].label, sz_out);
     1968    if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
     1969        strip_spaces(sz_out);
     1970        strcpy(raidrec->additional_vars.el[lino].value, sz_out);
     1971    }
    20651972}
    20661973
     
    20771984 */
    20781985int
    2079 edit_mountlist_in_newt (char*mountlist_fname, struct mountlist_itself *mountlist,
    2080         struct raidlist_itself *raidlist)
     1986edit_mountlist_in_newt(char *mountlist_fname,
     1987                       struct mountlist_itself *mountlist,
     1988                       struct raidlist_itself *raidlist)
    20811989{
    20821990
    20831991    /** newt **************************************************************/
    2084   newtComponent myForm;
     1992    newtComponent myForm;
    20851993    newtComponent bAdd;
    20861994    newtComponent bEdit;
     
    20972005
    20982006    /** ???? *************************************************************/
    2099   void *curr_choice;
    2100   void *keylist[ARBITRARY_MAXIMUM];
     2007    void *curr_choice;
     2008    void *keylist[ARBITRARY_MAXIMUM];
    21012009
    21022010    /** int **************************************************************/
    2103   int i = 0;
     2011    int i = 0;
    21042012    int currline = 0;
    21052013    int finished = FALSE;
     
    21112019    char flaws_str_C[MAX_STR_LEN];
    21122020
    2113   assert(mountlist!=NULL);
    2114   assert(raidlist!=NULL);
    2115 
    2116   strcpy (flaws_str_A, "xxxxxxxxx");
    2117   strcpy (flaws_str_B, "xxxxxxxxx");
    2118   strcpy (flaws_str_C, "xxxxxxxxx");
    2119   if (mountlist->entries > ARBITRARY_MAXIMUM)
    2120     {
    2121       log_to_screen ("Arbitrary limits suck, man!");
    2122       finish (1);
    2123     }
    2124   newtPushHelpLine
    2125     ("   Please edit the mountlist to your satisfaction, then click OK or Cancel.");
    2126   i = 4;
    2127   bAdd = newtCompactButton (i, 17, " Add ");
    2128   bEdit = newtCompactButton (i += 11, 17, " Edit ");
    2129   bDelete = newtCompactButton (i += 12, 17, "Delete");
    2130   bReload = newtCompactButton (i += 12, 17, "Reload");
    2131   bCancel = newtCompactButton (i += 12, 17, "Cancel");
    2132   bOK = newtCompactButton (i += 12, 17, "  OK  ");
    2133   sprintf (tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format",
    2134        "Size (MB)");
    2135   headerMsg = newtLabel (2, 1, tmp);
    2136   flawsLabelA = newtLabel (2, 13, flaws_str_A);
    2137   flawsLabelB = newtLabel (2, 14, flaws_str_B);
    2138   flawsLabelC = newtLabel (2, 15, flaws_str_C);
    2139   partitionsListbox =
    2140     newtListbox (2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2141   redraw_mountlist (mountlist, keylist, partitionsListbox);
    2142   newtOpenWindow (1, 3, 77, 18, "Editing mountlist");
    2143   myForm = newtForm (NULL, NULL, 0);
    2144   newtFormAddComponents (myForm, headerMsg, partitionsListbox, flawsLabelA,
    2145              flawsLabelB, flawsLabelC, bAdd, bEdit, bDelete,
    2146              bReload, bCancel, bOK, NULL);
    2147   while (!finished)
    2148     {
    2149       evaluate_mountlist (mountlist, flaws_str_A, flaws_str_B, flaws_str_C);
    2150       newtLabelSetText (flawsLabelA, flaws_str_A);
    2151       newtLabelSetText (flawsLabelB, flaws_str_B);
    2152       newtLabelSetText (flawsLabelC, flaws_str_C);
    2153       b_res = newtRunForm (myForm);
    2154       if (b_res == bOK)
    2155     {
    2156       if (!evaluate_mountlist
    2157           (mountlist, flaws_str_A, flaws_str_B, flaws_str_C))
    2158         {
    2159           finished =
    2160         ask_me_yes_or_no
    2161         ("Your mountlist might not work. Continue anyway?");
    2162         }
    2163       else
    2164         {
    2165           finished =
    2166         ask_me_yes_or_no
    2167         ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)");
    2168         }
    2169     }
    2170       else if (b_res == bCancel)
    2171     {
    2172       finished = TRUE;
    2173     }
    2174       else if (b_res == bReload)
    2175     {
    2176       if (ask_me_yes_or_no ("Reload original mountlist?"))
    2177         {
     2021    assert(mountlist != NULL);
     2022    assert(raidlist != NULL);
     2023
     2024    strcpy(flaws_str_A, "xxxxxxxxx");
     2025    strcpy(flaws_str_B, "xxxxxxxxx");
     2026    strcpy(flaws_str_C, "xxxxxxxxx");
     2027    if (mountlist->entries > ARBITRARY_MAXIMUM) {
     2028        log_to_screen("Arbitrary limits suck, man!");
     2029        finish(1);
     2030    }
     2031    newtPushHelpLine
     2032        ("   Please edit the mountlist to your satisfaction, then click OK or Cancel.");
     2033    i = 4;
     2034    bAdd = newtCompactButton(i, 17, " Add ");
     2035    bEdit = newtCompactButton(i += 11, 17, " Edit ");
     2036    bDelete = newtCompactButton(i += 12, 17, "Delete");
     2037    bReload = newtCompactButton(i += 12, 17, "Reload");
     2038    bCancel = newtCompactButton(i += 12, 17, "Cancel");
     2039    bOK = newtCompactButton(i += 12, 17, "  OK  ");
     2040    sprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format",
     2041            "Size (MB)");
     2042    headerMsg = newtLabel(2, 1, tmp);
     2043    flawsLabelA = newtLabel(2, 13, flaws_str_A);
     2044    flawsLabelB = newtLabel(2, 14, flaws_str_B);
     2045    flawsLabelC = newtLabel(2, 15, flaws_str_C);
     2046    partitionsListbox =
     2047        newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2048    redraw_mountlist(mountlist, keylist, partitionsListbox);
     2049    newtOpenWindow(1, 3, 77, 18, "Editing mountlist");
     2050    myForm = newtForm(NULL, NULL, 0);
     2051    newtFormAddComponents(myForm, headerMsg, partitionsListbox,
     2052                          flawsLabelA, flawsLabelB, flawsLabelC, bAdd,
     2053                          bEdit, bDelete, bReload, bCancel, bOK, NULL);
     2054    while (!finished) {
     2055        evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B,
     2056                           flaws_str_C);
     2057        newtLabelSetText(flawsLabelA, flaws_str_A);
     2058        newtLabelSetText(flawsLabelB, flaws_str_B);
     2059        newtLabelSetText(flawsLabelC, flaws_str_C);
     2060        b_res = newtRunForm(myForm);
     2061        if (b_res == bOK) {
     2062            if (!evaluate_mountlist
     2063                (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) {
     2064                finished =
     2065                    ask_me_yes_or_no
     2066                    ("Your mountlist might not work. Continue anyway?");
     2067            } else {
     2068                finished =
     2069                    ask_me_yes_or_no
     2070                    ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)");
     2071            }
     2072        } else if (b_res == bCancel) {
     2073            finished = TRUE;
     2074        } else if (b_res == bReload) {
     2075            if (ask_me_yes_or_no("Reload original mountlist?")) {
    21782076/*
    21792077This would be really dumb. RAIDTAB_FNAME is #define'd.   --- Hugo, 2003/04/24
     
    21842082        }
    21852083*/
    2186           load_mountlist (mountlist, mountlist_fname);
    2187           load_raidtab_into_raidlist (raidlist, RAIDTAB_FNAME);
    2188           redraw_mountlist (mountlist, keylist, partitionsListbox);
    2189         }
    2190     }
    2191       else
    2192     {
    2193       curr_choice = newtListboxGetCurrent (partitionsListbox);
    2194       for (i = 0; i < mountlist->entries && keylist[i] != curr_choice;
    2195            i++);
    2196       if (i == mountlist->entries && mountlist->entries > 0)
    2197         {
    2198           log_to_screen ("I don't know what that button does!");
    2199         }
    2200       else
    2201         {
    2202           currline = i;
    2203           if (b_res == bAdd)
    2204         {
    2205           add_mountlist_entry (mountlist, raidlist, partitionsListbox,
    2206                        currline, keylist);
    2207         }
    2208           else if (b_res == bDelete)
    2209         {
    2210           delete_mountlist_entry (mountlist, raidlist,
    2211                       partitionsListbox, currline,
    2212                       keylist);
    2213         }
    2214           else
    2215         {
    2216           if (mountlist->entries > 0)
    2217             {
    2218               edit_mountlist_entry (mountlist, raidlist,
    2219                         partitionsListbox, currline,
    2220                         keylist);
    2221             }
    2222           else
    2223             {
    2224               popup_and_OK
    2225             ("Please add an entry. Then press ENTER to edit it.");
    2226             }
    2227         }
    2228         }
    2229     }
    2230     }
    2231   newtFormDestroy (myForm);
    2232   newtPopWindow ();
    2233   newtPopHelpLine ();
    2234   if (b_res == bOK)
    2235     {
    2236       log_it("You pushed 'OK'. I shall now continue.");
    2237       return (0);
    2238     }
    2239   else
    2240     {
    2241       /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
    2242       return (1);
    2243     }
     2084                load_mountlist(mountlist, mountlist_fname);
     2085                load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     2086                redraw_mountlist(mountlist, keylist, partitionsListbox);
     2087            }
     2088        } else {
     2089            curr_choice = newtListboxGetCurrent(partitionsListbox);
     2090            for (i = 0;
     2091                 i < mountlist->entries && keylist[i] != curr_choice; i++);
     2092            if (i == mountlist->entries && mountlist->entries > 0) {
     2093                log_to_screen("I don't know what that button does!");
     2094            } else {
     2095                currline = i;
     2096                if (b_res == bAdd) {
     2097                    add_mountlist_entry(mountlist, raidlist,
     2098                                        partitionsListbox, currline,
     2099                                        keylist);
     2100                } else if (b_res == bDelete) {
     2101                    delete_mountlist_entry(mountlist, raidlist,
     2102                                           partitionsListbox, currline,
     2103                                           keylist);
     2104                } else {
     2105                    if (mountlist->entries > 0) {
     2106                        edit_mountlist_entry(mountlist, raidlist,
     2107                                             partitionsListbox, currline,
     2108                                             keylist);
     2109                    } else {
     2110                        popup_and_OK
     2111                            ("Please add an entry. Then press ENTER to edit it.");
     2112                    }
     2113                }
     2114            }
     2115        }
     2116    }
     2117    newtFormDestroy(myForm);
     2118    newtPopWindow();
     2119    newtPopHelpLine();
     2120    if (b_res == bOK) {
     2121        log_it("You pushed 'OK'. I shall now continue.");
     2122        return (0);
     2123    } else {
     2124        /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
     2125        return (1);
     2126    }
    22442127}
    22452128
     
    22532136 */
    22542137int
    2255 edit_mountlist (char *mountlist_fname, struct mountlist_itself *mountlist,
    2256         struct raidlist_itself *raidlist)
    2257 {
    2258   int res=0;
     2138edit_mountlist(char *mountlist_fname, struct mountlist_itself *mountlist,
     2139               struct raidlist_itself *raidlist)
     2140{
     2141    int res = 0;
    22592142//  char tmp[MAX_STR_LEN];
    22602143
    2261   iamhere("entering eml");
    2262 
    2263   if (g_text_mode)
    2264     {
    2265       fatal_error("Don't call edit_mountlist() in text mode");
    2266     }
    2267   else
    2268     {
    2269       log_it("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()");
    2270       res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist);
    2271     }
    2272   iamhere("leaving eml");
    2273   return(res);
     2144    iamhere("entering eml");
     2145
     2146    if (g_text_mode) {
     2147        fatal_error("Don't call edit_mountlist() in text mode");
     2148    } else {
     2149        log_it
     2150            ("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()");
     2151        res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist);
     2152    }
     2153    iamhere("leaving eml");
     2154    return (res);
    22742155}
    22752156
     
    22832164 * @ingroup restoreGuiVarslist
    22842165 */
    2285 void
    2286 edit_raidrec_additional_vars (struct raid_device_record *raidrec)
     2166void edit_raidrec_additional_vars(struct raid_device_record *raidrec)
    22872167{
    22882168
    22892169    /** structure *********************************************************/
    2290   struct raid_device_record bkp_raidrec;
     2170    struct raid_device_record bkp_raidrec;
    22912171
    22922172    /** newt **************************************************************/
    2293   newtComponent myForm;
     2173    newtComponent myForm;
    22942174    newtComponent bAdd;
    22952175    newtComponent bEdit;
     
    23022182
    23032183    /** ?? ***************************************************************/
    2304   void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
     2184    void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
    23052185
    23062186    /** buffers **********************************************************/
    2307   char title_of_window[MAX_STR_LEN];
     2187    char title_of_window[MAX_STR_LEN];
    23082188
    23092189    /** int **************************************************************/
    2310   int i = 0;
     2190    int i = 0;
    23112191    int currline = 0;
    23122192
    23132193
    2314   assert(raidrec!=NULL);
    2315 
    2316   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    2317       sizeof (struct raid_device_record));
    2318   sprintf (title_of_window, "Additional variables");
    2319   newtPushHelpLine
    2320     ("  Edit the additional fields to your heart's content, then click OK or Cancel.");
    2321   headerMsg = newtLabel (1, 1, "Label                            Value");
    2322   varsListbox =
    2323     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2324   i = 1;
    2325   bAdd = newtCompactButton (i, 9, " Add ");
    2326   bEdit = newtCompactButton (i += 8, 9, " Edit ");
    2327   bDelete = newtCompactButton (i += 9, 9, "Delete");
    2328   bOK = newtCompactButton (i += 9, 9, "  OK  ");
    2329   bCancel = newtCompactButton (i += 9, 9, "Cancel");
    2330   newtOpenWindow (17, 7, 46, 10, title_of_window);
    2331   myForm = newtForm (NULL, NULL, 0);
    2332   newtFormAddComponents (myForm, headerMsg, varsListbox, bAdd, bEdit, bDelete,
    2333              bOK, bCancel, NULL);
    2334   insert_essential_additionalvars (raidrec);
    2335   redraw_varslist (&raidrec->additional_vars, keylist, varsListbox);
    2336   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    2337     {
    2338       b_res = newtRunForm (myForm);
    2339       curr_choice = newtListboxGetCurrent (varsListbox);
    2340       for (currline = 0;
    2341        currline < raidrec->additional_vars.entries
    2342        && keylist[currline] != curr_choice; currline++);
    2343       if (currline == raidrec->additional_vars.entries
    2344       && raidrec->additional_vars.entries > 0)
    2345     {
    2346       log_it ("Warning - I don't know what this button does");
    2347     }
    2348       if (b_res == bOK)
    2349     {           /* do nothing */
    2350     }
    2351       else if (b_res == bCancel)
    2352     {           /* do nothing */
    2353     }
    2354       else if (b_res == bAdd)
    2355     {
    2356       add_varslist_entry (raidrec);
    2357     }
    2358       else if (b_res == bDelete)
    2359     {
    2360       delete_varslist_entry (raidrec, currline);
    2361     }
    2362       else
    2363     {
    2364       edit_varslist_entry (raidrec, currline);
    2365     }
    2366       redraw_varslist (&raidrec->additional_vars, keylist, varsListbox);
    2367     }
    2368   remove_essential_additionalvars (raidrec);
    2369   newtFormDestroy (myForm);
    2370   newtPopWindow ();
    2371   newtPopHelpLine ();
    2372   if (b_res == bCancel)
    2373     {
    2374       memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    2375           sizeof (struct raid_device_record));
    2376     }
    2377   return;
     2194    assert(raidrec != NULL);
     2195
     2196    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     2197           sizeof(struct raid_device_record));
     2198    sprintf(title_of_window, "Additional variables");
     2199    newtPushHelpLine
     2200        ("  Edit the additional fields to your heart's content, then click OK or Cancel.");
     2201    headerMsg = newtLabel(1, 1, "Label                            Value");
     2202    varsListbox =
     2203        newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2204    i = 1;
     2205    bAdd = newtCompactButton(i, 9, " Add ");
     2206    bEdit = newtCompactButton(i += 8, 9, " Edit ");
     2207    bDelete = newtCompactButton(i += 9, 9, "Delete");
     2208    bOK = newtCompactButton(i += 9, 9, "  OK  ");
     2209    bCancel = newtCompactButton(i += 9, 9, "Cancel");
     2210    newtOpenWindow(17, 7, 46, 10, title_of_window);
     2211    myForm = newtForm(NULL, NULL, 0);
     2212    newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit,
     2213                          bDelete, bOK, bCancel, NULL);
     2214    insert_essential_additionalvars(raidrec);
     2215    redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
     2216    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     2217        b_res = newtRunForm(myForm);
     2218        curr_choice = newtListboxGetCurrent(varsListbox);
     2219        for (currline = 0;
     2220             currline < raidrec->additional_vars.entries
     2221             && keylist[currline] != curr_choice; currline++);
     2222        if (currline == raidrec->additional_vars.entries
     2223            && raidrec->additional_vars.entries > 0) {
     2224            log_it("Warning - I don't know what this button does");
     2225        }
     2226        if (b_res == bOK) {     /* do nothing */
     2227        } else if (b_res == bCancel) {  /* do nothing */
     2228        } else if (b_res == bAdd) {
     2229            add_varslist_entry(raidrec);
     2230        } else if (b_res == bDelete) {
     2231            delete_varslist_entry(raidrec, currline);
     2232        } else {
     2233            edit_varslist_entry(raidrec, currline);
     2234        }
     2235        redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
     2236    }
     2237    remove_essential_additionalvars(raidrec);
     2238    newtFormDestroy(myForm);
     2239    newtPopWindow();
     2240    newtPopHelpLine();
     2241    if (b_res == bCancel) {
     2242        memcpy((void *) raidrec, (void *) &bkp_raidrec,
     2243               sizeof(struct raid_device_record));
     2244    }
     2245    return;
    23782246}
    23792247#endif
     
    23862254 * @ingroup restoreGuiDisklist
    23872255 */
    2388 int
    2389 find_next_free_index_in_disklist (struct list_of_disks *disklist)
     2256int find_next_free_index_in_disklist(struct list_of_disks *disklist)
    23902257{
    23912258
    23922259    /** int ***************************************************************/
    2393   int index = -1;
     2260    int index = -1;
    23942261    int pos = 0;
    2395    
     2262
    23962263  /** bool **************************************************************/
    2397   bool done;
    2398 
    2399   assert(disklist!=NULL);
    2400 
    2401   for (done = FALSE; !done;)
    2402     {
    2403       for (pos = 0;
    2404        pos < disklist->entries && disklist->el[pos].index <= index;
    2405        pos++);
    2406       if (pos >= disklist->entries)
    2407     {
    2408       done = TRUE;
    2409     }
    2410       else
    2411     {
    2412       index = disklist->el[pos].index;
    2413     }
    2414     }
    2415   return (index + 1);
     2264    bool done;
     2265
     2266    assert(disklist != NULL);
     2267
     2268    for (done = FALSE; !done;) {
     2269        for (pos = 0;
     2270             pos < disklist->entries && disklist->el[pos].index <= index;
     2271             pos++);
     2272        if (pos >= disklist->entries) {
     2273            done = TRUE;
     2274        } else {
     2275            index = disklist->el[pos].index;
     2276        }
     2277    }
     2278    return (index + 1);
    24162279}
    24172280
     
    24262289 */
    24272290int
    2428 find_raid_device_in_raidlist (struct raidlist_itself *raidlist, char *device)
     2291find_raid_device_in_raidlist(struct raidlist_itself *raidlist,
     2292                             char *device)
    24292293{
    24302294
    24312295    /** int ***************************************************************/
    2432   int i = 0;
     2296    int i = 0;
    24332297#ifdef __FreeBSD__
    2434   char vdev [64];
     2298    char vdev[64];
    24352299#else
    24362300// Linux
    24372301#endif
    2438  
    2439   assert(raidlist!=NULL);
    2440   assert_string_is_neither_NULL_nor_zerolength(device);
     2302
     2303    assert(raidlist != NULL);
     2304    assert_string_is_neither_NULL_nor_zerolength(device);
    24412305
    24422306#ifdef __FreeBSD__
    2443   for (i = 0; i < raidlist->entries; i++) {
    2444       sprintf (vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    2445       if (!strcmp (device, vdev)) break;
    2446   }
     2307    for (i = 0; i < raidlist->entries; i++) {
     2308        sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2309        if (!strcmp(device, vdev))
     2310            break;
     2311    }
    24472312#else
    24482313
    2449   for (i = 0;
    2450        strcmp (raidlist->el[i].raid_device, device) && i < raidlist->entries;
    2451       i++);
     2314    for (i = 0;
     2315         strcmp(raidlist->el[i].raid_device, device)
     2316         && i < raidlist->entries; i++);
    24522317#endif
    2453   if (i == raidlist->entries)
    2454     {
    2455       return (-1);
    2456     }
    2457   else
    2458     {
    2459       return (i);
    2460     }
     2318    if (i == raidlist->entries) {
     2319        return (-1);
     2320    } else {
     2321        return (i);
     2322    }
    24612323}
    24622324
     
    24712333 */
    24722334bool
    2473 get_isodir_info (char *isodir_device, char *isodir_format, char *isodir_path, bool nuke_me_please)
     2335get_isodir_info(char *isodir_device, char *isodir_format,
     2336                char *isodir_path, bool nuke_me_please)
    24742337{
    24752338
    24762339    /** initialize ********************************************************/
    24772340
    2478   assert(isodir_device!=NULL);
    2479   assert(isodir_format!=NULL);
    2480   assert(isodir_path!=NULL);
    2481 
    2482   log_it("%d - AAA - isodir_path = %s", isodir_path);
    2483   isodir_format[0] = '\0';
    2484   if (isodir_device[0]=='\0') { strcpy (isodir_device, "/dev/"); }
    2485   if (isodir_path[0]=='\0') { strcpy (isodir_path, "/"); }
    2486   if (does_file_exist ("/tmp/NFS-SERVER-PATH"))
    2487     {
    2488       strcpy (isodir_device, last_line_of_file ("/tmp/NFS-SERVER-MOUNT"));
    2489       strcpy (isodir_format, "nfs");
    2490       strcpy (isodir_path, last_line_of_file ("/tmp/NFS-SERVER-PATH"));
    2491     }
    2492   if (nuke_me_please) { return(TRUE); }
    2493 
    2494   if (popup_and_get_string
    2495       ("ISO Mode - device", "On what device do the ISO files live?",
    2496        isodir_device, MAX_STR_LEN/4))
    2497     {
    2498       if (popup_and_get_string
    2499       ("ISO Mode - format",
    2500        "What is the disk format of the device? (Hit ENTER if you don't know.)",
    2501        isodir_format, 16))
    2502     {
    2503       if (popup_and_get_string
    2504           ("ISO Mode - path",
    2505            "At what path on this device can the ISO files be found?",
    2506            isodir_path, MAX_STR_LEN/4))
    2507         {
    2508           strip_spaces (isodir_device);
    2509           strip_spaces (isodir_format);
    2510           strip_spaces (isodir_path);
    2511   log_it("%d - BBB - isodir_path = %s", isodir_path);
    2512           return (TRUE);
    2513         }
    2514     }
    2515     }
    2516   return (FALSE);
     2341    assert(isodir_device != NULL);
     2342    assert(isodir_format != NULL);
     2343    assert(isodir_path != NULL);
     2344
     2345    log_it("%d - AAA - isodir_path = %s", isodir_path);
     2346    isodir_format[0] = '\0';
     2347    if (isodir_device[0] == '\0') {
     2348        strcpy(isodir_device, "/dev/");
     2349    }
     2350    if (isodir_path[0] == '\0') {
     2351        strcpy(isodir_path, "/");
     2352    }
     2353    if (does_file_exist("/tmp/NFS-SERVER-PATH")) {
     2354        strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT"));
     2355        strcpy(isodir_format, "nfs");
     2356        strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH"));
     2357    }
     2358    if (nuke_me_please) {
     2359        return (TRUE);
     2360    }
     2361
     2362    if (popup_and_get_string
     2363        ("ISO Mode - device", "On what device do the ISO files live?",
     2364         isodir_device, MAX_STR_LEN / 4)) {
     2365        if (popup_and_get_string
     2366            ("ISO Mode - format",
     2367             "What is the disk format of the device? (Hit ENTER if you don't know.)",
     2368             isodir_format, 16)) {
     2369            if (popup_and_get_string
     2370                ("ISO Mode - path",
     2371                 "At what path on this device can the ISO files be found?",
     2372                 isodir_path, MAX_STR_LEN / 4)) {
     2373                strip_spaces(isodir_device);
     2374                strip_spaces(isodir_format);
     2375                strip_spaces(isodir_path);
     2376                log_it("%d - BBB - isodir_path = %s", isodir_path);
     2377                return (TRUE);
     2378            }
     2379        }
     2380    }
     2381    return (FALSE);
    25172382}
    25182383
     
    25272392 */
    25282393void
    2529 initiate_new_raidlist_entry (struct raidlist_itself *raidlist,
    2530                  struct mountlist_itself *mountlist, int currline,
    2531                 char *device)
     2394initiate_new_raidlist_entry(struct raidlist_itself *raidlist,
     2395                            struct mountlist_itself *mountlist,
     2396                            int currline, char *device)
    25322397{
    25332398
    25342399    /** structure *********************************************************/
    2535   struct OSSWAP (raid_device_record, vinum_volume) *raidrec;
     2400    struct OSSWAP (raid_device_record, vinum_volume) * raidrec;
    25362401
    25372402    /** int ***************************************************************/
    2538   int pos_in_raidlist = 0;
    2539 
    2540   assert(raidlist!=NULL);
    2541   assert(mountlist!=NULL);
    2542   assert_string_is_neither_NULL_nor_zerolength(device);
    2543 
    2544   pos_in_raidlist =
    2545     find_raid_device_in_raidlist (raidlist, mountlist->el[currline].device);
    2546   if (pos_in_raidlist >= 0)
    2547     {
    2548       fatal_error ("Sorry, that RAID device already exists. Weird.");
    2549     }
    2550   pos_in_raidlist = raidlist->entries++;
    2551   raidrec = &raidlist->el[pos_in_raidlist];
    2552   initialize_raidrec (raidrec);
    2553   strcpy (raidrec->OSSWAP (raid_device, volname), OSSWAP (device, basename (device)));
     2403    int pos_in_raidlist = 0;
     2404
     2405    assert(raidlist != NULL);
     2406    assert(mountlist != NULL);
     2407    assert_string_is_neither_NULL_nor_zerolength(device);
     2408
     2409    pos_in_raidlist =
     2410        find_raid_device_in_raidlist(raidlist,
     2411                                     mountlist->el[currline].device);
     2412    if (pos_in_raidlist >= 0) {
     2413        fatal_error("Sorry, that RAID device already exists. Weird.");
     2414    }
     2415    pos_in_raidlist = raidlist->entries++;
     2416    raidrec = &raidlist->el[pos_in_raidlist];
     2417    initialize_raidrec(raidrec);
     2418    strcpy(raidrec->OSSWAP(raid_device, volname),
     2419           OSSWAP(device, basename(device)));
    25542420#ifndef __FreeBSD__
    2555   choose_raid_level (raidrec);
    2556   select_raid_disks (mountlist, raidlist, raidrec, "data",
    2557              &raidrec->data_disks);
     2421    choose_raid_level(raidrec);
     2422    select_raid_disks(mountlist, raidlist, raidrec, "data",
     2423                      &raidrec->data_disks);
    25582424#endif
    2559   edit_raidlist_entry (mountlist, raidlist, raidrec, currline);
     2425    edit_raidlist_entry(mountlist, raidlist, raidrec, currline);
    25602426}
    25612427
     
    25672433 * @ingroup restoreGuiVarslist
    25682434 */
    2569 void
    2570 insert_essential_additionalvars (struct raid_device_record *raidrec)
     2435void insert_essential_additionalvars(struct raid_device_record *raidrec)
    25712436{
    25722437
    25732438    /** int **************************************************************/
    2574   int items = 0;
    2575 
    2576   assert(raidrec!=NULL);
    2577 
    2578   items = raidrec->additional_vars.entries;
    2579   write_variableINT_to_raid_var_line (raidrec, items++,
    2580                       "persistent-superblock",
    2581                       raidrec->persistent_superblock);
    2582   write_variableINT_to_raid_var_line (raidrec, items++, "chunk-size",
    2583                       raidrec->chunk_size);
    2584   raidrec->additional_vars.entries = items;
     2439    int items = 0;
     2440
     2441    assert(raidrec != NULL);
     2442
     2443    items = raidrec->additional_vars.entries;
     2444    write_variableINT_to_raid_var_line(raidrec, items++,
     2445                                       "persistent-superblock",
     2446                                       raidrec->persistent_superblock);
     2447    write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size",
     2448                                       raidrec->chunk_size);
     2449    raidrec->additional_vars.entries = items;
    25852450}
    25862451
     
    25902455 * Dummy function that proves that we can get to the point where Mondo is run.
    25912456 */
    2592 void
    2593 nuke_mode_dummy ()
     2457void nuke_mode_dummy()
    25942458{
    25952459
    25962460    /** newt *************************************************************/
    2597   newtComponent myForm;
     2461    newtComponent myForm;
    25982462    newtComponent b1;
    25992463    newtComponent b2;
     
    26022466
    26032467
    2604   newtPushHelpLine
    2605     ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!");
    2606   newtOpenWindow (24, 3, 32, 13, "Nuking");
    2607   b1 = newtButton (7, 1, "Slowly");
    2608   b2 = newtButton (7, 5, "Medium");
    2609   b3 = newtButton (7, 9, "Quickly");
    2610   myForm = newtForm (NULL, NULL, 0);
    2611   newtFormAddComponents (myForm, b1, b2, b3, NULL);
    2612   b_res = newtRunForm (myForm);
    2613   newtFormDestroy (myForm);
    2614   newtPopWindow ();
    2615   newtPopHelpLine ();
     2468    newtPushHelpLine
     2469        ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!");
     2470    newtOpenWindow(24, 3, 32, 13, "Nuking");
     2471    b1 = newtButton(7, 1, "Slowly");
     2472    b2 = newtButton(7, 5, "Medium");
     2473    b3 = newtButton(7, 9, "Quickly");
     2474    myForm = newtForm(NULL, NULL, 0);
     2475    newtFormAddComponents(myForm, b1, b2, b3, NULL);
     2476    b_res = newtRunForm(myForm);
     2477    newtFormDestroy(myForm);
     2478    newtPopWindow();
     2479    newtPopHelpLine();
    26162480}
    26172481
     
    26262490 */
    26272491void
    2628 redraw_disklist (struct list_of_disks *disklist,
    2629          void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
     2492redraw_disklist(struct list_of_disks *disklist,
     2493                void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
    26302494{
    26312495
    26322496    /** int *************************************************************/
    2633   int i = 0;
    2634 
    2635   assert(disklist!=NULL);
    2636   assert(keylist!=NULL);
    2637   assert(listbox!=NULL);
    2638 
    2639   newtListboxClear (listbox);
    2640 
    2641   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2642     {
    2643       keylist[i] = (void *) i;
    2644     }
    2645   for (i = 0; i < disklist->entries; i++)
    2646     {
    2647       newtListboxAppendEntry (listbox, disklist_entry_to_string (disklist, i),
    2648                   keylist[i]);
    2649     }
     2497    int i = 0;
     2498
     2499    assert(disklist != NULL);
     2500    assert(keylist != NULL);
     2501    assert(listbox != NULL);
     2502
     2503    newtListboxClear(listbox);
     2504
     2505    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2506        keylist[i] = (void *) i;
     2507    }
     2508    for (i = 0; i < disklist->entries; i++) {
     2509        newtListboxAppendEntry(listbox,
     2510                               disklist_entry_to_string(disklist, i),
     2511                               keylist[i]);
     2512    }
    26502513}
    26512514
     
    26592522 */
    26602523void
    2661 redraw_mountlist (struct mountlist_itself *mountlist,
    2662           void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
    2663 {
    2664    
     2524redraw_mountlist(struct mountlist_itself *mountlist,
     2525                void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
     2526{
     2527
    26652528    /** int **************************************************************/
    2666   int i = 0;
    2667 
    2668   assert(mountlist!=NULL);
    2669   assert(keylist!=NULL);
    2670   assert(listbox!=NULL);
    2671 
    2672   newtListboxClear (listbox);
     2529    int i = 0;
     2530
     2531    assert(mountlist != NULL);
     2532    assert(keylist != NULL);
     2533    assert(listbox != NULL);
     2534
     2535    newtListboxClear(listbox);
    26732536//  sort_mountlist_by_device (mountlist);
    2674   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2675     {
    2676       keylist[i] = (void *) i;
    2677     }
    2678   for (i = 0; i < mountlist->entries; i++)
    2679     {
    2680       newtListboxAppendEntry (listbox,
    2681                   mountlist_entry_to_string (mountlist, i),
    2682                   keylist[i]);
    2683     }
     2537    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2538        keylist[i] = (void *) i;
     2539    }
     2540    for (i = 0; i < mountlist->entries; i++) {
     2541        newtListboxAppendEntry(listbox,
     2542                               mountlist_entry_to_string(mountlist, i),
     2543                               keylist[i]);
     2544    }
    26842545}
    26852546
     
    26942555 * @ingroup restoreGuiDisklist
    26952556 */
    2696 void
    2697 redraw_unallocpartnslist (struct mountlist_itself
    2698               *unallocated_raid_partitions,
    2699               void *keylist[ARBITRARY_MAXIMUM],
    2700               newtComponent listbox)
     2557void redraw_unallocpartnslist(struct mountlist_itself
     2558                              *unallocated_raid_partitions,
     2559                              void *keylist[ARBITRARY_MAXIMUM],
     2560                              newtComponent listbox)
    27012561{
    27022562
    27032563    /** int **************************************************************/
    2704   int i = 0;
     2564    int i = 0;
    27052565
    27062566    /** buffers **********************************************************/
    2707   char tmp[MAX_STR_LEN];
    2708 
    2709   assert(unallocated_raid_partitions!=NULL);
    2710   assert(keylist!=NULL);
    2711   assert(listbox!=NULL);
    2712 
    2713   newtListboxClear (listbox);
    2714   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2715     {
    2716       keylist[i] = (void *) i;
    2717     }
    2718   for (i = 0; i < unallocated_raid_partitions->entries; i++)
    2719     {
    2720       sprintf (tmp, "%-22s %8lld", unallocated_raid_partitions->el[i].device,
    2721            unallocated_raid_partitions->el[i].size / 1024);
    2722       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    2723     }
     2567    char tmp[MAX_STR_LEN];
     2568
     2569    assert(unallocated_raid_partitions != NULL);
     2570    assert(keylist != NULL);
     2571    assert(listbox != NULL);
     2572
     2573    newtListboxClear(listbox);
     2574    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2575        keylist[i] = (void *) i;
     2576    }
     2577    for (i = 0; i < unallocated_raid_partitions->entries; i++) {
     2578        sprintf(tmp, "%-22s %8lld",
     2579                unallocated_raid_partitions->el[i].device,
     2580                unallocated_raid_partitions->el[i].size / 1024);
     2581        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2582    }
    27242583}
    27252584
     
    27332592 */
    27342593void
    2735 redraw_varslist (struct additional_raid_variables *additional_vars,
    2736          void *keylist[], newtComponent listbox)
     2594redraw_varslist(struct additional_raid_variables *additional_vars,
     2595                void *keylist[], newtComponent listbox)
    27372596{
    27382597    /** int *************************************************************/
    2739   int i = 0;
     2598    int i = 0;
    27402599
    27412600    /** buffers *********************************************************/
    2742   char tmp[MAX_STR_LEN];
    2743 
    2744   assert(additional_vars!=NULL);
    2745   assert(keylist!=NULL);
    2746   assert(listbox!=NULL);
    2747 
    2748   newtListboxClear (listbox);
    2749 
    2750   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2751     {
    2752       keylist[i] = (void *) i;
    2753     }
    2754   for (i = 0; i < additional_vars->entries; i++)
    2755     {
    2756       sprintf (tmp, "%-32s %-8s", additional_vars->el[i].label,
    2757            additional_vars->el[i].value);
    2758       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    2759     }
     2601    char tmp[MAX_STR_LEN];
     2602
     2603    assert(additional_vars != NULL);
     2604    assert(keylist != NULL);
     2605    assert(listbox != NULL);
     2606
     2607    newtListboxClear(listbox);
     2608
     2609    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2610        keylist[i] = (void *) i;
     2611    }
     2612    for (i = 0; i < additional_vars->entries; i++) {
     2613        sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label,
     2614                additional_vars->el[i].value);
     2615        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2616    }
    27602617}
    27612618
     
    27692626 */
    27702627int
    2771 read_variableINT_and_remove_from_raidvars (struct OSSWAP (raid_device_record, vinum_volume) *raidrec,
    2772                        char *label)
     2628read_variableINT_and_remove_from_raidvars(struct
     2629                                          OSSWAP (raid_device_record,
     2630                                                  vinum_volume) * raidrec,
     2631                                          char *label)
    27732632{
    27742633    /** int ***************************************************************/
    2775   int i = 0;
     2634    int i = 0;
    27762635    int res = 0;
    27772636
    27782637
    2779   assert(raidrec!=NULL);
    2780   assert(label!=NULL);
    2781 
    2782   for (i = 0;
    2783        i < raidrec->additional_vars.entries
    2784        && strcmp (raidrec->additional_vars.el[i].label, label); i++);
    2785   if (i == raidrec->additional_vars.entries)
    2786     {
    2787       res = -1;
    2788     }
    2789   else
    2790     {
    2791       res = atoi (raidrec->additional_vars.el[i].value);
    2792       for (i++; i < raidrec->additional_vars.entries; i++)
    2793     {
    2794       memcpy ((void *) &raidrec->additional_vars.el[i - 1],
    2795           (void *) &raidrec->additional_vars.el[i],
    2796           sizeof (struct raid_var_line));
    2797     }
    2798       raidrec->additional_vars.entries--;
    2799     }
    2800   return (res);
     2638    assert(raidrec != NULL);
     2639    assert(label != NULL);
     2640
     2641    for (i = 0;
     2642         i < raidrec->additional_vars.entries
     2643         && strcmp(raidrec->additional_vars.el[i].label, label); i++);
     2644    if (i == raidrec->additional_vars.entries) {
     2645        res = -1;
     2646    } else {
     2647        res = atoi(raidrec->additional_vars.el[i].value);
     2648        for (i++; i < raidrec->additional_vars.entries; i++) {
     2649            memcpy((void *) &raidrec->additional_vars.el[i - 1],
     2650                   (void *) &raidrec->additional_vars.el[i],
     2651                   sizeof(struct raid_var_line));
     2652        }
     2653        raidrec->additional_vars.entries--;
     2654    }
     2655    return (res);
    28012656}
    28022657#endif
     
    28092664 * @ingroup restoreGuiMountlist
    28102665 */
    2811 void
    2812 rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself
    2813                            *raidlist, char *old_dev,
    2814                            char *new_dev)
     2666void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself
     2667                                                   *raidlist,
     2668                                                  char *old_dev,
     2669                                                   char *new_dev)
    28152670{
    28162671    /** buffers ********************************************************/
    2817   char tmp[MAX_STR_LEN];
     2672    char tmp[MAX_STR_LEN];
    28182673
    28192674    /** int ************************************************************/
    2820   int pos = 0;
     2675    int pos = 0;
    28212676    int j = 0;
    28222677
    2823   assert(raidlist!=NULL);
    2824   assert_string_is_neither_NULL_nor_zerolength(old_dev);
    2825   assert_string_is_neither_NULL_nor_zerolength(new_dev);
    2826 
    2827   pos = which_raid_device_is_using_this_partition (raidlist, old_dev);
    2828   if (pos < 0)
    2829     {
    2830       sprintf (tmp, "No need to rejig %s in raidlist: it's not listed.",
    2831            old_dev);
    2832       log_it (tmp);
    2833     }
    2834   else
    2835     {
    2836       if ((j =
    2837        where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].data_disks, disks),
    2838                     old_dev)) >= 0)
    2839     {
    2840       strcpy (raidlist->OSSWAP (el[pos].data_disks, disks).el[j].device, new_dev);
    2841     }
    2842       else
    2843     if ((j =
    2844          where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].spare_disks, spares),
    2845                       old_dev)) >= 0)
    2846     {
    2847       strcpy (raidlist->OSSWAP (el[pos].spare_disks, spares).el[j].device, new_dev);
    2848     }
     2678    assert(raidlist != NULL);
     2679    assert_string_is_neither_NULL_nor_zerolength(old_dev);
     2680    assert_string_is_neither_NULL_nor_zerolength(new_dev);
     2681
     2682    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
     2683    if (pos < 0) {
     2684        sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
     2685                old_dev);
     2686        log_it(tmp);
     2687    } else {
     2688        if ((j =
     2689             where_in_drivelist_is_drive(&raidlist->
     2690                                         OSSWAP(el[pos].data_disks, disks),
     2691                                         old_dev)) >= 0) {
     2692            strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].
     2693                   device, new_dev);
     2694        } else
     2695            if ((j =
     2696                 where_in_drivelist_is_drive(&raidlist->
     2697                                             OSSWAP(el[pos].spare_disks,
     2698                                                    spares),
     2699                                             old_dev)) >= 0) {
     2700            strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].
     2701                   device, new_dev);
     2702        }
    28492703#ifndef __FreeBSD__
    2850       else
    2851     if ((j =
    2852          where_in_drivelist_is_drive (&raidlist->el[pos].parity_disks,
    2853                       old_dev)) >= 0)
    2854     {
    2855       strcpy (raidlist->el[pos].parity_disks.el[j].device, new_dev);
    2856     }
    2857       else
    2858     if ((j =
    2859          where_in_drivelist_is_drive (&raidlist->el[pos].failed_disks,
    2860                       old_dev)) >= 0)
    2861     {
    2862       strcpy (raidlist->el[pos].failed_disks.el[j].device, new_dev);
    2863     }
     2704        else if ((j =
     2705                  where_in_drivelist_is_drive(&raidlist->el[pos].
     2706                                              parity_disks,
     2707                                              old_dev)) >= 0) {
     2708            strcpy(raidlist->el[pos].parity_disks.el[j].device, new_dev);
     2709        } else
     2710            if ((j =
     2711                 where_in_drivelist_is_drive(&raidlist->el[pos].
     2712                                             failed_disks,
     2713                                             old_dev)) >= 0) {
     2714            strcpy(raidlist->el[pos].failed_disks.el[j].device, new_dev);
     2715        }
    28642716#endif
    2865       else
    2866     {
    2867       sprintf (tmp,
    2868            "%s is supposed to be listed in this raid dev but it's not...",
    2869            old_dev);
    2870       log_it (tmp);
    2871     }
    2872     }
     2717        else {
     2718            sprintf(tmp,
     2719                    "%s is supposed to be listed in this raid dev but it's not...",
     2720                    old_dev);
     2721            log_it(tmp);
     2722        }
     2723    }
    28732724}
    28742725
     
    28812732 * @ingroup restoreUtilityVarslist
    28822733 */
    2883 void
    2884 remove_essential_additionalvars (struct raid_device_record *raidrec)
     2734void remove_essential_additionalvars(struct raid_device_record *raidrec)
    28852735{
    28862736
    28872737    /** int **************************************************************/
    2888   int res = 0;
    2889 
    2890   assert(raidrec!=NULL);
    2891 
    2892 res =
    2893     read_variableINT_and_remove_from_raidvars (raidrec,
    2894                            "persistent-superblock");
    2895   if (res > 0)
    2896     {
    2897       raidrec->persistent_superblock = res;
    2898     }
    2899   res = read_variableINT_and_remove_from_raidvars (raidrec, "chunk-size");
    2900   if (res > 0)
    2901     {
    2902       raidrec->chunk_size = res;
    2903     }
    2904   res = read_variableINT_and_remove_from_raidvars (raidrec, "block-size");
     2738    int res = 0;
     2739
     2740    assert(raidrec != NULL);
     2741
     2742    res =
     2743        read_variableINT_and_remove_from_raidvars(raidrec,
     2744                                                  "persistent-superblock");
     2745    if (res > 0) {
     2746        raidrec->persistent_superblock = res;
     2747    }
     2748    res = read_variableINT_and_remove_from_raidvars(raidrec, "chunk-size");
     2749    if (res > 0) {
     2750        raidrec->chunk_size = res;
     2751    }
     2752    res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size");
    29052753}
    29062754
     
    29152763 */
    29162764void
    2917 select_raid_disks (struct mountlist_itself *mountlist_dontedit,
    2918            struct raidlist_itself *raidlist,
    2919            struct raid_device_record *raidrec,
    2920            char *description_of_list, struct list_of_disks *disklist)
    2921 {
    2922   void *curr_choice;
     2765select_raid_disks(struct mountlist_itself *mountlist_dontedit,
     2766                  struct raidlist_itself *raidlist,
     2767                  struct raid_device_record *raidrec,
     2768                  char *description_of_list,
     2769                  struct list_of_disks *disklist)
     2770{
     2771    void *curr_choice;
    29232772
    29242773    /** ??? ***************************************************************/
    29252774
    29262775    /** structures ********************************************************/
    2927   struct raidlist_itself *bkp_raidlist;
    2928   struct raid_device_record *bkp_raidrec;
    2929   struct list_of_disks *bkp_disklist;
    2930   struct mountlist_itself *unallocated_raid_partitions;
     2776    struct raidlist_itself *bkp_raidlist;
     2777    struct raid_device_record *bkp_raidrec;
     2778    struct list_of_disks *bkp_disklist;
     2779    struct mountlist_itself *unallocated_raid_partitions;
    29312780
    29322781    /** newt **************************************************************/
    2933   newtComponent myForm=NULL;
    2934   newtComponent bAdd=NULL;
    2935     newtComponent bDelete=NULL;
    2936     newtComponent bOK=NULL;
    2937     newtComponent bCancel=NULL;
    2938     newtComponent b_res=NULL;
    2939     newtComponent partitionsListbox=NULL;
    2940     newtComponent headerMsg=NULL;
     2782    newtComponent myForm = NULL;
     2783    newtComponent bAdd = NULL;
     2784    newtComponent bDelete = NULL;
     2785    newtComponent bOK = NULL;
     2786    newtComponent bCancel = NULL;
     2787    newtComponent b_res = NULL;
     2788    newtComponent partitionsListbox = NULL;
     2789    newtComponent headerMsg = NULL;
    29412790
    29422791    /** buffers **********************************************************/
    2943   void *keylist[ARBITRARY_MAXIMUM];
    2944   char *tmp;
    2945   char *help_text;
    2946   char *title_of_window;
    2947   char *sz_res;
    2948   char *header_text;
     2792    void *keylist[ARBITRARY_MAXIMUM];
     2793    char *tmp;
     2794    char *help_text;
     2795    char *title_of_window;
     2796    char *sz_res;
     2797    char *header_text;
    29492798
    29502799  /** int **************************************************************/
    2951   int i = 0;
    2952   int currline = 0;
    2953 
    2954   assert(mountlist_dontedit!=NULL);
    2955   assert(raidlist!=NULL);
    2956   assert(raidrec!=NULL);
    2957   assert(description_of_list!=NULL);
    2958   assert(disklist!=NULL);
    2959 
    2960   iamhere("malloc'ing");
    2961   malloc_string(tmp);
    2962   malloc_string(help_text);
    2963   malloc_string(title_of_window);
    2964   malloc_string(sz_res);
    2965   malloc_string(header_text);
    2966   if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record))))
    2967     { fatal_error("Cannot malloc space for raidrec"); }
    2968   if (!(bkp_disklist = malloc(sizeof(struct list_of_disks))))
    2969     { fatal_error("Cannot malloc space for disklist"); }
    2970   if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself))))
    2971     { fatal_error("Cannot malloc space for raidlist"); }
    2972   if (!(unallocated_raid_partitions = malloc(sizeof(struct mountlist_itself))))
    2973     { fatal_error("Cannot malloc space for unallocated_raid_partitions"); }
    2974 
    2975   memcpy ((void *) bkp_raidlist, (void *) raidlist,
    2976       sizeof (struct raidlist_itself));
    2977   memcpy ((void *) bkp_raidrec, (void *) raidrec,
    2978       sizeof (struct raid_device_record));
    2979   memcpy ((void *) bkp_disklist, (void *) disklist,
    2980       sizeof (struct list_of_disks));
    2981 
    2982   iamhere("Post-malloc");
    2983   strcpy (help_text,
    2984       "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
    2985   sprintf (header_text, "%-24s    %s", "Device", "Index");
    2986   sprintf (title_of_window, "%s contains...", raidrec->raid_device);
    2987   newtPushHelpLine (help_text);
    2988   for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;)
    2989     {
    2990       headerMsg = newtLabel (1, 1, header_text);
    2991       partitionsListbox =
    2992     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2993       redraw_disklist (disklist, keylist, partitionsListbox);
    2994       i = 1;
    2995       bAdd = newtCompactButton (i, 9, " Add ");
    2996       bDelete = newtCompactButton (i += 8, 9, "Delete");
    2997       bOK = newtCompactButton (i += 9, 9, "  OK  ");
    2998       bCancel = newtCompactButton (i += 9, 9, "Cancel");
    2999       newtOpenWindow (21, 7, 38, 10, title_of_window);
    3000       myForm = newtForm (NULL, NULL, 0);
    3001       if (disklist->entries == 0)
    3002     {
    3003       newtFormAddComponents (myForm, headerMsg, bAdd, bDelete, bOK,
    3004                  bCancel, NULL);
    3005     }
    3006       else
    3007     {
    3008       newtFormAddComponents (myForm, headerMsg, partitionsListbox, bAdd,
    3009                  bDelete, bOK, bCancel, NULL);
    3010     }
    3011       b_res = newtRunForm (myForm);
    3012       if (b_res == bOK || b_res == bCancel)
    3013     {           /* do nothing */
     2800    int i = 0;
     2801    int currline = 0;
     2802
     2803    assert(mountlist_dontedit != NULL);
     2804    assert(raidlist != NULL);
     2805    assert(raidrec != NULL);
     2806    assert(description_of_list != NULL);
     2807    assert(disklist != NULL);
     2808
     2809    iamhere("malloc'ing");
     2810    malloc_string(tmp);
     2811    malloc_string(help_text);
     2812    malloc_string(title_of_window);
     2813    malloc_string(sz_res);
     2814    malloc_string(header_text);
     2815    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
     2816        fatal_error("Cannot malloc space for raidrec");
     2817    }
     2818    if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) {
     2819        fatal_error("Cannot malloc space for disklist");
     2820    }
     2821    if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) {
     2822        fatal_error("Cannot malloc space for raidlist");
     2823    }
     2824    if (!
     2825        (unallocated_raid_partitions =
     2826         malloc(sizeof(struct mountlist_itself)))) {
     2827        fatal_error("Cannot malloc space for unallocated_raid_partitions");
     2828    }
     2829
     2830    memcpy((void *) bkp_raidlist, (void *) raidlist,
     2831           sizeof(struct raidlist_itself));
     2832    memcpy((void *) bkp_raidrec, (void *) raidrec,
     2833           sizeof(struct raid_device_record));
     2834    memcpy((void *) bkp_disklist, (void *) disklist,
     2835           sizeof(struct list_of_disks));
     2836
     2837    iamhere("Post-malloc");
     2838    strcpy(help_text,
     2839           "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
     2840    sprintf(header_text, "%-24s    %s", "Device", "Index");
     2841    sprintf(title_of_window, "%s contains...", raidrec->raid_device);
     2842    newtPushHelpLine(help_text);
     2843    for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) {
     2844        headerMsg = newtLabel(1, 1, header_text);
     2845        partitionsListbox =
     2846            newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2847        redraw_disklist(disklist, keylist, partitionsListbox);
     2848        i = 1;
     2849        bAdd = newtCompactButton(i, 9, " Add ");
     2850        bDelete = newtCompactButton(i += 8, 9, "Delete");
     2851        bOK = newtCompactButton(i += 9, 9, "  OK  ");
     2852        bCancel = newtCompactButton(i += 9, 9, "Cancel");
     2853        newtOpenWindow(21, 7, 38, 10, title_of_window);
     2854        myForm = newtForm(NULL, NULL, 0);
     2855        if (disklist->entries == 0) {
     2856            newtFormAddComponents(myForm, headerMsg, bAdd, bDelete, bOK,
     2857                                  bCancel, NULL);
     2858        } else {
     2859            newtFormAddComponents(myForm, headerMsg, partitionsListbox,
     2860                                  bAdd, bDelete, bOK, bCancel, NULL);
     2861        }
     2862        b_res = newtRunForm(myForm);
     2863        if (b_res == bOK || b_res == bCancel) { /* do nothing */
    30142864// That's OK. At the end of this subroutine (after this do/while loop),
    30152865// we'll throw away the changes if Cancel was pushed.
    3016     }
    3017       else
    3018     {
    3019       curr_choice = newtListboxGetCurrent (partitionsListbox);
    3020       for (i = 0; i < disklist->entries && keylist[i] != curr_choice;
    3021            i++);
    3022       if (i == disklist->entries && disklist->entries > 0)
    3023         {
    3024           log_to_screen ("I don't know what that button does!");
    3025         }
    3026       else
    3027         {
    3028           currline = i;
    3029           if (b_res == bAdd)
    3030         {
    3031           log_it ("Making list of unallocated RAID slices");
    3032           make_list_of_unallocated_raid_partitions
    3033             (unallocated_raid_partitions, mountlist_dontedit,
    3034              raidlist);
    3035           if (unallocated_raid_partitions->entries <= 0)
    3036             {
    3037               popup_and_OK
    3038             ("There are no unallocated partitions marked for RAID.");
    3039             }
    3040           else
    3041             {
    3042               log_it
    3043             ("Done. The user may add one or more of the above to RAID device");
    3044               add_disklist_entry (disklist, raidrec->raid_device,
    3045                       unallocated_raid_partitions);
    3046               log_it ("I have finished adding a disklist entry.");
    3047               redraw_disklist (disklist, keylist, partitionsListbox);
    3048             }
    3049         }
    3050           else if (b_res == bDelete)
    3051         {
    3052           delete_disklist_entry (disklist, raidrec->raid_device,
    3053                      currline);
    3054           redraw_disklist (disklist, keylist, partitionsListbox);
    3055         }
    3056           else
    3057         {
    3058           sprintf (tmp, "%s's index is %d. What should it be?",
    3059                raidrec->raid_device,
    3060                disklist->el[currline].index);
    3061           sprintf (sz_res, "%d", disklist->el[currline].index);
    3062           if (popup_and_get_string ("Set index", tmp, sz_res, 10))
    3063             {
    3064               disklist->el[currline].index = atoi (sz_res);
    3065             }
    3066           redraw_disklist (disklist, keylist, partitionsListbox);
    3067         }
    3068         }
    3069     }
    3070       newtFormDestroy (myForm);
    3071       newtPopWindow ();
    3072     }
    3073   newtPopHelpLine ();
    3074   if (b_res == bCancel)
    3075     {
    3076       memcpy ((void *) raidlist, (void *) bkp_raidlist,
    3077           sizeof (struct raidlist_itself));
    3078       memcpy ((void *) raidrec, (void *) bkp_raidrec,
    3079           sizeof (struct raid_device_record));
    3080       memcpy ((void *) disklist, (void *) bkp_disklist,
    3081           sizeof (struct list_of_disks));
    3082     }
    3083   paranoid_free(tmp);
    3084   paranoid_free(help_text);
    3085   paranoid_free(title_of_window);
    3086   paranoid_free(sz_res);
    3087   paranoid_free(header_text);
    3088   paranoid_free(bkp_raidrec);
    3089   paranoid_free(bkp_disklist);
    3090   paranoid_free(bkp_raidlist);
    3091   paranoid_free(unallocated_raid_partitions);
     2866        } else {
     2867            curr_choice = newtListboxGetCurrent(partitionsListbox);
     2868            for (i = 0; i < disklist->entries && keylist[i] != curr_choice;
     2869                 i++);
     2870            if (i == disklist->entries && disklist->entries > 0) {
     2871                log_to_screen("I don't know what that button does!");
     2872            } else {
     2873                currline = i;
     2874                if (b_res == bAdd) {
     2875                    log_it("Making list of unallocated RAID slices");
     2876                    make_list_of_unallocated_raid_partitions
     2877                        (unallocated_raid_partitions, mountlist_dontedit,
     2878                         raidlist);
     2879                    if (unallocated_raid_partitions->entries <= 0) {
     2880                        popup_and_OK
     2881                            ("There are no unallocated partitions marked for RAID.");
     2882                    } else {
     2883                        log_it
     2884                            ("Done. The user may add one or more of the above to RAID device");
     2885                        add_disklist_entry(disklist, raidrec->raid_device,
     2886                                           unallocated_raid_partitions);
     2887                        log_it("I have finished adding a disklist entry.");
     2888                        redraw_disklist(disklist, keylist,
     2889                                        partitionsListbox);
     2890                    }
     2891                } else if (b_res == bDelete) {
     2892                    delete_disklist_entry(disklist, raidrec->raid_device,
     2893                                          currline);
     2894                    redraw_disklist(disklist, keylist, partitionsListbox);
     2895                } else {
     2896                    sprintf(tmp, "%s's index is %d. What should it be?",
     2897                            raidrec->raid_device,
     2898                            disklist->el[currline].index);
     2899                    sprintf(sz_res, "%d", disklist->el[currline].index);
     2900                    if (popup_and_get_string("Set index", tmp, sz_res, 10)) {
     2901                        disklist->el[currline].index = atoi(sz_res);
     2902                    }
     2903                    redraw_disklist(disklist, keylist, partitionsListbox);
     2904                }
     2905            }
     2906        }
     2907        newtFormDestroy(myForm);
     2908        newtPopWindow();
     2909    }
     2910    newtPopHelpLine();
     2911    if (b_res == bCancel) {
     2912        memcpy((void *) raidlist, (void *) bkp_raidlist,
     2913               sizeof(struct raidlist_itself));
     2914        memcpy((void *) raidrec, (void *) bkp_raidrec,
     2915               sizeof(struct raid_device_record));
     2916        memcpy((void *) disklist, (void *) bkp_disklist,
     2917               sizeof(struct list_of_disks));
     2918    }
     2919    paranoid_free(tmp);
     2920    paranoid_free(help_text);
     2921    paranoid_free(title_of_window);
     2922    paranoid_free(sz_res);
     2923    paranoid_free(header_text);
     2924    paranoid_free(bkp_raidrec);
     2925    paranoid_free(bkp_disklist);
     2926    paranoid_free(bkp_raidlist);
     2927    paranoid_free(unallocated_raid_partitions);
    30922928}
    30932929#endif
     
    31002936 * or 'E' (or any other letter) for exit.
    31012937 */
    3102 char
    3103 which_restore_mode ()
    3104 {
    3105  
     2938char which_restore_mode()
     2939{
     2940
    31062941  /** char *************************************************************/
    3107   char output = '\0';
    3108   char tmp[MAX_STR_LEN];
    3109  
     2942    char output = '\0';
     2943    char tmp[MAX_STR_LEN];
     2944
    31102945  /** newt *************************************************************/
    31112946
    3112   newtComponent b1;
    3113   newtComponent b2;
    3114   newtComponent b3;
    3115   newtComponent b4;
    3116   newtComponent b_res;
    3117   newtComponent myForm;
    3118  
    3119   if (g_text_mode)
    3120     {
    3121       for(output='z'; !strchr("AICE", output); output=tmp[0])
    3122     {
    3123       printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
    3124       fgets(tmp, MAX_STR_LEN-1, stdin);
    3125     }
    3126       return(output);
    3127     }
    3128 
    3129   newtPushHelpLine
    3130     ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
    3131   newtOpenWindow (24, 3, 32, 17, "How should I restore?");
    3132   b1 = newtButton (7, 1, "Automatically");
    3133   b2 = newtButton (7, 5, "Interactively");
    3134   b3 = newtButton (7, 9, "Compare only!");
    3135   b4 = newtButton (7, 13, "Exit to shell");
    3136   myForm = newtForm (NULL, NULL, 0);
    3137   newtFormAddComponents (myForm, b1, b2, b3, b4, NULL);
    3138   b_res = newtRunForm (myForm);
    3139   newtFormDestroy (myForm);
    3140   newtPopWindow ();
    3141   if (b_res == b1)
    3142     {
    3143       output = 'N';
    3144     }
    3145   if (b_res == b2)
    3146     {
    3147       output = 'I';
    3148     }
    3149   if (b_res == b3)
    3150     {
    3151       output = 'C';
    3152     }
    3153   if (b_res == b4)
    3154     {
    3155       output = 'E';
    3156     }
    3157   newtPopHelpLine ();
    3158   return (output);
    3159 }
    3160 
     2947    newtComponent b1;
     2948    newtComponent b2;
     2949    newtComponent b3;
     2950    newtComponent b4;
     2951    newtComponent b_res;
     2952    newtComponent myForm;
     2953
     2954    if (g_text_mode) {
     2955        for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
     2956            printf
     2957                ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
     2958            fgets(tmp, MAX_STR_LEN - 1, stdin);
     2959        }
     2960        return (output);
     2961    }
     2962
     2963    newtPushHelpLine
     2964        ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
     2965    newtOpenWindow(24, 3, 32, 17, "How should I restore?");
     2966    b1 = newtButton(7, 1, "Automatically");
     2967    b2 = newtButton(7, 5, "Interactively");
     2968    b3 = newtButton(7, 9, "Compare only!");
     2969    b4 = newtButton(7, 13, "Exit to shell");
     2970    myForm = newtForm(NULL, NULL, 0);
     2971    newtFormAddComponents(myForm, b1, b2, b3, b4, NULL);
     2972    b_res = newtRunForm(myForm);
     2973    newtFormDestroy(myForm);
     2974    newtPopWindow();
     2975    if (b_res == b1) {
     2976        output = 'N';
     2977    }
     2978    if (b_res == b2) {
     2979        output = 'I';
     2980    }
     2981    if (b_res == b3) {
     2982        output = 'C';
     2983    }
     2984    if (b_res == b4) {
     2985        output = 'E';
     2986    }
     2987    newtPopHelpLine();
     2988    return (output);
     2989}
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-newt.h

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: mondo-rstr-newt.h,v 1.3 2004/06/10 15:29:13 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    3737/* external subroutines and global vars */
    3838
    39 extern long get_time (void);
    40 extern char *last_line_of_file (char *);
    41 extern void center_string (char *, int);
    42 extern bool does_file_exist (char *);
    43 extern void finish (int);
    44 extern long get_phys_size_of_drive (char *);
    45 extern bool is_this_device_mounted (char *);
    46 extern void strip_spaces (char *);
    47 extern void initialize_raidrec (struct raid_device_record *);
    48 extern int make_list_of_drives (struct mountlist_itself *,
    49                 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
    50 char *number_to_text (int);
    51 extern void reload_filelist (struct s_node *);
    52 extern void toggle_all_root_dirs_on (struct s_node *);
    53 extern void toggle_path_expandability (struct s_node *, char *, bool);
    54 extern void toggle_path_selection (struct s_node *, char *, bool);
    55 extern void toggle_node_selection (struct s_node *, bool);
    56 extern struct s_node *find_node_in_filelist (struct s_node *, char *filename);
    57 extern int what_number_cd_is_this (struct s_bkpinfo*);
     39extern long get_time(void);
     40extern char *last_line_of_file(char *);
     41extern void center_string(char *, int);
     42extern bool does_file_exist(char *);
     43extern void finish(int);
     44extern long get_phys_size_of_drive(char *);
     45extern bool is_this_device_mounted(char *);
     46extern void strip_spaces(char *);
     47extern void initialize_raidrec(struct raid_device_record *);
     48extern int make_list_of_drives(struct mountlist_itself *,
     49                               char[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
     50char *number_to_text(int);
     51extern void reload_filelist(struct s_node *);
     52extern void toggle_all_root_dirs_on(struct s_node *);
     53extern void toggle_path_expandability(struct s_node *, char *, bool);
     54extern void toggle_path_selection(struct s_node *, char *, bool);
     55extern void toggle_node_selection(struct s_node *, bool);
     56extern struct s_node *find_node_in_filelist(struct s_node *,
     57                                            char *filename);
     58extern int what_number_cd_is_this(struct s_bkpinfo *);
    5859//extern void fatal_error (char *);
    59 extern void sort_mountlist_by_device (struct mountlist_itself *);
    60 extern int load_mountlist (struct mountlist_itself *a, char *b);
     60extern void sort_mountlist_by_device(struct mountlist_itself *);
     61extern int load_mountlist(struct mountlist_itself *a, char *b);
    6162extern bool g_text_mode;
    6263
    6364
    6465/* hacks */
    65 extern int load_raidtab_into_raidlist (struct raidlist_itself *a, char *b);
     66extern int load_raidtab_into_raidlist(struct raidlist_itself *a, char *b);
    6667
    6768
    6869
    6970extern long g_start_time, g_minimum_progress, g_maximum_progress,
    70   g_current_progress, g_currentY;
     71    g_current_progress, g_currentY;
    7172extern bool g_ISO_restore_mode;
    7273
     
    9293/* my subroutines */
    9394
    94 void add_disklist_entry (struct list_of_disks *, char *,
    95              struct mountlist_itself *);
    96 void add_mountlist_entry (struct mountlist_itself *, struct raidlist_itself *,
    97               newtComponent, int, void *keylist[]);
    98 void add_varslist_entry (struct raid_device_record *);
    99 bool ask_me_yes_or_no (char *);
    100 bool ask_me_OK_or_cancel (char *);
    101 long calculate_raid_device_size (struct mountlist_itself *,
    102                  struct raidlist_itself *, char *);
    103 void choose_raid_level (struct
     95void add_disklist_entry(struct list_of_disks *, char *,
     96                        struct mountlist_itself *);
     97void add_mountlist_entry(struct mountlist_itself *,
     98                         struct raidlist_itself *, newtComponent, int,
     99                         void *keylist[]);
     100void add_varslist_entry(struct raid_device_record *);
     101bool ask_me_yes_or_no(char *);
     102bool ask_me_OK_or_cancel(char *);
     103long calculate_raid_device_size(struct mountlist_itself *,
     104                                struct raidlist_itself *, char *);
     105void choose_raid_level(struct
    104106#ifdef __FreeBSD__
    105 vinum_plex
     107                       vinum_plex
    106108#else
    107 raid_device_record
     109                       raid_device_record
    108110#endif
    109 *);
    110 void close_evalcall_form (void);
    111 void close_progress_form (void);
    112 void del_partns_listed_in_disklist (struct mountlist_itself *,
    113                     struct raidlist_itself *,
    114                     struct list_of_disks *);
    115 void delete_disklist_entry (struct list_of_disks *, char *, int);
    116 void delete_mountlist_entry (struct mountlist_itself *,
    117                  struct raidlist_itself *, newtComponent, int,
    118                  void *keylist[]);
    119 void delete_raidlist_entry (struct mountlist_itself *,
    120                 struct raidlist_itself *, char *);
    121 void delete_varslist_entry (struct raid_device_record *, int);
    122 char *disklist_entry_to_string (struct list_of_disks *, int);
    123 int edit_filelist (struct s_node *);
    124 void edit_mountlist_entry (struct mountlist_itself *,
    125                struct raidlist_itself *, newtComponent, int,
    126                void *keylist[]);
    127 void edit_raidlist_entry (struct mountlist_itself *, struct raidlist_itself *,
    128               struct raid_device_record *, int);
    129 void edit_varslist_entry (struct raid_device_record *, int);
    130 int edit_mountlist_in_newt (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *);
    131 int edit_mountlist (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *);
    132 void edit_raidrec_additional_vars (struct raid_device_record *);
    133 int evaluate_drive_within_mountlist (struct mountlist_itself *, char *,
    134                      char *);
    135 int evaluate_mountlist (struct mountlist_itself *, char *, char *, char *);
    136 int find_device_in_mountlist (struct mountlist_itself *, char *);
    137 int find_next_free_index_in_disklist (struct list_of_disks *);
    138 int find_raid_device_in_raidlist (struct raidlist_itself *, char *);
    139 bool get_isodir_info (char *, char *, char *, bool);
    140 void initiate_new_raidlist_entry (struct raidlist_itself *,
    141                   struct mountlist_itself *, int, char *);
    142 void insert_essential_additionalvars (struct raid_device_record *);
    143 bool is_this_raid_personality_registered (int);
    144 void log_file_end_to_screen (char *, char *);
    145 void log_to_screen (const char *fmt, ...);
    146 int look_for_duplicate_mountpoints (struct mountlist_itself *, char *);
    147 int look_for_weird_formats (struct mountlist_itself *, char *);
    148 void make_list_of_unallocated_raid_partitions (struct mountlist_itself *,
    149                            struct mountlist_itself *,
    150                            struct raidlist_itself *);
    151 char *mountlist_entry_to_string (struct mountlist_itself *, int);
    152 void mvaddstr_and_log_it (int, int, char *);
    153 void nuke_mode_dummy ();
    154 char *number_of_disks_as_string (int, char *);
    155 void open_evalcall_form (char *);
    156 void open_progress_form (char *, char *, char *, char *, long);
    157 void popup_and_OK (char *);
    158 bool popup_and_get_string (char *, char *, char *, int);
    159 bool popup_with_buttons (char *, char *, char *);
    160 void redraw_disklist (struct list_of_disks *, void *keylist[], newtComponent);
    161 void redraw_mountlist (struct mountlist_itself *, void *keylist[],
    162                newtComponent);
    163 void redraw_unallocpartnslist (struct mountlist_itself *, void *keylist[],
    164                    newtComponent);
    165 void redraw_varslist (struct additional_raid_variables *, void *keylist[],
    166               newtComponent);
    167 int read_variableINT_and_remove_from_raidvars (struct raid_device_record *,
    168                            char *);
    169 void refresh_log_screen (void);
    170 void rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself *,
    171                             char *, char *);
    172 void remove_essential_additionalvars (struct raid_device_record *);
    173 void select_raid_disks (struct mountlist_itself *, struct raidlist_itself *,
    174             struct raid_device_record *, char *,
    175             struct list_of_disks *);
    176 void setup_newt_stuff (void);
    177 long size_of_specific_device (struct mountlist_itself *, char *);
    178 bool spread_flaws_across_three_lines (char *, char *, char *, char *, int);
    179 char *turn_raid_level_number_to_string (int);
    180 void update_evalcall_form (int);
    181 void update_progress_form (char *);
    182 void update_progress_form_full (char *, char *, char *);
    183 char which_restore_mode (void);
    184 void write_variableINT_to_raid_var_line (struct raid_device_record *, int,
    185                      char *, int);
    186 int where_in_drivelist_is_drive (struct list_of_disks *, char *);
     111                       *);
     112void close_evalcall_form(void);
     113void close_progress_form(void);
     114void del_partns_listed_in_disklist(struct mountlist_itself *,
     115                                   struct raidlist_itself *,
     116                                   struct list_of_disks *);
     117void delete_disklist_entry(struct list_of_disks *, char *, int);
     118void delete_mountlist_entry(struct mountlist_itself *,
     119                            struct raidlist_itself *, newtComponent, int,
     120                            void *keylist[]);
     121void delete_raidlist_entry(struct mountlist_itself *,
     122                           struct raidlist_itself *, char *);
     123void delete_varslist_entry(struct raid_device_record *, int);
     124char *disklist_entry_to_string(struct list_of_disks *, int);
     125int edit_filelist(struct s_node *);
     126void edit_mountlist_entry(struct mountlist_itself *,
     127                          struct raidlist_itself *, newtComponent, int,
     128                          void *keylist[]);
     129void edit_raidlist_entry(struct mountlist_itself *,
     130                         struct raidlist_itself *,
     131                         struct raid_device_record *, int);
     132void edit_varslist_entry(struct raid_device_record *, int);
     133int edit_mountlist_in_newt(char *mountlist_fname,
     134                           struct mountlist_itself *,
     135                           struct raidlist_itself *);
     136int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
     137                   struct raidlist_itself *);
     138void edit_raidrec_additional_vars(struct raid_device_record *);
     139int evaluate_drive_within_mountlist(struct mountlist_itself *, char *,
     140                                    char *);
     141int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *);
     142int find_device_in_mountlist(struct mountlist_itself *, char *);
     143int find_next_free_index_in_disklist(struct list_of_disks *);
     144int find_raid_device_in_raidlist(struct raidlist_itself *, char *);
     145bool get_isodir_info(char *, char *, char *, bool);
     146void initiate_new_raidlist_entry(struct raidlist_itself *,
     147                                 struct mountlist_itself *, int, char *);
     148void insert_essential_additionalvars(struct raid_device_record *);
     149bool is_this_raid_personality_registered(int);
     150void log_file_end_to_screen(char *, char *);
     151void log_to_screen(const char *fmt, ...);
     152int look_for_duplicate_mountpoints(struct mountlist_itself *, char *);
     153int look_for_weird_formats(struct mountlist_itself *, char *);
     154void make_list_of_unallocated_raid_partitions(struct mountlist_itself *,
     155                                              struct mountlist_itself *,
     156                                              struct raidlist_itself *);
     157char *mountlist_entry_to_string(struct mountlist_itself *, int);
     158void mvaddstr_and_log_it(int, int, char *);
     159void nuke_mode_dummy();
     160char *number_of_disks_as_string(int, char *);
     161void open_evalcall_form(char *);
     162void open_progress_form(char *, char *, char *, char *, long);
     163void popup_and_OK(char *);
     164bool popup_and_get_string(char *, char *, char *, int);
     165bool popup_with_buttons(char *, char *, char *);
     166void redraw_disklist(struct list_of_disks *, void *keylist[],
     167                     newtComponent);
     168void redraw_mountlist(struct mountlist_itself *, void *keylist[],
     169                      newtComponent);
     170void redraw_unallocpartnslist(struct mountlist_itself *, void *keylist[],
     171                              newtComponent);
     172void redraw_varslist(struct additional_raid_variables *, void *keylist[],
     173                     newtComponent);
     174int read_variableINT_and_remove_from_raidvars(struct raid_device_record *,
     175                                              char *);
     176void refresh_log_screen(void);
     177void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself
     178                                                   *, char *, char *);
     179void remove_essential_additionalvars(struct raid_device_record *);
     180void select_raid_disks(struct mountlist_itself *, struct raidlist_itself *,
     181                       struct raid_device_record *, char *,
     182                       struct list_of_disks *);
     183void setup_newt_stuff(void);
     184long size_of_specific_device(struct mountlist_itself *, char *);
     185bool spread_flaws_across_three_lines(char *, char *, char *, char *, int);
     186char *turn_raid_level_number_to_string(int);
     187void update_evalcall_form(int);
     188void update_progress_form(char *);
     189void update_progress_form_full(char *, char *, char *);
     190char which_restore_mode(void);
     191void write_variableINT_to_raid_var_line(struct raid_device_record *, int,
     192                                        char *, int);
     193int where_in_drivelist_is_drive(struct list_of_disks *, char *);
    187194char *strip_path(char *);
    188195
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h

    r30 r128  
    44
    55extern void free_MR_global_filenames();
    6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo*);
    7 extern bool is_file_in_list(char*, char*, char*); /* needle, haystack, preamble */
     6extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);
     7extern bool is_file_in_list(char *, char *, char *);    /* needle, haystack, preamble */
    88extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99extern void kill_petris(void);
    10 extern int modify_rclocal_one_time( char *path );
     10extern int modify_rclocal_one_time(char *path);
    1111extern int mount_cdrom(struct s_bkpinfo *bkpinfo);
    12 extern int mount_device(char*,char*,char*,bool);
    13 extern int mount_all_devices(struct mountlist_itself*, bool);
     12extern int mount_device(char *, char *, char *, bool);
     13extern int mount_all_devices(struct mountlist_itself *, bool);
    1414extern void protect_against_braindead_sysadmins(void);
    15 extern int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo);
     15extern int read_cfg_file_into_bkpinfo(char *cfg_file,
     16                                      struct s_bkpinfo *bkpinfo);
    1617struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *);
    17 extern int backup_crucial_file(char *path_root, char*filename);
     18extern int backup_crucial_file(char *path_root, char *filename);
    1819extern int run_boot_loader(bool);
    19 extern int run_grub(bool, char*);
     20extern int run_grub(bool, char *);
    2021extern int run_lilo(bool);
    2122extern int run_elilo(bool);
     
    2324extern char *find_my_editor(void);
    2425
    25 extern void streamline_changes_file(char*,char*);
    26 extern void  set_signals( int on );
     26extern void streamline_changes_file(char *, char *);
     27extern void set_signals(int on);
    2728extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo);
    2829//extern void setup_signals(int);
    2930extern void terminate_daemon(int);
    3031extern void termination_in_progress(int);
    31 extern int unmount_all_devices(struct mountlist_itself*);
     32extern int unmount_all_devices(struct mountlist_itself *);
    3233extern int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo);
    33 extern int 
    34 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    35                   char *ramdisk_fname,
    36                   char *output_cfg_file,
    37                   char *output_mountlist_file);
     34extern int
     35extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     36                                 char *ramdisk_fname,
     37                                 char *output_cfg_file,
     38                                char *output_mountlist_file);
    3839
    39 extern void ask_about_these_imagedevs( char *infname, char *outfname );
     40extern void ask_about_these_imagedevs(char *infname, char *outfname);
    4041
    41 extern void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage);
     42extern void wait_until_software_raids_are_prepped(char *mdstat_file,
     43                                                  int wait_for_percentage);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r30 r128  
    134134
    135135extern bool g_sigpipe_caught;
    136 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
     136extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
    137137extern bool g_I_have_just_nuked;
    138138extern char *g_tmpfs_mountpt;
     
    140140extern char *g_isodir_format;
    141141extern long g_current_progress, g_maximum_progress;
    142 extern char *g_biggielist_txt;// where 'biggielist.txt' is stored, on ramdisk / tempdir;
    143                           // biggielist.txt is the list of big files stored on the
    144                           // backup media set in question
    145 extern char    *g_filelist_full; // filelist.full.gz is the list of all regular files
    146                           // (excluding big files) stored on the backup media set
    147 extern char    *g_biggielist_pot;// list of big files which _could_ be restored, if the
    148                           // user chooses them
    149 extern char  *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
    150                             // were archived as images, not just /dev entries
    151                             // ... e.g. NTFS, BeOS partitions
    152 extern char  *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
    153                               // restore only these
    154 extern char  *g_mondo_cfg_file;      // where m*ndo-restore.cfg (the config file) is stored
    155 extern char  *g_mountlist_fname;     // where mountlist.txt (the mountlist file) is stored
    156 extern char    *g_mondo_home;        // homedir of Mondo; usually /usr/local/share/mondo
     142extern char *g_biggielist_txt;  // where 'biggielist.txt' is stored, on ramdisk / tempdir;
     143                          // biggielist.txt is the list of big files stored on the
     144                          // backup media set in question
     145extern char *g_filelist_full;   // filelist.full.gz is the list of all regular files
     146                          // (excluding big files) stored on the backup media set
     147extern char *g_biggielist_pot;  // list of big files which _could_ be restored, if the
     148                          // user chooses them
     149extern char *g_filelist_imagedevs;  // list of devices (e.g. /dev/hda1, /dev/sda5) which
     150                            // were archived as images, not just /dev entries
     151                            // ... e.g. NTFS, BeOS partitions
     152extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
     153                              // restore only these
     154extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
     155extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
     156extern char *g_mondo_home;      // homedir of Mondo; usually /usr/local/share/mondo
    157157extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
    158158
     
    170170void free_MR_global_filenames()
    171171{
    172   paranoid_free ( g_biggielist_txt );
    173   paranoid_free ( g_filelist_full );
    174   paranoid_free ( g_filelist_imagedevs );
     172    paranoid_free(g_biggielist_txt);
     173    paranoid_free(g_filelist_full);
     174    paranoid_free(g_filelist_imagedevs);
    175175//  paranoid_free (g_imagedevs_pot );
    176   paranoid_free ( g_imagedevs_restthese );
    177   paranoid_free ( g_mondo_cfg_file );
    178   paranoid_free ( g_mountlist_fname );
    179   paranoid_free ( g_mondo_home );
    180   paranoid_free ( g_tmpfs_mountpt );
    181   paranoid_free ( g_isodir_device );
    182   paranoid_free ( g_isodir_format );
     176    paranoid_free(g_imagedevs_restthese);
     177    paranoid_free(g_mondo_cfg_file);
     178    paranoid_free(g_mountlist_fname);
     179    paranoid_free(g_mondo_home);
     180    paranoid_free(g_tmpfs_mountpt);
     181    paranoid_free(g_isodir_device);
     182    paranoid_free(g_isodir_format);
    183183
    184184}
     
    193193 * @ingroup restoreUtilityGroup
    194194 */
    195 void
    196 ask_about_these_imagedevs( char *infname, char *outfname )
    197 {
    198   FILE *fin;
    199   FILE *fout;
     195void ask_about_these_imagedevs(char *infname, char *outfname)
     196{
     197    FILE *fin;
     198    FILE *fout;
    200199  /************************************************************************
    201200   * allocate memory regions. test and set  -sab 16 feb 2003              *
    202201   ************************************************************************/
    203   char *incoming_ptr;
    204   char *question_ptr;
    205 
    206   char incoming[ MAX_STR_LEN ];
    207   char question[ MAX_STR_LEN ];
    208 
    209   assert_string_is_neither_NULL_nor_zerolength(infname);
    210   assert_string_is_neither_NULL_nor_zerolength(outfname);
    211 
    212   incoming_ptr = malloc(sizeof(incoming));
    213   if ( incoming_ptr == NULL )
    214     {
    215       fprintf(stderr, "Out of Memory\n");
    216       exit (EXIT_FAILURE);
    217     }
    218 
    219   question_ptr = malloc(sizeof(question));
    220   if ( question_ptr == NULL)
    221     {
    222       fprintf(stderr, "Out of Memory\n");
    223       exit (EXIT_FAILURE);
    224     }
    225 
    226   memset (incoming_ptr, '\0', sizeof(incoming));
    227   memset (question_ptr, '\0', sizeof(question));
    228 
    229  
    230 
    231   if (!( fin = fopen( infname,"r") ) ) 
    232     {
    233       fatal_error( "Cannot openin infname" );
    234     }
    235   if ( !( fout = fopen( outfname, "w" ) ) )
    236     {
    237       fatal_error( "Cannot openin outfname");
    238     }
    239   for( fgets( incoming_ptr, MAX_STR_LEN, fin);
    240        !feof( fin );
    241        fgets( incoming_ptr, MAX_STR_LEN, fin ) )
    242     {
    243       strip_spaces( incoming_ptr );
    244 
    245       if ( incoming[0] == '\0')
    246     {
    247       continue;
    248     }
    249 
    250       sprintf( question_ptr,
    251            "Should I restore the image of %s ?",
    252            incoming_ptr );
    253 
    254       if ( ask_me_yes_or_no( question_ptr ) )
    255         {
    256           fprintf( fout, "%s\n", incoming_ptr );
    257         }
    258     }
    259  
     202    char *incoming_ptr;
     203    char *question_ptr;
     204
     205    char incoming[MAX_STR_LEN];
     206    char question[MAX_STR_LEN];
     207
     208    assert_string_is_neither_NULL_nor_zerolength(infname);
     209    assert_string_is_neither_NULL_nor_zerolength(outfname);
     210
     211    incoming_ptr = malloc(sizeof(incoming));
     212    if (incoming_ptr == NULL) {
     213        fprintf(stderr, "Out of Memory\n");
     214        exit(EXIT_FAILURE);
     215    }
     216
     217    question_ptr = malloc(sizeof(question));
     218    if (question_ptr == NULL) {
     219        fprintf(stderr, "Out of Memory\n");
     220        exit(EXIT_FAILURE);
     221    }
     222
     223    memset(incoming_ptr, '\0', sizeof(incoming));
     224    memset(question_ptr, '\0', sizeof(question));
     225
     226
     227
     228    if (!(fin = fopen(infname, "r"))) {
     229        fatal_error("Cannot openin infname");
     230    }
     231    if (!(fout = fopen(outfname, "w"))) {
     232        fatal_error("Cannot openin outfname");
     233    }
     234    for (fgets(incoming_ptr, MAX_STR_LEN, fin);
     235         !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
     236        strip_spaces(incoming_ptr);
     237
     238        if (incoming[0] == '\0') {
     239            continue;
     240        }
     241
     242        sprintf(question_ptr,
     243                "Should I restore the image of %s ?", incoming_ptr);
     244
     245        if (ask_me_yes_or_no(question_ptr)) {
     246            fprintf(fout, "%s\n", incoming_ptr);
     247        }
     248    }
     249
    260250  /*** free memory ***********/
    261   paranoid_free(incoming_ptr);
    262   incoming_ptr = NULL;
    263   paranoid_free(question_ptr);
    264   question_ptr = NULL;
    265  
    266 
    267   paranoid_fclose( fout );
    268   paranoid_fclose( fin );
     251    paranoid_free(incoming_ptr);
     252    incoming_ptr = NULL;
     253    paranoid_free(question_ptr);
     254    question_ptr = NULL;
     255
     256
     257    paranoid_fclose(fout);
     258    paranoid_fclose(fin);
    269259}
    270260
     
    289279 * @ingroup restoreUtilityGroup
    290280 */
    291 int
    292 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    293                   char *ramdisk_fname,
    294                   char *output_cfg_file,
    295                   char *output_mountlist_file)
    296 {
    297   char *mountpt;
    298   char *command;
    299   char *orig_fname;
    300   int retval=0;
    301  
    302   assert(bkpinfo!=NULL);
    303   malloc_string(mountpt);
    304   malloc_string(command);
    305   malloc_string(orig_fname);
    306   assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
    307   assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
    308   assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
    309   sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir );
    310   sprintf( command, "mkdir -p %s", mountpt );
    311   run_program_and_log_output ( command, FALSE );
    312   sprintf( command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
    313        ramdisk_fname,
    314        bkpinfo->tmpdir );
    315 
    316   run_program_and_log_output( command, FALSE );
    317   sprintf( command, "umount %s", mountpt );
    318 
    319   run_program_and_log_output( command, FALSE );
    320 
    321   sprintf( command, "mount -o loop %s/mindi.rd -t ext2 %s",
    322        bkpinfo->tmpdir,
    323        mountpt );
    324 
    325   run_program_and_log_output( command, FALSE );
    326 
    327   sprintf( command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    328 
    329   run_program_and_log_output( command, FALSE );
    330 
    331   sprintf( command,
    332            "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
    333        mountpt, g_mondo_cfg_file,
    334        output_cfg_file );
    335   run_program_and_log_output(command, FALSE);
    336 
    337   sprintf( orig_fname, "%s/%s", mountpt, g_mountlist_fname );
    338   if (does_file_exist( orig_fname ))
    339     {
    340       sprintf( command,
    341        "cp -f %s %s",
    342        orig_fname, output_mountlist_file );
    343       run_program_and_log_output( command, FALSE );
    344     }
    345   sprintf( command, "umount %s", mountpt );
    346   run_program_and_log_output( command, FALSE );
    347   if ( !does_file_exist(output_cfg_file) || (!does_file_exist(output_mountlist_file) && does_file_exist(orig_fname)) )
    348     {
    349       log_msg(2, "Failed to extract %s and/or %s from ramdisk",
    350           output_cfg_file,
    351           output_mountlist_file );
    352       retval=1;
    353     }
    354   else
    355     {
    356       retval=0;
    357     }
    358   paranoid_free(mountpt);
    359   paranoid_free(command);
    360   paranoid_free(orig_fname);
    361   return(retval);
     281int
     282extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     283                                 char *ramdisk_fname,
     284                                 char *output_cfg_file,
     285                                 char *output_mountlist_file)
     286{
     287    char *mountpt;
     288    char *command;
     289    char *orig_fname;
     290    int retval = 0;
     291
     292    assert(bkpinfo != NULL);
     293    malloc_string(mountpt);
     294    malloc_string(command);
     295    malloc_string(orig_fname);
     296    assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
     297    assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
     298    assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
     299    sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     300    sprintf(command, "mkdir -p %s", mountpt);
     301    run_program_and_log_output(command, FALSE);
     302    sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
     303            ramdisk_fname, bkpinfo->tmpdir);
     304
     305    run_program_and_log_output(command, FALSE);
     306    sprintf(command, "umount %s", mountpt);
     307
     308    run_program_and_log_output(command, FALSE);
     309
     310    sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
     311            bkpinfo->tmpdir, mountpt);
     312
     313    run_program_and_log_output(command, FALSE);
     314
     315    sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     316
     317    run_program_and_log_output(command, FALSE);
     318
     319    sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
     320            mountpt, g_mondo_cfg_file, output_cfg_file);
     321    run_program_and_log_output(command, FALSE);
     322
     323    sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
     324    if (does_file_exist(orig_fname)) {
     325        sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
     326        run_program_and_log_output(command, FALSE);
     327    }
     328    sprintf(command, "umount %s", mountpt);
     329    run_program_and_log_output(command, FALSE);
     330    if (!does_file_exist(output_cfg_file)
     331        || (!does_file_exist(output_mountlist_file)
     332            && does_file_exist(orig_fname))) {
     333        log_msg(2, "Failed to extract %s and/or %s from ramdisk",
     334                output_cfg_file, output_mountlist_file);
     335        retval = 1;
     336    } else {
     337        retval = 0;
     338    }
     339    paranoid_free(mountpt);
     340    paranoid_free(command);
     341    paranoid_free(orig_fname);
     342    return (retval);
    362343
    363344}
     
    372353void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo)
    373354{
    374   while(get_cfg_file_from_archive(bkpinfo))
    375     {
    376       if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?"))
    377     { fatal_error("Could not find config file/archives. Aborting."); }
    378       interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    379     }
     355    while (get_cfg_file_from_archive(bkpinfo)) {
     356        if (!ask_me_yes_or_no
     357            ("Failed to find config file/archives. Choose another source?"))
     358        {
     359            fatal_error("Could not find config file/archives. Aborting.");
     360        }
     361        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     362    }
    380363}
    381364
     
    388371 * @return TRUE if it's in the list, FALSE if it's not.
    389372 */
    390 bool
    391 is_file_in_list(char *f, char *list_fname, char *preamble)
     373bool is_file_in_list(char *f, char *list_fname, char *preamble)
    392374{
    393375
    394376  /** needs malloc **/
    395   char *command;
    396   char *file;
    397   char *tmp;
    398   int res;
    399 
    400   malloc_string(command);
    401   malloc_string(file);
    402   malloc_string(tmp);
    403   assert_string_is_neither_NULL_nor_zerolength(f);
    404   assert_string_is_neither_NULL_nor_zerolength(list_fname);
    405   assert(preamble!=NULL);
    406 
    407   if ( strncmp( preamble, f, strlen(preamble ) ) == 0 )
    408     {
    409       strcpy( file, f + strlen(preamble) );
    410     }
    411   else
    412     {
    413       strcpy( file, f );
    414     }
    415   if ( file[0] == '/' && file[1] == '/')
    416     {
    417       strcpy( tmp, file );
    418       strcpy( file,tmp + 1 );
    419     }
    420   sprintf( tmp,"Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
    421   log_msg(2, tmp );
    422   sprintf( command, "cat %s | grep -x \"%s\"",  list_fname, file );
    423   res = run_program_and_log_output( command, FALSE);
    424   paranoid_free(command);
    425   paranoid_free(file);
    426   paranoid_free(tmp);
    427   if (res)
    428     {
    429       return(FALSE);
    430     }
    431   else
    432     {
    433       return(TRUE);
    434     }
    435 }
     377    char *command;
     378    char *file;
     379    char *tmp;
     380    int res;
     381
     382    malloc_string(command);
     383    malloc_string(file);
     384    malloc_string(tmp);
     385    assert_string_is_neither_NULL_nor_zerolength(f);
     386    assert_string_is_neither_NULL_nor_zerolength(list_fname);
     387    assert(preamble != NULL);
     388
     389    if (strncmp(preamble, f, strlen(preamble)) == 0) {
     390        strcpy(file, f + strlen(preamble));
     391    } else {
     392        strcpy(file, f);
     393    }
     394    if (file[0] == '/' && file[1] == '/') {
     395        strcpy(tmp, file);
     396        strcpy(file, tmp + 1);
     397    }
     398    sprintf(tmp,
     399            "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
     400            f, file);
     401    log_msg(2, tmp);
     402    sprintf(command, "cat %s | grep -x \"%s\"", list_fname, file);
     403    res = run_program_and_log_output(command, FALSE);
     404    paranoid_free(command);
     405    paranoid_free(file);
     406    paranoid_free(tmp);
     407    if (res) {
     408        return (FALSE);
     409    } else {
     410        return (TRUE);
     411    }
     412}
     413
    436414/**************************************************************************
    437415 *END_IS_FILE_IN_LIST                                                     *
     
    451429int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please)
    452430{
    453   char *mount_isodir_command, *tmp,
    454     *command;
    455   int retval=0, i;
    456   bool already_mounted=FALSE;
    457 
    458   assert(bkpinfo!=NULL);
    459   malloc_string(mount_isodir_command);
    460   malloc_string(tmp);
    461   malloc_string(command);
    462   g_ISO_restore_mode=TRUE;
    463   read_cfg_var( g_mondo_cfg_file, "iso-dev", g_isodir_device);
    464   if (bkpinfo->disaster_recovery)
    465     {
     431    char *mount_isodir_command, *tmp, *command;
     432    int retval = 0, i;
     433    bool already_mounted = FALSE;
     434
     435    assert(bkpinfo != NULL);
     436    malloc_string(mount_isodir_command);
     437    malloc_string(tmp);
     438    malloc_string(command);
     439    g_ISO_restore_mode = TRUE;
     440    read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     441    if (bkpinfo->disaster_recovery) {
    466442/* Patch Conor Daly 26-june-2004
    467443 * Don't let this clobber an existing bkpinfo->isodir */
    468       if (!bkpinfo->isodir[0]) {
    469         strcpy(bkpinfo->isodir, "/tmp/isodir");
    470       }
     444        if (!bkpinfo->isodir[0]) {
     445            strcpy(bkpinfo->isodir, "/tmp/isodir");
     446        }
    471447/* End patch */
    472       sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    473       run_program_and_log_output(command, 5);
    474       log_msg(2,"Setting isodir to %s", bkpinfo->isodir);
    475     }
    476 
    477   if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {return(1);}
    478   paranoid_system("umount "MNT_CDROM" 2> /dev/null"); /* just in case */
    479 
    480   if (is_this_device_mounted(g_isodir_device))
    481     {
    482       log_to_screen("WARNING - isodir is already mounted");
    483       already_mounted=TRUE;
    484     }
    485   else
    486     {
    487       sprintf(mount_isodir_command,"mount %s", g_isodir_device);
    488       if (strlen(g_isodir_format)>1)
    489         { sprintf(mount_isodir_command+strlen(mount_isodir_command)," -t %s", g_isodir_format); }
    490       strcat(mount_isodir_command," -o ro ");
    491       strcat(mount_isodir_command, bkpinfo->isodir);
    492       run_program_and_log_output("df -m", FALSE);
    493       sprintf(tmp, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
    494       log_msg(1,tmp);
    495       if (run_program_and_log_output(mount_isodir_command, FALSE))
    496         { popup_and_OK("Cannot mount the device where the ISO files are stored."); return(1); }
    497       log_to_screen("I have mounted the device where the ISO files are stored.");
    498     }
    499   if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { mount_cdrom(bkpinfo); }
    500   i=what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */
    501   sprintf(tmp,"%s #%d has been mounted via loopback mount", media_descriptor_string(bkpinfo->backup_media_type), i);
    502   log_msg(1,tmp);
    503   if (i<0)
    504     { popup_and_OK("Cannot find ISO images in the directory you specified."); retval=1; }
    505   log_msg(2,"%ld: bkpinfo->isodir is now %s", __LINE__, bkpinfo->isodir);
    506   paranoid_free(mount_isodir_command);
    507   paranoid_free(tmp);
    508   paranoid_free(command);
    509   return(retval);
     448        sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     449        run_program_and_log_output(command, 5);
     450        log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
     451    }
     452
     453    if (!get_isodir_info
     454        (g_isodir_device, g_isodir_format, bkpinfo->isodir,
     455         nuke_me_please)) {
     456        return (1);
     457    }
     458    paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
     459
     460    if (is_this_device_mounted(g_isodir_device)) {
     461        log_to_screen("WARNING - isodir is already mounted");
     462        already_mounted = TRUE;
     463    } else {
     464        sprintf(mount_isodir_command, "mount %s", g_isodir_device);
     465        if (strlen(g_isodir_format) > 1) {
     466            sprintf(mount_isodir_command + strlen(mount_isodir_command),
     467                    " -t %s", g_isodir_format);
     468        }
     469        strcat(mount_isodir_command, " -o ro ");
     470        strcat(mount_isodir_command, bkpinfo->isodir);
     471        run_program_and_log_output("df -m", FALSE);
     472        sprintf(tmp,
     473                "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
     474                mount_isodir_command);
     475        log_msg(1, tmp);
     476        if (run_program_and_log_output(mount_isodir_command, FALSE)) {
     477            popup_and_OK
     478                ("Cannot mount the device where the ISO files are stored.");
     479            return (1);
     480        }
     481        log_to_screen
     482            ("I have mounted the device where the ISO files are stored.");
     483    }
     484    if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     485        mount_cdrom(bkpinfo);
     486    }
     487    i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
     488    sprintf(tmp, "%s #%d has been mounted via loopback mount",
     489            media_descriptor_string(bkpinfo->backup_media_type), i);
     490    log_msg(1, tmp);
     491    if (i < 0) {
     492        popup_and_OK
     493            ("Cannot find ISO images in the directory you specified.");
     494        retval = 1;
     495    }
     496    log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
     497            bkpinfo->isodir);
     498    paranoid_free(mount_isodir_command);
     499    paranoid_free(tmp);
     500    paranoid_free(command);
     501    return (retval);
    510502}
    511503
     
    516508 * Kill all Petris processes.
    517509 */
    518 void
    519 kill_petris(void)
    520 {
    521   char *command;
    522   malloc_string(command);
    523   sprintf( command, "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
    524   paranoid_system( command );
    525   paranoid_free(command);
    526 }
     510void kill_petris(void)
     511{
     512    char *command;
     513    malloc_string(command);
     514    sprintf(command,
     515            "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
     516    paranoid_system(command);
     517    paranoid_free(command);
     518}
     519
    527520/**************************************************************************
    528521 *END_KILL_PETRIS                                                         *
     
    537530 * @return 0 for success, nonzero for failure.
    538531 */
    539 int
    540 modify_rclocal_one_time( char *path )
     532int modify_rclocal_one_time(char *path)
    541533{
    542534  /** malloc **/
    543   char *rclocal_fname;
    544   char *newfile_fname;
    545   char *tmp;
    546 
    547   malloc_string(rclocal_fname);
    548   malloc_string(newfile_fname);
    549   malloc_string(tmp);
    550   assert_string_is_neither_NULL_nor_zerolength(path);
    551 
    552   sprintf( rclocal_fname, "%s/rc.local", path );
     535    char *rclocal_fname;
     536    char *newfile_fname;
     537    char *tmp;
     538
     539    malloc_string(rclocal_fname);
     540    malloc_string(newfile_fname);
     541    malloc_string(tmp);
     542    assert_string_is_neither_NULL_nor_zerolength(path);
     543
     544    sprintf(rclocal_fname, "%s/rc.local", path);
    553545
    554546//  sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);
    555547//  run_program_and_log_output( tmp, FALSE );
    556   return( 0 ); /* remove this line to open the floodgates... */
    557 
    558   if (! does_file_exist( rclocal_fname ) )
    559     {
    560       sprintf( rclocal_fname, "%s/rc.d/rc.local", path );
    561     }
    562   if (! does_file_exist( rclocal_fname ) )
    563     {
    564 paranoid_free(rclocal_fname);
    565 paranoid_free(newfile_fname);
    566 paranoid_free(tmp);
    567       return( 1 );
    568     }
    569   sprintf( newfile_fname, "%s/rc.local.mondorescue", path );
    570   sprintf( tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",rclocal_fname );
    571   if (system( tmp ) )
    572     {
    573       sprintf( tmp,"echo \"[ -e %s ] && %s\n\" >> %s",
    574            newfile_fname,
    575            newfile_fname,
    576            rclocal_fname);
    577 
    578       paranoid_system( tmp );
    579     }
    580   sprintf( tmp, "echo -en \"#!/bin/sh\
     548    return (0);                 /* remove this line to open the floodgates... */
     549
     550    if (!does_file_exist(rclocal_fname)) {
     551        sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
     552    }
     553    if (!does_file_exist(rclocal_fname)) {
     554        paranoid_free(rclocal_fname);
     555        paranoid_free(newfile_fname);
     556        paranoid_free(tmp);
     557        return (1);
     558    }
     559    sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
     560    sprintf(tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",
     561            rclocal_fname);
     562    if (system(tmp)) {
     563        sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
     564                newfile_fname, newfile_fname, rclocal_fname);
     565
     566        paranoid_system(tmp);
     567    }
     568    sprintf(tmp, "echo -en \"#!/bin/sh\
    581569\\n\
    582570\\n\
     
    587575service xfs start\\n\
    588576yes | rm -f %s\\n\
    589 \" > %s",rclocal_fname,rclocal_fname,newfile_fname,newfile_fname);
    590   sprintf( tmp, "chmod +x \"%s\"", newfile_fname );
    591   run_program_and_log_output( tmp, FALSE );
    592 paranoid_free(rclocal_fname);
    593 paranoid_free(newfile_fname);
    594 paranoid_free(tmp);
    595   return( 0 );
    596 }
     577\" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);
     578    sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
     579    run_program_and_log_output(tmp, FALSE);
     580    paranoid_free(rclocal_fname);
     581    paranoid_free(newfile_fname);
     582    paranoid_free(tmp);
     583    return (0);
     584}
     585
    597586/**************************************************************************
    598587 *END_ MODIFY_RCLOCAL_ONE_TIME                                            *
     
    609598 * @return The number of errors encountered (0 for success).
    610599 */
    611 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
    612 {
    613   int retval=0,lino,res;
    614   char *tmp, *these_failed, *format;
    615   struct mountlist_itself *mountlist;
    616 
    617   malloc_string(tmp);
    618   malloc_string(format);
    619   malloc_string(these_failed);
    620   assert(p_external_copy_of_mountlist!=NULL);
    621   mountlist = malloc(sizeof(struct mountlist_itself));
    622   memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
    623   sort_mountlist_by_mountpoint(mountlist, 0);
     600int mount_all_devices(struct mountlist_itself
     601                      *p_external_copy_of_mountlist, bool writeable)
     602{
     603    int retval = 0, lino, res;
     604    char *tmp, *these_failed, *format;
     605    struct mountlist_itself *mountlist;
     606
     607    malloc_string(tmp);
     608    malloc_string(format);
     609    malloc_string(these_failed);
     610    assert(p_external_copy_of_mountlist != NULL);
     611    mountlist = malloc(sizeof(struct mountlist_itself));
     612    memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
     613           sizeof(struct mountlist_itself));
     614    sort_mountlist_by_mountpoint(mountlist, 0);
    624615
    625616  /** menset **/
    626   these_failed[0] = '\0';
    627 
    628   mvaddstr_and_log_it( g_currentY, 0, "Mounting devices         ");
    629   open_progress_form("Mounting devices",
    630              "I am now mounting all the drives.",
    631              "This should not take long.",
    632              "",
    633              mountlist->entries);
    634  
    635   for( lino = 0; lino < mountlist->entries; lino++ )
    636     {
    637       if ( !strcmp( mountlist->el[lino].device, "/proc" ) )
    638         {
    639       log_msg(1, "Again with the /proc - why is this in your mountlist?");
    640     }
    641       else if ( is_this_device_mounted( mountlist->el[lino].device ) )
    642     {
    643       sprintf( tmp, "%s is already mounted",mountlist->el[lino].device );
    644       log_to_screen( tmp );
    645     }
    646       else if ( strcmp( mountlist->el[lino].mountpoint, "none" ) && strcmp( mountlist->el[lino].mountpoint, "lvm" ) && strcmp( mountlist->el[lino].mountpoint,"raid" ) && strcmp(mountlist->el[lino].mountpoint, "image" ) )
    647     {
    648       sprintf( tmp, "Mounting %s",mountlist->el[lino].device );
    649       update_progress_form( tmp );
    650       strcpy(format, mountlist->el[lino].format);
    651       if (!strcmp(format, "ext3")) { strcpy(format, "ext2"); }
    652       res = mount_device( mountlist->el[lino].device,
    653                   mountlist->el[lino].mountpoint,
    654                   format,
    655                   writeable );
    656       retval += res;
    657           if ( res )
    658         {
    659           strcat( these_failed,mountlist->el[lino].device );
    660           strcat( these_failed, " " );
    661         }
    662     }
    663       g_current_progress++;
    664     }
    665   close_progress_form();
    666   run_program_and_log_output( "df -m", TRUE );
    667   if ( retval )
    668     {
    669       if (g_partition_table_locked_up > 0)
    670         {
    671           log_to_screen(
    672 "fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
    673       log_to_screen(
    674 "lock up the partition table. You might have to reboot and use Interactive Mode to");
    675       log_to_screen(
    676 "format and restore *without* partitioning first. Sorry for the inconvenience.");
    677         }
    678       sprintf( tmp, "Could not mount devices %s- shall I abort?", these_failed );
    679       if ( !ask_me_yes_or_no( tmp ) )
    680     {
    681       retval = 0;
    682       log_to_screen( "Continuing, although some devices failed to be mounted" );
    683       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    684     }
    685       else
    686     {
    687       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    688       log_to_screen( "Unable to mount some or all of your partitions." );
    689     }
    690     }
    691   else
    692     {
    693       log_to_screen("All partitions were mounted OK.");
    694       mvaddstr_and_log_it(g_currentY++,74,"Done.");
    695     }
    696   run_program_and_log_output("df -m", 3);
    697   paranoid_free(mountlist);
    698   paranoid_free(tmp);
    699   paranoid_free(format);
    700   paranoid_free(these_failed);
    701   return(retval);
    702 }
     617    these_failed[0] = '\0';
     618
     619    mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
     620    open_progress_form("Mounting devices",
     621                       "I am now mounting all the drives.",
     622                       "This should not take long.",
     623                       "", mountlist->entries);
     624
     625    for (lino = 0; lino < mountlist->entries; lino++) {
     626        if (!strcmp(mountlist->el[lino].device, "/proc")) {
     627            log_msg(1,
     628                    "Again with the /proc - why is this in your mountlist?");
     629        } else if (is_this_device_mounted(mountlist->el[lino].device)) {
     630            sprintf(tmp, "%s is already mounted",
     631                    mountlist->el[lino].device);
     632            log_to_screen(tmp);
     633        } else if (strcmp(mountlist->el[lino].mountpoint, "none")
     634                   && strcmp(mountlist->el[lino].mountpoint, "lvm")
     635                   && strcmp(mountlist->el[lino].mountpoint, "raid")
     636                   && strcmp(mountlist->el[lino].mountpoint, "image")) {
     637            sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
     638            update_progress_form(tmp);
     639            strcpy(format, mountlist->el[lino].format);
     640            if (!strcmp(format, "ext3")) {
     641                strcpy(format, "ext2");
     642            }
     643            res = mount_device(mountlist->el[lino].device,
     644                               mountlist->el[lino].mountpoint,
     645                               format, writeable);
     646            retval += res;
     647            if (res) {
     648                strcat(these_failed, mountlist->el[lino].device);
     649                strcat(these_failed, " ");
     650            }
     651        }
     652        g_current_progress++;
     653    }
     654    close_progress_form();
     655    run_program_and_log_output("df -m", TRUE);
     656    if (retval) {
     657        if (g_partition_table_locked_up > 0) {
     658            log_to_screen
     659                ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
     660            log_to_screen
     661                ("lock up the partition table. You might have to reboot and use Interactive Mode to");
     662            log_to_screen
     663                ("format and restore *without* partitioning first. Sorry for the inconvenience.");
     664        }
     665        sprintf(tmp, "Could not mount devices %s- shall I abort?",
     666                these_failed);
     667        if (!ask_me_yes_or_no(tmp)) {
     668            retval = 0;
     669            log_to_screen
     670                ("Continuing, although some devices failed to be mounted");
     671            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     672        } else {
     673            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     674            log_to_screen
     675                ("Unable to mount some or all of your partitions.");
     676        }
     677    } else {
     678        log_to_screen("All partitions were mounted OK.");
     679        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     680    }
     681    run_program_and_log_output("df -m", 3);
     682    paranoid_free(mountlist);
     683    paranoid_free(tmp);
     684    paranoid_free(format);
     685    paranoid_free(these_failed);
     686    return (retval);
     687}
     688
    703689 /**************************************************************************
    704690  *END_MOUNT_ALL_DEVICES                                                   *
     
    717703int mount_cdrom(struct s_bkpinfo *bkpinfo)
    718704{
    719   char *mount_cmd;
    720   int i,res;
     705    char *mount_cmd;
     706    int i, res;
    721707#ifdef __FreeBSD__
    722   char mdd[32];
    723   char *mddev = mdd;
     708    char mdd[32];
     709    char *mddev = mdd;
    724710#endif
    725711
    726   malloc_string(mount_cmd);
    727   assert(bkpinfo!=NULL);
    728  
    729   if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    730     {
    731       log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
    732       paranoid_free(mount_cmd);
    733       return 0;
    734     }
    735 
    736   if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE))
    737     {
    738       log_msg(2,"mount_cdrom() - CD already mounted. Fair enough.");
    739       paranoid_free(mount_cmd);
    740       return(0);
    741     }
    742 
    743   if (bkpinfo->backup_media_type == nfs)
    744     {
    745       log_msg(2,"Mounting for NFS thingy");
    746       log_msg(2, "isodir = %s", bkpinfo->isodir);
    747       if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    748       && am_I_in_disaster_recovery_mode())
    749         {
    750       strcpy(bkpinfo->isodir, "/tmp/isodir");
    751           log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    752     }
    753 
     712    malloc_string(mount_cmd);
     713    assert(bkpinfo != NULL);
     714
     715    if (bkpinfo->backup_media_type == tape
     716        || bkpinfo->backup_media_type == udev) {
     717        log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
     718        paranoid_free(mount_cmd);
     719        return 0;
     720    }
     721
     722    if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) {
     723        log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
     724        paranoid_free(mount_cmd);
     725        return (0);
     726    }
     727
     728    if (bkpinfo->backup_media_type == nfs) {
     729        log_msg(2, "Mounting for NFS thingy");
     730        log_msg(2, "isodir = %s", bkpinfo->isodir);
     731        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
     732            && am_I_in_disaster_recovery_mode()) {
     733            strcpy(bkpinfo->isodir, "/tmp/isodir");
     734            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
     735        }
    754736#ifdef __FreeBSD__
    755       sprintf (mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number);
    756       mddev = make_vn (mount_cmd);
    757       sprintf (mount_cmd, "mount_cd9660 -r %s "MNT_CDROM, mddev);
     737        sprintf(mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir,
     738                bkpinfo->nfs_remote_dir, g_current_media_number);
     739        mddev = make_vn(mount_cmd);
     740        sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    758741#else
    759       sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number, MNT_CDROM);
     742        sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s",
     743                bkpinfo->isodir, bkpinfo->nfs_remote_dir,
     744                g_current_media_number, MNT_CDROM);
    760745#endif
    761746
    762     }
    763   else
    764 
    765   if (bkpinfo->backup_media_type == iso)
    766     {
     747    } else
     748     if (bkpinfo->backup_media_type == iso) {
    767749#ifdef __FreeBSD__
    768       sprintf (mount_cmd, "%s/%d.iso", bkpinfo->isodir, g_current_media_number);
    769       mddev = make_vn (mount_cmd);
    770       sprintf (mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     750        sprintf(mount_cmd, "%s/%d.iso", bkpinfo->isodir,
     751                g_current_media_number);
     752        mddev = make_vn(mount_cmd);
     753        sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    771754#else
    772       sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, g_current_media_number, MNT_CDROM);
     755        sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s",
     756                bkpinfo->isodir, g_current_media_number, MNT_CDROM);
    773757#endif
    774     }
    775   else if (strstr(bkpinfo->media_device, "/dev/"))
    776 
     758    } else if (strstr(bkpinfo->media_device, "/dev/"))
    777759#ifdef __FreeBSD__
    778     { sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); }
     760    {
     761        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     762                MNT_CDROM);
     763    }
    779764#else
    780     { sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); }
     765    {
     766        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     767                bkpinfo->media_device, MNT_CDROM);
     768    }
    781769#endif
    782770
    783   else
    784     {
    785       if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE"))
    786         { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); }
    787       else
    788         { find_cdrom_device( bkpinfo->media_device, TRUE ); }
     771    else {
     772        if (bkpinfo->disaster_recovery
     773            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     774            strcpy(bkpinfo->media_device,
     775                   last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     776        } else {
     777            find_cdrom_device(bkpinfo->media_device, TRUE);
     778        }
    789779
    790780#ifdef __FreeBSD__
    791       sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
     781        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     782                MNT_CDROM);
    792783#else
    793       sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
     784        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     785                bkpinfo->media_device, MNT_CDROM);
    794786#endif
    795787
    796     }
    797   log_msg(2,"(mount_cdrom) --- command = %s", mount_cmd);
    798   for(i=0;i<2;i++)
    799     {
    800       res=run_program_and_log_output(mount_cmd, FALSE);
    801       if (!res)
    802     {
    803       break;
    804     }
    805       else
    806     {
    807       log_msg(2,"Failed to mount CD-ROM drive.");
    808       sleep(5);
    809       run_program_and_log_output( "sync", FALSE );
    810     }
    811     }
    812   if (res) { log_msg(2,"Failed, despite %d attempts", i); }
    813   else { log_msg(2,"Mounted CD-ROM drive OK"); }
    814   paranoid_free(mount_cmd);
    815   return(res);
     788    }
     789    log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
     790    for (i = 0; i < 2; i++) {
     791        res = run_program_and_log_output(mount_cmd, FALSE);
     792        if (!res) {
     793            break;
     794        } else {
     795            log_msg(2, "Failed to mount CD-ROM drive.");
     796            sleep(5);
     797            run_program_and_log_output("sync", FALSE);
     798        }
     799    }
     800    if (res) {
     801        log_msg(2, "Failed, despite %d attempts", i);
     802    } else {
     803        log_msg(2, "Mounted CD-ROM drive OK");
     804    }
     805    paranoid_free(mount_cmd);
     806    return (res);
    816807}
    817808
     
    833824 * @return 0 for success, nonzero for failure.
    834825 */
    835 int
    836 mount_device( char *device, char *mpt, char *format, bool writeable)
    837 {
    838   int res = 0;
     826int mount_device(char *device, char *mpt, char *format, bool writeable)
     827{
     828    int res = 0;
    839829
    840830  /** malloc **/
    841   char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
    842 
    843   assert_string_is_neither_NULL_nor_zerolength(device);
    844   assert_string_is_neither_NULL_nor_zerolength(mpt);
    845   assert(format!=NULL);
    846   malloc_string(tmp);
    847   malloc_string(command);
    848   malloc_string(mountdir);
    849   malloc_string(mountpoint);
    850   malloc_string(additional_parameters);
    851 
    852       if (!strcmp (mpt, "/1"))
    853       {
    854           strcpy (mountpoint, "/");
    855           log_msg (3,"Mommm! SME is being a dildo!");
    856       }
    857       else
    858       {
    859           strcpy (mountpoint, mpt);
    860       }
    861 
    862   if ( !strcmp(mountpoint,"lvm" ) )
    863     {
    864       return( 0 );
    865     }
    866   if ( !strcmp(mountpoint,"image" ) )
    867     {
    868       return( 0 );
    869     }
    870   sprintf( tmp, "Mounting device %s   ", device );
    871   log_msg( 1, tmp );
    872   if ( writeable )
    873     {
    874       strcpy( additional_parameters, "-o rw");
    875     }
    876   else
    877     {
    878       strcpy( additional_parameters, "-o ro");
    879     }
    880   if (find_home_of_exe("setfattr"))
    881     {
    882       strcat( additional_parameters, ",user_xattr");
    883     }
    884   if (find_home_of_exe("setfacl"))
    885     {
    886       strcat( additional_parameters, ",acl");
    887     }
    888    
    889   if ( !strcmp( mountpoint,"swap" ) )
    890     {
    891       sprintf( command, "swapon %s", device );
    892     }
    893   else
    894     {
    895       if ( !strcmp( mountpoint,"/" ) )
    896         {
    897       strcpy( mountdir, MNT_RESTORING);
    898     }
    899       else
    900         {
    901       sprintf( mountdir, "%s%s", MNT_RESTORING, mountpoint);
    902     }
    903       sprintf( command, "mkdir -p %s", mountdir );
    904       run_program_and_log_output( command, FALSE );
    905       sprintf( command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE );
    906       log_msg(2, "command='%s'", command);
    907     }
    908   res = run_program_and_log_output( command, TRUE );
    909   if ( res && (strstr(command, "xattr") || strstr(command, "acl")))
    910     {
    911       log_msg(1, "Re-trying without the fancy extra parameters");
    912       sprintf( command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE );
    913       res = run_program_and_log_output( command, TRUE );
    914     }
    915   if ( res )
    916     {
    917       log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir );
    918       log_msg(1, "command was '%s'", command);
    919       if ( !strcmp( mountpoint, "swap" ) )
    920         {
    921       log_to_screen( tmp );
    922     }
    923       else
    924     {
    925       log_msg(2, "Retrying w/o the '-t' switch" );
    926       sprintf( command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
    927       log_msg(2, "2nd command = '%s'", command);
    928       res = run_program_and_log_output( command, TRUE );
    929       if (res == 0 )
    930         {
    931           log_msg(1, "That's OK. I called mount w/o a filesystem type and it worked fine in the end." );
    932         }
    933       else
    934         {
    935           log_to_screen( tmp );
    936         }
    937         }
    938     }
    939   if (res && !strcmp( mountpoint, "swap" ))
    940     {
    941      log_msg(2, "That's ok. It's just a swap partition.");
    942      log_msg(2, "Non-fatal error. Returning 0.");
    943      res=0;
    944     }
    945 
    946   paranoid_free(tmp);
    947   paranoid_free(command);
    948   paranoid_free(mountdir);
    949   paranoid_free(mountpoint);
    950   paranoid_free(additional_parameters);
    951 
    952   return( res );
    953 }
     831    char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     832
     833    assert_string_is_neither_NULL_nor_zerolength(device);
     834    assert_string_is_neither_NULL_nor_zerolength(mpt);
     835    assert(format != NULL);
     836    malloc_string(tmp);
     837    malloc_string(command);
     838    malloc_string(mountdir);
     839    malloc_string(mountpoint);
     840    malloc_string(additional_parameters);
     841
     842    if (!strcmp(mpt, "/1")) {
     843        strcpy(mountpoint, "/");
     844        log_msg(3, "Mommm! SME is being a dildo!");
     845    } else {
     846        strcpy(mountpoint, mpt);
     847    }
     848
     849    if (!strcmp(mountpoint, "lvm")) {
     850        return (0);
     851    }
     852    if (!strcmp(mountpoint, "image")) {
     853        return (0);
     854    }
     855    sprintf(tmp, "Mounting device %s   ", device);
     856    log_msg(1, tmp);
     857    if (writeable) {
     858        strcpy(additional_parameters, "-o rw");
     859    } else {
     860        strcpy(additional_parameters, "-o ro");
     861    }
     862    if (find_home_of_exe("setfattr")) {
     863        strcat(additional_parameters, ",user_xattr");
     864    }
     865    if (find_home_of_exe("setfacl")) {
     866        strcat(additional_parameters, ",acl");
     867    }
     868
     869    if (!strcmp(mountpoint, "swap")) {
     870        sprintf(command, "swapon %s", device);
     871    } else {
     872        if (!strcmp(mountpoint, "/")) {
     873            strcpy(mountdir, MNT_RESTORING);
     874        } else {
     875            sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
     876        }
     877        sprintf(command, "mkdir -p %s", mountdir);
     878        run_program_and_log_output(command, FALSE);
     879        sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
     880                additional_parameters, mountdir, MONDO_LOGFILE);
     881        log_msg(2, "command='%s'", command);
     882    }
     883    res = run_program_and_log_output(command, TRUE);
     884    if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
     885        log_msg(1, "Re-trying without the fancy extra parameters");
     886        sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
     887                mountdir, MONDO_LOGFILE);
     888        res = run_program_and_log_output(command, TRUE);
     889    }
     890    if (res) {
     891        log_msg(1, "Unable to mount device %s (type %s) at %s", device,
     892                format, mountdir);
     893        log_msg(1, "command was '%s'", command);
     894        if (!strcmp(mountpoint, "swap")) {
     895            log_to_screen(tmp);
     896        } else {
     897            log_msg(2, "Retrying w/o the '-t' switch");
     898            sprintf(command, "mount %s %s 2>> %s", device, mountdir,
     899                    MONDO_LOGFILE);
     900            log_msg(2, "2nd command = '%s'", command);
     901            res = run_program_and_log_output(command, TRUE);
     902            if (res == 0) {
     903                log_msg(1,
     904                        "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
     905            } else {
     906                log_to_screen(tmp);
     907            }
     908        }
     909    }
     910    if (res && !strcmp(mountpoint, "swap")) {
     911        log_msg(2, "That's ok. It's just a swap partition.");
     912        log_msg(2, "Non-fatal error. Returning 0.");
     913        res = 0;
     914    }
     915
     916    paranoid_free(tmp);
     917    paranoid_free(command);
     918    paranoid_free(mountdir);
     919    paranoid_free(mountpoint);
     920    paranoid_free(additional_parameters);
     921
     922    return (res);
     923}
     924
    954925/**************************************************************************
    955926 *END_MOUNT_DEVICE                                                        *
     
    962933 * up correctly on the first boot.
    963934 */
    964 void
    965 protect_against_braindead_sysadmins()
    966 {
    967   run_program_and_log_output( "touch " MNT_RESTORING "/var/log/pacct", FALSE );
    968   run_program_and_log_output( "touch " MNT_RESTORING "/var/account/pacct", FALSE );
    969   if (run_program_and_log_output( "ls " MNT_RESTORING" /tmp", FALSE ) )
    970      {
    971       run_program_and_log_output( "chmod 1777 " MNT_RESTORING "/tmp", FALSE );
    972     }
    973   run_program_and_log_output( "mkdir -p " MNT_RESTORING "/var/run/console", FALSE );
    974   run_program_and_log_output( "chmod 777 " MNT_RESTORING "/dev/null", FALSE );
    975   run_program_and_log_output( "cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", TRUE);
    976   run_program_and_log_output( "rm -f " MNT_RESTORING "/var/run/*.pid", TRUE);
    977   run_program_and_log_output( "rm -f " MNT_RESTORING "/var/lock/subsys/*", TRUE);
    978 }
     935void protect_against_braindead_sysadmins()
     936{
     937    run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
     938                               FALSE);
     939    run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
     940                               FALSE);
     941    if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
     942        run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
     943                                   FALSE);
     944    }
     945    run_program_and_log_output("mkdir -p " MNT_RESTORING
     946                               "/var/run/console", FALSE);
     947    run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
     948                               FALSE);
     949    run_program_and_log_output("cd " MNT_RESTORING
     950                               "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done",
     951                               TRUE);
     952    run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
     953                               TRUE);
     954    run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
     955                               TRUE);
     956}
     957
    979958/**************************************************************************
    980959 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
     
    991970 * @return 0 for success, nonzero for failure.
    992971 */
    993 int
    994 read_cfg_file_into_bkpinfo( char* cfgf, struct s_bkpinfo *bkpinfo)
     972int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
    995973{
    996974  /** add mallocs **/
    997   char *value;
    998   char *tmp;
    999       char *command;
    1000       char *iso_mnt;
    1001       char *iso_path;
    1002       char *old_isodir;
    1003       char cfg_file[100];
    1004   t_bkptype media_specified_by_user;
    1005 
    1006   malloc_string(command);
    1007   malloc_string(iso_mnt);
    1008   malloc_string(iso_path);
    1009   malloc_string(old_isodir);
    1010   malloc_string(value);
    1011   malloc_string(tmp);
     975    char *value;
     976    char *tmp;
     977    char *command;
     978    char *iso_mnt;
     979    char *iso_path;
     980    char *old_isodir;
     981    char cfg_file[100];
     982    t_bkptype media_specified_by_user;
     983
     984    malloc_string(command);
     985    malloc_string(iso_mnt);
     986    malloc_string(iso_path);
     987    malloc_string(old_isodir);
     988    malloc_string(value);
     989    malloc_string(tmp);
    1012990//  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
    1013   assert(bkpinfo!=NULL);
    1014 
    1015   if (!cfgf)
    1016     { strcpy(cfg_file, g_mondo_cfg_file); }
    1017   else
    1018     { strcpy(cfg_file, cfgf); }
    1019 
    1020   media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
    1021 
    1022   if (0 == read_cfg_var(cfg_file, "backup-media-type", value))
    1023     {
    1024       if ( !strcmp(value, "cdstream" ) )
    1025     {
    1026       bkpinfo->backup_media_type = cdstream;
    1027     }
    1028       else if (!strcmp(value, "cdr"))
    1029     {
    1030       bkpinfo->backup_media_type = cdr;
    1031     }
    1032       else if (!strcmp(value, "cdrw"))
    1033     {
    1034       bkpinfo->backup_media_type = cdrw;
    1035     }
    1036       else if (!strcmp(value, "dvd"))
    1037     {
    1038       bkpinfo->backup_media_type = dvd;
    1039     }
    1040       else if (!strcmp(value, "iso"))
    1041     {
     991    assert(bkpinfo != NULL);
     992
     993    if (!cfgf) {
     994        strcpy(cfg_file, g_mondo_cfg_file);
     995    } else {
     996        strcpy(cfg_file, cfgf);
     997    }
     998
     999    media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
     1000
     1001    if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
     1002        if (!strcmp(value, "cdstream")) {
     1003            bkpinfo->backup_media_type = cdstream;
     1004        } else if (!strcmp(value, "cdr")) {
     1005            bkpinfo->backup_media_type = cdr;
     1006        } else if (!strcmp(value, "cdrw")) {
     1007            bkpinfo->backup_media_type = cdrw;
     1008        } else if (!strcmp(value, "dvd")) {
     1009            bkpinfo->backup_media_type = dvd;
     1010        } else if (!strcmp(value, "iso")) {
    10421011/*
    10431012      if (am_I_in_disaster_recovery_mode()
     
    10471016
    10481017// Patch by Conor Daly - 2004/07/12
    1049           bkpinfo->backup_media_type = iso;
    1050           if (am_I_in_disaster_recovery_mode())
    1051         {
    1052  /* Check to see if CD is already mounted before mounting it... */
    1053               if (!is_this_device_mounted("/dev/cdrom"))
    1054             {
    1055                   log_msg(2, "NB: CDROM device not mounted, mounting...");
    1056                   run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
    1057                 }
    1058               if( does_file_exist(MNT_CDROM"/archives/filelist.0"))
     1018            bkpinfo->backup_media_type = iso;
     1019            if (am_I_in_disaster_recovery_mode()) {
     1020                /* Check to see if CD is already mounted before mounting it... */
     1021                if (!is_this_device_mounted("/dev/cdrom")) {
     1022                    log_msg(2,
     1023                            "NB: CDROM device not mounted, mounting...");
     1024                    run_program_and_log_output("mount /dev/cdrom "
     1025                                               MNT_CDROM, 1);
     1026                }
     1027                if (does_file_exist(MNT_CDROM "/archives/filelist.0"))
    10591028// End patch
    1060             {
    1061                   bkpinfo->backup_media_type = cdr;
    1062               run_program_and_log_output("umount "MNT_CDROM, 1);
    1063               log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
    1064                 }
    1065           else
    1066             {
    1067               bkpinfo->backup_media_type = iso;
    1068             }
    1069         }
    1070     }
    1071       else if (!strcmp(value, "nfs"))
    1072     {
    1073       bkpinfo->backup_media_type = nfs;
    1074     }
    1075       else if (!strcmp(value, "tape"))
    1076     {
    1077       bkpinfo->backup_media_type = tape;
    1078     }
    1079       else if (!strcmp(value, "udev"))
    1080     {
    1081       bkpinfo->backup_media_type = udev;
    1082     }
    1083       else
    1084     {
    1085       fatal_error("UNKNOWN bkp-media-type");
    1086     }
    1087     }
    1088   else
    1089     {
    1090       fatal_error("backup-media-type not specified!");
    1091     }
    1092   if (bkpinfo->disaster_recovery)
    1093     {
    1094       if (bkpinfo->backup_media_type == cdstream)
    1095         {
    1096           sprintf(bkpinfo->media_device, "/dev/cdrom");
     1029                {
     1030                    bkpinfo->backup_media_type = cdr;
     1031                    run_program_and_log_output("umount " MNT_CDROM, 1);
     1032                    log_it
     1033                        ("Re-jigging configuration AGAIN. CD-R, not ISO.");
     1034                } else {
     1035                    bkpinfo->backup_media_type = iso;
     1036                }
     1037            }
     1038        } else if (!strcmp(value, "nfs")) {
     1039            bkpinfo->backup_media_type = nfs;
     1040        } else if (!strcmp(value, "tape")) {
     1041            bkpinfo->backup_media_type = tape;
     1042        } else if (!strcmp(value, "udev")) {
     1043            bkpinfo->backup_media_type = udev;
     1044        } else {
     1045            fatal_error("UNKNOWN bkp-media-type");
     1046        }
     1047    } else {
     1048        fatal_error("backup-media-type not specified!");
     1049    }
     1050    if (bkpinfo->disaster_recovery) {
     1051        if (bkpinfo->backup_media_type == cdstream) {
     1052            sprintf(bkpinfo->media_device, "/dev/cdrom");
    10971053//          bkpinfo->media_size[0] = -1;
    1098           bkpinfo->media_size[0] = 1999*1024;
    1099           bkpinfo->media_size[1] = 650; /* good guess */
    1100         }
    1101       else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    1102         {
    1103           if (read_cfg_var(cfg_file, "media-dev", value)) { fatal_error("Cannot get tape device name from cfg file"); }
    1104           strcpy(bkpinfo->media_device, value);
    1105           read_cfg_var(cfg_file, "media-size", value);
    1106           bkpinfo->media_size[1] = atol(value);
    1107           sprintf(tmp,"Backup medium is TAPE --- dev=%s",bkpinfo->media_device);
    1108           log_msg(2, tmp);
    1109         }
    1110        else
    1111          {
    1112            strcpy(bkpinfo->media_device,"/dev/cdrom"); /* we don't really need this var */
    1113            bkpinfo->media_size[0]= 1999*1024; /* 650, probably, but we don't need this var anyway */
    1114            bkpinfo->media_size[1]=1999*1024; /* 650, probably, but we don't need this var anyway */
    1115            log_msg(2, "Backup medium is CD-R[W]");
    1116          }
    1117       }
    1118   else
    1119     {
    1120       log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
    1121     }
    1122  
    1123   read_cfg_var(cfg_file, "use-star", value);
    1124   if (strstr(value,"yes"))
    1125     {
    1126       bkpinfo->use_star = TRUE;
    1127       log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
    1128     }
    1129 
    1130   if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value))
    1131     {
    1132       bkpinfo->internal_tape_block_size = atol(value);
    1133       log_msg(1, "Internal tape block size has been custom-set to %ld", bkpinfo->internal_tape_block_size);
    1134     }
    1135   else
    1136     {
    1137       bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    1138       log_msg(1, "Internal tape block size = default (%ld)", DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
    1139     }
    1140 
    1141   read_cfg_var(cfg_file, "use-lzo", value);
    1142   if (strstr(value,"yes"))
    1143     {
    1144       bkpinfo->use_lzo = TRUE;
    1145       strcpy(bkpinfo->zip_exe, "lzop");
    1146       strcpy(bkpinfo->zip_suffix, "lzo");
    1147     }
    1148   else
    1149     {
    1150       read_cfg_var(cfg_file, "use-comp", value);
    1151       if (strstr(value,"yes"))
    1152     {
    1153       bkpinfo->use_lzo = FALSE;
    1154       strcpy(bkpinfo->zip_exe, "bzip2");
    1155       strcpy(bkpinfo->zip_suffix, "bz2");
    1156     }
    1157       else
    1158     {
    1159       bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    1160     }
    1161     }
    1162 
    1163   value[0] = '\0';
    1164   read_cfg_var( cfg_file, "differential", value);
    1165   if (!strcmp(value, "yes") || !strcmp(value, "1"))
    1166     {
    1167       bkpinfo->differential = TRUE;
    1168     }
    1169   log_msg(2, "differential var = '%s'", value);
    1170   if (bkpinfo->differential)
    1171     {
    1172       log_msg(2, "THIS IS A DIFFERENTIAL BACKUP" );
    1173     }
    1174   else
    1175     {
    1176       log_msg(2, "This is a regular (full) backup");
    1177     }
    1178 
    1179   read_cfg_var( g_mondo_cfg_file, "please-dont-eject", tmp);
    1180   if (tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject"))
    1181     { bkpinfo->please_dont_eject = TRUE; log_msg(2, "Ok, I shan't eject when restoring! Groovy."); }
    1182 
    1183   if (bkpinfo->backup_media_type == nfs)
    1184     {
    1185       if (!cfgf)
    1186         {
    1187           log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
    1188           log_msg(2, "nfs_remote_dir remains %s", bkpinfo->nfs_remote_dir);
    1189       log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
    1190     }
    1191       else
    1192         {
    1193           read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", bkpinfo->nfs_mount);
    1194           read_cfg_var(g_mondo_cfg_file, "nfs-server-path", bkpinfo->nfs_remote_dir);
    1195           log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
    1196           log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
    1197     }
    1198     }
    1199   else if (bkpinfo->backup_media_type == iso)
    1200     {
    1201  /* Patch by Conor Daly 23-june-2004
    1202   * to correctly mount iso-dev and set a sensible
    1203   * isodir in disaster recovery mode
    1204   */
    1205       strcpy (old_isodir, bkpinfo->isodir);
    1206       read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    1207       read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
    1208       sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1209       if (!bkpinfo->isodir[0]) {
    1210       strcpy (bkpinfo->isodir, old_isodir);
    1211       }
    1212       if (!bkpinfo->disaster_recovery)
    1213         {
    1214         if (strcmp(old_isodir, bkpinfo->isodir)) {
    1215           log_it("user nominated isodir differs from archive, keeping user's choice: %s %s\n", old_isodir, bkpinfo->isodir);
    1216         strcpy (bkpinfo->isodir, old_isodir);
    1217         }
    1218         }
    1219       read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    1220       log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
    1221       if (bkpinfo->disaster_recovery) {
    1222       if (is_this_device_mounted(g_isodir_device))
    1223           { log_msg(2, "NB: isodir is already mounted");
    1224         /* Find out where it's mounted */
    1225          sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", g_isodir_device);
    1226         log_it("command = %s", command);
    1227         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    1228         sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    1229           }
    1230       else
    1231           {
    1232           sprintf(iso_mnt, "/tmp/isodir");
    1233           sprintf(tmp, "mkdir -p %s", iso_mnt);
    1234           run_program_and_log_output(tmp, 5);
    1235           sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
    1236           if (run_program_and_log_output(tmp, 3))
    1237               {
    1238                 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
    1239             bkpinfo->backup_media_type = cdr;
    1240             strcpy(bkpinfo->media_device,"/dev/cdrom"); /* superfluous */
    1241             bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    1242             if ( mount_cdrom( bkpinfo ) )
    1243               {
    1244                     fatal_error( "Unable to mount isodir. Failed to mount CD-ROM as well.");
    1245               }
    1246             else
    1247               {
    1248                 log_msg(1, "You backed up to disk, then burned some CDs. Naughty monkey!" );
    1249               }
    1250               }
    1251           }
    1252       /* bkpinfo->isodir should now be the true path to 1.iso etc... */
    1253       if (bkpinfo->backup_media_type == iso)
    1254         {
    1255               sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1256         }
    1257       }
    1258     }
    1259 
    1260   if (media_specified_by_user != none)
    1261     {
    1262       if (g_restoring_live_from_cd)
    1263         {
    1264           if (bkpinfo->backup_media_type != media_specified_by_user)
    1265             {
    1266               log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
    1267               interactively_obtain_media_parameters_from_user( bkpinfo, FALSE);
    1268               media_specified_by_user = bkpinfo->backup_media_type;
    1269               get_cfg_file_from_archive(bkpinfo);
     1054            bkpinfo->media_size[0] = 1999 * 1024;
     1055            bkpinfo->media_size[1] = 650;   /* good guess */
     1056        } else if (bkpinfo->backup_media_type == tape
     1057                   || bkpinfo->backup_media_type == udev) {
     1058            if (read_cfg_var(cfg_file, "media-dev", value)) {
     1059                fatal_error("Cannot get tape device name from cfg file");
     1060            }
     1061            strcpy(bkpinfo->media_device, value);
     1062            read_cfg_var(cfg_file, "media-size", value);
     1063            bkpinfo->media_size[1] = atol(value);
     1064            sprintf(tmp, "Backup medium is TAPE --- dev=%s",
     1065                    bkpinfo->media_device);
     1066            log_msg(2, tmp);
     1067        } else {
     1068            strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     1069            bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1070            bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1071            log_msg(2, "Backup medium is CD-R[W]");
     1072        }
     1073    } else {
     1074        log_msg(2,
     1075                "Not in Disaster Recovery Mode. No need to derive device name from config file.");
     1076    }
     1077
     1078    read_cfg_var(cfg_file, "use-star", value);
     1079    if (strstr(value, "yes")) {
     1080        bkpinfo->use_star = TRUE;
     1081        log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
     1082    }
     1083
     1084    if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
     1085        bkpinfo->internal_tape_block_size = atol(value);
     1086        log_msg(1, "Internal tape block size has been custom-set to %ld",
     1087                bkpinfo->internal_tape_block_size);
     1088    } else {
     1089        bkpinfo->internal_tape_block_size =
     1090            DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     1091        log_msg(1, "Internal tape block size = default (%ld)",
     1092                DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
     1093    }
     1094
     1095    read_cfg_var(cfg_file, "use-lzo", value);
     1096    if (strstr(value, "yes")) {
     1097        bkpinfo->use_lzo = TRUE;
     1098        strcpy(bkpinfo->zip_exe, "lzop");
     1099        strcpy(bkpinfo->zip_suffix, "lzo");
     1100    } else {
     1101        read_cfg_var(cfg_file, "use-comp", value);
     1102        if (strstr(value, "yes")) {
     1103            bkpinfo->use_lzo = FALSE;
     1104            strcpy(bkpinfo->zip_exe, "bzip2");
     1105            strcpy(bkpinfo->zip_suffix, "bz2");
     1106        } else {
     1107            bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     1108        }
     1109    }
     1110
     1111    value[0] = '\0';
     1112    read_cfg_var(cfg_file, "differential", value);
     1113    if (!strcmp(value, "yes") || !strcmp(value, "1")) {
     1114        bkpinfo->differential = TRUE;
     1115    }
     1116    log_msg(2, "differential var = '%s'", value);
     1117    if (bkpinfo->differential) {
     1118        log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
     1119    } else {
     1120        log_msg(2, "This is a regular (full) backup");
     1121    }
     1122
     1123    read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
     1124    if (tmp[0]
     1125        ||
     1126        strstr(call_program_and_get_last_line_of_output
     1127               ("cat /proc/cmdline"), "donteject")) {
     1128        bkpinfo->please_dont_eject = TRUE;
     1129        log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
     1130    }
     1131
     1132    if (bkpinfo->backup_media_type == nfs) {
     1133        if (!cfgf) {
     1134            log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
     1135            log_msg(2, "nfs_remote_dir remains %s",
     1136                    bkpinfo->nfs_remote_dir);
     1137            log_msg(2,
     1138                    "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
     1139        } else {
     1140            read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
     1141                         bkpinfo->nfs_mount);
     1142            read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
     1143                         bkpinfo->nfs_remote_dir);
     1144            log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
     1145            log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
     1146        }
     1147    } else if (bkpinfo->backup_media_type == iso) {
     1148        /* Patch by Conor Daly 23-june-2004
     1149         * to correctly mount iso-dev and set a sensible
     1150         * isodir in disaster recovery mode
     1151         */
     1152        strcpy(old_isodir, bkpinfo->isodir);
     1153        read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
     1154        read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
     1155        sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1156        if (!bkpinfo->isodir[0]) {
     1157            strcpy(bkpinfo->isodir, old_isodir);
     1158        }
     1159        if (!bkpinfo->disaster_recovery) {
     1160            if (strcmp(old_isodir, bkpinfo->isodir)) {
     1161                log_it
     1162                    ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
     1163                     old_isodir, bkpinfo->isodir);
     1164                strcpy(bkpinfo->isodir, old_isodir);
     1165            }
     1166        }
     1167        read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     1168        log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
     1169                g_isodir_device);
     1170        if (bkpinfo->disaster_recovery) {
     1171            if (is_this_device_mounted(g_isodir_device)) {
     1172                log_msg(2, "NB: isodir is already mounted");
     1173                /* Find out where it's mounted */
     1174                sprintf(command,
     1175                        "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     1176                        g_isodir_device);
     1177                log_it("command = %s", command);
     1178                log_it("res of it = %s",
     1179                       call_program_and_get_last_line_of_output(command));
     1180                sprintf(iso_mnt, "%s",
     1181                        call_program_and_get_last_line_of_output(command));
     1182            } else {
     1183                sprintf(iso_mnt, "/tmp/isodir");
     1184                sprintf(tmp, "mkdir -p %s", iso_mnt);
     1185                run_program_and_log_output(tmp, 5);
     1186                sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
     1187                if (run_program_and_log_output(tmp, 3)) {
     1188                    log_msg(1,
     1189                            "Unable to mount isodir. Perhaps this is really a CD backup?");
     1190                    bkpinfo->backup_media_type = cdr;
     1191                    strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
     1192                    bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
     1193                    if (mount_cdrom(bkpinfo)) {
     1194                        fatal_error
     1195                            ("Unable to mount isodir. Failed to mount CD-ROM as well.");
     1196                    } else {
     1197                        log_msg(1,
     1198                                "You backed up to disk, then burned some CDs. Naughty monkey!");
     1199                    }
     1200                }
     1201            }
     1202            /* bkpinfo->isodir should now be the true path to 1.iso etc... */
     1203            if (bkpinfo->backup_media_type == iso) {
     1204                sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1205            }
     1206        }
     1207    }
     1208
     1209    if (media_specified_by_user != none) {
     1210        if (g_restoring_live_from_cd) {
     1211            if (bkpinfo->backup_media_type != media_specified_by_user) {
     1212                log_msg(2,
     1213                        "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
     1214                interactively_obtain_media_parameters_from_user(bkpinfo,
     1215                                                                FALSE);
     1216                media_specified_by_user = bkpinfo->backup_media_type;
     1217                get_cfg_file_from_archive(bkpinfo);
    12701218/*
    12711219              if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
    12721220                { g_restoring_live_from_cd = FALSE; }
    12731221*/
    1274             }
    1275         }
    1276       bkpinfo->backup_media_type = media_specified_by_user;
    1277    }
    1278   g_backup_media_type = bkpinfo->backup_media_type;
    1279   paranoid_free(value);
    1280   paranoid_free(tmp);
    1281   paranoid_free(command);
    1282   paranoid_free(iso_mnt);
    1283   paranoid_free(iso_path);
    1284   paranoid_free(old_isodir);
    1285   return( 0 );
    1286 
    1287 }
     1222            }
     1223        }
     1224        bkpinfo->backup_media_type = media_specified_by_user;
     1225    }
     1226    g_backup_media_type = bkpinfo->backup_media_type;
     1227    paranoid_free(value);
     1228    paranoid_free(tmp);
     1229    paranoid_free(command);
     1230    paranoid_free(iso_mnt);
     1231    paranoid_free(iso_path);
     1232    paranoid_free(old_isodir);
     1233    return (0);
     1234
     1235}
     1236
    12881237/**************************************************************************
    12891238 *END_READ_CFG_FILE_INTO_BKPINFO                                          *
     
    12911240
    12921241
    1293  
     1242
    12941243
    12951244/**
     
    13041253 */
    13051254struct
    1306 s_node *process_filelist_and_biggielist( struct s_bkpinfo *bkpinfo )
    1307 {
    1308   struct s_node *filelist;
     1255s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo)
     1256{
     1257    struct s_node *filelist;
    13091258
    13101259  /** add mallocs**/
    1311   char *command;
    1312   char *tmp;
    1313   int res=0;
    1314   pid_t pid;
    1315 
    1316   assert(bkpinfo!=NULL);
    1317   malloc_string(command);
    1318   malloc_string(tmp);
    1319 
    1320   if ( does_file_exist( g_filelist_full ) && does_file_exist( g_biggielist_txt ) )
    1321     {
    1322       log_msg(1, "%s exists", g_filelist_full);
    1323       log_msg(1, "%s exists", g_biggielist_txt);
    1324       log_msg(2, "Filelist and biggielist already recovered from media. Yay!" );
    1325     }
    1326   else
    1327     {
    1328       getcwd( tmp, MAX_STR_LEN );
    1329       chdir( bkpinfo->tmpdir );
    1330       log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
    1331       log_to_screen( "Extracting filelist and biggielist from media..." );
    1332       unlink("/tmp/filelist.full");
    1333       unlink("/" FILELIST_FULL_STUB);
    1334       unlink("/tmp/i-want-my-lvm");
    1335       if ( IS_THIS_A_STREAMING_BACKUP( bkpinfo->backup_media_type ) )
    1336         {
    1337       sprintf( command,
    1338            "tar -zxf %s %s %s %s %s %s",
    1339            bkpinfo->media_device,
    1340            MOUNTLIST_FNAME_STUB,
    1341            BIGGIELIST_TXT_STUB,
    1342            FILELIST_FULL_STUB,
    1343            "tmp/i-want-my-lvm",
    1344            MONDO_CFG_FILE_STUB);
    1345           log_msg(1, "tarcommand = %s", command);
    1346           run_program_and_log_output( command, 1 );
    1347         }
    1348       else
    1349         {
    1350           log_msg(2,"Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
    1351       insist_on_this_cd_number( bkpinfo, 1 );
    1352           log_msg(2, "Back from iotcn");
    1353       run_program_and_log_output("mount", 1);
    1354           sprintf( command,
    1355            "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
    1356            MNT_CDROM,
    1357            MOUNTLIST_FNAME_STUB,
    1358            BIGGIELIST_TXT_STUB,
    1359            FILELIST_FULL_STUB,
    1360            "tmp/i-want-my-lvm",
    1361            MONDO_CFG_FILE_STUB);
    1362 
    1363           log_msg(1, "tarcommand = %s", command);
    1364       run_program_and_log_output(command, 1);
    1365 //    popup_and_OK("Press ENTER to continue");
    1366           if ( !does_file_exist( BIGGIELIST_TXT_STUB ) )
    1367             {
    1368           fatal_error( "all.tar.gz did not include tmp/biggielist.txt");
    1369         }
    1370           if ( !does_file_exist( FILELIST_FULL_STUB ) )
    1371             {
    1372           fatal_error( "all.tar.gz did not include tmp/filelist.full.gz");
    1373         }
    1374         }
    1375       sprintf( command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file );
    1376       run_program_and_log_output( command, FALSE );
    1377 
    1378       sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
    1379       log_msg(1, "command = %s", command);
    1380       paranoid_system(command);
    1381       sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
    1382       log_msg(1, "command = %s", command);
    1383       paranoid_system(command);
    1384     }
    1385 
    1386   if (am_I_in_disaster_recovery_mode() && ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
    1387     {
     1260    char *command;
     1261    char *tmp;
     1262    int res = 0;
     1263    pid_t pid;
     1264
     1265    assert(bkpinfo != NULL);
     1266    malloc_string(command);
     1267    malloc_string(tmp);
     1268
     1269    if (does_file_exist(g_filelist_full)
     1270        && does_file_exist(g_biggielist_txt)) {
     1271        log_msg(1, "%s exists", g_filelist_full);
     1272        log_msg(1, "%s exists", g_biggielist_txt);
     1273        log_msg(2,
     1274                "Filelist and biggielist already recovered from media. Yay!");
     1275    } else {
     1276        getcwd(tmp, MAX_STR_LEN);
     1277        chdir(bkpinfo->tmpdir);
     1278        log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
     1279        log_to_screen("Extracting filelist and biggielist from media...");
     1280        unlink("/tmp/filelist.full");
     1281        unlink("/" FILELIST_FULL_STUB);
     1282        unlink("/tmp/i-want-my-lvm");
     1283        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1284            sprintf(command,
     1285                    "tar -zxf %s %s %s %s %s %s",
     1286                    bkpinfo->media_device,
     1287                    MOUNTLIST_FNAME_STUB,
     1288                    BIGGIELIST_TXT_STUB,
     1289                    FILELIST_FULL_STUB,
     1290                    "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1291            log_msg(1, "tarcommand = %s", command);
     1292            run_program_and_log_output(command, 1);
     1293        } else {
     1294            log_msg(2,
     1295                    "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
     1296                    bkpinfo->isodir);
     1297            insist_on_this_cd_number(bkpinfo, 1);
     1298            log_msg(2, "Back from iotcn");
     1299            run_program_and_log_output("mount", 1);
     1300            sprintf(command,
     1301                    "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
     1302                    MNT_CDROM,
     1303                    MOUNTLIST_FNAME_STUB,
     1304                    BIGGIELIST_TXT_STUB,
     1305                    FILELIST_FULL_STUB,
     1306                    "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1307
     1308            log_msg(1, "tarcommand = %s", command);
     1309            run_program_and_log_output(command, 1);
     1310//    popup_and_OK("Press ENTER to continue");
     1311            if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
     1312                fatal_error
     1313                    ("all.tar.gz did not include tmp/biggielist.txt");
     1314            }
     1315            if (!does_file_exist(FILELIST_FULL_STUB)) {
     1316                fatal_error
     1317                    ("all.tar.gz did not include tmp/filelist.full.gz");
     1318            }
     1319        }
     1320        sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
     1321                g_mondo_cfg_file);
     1322        run_program_and_log_output(command, FALSE);
     1323
     1324        sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
     1325                BIGGIELIST_TXT_STUB, g_biggielist_txt);
     1326        log_msg(1, "command = %s", command);
     1327        paranoid_system(command);
     1328        sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
     1329                FILELIST_FULL_STUB, g_filelist_full);
     1330        log_msg(1, "command = %s", command);
     1331        paranoid_system(command);
     1332    }
     1333
     1334    if (am_I_in_disaster_recovery_mode()
     1335        &&
     1336        ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
     1337    {
    13881338//      sprintf(command, "cp -f tmp/mountlist.txt /tmp");
    1389       sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
    1390       paranoid_system(command);
    1391     }
    1392 
    1393   chdir( tmp );
    1394 
    1395   if (!does_file_exist( g_biggielist_txt) )
    1396     {
    1397       log_msg(1, "Warning - %s not found", g_biggielist_txt);
    1398     }
    1399   if (!does_file_exist(g_filelist_full) )
    1400     {
    1401       log_msg(1, "Warning - %s does not exist", g_filelist_full);
    1402     }
    1403 
     1339        sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
     1340                bkpinfo->tmpdir);
     1341        paranoid_system(command);
     1342    }
     1343
     1344    chdir(tmp);
     1345
     1346    if (!does_file_exist(g_biggielist_txt)) {
     1347        log_msg(1, "Warning - %s not found", g_biggielist_txt);
     1348    }
     1349    if (!does_file_exist(g_filelist_full)) {
     1350        log_msg(1, "Warning - %s does not exist", g_filelist_full);
     1351    }
    14041352//  popup_and_OK("Wonderful.");
    14051353
    1406   log_msg(2, "Forking" );
    1407   pid = fork();
    1408   switch( pid )
    1409     {
    1410     case -1:
    1411       fatal_error("Forking error");
    1412       break;
    1413 
    1414     case 0:
    1415       log_to_screen("Pre-processing filelist");
    1416       if (!does_file_exist(g_biggielist_txt))
    1417     {
    1418       sprintf(command,"> %s",g_biggielist_txt);
    1419       paranoid_system(command);
    1420     }
    1421       sprintf(command,"cat %s | grep  -x \"/dev/.*\" > %s", g_biggielist_txt, g_filelist_imagedevs);
    1422       paranoid_system(command);
    1423       exit( 0 );
    1424       break;
    1425 
    1426     default:
    1427       open_evalcall_form("Pre-processing filelist");
    1428       while( !waitpid( pid, (int*)0, WNOHANG ) )
    1429     {
    1430       usleep( 100000 );
    1431       update_evalcall_form( 0 );
    1432     }
    1433     }
    1434   close_evalcall_form();
    1435 
    1436   log_msg(3, "loading filelist");
    1437   filelist = load_filelist( g_filelist_full );
    1438   log_msg(3, "deleting original filelist");
    1439   unlink(g_filelist_full);
    1440   if (g_text_mode)
    1441     {
    1442       printf("Restore which directory? --> ");
    1443       fgets(tmp, sizeof(tmp), stdin);
    1444       toggle_path_selection (filelist, tmp, TRUE);
    1445       if (strlen(tmp)==0) { res=1; } else { res=0; }
    1446     }
    1447   else
    1448     {
    1449       res = edit_filelist( filelist );
    1450     }
    1451   if (res)
    1452     {
    1453       log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
    1454       free_filelist( filelist );
    1455       return( NULL );
    1456     }
    1457   ask_about_these_imagedevs( g_filelist_imagedevs, g_imagedevs_restthese );
    1458   close_evalcall_form();
    1459 
    1460   // NB: It's not necessary to add g_biggielist_txt to the filelist.full
    1461   // file. The filelist.full file already contains the filename of EVERY
    1462   // file backed up - regular and biggie files.
    1463 
    1464   // However, we do want to make sure the imagedevs selected by the user
    1465   // are flagged for restoring.
    1466   if ( length_of_file( g_imagedevs_restthese ) > 2 )
    1467     { add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, TRUE); }
    1468 
    1469   paranoid_free(command);
    1470   paranoid_free(tmp);
    1471   return( filelist );
    1472 }
     1354    log_msg(2, "Forking");
     1355    pid = fork();
     1356    switch (pid) {
     1357    case -1:
     1358        fatal_error("Forking error");
     1359        break;
     1360
     1361    case 0:
     1362        log_to_screen("Pre-processing filelist");
     1363        if (!does_file_exist(g_biggielist_txt)) {
     1364            sprintf(command, "> %s", g_biggielist_txt);
     1365            paranoid_system(command);
     1366        }
     1367        sprintf(command, "cat %s | grep  -x \"/dev/.*\" > %s",
     1368                g_biggielist_txt, g_filelist_imagedevs);
     1369        paranoid_system(command);
     1370        exit(0);
     1371        break;
     1372
     1373    default:
     1374        open_evalcall_form("Pre-processing filelist");
     1375        while (!waitpid(pid, (int *) 0, WNOHANG)) {
     1376            usleep(100000);
     1377            update_evalcall_form(0);
     1378        }
     1379    }
     1380    close_evalcall_form();
     1381
     1382    log_msg(3, "loading filelist");
     1383    filelist = load_filelist(g_filelist_full);
     1384    log_msg(3, "deleting original filelist");
     1385    unlink(g_filelist_full);
     1386    if (g_text_mode) {
     1387        printf("Restore which directory? --> ");
     1388        fgets(tmp, sizeof(tmp), stdin);
     1389        toggle_path_selection(filelist, tmp, TRUE);
     1390        if (strlen(tmp) == 0) {
     1391            res = 1;
     1392        } else {
     1393            res = 0;
     1394        }
     1395    } else {
     1396        res = edit_filelist(filelist);
     1397    }
     1398    if (res) {
     1399        log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
     1400        free_filelist(filelist);
     1401        return (NULL);
     1402    }
     1403    ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
     1404    close_evalcall_form();
     1405
     1406    // NB: It's not necessary to add g_biggielist_txt to the filelist.full
     1407    // file. The filelist.full file already contains the filename of EVERY
     1408    // file backed up - regular and biggie files.
     1409
     1410    // However, we do want to make sure the imagedevs selected by the user
     1411    // are flagged for restoring.
     1412    if (length_of_file(g_imagedevs_restthese) > 2) {
     1413        add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
     1414                                      TRUE);
     1415    }
     1416
     1417    paranoid_free(command);
     1418    paranoid_free(tmp);
     1419    return (filelist);
     1420}
     1421
    14731422/**************************************************************************
    14741423 *END_ PROCESS_FILELIST_AND_BIGGIELIST                                    *
     
    14851434 * @return 0 for success, nonzero for failure.
    14861435 */
    1487 int backup_crucial_file(char *path_root, char*filename)
    1488 {
    1489   char *tmp;
    1490   char *command;
    1491   int res;
    1492  
    1493   malloc_string(tmp);
    1494   malloc_string(command);
    1495   assert(path_root!=NULL);
    1496   assert_string_is_neither_NULL_nor_zerolength(filename);
    1497 
    1498   sprintf(tmp, "%s/%s", path_root, filename);
    1499   sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
    1500  
    1501   res = run_program_and_log_output(command, 5);
    1502   paranoid_free(tmp);
    1503   paranoid_free(command);
    1504   return(res);
     1436int backup_crucial_file(char *path_root, char *filename)
     1437{
     1438    char *tmp;
     1439    char *command;
     1440    int res;
     1441
     1442    malloc_string(tmp);
     1443    malloc_string(command);
     1444    assert(path_root != NULL);
     1445    assert_string_is_neither_NULL_nor_zerolength(filename);
     1446
     1447    sprintf(tmp, "%s/%s", path_root, filename);
     1448    sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
     1449
     1450    res = run_program_and_log_output(command, 5);
     1451    paranoid_free(tmp);
     1452    paranoid_free(command);
     1453    return (res);
    15051454}
    15061455
     
    15121461 * @return 0 for success, nonzero for failure.
    15131462 */
    1514 int
    1515 run_boot_loader(bool offer_to_hack_scripts)
    1516 {
    1517   int res;
    1518   int retval = 0;
     1463int run_boot_loader(bool offer_to_hack_scripts)
     1464{
     1465    int res;
     1466    int retval = 0;
    15191467
    15201468  /** malloc *******/
    1521   char *device;
    1522   char *tmp;
    1523   char *name;
    1524 
    1525   malloc_string(device);
    1526   malloc_string(tmp);
    1527   malloc_string(name);
    1528   backup_crucial_file( MNT_RESTORING, "/etc/fstab");
    1529   backup_crucial_file( MNT_RESTORING, "/etc/grub.conf");
    1530   backup_crucial_file( MNT_RESTORING, "/etc/lilo.conf");
    1531   backup_crucial_file( MNT_RESTORING, "/etc/elilo.conf");
    1532   read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    1533   read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
    1534   sprintf(tmp,"run_boot_loader: device='%s', name='%s'",device,name);
    1535   log_msg(2, tmp);
    1536   system("sync");
    1537   if (!strcmp(name,"LILO"))
    1538     {
    1539       res = run_lilo(offer_to_hack_scripts);
    1540     }
    1541   else if (!strcmp(name,"ELILO"))
    1542     {
    1543       res = run_elilo(offer_to_hack_scripts);
    1544     }
    1545   else if (!strcmp(name,"GRUB"))
    1546     {
     1469    char *device;
     1470    char *tmp;
     1471    char *name;
     1472
     1473    malloc_string(device);
     1474    malloc_string(tmp);
     1475    malloc_string(name);
     1476    backup_crucial_file(MNT_RESTORING, "/etc/fstab");
     1477    backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
     1478    backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
     1479    backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
     1480    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
     1481    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
     1482    sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
     1483    log_msg(2, tmp);
     1484    system("sync");
     1485    if (!strcmp(name, "LILO")) {
     1486        res = run_lilo(offer_to_hack_scripts);
     1487    } else if (!strcmp(name, "ELILO")) {
     1488        res = run_elilo(offer_to_hack_scripts);
     1489    } else if (!strcmp(name, "GRUB")) {
    15471490//      if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?")))
    15481491//        {
    1549       res = run_grub(offer_to_hack_scripts, device);
    1550 //    unlink(DO_MBR_PLEASE);
    1551 //  }
     1492        res = run_grub(offer_to_hack_scripts, device);
     1493//    unlink(DO_MBR_PLEASE);
     1494//  }
    15521495//      else
    15531496//        {
    1554 //    log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
    1555 //    res = 1;
    1556 //  }
    1557     }
    1558   else if (!strcmp(name,"RAW"))
    1559     {
    1560       res = run_raw_mbr(offer_to_hack_scripts, device);
    1561     }
     1497//    log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
     1498//    res = 1;
     1499//  }
     1500    } else if (!strcmp(name, "RAW")) {
     1501        res = run_raw_mbr(offer_to_hack_scripts, device);
     1502    }
    15621503#ifdef __FreeBSD__
    1563   else if (!strcmp(name,"BOOT0"))
    1564       {
    1565       sprintf (tmp, "boot0cfg -B %s", device);
    1566       res = run_program_and_log_output (tmp, FALSE);
    1567       } else {
    1568       sprintf (tmp, "ls /dev | grep -xq %ss[1-4].*", device);
    1569       if (!system (tmp)) {
    1570           sprintf (tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    1571           res = run_program_and_log_output (tmp, 3);
    1572       } else {
    1573           log_msg (1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
    1574       }
    1575       }
     1504    else if (!strcmp(name, "BOOT0")) {
     1505        sprintf(tmp, "boot0cfg -B %s", device);
     1506        res = run_program_and_log_output(tmp, FALSE);
     1507    } else {
     1508        sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device);
     1509        if (!system(tmp)) {
     1510            sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
     1511            res = run_program_and_log_output(tmp, 3);
     1512        } else {
     1513            log_msg(1,
     1514                    "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
     1515        }
     1516    }
    15761517#else
    1577   else
    1578     {
    1579       log_to_screen("Unable to determine type of boot loader. Defaulting to LILO.");
    1580       res=run_lilo(offer_to_hack_scripts);
    1581     }
     1518    else {
     1519        log_to_screen
     1520            ("Unable to determine type of boot loader. Defaulting to LILO.");
     1521        res = run_lilo(offer_to_hack_scripts);
     1522    }
    15821523#endif
    1583   retval += res;
    1584   if (res)
    1585     {
    1586       log_to_screen("Your boot loader returned an error");
    1587     }
    1588   else
    1589     {
    1590       log_to_screen("Your boot loader ran OK");
    1591     }
    1592   paranoid_free(device);
    1593   paranoid_free(tmp);
    1594   paranoid_free(name);
    1595   return(retval);
    1596 }
     1524    retval += res;
     1525    if (res) {
     1526        log_to_screen("Your boot loader returned an error");
     1527    } else {
     1528        log_to_screen("Your boot loader ran OK");
     1529    }
     1530    paranoid_free(device);
     1531    paranoid_free(tmp);
     1532    paranoid_free(name);
     1533    return (retval);
     1534}
     1535
    15971536/**************************************************************************
    15981537 *END_ RUN_BOOT_LOADER                                                    *
     
    16081547char *find_my_editor(void)
    16091548{
    1610   static char output[MAX_STR_LEN];
    1611   if (find_home_of_exe("pico"))
    1612     { strcpy(output, "pico"); }
    1613   else if (find_home_of_exe("nano"))
    1614     { strcpy(output, "nano"); }
    1615   else if (find_home_of_exe ("e3em"))
    1616       {
    1617       strcpy (output, "e3em");
    1618       }
    1619   else if (find_home_of_exe ("e3vi"))
    1620       {
    1621       strcpy (output, "e3vi");
    1622       }
    1623   else
    1624     { strcpy(output, "vi"); }
    1625   if (!find_home_of_exe(output))
    1626     { log_msg(2, " (find_my_editor) --- warning - %s not found", output); }
    1627   return(output);
     1549    static char output[MAX_STR_LEN];
     1550    if (find_home_of_exe("pico")) {
     1551        strcpy(output, "pico");
     1552    } else if (find_home_of_exe("nano")) {
     1553        strcpy(output, "nano");
     1554    } else if (find_home_of_exe("e3em")) {
     1555        strcpy(output, "e3em");
     1556    } else if (find_home_of_exe("e3vi")) {
     1557        strcpy(output, "e3vi");
     1558    } else {
     1559        strcpy(output, "vi");
     1560    }
     1561    if (!find_home_of_exe(output)) {
     1562        log_msg(2, " (find_my_editor) --- warning - %s not found", output);
     1563    }
     1564    return (output);
    16281565}
    16291566
     
    16351572 * @return 0 for success, nonzero for failure.
    16361573 */
    1637 int
    1638 run_grub(bool offer_to_run_stabgrub, char*bd)
     1574int run_grub(bool offer_to_run_stabgrub, char *bd)
    16391575{
    16401576  /** malloc **/
    1641   char *command;
    1642   char *boot_device;
    1643   char *rootdev;
    1644   char *rootdrive;
    1645   char *conffile;
    1646   char *tmp;
    1647   char *editor;
    1648 
    1649   int res;
    1650   int done;
    1651 
    1652   malloc_string(command);
    1653   malloc_string(boot_device);
    1654   malloc_string(tmp);
    1655   malloc_string(editor);
    1656   malloc_string(rootdev);
    1657   malloc_string(rootdrive);
    1658   malloc_string(conffile);
    1659   assert_string_is_neither_NULL_nor_zerolength(bd);
    1660   strcpy( editor, "vi" ); // find_my_editor() );
    1661   strcpy( boot_device, bd);
    1662  
    1663   if (!run_program_and_log_output("which grub-MR", FALSE))
    1664     {
    1665       log_msg(1, "Yay! grub-MR found...");
    1666       sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
    1667       log_msg(1, "command = %s", command);
    1668     }
    1669   else
    1670     {
    1671       sprintf(command, "chroot " MNT_RESTORING " grub-install %s",boot_device);
    1672       log_msg(1, "WARNING - grub-MR not found; using grub-install");
    1673     }
    1674   if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist?"))
    1675     /* interactive mode */
    1676     {
    1677       mvaddstr_and_log_it(g_currentY,
    1678               0,
    1679               "Modifying fstab and grub.conf, and running GRUB...                             ");
    1680       for(done = FALSE; !done; )
     1577    char *command;
     1578    char *boot_device;
     1579    char *rootdev;
     1580    char *rootdrive;
     1581    char *conffile;
     1582    char *tmp;
     1583    char *editor;
     1584
     1585    int res;
     1586    int done;
     1587
     1588    malloc_string(command);
     1589    malloc_string(boot_device);
     1590    malloc_string(tmp);
     1591    malloc_string(editor);
     1592    malloc_string(rootdev);
     1593    malloc_string(rootdrive);
     1594    malloc_string(conffile);
     1595    assert_string_is_neither_NULL_nor_zerolength(bd);
     1596    strcpy(editor, "vi");       // find_my_editor() );
     1597    strcpy(boot_device, bd);
     1598
     1599    if (!run_program_and_log_output("which grub-MR", FALSE)) {
     1600        log_msg(1, "Yay! grub-MR found...");
     1601        sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
     1602        log_msg(1, "command = %s", command);
     1603    } else {
     1604        sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
     1605                boot_device);
     1606        log_msg(1, "WARNING - grub-MR not found; using grub-install");
     1607    }
     1608    if (offer_to_run_stabgrub
     1609        && ask_me_yes_or_no("Did you change the mountlist?"))
     1610        /* interactive mode */
    16811611    {
    1682       popup_and_get_string("Boot device",
    1683                    "Please confirm/enter the boot device. If in doubt, try /dev/hda",
    1684                    boot_device, MAX_STR_LEN/4);
    1685       sprintf(command, "stabgrub-me %s", boot_device);
    1686       res = run_program_and_log_output(command, 1);
    1687       if (res)
    1688         {
    1689           popup_and_OK("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
    1690           newtSuspend();
    1691           system("chroot " MNT_RESTORING);
    1692           newtResume();
    1693           popup_and_OK("Thank you.");
    1694         }
    1695       else
    1696         {
    1697           done = TRUE;
    1698         }
    1699       popup_and_OK("You will now edit fstab and grub.conf");
    1700       if (!g_text_mode) { newtSuspend(); }
    1701       sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1702       paranoid_system(tmp);
    1703       sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
    1704       paranoid_system(tmp);
    1705       if (!g_text_mode) { newtResume(); }
    1706     }
    1707     }
    1708   else
    1709 
    1710     /* nuke mode */
    1711     {
    1712       mvaddstr_and_log_it(g_currentY,
    1713               0,
    1714               "Running GRUB...                                                 ");
    1715       iamhere(command);
    1716       res = run_program_and_log_output(command, 1);
    1717       if (res)
     1612        mvaddstr_and_log_it(g_currentY,
     1613                            0,
     1614                            "Modifying fstab and grub.conf, and running GRUB...                             ");
     1615        for (done = FALSE; !done;) {
     1616            popup_and_get_string("Boot device",
     1617                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
     1618                                 boot_device, MAX_STR_LEN / 4);
     1619            sprintf(command, "stabgrub-me %s", boot_device);
     1620            res = run_program_and_log_output(command, 1);
     1621            if (res) {
     1622                popup_and_OK
     1623                    ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
     1624                newtSuspend();
     1625                system("chroot " MNT_RESTORING);
     1626                newtResume();
     1627                popup_and_OK("Thank you.");
     1628            } else {
     1629                done = TRUE;
     1630            }
     1631            popup_and_OK("You will now edit fstab and grub.conf");
     1632            if (!g_text_mode) {
     1633                newtSuspend();
     1634            }
     1635            sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1636            paranoid_system(tmp);
     1637            sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
     1638            paranoid_system(tmp);
     1639            if (!g_text_mode) {
     1640                newtResume();
     1641            }
     1642        }
     1643    } else
     1644        /* nuke mode */
    17181645    {
    1719       popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
    1720       newtSuspend();
    1721       system("chroot " MNT_RESTORING);
    1722       newtResume();
    1723       popup_and_OK("Thank you.");
    1724     }
    1725     }
    1726   if (res)
    1727     {
    1728       mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1729       log_to_screen("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
    1730       log_msg(1,"Type:-");
    1731       log_msg(1,"    mount-me");
    1732       log_msg(1,"    chroot " MNT_RESTORING);
    1733       log_msg(1,"    mount /boot");
    1734       log_msg(1,"    grub-install '(hd0)'");
    1735       log_msg(1,"    exit");
    1736       log_msg(1,"    unmount-me");
    1737       log_msg(1,"If you're really stuck, please e-mail the mailing list.");
    1738     }
    1739   else
    1740     {
    1741       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    1742     }
    1743   paranoid_free(rootdev);
    1744   paranoid_free(rootdrive);
    1745   paranoid_free(conffile);
    1746   paranoid_free(command);
    1747   paranoid_free(boot_device);
    1748   paranoid_free(tmp);
    1749   paranoid_free(editor);
    1750 
    1751   return( res );
    1752 }
     1646        mvaddstr_and_log_it(g_currentY,
     1647                            0,
     1648                            "Running GRUB...                                                 ");
     1649        iamhere(command);
     1650        res = run_program_and_log_output(command, 1);
     1651        if (res) {
     1652            popup_and_OK
     1653                ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
     1654            newtSuspend();
     1655            system("chroot " MNT_RESTORING);
     1656            newtResume();
     1657            popup_and_OK("Thank you.");
     1658        }
     1659    }
     1660    if (res) {
     1661        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1662        log_to_screen
     1663            ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
     1664        log_msg(1, "Type:-");
     1665        log_msg(1, "    mount-me");
     1666        log_msg(1, "    chroot " MNT_RESTORING);
     1667        log_msg(1, "    mount /boot");
     1668        log_msg(1, "    grub-install '(hd0)'");
     1669        log_msg(1, "    exit");
     1670        log_msg(1, "    unmount-me");
     1671        log_msg(1,
     1672                "If you're really stuck, please e-mail the mailing list.");
     1673    } else {
     1674        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1675    }
     1676    paranoid_free(rootdev);
     1677    paranoid_free(rootdrive);
     1678    paranoid_free(conffile);
     1679    paranoid_free(command);
     1680    paranoid_free(boot_device);
     1681    paranoid_free(tmp);
     1682    paranoid_free(editor);
     1683
     1684    return (res);
     1685}
     1686
    17531687/**************************************************************************
    17541688 *END_RUN_GRUB                                                            *
     
    17611695 * @return 0 for success, nonzero for failure.
    17621696 */
    1763 int
    1764 run_elilo(bool offer_to_run_stabelilo)
     1697int run_elilo(bool offer_to_run_stabelilo)
    17651698{
    17661699  /** malloc **/
    1767   char *command;
    1768   char *tmp;
    1769   char *editor;
    1770 
    1771   int res;
    1772   int done;
    1773 
    1774   malloc_string(command);
    1775   malloc_string(tmp);
    1776   malloc_string(editor);
    1777   strcpy(editor, find_my_editor());
    1778   if (offer_to_run_stabelilo && ask_me_yes_or_no("Did you change the mountlist?"))
    1779 
    1780     /* interactive mode */
    1781     {
    1782       mvaddstr_and_log_it(g_currentY,
    1783               0,
    1784               "Modifying fstab and elilo.conf...                             ");
    1785       sprintf(command,"stabelilo-me");
    1786       res = run_program_and_log_output(command, 3);
    1787       if (res)
    1788         {
    1789           popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
    1790           for(done = FALSE; !done;)
    1791             {
    1792               if (!g_text_mode) { newtSuspend(); }
    1793           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1794           paranoid_system(tmp);
    1795           sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor);
    1796           paranoid_system(tmp);
    1797               if (!g_text_mode) { newtResume(); }
     1700    char *command;
     1701    char *tmp;
     1702    char *editor;
     1703
     1704    int res;
     1705    int done;
     1706
     1707    malloc_string(command);
     1708    malloc_string(tmp);
     1709    malloc_string(editor);
     1710    strcpy(editor, find_my_editor());
     1711    if (offer_to_run_stabelilo
     1712        && ask_me_yes_or_no("Did you change the mountlist?"))
     1713
     1714        /* interactive mode */
     1715    {
     1716        mvaddstr_and_log_it(g_currentY,
     1717                            0,
     1718                            "Modifying fstab and elilo.conf...                             ");
     1719        sprintf(command, "stabelilo-me");
     1720        res = run_program_and_log_output(command, 3);
     1721        if (res) {
     1722            popup_and_OK
     1723                ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
     1724            for (done = FALSE; !done;) {
     1725                if (!g_text_mode) {
     1726                    newtSuspend();
     1727                }
     1728                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1729                paranoid_system(tmp);
     1730                sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
     1731                        editor);
     1732                paranoid_system(tmp);
     1733                if (!g_text_mode) {
     1734                    newtResume();
     1735                }
    17981736//              newtCls();
    1799               if (ask_me_yes_or_no("Edit them again?"))
    1800         {
    1801           continue;
    1802         }
    1803           done = TRUE;
    1804             }
    1805     }
    1806       else
     1737                if (ask_me_yes_or_no("Edit them again?")) {
     1738                    continue;
     1739                }
     1740                done = TRUE;
     1741            }
     1742        } else {
     1743            log_to_screen("elilo.conf and fstab were modified OK");
     1744        }
     1745    } else
     1746        /* nuke mode */
    18071747    {
    1808       log_to_screen("elilo.conf and fstab were modified OK");
    1809     }
    1810     }
    1811   else
    1812 
    1813     /* nuke mode */
    1814     {
    1815     res = TRUE;
    1816     }
    1817   paranoid_free(command);
    1818   paranoid_free(tmp);
    1819   paranoid_free(editor);
    1820   return(res);
    1821 }
     1748        res = TRUE;
     1749    }
     1750    paranoid_free(command);
     1751    paranoid_free(tmp);
     1752    paranoid_free(editor);
     1753    return (res);
     1754}
     1755
    18221756/**************************************************************************
    18231757 *END_RUN_ELILO                                                            *
     
    18301764 * @return 0 for success, nonzero for failure.
    18311765 */
    1832 int
    1833 run_lilo(bool offer_to_run_stablilo)
     1766int run_lilo(bool offer_to_run_stablilo)
    18341767{
    18351768  /** malloc **/
    1836   char *command;
    1837   char *tmp;
    1838   char *editor;
    1839 
    1840   int res;
    1841   int done;
    1842   bool run_lilo_M = FALSE;
    1843   malloc_string(command);
    1844   malloc_string(tmp);
    1845   malloc_string(editor);
    1846 
    1847   if (!run_program_and_log_output("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1))
    1848         { run_lilo_M = TRUE; }
    1849 
    1850   strcpy(editor, find_my_editor());
    1851   if (offer_to_run_stablilo && ask_me_yes_or_no("Did you change the mountlist?"))
    1852 
    1853     /* interactive mode */
    1854     {
    1855       mvaddstr_and_log_it(g_currentY,
    1856               0,
    1857               "Modifying fstab and lilo.conf, and running LILO...                             ");
    1858       sprintf(command,"stablilo-me");
    1859       res = run_program_and_log_output(command, 3);
    1860       if (res)
    1861         {
    1862           popup_and_OK("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
    1863           for(done = FALSE; !done;)
    1864             {
    1865               if (!g_text_mode) { newtSuspend(); }
    1866           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1867           paranoid_system(tmp);
    1868           sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
    1869           paranoid_system(tmp);
    1870               if (!g_text_mode) { newtResume(); }
     1769    char *command;
     1770    char *tmp;
     1771    char *editor;
     1772
     1773    int res;
     1774    int done;
     1775    bool run_lilo_M = FALSE;
     1776    malloc_string(command);
     1777    malloc_string(tmp);
     1778    malloc_string(editor);
     1779
     1780    if (!run_program_and_log_output
     1781        ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
     1782        run_lilo_M = TRUE;
     1783    }
     1784
     1785    strcpy(editor, find_my_editor());
     1786    if (offer_to_run_stablilo
     1787        && ask_me_yes_or_no("Did you change the mountlist?"))
     1788
     1789        /* interactive mode */
     1790    {
     1791        mvaddstr_and_log_it(g_currentY,
     1792                            0,
     1793                            "Modifying fstab and lilo.conf, and running LILO...                             ");
     1794        sprintf(command, "stablilo-me");
     1795        res = run_program_and_log_output(command, 3);
     1796        if (res) {
     1797            popup_and_OK
     1798                ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
     1799            for (done = FALSE; !done;) {
     1800                if (!g_text_mode) {
     1801                    newtSuspend();
     1802                }
     1803                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1804                paranoid_system(tmp);
     1805                sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1806                paranoid_system(tmp);
     1807                if (!g_text_mode) {
     1808                    newtResume();
     1809                }
    18711810//              newtCls();
    1872               if (ask_me_yes_or_no("Edit them again?"))
    1873         {
    1874           continue;
    1875         }
    1876               res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
    1877               if (res)
    1878         {
    1879           res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
    1880         }
    1881               if (res)
    1882                 {
    1883                   done = ask_me_yes_or_no("LILO failed. Re-edit system files?");
    1884                 }
    1885               else
    1886             {
    1887               done = TRUE;
    1888             }
    1889             }
    1890     }
    1891       else
     1811                if (ask_me_yes_or_no("Edit them again?")) {
     1812                    continue;
     1813                }
     1814                res =
     1815                    run_program_and_log_output("chroot " MNT_RESTORING
     1816                                               " lilo -L", 3);
     1817                if (res) {
     1818                    res =
     1819                        run_program_and_log_output("chroot " MNT_RESTORING
     1820                                                   " lilo", 3);
     1821                }
     1822                if (res) {
     1823                    done =
     1824                        ask_me_yes_or_no
     1825                        ("LILO failed. Re-edit system files?");
     1826                } else {
     1827                    done = TRUE;
     1828                }
     1829            }
     1830        } else {
     1831            log_to_screen("lilo.conf and fstab were modified OK");
     1832        }
     1833    } else
     1834        /* nuke mode */
    18921835    {
    1893       log_to_screen("lilo.conf and fstab were modified OK");
    1894     }
    1895     }
    1896   else
    1897 
    1898     /* nuke mode */
    1899     {
    1900       mvaddstr_and_log_it(g_currentY,
    1901               0,
    1902               "Running LILO...                                                 ");
    1903       res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
    1904       if (res)
    1905     {
    1906       res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
    1907     }
    1908       if (res)
    1909         {
    1910           mvaddstr_and_log_it(g_currentY++,74,"Failed.");
    1911           log_to_screen("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
    1912         }
    1913       else
    1914     { 
    1915           mvaddstr_and_log_it(g_currentY++,74,"Done.");
    1916         }
    1917     }
    1918   if (run_lilo_M)
    1919     {
    1920       run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/hda", 3);
    1921       run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/sda", 3);
    1922     }
    1923   paranoid_free(command);
    1924   paranoid_free(tmp);
    1925   paranoid_free(editor);
    1926   return(res);
    1927 }
     1836        mvaddstr_and_log_it(g_currentY,
     1837                            0,
     1838                            "Running LILO...                                                 ");
     1839        res =
     1840            run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
     1841                                       3);
     1842        if (res) {
     1843            res =
     1844                run_program_and_log_output("chroot " MNT_RESTORING " lilo",
     1845                                           3);
     1846        }
     1847        if (res) {
     1848            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1849            log_to_screen
     1850                ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
     1851        } else {
     1852            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1853        }
     1854    }
     1855    if (run_lilo_M) {
     1856        run_program_and_log_output("chroot " MNT_RESTORING
     1857                                   " lilo -M /dev/hda", 3);
     1858        run_program_and_log_output("chroot " MNT_RESTORING
     1859                                   " lilo -M /dev/sda", 3);
     1860    }
     1861    paranoid_free(command);
     1862    paranoid_free(tmp);
     1863    paranoid_free(editor);
     1864    return (res);
     1865}
     1866
    19281867/**************************************************************************
    19291868 *END_RUN_LILO                                                            *
     
    19371876 * @return 0 for success, nonzero for failure.
    19381877 */
    1939 int
    1940 run_raw_mbr(bool offer_to_hack_scripts, char *bd)
     1878int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
    19411879{
    19421880  /** malloc **/
    1943   char *command;
    1944   char *boot_device;
    1945   char *tmp;
    1946   char *editor;
    1947   int res;
    1948   int done;
    1949 
    1950   malloc_string(command);
    1951   malloc_string(boot_device);
    1952   malloc_string(tmp);
    1953   malloc_string(editor);
    1954   assert_string_is_neither_NULL_nor_zerolength(bd);
    1955 
    1956   strcpy( editor, find_my_editor() );
    1957   strcpy( boot_device, bd );
    1958   sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
    1959   log_msg(2, "run_raw_mbr() --- command='%s'", command);
    1960 
    1961   if (offer_to_hack_scripts && ask_me_yes_or_no("Did you change the mountlist?"))
    1962     /* interactive mode */
    1963     {
    1964       mvaddstr_and_log_it(g_currentY,0,"Modifying fstab and restoring MBR...                           ");
    1965       for(done=FALSE; !done; )
     1881    char *command;
     1882    char *boot_device;
     1883    char *tmp;
     1884    char *editor;
     1885    int res;
     1886    int done;
     1887
     1888    malloc_string(command);
     1889    malloc_string(boot_device);
     1890    malloc_string(tmp);
     1891    malloc_string(editor);
     1892    assert_string_is_neither_NULL_nor_zerolength(bd);
     1893
     1894    strcpy(editor, find_my_editor());
     1895    strcpy(boot_device, bd);
     1896    sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
     1897    log_msg(2, "run_raw_mbr() --- command='%s'", command);
     1898
     1899    if (offer_to_hack_scripts
     1900        && ask_me_yes_or_no("Did you change the mountlist?"))
     1901        /* interactive mode */
    19661902    {
    1967       if (!run_program_and_log_output("which vi", FALSE))
    1968         {
    1969           popup_and_OK("You will now edit fstab");
    1970           if (!g_text_mode) { newtSuspend(); }
    1971           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1972           paranoid_system(tmp);
    1973           if (!g_text_mode) { newtResume(); }
     1903        mvaddstr_and_log_it(g_currentY, 0,
     1904                            "Modifying fstab and restoring MBR...                           ");
     1905        for (done = FALSE; !done;) {
     1906            if (!run_program_and_log_output("which vi", FALSE)) {
     1907                popup_and_OK("You will now edit fstab");
     1908                if (!g_text_mode) {
     1909                    newtSuspend();
     1910                }
     1911                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1912                paranoid_system(tmp);
     1913                if (!g_text_mode) {
     1914                    newtResume();
     1915                }
    19741916//              newtCls();
    1975         }
    1976       popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda",boot_device, MAX_STR_LEN/4);
    1977       sprintf(command, "stabraw-me %s", boot_device);
    1978       res = run_program_and_log_output(command, 3);
    1979       if (res)
    1980         {
    1981           done = ask_me_yes_or_no("Modifications failed. Re-try?");
    1982         }
    1983       else
    1984         {
    1985           done = TRUE;
    1986         }
    1987     }
    1988     }
    1989   else
    1990    
    1991     /* nuke mode */
    1992     {
    1993       mvaddstr_and_log_it(g_currentY,0,"Restoring MBR...                                               ");
    1994       res = run_program_and_log_output(command, 3);
    1995     }
    1996   if (res)
    1997     {
    1998       mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1999       log_to_screen("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
    2000     }
    2001   else
    2002     {
    2003       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2004     }
    2005   paranoid_free(command);
    2006   paranoid_free(boot_device);
    2007   paranoid_free(tmp);
    2008   paranoid_free(editor);
    2009   return(res);
    2010 }
     1917            }
     1918            popup_and_get_string("Boot device",
     1919                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
     1920                                 boot_device, MAX_STR_LEN / 4);
     1921            sprintf(command, "stabraw-me %s", boot_device);
     1922            res = run_program_and_log_output(command, 3);
     1923            if (res) {
     1924                done = ask_me_yes_or_no("Modifications failed. Re-try?");
     1925            } else {
     1926                done = TRUE;
     1927            }
     1928        }
     1929    } else
     1930        /* nuke mode */
     1931    {
     1932        mvaddstr_and_log_it(g_currentY, 0,
     1933                            "Restoring MBR...                                               ");
     1934        res = run_program_and_log_output(command, 3);
     1935    }
     1936    if (res) {
     1937        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1938        log_to_screen
     1939            ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
     1940    } else {
     1941        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1942    }
     1943    paranoid_free(command);
     1944    paranoid_free(boot_device);
     1945    paranoid_free(tmp);
     1946    paranoid_free(editor);
     1947    return (res);
     1948}
     1949
    20111950/**************************************************************************
    20121951 *END_RUN_RAW_MBR                                                         *
     
    20151954
    20161955
    2017  
    2018  
     1956
     1957
    20191958/**
    20201959 * Turn signal trapping on or off.
     
    20221961 * print a message and exit immediately.
    20231962 */
    2024 void
    2025 set_signals( int on )
    2026 {
    2027   int signals[]= { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGSTOP, 0 };
    2028   int i;
    2029   for ( i = 0; signals[i]; i++)
    2030     {
    2031       if (on)
    2032         {
    2033       signal( signals[i], terminate_daemon);
    2034     }
    2035       else
    2036         {
    2037       signal(signals[i], termination_in_progress);
    2038     }
    2039     }
     1963void set_signals(int on)
     1964{
     1965    int signals[] =
     1966        { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
     1967SIGSTOP, 0 };
     1968    int i;
     1969    for (i = 0; signals[i]; i++) {
     1970        if (on) {
     1971            signal(signals[i], terminate_daemon);
     1972        } else {
     1973            signal(signals[i], termination_in_progress);
     1974        }
     1975    }
    20401976}
    20411977
     
    20511987 * - @c bkpinfo->disaster_recovery
    20521988 */
    2053 void
    2054 setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
    2055 {
    2056   char *temppath;
    2057 
    2058   assert(bkpinfo!=NULL);
    2059 
    2060   malloc_string ( g_biggielist_txt );
    2061   malloc_string ( g_filelist_full );
    2062   malloc_string ( g_filelist_imagedevs );
    2063   malloc_string ( g_imagedevs_restthese );
    2064   malloc_string ( g_mondo_cfg_file );
    2065   malloc_string ( g_mountlist_fname );
    2066   malloc_string ( g_mondo_home );
    2067   malloc_string ( g_tmpfs_mountpt );
    2068   malloc_string ( g_isodir_device );
    2069   malloc_string ( g_isodir_format );
    2070 
    2071   temppath = bkpinfo->tmpdir;
    2072 
    2073   sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
    2074   sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
    2075   sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
     1989void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
     1990{
     1991    char *temppath;
     1992
     1993    assert(bkpinfo != NULL);
     1994
     1995    malloc_string(g_biggielist_txt);
     1996    malloc_string(g_filelist_full);
     1997    malloc_string(g_filelist_imagedevs);
     1998    malloc_string(g_imagedevs_restthese);
     1999    malloc_string(g_mondo_cfg_file);
     2000    malloc_string(g_mountlist_fname);
     2001    malloc_string(g_mondo_home);
     2002    malloc_string(g_tmpfs_mountpt);
     2003    malloc_string(g_isodir_device);
     2004    malloc_string(g_isodir_format);
     2005
     2006    temppath = bkpinfo->tmpdir;
     2007
     2008    sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
     2009    sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
     2010    sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
    20762011//  sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
    2077   sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", temppath);
    2078   if (bkpinfo->disaster_recovery)
    2079     {
    2080       sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
    2081       sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
    2082     }
    2083   else
    2084     {
    2085       sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
    2086       sprintf(g_mountlist_fname, "%s/%s", temppath, MOUNTLIST_FNAME_STUB);
    2087     }
    2088 }
     2012    sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
     2013            temppath);
     2014    if (bkpinfo->disaster_recovery) {
     2015        sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
     2016        sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
     2017    } else {
     2018        sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
     2019        sprintf(g_mountlist_fname, "%s/%s", temppath,
     2020                MOUNTLIST_FNAME_STUB);
     2021    }
     2022}
     2023
    20892024/**************************************************************************
    20902025 *END_SET_GLOBAL_FILENAME                                                 *
     
    20982033 * @param input_file The input file, a list of changed files created by a compare.
    20992034 */
    2100 void
    2101 streamline_changes_file(char *output_file, char *input_file)
    2102 {
    2103   FILE *fin;
    2104   FILE *fout;
     2035void streamline_changes_file(char *output_file, char *input_file)
     2036{
     2037    FILE *fin;
     2038    FILE *fout;
    21052039  /** malloc **/
    2106       char *incoming;
    2107 
    2108   assert_string_is_neither_NULL_nor_zerolength(output_file);
    2109   assert_string_is_neither_NULL_nor_zerolength(input_file);
    2110   malloc_string(incoming);
    2111  
    2112       if (!(fin=fopen(input_file,"r")))
    2113       {
    2114       log_OS_error(input_file);
    2115       return;
    2116       }
    2117       if (!(fout=fopen(output_file,"w")))
    2118       {
    2119       fatal_error("cannot open output_file");
    2120       }
    2121       for(fgets(incoming,MAX_STR_LEN-1,fin); !feof(fin); fgets(incoming,MAX_STR_LEN-1,fin))
    2122       {
    2123       if(strncmp(incoming,"etc/adjtime",11) \
    2124       && strncmp(incoming,"etc/mtab",8) \
    2125       && strncmp(incoming,"tmp/",4) \
    2126       && strncmp(incoming,"boot/map",8) \
    2127       && !strstr(incoming,"incheckentry") \
    2128       && strncmp(incoming,"etc/mail/statistics",19) \
    2129       && strncmp(incoming,"var/",4))
    2130       fprintf(fout,"%s",incoming); /* don't need \n here, for some reason.. */
    2131       }
    2132   paranoid_fclose(fout);
    2133   paranoid_fclose(fin);
    2134   paranoid_free(incoming);
    2135 }
     2040    char *incoming;
     2041
     2042    assert_string_is_neither_NULL_nor_zerolength(output_file);
     2043    assert_string_is_neither_NULL_nor_zerolength(input_file);
     2044    malloc_string(incoming);
     2045
     2046    if (!(fin = fopen(input_file, "r"))) {
     2047        log_OS_error(input_file);
     2048        return;
     2049    }
     2050    if (!(fout = fopen(output_file, "w"))) {
     2051        fatal_error("cannot open output_file");
     2052    }
     2053    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2054         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2055        if (strncmp(incoming, "etc/adjtime", 11)
     2056            && strncmp(incoming, "etc/mtab", 8)
     2057            && strncmp(incoming, "tmp/", 4)
     2058            && strncmp(incoming, "boot/map", 8)
     2059            && !strstr(incoming, "incheckentry")
     2060            && strncmp(incoming, "etc/mail/statistics", 19)
     2061            && strncmp(incoming, "var/", 4))
     2062            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
     2063    }
     2064    paranoid_fclose(fout);
     2065    paranoid_fclose(fin);
     2066    paranoid_free(incoming);
     2067}
     2068
    21362069/**************************************************************************
    21372070 *END_STREAMLINE_CHANGES_FILE                                             *
     
    21462079 * Prompt the user to support the Mondo project.
    21472080 */
    2148 void
    2149 success_message(void)
    2150 {
    2151   int i;
    2152   /* malloc and ptr */
    2153   char *tmp;
    2154 
    2155   malloc_string(tmp);
    2156   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
    2157       if (ask_me_yes_or_no("Have you contributed to the Mondo project financially or in some other way, yet?")) {
    2158           log_to_screen("Thank you for supporting Mondo. It goes from strength to strength,");
    2159           log_to_screen("thanks to the support of users like you.");
    2160           }
    2161       else {
    2162           if (ask_me_yes_or_no("Are you or your company willing to consider contributing to Mondo in some way?")) {
    2163               popup_and_OK("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'.");
    2164               }
    2165           else {
    2166               log_to_screen("Free Software, like freedom itself, must be supported or it will be lost.");
    2167               log_msg(1, "To your credit, you were honest: you said no, you wouldn't be contributing");
    2168               log_msg(1, "to this project, ever. However, that makes you a freeloader. I bet you're");
    2169               log_msg(1, "the sort of person who likes to sneak into movie theatres...");
    2170               popup_and_OK("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'.");
    2171               }
    2172            }
    2173   }
    2174 
     2081void success_message(void)
     2082{
     2083    int i;
     2084    /* malloc and ptr */
     2085    char *tmp;
     2086
     2087    malloc_string(tmp);
     2088    if (strstr
     2089        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     2090         "restore") == NULL) {
     2091        if (ask_me_yes_or_no
     2092            ("Have you contributed to the Mondo project financially or in some other way, yet?"))
     2093        {
     2094            log_to_screen
     2095                ("Thank you for supporting Mondo. It goes from strength to strength,");
     2096            log_to_screen("thanks to the support of users like you.");
     2097        } else {
     2098            if (ask_me_yes_or_no
     2099                ("Are you or your company willing to consider contributing to Mondo in some way?"))
     2100            {
     2101                popup_and_OK
     2102                    ("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'.");
     2103            } else {
     2104                log_to_screen
     2105                    ("Free Software, like freedom itself, must be supported or it will be lost.");
     2106                log_msg(1,
     2107                        "To your credit, you were honest: you said no, you wouldn't be contributing");
     2108                log_msg(1,
     2109                        "to this project, ever. However, that makes you a freeloader. I bet you're");
     2110                log_msg(1,
     2111                        "the sort of person who likes to sneak into movie theatres...");
     2112                popup_and_OK
     2113                    ("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'.");
     2114            }
     2115        }
     2116    }
    21752117#ifdef FREELOADER
    2176   i = (int)(random())%32;
     2118    i = (int) (random()) % 32;
    21772119#else
    2178   i=1;
     2120    i = 1;
    21792121#endif
    21802122
    2181   if (i!=25)
    2182     {
    2183       strcpy(tmp,"Mondo has restored your system. Please remove the backup media and reboot.");
    2184     }
    2185   else
    2186     {
    2187       strcpy(tmp,"M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
    2188     }
    2189   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
    2190       popup_and_OK(tmp);
    2191       }
    2192   log_to_screen(tmp);
    2193   paranoid_free(tmp);
    2194 }
     2123    if (i != 25) {
     2124        strcpy(tmp,
     2125               "Mondo has restored your system. Please remove the backup media and reboot.");
     2126    } else {
     2127        strcpy(tmp,
     2128               "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
     2129    }
     2130    if (strstr
     2131        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     2132         "restore") == NULL) {
     2133        popup_and_OK(tmp);
     2134    }
     2135    log_to_screen(tmp);
     2136    paranoid_free(tmp);
     2137}
     2138
    21952139/**************************************************************************
    21962140 *END_SUCCESS_MESSAGE                                                     *
     
    22032147 * @param sig The signal we're exiting due to.
    22042148 */
    2205 void
    2206 terminate_daemon(int sig)
    2207 {
    2208   log_to_screen("Mondorestore is terminating in response to a signal from the OS");
    2209   paranoid_MR_finish(254);
    2210 }
     2149void terminate_daemon(int sig)
     2150{
     2151    log_to_screen
     2152        ("Mondorestore is terminating in response to a signal from the OS");
     2153    paranoid_MR_finish(254);
     2154}
     2155
    22112156/**************************************************************************
    22122157 *END_TERMINATE_DAEMON                                                    *
     
    22172162 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
    22182163 */
    2219 void
    2220 twenty_seconds_til_yikes()
    2221 {
    2222   int i;
    2223   /* MALLOC **/
    2224   char *tmp;
    2225 
    2226   malloc_string(tmp);
    2227   if (does_file_exist("/tmp/NOPAUSE")) { return; }
    2228   open_progress_form("CAUTION",
    2229              "Be advised: I am about to ERASE your hard disk(s)!",
    2230              "You may press Ctrl+Alt+Del to abort safely.",
    2231              "",
    2232             20);
    2233   for(i = 0; i < 20; i++)
    2234     {
    2235       g_current_progress = i;
    2236       sprintf(tmp,"You have %d seconds left to abort.", 20 - i );
    2237       update_progress_form( tmp );
    2238       sleep( 1 );
    2239     }
    2240   close_progress_form();
    2241   paranoid_free(tmp);
    2242 }
     2164void twenty_seconds_til_yikes()
     2165{
     2166    int i;
     2167    /* MALLOC * */
     2168    char *tmp;
     2169
     2170    malloc_string(tmp);
     2171    if (does_file_exist("/tmp/NOPAUSE")) {
     2172        return;
     2173    }
     2174    open_progress_form("CAUTION",
     2175                       "Be advised: I am about to ERASE your hard disk(s)!",
     2176                       "You may press Ctrl+Alt+Del to abort safely.",
     2177                       "", 20);
     2178    for (i = 0; i < 20; i++) {
     2179        g_current_progress = i;
     2180        sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
     2181        update_progress_form(tmp);
     2182        sleep(1);
     2183    }
     2184    close_progress_form();
     2185    paranoid_free(tmp);
     2186}
     2187
    22432188/**************************************************************************
    22442189 *END_TWENTY_SECONDS_TIL_YIKES                                            *
     
    22532198 * @param sig The signal we're exiting due to.
    22542199 */
    2255 void
    2256 termination_in_progress(int sig)
    2257 {
    2258   log_msg(1, "Termination in progress");
    2259   usleep(1000);
    2260   pthread_exit(0);
    2261 }
     2200void termination_in_progress(int sig)
     2201{
     2202    log_msg(1, "Termination in progress");
     2203    usleep(1000);
     2204    pthread_exit(0);
     2205}
     2206
    22622207/**************************************************************************
    22632208 *END_TERMINATION_IN_PROGRESS                                             *
     
    22712216 * @return 0 for success, nonzero for failure.
    22722217 */
    2273 int unmount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist)
    2274 {
    2275   struct mountlist_itself *mountlist;
    2276   int retval=0,lino,res=0,i;
    2277   char *command;
    2278   char *tmp;
    2279 
    2280   malloc_string(command);
    2281   malloc_string(tmp);
    2282   assert(p_external_copy_of_mountlist!=NULL);
    2283 
    2284   mountlist = malloc(sizeof(struct mountlist_itself));
    2285   memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
    2286   sort_mountlist_by_mountpoint(mountlist, 0);
    2287 
    2288   run_program_and_log_output("df -m", 3);
    2289   mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
    2290   open_progress_form("Unmounting devices",
    2291              "Unmounting all devices that were mounted," ,
    2292              "in preparation for the post-restoration reboot.",
    2293              "",
    2294              mountlist->entries);
    2295   chdir( "/" );
    2296   for(i = 0; i < 10 && run_program_and_log_output("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++)
    2297     {
    2298       sleep( 1 );
    2299       log_msg(2, "Waiting for buffer() to finish");
    2300     }
    2301 
    2302   paranoid_system("sync");
    2303 
    2304   if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE ) )
    2305     {
    2306       log_msg(1, "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
    2307     }
    2308   if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE ) )
    2309     {
    2310       log_msg(1, "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
    2311     }
    2312   if (does_file_exist("/tmp/DUMBASS-GENTOO"))
    2313     {
    2314       run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
    2315     }
    2316   for( lino = mountlist->entries-1; lino >= 0; lino-- )
    2317     {
    2318       if (!strcmp(mountlist->el[lino].mountpoint,"lvm"))
    2319         {
    2320       continue;
    2321     }
    2322       sprintf(tmp,"Unmounting device %s  ",mountlist->el[lino].device);
    2323      
    2324       update_progress_form(tmp);
    2325       if (is_this_device_mounted(mountlist->el[lino].device))
    2326         {
    2327           if (!strcmp(mountlist->el[lino].mountpoint,"swap"))
    2328             {
    2329           sprintf(command,"swapoff %s",mountlist->el[lino].device);
    2330         } else {
    2331         if (!strcmp (mountlist->el[lino].mountpoint, "/1"))
    2332             {
    2333             sprintf (command, "umount %s/", MNT_RESTORING);
    2334             log_msg (3, "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
    2335             }
    2336         else
    2337             {
    2338             sprintf(command,"umount " MNT_RESTORING "%s",mountlist->el[lino].mountpoint);
    2339             }
    2340         }
    2341           log_msg(10, "The 'umount' command is '%s'", command);
    2342           res = run_program_and_log_output(command, 3);
    2343         }
    2344       else
    2345         {
    2346           strcat(tmp,"...not mounted anyway :-) OK");
    2347           res = 0;
    2348         }
    2349       g_current_progress++;
    2350       if (res)
    2351     {
    2352       strcat(tmp,"...Failed");
    2353       retval++;
    2354       log_to_screen(tmp);
    2355     }
    2356       else
    2357     {
    2358       log_msg(2, tmp);
    2359     }
    2360     }
    2361   close_progress_form();
    2362   if (retval)
    2363     {
    2364       mvaddstr_and_log_it(g_currentY++, 74, "Failed." );
    2365     }
    2366   else       
    2367     {
    2368       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2369     }
    2370   if (retval)
    2371     {
    2372       log_to_screen("Unable to unmount some of your partitions.");
    2373     }
    2374   else
    2375     {
    2376       log_to_screen("All partitions were unmounted OK.");
    2377     }
    2378   free(mountlist);
    2379   paranoid_free(command);
    2380   paranoid_free(tmp);
    2381   return(retval);
    2382 }
     2218int unmount_all_devices(struct mountlist_itself
     2219                        *p_external_copy_of_mountlist)
     2220{
     2221    struct mountlist_itself *mountlist;
     2222    int retval = 0, lino, res = 0, i;
     2223    char *command;
     2224    char *tmp;
     2225
     2226    malloc_string(command);
     2227    malloc_string(tmp);
     2228    assert(p_external_copy_of_mountlist != NULL);
     2229
     2230    mountlist = malloc(sizeof(struct mountlist_itself));
     2231    memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
     2232           sizeof(struct mountlist_itself));
     2233    sort_mountlist_by_mountpoint(mountlist, 0);
     2234
     2235    run_program_and_log_output("df -m", 3);
     2236    mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
     2237    open_progress_form("Unmounting devices",
     2238                       "Unmounting all devices that were mounted,",
     2239                       "in preparation for the post-restoration reboot.",
     2240                       "", mountlist->entries);
     2241    chdir("/");
     2242    for (i = 0;
     2243         i < 10
     2244         &&
     2245         run_program_and_log_output
     2246         ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
     2247         i++) {
     2248        sleep(1);
     2249        log_msg(2, "Waiting for buffer() to finish");
     2250    }
     2251
     2252    paranoid_system("sync");
     2253
     2254    if (run_program_and_log_output
     2255        ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) {
     2256        log_msg(1,
     2257                "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
     2258    }
     2259    if (run_program_and_log_output
     2260        ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) {
     2261        log_msg(1,
     2262                "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
     2263    }
     2264    if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
     2265        run_program_and_log_output("mkdir -p " MNT_RESTORING
     2266                                   "/mnt/.boot.d", 5);
     2267    }
     2268    for (lino = mountlist->entries - 1; lino >= 0; lino--) {
     2269        if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
     2270            continue;
     2271        }
     2272        sprintf(tmp, "Unmounting device %s  ", mountlist->el[lino].device);
     2273
     2274        update_progress_form(tmp);
     2275        if (is_this_device_mounted(mountlist->el[lino].device)) {
     2276            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
     2277                sprintf(command, "swapoff %s", mountlist->el[lino].device);
     2278            } else {
     2279                if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
     2280                    sprintf(command, "umount %s/", MNT_RESTORING);
     2281                    log_msg(3,
     2282                            "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
     2283                } else {
     2284                    sprintf(command, "umount " MNT_RESTORING "%s",
     2285                            mountlist->el[lino].mountpoint);
     2286                }
     2287            }
     2288            log_msg(10, "The 'umount' command is '%s'", command);
     2289            res = run_program_and_log_output(command, 3);
     2290        } else {
     2291            strcat(tmp, "...not mounted anyway :-) OK");
     2292            res = 0;
     2293        }
     2294        g_current_progress++;
     2295        if (res) {
     2296            strcat(tmp, "...Failed");
     2297            retval++;
     2298            log_to_screen(tmp);
     2299        } else {
     2300            log_msg(2, tmp);
     2301        }
     2302    }
     2303    close_progress_form();
     2304    if (retval) {
     2305        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     2306    } else {
     2307        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2308    }
     2309    if (retval) {
     2310        log_to_screen("Unable to unmount some of your partitions.");
     2311    } else {
     2312        log_to_screen("All partitions were unmounted OK.");
     2313    }
     2314    free(mountlist);
     2315    paranoid_free(command);
     2316    paranoid_free(tmp);
     2317    return (retval);
     2318}
     2319
    23832320/**************************************************************************
    23842321 *END_UNMOUNT_ALL_DEVICES                                                 *
     
    23932330 * @return 0 for success, nonzero for failure.
    23942331 */
    2395 int extract_cfg_file_and_mountlist_from_tape_dev(char*dev)
    2396 {
    2397   char *command;
    2398   int res=0;
    2399   // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
    2400   long tape_block_size=32768;
    2401 
    2402   malloc_string(command);
    2403 
    2404   // tar -zxvf-
    2405        sprintf( command,
    2406         "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
    2407            dev,
    2408            tape_block_size,
    2409            1024L*1024*32/tape_block_size,
    2410                    MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
    2411            BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB,
    2412            "tmp/i-want-my-lvm" );
    2413        log_msg (2, "command = '%s'", command);
    2414            res = run_program_and_log_output( command, -1 );
    2415        if (res!=0 && does_file_exist(MONDO_CFG_FILE_STUB)) { res=0; }
    2416   paranoid_free(command);
    2417   return(res);
    2418 }
    2419 
    2420  
    2421  
     2332int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
     2333{
     2334    char *command;
     2335    int res = 0;
     2336    // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
     2337    long tape_block_size = 32768;
     2338
     2339    malloc_string(command);
     2340
     2341    // tar -zxvf-
     2342    sprintf(command,
     2343            "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
     2344            dev,
     2345            tape_block_size,
     2346            1024L * 1024 * 32 / tape_block_size,
     2347            MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
     2348            BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
     2349    log_msg(2, "command = '%s'", command);
     2350    res = run_program_and_log_output(command, -1);
     2351    if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
     2352        res = 0;
     2353    }
     2354    paranoid_free(command);
     2355    return (res);
     2356}
     2357
     2358
     2359
    24222360/**
    24232361 * Get the configuration file from the floppy, tape, or CD.
     
    24282366 * @return 0 for success, nonzero for failure.
    24292367 */
    2430 int
    2431 get_cfg_file_from_archive( struct s_bkpinfo *bkpinfo )
    2432 {
    2433    int retval = 0;
    2434    
     2368int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo)
     2369{
     2370    int retval = 0;
     2371
    24352372   /** malloc *****/
    2436    char *device;
    2437    char *command;
    2438    char *cfg_file;
    2439    char *mounted_cfgf_path;
    2440    char *tmp;
    2441    char *mountpt;
    2442    char *ramdisk_fname;
    2443    char *mountlist_file;
    2444    int res;
    2445    
    2446    bool try_plan_B;
    2447 
    2448    assert(bkpinfo!=NULL);
    2449    malloc_string(cfg_file);
    2450    malloc_string(mounted_cfgf_path);
    2451    malloc_string(mountpt);
    2452    malloc_string(ramdisk_fname);
    2453    malloc_string(mountlist_file);
    2454    malloc_string(device);
    2455    malloc_string(command);
    2456    malloc_string(tmp);
    2457    log_msg(2, "gcffa --- starting" );
    2458    log_to_screen("I'm thinking...");
    2459    sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir );
    2460    device[0] = '\0';
    2461    chdir( bkpinfo->tmpdir );
    2462    strcpy( cfg_file, MONDO_CFG_FILE_STUB);
    2463    unlink( cfg_file ); // cfg_file[] is missing the '/' at the start, FYI, by intent
    2464    unlink( FILELIST_FULL_STUB );
    2465    unlink( BIGGIELIST_TXT_STUB );
    2466    unlink( "tmp/i-want-my-lvm");
    2467    sprintf( command, "mkdir -p %s", mountpt );
    2468    run_program_and_log_output( command, FALSE );
    2469    
     2373    char *device;
     2374    char *command;
     2375    char *cfg_file;
     2376    char *mounted_cfgf_path;
     2377    char *tmp;
     2378    char *mountpt;
     2379    char *ramdisk_fname;
     2380    char *mountlist_file;
     2381    int res;
     2382
     2383    bool try_plan_B;
     2384
     2385    assert(bkpinfo != NULL);
     2386    malloc_string(cfg_file);
     2387    malloc_string(mounted_cfgf_path);
     2388    malloc_string(mountpt);
     2389    malloc_string(ramdisk_fname);
     2390    malloc_string(mountlist_file);
     2391    malloc_string(device);
     2392    malloc_string(command);
     2393    malloc_string(tmp);
     2394    log_msg(2, "gcffa --- starting");
     2395    log_to_screen("I'm thinking...");
     2396    sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     2397    device[0] = '\0';
     2398    chdir(bkpinfo->tmpdir);
     2399    strcpy(cfg_file, MONDO_CFG_FILE_STUB);
     2400    unlink(cfg_file);           // cfg_file[] is missing the '/' at the start, FYI, by intent
     2401    unlink(FILELIST_FULL_STUB);
     2402    unlink(BIGGIELIST_TXT_STUB);
     2403    unlink("tmp/i-want-my-lvm");
     2404    sprintf(command, "mkdir -p %s", mountpt);
     2405    run_program_and_log_output(command, FALSE);
     2406
    24702407//   unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
    2471  
    2472    sprintf( cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
    2473    sprintf( mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
    2474    //   make_hole_for_file( cfg_file );
    2475    //   make_hole_for_file( mountlist_file);
    2476    log_msg (2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file );
    2477  
    2478    /* Floppy? */
    2479    sprintf( tmp, "mkdir -p %s", mountpt );
    2480    run_program_and_log_output( tmp, FALSE );
    2481    sprintf( tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    2482    run_program_and_log_output( tmp, FALSE);
    2483 
    2484    sprintf( command, "mount /dev/fd0u1722 %s", mountpt );
    2485    sprintf( tmp, "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", command);
    2486    log_msg(1, "tmp = '%s'", tmp);
    2487    system(tmp);
    2488    res = run_program_and_log_output( command, FALSE );
    2489    if (res) {
    2490     sprintf( command, "mount /dev/fd0H1440 %s", mountpt );
    2491     res = run_program_and_log_output( command, FALSE );
    2492    }
    2493    if (res) {
    2494     try_plan_B=TRUE;
    2495    } else {
    2496         try_plan_B=TRUE;
    2497         log_msg(2, "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
     2408
     2409    sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
     2410    sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
     2411            MOUNTLIST_FNAME_STUB);
     2412    //   make_hole_for_file( cfg_file );
     2413    //   make_hole_for_file( mountlist_file);
     2414    log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
     2415
     2416    /* Floppy? */
     2417    sprintf(tmp, "mkdir -p %s", mountpt);
     2418    run_program_and_log_output(tmp, FALSE);
     2419    sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     2420    run_program_and_log_output(tmp, FALSE);
     2421
     2422    sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
     2423    sprintf(tmp,
     2424            "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
     2425            command);
     2426    log_msg(1, "tmp = '%s'", tmp);
     2427    system(tmp);
     2428    res = run_program_and_log_output(command, FALSE);
     2429    if (res) {
     2430        sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
     2431        res = run_program_and_log_output(command, FALSE);
     2432    }
     2433    if (res) {
     2434        try_plan_B = TRUE;
     2435    } else {
     2436        try_plan_B = TRUE;
     2437        log_msg(2,
     2438                "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
    24982439// NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
    2499     log_msg(2, "Processing floppy (plan A?)" );
    2500     sprintf( ramdisk_fname, "%s/mindi.rdz", mountpt );
    2501     if ( !does_file_exist( ramdisk_fname ) )
    2502       {
    2503         sprintf( ramdisk_fname, "%s/initrd.img", mountpt );
    2504       }
    2505     if ( !does_file_exist( ramdisk_fname ) )
    2506       {
    2507         log_msg(2, "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?" );
    2508       }
    2509     if ( extract_config_file_from_ramdisk( bkpinfo, ramdisk_fname, cfg_file, mountlist_file ) )
    2510       {
    2511         log_msg(2, "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled." );
    2512       }
    2513     sprintf( command, "umount %s", mountpt );
    2514         run_program_and_log_output(command, 5);
    2515     unlink(ramdisk_fname);
    2516        }
    2517    if ( !does_file_exist( cfg_file ) )
    2518      {
    2519 log_msg(2, "gcffa --- we don't have cfg file yet." );
    2520        if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) )
    2521          {
    2522       try_plan_B = TRUE;
    2523     }
    2524         else
    2525           {
    2526            log_msg(2, "gcffa --- calling mount_cdrom now :)" );
    2527            if ( !mount_cdrom( bkpinfo ) )
    2528              {
    2529 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B" );
    2530           try_plan_B = FALSE;
    2531         }
    2532             else
    2533              {
    2534           try_plan_B = TRUE;
    2535         }
    2536       if ( what_number_cd_is_this(bkpinfo) > 1 )
    2537               {
    2538                insist_on_this_cd_number( bkpinfo, ( g_current_media_number = 1 ) );
    2539               }
    2540           }
    2541        if ( try_plan_B )
    2542           {
    2543            log_msg(2, "gcffa --- OK, switching to Plan B" );
    2544            chdir( bkpinfo->tmpdir );
    2545            run_program_and_log_output ( "mkdir -p tmp", FALSE );
    2546 
    2547        if (strlen(bkpinfo->media_device) ==0 )
    2548          {
    2549            strcpy(bkpinfo->media_device, "/dev/st0");
    2550            log_msg(2,"media_device is blank; assuming %s");
    2551          }
    2552            strcpy(tmp, bkpinfo->media_device);
    2553            if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2554          {
    2555            strcpy(bkpinfo->media_device, "/dev/st0");
    2556                if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2557              {
    2558                strcpy(bkpinfo->media_device, "/dev/osst0");
    2559                    if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2560              {
    2561                strcpy(bkpinfo->media_device, "/dev/ht0");
    2562                        if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2563                          {
    2564                log_msg(3, "I tried lots of devices but none worked.");
    2565                strcpy(bkpinfo->media_device, tmp);
    2566                          }
    2567                      }
    2568              }
    2569              }
    2570 
    2571            if ( !does_file_exist( "tmp/mondo-restore.cfg") )
    2572              {
    2573           log_to_screen ( "Cannot find config info on tape/CD/floppy");
    2574               return(1);
    2575         }
    2576           }
    2577       else
    2578         {
    2579 log_msg(2, "gcffa --- looking at mounted CD for mindi-boot.2880.img" );
    2580           sprintf( command, "mount "MNT_CDROM"/images/mindi-boot.2880.img -o loop %s", mountpt );
    2581           sprintf( mounted_cfgf_path, "%s/%s", mountpt, cfg_file );
    2582           if (!does_file_exist(mounted_cfgf_path))
    2583             {
    2584               log_msg(2,"gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz" );
    2585               sprintf( command,
    2586                "tar -zxvf "MNT_CDROM"/images/all.tar.gz %s %s %s %s %s",
    2587                 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"
    2588                ); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
    2589               run_program_and_log_output( command, TRUE );
    2590               if ( !does_file_exist( MONDO_CFG_FILE_STUB ) )
    2591                 {
    2592           fatal_error( "Please reinsert the disk/CD and try again." );
    2593         }
    2594             }
    2595         }
    2596     }
    2597   if ( does_file_exist( MONDO_CFG_FILE_STUB) )
    2598     {
    2599       log_msg(1, "gcffa --- great! We've got the config file" );
    2600       sprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB);
    2601       sprintf( command, "cp -f %s %s", tmp, cfg_file);
    2602       iamhere(command);
    2603       if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 ))
    2604         { log_msg(1,"... but an error occurred when I tried to move it to %s", cfg_file); }
    2605       else
    2606         { log_msg(1,"... and I moved it successfully to %s", cfg_file); }
    2607       sprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file);
    2608       iamhere(command);
    2609       if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 ))
    2610         { log_msg(1,"Failed to get mountlist"); }
    2611       else
    2612         {
    2613       log_msg(1,"Got mountlist too");
    2614       sprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
    2615       if (run_program_and_log_output(command, 1))
    2616         { log_msg(1, "Failed to copy mountlist to /tmp"); }
    2617       else
    2618         {
    2619           log_msg(1, "Copied mountlist to /tmp as well OK");
    2620           sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
    2621           run_program_and_log_output(command, 1);
     2440        log_msg(2, "Processing floppy (plan A?)");
     2441        sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
     2442        if (!does_file_exist(ramdisk_fname)) {
     2443            sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
     2444        }
     2445        if (!does_file_exist(ramdisk_fname)) {
     2446            log_msg(2,
     2447                    "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
     2448        }
     2449        if (extract_config_file_from_ramdisk
     2450            (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) {
     2451            log_msg(2,
     2452                    "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
     2453        }
     2454        sprintf(command, "umount %s", mountpt);
     2455        run_program_and_log_output(command, 5);
     2456        unlink(ramdisk_fname);
     2457    }
     2458    if (!does_file_exist(cfg_file)) {
     2459        log_msg(2, "gcffa --- we don't have cfg file yet.");
     2460        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2461            try_plan_B = TRUE;
     2462        } else {
     2463            log_msg(2, "gcffa --- calling mount_cdrom now :)");
     2464            if (!mount_cdrom(bkpinfo)) {
     2465                log_msg(2,
     2466                        "gcffa --- managed to mount CD; so, no need for Plan B");
     2467                try_plan_B = FALSE;
     2468            } else {
     2469                try_plan_B = TRUE;
     2470            }
     2471            if (what_number_cd_is_this(bkpinfo) > 1) {
     2472                insist_on_this_cd_number(bkpinfo,
     2473                                         (g_current_media_number = 1));
     2474            }
     2475        }
     2476        if (try_plan_B) {
     2477            log_msg(2, "gcffa --- OK, switching to Plan B");
     2478            chdir(bkpinfo->tmpdir);
     2479            run_program_and_log_output("mkdir -p tmp", FALSE);
     2480
     2481            if (strlen(bkpinfo->media_device) == 0) {
     2482                strcpy(bkpinfo->media_device, "/dev/st0");
     2483                log_msg(2, "media_device is blank; assuming %s");
     2484            }
     2485            strcpy(tmp, bkpinfo->media_device);
     2486            if (extract_cfg_file_and_mountlist_from_tape_dev
     2487                (bkpinfo->media_device)) {
     2488                strcpy(bkpinfo->media_device, "/dev/st0");
     2489                if (extract_cfg_file_and_mountlist_from_tape_dev
     2490                    (bkpinfo->media_device)) {
     2491                    strcpy(bkpinfo->media_device, "/dev/osst0");
     2492                    if (extract_cfg_file_and_mountlist_from_tape_dev
     2493                        (bkpinfo->media_device)) {
     2494                        strcpy(bkpinfo->media_device, "/dev/ht0");
     2495                        if (extract_cfg_file_and_mountlist_from_tape_dev
     2496                            (bkpinfo->media_device)) {
     2497                            log_msg(3,
     2498                                    "I tried lots of devices but none worked.");
     2499                            strcpy(bkpinfo->media_device, tmp);
     2500                        }
     2501                    }
     2502                }
     2503            }
     2504
     2505            if (!does_file_exist("tmp/mondo-restore.cfg")) {
     2506                log_to_screen("Cannot find config info on tape/CD/floppy");
     2507                return (1);
     2508            }
     2509        } else {
     2510            log_msg(2,
     2511                    "gcffa --- looking at mounted CD for mindi-boot.2880.img");
     2512            sprintf(command,
     2513                    "mount " MNT_CDROM
     2514                    "/images/mindi-boot.2880.img -o loop %s", mountpt);
     2515            sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
     2516            if (!does_file_exist(mounted_cfgf_path)) {
     2517                log_msg(2,
     2518                        "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz");
     2519                sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
     2520                run_program_and_log_output(command, TRUE);
     2521                if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
     2522                    fatal_error
     2523                        ("Please reinsert the disk/CD and try again.");
     2524                }
     2525            }
     2526        }
     2527    }
     2528    if (does_file_exist(MONDO_CFG_FILE_STUB)) {
     2529        log_msg(1, "gcffa --- great! We've got the config file");
     2530        sprintf(tmp, "%s/%s",
     2531                call_program_and_get_last_line_of_output("pwd"),
     2532                MONDO_CFG_FILE_STUB);
     2533        sprintf(command, "cp -f %s %s", tmp, cfg_file);
     2534        iamhere(command);
     2535        if (strcmp(tmp, cfg_file)
     2536            && run_program_and_log_output(command, 1)) {
     2537            log_msg(1,
     2538                    "... but an error occurred when I tried to move it to %s",
     2539                    cfg_file);
     2540        } else {
     2541            log_msg(1, "... and I moved it successfully to %s", cfg_file);
     2542        }
     2543        sprintf(command, "cp -f %s/%s %s",
     2544                call_program_and_get_last_line_of_output("pwd"),
     2545                MOUNTLIST_FNAME_STUB, mountlist_file);
     2546        iamhere(command);
     2547        if (strcmp(tmp, cfg_file)
     2548            && run_program_and_log_output(command, 1)) {
     2549            log_msg(1, "Failed to get mountlist");
     2550        } else {
     2551            log_msg(1, "Got mountlist too");
     2552            sprintf(command, "cp -f %s %s", mountlist_file,
     2553                    g_mountlist_fname);
     2554            if (run_program_and_log_output(command, 1)) {
     2555                log_msg(1, "Failed to copy mountlist to /tmp");
     2556            } else {
     2557                log_msg(1, "Copied mountlist to /tmp as well OK");
     2558                sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2559                run_program_and_log_output(command, 1);
    26222560/*        sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
    26232561          if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
     
    26392577        }
    26402578*/
    2641         }
    2642         }
    2643     }
    2644   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    2645   if ( !does_file_exist( cfg_file ) )
    2646     {
    2647       iamhere(cfg_file);
    2648       log_msg(1, "%s not found", cfg_file);
    2649       log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
    2650       return(1);
    2651     }
    2652 
    2653   log_to_screen( "Recovered mondo-restore.cfg" );
    2654   if (!does_file_exist( MOUNTLIST_FNAME_STUB ))
    2655     { log_to_screen( "...but not mountlist.txt - a pity, really..."); }
     2579            }
     2580        }
     2581    }
     2582    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     2583    if (!does_file_exist(cfg_file)) {
     2584        iamhere(cfg_file);
     2585        log_msg(1, "%s not found", cfg_file);
     2586        log_to_screen
     2587            ("Oh dear. Unable to recover configuration file from boot disk");
     2588        return (1);
     2589    }
     2590
     2591    log_to_screen("Recovered mondo-restore.cfg");
     2592    if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
     2593        log_to_screen("...but not mountlist.txt - a pity, really...");
     2594    }
    26562595/* start SAH */
    2657   else
    2658     {
    2659       sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    2660       run_program_and_log_output(command,FALSE);
    2661     }
     2596    else {
     2597        sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
     2598                bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
     2599        run_program_and_log_output(command, FALSE);
     2600    }
    26622601/*--commented out by SAH
    26632602  sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
     
    26682607/* end SAH */
    26692608
    2670   sprintf( command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB );
    2671   run_program_and_log_output( command, FALSE );
    2672   sprintf( command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB );
    2673   run_program_and_log_output( command, FALSE );
    2674   sprintf( command, "cp -f etc/raidtab /etc/");
    2675   run_program_and_log_output( command, FALSE );
    2676   sprintf( command, "cp -f tmp/i-want-my-lvm /tmp/");
    2677   run_program_and_log_output( command, FALSE );
    2678   g_backup_media_type = bkpinfo->backup_media_type;
    2679   paranoid_free(device);
    2680   paranoid_free(command);
    2681   paranoid_free(tmp);
    2682   paranoid_free(cfg_file);
    2683   paranoid_free(mounted_cfgf_path);
    2684   paranoid_free(mountpt);
    2685   paranoid_free(ramdisk_fname);
    2686   paranoid_free(mountlist_file);
    2687   return( retval );
     2609    sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2610    run_program_and_log_output(command, FALSE);
     2611    sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2612    run_program_and_log_output(command, FALSE);
     2613    sprintf(command, "cp -f etc/raidtab /etc/");
     2614    run_program_and_log_output(command, FALSE);
     2615    sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2616    run_program_and_log_output(command, FALSE);
     2617    g_backup_media_type = bkpinfo->backup_media_type;
     2618    paranoid_free(device);
     2619    paranoid_free(command);
     2620    paranoid_free(tmp);
     2621    paranoid_free(cfg_file);
     2622    paranoid_free(mounted_cfgf_path);
     2623    paranoid_free(mountpt);
     2624    paranoid_free(ramdisk_fname);
     2625    paranoid_free(mountlist_file);
     2626    return (retval);
    26882627}
    26892628
     
    27062645 ***************************************************************************/
    27072646
    2708  
    2709  
    2710 void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage)
    2711 {
    2712   struct s_mdstat *mdstat;
    2713   int unfinished_mdstat_devices=9999, i;
    2714   char *screen_message;
    2715  
    2716   malloc_string(screen_message);
    2717   mdstat = malloc(sizeof(struct s_mdstat));
    2718 
    2719   assert(wait_for_percentage <= 100);
    2720   iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
    2721   while(unfinished_mdstat_devices > 0)
    2722     {
    2723       if (read_mdstat(mdstat, mdstat_file))
    2724         { log_to_screen("Sorry, cannot read %s", mdstat_file); return; }
    2725       for(unfinished_mdstat_devices=i=0; i<mdstat->entries; i++)
    2726         {
    2727           if (mdstat->el[i].progress < wait_for_percentage)
    2728             {
    2729           unfinished_mdstat_devices++;
    2730           sprintf(screen_message, "Sync'ing /dev/md%d", mdstat->el[i].md);
    2731           open_evalcall_form(screen_message);
    2732           if (mdstat->el[i].progress == -1) // delayed while another partition inits
    2733             {
    2734           continue;
    2735         }
    2736           while(mdstat->el[i].progress < wait_for_percentage)
    2737             {
    2738           update_evalcall_form(mdstat->el[i].progress);
    2739           sleep(2);
    2740           if (read_mdstat(mdstat, mdstat_file)) {break;}
    2741         }
    2742           close_evalcall_form();
    2743         }
    2744         }
    2745     }
    2746   paranoid_free(screen_message);
    2747   paranoid_free(mdstat);
    2748 }
    2749 
    2750 
     2647
     2648
     2649void wait_until_software_raids_are_prepped(char *mdstat_file,
     2650                                           int wait_for_percentage)
     2651{
     2652    struct s_mdstat *mdstat;
     2653    int unfinished_mdstat_devices = 9999, i;
     2654    char *screen_message;
     2655
     2656    malloc_string(screen_message);
     2657    mdstat = malloc(sizeof(struct s_mdstat));
     2658
     2659    assert(wait_for_percentage <= 100);
     2660    iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
     2661    while (unfinished_mdstat_devices > 0) {
     2662        if (read_mdstat(mdstat, mdstat_file)) {
     2663            log_to_screen("Sorry, cannot read %s", mdstat_file);
     2664            return;
     2665        }
     2666        for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {
     2667            if (mdstat->el[i].progress < wait_for_percentage) {
     2668                unfinished_mdstat_devices++;
     2669                sprintf(screen_message, "Sync'ing /dev/md%d",
     2670                        mdstat->el[i].md);
     2671                open_evalcall_form(screen_message);
     2672                if (mdstat->el[i].progress == -1)   // delayed while another partition inits
     2673                {
     2674                    continue;
     2675                }
     2676                while (mdstat->el[i].progress < wait_for_percentage) {
     2677                    update_evalcall_form(mdstat->el[i].progress);
     2678                    sleep(2);
     2679                    if (read_mdstat(mdstat, mdstat_file)) {
     2680                        break;
     2681                    }
     2682                }
     2683                close_evalcall_form();
     2684            }
     2685        }
     2686    }
     2687    paranoid_free(screen_message);
     2688    paranoid_free(mdstat);
     2689}
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools.h

    r30 r128  
    44
    55void free_global_filenames();
    6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo*);
    7 bool is_file_in_list(char*, char*, char*); /* needle, haystack, preamble */
     6void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);
     7bool is_file_in_list(char *, char *, char *);   /* needle, haystack, preamble */
    88int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99void kill_petris(void);
    10 int modify_rclocal_one_time( char *path );
     10int modify_rclocal_one_time(char *path);
    1111int mount_cdrom(struct s_bkpinfo *bkpinfo);
    12 int mount_device(char*,char*,char*,bool);
    13 int mount_all_devices(struct mountlist_itself*, bool);
     12int mount_device(char *, char *, char *, bool);
     13int mount_all_devices(struct mountlist_itself *, bool);
    1414void protect_against_braindead_sysadmins(void);
    15 int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo);
     15int read_cfg_file_into_bkpinfo(char *cfg_file, struct s_bkpinfo *bkpinfo);
    1616struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *);
    17 int backup_crucial_file(char *path_root, char*filename);
     17int backup_crucial_file(char *path_root, char *filename);
    1818
    1919int run_boot_loader(bool);
    20 int run_grub(bool, char*);
     20int run_grub(bool, char *);
    2121int run_lilo(bool);
    2222int run_elilo(bool);
    2323int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
    2424char *find_my_editor(void);
    25 void streamline_changes_file(char*,char*);
    26 void  set_signals( int on );
     25void streamline_changes_file(char *, char *);
     26void set_signals(int on);
    2727void setup_global_filenames(struct s_bkpinfo *bkpinfo);
    2828//void setup_signals(int);
    2929void success_message(void);
    3030void twenty_seconds_til_yikes(void);
    31 int run_raw_mbr(bool offer_to_hack_scripts, char*bd);
     31int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
    3232void terminate_daemon(int);
    3333void termination_in_progress(int);
    34 int unmount_all_devices(struct mountlist_itself*);
     34int unmount_all_devices(struct mountlist_itself *);
    3535int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo);
    36 void ask_about_these_imagedevs( char *infname, char *outfname );
    37 
     36void ask_about_these_imagedevs(char *infname, char *outfname);
  • branches/2.05/mondo/mondo/mondorestore/mondoprep.h

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: mondoprep.h,v 1.4 2004/06/16 10:38:29 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    2323extern int g_currentY, g_current_cd_number;
    2424extern char *g_tape_device;
    25 extern void finish (int);
    26 extern void setup_newt_stuff (void);
    27 extern char which_restore_mode (void);
    28 extern bool ask_me_yes_or_no (char *);
    29 extern long get_phys_size_of_drive (char *);
     25extern void finish(int);
     26extern void setup_newt_stuff(void);
     27extern char which_restore_mode(void);
     28extern bool ask_me_yes_or_no(char *);
     29extern long get_phys_size_of_drive(char *);
    3030//extern void log_to_screen (char *);
    31 extern void update_progress_form (char *);
    32 extern void open_progress_form (char *, char *, char *, char *, long);
    33 extern void close_progress_form (void);
    34 extern void popup_and_OK (char *);
    35 extern bool popup_and_get_string (char *, char *, char *, int);
    36 extern long get_time (void);
    37 extern bool is_this_device_mounted (char *);
    38 extern int does_partition_exist (const char *device, int partno);
    39 extern int strcmp_inc_numbers (char *, char *);
    40 extern long count_lines_in_file (char *);
    41 extern long long length_of_file (char *);
    42 extern long noof_lines_that_match_wildcard (char *, char *);
     31extern void update_progress_form(char *);
     32extern void open_progress_form(char *, char *, char *, char *, long);
     33extern void close_progress_form(void);
     34extern void popup_and_OK(char *);
     35extern bool popup_and_get_string(char *, char *, char *, int);
     36extern long get_time(void);
     37extern bool is_this_device_mounted(char *);
     38extern int does_partition_exist(const char *device, int partno);
     39extern int strcmp_inc_numbers(char *, char *);
     40extern long count_lines_in_file(char *);
     41extern long long length_of_file(char *);
     42extern long noof_lines_that_match_wildcard(char *, char *);
    4343//extern char *slice_fname (long, long, bool, char *);
    44 extern char *last_line_of_file (char *);
    45 extern void log_file_end_to_screen (char *, char *);
    46 extern int zero_out_a_device (char *);
    47 extern void mvaddstr_and_log_it (int, int, char *);
    48 extern bool does_file_exist (char *);
     44extern char *last_line_of_file(char *);
     45extern void log_file_end_to_screen(char *, char *);
     46extern int zero_out_a_device(char *);
     47extern void mvaddstr_and_log_it(int, int, char *);
     48extern bool does_file_exist(char *);
    4949
    5050
    5151/** locals **********************************************************/
    52 int extrapolate_mountlist_to_include_raid_partitions (struct mountlist_itself
    53                               *,
    54                               struct mountlist_itself
    55                               *);
    56 bool mountlist_contains_raid_devices (struct mountlist_itself *);
    57 int start_raid_device (char *);
    58 int stop_raid_device (char *);
    59 int start_all_raid_devices (struct mountlist_itself *);
    60 int stop_all_raid_devices (struct mountlist_itself *);
    61 int format_everything (struct mountlist_itself *, bool);
    62 int partition_device (FILE*,const char *, int, int, const char *, long long);
    63 int partition_device_with_parted (FILE*,const char *, int, int, const char *, long long);
    64 int partition_device_with_fdisk (FILE*,const char *, int, int, const char *, long long);
    65 int format_device (char *, char *);
    66 int partition_drive (struct mountlist_itself *, char *);
    67 int partition_everything (struct mountlist_itself *);
    68 int do_my_funky_lvm_stuff (bool, bool);
    69 int which_format_command_do_i_need (char *, char *);
    70 int make_dummy_partitions (FILE*, char *, int);
    71 int make_list_of_drives (struct mountlist_itself *,
    72              char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
    73 int set_partition_type (FILE*,const char *, int, const char *, long long);
    74 void resize_drive_proportionately_to_suit_new_drives (struct mountlist_itself
    75                               *mountlist,
    76                               char *drive_name);
    77 void resize_mountlist_proportionately_to_suit_new_drives (struct
    78                               mountlist_itself
    79                               *mountlist);
     52int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
     53                                                     *, struct mountlist_itself
     54                                                     *);
     55bool mountlist_contains_raid_devices(struct mountlist_itself *);
     56int start_raid_device(char *);
     57int stop_raid_device(char *);
     58int start_all_raid_devices(struct mountlist_itself *);
     59int stop_all_raid_devices(struct mountlist_itself *);
     60int format_everything(struct mountlist_itself *, bool);
     61int partition_device(FILE *, const char *, int, int, const char *,
     62                     long long);
     63int partition_device_with_parted(FILE *, const char *, int, int,
     64                                 const char *, long long);
     65int partition_device_with_fdisk(FILE *, const char *, int, int,
     66                                const char *, long long);
     67int format_device(char *, char *);
     68int partition_drive(struct mountlist_itself *, char *);
     69int partition_everything(struct mountlist_itself *);
     70int do_my_funky_lvm_stuff(bool, bool);
     71int which_format_command_do_i_need(char *, char *);
     72int make_dummy_partitions(FILE *, char *, int);
     73int make_list_of_drives(struct mountlist_itself *,
     74                        char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
     75int set_partition_type(FILE *, const char *, int, const char *, long long);
     76void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself
     77                                                     *mountlist,
     78                                                     char *drive_name);
     79void resize_mountlist_proportionately_to_suit_new_drives(struct
     80                                                         mountlist_itself
     81                                                         *mountlist);
    8082
    8183
    82 char *
    83 truncate_to_drive_name (char *partition);
    84 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist);
    85 
     84char *truncate_to_drive_name(char *partition);
     85void create_mountlist_for_drive(struct mountlist_itself *mountlist,
     86                                char *drive_name,
     87                                struct mountlist_reference *drivemntlist);
  • branches/2.05/mondo/mondo/mondorestore/mr-externs.h

    r30 r128  
    11/*
    2  * $Id: mr-externs.h,v 1.3 2004/06/10 15:29:13 hugo Exp $
     2 * $Id$
    33 *
    44 * mondo-restore.c's externs
     
    66 */
    77
    8 #define SIZE 730000 * 1024                        /*  Size for ISO's stops -1 */
     8#define SIZE 730000 * 1024      /*  Size for ISO's stops -1 */
    99#define BIGGIELIST MNT_CDROM"/archives/biggielist.txt"
    1010#define ARCHIVES_PATH MNT_CDROM"/archives"
     
    1414#endif
    1515
    16 extern bool ask_me_yes_or_no(char*);
    17 extern char* calc_checksum_of_file(char*);
    18 extern int closein_tape(struct s_bkpinfo*);
     16extern bool ask_me_yes_or_no(char *);
     17extern char *calc_checksum_of_file(char *);
     18extern int closein_tape(struct s_bkpinfo *);
    1919extern void close_evalcall_form(void);
    20 extern char *call_program_and_get_last_line_of_output(char*);
     20extern char *call_program_and_get_last_line_of_output(char *);
    2121extern void close_progress_form(void);
    22 extern long count_lines_in_file(char*);
    23 extern bool does_file_exist(char*);
    24 extern int does_partition_exist(const char*device, int partno);
     22extern long count_lines_in_file(char *);
     23extern bool does_file_exist(char *);
     24extern int does_partition_exist(const char *device, int partno);
    2525extern int do_my_funky_lvm_stuff(bool, bool);
    2626extern int edit_filelist(struct s_node *);
    27 extern int edit_mountlist(char* mountlist_fname, struct mountlist_itself*, struct raidlist_itself*);
    28 extern int format_everything(struct mountlist_itself*, bool);
    29 extern int format_device(char*,char*);
     27extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
     28                          struct raidlist_itself *);
     29extern int format_everything(struct mountlist_itself *, bool);
     30extern int format_device(char *, char *);
    3031extern void finish(int);
    31 extern void free_filelist(struct s_node*);
     32extern void free_filelist(struct s_node *);
    3233extern long get_time(void);
    33 extern bool get_isodir_info(char*,char*,char*,bool);
    34 extern void fatal_error(char*);
    35 extern void initialize_raid_record(struct raid_device_record*);
    36 extern bool is_this_device_mounted(char*);
    37 extern long long length_of_file(char*);
    38 extern char *last_line_of_file(char*);
    39 extern struct s_node *load_filelist(char*);
     34extern bool get_isodir_info(char *, char *, char *, bool);
     35extern void fatal_error(char *);
     36extern void initialize_raid_record(struct raid_device_record *);
     37extern bool is_this_device_mounted(char *);
     38extern long long length_of_file(char *);
     39extern char *last_line_of_file(char *);
     40extern struct s_node *load_filelist(char *);
    4041extern void log_tape_pos(void);
    41 extern void initialize_raidrec(struct raid_device_record*);
    42 extern void log_file_end_to_screen(char*,char*);
    43 extern void log_to_screen (const char *fmt, ...);
     42extern void initialize_raidrec(struct raid_device_record *);
     43extern void log_file_end_to_screen(char *, char *);
     44extern void log_to_screen(const char *fmt, ...);
    4445extern void mvaddstr_and_log_it(int, int, char *);
    45 extern int make_dummy_partitions(char*,int);
    46 extern int make_hole_for_file(char*);
    47 extern int make_list_of_drives(struct mountlist_itself*, struct list_of_disks*);
    48 extern bool mountlist_contains_raid_devices(struct mountlist_itself*);
    49 extern void open_evalcall_form(char*);
    50 extern void open_progress_form(char*,char*,char*,char*,long);
     46extern int make_dummy_partitions(char *, int);
     47extern int make_hole_for_file(char *);
     48extern int make_list_of_drives(struct mountlist_itself *,
     49                               struct list_of_disks *);
     50extern bool mountlist_contains_raid_devices(struct mountlist_itself *);
     51extern void open_evalcall_form(char *);
     52extern void open_progress_form(char *, char *, char *, char *, long);
    5153extern int openin_cdstream(struct s_bkpinfo *);
    5254extern int openin_tape(struct s_bkpinfo *);
    53 extern int partition_device(char*,int,int,char*,long);
    54 extern int partition_device_with_fdisk(char*,int,int,char*,long);
    55 extern int partition_device_with_parted(char*,int,int,char*,long);
    56 extern int partition_drive(struct mountlist_itself*, char*);
    57 extern int partition_everything(struct mountlist_itself*);
    58 extern void popup_and_OK(char*);
    59 extern bool popup_and_get_string(char*,char*,char*, int);
     55extern int partition_device(char *, int, int, char *, long);
     56extern int partition_device_with_fdisk(char *, int, int, char *, long);
     57extern int partition_device_with_parted(char *, int, int, char *, long);
     58extern int partition_drive(struct mountlist_itself *, char *);
     59extern int partition_everything(struct mountlist_itself *);
     60extern void popup_and_OK(char *);
     61extern bool popup_and_get_string(char *, char *, char *, int);
    6062extern void setup_newt_stuff(void);
    61 extern void reset_bkpinfo(struct s_bkpinfo*);
    62 extern int read_cfg_var(char*, char*, char*);
    63 extern int read_file_from_stream_to_file(struct s_bkpinfo*, char*, long long);
    64 extern int read_file_from_stream_to_stream(struct s_bkpinfo*, FILE*, long long);
    65 extern int read_file_from_stream_FULL(struct s_bkpinfo*, char*, FILE*, long long);
    66 extern int read_header_block_from_stream(long long *, char*, int *);
    67 extern void save_filelist(struct s_node*, char*);
    68 extern void strip_spaces(char*);
    69 extern int strcmp_inc_numbers(char*,char*);
    70 extern char *slice_fname(long,long,char*,char*);
    71 extern int stop_raid_device(char*);
    72 extern int stop_all_raid_devices(struct mountlist_itself*);
     63extern void reset_bkpinfo(struct s_bkpinfo *);
     64extern int read_cfg_var(char *, char *, char *);
     65extern int read_file_from_stream_to_file(struct s_bkpinfo *, char *,
     66                                         long long);
     67extern int read_file_from_stream_to_stream(struct s_bkpinfo *, FILE *,
     68                                           long long);
     69extern int read_file_from_stream_FULL(struct s_bkpinfo *, char *, FILE *,
     70                                      long long);
     71extern int read_header_block_from_stream(long long *, char *, int *);
     72extern void save_filelist(struct s_node *, char *);
     73extern void strip_spaces(char *);
     74extern int strcmp_inc_numbers(char *, char *);
     75extern char *slice_fname(long, long, char *, char *);
     76extern int stop_raid_device(char *);
     77extern int stop_all_raid_devices(struct mountlist_itself *);
    7378extern void update_evalcall_form(int);
    74 extern void update_progress_form(char*);
    75 extern int verify_tape_backups(struct s_bkpinfo*);
     79extern void update_progress_form(char *);
     80extern int verify_tape_backups(struct s_bkpinfo *);
    7681extern char which_restore_mode(void);
    77 extern int which_format_command_do_i_need(char*,char*);
    78 extern int write_cfg_var(char*,char*,char*);
    79 extern void wrong_marker(int,int);
    80 extern void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist, char*drive_name);
    81 extern void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist);
    82 extern int get_cfg_file_from_archive(struct s_bkpinfo*);
     82extern int which_format_command_do_i_need(char *, char *);
     83extern int write_cfg_var(char *, char *, char *);
     84extern void wrong_marker(int, int);
     85extern void resize_drive_proportionately_to_suit_new_drives(struct
     86                                                            mountlist_itself
     87                                                            *mountlist,
     88                                                            char
     89                                                            *drive_name);
     90extern void resize_mountlist_proportionately_to_suit_new_drives(struct
     91                                                                mountlist_itself
     92                                                                *mountlist);
     93extern int get_cfg_file_from_archive(struct s_bkpinfo *);
    8394
    8495
     
    8798 * Externals   yummmy!!!                                                  *
    8899 **************************************************************************/
    89 extern long   g_maximum_progress;
    90 extern long   g_current_progress;
    91 extern long   g_start_time;
    92 extern int    g_currentY;
    93 extern int    g_current_media_number;  /* set to 1 in mondo-tools.c (tape)*/
     100extern long g_maximum_progress;
     101extern long g_current_progress;
     102extern long g_start_time;
     103extern int g_currentY;
     104extern int g_current_media_number;  /* set to 1 in mondo-tools.c (tape) */
    94105extern long long g_tape_posK;
    95106extern FILE *g_tape_stream;
     
    97108extern bool g_text_mode;
    98109extern bool g_restoring_live_from_cd;
    99 extern int fput_string_one_char_at_a_time(FILE*, char*);
     110extern int fput_string_one_char_at_a_time(FILE *, char *);
    100111
    101112
     
    104115
    105116extern int
    106 evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    107             char *flaws_str_B, char *flaws_str_C);
     117evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A,
     118                   char *flaws_str_B, char *flaws_str_C);
    108119
    109120
Note: See TracChangeset for help on using the changeset viewer.