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