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