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