source: MondoRescue/branches/stable/mondo/src/mondorestore/mondo-rstr-newt.c@ 1200

Last change on this file since 1200 was 1168, checked in by Bruno Cornec, 17 years ago

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

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