merge mainline into rescue-efi

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-04-17 02:32:05 +02:00
commit 1989170fd5
596 changed files with 57408 additions and 15601 deletions

127
util/bin2h.c Normal file
View file

@ -0,0 +1,127 @@
/*
* 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\
Convert a binary file to a C header.\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);
@ -264,10 +264,17 @@ find_root_device (const char *dir, dev_t dev)
/* Found! */
char *res;
char *cwd;
#if defined(__NetBSD__)
/* Convert this block device to its character (raw) device. */
const char *template = "%s/r%s";
#else
/* Keep the device name as it is. */
const char *template = "%s/%s";
#endif
cwd = xgetcwd ();
res = xmalloc (strlen (cwd) + strlen (ent->d_name) + 2);
sprintf (res, "%s/%s", cwd, ent->d_name);
res = xmalloc (strlen (cwd) + strlen (ent->d_name) + 3);
sprintf (res, template, cwd, ent->d_name);
strip_extra_slashes (res);
free (cwd);
@ -279,7 +286,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 +295,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 +452,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. */
@ -460,7 +467,8 @@ grub_guess_root_device (const char *dir)
return os_dev;
}
int
static int
grub_util_is_dmraid (const char *os_dev)
{
if (! strncmp (os_dev, "/dev/mapper/nvidia_", 19))
@ -483,12 +491,12 @@ grub_util_is_dmraid (const char *os_dev)
return 1;
else if (! strncmp (os_dev, "/dev/mapper/sil_", 16))
return 1;
return 0;
}
int
grub_util_get_dev_abstraction (const char *os_dev UNUSED)
grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused)))
{
#ifdef __linux__
/* Check for LVM. */
@ -546,7 +554,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q)
*q = ',';
asprintf (&grub_dev, "md%s", p);
grub_dev = xasprintf ("md%s", p);
free (p);
}
else if (os_dev[7] == '/' && os_dev[8] == 'd')
@ -561,7 +569,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q)
*q = ',';
asprintf (&grub_dev, "md%s", p);
grub_dev = xasprintf ("md%s", p);
free (p);
}
else if (os_dev[7] >= '0' && os_dev[7] <= '9')
@ -574,7 +582,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q)
*q = ',';
asprintf (&grub_dev, "md%s", p);
grub_dev = xasprintf ("md%s", p);
free (p);
}
else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
@ -587,11 +595,11 @@ grub_util_get_grub_dev (const char *os_dev)
if (q)
*q = ',';
asprintf (&grub_dev, "md%s", p);
grub_dev = xasprintf ("md%s", p);
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 +616,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 +630,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);
}
@ -107,7 +104,7 @@ create_envblk_file (const char *name)
if (! buf)
grub_util_error ("out of memory");
asprintf (&namenew, "%s.new", name);
namenew = xasprintf ("%s.new", name);
fp = fopen (namenew, "wb");
if (! fp)
grub_util_error ("cannot open the file %s", namenew);
@ -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
@ -38,8 +38,7 @@
#include <grub/partition.h>
#include <grub/i18n.h>
#include <grub_emu_init.h>
#define ENABLE_RELOCATABLE 0
#include "progname.h"
/* Used for going back to the main function. */
@ -51,9 +50,10 @@ static char *prefix = NULL;
grub_addr_t
grub_arch_modules_addr (void)
{
return NULL;
return 0;
}
#if GRUB_NO_MODULES
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
@ -70,6 +70,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
return GRUB_ERR_BAD_MODULE;
}
#endif
void
grub_reboot (void)
@ -106,10 +107,6 @@ grub_machine_fini (void)
grub_console_fini ();
}
void
read_command_list (void)
{
}
static struct option options[] =
@ -129,10 +126,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,11 +141,20 @@ 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;
}
void grub_hostfs_init (void);
void grub_hostfs_fini (void);
void grub_host_init (void);
void grub_host_fini (void);
#if GRUB_NO_MODULES
void grub_init_all (void);
void grub_fini_all (void);
#endif
int
main (int argc, char *argv[])
{
@ -159,9 +165,6 @@ main (int argc, char *argv[])
int opt;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
switch (opt)
@ -210,29 +213,36 @@ main (int argc, char *argv[])
signal (SIGINT, SIG_IGN);
grub_console_init ();
grub_host_init ();
grub_hostfs_init ();
/* XXX: This is a bit unportable. */
grub_util_biosdisk_init (dev_map);
#if GRUB_NO_MODULES
grub_init_all ();
#endif
/* Make sure that there is a root device. */
if (! root_dev)
{
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'");
}
}
dir = grub_get_prefix (dir);
if (strcmp (root_dev, "host") == 0)
dir = xstrdup (dir);
else
dir = grub_get_prefix (dir);
prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
sprintf (prefix, "(%s)%s", root_dev, dir);
free (dir);
@ -241,7 +251,11 @@ main (int argc, char *argv[])
if (setjmp (main_env) == 0)
grub_main ();
#if GRUB_NO_MODULES
grub_fini_all ();
#endif
grub_hostfs_fini ();
grub_host_fini ();
grub_machine_fini ();

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);
}
@ -85,7 +85,7 @@ execute_command (char *name, int n, char **args)
#define BUF_SIZE 32256
static grub_off_t skip, leng;
static grub_disk_addr_t skip, leng;
static void
read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
@ -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 %d.");
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);
@ -278,21 +278,31 @@ cmd_crc (char *pathname)
static void
fstest (char **images, int num_disks, int cmd, int n, char **args)
{
char host_file[128];
char loop_name[8];
char *argv[3] = { "-p", loop_name, host_file};
char *host_file;
char *loop_name;
char *argv[3];
int i;
argv[0] = "-p";
for (i = 0; i < num_disks; i++)
{
if (grub_strlen (images[i]) + 7 > sizeof (host_file))
grub_util_error ("Pathname %s too long.", images[i]);
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
grub_sprintf (loop_name, "loop%d", i);
grub_sprintf (host_file, "(host)%s", images[i]);
host_file = grub_xasprintf ("(host)%s", images[i]);
if (!host_file)
grub_util_error (grub_errmsg);
argv[1] = loop_name;
argv[2] = host_file;
if (execute_command ("loopback", 3, argv))
grub_util_error ("loopback command fails.");
grub_util_error ("loopback command fails");
grub_free (loop_name);
grub_free (host_file);
}
grub_lvm_fini ();
@ -328,8 +338,15 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
for (i = 0; i < num_disks; i++)
{
grub_sprintf (loop_name, "loop%d", i);
loop_name = grub_xasprintf ("loop%d", i);
if (!loop_name)
grub_util_error (grub_errmsg);
argv[1] = loop_name;
execute_command ("loopback", 2, argv);
grub_free (loop_name);
}
}
@ -349,7 +366,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\
@ -384,9 +401,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

@ -29,16 +29,20 @@ PACKAGE_TARNAME=@PACKAGE_TARNAME@
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}`
localedir=@datadir@/locale
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; 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=
@ -51,6 +55,8 @@ debug=no
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
disk_module=biosdisk
elif [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
disk_module=
else
disk_module=ata
fi
@ -79,14 +85,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
@ -103,6 +116,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=*)
@ -144,7 +159,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
@ -177,7 +192,7 @@ device_map=${grubdir}/device.map
grub_probe="${grub_probe} --device-map=${device_map}"
# Check if GRUB is installed.
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
set $grub_setup dummy
if test -f "$1"; then
:
@ -204,8 +219,7 @@ else
fi
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
mkdir -p "$grubdir" || exit 1
# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
@ -239,7 +253,7 @@ done
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do
if test -f $file; then
cp -f $file ${grubdir} || exit 1
@ -247,8 +261,20 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
done
fi
# Copy gettext files
mkdir -p ${grubdir}/locale/
for dir in ${localedir}/*; do
if test -f "$dir/LC_MESSAGES/grub.mo"; then
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
fi
done
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
grub_device=`$grub_probe --target=device ${grubdir}` || exit 1
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}`
@ -261,7 +287,10 @@ fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
partmap_module=
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
partmap_module="$partmap_module part_$x";
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
@ -270,17 +299,26 @@ devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
modules="$modules $disk_module"
modules="$modules $fs_module $partmap_module $devabstraction_module"
relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
if [ "x${relative_grubdir}" = "x" ] ; then
relative_grubdir=/
fi
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}`" || exit 1
fi
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
fi
grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
grub_drive="`$grub_probe --target=drive --device ${grub_device}`" || exit 1
# 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)
@ -289,34 +327,35 @@ if [ "x${devabstraction_module}" = "x" ] ; then
echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
exit 1
fi
prefix_drive="(UUID=${uuid})"
modules="$modules fs_uuid"
echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
config_opt="-c ${grubdir}/load.cfg "
modules="$modules search_fs_uuid"
elif [ "x${grub_drive}" != "x${install_drive}" ] ; then
uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
if [ "x${uuid}" = "x" ] ; then
echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
exit 1
fi
prefix_drive="(UUID=${uuid})"
modules="$modules fs_uuid"
echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg
echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg
config_opt="-c ${grubdir}/load.cfg "
modules="$modules search_fs_uuid"
fi
else
prefix_drive=`$grub_probe --target=drive --device ${grub_device}`
prefix_drive=`$grub_probe --target=drive --device ${grub_device}` || exit 1
fi
relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
if [ "x${relative_grubdir}" = "x" ] ; then
relative_grubdir=/
fi
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
$grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
$grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
# 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 -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
$grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
fi
echo "Installation finished. No error reported."

View file

@ -140,64 +140,73 @@ if [ "x${GRUB_TERMINAL}" != "x" ] ; then
GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
fi
case x${GRUB_TERMINAL_OUTPUT} in
x | xgfxterm)
# If this platform supports gfxterm, try to use it.
if test -e ${grub_prefix}/gfxterm.mod ; then
GRUB_VIDEO_BACKEND=
for i in vbe ; do
if test -e ${grub_prefix}/$i.mod ; then
GRUB_VIDEO_BACKEND=$i
break
fi
done
if [ -n "${GRUB_VIDEO_BACKEND}" ] ; then
GRUB_TERMINAL_OUTPUT=gfxterm
elif [ "${GRUB_TERMINAL_OUTPUT}" = "gfxterm" ] ; then
echo "No suitable backend could be found for gfxterm." >&2 ; exit 1
fi
fi
;;
xconsole | xserial | xofconsole) ;;
*) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
esac
termoutdefault=0
if [ "x${GRUB_TERMINAL_OUTPUT}" == x ]; then
GRUB_TERMINAL_OUTPUT=gfxterm;
termoutdefault=1;
fi
# check for terminals that require fonts
case ${GRUB_TERMINAL_OUTPUT} in
gfxterm)
if [ -n "$GRUB_FONT" ] ; then
if is_path_readable_by_grub ${GRUB_FONT} > /dev/null ; then
GRUB_FONT_PATH=${GRUB_FONT}
else
echo "No such font or not readable by grub: ${GRUB_FONT}" >&2
exit 1
for x in ${GRUB_TERMINAL_OUTPUT}; do
if [ x${x} == xgfxterm ]; then
# If this platform supports gfxterm, try to use it.
if ! test -e ${grub_prefix}/gfxterm.mod ; then
if [ "x$termoutdefault" != "x1" ]; then
echo "gfxterm isn't available on your platform" >&2 ; exit 1
fi
GRUB_TERMINAL_OUTPUT=
break;
fi
# FIXME: this should do something smarter than just loading first
# video backend.
GRUB_VIDEO_BACKEND=$(head -n 1 ${grub_prefix}/video.lst || true)
if [ -z "${GRUB_VIDEO_BACKEND}" ] ; then
if [ "x$termoutdefault" != "x1" ]; then
echo "No suitable backend could be found for gfxterm." >&2 ; exit 1
fi
GRUB_TERMINAL_OUTPUT=
fi
if [ -n "$GRUB_FONT" ] ; then
if is_path_readable_by_grub ${GRUB_FONT} > /dev/null ; then
GRUB_FONT_PATH=${GRUB_FONT}
else
echo "No such font or not readable by grub: ${GRUB_FONT}" >&2
exit 1
fi
else
for dir in ${pkgdatadir} /boot/grub /usr/share/grub ; do
for basename in unicode unifont ascii; do
path="${dir}/${basename}.pf2"
if is_path_readable_by_grub ${path} > /dev/null ; then
GRUB_FONT_PATH=${path}
else
continue
fi
if [ "${basename}" = "ascii" ] ; then
# make sure all our children behave in conformance with ascii..
export LANG=C
fi
break 2
done
done
fi
if [ -z "${GRUB_FONT_PATH}" ] ; then
if [ "x$termoutdefault" != "x1" ]; then
echo "No font for gfxterm found." >&2 ; exit 1
fi
GRUB_TERMINAL_OUTPUT=
fi
else
for dir in ${pkgdatadir} /boot/grub /usr/share/grub ; do
for basename in unicode unifont ascii; do
path="${dir}/${basename}.pf2"
if is_path_readable_by_grub ${path} > /dev/null ; then
GRUB_FONT_PATH=${path}
else
continue
fi
if [ "${basename}" = "ascii" ] ; then
# make sure all our children behave in conformance with ascii..
export LANG=C
fi
break 2
done
done
fi
if [ -z "${GRUB_FONT_PATH}" ] ; then
# fallback to the native terminal for this platform
unset GRUB_TERMINAL_OUTPUT
fi
;;
*)
# make sure all our children behave in conformance with ascii..
export LANG=C
esac
done
for x in ${GRUB_TERMINAL_OUTPUT}; do
case "x${x}" in
xgfxterm) ;;
xconsole | xserial | xofconsole)
# make sure all our children behave in conformance with ascii..
export LANG=C;;
*) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
esac
done
# These are defined in this script, export them here so that user can
# override them.
@ -224,7 +233,12 @@ export GRUB_DEFAULT \
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_GFXMODE \
GRUB_DISABLE_OS_PROBER
GRUB_BACKGROUND \
GRUB_THEME \
GRUB_GFXPAYLOAD_LINUX \
GRUB_DISABLE_OS_PROBER \
GRUB_INIT_TUNE \
GRUB_SAVEDEFAULT
if test "x${grub_cfg}" != "x"; then
rm -f ${grub_cfg}.new

View file

@ -24,8 +24,12 @@ bindir=@bindir@
sbindir=@sbindir@
pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
if test "x$grub_probe" = x; then
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
fi
if test "x$grub_mkrelpath" = x; then
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
fi
grub_warn ()
{
@ -90,13 +94,22 @@ convert_system_path_to_grub_path ()
echo ${drive}${relative_path}
}
save_default_entry ()
{
if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
cat << EOF
savedefault
EOF
fi
}
prepare_grub_to_access_device ()
{
device=$1
# Abstraction modules aren't auto-loaded.
abstraction="`${grub_probe} --device ${device} --target=abstraction`"
for module in ${abstraction} ; do
for module in ${abstraction} ; do
echo "insmod ${module}"
done
@ -107,7 +120,7 @@ prepare_grub_to_access_device ()
# If there's a filesystem UUID that GRUB is capable of identifying, use it;
# otherwise set root as per value in device.map.
echo "set root=`${grub_probe} --device ${device} --target=drive`"
echo "set root='`${grub_probe} --device ${device} --target=drive`'"
if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
fi

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
@ -20,6 +20,7 @@
#include <grub/types.h>
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include <grub/fontformat.h>
#include <stdio.h>
#include <stdlib.h>
@ -49,6 +50,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 +66,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 +86,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 +94,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 +104,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 +206,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 +300,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 +332,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 +346,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,14 +388,15 @@ 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;
leng = grub_cpu_to_be32 (4);
grub_util_write_image ("FILE", 4, file);
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE,
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file);
grub_util_write_image ((char *) &leng, 4, file);
grub_util_write_image ("PFF2", 4, file);
grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file);
offset += 12;
if (! font_info->name)
@ -366,23 +415,28 @@ write_font (struct grub_font_info *font_info, char *output_file)
if (! style_name[0])
strcpy (style_name, " Regular");
asprintf (&font_name, "%s %s %d", font_info->name, &style_name[1],
font_info->size);
font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
font_info->size);
write_string_section ("NAME", font_name, &offset, file);
write_string_section ("FAMI", font_info->name, &offset, file);
write_string_section ("WEIG",
write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME,
font_name, &offset, file);
write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY,
font_info->name, &offset, file);
write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT,
(font_info->style & FT_STYLE_FLAG_BOLD) ?
"bold" : "normal",
&offset, file);
write_string_section ("SLAN",
write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN,
(font_info->style & FT_STYLE_FLAG_ITALIC) ?
"italic" : "normal",
&offset, file);
write_be16_section ("PTSZ", font_info->size, &offset, file);
write_be16_section ("MAXW", font_info->max_width, &offset, file);
write_be16_section ("MAXH", font_info->max_height, &offset, file);
write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
font_info->size, &offset, file);
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
font_info->max_width, &offset, file);
write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
font_info->max_height, &offset, file);
if (! font_info->desc)
{
@ -392,15 +446,25 @@ 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);
write_be16_section ("DESC", 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 (FONT_FORMAT_SECTION_NAMES_ASCENT,
font_info->asce, &offset, file);
write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT,
font_info->desc, &offset, file);
if (font_verbosity > 0)
{
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);
}
@ -424,7 +488,9 @@ write_font (struct grub_font_info *font_info, char *output_file)
printf ("Number of glyph: %d\n", num);
leng = grub_cpu_to_be32 (num * 9);
grub_util_write_image ("CHIX", 4, file);
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1,
file);
grub_util_write_image ((char *) &leng, 4, file);
offset += 8 + num * 9 + 8;
@ -440,7 +506,8 @@ write_font (struct grub_font_info *font_info, char *output_file)
}
leng = 0xffffffff;
grub_util_write_image ("DATA", 4, file);
grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA,
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1, file);
grub_util_write_image ((char *) &leng, 4, file);
for (cur = font_info->glyph; cur; cur = cur->next)
@ -458,9 +525,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 +536,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 +596,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 +611,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 +625,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 +641,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 +681,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 +709,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,8 @@
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <grub/machine/memory.h>
#include <grub/elf.h>
#include <grub/aout.h>
#include <grub/i18n.h>
#include <grub/kernel.h>
#include <grub/disk.h>
@ -33,12 +35,15 @@
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define _GNU_SOURCE 1
#include <getopt.h>
#include "progname.h"
#define ALIGN_ADDR(x) (ALIGN_UP((x), GRUB_TARGET_SIZEOF_VOID_P))
#ifdef ENABLE_LZMA
#include <grub/lib/LzmaEnc.h>
@ -94,12 +99,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,15 +130,22 @@ 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_ADDR (grub_util_get_image_size (font_path));
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_ADDR (config_size_pure);
grub_util_info ("the size of config file 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)
total_module_size += (ALIGN_ADDR (grub_util_get_image_size (p->name))
+ sizeof (struct grub_module_header));
grub_util_info ("the total module size is 0x%x", total_module_size);
@ -141,23 +160,25 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
/* Fill in the grub_module_info structure. */
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
memset (modinfo, 0, sizeof (struct grub_module_info));
modinfo->magic = GRUB_MODULE_MAGIC;
modinfo->offset = sizeof (struct grub_module_info);
modinfo->size = total_module_size;
modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info));
modinfo->size = grub_host_to_target_addr (total_module_size);
offset = kernel_size + sizeof (struct grub_module_info);
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_ADDR (orig_size);
header = (struct grub_module_header *) (kernel_img + offset);
memset (header, 0, sizeof (struct grub_module_header));
header->type = OBJ_TYPE_ELF;
header->type = grub_host_to_target32 (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;
@ -169,7 +190,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
header = (struct grub_module_header *) (kernel_img + offset);
memset (header, 0, sizeof (struct grub_module_header));
header->type = OBJ_TYPE_MEMDISK;
header->type = grub_host_to_target32 (OBJ_TYPE_MEMDISK);
header->size = grub_host_to_target32 (memdisk_size + sizeof (*header));
offset += sizeof (*header);
@ -177,19 +198,33 @@ 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 = grub_host_to_target32 (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;
header = (struct grub_module_header *) (kernel_img + offset);
memset (header, 0, sizeof (struct grub_module_header));
header->type = OBJ_TYPE_CONFIG;
header->type = grub_host_to_target32 (OBJ_TYPE_CONFIG);
header->size = grub_host_to_target32 (config_size + sizeof (*header));
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);
@ -198,25 +233,66 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
grub_util_info ("the core size is 0x%x", core_size);
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_host_to_target32 (total_module_size);
#endif
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_host_to_target32 (kernel_size);
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_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)
/* If we included a drive in our prefix, let GRUB know it doesn't have to
prepend the drive told by BIOS. */
if (prefix[0] == '(')
{
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
= grub_host_to_target32 (-2);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
= 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)"),
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
GRUB_MEMORY_MACHINE_UPPER);
#endif
#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 +301,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 +315,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,36 +331,111 @@ 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);
#endif
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_cpu_to_le32 (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);
#endif
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
/* If we included a drive in our prefix, let GRUB know it doesn't have to
prepend the drive told by BIOS. */
if (prefix[0] == '(')
#elif defined (GRUB_MACHINE_SPARC64)
if (format == GRUB_PLATFORM_IMAGE_AOUT)
{
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
= grub_cpu_to_le32 (-2);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
= grub_cpu_to_le32 (-2);
}
#endif
void *aout_img;
size_t aout_size;
struct grub_aout32_header *aout_head;
#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);
aout_size = core_size + sizeof (*aout_head);
aout_img = xmalloc (aout_size);
aout_head = aout_img;
aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
| AOUT32_OMAGIC);
aout_head->a_text = grub_host_to_target32 (core_size);
aout_head->a_entry
= grub_host_to_target32 (GRUB_BOOT_MACHINE_IMAGE_ADDRESS);
memcpy (aout_img + sizeof (*aout_head), core_img, core_size);
free (core_img);
core_img = aout_img;
core_size = aout_size;
}
else
{
unsigned int num;
char *boot_path, *boot_img;
size_t boot_size;
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
num <<= GRUB_DISK_SECTOR_BITS;
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 is not one sector size");
boot_img = grub_util_read_image (boot_path);
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_host_to_target32 (num);
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
}
#elif 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_ADDR (core_size);
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 +459,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 +475,36 @@ 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=%s]\n\
available formats: %s\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,
#ifdef GRUB_PLATFORM_IMAGE_DEFAULT
GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT, GRUB_PLATFORM_IMAGE_FORMATS,
#endif
PACKAGE_BUGREPORT);
exit (status);
}
@ -347,17 +516,20 @@ 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 +543,27 @@ 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
#ifdef GRUB_PLATFORM_IMAGE_AOUT
if (strcmp (optarg, "aout") == 0)
format = GRUB_PLATFORM_IMAGE_AOUT;
else
#endif
usage (1);
break;
#endif
case 'd':
if (dir)
free (dir);
@ -390,6 +583,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 +631,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
@ -27,13 +27,14 @@ 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);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] PATH\n\
@ -55,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

@ -28,6 +28,7 @@ PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
native_platform=@platform@
pkglib_DATA="@pkglib_DATA@"
coreboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-coreboot
pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-pc
@ -87,7 +88,15 @@ if [ "x${output_image}" = x ] ; then
exit 1
fi
iso9660_dir=`mktemp -d`
if test "x$TMP" != x; then
MKTEMP_TEMPLATE="$TMP/grub-mkrescue.XXXXXXXXXX"
elif test "x$TEMP" != x; then
MKTEMP_TEMPLATE="$TEMP/grub-mkrescue.XXXXXXXXXX"
else
MKTEMP_TEMPLATE="/tmp/grub-mkrescue.XXXXXXXXXX"
fi
iso9660_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
mkdir -p ${iso9660_dir}/boot/grub
process_input_dir ()
@ -95,13 +104,23 @@ process_input_dir ()
input_dir="$1"
platform="$2"
mkdir -p ${iso9660_dir}/boot/grub/${target_cpu}-${platform}
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
for file in ${input_dir}/*.mod; do
if test -f "$file"; then
cp -f "$file" ${iso9660_dir}/boot/grub/${target_cpu}-${platform}/
fi
done
for file in ${pkglib_DATA}; do
if test -f "${input_dir}/${file}"; then
cp -f "${input_dir}/${file}" ${iso9660_dir}/boot/grub/${target_cpu}-${platform}/
fi
done
mkdir -p ${iso9660_dir}/boot/grub/locale
for file in ${input_dir}/po/*.mo; do
if test -f "$file"; then
cp -f "$file" ${iso9660_dir}/boot/grub/locale/
fi
done
}
if [ "${override_dir}" = "" ] ; then
@ -133,12 +152,12 @@ fi
# build coreboot core.img
if test -e "${coreboot_dir}" ; then
echo "Generates coreboot"
memdisk_img=`mktemp`
memdisk_dir=`mktemp -d`
echo "Enabling coreboot support ..."
memdisk_img=`mktemp "$MKTEMP_TEMPLATE"`
memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
mkdir -p ${memdisk_dir}/boot/grub
# obtain date-based UUID
iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00)
iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00)
modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}"
cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
@ -149,7 +168,7 @@ EOF
echo "insmod $i"
done ; \
echo "source /boot/grub/grub.cfg") \
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
> ${iso9660_dir}/boot/grub/i386-coreboot/grub.cfg
tar -C ${memdisk_dir} -cf ${memdisk_img} boot
rm -rf ${memdisk_dir}
@ -160,14 +179,17 @@ EOF
grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
fi
# build eltorito core.img
# build BIOS core.img
if test -e "${pc_dir}" ; then
echo "Generates eltorito"
core_img=`mktemp`
echo "Enabling BIOS support ..."
core_img=`mktemp "$MKTEMP_TEMPLATE"`
grub-mkimage -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \
memdisk tar search iso9660 configfile sh \
biosdisk
iso9660 biosdisk
cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img
embed_img=`mktemp "$MKTEMP_TEMPLATE"`
cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
rm -f ${core_img}
modules="$(cat ${pc_dir}/partmap.lst) ${modules}"
@ -177,7 +199,8 @@ if test -e "${pc_dir}" ; then
echo "source /boot/grub/grub.cfg") \
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -boot-info-table"
grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
--embedded-boot ${embed_img}"
fi
# build bootx64.efi
@ -198,7 +221,9 @@ if test -e "${efi64_dir}" ; then
fi
# build iso image
grub-mkisofs ${grub_mkisofs_arguments} -o ${output_image} -r ${iso9660_dir} ${source}
grub-mkisofs ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} ${source}
rm -rf ${iso9660_dir}
rm -f ${embed_img}
exit 0

View file

@ -29,6 +29,8 @@
#include <stdlib.h>
#include <getopt.h>
#include "progname.h"
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
@ -40,7 +42,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 +184,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 +232,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 +250,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 +442,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
@ -82,18 +82,26 @@ grub_refresh (void)
static void
probe_partmap (grub_disk_t disk)
{
grub_partition_t part;
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;
}
printf ("%s\n", disk->partition->partmap->name);
for (part = disk->partition; part; part = part->parent)
printf ("%s\n", part->partmap->name);
}
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;
@ -111,19 +119,19 @@ probe (const char *path, char *device_name)
if (path == NULL)
{
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
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.\n", path);
grub_util_error ("cannot find a device for %s (is /dev mounted?)", path);
if (print == PRINT_DEVICE)
{
@ -133,7 +141,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)
{
@ -238,33 +246,36 @@ probe (const char *path, char *device_name)
if (print == PRINT_FS)
{
struct stat st;
if (path)
{
struct stat st;
stat (path, &st);
stat (path, &st);
if (S_ISREG (st.st_mode))
{
/* Regular file. Verify that we can read it properly. */
if (S_ISREG (st.st_mode))
{
/* Regular file. Verify that we can read it properly. */
grub_file_t file;
char *rel_path;
grub_util_info ("reading %s via OS facilities", path);
filebuf_via_sys = grub_util_read_image (path);
grub_file_t file;
char *rel_path;
grub_util_info ("reading %s via OS facilities", path);
filebuf_via_sys = grub_util_read_image (path);
rel_path = make_system_path_relative_to_its_root (path);
asprintf (&grub_path, "(%s)%s", drive_name, rel_path);
free (rel_path);
grub_util_info ("reading %s via GRUB facilities", grub_path);
file = grub_file_open (grub_path);
if (! file)
grub_util_error ("can not open %s via GRUB facilities", grub_path);
filebuf_via_grub = xmalloc (file->size);
grub_file_read (file, filebuf_via_grub, file->size);
rel_path = make_system_path_relative_to_its_root (path);
grub_path = xasprintf ("(%s)%s", drive_name, rel_path);
free (rel_path);
grub_util_info ("reading %s via GRUB facilities", grub_path);
file = grub_file_open (grub_path);
if (! file)
grub_util_error ("cannot open %s via GRUB facilities", grub_path);
filebuf_via_grub = xmalloc (file->size);
grub_file_read (file, filebuf_via_grub, file->size);
grub_util_info ("comparing");
grub_util_info ("comparing");
if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
grub_util_error ("files differ");
if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
grub_util_error ("files differ");
}
}
printf ("%s\n", fs->name);
@ -306,7 +317,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\
@ -335,9 +346,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

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

@ -0,0 +1,266 @@
/* grub-script-check.c - check grub script file for syntax errors */
/*
* GRUB -- GRand Unified Bootloader
* 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
* 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_cmdfor (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdwhile (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
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 the script as it is 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)))
{
int i;
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);
for (i = 0; cmdline[i] != '\0'; i++)
{
/* Replace tabs and carriage returns with spaces. */
if (cmdline[i] == '\t' || cmdline[i] == '\r')
cmdline[i] = ' ';
/* Replace '\n' with '\0'. */
if (cmdline[i] == '\n')
cmdline[i] = '\0';
}
*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

@ -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
@ -34,26 +34,117 @@ 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
serial:* | *:serial)
serial=0;
gfxterm=0;
for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
if [ xserial = "x$x" ]; then
serial=1;
fi
if [ xgfxterm = "x$x" ]; then
gfxterm=1;
fi
done
if [ "x$serial" = x1 ]; then
if ! test -e ${grub_prefix}/serial.mod ; then
echo "Serial terminal not available on this platform." >&2 ; exit 1
echo "Serial terminal not available on this platform." >&2 ; exit 1
fi
if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
grub_warn "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used."
GRUB_SERIAL_COMMAND=serial
grub_warn "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used."
GRUB_SERIAL_COMMAND=serial
fi
echo "${GRUB_SERIAL_COMMAND}"
;;
esac
fi
if [ "x$gfxterm" = x1 ]; then
# Make the font accessible
prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT_PATH}"`
cat << EOF
if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then
set gfxmode=${GRUB_GFXMODE}
insmod gfxterm
insmod ${GRUB_VIDEO_BACKEND}
EOF
if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
&& is_path_readable_by_grub "$GRUB_THEME"; then
echo "Found theme: $GRUB_THEME" >&2
prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"` | sed -e "s/^/ /"
cat << EOF
insmod gfxmenu
EOF
themedir="`dirname "$GRUB_THEME"`"
for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
if [ -f "$x" ]; then
cat << EOF
loadfont (\$root)`make_system_path_relative_to_its_root $x`
EOF
fi
done
if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
cat << EOF
insmod jpeg
EOF
fi
if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
cat << EOF
insmod png
EOF
fi
if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
cat << EOF
insmod tga
EOF
fi
cat << EOF
set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
EOF
elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
&& is_path_readable_by_grub "$GRUB_BACKGROUND"; then
echo "Found background: $GRUB_BACKGROUND" >&2
case "$GRUB_BACKGROUND" in
*.png) reader=png ;;
*.tga) reader=tga ;;
*.jpg|*.jpeg) reader=jpeg ;;
*) echo "Unsupported image format" >&2; exit 1 ;;
esac
prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"` | sed -e "s/^/ /"
cat << EOF
insmod $reader
background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
EOF
fi
cat << EOF
fi
EOF
fi
case x${GRUB_TERMINAL_INPUT} in
x)
@ -71,23 +162,6 @@ EOF
esac
case x${GRUB_TERMINAL_OUTPUT} in
xgfxterm)
# Make the font accessible
prepare_grub_to_access_device `${grub_probe} --target=device ${GRUB_FONT_PATH}`
cat << EOF
if loadfont `make_system_path_relative_to_its_root ${GRUB_FONT_PATH}` ; then
set gfxmode=${GRUB_GFXMODE}
insmod gfxterm
insmod ${GRUB_VIDEO_BACKEND}
if terminal_output gfxterm ; then true ; else
# For backward compatibility with versions of terminal.mod that don't
# understand terminal_output
terminal gfxterm
fi
fi
EOF
;;
x)
# Just use the native terminal
;;
@ -104,15 +178,16 @@ esac
# Gettext variables and module
if [ "x${LANG}" != "xC" ] ; then
prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir})
cat << EOF
set locale_dir=${locale_dir}
set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir})
set lang=${grub_lang}
insmod gettext
insmod gettext
EOF
fi
if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then
if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
verbose=
else
verbose=" --verbose"
@ -127,3 +202,11 @@ else
set timeout=${GRUB_TIMEOUT}
EOF
fi
# Play an initial tune
if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
cat << EOF
insmod play
play ${GRUB_INIT_TUNE}
EOF
fi

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
@ -21,10 +21,13 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
CLASS="--class gnu --class os"
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU
else
OS="${GRUB_DISTRIBUTOR} GNU/Hurd"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
fi
at_least_one=false
@ -69,20 +72,45 @@ if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else
fi
cat << EOF
menuentry "${OS}" {
menuentry "${OS}" ${CLASS} {
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
cat << EOF
menuentry "${OS} (recovery mode)" {
EOF
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
cat << EOF
echo $(gettext "Loading GNU Mach ...")
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
cat << EOF
echo $(gettext "Loading the Hurd ...")
module /hurd/${hurd_fs}.static ${hurd_fs} \\
--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)'
}
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
@ -22,13 +22,20 @@ bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${bindir}/gettext.sh
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@
export TEXTDOMAINDIR=@LOCALEDIR@
CLASS="--class os"
case "${GRUB_DISTRIBUTOR}" in
Debian) OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" ;;
*) OS="FreeBSD" ;;
Debian)
OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}"
;;
*)
OS="FreeBSD"
CLASS="--class freebsd --class bsd ${CLASS}"
;;
esac
kfreebsd_entry ()
@ -38,18 +45,20 @@ kfreebsd_entry ()
recovery="$3" # not used yet
args="$4" # not used yet
title="$(gettext "%s, with kFreeBSD %s")"
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
printf "menuentry \"${title}\" ${CLASS} {\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
@ -22,14 +22,16 @@ bindir=@bindir@
libdir=@libdir@
. ${libdir}/grub/grub-mkconfig_lib
. ${bindir}/gettext.sh
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR=@localedir@
export TEXTDOMAINDIR=@LOCALEDIR@
CLASS="--class gnu-linux --class gnu --class os"
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS=GNU/Linux
else
OS="${GRUB_DISTRIBUTOR} GNU/Linux"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
fi
# loop-AES arranges things so that /dev/loop/X can be our root device, but
@ -58,16 +60,35 @@ linux_entry ()
else
title="$(gettext "%s, with Linux %s")"
fi
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
printf "menuentry \"${title}\" ${CLASS} {\n" "${os}" "${version}"
save_default_entry | sed -e "s/^/\t/"
# Use ELILO's generic "efifb" when it's known to be available.
# FIXME: We need an interface to select vesafb in case efifb can't be used.
if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \
&& grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then
cat << EOF
set gfxpayload=keep
EOF
fi
else
cat << EOF
set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
EOF
fi
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

