merge mainline into asprintf

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-20 07:36:17 +01:00
commit 2d49abe9e7
342 changed files with 14569 additions and 4699 deletions

125
util/bin2h.c Normal file
View file

@ -0,0 +1,125 @@
/*
* Copyright (C) 2008,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 <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE 1
#include <getopt.h>
#include "progname.h"
static struct option options[] =
{
{"help", no_argument, 0, 'h' },
{"version", 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] SYMBOL-NAME\n\
\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
\n\
Report bugs to <%s>.\n\
", program_name, PACKAGE_BUGREPORT);
exit (status);
}
int
main (int argc, char *argv[])
{
int b, i;
char *sym;
set_program_name (argv[0]);
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "snm:r: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;
default:
usage (1);
break;
}
}
if (optind >= argc)
usage (1);
if (optind + 1 != argc)
usage (1);
sym = argv[optind];
b = getchar ();
if (b == EOF)
goto abort;
printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALY GENERATED */\n"
"unsigned char %s[] =\n{\n", sym);
while (1)
{
printf ("0x%02x", b);
b = getchar ();
if (b == EOF)
goto end;
for (i = 0; i < 16 - 1; i++)
{
printf (", 0x%02x", b);
b = getchar ();
if (b == EOF)
goto end;
}
printf (",\n");
}
end:
printf ("\n};\n");
abort:
exit (0);
}

View file

@ -19,14 +19,6 @@
#include <config.h>
#if defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#elif defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
#endif
/* For compatibility. */
#ifndef A_NORMAL
# define A_NORMAL 0
@ -39,6 +31,14 @@
#include <grub/term.h>
#include <grub/types.h>
#if defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#elif defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
#endif
static int grub_console_attr = A_NORMAL;
grub_uint8_t grub_console_cur_color = 7;
@ -367,8 +367,7 @@ static struct grub_term_output grub_ncurses_term_output =
.setcolor = grub_ncurses_setcolor,
.getcolor = grub_ncurses_getcolor,
.setcursor = grub_ncurses_setcursor,
.refresh = grub_ncurses_refresh,
.flags = 0,
.refresh = grub_ncurses_refresh
};
void
@ -376,8 +375,6 @@ grub_console_init (void)
{
grub_term_register_output ("console", &grub_ncurses_term_output);
grub_term_register_input ("console", &grub_ncurses_term_input);
grub_term_set_current_output (&grub_ncurses_term_output);
grub_term_set_current_input (&grub_ncurses_term_input);
}
void

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2004,2005,2006,2007,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
@ -100,7 +100,7 @@ load_note (Elf32_Phdr *phdr, FILE *out)
void
load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
char *mods[], FILE *out, char *memdisk_path)
char *mods[], FILE *out, char *memdisk_path, char *config_path)
{
char *module_img;
struct grub_util_path_list *path_list;
@ -109,6 +109,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
size_t offset;
size_t total_module_size;
size_t memdisk_size = 0;
size_t config_size = 0;
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
@ -122,6 +123,13 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
total_module_size += memdisk_size + sizeof (struct grub_module_header);
}
if (config_path)
{
config_size = ALIGN_UP(grub_util_get_image_size (config_path), 512);
grub_util_info ("the size of memory disk is 0x%x", config_size);
total_module_size += config_size + sizeof (struct grub_module_header);
}
for (p = path_list; p; p = p->next)
{
total_module_size += (grub_util_get_image_size (p->name)
@ -168,6 +176,19 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
offset += memdisk_size;
}
if (config_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (module_img + offset);
header->type = OBJ_TYPE_CONFIG;
header->size = grub_host_to_target32 (config_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (config_path, module_img + offset);
offset += config_size;
}
/* Write the module data to the new segment. */
grub_util_write_image_at (module_img, total_module_size,
@ -184,7 +205,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
}
void
add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path)
add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path, char *config_path)
{
Elf32_Ehdr ehdr;
Elf32_Phdr *phdrs = NULL;
@ -273,7 +294,7 @@ add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *
phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out),
GRUB_TARGET_SIZEOF_LONG));
load_modules (modbase, phdr, dir, mods, out, memdisk_path);
load_modules (modbase, phdr, dir, mods, out, memdisk_path, config_path);
}
if (chrp)
@ -316,6 +337,7 @@ static struct option options[] =
{"directory", required_argument, 0, 'd'},
{"prefix", required_argument, 0, 'p'},
{"memdisk", required_argument, 0, 'm'},
{"config", required_argument, 0, 'c'},
{"output", required_argument, 0, 'o'},
{"help", no_argument, 0, 'h'},
{"note", no_argument, 0, 'n'},
@ -328,7 +350,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s -o FILE [OPTION]... [MODULES]\n\
@ -338,6 +360,7 @@ Make a bootable image of GRUB.\n\
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
-p, --prefix=DIR set grub_prefix directory\n\
-m, --memdisk=FILE embed FILE as a memdisk image\n\
-c, --config=FILE embed FILE as boot config\n\
-o, --output=FILE output a generated image to FILE\n\
-h, --help display this message and exit\n\
-n, --note add NOTE segment for CHRP Open Firmware\n\
@ -358,16 +381,16 @@ main (int argc, char *argv[])
char *dir = NULL;
char *prefix = NULL;
char *memdisk = NULL;
char *config = NULL;
int chrp = 0;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while (1)
{
int c = getopt_long (argc, argv, "d:p:m:o:hVvn", options, 0);
int c = getopt_long (argc, argv, "d:p:m:c:o:hVvn", options, 0);
if (c == -1)
break;
@ -393,6 +416,13 @@ main (int argc, char *argv[])
prefix = xstrdup ("(memdisk)/boot/grub");
break;
case 'c':
if (config)
free (config);
config = xstrdup (optarg);
break;
case 'h':
usage (0);
break;
@ -423,7 +453,8 @@ main (int argc, char *argv[])
if (! fp)
grub_util_error ("cannot open %s", output);
add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk);
add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk,
config);
fclose (fp);

View file

