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