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