merge mainline into emu-mod

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-07 03:06:33 +01:00
commit 19a9fb834b
459 changed files with 26481 additions and 7640 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);
@ -279,7 +279,7 @@ find_root_device (const char *dir, dev_t dev)
continue;
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot restore the original directory");
grub_util_error ("cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -288,7 +288,7 @@ find_root_device (const char *dir, dev_t dev)
}
if (chdir (saved_cwd) < 0)
grub_util_error ("Cannot restore the original directory");
grub_util_error ("cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -445,7 +445,7 @@ grub_guess_root_device (const char *dir)
struct stat st;
if (stat (dir, &st) < 0)
grub_util_error ("Cannot stat `%s'", dir);
grub_util_error ("cannot stat `%s'", dir);
#ifdef __CYGWIN__
/* Cygwin specific function. */
@ -460,7 +460,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,7 +484,7 @@ grub_util_is_dmraid (const char *os_dev)
return 1;
else if (! strncmp (os_dev, "/dev/mapper/sil_", 16))
return 1;
return 0;
}
@ -591,7 +592,7 @@ grub_util_get_grub_dev (const char *os_dev)
free (p);
}
else
grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
grub_util_error ("unknown kind of RAID device `%s'", os_dev);
break;
@ -608,7 +609,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 +623,7 @@ grub_util_check_char_device (const char *blk_dev)
struct stat st;
if (stat (blk_dev, &st) < 0)
grub_util_error ("Cannot stat `%s'", blk_dev);
grub_util_error ("cannot stat `%s'", blk_dev);
if (S_ISCHR (st.st_mode))
return (blk_dev);

View file

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

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,6 +40,7 @@
#include <grub_emu_init.h>
#define ENABLE_RELOCATABLE 0
#include "progname.h"
/* Used for going back to the main function. */
@ -125,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"
@ -140,7 +141,7 @@ usage (int status)
" -h, --help display this message and exit\n"
" -V, --version print version information and exit\n"
"\n"
"Report bugs to <%s>.\n", DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
"Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
return status;
}
@ -155,9 +156,8 @@ main (int argc, char *argv[])
int opt;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
switch (opt)
@ -217,14 +217,14 @@ main (int argc, char *argv[])
{
char *device_name = grub_guess_root_device (dir);
if (! device_name)
grub_util_error ("cannot find a device for %s.\n", dir);
grub_util_error ("cannot find a device for %s", dir);
root_dev = grub_util_get_grub_dev (device_name);
if (! root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
}
}

View file