@ -115,14 +115,14 @@ grub_get_prefix (const char *dir)
saved_cwd = xgetcwd ();
if (chdir (dir) < 0)
grub_util_error ("Cannot change directory to `%s'", dir);
grub_util_error ("cannot change directory to `%s'", dir);
abs_dir = xgetcwd ();
strip_extra_slashes (abs_dir);
prev_dir = xstrdup (abs_dir);
if (stat (".", &prev_st) < 0)
grub_util_error ("Cannot stat `%s'", dir);
grub_util_error ("cannot stat `%s'", dir);
if (! S_ISDIR (prev_st.st_mode))
grub_util_error ("`%s' is not a directory", dir);
@ -130,13 +130,13 @@ grub_get_prefix (const char *dir)
while (1)
{
if (chdir ("..") < 0)
grub_util_error ("Cannot change directory to the parent");
grub_util_error ("cannot change directory to the parent");
if (stat (".", &st) < 0)
grub_util_error ("Cannot stat current directory");
grub_util_error ("cannot stat current directory");
if (! S_ISDIR (st.st_mode))
grub_util_error ("Current directory is not a directory???");
grub_util_error ("current directory is not a directory???");
if (prev_st.st_dev != st.st_dev || prev_st.st_ino == st.st_ino)
break;
@ -153,7 +153,7 @@ grub_get_prefix (const char *dir)
strip_extra_slashes (prefix);
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot change directory to `%s'", dir);
grub_util_error ("cannot change directory to `%s'", dir);
#ifdef __CYGWIN__
if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
@ -236,7 +236,7 @@ find_root_device (const char *dir, dev_t dev)
if (res)
{
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot restore the original directory");
grub_util_error ("cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -279,7 +279,7 @@ find_root_device (const char *dir, dev_t dev)
continue;
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot restore the original directory");
grub_util_error ("cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -288,7 +288,7 @@ find_root_device (const char *dir, dev_t dev)
}
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot restore the original directory");
grub_util_error ("cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -445,7 +445,7 @@ grub_guess_root_device (const char *dir)
struct stat st;
if (stat (dir, &st) < 0)
grub_util_error ("Cannot stat `%s'", dir);
grub_util_error ("cannot stat `%s'", dir);
#ifdef __CYGWIN__
/* Cygwin specific function. */
@ -591,7 +591,7 @@ grub_util_get_grub_dev (const char *os_dev)
free (p);
}
else
grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
grub_util_error ("unknown kind of RAID device `%s'", os_dev);
break;
@ -608,7 +608,7 @@ grub_util_check_block_device (const char *blk_dev)
struct stat st;
if (stat (blk_dev, &st) < 0)
grub_util_error ("Cannot stat `%s'", blk_dev);
grub_util_error ("cannot stat `%s'", blk_dev);
if (S_ISBLK (st.st_mode))
return (blk_dev);
@ -622,7 +622,7 @@ grub_util_check_char_device (const char *blk_dev)
struct stat st;
if (stat (blk_dev, &st) < 0)
grub_util_error ("Cannot stat `%s'", blk_dev);
grub_util_error ("cannot stat `%s'", blk_dev);
if (S_ISCHR (st.st_mode))
return (blk_dev);

View file

@ -1,7 +1,7 @@
/* grub-editenv.c - tool to edit environment block. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
* 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
@ -46,9 +46,6 @@ grub_refresh (void)
fflush (stdout);
}
struct grub_handler_class grub_term_input_class;
struct grub_handler_class grub_term_output_class;
int
grub_getkey (void)
{
@ -72,10 +69,10 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``grub-editenv --help'' for more information.\n");
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: grub-editenv [OPTIONS] [FILENAME] COMMAND\n\
Usage: %s [OPTIONS] [FILENAME] COMMAND\n\
\n\
Tool to edit environment block.\n\
\nCommands:\n\
@ -91,7 +88,7 @@ Tool to edit environment block.\n\
If not given explicitly, FILENAME defaults to %s.\n\
\n\
Report bugs to <%s>.\n",
DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
program_name, DEFAULT_DIRECTORY "/" GRUB_ENVBLK_DEFCFG, PACKAGE_BUGREPORT);
exit (status);
}
@ -256,9 +253,8 @@ main (int argc, char *argv[])
char *command;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2003,2004,2005,2006,2007,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
@ -129,10 +129,10 @@ usage (int status)
{
if (status)
fprintf (stderr,
"Try ``grub-emu --help'' for more information.\n");
"Try `%s --help' for more information.\n", program_name);
else
printf (
"Usage: grub-emu [OPTION]...\n"
"Usage: %s [OPTION]...\n"
"\n"
"GRUB emulator.\n"
"\n"
@ -144,7 +144,7 @@ usage (int status)
" -h, --help display this message and exit\n"
" -V, --version print version information and exit\n"
"\n"
"Report bugs to <%s>.\n", DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
"Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
return status;
}
@ -159,9 +159,8 @@ main (int argc, char *argv[])
int opt;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
switch (opt)
@ -221,14 +220,14 @@ main (int argc, char *argv[])
{
char *device_name = grub_guess_root_device (dir);
if (! device_name)
grub_util_error ("cannot find a device for %s.\n", dir);
grub_util_error ("cannot find a device for %s", dir);
root_dev = grub_util_get_grub_dev (device_name);
if (! root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
}
}

View file

@ -1,7 +1,7 @@
/* grub-fstest.c - debug tool for filesystem driver */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
* 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
@ -71,7 +71,7 @@ execute_command (char *name, int n, char **args)
cmd = grub_command_find (name);
if (! cmd)
grub_util_error ("Can\'t find command %s", name);
grub_util_error ("can\'t find command %s", name);
return (cmd->func) (cmd, n, args);
}
@ -100,9 +100,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
dev = grub_device_open (0);
if ((! dev) || (! dev->disk))
grub_util_error ("Can\'t open device.");
grub_util_error ("can\'t open device");
grub_util_info ("total sectors : %lld.",
grub_util_info ("total sectors : %lld",
(unsigned long long) dev->disk->total_sectors);
if (! leng)
@ -115,7 +115,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
len = (leng > BUF_SIZE) ? BUF_SIZE : leng;
if (grub_disk_read (dev->disk, 0, skip, len, buf))
grub_util_error ("Disk read fails at offset %lld, length %d.",
grub_util_error ("disk read fails at offset %lld, length %d",
skip, len);
if (hook (skip, buf, len))
@ -132,15 +132,15 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
file = grub_file_open (pathname);
if (!file)
{
grub_util_error ("cannot open file %s.", pathname);
grub_util_error ("cannot open file %s", pathname);
return;
}
grub_util_info ("file size : %lld.", (unsigned long long) file->size);
grub_util_info ("file size : %lld", (unsigned long long) file->size);
if (skip > file->size)
{
grub_util_error ("invalid skip value %lld.", (unsigned long long) skip);
grub_util_error ("invalid skip value %lld", (unsigned long long) skip);
return;
}
@ -158,7 +158,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
if (sz < 0)
{
grub_util_error ("read error at offset %llu.", ofs);
grub_util_error ("read error at offset %llu", ofs);
break;
}
@ -184,7 +184,7 @@ cmd_cp (char *src, char *dest)
if ((int) fwrite (buf, 1, len, ff) != len)
{
grub_util_error ("write error.");
grub_util_error ("write error");
return 1;
}
@ -194,7 +194,7 @@ cmd_cp (char *src, char *dest)
ff = fopen (dest, "wb");
if (ff == NULL)
{
grub_util_error ("open error.");
grub_util_error ("open error");
return;
}
read_file (src, cp_hook);
@ -212,7 +212,7 @@ cmd_cmp (char *src, char *dest)
{
if ((int) fread (buf_1, 1, len, ff) != len)
{
grub_util_error ("read error at offset %llu.", ofs);
grub_util_error ("read error at offset %llu", ofs);
return 1;
}
@ -223,7 +223,7 @@ cmd_cmp (char *src, char *dest)
for (i = 0; i < len; i++, ofs++)
if (buf_1[i] != buf[i])
{
grub_util_error ("compare fail at offset %llu.", ofs);
grub_util_error ("compare fail at offset %llu", ofs);
return 1;
}
}
@ -233,12 +233,12 @@ cmd_cmp (char *src, char *dest)
ff = fopen (dest, "rb");
if (ff == NULL)
{
grub_util_error ("open error.");
grub_util_error ("open error");
return;
}
if ((skip) && (fseeko (ff, skip, SEEK_SET)))
grub_util_error ("seek error.");
grub_util_error ("seek error");
read_file (src, cmp_hook);
fclose (ff);
@ -300,7 +300,7 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
argv[2] = host_file;
if (execute_command ("loopback", 3, argv))
grub_util_error ("loopback command fails.");
grub_util_error ("loopback command fails");
}
grub_lvm_fini ();
@ -367,7 +367,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\
@ -402,9 +402,8 @@ main (int argc, char *argv[])
int i, cmd, num_opts, image_index, num_disks = 1;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Find the first non option entry. */
for (num_opts = 1; num_opts < argc; num_opts++)

View file

@ -30,16 +30,18 @@ PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
host_os=@host_os@
font=@datadir@/@PACKAGE_TARNAME@/ascii.pf2
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] || [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
else
grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
fi
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -82,14 +84,21 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
--disk-module=MODULE disk module to use
EOF
fi
if [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
cat <<EOF
--font=FILE font file to use
EOF
fi
cat <<EOF
INSTALL_DEVICE can be a GRUB device name or a system device filename.
grub-install copies GRUB images into the DIR/boot directory specified by
--root-directory, and uses grub-setup to install grub into the boot
sector.
grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and
OpenBSD), and uses grub-setup to install grub into the boot sector.
If the --root-directory option is used, then grub-install will copy
images into the operating system installation rooted at that directory.
Report bugs to <bug-grub@gnu.org>.
EOF
@ -106,6 +115,8 @@ for option in "$@"; do
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--font=*)
font=`echo "$option" | sed 's/--font=//'` ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-setup=*)
@ -147,7 +158,7 @@ done
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
if test "x$install_device" = x; then
if test "x$install_device" = x && test "${target_cpu}-${platform}" != "mips-yeeloong"; then
echo "install_device not specified." 1>&2
usage
exit 1
@ -261,6 +272,10 @@ done
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device ${grub_device}`
if test "x$fs_module" = x -a "x$modules" = x; then
@ -290,15 +305,17 @@ prefix_drive=
config_opt=
if [ "x${devabstraction_module}" = "x" ] ; then
if echo "${install_device}" | grep -qx "(.*)" ; then
install_drive="${install_device}"
else
install_drive="`$grub_probe --target=drive --device ${install_device}`"
if [ x"${install_device}" != x ]; then
if echo "${install_device}" | grep -qx "(.*)" ; then
install_drive="${install_device}"
else
install_drive="`$grub_probe --target=drive --device ${install_device}`"
fi
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
fi
grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
# Strip partition number
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`"
if [ "$disk_module" = ata ] ; then
# generic method (used on coreboot and ata mod)
@ -332,6 +349,8 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}"
# Now perform the installation.
$grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
${install_device} || exit 1
elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
$grub_mkimage ${config_opt} -f ${font} -d ${pkglibdir} -O elf --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
else
$grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
fi

View file

@ -94,6 +94,15 @@ convert_system_path_to_grub_path ()
echo ${drive}${relative_path}
}
save_default_entry ()
{
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
cat << EOF
savedefault
EOF
fi
}
prepare_grub_to_access_device ()
{
device=$1

View file

@ -1,7 +1,7 @@
/* grub-mkdevicemap.c - make a device map file automatically */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,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
@ -84,7 +84,7 @@ usage (int status)
{
if (status)
fprintf (stderr,
"Try ``%s --help'' for more information.\n", program_name);
"Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]...\n\
@ -112,9 +112,8 @@ main (int argc, char *argv[])
int floppy_disks = 1;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 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
@ -49,6 +49,12 @@ struct grub_glyph_info
grub_uint8_t bitmap[0];
};
enum file_formats
{
PF2,
ASCII_BITMAPS
};
#define GRUB_FONT_FLAG_BOLD 1
#define GRUB_FONT_FLAG_NOBITMAP 2
#define GRUB_FONT_FLAG_NOHINTING 4
@ -59,10 +65,12 @@ struct grub_font_info
char* name;
int style;
int desc;
int asce;
int size;
int max_width;
int max_height;
int min_y;
int max_y;
int flags;
int num_range;
grub_uint32_t *ranges;
@ -77,6 +85,7 @@ static struct option options[] =
{"range", required_argument, 0, 'r'},
{"size", required_argument, 0, 's'},
{"desc", required_argument, 0, 'd'},
{"asce", required_argument, 0, 'c'},
{"bold", no_argument, 0, 'b'},
{"no-bitmap", no_argument, 0, 0x100},
{"no-hinting", no_argument, 0, 0x101},
@ -84,6 +93,7 @@ static struct option options[] =
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{"ascii-bitmaps", no_argument, 0, 0x102},
{0, 0, 0, 0}
};
@ -93,17 +103,19 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] FONT_FILES\n\
\nOptions:\n\
-o, --output=FILE_NAME set output file name\n\
--ascii-bitmaps save only the ASCII bitmaps\n\
-i, --index=N set face index\n\
-r, --range=A-B[,C-D] set font range\n\
-n, --name=S set font family name\n\
-s, --size=N set font size\n\
-d, --desc=N set font descent\n\
-c, --asce=N set font ascent\n\
-b, --bold convert to bold font\n\
-a, --force-autohint force autohint\n\
--no-hinting disable hinting\n\
@ -193,9 +205,12 @@ add_char (struct grub_font_info *font_info, FT_Face face,
if (height > font_info->max_height)
font_info->max_height = height;
if (glyph_info->y_ofs < font_info->min_y)
if (glyph_info->y_ofs < font_info->min_y && glyph_info->y_ofs > -font_info->size)
font_info->min_y = glyph_info->y_ofs;
if (glyph_info->y_ofs + height > font_info->max_y)
font_info->max_y = glyph_info->y_ofs + height;
mask = 0;
data = &glyph_info->bitmap[0] - 1;
for (j = 0; j < height; j++)
@ -284,8 +299,8 @@ print_glyphs (struct grub_font_info *font_info)
xmin = 0;
ymax = glyph->y_ofs + glyph->height;
if (ymax < font_info->size - font_info->desc)
ymax = font_info->size - font_info->desc;
if (ymax < font_info->asce)
ymax = font_info->asce;
ymin = glyph->y_ofs;
if (ymin > - font_info->desc)
@ -316,7 +331,7 @@ print_glyphs (struct grub_font_info *font_info)
else if ((x >= 0) &&
(x < glyph->device_width) &&
(y >= - font_info->desc) &&
(y < font_info->size - font_info->desc))
(y < font_info->asce))
{
line[line_pos++] = ((x == 0) || (y == 0)) ? '+' : '.';
}
@ -330,7 +345,39 @@ print_glyphs (struct grub_font_info *font_info)
}
void
write_font (struct grub_font_info *font_info, char *output_file)
write_font_ascii_bitmap (struct grub_font_info *font_info, char *output_file)
{
FILE *file;
struct grub_glyph_info *glyph;
int num;
file = fopen (output_file, "wb");
if (! file)
grub_util_error ("Can\'t write to file %s.", output_file);
int correct_size;
for (glyph = font_info->glyph, num = 0; glyph; glyph = glyph->next, num++)
{
correct_size = 1;
if (glyph->width != 8 || glyph->height != 16)
{
/* printf ("Width or height from glyph U+%04x not supported, skipping.\n", glyph->char_code); */
correct_size = 0;
}
int row;
for (row = 0; row < glyph->height; row++)
{
if (correct_size)
fwrite (&glyph->bitmap[row], sizeof(glyph->bitmap[row]), 1, file);
else
fwrite (&correct_size, 1, 1, file);
}
}
fclose (file);
}
void
write_font_pf2 (struct grub_font_info *font_info, char *output_file)
{
FILE *file;
grub_uint32_t leng, data;
@ -340,7 +387,7 @@ write_font (struct grub_font_info *font_info, char *output_file)
file = fopen (output_file, "wb");
if (! file)
grub_util_error ("Can\'t write to file %s.", output_file);
grub_util_error ("can\'t write to file %s.", output_file);
offset = 0;
@ -392,7 +439,15 @@ write_font (struct grub_font_info *font_info, char *output_file)
font_info->desc = - font_info->min_y;
}
write_be16_section ("ASCE", font_info->size - font_info->desc, &offset, file);
if (! font_info->asce)
{
if (font_info->max_y <= 0)
font_info->asce = 1;
else
font_info->asce = font_info->max_y;
}
write_be16_section ("ASCE", font_info->asce, &offset, file);
write_be16_section ("DESC", font_info->desc, &offset, file);
if (font_verbosity > 0)
@ -400,7 +455,7 @@ write_font (struct grub_font_info *font_info, char *output_file)
printf ("Font name: %s\n", font_name);
printf ("Max width: %d\n", font_info->max_width);
printf ("Max height: %d\n", font_info->max_height);
printf ("Font ascent: %d\n", font_info->size - font_info->desc);
printf ("Font ascent: %d\n", font_info->asce);
printf ("Font descent: %d\n", font_info->desc);
}
@ -458,9 +513,6 @@ write_font (struct grub_font_info *font_info, char *output_file)
grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size, file);
}
if (font_verbosity > 1)
print_glyphs (font_info);
fclose (file);
}
@ -472,13 +524,13 @@ main (int argc, char *argv[])
int font_index = 0;
int font_size = 0;
char *output_file = NULL;
enum file_formats file_format = PF2;
memset (&font_info, 0, sizeof (font_info));
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)
@ -532,13 +584,13 @@ main (int argc, char *argv[])
a = strtoul (p, &p, 0);
if (*p != '-')
grub_util_error ("Invalid font range");
grub_util_error ("invalid font range");
b = strtoul (p + 1, &p, 0);
if ((font_info.num_range & (GRUB_FONT_RANGE_BLOCK - 1)) == 0)
font_info.ranges = xrealloc (font_info.ranges,
(font_info.num_range +
GRUB_FONT_RANGE_BLOCK) *
sizeof (int) * 2);
sizeof (grub_uint32_t) * 2);
font_info.ranges[font_info.num_range * 2] = a;
font_info.ranges[font_info.num_range * 2 + 1] = b;
@ -547,7 +599,7 @@ main (int argc, char *argv[])
if (*p)
{
if (*p != ',')
grub_util_error ("Invalid font range");
grub_util_error ("invalid font range");
else
p++;
}
@ -561,6 +613,10 @@ main (int argc, char *argv[])
font_info.desc = strtoul (optarg, NULL, 0);
break;
case 'e':
font_info.asce = strtoul (optarg, NULL, 0);
break;
case 'h':
usage (0);
break;
@ -573,14 +629,35 @@ main (int argc, char *argv[])
font_verbosity++;
break;
case 0x102:
file_format = ASCII_BITMAPS;
break;
default:
usage (1);
break;
}
}
if (file_format == ASCII_BITMAPS && font_info.num_range > 0)
{
grub_util_error ("Option --ascii-bitmaps doesn't accept ranges (use ASCII).");
return 1;
}
else if (file_format == ASCII_BITMAPS)
{
font_info.ranges = xrealloc (font_info.ranges,
GRUB_FONT_RANGE_BLOCK *
sizeof (grub_uint32_t) * 2);
font_info.ranges[0] = (grub_uint32_t) 0x00;
font_info.ranges[1] = (grub_uint32_t) 0x7f;
font_info.num_range = 1;
}
if (! output_file)
grub_util_error ("No output file is specified.");
grub_util_error ("no output file is specified");
if (FT_Init_FreeType (&ft_lib))
grub_util_error ("FT_Init_FreeType fails");
@ -592,7 +669,7 @@ main (int argc, char *argv[])
if (FT_New_Face (ft_lib, argv[optind], font_index, &ft_face))
{
grub_util_info ("Can't open file %s, index %d\n", argv[optind],
grub_util_info ("can't open file %s, index %d", argv[optind],
font_index);
continue;
}
@ -620,7 +697,13 @@ main (int argc, char *argv[])
FT_Done_FreeType (ft_lib);
write_font (&font_info, output_file);
if (file_format == PF2)
write_font_pf2 (&font_info, output_file);
else if (file_format == ASCII_BITMAPS)
write_font_ascii_bitmap (&font_info, output_file);
if (font_verbosity > 1)
print_glyphs (&font_info);
return 0;
}

