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