source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondo-rstr-newt.c@ 3067

Last change on this file since 3067 was 3067, checked in by Bruno Cornec, 11 years ago

Adds a warning msg at restore time so that LVM modifications are done in /tmp/i-want-my-lvm and not in the mountlist

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