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

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

Merge trunk memory management for mondo-rstr-newt.c

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