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