Exemple #1
0
struct dfui_form *
dfui_decode_form(struct aura_buffer *e)
{
	char *id;
	struct dfui_info *i;
	struct dfui_form *f;

	if (!aura_buffer_expect(e, "F{")) return(NULL);

	id = dfui_decode_string(e);
	i = dfui_decode_info(e);
	
	f = dfui_form_new(id, i);

	dfui_form_set_multiple(f, dfui_decode_bool(e));
	dfui_form_set_extensible(f, dfui_decode_bool(e));

	f->field_head = dfui_decode_fields(e);
	f->action_head = dfui_decode_actions(e);
	f->dataset_head = dfui_decode_datasets(e);
	f->property_head = dfui_decode_properties(e);

	aura_buffer_expect(e, "}");
	free(id);

	return(f);
}
Exemple #2
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);
}
static struct dfui_form *
make_create_subpartitions_form(struct i_fn_args *a)
{
	struct dfui_form *f;
	char msg_buf[1][1024];

	snprintf(msg_buf[0], sizeof(msg_buf[0]),
	    _("Subpartitions further divide a primary partition for "
	    "use with %s.  Some reasons you may want "
	    "a set of subpartitions are:\n\n"
	    "- you want to restrict how much data can be written "
	    "to certain parts of the primary partition, to quell "
	    "denial-of-service attacks; and\n"
	    "- you want to speed up access to data on the disk."
	    ""), OPERATING_SYSTEM_NAME);

	f = dfui_form_create(
	    "create_subpartitions",
	    _("Create Subpartitions"),
	    _("Set up the subpartitions (also known as just `partitions' "
	    "in BSD tradition) you want to have on this primary "
	    "partition. In most cases you should be fine with "
	    "the default settings.\n\n"
	    "For Capacity, use 'M' to indicate megabytes, 'G' to "
	    "indicate gigabytes, and so on (up to 'E'.) A single '*' "
	    "indicates 'use the remaining space on the primary partition'."),

	    msg_buf[0],

	    "p", "special", "dfinstaller_create_subpartitions",
	    "p", "minimum_width","64",

	    "f", "mountpoint", _("Mountpoint"), "", "",
	    "f", "capacity", _("Capacity"), "", "",

	    "f", "encrypted", _("Encrypted"), "", "",
	    "p", "control", "checkbox",

	    "a", "ok", _("Accept and Create"), "", "",
	    "a", "cancel",
	    (disk_get_formatted(storage_get_selected_disk(a->s)) ?
	    _("Return to Select Disk") :
	    _("Return to Select Primary Partition")), "", "",
	    "p", "accelerator", "ESC",

	    NULL
	);

	dfui_form_set_multiple(f, 1);
	dfui_form_set_extensible(f, 1);
	/*
	 * Remove ATM until HAMMER installer support is better
	 * dfui_form_set_extensible(f, 1);
	 */
#if 0
	if (expert) {
		fi = dfui_form_field_add(f, "softupdates",
		    dfui_info_new(_("Softupdates"), "", ""));
		dfui_field_property_set(fi, "control", "checkbox");

		fi = dfui_form_field_add(f, "tmpfsbacked",
		    dfui_info_new(_("TMPFS"), "", ""));
		dfui_field_property_set(fi, "control", "checkbox");

		fi = dfui_form_field_add(f, "fsize",
		    dfui_info_new(_("Frag Sz"), "", ""));

		fi = dfui_form_field_add(f, "bsize",
		    dfui_info_new(_("Block Sz"), "", ""));

		dfui_form_action_add(f, "switch",
		    dfui_info_new(_("Switch to Normal Mode"), "", ""));
	} else {
		dfui_form_action_add(f, "switch",
		    dfui_info_new(_("Switch to Expert Mode"), "", ""));
	}
#endif
	return(f);
}
Exemple #4
0
static void
set_dfui_properties_from_lua_table(lua_State *L, int table_idx,
				   int dfui_obj_type, void *dfui_obj)
{
	const char *key, *value;

	/*
	 * Traverse the table, looking for key->value pairs that we can use
	 * to modify the field.
	 * For each entry, if it is standard (id, name, short_desc, long_desc)
	 * ignore it; if it is anything else, assume it is a property.
	 */
	lua_pushnil(L);
	while (lua_next(L, table_idx) != 0) {
		if (lua_isstring(L, -2) && lua_isstring(L, -1)) {
			key = lua_tostring(L, -2);
			value = lua_tostring(L, -1);

			if (strcmp(key, "id") == 0 ||
			    strcmp(key, "name") == 0 ||
			    strcmp(key, "short_desc") == 0 ||
			    strcmp(key, "long_desc") == 0) {
				/*
				 * Skip it, we've already done it.
				 */
			} else if (strcmp(key, "multiple") == 0 &&
			    dfui_obj_type == DFUI_OBJ_FORM) {
				dfui_form_set_multiple(
				    (struct dfui_form *)dfui_obj,
				    strcmp(value, "true") == 0
				);
			} else if (strcmp(key, "extensible") == 0 &&
			    dfui_obj_type == DFUI_OBJ_FORM) {
				dfui_form_set_extensible(
				    (struct dfui_form *)dfui_obj,
				    strcmp(value, "true") == 0
				);
			} else {
				/*
				 * It's a property.
				 */
				switch (dfui_obj_type) {
				case DFUI_OBJ_FORM:
					dfui_form_property_set(
					    (struct dfui_form *)dfui_obj,
					    key, value);
					break;
				case DFUI_OBJ_FIELD:
					dfui_field_property_set(
					    (struct dfui_field *)dfui_obj,
					    key, value);
					break;
				case DFUI_OBJ_ACTION:
					dfui_action_property_set(
					    (struct dfui_action *)dfui_obj,
					    key, value);
					break;
				}
			}
		} else if (lua_isstring(L, -2) && lua_istable(L, -1)) {
			key = lua_tostring(L, -2);
			if (strcmp(key, "options") == 0 &&
			    dfui_obj_type == DFUI_OBJ_FIELD) {
				dfui_field_options_from_lua_table(L,
				    (struct dfui_field *)dfui_obj
				);
			}
		} else {
			/*
			 * Either the key or the value is not a string,
			 * so just skip it.
			 */
		}

		/*
		 * Remove the value, but leave the key for the next iteration.
		 */
		lua_pop(L, 1);
	}
}