341
util/grub-mkpasswd-pbkdf2.c Normal file
View file

@ -0,0 +1,341 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1992-1999,2001,2003,2004,2005,2009 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 <grub/types.h>
#include <grub/crypto.h>
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <termios.h>
#include "progname.h"
/* Few functions to make crypto happy. */
void *
grub_memmove (void *dest, const void *src, grub_size_t n)
{
return memmove (dest, src, n);
}
void *
grub_memset (void *s, int c, grub_size_t n)
{
return memset (s, c, n);
}
int
grub_vprintf (const char *fmt, va_list args)
{
return vprintf (fmt, args);
}
int
grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list args)
{
return vsnprintf (str, n, fmt, args);
}
void
grub_abort (void)
{
abort ();
}
static struct option options[] =
{
{"iteration_count", required_argument, 0, 'c'},
{"buflen", required_argument, 0, 'l'},
{"saltlen", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
};
static void
usage (int status)
{
if (status)
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS]\n\
\nOptions:\n\
-c number, --iteration-count=number Number of PBKDF2 iterations\n\
-l number, --buflen=number Length of generated hash\n\
-s number, --salt=number Length of salt\n\
\n\
Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
exit (status);
}
static void
hexify (char *hex, grub_uint8_t *bin, grub_size_t n)
{
while (n--)
{
if (((*bin & 0xf0) >> 4) < 10)
*hex = ((*bin & 0xf0) >> 4) + '0';
else
*hex = ((*bin & 0xf0) >> 4) + 'A' - 10;
hex++;
if ((*bin & 0xf) < 10)
*hex = (*bin & 0xf) + '0';
else
*hex = (*bin & 0xf) + 'A' - 10;
hex++;
bin++;
}
*hex = 0;
}
int
main (int argc, char *argv[])
{
unsigned int c = 10000, buflen = 64, saltlen = 64;
char *pass1, *pass2;
char *bufhex, *salthex;
gcry_err_code_t gcry_err;
grub_uint8_t *buf, *salt;
ssize_t nr;
FILE *in, *out;
struct termios s, t;
int tty_changed;
set_program_name (argv[0]);
grub_util_init_nls ();
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "c:l:s:hvV", options, 0);
if (c == -1)
break;
switch (c)
{
case 'c':
c = strtoul (optarg, NULL, 0);
break;
case 'l':
buflen = strtoul (optarg, NULL, 0);
break;
case 's':
saltlen = strtoul (optarg, NULL, 0);
break;
case 'h':
usage (0);
return 0;
case 'V':
printf ("%s (%s) %s\n", program_name,
PACKAGE_NAME, PACKAGE_VERSION);
return 0;
default:
usage (1);
return 1;
}
}
bufhex = malloc (buflen * 2 + 1);
if (!bufhex)
grub_util_error ("out of memory");
buf = malloc (buflen);
if (!buf)
{
free (bufhex);
grub_util_error ("out of memory");
}
salt = malloc (saltlen);
if (!salt)
{
free (bufhex);
free (buf);
grub_util_error ("out of memory");
}
salthex = malloc (saltlen * 2 + 1);
if (!salthex)
{
free (salt);
free (bufhex);
free (buf);
grub_util_error ("out of memory");
}
/* Disable echoing. Based on glibc. */
in = fopen ("/dev/tty", "w+c");
if (in == NULL)
{
in = stdin;
out = stderr;
}
else
out = in;
if (tcgetattr (fileno (in), &t) == 0)
{
/* Save the old one. */
s = t;
/* Tricky, tricky. */
t.c_lflag &= ~(ECHO|ISIG);
tty_changed = (tcsetattr (fileno (in), TCSAFLUSH, &t) == 0);
}
else
tty_changed = 0;
printf ("Enter password: ");
pass1 = NULL;
{
grub_size_t n;
nr = getline (&pass1, &n, stdin);
}
if (nr < 0 || !pass1)
{
free (buf);
free (bufhex);
free (salthex);
free (salt);
/* Restore the original setting. */
if (tty_changed)
(void) tcsetattr (fileno (in), TCSAFLUSH, &s);
grub_util_error ("failure to read password");
}
if (nr >= 1 && pass1[nr-1] == '\n')
pass1[nr-1] = 0;
printf ("\nReenter password: ");
pass2 = NULL;
{
grub_size_t n;
nr = getline (&pass2, &n, stdin);
}
/* Restore the original setting. */
if (tty_changed)
(void) tcsetattr (fileno (in), TCSAFLUSH, &s);
printf ("\n");
if (nr < 0 || !pass2)
{
memset (pass1, 0, strlen (pass1));
free (pass1);
free (buf);
free (bufhex);
free (salthex);
free (salt);
grub_util_error ("failure to read password");
}
if (nr >= 1 && pass2[nr-1] == '\n')
pass2[nr-1] = 0;
if (strcmp (pass1, pass2) != 0)
{
memset (pass1, 0, strlen (pass1));
memset (pass2, 0, strlen (pass2));
free (pass1);
free (pass2);
free (buf);
free (bufhex);
free (salthex);
free (salt);
grub_util_error ("passwords don't match");
}
memset (pass2, 0, strlen (pass2));
free (pass2);
#if ! defined (__linux__) && ! defined (__FreeBSD__)
printf ("WARNING: your random generator isn't known to be secure\n");
#endif
{
FILE *f;
size_t rd;
f = fopen ("/dev/random", "rb");
if (!f)
{
memset (pass1, 0, strlen (pass1));
free (pass1);
free (buf);
free (bufhex);
free (salthex);
free (salt);
fclose (f);
grub_util_error ("couldn't retrieve random data for salt");
}
rd = fread (salt, 1, saltlen, f);
if (rd != saltlen)
{
fclose (f);
memset (pass1, 0, strlen (pass1));
free (pass1);
free (buf);
free (bufhex);
free (salthex);
free (salt);
fclose (f);
grub_util_error ("couldn't retrieve random data for salt");
}
fclose (f);
}
gcry_err = grub_crypto_pbkdf2 (GRUB_MD_SHA512,
(grub_uint8_t *) pass1, strlen (pass1),
salt, saltlen,
c, buf, buflen);
memset (pass1, 0, strlen (pass1));
free (pass1);
if (gcry_err)
{
memset (buf, 0, buflen);
memset (bufhex, 0, 2 * buflen);
free (buf);
free (bufhex);
memset (salt, 0, saltlen);
memset (salthex, 0, 2 * saltlen);
free (salt);
free (salthex);
grub_util_error ("cryptographic error number %d", gcry_err);
}
hexify (bufhex, buf, buflen);
hexify (salthex, salt, saltlen);
printf ("Your PBKDF2 is grub.pbkdf2.sha512.%d.%s.%s\n", c, salthex, bufhex);
memset (buf, 0, buflen);
memset (bufhex, 0, 2 * buflen);
free (buf);
free (bufhex);
memset (salt, 0, saltlen);
memset (salthex, 0, 2 * saltlen);
free (salt);
free (salthex);
return 0;
}

View file

