/* * Ask the user which physical disk they want. * Changes ss->selected_disk if successful. */ void fn_select_disk(struct i_fn_args *a) { struct dfui_form *f; struct dfui_action *k; struct dfui_response *r; struct disk *d; f = dfui_form_create( "select_disk", _("Select Disk"), a->short_desc, "", "p", "role", "menu", "p", "special", "dfinstaller_select_disk", NULL ); for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) { dfui_form_action_add(f, disk_get_device_name(d), dfui_info_new(disk_get_desc(d), "", "")); } k = dfui_form_action_add(f, "cancel", dfui_info_new(a->cancel_desc, "", "")); dfui_action_property_set(k, "accelerator", "ESC"); if (!dfui_be_present(a->c, f, &r)) abort_backend(); if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) { a->result = 0; } else { d = disk_find(a->s, dfui_response_get_action_id(r)); if (d == NULL) { inform(a->c, _("Internal error - response from frontend " "should be a valid device name.")); a->result = 0; } else { storage_set_selected_disk(a->s, d); a->result = 1; } } dfui_form_free(f); dfui_response_free(r); }
/* * Wipes the start of the selected slice. */ void fn_wipe_start_of_slice(struct i_fn_args *a) { struct commands *cmds; a->short_desc = _("If you are having problems formatting a primary partition, " "it may be because of junk that has accumulated in the " "partition's `disklabel'. A cure for this is to wipe out " "everything on the first few sectors of the primary partition. " "However, this is a rather drastic action to take, so it is not " "recommended unless you are otherwise encountering problems."); a->cancel_desc = _("Return to Utilities Menu"); fn_select_slice(a); if (!a->result) return; if (confirm_dangerous_action(a->c, _("WARNING! ALL data in primary partition #%d,\n\n%s\n\non the " "disk\n\n%s\n\n will be IRREVOCABLY ERASED!\n\nAre you " "ABSOLUTELY SURE you wish to take this action? This is " "your LAST CHANCE to cancel!"), slice_get_number(storage_get_selected_slice(a->s)), slice_get_desc(storage_get_selected_slice(a->s)), disk_get_desc(storage_get_selected_disk(a->s)))) { /* XXX check to make sure this slice is not mounted first */ cmds = commands_new(); command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16", a->os_root, cmd_name(a, "DD"), slice_get_device_name(storage_get_selected_slice(a->s))); if (commands_execute(a, cmds)) { inform(a->c, _("Start of primary partition was successfully wiped.")); } else { inform(a->c, _("Some errors occurred. " "Start of primary partition was not successfully wiped.")); } commands_free(cmds); } }
/* * Wipes the start of the selected disk. */ void fn_wipe_start_of_disk(struct i_fn_args *a) { struct commands *cmds; a->short_desc = _("If you are having problems formatting a disk, " "it may be because of junk that has accumulated " "in the boot block and the partition table. " "A cure for this is to wipe out everything on " "the first few sectors of the disk. However, this " "is a rather drastic action to take, so it is not " "recommended unless you are otherwise " "encountering problems."); a->cancel_desc = _("Return to Utilities Menu"); fn_select_disk(a); if (!a->result) return; /* XXX check to make sure no slices on this disk are mounted first? */ if (storage_get_selected_disk(a->s) != NULL && confirm_dangerous_action(a->c, _("WARNING! ALL data in ALL partitions on the disk\n\n" "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY " "SURE you wish to take this action? This is your " "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) { cmds = commands_new(); command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16", a->os_root, cmd_name(a, "DD"), disk_get_device_name(storage_get_selected_disk(a->s))); if (commands_execute(a, cmds)) { inform(a->c, _("Start of disk was successfully wiped.")); } else { inform(a->c, _("Some errors occurred. " "Start of disk was not successfully wiped.")); } commands_free(cmds); } }
/* * state_format_disk: ask the user if they wish to format the disk they * selected. */ void state_format_disk(struct i_fn_args *a) { switch (dfui_be_present_dialog(a->c, _("How Much Disk?"), _("Use Entire Disk|Use Part of Disk|Return to Select Disk"), _("Select how much of this disk you want to use for %s.\n\n%s"), OPERATING_SYSTEM_NAME, disk_get_desc(storage_get_selected_disk(a->s)))) { case 1: /* Entire Disk */ if (measure_activated_swap_from_disk(a, storage_get_selected_disk(a->s)) > 0) { if (swapoff_all(a) == NULL) { inform(a->c, _("Warning: swap could not be turned off.")); state = state_select_disk; return; } } fn_format_disk(a); if (a->result) state = state_ask_fs; else state = state_format_disk; break; case 2: /* Part of Disk */ state = state_select_slice; break; case 3: /* Return */ state = state_select_disk; break; default: abort_backend(); break; } }
/* * state_select_slice: ask the user which slice they wish to install * DragonFly on. In order to avoid confusing them, refer to it as * a primary partition, but tell them what BSD has traditionally called * it, too. */ void state_select_slice(struct i_fn_args *a) { char msg_buf[1][1024]; snprintf(msg_buf[0], sizeof(msg_buf[0]), _("Select the existing primary partition (also " "known as a `slice' in the BSD tradition) on " "which to install %s.\n\n" "Note that if you do not have any existing " "primary partitions on this disk, you must " "first create some. This installer does not " "currently have the ability to do this, so " "you will have to exit and run fdisk (in " "DOS or *BSD) or parted (in Linux) to do so."), OPERATING_SYSTEM_NAME); a->short_desc = msg_buf[0]; a->cancel_desc = _("Return to Select Disk"); fn_select_slice(a); if (!a->result || storage_get_selected_slice(a->s) == NULL) { state = state_select_disk; } else { if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s), storage_get_selected_slice(a->s)) > 0) { if (swapoff_all(a) == NULL) { inform(a->c, _("Warning: swap could not be turned off.")); state = state_select_slice; return; } } if (slice_get_capacity(storage_get_selected_slice(a->s)) < DISK_MIN) { inform(a->c, _("WARNING: you should have a primary " "partition at least %dM in size, or " "you may encounter problems trying to " "install %s."), DISK_MIN, OPERATING_SYSTEM_NAME); } if (confirm_dangerous_action(a->c, _("WARNING! ALL data in primary partition #%d,\n\n%s\n\non the " "disk\n\n%s\n\n will be IRREVOCABLY ERASED!\n\nAre you " "ABSOLUTELY SURE you wish to take this action? This is " "your LAST CHANCE to cancel!"), slice_get_number(storage_get_selected_slice(a->s)), slice_get_desc(storage_get_selected_slice(a->s)), disk_get_desc(storage_get_selected_disk(a->s)))) { if (!format_slice(a)) { inform(a->c, _("Primary partition #%d was " "not correctly formatted, and may " "now be in an inconsistent state. " "We recommend re-formatting it " "before proceeding."), slice_get_number(storage_get_selected_slice(a->s))); } else { inform(a->c, _("Primary partition #%d was formatted."), slice_get_number(storage_get_selected_slice(a->s))); state = state_ask_fs; } } else { inform(a->c, _("Action cancelled - no primary partitions were formatted.")); state = state_select_slice; } } }
/* * If ss->selected_disk == NULL, user will be asked for which disk. * Returns 1 if disk was formatted, 0 if it wasn't. * If it was, ss->selected_disk and ss->selected_slice are set to it. */ void fn_format_disk(struct i_fn_args *a) { struct commands *cmds; char *selected_disk_string; if (storage_get_selected_disk(a->s) == NULL) { a->short_desc = _("Select a disk to format."); a->cancel_desc = _("Return to Utilities Menu"); fn_select_disk(a); if (!a->result || storage_get_selected_disk(a->s) == NULL) { a->result = 0; return; } } if (confirm_dangerous_action(a->c, _("WARNING! ALL data in ALL partitions on the disk\n\n" "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY " "SURE you wish to take this action? This is your " "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) { cmds = commands_new(); command_add(cmds, "%s%s -BI %s", a->os_root, cmd_name(a, "FDISK"), disk_get_device_name(storage_get_selected_disk(a->s))); if (!commands_execute(a, cmds)) { inform(a->c, _("The disk\n\n%s\n\nwas " "not correctly formatted, and may " "now be in an inconsistent state. " "We recommend re-formatting it " "before attempting to install " "%s on it."), disk_get_desc(storage_get_selected_disk(a->s)), OPERATING_SYSTEM_NAME); commands_free(cmds); a->result = 0; return; } commands_free(cmds); /* * Since one of the disks has now changed, we must * refresh our view of them and re-select the disk * since the selected_disk pointer will be invalidated. */ selected_disk_string = aura_strdup( disk_get_device_name(storage_get_selected_disk(a->s))); if (!survey_storage(a)) { inform(a->c, _("Errors occurred while probing " "the system for its storage capabilities.")); } storage_set_selected_disk(a->s, disk_find(a->s, selected_disk_string)); free(selected_disk_string); /* * Note that we formatted this disk and that we want * to use the first (and only) slice of it. */ disk_set_formatted(storage_get_selected_disk(a->s), 1); storage_set_selected_slice(a->s, disk_slice_first(storage_get_selected_disk(a->s))); if (!format_slice(a)) { inform(a->c, _("The sole primary partition of " "the disk\n\n%s\n\nwas " "not correctly formatted, and may " "now be in an inconsistent state. " "We recommend re-formatting the " "disk before attempting to install " "%s on it."), disk_get_desc(storage_get_selected_disk(a->s)), OPERATING_SYSTEM_NAME); a->result = 0; return; } inform(a->c, _("The disk\n\n%s\n\nwas formatted."), disk_get_desc(storage_get_selected_disk(a->s))); a->result = 1; } else { inform(a->c, _("Action cancelled - no disks were formatted.")); a->result = 0; } }