/* corecmd.c - critical commands which are registered in kernel */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include /* set ENVVAR=VALUE */ static VasEBoot_err_t VasEBoot_core_cmd_set (struct VasEBoot_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { char *var; char *val; if (argc < 1) { struct VasEBoot_env_var *env; FOR_SORTED_ENV (env) { val = (char *) VasEBoot_env_get (env->name); VasEBoot_printf ("%s='%s'\n", env->name, val == NULL ? "" : val); } return 0; } var = argv[0]; val = VasEBoot_strchr (var, '='); if (! val) return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, "not an assignment"); val[0] = 0; VasEBoot_env_set (var, val + 1); val[0] = '='; return 0; } static VasEBoot_err_t VasEBoot_core_cmd_unset (struct VasEBoot_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { if (argc < 1) return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("one argument expected")); VasEBoot_env_unset (argv[0]); return 0; } /* insmod MODULE */ static VasEBoot_err_t VasEBoot_core_cmd_insmod (struct VasEBoot_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { VasEBoot_dl_t mod; if (argc == 0) return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("one argument expected")); if (argv[0][0] == '/' || argv[0][0] == '(' || argv[0][0] == '+') mod = VasEBoot_dl_load_file (argv[0]); else mod = VasEBoot_dl_load (argv[0]); if (mod) VasEBoot_dl_ref (mod); return 0; } static int VasEBoot_mini_print_devices (const char *name, void *data __attribute__ ((unused))) { VasEBoot_printf ("(%s) ", name); return 0; } static int VasEBoot_mini_print_files (const char *filename, const struct VasEBoot_dirhook_info *info, void *data __attribute__ ((unused))) { VasEBoot_printf ("%s%s ", filename, info->dir ? "/" : ""); return 0; } /* ls [ARG] */ static VasEBoot_err_t VasEBoot_core_cmd_ls (struct VasEBoot_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { if (argc < 1) { VasEBoot_device_iterate (VasEBoot_mini_print_devices, NULL); VasEBoot_xputs ("\n"); VasEBoot_refresh (); } else { char *device_name; VasEBoot_device_t dev = 0; VasEBoot_fs_t fs; char *path; device_name = VasEBoot_file_get_device_name (argv[0]); if (VasEBoot_errno) goto fail; dev = VasEBoot_device_open (device_name); if (! dev) goto fail; fs = VasEBoot_fs_probe (dev); path = VasEBoot_strchr (argv[0], ')'); if (! path) path = argv[0]; else path++; if (! *path && ! device_name) { VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, "invalid argument"); goto fail; } if (! *path) { if (VasEBoot_errno == VAS_EBOOT_ERR_UNKNOWN_FS) VasEBoot_errno = VAS_EBOOT_ERR_NONE; VasEBoot_printf ("(%s): Filesystem is %s.\n", device_name, fs ? fs->name : "unknown"); } else if (fs) { (fs->fs_dir) (dev, path, VasEBoot_mini_print_files, NULL); VasEBoot_xputs ("\n"); VasEBoot_refresh (); } fail: if (dev) VasEBoot_device_close (dev); VasEBoot_free (device_name); } return VasEBoot_errno; } void VasEBoot_register_core_commands (void) { VasEBoot_command_t cmd; cmd = VasEBoot_register_command ("set", VasEBoot_core_cmd_set, N_("[ENVVAR=VALUE]"), N_("Set an environment variable.")); if (cmd) cmd->flags |= VAS_EBOOT_COMMAND_FLAG_EXTRACTOR; VasEBoot_register_command ("unset", VasEBoot_core_cmd_unset, N_("ENVVAR"), N_("Remove an environment variable.")); VasEBoot_register_command ("ls", VasEBoot_core_cmd_ls, N_("[ARG]"), N_("List devices or files.")); VasEBoot_register_command ("insmod", VasEBoot_core_cmd_insmod, N_("MODULE"), N_("Insert a module.")); }