@ -1,7 +1,7 @@
/* grub-mkimage.c - make a bootable image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2002,2003,2004,2005,2006,2007,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
@ -22,6 +22,7 @@
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <grub/machine/memory.h>
#include <grub/elf.h>
#include <grub/i18n.h>
#include <grub/kernel.h>
#include <grub/disk.h>
@ -33,6 +34,7 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define _GNU_SOURCE 1
#include <getopt.h>
@ -94,12 +96,19 @@ compress_kernel (char *kernel_img, size_t kernel_size,
static void
generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
char *memdisk_path, char *config_path)
char *memdisk_path, char *font_path, char *config_path,
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
grub_platform_image_format_t format
#else
int dummy __attribute__ ((unused))
#endif
)
{
char *kernel_img, *boot_img, *core_img;
size_t kernel_size, boot_size, total_module_size, core_size;
size_t memdisk_size = 0, config_size = 0;
char *kernel_path, *boot_path;
char *kernel_img, *core_img;
size_t kernel_size, total_module_size, core_size;
size_t memdisk_size = 0, font_size = 0, config_size = 0, config_size_pure = 0;
char *kernel_path;
size_t offset;
struct grub_util_path_list *path_list, *p, *next;
struct grub_module_info *modinfo;
@ -118,9 +127,16 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
total_module_size += memdisk_size + sizeof (struct grub_module_header);
}
if (font_path)
{
font_size = ALIGN_UP(grub_util_get_image_size (font_path), 4);
total_module_size += font_size + sizeof (struct grub_module_header);
}
if (config_path)
{
config_size = grub_util_get_image_size (config_path) + 1;
config_size_pure = grub_util_get_image_size (config_path) + 1;
config_size = ALIGN_UP(config_size_pure, 4);
grub_util_info ("the size of config file is 0x%x", config_size);
total_module_size += config_size + sizeof (struct grub_module_header);
}
@ -149,15 +165,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
for (p = path_list; p; p = p->next)
{
struct grub_module_header *header;
size_t mod_size;
size_t mod_size, orig_size;
mod_size = grub_util_get_image_size (p->name);
orig_size = grub_util_get_image_size (p->name);
mod_size = ALIGN_UP(orig_size, 4);
header = (struct grub_module_header *) (kernel_img + offset);
memset (header, 0, sizeof (struct grub_module_header));
header->type = OBJ_TYPE_ELF;
header->size = grub_host_to_target32 (mod_size + sizeof (*header));
offset += sizeof (*header);
memset (kernel_img + offset + orig_size, 0, mod_size - orig_size);
grub_util_load_image (p->name, kernel_img + offset);
offset += mod_size;
@ -177,6 +195,20 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
offset += memdisk_size;
}
if (font_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
memset (header, 0, sizeof (struct grub_module_header));
header->type = OBJ_TYPE_FONT;
header->size = grub_host_to_target32 (font_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (font_path, kernel_img + offset);
offset += font_size;
}
if (config_path)
{
struct grub_module_header *header;
@ -188,8 +220,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
offset += sizeof (*header);
grub_util_load_image (config_path, kernel_img + offset);
*(kernel_img + offset + config_size_pure - 1) = 0;
offset += config_size;
*(kernel_img + offset - 1) = 0;
}
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
@ -201,22 +233,33 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
#if defined(GRUB_MACHINE_PCBIOS)
{
unsigned num;
char *boot_path, *boot_img;
size_t boot_size;
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
if (num > 0xffff)
grub_util_error (_("the core image is too big"));
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("diskboot.img size must be %u bytes"), GRUB_DISK_SECTOR_SIZE);
grub_util_error (_("diskboot.img size must be %u bytes"),
GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
/* i386 is a little endian architecture. */
*((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_cpu_to_le16 (num);
{
struct grub_boot_blocklist *block;
block = (struct grub_boot_blocklist *) (boot_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
block->len = grub_host_to_target16 (num);
/* This is filled elsewhere. Verify it just in case. */
assert (block->segment
== grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4)));
}
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
@ -225,6 +268,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
{
char *rom_img;
size_t rom_size;
char *boot_path, *boot_img;
size_t boot_size;
boot_path = grub_util_get_path (dir, "boot.img");
boot_size = grub_util_get_image_size (boot_path);
@ -237,12 +282,12 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
memset (rom_img, 0, rom_size);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_CORE_ENTRY_ADDR))
= grub_cpu_to_le32 ((grub_uint32_t) -rom_size);
= grub_host_to_target32 ((grub_uint32_t) -rom_size);
memcpy (rom_img, core_img, core_size);
*((grub_int32_t *) (boot_img + GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR))
= grub_cpu_to_le32 ((grub_uint32_t) -rom_size);
= grub_host_to_target32 ((grub_uint32_t) -rom_size);
memcpy (rom_img + rom_size - boot_size, boot_img, boot_size);
@ -253,18 +298,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
free (boot_img);
free (boot_path);
}
#endif
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_cpu_to_le32 (total_module_size);
= grub_host_to_target32 (total_module_size);
#endif
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_cpu_to_le32 (kernel_size);
= grub_host_to_target32 (kernel_size);
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
= grub_cpu_to_le32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
= grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
#endif
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
@ -273,16 +317,79 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
if (prefix[0] == '(')
{
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
= grub_cpu_to_le32 (-2);
= grub_host_to_target32 (-2);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
= grub_cpu_to_le32 (-2);
= grub_host_to_target32 (-2);
}
#endif
#ifdef GRUB_MACHINE_PCBIOS
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
grub_util_error (_("Core image is too big (%p > %p)\n"),
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER);
grub_util_error (_("core image is too big (%p > %p)"),
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
GRUB_MEMORY_MACHINE_UPPER);
#endif
#if defined(GRUB_MACHINE_MIPS)
if (format == GRUB_PLATFORM_IMAGE_ELF)
{
char *elf_img;
size_t program_size;
Elf32_Ehdr *ehdr;
Elf32_Phdr *phdr;
grub_uint32_t target_addr;
program_size = ALIGN_UP (core_size, 4);
elf_img = xmalloc (program_size + sizeof (*ehdr) + sizeof (*phdr));
memset (elf_img, 0, program_size + sizeof (*ehdr) + sizeof (*phdr));
memcpy (elf_img + sizeof (*ehdr) + sizeof (*phdr), core_img, core_size);
ehdr = (void *) elf_img;
phdr = (void *) (elf_img + sizeof (*ehdr));
memcpy (ehdr->e_ident, ELFMAG, SELFMAG);
ehdr->e_ident[EI_CLASS] = ELFCLASS32;
#ifdef GRUB_CPU_MIPSEL
ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
#else
ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
#endif
ehdr->e_ident[EI_VERSION] = EV_CURRENT;
ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE;
ehdr->e_type = grub_host_to_target16 (ET_EXEC);
ehdr->e_machine = grub_host_to_target16 (EM_MIPS);
ehdr->e_version = grub_host_to_target32 (EV_CURRENT);
ehdr->e_phoff = grub_host_to_target32 ((char *) phdr - (char *) ehdr);
ehdr->e_phentsize = grub_host_to_target16 (sizeof (*phdr));
ehdr->e_phnum = grub_host_to_target16 (1);
/* No section headers. */
ehdr->e_shoff = grub_host_to_target32 (0);
ehdr->e_shentsize = grub_host_to_target16 (0);
ehdr->e_shnum = grub_host_to_target16 (0);
ehdr->e_shstrndx = grub_host_to_target16 (0);
ehdr->e_ehsize = grub_host_to_target16 (sizeof (*ehdr));
phdr->p_type = grub_host_to_target32 (PT_LOAD);
phdr->p_offset = grub_host_to_target32 (sizeof (*ehdr) + sizeof (*phdr));
phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
target_addr = ALIGN_UP (GRUB_KERNEL_MACHINE_LINK_ADDR
+ kernel_size + total_module_size, 32);
ehdr->e_entry = grub_host_to_target32 (target_addr);
phdr->p_vaddr = grub_host_to_target32 (target_addr);
phdr->p_paddr = grub_host_to_target32 (target_addr);
phdr->p_align = grub_host_to_target32 (GRUB_KERNEL_MACHINE_LINK_ALIGN);
ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER
| EF_MIPS_PIC | EF_MIPS_CPIC);
phdr->p_filesz = grub_host_to_target32 (core_size);
phdr->p_memsz = grub_host_to_target32 (core_size);
free (core_img);
core_img = elf_img;
core_size = program_size + sizeof (*ehdr) + sizeof (*phdr);
}
#endif
grub_util_write_image (core_img, core_size, out);
@ -306,8 +413,12 @@ static struct option options[] =
{"directory", required_argument, 0, 'd'},
{"prefix", required_argument, 0, 'p'},
{"memdisk", required_argument, 0, 'm'},
{"font", required_argument, 0, 'f'},
{"config", required_argument, 0, 'c'},
{"output", required_argument, 0, 'o'},
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
{"format", required_argument, 0, 'O'},
#endif
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
@ -318,24 +429,33 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name);
fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
else
printf (_("\
Usage: grub-mkimage [OPTION]... [MODULES]\n\
Usage: %s [OPTION]... [MODULES]\n\
\n\
Make a bootable image of GRUB.\n\
\n\
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
-m, --memdisk=FILE embed FILE as a memdisk image\n\
-f, --font=FILE embed FILE as a boot font\n\
-c, --config=FILE embed FILE as boot config\n\
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
-o, --output=FILE output a generated image to FILE [default=stdout]\n"
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
"\
-O, --format=FORMAT generate an image in format [default="
GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "]\n \
available formats: "
GRUB_PLATFORM_IMAGE_FORMATS "\n"
#endif
"\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n\
"), GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
"), program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
exit (status);
}
@ -347,17 +467,18 @@ main (int argc, char *argv[])
char *dir = NULL;
char *prefix = NULL;
char *memdisk = NULL;
char *font = NULL;
char *config = NULL;
FILE *fp = stdout;
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
grub_platform_image_format_t format = GRUB_PLATFORM_IMAGE_DEFAULT;
#endif
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while (1)
{
int c = getopt_long (argc, argv, "d:p:m:c:o:hVv", options, 0);
int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:hVv", options, 0);
if (c == -1)
break;
@ -371,6 +492,22 @@ main (int argc, char *argv[])
output = xstrdup (optarg);
break;
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
case 'O':
#ifdef GRUB_PLATFORM_IMAGE_RAW
if (strcmp (optarg, "raw") == 0)
format = GRUB_PLATFORM_IMAGE_RAW;
else
#endif
#ifdef GRUB_PLATFORM_IMAGE_ELF
if (strcmp (optarg, "elf") == 0)
format = GRUB_PLATFORM_IMAGE_ELF;
else
#endif
usage (1);
break;
#endif
case 'd':
if (dir)
free (dir);
@ -390,6 +527,13 @@ main (int argc, char *argv[])
prefix = xstrdup ("(memdisk)/boot/grub");
break;
case 'f':
if (font)
free (font);
font = xstrdup (optarg);
break;
case 'c':
if (config)
free (config);
@ -431,7 +575,13 @@ main (int argc, char *argv[])
}
generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp,
argv + optind, memdisk, config);
argv + optind, memdisk, font, config,
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
format
#else
0
#endif
);
fclose (fp);

View file

@ -1,7 +1,7 @@
/* grub-mkrelpath.c - make a system path relative to its root */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 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
@ -34,7 +34,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] PATH\n\
@ -56,9 +56,8 @@ main (int argc, char *argv[])
char *argument, *relpath;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)

View file

