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

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

mr_gettext.h added again + locale.h

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