grub/util/grub-editenv.c

323 lines
6.9 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>
#include <grub/util/misc.h>
#include <grub/lib/envblk.h>
2009-03-01 Bean <bean123ch@gmail.com> * commands/terminal.c: Removed. * commands/handler.c: New file. * include/grub/list.h: Likewise. * include/grub/handler.h: Likewise. * kern/list.c: Likewise. * kern/handler.c: Likewise. * kern/term.h: Include header file <grub/handler.h>. (grub_term_input): Move next field to the beginning. (grub_term_output): Likewise. (grub_term_input_class): New variable. (grub_term_output_class): Likewise. (grub_term_register_input): Changed to inline function. (grub_term_register_output): Likewise. (grub_term_unregister_input): Likewise. (grub_term_unregister_output): Likewise. (grub_term_set_current_input): Likewise. (grub_term_set_current_output): Likewise. (grub_term_get_current_input): Likewise. (grub_term_get_current_output): Likewise. (grub_term_iterate_input): Removed. (grub_term_iterate_output): Likewise. * kern/term.c (grub_term_list_input): Removed. (grub_term_list_output): Likewise. (grub_term_input_class): New variable. (grub_term_output_class): Likewise. (grub_cur_term_input): Change varaible as macro. (grub_cur_term_output): Likewise. (grub_term_register_input): Removed. (grub_term_register_output): Likewise. (grub_term_unregister_input): Likewise. (grub_term_unregister_output): Likewise. (grub_term_set_current_input): Likewise. (grub_term_set_current_output): Likewise. (grub_term_iterate_input): Likewise. (grub_term_iterate_output): Likewise. (grub_term_get_current_input): Likewise. (grub_term_get_current_output): Likewise. * util/grub-editenv.c: Include header file <grub/handler.h>. (grub_term_get_current_input): Removed. (grub_term_get_current_output): Likewise. (grub_term_input_class): New variable. (grub_term_outout_class): Likewise. * util/grub-fstest.c (grub_term_get_current_input): Removed. (grub_term_get_current_output): Likewise. (grub_term_input_class): New variable. (grub_term_outout_class): Likewise. * util/grub-probe.c (grub_term_get_current_input): Removed. (grub_term_get_current_output): Likewise. (grub_term_input_class): New variable. (grub_term_outout_class): Likewise. * util/i386/pc/grub-setup.c (grub_term_get_current_input): Removed. (grub_term_get_current_output): Likewise. (grub_term_input_class): New variable. (grub_term_outout_class): Likewise. * conf/common.rmk (pkglib_MODULES): Replace terminal with handler. (terminal_mod_SOURCES): Likewise. (terminal_mod_CFLAGS): Likewise. (terminal_mod_LDFLAGS): Likewise. * conf/i386-pc.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_img_SOURCES): Add list.c and handler.c. (kernel_img_HEADERS): Add list.h and handler.h. * conf/i386-efi.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_mod_SOURCES): Add list.c and handler.c. (kernel_mod_HEADERS): Add list.h and handler.h. * conf/i386-coreboot.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_elf_SOURCES): Add list.c and handler.c. (kernel_elf_HEADERS): Add list.h and handler.h. * conf/i386-ieee1275.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_elf_SOURCES): Add list.c and handler.c. (kernel_elf_HEADERS): Add list.h and handler.h. * conf/x86_64-efi.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_mod_SOURCES): Add list.c and handler.c. (kernel_mod_HEADERS): Add list.h and handler.h. * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Replace terminal.c with handler.c. (kernel_elf_SOURCES): Add list.c and handler.c. (kernel_elf_HEADERS): Add list.h and handler.h.
2009-03-01 17:51:44 +00:00
#include <grub/handler.h>
#include <grub/i18n.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include "progname.h"
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
#define DEFAULT_ENVBLK_SIZE 1024
void
grub_refresh (void)
{
fflush (stdout);
}
int
grub_getkey (void)
{
return 0;
}
2010-03-15 10:49:27 +00:00
void
grub_xputs_real (const char *str)
{
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
char *
grub_env_get (const char *name __attribute__ ((unused)))
{
return NULL;
}
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static void
usage (int status)
{
if (status)
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] [FILENAME] COMMAND\n\
\n\
Tool to edit environment block.\n\
\nCommands:\n\
create create a blank environment block file\n\
list list the current variables\n\
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 [name=value ...] set variables\n\
unset [name ....] delete variables\n\
\nOptions:\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
\n\
If not given explicitly, FILENAME defaults to %s.\n\
\n\
Report bugs to <%s>.\n",
program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
exit (status);
}
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 void
create_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;
char *namenew;
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
buf = malloc (DEFAULT_ENVBLK_SIZE);
if (! buf)
grub_util_error ("out of memory");
namenew = xasprintf ("%s.new", name);
fp = fopen (namenew, "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)
grub_util_error ("cannot open the file %s", namenew);
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
memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
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 (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
grub_util_error ("cannot write to the file %s", namenew);
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
fsync (fileno (fp));
free (buf);
fclose (fp);
if (rename (namenew, name) < 0)
grub_util_error ("cannot rename the file %s to %s", namenew, name);
free (namenew);
}
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
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
fp = fopen (name, "rb");
if (! fp)
{
/* Create the file implicitly. */
create_envblk_file (name);
fp = fopen (name, "rb");
if (! fp)
grub_util_error ("cannot open the file %s", 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
if (fseek (fp, 0, SEEK_END) < 0)
grub_util_error ("cannot seek the file %s", 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
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 the file %s", 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
buf = malloc (size);
if (! buf)
grub_util_error ("out of memory");
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 the file %s", 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
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 ("invalid environment block");
return 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
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
auto int print_var (const char *name, const char *value);
int print_var (const char *name, const char *value)
{
printf ("%s=%s\n", name, value);
return 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
envblk = open_envblk_file (name);
grub_envblk_iterate (envblk, print_var);
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
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
fp = fopen (name, "wb");
if (! fp)
grub_util_error ("cannot open the file %s", name);
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 the file %s", name);
fsync (fileno (fp));
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)
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_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 ("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[])
{
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 *filename;
char *command;
2009-06-10 21:04:23 +00:00
set_program_name (argv[0]);
grub_util_init_nls ();
2009-06-10 21:04:23 +00:00
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "hVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'h':
usage (0);
break;
case 'V':
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
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
/* Obtain the filename. */
if (optind >= argc)
{
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
fprintf (stderr, "no filename specified\n");
usage (1);
}
if (optind + 1 >= argc)
{
filename = DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG;
command = argv[optind];
}
else
{
filename = argv[optind];
command = argv[optind + 1];
}
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)
create_envblk_file (filename);
else if (strcmp (command, "list") == 0)
list_variables (filename);
else if (strcmp (command, "set") == 0)
set_variables (filename, argc - optind - 2, argv + optind + 2);
else if (strcmp (command, "unset") == 0)
unset_variables (filename, argc - optind - 2, argv + optind + 2);
else
{
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
fprintf (stderr, "unknown command %s\n", command);
usage (1);
}
return 0;
}