@ -40,7 +40,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] input [output]\n\
@ -182,7 +182,7 @@ write_section_data (FILE* fp, char *image,
char name[5 + strlen (pe_shdr->name)];
if (num_sections >= MAX_SECTIONS)
grub_util_error ("Too many sections");
grub_util_error ("too many sections");
sprintf (name, ".rel%s", pe_shdr->name);
@ -230,14 +230,14 @@ write_reloc_section (FILE* fp, char *image,
if ((pe_rel->symtab_index >= pe_chdr->num_symbols) ||
(symtab_map[pe_rel->symtab_index] == -1))
grub_util_error ("Invalid symbol");
grub_util_error ("invalid symbol");
if (pe_rel->type == GRUB_PE32_REL_I386_DIR32)
type = R_386_32;
else if (pe_rel->type == GRUB_PE32_REL_I386_REL32)
type = R_386_PC32;
else
grub_util_error ("Unknown pe relocation type %d\n", pe_rel->type);
grub_util_error ("unknown pe relocation type %d\n", pe_rel->type);
ofs = pe_rel->offset - pe_sec->virtual_address;
addr = (grub_uint32_t *)(image + pe_sec->raw_data_offset + ofs);
@ -248,14 +248,14 @@ write_reloc_section (FILE* fp, char *image,
code = image[pe_sec->raw_data_offset + ofs - 1];
if (((code != 0xe8) && (code != 0xe9)) || (*addr))
grub_util_error ("Invalid relocation (%x %x)", code, *addr);
grub_util_error ("invalid relocation (%x %x)", code, *addr);
modified = 1;
if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx)
{
if (symtab[symtab_map[pe_rel->symtab_index]].st_shndx
!= shdr[i].sh_info)
grub_util_error ("Cross section call is not allowed");
grub_util_error ("cross section call is not allowed");
*addr = (symtab[symtab_map[pe_rel->symtab_index]].st_value
- ofs - 4);
@ -440,7 +440,7 @@ convert_pe (FILE* fp, char *image)
pe_chdr = (struct grub_pe32_coff_header *) image;
if (grub_le_to_cpu16 (pe_chdr->machine) != GRUB_PE32_MACHINE_I386)
grub_util_error ("Invalid coff image");
grub_util_error ("invalid coff image");
strtab = xmalloc (STRTAB_BLOCK);
strtab_max = STRTAB_BLOCK;

View file

@ -1,7 +1,7 @@
/* grub-probe.c - probe device information for a given path */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2005,2006,2007,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
@ -84,7 +84,7 @@ probe_partmap (grub_disk_t disk)
{
if (disk->partition == NULL)
{
grub_util_info ("No partition map found for %s", disk->name);
grub_util_info ("no partition map found for %s", disk->name);
return;
}
@ -94,6 +94,11 @@ probe_partmap (grub_disk_t disk)
static int
probe_raid_level (grub_disk_t disk)
{
/* disk might be NULL in the case of a LVM physical volume with no LVM
signature. Ignore such cases here. */
if (!disk)
return -1;
if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID)
return -1;
@ -113,17 +118,17 @@ probe (const char *path, char *device_name)
{
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (! grub_util_check_char_device (device_name))
grub_util_error ("%s is not a character device.\n", device_name);
grub_util_error ("%s is not a character device", device_name);
#else
if (! grub_util_check_block_device (device_name))
grub_util_error ("%s is not a block device.\n", device_name);
grub_util_error ("%s is not a block device", device_name);
#endif
}
else
device_name = grub_guess_root_device (path);
if (! device_name)
grub_util_error ("cannot find a device for %s (is /dev mounted?).\n", path);
grub_util_error ("cannot find a device for %s (is /dev mounted?)", path);
if (print == PRINT_DEVICE)
{
@ -133,7 +138,7 @@ probe (const char *path, char *device_name)
drive_name = grub_util_get_grub_dev (device_name);
if (! drive_name)
grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name);
grub_util_error ("cannot find a GRUB drive for %s. Check your device.map", device_name);
if (print == PRINT_DRIVE)
{
@ -309,7 +314,7 @@ usage (int status)
{
if (status)
fprintf (stderr,
"Try ``%s --help'' for more information.\n", program_name);
"Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... [PATH|DEVICE]\n\
@ -338,9 +343,8 @@ main (int argc, char *argv[])
char *argument;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)

108
util/grub-reboot.in Normal file
View file

@ -0,0 +1,108 @@
#! /bin/sh
#
# Set a default boot entry for GRUB, for the next boot only.
# Copyright (C) 2004,2009 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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] entry
Set the default boot entry for GRUB, for the next boot only.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
ENTRY is a number or a menu item title.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-reboot (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$entry" != x; then
echo "More than one entry?" 1>&2
usage
exit 1
fi
entry="${option}" ;;
esac
done
if test "x$entry" = x; then
echo "entry not specified." 1>&2
usage
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
if [ "$prev_saved_entry" ]; then
$grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
else
# We need some non-empty value for prev_saved_entry so that GRUB will
# recognise that grub-reboot has been used and restore the previous
# saved entry. "0" is the same as an empty value, i.e. the first menu
# entry.
$grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
fi
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.
exit 0

250
util/grub-script-check.c Normal file
View file

@ -0,0 +1,250 @@
/* grub-script-check.c - check grub script file for syntax errors */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2006,2007,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/mm.h>
#include <grub/misc.h>
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include <grub/parser.h>
#include <grub/script_sh.h>
#include <grub_script_check_init.h>
#define _GNU_SOURCE 1
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "progname.h"
void
grub_putchar (int c)
{
putchar (c);
}
int
grub_getkey (void)
{
return -1;
}
void
grub_refresh (void)
{
fflush (stdout);
}
char *
grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdline (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdblock (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdif (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
{
struct grub_script_cmd_menuentry *menu;
menu = (struct grub_script_cmd_menuentry *)cmd;
if (menu->sourcecode)
{
grub_free (menu->sourcecode);
menu->sourcecode = 0;
}
return 0;
}
grub_err_t
grub_script_execute (struct grub_script *script)
{
if (script == 0 || script->cmd == 0)
return 0;
return script->cmd->exec (script->cmd);
}
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 [PATH]\n\
\n\
Checks GRUB script configuration file for syntax errors.\n\
\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print script being processed\n\
\n\
Report bugs to <%s>.\n\
", program_name,
PACKAGE_BUGREPORT);
exit (status);
}
int
main (int argc, char *argv[])
{
char *argument;
char *input;
FILE *file = 0;
int verbose = 0;
struct grub_script *script;
auto grub_err_t get_config_line (char **line, int cont);
grub_err_t get_config_line (char **line, int cont __attribute__ ((unused)))
{
char *cmdline = 0;
size_t len = 0;
ssize_t read;
read = getline(&cmdline, &len, (file ?: stdin));
if (read == -1)
{
*line = 0;
grub_errno = GRUB_ERR_READ_ERROR;
if (cmdline)
free (cmdline);
return grub_errno;
}
if (verbose)
grub_printf("%s", cmdline);
*line = grub_strdup (cmdline);
free (cmdline);
return 0;
}
set_program_name (argv[0]);
grub_util_init_nls ();
/* 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':
verbose = 1;
break;
default:
usage (1);
break;
}
}
/* Obtain ARGUMENT. */
if (optind >= argc)
{
file = 0; /* read from stdin */
}
else if (optind + 1 != argc)
{
fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind + 1]);
usage (1);
}
else
{
argument = argv[optind];
file = fopen (argument, "r");
if (! file)
{
fprintf (stderr, "%s: %s: %s\n", program_name, argument, strerror(errno));
usage (1);
}
}
/* Initialize all modules. */
grub_init_all ();
do
{
input = 0;
get_config_line(&input, 0);
if (! input)
break;
script = grub_script_parse (input, get_config_line);
if (script)
{
grub_script_execute (script);
grub_script_free (script);
}
grub_free (input);
} while (script != 0);
/* Free resources. */
grub_fini_all ();
if (file) fclose (file);
return (script == 0);
}

99
util/grub-set-default.in Normal file
View file

@ -0,0 +1,99 @@
#! /bin/sh
#
# Set a default boot entry for GRUB.
# Copyright (C) 2004,2009 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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] entry
Set the default boot entry for GRUB.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
ENTRY is a number or a menu item title.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-set-default (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$entry" != x; then
echo "More than one entry?" 1>&2
usage
exit 1
fi
entry="${option}" ;;
esac
done
if test "x$entry" = x; then
echo "entry not specified." 1>&2
usage
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.
exit 0

View file

@ -34,11 +34,29 @@ for i in ${GRUB_PRELOAD_MODULES} ; do
done
if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
cat << EOF
set default=${GRUB_DEFAULT}
if [ -s \$prefix/grubenv ]; then
load_env
fi
set default="${GRUB_DEFAULT}"
if [ \${prev_saved_entry} ]; then
set saved_entry=\${prev_saved_entry}
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z \${boot_once} ]; then
saved_entry=\${chosen}
save_env saved_entry
fi
}
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in

View file

@ -1,7 +1,7 @@
#! /bin/sh -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
# Copyright (C) 2006,2007,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
@ -73,16 +73,19 @@ menuentry "${OS}" {
EOF
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
cat << EOF
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
echo $(gettext "Loading GNU Mach ...")
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
cat << EOF
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
echo $(gettext "Loading the Hurd ...")
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
--multiboot-command-line='\${kernel-command-line}' \\
--host-priv-port='\${host-port}' \\
--device-master-port='\${device-port}' \\
--exec-server-task='\${exec-task}' -T typed '\${root}' \\
'\$(task-create)' '\$(task-resume)'
module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
}
EOF

View file

@ -1,7 +1,7 @@
#! /bin/sh -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
# Copyright (C) 2006,2007,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
@ -39,17 +39,19 @@ kfreebsd_entry ()
args="$4" # not used yet
title="$(gettext "%s, with kFreeBSD %s")"
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_boot_cache}"
cat << EOF
kfreebsd ${rel_dirname}/${basename}
echo $(printf "$(gettext "Loading kernel of FreeBSD %s ...")" ${version})
kfreebsd ${rel_dirname}/${basename}
EOF
if test -n "${devices}" ; then
cat << EOF
kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
EOF
fi

View file

@ -1,7 +1,7 @@
#! /bin/sh -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
# Copyright (C) 2006,2007,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
@ -59,15 +59,18 @@ linux_entry ()
title="$(gettext "%s, with Linux %s")"
fi
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_boot_cache}"
cat << EOF
echo $(printf "$(gettext "Loading Linux %s ...")" ${version})
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
EOF
if test -n "${initrd}" ; then
cat << EOF
echo $(gettext "Loading initial ramdisk ...")
initrd ${rel_dirname}/${initrd}
EOF
fi

View file

@ -73,6 +73,7 @@ for dir in $dirlist ; do
menuentry "$OS" {
EOF
save_default_entry | sed -e 's,^,\t,'
prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
cat << EOF

View file

@ -41,13 +41,14 @@ osx_entry() {
cat << EOF
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
cat << EOF
insmod ${GRUB_VIDEO_BACKEND}
do_resume=0
set do_resume=0
if [ /var/vm/sleepimage -nt10 / ]; then
if xnu_resume /var/vm/sleepimage; then
do_resume=1
set do_resume=1
fi
fi
if [ \$do_resume == 0 ]; then
@ -105,6 +106,7 @@ for OS in ${OSPROBED} ; do
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
case ${LONGNAME} in
@ -146,6 +148,7 @@ EOF
cat << EOF
menuentry "${LLABEL} (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
fi
@ -172,6 +175,7 @@ EOF
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`"

View file

@ -568,7 +568,7 @@ read_device_map (const char *dev_map)
fp = fopen (dev_map, "r");
if (! fp)
{
grub_util_info (_("Cannot open `%s'"), dev_map);
grub_util_info (_("cannot open `%s'"), dev_map);
return;
}
@ -639,7 +639,7 @@ read_device_map (const char *dev_map)
symbolic links. */
map[drive].device = xmalloc (PATH_MAX);
if (! realpath (p, map[drive].device))
grub_util_error ("Cannot get the real path of `%s'", p);
grub_util_error ("cannot get the real path of `%s'", p);
#else
map[drive].device = xstrdup (p);
#endif

View file

@ -1,7 +1,7 @@
/* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008 Free Software Foundation, Inc.
* Copyright (C) 2007,2008,2009 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

View file

@ -35,6 +35,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -179,6 +180,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = xfat; then :; else

View file

@ -778,7 +778,7 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
if ((ELF_R_TYPE (info) == R_X86_64_32) ||
(ELF_R_TYPE (info) == R_X86_64_32S))
{
grub_util_error ("Can\'t add fixup entry for R_X86_64_32(S)");
grub_util_error ("can\'t add fixup entry for R_X86_64_32(S)");
}
else if (ELF_R_TYPE (info) == R_X86_64_64)
{
@ -1029,10 +1029,10 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``grub-mkimage --help'' for more information.\n");
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\
Usage: %s -o FILE [OPTION]... [MODULES]\n\
\n\
Make a bootable image of GRUB.\n\
\n\
@ -1044,7 +1044,7 @@ Make a bootable image of GRUB.\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n\
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
exit (status);
}

View file

@ -1,116 +0,0 @@
#! /bin/sh -e
# Make GRUB rescue floppy
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] output_image
Make GRUB rescue floppy.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--output=FILE save output in FILE
$0 generates a bootable rescue floppy.
Report bugs to <bug-grub@gnu.org>.
EOF
}
input_dir=${pkglibdir}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--output=*)
output_image=`echo "$option" | sed 's/--output=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$output_image" != x; then
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
fi
output_image="${option}" ;;
esac
done
if test "x$output_image" = x; then
usage
exit 1
fi
aux_dir=`mktemp -d`
mkdir -p ${aux_dir}/boot/grub
for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \
${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
${input_dir}/handler.lst ${input_dir}/parttool.lst; do
if test -f "$file"; then
cp -f "$file" ${aux_dir}/boot/grub/
fi
done
modules="$(cat ${input_dir}/partmap.lst) ${modules}"
for i in ${modules} ; do
echo "insmod $i"
done > ${aux_dir}/boot/grub/grub.cfg
# build memdisk
memdisk_img=`mktemp`
tar -C ${aux_dir} -cf ${memdisk_img} boot
rm -rf ${aux_dir}
# build core.img
core_img=`mktemp`
grub-mkimage -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar biosdisk
rm -f ${memdisk_img}
# build floppy image
cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${output_image}
rm -f ${core_img}
exit 0

View file

@ -1,7 +1,7 @@
/* grub-setup.c - make GRUB usable */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,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
@ -48,6 +48,7 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <assert.h>
#include "progname.h"
#define _GNU_SOURCE 1
@ -56,14 +57,6 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#define DEFAULT_BOOT_FILE "boot.img"
#define DEFAULT_CORE_FILE "core.img"
/* This is the blocklist used in the diskboot image. */
struct boot_blocklist
{
grub_uint64_t start;
grub_uint16_t len;
grub_uint16_t segment;
} __attribute__ ((packed));
void
grub_putchar (int c)
{
@ -99,7 +92,7 @@ setup (const char *dir,
grub_uint8_t *boot_drive;
grub_disk_addr_t *kernel_sector;
grub_uint16_t *boot_drive_check;
struct boot_blocklist *first_block, *block;
struct grub_boot_blocklist *first_block, *block;
grub_int32_t *install_dos_part, *install_bsd_part;
grub_int32_t dos_part, bsd_part;
char *tmp_img;
@ -163,7 +156,7 @@ setup (const char *dir,
sector, offset, length);
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("The first sector of the core file is not sector-aligned"));
grub_util_error (_("the first sector of the core file is not sector-aligned"));
first_sector = sector;
}
@ -171,13 +164,13 @@ setup (const char *dir,
void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
unsigned length)
{
struct boot_blocklist *prev = block + 1;
struct grub_boot_blocklist *prev = block + 1;
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
sector, offset, length, (unsigned) current_segment);
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("Non-sector-aligned data is found in the core file"));
grub_util_error (_("non-sector-aligned data is found in the core file"));
if (block != first_block
&& (grub_le_to_cpu64 (prev->start)
@ -191,7 +184,7 @@ setup (const char *dir,
block--;
if (block->len)
grub_util_error (_("The sectors of the core file are too fragmented"));
grub_util_error (_("the sectors of the core file are too fragmented"));
}
last_length = length;
@ -202,7 +195,7 @@ setup (const char *dir,
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("The size of `%s' is not %u"),
grub_util_error (_("the size of `%s' is not %u"),
boot_path, GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
@ -219,16 +212,16 @@ setup (const char *dir,
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
if (core_size < GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("The size of `%s' is too small"), core_path);
grub_util_error (_("the size of `%s' is too small"), core_path);
else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("The size of `%s' is too large"), core_path);
grub_util_error (_("the size of `%s' is too large"), core_path);
core_img = grub_util_read_image (core_path);
/* Have FIRST_BLOCK to point to the first blocklist. */
first_block = (struct boot_blocklist *) (core_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
first_block = (struct grub_boot_blocklist *) (core_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
@ -258,7 +251,7 @@ setup (const char *dir,
grub_fs_t fs;
fs = grub_fs_probe (dest_dev);
if (! fs)
grub_util_error (_("Unable to identify a filesystem in %s; safety check can't be performed"),
grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"),
dest_dev->disk->name);
if (! fs->reserved_first_sector)
@ -311,7 +304,7 @@ setup (const char *dir,
bsd_part = -1;
}
else
grub_util_error (_("No DOS-style partitions found"));
grub_util_error (_("no DOS-style partitions found"));
}
else
dos_part = bsd_part = -1;
@ -389,10 +382,11 @@ setup (const char *dir,
/* The first blocklist contains the whole sectors. */
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
first_block->segment
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4));
/* These are filled elsewhere. Verify them just in case. */
assert (first_block->len == grub_host_to_target16 (core_sectors - 1));
assert (first_block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4)));
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
@ -419,14 +413,14 @@ setup (const char *dir,
unable_to_embed:
if (must_embed)
grub_util_error (_("Embedding is not possible, but this is required when "
"the root device is on a RAID array or LVM volume."));
grub_util_error (_("embedding is not possible, but this is required when "
"the root device is on a RAID array or LVM volume"));
grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this "
"setup by using blocklists. However, blocklists are UNRELIABLE and "
"its use is discouraged."));
if (! force)
grub_util_error (_("If you really want blocklists, use --force."));
grub_util_error (_("if you really want blocklists, use --force"));
/* Make sure that GRUB reads the identical image as the OS. */
tmp_img = xmalloc (core_size);
@ -501,7 +495,7 @@ unable_to_embed:
}
if (i == MAX_TRIES)
grub_util_error (_("Cannot read `%s' correctly"), core_path_dev);
grub_util_error (_("cannot read `%s' correctly"), core_path_dev);
/* Clean out the blocklists. */
block = first_block;
@ -514,7 +508,7 @@ unable_to_embed:
block--;
if ((char *) block <= core_img)
grub_util_error (_("No terminator in the core image"));
grub_util_error (_("no terminator in the core image"));
}
/* Now read the core image to determine where the sectors are. */
@ -525,13 +519,13 @@ unable_to_embed:
file->read_hook = save_first_sector;
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("Failed to read the first sector of the core image"));
grub_util_error (_("failed to read the first sector of the core image"));
block = first_block;
file->read_hook = save_blocklists;
if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("Failed to read the rest sectors of the core image"));
grub_util_error (_("failed to read the rest sectors of the core image"));
grub_file_close (file);
@ -550,7 +544,7 @@ unable_to_embed:
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
if (! fp)
grub_util_error (_("Cannot open `%s'"), core_path);
grub_util_error (_("cannot open `%s'"), core_path);
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
fclose (fp);
@ -590,13 +584,13 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, _("Try ``%s --help'' for more information.\n"), program_name);
fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
else
printf (_("\
Usage: grub-setup [OPTION]... DEVICE\n\
Usage: %s [OPTION]... DEVICE\n\
\n\
Set up images to boot from DEVICE.\n\
DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\
\n\
-b, --boot-image=FILE use FILE as the boot image [default=%s]\n\
-c, --core-image=FILE use FILE as the core image [default=%s]\n\
@ -611,6 +605,7 @@ DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
\n\
Report bugs to <%s>.\n\
"),
program_name,
DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY,
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
@ -641,9 +636,8 @@ main (int argc, char *argv[])
int must_embed = 0, force = 0, fs_probe = 1;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)
@ -758,7 +752,7 @@ main (int argc, char *argv[])
char *tmp = get_device_name (root_dev);
if (! tmp)
grub_util_error (_("Invalid root device `%s'"), root_dev);
grub_util_error (_("invalid root device `%s'"), root_dev);
tmp = xstrdup (tmp);
free (root_dev);
@ -771,7 +765,7 @@ main (int argc, char *argv[])
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error (_("Cannot guess the root device. Specify the option ``--root-device''."));
grub_util_error (_("cannot guess the root device. Specify the option `--root-device'"));
}
}

