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