source: MondoRescue/trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c@ 729

Last change on this file since 729 was 729, checked in by Bruno Cornec, 18 years ago

merge -r686:728 $SVN_M/branches/stable

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