View file

@ -37,6 +37,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t
grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -163,6 +164,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = x -a "x$modules" = x; then

View file

@ -131,12 +131,12 @@ block_device_get_sysfs_path_and_link(const char *devicenode,
snprintf(sysfs_path, sysfs_path_len, "/sys/block/%s", devicenode);
if (!realpath (sysfs_path, rpath))
grub_util_error ("Cannot get the real path of `%s'", sysfs_path);
grub_util_error ("cannot get the real path of `%s'", sysfs_path);
strcat(rpath, "/device");
if (!realpath (rpath, sysfs_path))
grub_util_error ("Cannot get the real path of `%s'", rpath);
grub_util_error ("cannot get the real path of `%s'", rpath);
free (rpath);
}
@ -247,12 +247,12 @@ vendor_is_ATA(const char *path)
snprintf(buf, PATH_MAX, "%s/vendor", path);
fd = open(buf, O_RDONLY);
if (fd < 0)
grub_util_error ("Cannot open 'vendor' node of `%s'", path);
grub_util_error ("cannot open 'vendor' node of `%s'", path);
memset(buf, 0, PATH_MAX);
err = read(fd, buf, PATH_MAX);
if (err < 0)
grub_util_error ("Cannot read 'vendor' node of `%s'", path);
grub_util_error ("cannot read 'vendor' node of `%s'", path);
close(fd);
@ -288,7 +288,7 @@ check_sas (char *sysfs_path, int *tgt)
fd = open(path, O_RDONLY);
if (fd < 0)
grub_util_error("Cannot open SAS PHY ID '%s'\n", path);
grub_util_error("cannot open SAS PHY ID `%s'\n", path);
memset (phy, 0, sizeof (phy));
read (fd, phy, sizeof (phy));
@ -375,7 +375,7 @@ grub_util_devname_to_ofpath (char *devname)
name_buf = xmalloc (PATH_MAX);
name_buf = realpath (devname, name_buf);
if (! name_buf)
grub_util_error ("Cannot get the real path of `%s'", devname);
grub_util_error ("cannot get the real path of `%s'", devname);
device = get_basename (devname);
devnode = strip_trailing_digits (devname);

View file

