diff options
Diffstat (limited to 'com32/lua/src')
-rw-r--r-- | com32/lua/src/cpu.c | 4 | ||||
-rw-r--r-- | com32/lua/src/dmi.c | 624 | ||||
-rw-r--r-- | com32/lua/src/liolib.c | 40 | ||||
-rw-r--r-- | com32/lua/src/syslinux.c | 33 |
4 files changed, 482 insertions, 219 deletions
diff --git a/com32/lua/src/cpu.c b/com32/lua/src/cpu.c index 8a246e3d..6ef4e5a3 100644 --- a/com32/lua/src/cpu.c +++ b/com32/lua/src/cpu.c @@ -9,13 +9,13 @@ #include"lualib.h" #include"cpuid.h" -static void add_string_item(lua_State *L, const char *item, const char *value_str) { +void add_string_item(lua_State *L, const char *item, const char *value_str) { lua_pushstring(L,item); lua_pushstring(L,value_str); lua_settable(L,-3); } -static void add_int_item(lua_State *L, const char *item, int value_int) { +void add_int_item(lua_State *L, const char *item, int value_int) { lua_pushstring(L,item); lua_pushnumber(L,value_int); lua_settable(L,-3); diff --git a/com32/lua/src/dmi.c b/com32/lua/src/dmi.c index c8329d33..984fb60c 100644 --- a/com32/lua/src/dmi.c +++ b/com32/lua/src/dmi.c @@ -9,275 +9,487 @@ #include "lualib.h" #include "dmi/dmi.h" -static int dmi_gettable(lua_State *L) +extern void add_string_item(lua_State*, const char*, const char*); +extern void add_int_item(lua_State*, const char*, int); +typedef int (*table_fn)(lua_State*, s_dmi*); + +/* Add a Lua_String entry to the table on stack + xxx_P is the poiter version (i.e., pBase is a pointer) + xxx_S is the staic version (i.e., Base is the struct) +*/ +#define LUA_ADD_STR_P(pLua_state, pBase, Field) \ + add_string_item(pLua_state, #Field, pBase->Field); +#define LUA_ADD_STR_S(pLua_state, Base, Field) \ + add_string_item(pLua_state, #Field, Base.Field); + +/* Add a Lua_Number entry to the table on stack + xxx_P is the poiter version (i.e., pBase is a pointer) + xxx_S is the staic version (i.e., Base is the struct) +*/ +#define LUA_ADD_NUM_P(pLua_state, pBase, Field) \ + add_int_item(pLua_state, #Field, pBase->Field); +#define LUA_ADD_NUM_S(pLua_state, Base, Field) \ + add_int_item(pLua_state, #Field, Base.Field); + +/* Add a sub-DMI table to the table on stack + All (*table_fn)() have to be named as get_<tabel_name>_table() for this + macro to work. For example, for the bios subtable, the table_fn is + get_bios_table() and the subtable name is "bios". + All (*table_fn)() have to return 1 if a subtable is created on the stack + or 0 if the subtable is not created (no corresponding dim subtable found). +*/ +#define LUA_ADD_TABLE(pLua_state, pDmi, tb_name) \ + add_dmi_sub_table(pLua_state, pDmi, #tb_name, get_ ## tb_name ## _table); + + +static void add_dmi_sub_table(lua_State *L, s_dmi *dmi_ptr, char *table_name, + table_fn get_table_fn) { - s_dmi dmi; - - lua_newtable(L); - - if ( ! dmi_iterate(&dmi) ) { - printf("No DMI Structure found\n"); - return -1; + if (get_table_fn(L, dmi_ptr)) { /* only adding it when it is there */ + lua_pushstring(L, table_name); + lua_insert(L, -2); + lua_settable(L,-3); } +} - parse_dmitable(&dmi); - - /* bios */ - lua_pushstring(L, "bios.vendor"); - lua_pushstring(L, dmi.bios.vendor); - lua_settable(L,-3); - - lua_pushstring(L, "bios.version"); - lua_pushstring(L, dmi.bios.version); - lua_settable(L,-3); - - lua_pushstring(L, "bios.release_date"); - lua_pushstring(L, dmi.bios.release_date); - lua_settable(L,-3); - lua_pushstring(L, "bios.bios_revision"); - lua_pushstring(L, dmi.bios.bios_revision); - lua_settable(L,-3); +void get_bool_table(lua_State *L, const char *str_table[], int n_elem, + bool *bool_table) +{ + int i; + for (i = 0; i < n_elem; i++) { + if (!str_table[i] || !*str_table[i]) /* aviod NULL/empty string */ + continue; + + lua_pushstring(L, str_table[i]); + lua_pushboolean(L, bool_table[i]); + lua_settable(L,-3); + } +} - lua_pushstring(L, "bios.firmware_revision"); - lua_pushstring(L, dmi.bios.firmware_revision); - lua_settable(L,-3); - lua_pushstring(L, "bios.address"); - lua_pushnumber(L, dmi.bios.address); - lua_settable(L,-3); +/* +** {====================================================== +** DMI subtables +** ======================================================= +*/ +static int get_bios_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_bios *bios = &dmi_ptr->bios; - lua_pushstring(L, "bios.runtime_size"); - lua_pushnumber(L, dmi.bios.runtime_size); + if (!bios->filled) + return 0; + /* bios */ + lua_newtable(L); + LUA_ADD_STR_P(L, bios, vendor) + LUA_ADD_STR_P(L, bios, version) + LUA_ADD_STR_P(L, bios, release_date) + LUA_ADD_STR_P(L, bios, bios_revision) + LUA_ADD_STR_P(L, bios, firmware_revision) + LUA_ADD_NUM_P(L, bios, address) + LUA_ADD_NUM_P(L, bios, runtime_size) + LUA_ADD_STR_P(L, bios, runtime_size_unit) + LUA_ADD_NUM_P(L, bios, rom_size) + LUA_ADD_STR_P(L, bios, rom_size_unit) + + /* bios characteristics */ + lua_pushstring(L, "chars"); + lua_newtable(L); + get_bool_table(L, bios_charac_strings, + sizeof(s_characteristics)/sizeof(bool), + (bool *)(&bios->characteristics)); + get_bool_table(L, bios_charac_x1_strings, + sizeof(s_characteristics_x1)/sizeof(bool), + (bool *)(&bios->characteristics_x1)); + get_bool_table(L, bios_charac_x2_strings, + sizeof(s_characteristics_x2)/sizeof(bool), + (bool *)(&bios->characteristics_x2)); lua_settable(L,-3); - lua_pushstring(L, "bios.runtime_size_unit"); - lua_pushstring(L, dmi.bios.runtime_size_unit); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "bios.rom_size"); - lua_pushnumber(L, dmi.bios.rom_size); - lua_settable(L,-3); - lua_pushstring(L, "bios.rom_size_unit"); - lua_pushstring(L, dmi.bios.rom_size_unit); - lua_settable(L,-3); +static int get_system_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_system *system = &dmi_ptr->system; + if (!system->filled) + return 0; /* system */ - lua_pushstring(L, "system.manufacturer"); - lua_pushstring(L, dmi.system.manufacturer); - lua_settable(L,-3); - - lua_pushstring(L, "system.product_name"); - lua_pushstring(L, dmi.system.product_name); - lua_settable(L,-3); - - lua_pushstring(L, "system.version"); - lua_pushstring(L, dmi.system.version); - lua_settable(L,-3); - - lua_pushstring(L, "system.serial"); - lua_pushstring(L, dmi.system.serial); - lua_settable(L,-3); - - lua_pushstring(L, "system.uuid"); - lua_pushstring(L, dmi.system.uuid); - lua_settable(L,-3); + lua_newtable(L); + LUA_ADD_STR_P(L, system, manufacturer) + LUA_ADD_STR_P(L, system, product_name) + LUA_ADD_STR_P(L, system, version) + LUA_ADD_STR_P(L, system, serial) + LUA_ADD_STR_P(L, system, uuid) + LUA_ADD_STR_P(L, system, wakeup_type) + LUA_ADD_STR_P(L, system, sku_number) + LUA_ADD_STR_P(L, system, family) + LUA_ADD_STR_P(L, system, system_boot_status) + LUA_ADD_STR_P(L, system, configuration_options) + + /* system reset */ + if (system->system_reset.filled) { + lua_pushstring(L, "reset"); + lua_newtable(L); + LUA_ADD_NUM_S(L, system->system_reset, status) + LUA_ADD_NUM_S(L, system->system_reset, watchdog) + LUA_ADD_STR_S(L, system->system_reset, boot_option) + LUA_ADD_STR_S(L, system->system_reset, boot_option_on_limit) + LUA_ADD_STR_S(L, system->system_reset, reset_count) + LUA_ADD_STR_S(L, system->system_reset, reset_limit) + LUA_ADD_STR_S(L, system->system_reset, timer_interval) + LUA_ADD_STR_S(L, system->system_reset, timeout) + lua_settable(L,-3); + } - lua_pushstring(L, "system.wakeup_type"); - lua_pushstring(L, dmi.system.wakeup_type); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "system.sku_number"); - lua_pushstring(L, dmi.system.sku_number); - lua_settable(L,-3); - lua_pushstring(L, "system.family"); - lua_pushstring(L, dmi.system.family); - lua_settable(L,-3); +static int get_base_board_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_base_board *base_board = &dmi_ptr->base_board; + int n_dev = sizeof(base_board->devices_information) / + sizeof(base_board->devices_information[0]); + int i, j, has_dev; + if (!base_board->filled) + return 0; /* base_board */ - lua_pushstring(L, "base_board.manufacturer"); - lua_pushstring(L, dmi.base_board.manufacturer); - lua_settable(L,-3); - - lua_pushstring(L, "base_board.product_name"); - lua_pushstring(L, dmi.base_board.product_name); - lua_settable(L,-3); + lua_newtable(L); + LUA_ADD_STR_P(L, base_board, manufacturer) + LUA_ADD_STR_P(L, base_board, product_name) + LUA_ADD_STR_P(L, base_board, version) + LUA_ADD_STR_P(L, base_board, serial) + LUA_ADD_STR_P(L, base_board, asset_tag) + LUA_ADD_STR_P(L, base_board, location) + LUA_ADD_STR_P(L, base_board, type) + + /* base board features */ + lua_pushstring(L, "features"); + lua_newtable(L); + get_bool_table(L, base_board_features_strings, + sizeof(s_base_board_features)/sizeof(bool), + (bool *)(&base_board->features)); + lua_settable(L,-3); + + /* on-board devices */ + for (has_dev = 0, i = 0; i < n_dev; i++) + if (*base_board->devices_information[i].type) + has_dev++; + + if (has_dev) { + lua_pushstring(L, "devices"); + lua_newtable(L); + for (i = 0, j = 1; i < n_dev; i++) { + if (!*base_board->devices_information[i].type) /* empty device */ + continue; + + lua_pushinteger(L, j++); + lua_newtable(L); + LUA_ADD_STR_S(L, base_board->devices_information[i], type) + LUA_ADD_STR_S(L, base_board->devices_information[i], description) + LUA_ADD_NUM_S(L, base_board->devices_information[i], status) + lua_settable(L,-3); + } + lua_settable(L,-3); + } - lua_pushstring(L, "base_board.version"); - lua_pushstring(L, dmi.base_board.version); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "base_board.serial"); - lua_pushstring(L, dmi.base_board.serial); - lua_settable(L,-3); - lua_pushstring(L, "base_board.asset_tag"); - lua_pushstring(L, dmi.base_board.asset_tag); - lua_settable(L,-3); +static int get_chassis_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_chassis *chassis = &dmi_ptr->chassis; - lua_pushstring(L, "base_board.location"); - lua_pushstring(L, dmi.base_board.location); - lua_settable(L,-3); + if (!chassis->filled) + return 0; + /* chassis */ + lua_newtable(L); + LUA_ADD_STR_P(L, chassis, manufacturer) + LUA_ADD_STR_P(L, chassis, type) + LUA_ADD_STR_P(L, chassis, lock) + LUA_ADD_STR_P(L, chassis, version) + LUA_ADD_STR_P(L, chassis, serial) + LUA_ADD_STR_P(L, chassis, asset_tag) + LUA_ADD_STR_P(L, chassis, boot_up_state) + LUA_ADD_STR_P(L, chassis, power_supply_state) + LUA_ADD_STR_P(L, chassis, thermal_state) + LUA_ADD_STR_P(L, chassis, security_status) + LUA_ADD_STR_P(L, chassis, oem_information) + LUA_ADD_NUM_P(L, chassis, height) + LUA_ADD_NUM_P(L, chassis, nb_power_cords) - lua_pushstring(L, "base_board.type"); - lua_pushstring(L, dmi.base_board.type); - lua_settable(L,-3); + return 1; +} - /* chassis */ - lua_pushstring(L, "chassis.manufacturer"); - lua_pushstring(L, dmi.chassis.manufacturer); - lua_settable(L,-3); - lua_pushstring(L, "chassis.type"); - lua_pushstring(L, dmi.chassis.type); - lua_settable(L,-3); +static int get_processor_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_processor *processor = &dmi_ptr->processor; + s_signature *signature = &processor->signature; - lua_pushstring(L, "chassis.lock"); - lua_pushstring(L, dmi.chassis.lock); + if (!processor->filled) + return 0; + /* processor */ + lua_newtable(L); + LUA_ADD_STR_P(L, processor, socket_designation) + LUA_ADD_STR_P(L, processor, type) + LUA_ADD_STR_P(L, processor, family) + LUA_ADD_STR_P(L, processor, manufacturer) + LUA_ADD_STR_P(L, processor, version) + LUA_ADD_NUM_P(L, processor, external_clock) + LUA_ADD_NUM_P(L, processor, max_speed) + LUA_ADD_NUM_P(L, processor, current_speed) + LUA_ADD_NUM_P(L, processor, voltage_mv) + LUA_ADD_STR_P(L, processor, status) + LUA_ADD_STR_P(L, processor, upgrade) + LUA_ADD_STR_P(L, processor, cache1) + LUA_ADD_STR_P(L, processor, cache2) + LUA_ADD_STR_P(L, processor, cache3) + LUA_ADD_STR_P(L, processor, serial) + LUA_ADD_STR_P(L, processor, part_number) + LUA_ADD_STR_P(L, processor, id) + LUA_ADD_NUM_P(L, processor, core_count) + LUA_ADD_NUM_P(L, processor, core_enabled) + LUA_ADD_NUM_P(L, processor, thread_count) + + /* processor signature */ + lua_pushstring(L, "signature"); + lua_newtable(L); + LUA_ADD_NUM_P(L, signature, type) + LUA_ADD_NUM_P(L, signature, family) + LUA_ADD_NUM_P(L, signature, model) + LUA_ADD_NUM_P(L, signature, stepping) + LUA_ADD_NUM_P(L, signature, minor_stepping) lua_settable(L,-3); - lua_pushstring(L, "chassis.version"); - lua_pushstring(L, dmi.chassis.version); + /* processor flags */ + lua_pushstring(L, "flags"); + lua_newtable(L); + get_bool_table(L, cpu_flags_strings, + sizeof(s_dmi_cpu_flags)/sizeof(bool), + (bool *)(&processor->cpu_flags)); lua_settable(L,-3); - lua_pushstring(L, "chassis.serial"); - lua_pushstring(L, dmi.chassis.serial); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "chassis.asset_tag"); - lua_pushstring(L, dmi.chassis.asset_tag); - lua_settable(L,-3); - lua_pushstring(L, "chassis.boot_up_state"); - lua_pushstring(L, dmi.chassis.boot_up_state); - lua_settable(L,-3); +static int get_battery_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_battery *battery = &dmi_ptr->battery; - lua_pushstring(L, "chassis.power_supply_state"); - lua_pushstring(L, dmi.chassis.power_supply_state); - lua_settable(L,-3); + if (!battery->filled) + return 0; + /* battery */ + lua_newtable(L); + LUA_ADD_STR_P(L, battery, location) + LUA_ADD_STR_P(L, battery, manufacturer) + LUA_ADD_STR_P(L, battery, manufacture_date) + LUA_ADD_STR_P(L, battery, serial) + LUA_ADD_STR_P(L, battery, name) + LUA_ADD_STR_P(L, battery, chemistry) + LUA_ADD_STR_P(L, battery, design_capacity) + LUA_ADD_STR_P(L, battery, design_voltage) + LUA_ADD_STR_P(L, battery, sbds) + LUA_ADD_STR_P(L, battery, sbds_serial) + LUA_ADD_STR_P(L, battery, maximum_error) + LUA_ADD_STR_P(L, battery, sbds_manufacture_date) + LUA_ADD_STR_P(L, battery, sbds_chemistry) + LUA_ADD_STR_P(L, battery, oem_info) - lua_pushstring(L, "chassis.thermal_state"); - lua_pushstring(L, dmi.chassis.thermal_state); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "chassis.security_status"); - lua_pushstring(L, dmi.chassis.security_status); - lua_settable(L,-3); - lua_pushstring(L, "chassis.oem_information"); - lua_pushstring(L, dmi.chassis.oem_information); - lua_settable(L,-3); +static int get_memory_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_memory *memory = dmi_ptr->memory; + int i, j, n_mem = dmi_ptr->memory_count; - lua_pushstring(L, "chassis.height"); - lua_pushnumber(L, dmi.chassis.height); - lua_settable(L,-3); + if (n_mem <= 0) /* no memory info */ + return 0; - lua_pushstring(L, "chassis.nb_power_cords"); - lua_pushnumber(L, dmi.chassis.nb_power_cords); - lua_settable(L,-3); + /* memory */ + lua_newtable(L); + for (j = 1, i = 0; i < n_mem; i++) { + if (!memory[i].filled) + continue; + + lua_pushinteger(L, j++); + lua_newtable(L); + LUA_ADD_STR_S(L, memory[i], manufacturer) + LUA_ADD_STR_S(L, memory[i], error) + LUA_ADD_STR_S(L, memory[i], total_width) + LUA_ADD_STR_S(L, memory[i], data_width) + LUA_ADD_STR_S(L, memory[i], size) + LUA_ADD_STR_S(L, memory[i], form_factor) + LUA_ADD_STR_S(L, memory[i], device_set) + LUA_ADD_STR_S(L, memory[i], device_locator) + LUA_ADD_STR_S(L, memory[i], bank_locator) + LUA_ADD_STR_S(L, memory[i], type) + LUA_ADD_STR_S(L, memory[i], type_detail) + LUA_ADD_STR_S(L, memory[i], speed) + LUA_ADD_STR_S(L, memory[i], serial) + LUA_ADD_STR_S(L, memory[i], asset_tag) + LUA_ADD_STR_S(L, memory[i], part_number) + lua_settable(L,-3); + } + return 1; +} - /* processor */ - lua_pushstring(L, "processor.socket_designation"); - lua_pushstring(L, dmi.processor.socket_designation); - lua_settable(L,-3); - lua_pushstring(L, "processor.type"); - lua_pushstring(L, dmi.processor.type); - lua_settable(L,-3); +static int get_memory_module_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_memory_module *memory_module = dmi_ptr->memory_module; + int i, j, n_mem = dmi_ptr->memory_module_count; - lua_pushstring(L, "processor.family"); - lua_pushstring(L, dmi.processor.family); - lua_settable(L,-3); + if (n_mem <= 0) /* no memory module info */ + return 0; - lua_pushstring(L, "processor.manufacturer"); - lua_pushstring(L, dmi.processor.manufacturer); - lua_settable(L,-3); + /* memory module */ + lua_newtable(L); + for (j = 1, i = 0; i < n_mem; i++) { + if (!memory_module[i].filled) + continue; + + lua_pushinteger(L, j++); + lua_newtable(L); + LUA_ADD_STR_S(L, memory_module[i], socket_designation) + LUA_ADD_STR_S(L, memory_module[i], bank_connections) + LUA_ADD_STR_S(L, memory_module[i], speed) + LUA_ADD_STR_S(L, memory_module[i], type) + LUA_ADD_STR_S(L, memory_module[i], installed_size) + LUA_ADD_STR_S(L, memory_module[i], enabled_size) + LUA_ADD_STR_S(L, memory_module[i], error_status) + lua_settable(L,-3); + } + return 1; +} - lua_pushstring(L, "processor.version"); - lua_pushstring(L, dmi.processor.version); - lua_settable(L,-3); - lua_pushstring(L, "processor.external_clock"); - lua_pushnumber(L, dmi.processor.external_clock); - lua_settable(L,-3); +static int get_cache_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_cache *cache = dmi_ptr->cache; + int i, n_cache = dmi_ptr->cache_count; - lua_pushstring(L, "processor.max_speed"); - lua_pushnumber(L, dmi.processor.max_speed); - lua_settable(L,-3); + if (n_cache <= 0) /* no cache info */ + return 0; - lua_pushstring(L, "processor.current_speed"); - lua_pushnumber(L, dmi.processor.current_speed); - lua_settable(L,-3); + /* memory */ + lua_newtable(L); + for (i = 0; i < n_cache; i++) { + lua_pushinteger(L, i + 1); + lua_newtable(L); + LUA_ADD_STR_S(L, cache[i], socket_designation) + LUA_ADD_STR_S(L, cache[i], configuration) + LUA_ADD_STR_S(L, cache[i], mode) + LUA_ADD_STR_S(L, cache[i], location) + LUA_ADD_NUM_S(L, cache[i], installed_size) + LUA_ADD_NUM_S(L, cache[i], max_size) + LUA_ADD_STR_S(L, cache[i], supported_sram_types) + LUA_ADD_STR_S(L, cache[i], installed_sram_types) + LUA_ADD_NUM_S(L, cache[i], speed) + LUA_ADD_STR_S(L, cache[i], error_correction_type) + LUA_ADD_STR_S(L, cache[i], system_type) + LUA_ADD_STR_S(L, cache[i], associativity) + lua_settable(L,-3); + } + return 1; +} - lua_pushstring(L, "processor.signature.type"); - lua_pushnumber(L, dmi.processor.signature.type); - lua_settable(L,-3); - lua_pushstring(L, "processor.signature.family"); - lua_pushnumber(L, dmi.processor.signature.family); - lua_settable(L,-3); +static int get_hardware_security_table(lua_State *L, s_dmi *dmi_ptr) +{ + if (!dmi_ptr->hardware_security.filled) + return 0; + /* hardware_security */ + lua_newtable(L); + LUA_ADD_STR_S(L, dmi_ptr->hardware_security, power_on_passwd_status) + LUA_ADD_STR_S(L, dmi_ptr->hardware_security, keyboard_passwd_status) + LUA_ADD_STR_S(L, dmi_ptr->hardware_security, administrator_passwd_status) + LUA_ADD_STR_S(L, dmi_ptr->hardware_security, front_panel_reset_status) - lua_pushstring(L, "processor.signature.model"); - lua_pushnumber(L, dmi.processor.signature.model); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "processor.signature.stepping"); - lua_pushnumber(L, dmi.processor.signature.stepping); - lua_settable(L,-3); - lua_pushstring(L, "processor.signature.minor_stepping"); - lua_pushnumber(L, dmi.processor.signature.minor_stepping); - lua_settable(L,-3); +static int get_dmi_info_table(lua_State *L, s_dmi *dmi_ptr) +{ + dmi_table *dmitable = &dmi_ptr->dmitable; - lua_pushstring(L, "processor.voltage_mv"); - lua_pushnumber(L, dmi.processor.voltage_mv); - lua_settable(L,-3); + /* dmi info */ + lua_newtable(L); + LUA_ADD_NUM_P(L, dmitable, num) + LUA_ADD_NUM_P(L, dmitable, len) + LUA_ADD_NUM_P(L, dmitable, ver) + LUA_ADD_NUM_P(L, dmitable, base) + LUA_ADD_NUM_P(L, dmitable, major_version) + LUA_ADD_NUM_P(L, dmitable, minor_version) - lua_pushstring(L, "processor.status"); - lua_pushstring(L, dmi.processor.status); - lua_settable(L,-3); + return 1; +} - lua_pushstring(L, "processor.upgrade"); - lua_pushstring(L, dmi.processor.upgrade); - lua_settable(L,-3); - lua_pushstring(L, "processor.cache1"); - lua_pushstring(L, dmi.processor.cache1); - lua_settable(L,-3); +static int get_ipmi_table(lua_State *L, s_dmi *dmi_ptr) +{ + s_ipmi *ipmi = &dmi_ptr->ipmi; - lua_pushstring(L, "processor.cache2"); - lua_pushstring(L, dmi.processor.cache2); - lua_settable(L,-3); + if (!ipmi->filled) + return 0; + /* ipmi */ + lua_newtable(L); + LUA_ADD_STR_P(L, ipmi, interface_type) + LUA_ADD_NUM_P(L, ipmi, major_specification_version) + LUA_ADD_NUM_P(L, ipmi, minor_specification_version) + LUA_ADD_NUM_P(L, ipmi, I2C_slave_address) + LUA_ADD_NUM_P(L, ipmi, nv_address) + LUA_ADD_NUM_P(L, ipmi, base_address) + LUA_ADD_NUM_P(L, ipmi, irq) - lua_pushstring(L, "processor.cache3"); - lua_pushstring(L, dmi.processor.cache3); - lua_settable(L,-3); + return 1; +} +/* +** {====================================================== +** End of DMI subtables +** ======================================================= +*/ - lua_pushstring(L, "processor.serial"); - lua_pushstring(L, dmi.processor.serial); - lua_settable(L,-3); - lua_pushstring(L, "processor.part_number"); - lua_pushstring(L, dmi.processor.part_number); - lua_settable(L,-3); +static int dmi_gettable(lua_State *L) +{ + s_dmi dmi; - lua_pushstring(L, "processor.id"); - lua_pushstring(L, dmi.processor.id); - lua_settable(L,-3); + lua_newtable(L); - lua_pushstring(L, "processor.core_count"); - lua_pushnumber(L, dmi.processor.core_count); - lua_settable(L,-3); + if ( ! dmi_iterate(&dmi) ) { + printf("No DMI Structure found\n"); + return -1; + } - lua_pushstring(L, "processor.core_enabled"); - lua_pushnumber(L, dmi.processor.core_enabled); - lua_settable(L,-3); + parse_dmitable(&dmi); - lua_pushstring(L, "processor.thread_count"); - lua_pushnumber(L, dmi.processor.thread_count); - lua_settable(L,-3); + LUA_ADD_NUM_S(L, dmi, memory_module_count) + LUA_ADD_NUM_S(L, dmi, memory_count) + LUA_ADD_NUM_S(L, dmi, cache_count) + LUA_ADD_STR_S(L, dmi, oem_strings) + + LUA_ADD_TABLE(L, &dmi, bios) + LUA_ADD_TABLE(L, &dmi, system) + LUA_ADD_TABLE(L, &dmi, base_board) + LUA_ADD_TABLE(L, &dmi, chassis) + LUA_ADD_TABLE(L, &dmi, processor) + LUA_ADD_TABLE(L, &dmi, battery) + LUA_ADD_TABLE(L, &dmi, memory) + LUA_ADD_TABLE(L, &dmi, memory_module) + LUA_ADD_TABLE(L, &dmi, cache) + LUA_ADD_TABLE(L, &dmi, ipmi) + LUA_ADD_TABLE(L, &dmi, hardware_security) + LUA_ADD_TABLE(L, &dmi, dmi_info) /* set global variable: lua_setglobal(L, "dmitable"); */ diff --git a/com32/lua/src/liolib.c b/com32/lua/src/liolib.c index 3f27395d..cf9dca22 100644 --- a/com32/lua/src/liolib.c +++ b/com32/lua/src/liolib.c @@ -18,12 +18,18 @@ #include "lauxlib.h" #include "lualib.h" - +#ifdef SYSLINUX + #define NO_TMP_FILE 1 + #define NO_READ_NUMBER 1 + #define NO_TEST_EOF 1 + #define NO_CLEAR_ERR 1 + #define NO_F_SEEK 1 + #define NO_F_SETVBUF 1 +#endif #define IO_INPUT 1 #define IO_OUTPUT 2 - static const char *const fnames[] = {"input", "output"}; @@ -180,7 +186,7 @@ static int io_popen (lua_State *L) { } -#ifndef SYSLINUX +#ifndef NO_TMP_FILE static int io_tmpfile (lua_State *L) { FILE **pf = newfile(L); *pf = tmpfile(); @@ -271,7 +277,7 @@ static int io_lines (lua_State *L) { ** ======================================================= */ -#ifndef SYSLINUX +#ifndef NO_READ_NUMBER /* No fscanf() and thus no read_number() */ static int read_number (lua_State *L, FILE *f) { lua_Number d; if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { @@ -283,8 +289,9 @@ static int read_number (lua_State *L, FILE *f) { return 0; /* read fails */ } } +#endif - +#ifndef NO_TEST_EOF /* no buffering -> no ungetc() -> no EOF test */ static int test_eof (lua_State *L, FILE *f) { int c = getc(f); ungetc(c, f); @@ -315,7 +322,6 @@ static int read_line (lua_State *L, FILE *f) { } } -#ifndef SYSLINUX /* Not used */ static int read_chars (lua_State *L, FILE *f, size_t n) { size_t rlen; /* how much to read */ size_t nr; /* number of chars actually read */ @@ -337,7 +343,9 @@ static int g_read (lua_State *L, FILE *f, int first) { int nargs = lua_gettop(L) - 1; int success; int n; +#ifndef NO_CLEAR_ERR clearerr(f); +#endif if (nargs == 0) { /* no arguments? */ success = read_line(L, f); n = first+1; /* to return 1 result */ @@ -348,14 +356,22 @@ static int g_read (lua_State *L, FILE *f, int first) { for (n = first; nargs-- && success; n++) { if (lua_type(L, n) == LUA_TNUMBER) { size_t l = (size_t)lua_tointeger(L, n); +#ifndef NO_TEST_EOF success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); +#else /* we don't have test_eof defined */ + success = (l == 0) ? 1 : read_chars(L, f, l); +#endif } else { const char *p = lua_tostring(L, n); luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); switch (p[1]) { case 'n': /* number */ +#ifndef NO_READ_NUMBER success = read_number(L, f); +#else + return luaL_argerror(L, n, "\"*number\" not supported"); +#endif break; case 'l': /* line */ success = read_line(L, f); @@ -388,7 +404,6 @@ static int io_read (lua_State *L) { static int f_read (lua_State *L) { return g_read(L, tofile(L), 2); } -#endif static int io_readline (lua_State *L) { @@ -441,7 +456,7 @@ static int f_write (lua_State *L) { return g_write(L, tofile(L), 2); } -#ifndef SYSLINUX +#ifndef NO_F_SEEK static int f_seek (lua_State *L) { static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; static const char *const modenames[] = {"set", "cur", "end", NULL}; @@ -456,8 +471,9 @@ static int f_seek (lua_State *L) { return 1; } } +#endif - +#ifndef NO_F_SETVBUF static int f_setvbuf (lua_State *L) { static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; static const char *const modenames[] = {"no", "full", "line", NULL}; @@ -488,8 +504,8 @@ static const luaL_Reg iolib[] = { {"open", io_open}, {"output", io_output}, {"popen", io_popen}, -#ifndef SYSLINUX {"read", io_read}, +#ifndef NO_TMP_FILE {"tmpfile", io_tmpfile}, #endif {"type", io_type}, @@ -502,9 +518,11 @@ static const luaL_Reg flib[] = { {"close", io_close}, {"flush", f_flush}, {"lines", f_lines}, -#ifndef SYSLINUX {"read", f_read}, +#ifndef NO_F_SEEK {"seek", f_seek}, +#endif +#ifndef NO_F_SETVBUF {"setvbuf", f_setvbuf}, #endif {"write", f_write}, diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c index af5db834..afcdcaad 100644 --- a/com32/lua/src/syslinux.c +++ b/com32/lua/src/syslinux.c @@ -39,6 +39,7 @@ #include "syslinux/loadfile.h" #include "syslinux/linux.h" #include "syslinux/config.h" +#include "syslinux/reboot.h" int __parse_argv(char ***argv, const char *str); @@ -408,6 +409,35 @@ static int sl_boot_it(lua_State * L) initramfs, NULL, (char *)cmdline); } +static int sl_config_file(lua_State * L) +{ + const char *config_file = syslinux_config_file(); + lua_pushstring(L, config_file); + return 1; +} + +static int sl_reboot(lua_State * L) +{ + int warm_boot = luaL_optint(L, 1, 0); + /* explicitly convert it to 1 or 0 */ + warm_boot = warm_boot? 1 : 0; + syslinux_reboot(warm_boot); + return 0; +} + +static int sl_ipappend_strs(lua_State * L) +{ + int i; + const struct syslinux_ipappend_strings *ip_strs = syslinux_ipappend_strings(); + lua_newtable(L); + for (i = 0; i < ip_strs->count; i++) { + lua_pushinteger(L, i + 1); + lua_pushstring(L, ip_strs->ptr[i]); + lua_settable(L,-3); + } + return 1; +} + static int sl_derivative(lua_State * L) { const struct syslinux_version *sv; @@ -459,6 +489,9 @@ static const luaL_reg syslinuxlib[] = { {"initramfs_load_archive", sl_initramfs_load_archive}, {"initramfs_add_file", sl_initramfs_add_file}, {"boot_it", sl_boot_it}, + {"config_file", sl_config_file}, + {"ipappend_strs", sl_ipappend_strs}, + {"reboot", sl_reboot}, {"derivative", sl_derivative}, {"version", sl_version}, {NULL, NULL} |