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