@ -61,12 +61,30 @@ mdblocksizes = {"_gcry_digest_spec_crc32" : 64,
"_gcry_digest_spec_tiger" : 64,
"_gcry_digest_spec_whirlpool" : 64}
cryptolist = open (os.path.join (cipher_dir_out, "crypto.lst"), "w")
# rijndael is the only cipher using aliases. So no need for mangling, just
# hardcode it
cryptolist.write ("RIJNDAEL: gcry_rijndael\n");
cryptolist.write ("RIJNDAEL192: gcry_rijndael\n");
cryptolist.write ("RIJNDAEL256: gcry_rijndael\n");
cryptolist.write ("AES128: gcry_rijndael\n");
cryptolist.write ("AES-128: gcry_rijndael\n");
cryptolist.write ("AES-192: gcry_rijndael\n");
cryptolist.write ("AES-256: gcry_rijndael\n");
for cipher_file in cipher_files:
infile = os.path.join (cipher_dir_in, cipher_file)
outfile = os.path.join (cipher_dir_out, cipher_file)
if cipher_file == "ChangeLog":
continue
chlognew = " * %s" % cipher_file
if re.match ("(Manifest|Makefile\.am|ac\.c|cipher\.c|hash-common\.c|hmac-tests\.c|md\.c|pubkey\.c)$", cipher_file):
chlog = "%s%s: Removed\n" % (chlog, chlognew)
continue
# Autogenerated files. Not even worth mentionning in ChangeLog
if re.match ("Makefile\.in$", cipher_file):
continue
nch = False
if re.match (".*\.[ch]$", cipher_file):
isc = re.match (".*\.c$", cipher_file)
@ -80,8 +98,21 @@ for cipher_file in cipher_files:
skip = False
skip2 = False
ismd = False
iscryptostart = False
iscomma = False
isglue = False
skip_statement = False
if isc:
modname = cipher_file [0:len(cipher_file) - 2]
if re.match (".*-glue$", modname):
modname = modname.replace ("-glue", "")
isglue = True
modname = "gcry_%s" % modname
for line in f:
if skip_statement:
if not re.search (";", line) is None:
skip_statement = False
continue
if skip:
if line[0] == "}":
skip = False
@ -90,6 +121,12 @@ for cipher_file in cipher_files:
if not re.search (" *};", line) is None:
skip2 = False
continue
if iscryptostart:
s = re.search (" *\"([A-Z0-9_a-z]*)\"", line)
if not s is None:
sg = s.groups()[0]
cryptolist.write (("%s: %s\n") % (sg, modname))
iscryptostart = False
if ismd:
if not re.search (" *};", line) is None:
if not mdblocksizes.has_key (mdname):
@ -100,10 +137,22 @@ for cipher_file in cipher_files:
fw.write (" .blocksize = %s\n" % mdblocksizes [mdname])
ismd = False
iscomma = not re.search (",$", line) is None
# Used only for selftests.
m = re.match ("(static byte|static unsigned char) (weak_keys_chksum)\[[0-9]*\] =", line)
if not m is None:
skip = True
fname = m.groups ()[1]
chmsg = "(%s): Removed." % fname
if nch:
chlognew = "%s\n %s" % (chlognew, chmsg)
else:
chlognew = "%s %s" % (chlognew, chmsg)
nch = True
continue
if hold:
hold = False
# We're optimising for size.
if not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None:
if not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer|tripledes_set2keys|do_tripledes_set_extra_info)", line) is None:
skip = True
fname = re.match ("[a-zA-Z0-9_]*", line).group ()
chmsg = "(%s): Removed." % fname
@ -127,16 +176,20 @@ for cipher_file in cipher_files:
continue
m = re.match ("gcry_cipher_spec_t", line)
if isc and not m is None:
assert (not iscryptostart)
ciphername = line [len ("gcry_cipher_spec_t"):].strip ()
ciphername = re.match("[a-zA-Z0-9_]*",ciphername).group ()
ciphernames.append (ciphername)
iscryptostart = True
m = re.match ("gcry_md_spec_t", line)
if isc and not m is None:
assert (not ismd)
assert (not iscryptostart)
mdname = line [len ("gcry_md_spec_t"):].strip ()
mdname = re.match("[a-zA-Z0-9_]*",mdname).group ()
mdnames.append (mdname)
ismd = True
iscryptostart = True
m = re.match ("static const char \*selftest.*;$", line)
if not m is None:
fname = line[len ("static const char \*"):]
@ -148,11 +201,18 @@ for cipher_file in cipher_files:
chlognew = "%s %s" % (chlognew, chmsg)
nch = True
continue
m = re.match ("(static const char( |)\*|static gpg_err_code_t|void)$", line)
m = re.match ("(static const char( |)\*|static gpg_err_code_t|void|static int|static gcry_err_code_t)$", line)
if not m is None:
hold = True
holdline = line
continue
m = re.match ("static int tripledes_set2keys \(.*\);", line)
if not m is None:
continue
m = re.match ("static int tripledes_set2keys \(", line)
if not m is None:
skip_statement = True
continue
m = re.match ("cipher_extra_spec_t", line)
if isc and not m is None:
skip2 = True
@ -179,14 +239,11 @@ for cipher_file in cipher_files:
continue
fw.write (line)
if len (ciphernames) > 0 or len (mdnames) > 0:
modname = cipher_file [0:len(cipher_file) - 2]
if re.match (".*-glue$", modname):
modfiles = "libgcrypt-grub/cipher/%s libgcrypt-grub/cipher/%s" \
if isglue:
modfiles = "lib/libgcrypt-grub/cipher/%s lib/libgcrypt-grub/cipher/%s" \
% (cipher_file, cipher_file.replace ("-glue.c", ".c"))
modname = modname.replace ("-glue", "")
else:
modfiles = "libgcrypt-grub/cipher/%s" % cipher_file
modname = "gcry_%s" % modname
modfiles = "lib/libgcrypt-grub/cipher/%s" % cipher_file
chmsg = "(GRUB_MOD_INIT(%s)): New function\n" % modname
if nch:
chlognew = "%s\n %s" % (chlognew, chmsg)
@ -220,7 +277,7 @@ for cipher_file in cipher_files:
conf.write ("pkglib_MODULES += %s.mod\n" % modname)
conf.write ("%s_mod_SOURCES = %s\n" %\
(modname, modfiles))
conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error\n" % modname)
conf.write ("%s_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap\n" % modname)
conf.write ("%s_mod_LDFLAGS = $(COMMON_LDFLAGS)\n\n" % modname)
elif isc and cipher_file != "camellia.c":
print ("WARNING: C file isn't a module: %s" % cipher_file)
@ -229,26 +286,22 @@ for cipher_file in cipher_files:
if nch:
chlog = "%s%s\n" % (chlog, chlognew)
continue
if re.match ("(Manifest|Makefile\.am)$", cipher_file):
chlog = "%s%sRemoved\n" % (chlog, chlognew)
continue
# Autogenerated files. Not even worth mentionning in ChangeLog
if re.match ("Makefile\.in$", cipher_file):
chlog = "%s%sRemoved\n" % (chlog, chlognew)
continue
chlog = "%s%sSkipped unknown file\n" % (chlog, chlognew)
print ("WARNING: unknown file %s" % cipher_file)
cryptolist.close ()
chlog = "%s * crypto.lst: New file.\n" % chlog
outfile = os.path.join (cipher_dir_out, "types.h")
fw=open (outfile, "w")
fw.write ("#include <grub/types.h>\n")
fw.write ("#include <grub/cipher_wrap.h>\n")
fw.write ("#include <cipher_wrap.h>\n")
chlog = "%s * types.h: New file.\n" % chlog
fw.close ()
outfile = os.path.join (cipher_dir_out, "memory.h")
fw=open (outfile, "w")
fw.write ("#include <grub/cipher_wrap.h>\n")
fw.write ("#include <cipher_wrap.h>\n")
chlog = "%s * memory.h: New file.\n" % chlog
fw.close ()
@ -256,13 +309,13 @@ fw.close ()
outfile = os.path.join (cipher_dir_out, "cipher.h")
fw=open (outfile, "w")
fw.write ("#include <grub/crypto.h>\n")
fw.write ("#include <grub/cipher_wrap.h>\n")
fw.write ("#include <cipher_wrap.h>\n")
chlog = "%s * cipher.h: Likewise.\n" % chlog
fw.close ()
outfile = os.path.join (cipher_dir_out, "g10lib.h")
fw=open (outfile, "w")
fw.write ("#include <grub/cipher_wrap.h>\n")
fw.write ("#include <cipher_wrap.h>\n")
chlog = "%s * g10lib.h: Likewise.\n" % chlog
fw.close ()

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2002,2003,2005,2006,2007,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
@ -38,6 +38,7 @@
#include <grub/mm.h>
#include <grub/term.h>
#include <grub/time.h>
#include <grub/i18n.h>
#include "progname.h"
@ -59,11 +60,12 @@ grub_util_warn (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: warn: ", program_name);
fprintf (stderr, _("%s: warn:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fprintf (stderr, ".\n");
fflush (stderr);
}
@ -74,11 +76,12 @@ grub_util_info (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: info: ", program_name);
fprintf (stderr, _("%s: info:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fprintf (stderr, ".\n");
fflush (stderr);
}
}
@ -88,11 +91,12 @@ grub_util_error (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: error: ", program_name);
fprintf (stderr, _("%s: error:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fprintf (stderr, ".\n");
exit (1);
}
@ -478,6 +482,19 @@ fail:
#endif /* __MINGW32__ */
char *
canonicalize_file_name (const char *path)
{
char *ret;
#ifdef PATH_MAX
ret = xmalloc (PATH_MAX);
(void) realpath (path, ret);
#else
ret = realpath (path, NULL);
#endif
return ret;
}
/* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */
char *
@ -490,15 +507,11 @@ make_system_path_relative_to_its_root (const char *path)
size_t len;
/* canonicalize. */
p = realpath (path, NULL);
p = canonicalize_file_name (path);
if (p == NULL)
{
if (errno != EINVAL)
grub_util_error ("failed to get realpath of %s", path);
else
grub_util_error ("realpath not supporting (path, NULL)");
}
grub_util_error ("failed to get canonical path of %s", path);
len = strlen (p) + 1;
buf = strdup (p);
free (p);
@ -566,3 +579,13 @@ make_system_path_relative_to_its_root (const char *path)
return buf3;
}
void
grub_util_init_nls (void)
{
#if ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* ENABLE_NLS */
}

View file

@ -8,7 +8,7 @@
#define PREPARER_DEFAULT NULL
#define PUBLISHER_DEFAULT NULL
#ifndef APPID_DEFAULT
#define APPID_DEFAULT "MKISOFS ISO 9660 FILESYSTEM BUILDER"
#define APPID_DEFAULT PACKAGE_NAME " ISO 9660 filesystem builder"
#endif
#define COPYRIGHT_DEFAULT NULL
#define BIBLIO_DEFAULT NULL
@ -17,38 +17,4 @@
#define VOLUME_ID_DEFAULT "CDROM"
#define BOOT_CATALOG_DEFAULT "boot.catalog"
#define BOOT_IMAGE_DEFAULT NULL
#ifdef __QNX__
#define SYSTEM_ID_DEFAULT "QNX"
#endif
#ifdef __osf__
#define SYSTEM_ID_DEFAULT "OSF"
#endif
#ifdef __sun
#ifdef __SVR4
#define SYSTEM_ID_DEFAULT "Solaris"
#else
#define SYSTEM_ID_DEFAULT "SunOS"
#endif
#endif
#ifdef __hpux
#define SYSTEM_ID_DEFAULT "HP-UX"
#endif
#ifdef __sgi
#define SYSTEM_ID_DEFAULT "SGI"
#endif
#ifdef _AIX
#define SYSTEM_ID_DEFAULT "AIX"
#endif
#ifdef _WIN
#define SYSTEM_ID_DEFAULT "Win32"
#endif /* _WIN */
#ifndef SYSTEM_ID_DEFAULT
#define SYSTEM_ID_DEFAULT "LINUX"
#endif
#define SYSTEM_ID_DEFAULT "GNU"

View file

@ -288,7 +288,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
struct eltorito_boot_info bi_table;
bootimage = fopen (de->whole_name, "r+b");
if (bootimage == NULL)
error (1, errno, _("Error opening boot image file '%s' for update"),
error (1, errno, _("Error opening boot image file `%s' for update"),
de->whole_name);
/* Compute checksum of boot image, sans 64 bytes */
total_len = 0;
@ -296,7 +296,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
while ((len = fread (csum_buffer, 1, SECTOR_SIZE, bootimage)) > 0)
{
if (total_len & 3)
error (1, 0, _("Odd alignment at non-end-of-file in boot image '%s'"),
error (1, 0, _("Odd alignment at non-end-of-file in boot image `%s'"),
de->whole_name);
if (total_len < 64)
memset (csum_buffer, 0, 64 - total_len);
@ -308,7 +308,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
}
if (total_len != de->size)
error (1, 0, _("Boot image file '%s' changed unexpectedly"),
error (1, 0, _("Boot image file `%s' changed unexpectedly"),
de->whole_name);
/* End of file, set position to byte 8 */
fseeko (bootimage, (off_t) 8, SEEK_SET);

View file

@ -6,7 +6,7 @@
Copyright 1993 Yggdrasil Computing, Incorporated
Copyright (C) 2009 Free Software Foundation, Inc.
Copyright (C) 2009,2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -26,12 +26,7 @@
#include "config.h"
#include "mkisofs.h"
#include "match.h"
#ifdef linux
#include <getopt.h>
#else
#include "getopt.h"
#endif
#include "iso9660.h"
#include <ctype.h>
@ -490,7 +485,7 @@ void usage(){
int comma;
int len;
unsigned int j;
char *arg;
const char *arg;
printf (" ");
@ -645,9 +640,11 @@ int FDECL2(main, int, argc, char **, argv){
char *log_file = 0;
set_program_name (argv[0]);
#if ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* ENABLE_NLS */
if (argc < 2)
usage();
@ -912,7 +909,7 @@ int FDECL2(main, int, argc, char **, argv){
exit (0);
break;
case OPTION_VERSION:
printf ("%s (%s %s)\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
exit (0);
break;
case OPTION_NOSPLIT_SL_COMPONENT:

View file

@ -5,7 +5,7 @@
Copyright 1993 Yggdrasil Computing, Incorporated
Copyright (C) 2009 Free Software Foundation, Inc.
Copyright (C) 2009,2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -30,8 +30,21 @@
#include <prototyp.h>
#include <sys/stat.h>
#include <locale.h>
#include <libintl.h>
#if ENABLE_NLS
# include <locale.h>
# include <libintl.h>
#else /* ! ENABLE_NLS */
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
#endif /* ENABLE_NLS */
#define _(str) gettext(str)
#define N_(str) str

View file

@ -5,7 +5,7 @@
Copyright 1993 Yggdrasil Computing, Incorporated
Copyright (C) 2009 Free Software Foundation, Inc.
Copyright (C) 2009,2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -306,7 +306,7 @@ int deep_opt;
* the symbolic link won't fit into one SL System Use Field
* print an error message and continue with splited one
*/
fprintf(stderr, _("symbolic link ``%s'' to long for one SL System Use Field, splitting"), cpnt);
fprintf (stderr, _("symbolic link `%s' too long for one SL System Use Field, splitting"), cpnt);
}
if(MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes)) add_CE_entry();
}

View file

@ -158,7 +158,7 @@ void FDECL4(xfwrite, void *, buffer, uint64_t, count, uint64_t, size, FILE *, fi
sprintf(nbuf, "%s_%02d", outfile, idx++);
file = freopen(nbuf, "wb", file);
if (file == NULL)
error (1, errno, _("Cannot open '%s'"), nbuf);
error (1, errno, _("Cannot open `%s'"), nbuf);
}
while(count)
@ -1437,7 +1437,9 @@ static int FDECL1(padblock_write, FILE *, outfile)
if (! fp)
error (1, errno, _("Unable to open %s"), boot_image_embed);
fread (buffer, 2048 * PADBLOCK_SIZE, 1, fp);
if (fread (buffer, 1, 2048 * PADBLOCK_SIZE, fp) == 0)
error (1, errno, _("cannot read %d bytes from %s"),
2048 * PADBLOCK_SIZE, boot_image_embed);
if (fgetc (fp) != EOF)
error (1, 0, _("%s is too big for embed area"), boot_image_embed);
}

View file

@ -50,7 +50,7 @@ grub_util_getdiskname (int major, int minor)
else if (major == SCSI_DISK0_MAJOR)
sprintf (name, "/dev/sd%c", 'a' + minor / 16);
else
grub_util_error ("Unknown device number: %d, %d", major, minor);
grub_util_error ("unknown device number: %d, %d", major, minor);
return name;
}
@ -72,7 +72,7 @@ grub_util_raid_getmembers (char *name)
fd = open (devname, O_RDONLY);
if (fd == -1)
grub_util_error ("Can't open %s: %s", devname, strerror (errno));
grub_util_error ("can't open %s: %s", devname, strerror (errno));
free (devname);
@ -81,7 +81,7 @@ grub_util_raid_getmembers (char *name)
grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno));
if (version.major != 0 || version.minor != 90)
grub_util_error ("Unsupported RAID version: %d.%d",
grub_util_error ("unsupported RAID version: %d.%d",
version.major, version.minor);
ret = ioctl (fd, GET_ARRAY_INFO, &info);

View file

@ -1,7 +1,7 @@
/* grub-mkimage.c - make a bootable image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
* 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
@ -191,7 +191,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... [MODULES]\n\
@ -222,9 +222,8 @@ main (int argc, char *argv[])
FILE *fp = stdout;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while (1)
{

View file

@ -1,7 +1,7 @@
/* grub-ofpathname.c - Find OpenBOOT path for a given device */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 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
@ -29,9 +29,8 @@ int main(int argc, char **argv)
char *of_path;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
if (argc != 2)
{

View file

@ -1,7 +1,7 @@
/* grub-setup.c - make GRUB usable */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,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
@ -161,7 +161,7 @@ setup (const char *prefix, const char *dir,
grub_util_info ("first sector is <%llu,%u,%u>", sector, offset, length);
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The first sector of the core file "
grub_util_error ("the first sector of the core file "
"is not sector-aligned");
first_sector = sector;
@ -176,7 +176,7 @@ setup (const char *prefix, const char *dir,
grub_util_info ("saving <%llu,%u,%u>", sector, offset, length);
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Non-sector-aligned data is found in the core file");
grub_util_error ("non-sector-aligned data is found in the core file");
if (block != first_block
&& (grub_be_to_cpu64 (prev->start)
@ -189,7 +189,7 @@ setup (const char *prefix, const char *dir,
block--;
if (block->len)
grub_util_error ("The sectors of the core file are too fragmented");
grub_util_error ("the sectors of the core file are too fragmented");
}
last_length = length;
@ -201,7 +201,7 @@ setup (const char *prefix, const char *dir,
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The size of `%s' is not %d",
grub_util_error ("the size of `%s' is not %d",
boot_path, GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
@ -219,7 +219,7 @@ setup (const char *prefix, const char *dir,
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
if (core_size < GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The size of `%s' is too small", core_path);
grub_util_error ("the size of `%s' is too small", core_path);
core_img = grub_util_read_image (core_path);
free (core_path);
@ -229,7 +229,7 @@ setup (const char *prefix, const char *dir,
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
grub_util_info ("root is '%s', dest is '%s', and dest_ofpath is '%s'",
grub_util_info ("root is `%s', dest is `%s', and dest_ofpath is `%s'",
root, dest, dest_ofpath);
/* Open the root device and the destination device. */
@ -320,7 +320,7 @@ setup (const char *prefix, const char *dir,
}
if (i == MAX_TRIES)
grub_util_error ("Cannot read `%s' correctly", core_path);
grub_util_error ("cannot read `%s' correctly", core_path);
/* Clean out the blocklists. */
block = first_block;
@ -332,7 +332,7 @@ setup (const char *prefix, const char *dir,
block--;
if ((char *) block <= core_img)
grub_util_error ("No terminator in the core image");
grub_util_error ("no terminator in the core image");
}
/* Now read the core image to determine where the sectors are. */
@ -343,13 +343,13 @@ setup (const char *prefix, const char *dir,
file->read_hook = save_first_sector;
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Failed to read the first sector of the core image");
grub_util_error ("failed to read the first sector of the core image");
block = first_block;
file->read_hook = save_blocklists;
if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Failed to read the rest sectors of the core image");
grub_util_error ("failed to read the rest sectors of the core image");
grub_file_close (file);
@ -368,7 +368,7 @@ setup (const char *prefix, const char *dir,
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
if (! fp)
grub_util_error ("Cannot open `%s'", core_path);
grub_util_error ("cannot open `%s'", core_path);
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE, fp);
fclose (fp);
@ -404,13 +404,13 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... DEVICE\n\
\n\
Set up images to boot from DEVICE.\n\
DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\
\n\
-b, --boot-image=FILE use FILE as the boot image [default=%s]\n\
-c, --core-image=FILE use FILE as the core image [default=%s]\n\
@ -559,14 +559,14 @@ find_dest_dev (struct grub_setup_info *gp, char *argv[])
fprintf (stderr, "Invalid device `%s'.\n", argv[optind]);
usage (1);
}
grub_util_info ("transformed OS device '%s' into GRUB device '%s'",
grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
argv[optind], gp->dest_dev);
}
else
{
/* For simplicity. */
gp->dest_dev = xstrdup (gp->dest_dev);
grub_util_info ("Using '%s' as GRUB device", gp->dest_dev);
grub_util_info ("Using `%s' as GRUB device", gp->dest_dev);
}
}
@ -578,7 +578,7 @@ check_root_dev (struct grub_setup_info *gp)
char *tmp = get_device_name (gp->root_dev);
if (! tmp)
grub_util_error ("Invalid root device `%s'", gp->root_dev);
grub_util_error ("invalid root device `%s'", gp->root_dev);
tmp = xstrdup (tmp);
free (gp->root_dev);
@ -594,11 +594,11 @@ check_root_dev (struct grub_setup_info *gp)
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("Cannot guess the root device. "
"Specify the option ``--root-device''.");
grub_util_error ("cannot guess the root device. "
"Specify the option `--root-device'");
}
grub_util_info ("Guessed root device '%s' and root_dev '%s' from "
"dir '%s'", root_device, gp->root_dev, dir);
grub_util_info ("guessed root device `%s' and root_dev `%s' from "
"dir `%s'", root_device, gp->root_dev, dir);
}
}
@ -620,9 +620,8 @@ main (int argc, char *argv[])
struct grub_setup_info ginfo;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
init_info (&ginfo);
if (!parse_options (&ginfo, argc, argv))