source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondo-rstr-newt.c@ 3857

Last change on this file since 3857 was 3856, checked in by Bruno Cornec, 4 months ago

remove snprintf usage and use bkpinfo for serial_string

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