source: MondoRescue/branches/2.2.9/mondo/src/mondorestore/mondo-rstr-newt.c@ 2770

Last change on this file since 2770 was 2770, checked in by Bruno Cornec, 13 years ago
  • Fix compilation issues due to level of visibility of functions
  • Property svn:keywords set to Id
File size: 87.4 KB
RevLine 
[1]1/***************************************************************************
[2094]2 * $Id: mondo-rstr-newt.c 2770 2011-04-21 12:14:52Z bruno $
[1]3 * Functions for handling GUI interfaces in the restore.
4 */
5
6#ifdef __FreeBSD__
7#define OSSWAP(linux,fbsd) fbsd
8#else
9#define OSSWAP(linux,fbsd) linux
10#endif
11
12#include "mondo-rstr-newt.h"
[2211]13#include "mr_mem.h"
[1]14
[128]15//static char cvsid[] = "$Id: mondo-rstr-newt.c 2770 2011-04-21 12:14:52Z bruno $";
[1]16
[2770]17extern bool popup_with_buttons(char *p, char *button1, char *button2);
[1]18extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
19
20/**
21 * @defgroup restoreGuiDisklist Disklist GUI
22 * Functions for manipulating the disklist GUI.
23 * @ingroup restoreGuiGroup
24 */
25/**
26 * @defgroup restoreGuiMountlist Mountlist GUI
27 * Functions for manipulating the mountlist/raidlist GUI.
28 * @ingroup restoreGuiGroup
29 */
30/**
31 * @defgroup restoreGuiVarslist RAID Variables GUI
32 * Functions for manipulating the RAID variables GUI.
33 * @ingroup restoreGuiGroup
34 */
35
36/**
37 * @addtogroup restoreGuiGroup
38 * @{
39 */
40/**
41 * Add an entry in @p disklist from the list in @p unallocated_raid_partitions.
42 * @param disklist The disklist to add an entry to.
43 * @param raid_device Unused; make sure it's non-NULL non-"".
44 * @param unallocated_raid_partitions The list of unallocated RAID partitions
45 * that the user may choose from.
46 * @bug raid_device is unused.
47 * @ingroup restoreGuiDisklist
48 */
49void
[128]50add_disklist_entry(struct list_of_disks *disklist, char *raid_device,
51 struct mountlist_itself *unallocated_raid_partitions)
[1]52{
53 /** buffers ***********************************************************/
[128]54 char tmp[MAX_STR_LEN];
[1]55
56 /** newt **************************************************************/
[128]57 newtComponent myForm;
[1]58 newtComponent bOK;
59 newtComponent bCancel;
60 newtComponent b_res;
61 newtComponent partitionsListbox;
62 newtComponent headerMsg;
[128]63
[1]64 /** prototypes *********************************************************/
[128]65 void *keylist[ARBITRARY_MAXIMUM];
66 void *curr_choice;
[1]67
68 /** int ****************************************************************/
[128]69 int i = 0;
[1]70 int index = 0;
71 int currline = 0;
72 int items = 0;
73
[128]74 assert(disklist != NULL);
75 assert_string_is_neither_NULL_nor_zerolength(raid_device);
76 assert(unallocated_raid_partitions != NULL);
[1]77
[128]78 newtPushHelpLine
[541]79 (" Add one of the following unallocated RAID partitions to this RAID device.");
80 sprintf(tmp, "%-26s %s", "Device", "Size");
[128]81 headerMsg = newtLabel(1, 1, tmp);
82 partitionsListbox =
83 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
84 redraw_unallocpartnslist(unallocated_raid_partitions, keylist,
85 partitionsListbox);
86 i = 7;
[541]87 bOK = newtCompactButton(i, 9, " OK ");
88 bCancel = newtCompactButton(i += 9, 9, "Cancel");
89 newtOpenWindow(22, 6, 36, 10, "Unallocated RAID partitions");
[128]90 myForm = newtForm(NULL, NULL, 0);
91 newtFormAddComponents(myForm, headerMsg, partitionsListbox, bOK,
92 bCancel, NULL);
93 b_res = newtRunForm(myForm);
94 if (b_res != bCancel) {
95 curr_choice = newtListboxGetCurrent(partitionsListbox);
96 for (currline = 0;
97 currline < unallocated_raid_partitions->entries
98 && keylist[currline] != curr_choice; currline++);
99 if (currline == unallocated_raid_partitions->entries
100 && unallocated_raid_partitions->entries > 0) {
101 log_it("I don't know what this button does");
102 } else {
103 index = find_next_free_index_in_disklist(disklist);
104
105 items = disklist->entries;
106 strcpy(disklist->el[items].device,
107 unallocated_raid_partitions->el[currline].device);
108 disklist->el[items].index = index;
109 disklist->entries = ++items;
110
111 }
[1]112 }
[128]113 newtFormDestroy(myForm);
114 newtPopWindow();
115 newtPopHelpLine();
[1]116}
117
118
119
120
121/**
122 * Add an entry to @p mountlist.
123 * @param mountlist The mountlist to add an entry to.
124 * @param raidlist The raidlist that accompanies @p mountlist.
125 * @param listbox The listbox component in the mountlist editor.
126 * @param currline The line selected in @p listbox.
127 * @param keylist The list of keys for @p listbox.
128 * @ingroup restoreGuiMountlist
129 */
130void
[128]131add_mountlist_entry(struct mountlist_itself *mountlist,
132 struct raidlist_itself *raidlist,
133 newtComponent listbox, int currline, void *keylist[])
[1]134{
135
136 /** int **************************************************************/
[128]137 int i = 0;
[1]138 int num_to_add = 0;
139
140 /** newt *************************************************************/
[128]141 newtComponent myForm;
[1]142 newtComponent bOK;
143 newtComponent bCancel;
144 newtComponent b_res;
145 newtComponent mountpointComp;
146 newtComponent label0;
147 newtComponent label1;
148 newtComponent label2;
149 newtComponent label3;
150 newtComponent sizeComp;
151 newtComponent deviceComp;
152 newtComponent formatComp;
153
154 /** buffers **********************************************************/
[128]155 char drive_to_add[MAX_STR_LEN];
[1]156 char mountpoint_str[MAX_STR_LEN];
157 char size_str[MAX_STR_LEN];
[128]158 char device_str[MAX_STR_LEN];
[1]159 char format_str[MAX_STR_LEN];
160
161 /** pointers *********************************************************/
162 char *mountpoint_here;
163 char *size_here;
164 char *device_here;
165 char *format_here;
166
[128]167 assert(mountlist != NULL);
168 assert(raidlist != NULL);
169 assert(listbox != NULL);
170 assert(keylist != NULL);
[1]171
[128]172 strcpy(device_str, "/dev/");
173 strcpy(mountpoint_str, "/");
[1]174#ifdef __FreeBSD__
[128]175 strcpy(format_str, "ufs");
[1]176#else
[1741]177 strcpy(format_str, "ext3");
[1]178#endif
[128]179 size_str[0] = '\0';
180 /* sprintf(size_str,""); */
[541]181 newtOpenWindow(20, 5, 48, 10, "Add entry");
182 label0 = newtLabel(2, 1, "Device: ");
183 label1 = newtLabel(2, 2, "Mountpoint:");
184 label2 = newtLabel(2, 3, "Size (MB): ");
185 label3 = newtLabel(2, 4, "Format: ");
[128]186 deviceComp =
187 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
188 mountpointComp =
189 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
190 formatComp =
191 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
192 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
[541]193 bOK = newtButton(5, 6, " OK ");
194 bCancel = newtButton(17, 6, "Cancel");
[128]195 newtPushHelpLine
[541]196 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'");
[128]197 myForm = newtForm(NULL, NULL, 0);
198 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
199 formatComp, label0, label1, label2, label3, bOK,
200 bCancel, NULL);
201 for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
202 b_res = newtRunForm(myForm);
203 strcpy(device_str, device_here);
204 strcpy(mountpoint_str, mountpoint_here);
205 strcpy(format_str, format_here);
206 strcpy(size_str, size_here);
[1]207// log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
[128]208 strip_spaces(device_str);
209 strip_spaces(mountpoint_str);
210 strip_spaces(format_str);
211 strip_spaces(size_str);
[1]212// log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
[128]213 if (b_res == bOK) {
214 if (device_str[strlen(device_str) - 1] == '/') {
[541]215 popup_and_OK("You left the device nearly blank!");
[128]216 b_res = NULL;
217 }
218 if (size_of_specific_device_in_mountlist(mountlist, device_str)
219 >= 0) {
[541]220 popup_and_OK("Can't add this - you've got one already!");
[128]221 b_res = NULL;
222 }
223 }
[1]224 }
[128]225 newtFormDestroy(myForm);
226 newtPopHelpLine();
227 newtPopWindow();
228 if (b_res == bCancel) {
229 return;
230 }
231 strcpy(drive_to_add, device_str);
232 for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--);
233 num_to_add = atoi(drive_to_add + i);
234 drive_to_add[i] = '\0';
235 currline = mountlist->entries;
236 strcpy(mountlist->el[currline].device, device_str);
237 strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
238 strcpy(mountlist->el[currline].format, format_str);
[2125]239 mountlist->el[currline].size = atol(size_str) * 1024L;
[128]240 mountlist->entries++;
241 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
242 initiate_new_raidlist_entry(raidlist, mountlist, currline,
243 device_str);
244 }
245 redraw_mountlist(mountlist, keylist, listbox);
[1]246}
247
248
249#ifndef __FreeBSD__
250/**
251 * Add an entry to the additional RAID variables section of @p raidrec.
252 * @param raidrec The RAID device record containing the RAID variables list to add to.
253 * @ingroup restoreGuiVarslist
254 */
[128]255void add_varslist_entry(struct raid_device_record *raidrec)
[1]256{
257
258 /** buffers ***********************************************************/
[128]259 char sz_out[MAX_STR_LEN];
[1]260
261 /** int ****************************************************************/
[128]262 int items = 0;
[1]263 int i = 0;
264
[128]265 assert(raidrec != NULL);
[1]266
[128]267 sz_out[0] = '\0';
268 if (popup_and_get_string
[541]269 ("Add variable", "Enter the name of the variable to add", sz_out,
[128]270 MAX_STR_LEN)) {
271 strip_spaces(sz_out);
272 items = raidrec->additional_vars.entries;
273 for (i = 0;
274 i < items
275 && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++);
276 if (i < items) {
277 popup_and_OK
[541]278 ("No need to add that variable. It is already listed here.");
[128]279 } else {
280 strcpy(raidrec->additional_vars.el[items].label, sz_out);
281 edit_varslist_entry(raidrec, items);
282 raidrec->additional_vars.entries = ++items;
283 }
[1]284 }
285}
286#endif
287
288/**
289 * Calculate the size of @p raid_device.
290 * @param mountlist The mountlist containing information about the user's partitions.
291 * @param raidlist The raidlist that goes with @p mountlist.
292 * @param raid_device The device to calculate the size of.
293 * @return The size of the RAID device in Kilobytes.
294 * @ingroup restoreUtilityGroup
295 */
296long
[128]297calculate_raid_device_size(struct mountlist_itself *mountlist,
298 struct raidlist_itself *raidlist,
299 char *raid_device)
[1]300{
301#ifdef __FreeBSD__
[128]302 /** FreeBSD-specific version of calculate_raid_device_size() **/
[1]303
304 /** structures ********************************************************/
[128]305 struct vinum_volume *raidrec;
[1]306
307 /** int ***************************************************************/
[128]308 int i = 0, j = 0;
[1]309 int noof_partitions = 0;
310
311 /** long **************************************************************/
[128]312 long total_size = 0;
313 long plex_size = 0;
314 long smallest_partition = 999999999;
315 long smallest_plex = 999999999;
[1]316 long sp = 0;
317
318 /** buffers ***********************************************************/
[128]319 char tmp[MAX_STR_LEN];
[1]320
321
322
323
[128]324 for (i = 0;
325 i < raidlist->entries
326 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
327 if (i == raidlist->entries) {
328 sprintf(tmp,
329 "Cannot calc size of raid device %s - cannot find it in raidlist",
330 raid_device);
331 log_it(tmp);
332 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists,
333 // then it has no size, right?
334 }
335 raidrec = &raidlist->el[i];
336 total_size = 0;
337 if (raidrec->plexes == 0)
338 return 0;
339 for (j = 0; j < raidrec->plexes; j++) {
340 plex_size = 0;
341 int k = 0, l = 0;
342 for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
343 char devname[64];
344 strcpy(devname, raidrec->plex[j].sd[k].which_device);
345 for (l = 0; l < raidlist->disks.entries; ++l) {
346 if (!strcmp(devname, raidlist->disks.el[l].name)) {
347 switch (raidrec->plex[j].raidlevel) {
348 case -1:
349 plex_size +=
350 size_of_specific_device_in_mountlist(mountlist,
351 raidlist->
352 disks.
353 el[l].
354 device);
355 break;
356 case 0:
357 case 5:
358 if (size_of_specific_device_in_mountlist(mountlist,
359 raidlist->
360 disks.
361 el[l].
362 device) <
363 smallest_partition) {
364 smallest_partition =
365 size_of_specific_device_in_mountlist
366 (mountlist, raidlist->disks.el[l].device);
367 }
368 break;
369 }
370 }
371 }
372 }
[1]373
[128]374 if (!is_this_raid_personality_registered
375 (raidrec->plex[j].raidlevel)) {
376 log_it
377 ("%s has a really weird RAID level - couldn't calc size :(",
378 raid_device);
379 return (999999999);
380 }
381 if (raidrec->plex[j].raidlevel != -1) {
382 plex_size = smallest_partition * (raidrec->plex[j].subdisks -
383 (raidrec->plex[j].
384 raidlevel == 5 ? 1 : 0));
385 }
386 if (plex_size < smallest_plex)
387 smallest_plex = plex_size;
[1]388
[128]389 smallest_partition = 999999999;
390 }
391
392 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
393 (long) smallest_plex);
394 log_it(tmp);
395 return (smallest_plex);
[1]396#else
[128]397 /** Linux-specific version of calculate_raid_device_size() **/
[1]398
399 /** structures ********************************************************/
[128]400 struct raid_device_record *raidrec;
[1]401
402 /** int ***************************************************************/
[128]403 int i = 0;
[1]404 int noof_partitions = 0;
405
406 /** long **************************************************************/
[128]407 long total_size = 0;
[1]408 long smallest_partition = 999999999;
409 long sp = 0;
410
411 /** buffers ***********************************************************/
[128]412 char tmp[MAX_STR_LEN];
[1]413
[128]414 assert(mountlist != NULL);
415 assert(raidlist != NULL);
416 assert_string_is_neither_NULL_nor_zerolength(raid_device);
[1]417
[128]418 for (i = 0;
419 i < raidlist->entries
420 && strcmp(raidlist->el[i].raid_device, raid_device); i++);
421 if (i == raidlist->entries) {
422 sprintf(tmp,
423 "Cannot calc size of raid device %s - cannot find it in raidlist",
424 raid_device);
425 log_it(tmp);
426 return (999999999);
[1]427 }
[128]428 raidrec = &raidlist->el[i];
429 noof_partitions = raidrec->data_disks.entries;
430 if (raidrec->raid_level == -1 || raidrec->raid_level == 0) {
431 for (total_size = 0, i = 0; i < noof_partitions; i++) {
432 total_size +=
433 size_of_specific_device_in_mountlist(mountlist,
434 raidrec->data_disks.
435 el[i].device);
436 }
437 } else {
438 for (i = 0; i < noof_partitions; i++) {
439 sp = size_of_specific_device_in_mountlist(mountlist,
440 raidrec->data_disks.
441 el[i].device);
442 if (smallest_partition > sp) {
443 smallest_partition = sp;
444 }
445 }
446 total_size = smallest_partition * (noof_partitions - 1);
[1]447 }
[128]448 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
449 (long) total_size);
450 log_it(tmp);
451 return (total_size);
[1]452#endif
453}
454
455
456
457/**
458 * Choose the RAID level for the RAID device record in @p raidrec.
459 * @param raidrec The RAID device record to set the RAID level of.
460 * @ingroup restoreGuiMountlist
461 */
462void
[128]463choose_raid_level(struct OSSWAP (raid_device_record, vinum_plex) * raidrec)
[1]464{
465
466#ifdef __FreeBSD__
[128]467
[1]468 /** int ***************************************************************/
[128]469 int res = 0;
[1]470 int out = 0;
471
472 /** buffers ***********************************************************/
[128]473 char tmp[MAX_STR_LEN];
474 char prompt[MAX_STR_LEN];
475 char sz[MAX_STR_LEN];
[1]476
[128]477 sprintf(prompt,
[541]478 "Please enter the RAID level you want. (concat, striped, raid5)");
[128]479 if (raidrec->raidlevel == -1) {
480 strcpy(tmp, "concat");
481 } else if (raidrec->raidlevel == 0) {
482 strcpy(tmp, "striped");
483 } else {
484 sprintf(tmp, "raid%i", raidrec->raidlevel);
[1]485 }
[128]486 for (out = 999; out == 999;) {
487 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
488 if (!res) {
489 return;
490 }
491 strip_spaces(tmp);
492 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
493 strcpy(sz, tmp);
494 strncpy(tmp, sz + 1, strlen(sz) - 2);
495 tmp[strlen(sz) - 2] = '\0';
496 }
497 if (!strcmp(tmp, "concat")) {
498 out = -1;
499 } else if (!strcmp(tmp, "striped")) {
500 out = 0;
501 } else if (!strcmp(tmp, "raid5")) {
502 out = 5;
503 }
504 log_it(tmp);
505 if (is_this_raid_personality_registered(out)) {
506 log_it
507 ("Groovy. You've picked a RAID personality which is registered.");
508 } else {
509 if (ask_me_yes_or_no
510 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
511 {
512 out = 999;
513 }
514 }
[1]515 }
[128]516 raidrec->raidlevel = out;
[1]517#else
518 /** buffers ***********************************************************/
[128]519 char tmp[MAX_STR_LEN];
[1]520 char personalities[MAX_STR_LEN];
521 char prompt[MAX_STR_LEN];
522 char sz[MAX_STR_LEN];
[128]523 int out = 0, res = 0;
[1]524
525
[128]526 assert(raidrec != NULL);
527 system
[273]528 ("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
[128]529 strcpy(personalities,
530 last_line_of_file("/tmp/raid-personalities.txt"));
[541]531 sprintf(prompt, "Please enter the RAID level you want. %s",
[128]532 personalities);
533 if (raidrec->raid_level == -1) {
534 strcpy(tmp, "linear");
535 } else {
536 sprintf(tmp, "%d", raidrec->raid_level);
[1]537 }
[128]538 for (out = 999;
539 out != -1 && out != 0 && out != 1 && out != 4 && out != 5
540 && out != 10;) {
[541]541 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
[128]542 if (!res) {
543 return;
544 }
545 strip_spaces(tmp);
546 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
547 strcpy(sz, tmp);
548 strncpy(tmp, sz + 1, strlen(sz) - 2);
549 tmp[strlen(sz) - 2] = '\0';
550 }
551 if (!strcmp(tmp, "linear")) {
552 out = -1;
553 } else if (!strncmp(tmp, "raid", 4)) {
554 out = atoi(tmp + 4);
555 } else {
556 out = atoi(tmp);
557 }
558 log_it(tmp);
559 if (is_this_raid_personality_registered(out)) {
560 log_it
561 ("Groovy. You've picked a RAID personality which is registered.");
562 } else {
563 if (ask_me_yes_or_no
[541]564 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
[128]565 {
566 out = 999;
567 }
568 }
[1]569 }
[128]570 raidrec->raid_level = out;
[1]571#endif
572}
573
574
575
576/**
577 * Delete the partitions in @p disklist from @p mountlist because they
578 * were part of a deleted RAID device.
579 * @param mountlist The mountlist containing information about the user's partitions.
580 * @param raidlist The raidlist that goes with @p mounntlist.
581 * @param disklist The list of disks to remove from @p mountlist.
582 * @ingroup restoreGuiDisklist
583 */
584void
[128]585del_partns_listed_in_disklist(struct mountlist_itself *mountlist,
586 struct raidlist_itself *raidlist,
587 struct list_of_disks *disklist)
[1]588{
589
590 /** int ***************************************************************/
[128]591 int i = 0;
[1]592 int pos = 0;
593
594 /** buffers ***********************************************************/
[128]595 char tmp[MAX_STR_LEN];
[1]596
[128]597 assert(mountlist != NULL);
598 assert(raidlist != NULL);
599 assert(disklist != NULL);
[1]600
[128]601 for (i = 0; i < disklist->entries; i++) {
602 for (pos = 0;
603 pos < mountlist->entries
604 && strcmp(mountlist->el[pos].device, disklist->el[i].device);
605 pos++);
606 if (pos < mountlist->entries) {
607 sprintf(tmp,
608 "Deleting partition %s cos it was part of a now-defunct RAID",
609 mountlist->el[pos].device);
610 log_it(tmp);
611 memcpy((void *) &mountlist->el[pos],
612 (void *) &mountlist->el[mountlist->entries - 1],
613 sizeof(struct mountlist_line));
614 mountlist->entries--;
615 }
[1]616 }
617}
618
619
620
621/**
622 * Delete entry number @p currline from @p disklist.
623 * @param disklist The disklist to remove the entry from.
624 * @param raid_device The RAID device containing the partition we're removing.
625 * Used only in the popup "are you sure?" box.
626 * @param currline The line number (starting from 0) of the item to delete.
627 * @ingroup restoreGuiDisklist
628 */
629void
[128]630delete_disklist_entry(struct list_of_disks *disklist, char *raid_device,
631 int currline)
[1]632{
633
634 /** int ***************************************************************/
[128]635 int pos = 0;
[1]636
637 /** buffers ***********************************************************/
[128]638 char tmp[MAX_STR_LEN];
[1]639
[128]640 assert(disklist != NULL);
641 assert_string_is_neither_NULL_nor_zerolength(raid_device);
[1]642
[541]643 sprintf(tmp, "Delete %s from RAID device %s - are you sure?",
[128]644 disklist->el[currline].device, raid_device);
645 if (!ask_me_yes_or_no(tmp)) {
646 return;
647 }
648 for (pos = currline; pos < disklist->entries - 1; pos++) {
649 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
650 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device);
651 }
652 disklist->entries--;
[1]653}
654
655
656
657/**
658 * Delete entry number @p currline from @p mountlist.
659 * @param mountlist The mountlist to delete the entry from.
660 * @param raidlist The raidlist that goes with @p mountlist.
661 * @param listbox The Newt listbox component in the mountlist editor.
662 * @param currline The line number (starting from 0) of the item to delete.
663 * @param keylist The list of keys for @p listbox.
664 * @ingroup restoreGuiMountlist
665 */
666void
[128]667delete_mountlist_entry(struct mountlist_itself *mountlist,
668 struct raidlist_itself *raidlist,
669 newtComponent listbox, int currline,
670 void *keylist[])
[1]671{
672
673 /** int ***************************************************************/
[128]674 int pos = 0;
[1]675
676 /** buffers ***********************************************************/
[128]677 char tmp[MAX_STR_LEN];
[1]678 char device[MAX_STR_LEN];
679
680
[128]681 assert(mountlist != NULL);
682 assert(raidlist != NULL);
683 assert(listbox != NULL);
684 assert(keylist != NULL);
[1]685
[128]686 pos =
687 which_raid_device_is_using_this_partition(raidlist,
688 mountlist->el[currline].
689 device);
690 if (pos >= 0) {
[541]691 sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s",
[128]692 mountlist->el[currline].device,
693 raidlist->el[pos].OSSWAP(raid_device, volname));
694 popup_and_OK(tmp);
695 return;
[1]696 }
[541]697 sprintf(tmp, "Delete %s - are you sure?",
[128]698 mountlist->el[currline].device);
699 if (!ask_me_yes_or_no(tmp)) {
700 return;
701 }
702 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
703 strcpy(device, mountlist->el[currline].device);
704 delete_raidlist_entry(mountlist, raidlist, device);
705 for (currline = 0;
706 currline < mountlist->entries
707 && strcmp(mountlist->el[currline].device, device);
708 currline++);
709 if (currline == mountlist->entries) {
710 log_it("Dev is gone. I can't delete it. Ho-hum");
711 return;
712 }
713 }
714 memcpy((void *) &mountlist->el[currline],
715 (void *) &mountlist->el[mountlist->entries - 1],
716 sizeof(struct mountlist_line));
717 mountlist->entries--;
718 redraw_mountlist(mountlist, keylist, listbox);
[1]719}
720
721
722/**
723 * Delete @p device from @p raidlist.
724 * @param mountlist The mountlist containing information about the user's partitions.
725 * @param raidlist The raidlist containing the RAID device to delete.
726 * @param device The device (e.g. /dev/md0) to delete.
727 * @ingroup restoreGuiMountlist
728 */
729void
[128]730delete_raidlist_entry(struct mountlist_itself *mountlist,
731 struct raidlist_itself *raidlist, char *device)
[1]732{
[128]733
[1]734 /** int ***************************************************************/
[128]735 int i = 0;
736 int items = 0;
[1]737
738 /** bool **************************************************************/
[128]739 bool delete_partitions_too;
[1]740
741 /** buffers ***********************************************************/
[128]742 char tmp[MAX_STR_LEN];
[1]743
[128]744 assert(mountlist != NULL);
745 assert(raidlist != NULL);
746 assert_string_is_neither_NULL_nor_zerolength(device);
[1]747
[128]748 i = find_raid_device_in_raidlist(raidlist, device);
749 if (i < 0) {
750 return;
751 }
[541]752 sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
[128]753 delete_partitions_too = ask_me_yes_or_no(tmp);
754 if (delete_partitions_too) {
[1]755#ifdef __FreeBSD__
[128]756 // static so it's zeroed
757 static struct list_of_disks d;
758 int x, y, z;
759
760 for (x = 0; x < raidlist->el[i].plexes; ++x) {
761 for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) {
762 for (z = 0; z < raidlist->disks.entries; ++z) {
763 if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device,
764 raidlist->disks.el[z].name)) {
765 strcpy(d.el[d.entries].name,
766 raidlist->disks.el[z].name);
767 strcpy(d.el[d.entries++].device,
768 raidlist->disks.el[z].device);
769 }
770 }
771 }
772 }
773
774 del_partns_listed_in_disklist(mountlist, raidlist, &d);
[1]775#else
[128]776 del_partns_listed_in_disklist(mountlist, raidlist,
777 &raidlist->el[i].data_disks);
778 del_partns_listed_in_disklist(mountlist, raidlist,
779 &raidlist->el[i].spare_disks);
780 del_partns_listed_in_disklist(mountlist, raidlist,
781 &raidlist->el[i].parity_disks);
782 del_partns_listed_in_disklist(mountlist, raidlist,
783 &raidlist->el[i].failed_disks);
[1]784#endif
[128]785 }
786 items = raidlist->entries;
787 if (items == 1) {
788 items = 0;
789 } else {
790 log_it(tmp);
791 memcpy((void *) &raidlist->el[i],
792 (void *) &raidlist->el[items - 1],
793 sizeof(struct OSSWAP (raid_device_record, vinum_volume)));
794 items--;
795 }
796 raidlist->entries = items;
[1]797}
798
799
800#ifndef __FreeBSD__
801/**
802 * Delete entry number @p lino in the additional RAID variables section of @p raidrec.
803 * @param raidrec The RAID device record containing the RAID variable to delete.
804 * @param lino The line number (starting from 0) of the variable to delete.
805 * @ingroup restoreGuiVarslist
806 */
[128]807void delete_varslist_entry(struct raid_device_record *raidrec, int lino)
[1]808{
809
810 /** buffers ************************************************************/
[128]811 char tmp[MAX_STR_LEN];
[1]812
813 /** structures *********************************************************/
[128]814 struct additional_raid_variables *av;
[1]815
[128]816 assert(raidrec != NULL);
[1]817
[128]818 av = &raidrec->additional_vars;
[541]819 sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
[128]820 if (ask_me_yes_or_no(tmp)) {
821 if (!strcmp(av->el[lino].label, "persistent-superblock")
822 || !strcmp(av->el[lino].label, "chunk-size")) {
[541]823 sprintf(tmp, "%s must not be deleted. It would be bad.",
[128]824 av->el[lino].label);
825 popup_and_OK(tmp);
826 } else {
827 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
828 sizeof(struct raid_var_line));
829 }
[1]830 }
831}
832#endif
833
834
835/**
836 * Redraw the filelist display.
837 * @param filelist The filelist structure to edit.
838 * @param keylist The list of keys for @p listbox.
839 * @param listbox The Newt listbox component containing some of the filelist entries.
840 * @return The number of lines currently being displayed.
841 * @ingroup restoreGuiGroup
842 */
843int
[128]844redraw_filelist(struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM],
845 newtComponent listbox)
[1]846{
847
848 /** int ***************************************************************/
[128]849 static int lines_in_flist_window = 0;
850 static int depth = 0;
[1]851
[738]852 /** long **************************************************************/
853 long i = 0;
854
[1]855 /** structures *******************************************************/
[128]856 struct s_node *node;
[1]857
858 /** buffers **********************************************************/
[128]859 static char current_filename[MAX_STR_LEN];
860 char tmp[MAX_STR_LEN + 2];
[1]861
862 /** bool *************************************************************/
863 /* void*dummyptr; */
[128]864 bool dummybool;
865 static bool warned_already;
[1]866
[128]867 assert(filelist != NULL);
868 assert(keylist != NULL);
869 assert(listbox != NULL);
[1]870
871
[128]872 if (depth == 0) {
873 lines_in_flist_window = 0;
874 warned_already = FALSE;
875 for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
876 g_strings_of_flist_window[i][0] = '\0';
877 g_is_path_selected[i] = FALSE;
878 }
[1]879 }
[128]880 for (node = filelist; node != NULL; node = node->right) {
881 current_filename[depth] = node->ch;
882 if (node->down) {
883 depth++;
884 i = redraw_filelist(node->down, keylist, listbox);
885 depth--;
886 }
887 if (node->ch == '\0' && node->expanded) {
888 if (lines_in_flist_window == ARBITRARY_MAXIMUM) {
889 if (!warned_already) {
890 warned_already = TRUE;
891 sprintf(tmp,
[541]892 "Too many lines. Displaying first %d entries only. Close a directory to see more.",
[128]893 ARBITRARY_MAXIMUM);
894 popup_and_OK(tmp);
895 }
896 } else {
897 strcpy(g_strings_of_flist_window[lines_in_flist_window],
898 current_filename);
899 g_is_path_selected[lines_in_flist_window] = node->selected;
900 lines_in_flist_window++;
901 }
902 }
[1]903 }
[128]904 if (depth == 0) {
905 if (lines_in_flist_window > ARBITRARY_MAXIMUM) {
906 lines_in_flist_window = ARBITRARY_MAXIMUM;
[1]907 }
908/* do an elementary sort */
[128]909 for (i = 1; i < lines_in_flist_window; i++) {
910 if (strcmp
911 (g_strings_of_flist_window[i],
912 g_strings_of_flist_window[i - 1]) < 0) {
913 strcpy(tmp, g_strings_of_flist_window[i]);
914 strcpy(g_strings_of_flist_window[i],
915 g_strings_of_flist_window[i - 1]);
916 strcpy(g_strings_of_flist_window[i - 1], tmp);
917 dummybool = g_is_path_selected[i];
918 g_is_path_selected[i] = g_is_path_selected[i - 1];
919 g_is_path_selected[i - 1] = dummybool;
920 i = 0;
921 }
922 }
[1]923/* write list to screen */
[128]924 newtListboxClear(listbox);
925 for (i = 0; i < lines_in_flist_window; i++) {
926 sprintf(tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
927 (g_is_path_expanded[i] ? '+' : '-'),
928 strip_path(g_strings_of_flist_window[i]));
929 tmp[70] = '\0';
930 keylist[i] = (void *) i;
931 newtListboxAppendEntry(listbox, tmp, keylist[i]);
932 }
933 return (lines_in_flist_window);
934 } else {
935 return (0);
[1]936 }
937}
938
939
940/**
941 * Strip a path to the bare minimum (^ pointing to the directory above, plus filename).
942 * @param tmp The path to strip.
943 * @return The stripped path.
944 * @author Conor Daly
945 * @ingroup restoreUtilityGroup
946 */
[128]947char *strip_path(char *tmp)
[1]948{
949
950 int i = 0, j = 0, slashcount = 0;
951 int slashloc = 0, lastslashloc = 0;
952
[128]953 while (tmp[i] != '\0') { /* Count the slashes in tmp
954 1 slash per dir */
955 if (tmp[i] == '/') {
956 slashcount++;
957 lastslashloc = slashloc;
958 slashloc = i;
959 if (tmp[i + 1] == '\0') { /* if this slash is last char, back off */
960 slashcount--;
961 slashloc = lastslashloc;
962 }
963 }
964 i++;
[1]965 }
[128]966 if (slashcount > 0)
967 slashcount--; /* Keep one slash 'cos Hugh does... */
[1]968
[128]969 for (i = 0; i < slashcount; i++) { /* Replace each dir with a space char */
970 tmpnopath[i] = ' ';
[1]971 }
972
973 i = slashloc;
974 j = slashcount;
[128]975 while (tmp[i] != '\0') { /* Now add what's left of tmp */
976 if ((tmpprevpath[j] == ' ' || tmpprevpath[j] == '^')
977 && tmp[i] == '/' && tmpnopath[j - 1] != '^' && j != 0) { /* Add a pointer upwards if this is not in the same dir as line above */
978 tmpnopath[j - 1] = '^';
979 } else {
980 tmpnopath[j++] = tmp[i++];
981 }
[1]982 }
983 tmpnopath[j] = '\0';
984
[128]985 strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */
986
987 return (tmpnopath);
[1]988}
989
990
991/**
992 * Allow the user to edit the filelist and choose which files to restore.
993 * @param filelist The node structure containing the filelist.
994 * @return 0 if the user pressed OK, 1 if they pressed Cancel.
995 */
[128]996int edit_filelist(struct s_node *filelist)
[1]997{
998
999 /** newt **************************************************************/
[128]1000 newtComponent myForm;
1001 newtComponent bLess = NULL;
1002 newtComponent bMore = NULL;
1003 newtComponent bToggle = NULL;
1004 newtComponent bOK = NULL;
1005 newtComponent bCancel = NULL;
1006 newtComponent b_res = NULL;
1007 newtComponent filelistListbox = NULL;
1008 newtComponent bRegex = NULL;
[1]1009
1010 /** int ***************************************************************/
1011 int finished = FALSE;
1012 int lines_in_flist_window = 0;
1013 int indexno = 0;
1014 int j = 0;
1015
1016 /** ???? **************************************************************/
[128]1017 void *curr_choice;
1018 void *keylist[ARBITRARY_MAXIMUM];
[1]1019
1020 /** buffers ***********************************************************/
[128]1021 char tmp[MAX_STR_LEN];
[1]1022
1023 /** bool **************************************************************/
[128]1024 bool dummybool;
[1]1025
1026/* struct s_node *node; */
1027
[128]1028 assert(filelist != NULL);
[1]1029
[541]1030 log_to_screen("Editing filelist");
[128]1031 newtPushHelpLine
[541]1032 (" Please edit the filelist to your satisfaction, then click OK or Cancel.");
[128]1033 j = 4;
[541]1034 bLess = newtCompactButton(j, 17, " Less ");
1035 bMore = newtCompactButton(j += 12, 17, " More ");
1036 bToggle = newtCompactButton(j += 12, 17, "Toggle");
1037 bRegex = newtCompactButton(j += 12, 17, "RegEx");
1038 bCancel = newtCompactButton(j += 12, 17, "Cancel");
1039 bOK = newtCompactButton(j += 12, 17, " OK ");
[128]1040 filelistListbox =
1041 newtListbox(2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1042 toggle_all_root_dirs_on(filelist);
1043 lines_in_flist_window =
1044 redraw_filelist(filelist, keylist, filelistListbox);
[541]1045 newtOpenWindow(1, 3, 77, 18, "Editing filelist");
[128]1046 myForm = newtForm(NULL, NULL, 0);
1047 newtFormAddComponents(myForm, filelistListbox, bLess, bMore, bToggle,
1048 bRegex, bCancel, bOK, NULL);
1049 while (!finished) {
1050 b_res = newtRunForm(myForm);
1051 if (b_res == bOK) {
1052 finished =
1053 ask_me_yes_or_no
[541]1054 ("Are you happy with your file selection?");
[128]1055 } else if (b_res == bCancel) {
1056 finished = TRUE;
1057 } else if (b_res == bRegex) {
[541]1058 popup_and_OK("I haven't implemented this yet...");
[128]1059 } else {
1060 curr_choice = newtListboxGetCurrent(filelistListbox);
1061 for (indexno = 0;
1062 indexno < lines_in_flist_window
1063 && keylist[indexno] != curr_choice; indexno++);
1064 if (indexno == lines_in_flist_window) {
1065 log_it
1066 ("I don't know what this button does; assuming I am to toggle 1st entry");
1067 indexno = 0;
1068 }
1069 sprintf(tmp, "You selected '%s'",
1070 g_strings_of_flist_window[indexno]);
1071 log_it(tmp);
1072 if (b_res == bMore) {
1073 g_is_path_expanded[indexno] = TRUE;
1074 toggle_path_expandability(filelist,
1075 g_strings_of_flist_window
1076 [indexno], TRUE);
1077 lines_in_flist_window =
1078 redraw_filelist(filelist, keylist, filelistListbox);
1079 newtListboxSetCurrentByKey(filelistListbox, curr_choice);
1080 } else if (b_res == bLess) {
1081 g_is_path_expanded[indexno] = FALSE;
1082 toggle_path_expandability(filelist,
1083 g_strings_of_flist_window
1084 [indexno], FALSE);
1085 lines_in_flist_window =
1086 redraw_filelist(filelist, keylist, filelistListbox);
1087 newtListboxSetCurrentByKey(filelistListbox, curr_choice);
1088 } else {
1089 if (!strcmp(g_strings_of_flist_window[indexno], "/")) {
1090 dummybool = !g_is_path_selected[indexno];
1091 for (j = 1; j < lines_in_flist_window; j++) {
1092 toggle_path_selection(filelist,
1093 g_strings_of_flist_window[j],
1094 dummybool);
1095 }
1096 } else {
1097 toggle_path_selection(filelist,
1098 g_strings_of_flist_window
1099 [indexno],
1100 !g_is_path_selected[indexno]);
1101 lines_in_flist_window =
1102 redraw_filelist(filelist, keylist,
1103 filelistListbox);
1104 }
1105 newtListboxSetCurrentByKey(filelistListbox, curr_choice);
1106 }
1107 for (indexno = 0;
1108 indexno < lines_in_flist_window
1109 && keylist[indexno] != curr_choice; indexno++);
1110 if (indexno == lines_in_flist_window) {
1111 log_it
1112 ("Layout of table has changed. Y pointer is reverting to zero.");
1113 indexno = 0;
1114 }
[1]1115 }
1116 }
[128]1117 newtFormDestroy(myForm);
1118 newtPopWindow();
1119 newtPopHelpLine();
1120 if (b_res == bOK) {
1121 return (0);
1122 } else {
[1]1123/* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
[128]1124 return (1);
1125 }
[1]1126}
1127
1128
1129/**
1130 * Edit an entry in @p mountlist.
1131 * @param mountlist The mountlist containing information about the user's partitions.
1132 * @param raidlist The raidlist to accompany @p mountlist.
1133 * @param listbox The Newt listbox component in the mountlist editor.
1134 * @param currline The selected line (starting from 0) in @p listbox.
1135 * @param keylist The list of keys for @p listbox.
1136 * @ingroup restoreGuiMountlist
1137 */
1138void
[128]1139edit_mountlist_entry(struct mountlist_itself *mountlist,
1140 struct raidlist_itself *raidlist,
1141 newtComponent listbox, int currline, void *keylist[])
[1]1142{
1143
1144 /** structures ********************************************************/
[128]1145 static struct raidlist_itself bkp_raidlist;
[1]1146
1147 /** newt **************************************************************/
[128]1148 newtComponent myForm;
[1]1149 newtComponent bOK;
1150 newtComponent bCancel;
1151 newtComponent b_res;
1152 newtComponent mountpointComp;
1153 newtComponent label0;
1154 newtComponent label1;
1155 newtComponent label2;
1156 newtComponent label3;
1157 newtComponent sizeComp;
1158 newtComponent deviceComp;
1159 newtComponent formatComp;
1160 newtComponent b_raid = NULL;
1161
1162 /** buffers ***********************************************************/
1163 char device_str[MAX_STR_LEN];
1164 char mountpoint_str[MAX_STR_LEN];
1165 char size_str[MAX_STR_LEN];
1166 char format_str[MAX_STR_LEN];
[128]1167 char tmp[MAX_STR_LEN];
1168 char device_used_to_be[MAX_STR_LEN];
[1]1169 char mountpt_used_to_be[MAX_STR_LEN];
1170
1171 /** pointers **********************************************************/
1172 char *device_here;
1173 char *mountpoint_here;
1174 char *size_here;
1175 char *format_here;
1176
1177 /** int ***************************************************************/
[128]1178 int j = 0;
[1]1179
[128]1180 assert(mountlist != NULL);
1181 assert(raidlist != NULL);
1182 assert(listbox != NULL);
1183 assert(keylist != NULL);
[1]1184
[128]1185 memcpy((void *) &bkp_raidlist, (void *) raidlist,
1186 sizeof(struct raidlist_itself));
1187 strcpy(device_str, mountlist->el[currline].device);
1188 strcpy(device_used_to_be, mountlist->el[currline].device);
1189 strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
1190 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
1191 strcpy(format_str, mountlist->el[currline].format);
[2125]1192 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);
[128]1193 newtOpenWindow(20, 5, 48, 10, "Edit entry");
[541]1194 label0 = newtLabel(2, 1, "Device:");
1195 label1 = newtLabel(2, 2, "Mountpoint:");
1196 label2 = newtLabel(2, 3, "Size (MB): ");
1197 label3 = newtLabel(2, 4, "Format: ");
[128]1198 deviceComp =
1199 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
1200 mountpointComp =
1201 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
1202 formatComp =
1203 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
1204 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
1205 || !strcmp(mountlist->el[currline].mountpoint, "image")) {
1206 sizeComp = newtLabel(14, 3, size_str);
1207 } else {
1208 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
[1]1209 }
[541]1210 bOK = newtButton(2, 6, " OK ");
1211 bCancel = newtButton(14, 6, "Cancel");
[128]1212 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
1213 b_raid = newtButton(26, 6, "RAID..");
[1]1214 }
[128]1215 newtPushHelpLine
[541]1216 (" Edit this partition's mountpoint, size and format; then click 'OK'.");
[128]1217 myForm = newtForm(NULL, NULL, 0);
1218 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
1219 formatComp, label0, label1, label2, label3, bOK,
1220 bCancel, b_raid, NULL);
1221 for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
1222 b_res = newtRunForm(myForm);
1223 strcpy(device_str, device_here);
1224 strip_spaces(device_str);
1225 strcpy(mountpoint_str, mountpoint_here);
1226 strip_spaces(mountpoint_str);
1227 strcpy(format_str, format_here);
1228 strip_spaces(format_str);
1229 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
1230 && strstr(device_used_to_be, RAID_DEVICE_STUB)
1231 && strcmp(device_str, device_used_to_be)) {
[541]1232 popup_and_OK("You can't change /dev/mdX to /dev/mdY.");
[128]1233 b_res = NULL;
1234 continue;
1235 } else if (b_res == bOK && !strcmp(mountpoint_str, "image")
1236 && strcmp(mountpt_used_to_be, "image")) {
[541]1237 popup_and_OK("You can't change a regular device to an image.");
[128]1238 b_res = NULL;
1239 continue;
[1]1240 }
[128]1241 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
1242 && strcmp(mountlist->el[currline].mountpoint, "image")) {
1243 strcpy(size_str, size_here);
1244 strip_spaces(size_str);
1245 } else {
1246 sprintf(size_str, "%ld",
1247 calculate_raid_device_size(mountlist, raidlist,
1248 mountlist->el[currline].
1249 device) / 1024);
1250 newtLabelSetText(sizeComp, size_str);
[1]1251 }
[128]1252 /* do not let user click RAID button if user has changed device_str */
1253 if (b_res == b_raid) {
1254 if (strcmp(device_str, mountlist->el[currline].device)) {
1255 /*
1256 can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly
1257 when you try to map the changes over to the raidtab list, trust me
1258 */
1259 popup_and_OK
[541]1260 ("You cannot edit the RAID settings until you have OK'd your change to the device node.");
[128]1261 } else {
1262 j = find_raid_device_in_raidlist(raidlist,
1263 mountlist->el[currline].
1264 device);
1265 if (j < 0) {
1266 sprintf(tmp,
[541]1267 "/etc/raidtab does not have an entry for %s; please delete it and add it again",
[128]1268 mountlist->el[currline].device);
1269 popup_and_OK(tmp);
1270 } else {
[541]1271 log_it("edit_raidlist_entry - calling");
[128]1272 edit_raidlist_entry(mountlist, raidlist,
1273 &raidlist->el[j], currline);
1274 }
1275 }
1276 }
[1]1277 }
[128]1278 newtFormDestroy(myForm);
1279 newtPopHelpLine();
1280 newtPopWindow();
1281 if (b_res == bCancel) {
1282 memcpy((void *) raidlist, (void *) &bkp_raidlist,
1283 sizeof(struct raidlist_itself));
1284 return;
1285 }
1286 strcpy(mountlist->el[currline].device, device_str);
1287 strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
1288 strcpy(mountlist->el[currline].format, format_str);
[705]1289 if (strcmp(mountlist->el[currline].mountpoint, "image")) {
1290 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
1291 mountlist->el[currline].size =
1292 calculate_raid_device_size(mountlist, raidlist,
[128]1293 mountlist->el[currline].device);
[705]1294 } else {
[2125]1295 mountlist->el[currline].size = atol(size_str) * 1024L;
[705]1296 }
[128]1297 }
[738]1298 newtListboxSetEntry(listbox, (long) keylist[currline],
[128]1299 mountlist_entry_to_string(mountlist, currline));
1300 /* if new /dev/md RAID device then do funky stuff */
1301 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
1302 && !strstr(device_used_to_be, RAID_DEVICE_STUB)) {
1303 initiate_new_raidlist_entry(raidlist, mountlist, currline,
1304 device_str);
1305 }
1306 /* if moving from RAID to non-RAID then do funky stuff */
1307 else if (strstr(device_used_to_be, RAID_DEVICE_STUB)
1308 && !strstr(device_str, RAID_DEVICE_STUB)) {
1309 delete_raidlist_entry(mountlist, raidlist, device_str);
1310 }
1311 /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */
1312 else if (!strstr(device_used_to_be, RAID_DEVICE_STUB)
1313 && !strstr(device_str, RAID_DEVICE_STUB)) {
1314 rejig_partition_name_in_raidlist_if_necessary(raidlist,
1315 device_used_to_be,
1316 device_str);
1317 }
[1]1318/* else, moving a RAID to another RAID; bad idea, or so I thought */
[128]1319#ifndef __FreeBSD__ /* It works fine under FBSD. */
1320 else if (strcmp(device_used_to_be, device_str)) {
1321 popup_and_OK
[541]1322 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
[128]1323 }
[1]1324#endif
[128]1325 redraw_mountlist(mountlist, keylist, listbox);
[1]1326}
1327
1328
1329#if __FreeBSD__
1330/**
1331 * Add a subdisk to @p raidrec.
1332 * @param raidlist The raidlist containing information about RAID partitions.
1333 * @param raidrec The RAID device record to add the subdisk to.
1334 * @param temp The device name of the RAID disk to add it to.
1335 * @author Joshua Oreman
1336 * @ingroup restoreGuiMountlist
1337 */
1338void
[128]1339add_raid_subdisk(struct raidlist_itself *raidlist,
1340 struct vinum_plex *raidrec, char *temp)
[1]1341{
[128]1342 int i;
1343 bool found = FALSE;
1344
1345 for (i = 0; i < raidlist->disks.entries; ++i) {
1346 if (!strcmp(raidlist->disks.el[i].device, temp)) {
1347 strcpy(raidrec->sd[raidrec->subdisks].which_device,
1348 raidlist->disks.el[i].name);
1349 found = TRUE;
1350 }
[1]1351 }
[128]1352 if (!found) {
1353 sprintf(raidlist->disks.el[raidlist->disks.entries].name,
1354 "drive%i", raidlist->disks.entries);
1355 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i",
1356 raidlist->disks.entries);
1357 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp);
1358 }
1359 raidrec->subdisks++;
[1]1360}
1361
1362
1363/**
1364 * Determine the /dev entry for @p vinum_name.
1365 * @param raidlist The raidlist containing information about RAID devices.
1366 * @param vinum_name The name of the Vinum drive to map to a /dev entry.
1367 * @return The /dev entry, or NULL if none was found.
1368 * @note The returned string points to static storage that will be overwritten with each call.
1369 * @author Joshua Oreman
1370 * @ingroup restoreUtilityGroup
1371 */
[128]1372char *find_dev_entry_for_raid_device_name(struct raidlist_itself *raidlist,
1373 char *vinum_name)
[1]1374{
[128]1375 int i;
1376 for (i = 0; i < raidlist->disks.entries; ++i) {
1377 if (!strcmp(raidlist->disks.el[i].name, vinum_name)) {
1378 return raidlist->disks.el[i].device;
1379 }
[1]1380 }
[128]1381 return NULL;
[1]1382}
1383
1384void
[128]1385edit_raidlist_plex(struct mountlist_itself *mountlist,
1386 struct raidlist_itself *raidlist,
1387 struct vinum_plex *raidrec, int currline,
1388 int currline2);
[1]1389
1390#endif
1391
1392
1393/**
1394 * Edit the entry for @p raidrec in @p raidlist.
1395 * @param mountlist The mountlist to get some information from.
1396 * @param raidlist The raidlist containing information about RAID devices.
1397 * @param raidrec The RAID device record for this partition.
1398 * @param currline The line number (starting from 0) in the mountlist of the RAID device.
1399 * @ingroup restoreGuiMountlist
1400 */
1401void
[128]1402edit_raidlist_entry(struct mountlist_itself *mountlist,
1403 struct raidlist_itself *raidlist,
1404 struct OSSWAP (raid_device_record,
1405 vinum_volume) * raidrec, int currline)
[1]1406{
1407
1408#ifdef __FreeBSD__
1409 /** structures ********************************************************/
[128]1410 struct vinum_volume bkp_raidrec;
[1]1411
1412
1413 /** buffers ***********************************************************/
[128]1414 char title_of_editraidForm_window[MAX_STR_LEN];
[1]1415
1416 /** newt **************************************************************/
[128]1417 newtComponent editraidForm;
1418 newtComponent bOK;
1419 newtComponent bCancel;
1420 newtComponent bEdit;
1421 newtComponent bAdd;
1422 newtComponent bDelete;
1423 newtComponent b_res;
1424 newtComponent plexesListbox;
1425 newtComponent plexesHeader;
[1]1426
[128]1427 void *keylist[10];
1428 void *curr_choice;
[1]1429
[128]1430 int currline2 = 0;
[1]1431
[541]1432 log_it("Started edit_raidlist_entry");
[128]1433 memcpy((void *) &bkp_raidrec, (void *) raidrec,
1434 sizeof(struct vinum_volume));
[541]1435 sprintf(title_of_editraidForm_window, "Plexes on %s",
[128]1436 raidrec->volname);
[541]1437 newtPushHelpLine(" Please select a plex to edit");
[128]1438 newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window);
1439 for (;;) {
1440 int i;
1441 char headerstr[MAX_STR_LEN];
1442 snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s",
[541]1443 "Plex", "Level", "Stripe Size", "Subdisks");
[1]1444
[541]1445 bOK = newtCompactButton(2, 13, " OK ");
1446 bCancel = newtCompactButton(12, 13, "Cancel");
1447 bAdd = newtCompactButton(22, 13, " Add ");
1448 bEdit = newtCompactButton(32, 13, " Edit ");
1449 bDelete = newtCompactButton(42, 13, "Delete");
[1]1450
[128]1451 plexesListbox =
1452 newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1453 plexesHeader = newtLabel(2, 2, headerstr);
1454 editraidForm = newtForm(NULL, NULL, 0);
[1]1455
[128]1456 newtListboxClear(plexesListbox);
1457 for (i = 0; i < 10; ++i) {
1458 keylist[i] = (void *) i;
1459 if (i < raidrec->plexes) {
1460 char pname[64], entry[MAX_STR_LEN], raidlevel[64],
1461 chunksize[64];
1462 switch (raidrec->plex[i].raidlevel) {
1463 case -1:
1464 strcpy(raidlevel, "concat");
1465 break;
1466 case 0:
1467 strcpy(raidlevel, "striped");
1468 break;
1469 case 5:
1470 strcpy(raidlevel, "raid5");
1471 break;
1472 default:
1473 sprintf(raidlevel, "raid%i",
1474 raidrec->plex[i].raidlevel);
1475 break;
1476 }
1477
1478 if (raidrec->plex[i].raidlevel == -1) {
1479 strcpy(chunksize, "N/A");
1480 } else {
1481 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
1482 }
1483 snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
1484 snprintf(entry, MAX_STR_LEN, "%-14s %-8s %11s %8d",
1485 pname, raidlevel, chunksize,
1486 raidrec->plex[i].subdisks);
1487 newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
1488 }
[1]1489 }
1490
[128]1491 newtFormAddComponents(editraidForm, bOK, bCancel, bAdd, bEdit,
1492 bDelete, plexesListbox, plexesHeader, NULL);
1493
1494 b_res = newtRunForm(editraidForm);
1495 if (b_res == bOK || b_res == bCancel) {
1496 break;
[1]1497 }
1498
[128]1499 curr_choice = newtListboxGetCurrent(plexesListbox);
1500 for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) {
1501 if (currline2 > 9)
1502 break;
1503 if (keylist[currline2] == curr_choice)
1504 break;
1505 }
[1]1506
[128]1507 if (b_res == bDelete) {
1508 char msg[MAX_STR_LEN];
[541]1509 sprintf(msg, "Are you sure you want to delete %s.p%i?",
[128]1510 raidrec->volname, currline2);
1511 if (ask_me_yes_or_no(msg)) {
[541]1512 log_it("Deleting RAID plex");
[128]1513 memcpy((void *) &raidrec->plex[currline2],
1514 (void *) &raidrec->plex[raidrec->plexes - 1],
1515 sizeof(struct vinum_plex));
1516 raidrec->plexes--;
1517 }
1518 continue;
1519 }
1520 if (b_res == bAdd) {
1521 raidrec->plex[raidrec->plexes].raidlevel = 0;
1522 raidrec->plex[raidrec->plexes].stripesize = 279;
1523 raidrec->plex[raidrec->plexes].subdisks = 0;
1524 currline2 = raidrec->plexes++;
1525 }
1526 edit_raidlist_plex(mountlist, raidlist, &raidrec->plex[currline2],
1527 currline, currline2);
1528 newtFormDestroy(editraidForm);
[1]1529 }
[128]1530 if (b_res == bCancel) {
1531 memcpy((void *) raidrec, (void *) &bkp_raidrec,
1532 sizeof(struct vinum_volume));
1533 }
1534 newtPopHelpLine();
1535 newtPopWindow();
1536 mountlist->el[currline].size =
1537 calculate_raid_device_size(mountlist, raidlist, raidrec->volname);
[1]1538#else
1539 /** structures ********************************************************/
[128]1540 struct raid_device_record *bkp_raidrec;
[1]1541
1542
1543 /** buffers ***********************************************************/
[128]1544 char *title_of_editraidForm_window;
[1]1545 char *sz_raid_level;
1546 char *sz_data_disks;
1547 char *sz_spare_disks;
1548 char *sz_parity_disks;
1549 char *sz_failed_disks;
1550
1551 /** newt **************************************************************/
[128]1552 newtComponent editraidForm;
[1]1553 newtComponent bOK;
1554 newtComponent bCancel;
1555 newtComponent bAdditional;
1556 newtComponent bChangeRaid;
1557 newtComponent bSelectData;
1558 newtComponent bSelectSpare;
1559 newtComponent bSelectParity;
1560 newtComponent bSelectFailed;
1561 newtComponent b_res;
1562
[128]1563 assert(mountlist != NULL);
1564 assert(raidlist != NULL);
1565 assert(raidrec != NULL);
[1]1566
[128]1567 malloc_string(title_of_editraidForm_window);
1568 malloc_string(sz_raid_level);
1569 malloc_string(sz_data_disks);
1570 malloc_string(sz_spare_disks);
1571 malloc_string(sz_parity_disks);
1572 malloc_string(sz_failed_disks);
1573 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
1574 fatal_error("Cannot malloc space for raidrec");
1575 }
[1]1576
[128]1577 log_it("Started edit_raidlist_entry");
[1]1578
[128]1579 memcpy((void *) bkp_raidrec, (void *) raidrec,
1580 sizeof(struct raid_device_record));
1581 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
1582 log_msg(2, "Opening newt window");
1583 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
1584 for (;;) {
1585 log_msg(2, "Main loop");
[541]1586 sprintf(title_of_editraidForm_window, "Edit %s",
[128]1587 raidrec->raid_device);
1588 strcpy(sz_raid_level,
1589 turn_raid_level_number_to_string(raidrec->raid_level));
1590 strcpy(sz_data_disks,
1591 number_of_disks_as_string(raidrec->data_disks.entries,
[541]1592 "data"));
[128]1593 strcpy(sz_spare_disks,
1594 number_of_disks_as_string(raidrec->spare_disks.entries,
[541]1595 "spare"));
[128]1596 strcpy(sz_parity_disks,
1597 number_of_disks_as_string(raidrec->parity_disks.entries,
[541]1598 "parity"));
[128]1599 strcpy(sz_failed_disks,
1600 number_of_disks_as_string(raidrec->failed_disks.entries,
[541]1601 "failed"));
[128]1602 bSelectData = newtButton(1, 1, sz_data_disks);
1603 bSelectSpare = newtButton(20, 1, sz_spare_disks);
1604 bSelectParity = newtButton(1, 5, sz_parity_disks);
1605 bSelectFailed = newtButton(20, 5, sz_failed_disks);
1606 bChangeRaid = newtButton(1, 9, sz_raid_level);
[541]1607 bOK = newtButton(16 + (raidrec->raid_level == -1), 9, " OK ");
1608 bCancel = newtButton(28, 9, "Cancel");
[128]1609 bAdditional =
1610 newtCompactButton(1, 13,
[541]1611 "Additional settings and information");
[128]1612 newtPushHelpLine
[541]1613 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel.");
[128]1614 editraidForm = newtForm(NULL, NULL, 0);
1615 newtFormAddComponents(editraidForm, bSelectData, bSelectParity,
1616 bChangeRaid, bSelectSpare, bSelectFailed,
1617 bOK, bCancel, bAdditional);
1618 b_res = newtRunForm(editraidForm);
1619 if (b_res == bChangeRaid) {
1620 choose_raid_level(raidrec);
1621 } else if (b_res == bSelectData) {
[541]1622 select_raid_disks(mountlist, raidlist, raidrec, "data",
[128]1623 &raidrec->data_disks);
1624 } else if (b_res == bSelectSpare) {
[541]1625 select_raid_disks(mountlist, raidlist, raidrec, "spare",
[128]1626 &raidrec->spare_disks);
1627 } else if (b_res == bSelectParity) {
[541]1628 select_raid_disks(mountlist, raidlist, raidrec, "parity",
[128]1629 &raidrec->parity_disks);
1630 } else if (b_res == bSelectFailed) {
[541]1631 select_raid_disks(mountlist, raidlist, raidrec, "failed",
[128]1632 &raidrec->failed_disks);
1633 } else if (b_res == bAdditional) {
1634 edit_raidrec_additional_vars(raidrec);
1635 }
1636 newtFormDestroy(editraidForm);
1637 if (b_res == bOK || b_res == bCancel) {
1638 break;
1639 }
[1]1640 }
[128]1641 if (b_res == bCancel) {
1642 memcpy((void *) raidrec, (void *) bkp_raidrec,
1643 sizeof(struct raid_device_record));
[1]1644 }
[128]1645 newtPopHelpLine();
1646 newtPopWindow();
1647 mountlist->el[currline].size =
1648 calculate_raid_device_size(mountlist, raidlist,
1649 raidrec->raid_device);
1650 paranoid_free(title_of_editraidForm_window);
1651 paranoid_free(sz_raid_level);
1652 paranoid_free(sz_data_disks);
1653 paranoid_free(sz_spare_disks);
1654 paranoid_free(sz_parity_disks);
1655 paranoid_free(sz_failed_disks);
1656 paranoid_free(bkp_raidrec);
[1]1657#endif
1658}
1659
1660#ifdef __FreeBSD__
1661
1662/**
1663 * Edit the plex @p raidrec in @p raidlist.
1664 * @param mountlist The mountlist to get some of the information from.
1665 * @param raidlist The raidlist containing information about RAID devices.
1666 * @param raidrec The plex to edit.
1667 * @param currline The line number (starting from 0) of the RAID device in @p mountlist.
1668 * @param currline2 The line number (starting from 0) of the plex within the RAID device.
1669 * @author Joshua Oreman
1670 * @ingroup restoreGuiMountlist
1671 */
1672void
[128]1673edit_raidlist_plex(struct mountlist_itself *mountlist,
1674 struct raidlist_itself *raidlist,
1675 struct vinum_plex *raidrec, int currline, int currline2)
[1]1676{
1677
1678 /** structures ********************************************************/
[128]1679 struct vinum_plex bkp_raidrec;
[1]1680
1681
1682 /** buffers ***********************************************************/
[128]1683 char title_of_editraidForm_window[MAX_STR_LEN];
[1]1684
1685 /** newt **************************************************************/
[128]1686 newtComponent editraidForm;
1687 newtComponent bOK;
1688 newtComponent bCancel;
1689 newtComponent bEdit;
1690 newtComponent bAdd;
1691 newtComponent bDelete;
1692 newtComponent b_res;
1693 newtComponent unallocListbox, allocListbox;
1694 newtComponent bLevel, sLevel;
1695 newtComponent bStripeSize, sStripeSize;
1696 newtComponent bAlloc, bUnalloc;
[1]1697
[128]1698 void *keylist[ARBITRARY_MAXIMUM];
1699 void *curr_choice_a, *curr_choice_u;
1700 int currline_a, currline_u;
[1]1701
[128]1702 struct mountlist_itself *unallocparts;
[1]1703
[128]1704 unallocparts = malloc(sizeof(struct mountlist_itself));
[1]1705
[128]1706 log_it("Started edit_raidlist_entry");
1707 memcpy((void *) &bkp_raidrec, (void *) raidrec,
1708 sizeof(struct vinum_plex));
1709 sprintf(title_of_editraidForm_window, "%s.p%i",
1710 raidlist->el[currline].volname, currline2);
1711 newtPushHelpLine
[541]1712 (" Please select a subdisk to edit, or edit this plex's parameters");
[128]1713 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
1714 for (;;) {
1715 int i;
1716 char headerstr[MAX_STR_LEN];
1717 char tmp[64];
[541]1718 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");
[1]1719
[128]1720
1721 switch (raidrec->raidlevel) {
1722 case -1:
1723 strcpy(tmp, "concat");
1724 break;
1725 case 0:
1726 strcpy(tmp, "striped");
1727 break;
1728 case 5:
1729 strcpy(tmp, "raid5");
1730 break;
1731 default:
[541]1732 sprintf(tmp, "unknown (%i)", raidrec->raidlevel);
[128]1733 break;
1734 }
[541]1735 bLevel = newtCompactButton(2, 2, " RAID level ");
[128]1736 sLevel = newtLabel(19, 2, tmp);
1737
1738 if (raidrec->raidlevel >= 0) {
1739 sprintf(tmp, "%ik", raidrec->stripesize);
[541]1740 bStripeSize = newtCompactButton(2, 4, " Stripe size ");
[128]1741 } else {
1742 strcpy(tmp, "N/A");
[541]1743 bStripeSize = newtLabel(2, 4, "Stripe size:");
[128]1744 }
1745 sStripeSize = newtLabel(19, 4, tmp);
1746
[541]1747 bOK = newtCompactButton(2, 16, " OK ");
1748 bCancel = newtCompactButton(12, 16, "Cancel");
1749 bAdd = newtCompactButton(22, 16, " Add ");
1750 bEdit = newtCompactButton(32, 16, " Edit ");
1751 bDelete = newtCompactButton(42, 16, "Delete");
[128]1752
1753
1754 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1755 // plexesHeader = newtLabel (2, 6, headerstr);
1756 unallocListbox =
1757 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1758 allocListbox =
1759 newtListbox(33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1760 bAlloc = newtButton(23, 7, " -> ");
1761 bUnalloc = newtButton(23, 11, " <- ");
1762
1763 editraidForm = newtForm(NULL, NULL, 0);
1764
1765 newtListboxClear(allocListbox);
1766 newtListboxClear(unallocListbox);
1767 bzero(unallocparts, sizeof(struct mountlist_itself));
1768 make_list_of_unallocated_raid_partitions(unallocparts, mountlist,
1769 raidlist);
1770 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
1771 char entry[MAX_STR_LEN];
1772 keylist[i] = (void *) i;
1773 if (i < raidrec->subdisks) {
1774 snprintf(entry, MAX_STR_LEN, "%-17s",
1775 find_dev_entry_for_raid_device_name(raidlist,
1776 raidrec->
1777 sd[i].
1778 which_device));
1779 newtListboxAppendEntry(allocListbox, entry, keylist[i]);
1780 }
1781 if (i < unallocparts->entries) {
1782 snprintf(entry, MAX_STR_LEN, "%-17s",
1783 unallocparts->el[i].device);
1784 newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
1785 }
1786 }
1787
[1]1788#define COMP(x) newtFormAddComponent (editraidForm, x)
1789#define UCOMP(x) if (unallocparts->entries > 0) COMP(x)
1790#define ACOMP(x) if (raidrec->subdisks > 0) COMP(x)
[128]1791 editraidForm = newtForm(NULL, NULL, 0);
1792 UCOMP(unallocListbox);
1793 UCOMP(bAlloc);
1794 ACOMP(allocListbox);
1795 ACOMP(bUnalloc);
1796 COMP(bOK);
1797 COMP(bCancel);
1798 COMP(bLevel);
1799 COMP(sLevel);
1800 if (raidrec->raidlevel != -1) {
1801 COMP(bStripeSize);
1802 COMP(sStripeSize);
1803 }
[1]1804#undef COMP
1805#undef UCOMP
1806#undef ACOMP
1807
[128]1808 newtRefresh();
1809 b_res = newtRunForm(editraidForm);
1810 if (b_res == bOK || b_res == bCancel) {
1811 break;
1812 }
1813
1814 curr_choice_a = (raidrec->subdisks > 0) ?
1815 newtListboxGetCurrent(allocListbox) : (void *) 1234;
1816 curr_choice_u = (unallocparts->entries > 0) ?
1817 newtListboxGetCurrent(unallocListbox) : (void *) 1234;
1818 for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) {
1819 if (currline_a > ARBITRARY_MAXIMUM)
1820 break;
1821 if (keylist[currline_a] == curr_choice_a)
1822 break;
1823 }
1824 for (currline_u = 0; currline_u < unallocparts->entries;
1825 ++currline_u) {
1826 if (currline_u > ARBITRARY_MAXIMUM)
1827 break;
1828 if (keylist[currline_u] == curr_choice_u)
1829 break;
1830 }
1831 if (b_res == bLevel) {
1832 choose_raid_level(raidrec);
1833 } else if (b_res == bStripeSize) {
1834 char tmp[64];
1835 sprintf(tmp, "%i", raidrec->stripesize);
1836 if (popup_and_get_string
[541]1837 ("Stripe size",
1838 "Please enter the stripe size in kilobytes.", tmp, 20)) {
[128]1839 raidrec->stripesize = atoi(tmp);
1840 }
1841 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
1842 if (currline_u <= unallocparts->entries)
1843 add_raid_subdisk(raidlist, raidrec,
1844 unallocparts->el[currline_u].device);
1845 } else if ((b_res == bUnalloc) || (b_res == allocListbox)) {
1846 if (currline_a <= raidrec->subdisks) {
1847 memcpy((void *) &raidrec->sd[currline_a],
1848 (void *) &raidrec->sd[raidrec->subdisks - 1],
1849 sizeof(struct vinum_subdisk));
1850 raidrec->subdisks--;
1851 }
1852 }
1853#if 0
1854 } else {
1855 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],
1856 currline3);
[1]1857 }
1858#endif
[128]1859 newtFormDestroy(editraidForm);
1860 newtRefresh();
[1]1861}
[128]1862
1863if (b_res == bCancel) {
1864 memcpy((void *) raidrec, (void *) &bkp_raidrec,
1865 sizeof(struct vinum_plex));
1866}
1867newtPopWindow();
1868newtPopHelpLine();
1869}
[1]1870#else
1871/**
1872 * Edit additional RAID variable number @p lino.
1873 * @param raidrec The RAID device record to edit the variable in.
1874 * @param lino The line number (starting from 0) of the variable to edit.
1875 * @ingroup restoreGuiVarslist
1876 */
[128]1877void edit_varslist_entry(struct raid_device_record *raidrec, int lino)
[1]1878{
1879
1880 /** buffers ***********************************************************/
[128]1881 char header[MAX_STR_LEN];
[1]1882 char comment[MAX_STR_LEN];
1883 char sz_out[MAX_STR_LEN];
1884
[128]1885 assert(raidrec != 0);
1886 assert(lino >= 0);
[1]1887
[128]1888 strcpy(sz_out, raidrec->additional_vars.el[lino].value);
[541]1889 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label);
1890 sprintf(comment, "Please set %s's value (currently '%s')",
[128]1891 raidrec->additional_vars.el[lino].label, sz_out);
1892 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
1893 strip_spaces(sz_out);
1894 strcpy(raidrec->additional_vars.el[lino].value, sz_out);
1895 }
[1]1896}
1897
1898
1899/* I'm not racist against white people. I just don't like people who think Liberia is near Spain. - Hugo, 09/01/2001 */
1900
1901#endif
1902
1903/**
1904 * Edit the mountlist using Newt.
1905 * @param mountlist The mountlist to edit.
1906 * @param raidlist The raidlist that goes with @p mountlist.
1907 * @return 0 if the user pressed OK, 1 if they pressed Cancel.
1908 */
1909int
[128]1910edit_mountlist_in_newt(char *mountlist_fname,
1911 struct mountlist_itself *mountlist,
1912 struct raidlist_itself *raidlist)
[1]1913{
1914
1915 /** newt **************************************************************/
[128]1916 newtComponent myForm;
[1]1917 newtComponent bAdd;
1918 newtComponent bEdit;
1919 newtComponent bDelete;
1920 newtComponent bOK;
1921 newtComponent bCancel;
1922 newtComponent b_res = NULL;
1923 newtComponent partitionsListbox;
1924 newtComponent headerMsg;
1925 newtComponent flawsLabelA;
1926 newtComponent flawsLabelB;
1927 newtComponent flawsLabelC;
1928 newtComponent bReload;
1929
1930 /** ???? *************************************************************/
[128]1931 void *curr_choice;
1932 void *keylist[ARBITRARY_MAXIMUM];
[1]1933
1934 /** int **************************************************************/
[128]1935 int i = 0;
[1]1936 int currline = 0;
1937 int finished = FALSE;
1938
1939 /** buffers **********************************************************/
1940 char tmp[MAX_STR_LEN];
[2350]1941 char *flaws_str = NULL;
[2209]1942 char *flaws_str_A = NULL;
1943 char *flaws_str_B = NULL;
1944 char *flaws_str_C = NULL;
[1]1945
[128]1946 assert(mountlist != NULL);
1947 assert(raidlist != NULL);
[1]1948
[128]1949 if (mountlist->entries > ARBITRARY_MAXIMUM) {
[541]1950 log_to_screen("Arbitrary limits suck, man!");
[128]1951 finish(1);
[1]1952 }
[128]1953 newtPushHelpLine
[541]1954 (" Please edit the mountlist to your satisfaction, then click OK or Cancel.");
[128]1955 i = 4;
[541]1956 bAdd = newtCompactButton(i, 17, " Add ");
1957 bEdit = newtCompactButton(i += 11, 17, " Edit ");
1958 bDelete = newtCompactButton(i += 12, 17, "Delete");
1959 bReload = newtCompactButton(i += 12, 17, "Reload");
1960 bCancel = newtCompactButton(i += 12, 17, "Cancel");
1961 bOK = newtCompactButton(i += 12, 17, " OK ");
1962 sprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format",
1963 "Size (MB)");
[128]1964 headerMsg = newtLabel(2, 1, tmp);
[2350]1965 flawsLabelA = newtLabel(2, 13, " ");
1966 flawsLabelB = newtLabel(2, 14, " ");
1967 flawsLabelC = newtLabel(2, 15, " ");
[128]1968 partitionsListbox =
1969 newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
1970 redraw_mountlist(mountlist, keylist, partitionsListbox);
[541]1971 newtOpenWindow(1, 3, 77, 18, "Editing mountlist");
[128]1972 myForm = newtForm(NULL, NULL, 0);
1973 newtFormAddComponents(myForm, headerMsg, partitionsListbox,
1974 flawsLabelA, flawsLabelB, flawsLabelC, bAdd,
1975 bEdit, bDelete, bReload, bCancel, bOK, NULL);
1976 while (!finished) {
[2394]1977 flaws_str = evaluate_mountlist(mountlist);
[2398]1978 /* flaws_str can be NULL */
1979 if ((flaws_str == NULL) || (strlen(flaws_str) == 0)) {
1980 mr_asprintf(&flaws_str_A, "");
1981 } else {
[2355]1982 mr_asprintf(&flaws_str_A, "%s", flaws_str + 1);
1983 }
1984 if (strlen(flaws_str_A) >= 74) {
1985 for (i = 74; flaws_str_A[i] != ' '; i--);
1986 mr_asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1);
1987 flaws_str_A[i] = '\0';
1988 } else {
1989 mr_asprintf(&flaws_str_B, "");
1990 }
1991 if (strlen(flaws_str_B) >= 74) {
1992 for (i = 74; flaws_str_B[i] != ' '; i--);
1993 mr_asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1);
1994 flaws_str_B[i] = '\0';
1995 } else {
1996 mr_asprintf(&flaws_str_C, "");
1997 }
[2350]1998
[128]1999 newtLabelSetText(flawsLabelA, flaws_str_A);
2000 newtLabelSetText(flawsLabelB, flaws_str_B);
2001 newtLabelSetText(flawsLabelC, flaws_str_C);
2002 b_res = newtRunForm(myForm);
[2350]2003 mr_free(flaws_str_A);
2004 mr_free(flaws_str_B);
2005 mr_free(flaws_str_C);
2006
[128]2007 if (b_res == bOK) {
[2394]2008 if (flaws_str != NULL) {
[128]2009 finished =
2010 ask_me_yes_or_no
[541]2011 ("Your mountlist might not work. Continue anyway?");
[128]2012 } else {
2013 finished =
2014 ask_me_yes_or_no
[541]2015 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)");
[128]2016 }
2017 } else if (b_res == bCancel) {
2018 finished = TRUE;
2019 } else if (b_res == bReload) {
[541]2020 if (ask_me_yes_or_no("Reload original mountlist?")) {
[1]2021/*
2022This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/24
2023 if (!RAIDTAB_FNAME[0])
2024 {
2025 strcpy(RAIDTAB_FNAME, "/etc/raidtab");
2026 log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);
2027 }
2028*/
[128]2029 load_mountlist(mountlist, mountlist_fname);
2030 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2031 redraw_mountlist(mountlist, keylist, partitionsListbox);
2032 }
2033 } else {
2034 curr_choice = newtListboxGetCurrent(partitionsListbox);
2035 for (i = 0;
2036 i < mountlist->entries && keylist[i] != curr_choice; i++);
2037 if (i == mountlist->entries && mountlist->entries > 0) {
[541]2038 log_to_screen("I don't know what that button does!");
[128]2039 } else {
2040 currline = i;
2041 if (b_res == bAdd) {
2042 add_mountlist_entry(mountlist, raidlist,
2043 partitionsListbox, currline,
2044 keylist);
2045 } else if (b_res == bDelete) {
2046 delete_mountlist_entry(mountlist, raidlist,
2047 partitionsListbox, currline,
2048 keylist);
2049 } else {
2050 if (mountlist->entries > 0) {
2051 edit_mountlist_entry(mountlist, raidlist,
2052 partitionsListbox, currline,
2053 keylist);
2054 } else {
2055 popup_and_OK
[541]2056 ("Please add an entry. Then press ENTER to edit it.");
[128]2057 }
2058 }
2059 }
[1]2060 }
[2398]2061 mr_free(flaws_str);
[1]2062 }
[128]2063 newtFormDestroy(myForm);
2064 newtPopWindow();
2065 newtPopHelpLine();
2066 if (b_res == bOK) {
[541]2067 log_it("You pushed 'OK'. I shall now continue.");
[128]2068 return (0);
2069 } else {
2070 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
2071 return (1);
2072 }
[1]2073}
2074
2075
2076
2077/**
2078 * Edit the mountlist.
2079 * @param mountlist The mountlist to edit.
2080 * @param raidlist The raidlist that goes with @p mountlist.
2081 * @return 0 if the user pressed OK, 1 if they pressed Cancel.
2082 */
2083int
[128]2084edit_mountlist(char *mountlist_fname, struct mountlist_itself *mountlist,
2085 struct raidlist_itself *raidlist)
[1]2086{
[128]2087 int res = 0;
[1]2088
[2230]2089 log_it("entering eml");
[1]2090
[128]2091 if (g_text_mode) {
2092 fatal_error("Don't call edit_mountlist() in text mode");
2093 } else {
2094 log_it
2095 ("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()");
2096 res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist);
2097 }
[2230]2098 log_it("leaving eml");
[128]2099 return (res);
[1]2100}
2101
2102
2103
2104
2105#ifndef __FreeBSD__
2106/**
2107 * Edit the additional RAID variables in @p raidrec.
2108 * @param raidrec The RAID device record to edit the RAID variables in.
2109 * @ingroup restoreGuiVarslist
2110 */
[128]2111void edit_raidrec_additional_vars(struct raid_device_record *raidrec)
[1]2112{
2113
2114 /** structure *********************************************************/
[128]2115 struct raid_device_record bkp_raidrec;
[1]2116
2117 /** newt **************************************************************/
[128]2118 newtComponent myForm;
[1]2119 newtComponent bAdd;
2120 newtComponent bEdit;
2121 newtComponent bDelete;
2122 newtComponent bOK;
2123 newtComponent bCancel;
2124 newtComponent b_res;
2125 newtComponent varsListbox;
2126 newtComponent headerMsg;
2127
2128 /** ?? ***************************************************************/
[128]2129 void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
[1]2130
2131 /** buffers **********************************************************/
[128]2132 char title_of_window[MAX_STR_LEN];
[1]2133
2134 /** int **************************************************************/
[128]2135 int i = 0;
[1]2136 int currline = 0;
2137
2138
[128]2139 assert(raidrec != NULL);
[1]2140
[128]2141 memcpy((void *) &bkp_raidrec, (void *) raidrec,
2142 sizeof(struct raid_device_record));
2143 sprintf(title_of_window, "Additional variables");
2144 newtPushHelpLine
[541]2145 (" Edit the additional fields to your heart's content, then click OK or Cancel.");
2146 headerMsg = newtLabel(1, 1, "Label Value");
[128]2147 varsListbox =
2148 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
2149 i = 1;
[541]2150 bAdd = newtCompactButton(i, 9, " Add ");
2151 bEdit = newtCompactButton(i += 8, 9, " Edit ");
2152 bDelete = newtCompactButton(i += 9, 9, "Delete");
2153 bOK = newtCompactButton(i += 9, 9, " OK ");
2154 bCancel = newtCompactButton(i += 9, 9, "Cancel");
[128]2155 newtOpenWindow(17, 7, 46, 10, title_of_window);
2156 myForm = newtForm(NULL, NULL, 0);
2157 newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit,
2158 bDelete, bOK, bCancel, NULL);
2159 insert_essential_additionalvars(raidrec);
2160 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
2161 for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
2162 b_res = newtRunForm(myForm);
2163 curr_choice = newtListboxGetCurrent(varsListbox);
2164 for (currline = 0;
2165 currline < raidrec->additional_vars.entries
2166 && keylist[currline] != curr_choice; currline++);
2167 if (currline == raidrec->additional_vars.entries
2168 && raidrec->additional_vars.entries > 0) {
2169 log_it("Warning - I don't know what this button does");
2170 }
2171 if (b_res == bOK) { /* do nothing */
2172 } else if (b_res == bCancel) { /* do nothing */
2173 } else if (b_res == bAdd) {
2174 add_varslist_entry(raidrec);
2175 } else if (b_res == bDelete) {
2176 delete_varslist_entry(raidrec, currline);
2177 } else {
2178 edit_varslist_entry(raidrec, currline);
2179 }
2180 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
[1]2181 }
[128]2182 remove_essential_additionalvars(raidrec);
2183 newtFormDestroy(myForm);
2184 newtPopWindow();
2185 newtPopHelpLine();
2186 if (b_res == bCancel) {
2187 memcpy((void *) raidrec, (void *) &bkp_raidrec,
2188 sizeof(struct raid_device_record));
[1]2189 }
[128]2190 return;
[1]2191}
2192#endif
2193
2194
2195/**
2196 * Find the next free location to place a disk in @p disklist.
2197 * @param disklist The disklist to operate on.
2198 * @return The next free location (starting from 0).
2199 * @ingroup restoreGuiDisklist
2200 */
[128]2201int find_next_free_index_in_disklist(struct list_of_disks *disklist)
[1]2202{
2203
2204 /** int ***************************************************************/
[128]2205 int index = -1;
[1]2206 int pos = 0;
[128]2207
[1]2208 /** bool **************************************************************/
[128]2209 bool done;
[1]2210
[128]2211 assert(disklist != NULL);
[1]2212
[128]2213 for (done = FALSE; !done;) {
2214 for (pos = 0;
2215 pos < disklist->entries && disklist->el[pos].index <= index;
2216 pos++);
2217 if (pos >= disklist->entries) {
2218 done = TRUE;
2219 } else {
2220 index = disklist->el[pos].index;
2221 }
[1]2222 }
[128]2223 return (index + 1);
[1]2224}
2225
2226
2227
2228/**
2229 * Locate @p device in @p raidlist.
2230 * @param raidlist The raidlist ot search in.
2231 * @param device The RAID device to search for.
2232 * @return The index of the device, or -1 if it could not be found.
2233 * @ingroup restoreGuiMountlist
2234 */
2235int
[128]2236find_raid_device_in_raidlist(struct raidlist_itself *raidlist,
2237 char *device)
[1]2238{
2239
2240 /** int ***************************************************************/
[128]2241 int i = 0;
[1]2242#ifdef __FreeBSD__
[128]2243 char vdev[64];
[1]2244#else
2245// Linux
2246#endif
2247
[128]2248 assert(raidlist != NULL);
2249 assert_string_is_neither_NULL_nor_zerolength(device);
2250
[1]2251#ifdef __FreeBSD__
[128]2252 for (i = 0; i < raidlist->entries; i++) {
2253 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
2254 if (!strcmp(device, vdev))
2255 break;
2256 }
[1]2257#else
2258
[128]2259 for (i = 0;
2260 strcmp(raidlist->el[i].raid_device, device)
2261 && i < raidlist->entries; i++);
[1]2262#endif
[128]2263 if (i == raidlist->entries) {
2264 return (-1);
2265 } else {
2266 return (i);
2267 }
[1]2268}
2269
2270
2271/**
2272 * Get information about the location of ISO images from the user.
2273 * @param isodir_device Where to put the device (e.g. /dev/hda4) the user enters.
2274 * @param isodir_format Where to put the format (e.g. ext2) the user enters.
[1967]2275 * @param isodir_path Where to put the path (e.g. /var/cache/mondo) the user enters.
[1]2276 * @param nuke_me_please Whether we're planning on nuking or not.
2277 * @return TRUE if OK was pressed, FALSE otherwise.
2278 */
2279bool
[128]2280get_isodir_info(char *isodir_device, char *isodir_format,
[2770]2281 char *isodir_path, char *subdir_path, bool nuke_me_please)
[1]2282{
2283
[2769]2284 bool HDD = FALSE;
[1]2285 /** initialize ********************************************************/
2286
[128]2287 assert(isodir_device != NULL);
2288 assert(isodir_format != NULL);
2289 assert(isodir_path != NULL);
[1]2290
[2080]2291 log_it("isodir_path = %s", isodir_path);
[128]2292 isodir_format[0] = '\0';
2293 if (isodir_device[0] == '\0') {
2294 strcpy(isodir_device, "/dev/");
2295 }
2296 if (isodir_path[0] == '\0') {
2297 strcpy(isodir_path, "/");
2298 }
[2380]2299 if (does_file_exist("/tmp/NETFS-SERVER-PATH")) {
2300 strcpy(isodir_device, last_line_of_file("/tmp/NETFS-SERVER-MOUNT"));
2301 strcpy(isodir_format, "netfs");
2302 strcpy(isodir_path, last_line_of_file("/tmp/NETFS-SERVER-PATH"));
[128]2303 }
2304 if (nuke_me_please) {
2305 return (TRUE);
2306 }
[1]2307
[128]2308 if (popup_and_get_string
[541]2309 ("ISO Mode - device", "On what device do the ISO files live?",
[128]2310 isodir_device, MAX_STR_LEN / 4)) {
2311 if (popup_and_get_string
[541]2312 ("ISO Mode - format",
2313 "What is the disk format of the device? (Hit ENTER if you don't know.)",
[128]2314 isodir_format, 16)) {
[2770]2315 if (popup_with_buttons("Are you restoring from an external hard drive ?", "Yes", "No")) {
[2769]2316 HDD = TRUE;
2317 }
[128]2318 if (popup_and_get_string
[541]2319 ("ISO Mode - path",
[2769]2320 "At what path on this device can the ISO files be found ?",
2321 isodir_path, MAX_STR_LEN / 4)) {
[128]2322 strip_spaces(isodir_device);
2323 strip_spaces(isodir_format);
2324 strip_spaces(isodir_path);
[2140]2325 log_it("isodir_device = %s - isodir_format = %s - isodir_path = %s", isodir_device, isodir_format, isodir_path);
[2769]2326 if (HDD) {
2327 /* We need an additional param */
2328 mr_asprintf(&subdir_path, "%s", isodir_path);
2329 strcpy(isodir_path, "/tmp/isodir");
2330 }
[128]2331 return (TRUE);
2332 }
2333 }
[1]2334 }
[128]2335 return (FALSE);
[1]2336}
2337
2338
2339/**
2340 * Create a new raidtab entry for @p device in @p raidlist.
2341 * @param raidlist The raidlist to add the device to.
2342 * @param mountlist The mountlist containing information about the user's partitions.
2343 * @param currline The selected line in the mountlist.
2344 * @param device The RAID device (e.g. /dev/md0) to use.
2345 * @ingroup restoreGuiMountlist
2346 */
2347void
[128]2348initiate_new_raidlist_entry(struct raidlist_itself *raidlist,
2349 struct mountlist_itself *mountlist,
2350 int currline, char *device)
[1]2351{
2352
2353 /** structure *********************************************************/
[128]2354 struct OSSWAP (raid_device_record, vinum_volume) * raidrec;
[1]2355
2356 /** int ***************************************************************/
[128]2357 int pos_in_raidlist = 0;
[1]2358
[128]2359 assert(raidlist != NULL);
2360 assert(mountlist != NULL);
2361 assert_string_is_neither_NULL_nor_zerolength(device);
[1]2362
[128]2363 pos_in_raidlist =
2364 find_raid_device_in_raidlist(raidlist,
2365 mountlist->el[currline].device);
2366 if (pos_in_raidlist >= 0) {
2367 fatal_error("Sorry, that RAID device already exists. Weird.");
2368 }
2369 pos_in_raidlist = raidlist->entries++;
2370 raidrec = &raidlist->el[pos_in_raidlist];
2371 initialize_raidrec(raidrec);
2372 strcpy(raidrec->OSSWAP(raid_device, volname),
2373 OSSWAP(device, basename(device)));
[1]2374#ifndef __FreeBSD__
[128]2375 choose_raid_level(raidrec);
2376 select_raid_disks(mountlist, raidlist, raidrec, "data",
2377 &raidrec->data_disks);
[1]2378#endif
[128]2379 edit_raidlist_entry(mountlist, raidlist, raidrec, currline);
[1]2380}
2381
2382
2383#ifndef __FreeBSD__
2384/**
2385 * Insert the RAID variables not stored in the "additional RAID variables" list there too.
2386 * @param raidrec The RAID device record to operate on.
2387 * @ingroup restoreGuiVarslist
2388 */
[128]2389void insert_essential_additionalvars(struct raid_device_record *raidrec)
[1]2390{
2391
2392 /** int **************************************************************/
[128]2393 int items = 0;
[1]2394
[128]2395 assert(raidrec != NULL);
[1]2396
[128]2397 items = raidrec->additional_vars.entries;
2398 write_variableINT_to_raid_var_line(raidrec, items++,
2399 "persistent-superblock",
2400 raidrec->persistent_superblock);
2401 write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size",
2402 raidrec->chunk_size);
2403 raidrec->additional_vars.entries = items;
[1]2404}
2405
2406#endif
2407
2408/**
2409 * Dummy function that proves that we can get to the point where Mondo is run.
2410 */
[128]2411void nuke_mode_dummy()
[1]2412{
2413
2414 /** newt *************************************************************/
[128]2415 newtComponent myForm;
[1]2416 newtComponent b1;
2417 newtComponent b2;
2418 newtComponent b3;
2419 newtComponent b_res;
2420
2421
[128]2422 newtPushHelpLine
[541]2423 ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!");
2424 newtOpenWindow(24, 3, 32, 13, "Nuking");
2425 b1 = newtButton(7, 1, "Slowly");
2426 b2 = newtButton(7, 5, "Medium");
2427 b3 = newtButton(7, 9, "Quickly");
[128]2428 myForm = newtForm(NULL, NULL, 0);
2429 newtFormAddComponents(myForm, b1, b2, b3, NULL);
2430 b_res = newtRunForm(myForm);
2431 newtFormDestroy(myForm);
2432 newtPopWindow();
2433 newtPopHelpLine();
[1]2434}
2435
2436
2437
2438/**
2439 * Redraw the disklist.
2440 * @param disklist The disklist to read from.
2441 * @param keylist The list of keys for @p listbox.
2442 * @param listbox The Newt listbox component to redraw.
2443 * @ingroup restoreGuiDisklist
2444 */
2445void
[128]2446redraw_disklist(struct list_of_disks *disklist,
2447 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
[1]2448{
2449
[738]2450 /** long **************************************************************/
2451 long i = 0;
[1]2452
[128]2453 assert(disklist != NULL);
2454 assert(keylist != NULL);
2455 assert(listbox != NULL);
[1]2456
[128]2457 newtListboxClear(listbox);
[1]2458
[128]2459 for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
2460 keylist[i] = (void *) i;
2461 }
2462 for (i = 0; i < disklist->entries; i++) {
2463 newtListboxAppendEntry(listbox,
2464 disklist_entry_to_string(disklist, i),
2465 keylist[i]);
2466 }
[1]2467}
2468
2469
2470/**
2471 * Redraw the mountlist.
2472 * @param mountlist The mountlist to read from.
2473 * @param keylist The list of keys for @p listbox.
2474 * @param listbox The Newt listbox component to redraw.
2475 * @ingroup restoreGuiMountlist
2476 */
2477void
[128]2478redraw_mountlist(struct mountlist_itself *mountlist,
2479 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
[1]2480{
[128]2481
[738]2482 /** long **************************************************************/
2483 long i = 0;
[1]2484
[128]2485 assert(mountlist != NULL);
2486 assert(keylist != NULL);
2487 assert(listbox != NULL);
[1]2488
[128]2489 newtListboxClear(listbox);
[1]2490// sort_mountlist_by_device (mountlist);
[128]2491 for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
2492 keylist[i] = (void *) i;
2493 }
2494 for (i = 0; i < mountlist->entries; i++) {
2495 newtListboxAppendEntry(listbox,
2496 mountlist_entry_to_string(mountlist, i),
2497 keylist[i]);
2498 }
[1]2499}
2500
2501
2502
2503
2504/**
2505 * Redraw the list of unallocated RAID partitions.
2506 * @param unallocated_raid_partitions The mountlist containing unallocated RAID partitions.
2507 * @param keylist The list of keys for @p listbox.
2508 * @param listbox The Newt listbox component to redraw.
2509 * @ingroup restoreGuiDisklist
2510 */
[128]2511void redraw_unallocpartnslist(struct mountlist_itself
2512 *unallocated_raid_partitions,
2513 void *keylist[ARBITRARY_MAXIMUM],
2514 newtComponent listbox)
[1]2515{
2516
[738]2517 /** long *************************************************************/
2518 long i = 0;
[1]2519
2520 /** buffers **********************************************************/
[128]2521 char tmp[MAX_STR_LEN];
[1]2522
[128]2523 assert(unallocated_raid_partitions != NULL);
2524 assert(keylist != NULL);
2525 assert(listbox != NULL);
[1]2526
[128]2527 newtListboxClear(listbox);
2528 for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
2529 keylist[i] = (void *) i;
2530 }
2531 for (i = 0; i < unallocated_raid_partitions->entries; i++) {
2532 sprintf(tmp, "%-22s %8lld",
2533 unallocated_raid_partitions->el[i].device,
[2125]2534 unallocated_raid_partitions->el[i].size / 1024L);
[128]2535 newtListboxAppendEntry(listbox, tmp, keylist[i]);
2536 }
[1]2537}
2538
2539#ifndef __FreeBSD__
2540/**
2541 * Redraw the list of additional RAID variables.
2542 * @param additional_vars The list of additional RAID varibals.
2543 * @param keylist The list of keys for @p listbox.
2544 * @param listbox The Newt listbox component to redraw.
2545 * @ingroup restoreGuiVarslist
2546 */
2547void
[128]2548redraw_varslist(struct additional_raid_variables *additional_vars,
2549 void *keylist[], newtComponent listbox)
[1]2550{
[738]2551 /** long ************************************************************/
2552 long i = 0;
[1]2553
2554 /** buffers *********************************************************/
[128]2555 char tmp[MAX_STR_LEN];
[1]2556
[128]2557 assert(additional_vars != NULL);
2558 assert(keylist != NULL);
2559 assert(listbox != NULL);
[1]2560
[128]2561 newtListboxClear(listbox);
[1]2562
[128]2563 for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
2564 keylist[i] = (void *) i;
2565 }
2566 for (i = 0; i < additional_vars->entries; i++) {
2567 sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label,
2568 additional_vars->el[i].value);
2569 newtListboxAppendEntry(listbox, tmp, keylist[i]);
2570 }
[1]2571}
2572
2573
2574/**
2575 * Remove variable @p label from the RAID variables list in @p raidrec.
2576 * @param raidrec The RAID device record to remove the variable from.
2577 * @param label The variable name to remove.
2578 * @return The value of the variable removed.
2579 * @ingroup restoreUtilityGroup
2580 */
2581int
[128]2582read_variableINT_and_remove_from_raidvars(struct
2583 OSSWAP (raid_device_record,
2584 vinum_volume) * raidrec,
2585 char *label)
[1]2586{
2587 /** int ***************************************************************/
[128]2588 int i = 0;
[1]2589 int res = 0;
2590
2591
[128]2592 assert(raidrec != NULL);
2593 assert(label != NULL);
[1]2594
[128]2595 for (i = 0;
2596 i < raidrec->additional_vars.entries
2597 && strcmp(raidrec->additional_vars.el[i].label, label); i++);
2598 if (i == raidrec->additional_vars.entries) {
2599 res = -1;
2600 } else {
2601 res = atoi(raidrec->additional_vars.el[i].value);
2602 for (i++; i < raidrec->additional_vars.entries; i++) {
2603 memcpy((void *) &raidrec->additional_vars.el[i - 1],
2604 (void *) &raidrec->additional_vars.el[i],
2605 sizeof(struct raid_var_line));
2606 }
2607 raidrec->additional_vars.entries--;
[1]2608 }
[128]2609 return (res);
[1]2610}
2611#endif
2612
2613/**
2614 * Change all RAID devices to use @p new_dev instead of @p old_dev.
2615 * @param raidlist The raidlist to make the changes in.
2616 * @param old_dev The old name of the device (what it used to be).
2617 * @param new_dev The new name of the device (what it is now).
2618 * @ingroup restoreGuiMountlist
2619 */
[128]2620void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself
2621 *raidlist,
2622 char *old_dev,
2623 char *new_dev)
[1]2624{
2625 /** buffers ********************************************************/
[128]2626 char tmp[MAX_STR_LEN];
[1]2627
2628 /** int ************************************************************/
[128]2629 int pos = 0;
[1]2630 int j = 0;
2631
[128]2632 assert(raidlist != NULL);
2633 assert_string_is_neither_NULL_nor_zerolength(old_dev);
2634 assert_string_is_neither_NULL_nor_zerolength(new_dev);
[1]2635
[128]2636 pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
2637 if (pos < 0) {
2638 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
2639 old_dev);
2640 log_it(tmp);
2641 } else {
2642 if ((j =
2643 where_in_drivelist_is_drive(&raidlist->
2644 OSSWAP(el[pos].data_disks, disks),
2645 old_dev)) >= 0) {
2646 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].
2647 device, new_dev);
2648 } else
2649 if ((j =
2650 where_in_drivelist_is_drive(&raidlist->
2651 OSSWAP(el[pos].spare_disks,
2652 spares),
2653 old_dev)) >= 0) {
2654 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].
2655 device, new_dev);
2656 }
[1]2657#ifndef __FreeBSD__
[128]2658 else if ((j =
2659 where_in_drivelist_is_drive(&raidlist->el[pos].
2660 parity_disks,
2661 old_dev)) >= 0) {
2662 strcpy(raidlist->el[pos].parity_disks.el[j].device, new_dev);
2663 } else
2664 if ((j =
2665 where_in_drivelist_is_drive(&raidlist->el[pos].
2666 failed_disks,
2667 old_dev)) >= 0) {
2668 strcpy(raidlist->el[pos].failed_disks.el[j].device, new_dev);
2669 }
[1]2670#endif
[128]2671 else {
2672 sprintf(tmp,
2673 "%s is supposed to be listed in this raid dev but it's not...",
2674 old_dev);
2675 log_it(tmp);
2676 }
[1]2677 }
2678}
2679
2680
2681#ifndef __FreeBSD__
2682/**
2683 * Remove the essential RAID variables from the "additional variables" section.
2684 * If they have been changed, set them in their normal locations too.
2685 * @param raidrec The RAID device record to operate on.
2686 * @ingroup restoreUtilityVarslist
2687 */
[128]2688void remove_essential_additionalvars(struct raid_device_record *raidrec)
[1]2689{
2690
2691 /** int **************************************************************/
[128]2692 int res = 0;
[1]2693
[128]2694 assert(raidrec != NULL);
[1]2695
[128]2696 res =
2697 read_variableINT_and_remove_from_raidvars(raidrec,
2698 "persistent-superblock");
2699 if (res > 0) {
2700 raidrec->persistent_superblock = res;
2701 }
2702 res = read_variableINT_and_remove_from_raidvars(raidrec, "chunk-size");
2703 if (res > 0) {
2704 raidrec->chunk_size = res;
2705 }
2706 res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size");
[1]2707}
2708
2709/**
2710 * Select the RAID disks to use in @p raidrec.
2711 * @param mountlist_dontedit The mountlist (will not be edited).
2712 * @param raidlist The raidlist to modify.
2713 * @param raidrec The RAID device record in @p raidlist to work on.
2714 * @param description_of_list The type of disks we're selecting (e.g. "data").
2715 * @param disklist The disklist to put the user-selected disks in.
2716 * @ingroup restoreGuiMountlist
2717 */
2718void
[128]2719select_raid_disks(struct mountlist_itself *mountlist_dontedit,
2720 struct raidlist_itself *raidlist,
2721 struct raid_device_record *raidrec,
2722 char *description_of_list,
2723 struct list_of_disks *disklist)
[1]2724{
[128]2725 void *curr_choice;
[1]2726
2727 /** ??? ***************************************************************/
2728
2729 /** structures ********************************************************/
[128]2730 struct raidlist_itself *bkp_raidlist;
2731 struct raid_device_record *bkp_raidrec;
2732 struct list_of_disks *bkp_disklist;
2733 struct mountlist_itself *unallocated_raid_partitions;
[1]2734
2735 /** newt **************************************************************/
[128]2736 newtComponent myForm = NULL;
2737 newtComponent bAdd = NULL;
2738 newtComponent bDelete = NULL;
2739 newtComponent bOK = NULL;
2740 newtComponent bCancel = NULL;
2741 newtComponent b_res = NULL;
2742 newtComponent partitionsListbox = NULL;
2743 newtComponent headerMsg = NULL;
[1]2744
2745 /** buffers **********************************************************/
[128]2746 void *keylist[ARBITRARY_MAXIMUM];
2747 char *tmp;
2748 char *help_text;
2749 char *title_of_window;
2750 char *sz_res;
2751 char *header_text;
[1]2752
2753 /** int **************************************************************/
[128]2754 int i = 0;
2755 int currline = 0;
[1]2756
[128]2757 assert(mountlist_dontedit != NULL);
2758 assert(raidlist != NULL);
2759 assert(raidrec != NULL);
2760 assert(description_of_list != NULL);
2761 assert(disklist != NULL);
[1]2762
[2230]2763 log_it("malloc'ing");
[128]2764 malloc_string(tmp);
2765 malloc_string(help_text);
2766 malloc_string(title_of_window);
2767 malloc_string(sz_res);
2768 malloc_string(header_text);
2769 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
2770 fatal_error("Cannot malloc space for raidrec");
2771 }
2772 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) {
2773 fatal_error("Cannot malloc space for disklist");
2774 }
2775 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) {
2776 fatal_error("Cannot malloc space for raidlist");
2777 }
2778 if (!
2779 (unallocated_raid_partitions =
2780 malloc(sizeof(struct mountlist_itself)))) {
2781 fatal_error("Cannot malloc space for unallocated_raid_partitions");
2782 }
[1]2783
[128]2784 memcpy((void *) bkp_raidlist, (void *) raidlist,
2785 sizeof(struct raidlist_itself));
2786 memcpy((void *) bkp_raidrec, (void *) raidrec,
2787 sizeof(struct raid_device_record));
2788 memcpy((void *) bkp_disklist, (void *) disklist,
2789 sizeof(struct list_of_disks));
[1]2790
[2230]2791 log_it("Post-malloc");
[128]2792 strcpy(help_text,
[541]2793 " Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
2794 sprintf(header_text, "%-24s %s", "Device", "Index");
2795 sprintf(title_of_window, "%s contains...", raidrec->raid_device);
[128]2796 newtPushHelpLine(help_text);
2797 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) {
2798 headerMsg = newtLabel(1, 1, header_text);
2799 partitionsListbox =
2800 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
2801 redraw_disklist(disklist, keylist, partitionsListbox);
2802 i = 1;
[541]2803 bAdd = newtCompactButton(i, 9, " Add ");
2804 bDelete = newtCompactButton(i += 8, 9, "Delete");
2805 bOK = newtCompactButton(i += 9, 9, " OK ");
2806 bCancel = newtCompactButton(i += 9, 9, "Cancel");
[128]2807 newtOpenWindow(21, 7, 38, 10, title_of_window);
2808 myForm = newtForm(NULL, NULL, 0);
2809 if (disklist->entries == 0) {
2810 newtFormAddComponents(myForm, headerMsg, bAdd, bDelete, bOK,
2811 bCancel, NULL);
2812 } else {
2813 newtFormAddComponents(myForm, headerMsg, partitionsListbox,
2814 bAdd, bDelete, bOK, bCancel, NULL);
2815 }
2816 b_res = newtRunForm(myForm);
2817 if (b_res == bOK || b_res == bCancel) { /* do nothing */
[1]2818// That's OK. At the end of this subroutine (after this do/while loop),
2819// we'll throw away the changes if Cancel was pushed.
[128]2820 } else {
2821 curr_choice = newtListboxGetCurrent(partitionsListbox);
2822 for (i = 0; i < disklist->entries && keylist[i] != curr_choice;
2823 i++);
2824 if (i == disklist->entries && disklist->entries > 0) {
[541]2825 log_to_screen("I don't know what that button does!");
[128]2826 } else {
2827 currline = i;
2828 if (b_res == bAdd) {
[541]2829 log_it("Making list of unallocated RAID slices");
[128]2830 make_list_of_unallocated_raid_partitions
2831 (unallocated_raid_partitions, mountlist_dontedit,
2832 raidlist);
2833 if (unallocated_raid_partitions->entries <= 0) {
2834 popup_and_OK
[541]2835 ("There are no unallocated partitions marked for RAID.");
[128]2836 } else {
2837 log_it
[541]2838 ("Done. The user may add one or more of the above to RAID device");
[128]2839 add_disklist_entry(disklist, raidrec->raid_device,
2840 unallocated_raid_partitions);
[541]2841 log_it("I have finished adding a disklist entry.");
[128]2842 redraw_disklist(disklist, keylist,
2843 partitionsListbox);
2844 }
2845 } else if (b_res == bDelete) {
2846 delete_disklist_entry(disklist, raidrec->raid_device,
2847 currline);
2848 redraw_disklist(disklist, keylist, partitionsListbox);
2849 } else {
[541]2850 sprintf(tmp, "%s's index is %d. What should it be?",
[128]2851 raidrec->raid_device,
2852 disklist->el[currline].index);
2853 sprintf(sz_res, "%d", disklist->el[currline].index);
[541]2854 if (popup_and_get_string("Set index", tmp, sz_res, 10)) {
[128]2855 disklist->el[currline].index = atoi(sz_res);
2856 }
2857 redraw_disklist(disklist, keylist, partitionsListbox);
2858 }
2859 }
[1]2860 }
[128]2861 newtFormDestroy(myForm);
2862 newtPopWindow();
[1]2863 }
[128]2864 newtPopHelpLine();
2865 if (b_res == bCancel) {
2866 memcpy((void *) raidlist, (void *) bkp_raidlist,
2867 sizeof(struct raidlist_itself));
2868 memcpy((void *) raidrec, (void *) bkp_raidrec,
2869 sizeof(struct raid_device_record));
2870 memcpy((void *) disklist, (void *) bkp_disklist,
2871 sizeof(struct list_of_disks));
2872 }
2873 paranoid_free(tmp);
2874 paranoid_free(help_text);
2875 paranoid_free(title_of_window);
2876 paranoid_free(sz_res);
2877 paranoid_free(header_text);
2878 paranoid_free(bkp_raidrec);
2879 paranoid_free(bkp_disklist);
2880 paranoid_free(bkp_raidlist);
2881 paranoid_free(unallocated_raid_partitions);
[1]2882}
2883#endif
2884
2885
2886
2887/**
2888 * Ask the user which restore mode (nuke, interactive, or compare) we should use.
2889 * @return The mode selected: 'I' for interactive, 'N' for nuke, 'C' for compare,
2890 * or 'E' (or any other letter) for exit.
2891 */
[128]2892char which_restore_mode()
[1]2893{
[128]2894
[1]2895 /** char *************************************************************/
[128]2896 char output = '\0';
2897 char tmp[MAX_STR_LEN];
2898
[1]2899 /** newt *************************************************************/
2900
[128]2901 newtComponent b1;
2902 newtComponent b2;
2903 newtComponent b3;
2904 newtComponent b4;
2905 newtComponent b_res;
2906 newtComponent myForm;
2907
2908 if (g_text_mode) {
2909 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
2910 printf
[541]2911 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
[128]2912 fgets(tmp, MAX_STR_LEN - 1, stdin);
2913 }
2914 return (output);
[1]2915 }
2916
[128]2917 newtPushHelpLine
[541]2918 (" Do you want to 'nuke' your system, restore interactively, or just compare?");
2919 newtOpenWindow(24, 3, 32, 17, "How should I restore?");
2920 b1 = newtButton(7, 1, "Automatically");
2921 b2 = newtButton(7, 5, "Interactively");
2922 b3 = newtButton(7, 9, "Compare only!");
2923 b4 = newtButton(7, 13, "Exit to shell");
[128]2924 myForm = newtForm(NULL, NULL, 0);
2925 newtFormAddComponents(myForm, b1, b2, b3, b4, NULL);
2926 b_res = newtRunForm(myForm);
2927 newtFormDestroy(myForm);
2928 newtPopWindow();
2929 if (b_res == b1) {
2930 output = 'N';
2931 }
2932 if (b_res == b2) {
2933 output = 'I';
2934 }
2935 if (b_res == b3) {
2936 output = 'C';
2937 }
2938 if (b_res == b4) {
2939 output = 'E';
2940 }
2941 newtPopHelpLine();
2942 return (output);
[1]2943}
Note: See TracBrowser for help on using the repository browser.