示例#1
0
/*
 * 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);
}
示例#2
0
/*
 * state_install_bootstrap: put boot0 bootblocks on selected disks.
 */
void
state_install_bootstrap(struct i_fn_args *a)
{
	char msg_buf[1][1024];

	snprintf(msg_buf[0], sizeof(msg_buf[0]),
	    _("You may now wish to install bootblocks on one or more disks. "
	    "If you already have a boot manager installed, you can skip "
	    "this step (but you may have to configure your boot manager "
	    "separately.)  If you installed %s on a disk other "
	    "than your first disk, you will need to put the bootblock "
	    "on at least your first disk and the %s disk."),
	    OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);

	a->short_desc = msg_buf[0];
	a->cancel_desc = _("Skip this Step");
	fn_install_bootblocks(a,
	    disk_get_device_name(storage_get_selected_disk(a->s)));
	state = state_finish_install;
}
示例#3
0
/*
 * 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);
	}
}
示例#4
0
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);
}
示例#5
0
void
fn_install_bootblocks(struct i_fn_args *a, const char *device)
{
	struct dfui_form *f;
	struct dfui_response *r;
	struct dfui_dataset *ds;
	struct disk *d;
	struct commands *cmds;
	struct command *cmd;
	char disk[64], boot0cfg[32], packet[32];
	char msg_buf[1][1024];

	snprintf(msg_buf[0], sizeof(msg_buf[0]),
	    "'Packet Mode' refers to using newer BIOS calls to boot "
	    "from a partition of the disk.  It is generally not "
	    "required unless:\n\n"
	    "- your BIOS does not support legacy mode; or\n"
	    "- your %s primary partition resides on a "
	    "cylinder of the disk beyond cylinder 1024; or\n"
	    "- you just can't get it to boot without it.",
	    OPERATING_SYSTEM_NAME);

	f = dfui_form_create(
	    "install_bootstrap",
	    _("Install Bootblock(s)"),
	    a->short_desc,

	    msg_buf[0],

	    "p", "special", "dfinstaller_install_bootstrap",

	    "f", "disk", _("Disk Drive"),
	    _("The disk on which you wish to install a bootblock"), "",
	    "p", "editable", "false",
	    "f", "boot0cfg", _("Install Bootblock?"),
	    _("Install a bootblock on this disk"), "",
	    "p", "control", "checkbox",
	    "f", "packet", _("Packet Mode?"),
	    _("Select this to use 'packet mode' to boot the disk"), "",
	    "p", "control", "checkbox",

	    "a", "ok", _("Accept and Install Bootblocks"), "", "",
	    "a", "cancel", a->cancel_desc, "", "",
	    "p", "accelerator", "ESC",

	    NULL
	);

	dfui_form_set_multiple(f, 1);

	if (device != NULL) {
		ds = dfui_dataset_new();
		dfui_dataset_celldata_add(ds, "disk", device);
		dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
		dfui_dataset_celldata_add(ds, "packet", "Y");
		dfui_form_dataset_add(f, ds);
	} else {
		for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) {
			ds = dfui_dataset_new();
			dfui_dataset_celldata_add(ds, "disk",
			    disk_get_device_name(d));
			dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
			dfui_dataset_celldata_add(ds, "packet", "Y");
			dfui_form_dataset_add(f, ds);
		}
	}

	if (!dfui_be_present(a->c, f, &r))
		abort_backend();

	a->result = 0;
	if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
		cmds = commands_new();

		for (ds = dfui_response_dataset_get_first(r); ds != NULL;
		     ds = dfui_dataset_get_next(ds)) {
			strlcpy(disk, dfui_dataset_get_value(ds, "disk"), 64);
			strlcpy(boot0cfg, dfui_dataset_get_value(ds, "boot0cfg"), 32);
			strlcpy(packet, dfui_dataset_get_value(ds, "packet"), 32);

			if (strcasecmp(boot0cfg, "Y") == 0) {
				cmd = command_add(cmds, "%s%s -B -o %spacket %s",
				    a->os_root, cmd_name(a, "BOOT0CFG"),
				    strcasecmp(packet, "Y") == 0 ? "" : "no",
				    disk);
				command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
				command_set_tag(cmd, "%s", disk);
				cmd = command_add(cmds, "%s%s -v %s",
				    a->os_root, cmd_name(a, "BOOT0CFG"),
				    disk);
				command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
				command_set_tag(cmd, "%s", disk);
			}
		}

		if (!commands_execute(a, cmds)) {
			ask_to_wipe_boot_sector(a, cmds);
		} else {
			inform(a->c, _("Bootblocks were successfully installed!"));
			a->result = 1;
		}
		commands_free(cmds);
	}

	dfui_form_free(f);
	dfui_response_free(r);
}
示例#6
0
/*
 * 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;
	}
}