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