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