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