Changeset 59 in MondoRescue for trunk/mondo/mondo/mondorestore/mondo-prep.c


Ignore:
Timestamp:
Oct 11, 2005, 1:34:31 AM (19 years ago)
Author:
bcornec
Message:

Trunk: indent on all source files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/mondo-prep.c

    r30 r59  
    88edited by : by Stan Benoit 4/2002
    99email     : troff@nakedsoul.org
    10 cvsid     : $Id: mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp $
     10cvsid     : $Id$
    1111***************************************************************************/
    1212
     
    181181#define MONDO_WAS_HERE "MONDOWOZEREMONDOWOZEREMONDOWOZEREhahahaMOJOJOJO"
    182182
    183 //static char cvsid[] = "$Id: mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp $";
     183//static char cvsid[] = "$Id$";
    184184
    185185extern char *g_mountlist_fname;
     
    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                     ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1"));
    481               }
    482             else
    483               {
    484                 strcpy(tmp, call_program_and_get_last_line_of_output
    485                     ("cat /var/log/mondo-archive.log | tail -n5 | 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                       ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1"));
     491            } else {
     492                strcpy(tmp, call_program_and_get_last_line_of_output
     493                       ("cat /var/log/mondo-archive.log | tail -n5 | 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);
     
    837888#endif
    838889        res = run_program_and_log_output(program, FALSE);
    839         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     890        if (g_fprep) {
     891            fprintf(g_fprep, "%s\n", program);
     892        }
    840893    }
    841894    retval += res;
     
    847900
    848901    log_to_screen(tmp);
    849     paranoid_free(program); paranoid_free(tmp);
    850     system("sync"); sleep(1);
     902    paranoid_free(program);
     903    paranoid_free(tmp);
     904    system("sync");
     905    sleep(1);
    851906    return (retval);
    852907}
     
    862917 * @return The number of errors encountered (0 for success).
    863918 */
    864 int format_everything(struct mountlist_itself *mountlist, bool interactively)
     919int format_everything(struct mountlist_itself *mountlist,
     920                      bool interactively)
    865921{
    866922    /** int **************************************************************/
     
    868924    int lino;
    869925    int res;
    870 //  int i;
    871 //  struct list_of_disks *drivelist;
     926//  int i;
     927//  struct list_of_disks *drivelist;
    872928
    873929    /** long *************************************************************/
     
    884940    /** end **************************************************************/
    885941
    886     assert(mountlist!=NULL);
     942    assert(mountlist != NULL);
    887943    malloc_string(tmp);
    888     sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
     944    sprintf(tmp, "format_everything (mountlist, interactively = %s",
     945            (interactively) ? "true" : "false");
    889946    log_it(tmp);
    890947    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
    891     open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.",
    892                "This may take up to five minutes.", "", mountlist->entries + 1);
    893 
    894     progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1;
     948    open_progress_form("Formatting partitions",
     949                       "I am now formatting your hard disk partitions.",
     950                       "This may take up to five minutes.", "",
     951                       mountlist->entries + 1);
     952
     953    progress_step =
     954        (mountlist->entries >
     955         0) ? g_maximum_progress / mountlist->entries : 1;
    895956// start soft-raids now (because LVM might depend on them)
    896957// ...and for simplicity's sake, let's format them at the same time :)
    897958    log_msg(1, "Stopping all RAID devices");
    898959    stop_all_raid_devices(mountlist);
    899     system("sync"); system("sync"); system("sync");
     960    system("sync");
     961    system("sync");
     962    system("sync");
    900963    sleep(2);
    901     log_msg(1, "Prepare soft-RAIDs"); // prep and format too
     964    log_msg(1, "Prepare soft-RAIDs");   // prep and format too
    902965    for (lino = 0; lino < mountlist->entries; lino++) {
    903966        me = &mountlist->el[lino];  // the current mountlist entry
     
    906969            if (interactively) {
    907970                // ask user if we should format the current device
    908                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     971                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     972                        me->mountpoint);
    909973                do_it = ask_me_yes_or_no(tmp);
    910974            } else {
     
    912976            }
    913977            if (do_it) {
    914             // NB: format_device() also stops/starts RAID device if necessary
     978                // NB: format_device() also stops/starts RAID device if necessary
    915979                retval += format_device(me->device, me->format);
    916980            }
     
    918982        }
    919983    }
    920     system("sync"); system("sync"); system("sync");
     984    system("sync");
     985    system("sync");
     986    system("sync");
    921987    sleep(2);
    922988// This last step is probably necessary
    923 //  log_to_screen("Re-starting software RAIDs...");
    924 //  start_all_raid_devices(mountlist);
    925 //  system("sync"); system("sync"); system("sync");
    926 //  sleep(5);
     989//  log_to_screen("Re-starting software RAIDs...");
     990//  start_all_raid_devices(mountlist);
     991//  system("sync"); system("sync"); system("sync");
     992//  sleep(5);
    927993// do LVMs now
    928994    log_msg(1, "Creating LVMs");
     
    930996        wait_until_software_raids_are_prepped("/proc/mdstat", 10);
    931997        log_to_screen("Configuring LVM");
    932                 if (!g_text_mode) { newtSuspend(); }
     998        if (!g_text_mode) {
     999            newtSuspend();
     1000        }
    9331001/*
    9341002        for(i=0; i<3; i++)
     
    9431011            log_msg(1, "Vacuum-packing...");
    9441012*/
    945             res = do_my_funky_lvm_stuff(FALSE, TRUE);
     1013        res = do_my_funky_lvm_stuff(FALSE, TRUE);
    9461014/*
    9471015        }
    9481016*/
    949                 if (!g_text_mode) { newtResume(); }
    950         if (!res) { log_to_screen("LVM initialized OK"); }
    951         else { log_to_screen("Failed to initialize LVM"); }
     1017        if (!g_text_mode) {
     1018            newtResume();
     1019        }
     1020        if (!res) {
     1021            log_to_screen("LVM initialized OK");
     1022        } else {
     1023            log_to_screen("Failed to initialize LVM");
     1024        }
    9521025        // retval += res;
    9531026        if (res) {
    954             retval ++;
    955         }
    956         sleep(3);
    957     }
    958 
     1027            retval++;
     1028        }
     1029        sleep(3);
     1030    }
    9591031// do regulars at last
    960     sleep(2); // woo!
    961         log_msg(1, "Formatting regulars");
     1032    sleep(2);                   // woo!
     1033    log_msg(1, "Formatting regulars");
    9621034    for (lino = 0; lino < mountlist->entries; lino++) {
    9631035        me = &mountlist->el[lino];  // the current mountlist entry
     
    9661038            log_it(tmp);
    9671039        } else if (!strcmp(me->format, "raid")) {
    968             sprintf(tmp, "Not formatting %s - it's a raid-let", me->device);
     1040            sprintf(tmp, "Not formatting %s - it's a raid-let",
     1041                    me->device);
    9691042            log_it(tmp);
    9701043            continue;
     
    9741047            continue;
    9751048        } else if (!strncmp(me->device, "/dev/md", 7)) {
    976             sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device);
     1049            sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",
     1050                    me->device);
    9771051            log_it(tmp);
    9781052            continue;
    9791053        } else if (!does_file_exist(me->device)
    980                     && strncmp(me->device, "/dev/hd", 7)
    981                     && strncmp(me->device, "/dev/sd", 7)) {
    982             sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device);
     1054                   && strncmp(me->device, "/dev/hd", 7)
     1055                   && strncmp(me->device, "/dev/sd", 7)) {
     1056            sprintf(tmp,
     1057                    "Not formatting %s yet - doesn't exist - probably an LVM",
     1058                    me->device);
    9831059            log_it(tmp);
    9841060            continue;
     
    9861062            if (interactively) {
    9871063                // ask user if we should format the current device
    988                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     1064                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     1065                        me->mountpoint);
    9891066                do_it = ask_me_yes_or_no(tmp);
    9901067            } else {
     
    10101087    if (retval) {
    10111088        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1012         log_to_screen("Errors occurred during the formatting of your hard drives.");
     1089        log_to_screen
     1090            ("Errors occurred during the formatting of your hard drives.");
    10131091    } else {
    10141092        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    10151093    }
    10161094
    1017     sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully");
     1095    sprintf(tmp, "format_everything () - %s",
     1096            (retval) ? "failed!" : "finished successfully");
    10181097    log_it(tmp);
    10191098
    1020     if (g_partition_table_locked_up > 0)
    1021       {
    1022         if (retval > 0 && !interactively)
    1023               {
     1099    if (g_partition_table_locked_up > 0) {
     1100        if (retval > 0 && !interactively) {
    10241101//123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    1025                 log_to_screen(
    1026   "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up);
    1027                 log_to_screen(
    1028   "failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
    1029                 log_to_screen(
    1030   "to refresh its copy of the partition table causes the kernel to lock the ");
    1031                 log_to_screen(
    1032   "partition table. I believe this has just happened.");
    1033                 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
    1034                   {
    1035             system("sync");
    1036             system("sync");
    1037             system("sync");
    1038             system("reboot");
    1039           }
    1040           }
    1041         else
    1042           {
    1043             log_to_screen(
    1044 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s');
    1045           }
    1046       }
    1047         newtSuspend();
     1102            log_to_screen
     1103                ("Partition table locked up %d times. At least one 'mkfs' (format) command",
     1104                 g_partition_table_locked_up);
     1105            log_to_screen
     1106                ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
     1107            log_to_screen
     1108                ("to refresh its copy of the partition table causes the kernel to lock the ");
     1109            log_to_screen
     1110                ("partition table. I believe this has just happened.");
     1111            if (ask_me_yes_or_no
     1112                ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
     1113            {
     1114                system("sync");
     1115                system("sync");
     1116                system("sync");
     1117                system("reboot");
     1118            }
     1119        } else {
     1120            log_to_screen
     1121                ("Partition table locked up %d time%c. However, disk formatting succeeded.",
     1122                 g_partition_table_locked_up,
     1123                 (g_partition_table_locked_up == 1) ? '.' : 's');
     1124        }
     1125    }
     1126    newtSuspend();
    10481127    system("clear");
    10491128    newtResume();
     
    10611140 * @return The number of errors encountered (0 for success).
    10621141 */
    1063 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for)
     1142int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename,
     1143                          int devno_we_must_allow_for)
    10641144{
    10651145    /** int **************************************************************/
     
    10811161        log_it(tmp);
    10821162        g_maximum_progress++;
    1083         res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000);
     1163        res =
     1164            partition_device(pout_to_fdisk, drivename, 1, 0, "ext2",
     1165                             32000);
    10841166        retval += res;
    10851167        previous_devno = 1;
     
    10901172    }
    10911173    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1092         sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno);
     1174        sprintf(tmp, "Creating dummy partition %s%d", drivename,
     1175                current_devno);
    10931176        log_it(tmp);
    10941177        g_maximum_progress++;
    1095         res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000);
     1178        res =
     1179            partition_device(pout_to_fdisk, drivename, current_devno,
     1180                             previous_devno, OSSWAP("ext2", "ufs"), 32000);
    10961181        retval += res;
    10971182        previous_devno = current_devno;
     
    11411226    else
    11421227        fprintf(f, "type: %u\n", lp->d_type);
    1143     fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
    1144     fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
     1228    fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
     1229            lp->d_typename);
     1230    fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
     1231            lp->d_packname);
    11451232    fprintf(f, "flags:");
    11461233    if (lp->d_flags & D_REMOVABLE)
     
    11611248    fprintf(f, "trackskew: %u\n", lp->d_trackskew);
    11621249    fprintf(f, "cylinderskew: %u\n", lp->d_cylskew);
    1163     fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch);
    1164     fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek);
     1250    fprintf(f, "headswitch: %lu\t\t# milliseconds\n",
     1251            (u_long) lp->d_headswitch);
     1252    fprintf(f, "track-to-track seek: %ld\t# milliseconds\n",
     1253            (u_long) lp->d_trkseek);
    11651254    fprintf(f, "drivedata: ");
    11661255    for (i = NDDATA - 1; i >= 0; i--)
     
    11721261        fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]);
    11731262    fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
    1174     fprintf(f, "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
     1263    fprintf(f,
     1264            "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
    11751265    pp = lp->d_partitions;
    11761266    for (i = 0; i < lp->d_npartitions; i++, pp++) {
    11771267        if (pp->p_size) {
    1178             fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset);
     1268            fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
     1269                    (u_long) pp->p_offset);
    11791270            if (pp->p_fstype < FSMAXTYPES)
    11801271                fprintf(f, "%8.8s", fstypenames[pp->p_fstype]);
     
    11841275
    11851276            case FS_UNUSED: /* XXX */
    1186                 fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), "");
     1277                fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
     1278                        (u_long) (pp->p_fsize * pp->p_frag), "");
    11871279                break;
    11881280
    11891281            case FS_BSDFFS:
    1190                 fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1191                     pp->p_cpg);
     1282                fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize,
     1283                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    11921284                break;
    11931285
    11941286            case FS_BSDLFS:
    1195                 fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1196                     pp->p_cpg);
     1287                fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize,
     1288                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    11971289                break;
    11981290
     
    12011293                break;
    12021294            }
    1203             fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl));
     1295            fprintf(f, "\t# (Cyl. %4lu",
     1296                    (u_long) (pp->p_offset / lp->d_secpercyl));
    12041297            if (pp->p_offset % lp->d_secpercyl)
    12051298                putc('*', f);
    12061299            else
    12071300                putc(' ', f);
    1208             fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1));
     1301            fprintf(f, "- %lu",
     1302                    (u_long) ((pp->p_offset + pp->p_size +
     1303                               lp->d_secpercyl - 1) / lp->d_secpercyl -
     1304                              1));
    12091305            if (pp->p_size % lp->d_secpercyl)
    12101306                putc('*', f);
     
    12321328    /* New world order */
    12331329    if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0)
    1234         || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
     1330        || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
    12351331        close(f);
    12361332        return (NULL);
     
    12761372    return (&loclab);
    12771373}
     1374
    12781375/* End stolen from /usr/src/sbin/disklabel/disklabel.c. */
    12791376
     
    12951392 * @return The number of errors encountered (0 for success).
    12961393 */
    1297 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret)
     1394int label_drive_or_slice(struct mountlist_itself *mountlist,
     1395                         char *drivename, struct disklabel *ret)
    12981396{
    12991397    char subdev_str[MAX_STR_LEN];
     
    13191417            lp->d_partitions[c - 'a'].p_cpg = 0;
    13201418            if (!strcmp(mountlist->el[idx].format, "ufs")
    1321                 || !strcmp(mountlist->el[idx].format, "ffs")
    1322                 || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
     1419                || !strcmp(mountlist->el[idx].format, "ffs")
     1420                || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
    13231421                lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS;
    13241422                lp->d_partitions[c - 'a'].p_fsize = 2048;
     
    13261424                lp->d_partitions[c - 'a'].p_cpg = 64;
    13271425            } else if (!strcasecmp(mountlist->el[idx].format, "raid")
    1328                    || !strcasecmp(mountlist->el[idx].format, "vinum")) {
     1426                       || !strcasecmp(mountlist->el[idx].format, "vinum")) {
    13291427                lp->d_partitions[c - 'a'].p_fstype = FS_VINUM;
    13301428            } else if (!strcmp(mountlist->el[idx].format, "swap")) {
     
    13471445        for (lastone = i - 1; lastone >= 0; lastone--) {
    13481446            if ((lp->d_partitions[lastone].p_size)
    1349                 && (lastone != RAW_PART))
     1447                && (lastone != RAW_PART))
    13501448                break;
    13511449        }
    1352         lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size;
    1353     }
    1354     if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) {
    1355         lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset;
     1450        lp->d_partitions[i].p_offset =
     1451            lp->d_partitions[lastone].p_offset +
     1452            lp->d_partitions[lastone].p_size;
     1453    }
     1454    if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size >
     1455        lp->d_secperunit) {
     1456        lp->d_partitions[lo].p_size =
     1457            lp->d_secperunit - lp->d_partitions[lo].p_offset;
    13561458    }
    13571459
     
    13611463    sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));
    13621464    retval += run_program_and_log_output(command, TRUE);
    1363     sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename));
     1465    sprintf(command, "disklabel -R %s /tmp/disklabel",
     1466            canonical_name(drivename));
    13641467    retval += run_program_and_log_output(command, TRUE);
    13651468    if (ret)
     
    13841487    int retval = 0;
    13851488    int i;
    1386     FILE*pout_to_fdisk=NULL;
    1387    
     1489    FILE *pout_to_fdisk = NULL;
     1490
    13881491#ifdef __FreeBSD__
    13891492    bool fbsd_part = FALSE;
     
    14071510    malloc_string(format);
    14081511    malloc_string(tmp);
    1409    
     1512
    14101513    sprintf(tmp, "Partitioning drive %s", drivename);
    14111514    log_it(tmp);
    14121515
    1413 #if __FreeBSD__ 
    1414         log_it("(Not opening fdisk now; that's the Linux guy's job)");
     1516#if __FreeBSD__
     1517    log_it("(Not opening fdisk now; that's the Linux guy's job)");
    14151518    pout_to_fdisk = NULL;
    14161519#else
    14171520    make_hole_for_file(FDISK_LOG);
    14181521#ifdef __IA64__
    1419     sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1522    sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1523            FDISK_LOG);
    14201524#else
    14211525    sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
    14221526#endif
    14231527    pout_to_fdisk = popen(tmp, "w");
    1424     if (!pout_to_fdisk) { 
    1425         log_to_screen("Cannot call fdisk to configure %s", drivename); 
     1528    if (!pout_to_fdisk) {
     1529        log_to_screen("Cannot call fdisk to configure %s", drivename);
    14261530        paranoid_free(device_str);
    14271531        paranoid_free(format);
    14281532        paranoid_free(tmp);
    1429         return(1);
     1533        return (1);
    14301534    }
    14311535#endif
     
    14451549                for (c = 'a'; c <= 'z'; c++) {
    14461550                    sprintf(subdev_str, "%s%c", drivename, c);
    1447                     if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
     1551                    if (find_device_in_mountlist(mountlist, subdev_str) >
     1552                        0) {
    14481553                        fbsd_part = TRUE;
    14491554                    }
     
    14511556                if (fbsd_part) {
    14521557                    int r = label_drive_or_slice(mountlist,
    1453                                     drivename,
    1454                                     0);
     1558                                                drivename,
     1559                                                0);
    14551560                    char command[MAX_STR_LEN];
    1456                     sprintf(command, "disklabel -B %s", basename(drivename));
     1561                    sprintf(command, "disklabel -B %s",
     1562                            basename(drivename));
    14571563                    if (system(command)) {
    1458                         log_to_screen("Warning! Unable to make the drive bootable.");
     1564                        log_to_screen
     1565                            ("Warning! Unable to make the drive bootable.");
    14591566                    }
    14601567                    paranoid_free(device_str);
     
    15011608#if __FreeBSD__
    15021609            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1503 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1504 //          if (run_program_and_log_output(tmp, TRUE)) {
     1610//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1611//          if (run_program_and_log_output(tmp, TRUE)) {
    15051612            file = open(drivename, O_WRONLY);
    15061613            if (!file) {
    1507                 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename);
     1614                sprintf(tmp,
     1615                        "Warning - unable to open %s for wiping it's partition table",
     1616                        drivename);
    15081617                log_to_screen(tmp);
    15091618            }
    15101619
    1511             for (i=0; i<512; i++) {
    1512                 if ( !write(file, "\0", 1) ) {
    1513                     sprintf(tmp, "Warning - unable to write to %s", drivename);
     1620            for (i = 0; i < 512; i++) {
     1621                if (!write(file, "\0", 1)) {
     1622                    sprintf(tmp, "Warning - unable to write to %s",
     1623                            drivename);
    15141624                    log_to_screen(tmp);
    15151625                }
     
    15181628#else
    15191629            iamhere("New, kernel-friendly partition remover");
    1520             for(i=20;i>0;i--)
    1521               {
    1522                 fprintf(pout_to_fdisk, "d\n%d\n", i);
    1523                 fflush(pout_to_fdisk);
    1524               }
    1525 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1526 //          run_program_and_log_output(tmp, 1);
    1527 #endif 
     1630            for (i = 20; i > 0; i--) {
     1631                fprintf(pout_to_fdisk, "d\n%d\n", i);
     1632                fflush(pout_to_fdisk);
     1633            }
     1634//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1635//          run_program_and_log_output(tmp, 1);
     1636#endif
    15281637            if (current_devno > 1) {
    1529                 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno);
     1638                previous_devno =
     1639                    make_dummy_partitions(pout_to_fdisk, drivename,
     1640                                          current_devno);
    15301641            }
    15311642        }
     
    15341645#endif
    15351646
    1536         strcpy(format, mountlist->el[lino].format);
    1537         partsize = mountlist->el[lino].size;
     1647            strcpy(format, mountlist->el[lino].format);
     1648            partsize = mountlist->el[lino].size;
    15381649
    15391650#ifdef __FreeBSD__
     
    15421653
    15431654        if (current_devno == 5 && previous_devno == 4) {
    1544             log_to_screen("You must leave at least one partition spare as the Extended partition.");
     1655            log_to_screen
     1656                ("You must leave at least one partition spare as the Extended partition.");
    15451657            paranoid_free(device_str);
    15461658            paranoid_free(format);
     
    15491661        }
    15501662
    1551         retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize);
     1663        retval +=
     1664            partition_device(pout_to_fdisk, drivename, current_devno,
     1665                             previous_devno, format, partsize);
    15521666
    15531667#ifdef __FreeBSD__
     
    15561670            retval += label_drive_or_slice(mountlist, device_str, 0);
    15571671            if (system(tmp)) {
    1558                 log_to_screen("Warning! Unable to make the slice bootable.");
     1672                log_to_screen
     1673                    ("Warning! Unable to make the slice bootable.");
    15591674            }
    15601675        }
     
    15641679    }
    15651680
    1566     if (pout_to_fdisk)
    1567     {
     1681    if (pout_to_fdisk) {
    15681682// mark relevant partition as bootable
    1569         sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy"));
     1683        sprintf(tmp, "a\n%s\n",
     1684                call_program_and_get_last_line_of_output
     1685                ("make-me-bootable /tmp/mountlist.txt dummy"));
    15701686        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    15711687// close fdisk
    15721688        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    15731689        system("sync");
    1574         paranoid_pclose(pout_to_fdisk);
    1575         log_msg(0, "------------------- fdisk.log looks like this ------------------");
     1690        paranoid_pclose(pout_to_fdisk);
     1691        log_msg(0,
     1692                "------------------- fdisk.log looks like this ------------------");
    15761693        sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    15771694        system(tmp);
    1578         log_msg(0, "------------------- end of fdisk.log... word! ------------------");
     1695        log_msg(0,
     1696                "------------------- end of fdisk.log... word! ------------------");
    15791697        sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG);
    1580         if (!run_program_and_log_output(tmp, 5))
    1581           {
    1582             g_partition_table_locked_up++;
    1583             log_to_screen("A flaw in the Linux kernel has locked the partition table.");
    1584           }
     1698        if (!run_program_and_log_output(tmp, 5)) {
     1699            g_partition_table_locked_up++;
     1700            log_to_screen
     1701                ("A flaw in the Linux kernel has locked the partition table.");
     1702        }
    15851703    }
    15861704    paranoid_free(device_str);
     
    15991717 * @return 0 for success, nonzero for failure.
    16001718 */
    1601 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize)
     1719int partition_device(FILE * pout_to_fdisk, const char *drive, int partno,
     1720                     int prev_partno, const char *format,
     1721                     long long partsize)
    16021722{
    16031723    /** int **************************************************************/
     
    16241744    malloc_string(logfile);
    16251745    malloc_string(output);
    1626    
     1746
    16271747    assert_string_is_neither_NULL_nor_zerolength(drive);
    16281748    assert(format != NULL);
    16291749
    1630     log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize);
     1750    log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting",
     1751           drive, partno, prev_partno, format, partsize);
    16311752
    16321753    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     
    16441765        sprintf(tmp, "Partitioning device %s (max size)", partition_name);
    16451766    } else {
    1646         sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024);
     1767        sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,
     1768                (long long) partsize / 1024);
    16471769    }
    16481770    update_progress_form(tmp);
     
    16501772
    16511773    if (is_this_device_mounted(partition_name)) {
    1652         sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name);
     1774        sprintf(tmp, "%s is mounted, and should not be partitioned",
     1775                partition_name);
    16531776        log_to_screen(tmp);
    16541777        paranoid_free(program);
     
    16711794    p = (char *) strrchr(partition_name, '/');
    16721795    sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
    1673     sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     1796    sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1797            MONDO_LOGFILE);
    16741798
    16751799    output[0] = '\0';
     
    16811805            part_table_fmt = which_partition_format(drive);
    16821806            /* GPT allows more than 4 primary partitions */
    1683             if ((prev_partno >= 4) && (strcmp(part_table_fmt,"MBR") == 0)) {
    1684                 log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
     1807            if ((prev_partno >= 4) && (strcmp(part_table_fmt, "MBR") == 0)) {
     1808                log_to_screen
     1809                    ("You need to leave at least one partition free, for 'extended/logical'");
    16851810                paranoid_free(program);
    16861811                paranoid_free(partition_name);
     
    16901815                return (1);
    16911816            } else {
    1692                 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1);
     1817                sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
     1818                        prev_partno + 1);
    16931819            }
    16941820        }
     
    16971823    strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
    16981824    if (partsize > 0) {
    1699                 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; }
     1825        if (!strcmp(format, "7")) {
     1826            log_msg(1, "Adding 512K, just in case");
     1827            partsize += 512;
     1828        }
    17001829        sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    17011830    }
     
    17141843
    17151844
    1716     if (pout_to_fdisk)
    1717     {
     1845    if (pout_to_fdisk) {
    17181846        log_msg(1, "Doing the new all-in-one fdisk thing");
    17191847        log_msg(1, "output = '%s'", output);
     
    17211849        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    17221850        strcpy(tmp, last_line_of_file(FDISK_LOG));
    1723         if (strstr(tmp, " (m "))
    1724         {
     1851        if (strstr(tmp, " (m ")) {
    17251852            log_msg(1, "Successfully created %s%d", drive, partno);
    1726         }
    1727         else
    1728         {
     1853        } else {
    17291854            log_msg(1, "last line = %s", tmp);
    1730             log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno);
    1731         }
    1732         if (!retval)
    1733         {
    1734             log_msg(1, "Trying to set %s%d's partition type now", drive, partno);
    1735             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1736             if (retval)
    1737             {
     1855            log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive,
     1856                    partno);
     1857        }
     1858        if (!retval) {
     1859            log_msg(1, "Trying to set %s%d's partition type now", drive,
     1860                    partno);
     1861            retval =
     1862                set_partition_type(pout_to_fdisk, drive, partno, format,
     1863                                   partsize);
     1864            if (retval) {
    17381865                log_msg(1, "Failed. Trying again...");
    1739                     retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1740             }
    1741           }
    1742         if (retval) { log_msg(1, "...but failed to set type"); }
    1743     }
    1744     else
    1745     {
     1866                retval =
     1867                    set_partition_type(pout_to_fdisk, drive, partno,
     1868                                       format, partsize);
     1869            }
     1870        }
     1871        if (retval) {
     1872            log_msg(1, "...but failed to set type");
     1873        }
     1874    } else {
    17461875        strcat(output, "w\n\n");
    1747             if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); }
     1876        if (g_fprep) {
     1877            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     1878        }
    17481879        /* write to disk; close fdisk's stream */
    17491880        if (!(fout = popen(program, "w"))) {
     
    17561887            log_it("Vaccum-packing");
    17571888            g_current_progress--;
    1758             res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1);
     1889            res =
     1890                partition_device(pout_to_fdisk, drive, partno, prev_partno,
     1891                                 format, -1);
    17591892            if (res) {
    17601893                sprintf(tmp, "Failed to vacuum-pack %s", partition_name);
     
    17661899        }
    17671900        if (does_partition_exist(drive, partno)) {
    1768             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
     1901            retval =
     1902                set_partition_type(pout_to_fdisk, drive, partno, format,
     1903                                   partsize);
    17691904            if (retval) {
    1770                 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name);
     1905                sprintf(tmp, "Partitioned %s but failed to set its type",
     1906                        partition_name);
    17711907                log_it(tmp);
    17721908            } else {
    17731909                if (partsize > 0) {
    1774                     sprintf(tmp, "Partition %s created+configured OK", partition_name);
     1910                    sprintf(tmp, "Partition %s created+configured OK",
     1911                            partition_name);
    17751912                    log_to_screen(tmp);
    17761913                } else {
     
    17781915                }
    17791916            }
    1780             } else {
     1917        } else {
    17811918            sprintf(tmp, "Failed to partition %s", partition_name);
    17821919            if (partsize > 0) {
     
    18301967        /*      mountlist=&new_mtlist; */
    18311968        /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
    1832         log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-");
     1969        log_msg(0,
     1970                "Mountlist, including the partitions incorporated in RAID devices:-");
    18331971        for (i = 0; i < mountlist->entries; i++) {
    18341972            log_it(mountlist->el[i].device);
     
    18371975    }
    18381976    log_msg(0, "Stopping all LVMs, just in case");
    1839         if (!g_text_mode) { newtSuspend(); }
    1840     do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
    1841         if (!g_text_mode) { newtResume(); }
     1977    if (!g_text_mode) {
     1978        newtSuspend();
     1979    }
     1980    do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
     1981    if (!g_text_mode) {
     1982        newtResume();
     1983    }
    18421984    log_msg(0, "Stopping all software RAID devices, just in case");
    18431985    stop_all_raid_devices(mountlist);
    18441986    log_msg(0, "Done.");
    1845    
     1987
    18461988/* 
    18471989    if (does_file_exist("/tmp/i-want-my-lvm"))
     
    18511993*/
    18521994
    1853     open_progress_form("Partitioning devices", "I am now going to partition all your drives.",
    1854                "This should not take more than five minutes.", "", mountlist->entries);
     1995    open_progress_form("Partitioning devices",
     1996                       "I am now going to partition all your drives.",
     1997                       "This should not take more than five minutes.", "",
     1998                       mountlist->entries);
    18551999
    18562000    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    18642008    if (retval) {
    18652009        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1866         log_to_screen("Errors occurred during the partitioning of your hard drives.");
     2010        log_to_screen
     2011            ("Errors occurred during the partitioning of your hard drives.");
    18672012    } else {
    18682013        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    18902035 * @return 0 for success, nonzero for failure.
    18912036 */
    1892 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize)
     2037int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno,
     2038                       const char *format, long long partsize)
    18932039{
    18942040    /** buffers *********************************************************/
    1895   char *partition;
    1896   char *command;
    1897   char *output;
    1898   char *tmp;
    1899   char *partcode;
    1900   char *logfile;
     2041    char *partition;
     2042    char *command;
     2043    char *output;
     2044    char *tmp;
     2045    char *partcode;
     2046    char *logfile;
    19012047
    19022048    /** pointers *********************************************************/
     
    19122058    assert(format != NULL);
    19132059
    1914   malloc_string(partition);
    1915   malloc_string(command);
    1916   malloc_string(output);
    1917   malloc_string(tmp);
    1918   malloc_string(partcode);
    1919   malloc_string(logfile);
     2060    malloc_string(partition);
     2061    malloc_string(command);
     2062    malloc_string(output);
     2063    malloc_string(tmp);
     2064    malloc_string(partcode);
     2065    malloc_string(logfile);
    19202066
    19212067    build_partition_name(partition, drive, partno);
     
    19302076            strcpy(partcode, "b");
    19312077        }
    1932     } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0
    1933            || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) {
     2078    } else if (strcmp(format, "ext2") == 0
     2079               || strcmp(format, "reiserfs") == 0
     2080               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
     2081               || strcmp(format, "jfs") == 0) {
    19342082        strcpy(partcode, "83");
    19352083    } else if (strcmp(format, "minix") == 0) {
     
    19382086        strcpy(partcode, "fd");
    19392087    } else if ((strcmp(format, "ufs") == 0)
    1940            || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
     2088               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    19412089        strcpy(partcode, "a5");
    19422090    } else if (strcmp(format, "lvm") == 0) {
     
    19482096    } else {
    19492097        /* probably an image */
    1950         sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format);
     2098        sprintf(tmp,
     2099                "Unknown format ('%s') - using supplied string anyway",
     2100                format);
    19512101        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    19522102#ifdef __FreeBSD__
    1953         strcpy(partcode, format); // was a5
     2103        strcpy(partcode, format);   // was a5
    19542104#else
    1955         strcpy(partcode, format); // was 83
    1956 #endif
    1957     }
    1958     sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode);
     2105        strcpy(partcode, format);   // was 83
     2106#endif
     2107    }
     2108    sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,
     2109            partcode);
    19592110    log_msg(1, tmp);
    19602111    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    1961        
    1962         if (pout_to_fdisk)
    1963         {
     2112
     2113        if (pout_to_fdisk) {
    19642114            res = 0;
    19652115            fput_string_one_char_at_a_time(pout_to_fdisk, "t\n");
    1966             if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))
    1967             {
     2116            if (partno > 1
     2117                || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
    19682118                log_msg(5, "Specifying partno (%d) - yay", partno);
    19692119                sprintf(tmp, "%d\n", partno);
    19702120                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1971                 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG));
    1972             }
    1973            
     2121                log_msg(5, "A - last line = '%s'",
     2122                        last_line_of_file(FDISK_LOG));
     2123            }
     2124
    19742125            sprintf(tmp, "%s\n", partcode);
    19752126            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1976             log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG));
     2127            log_msg(5, "B - last line = '%s'",
     2128                    last_line_of_file(FDISK_LOG));
    19772129            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    1978             log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG));
    1979            
     2130            log_msg(5, "C - last line = '%s'",
     2131                    last_line_of_file(FDISK_LOG));
     2132
    19802133            strcpy(tmp, last_line_of_file(FDISK_LOG));
    1981             if (!strstr(tmp, " (m "))
    1982               {
    1983                 log_msg(1, "last line = '%s'; part type set failed", tmp);
    1984                 res++;
    1985                 fput_string_one_char_at_a_time(pout_to_fdisk,"\n");
    1986               }
    1987             fput_string_one_char_at_a_time(pout_to_fdisk,"p\n");
    1988         }
    1989         else
    1990         {
     2134            if (!strstr(tmp, " (m ")) {
     2135                log_msg(1, "last line = '%s'; part type set failed", tmp);
     2136                res++;
     2137                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
     2138            }
     2139            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
     2140        } else {
    19912141            sprintf(output, "t\n%d\n%s\n", partno, partcode);
    19922142            strcat(output, "w\n");
    1993             sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     2143            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
     2144                    MONDO_LOGFILE, MONDO_LOGFILE);
    19942145            log_msg(5, "output = '%s'", output);
    19952146            log_msg(5, "partno=%d; partcode=%s", partno, partcode);
     
    20052156            }
    20062157        }
    2007     if (res)
    2008       {
    2009         log_OS_error(command);
    2010       }
    2011     }
    2012 
    2013   paranoid_free(partition);
    2014   paranoid_free(command);
    2015   paranoid_free(output);
    2016   paranoid_free(tmp);
    2017   paranoid_free(partcode);
    2018   paranoid_free(logfile);
    2019 
    2020   return (res);
     2158        if (res) {
     2159            log_OS_error(command);
     2160        }
     2161    }
     2162
     2163    paranoid_free(partition);
     2164    paranoid_free(command);
     2165    paranoid_free(output);
     2166    paranoid_free(tmp);
     2167    paranoid_free(partcode);
     2168    paranoid_free(logfile);
     2169
     2170    return (res);
    20212171}
    20222172
     
    20352185    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20362186    malloc_string(program);
    2037    
     2187
    20382188#ifdef __FreeBSD__
    20392189    if (is_this_device_mounted(raid_device)) {
     
    20482198    log_msg(1, "program = %s", program);
    20492199    res = run_program_and_log_output(program, 1);
    2050     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2051     if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); }
     2200    if (g_fprep) {
     2201        fprintf(g_fprep, "%s\n", program);
     2202    }
     2203    if (res) {
     2204        log_msg(1, "Warning - failed to start RAID device %s",
     2205                raid_device);
     2206    }
    20522207    retval += res;
    20532208    sleep(1);
     
    20752230    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20762231    malloc_string(program);
    2077    
     2232
    20782233#ifdef __FreeBSD__
    20792234    if (is_this_device_mounted(raid_device)) {
     
    20882243    log_msg(1, "program = %s", program);
    20892244    res = run_program_and_log_output(program, 1);
    2090     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2091     if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); }
     2245    if (g_fprep) {
     2246        fprintf(g_fprep, "%s\n", program);
     2247    }
     2248    if (res) {
     2249        log_msg(1, "Warning - failed to stop RAID device %s", raid_device);
     2250    }
    20922251    retval += res;
    20932252    return (retval);
     
    20982257{
    20992258    int i;
    2100     int retval=0;
     2259    int retval = 0;
    21012260    int res;
    2102    
    2103     for(i=0; i<mountlist->entries; i++)
    2104       {
    2105         if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)))
    2106           {
    2107             log_msg(1, "Starting %s", mountlist->el[i].device);
    2108         res = start_raid_device(mountlist->el[i].device);
    2109         retval += res;
    2110           }
    2111       }
    2112     if (retval) { log_msg(1, "Started all s/w raid devices OK"); }
    2113     else { log_msg(1, "Failed to start some/all s/w raid devices"); }
    2114     return(retval);
     2261
     2262    for (i = 0; i < mountlist->entries; i++) {
     2263        if (!strncmp
     2264            (mountlist->el[i].device, RAID_DEVICE_STUB,
     2265             strlen(RAID_DEVICE_STUB))) {
     2266            log_msg(1, "Starting %s", mountlist->el[i].device);
     2267            res = start_raid_device(mountlist->el[i].device);
     2268            retval += res;
     2269        }
     2270    }
     2271    if (retval) {
     2272        log_msg(1, "Started all s/w raid devices OK");
     2273    } else {
     2274        log_msg(1, "Failed to start some/all s/w raid devices");
     2275    }
     2276    return (retval);
    21152277}
    21162278
     
    21492311    for (i = 0; i < 3; i++) {
    21502312#ifdef __FreeBSD__
    2151         fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r");
     2313        fin =
     2314            popen
     2315            ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2",
     2316             "r");
    21522317        if (!fin) {
    21532318            paranoid_free(dev);
     
    21552320            return (1);
    21562321        }
    2157         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2322        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2323             fgets(incoming, MAX_STR_LEN - 1, fin)) {
    21582324            retval += stop_raid_device(incoming);
    21592325        }
     
    21662332            return (1);
    21672333        }
    2168         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
    2169             for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++);
     2334        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2335             fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2336            for (p = incoming;
     2337                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
     2338                                || !isdigit(*(p + 2))); p++);
    21702339            if (*p != '\0') {
    21712340                sprintf(dev, "/dev/%s", p);
     
    21782347    }
    21792348    paranoid_fclose(fin);
    2180     if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); }
     2349    if (retval) {
     2350        log_msg(1, "Warning - unable to stop some RAID devices");
     2351    }
    21812352    paranoid_free(dev);
    21822353    paranoid_free(incoming);
    2183     system("sync"); system("sync"); system("sync");
     2354    system("sync");
     2355    system("sync");
     2356    system("sync");
    21842357    sleep(1);
    21852358    return (retval);
     
    22362409        sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    22372410#endif
    2238         sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program);
     2411        sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2412                program);
    22392413        log_it(tmp);
    22402414        res = 0;
     
    22532427 */
    22542428long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself
    2255                         *mountlist, char *drive_name)
     2429                                            *mountlist, char *drive_name)
    22562430{
    22572431    /** long ************************************************************/
     
    22702444    assert_string_is_neither_NULL_nor_zerolength(drive_name);
    22712445
    2272     for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) {
    2273         if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) {
     2446    for (original_size_of_drive = 0, partno = 0;
     2447         partno < mountlist->entries; partno++) {
     2448        if (strncmp
     2449            (mountlist->el[partno].device, drive_name,
     2450             strlen(drive_name)) == 0) {
    22742451            original_size_of_drive += mountlist->el[partno].size;
    22752452        } else {
     
    22962473 */
    22972474void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself
    2298                              *mountlist, char *drive_name)
     2475                                                     *mountlist,
     2476                                                     char *drive_name)
    22992477{
    23002478    /**buffers **********************************************************/
     
    23032481    /** int *************************************************************/
    23042482    int partno, lastpart;
    2305                /** remove driveno, noof_drives stan benoit apr 2002**/
     2483               /** remove driveno, noof_drives stan benoit apr 2002**/
    23062484
    23072485    /** float ***********************************************************/
    23082486    float factor;
    23092487    float new_size;
    2310 //  float newcylinderno;
     2488//  float newcylinderno;
    23112489
    23122490    /** long *************************************************************/
     
    23142492    long current_size_of_drive = 0;
    23152493    long original_size_of_drive = 0;
    2316     long final_size;    /* all in Megabytes */
     2494    long final_size;            /* all in Megabytes */
    23172495    struct mountlist_reference *drivemntlist;
    23182496
     
    23262504
    23272505    if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) {
    2328         if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) {
     2506        if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))
     2507            == 0) {
    23292508            paranoid_free(tmp);
    23302509            return;
     
    23382517
    23392518    current_size_of_drive = get_phys_size_of_drive(drive_name);
    2340    
     2519
    23412520    if (current_size_of_drive <= 0) {
    23422521        log_it("Not resizing to match %s - can't find drive", drive_name);
     
    23442523        return;
    23452524    }
    2346     sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive);
     2525    sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name,
     2526            current_size_of_drive);
    23472527    log_to_screen(tmp);
    23482528
    2349     drivemntlist = malloc(sizeof (struct mountlist_reference));
    2350     drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
     2529    drivemntlist = malloc(sizeof(struct mountlist_reference));
     2530    drivemntlist->el =
     2531        malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
    23512532
    23522533    if (!drivemntlist) {
     
    23612542
    23622543    if (original_size_of_drive <= 0) {
    2363         sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name);
     2544        sprintf(tmp, "Cannot resize %s's entries. Drive not found.",
     2545                drive_name);
    23642546        log_to_screen(tmp);
    23652547        paranoid_free(tmp);
    23662548        return;
    23672549    }
    2368     factor = (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2369     sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive,
    2370         factor);
     2550    factor =
     2551        (float) (current_size_of_drive) / (float) (original_size_of_drive);
     2552    sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2553            drive_name, original_size_of_drive, current_size_of_drive,
     2554            factor);
    23712555    log_to_screen(tmp);
    23722556
    2373     lastpart = drivemntlist->entries-1;
     2557    lastpart = drivemntlist->entries - 1;
    23742558    for (partno = 0; partno < drivemntlist->entries; partno++) {
    23752559        /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */
    2376         if ( !atoi(drivemntlist->el[partno]->format) ) {
     2560        if (!atoi(drivemntlist->el[partno]->format)) {
    23772561            new_size = (float) (drivemntlist->el[partno]->size) * factor;
    23782562        } else {
    23792563            new_size = drivemntlist->el[partno]->size;
    23802564        }
    2381        
     2565
    23822566        if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) {
    23832567            log_msg(1, "Skipping %s (%s) because it's an image",
    2384                             drivemntlist->el[partno]->device,
    2385                             drivemntlist->el[partno]->mountpoint);
    2386             newsizL = (long) new_size; // It looks wrong but it's not
     2568                    drivemntlist->el[partno]->device,
     2569                    drivemntlist->el[partno]->mountpoint);
     2570            newsizL = (long) new_size;  // It looks wrong but it's not
    23872571        } else {
    23882572            newsizL = (long) new_size;
    23892573        }
    2390         sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL);
     2574        sprintf(tmp, "Changing %s from %lld KB to %ld KB",
     2575                drivemntlist->el[partno]->device,
     2576                drivemntlist->el[partno]->size, newsizL);
    23912577        log_to_screen(tmp);
    23922578        drivemntlist->el[partno]->size = newsizL;
     
    24062592 */
    24072593void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself
    2408                             *mountlist)
     2594                                                        *mountlist)
    24092595{
    24102596    /** buffers *********************************************************/
     
    24202606
    24212607    if (g_mountlist_fname[0] == '\0') {
    2422         log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank");
    2423         log_it ("That does NOT affect the functioning of this subroutine.");
    2424         log_it ("--- Hugo, 2002/11/20");
     2608        log_it
     2609            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
     2610        log_it("That does NOT affect the functioning of this subroutine.");
     2611        log_it("--- Hugo, 2002/11/20");
    24252612    }
    24262613    iamhere("Resizing mountlist");
     
    24282615    iamhere("Back from MLoDiM");
    24292616    for (driveno = 0; driveno < drivelist->entries; driveno++) {
    2430         resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device);
     2617        resize_drive_proportionately_to_suit_new_drives(mountlist,
     2618                                                        drivelist->
     2619                                                        el[driveno].
     2620                                                        device);
    24312621    }
    24322622    log_to_screen("Mountlist adjusted to suit current hard drive(s)");
     
    24422632 * @author Ralph Grewe
    24432633 */
    2444 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) {
     2634void create_mountlist_for_drive(struct mountlist_itself *mountlist,
     2635                                char *drive_name,
     2636                                struct mountlist_reference *drivemntlist)
     2637{
    24452638    int partno;
    24462639    char *tmp_drive_name, *c;
     
    24502643    assert(drivemntlist != NULL);
    24512644
    2452     log_msg (1, "Creating list of partitions for drive %s",drive_name);
    2453 
    2454     tmp_drive_name = strdup (drive_name);
    2455     if (!tmp_drive_name) fatal_error ("Out of memory");
    2456    
     2645    log_msg(1, "Creating list of partitions for drive %s", drive_name);
     2646
     2647    tmp_drive_name = strdup(drive_name);
     2648    if (!tmp_drive_name)
     2649        fatal_error("Out of memory");
     2650
    24572651    /* devfs devices? */
    2458     c = strrchr (tmp_drive_name, '/');
    2459     if (c && strncmp (c, "/disc", 5) == 0) {
    2460         /* yup its devfs, change the "disc" to "part" so the existing code works */
    2461         strcpy (c + 1, "part");
    2462     }
    2463     drivemntlist->entries=0;
     2652    c = strrchr(tmp_drive_name, '/');
     2653    if (c && strncmp(c, "/disc", 5) == 0) {
     2654        /* yup its devfs, change the "disc" to "part" so the existing code works */
     2655        strcpy(c + 1, "part");
     2656    }
     2657    drivemntlist->entries = 0;
    24642658    for (partno = 0; partno < mountlist->entries; partno++) {
    2465         if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) {
    2466             drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno];
     2659        if (strncmp
     2660            (mountlist->el[partno].device, tmp_drive_name,
     2661             strlen(tmp_drive_name)) == 0) {
     2662            drivemntlist->el[drivemntlist->entries] =
     2663                &mountlist->el[partno];
    24672664            drivemntlist->entries++;
    24682665        }
    24692666    }
    24702667    if (tmp_drive_name)
    2471         free (tmp_drive_name);
     2668        free(tmp_drive_name);
    24722669}
    24732670
Note: See TracChangeset for help on using the changeset viewer.