/* * Pop a Lua table representing a DFUI dataset from the Lua stack, * create a new DFUI dataset from it, and return it. */ static struct dfui_dataset * dfui_dataset_from_lua_table(lua_State *L, int table_idx) { struct dfui_dataset *ds; /* * Create the initial dataset. */ ds = dfui_dataset_new(); /* * Traverse the table, looking for key->value pairs that we can use. */ lua_pushnil(L); while (lua_next(L, table_idx) != 0) { if (lua_isstring(L, -2) && lua_isstring(L, -1)) { dfui_dataset_celldata_add(ds, lua_tostring(L, -2), lua_tostring(L, -1) ); } else { /* Bogus, just skip it */ } /* * Remove the value, but leave the key for the next iteration. */ lua_pop(L, 1); } /* * Remove the table. */ lua_pop(L, 1); return(ds); }
static struct dfui_response * response_construct_from_curses_form_single(const struct dfui_form *f, const struct curses_form *cf, const struct curses_widget *cw) { struct dfui_response *r = NULL; struct dfui_action *selected = NULL; struct dfui_dataset *ds = NULL; const char *id; const char *value; selected = cw->userdata; r = dfui_response_new(dfui_form_get_id(f), dfui_action_get_id(selected)); ds = dfui_dataset_new(); for (cw = cf->widget_head; cw != NULL; cw = cw->next) { if (cw->user_id > 0) { id = dfui_field_get_id((struct dfui_field *)cw->userdata); value = curses_widget_xlat_value(cw); dfui_dataset_celldata_add(ds, id, value); } } dfui_response_dataset_add(r, ds); return(r); }
static void populate_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a) { struct subpartition *sp; struct dfui_dataset *ds; int i; long capacity; if (slice_subpartition_first(storage_get_selected_slice(a->s)) != NULL) { /* * The user has already given us their subpartition * preferences, so use them here. */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { ds = dfui_dataset_new(); dfui_dataset_celldata_add(ds, "mountpoint", subpartition_get_mountpoint(sp)); dfui_dataset_celldata_add(ds, "capacity", capacity_to_string(subpartition_get_capacity(sp))); dfui_dataset_celldata_add(ds, "encrypted", subpartition_is_encrypted(sp) ? "Y" : "N"); dfui_form_dataset_add(f, ds); } } else { /* * Otherwise, populate the form with datasets representing * reasonably-calculated defaults. The defaults are chosen * based on the slice's total capacity and the machine's * total physical memory (for swap.) */ for (i = 0; def_mountpt[i] != NULL; i++) { capacity = default_capacity(a->s, def_mountpt[i]); ds = dfui_dataset_new(); dfui_dataset_celldata_add(ds, "mountpoint", def_mountpt[i]); dfui_dataset_celldata_add(ds, "capacity", capacity_to_string(capacity)); dfui_dataset_celldata_add(ds, "encrypted", "N"); dfui_form_dataset_add(f, ds); } } }
struct dfui_dataset * dfui_decode_dataset(struct aura_buffer *e) { struct dfui_dataset *ds; ds = dfui_dataset_new(); ds->celldata_head = dfui_decode_celldatas(e); return(ds); }
/* * XXX this should maybe be in libdfui. */ static struct dfui_dataset * create_default_dataset(const struct dfui_form *f) { struct dfui_dataset *ds; struct dfui_field *fi; ds = dfui_dataset_new(); for (fi = dfui_form_field_get_first(f); fi != NULL; fi = dfui_field_get_next(fi)) { dfui_dataset_celldata_add(ds, dfui_field_get_id(fi), ""); } return(ds); }
static struct dfui_response * response_construct_from_curses_form_multiple(const struct dfui_form *f, const struct curses_form *cf, const struct curses_widget *cw) { struct dfui_response *r = NULL; struct dfui_action *selected = NULL; struct dfui_dataset *ds = NULL; const char *id; const char *value; int row = 0; int rows = 100; /* XXX obviously we'd prefer something more efficient here! */ int cds_added = 0; selected = cw->userdata; r = dfui_response_new(dfui_form_get_id(f), dfui_action_get_id(selected)); /* Create one dataset per row. */ for (row = 1; row < rows; row++) { ds = dfui_dataset_new(); cds_added = 0; for (cw = cf->widget_head; cw != NULL; cw = cw->next) { if (cw->user_id == row && (cw->type == CURSES_TEXTBOX || cw->type == CURSES_CHECKBOX)) { id = dfui_field_get_id((struct dfui_field *)cw->userdata); value = curses_widget_xlat_value(cw); dfui_dataset_celldata_add(ds, id, value); cds_added += 1; } } if (cds_added > 0) { dfui_response_dataset_add(r, ds); } else { dfui_dataset_free(ds); } } return(r); }
void fn_memtest(struct i_fn_args *a) { struct dfui_form *f; struct dfui_response *r; struct dfui_dataset *ds, *new_ds; struct commands *cmds; struct command *cmd; const char *memtestsize; f = dfui_form_create( "memtest", _("Memory test"), _("Memory test - Enter the size in values such as 400M, 1G."), "", "f", "memtestsize", _("Memory test size"), _("Enter the amount of memory you would like to check:"), "", "a", "ok", _("OK"), "", "", "a", "cancel", _("Cancel Memory Test"), "", "", "p", "accelerator", "ESC", NULL ); ds = dfui_dataset_new(); dfui_dataset_celldata_add(ds, "memtestsize", ""); dfui_form_dataset_add(f, ds); if (!dfui_be_present(a->c, f, &r)) abort_backend(); if (strcmp(dfui_response_get_action_id(r), "ok") == 0) { new_ds = dfui_response_dataset_get_first(r); memtestsize = dfui_dataset_get_value(new_ds, "memtestsize"); cmds = commands_new(); cmd = command_add(cmds, "cd %s && %s%s %s 1 --log", a->tmp, a->os_root, cmd_name(a, "MEMTEST"), memtestsize); command_set_log_mode(cmd, COMMAND_LOG_QUIET); cmd = command_add(cmds, "%s%s -E -v '^Unable to malloc' %smemtest.log > %smemtest.log.new", a->os_root, cmd_name(a, "GREP"), a->tmp, a->tmp); cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log", a->os_root, cmd_name(a, "MV"), a->tmp, a->tmp); cmd = command_add(cmds, "%s%s -E -v '^Allocated.*failed' %smemtest.log > %smemtest.log.new", a->os_root, cmd_name(a, "GREP"), a->tmp, a->tmp); cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log", a->os_root, cmd_name(a, "MV"), a->tmp, a->tmp); if (commands_execute(a, cmds)) { commands_free(cmds); view_memtest_log(a); cmds = commands_new(); cmd = command_add(cmds, "%s%s -f %smemtest.log", a->os_root, cmd_name(a, "RM"), a->tmp); commands_execute(a, cmds); } else { inform(a->c, _("Memory test could not be run.")); } commands_free(cmds); } dfui_form_free(f); dfui_response_free(r); }
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); }