grub/util/grub-editenv.c

299 lines
7.3 KiB
C
Raw Normal View History

/* grub-editenv.c - tool to edit environment block. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
2010-05-06 06:04:04 +00:00
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/lib/envblk.h>
#include <grub/i18n.h>
#include <grub/emu/hostfile.h>
#include <grub/util/install.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
2013-12-21 17:08:25 +00:00
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#include <argp.h>
2013-12-21 17:08:25 +00:00
#pragma GCC diagnostic error "-Wmissing-prototypes"
#pragma GCC diagnostic error "-Wmissing-declarations"
#include "progname.h"
#define DEFAULT_ENVBLK_PATH DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG
static struct argp_option options[] = {
{0, 0, 0, OPTION_DOC, N_("Commands:"), 1},
{"create", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
N_("Create a blank environment block file."), 0},
{"list", 0, 0, OPTION_DOC|OPTION_NO_USAGE,
N_("List the current variables."), 0},
/* TRANSLATORS: "set" is a keyword. It's a summary of "set" subcommand. */
{N_("set [NAME=VALUE ...]"), 0, 0, OPTION_DOC|OPTION_NO_USAGE,
N_("Set variables."), 0},
/* TRANSLATORS: "unset" is a keyword. It's a summary of "unset" subcommand. */
{N_("unset [NAME ...]"), 0, 0, OPTION_DOC|OPTION_NO_USAGE,
N_("Delete variables."), 0},
{0, 0, 0, OPTION_DOC, N_("Options:"), -1},
Clarify and unify messages. * grub-core/commands/hashsum.c (options): Unify messages. * grub-core/commands/keystatus.c (GRUB_MOD_INIT): Don't mark a literal-only message as translatable. * grub-core/commands/lsacpi.c (GRUB_MOD_INIT): Likewise. * grub-core/loader/ia64/efi/linux.c (GRUB_MOD_INIT): Likewise. * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Add quoting around commands. * grub-core/commands/menuentry.c (options): Clarify that it's a keyboard key, not the key used to unlock. Clarify what it's used for. * grub-core/kern/emu/hostdisk.c (read_device_map): Unify error message. * grub-core/loader/xnu.c (grub_xnu_load_driver): Remove erroneous colon. * grub-core/script/main.c (GRUB_MOD_INIT): Clarify [n] to be [NUM]. * util/grub-editenv.c (options): Unify "verbose" message. * util/grub-fstest.c (read_file): Unify error message. (fstest): Add quotes around commands. (options): Unify "verbose" message. * util/grub-install.in: Add quotes around variable name. * util/grub-kbdcomp.in: Unify error message. * util/grub-mkfont.c (main): Likewise. * util/grub-mkrescue.in: Likewise. * util/grub-mklayout.c (options): Unify "verbose" message. * util/grub-mkstandalone.in: Unify help and verbose messages. * util/grub-mount.c (options): Unify "verbose" message. * util/grub-probe.c (options): Likewise. * util/grub-script-check.c (options): Likewise. * util/grub-setup.c (setup): Unify no-terminator message. (options): Use DEVICE and not DEV. Unify "verbose" message. * util/ieee1275/ofpath.c (xrealpath): Unify error message.
2012-02-05 10:23:47 +00:00
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
{ 0, 0, 0, 0, 0, 0 }
};
/* Print the version information. */
static void
print_version (FILE *stream, struct argp_state *state)
{
fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
}
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
/* Set the bug report address */
const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
static error_t argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'v':
verbosity++;
break;
case ARGP_KEY_NO_ARGS:
fprintf (stderr, "%s",
_("You need to specify at least one command.\n"));
argp_usage (state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
2013-12-21 14:28:28 +00:00
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static char *
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
{
switch (key)
{
case ARGP_KEY_HELP_POST_DOC:
return xasprintf (text, DEFAULT_ENVBLK_PATH, DEFAULT_ENVBLK_PATH);
default:
return (char *) text;
}
}
2013-12-21 14:28:28 +00:00
#pragma GCC diagnostic error "-Wformat-nonliteral"
struct argp argp = {
options, argp_parser, N_("FILENAME COMMAND"),
"\n"N_("\
Tool to edit environment block.")
"\v"N_("\
If FILENAME is `-', the default value %s is used.\n\n\
There is no `delete' command; if you want to delete the whole environment\n\
block, use `rm %s'."),
NULL, help_filter, NULL
};
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
static grub_envblk_t
open_envblk_file (const char *name)
{
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
FILE *fp;
char *buf;
size_t size;
grub_envblk_t envblk;
2009-06-10 21:04:23 +00:00
fp = grub_util_fopen (name, "rb");
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (! fp)
{
/* Create the file implicitly. */
grub_util_create_envblk_file (name);
fp = grub_util_fopen (name, "rb");
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (! fp)
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
grub_util_error (_("cannot open `%s': %s"), name,
strerror (errno));
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
}
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (fseek (fp, 0, SEEK_END) < 0)
grub_util_error (_("cannot seek `%s': %s"), name,
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
strerror (errno));
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
size = (size_t) ftell (fp);
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (fseek (fp, 0, SEEK_SET) < 0)
grub_util_error (_("cannot seek `%s': %s"), name,
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
strerror (errno));
buf = xmalloc (size);
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (fread (buf, 1, size, fp) != size)
grub_util_error (_("cannot read `%s': %s"), name,
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
strerror (errno));
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
fclose (fp);
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
envblk = grub_envblk_open (buf, size);
if (! envblk)
grub_util_error ("%s", _("invalid environment block"));
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
return envblk;
}
static int
print_var (const char *varname, const char *value,
void *hook_data __attribute__ ((unused)))
{
printf ("%s=%s\n", varname, value);
return 0;
}
static void
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
list_variables (const char *name)
{
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
grub_envblk_t envblk;
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
envblk = open_envblk_file (name);
grub_envblk_iterate (envblk, NULL, print_var);
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
grub_envblk_close (envblk);
}
static void
write_envblk (const char *name, grub_envblk_t envblk)
{
FILE *fp;
2009-06-10 21:04:23 +00:00
fp = grub_util_fopen (name, "wb");
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (! fp)
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
grub_util_error (_("cannot open `%s': %s"), name,
strerror (errno));
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (fwrite (grub_envblk_buffer (envblk), 1, grub_envblk_size (envblk), fp)
!= grub_envblk_size (envblk))
grub_util_error (_("cannot write to `%s': %s"), name,
Improve and unify messages. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument name. All users updated. Print filename in error. (read_device_map): Print filename in error. * util/getroot.c (grub_guess_root_devices): Print filename in error. (grub_util_get_os_disk): Likewise. (grub_util_biosdisk_get_grub_dev): Likewise. (grub_util_check_block_device): Likewise. (grub_util_check_char_device): Likewise. (grub_make_system_path_relative_to_its_root): Likewise. * util/grub-editenv.c (create_envblk_file): Likewise. (open_envblk_file): Likewise. (write_envblk): Likewise. * util/grub-fstest.c (cmd_cp): Likewise. (cmd_cat): Likewise. (cmd_cmp): Likewise. * util/grub-menulst2cfg.c (main): Likewise. * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise. (write_font_width_spec): Likewise. (write_font_pf2): Likewise. * util/grub-mkimage.c (generate_image): New argument outname. All users updated. Remove unreacheable message. (options): Unify messages. (help_filter): Likewise. * util/grub-mklayout.c (usage): Removed (unused). (main): Print filename in error. * util/grub-mkrescue.in: Fix wrong quoting. * util/grub-setup.c (setup): Print filename in error. * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise. (check_sas): Likewise. * util/misc.c (grub_util_get_fp_size): Removed. (grub_util_get_image_size): Print filename in error. (grub_util_read_at): Removed. (grub_util_read_image): Print filename in error. (grub_util_load_image): Likewise. (grub_util_write_image_at): New argument filename. All users updated. Print filename in error. (grub_util_write_image): New argument filename. All users updated. Print filename in error. * util/raid.c (grub_util_raid_getmembers): Print filename in error. * util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 10:07:33 +00:00
strerror (errno));
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
grub_util_file_sync (fp);
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
fclose (fp);
}
static void
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
set_variables (const char *name, int argc, char *argv[])
{
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
grub_envblk_t envblk;
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
envblk = open_envblk_file (name);
while (argc)
{
char *p;
p = strchr (argv[0], '=');
if (! p)
grub_util_error (_("invalid parameter %s"), argv[0]);
*(p++) = 0;
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (! grub_envblk_set (envblk, argv[0], p))
grub_util_error ("%s", _("environment block too small"));
argc--;
argv++;
}
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
write_envblk (name, envblk);
grub_envblk_close (envblk);
}
static void
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
unset_variables (const char *name, int argc, char *argv[])
{
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
grub_envblk_t envblk;
2009-06-10 21:04:23 +00:00
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
envblk = open_envblk_file (name);
while (argc)
{
grub_envblk_delete (envblk, argv[0]);
argc--;
argv++;
}
write_envblk (name, envblk);
grub_envblk_close (envblk);
}
int
main (int argc, char *argv[])
{
const char *filename;
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
char *command;
int curindex, arg_count;
2009-06-10 21:04:23 +00:00
grub_util_host_init (&argc, &argv);
/* Parse our arguments */
if (argp_parse (&argp, argc, argv, 0, &curindex, 0) != 0)
{
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
exit(1);
}
arg_count = argc - curindex;
if (arg_count == 1)
{
filename = DEFAULT_ENVBLK_PATH;
command = argv[curindex++];
}
else
{
filename = argv[curindex++];
if (strcmp (filename, "-") == 0)
filename = DEFAULT_ENVBLK_PATH;
command = argv[curindex++];
}
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
if (strcmp (command, "create") == 0)
grub_util_create_envblk_file (filename);
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
else if (strcmp (command, "list") == 0)
list_variables (filename);
else if (strcmp (command, "set") == 0)
set_variables (filename, argc - curindex, argv + curindex);
2009-03-29 Yoshinori K. Okuji <okuji@enbug.org> Make the format of Environment Block plain text. The boot loader part is not tested well yet. * util/grub-editenv.c (DEFAULT_ENVBLK_SIZE): New macro. (buffer): Removed. (envblk): Likewise. (usage): Remove "info" and "clear". Add "unset". Update the description of "set", as this does not delete variables any longer. (create_envblk_file): Complete rewrite. (open_envblk_file): Likewise. (cmd_info): Removed. (cmd_list): Likewise. (cmd_set): Likewise. (cmd_clear): Likewise. (list_variables): New function. (write_envblk): Likewise. (set_variables): Likewise. (unset_variables): Likewise. (main): Complete rewrite. * commands/loadenv.c (buffer): Removed. (envblk): Likewise. (open_envblk_file): New function. (read_envblk_file): Complete rewrite. (grub_cmd_load_env): Likewise. (grub_cmd_list_env): Likewise. (struct blocklist): New struct. (free_blocklists): New function. (check_blocklists): Likewise. (write_blocklists): Likewise. (grub_cmd_save_env): Complete rewrite. * include/grub/lib/envblk.h (GRUB_ENVBLK_SIGNATURE): Replaced with a plain text signature. (GRUB_ENVBLK_MAXLEN): Removed. (struct grub_envblk): Complete rewrite. (grub_envblk_find): Removed. (grub_envblk_insert): Likewise. (grub_envblk_open): New prototype. (grub_envblk_set): Likewise. (grub_envblk_delete): Put const to VALUE. (grub_envblk_iterate): Put const to NAME and VALUE. (grub_envblk_close): New prototype. (grub_envblk_buffer): New inline function. (grub_envblk_size): Likewise. * lib/envblk.c: Include grub/mm.h. (grub_env_find): Removed. (grub_envblk_open): New function. (grub_envblk_close): Likewise. (escaped_value_len): Likewise. (find_next_line): Likewise. (grub_envblk_insert): Removed. (grub_envblk_set): New function. (grub_envblk_delete): Complete rewrite. (grub_envblk_iterate): Likewise.
2009-03-28 19:58:15 +00:00
else if (strcmp (command, "unset") == 0)
unset_variables (filename, argc - curindex, argv + curindex);
else
{
char *program = xstrdup(program_name);
fprintf (stderr, _("Unknown command `%s'.\n"), command);
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
free(program);
exit(1);
}
return 0;
}