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