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

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