@ -1,7 +1,7 @@
/* grub-fstest.c - debug tool for filesystem driver */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -71,7 +71,7 @@ execute_command (char *name, int n, char **args)
cmd = grub_command_find (name);
if (! cmd)
grub_util_error ("Can\'t find command %s", name);
grub_util_error ("can\'t find command %s", name);
return (cmd->func) (cmd, n, args);
}
@ -100,9 +100,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
dev = grub_device_open (0);
if ((! dev) || (! dev->disk))
grub_util_error ("Can\'t open device.");
grub_util_error ("can\'t open device");
grub_util_info ("total sectors : %lld.",
grub_util_info ("total sectors : %lld",
(unsigned long long) dev->disk->total_sectors);
if (! leng)
@ -115,7 +115,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
len = (leng > BUF_SIZE) ? BUF_SIZE : leng;
if (grub_disk_read (dev->disk, 0, skip, len, buf))
grub_util_error ("Disk read fails at offset %lld, length %d.",
grub_util_error ("disk read fails at offset %lld, length %d",
skip, len);
if (hook (skip, buf, len))
@ -132,15 +132,15 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
file = grub_file_open (pathname);
if (!file)
{
grub_util_error ("cannot open file %s.", pathname);
grub_util_error ("cannot open file %s", pathname);
return;
}
grub_util_info ("file size : %lld.", (unsigned long long) file->size);
grub_util_info ("file size : %lld", (unsigned long long) file->size);
if (skip > file->size)
{
grub_util_error ("invalid skip value %lld.", (unsigned long long) skip);
grub_util_error ("invalid skip value %lld", (unsigned long long) skip);
return;
}
@ -158,7 +158,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
if (sz < 0)
{
grub_util_error ("read error at offset %llu.", ofs);
grub_util_error ("read error at offset %llu", ofs);
break;
}
@ -184,7 +184,7 @@ cmd_cp (char *src, char *dest)
if ((int) fwrite (buf, 1, len, ff) != len)
{
grub_util_error ("write error.");
grub_util_error ("write error");
return 1;
}
@ -194,7 +194,7 @@ cmd_cp (char *src, char *dest)
ff = fopen (dest, "wb");
if (ff == NULL)
{
grub_util_error ("open error.");
grub_util_error ("open error");
return;
}
read_file (src, cp_hook);
@ -212,7 +212,7 @@ cmd_cmp (char *src, char *dest)
{
if ((int) fread (buf_1, 1, len, ff) != len)
{
grub_util_error ("read error at offset %llu.", ofs);
grub_util_error ("read error at offset %llu", ofs);
return 1;
}
@ -223,7 +223,7 @@ cmd_cmp (char *src, char *dest)
for (i = 0; i < len; i++, ofs++)
if (buf_1[i] != buf[i])
{
grub_util_error ("compare fail at offset %llu.", ofs);
grub_util_error ("compare fail at offset %llu", ofs);
return 1;
}
}
@ -233,12 +233,12 @@ cmd_cmp (char *src, char *dest)
ff = fopen (dest, "rb");
if (ff == NULL)
{
grub_util_error ("open error.");
grub_util_error ("open error");
return;
}
if ((skip) && (fseeko (ff, skip, SEEK_SET)))
grub_util_error ("seek error.");
grub_util_error ("seek error");
read_file (src, cmp_hook);
fclose (ff);
@ -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,19 @@ 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}`
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 +54,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 +84,21 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
--disk-module=MODULE disk module to use
EOF
fi
if [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
cat <<EOF
--font=FILE font file to use
EOF
fi
cat <<EOF
INSTALL_DEVICE can be a GRUB device name or a system device filename.
grub-install copies GRUB images into the DIR/boot directory specified by
--root-directory, and uses grub-setup to install grub into the boot
sector.
grub-install copies GRUB images into /boot/grub (or /grub on NetBSD and
OpenBSD), and uses grub-setup to install grub into the boot sector.
If the --root-directory option is used, then grub-install will copy
images into the operating system installation rooted at that directory.
Report bugs to <bug-grub@gnu.org>.
EOF
@ -103,6 +115,8 @@ for option in "$@"; do
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--font=*)
font=`echo "$option" | sed 's/--font=//'` ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-setup=*)
@ -144,7 +158,7 @@ done
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
if test "x$install_device" = x; then
if test "x$install_device" = x && test "${target_cpu}-${platform}" != "mips-yeeloong"; then
echo "install_device not specified." 1>&2
usage
exit 1
@ -177,7 +191,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
:
@ -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
@ -258,6 +272,10 @@ done
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device ${grub_device}`
if test "x$fs_module" = x -a "x$modules" = x; then
@ -278,17 +296,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}`"
fi
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
fi
grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
# Strip partition number
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`"
if [ "$disk_module" = ata ] ; then
# generic method (used on coreboot and ata mod)
@ -297,34 +324,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}`
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

@ -220,6 +220,7 @@ export GRUB_DEFAULT \
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_GFXMODE \
GRUB_THEME \
GRUB_DISABLE_OS_PROBER
if test "x${grub_cfg}" != "x"; then

View file

@ -94,13 +94,22 @@ convert_system_path_to_grub_path ()
echo ${drive}${relative_path}
}
save_default_entry ()
{
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
cat << EOF
savedefault
EOF
fi
}
prepare_grub_to_access_device ()
{
device=$1
# 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

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

View file

@ -1,7 +1,7 @@
/* grub-mkrelpath.c - make a system path relative to its root */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTIONS] PATH\n\
@ -56,9 +56,8 @@ main (int argc, char *argv[])
char *argument, *relpath;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
/* Check for options. */
while (1)

View file

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

View file

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

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

@ -0,0 +1,108 @@
#! /bin/sh
#
# Set a default boot entry for GRUB, for the next boot only.
# Copyright (C) 2004,2009 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] entry
Set the default boot entry for GRUB, for the next boot only.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
ENTRY is a number or a menu item title.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-reboot (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$entry" != x; then
echo "More than one entry?" 1>&2
usage
exit 1
fi
entry="${option}" ;;
esac
done
if test "x$entry" = x; then
echo "entry not specified." 1>&2
usage
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
if [ "$prev_saved_entry" ]; then
$grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
else
# We need some non-empty value for prev_saved_entry so that GRUB will
# recognise that grub-reboot has been used and restore the previous
# saved entry. "0" is the same as an empty value, i.e. the first menu
# entry.
$grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
fi
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.
exit 0

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

@ -0,0 +1,254 @@
/* grub-script-check.c - check grub script file for syntax errors */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include <grub/parser.h>
#include <grub/script_sh.h>
#include <grub_script_check_init.h>
#define _GNU_SOURCE 1
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "progname.h"
void
grub_putchar (int c)
{
putchar (c);
}
int
grub_getkey (void)
{
return -1;
}
void
grub_refresh (void)
{
fflush (stdout);
}
char *
grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdline (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdblock (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_cmdif (struct grub_script_cmd *cmd __attribute__ ((unused)))
{
return 0;
}
grub_err_t
grub_script_execute_menuentry (struct grub_script_cmd *cmd __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 script being processed\n\
\n\
Report bugs to <%s>.\n\
", program_name,
PACKAGE_BUGREPORT);
exit (status);
}
int
main (int argc, char *argv[])
{
char *argument;
char *input;
FILE *file = 0;
int verbose = 0;
struct grub_script *script;
auto grub_err_t get_config_line (char **line, int cont);
grub_err_t get_config_line (char **line, int cont __attribute__ ((unused)))
{
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,11 +34,29 @@ for i in ${GRUB_PRELOAD_MODULES} ; do
done
if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
cat << EOF
set default=${GRUB_DEFAULT}
if [ -s \$prefix/grubenv ]; then
load_env
fi
set default="${GRUB_DEFAULT}"
if [ \${prev_saved_entry} ]; then
set saved_entry=\${prev_saved_entry}
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z \${boot_once} ]; then
saved_entry=\${chosen}
save_env saved_entry
fi
}
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in
@ -85,6 +103,18 @@ if loadfont `make_system_path_relative_to_its_root ${GRUB_FONT_PATH}` ; then
# understand terminal_output
terminal gfxterm
fi
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
set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
set menuviewer=gfxmenu
EOF
fi
cat << EOF
fi
EOF
;;
@ -104,15 +134,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"

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]') ${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]') --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]') ${CLASS}"
fi
# loop-AES arranges things so that /dev/loop/X can be our root device, but
@ -58,16 +60,28 @@ 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 grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null ; then
cat << EOF
set gfxpayload=keep
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

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

View file

@ -137,7 +137,7 @@ find_grub_drive (const char *name)
}
static int
find_free_slot ()
find_free_slot (void)
{
unsigned int i;
@ -336,11 +336,12 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
char dev[PATH_MAX];
strcpy (dev, map[disk->id].device);
if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) == 0)
if (disk->partition && sector >= disk->partition->start
&& strncmp (map[disk->id].device, "/dev/", 5) == 0)
is_partition = linux_find_partition (dev, disk->partition->start);
/* Open the partition. */
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()", dev);
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev);
fd = open (dev, flags);
if (fd < 0)
{
@ -348,7 +349,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
return -1;
}
/* Make the buffer cache consistent with the physical disk. */
/* Flush the buffer cache to the physical disk.
XXX: This also empties the buffer cache. */
ioctl (fd, BLKFLSBUF, 0);
if (is_partition)
@ -489,6 +491,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;
@ -526,6 +545,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;
@ -567,7 +603,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 +674,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
@ -945,10 +981,10 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
struct hd_geometry hdg;
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;

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

@ -29,11 +29,13 @@ 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}`
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=
@ -178,6 +180,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = xfat; then :; else