@ -37,6 +37,57 @@ if [ -z "${OSPROBED}" ] ; then
exit 0
fi
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}
set do_resume=0
if [ /var/vm/sleepimage -nt10 / ]; then
if xnu_resume /var/vm/sleepimage; then
set do_resume=1
fi
fi
if [ \$do_resume == 0 ]; then
xnu_uuid ${OSXUUID} uuid
if [ -f /Extra/DSDT.aml ]; then
acpi -e /Extra/DSDT.aml
fi
$1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
xnu_mkext /System/Library/Extensions.mkext
else
xnu_kextdir /System/Library/Extensions
fi
if [ -f /Extra/Extensions.mkext ]; then
xnu_mkext /Extra/Extensions.mkext
fi
if [ -d /Extra/Extensions ]; then
xnu_kextdir /Extra/Extensions
fi
if [ -f /Extra/devprop.bin ]; then
xnu_devprop_load /Extra/devprop.bin
fi
if [ -f /Extra/splash.jpg ]; then
insmod jpeg
xnu_splash /Extra/splash.jpg
fi
if [ -f /Extra/splash.png ]; then
insmod png
xnu_splash /Extra/splash.png
fi
if [ -f /Extra/splash.tga ]; then
insmod tga
xnu_splash /Extra/splash.tga
fi
fi
}
EOF
}
for OS in ${OSPROBED} ; do
DEVICE="`echo ${OS} | cut -d ':' -f 1`"
LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
@ -55,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
@ -96,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
@ -115,58 +168,14 @@ EOF
;;
macosx)
OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
cat << EOF
insmod vbe
do_resume=0
if [ /var/vm/sleepimage -nt10 / ]; then
if xnu_resume /var/vm/sleepimage; then
do_resume=1
fi
fi
if [ \$do_resume == 0 ]; then
xnu_uuid ${OSXUUID} uuid
if [ -f /Extra/DSDT.aml ]; then
acpi -e /Extra/DSDT.aml
fi
xnu_kernel /mach_kernel boot-uuid=\${uuid} rd=*uuid
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
xnu_mkext /System/Library/Extensions.mkext
else
xnu_kextdir /System/Library/Extensions
fi
if [ -f /Extra/Extensions.mkext ]; then
xnu_mkext /Extra/Extensions.mkext
fi
if [ -d /Extra/Extensions ]; then
xnu_kextdir /Extra/Extensions
fi
if [ -f /Extra/devtree.txt ]; then
xnu_devtree /Extra/devtree.txt
fi
if [ -f /Extra/splash.jpg ]; then
insmod jpeg
xnu_splash /Extra/splash.jpg
fi
if [ -f /Extra/splash.png ]; then
insmod png
xnu_splash /Extra/splash.png
fi
if [ -f /Extra/splash.tga ]; then
insmod tga
xnu_splash /Extra/splash.tga
fi
fi
}
EOF
osx_entry xnu_kernel 32
osx_entry xnu_kernel64 64
;;
hurd)
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

