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

Trunk: indent on all source files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c

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