/* * Ask the user which slice on a the selected disk they want. * Changes ss->selected_slice. */ void fn_select_slice(struct i_fn_args *a) { struct dfui_form *f; struct dfui_action *k; struct dfui_response *r; struct slice *s; char string[16]; f = dfui_form_create( "select_slice", _("Select Primary Partition"), a->short_desc, "", "p", "role", "menu", "p", "special", "dfinstaller_select_slice", NULL ); for (s = disk_slice_first(storage_get_selected_disk(a->s)); s != NULL; s = slice_next(s)) { snprintf(string, 16, "%d", slice_get_number(s)); dfui_form_action_add(f, string, dfui_info_new(slice_get_desc(s), "", "")); } 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 { s = slice_find(storage_get_selected_disk(a->s), atoi(dfui_response_get_action_id(r))); if (s == NULL) { inform(a->c, _("Internal error - response from frontend " "should be a valid slice number.")); a->result = 0; } else { storage_set_selected_slice(a->s, s); 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); } }
/* * 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; } } }
int format_slice(struct i_fn_args *a) { struct commands *cmds; struct command *cmd; int result; int cyl, hd, sec; cmds = commands_new(); /* * The information in a->s NEEDS to be accurate here! * Presumably we just did a survey_storage() recently. * XXX should we do another one here anyway just to be paranoid? */ /* * Set the slice's sysid to 165. */ disk_get_geometry(storage_get_selected_disk(a->s), &cyl, &hd, &sec); command_add(cmds, "%s%s 'g c%d h%d s%d' >%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), cyl, hd, sec, a->tmp); command_add(cmds, "%s%s 'p %d %d %lu %lu' >>%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), slice_get_number(storage_get_selected_slice(a->s)), 165, slice_get_start(storage_get_selected_slice(a->s)), slice_get_size(storage_get_selected_slice(a->s)), a->tmp); if (slice_get_flags(storage_get_selected_slice(a->s)) & 0x80) { command_add(cmds, "%s%s 'a %d' >>%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), slice_get_number(storage_get_selected_slice(a->s)), a->tmp); } command_add(cmds, "%s%s %snew.fdisk", a->os_root, cmd_name(a, "CAT"), a->tmp); temp_file_add(a, "new.fdisk"); /* * Execute the fdisk script. */ cmd = command_add(cmds, "%s%s -v -f %snew.fdisk %s", a->os_root, cmd_name(a, "FDISK"), a->tmp, disk_get_device_name(storage_get_selected_disk(a->s))); if (slice_get_size(storage_get_selected_slice(a->s)) == 0xFFFFFFFFU) command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE); /* * If there is an old 'virgin' disklabel hanging around * in the temp dir, get rid of it. This won't happen * from a real CD, but might happen with '-o' installs. */ command_add(cmds, "%s%s -f %sinstall.disklabel.%s", a->os_root, cmd_name(a, "RM"), a->tmp, slice_get_device_name(storage_get_selected_slice(a->s))); result = commands_execute(a, cmds); commands_free(cmds); return(result); }