@ -26,6 +26,7 @@
#include <grub/util/hostdisk.h>
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/list.h>
#include <stdio.h>
#include <stdlib.h>
@ -97,12 +98,31 @@ struct hd_geometry
# include <sys/disk.h>
#endif
#if defined(__NetBSD__)
# include <sys/ioctl.h>
# include <sys/disklabel.h> /* struct disklabel */
# ifdef HAVE_GETRAWPARTITION
# include <util.h> /* getrawpartition */
# endif /* HAVE_GETRAWPARTITION */
# include <sys/fdio.h>
# ifndef RAW_FLOPPY_MAJOR
# define RAW_FLOPPY_MAJOR 9
# endif /* ! RAW_FLOPPY_MAJOR */
#endif /* defined(__NetBSD__) */
struct
{
char *drive;
char *device;
} map[256];
struct grub_util_biosdisk_data
{
char *dev;
int access_mode;
int fd;
};
#ifdef __linux__
/* Check if we have devfs support. */
static int
@ -121,6 +141,31 @@ have_devfs (void)
}
#endif /* __linux__ */
#if defined(__NetBSD__)
/* Adjust device driver parameters. This function should be called just
after successfully opening the device. For now, it simply prevents the
floppy driver from retrying operations on failure, as otherwise the
driver takes a while to abort when there is no floppy in the drive. */
static void
configure_device_driver (int fd)
{
struct stat st;
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
return;
if (major(st.st_rdev) == RAW_FLOPPY_MAJOR)
{
int floppy_opts;
if (ioctl (fd, FDIOCGETOPTS, &floppy_opts) == -1)
return;
floppy_opts |= FDOPT_NORETRY;
if (ioctl (fd, FDIOCSETOPTS, &floppy_opts) == -1)
return;
}
}
#endif /* defined(__NetBSD__) */
static int
find_grub_drive (const char *name)
{
@ -137,7 +182,7 @@ find_grub_drive (const char *name)
}
static int
find_free_slot ()
find_free_slot (void)
{
unsigned int i;
@ -165,14 +210,19 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
{
int drive;
struct stat st;
struct grub_util_biosdisk_data *data;
drive = find_grub_drive (name);
if (drive < 0)
return grub_error (GRUB_ERR_BAD_DEVICE,
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"no mapping exists for `%s'", name);
disk->has_partitions = 1;
disk->id = drive;
disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data));
data->dev = NULL;
data->access_mode = 0;
data->fd = -1;
/* Get the size. */
#if defined(__MINGW32__)
@ -191,16 +241,20 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
return GRUB_ERR_NONE;
}
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || defined(__APPLE__)
defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
{
# if defined(__NetBSD__)
struct disklabel label;
# else
unsigned long long nr;
# endif
int fd;
fd = open (map[drive].device, O_RDONLY);
if (fd == -1)
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
# else
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
@ -214,6 +268,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
if (ioctl (fd, DIOCGMEDIASIZE, &nr))
# elif defined(__APPLE__)
if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
# elif defined(__NetBSD__)
configure_device_driver (fd);
if (ioctl (fd, DIOCGDINFO, &label) == -1)
# else
if (ioctl (fd, BLKGETSIZE64, &nr))
# endif
@ -224,14 +281,16 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
close (fd);
#if defined (__APPLE__)
# if defined (__APPLE__)
disk->total_sectors = nr;
#else
# elif defined(__NetBSD__)
disk->total_sectors = label.d_secperunit;
# else
disk->total_sectors = nr / 512;
if (nr % 512)
grub_util_error ("unaligned device size");
#endif
# endif
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
@ -244,7 +303,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal."
#endif
if (stat (map[drive].device, &st) < 0)
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device);
disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
@ -254,6 +313,17 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
}
#ifdef __linux__
/* Cache of partition start sectors for each disk. */
struct linux_partition_cache
{
struct linux_partition_cache *next;
char *dev;
unsigned long start;
int partno;
};
struct linux_partition_cache *linux_partition_cache_list;
static int
linux_find_partition (char *dev, unsigned long sector)
{
@ -262,6 +332,7 @@ linux_find_partition (char *dev, unsigned long sector)
char *p;
int i;
char real_dev[PATH_MAX];
struct linux_partition_cache *cache;
strcpy(real_dev, dev);
@ -281,6 +352,16 @@ linux_find_partition (char *dev, unsigned long sector)
format = "%d";
}
for (cache = linux_partition_cache_list; cache; cache = cache->next)
{
if (strcmp (cache->dev, dev) == 0 && cache->start == sector)
{
sprintf (p, format, cache->partno);
strcpy (dev, real_dev);
return 1;
}
}
for (i = 1; i < 10000; i++)
{
int fd;
@ -301,6 +382,15 @@ linux_find_partition (char *dev, unsigned long sector)
if (hdg.start == sector)
{
struct linux_partition_cache *new_cache_item;
new_cache_item = xmalloc (sizeof *new_cache_item);
new_cache_item->dev = xstrdup (dev);
new_cache_item->start = hdg.start;
new_cache_item->partno = i;
grub_list_push (GRUB_AS_LIST_P (&linux_partition_cache_list),
GRUB_AS_LIST (new_cache_item));
strcpy (dev, real_dev);
return 1;
}
@ -314,6 +404,7 @@ static int
open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
{
int fd;
struct grub_util_biosdisk_data *data = disk->data;
#ifdef O_LARGEFILE
flags |= O_LARGEFILE;
@ -334,25 +425,47 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
{
int is_partition = 0;
char dev[PATH_MAX];
grub_disk_addr_t part_start = 0;
part_start = grub_partition_get_start (disk->partition);
strcpy (dev, map[disk->id].device);
if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) == 0)
is_partition = linux_find_partition (dev, disk->partition->start);
if (disk->partition && sector >= part_start
&& strncmp (map[disk->id].device, "/dev/", 5) == 0)
is_partition = linux_find_partition (dev, part_start);
/* Open the partition. */
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()", dev);
fd = open (dev, flags);
if (fd < 0)
if (data->dev && strcmp (data->dev, dev) == 0 &&
data->access_mode == (flags & O_ACCMODE))
{
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
return -1;
grub_dprintf ("hostdisk", "reusing open device `%s'\n", dev);
fd = data->fd;
}
else
{
free (data->dev);
if (data->fd != -1)
close (data->fd);
/* Open the partition. */
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev);
fd = open (dev, flags);
if (fd < 0)
{
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
return -1;
}
/* Flush the buffer cache to the physical disk.
XXX: This also empties the buffer cache. */
ioctl (fd, BLKFLSBUF, 0);
data->dev = xstrdup (dev);
data->access_mode = (flags & O_ACCMODE);
data->fd = fd;
}
/* Make the buffer cache consistent with the physical disk. */
ioctl (fd, BLKFLSBUF, 0);
if (is_partition)
sector -= disk->partition->start;
sector -= part_start;
}
#else /* ! __linux__ */
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
@ -373,7 +486,26 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
}
#endif
fd = open (map[disk->id].device, flags);
if (data->dev && strcmp (data->dev, map[disk->id].device) == 0 &&
data->access_mode == (flags & O_ACCMODE))
{
grub_dprintf ("hostdisk", "reusing open device `%s'\n", data->dev);
fd = data->fd;
}
else
{
free (data->dev);
if (data->fd != -1)
close (data->fd);
fd = open (map[disk->id].device, flags);
if (fd >= 0)
{
data->dev = xstrdup (map[disk->id].device);
data->access_mode = (flags & O_ACCMODE);
data->fd = fd;
}
}
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (! (sysctl_oldflags & 0x10)
@ -397,6 +529,10 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
}
#endif /* ! __linux__ */
#if defined(__NetBSD__)
configure_device_driver (fd);
#endif /* defined(__NetBSD__) */
#if defined(__linux__) && (!defined(__GLIBC__) || \
((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
/* Maybe libc doesn't have large file support. */
@ -489,6 +625,23 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
{
int fd;
/* Split pre-partition and partition reads. */
if (disk->partition && sector < disk->partition->start
&& sector + size > disk->partition->start)
{
grub_err_t err;
err = grub_util_biosdisk_read (disk, sector,
disk->partition->start - sector,
buf);
if (err)
return err;
return grub_util_biosdisk_read (disk, disk->partition->start,
size - (disk->partition->start - sector),
buf + ((disk->partition->start - sector)
<< GRUB_DISK_SECTOR_BITS));
}
fd = open_device (disk, sector, O_RDONLY);
if (fd < 0)
return grub_errno;
@ -516,7 +669,6 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
close (fd);
return grub_errno;
}
@ -526,6 +678,23 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
{
int fd;
/* Split pre-partition and partition writes. */
if (disk->partition && sector < disk->partition->start
&& sector + size > disk->partition->start)
{
grub_err_t err;
err = grub_util_biosdisk_write (disk, sector,
disk->partition->start - sector,
buf);
if (err)
return err;
return grub_util_biosdisk_write (disk, disk->partition->start,
size - (disk->partition->start - sector),
buf + ((disk->partition->start - sector)
<< GRUB_DISK_SECTOR_BITS));
}
fd = open_device (disk, sector, O_WRONLY);
if (fd < 0)
return grub_errno;
@ -534,17 +703,27 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
close (fd);
return grub_errno;
}
static void
grub_util_biosdisk_close (struct grub_disk *disk)
{
struct grub_util_biosdisk_data *data = disk->data;
free (data->dev);
if (data->fd != -1)
close (data->fd);
free (data);
}
static struct grub_disk_dev grub_util_biosdisk_dev =
{
.name = "biosdisk",
.id = GRUB_DISK_DEVICE_BIOSDISK_ID,
.iterate = grub_util_biosdisk_iterate,
.open = grub_util_biosdisk_open,
.close = 0,
.close = grub_util_biosdisk_close,
.read = grub_util_biosdisk_read,
.write = grub_util_biosdisk_write,
.next = 0
@ -567,7 +746,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;
}
@ -638,7 +817,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
@ -679,14 +858,14 @@ make_device_name (int drive, int dos_part, int bsd_part)
char *bsd_part_str = NULL;
if (dos_part >= 0)
asprintf (&dos_part_str, ",%d", dos_part + 1);
dos_part_str = xasprintf (",%d", dos_part + 1);
if (bsd_part >= 0)
asprintf (&bsd_part_str, ",%c", dos_part + 'a');
bsd_part_str = xasprintf (",%c", bsd_part + 'a');
asprintf (&ret, "%s%s%s", map[drive].drive,
dos_part_str ? : "",
bsd_part_str ? : "");
ret = xasprintf ("%s%s%s", map[drive].drive,
dos_part_str ? : "",
bsd_part_str ? : "");
if (dos_part_str)
free (dos_part_str);
@ -852,6 +1031,27 @@ convert_system_partition_to_system_disk (const char *os_dev)
}
return path;
#elif defined(__NetBSD__)
/* NetBSD uses "/dev/r[wsc]d[0-9]+[a-z]". */
char *path = xstrdup (os_dev);
if (strncmp ("/dev/rwd", path, 8) == 0 ||
strncmp ("/dev/rsd", path, 8) == 0 ||
strncmp ("/dev/rcd", path, 8) == 0)
{
char *q;
q = path + strlen(path) - 1; /* last character */
if (grub_isalpha(*q) && grub_isdigit(*(q-1)))
{
int rawpart = -1;
# ifdef HAVE_GETRAWPARTITION
rawpart = getrawpartition();
# endif /* HAVE_GETRAWPARTITION */
if (rawpart >= 0)
*q = 'a' + rawpart;
}
}
return path;
#else
# warning "The function `convert_system_partition_to_system_disk' might not work on your OS correctly."
return xstrdup (os_dev);
@ -870,6 +1070,26 @@ device_is_wholedisk (const char *os_dev)
}
#endif
#if defined(__NetBSD__)
/* Try to determine whether a given device name corresponds to a whole disk.
This function should give in most cases a definite answer, but it may
actually give an approximate one in the following sense: if the return
value is 0 then the device name does not correspond to a whole disk. */
static int
device_is_wholedisk (const char *os_dev)
{
int len = strlen (os_dev);
int rawpart = -1;
# ifdef HAVE_GETRAWPARTITION
rawpart = getrawpartition();
# endif /* HAVE_GETRAWPARTITION */
if (rawpart < 0)
return 1;
return (os_dev[len - 1] == ('a' + rawpart));
}
#endif /* defined(__NetBSD__) */
static int
find_system_device (const char *os_dev)
{
@ -913,7 +1133,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
drive = find_system_device (os_dev);
if (drive < 0)
{
grub_error (GRUB_ERR_BAD_DEVICE,
grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"no mapping exists for `%s'", os_dev);
return 0;
}
@ -922,14 +1142,14 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
== 0)
return make_device_name (drive, -1, -1);
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
if (! S_ISCHR (st.st_mode))
#else
if (! S_ISBLK (st.st_mode))
#endif
return make_device_name (drive, -1, -1);
#if defined(__linux__) || defined(__CYGWIN__)
#if defined(__linux__) || defined(__CYGWIN__) || defined(__NetBSD__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
partition, so mapping them to GRUB devices is not trivial.
Here, get the start sector of a partition by HDIO_GETGEO, and
@ -937,53 +1157,49 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
Cygwin /dev/sdXN emulation uses Windows partition mapping. It
does not count the extended partition and missing primary
partitions. Use same method as on Linux here. */
partitions. Use same method as on Linux here.
For NetBSD, proceed as for Linux, except that the start sector is
obtained from the disk label. */
{
char *name;
grub_disk_t disk;
int fd;
# if !defined(__NetBSD__)
struct hd_geometry hdg;
typeof (hdg.start) p_offset;
# else /* defined(__NetBSD__) */
struct disklabel label;
int index;
u_int32_t p_offset;
# endif /* !defined(__NetBSD__) */
int dos_part = -1;
int bsd_part = -1;
auto int find_partition (grub_disk_t disk,
auto int find_partition (grub_disk_t dsk,
const grub_partition_t partition);
int find_partition (grub_disk_t disk __attribute__ ((unused)),
int find_partition (grub_disk_t dsk __attribute__ ((unused)),
const grub_partition_t partition)
{
struct grub_msdos_partition *pcdata = NULL;
grub_disk_addr_t part_start = 0;
grub_util_info ("Partition %d starts from %lu",
partition->number, partition->start);
if (strcmp (partition->partmap->name, "part_msdos") == 0)
pcdata = partition->data;
part_start = grub_partition_get_start (partition);
if (pcdata)
if (p_offset == part_start)
{
if (pcdata->bsd_part < 0)
grub_util_info ("DOS partition %d starts from %lu",
pcdata->dos_part, partition->start);
else
grub_util_info ("BSD partition %d,%c starts from %lu",
pcdata->dos_part, pcdata->bsd_part + 'a',
partition->start);
}
else
{
grub_util_info ("Partition %d starts from %lu",
partition->index, partition->start);
}
if (hdg.start == partition->start)
{
if (pcdata)
if (partition->parent)
{
dos_part = pcdata->dos_part;
bsd_part = pcdata->bsd_part;
dos_part = partition->parent->number;
bsd_part = partition->number;
}
else
{
dos_part = partition->index;
dos_part = partition->number;
bsd_part = -1;
}
return 1;
}
@ -992,8 +1208,15 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
name = make_device_name (drive, -1, -1);
# if !defined(__NetBSD__)
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
return name;
# else /* defined(__NetBSD__) */
/* Since os_dev and convert_system_partition_to_system_disk (os_dev) are
* different, we know that os_dev is of the form /dev/r[wsc]d[0-9]+[a-z]
* and in particular it cannot be a floppy device. */
index = os_dev[strlen(os_dev) - 1] - 'a';
# endif /* !defined(__NetBSD__) */
fd = open (os_dev, O_RDONLY);
if (fd == -1)
@ -1003,10 +1226,15 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
return 0;
}
# if !defined(__NetBSD__)
if (ioctl (fd, HDIO_GETGEO, &hdg))
# else /* defined(__NetBSD__) */
configure_device_driver (fd);
if (ioctl (fd, DIOCGDINFO, &label) == -1)
# endif /* !defined(__NetBSD__) */
{
grub_error (GRUB_ERR_BAD_DEVICE,
"cannot get geometry of `%s'", os_dev);
"cannot get disk geometry of `%s'", os_dev);
close (fd);
free (name);
return 0;
@ -1014,9 +1242,22 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
close (fd);
grub_util_info ("%s starts from %lu", os_dev, hdg.start);
# if !defined(__NetBSD__)
p_offset = hdg.start;
# else /* defined(__NetBSD__) */
if (index >= label.d_npartitions)
{
grub_error (GRUB_ERR_BAD_DEVICE,
"no disk label entry for `%s'", os_dev);
free (name);
return 0;
}
p_offset = label.d_partitions[index].p_offset;
# endif /* !defined(__NetBSD__) */
if (hdg.start == 0 && device_is_wholedisk (os_dev))
grub_util_info ("%s starts from %lu", os_dev, p_offset);
if (p_offset == 0 && device_is_wholedisk (os_dev))
return name;
grub_util_info ("opening the device %s", name);

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,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
@ -26,6 +26,7 @@
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
/* dirent.d_type is a BSD extension, not part of POSIX */
@ -118,10 +119,17 @@ grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len)
FILE *f;
f = (FILE *) file->data;
fseeko (f, file->offset, SEEK_SET);
int s = fread (buf, 1, len, f);
if (fseeko (f, file->offset, SEEK_SET) != 0)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "fseeko: %s", strerror (errno));
return -1;
}
return s;
unsigned int s = fread (buf, 1, len, f);
if (s != len)
grub_error (GRUB_ERR_FILE_READ_ERROR, "fread: %s", strerror (errno));
return (signed) s;
}
static grub_err_t

View file

@ -15,11 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
hexify()
{
echo -n "$@" | od -A n -t x1 - | sed -e 's/ //g' | tr '\n' '\0'
}
if [ "x$1" = "x" ]; then
echo "Filename required".
fi
echo "`hexify efi`{ `hexify device-properties`:"
ioreg -lw0 -p IODeviceTree -n efi -r -x |grep device-properties | sed 's/.*<//;s/>.*//;'
echo ";}"
ioreg -lw0 -p IODeviceTree -n efi -r -x |grep device-properties | sed 's/.*<//;s/>.*//;' | xxd -r -p > $1

View file

@ -29,11 +29,14 @@ PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
host_os=@host_os@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
localedir=@datadir@/locale
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=
@ -142,8 +145,7 @@ else
fi
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
mkdir -p "$grubdir" || exit 1
# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
@ -178,6 +180,18 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
# Copy gettext files
mkdir -p ${grubdir}/locale/
for dir in ${localedir}/*; do
if test -f "$dir/LC_MESSAGES/grub.mo"; then
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
fi
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
@ -188,7 +202,10 @@ fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
partmap_module=
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
partmap_module="$partmap_module part_$x";
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`

View file

@ -55,12 +55,12 @@ align_pe32_section (Elf_Addr addr)
/* Read the whole kernel image. Return the pointer to a read image,
and store the size in bytes in *SIZE. */
static char *
read_kernel_module (const char *dir, size_t *size)
read_kernel_image (const char *dir, size_t *size)
{
char *kernel_image;
char *kernel_path;
kernel_path = grub_util_get_path (dir, "kernel.mod");
kernel_path = grub_util_get_path (dir, "kernel.img");
*size = grub_util_get_image_size (kernel_path);
kernel_image = grub_util_read_image (kernel_path);
free (kernel_path);
@ -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)
{
@ -945,7 +945,7 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
int i;
/* Get the kernel image and check the format. */
kernel_image = read_kernel_module (dir, &kernel_size);
kernel_image = read_kernel_image (dir, &kernel_size);
e = (Elf_Ehdr *) kernel_image;
if (! check_elf_header (e, kernel_size))
grub_util_error ("invalid ELF header");
@ -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;
@ -123,15 +116,10 @@ setup (const char *dir,
int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
struct grub_msdos_partition *pcdata = p->data;
/* There's always an embed region, and it starts right after the MBR. */
embed_region.start = 1;
/* For its end offset, include as many dummy partitions as we can. */
if (! grub_msdos_partition_is_empty (pcdata->dos_type)
&& ! grub_msdos_partition_is_bsd (pcdata->dos_type)
&& embed_region.end > p->start)
if (embed_region.end > p->start)
embed_region.end = p->start;
return 0;
@ -142,17 +130,21 @@ setup (const char *dir,
int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
struct grub_gpt_partentry *gptdata = p->data;
struct grub_gpt_partentry gptdata;
disk->partition = p->parent;
if (grub_disk_read (disk, p->offset, p->index,
sizeof (gptdata), &gptdata))
return 0;
/* If there's an embed region, it is in a dedicated partition. */
if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16))
if (! memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
{
embed_region.start = p->start;
embed_region.end = p->start + p->len;
return 1;
}
return 0;
}
@ -163,7 +155,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 +163,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 +183,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 +194,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 +211,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 +250,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)
@ -296,22 +288,19 @@ setup (const char *dir,
/* Embed information about the installed location. */
if (root_dev->disk->partition)
{
if (strcmp (root_dev->disk->partition->partmap->name,
"part_msdos") == 0)
{
struct grub_msdos_partition *pcdata =
root_dev->disk->partition->data;
dos_part = pcdata->dos_part;
bsd_part = pcdata->bsd_part;
}
else if (strcmp (root_dev->disk->partition->partmap->name,
"part_gpt") == 0)
{
dos_part = root_dev->disk->partition->index;
bsd_part = -1;
}
if (root_dev->disk->partition->parent)
{
if (root_dev->disk->partition->parent->parent)
grub_util_error ("Installing on doubly nested partitions is "
"not supported");
dos_part = root_dev->disk->partition->parent->number;
bsd_part = root_dev->disk->partition->number;
}
else
grub_util_error (_("No DOS-style partitions found"));
{
dos_part = root_dev->disk->partition->number;
bsd_part = -1;
}
}
else
dos_part = bsd_part = -1;
@ -344,6 +333,8 @@ setup (const char *dir,
int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
if (p->parent)
return 0;
dest_partmap = p->partmap->name;
return 1;
}
@ -356,12 +347,16 @@ setup (const char *dir,
goto unable_to_embed;
}
grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "part_msdos") ?
find_usable_region_gpt : find_usable_region_msdos));
if (strcmp (dest_partmap, "msdos") == 0)
grub_partition_iterate (dest_dev->disk, find_usable_region_msdos);
else if (strcmp (dest_partmap, "gpt") == 0)
grub_partition_iterate (dest_dev->disk, find_usable_region_gpt);
else
grub_util_error (_("No DOS-style partitions found"));
if (embed_region.end == embed_region.start)
{
if (! strcmp (dest_partmap, "part_msdos"))
if (! strcmp (dest_partmap, "msdos"))
grub_util_warn (_("This msdos-style partition label has no post-MBR gap; embedding won't be possible!"));
else
grub_util_warn (_("This GPT partition label has no BIOS Boot Partition; embedding won't be possible!"));
@ -385,10 +380,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;
@ -415,14 +411,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."));
"their 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);
@ -497,7 +493,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;
@ -510,7 +506,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. */
@ -521,13 +517,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);
@ -546,7 +542,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);
@ -586,13 +582,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\
@ -607,6 +603,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);
@ -637,9 +634,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)
@ -754,7 +750,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);
@ -767,7 +763,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

@ -35,8 +35,10 @@ escape_of_path (const char *orig_path)
}
void
grub_util_emit_devicemap_entry (FILE *fp, char *name, int is_floppy UNUSED,
int *num_fd UNUSED, int *num_hd UNUSED)
grub_util_emit_devicemap_entry (FILE *fp, char *name,
int is_floppy __attribute__((unused)),
int *num_fd __attribute__((unused)),
int *num_hd __attribute__((unused)))
{
const char *orig_path = grub_util_devname_to_ofpath (name);
char *ofpath = escape_of_path (orig_path);

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=
@ -45,8 +46,8 @@ install_device=
debug=no
update_nvram=yes
ofpathname=/usr/sbin/ofpathname
nvsetenv=/sbin/nvsetenv
ofpathname=`which ofpathname`
nvsetenv=`which nvsetenv`
# Usage: usage
# Print the usage.
@ -140,8 +141,7 @@ fi
# XXX warn on firmware-unreadable filesystems?
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
mkdir -p "$grubdir" || exit 1
# Create the device map file if it is not present.
if test -f "$device_map"; then
@ -163,6 +163,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
@ -174,7 +178,10 @@ fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
partmap_module=
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
partmap_module="$partmap_module part_$x";
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
@ -211,11 +218,11 @@ if test $update_nvram = yes; then
}
# Point boot-device at the new grub install
boot_device="boot-device $ofpath:$partno,\\grub"
"$nvsetenv" "$boot_device" || {
boot_device="$ofpath:$partno,\\grub"
"$nvsetenv" boot-device "$boot_device" || {
echo "$nvsetenv failed."
echo "You will have to set boot-device manually. At the Open Firmware prompt, type:"
echo " setenv $boot_device"
echo " setenv boot-device $boot_device"
exit 1
}
fi

View file

@ -39,7 +39,6 @@
#include <ctype.h>
#ifdef OFPATH_STANDALONE
#define UNUSED __attribute__((unused))
#define xmalloc malloc
void
grub_util_error (const char *fmt, ...)
@ -132,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);
}
@ -199,8 +198,10 @@ get_basename(char *p)
static void
of_path_of_vdisk(char *of_path,
const char *devname UNUSED, const char *device,
const char *devnode UNUSED, const char *devicenode)
const char *devname __attribute__((unused)),
const char *device,
const char *devnode __attribute__((unused)),
const char *devicenode)
{
char *sysfs_path, *p;
int devno, junk;
@ -217,8 +218,9 @@ of_path_of_vdisk(char *of_path,
static void
of_path_of_ide(char *of_path,
const char *devname UNUSED, const char *device,
const char *devnode UNUSED, const char *devicenode)
const char *devname __attribute__((unused)), const char *device,
const char *devnode __attribute__((unused)),
const char *devicenode)
{
char *sysfs_path, *p;
int chan, devno;
@ -245,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);
@ -286,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));
@ -299,8 +301,9 @@ check_sas (char *sysfs_path, int *tgt)
static void
of_path_of_scsi(char *of_path,
const char *devname UNUSED, const char *device,
const char *devnode UNUSED, const char *devicenode)
const char *devname __attribute__((unused)), const char *device,
const char *devnode __attribute__((unused)),
const char *devicenode)
{
const char *p, *digit_string, *disk_name;
int host, bus, tgt, lun;
@ -372,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,14 +61,34 @@ 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")
conf.write ("MAINTAINER_CLEANFILES += $(srcdir)/conf/gcry.rmk $(srcdir)/lib/libgcrypt-grub/cipher/ChangeLog $(srcdir)/lib/libgcrypt-grub/cipher/cipher.h $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst $(srcdir)/lib/libgcrypt-grub/cipher/g10lib.h $(srcdir)/lib/libgcrypt-grub/cipher/memory.h $(srcdir)/lib/libgcrypt-grub/cipher/types.h\n");
# 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):
conf.write ("MAINTAINER_CLEANFILES += $(srcdir)/lib/libgcrypt-grub/cipher/" + cipher_file + "\n");
isc = re.match (".*\.c$", cipher_file)
f = open (infile, "r")
fw = open (outfile, "w")
@ -80,8 +100,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 +123,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 +139,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 +178,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 +203,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 +241,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 +279,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 +288,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 +311,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

@ -26,6 +26,8 @@
#include <string.h>
#include <sys/stat.h>
#define LVM_DEV_MAPPER_STRING "/dev/mapper/"
int
grub_util_lvm_isvolume (char *name)
{
@ -33,10 +35,10 @@ grub_util_lvm_isvolume (char *name)
struct stat st;
int err;
devname = xmalloc (strlen (name) + 13);
devname = xmalloc (strlen (name) + sizeof (LVM_DEV_MAPPER_STRING));
strcpy (devname, "/dev/mapper/");
strcpy (devname+12, name);
strcpy (devname, LVM_DEV_MAPPER_STRING);
strcpy (devname + sizeof(LVM_DEV_MAPPER_STRING) - 1, name);
err = stat (devname, &st);
free (devname);

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
@ -30,15 +30,21 @@
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <grub/kernel.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/cache.h>
#include <grub/util/misc.h>
#include <grub/mm.h>
#include <grub/term.h>
#include <grub/time.h>
#include <grub/i18n.h>
#define ENABLE_RELOCATABLE 0
#include "progname.h"
/* Include malloc.h, only if memalign is available. It is known that
@ -59,11 +65,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 +81,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,14 +96,16 @@ 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);
}
#ifdef GRUB_UTIL
int
grub_err_printf (const char *fmt, ...)
{
@ -108,6 +118,7 @@ grub_err_printf (const char *fmt, ...)
return ret;
}
#endif
void *
xmalloc (size_t size)
@ -135,13 +146,13 @@ char *
xstrdup (const char *str)
{
size_t len;
char *dup;
char *newstr;
len = strlen (str);
dup = (char *) xmalloc (len + 1);
memcpy (dup, str, len + 1);
newstr = (char *) xmalloc (len + 1);
memcpy (newstr, str, len + 1);
return dup;
return newstr;
}
char *
@ -252,56 +263,6 @@ grub_util_write_image (const char *img, size_t size, FILE *out)
grub_util_error ("write failed");
}
void *
grub_malloc (grub_size_t size)
{
return xmalloc (size);
}
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = xmalloc (size);
memset (ret, 0, size);
return ret;
}
void
grub_free (void *ptr)
{
free (ptr);
}
void *
grub_realloc (void *ptr, grub_size_t size)
{
return xrealloc (ptr, size);
}
void *
grub_memalign (grub_size_t align, grub_size_t size)
{
void *p;
#if defined(HAVE_POSIX_MEMALIGN)
if (posix_memalign (&p, align, size) != 0)
p = 0;
#elif defined(HAVE_MEMALIGN)
p = memalign (align, size);
#else
(void) align;
(void) size;
grub_util_error ("grub_memalign is not supported");
#endif
if (! p)
grub_util_error ("out of memory");
return p;
}
/* Some functions that we don't use. */
void
grub_mm_init_region (void *addr __attribute__ ((unused)),
@ -309,10 +270,12 @@ grub_mm_init_region (void *addr __attribute__ ((unused)),
{
}
#if GRUB_NO_MODULES
void
grub_register_exported_symbols (void)
{
}
#endif
void
grub_exit (void)
@ -364,11 +327,26 @@ grub_millisleep (grub_uint32_t ms)
#endif
#if !(defined (__i386__) || defined (__x86_64__)) && GRUB_NO_MODULES
void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#endif
#ifndef HAVE_VASPRINTF
int
vasprintf (char **buf, const char *fmt, va_list ap)
{
/* Should be large enough. */
*buf = xmalloc (512);
return vsprintf (*buf, fmt, ap);
}
#endif
#ifndef HAVE_ASPRINTF
@ -378,11 +356,8 @@ asprintf (char **buf, const char *fmt, ...)
int status;
va_list ap;
/* Should be large enough. */
*buf = xmalloc (512);
va_start (ap, fmt);
status = vsprintf (*buf, fmt, ap);
status = vasprintf (*buf, fmt, ap);
va_end (ap);
return status;
@ -390,6 +365,23 @@ asprintf (char **buf, const char *fmt, ...)
#endif
char *
xasprintf (const char *fmt, ...)
{
va_list ap;
char *result;
va_start (ap, fmt);
if (vasprintf (&result, fmt, ap) < 0)
{
if (errno == ENOMEM)
grub_util_error ("out of memory");
return NULL;
}
return result;
}
#ifdef __MINGW32__
void sync (void)
@ -451,6 +443,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 *
@ -463,23 +468,19 @@ 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);
buf = xstrdup (p);
free (p);
if (stat (buf, &st) < 0)
grub_util_error ("can not stat %s: %s", buf, strerror (errno));
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
buf2 = strdup (buf);
buf2 = xstrdup (buf);
num = st.st_dev;
/* This loop sets offset to the number of chars of the root
@ -496,11 +497,25 @@ make_system_path_relative_to_its_root (const char *path)
*++p = 0;
if (stat (buf, &st) < 0)
grub_util_error ("can not stat %s: %s", buf, strerror (errno));
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
/* buf is another filesystem; we found it. */
if (st.st_dev != num)
break;
{
/* offset == 0 means path given is the mount point.
This works around special-casing of "/" in Un*x. This function never
prints trailing slashes (so that its output can be appended a slash
unconditionally). Each slash in is considered a preceding slash, and
therefore the root directory is an empty string. */
if (offset == 0)
{
free (buf);
free (buf2);
return xstrdup ("");
}
else
break;
}
offset = p - buf;
/* offset == 1 means root directory. */
@ -513,11 +528,19 @@ make_system_path_relative_to_its_root (const char *path)
buf2[len - 1] = '\0';
len--;
}
return buf2;
if (len > 1)
return buf2;
else
{
/* This means path given is just a backslash. As above
we have to return an empty string. */
free (buf2);
return xstrdup ("");
}
}
}
free (buf);
buf3 = strdup (buf2 + offset);
buf3 = xstrdup (buf2 + offset);
free (buf2);
len = strlen (buf3);
@ -529,3 +552,15 @@ make_system_path_relative_to_its_root (const char *path)
return buf3;
}
#ifdef GRUB_UTIL
void
grub_util_init_nls (void)
{
#if (defined(ENABLE_NLS) && ENABLE_NLS)
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
}
#endif

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