View file

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

View file

@ -1,116 +0,0 @@
#! /bin/sh -e
# Make GRUB rescue floppy
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] output_image
Make GRUB rescue floppy.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--output=FILE save output in FILE
$0 generates a bootable rescue floppy.
Report bugs to <bug-grub@gnu.org>.
EOF
}
input_dir=${pkglibdir}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--output=*)
output_image=`echo "$option" | sed 's/--output=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$output_image" != x; then
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
fi
output_image="${option}" ;;
esac
done
if test "x$output_image" = x; then
usage
exit 1
fi
aux_dir=`mktemp -d`
mkdir -p ${aux_dir}/boot/grub
for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \
${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
${input_dir}/handler.lst ${input_dir}/parttool.lst; do
if test -f "$file"; then
cp -f "$file" ${aux_dir}/boot/grub/
fi
done
modules="$(cat ${input_dir}/partmap.lst) ${modules}"
for i in ${modules} ; do
echo "insmod $i"
done > ${aux_dir}/boot/grub/grub.cfg
# build memdisk
memdisk_img=`mktemp`
tar -C ${aux_dir} -cf ${memdisk_img} boot
rm -rf ${aux_dir}
# build core.img
core_img=`mktemp`
grub-mkimage -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar biosdisk
rm -f ${memdisk_img}
# build floppy image
cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${output_image}
rm -f ${core_img}
exit 0

View file

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

View file

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

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

View file

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

View file

@ -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,6 +30,9 @@
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <grub/kernel.h>
#include <grub/misc.h>
@ -38,7 +41,9 @@
#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 +64,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 +80,12 @@ grub_util_info (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: info: ", program_name);
fprintf (stderr, _("%s: info:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fprintf (stderr, ".\n");
fflush (stderr);
}
}
@ -88,11 +95,12 @@ grub_util_error (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: error: ", program_name);
fprintf (stderr, _("%s: error:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fputc ('\n', stderr);
fprintf (stderr, ".\n");
exit (1);
}
@ -135,13 +143,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 *
@ -364,11 +372,13 @@ grub_millisleep (grub_uint32_t ms)
#endif
#if !(defined (__i386__) || defined (__x86_64__))
void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
{
}
#endif
#ifndef HAVE_VASPRINTF
@ -478,6 +488,19 @@ fail:
#endif /* __MINGW32__ */
char *
canonicalize_file_name (const char *path)
{
char *ret;
#ifdef PATH_MAX
ret = xmalloc (PATH_MAX);
(void) realpath (path, ret);
#else
ret = realpath (path, NULL);
#endif
return ret;
}
/* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */
char *
@ -490,23 +513,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
@ -523,17 +542,21 @@ 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)
{
/* offset == 0 means path given is the mount point. */
/* 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 strdup ("/");
return xstrdup ("");
}
else
break;
@ -550,11 +573,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);
@ -566,3 +597,13 @@ make_system_path_relative_to_its_root (const char *path)
return buf3;
}
void
grub_util_init_nls (void)
{
#if ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* ENABLE_NLS */
}

View file

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

View file

@ -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>
@ -490,7 +485,7 @@ void usage(){
int comma;
int len;
unsigned int j;
char *arg;
const char *arg;
printf (" ");
@ -564,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.
@ -583,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);
@ -593,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;
}
@ -645,9 +640,11 @@ int FDECL2(main, int, argc, char **, argv){
char *log_file = 0;
set_program_name (argv[0]);
#if ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* ENABLE_NLS */
if (argc < 2)
usage();
@ -912,7 +909,7 @@ int FDECL2(main, int, argc, char **, argv){
exit (0);
break;
case OPTION_VERSION:
printf ("%s (%s %s)\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
exit (0);
break;
case OPTION_NOSPLIT_SL_COMPONENT:
@ -972,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;
@ -1092,7 +1089,7 @@ parse_input_files:
merge_image);
}
memcpy(&de.isorec.extent, mrootp->extent, 8);
memcpy(&de.isorec.extent, mrootp->extent, 8);
}
/*
@ -1175,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;
@ -1262,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 */
/*
@ -1344,8 +1341,8 @@ parse_input_files:
outputlist_insert(&dirtree_clean);
if(extension_record)
{
if(extension_record)
{
outputlist_insert(&extension_desc);
}
@ -1356,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.
@ -1402,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 ENABLE_NLS
# include <locale.h>
# include <libintl.h>
#else /* ! ENABLE_NLS */
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
#endif /* ENABLE_NLS */
#define _(str) gettext(str)
#define N_(str) str
@ -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
@ -326,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));
@ -374,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 *));
@ -401,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 *));
@ -413,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,

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

@ -40,7 +40,7 @@
#include "mkisofs.h"
#include "iso9660.h"
#include "msdos_partition.h"
#ifdef __SVR4
extern char * strdup(const char *);
#endif
@ -158,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);
@ -196,7 +196,7 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
struct directory * dpnt;
dpnt = node;
while (dpnt)
{
/* skip if it's hidden */
@ -214,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)
{
@ -228,7 +228,7 @@ static int FDECL1(assign_directory_addresses, struct directory *, node)
}
}
if(dpnt->subdir)
if(dpnt->subdir)
{
assign_directory_addresses(dpnt->subdir);
}
@ -238,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];
@ -247,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;
@ -256,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);
}
@ -271,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;
@ -290,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
@ -327,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;
@ -344,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
@ -376,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++;
@ -395,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
@ -411,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)
@ -428,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;
@ -452,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.
*/
@ -482,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];
}
@ -494,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;
@ -533,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);
@ -551,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;
@ -564,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);
@ -581,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
@ -627,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);
@ -672,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);
@ -699,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);
}
@ -711,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);
@ -753,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) {
@ -785,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)
{
@ -812,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)
@ -837,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++;
}
@ -868,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;
}
@ -880,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;
@ -915,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 */
@ -936,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;
@ -946,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()
@ -968,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);
@ -977,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 )
{
@ -986,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);
@ -995,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
@ -1020,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)
{
@ -1111,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;
@ -1127,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.
*/
@ -1148,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)
@ -1195,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,
@ -1207,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);
@ -1238,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);
/*
@ -1260,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);
@ -1284,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++;
@ -1299,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;
@ -1316,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);
@ -1436,7 +1436,12 @@ static int FDECL1(padblock_write, FILE *, outfile)
FILE *fp = fopen (boot_image_embed, "rb");
if (! fp)
error (1, errno, _("Unable to open %s"), boot_image_embed);
fread (buffer, 2048 * PADBLOCK_SIZE, 1, fp);
if (fread (buffer, 1, 2048 * PADBLOCK_SIZE, fp) == 0)
error (1, errno, _("cannot read %d bytes from %s"),
2048 * PADBLOCK_SIZE, boot_image_embed);
if (fgetc (fp) != EOF)
error (1, 0, _("%s is too big for embed area"), boot_image_embed);
}
if (use_protective_msdos_label)

View file

@ -26,7 +26,7 @@ grub_pci_make_address (grub_pci_device_t dev, int reg)
{
grub_pci_address_t ret;
ret.dev = dev;
ret.pos = reg << 2;
ret.pos = reg;
return ret;
}

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}`
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
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
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,7 +1,7 @@
/* grub-mkimage.c - make a bootable image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -191,7 +191,7 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``%s --help'' for more information.\n", program_name);
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
else
printf ("\
Usage: %s [OPTION]... [MODULES]\n\
@ -222,9 +222,8 @@ main (int argc, char *argv[])
FILE *fp = stdout;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
while (1)
{

View file

@ -1,7 +1,7 @@
/* grub-ofpathname.c - Find OpenBOOT path for a given device */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,9 +29,8 @@ int main(int argc, char **argv)
char *of_path;
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
grub_util_init_nls ();
if (argc != 2)
{

View file

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