@ -1,6 +1,6 @@
/*
* Program eltorito.c - Handle El Torito specific extensions to iso9660.
*
*
Written by Michael Fulbright <msf@redhat.com> (1996).
@ -53,7 +53,7 @@ static struct eltorito_boot_descriptor gboot_desc;
static int tvd_write __PR((FILE * outfile));
/*
* Check for presence of boot catalog. If it does not exist then make it
* Check for presence of boot catalog. If it does not exist then make it
*/
void FDECL1(init_boot_catalog, const char *, path)
{
@ -61,37 +61,37 @@ void FDECL1(init_boot_catalog, const char *, path)
char * bootpath; /* filename of boot catalog */
char * buf;
struct stat statbuf;
bootpath = (char *) e_malloc(strlen(boot_catalog)+strlen(path)+2);
strcpy(bootpath, path);
if (bootpath[strlen(bootpath)-1] != '/')
if (bootpath[strlen(bootpath)-1] != '/')
{
strcat(bootpath,"/");
}
strcat(bootpath, boot_catalog);
/*
* check for the file existing
* check for the file existing
*/
#ifdef DEBUG_TORITO
fprintf(stderr,"Looking for boot catalog file %s\n",bootpath);
#endif
if (!stat_filter(bootpath, &statbuf))
if (!stat_filter(bootpath, &statbuf))
{
/*
* make sure its big enough to hold what we want
* make sure its big enough to hold what we want
*/
if (statbuf.st_size == 2048)
if (statbuf.st_size == 2048)
{
/*
* printf("Boot catalog exists, so we do nothing\n");
* printf("Boot catalog exists, so we do nothing\n");
*/
free(bootpath);
return;
}
else
else
{
fprintf (stderr, _("A boot catalog exists and appears corrupted.\n"));
fprintf (stderr, _("Please check the following file: %s.\n"), bootpath);
@ -100,15 +100,15 @@ void FDECL1(init_boot_catalog, const char *, path)
exit (1);
}
}
/*
* file does not exist, so we create it
* file does not exist, so we create it
* make it one CD sector long
*/
bcat = fopen (bootpath, "wb");
if (bcat == NULL)
error (1, errno, _("Error creating boot catalog (%s)"), bootpath);
buf = (char *) e_malloc( 2048 );
if (fwrite (buf, 1, 2048, bcat) != 2048)
error (1, errno, _("Error writing to boot catalog (%s)"), bootpath);
@ -127,65 +127,65 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
struct directory_entry * de2;
unsigned int i;
int nsectors;
memset(boot_desc, 0, sizeof(*boot_desc));
boot_desc->id[0] = 0;
memcpy(boot_desc->id2, ISO_STANDARD_ID, sizeof(ISO_STANDARD_ID));
boot_desc->version[0] = 1;
memcpy(boot_desc->system_id, EL_TORITO_ID, sizeof(EL_TORITO_ID));
/*
* search from root of iso fs to find boot catalog
* search from root of iso fs to find boot catalog
*/
de2 = search_tree_file(root, boot_catalog);
if (!de2)
if (!de2)
{
fprintf (stderr, _("Boot catalog cannot be found!\n"));
exit (1);
}
set_731(boot_desc->bootcat_ptr,
(unsigned int) get_733(de2->isorec.extent));
/*
/*
* now adjust boot catalog
* lets find boot image first
* lets find boot image first
*/
de=search_tree_file(root, boot_image);
if (!de)
if (!de)
{
fprintf (stderr, _("Boot image cannot be found!\n"));
exit (1);
}
/*
}
/*
* we have the boot image, so write boot catalog information
* Next we write out the primary descriptor for the disc
* Next we write out the primary descriptor for the disc
*/
memset(&valid_desc, 0, sizeof(valid_desc));
valid_desc.headerid[0] = 1;
valid_desc.arch[0] = EL_TORITO_ARCH_x86;
/*
* we'll shove start of publisher id into id field, may get truncated
* but who really reads this stuff!
*/
if (publisher)
memcpy_max(valid_desc.id, publisher, MIN(23, strlen(publisher)));
valid_desc.key1[0] = 0x55;
valid_desc.key2[0] = 0xAA;
/*
* compute the checksum
* compute the checksum
*/
checksum=0;
checksum_ptr = (unsigned char *) &valid_desc;
for (i=0; i<sizeof(valid_desc); i+=2)
for (i=0; i<sizeof(valid_desc); i+=2)
{
/*
* skip adding in ckecksum word, since we dont have it yet!
* skip adding in ckecksum word, since we dont have it yet!
*/
if (i == 28)
{
@ -194,82 +194,82 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
checksum += (unsigned int)checksum_ptr[i];
checksum += ((unsigned int)checksum_ptr[i+1])*256;
}
/*
* now find out the real checksum
/*
* now find out the real checksum
*/
checksum = -checksum;
set_721(valid_desc.cksum, (unsigned int) checksum);
/*
* now make the initial/default entry for boot catalog
* now make the initial/default entry for boot catalog
*/
memset(&default_desc, 0, sizeof(default_desc));
default_desc.boot_id[0] = EL_TORITO_BOOTABLE;
/*
* use default BIOS loadpnt
*/
*/
set_721(default_desc.loadseg, 0);
default_desc.arch[0] = EL_TORITO_ARCH_x86;
/*
* figure out size of boot image in sectors, for now hard code to
* assume 512 bytes/sector on a bootable floppy
*/
nsectors = ((de->size + 511) & ~(511))/512;
fprintf (stderr, _("\nSize of boot image is %d sectors"), nsectors);
fprintf (stderr, " -> ");
fprintf (stderr, _("\nSize of boot image is %d sectors"), nsectors);
fprintf (stderr, " -> ");
if (! use_eltorito_emul_floppy)
{
default_desc.boot_media[0] = EL_TORITO_MEDIA_NOEMUL;
fprintf (stderr, _("No emulation\n"));
}
else if (nsectors == 2880 )
else if (nsectors == 2880 )
/*
* choose size of emulated floppy based on boot image size
* choose size of emulated floppy based on boot image size
*/
{
default_desc.boot_media[0] = EL_TORITO_MEDIA_144FLOP;
fprintf (stderr, _("Emulating a 1.44 meg floppy\n"));
}
else if (nsectors == 5760 )
else if (nsectors == 5760 )
{
default_desc.boot_media[0] = EL_TORITO_MEDIA_288FLOP;
fprintf (stderr, _("Emulating a 2.88 meg floppy\n"));
}
else if (nsectors == 2400 )
else if (nsectors == 2400 )
{
default_desc.boot_media[0] = EL_TORITO_MEDIA_12FLOP;
fprintf (stderr, _("Emulating a 1.2 meg floppy\n"));
}
else
else
{
fprintf (stderr, _("\nError - boot image is not the an allowable size.\n"));
exit (1);
}
/*
* FOR NOW LOAD 1 SECTOR, JUST LIKE FLOPPY BOOT!!!
/*
* FOR NOW LOAD 1 SECTOR, JUST LIKE FLOPPY BOOT!!!
*/
nsectors = 1;
set_721(default_desc.nsect, (unsigned int) nsectors );
#ifdef DEBUG_TORITO
fprintf(stderr,"Extent of boot images is %d\n",get_733(de->isorec.extent));
#endif
set_731(default_desc.bootoff,
set_731(default_desc.bootoff,
(unsigned int) get_733(de->isorec.extent));
/*
* now write it to disk
* now write it to disk
*/
bootcat = fopen (de2->whole_name, "r+b");
if (bootcat == NULL)
if (bootcat == NULL)
error (1, errno, _("Error opening boot catalog for update"));
/*
* write out
/*
* write out
*/
if (fwrite (&valid_desc, 1, 32, bootcat) != 32)
error (1, errno, _("Error writing to boot catalog"));
@ -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);
@ -332,7 +332,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
static int FDECL1(tvd_write, FILE *, outfile)
{
/*
* Next we write out the boot volume descriptor for the disc
* Next we write out the boot volume descriptor for the disc
*/
get_torito_desc(&gboot_desc);
xfwrite(&gboot_desc, 1, 2048, outfile);

View file

@ -1,6 +1,6 @@
/*
* 9-Dec-93 R.-D. Marzusch, marzusch@odiehh.hanse.de:
* added 'exclude' option (-x) to specify pathnames NOT to be included in
* added 'exclude' option (-x) to specify pathnames NOT to be included in
* CD image.
*
* $Id: exclude.h,v 1.2 1999/03/02 03:41:25 eric Exp $

View file

@ -33,7 +33,7 @@ void FDECL1(add_hash, struct directory_entry *, spnt){
struct file_hash * s_hash;
unsigned int hash_number;
if(spnt->size == 0 || spnt->starting_block == 0)
if(spnt->size == 0 || spnt->starting_block == 0)
if(spnt->size != 0 || spnt->starting_block != 0) {
fprintf(stderr,"Non zero-length file assigned zero extent.\n");
exit(1);
@ -116,10 +116,10 @@ static unsigned int FDECL1(name_hash, const char *, name)
{
unsigned int hash = 0;
const char * p;
p = name;
while (*p)
while (*p)
{
/*
* Don't hash the iso9660 version number. This way
@ -155,7 +155,7 @@ struct directory_entry * FDECL1(find_file_hash, char *, name)
struct name_hash * nh;
char * p1;
char * p2;
for(nh = name_hash_table[name_hash(name)]; nh; nh = nh->next)
{
p1 = name;
@ -220,6 +220,6 @@ void flush_file_hash(){
nh = nh1;
}
name_hash_table[i] = NULL;
}
}

View file

@ -138,7 +138,7 @@ struct eltorito_boot_info
char pvd_addr[ISODCL (1, 4)];
/* Boot file address. */
char file_addr[ISODCL (5, 8)];
/* Boot file length. */
/* Boot file length. */
char file_length[ISODCL (9, 12)];
/* Boot file checksum. */
char file_checksum[ISODCL (13, 16)];

View file

@ -87,13 +87,13 @@ static int DECL(joliet_sort_directory, (struct directory_entry ** sort_dir));
static void DECL(assign_joliet_directory_addresses, (struct directory * node));
static int jroot_gen __PR((void));
/*
/*
* Function: convert_to_unicode
*
* Purpose: Perform a 1/2 assed unicode conversion on a text
* string.
*
* Notes:
* Notes:
*/
static void FDECL3(convert_to_unicode, unsigned char *, buffer, int, size, char *, source )
{
@ -127,9 +127,9 @@ static void FDECL3(convert_to_unicode, unsigned char *, buffer, int, size, char
* JS integrated from: Achim_Kaiser@t-online.de
*
* Let all valid unicode characters pass through (assuming ISO-8859-1).
* Others are set to '_' .
*/
if( tmpbuf[j] != 0 &&
* Others are set to '_' .
*/
if( tmpbuf[j] != 0 &&
(tmpbuf[j] <= 0x1f || (tmpbuf[j] >= 0x7F && tmpbuf[j] <= 0xA0)) )
{
buffer[i+1] = '_';
@ -163,7 +163,7 @@ static void FDECL3(convert_to_unicode, unsigned char *, buffer, int, size, char
}
}
/*
/*
* Function: joliet_strlen
*
* Purpose: Return length in bytes of string after conversion to unicode.
@ -178,7 +178,7 @@ static int FDECL1(joliet_strlen, const char *, string)
rtn = strlen(string) << 1;
/*
/*
* We do clamp the maximum length of a Joliet string to be the
* maximum path size. This helps to ensure that we don't completely
* bolix things up with very long paths. The Joliet specs say
@ -191,7 +191,7 @@ static int FDECL1(joliet_strlen, const char *, string)
return rtn;
}
/*
/*
* Function: get_joliet_vol_desc
*
* Purpose: generate a Joliet compatible volume desc.
@ -212,7 +212,7 @@ static void FDECL1(get_joliet_vol_desc, struct iso_primary_descriptor *, jvol_de
* "expands" 8 bit character codes to 16 bits and does nothing
* special with the Unicode characters, therefore shouldn't mkisofs
* really be stating that it's using UCS-2 Level 1, not Level 3 for
* the Joliet directory tree.
* the Joliet directory tree.
*/
strcpy(jvol_desc->escape_sequences, "%/@");
@ -228,7 +228,7 @@ static void FDECL1(get_joliet_vol_desc, struct iso_primary_descriptor *, jvol_de
/*
* Set this one up.
*/
memcpy(jvol_desc->root_directory_record, &jroot_record,
memcpy(jvol_desc->root_directory_record, &jroot_record,
sizeof(struct iso_directory_record));
/*
@ -256,7 +256,7 @@ static void FDECL1(assign_joliet_directory_addresses, struct directory *, node)
struct directory * dpnt;
dpnt = node;
while (dpnt)
{
if( (dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) == 0 )
@ -275,7 +275,7 @@ static void FDECL1(assign_joliet_directory_addresses, struct directory *, node)
}
/* skip if hidden - but not for the rr_moved dir */
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
{
assign_joliet_directory_addresses(dpnt->subdir);
}
@ -283,13 +283,13 @@ static void FDECL1(assign_joliet_directory_addresses, struct directory *, node)
}
}
static
static
void FDECL1(build_jpathlist, struct directory *, node)
{
struct directory * dpnt;
dpnt = node;
while (dpnt)
{
@ -302,7 +302,7 @@ void FDECL1(build_jpathlist, struct directory *, node)
}
} /* build_jpathlist(... */
static int FDECL2(joliet_compare_paths, void const *, r, void const *, l)
static int FDECL2(joliet_compare_paths, void const *, r, void const *, l)
{
struct directory const *ll = *(struct directory * const *)l;
struct directory const *rr = *(struct directory * const *)r;
@ -325,13 +325,13 @@ static int FDECL2(joliet_compare_paths, void const *, r, void const *, l)
return -1;
}
if (rparent > lparent)
if (rparent > lparent)
{
return 1;
}
return strcmp(rr->self->name, ll->self->name);
} /* compare_paths(... */
static int generate_joliet_path_tables()
@ -346,7 +346,7 @@ static int generate_joliet_path_tables()
int tablesize;
/*
* First allocate memory for the tables and initialize the memory
* First allocate memory for the tables and initialize the memory
*/
tablesize = jpath_blocks << 11;
jpath_table_m = (char *) e_malloc(tablesize);
@ -361,10 +361,10 @@ static int generate_joliet_path_tables()
exit (1);
}
/*
* Now start filling in the path tables. Start with root directory
* Now start filling in the path tables. Start with root directory
*/
jpath_table_index = 0;
jpathlist = (struct directory **) e_malloc(sizeof(struct directory *)
jpathlist = (struct directory **) e_malloc(sizeof(struct directory *)
* next_jpath_index);
memset(jpathlist, 0, sizeof(struct directory *) * next_jpath_index);
build_jpathlist(root);
@ -373,10 +373,10 @@ static int generate_joliet_path_tables()
{
fix = 0;
#ifdef __STDC__
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
(int (*)(const void *, const void *))joliet_compare_paths);
#else
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
joliet_compare_paths);
#endif
@ -399,20 +399,20 @@ static int generate_joliet_path_tables()
exit (1);
}
npnt = dpnt->de_name;
npnt1 = strrchr(npnt, PATH_SEPARATOR);
if(npnt1)
{
if(npnt1)
{
npnt = npnt1 + 1;
}
de = dpnt->self;
if(!de)
if(!de)
{
fprintf (stderr, _("Fatal goof - directory has amnesia\n"));
fprintf (stderr, _("Fatal goof - directory has amnesia\n"));
exit (1);
}
namelen = joliet_strlen(de->name);
if( dpnt == root )
@ -426,28 +426,28 @@ static int generate_joliet_path_tables()
jpath_table_m[jpath_table_index] = namelen;
}
jpath_table_index += 2;
set_731(jpath_table_l + jpath_table_index, dpnt->jextent);
set_732(jpath_table_m + jpath_table_index, dpnt->jextent);
set_731(jpath_table_l + jpath_table_index, dpnt->jextent);
set_732(jpath_table_m + jpath_table_index, dpnt->jextent);
jpath_table_index += 4;
if( dpnt->parent != reloc_dir )
{
set_721(jpath_table_l + jpath_table_index,
dpnt->parent->jpath_index);
set_722(jpath_table_m + jpath_table_index,
dpnt->parent->jpath_index);
set_721(jpath_table_l + jpath_table_index,
dpnt->parent->jpath_index);
set_722(jpath_table_m + jpath_table_index,
dpnt->parent->jpath_index);
}
else
{
set_721(jpath_table_l + jpath_table_index,
dpnt->self->parent_rec->filedir->jpath_index);
set_722(jpath_table_m + jpath_table_index,
dpnt->self->parent_rec->filedir->jpath_index);
set_721(jpath_table_l + jpath_table_index,
dpnt->self->parent_rec->filedir->jpath_index);
set_722(jpath_table_m + jpath_table_index,
dpnt->self->parent_rec->filedir->jpath_index);
}
jpath_table_index += 2;
/*
* The root directory is still represented in non-unicode fashion.
*/
@ -459,19 +459,19 @@ static int generate_joliet_path_tables()
}
else
{
convert_to_unicode((uint8_t *)jpath_table_l + jpath_table_index,
convert_to_unicode((uint8_t *)jpath_table_l + jpath_table_index,
namelen, de->name);
convert_to_unicode((uint8_t *)jpath_table_m + jpath_table_index,
convert_to_unicode((uint8_t *)jpath_table_m + jpath_table_index,
namelen, de->name);
jpath_table_index += namelen;
}
if(jpath_table_index & 1)
if(jpath_table_index & 1)
{
jpath_table_index++; /* For odd lengths we pad */
}
}
free(jpathlist);
if(jpath_table_index != jpath_table_size)
{
@ -493,20 +493,20 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
unsigned int total_size;
int cvt_len;
struct directory * finddir;
total_size = (dpnt->jsize + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1);
directory_buffer = (char *) e_malloc(total_size);
memset(directory_buffer, 0, total_size);
dir_index = 0;
s_entry = dpnt->jcontents;
while(s_entry)
while(s_entry)
{
if(s_entry->de_flags & INHIBIT_JOLIET_ENTRY) {
s_entry = s_entry->jnext;
continue;
}
/*
* If this entry was a directory that was relocated, we have a bit
* of trouble here. We need to dig out the real thing and put it
@ -535,43 +535,43 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
{
s_entry1 = s_entry;
}
/*
* We do not allow directory entries to cross sector boundaries.
* Simply pad, and then start the next entry at the next sector
/*
* We do not allow directory entries to cross sector boundaries.
* Simply pad, and then start the next entry at the next sector
*/
new_reclen = s_entry1->jreclen;
if( (dir_index & (SECTOR_SIZE - 1)) + new_reclen >= SECTOR_SIZE )
{
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
~(SECTOR_SIZE - 1);
}
memcpy(&jrec, &s_entry1->isorec, sizeof(struct iso_directory_record) -
sizeof(s_entry1->isorec.name));
cvt_len = joliet_strlen(s_entry1->name);
/*
* Fix the record length - this was the non-Joliet version we
* were seeing.
*/
jrec.name_len[0] = cvt_len;
jrec.length[0] = s_entry1->jreclen;
/*
* If this is a directory, fix the correct size and extent
* number.
*/
if( (jrec.flags[0] & 2) != 0 )
{
if(strcmp(s_entry1->name,".") == 0)
if(strcmp(s_entry1->name,".") == 0)
{
jrec.name_len[0] = 1;
set_733((char *) jrec.extent, dpnt->jextent);
set_733((char *) jrec.size, ROUND_UP(dpnt->jsize));
}
else if(strcmp(s_entry1->name,"..") == 0)
else if(strcmp(s_entry1->name,"..") == 0)
{
jrec.name_len[0] = 1;
if( dpnt->parent == reloc_dir )
@ -600,7 +600,7 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
{
if(finddir->self == s_entry1) break;
finddir = finddir->next;
if(!finddir)
if(!finddir)
{
fprintf (stderr, _("Fatal goof - unable to find directory location\n"));
exit (1);
@ -610,25 +610,25 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
set_733((char *) jrec.size, ROUND_UP(finddir->jsize));
}
}
memcpy(directory_buffer + dir_index, &jrec,
memcpy(directory_buffer + dir_index, &jrec,
sizeof(struct iso_directory_record) -
sizeof(s_entry1->isorec.name));
dir_index += sizeof(struct iso_directory_record) -
dir_index += sizeof(struct iso_directory_record) -
sizeof (s_entry1->isorec.name);
/*
* Finally dump the Unicode version of the filename.
* Note - . and .. are the same as with non-Joliet discs.
*/
if( (jrec.flags[0] & 2) != 0
if( (jrec.flags[0] & 2) != 0
&& strcmp(s_entry1->name, ".") == 0 )
{
directory_buffer[dir_index++] = 0;
}
else if( (jrec.flags[0] & 2) != 0
else if( (jrec.flags[0] & 2) != 0
&& strcmp(s_entry1->name, "..") == 0 )
{
directory_buffer[dir_index++] = 1;
@ -640,7 +640,7 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
s_entry1->name);
dir_index += cvt_len;
}
if(dir_index & 1)
{
directory_buffer[dir_index++] = 0;
@ -648,13 +648,13 @@ static void FDECL2(generate_one_joliet_directory, struct directory *, dpnt, FILE
s_entry = s_entry->jnext;
}
if(dpnt->jsize != dir_index)
{
fprintf (stderr, _("Unexpected joliet directory length %d %d %s\n"),
dpnt->jsize, dir_index, dpnt->de_name);
}
xfwrite(directory_buffer, 1, total_size, outfile);
last_extent_written += total_size >> 11;
free(directory_buffer);
@ -678,7 +678,7 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
{
continue;
}
/*
* First update the path table sizes for directories.
*
@ -690,15 +690,15 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
*/
if(s_entry->isorec.flags[0] == 2)
{
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
{
jpath_table_size += joliet_strlen(s_entry->name) + sizeof(struct iso_path_table) - 1;
if (jpath_table_size & 1)
if (jpath_table_size & 1)
{
jpath_table_size++;
}
}
else
else
{
if (this_dir == root && strlen(s_entry->name) == 1)
{
@ -708,11 +708,11 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
}
}
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
{
s_entry->jreclen = sizeof(struct iso_directory_record)
- sizeof(s_entry->isorec.name)
+ joliet_strlen(s_entry->name)
+ joliet_strlen(s_entry->name)
+ 1;
}
else
@ -737,9 +737,9 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
this_dir->jcontents = this_dir->contents;
status = joliet_sort_directory(&this_dir->jcontents);
/*
/*
* Now go through the directory and figure out how large this one will be.
* Do not split a directory entry across a sector boundary
* Do not split a directory entry across a sector boundary
*/
s_entry = this_dir->jcontents;
/*
@ -756,10 +756,10 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
}
jreclen = s_entry->jreclen;
if ((this_dir->jsize & (SECTOR_SIZE - 1)) + jreclen >= SECTOR_SIZE)
{
this_dir->jsize = (this_dir->jsize + (SECTOR_SIZE - 1)) &
this_dir->jsize = (this_dir->jsize + (SECTOR_SIZE - 1)) &
~(SECTOR_SIZE - 1);
}
this_dir->jsize += jreclen;
@ -771,11 +771,11 @@ static int FDECL1(joliet_sort_n_finish, struct directory *, this_dir)
* Similar to the iso9660 case, except here we perform a full sort based upon the
* regular name of the file, not the 8.3 version.
*/
static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
{
char * rpnt, *lpnt;
struct directory_entry ** r, **l;
r = (struct directory_entry **) rr;
l = (struct directory_entry **) ll;
rpnt = (*r)->name;
@ -788,7 +788,7 @@ static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
{
sort_goof++;
}
/*
* Put the '.' and '..' entries on the head of the sorted list.
* For normal ASCII, this always happens to be the case, but out of
@ -800,13 +800,13 @@ static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
if( strcmp(rpnt, "..") == 0 ) return -1;
if( strcmp(lpnt, "..") == 0 ) return 1;
while(*rpnt && *lpnt)
while(*rpnt && *lpnt)
{
if(*rpnt == ';' && *lpnt != ';') return -1;
if(*rpnt != ';' && *lpnt == ';') return 1;
if(*rpnt == ';' && *lpnt == ';') return 0;
/*
* Extensions are not special here. Don't treat the dot as something that
* must be bumped to the start of the list.
@ -815,7 +815,7 @@ static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
if(*rpnt == '.' && *lpnt != '.') return -1;
if(*rpnt != '.' && *lpnt == '.') return 1;
#endif
if(*rpnt < *lpnt) return -1;
if(*rpnt > *lpnt) return 1;
rpnt++; lpnt++;
@ -826,7 +826,7 @@ static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
}
/*
/*
* Function: sort_directory
*
* Purpose: Sort the directory in the appropriate ISO9660
@ -840,7 +840,7 @@ static int FDECL1(joliet_sort_directory, struct directory_entry **, sort_dir)
int i;
struct directory_entry * s_entry;
struct directory_entry ** sortlist;
s_entry = *sort_dir;
while(s_entry)
{
@ -851,9 +851,9 @@ static int FDECL1(joliet_sort_directory, struct directory_entry **, sort_dir)
}
/*
* OK, now we know how many there are. Build a vector for sorting.
* OK, now we know how many there are. Build a vector for sorting.
*/
sortlist = (struct directory_entry **)
sortlist = (struct directory_entry **)
e_malloc(sizeof(struct directory_entry *) * dcount);
dcount = 0;
@ -867,18 +867,18 @@ static int FDECL1(joliet_sort_directory, struct directory_entry **, sort_dir)
}
s_entry = s_entry->next;
}
sort_goof = 0;
#ifdef __STDC__
qsort(sortlist, dcount, sizeof(struct directory_entry *),
qsort(sortlist, dcount, sizeof(struct directory_entry *),
(int (*)(const void *, const void *))joliet_compare_dirs);
#else
qsort(sortlist, dcount, sizeof(struct directory_entry *),
qsort(sortlist, dcount, sizeof(struct directory_entry *),
joliet_compare_dirs);
#endif
/*
* Now reassemble the linked list in the proper sorted order
/*
* Now reassemble the linked list in the proper sorted order
*/
for(i=0; i<dcount-1; i++)
{
@ -887,7 +887,7 @@ static int FDECL1(joliet_sort_directory, struct directory_entry **, sort_dir)
sortlist[dcount-1]->jnext = NULL;
*sort_dir = sortlist[0];
free(sortlist);
return sort_goof;
}
@ -934,7 +934,7 @@ static void FDECL2(generate_joliet_directories, struct directory *, node, FILE*,
}
}
/* skip if hidden - but not for the rr_moved dir */
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
generate_joliet_directories(dpnt->subdir, outfile);
dpnt = dpnt->next;
}
@ -947,7 +947,7 @@ static void FDECL2(generate_joliet_directories, struct directory *, node, FILE*,
static int FDECL1(jpathtab_write, FILE *, outfile)
{
/*
* Next we write the path tables
* Next we write the path tables
*/
xfwrite(jpath_table_l, 1, jpath_blocks << 11, outfile);
xfwrite(jpath_table_m, 1, jpath_blocks << 11, outfile);
@ -995,7 +995,7 @@ static int FDECL1(jvd_write, FILE *, outfile)
struct iso_primary_descriptor jvol_desc;
/*
* Next we write out the boot volume descriptor for the disc
* Next we write out the boot volume descriptor for the disc
*/
jvol_desc = vol_desc;
get_joliet_vol_desc(&jvol_desc);
@ -1013,7 +1013,7 @@ static int FDECL1(jpathtab_size, int, starting_extent)
jpath_table[1] = 0;
jpath_table[2] = jpath_table[0] + jpath_blocks;
jpath_table[3] = 0;
last_extent += 2*jpath_blocks;
return 0;
}

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>
@ -90,6 +85,8 @@ int extension_record_size = 0;
/* These variables are associated with command line options */
int use_eltorito = 0;
int use_eltorito_emul_floppy = 0;
int use_embedded_boot = 0;
int use_protective_msdos_label = 0;
int use_boot_info_table = 0;
int use_RockRidge = 0;
int use_Joliet = 0;
@ -100,17 +97,18 @@ int rationalize = 0;
int generate_tables = 0;
int print_size = 0;
int split_output = 0;
char * preparer = PREPARER_DEFAULT;
char * publisher = PUBLISHER_DEFAULT;
char * appid = APPID_DEFAULT;
char * copyright = COPYRIGHT_DEFAULT;
char * biblio = BIBLIO_DEFAULT;
char * abstract = ABSTRACT_DEFAULT;
char * volset_id = VOLSET_ID_DEFAULT;
char * volume_id = VOLUME_ID_DEFAULT;
char * system_id = SYSTEM_ID_DEFAULT;
char * boot_catalog = BOOT_CATALOG_DEFAULT;
char * boot_image = BOOT_IMAGE_DEFAULT;
char *preparer = PREPARER_DEFAULT;
char *publisher = PUBLISHER_DEFAULT;
char *appid = APPID_DEFAULT;
char *copyright = COPYRIGHT_DEFAULT;
char *biblio = BIBLIO_DEFAULT;
char *abstract = ABSTRACT_DEFAULT;
char *volset_id = VOLSET_ID_DEFAULT;
char *volume_id = VOLUME_ID_DEFAULT;
char *system_id = SYSTEM_ID_DEFAULT;
char *boot_catalog = BOOT_CATALOG_DEFAULT;
char *boot_image = BOOT_IMAGE_DEFAULT;
char *boot_image_embed = NULL;
int volume_set_size = 1;
int volume_sequence_number = 1;
@ -197,22 +195,28 @@ struct ld_option
#define OPTION_VERSION 173
#define OPTION_PROTECTIVE_MSDOS_LABEL 174
static const struct ld_option ld_options[] =
{
{ {"all-files", no_argument, NULL, 'a'},
'a', NULL, N_("Process all files (don't skip backup files)"), ONE_DASH },
{ {"abstract", required_argument, NULL, OPTION_ABSTRACT},
'\0', "FILE", N_("Set Abstract filename"), ONE_DASH },
'\0', N_("FILE"), N_("Set Abstract filename"), ONE_DASH },
{ {"appid", required_argument, NULL, 'A'},
'A', "ID", N_("Set Application ID"), ONE_DASH },
'A', N_("ID"), N_("Set Application ID"), ONE_DASH },
{ {"biblio", required_argument, NULL, OPTION_BIBLIO},
'\0', "FILE", N_("Set Bibliographic filename"), ONE_DASH },
'\0', N_("FILE"), N_("Set Bibliographic filename"), ONE_DASH },
{ {"copyright", required_argument, NULL, OPTION_COPYRIGHT},
'\0', "FILE", N_("Set Copyright filename"), ONE_DASH },
'\0', N_("FILE"), N_("Set Copyright filename"), ONE_DASH },
{ {"embedded-boot", required_argument, NULL, 'G'},
'G', N_("FILE"), N_("Set embedded boot image name"), TWO_DASHES },
{ {"protective-msdos-label", no_argument, NULL, OPTION_PROTECTIVE_MSDOS_LABEL },
'\0', NULL, N_("Patch a protective DOS-style label in the image"), TWO_DASHES },
{ {"eltorito-boot", required_argument, NULL, 'b'},
'b', "FILE", N_("Set El Torito boot image name"), ONE_DASH },
'b', N_("FILE"), N_("Set El Torito boot image name"), ONE_DASH },
{ {"eltorito-catalog", required_argument, NULL, 'c'},
'c', "FILE", N_("Set El Torito boot catalog name"), ONE_DASH },
'c', N_("FILE"), N_("Set El Torito boot catalog name"), ONE_DASH },
{ {"boot-info-table", no_argument, NULL, OPTION_BOOT_INFO_TABLE },
'\0', NULL, N_("Patch Boot Info Table in El Torito boot image"), ONE_DASH },
{ {"no-emul-boot", no_argument, NULL, OPTION_NO_EMUL_BOOT },
@ -220,7 +224,7 @@ static const struct ld_option ld_options[] =
{ {"eltorito-emul-floppy", no_argument, NULL, OPTION_ELTORITO_EMUL_FLOPPY },
'\0', NULL, N_("Enable floppy drive emulation for El Torito"), TWO_DASHES },
{ {"cdwrite-params", required_argument, NULL, 'C'},
'C', "PARAMS", N_("Magic parameters from cdrecord"), ONE_DASH },
'C', N_("PARAMS"), N_("Magic parameters from cdrecord"), ONE_DASH },
{ {"omit-period", no_argument, NULL, 'd'},
'd', NULL, N_("Omit trailing periods from filenames"), ONE_DASH },
{ {"disable-deep-relocation", no_argument, NULL, 'D'},
@ -234,11 +238,11 @@ static const struct ld_option ld_options[] =
{ {"version", no_argument, NULL, OPTION_VERSION},
'\0', NULL, N_("Print version information and exit"), TWO_DASHES },
{ {"hide", required_argument, NULL, OPTION_I_HIDE},
'\0', "GLOBFILE", N_("Hide ISO9660/RR file"), ONE_DASH },
'\0', N_("GLOBFILE"), N_("Hide ISO9660/RR file"), ONE_DASH },
{ {"hide-joliet", required_argument, NULL, OPTION_J_HIDE},
'\0', "GLOBFILE", N_("Hide Joliet file"), ONE_DASH },
'\0', N_("GLOBFILE"), N_("Hide Joliet file"), ONE_DASH },
{ {NULL, required_argument, NULL, 'i'},
'i', "ADD_FILES", N_("No longer supported"), TWO_DASHES },
'i', N_("ADD_FILES"), N_("No longer supported"), TWO_DASHES },
{ {"joliet", no_argument, NULL, 'J'},
'J', NULL, N_("Generate Joliet directory information"), ONE_DASH },
{ {"full-iso9660-filenames", no_argument, NULL, 'l'},
@ -246,11 +250,11 @@ static const struct ld_option ld_options[] =
{ {"allow-leading-dots", no_argument, NULL, 'L'},
'L', NULL, N_("Allow iso9660 filenames to start with '.'"), ONE_DASH },
{ {"log-file", required_argument, NULL, OPTION_LOG_FILE},
'\0', "LOG_FILE", N_("Re-direct messages to LOG_FILE"), ONE_DASH },
'\0', N_("LOG_FILE"), N_("Re-direct messages to LOG_FILE"), ONE_DASH },
{ {"exclude", required_argument, NULL, 'm'},
'm', "GLOBFILE", N_("Exclude file name"), ONE_DASH },
'm', N_("GLOBFILE"), N_("Exclude file name"), ONE_DASH },
{ {"prev-session", required_argument, NULL, 'M'},
'M', "FILE", N_("Set path to previous session to merge"), ONE_DASH },
'M', N_("FILE"), N_("Set path to previous session to merge"), ONE_DASH },
{ {"omit-version-number", no_argument, NULL, 'N'},
'N', NULL, N_("Omit version number from iso9660 filename"), ONE_DASH },
{ {"no-split-symlink-components", no_argument, NULL, 0},
@ -258,13 +262,13 @@ static const struct ld_option ld_options[] =
{ {"no-split-symlink-fields", no_argument, NULL, 0},
0, NULL, N_("Inhibit splitting symlink fields"), ONE_DASH },
{ {"output", required_argument, NULL, 'o'},
'o', "FILE", N_("Set output file name"), ONE_DASH },
'o', N_("FILE"), N_("Set output file name"), ONE_DASH },
{ {"preparer", required_argument, NULL, 'p'},
'p', "PREP", N_("Set Volume preparer"), ONE_DASH },
'p', N_("PREP"), N_("Set Volume preparer"), ONE_DASH },
{ {"print-size", no_argument, NULL, OPTION_PRINT_SIZE},
'\0', NULL, N_("Print estimated filesystem size and exit"), ONE_DASH },
{ {"publisher", required_argument, NULL, 'P'},
'P', "PUB", N_("Set Volume publisher"), ONE_DASH },
'P', N_("PUB"), N_("Set Volume publisher"), ONE_DASH },
{ {"quiet", no_argument, NULL, OPTION_QUIET},
'\0', NULL, N_("Run quietly"), ONE_DASH },
{ {"rational-rock", no_argument, NULL, 'r'},
@ -274,21 +278,21 @@ static const struct ld_option ld_options[] =
{ {"split-output", no_argument, NULL, OPTION_SPLIT_OUTPUT},
'\0', NULL, N_("Split output into files of approx. 1GB size"), ONE_DASH },
{ {"sysid", required_argument, NULL, OPTION_SYSID},
'\0', "ID", N_("Set System ID"), ONE_DASH },
'\0', N_("ID"), N_("Set System ID"), ONE_DASH },
{ {"translation-table", no_argument, NULL, 'T'},
'T', NULL, N_("Generate translation tables for systems that don't understand long filenames"), ONE_DASH },
{ {"verbose", no_argument, NULL, 'v'},
'v', NULL, N_("Verbose"), ONE_DASH },
{ {"volid", required_argument, NULL, 'V'},
'V', "ID", N_("Set Volume ID"), ONE_DASH },
'V', N_("ID"), N_("Set Volume ID"), ONE_DASH },
{ {"volset", required_argument, NULL, OPTION_VOLSET},
'\0', "ID", N_("Set Volume set ID"), ONE_DASH },
'\0', N_("ID"), N_("Set Volume set ID"), ONE_DASH },
{ {"volset-size", required_argument, NULL, OPTION_VOLSET_SIZE},
'\0', "#", N_("Set Volume set size"), ONE_DASH },
{ {"volset-seqno", required_argument, NULL, OPTION_VOLSET_SEQ_NUM},
'\0', "#", N_("Set Volume set sequence number"), ONE_DASH },
{ {"old-exclude", required_argument, NULL, 'x'},
'x', "FILE", N_("Exclude file name (deprecated)"), ONE_DASH },
'x', N_("FILE"), N_("Exclude file name (deprecated)"), ONE_DASH },
#ifdef ERIC_neverdef
{ {"transparent-compression", no_argument, NULL, 'z'},
'z', NULL, "Enable transparent compression of files", ONE_DASH },
@ -481,6 +485,7 @@ void usage(){
int comma;
int len;
unsigned int j;
const char *arg;
printf (" ");
@ -502,8 +507,9 @@ void usage(){
putchar (' ');
++len;
}
printf ("%s", ld_options[j].arg);
len += strlen (ld_options[j].arg);
arg = gettext (ld_options[j].arg);
printf ("%s", arg);
len += strlen (arg);
}
comma = TRUE;
}
@ -527,8 +533,9 @@ void usage(){
+ strlen (ld_options[j].opt.name));
if (ld_options[j].arg != NULL)
{
printf (" %s", ld_options[j].arg);
len += 1 + strlen (ld_options[j].arg);
arg = gettext (ld_options[j].arg);
printf (" %s", arg);
len += 1 + strlen (arg);
}
comma = TRUE;
}
@ -552,8 +559,8 @@ void usage(){
}
/*
* Fill in date in the iso9660 format
/*
* Fill in date in the iso9660 format
*
* The standards state that the timezone offset is in multiples of 15
* minutes, and is what you add to GMT to get the localtime. The U.S.
@ -571,9 +578,9 @@ int FDECL2(iso9660_date,char *, result, time_t, crtime){
result[4] = local->tm_min;
result[5] = local->tm_sec;
/*
/*
* Must recalculate proper timezone offset each time,
* as some files use daylight savings time and some don't...
* as some files use daylight savings time and some don't...
*/
result[6] = local->tm_yday; /* save yday 'cause gmtime zaps it */
local = gmtime(&crtime);
@ -581,11 +588,11 @@ int FDECL2(iso9660_date,char *, result, time_t, crtime){
local->tm_yday -= result[6];
local->tm_hour -= result[3];
local->tm_min -= result[4];
if (local->tm_year < 0)
if (local->tm_year < 0)
{
local->tm_yday = -1;
}
else
else
{
if (local->tm_year > 0) local->tm_yday = 1;
}
@ -633,9 +640,11 @@ int FDECL2(main, int, argc, char **, argv){
char *log_file = 0;
set_program_name (argv[0]);
#if (defined(ENABLE_NLS) && ENABLE_NLS)
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
if (argc < 2)
usage();
@ -716,10 +725,16 @@ int FDECL2(main, int, argc, char **, argv){
use_eltorito++;
boot_image = optarg; /* pathname of the boot image on cd */
if (boot_image == NULL)
{
fprintf (stderr, _("Required boot image pathname missing\n"));
exit (1);
}
error (1, 0, _("Required boot image pathname missing"));
break;
case 'G':
use_embedded_boot = 1;
boot_image_embed = optarg; /* pathname of the boot image on host filesystem */
if (boot_image_embed == NULL)
error (1, 0, _("Required boot image pathname missing"));
break;
case OPTION_PROTECTIVE_MSDOS_LABEL:
use_protective_msdos_label = 1;
break;
case 'c':
use_eltorito++;
@ -894,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:
@ -954,7 +969,7 @@ parse_input_files:
{
int resource;
struct rlimit rlp;
if (getrlimit(RLIMIT_DATA,&rlp) == -1)
if (getrlimit(RLIMIT_DATA,&rlp) == -1)
perror (_("Warning: getrlimit"));
else {
rlp.rlim_cur=33554432;
@ -1074,7 +1089,7 @@ parse_input_files:
merge_image);
}
memcpy(&de.isorec.extent, mrootp->extent, 8);
memcpy(&de.isorec.extent, mrootp->extent, 8);
}
/*
@ -1157,8 +1172,8 @@ parse_input_files:
break;
}
*pnt = '\0';
graft_dir = find_or_create_directory(graft_dir,
graft_point,
graft_dir = find_or_create_directory(graft_dir,
graft_point,
NULL, TRUE);
*pnt = PATH_SEPARATOR;
xpnt = pnt + 1;
@ -1244,12 +1259,12 @@ parse_input_files:
if (goof)
error (1, 0, _("Joliet tree sort failed.\n"));
/*
* Fix a couple of things in the root directory so that everything
* is self consistent.
*/
root->self = root->contents; /* Fix this up so that the path
root->self = root->contents; /* Fix this up so that the path
tables get done right */
/*
@ -1326,8 +1341,8 @@ parse_input_files:
outputlist_insert(&dirtree_clean);
if(extension_record)
{
if(extension_record)
{
outputlist_insert(&extension_desc);
}
@ -1338,7 +1353,7 @@ parse_input_files:
* will always be a primary and an end volume descriptor.
*/
last_extent = session_start;
/*
* Calculate the size of all of the components of the disc, and assign
* extent numbers.
@ -1384,7 +1399,7 @@ parse_input_files:
if( verbose > 0 )
{
#ifdef HAVE_SBRK
fprintf (stderr, _("Max brk space used %x\n"),
fprintf (stderr, _("Max brk space used %x\n"),
(unsigned int)(((unsigned long)sbrk(0)) - mem_start));
#endif
fprintf (stderr, _("%llu extents written (%llu MiB)\n"), last_extent, last_extent >> 9);

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 (defined(ENABLE_NLS) && ENABLE_NLS)
# include <locale.h>
# include <libintl.h>
#else /* ! (defined(ENABLE_NLS) && 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 /* (defined(ENABLE_NLS) && ENABLE_NLS) */
#define _(str) gettext(str)
#define N_(str) str
@ -190,7 +203,7 @@ struct file_hash{
unsigned int starting_block;
unsigned int size;
};
/*
* This structure is used to control the output of fragments to the cdrom
@ -243,7 +256,7 @@ extern struct output_fragment jdirtree_desc;
extern struct output_fragment extension_desc;
extern struct output_fragment files_desc;
/*
/*
* This structure describes one complete directory. It has pointers
* to other directories in the overall tree so that it is clear where
* this directory lives in the tree, and it also must contain pointers
@ -296,6 +309,8 @@ extern struct iso_directory_record root_record;
extern struct iso_directory_record jroot_record;
extern int use_eltorito;
extern int use_embedded_boot;
extern int use_protective_msdos_label;
extern int use_eltorito_emul_floppy;
extern int use_boot_info_table;
extern int use_RockRidge;
@ -324,14 +339,14 @@ extern struct directory *
struct directory_entry * self, int));
extern void DECL (finish_cl_pl_entries, (void));
extern int DECL(scan_directory_tree,(struct directory * this_dir,
char * path,
char * path,
struct directory_entry * self));
extern int DECL(insert_file_entry,(struct directory *, char *,
extern int DECL(insert_file_entry,(struct directory *, char *,
char *));
extern void DECL(generate_iso9660_directories,(struct directory *, FILE*));
extern void DECL(dump_tree,(struct directory * node));
extern struct directory_entry * DECL(search_tree_file, (struct
extern struct directory_entry * DECL(search_tree_file, (struct
directory * node,char * filename));
extern void DECL(update_nlink_field,(struct directory * node));
extern void DECL (init_fstatbuf, (void));
@ -372,17 +387,17 @@ extern char *effective_date;
extern FILE * in_image;
extern struct iso_directory_record *
DECL(merge_isofs,(char * path));
DECL(merge_isofs,(char * path));
extern int DECL(free_mdinfo, (struct directory_entry **, int len));
extern struct directory_entry **
extern struct directory_entry **
DECL(read_merging_directory,(struct iso_directory_record *, int*));
extern void
DECL(merge_remaining_entries, (struct directory *,
extern void
DECL(merge_remaining_entries, (struct directory *,
struct directory_entry **, int));
extern int
DECL(merge_previous_session, (struct directory *,
extern int
DECL(merge_previous_session, (struct directory *,
struct iso_directory_record *));
extern int DECL(get_session_start, (int *));
@ -399,7 +414,7 @@ struct dirent * DECL(readdir_add_files, (char **, char *, DIR *));
/* */
extern int DECL(iso9660_file_length,(const char* name,
extern int DECL(iso9660_file_length,(const char* name,
struct directory_entry * sresult, int flag));
extern int DECL(iso9660_date,(char *, time_t));
extern void DECL(add_hash,(struct directory_entry *));
@ -411,7 +426,7 @@ extern int DECL(delete_file_hash,(struct directory_entry *));
extern struct directory_entry * DECL(find_file_hash,(char *));
extern void DECL(add_file_hash,(struct directory_entry *));
extern int DECL(generate_rock_ridge_attributes,(char *, char *,
struct directory_entry *,
struct directory_entry *,
struct stat *, struct stat *,
int deep_flag));
extern char * DECL(generate_rr_extension_record,(char * id, char * descriptor,
@ -438,20 +453,21 @@ extern char * extension_record;
extern int extension_record_extent;
extern int n_data_extents;
/* These are a few goodies that can be specified on the command line, and are
/* These are a few goodies that can be specified on the command line, and are
filled into the root record */
extern char * preparer;
extern char * publisher;
extern char * copyright;
extern char * biblio;
extern char * abstract;
extern char * appid;
extern char * volset_id;
extern char * system_id;
extern char * volume_id;
extern char * boot_catalog;
extern char * boot_image;
extern char *preparer;
extern char *publisher;
extern char *copyright;
extern char *biblio;
extern char *abstract;
extern char *appid;
extern char *volset_id;
extern char *system_id;
extern char *volume_id;
extern char *boot_catalog;
extern char *boot_image;
extern char *boot_image_embed;
extern int volume_set_size;
extern int volume_sequence_number;

View file

@ -0,0 +1,75 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2004,2007 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/>.
*/
#ifndef MSDOS_PARTITION_H
#define MSDOS_PARTITION_H 1
#include <stdint.h>
/* The signature. */
#define MSDOS_PARTITION_SIGNATURE ((0xaa << 8) | 0x55)
/* This is not a flag actually, but used as if it were a flag. */
#define MSDOS_PARTITION_TYPE_HIDDEN_FLAG 0x10
/* The partition entry. */
struct msdos_partition_entry
{
/* If active, 0x80, otherwise, 0x00. */
uint8_t flag;
/* The head of the start. */
uint8_t start_head;
/* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
is the cylinder of the start. Note that S is counted from one. */
uint8_t start_sector;
/* (C & 0xFF) where C is the cylinder of the start. */
uint8_t start_cylinder;
/* The partition type. */
uint8_t type;
/* The end versions of start_head, start_sector and start_cylinder,
respectively. */
uint8_t end_head;
uint8_t end_sector;
uint8_t end_cylinder;
/* The start sector. Note that this is counted from zero. */
uint32_t start;
/* The length in sector units. */
uint32_t length;
} __attribute__ ((packed));
/* The structure of MBR. */
struct msdos_partition_mbr
{
/* The code area (actually, including BPB). */
uint8_t code[446];
/* Four partition entries. */
struct msdos_partition_entry entries[4];
/* The signature 0xaa55. */
uint16_t signature;
} __attribute__ ((packed));
#endif

View file

@ -1,5 +1,5 @@
/*
* File multi.c - scan existing iso9660 image and merge into
* File multi.c - scan existing iso9660 image and merge into
* iso9660 filesystem. Used for multisession support.
*
* Written by Eric Youngdale (1996).
@ -166,7 +166,7 @@ readsecs(startsecno, buffer, sectorcount)
/*
* Parse the RR attributes so we can find the file name.
*/
static int
static int
FDECL3(parse_rr, unsigned char *, pnt, int, len, struct directory_entry *,dpnt)
{
int cont_extent, cont_offset, cont_size;
@ -219,10 +219,10 @@ FDECL3(parse_rr, unsigned char *, pnt, int, len, struct directory_entry *,dpnt)
} /* parse_rr */
static int
FDECL4(check_rr_dates, struct directory_entry *, dpnt,
struct directory_entry *, current,
struct stat *, statbuf,
static int
FDECL4(check_rr_dates, struct directory_entry *, dpnt,
struct directory_entry *, current,
struct stat *, statbuf,
struct stat *,lstatbuf)
{
int cont_extent, cont_offset, cont_size;
@ -233,8 +233,8 @@ FDECL4(check_rr_dates, struct directory_entry *, dpnt,
int same_file_type;
mode_t mode;
char time_buf[7];
cont_extent = cont_offset = cont_size = 0;
same_file = 1;
same_file_type = 1;
@ -270,14 +270,14 @@ FDECL4(check_rr_dates, struct directory_entry *, dpnt,
if( pnt[4] & TF_CREATE )
{
iso9660_date((char *) time_buf, lstatbuf->st_ctime);
if(memcmp(time_buf, pnt+offset, 7) == 0)
if(memcmp(time_buf, pnt+offset, 7) == 0)
same_file = 0;
offset += 7;
}
if( pnt[4] & TF_MODIFY )
{
iso9660_date((char *) time_buf, lstatbuf->st_mtime);
if(memcmp(time_buf, pnt+offset, 7) == 0)
if(memcmp(time_buf, pnt+offset, 7) == 0)
same_file = 0;
offset += 7;
}
@ -350,7 +350,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
while(i < len )
{
idr = (struct iso_directory_record *) &dirbuff[i];
if(idr->length[0] == 0)
if(idr->length[0] == 0)
{
i = (i + SECTOR_SIZE - 1) & ~(SECTOR_SIZE - 1);
continue;
@ -378,7 +378,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
while(i < len )
{
idr = (struct iso_directory_record *) &dirbuff[i];
if(idr->length[0] == 0)
if(idr->length[0] == 0)
{
i = (i + SECTOR_SIZE - 1) & ~(SECTOR_SIZE - 1);
continue;
@ -413,16 +413,16 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
*/
rlen = idr->length[0] & 0xff;
cpnt = (unsigned char *) idr;
rlen -= sizeof(struct iso_directory_record);
cpnt += sizeof(struct iso_directory_record);
rlen += sizeof(idr->name);
cpnt -= sizeof(idr->name);
rlen -= idr->name_len[0];
cpnt += idr->name_len[0];
if((idr->name_len[0] & 1) == 0){
cpnt++;
rlen--;
@ -444,7 +444,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
memset(cpnt, 0, sizeof((*pnt)->isorec.name) - idr->name_len[0]);
parse_rr((*pnt)->rr_attributes, rlen, *pnt);
if( ((*pnt)->isorec.name_len[0] == 1)
&& ( ((*pnt)->isorec.name[0] == 0)
|| ((*pnt)->isorec.name[0] == 1)) )
@ -485,7 +485,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
tt_extent = isonum_733((unsigned char *)idr->extent);
tt_size = isonum_733((unsigned char *)idr->size);
}
pnt++;
i += idr->length[0];
}
@ -515,7 +515,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
{
rlen = isonum_711((*pnt)->isorec.name_len);
if( strncmp((char *) cpnt + 2, (*pnt)->isorec.name,
rlen) == 0
rlen) == 0
&& cpnt[2+rlen] == ' ')
{
(*pnt)->table = e_malloc(strlen((char*)cpnt) - 33);
@ -534,7 +534,7 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
cpnt = cpnt1 + 1;
cpnt1 = cpnt;
}
free(tt_buf);
}
else if( !seen_rockridge && !warning_given )
@ -553,14 +553,14 @@ FDECL2(read_merging_directory, struct iso_directory_record *, mrootp,
{
free(dirbuff);
}
return rtn;
} /* read_merging_directory */
/*
* Free any associated data related to the structures.
*/
int
int
FDECL2(free_mdinfo, struct directory_entry ** , ptr, int, len )
{
int i;
@ -792,7 +792,7 @@ struct iso_directory_record * FDECL1(merge_isofs, char *, path)
/*
* Get the location and size of the root directory.
*/
rootp = (struct iso_directory_record *)
rootp = (struct iso_directory_record *)
malloc(sizeof(struct iso_directory_record));
memcpy(rootp, pri->root_directory_record, sizeof(*rootp));
@ -820,7 +820,7 @@ void FDECL3(merge_remaining_entries, struct directory *, this_dir,
{
continue;
}
if( pnt[i]->name != NULL && pnt[i]->whole_name == NULL)
{
/*
@ -868,7 +868,7 @@ void FDECL3(merge_remaining_entries, struct directory *, this_dir,
this_dir->contents = pnt[i];
pnt[i] = NULL;
}
/*
* If we don't have an entry for the translation table, then
@ -945,7 +945,7 @@ void FDECL3(merge_remaining_entries, struct directory *, this_dir,
* location. FIXME(eric).
*/
static int
FDECL2(merge_old_directory_into_tree, struct directory_entry *, dpnt,
FDECL2(merge_old_directory_into_tree, struct directory_entry *, dpnt,
struct directory *, parent)
{
struct directory_entry **contents = NULL;
@ -997,7 +997,7 @@ FDECL2(merge_old_directory_into_tree, struct directory_entry *, dpnt,
/*
* We can always reuse the TRANS.TBL in this particular case.
*/
contents[i]->de_flags |= SAFE_TO_REUSE_TABLE_ENTRY;
contents[i]->de_flags |= SAFE_TO_REUSE_TABLE_ENTRY;
if( ((contents[i]->isorec.flags[0] & 2) != 0)
&& (i >= 2) )
@ -1059,7 +1059,7 @@ FDECL2(merge_old_directory_into_tree, struct directory_entry *, dpnt,
char * cdwrite_data = NULL;
int
FDECL1(get_session_start, int *, file_addr)
FDECL1(get_session_start, int *, file_addr)
{
char * pnt;
@ -1171,14 +1171,14 @@ FDECL2(merge_previous_session,struct directory *, this_dir,
{
int dflag;
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
{
struct directory * child;
child = find_or_create_directory(this_dir,
s_entry->whole_name,
child = find_or_create_directory(this_dir,
s_entry->whole_name,
s_entry, 1);
dflag = merge_previous_session(child,
dflag = merge_previous_session(child,
&odpnt->isorec);
/* If unable to scan directory, mark this as a non-directory */
if(!dflag)
@ -1188,14 +1188,14 @@ FDECL2(merge_previous_session,struct directory *, this_dir,
}
}
}
/*
* Whatever is left over, are things which are no longer in the tree
* on disk. We need to also merge these into the tree.
*/
merge_remaining_entries(this_dir, orig_contents, n_orig);
free_mdinfo(orig_contents, n_orig);
return 1;
}

View file

@ -27,7 +27,7 @@
#include <ctype.h>
extern int allow_leading_dots;
/*
* Function: iso9660_file_length
*
@ -43,8 +43,8 @@ extern int allow_leading_dots;
* would also be nice to have.
*/
int FDECL3(iso9660_file_length,
const char*, name,
struct directory_entry *, sresult,
const char*, name,
struct directory_entry *, sresult,
int, dirflag)
{
char * c;
@ -69,7 +69,7 @@ int FDECL3(iso9660_file_length,
*/
if(strcmp(name,".") == 0)
{
if(result)
if(result)
{
*result = 0;
}
@ -82,7 +82,7 @@ int FDECL3(iso9660_file_length,
*/
if(strcmp(name,"..") == 0)
{
if(result)
if(result)
{
*result++ = 1;
*result++ = 0;
@ -115,7 +115,7 @@ int FDECL3(iso9660_file_length,
while(*pnt)
{
#ifdef VMS
if( strcmp(pnt,".DIR;1") == 0 )
if( strcmp(pnt,".DIR;1") == 0 )
{
break;
}
@ -126,11 +126,11 @@ int FDECL3(iso9660_file_length,
* generated by some editors. Lower the priority of
* the file.
*/
if(*pnt == '#')
if(*pnt == '#')
{
priority = 1;
pnt++;
continue;
priority = 1;
pnt++;
continue;
}
/*
@ -138,11 +138,11 @@ int FDECL3(iso9660_file_length,
* generated by some editors. Lower the priority of
* the file.
*/
if(*pnt == '~')
if(*pnt == '~')
{
priority = 1;
tildes++;
pnt++;
priority = 1;
tildes++;
pnt++;
continue;
}
@ -170,9 +170,9 @@ int FDECL3(iso9660_file_length,
* If we have a name with multiple '.' characters, we ignore everything
* after we have gotten the extension.
*/
if(ignore)
if(ignore)
{
pnt++;
pnt++;
continue;
}
@ -181,7 +181,7 @@ int FDECL3(iso9660_file_length,
*/
if(seen_semic)
{
if(*pnt >= '0' && *pnt <= '9')
if(*pnt >= '0' && *pnt <= '9')
{
*result++ = *pnt;
}
@ -197,19 +197,19 @@ int FDECL3(iso9660_file_length,
* option. We still only allow one '.' character in the
* name, however.
*/
if(full_iso9660_filenames)
if(full_iso9660_filenames)
{
/* Here we allow a more relaxed syntax. */
if(*pnt == '.')
if(*pnt == '.')
{
if (seen_dot)
if (seen_dot)
{
ignore++;
ignore++;
continue;
}
seen_dot++;
}
if(current_length < 30)
if(current_length < 30)
{
if( !isascii (*pnt))
{
@ -222,21 +222,21 @@ int FDECL3(iso9660_file_length,
}
}
else
{
/*
{
/*
* Dos style filenames. We really restrict the
* names here.
*/
/* It would be nice to have .tar.gz transform to .tgz,
* .ps.gz to .psz, ...
*/
if(*pnt == '.')
if(*pnt == '.')
{
if (!chars_before_dot && !allow_leading_dots)
if (!chars_before_dot && !allow_leading_dots)
{
/* DOS can't read files with dot first */
chars_before_dot++;
if (result)
if (result)
{
*result++ = '_'; /* Substitute underscore */
}
@ -247,36 +247,36 @@ int FDECL3(iso9660_file_length,
* If this isn't the dot that we use for the extension,
* then change the character into a '_' instead.
*/
if(chars_before_dot < 8)
if(chars_before_dot < 8)
{
chars_before_dot++;
if(result)
if(result)
{
*result++ = '_';
}
}
}
else
else
{
if (seen_dot)
if (seen_dot)
{
ignore++; continue;
}
if(result)
if(result)
{
*result++ = '.';
}
seen_dot++;
}
}
else
else
{
if( (seen_dot && (chars_after_dot < 3) && ++chars_after_dot)
|| (!seen_dot && (chars_before_dot < 8) && ++chars_before_dot) )
{
if(result)
if(result)
{
switch (*pnt)
switch (*pnt)
{
default:
if( !isascii (*pnt) )
@ -289,7 +289,7 @@ int FDECL3(iso9660_file_length,
}
break;
/*
/*
* Descriptions of DOS's 'Parse Filename'
* (function 29H) describes V1 and V2.0+
* separator and terminator characters.
@ -329,7 +329,7 @@ int FDECL3(iso9660_file_length,
current_length++;
pnt++;
} /* while (*pnt) */
/*
* OK, that wraps up the scan of the name. Now tidy up a few other
* things.
@ -345,11 +345,11 @@ int FDECL3(iso9660_file_length,
{
int prio1 = 0;
pnt = name;
while (*pnt && *pnt != '~')
while (*pnt && *pnt != '~')
{
pnt++;
}
if (*pnt)
if (*pnt)
{
pnt++;
}
@ -360,7 +360,7 @@ int FDECL3(iso9660_file_length,
}
priority = prio1;
}
/*
* If this is not a directory, force a '.' in case we haven't
* seen one, and add a version number if we haven't seen one
@ -368,12 +368,12 @@ int FDECL3(iso9660_file_length,
*/
if (!dirflag)
{
if (!seen_dot && !omit_period)
if (!seen_dot && !omit_period)
{
if (result) *result++ = '.';
if (result) *result++ = '.';
extra++;
}
if(!omit_version_number && !seen_semic)
if(!omit_version_number && !seen_semic)
{
if(result)
{
@ -383,8 +383,8 @@ int FDECL3(iso9660_file_length,
extra += 2;
}
}
if(result)
if(result)
{
*result++ = 0;
}

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
@ -87,7 +87,7 @@
a CE entry for the continuation record */
#define MAYBE_ADD_CE_ENTRY(BYTES) \
((unsigned) ((BYTES) + CE_SIZE + currlen + ipnt) > (unsigned) (recstart + reclimit) ? 1 : 0)
((unsigned) ((BYTES) + CE_SIZE + currlen + ipnt) > (unsigned) (recstart + reclimit) ? 1 : 0)
/*
* Buffer to build RR attributes
@ -210,13 +210,13 @@ int deep_opt;
};
/*
* Add the posix modes
* Add the posix modes
*/
if(MAYBE_ADD_CE_ENTRY(PX_SIZE)) add_CE_entry();
Rock[ipnt++] ='P';
Rock[ipnt++] ='X';
Rock[ipnt++] = PX_SIZE;
Rock[ipnt++] = SU_VERSION;
Rock[ipnt++] = SU_VERSION;
flagval |= (1<<0);
set_733((char*)Rock + ipnt, lstatbuf->st_mode);
ipnt += 8;
@ -236,7 +236,7 @@ int deep_opt;
Rock[ipnt++] ='P';
Rock[ipnt++] ='N';
Rock[ipnt++] = PN_SIZE;
Rock[ipnt++] = SU_VERSION;
Rock[ipnt++] = SU_VERSION;
flagval |= (1<<1);
#if defined(MAJOR_IN_SYSMACROS) || defined(MAJOR_IN_MKDEV)
set_733((char*)Rock + ipnt, major(lstatbuf->st_rdev ));
@ -286,27 +286,27 @@ int deep_opt;
cpnt = &symlink_buff[0];
flagval |= (1<<2);
if (! split_SL_field)
if (! split_SL_field)
{
int sl_bytes = 0;
for (cpnt1 = cpnt; *cpnt1 != '\0'; cpnt1++)
for (cpnt1 = cpnt; *cpnt1 != '\0'; cpnt1++)
{
if (*cpnt1 == '/')
if (*cpnt1 == '/')
{
sl_bytes += 4;
}
else
}
else
{
sl_bytes += 1;
}
}
if (sl_bytes > 250)
if (sl_bytes > 250)
{
/*
/*
* the symbolic link won't fit into one SL System Use Field
* print an error message and continue with splited one
* 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();
}
@ -317,7 +317,7 @@ int deep_opt;
Rock[ipnt++] ='L';
lenpos = ipnt;
Rock[ipnt++] = SL_SIZE;
Rock[ipnt++] = SU_VERSION;
Rock[ipnt++] = SU_VERSION;
Rock[ipnt++] = 0; /* Flags */
lenval = 5;
while(*cpnt){
@ -326,7 +326,7 @@ int deep_opt;
nchar--;
*cpnt1 = 0;
};
/* We treat certain components in a special way. */
if(cpnt[0] == '.' && cpnt[1] == '.' && cpnt[2] == 0){
if(MAYBE_ADD_CE_ENTRY(2)) add_CE_entry();
@ -349,7 +349,7 @@ int deep_opt;
/* If we do not have enough room for a component, start
a new continuations segment now */
if(split_SL_component ? MAYBE_ADD_CE_ENTRY(6) :
MAYBE_ADD_CE_ENTRY(6 + strlen ((char *) cpnt)))
MAYBE_ADD_CE_ENTRY(6 + strlen ((char *) cpnt)))
{
add_CE_entry();
if(cpnt1)
@ -397,7 +397,7 @@ int deep_opt;
if(nchar) Rock[lenpos + 2] = SL_CONTINUE; /* We need another SL entry */
} /* while nchar */
} /* Is a symbolic link */
/*
/*
* Add in the Rock Ridge TF time field
*/
if(MAYBE_ADD_CE_ENTRY(TF_SIZE)) add_CE_entry();
@ -422,7 +422,7 @@ int deep_opt;
iso9660_date((char *) &Rock[ipnt], lstatbuf->st_ctime);
ipnt += 7;
/*
/*
* Add in the Rock Ridge RE time field
*/
if(deep_opt & NEED_RE){
@ -433,7 +433,7 @@ int deep_opt;
Rock[ipnt++] = SU_VERSION;
flagval |= (1<<6);
};
/*
/*
* Add in the Rock Ridge PL record, if required.
*/
if(deep_opt & NEED_PL){
@ -447,7 +447,7 @@ int deep_opt;
flagval |= (1<<5);
};
/*
/*
* Add in the Rock Ridge CL field, if required.
*/
if(deep_opt & NEED_CL){
@ -464,7 +464,7 @@ int deep_opt;
#ifndef VMS
/* If transparent compression was requested, fill in the correct
field for this file */
if(transparent_compression &&
if(transparent_compression &&
S_ISREG(lstatbuf->st_mode) &&
strlen(name) > 3 &&
strcmp(name + strlen(name) - 3,".gZ") == 0){
@ -498,8 +498,8 @@ int deep_opt;
else {
int blocksize;
blocksize = (header[3] << 8) | header[2];
file_size = ((unsigned int)header[7] << 24) |
((unsigned int)header[6] << 16) |
file_size = ((unsigned int)header[7] << 24) |
((unsigned int)header[6] << 16) |
((unsigned int)header[5] << 8) | header[4];
#if 0
fprintf(stderr,"Blocksize = %d %d\n", blocksize, file_size);
@ -534,7 +534,7 @@ int deep_opt;
};
}
#endif
/*
/*
* Add in the Rock Ridge CE field, if required. We use this for the
* extension record that is stored in the root directory.
*/

File diff suppressed because it is too large Load diff

View file

@ -21,11 +21,10 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include "config.h"
#include "mkisofs.h"
#include "iso9660.h"
#include <time.h>
#include <errno.h>
@ -37,7 +36,11 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "mkisofs.h"
#include "iso9660.h"
#include "msdos_partition.h"
#ifdef __SVR4
extern char * strdup(const char *);
#endif
@ -155,10 +158,10 @@ 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)
while(count)
{
size_t got = fwrite (buffer, size, count, file);
@ -193,7 +196,7 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
struct directory * dpnt;
dpnt = node;
while (dpnt)
{
/* skip if it's hidden */
@ -211,13 +214,13 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
{
dpnt->extent = last_extent;
dir_size = (dpnt->size + (SECTOR_SIZE - 1)) >> 11;
last_extent += dir_size;
/*
/*
* Leave room for the CE entries for this directory. Keep them
* close to the reference directory so that access will be
* quick.
* close to the reference directory so that access will be
* quick.
*/
if(dpnt->ce_bytes)
{
@ -225,7 +228,7 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
}
}
if(dpnt->subdir)
if(dpnt->subdir)
{
assign_directory_addresses(dpnt->subdir);
}
@ -235,7 +238,7 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
return 0;
}
static void FDECL3(write_one_file, char *, filename,
static void FDECL3(write_one_file, char *, filename,
uint64_t, size, FILE *, outfile)
{
char buffer[SECTOR_SIZE * NSECT];
@ -244,7 +247,7 @@ static void FDECL3(write_one_file, char *, filename,
size_t use;
if ((infile = fopen(filename, "rb")) == NULL)
if ((infile = fopen(filename, "rb")) == NULL)
error (1, errno, _("cannot open %s\n"), filename);
remain = size;
@ -253,12 +256,12 @@ static void FDECL3(write_one_file, char *, filename,
use = (remain > SECTOR_SIZE * NSECT - 1 ? NSECT*SECTOR_SIZE : remain);
use = ROUND_UP(use); /* Round up to nearest sector boundary */
memset(buffer, 0, use);
if (fread(buffer, 1, use, infile) == 0)
error (1, errno, _("cannot read %llu bytes from %s"), use, filename);
if (fread(buffer, 1, use, infile) == 0)
error (1, errno, _("cannot read %llu bytes from %s"), use, filename);
xfwrite(buffer, 1, use, outfile);
last_extent_written += use/SECTOR_SIZE;
#if 0
if((last_extent_written % 1000) < use/SECTOR_SIZE)
if((last_extent_written % 1000) < use/SECTOR_SIZE)
{
fprintf(stderr,"%d..", last_extent_written);
}
@ -268,7 +271,7 @@ static void FDECL3(write_one_file, char *, filename,
time_t now;
time_t the_end;
double frac;
time(&now);
frac = last_extent_written / (double)last_extent;
the_end = begun + (now - begun) / frac;
@ -287,13 +290,13 @@ static void FDECL1(write_files, FILE *, outfile)
dwpnt = dw_head;
while(dwpnt)
{
if(dwpnt->table)
if(dwpnt->table)
{
write_one_file (dwpnt->table, dwpnt->size, outfile);
table_size += dwpnt->size;
free (dwpnt->table);
}
else
else
{
#ifdef VMS
@ -324,11 +327,11 @@ static void dump_filelist()
}
#endif
static int FDECL2(compare_dirs, const void *, rr, const void *, ll)
static int FDECL2(compare_dirs, const void *, rr, const void *, ll)
{
char * rpnt, *lpnt;
struct directory_entry ** r, **l;
r = (struct directory_entry **) rr;
l = (struct directory_entry **) ll;
rpnt = (*r)->isorec.name;
@ -341,7 +344,7 @@ static int FDECL2(compare_dirs, const void *, rr, const void *, ll)
{
sort_goof++;
}
/*
* Put the '.' and '..' entries on the head of the sorted list.
* For normal ASCII, this always happens to be the case, but out of
@ -373,16 +376,16 @@ static int FDECL2(compare_dirs, const void *, rr, const void *, ll)
if((*l)->isorec.name_len[0] == 1 && *lpnt == 1) return 1;
#endif
while(*rpnt && *lpnt)
while(*rpnt && *lpnt)
{
if(*rpnt == ';' && *lpnt != ';') return -1;
if(*rpnt != ';' && *lpnt == ';') return 1;
if(*rpnt == ';' && *lpnt == ';') return 0;
if(*rpnt == '.' && *lpnt != '.') return -1;
if(*rpnt != '.' && *lpnt == '.') return 1;
if((unsigned char)*rpnt < (unsigned char)*lpnt) return -1;
if((unsigned char)*rpnt > (unsigned char)*lpnt) return 1;
rpnt++; lpnt++;
@ -392,7 +395,7 @@ static int FDECL2(compare_dirs, const void *, rr, const void *, ll)
return 0;
}
/*
/*
* Function: sort_directory
*
* Purpose: Sort the directory in the appropriate ISO9660
@ -408,7 +411,7 @@ int FDECL1(sort_directory, struct directory_entry **, sort_dir)
int i, len;
struct directory_entry * s_entry;
struct directory_entry ** sortlist;
/* need to keep a count of how many entries are hidden */
s_entry = *sort_dir;
while(s_entry)
@ -425,9 +428,9 @@ int FDECL1(sort_directory, struct directory_entry **, sort_dir)
}
/*
* OK, now we know how many there are. Build a vector for sorting.
* OK, now we know how many there are. Build a vector for sorting.
*/
sortlist = (struct directory_entry **)
sortlist = (struct directory_entry **)
e_malloc(sizeof(struct directory_entry *) * dcount);
j = dcount - 1;
@ -449,29 +452,29 @@ int FDECL1(sort_directory, struct directory_entry **, sort_dir)
s_entry->isorec.name[len] = 0;
s_entry = s_entry->next;
}
/*
* Each directory is required to contain at least . and ..
*/
if( dcount < 2 )
{
sort_goof = 1;
}
else
{
/* only sort the non-hidden entries */
sort_goof = 0;
#ifdef __STDC__
qsort(sortlist, dcount, sizeof(struct directory_entry *),
qsort(sortlist, dcount, sizeof(struct directory_entry *),
(int (*)(const void *, const void *))compare_dirs);
#else
qsort(sortlist, dcount, sizeof(struct directory_entry *),
qsort(sortlist, dcount, sizeof(struct directory_entry *),
compare_dirs);
#endif
/*
* Now reassemble the linked list in the proper sorted order
/*
* Now reassemble the linked list in the proper sorted order
* We still need the hidden entries, as they may be used in the
* Joliet tree.
*/
@ -479,7 +482,7 @@ int FDECL1(sort_directory, struct directory_entry **, sort_dir)
{
sortlist[i]->next = sortlist[i+1];
}
sortlist[dcount+xcount-1]->next = NULL;
*sort_dir = sortlist[0];
}
@ -491,7 +494,7 @@ int FDECL1(sort_directory, struct directory_entry **, sort_dir)
static int root_gen()
{
init_fstatbuf();
root_record.length[0] = 1 + sizeof(struct iso_directory_record)
- sizeof(root_record.name);
root_record.ext_attr_length[0] = 0;
@ -530,16 +533,16 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
{
continue;
}
/*
* This saves some space if there are symlinks present
/*
* This saves some space if there are symlinks present
*/
s_hash = find_hash(s_entry->dev, s_entry->inode);
if(s_hash)
{
if(verbose > 2)
{
fprintf (stderr, _("Cache hit for %s%s%s\n"), s_entry->filedir->de_name,
fprintf (stderr, _("Cache hit for %s%s%s\n"), s_entry->filedir->de_name,
SPATH_SEPARATOR, s_entry->name);
}
set_733((char *) s_entry->isorec.extent, s_hash->starting_block);
@ -548,12 +551,12 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
}
/*
* If this is for a directory that is not a . or a .. entry,
* If this is for a directory that is not a . or a .. entry,
* then look up the information for the entry. We have already
* assigned extents for directories, so we just need to
* fill in the blanks here.
*/
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,"..") &&
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,"..") &&
s_entry->isorec.flags[0] == 2)
{
finddir = dpnt->subdir;
@ -561,7 +564,7 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
{
if(finddir->self == s_entry) break;
finddir = finddir->next;
if (!finddir)
if (!finddir)
error (1, 0, _("Fatal goof\n"));
}
set_733((char *) s_entry->isorec.extent, finddir->extent);
@ -578,45 +581,45 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
* If this is . or .., then look up the relevant info from the
* tables.
*/
if(strcmp(s_entry->name,".") == 0)
if(strcmp(s_entry->name,".") == 0)
{
set_733((char *) s_entry->isorec.extent, dpnt->extent);
/*
/*
* Set these so that the hash table has the
* correct information
*/
s_entry->starting_block = dpnt->extent;
s_entry->size = ROUND_UP(dpnt->size);
add_hash(s_entry);
s_entry->starting_block = dpnt->extent;
set_733((char *) s_entry->isorec.size, ROUND_UP(dpnt->size));
continue;
}
if(strcmp(s_entry->name,"..") == 0)
if(strcmp(s_entry->name,"..") == 0)
{
if(dpnt == root)
{
{
total_dir_size += root->size;
}
set_733((char *) s_entry->isorec.extent, dpnt->parent->extent);
/*
/*
* Set these so that the hash table has the
* correct information
*/
s_entry->starting_block = dpnt->parent->extent;
s_entry->size = ROUND_UP(dpnt->parent->size);
add_hash(s_entry);
s_entry->starting_block = dpnt->parent->extent;
set_733((char *) s_entry->isorec.size, ROUND_UP(dpnt->parent->size));
continue;
}
/*
/*
* Some ordinary non-directory file. Just schedule the
* file to be written. This is all quite
* straightforward, just make a list and assign extents
@ -624,28 +627,28 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
* directories, we should be ready write out these
* files
*/
if(s_entry->size)
if(s_entry->size)
{
dwpnt = (struct deferred_write *)
dwpnt = (struct deferred_write *)
e_malloc(sizeof(struct deferred_write));
if(dw_tail)
{
dw_tail->next = dwpnt;
dw_tail = dwpnt;
}
else
}
else
{
dw_head = dwpnt;
dw_tail = dwpnt;
}
if(s_entry->inode == TABLE_INODE)
if(s_entry->inode == TABLE_INODE)
{
dwpnt->table = s_entry->table;
dwpnt->name = NULL;
sprintf(whole_path,"%s%sTRANS.TBL",
s_entry->filedir->whole_name, SPATH_SEPARATOR);
}
else
}
else
{
dwpnt->table = NULL;
strcpy(whole_path, s_entry->whole_name);
@ -669,15 +672,15 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
fprintf (stderr, "Warning: large file %s\n", whole_path);
fprintf (stderr, "Starting block is %d\n", s_entry->starting_block);
fprintf (stderr, "Reported file size is %d extents\n", s_entry->size);
}
#endif
#ifdef NOT_NEEDED /* Never use this code if you like to create a DVD */
if(last_extent > (800000000 >> 11))
{
if(last_extent > (800000000 >> 11))
{
/*
* More than 800Mb? Punt
* More than 800Mb? Punt
*/
fprintf(stderr,"Extent overflow processing file %s\n", whole_path);
fprintf(stderr,"Starting block is %d\n", s_entry->starting_block);
@ -696,7 +699,7 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt)
*/
set_733((char *) s_entry->isorec.extent, last_extent);
}
if(dpnt->subdir)
if(dpnt->subdir)
{
assign_file_addresses(dpnt->subdir);
}
@ -708,13 +711,13 @@ static void FDECL1(free_one_directory, struct directory *, dpnt)
{
struct directory_entry * s_entry;
struct directory_entry * s_entry_d;
s_entry = dpnt->contents;
while(s_entry)
while(s_entry)
{
s_entry_d = s_entry;
s_entry = s_entry->next;
if( s_entry_d->name != NULL )
{
free (s_entry_d->name);
@ -750,31 +753,31 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
struct directory_entry * s_entry;
struct directory_entry * s_entry_d;
unsigned int total_size;
total_size = (dpnt->size + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1);
directory_buffer = (char *) e_malloc(total_size);
memset(directory_buffer, 0, total_size);
dir_index = 0;
ce_size = (dpnt->ce_bytes + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1);
ce_buffer = NULL;
if(ce_size)
if(ce_size)
{
ce_buffer = (char *) e_malloc(ce_size);
memset(ce_buffer, 0, ce_size);
ce_index = 0;
/*
* Absolute byte address of CE entries for this directory
* Absolute byte address of CE entries for this directory
*/
ce_address = last_extent_written + (total_size >> 11);
ce_address = ce_address << 11;
}
s_entry = dpnt->contents;
while(s_entry)
while(s_entry)
{
/* skip if it's hidden */
if(s_entry->de_flags & INHIBIT_ISO9660_ENTRY) {
@ -782,25 +785,25 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
continue;
}
/*
* We do not allow directory entries to cross sector boundaries.
* Simply pad, and then start the next entry at the next sector
/*
* We do not allow directory entries to cross sector boundaries.
* Simply pad, and then start the next entry at the next sector
*/
new_reclen = s_entry->isorec.length[0];
if( (dir_index & (SECTOR_SIZE - 1)) + new_reclen >= SECTOR_SIZE )
{
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
~(SECTOR_SIZE - 1);
}
memcpy(directory_buffer + dir_index, &s_entry->isorec,
memcpy(directory_buffer + dir_index, &s_entry->isorec,
sizeof(struct iso_directory_record) -
sizeof(s_entry->isorec.name) + s_entry->isorec.name_len[0]);
dir_index += sizeof(struct iso_directory_record) -
dir_index += sizeof(struct iso_directory_record) -
sizeof (s_entry->isorec.name)+ s_entry->isorec.name_len[0];
/*
* Add the Rock Ridge attributes, if present
* Add the Rock Ridge attributes, if present
*/
if(s_entry->rr_attr_size)
{
@ -809,20 +812,20 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
directory_buffer[dir_index++] = 0;
}
/*
/*
* If the RR attributes were too long, then write the
* CE records, as required.
*/
if(s_entry->rr_attr_size != s_entry->total_rr_attr_size)
if(s_entry->rr_attr_size != s_entry->total_rr_attr_size)
{
unsigned char * pnt;
int len, nbytes;
/*
/*
* Go through the entire record and fix up the CE entries
* so that the extent and offset are correct
* so that the extent and offset are correct
*/
pnt = s_entry->rr_attributes;
len = s_entry->total_rr_attr_size;
while(len > 3)
@ -834,30 +837,30 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
ce_index, ce_address);
}
#endif
if(pnt[0] == 'C' && pnt[1] == 'E')
if(pnt[0] == 'C' && pnt[1] == 'E')
{
nbytes = get_733( (char *) pnt+20);
if((ce_index & (SECTOR_SIZE - 1)) + nbytes >=
SECTOR_SIZE)
SECTOR_SIZE)
{
ce_index = ROUND_UP(ce_index);
}
set_733( (char *) pnt+4,
set_733( (char *) pnt+4,
(ce_address + ce_index) >> 11);
set_733( (char *) pnt+12,
set_733( (char *) pnt+12,
(ce_address + ce_index) & (SECTOR_SIZE - 1));
/*
* Now store the block in the ce buffer
/*
* Now store the block in the ce buffer
*/
memcpy(ce_buffer + ce_index,
memcpy(ce_buffer + ce_index,
pnt + pnt[2], nbytes);
ce_index += nbytes;
if(ce_index & 1)
if(ce_index & 1)
{
ce_index++;
}
@ -865,11 +868,11 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
len -= pnt[2];
pnt += pnt[2];
}
}
rockridge_size += s_entry->total_rr_attr_size;
memcpy(directory_buffer + dir_index, s_entry->rr_attributes,
memcpy(directory_buffer + dir_index, s_entry->rr_attributes,
s_entry->rr_attr_size);
dir_index += s_entry->rr_attr_size;
}
@ -877,14 +880,14 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
{
directory_buffer[dir_index++] = 0;
}
s_entry_d = s_entry;
s_entry = s_entry->next;
/*
* Joliet doesn't use the Rock Ridge attributes, so we free it here.
*/
if (s_entry_d->rr_attributes)
if (s_entry_d->rr_attributes)
{
free(s_entry_d->rr_attributes);
s_entry_d->rr_attributes = NULL;
@ -912,16 +915,16 @@ void FDECL2(generate_one_directory, struct directory *, dpnt, FILE *, outfile)
last_extent_written += ce_size >> 11;
free(ce_buffer);
}
} /* generate_one_directory(... */
static
static
void FDECL1(build_pathlist, struct directory *, node)
{
struct directory * dpnt;
dpnt = node;
while (dpnt)
{
/* skip if it's hidden */
@ -933,7 +936,7 @@ void FDECL1(build_pathlist, struct directory *, node)
}
} /* build_pathlist(... */
static int FDECL2(compare_paths, void const *, r, void const *, l)
static int FDECL2(compare_paths, void const *, r, void const *, l)
{
struct directory const *ll = *(struct directory * const *)l;
struct directory const *rr = *(struct directory * const *)r;
@ -943,13 +946,13 @@ static int FDECL2(compare_paths, void const *, r, void const *, l)
return -1;
}
if (rr->parent->path_index > ll->parent->path_index)
if (rr->parent->path_index > ll->parent->path_index)
{
return 1;
}
return strcmp(rr->self->isorec.name, ll->self->isorec.name);
} /* compare_paths(... */
static int generate_path_tables()
@ -965,7 +968,7 @@ static int generate_path_tables()
int tablesize;
/*
* First allocate memory for the tables and initialize the memory
* First allocate memory for the tables and initialize the memory
*/
tablesize = path_blocks << 11;
path_table_m = (char *) e_malloc(tablesize);
@ -974,7 +977,7 @@ static int generate_path_tables()
memset(path_table_m, 0, tablesize);
/*
* Now start filling in the path tables. Start with root directory
* Now start filling in the path tables. Start with root directory
*/
if( next_path_index > 0xffff )
{
@ -983,7 +986,7 @@ static int generate_path_tables()
}
path_table_index = 0;
pathlist = (struct directory **) e_malloc(sizeof(struct directory *)
pathlist = (struct directory **) e_malloc(sizeof(struct directory *)
* next_path_index);
memset(pathlist, 0, sizeof(struct directory *) * next_path_index);
build_pathlist(root);
@ -992,10 +995,10 @@ static int generate_path_tables()
{
fix = 0;
#ifdef __STDC__
qsort(&pathlist[1], next_path_index-1, sizeof(struct directory *),
qsort(&pathlist[1], next_path_index-1, sizeof(struct directory *),
(int (*)(const void *, const void *))compare_paths);
#else
qsort(&pathlist[1], next_path_index-1, sizeof(struct directory *),
qsort(&pathlist[1], next_path_index-1, sizeof(struct directory *),
compare_paths);
#endif
@ -1017,55 +1020,55 @@ static int generate_path_tables()
error (1, 0, _("Entry %d not in path tables\n"), j);
}
npnt = dpnt->de_name;
/*
* So the root comes out OK
/*
* So the root comes out OK
*/
if( (*npnt == 0) || (dpnt == root) )
if( (*npnt == 0) || (dpnt == root) )
{
npnt = ".";
npnt = ".";
}
npnt1 = strrchr(npnt, PATH_SEPARATOR);
if(npnt1)
{
if(npnt1)
{
npnt = npnt1 + 1;
}
de = dpnt->self;
if(!de)
if(!de)
{
error (1, 0, _("Fatal goof\n"));
}
namelen = de->isorec.name_len[0];
path_table_l[path_table_index] = namelen;
path_table_m[path_table_index] = namelen;
path_table_index += 2;
set_731(path_table_l + path_table_index, dpnt->extent);
set_732(path_table_m + path_table_index, dpnt->extent);
set_731(path_table_l + path_table_index, dpnt->extent);
set_732(path_table_m + path_table_index, dpnt->extent);
path_table_index += 4;
set_721(path_table_l + path_table_index,
dpnt->parent->path_index);
set_722(path_table_m + path_table_index,
dpnt->parent->path_index);
set_721(path_table_l + path_table_index,
dpnt->parent->path_index);
set_722(path_table_m + path_table_index,
dpnt->parent->path_index);
path_table_index += 2;
for(i =0; i<namelen; i++)
{
path_table_l[path_table_index] = de->isorec.name[i];
path_table_m[path_table_index] = de->isorec.name[i];
path_table_index++;
}
if(path_table_index & 1)
if(path_table_index & 1)
{
path_table_index++; /* For odd lengths we pad */
}
}
free(pathlist);
if(path_table_index != path_table_size)
{
@ -1108,7 +1111,7 @@ static int FDECL1(file_write, FILE *, outfile)
/*
* OK, all done with that crap. Now write out the directories.
* This is where the fur starts to fly, because we need to keep track of
* each file as we find it and keep track of where we put it.
* each file as we find it and keep track of where we put it.
*/
should_write = last_extent - session_start;
@ -1124,16 +1127,16 @@ static int FDECL1(file_write, FILE *, outfile)
#ifdef DBG_ISO
fprintf(stderr,"Total directory extents being written = %llu\n", last_extent);
#endif
fprintf (stderr, _("Total extents scheduled to be written = %llu\n"),
fprintf (stderr, _("Total extents scheduled to be written = %llu\n"),
last_extent - session_start);
}
/*
* Now write all of the files that we need.
/*
* Now write all of the files that we need.
*/
write_files(outfile);
/*
* The rest is just fluff.
*/
@ -1145,8 +1148,8 @@ static int FDECL1(file_write, FILE *, outfile)
fprintf (stderr, _("Total extents actually written = %llu\n"),
last_extent_written - session_start);
/*
* Hard links throw us off here
/*
* Hard links throw us off here
*/
assert (last_extent > session_start);
if(should_write + session_start != last_extent)
@ -1192,7 +1195,7 @@ static int FDECL1(pvd_write, FILE *, outfile)
/*
* This will break in the year 2000, I supose, but there is no good way
* to get the top two digits of the year.
* to get the top two digits of the year.
*/
sprintf(iso_time, "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d00", 1900 + local.tm_year,
local.tm_mon+1, local.tm_mday,
@ -1204,28 +1207,28 @@ static int FDECL1(pvd_write, FILE *, outfile)
iso_time[16] = (local.tm_min + 60*(local.tm_hour + 24*local.tm_yday)) / 15;
/*
* Next we write out the primary descriptor for the disc
* Next we write out the primary descriptor for the disc
*/
memset(&vol_desc, 0, sizeof(vol_desc));
vol_desc.type[0] = ISO_VD_PRIMARY;
memcpy(vol_desc.id, ISO_STANDARD_ID, sizeof(ISO_STANDARD_ID));
vol_desc.version[0] = 1;
memset(vol_desc.system_id, ' ', sizeof(vol_desc.system_id));
memcpy_max(vol_desc.system_id, system_id, strlen(system_id));
memset(vol_desc.volume_id, ' ', sizeof(vol_desc.volume_id));
memcpy_max(vol_desc.volume_id, volume_id, strlen(volume_id));
should_write = last_extent - session_start;
set_733((char *) vol_desc.volume_space_size, should_write);
set_723(vol_desc.volume_set_size, volume_set_size);
set_723(vol_desc.volume_sequence_number, volume_sequence_number);
set_723(vol_desc.logical_block_size, 2048);
/*
* The path tables are used by DOS based machines to cache directory
* locations
* locations
*/
set_733((char *) vol_desc.path_table_size, path_table_size);
@ -1235,9 +1238,9 @@ static int FDECL1(pvd_write, FILE *, outfile)
set_732(vol_desc.opt_type_m_path_table, path_table[3]);
/*
* Now we copy the actual root directory record
* Now we copy the actual root directory record
*/
memcpy(vol_desc.root_directory_record, &root_record,
memcpy(vol_desc.root_directory_record, &root_record,
sizeof(struct iso_directory_record) + 1);
/*
@ -1257,15 +1260,15 @@ static int FDECL1(pvd_write, FILE *, outfile)
if(appid) memcpy_max(vol_desc.application_id, appid, strlen(appid));
FILL_SPACE(copyright_file_id);
if(copyright) memcpy_max(vol_desc.copyright_file_id, copyright,
if(copyright) memcpy_max(vol_desc.copyright_file_id, copyright,
strlen(copyright));
FILL_SPACE(abstract_file_id);
if(abstract) memcpy_max(vol_desc.abstract_file_id, abstract,
if(abstract) memcpy_max(vol_desc.abstract_file_id, abstract,
strlen(abstract));
FILL_SPACE(bibliographic_file_id);
if(biblio) memcpy_max(vol_desc.bibliographic_file_id, biblio,
if(biblio) memcpy_max(vol_desc.bibliographic_file_id, biblio,
strlen(biblio));
FILL_SPACE(creation_date);
@ -1281,7 +1284,7 @@ static int FDECL1(pvd_write, FILE *, outfile)
memcpy(vol_desc.effective_date, effective_date ? effective_date : iso_time, 17);
/*
* if not a bootable cd do it the old way
* if not a bootable cd do it the old way
*/
xfwrite(&vol_desc, 1, 2048, outfile);
last_extent_written++;
@ -1296,7 +1299,7 @@ static int FDECL1(evd_write, FILE *, outfile)
struct iso_primary_descriptor evol_desc;
/*
* Now write the end volume descriptor. Much simpler than the other one
* Now write the end volume descriptor. Much simpler than the other one
*/
memset(&evol_desc, 0, sizeof(evol_desc));
evol_desc.type[0] = ISO_VD_END;
@ -1313,7 +1316,7 @@ static int FDECL1(evd_write, FILE *, outfile)
static int FDECL1(pathtab_write, FILE *, outfile)
{
/*
* Next we write the path tables
* Next we write the path tables
*/
xfwrite(path_table_l, 1, path_blocks << 11, outfile);
xfwrite(path_table_m, 1, path_blocks << 11, outfile);
@ -1344,6 +1347,9 @@ int FDECL1(oneblock_size, int, starting_extent)
/*
* Functions to describe padding block at the start of the disc.
*/
#define PADBLOCK_SIZE 16
static int FDECL1(pathtab_size, int, starting_extent)
{
path_table[0] = starting_extent;
@ -1357,7 +1363,7 @@ static int FDECL1(pathtab_size, int, starting_extent)
static int FDECL1(padblock_size, int, starting_extent)
{
last_extent += 16;
last_extent += PADBLOCK_SIZE;
return 0;
}
@ -1420,17 +1426,50 @@ static int FDECL1(dirtree_cleanup, FILE *, outfile)
static int FDECL1(padblock_write, FILE *, outfile)
{
char buffer[2048];
int i;
char *buffer;
memset(buffer, 0, sizeof(buffer));
buffer = e_malloc (2048 * PADBLOCK_SIZE);
memset (buffer, 0, 2048 * PADBLOCK_SIZE);
for(i=0; i<16; i++)
if (use_embedded_boot)
{
xfwrite(buffer, 1, sizeof(buffer), outfile);
FILE *fp = fopen (boot_image_embed, "rb");
if (! fp)
error (1, errno, _("Unable to open %s"), boot_image_embed);
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);
}
last_extent_written += 16;
if (use_protective_msdos_label)
{
struct msdos_partition_mbr *mbr = (void *) buffer;
memset (mbr->entries, 0, sizeof(mbr->entries));
/* Some idiotic BIOSes refuse to boot if they don't find at least
one partition with active bit set. */
mbr->entries[0].flag = 0x80;
/* Doesn't really matter, as long as it's non-zero. It seems that
0xCD is used elsewhere, so we follow suit. */
mbr->entries[0].type = 0xcd;
/* Start immediately (sector 1). */
mbr->entries[0].start = 1;
/* We don't know yet. Let's keep it safe. */
mbr->entries[0].length = UINT32_MAX;
mbr->signature = MSDOS_PARTITION_SIGNATURE;
}
xfwrite (buffer, 1, 2048 * PADBLOCK_SIZE, outfile);
last_extent_written += PADBLOCK_SIZE;
return 0;
}

85
util/mm.c Normal file
View file

@ -0,0 +1,85 @@
/*
* GRUB -- GRand Unified Bootloader
* 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
* 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/err.h>
#include <grub/mm.h>
#include <stdlib.h>
#include <string.h>
void *
grub_malloc (grub_size_t size)
{
void *ret;
ret = malloc (size);
if (!ret)
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
return ret;
}
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = grub_malloc (size);
if (!ret)
return NULL;
memset (ret, 0, size);
return ret;
}
void
grub_free (void *ptr)
{
free (ptr);
}
void *
grub_realloc (void *ptr, grub_size_t size)
{
void *ret;
ret = realloc (ptr, size);
if (!ret)
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
return ret;
}
void *
grub_memalign (grub_size_t align, grub_size_t size)
{
void *p;
#if defined(HAVE_POSIX_MEMALIGN)
if (align < sizeof (void *))
align = sizeof (void *);
if (posix_memalign (&p, align, size) != 0)
p = 0;
#elif defined(HAVE_MEMALIGN)
p = memalign (align, size);
#else
(void) align;
(void) size;
grub_util_error ("grub_memalign is not supported");
#endif
if (!p)
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
return p;
}

76
util/pci.c Normal file
View file

@ -0,0 +1,76 @@
/* pci.c - Generic PCI interfaces. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,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/pci.h>
#include <grub/dl.h>
#include <grub/util/misc.h>
grub_pci_address_t
grub_pci_make_address (grub_pci_device_t dev, int reg)
{
grub_pci_address_t ret;
ret.dev = dev;
ret.pos = reg;
return ret;
}
void
grub_pci_iterate (grub_pci_iteratefunc_t hook)
{
struct pci_device_iterator *iter;
struct pci_slot_match slot;
struct pci_device *dev;
slot.domain = PCI_MATCH_ANY;
slot.bus = PCI_MATCH_ANY;
slot.dev = PCI_MATCH_ANY;
slot.func = PCI_MATCH_ANY;
iter = pci_slot_match_iterator_create (&slot);
while ((dev = pci_device_next (iter)))
hook (dev, dev->vendor_id | (dev->device_id << 16));
pci_iterator_destroy (iter);
}
void *
grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
grub_size_t size)
{
void *addr;
int err;
err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
if (err)
grub_util_error ("mapping 0x%x failed (error %d)\n", base, err);
return addr;
}
void
grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
grub_size_t size)
{
pci_device_unmap_range (dev, mem, size);
}
GRUB_MOD_INIT (pci)
{
pci_system_init ();
}
GRUB_MOD_FINI (pci)
{
pci_system_cleanup ();
}

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);

237
util/sdl.c Normal file
View file

@ -0,0 +1,237 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,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
* 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/>.
*/
#define grub_video_render_target grub_video_fbrender_target
#include <grub/err.h>
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/video.h>
#include <grub/video_fb.h>
#include <SDL/SDL.h>
static SDL_Surface *window = 0;
static struct grub_video_render_target *sdl_render_target;
static struct grub_video_mode_info mode_info;
static grub_err_t
grub_video_sdl_set_palette (unsigned int start, unsigned int count,
struct grub_video_palette_data *palette_data);
static grub_err_t
grub_video_sdl_init (void)
{
window = 0;
if (SDL_Init (SDL_INIT_VIDEO) < 0)
return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't init SDL: %s",
SDL_GetError ());
grub_memset (&mode_info, 0, sizeof (mode_info));
return grub_video_fb_init ();
}
static grub_err_t
grub_video_sdl_fini (void)
{
SDL_Quit ();
window = 0;
grub_memset (&mode_info, 0, sizeof (mode_info));
return grub_video_fb_fini ();
}
static inline unsigned int
get_mask_size (grub_uint32_t mask)
{
unsigned i;
for (i = 0; mask > 1U << i; i++);
return i;
}
static grub_err_t
grub_video_sdl_setup (unsigned int width, unsigned int height,
unsigned int mode_type, unsigned int mode_mask)
{
int depth;
int flags = 0;
grub_err_t err;
/* Decode depth from mode_type. If it is zero, then autodetect. */
depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
>> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
if (depth == 0)
depth = 32;
if (width == 0 && height == 0)
{
width = 800;
height = 600;
}
if ((mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
|| !(mode_mask & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED))
flags |= SDL_DOUBLEBUF;
window = SDL_SetVideoMode (width, height, depth, flags | SDL_HWSURFACE);
if (! window)
window = SDL_SetVideoMode (width, height, depth, flags | SDL_SWSURFACE);
if (! window)
return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't open window: %s",
SDL_GetError ());
grub_memset (&sdl_render_target, 0, sizeof (sdl_render_target));
mode_info.width = window->w;
mode_info.height = window->h;
mode_info.mode_type = 0;
if (window->flags & SDL_DOUBLEBUF)
mode_info.mode_type
|= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED;
if (window->format->palette)
mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
else
mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_RGB;
mode_info.bpp = window->format->BitsPerPixel;
mode_info.bytes_per_pixel = window->format->BytesPerPixel;
mode_info.pitch = window->pitch;
/* In index color mode, number of colors. In RGB mode this is 256. */
if (window->format->palette)
mode_info.number_of_colors
= 1 << window->format->BitsPerPixel;
else
mode_info.number_of_colors = 256;
if (! window->format->palette)
{
mode_info.red_mask_size
= get_mask_size (window->format->Rmask >> window->format->Rshift);
mode_info.red_field_pos = window->format->Rshift;
mode_info.green_mask_size
= get_mask_size (window->format->Gmask >> window->format->Gshift);
mode_info.green_field_pos = window->format->Gshift;
mode_info.blue_mask_size
= get_mask_size (window->format->Bmask >> window->format->Bshift);
mode_info.blue_field_pos = window->format->Bshift;
mode_info.reserved_mask_size
= get_mask_size (window->format->Amask >> window->format->Ashift);
mode_info.reserved_field_pos = window->format->Ashift;
mode_info.blit_format
= grub_video_get_blit_format (&mode_info);
}
err = grub_video_fb_create_render_target_from_pointer (&sdl_render_target,
&mode_info,
window->pixels);
if (err)
return err;
/* Copy default palette to initialize emulated palette. */
grub_video_sdl_set_palette (0, (sizeof (grub_video_fbstd_colors)
/ sizeof (grub_video_fbstd_colors[0])),
grub_video_fbstd_colors);
/* Reset render target to SDL one. */
return grub_video_fb_set_active_render_target (sdl_render_target);
}
static grub_err_t
grub_video_sdl_set_palette (unsigned int start, unsigned int count,
struct grub_video_palette_data *palette_data)
{
unsigned i;
if (window->format->palette)
{
SDL_Color *tmp = grub_malloc (count * sizeof (tmp[0]));
for (i = 0; i < count; i++)
{
tmp[i].r = palette_data[i].r;
tmp[i].g = palette_data[i].g;
tmp[i].b = palette_data[i].b;
tmp[i].unused = palette_data[i].a;
}
SDL_SetColors (window, tmp, start, count);
grub_free (tmp);
}
return grub_video_fb_set_palette (start, count, palette_data);
}
static grub_err_t
grub_video_sdl_swap_buffers (void)
{
if (SDL_Flip (window) < 0)
return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't swap buffers: %s",
SDL_GetError ());
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_sdl_set_active_render_target (struct grub_video_render_target *target)
{
if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
return grub_video_fb_set_active_render_target (sdl_render_target);
return grub_video_fb_set_active_render_target (target);
}
static struct grub_video_adapter grub_video_sdl_adapter =
{
.name = "SDL Video Driver",
.init = grub_video_sdl_init,
.fini = grub_video_sdl_fini,
.setup = grub_video_sdl_setup,
.get_info = grub_video_fb_get_info,
.set_palette = grub_video_sdl_set_palette,
.get_palette = grub_video_fb_get_palette,
.set_viewport = grub_video_fb_set_viewport,
.get_viewport = grub_video_fb_get_viewport,
.map_color = grub_video_fb_map_color,
.map_rgb = grub_video_fb_map_rgb,
.map_rgba = grub_video_fb_map_rgba,
.unmap_color = grub_video_fb_unmap_color,
.fill_rect = grub_video_fb_fill_rect,
.blit_bitmap = grub_video_fb_blit_bitmap,
.blit_render_target = grub_video_fb_blit_render_target,
.scroll = grub_video_fb_scroll,
.swap_buffers = grub_video_sdl_swap_buffers,
.create_render_target = grub_video_fb_create_render_target,
.delete_render_target = grub_video_fb_delete_render_target,
.set_active_render_target = grub_video_sdl_set_active_render_target,
.get_active_render_target = grub_video_fb_get_active_render_target,
.next = 0
};
GRUB_MOD_INIT(sdl)
{
grub_video_register (&grub_video_sdl_adapter);
}
GRUB_MOD_FINI(sdl)
{
grub_video_unregister (&grub_video_sdl_adapter);
}

View file

@ -1,276 +0,0 @@
#! /bin/sh
# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,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
# 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@
sbindir=@sbindir@
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}`
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
install_device=
no_floppy=
force_lba=
recheck=no
debug=no
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
--grub-setup=FILE use FILE as grub-setup
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
--grub-probe=FILE use FILE as grub-probe
--no-floppy do not probe any floppy drive
--recheck probe a device map even if it already exists
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.
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-install (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-setup=*)
grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
--no-floppy)
no_floppy="--no-floppy" ;;
--recheck)
recheck=yes ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$install_device" != x; then
echo "More than one install_devices?" 1>&2
usage
exit 1
fi
install_device="${option}" ;;
esac
done
if test "x$install_device" = x; then
echo "install_device not specified." 1>&2
usage
exit 1
fi
# If the debugging feature is enabled, print commands.
setup_verbose=
if test $debug = yes; then
set -x
setup_verbose="--verbose"
fi
# Initialize these directories here, since ROOTDIR was initialized.
bootdir=${rootdir}/boot
grubdir=${bootdir}/`echo grub | sed ${transform}`
device_map=${grubdir}/device.map
grub_probe="${grub_probe} --device-map=${device_map}"
# Check if GRUB is installed.
set $grub_setup dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set $grub_mkimage dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
set $grub_mkdevicemap dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
rm -f $device_map
fi
# Create the device map file if it is not present.
if test -f "$device_map"; then
:
else
# Create a safe temporary file.
test -n "$mklog" && log_file=`$mklog`
$grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1
fi
# Make sure that there is no duplicated entry.
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
| sort | uniq -d | sed -n 1p`
if test -n "$tmp"; then
echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
exit 1
fi
# Copy the GRUB images to the GRUB directory.
for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do
if test -f $file && [ "`basename $file`" != menu.lst ]; then
rm -f $file || exit 1
fi
done
for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
for file in ${pkglibdir}/*.img; do
cp -f $file ${grubdir} || exit 1
done
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
# 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
echo "Auto-detection of a filesystem module failed." 1>&2
echo "Please specify the module with the option \`--modules' explicitly." 1>&2
exit 1
fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
# Device abstraction module, if any (lvm, raid).
devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
modules="$modules $fs_module $partmap_module $devabstraction_module"
prefix_drive=
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}`"
fi
grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
# Strip partition number
install_drive="`echo ${install_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`"
grub_drive="`echo ${grub_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`"
if [ "x${grub_drive}" != "x${install_drive}" ] ; then
uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`"
if [ "x${uuid}" = "x" ] ; then
echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2
exit 1
fi
prefix_drive="(UUID=${uuid})"
modules="$modules fs_uuid"
fi
else
prefix_drive=`$grub_probe --target=drive --device ${grub_device}`
fi
relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1
if [ "x${relative_grubdir}" = "x" ] ; then
relative_grubdir=/
fi
$grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
# Now perform the installation.
$grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \
${install_device} || exit 1
# Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
echo "fix it and re-run the script \`grub-install'."
echo
cat $device_map
# Bye.
exit 0

View file

@ -1,298 +0,0 @@
/* grub-mkimage.c - make a bootable image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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
* 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/machine/boot.h>
#include <grub/machine/kernel.h>
#include <grub/kernel.h>
#include <grub/disk.h>
#include <grub/util/misc.h>
#include <grub/util/resolve.h>
#include <grub/misc.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define _GNU_SOURCE 1
#include <getopt.h>
static void
compress_kernel (char *kernel_img, size_t kernel_size,
char **core_img, size_t *core_size)
{
/* No compression support yet. */
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
*core_img = xmalloc (kernel_size);
memcpy (*core_img, kernel_img, kernel_size);
*core_size = kernel_size;
}
static void
generate_image (const char *dir, const char *prefix, FILE *out, char *mods[], char *memdisk_path)
{
size_t kernel_size, total_module_size, memdisk_size, core_size, boot_size, offset;
char *kernel_path, *kernel_img, *core_img, *boot_path, *boot_img;
struct grub_util_path_list *path_list, *p;
struct grub_module_info *modinfo;
grub_addr_t module_addr;
unsigned int num;
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
kernel_path = grub_util_get_path (dir, "kernel.img");
kernel_size = grub_util_get_image_size (kernel_path);
total_module_size = sizeof (struct grub_module_info);
for (p = path_list; p; p = p->next)
total_module_size += (grub_util_get_image_size (p->name)
+ sizeof (struct grub_module_header));
memdisk_size = 0;
if (memdisk_path)
{
memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512);
grub_util_info ("the size of memory disk is 0x%x", memdisk_size);
total_module_size += memdisk_size + sizeof (struct grub_module_header);
}
grub_util_info ("the total module size is 0x%x", total_module_size);
kernel_img = xmalloc (kernel_size + total_module_size);
grub_util_load_image (kernel_path, kernel_img);
if ((GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1)
> GRUB_KERNEL_MACHINE_DATA_END)
grub_util_error ("prefix too long");
strcpy (kernel_img + GRUB_KERNEL_MACHINE_PREFIX, prefix);
/* Fill in the grub_module_info structure. */
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
modinfo->magic = GRUB_MODULE_MAGIC;
modinfo->offset = sizeof (struct grub_module_info);
modinfo->size = total_module_size;
offset = kernel_size + sizeof (struct grub_module_info);
for (p = path_list; p; p = p->next)
{
struct grub_module_header *header;
size_t mod_size;
mod_size = grub_util_get_image_size (p->name);
header = (struct grub_module_header *) (kernel_img + offset);
header->type = OBJ_TYPE_ELF;
header->size = grub_host_to_target32 (mod_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (p->name, kernel_img + offset);
offset += mod_size;
}
if (memdisk_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
header->type = OBJ_TYPE_MEMDISK;
header->size = grub_host_to_target32 (memdisk_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (memdisk_path, kernel_img + offset);
offset += memdisk_size;
}
compress_kernel (kernel_img, kernel_size + total_module_size,
&core_img, &core_size);
grub_util_info ("the core size is 0x%x", core_size);
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
num <<= GRUB_DISK_SECTOR_BITS;
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 is not one sector size");
boot_img = grub_util_read_image (boot_path);
/* sparc is a big endian architecture. */
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_cpu_to_be32 (num);
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
module_addr = (path_list
? (GRUB_BOOT_MACHINE_IMAGE_ADDRESS + kernel_size)
: 0);
grub_util_info ("the first module address is 0x%x", module_addr);
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_cpu_to_be32 (total_module_size);
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_cpu_to_be32 (kernel_size);
/* No compression support yet. */
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
= grub_cpu_to_be32 (0);
grub_util_write_image (core_img, core_size, out);
free (kernel_img);
free (core_img);
free (kernel_path);
while (path_list)
{
struct grub_util_path_list *next = path_list->next;
free ((void *) path_list->name);
free (path_list);
path_list = next;
}
}
static struct option options[] =
{
{"directory", required_argument, 0, 'd'},
{"prefix", required_argument, 0, 'p'},
{"memdisk", required_argument, 0, 'm'},
{"output", required_argument, 0, 'o'},
{"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 [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\
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
-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\
", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
exit (status);
}
int
main (int argc, char *argv[])
{
char *output = NULL;
char *dir = NULL;
char *prefix = NULL;
char *memdisk = NULL;
FILE *fp = stdout;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
while (1)
{
int c = getopt_long (argc, argv, "d:p:m:o:hVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'o':
if (output)
free (output);
output = xstrdup (optarg);
break;
case 'd':
if (dir)
free (dir);
dir = xstrdup (optarg);
break;
case 'm':
if (memdisk)
free (memdisk);
memdisk = xstrdup (optarg);
if (prefix)
free (prefix);
prefix = xstrdup ("(memdisk)/boot/grub");
break;
case 'h':
usage (0);
break;
case 'p':
if (prefix)
free (prefix);
prefix = xstrdup (optarg);
break;
case 'V':
printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
if (output)
{
fp = fopen (output, "wb");
if (! fp)
grub_util_error ("cannot open %s", output);
}
generate_image (dir ? : GRUB_LIBDIR,
prefix ? : DEFAULT_DIRECTORY, fp,
argv + optind, memdisk);
fclose (fp);
if (dir)
free (dir);
return 0;
}

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
@ -20,14 +20,17 @@
#include <grub/util/misc.h>
#include <grub/util/ofpath.h>
#include <grub/i18n.h>
#include "progname.h"
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
@ -21,6 +21,7 @@
#include <grub/types.h>
#include <grub/util/misc.h>
#include <grub/device.h>
#include <grub/i18n.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
@ -49,6 +50,8 @@
#define _GNU_SOURCE 1
#include <getopt.h>
#include "progname.h"
/* This program fills in various fields inside of the 'boot' and 'core'
* image files.
*
@ -158,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;
@ -173,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)
@ -186,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;
@ -198,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);
@ -216,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);
@ -226,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. */
@ -317,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;
@ -329,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. */
@ -340,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);
@ -365,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);
@ -401,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\
@ -419,7 +422,7 @@ DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n\
", program_name
", program_name,
DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY,
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
@ -556,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);
}
}
@ -575,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);
@ -591,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);
}
}
@ -617,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))

46
util/time.c Normal file
View file

@ -0,0 +1,46 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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 <grub/datetime.h>
#include <time.h>
grub_err_t
grub_get_datetime (struct grub_datetime *datetime)
{
struct tm *mytm;
time_t mytime;
mytime = time (&mytime);
mytm = gmtime (&mytime);
datetime->year = mytm->tm_year + 1900;
datetime->month = mytm->tm_mon + 1;
datetime->day = mytm->tm_mday;
datetime->hour = mytm->tm_hour;
datetime->minute = mytm->tm_min;
datetime->second = mytm->tm_sec;
return GRUB_ERR_NONE;
}
grub_err_t
grub_set_datetime (struct grub_datetime *datetime __attribute__ ((unused)))
{
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"no clock setting routine available");
}