Merge from trunk

This commit is contained in:
Robert Millan 2009-12-11 21:15:58 +00:00
commit 838114b687
30 changed files with 357 additions and 103 deletions

141
ChangeLog
View file

@ -1,3 +1,144 @@
2009-12-11 Vladimir Serbinenko <phcoder@gmail.com>
libpciaccess support.
* Makefile.in (LIBPCIACCESS): New variable.
(enable_grub_emu_pci): Likewise.
* conf/any-emu.rmk (grub_emu_SOURCES) [enable_grub_emu_pci]: Add
util/pci.c and commands/lspci.c.
(grub_emu_LDFLAGS) [enable_grub_emu_pci]: Add $(LIBPCIACCESS).
* configure.ac (grub-emu-pci): New option.
* include/grub/i386/pci.h (grub_pci_device_map_range): New function.
(grub_pci_device_unmap_range): Likewise.
* include/grub/pci.h [GRUB_UTIL]: Include grub/pciutils.h.
(grub_pci_device) [!GRUB_UTIL]: New structure. All users updated.
(grub_pci_address_t) [!GRUB_UTIL]: New type.
(grub_pci_device_t) [!GRUB_UTIL]: Likewise.
(grub_pci_get_bus) [!GRUB_UTIL]: New function.
(grub_pci_get_device) [!GRUB_UTIL]: Likewise.
(grub_pci_get_function) [!GRUB_UTIL]: Likewise.
* include/grub/pciutils.h: New file.
* util/pci.c: Likewise.
2009-12-11 Felix Zielcke <fzielcke@z-51.de>
* util/misc.c: Don't include <errno.h> twice.
2009-12-10 Felix Zielcke <fzielcke@z-51.de>
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Show the disk
name in an error message.
(grub_biosdisk_rw): Likewise.
2009-12-10 Vladimir Serbinenko <phcoder@gmail.com>
Eliminate NTFS 4Gib barrier.
* fs/ntfs.c (read_attr): Use grub_disk_addr_t and grub_size_t.
(read_run_data): Likewise.
(grub_ntfs_read_run_list): Likewise.
(grub_ntfs_read_block): Likewise.
(grub_ntfs_iterate_dir): Likewise.
(read_mft): Likewise.
(read_data): Likewise.
Use COM_LOG_LEN.
* fs/ntfscomp.c (read_block): Cast ctx->target_vcn & 0xF to unsigned
to avoid 64-bit division
* include/grub/ntfs.h (COM_LOG_LEN): New definition.
(grub_ntfs_rlst): Use grub_disk_addr_t.
2009-12-10 Vladimir Serbinenko <phcoder@gmail.com>
Eliminate grub-fstest 4Gib barrier.
* util/grub-fstest.c (skip, leng): Use grub_disk_addr_t.
(read_file): Fix error reporting.
2009-12-10 Vladimir Serbinenko <phcoder@gmail.com>
Eliminate hexdump 4Gib barrier.
* commands/hexdump.c (grub_cmd_hexdump): Use grub_disk_addr_t.
* lib/arg.c (grub_arg_parse): Use grub_strtoull.
2009-12-10 Vladimir Serbinenko <phcoder@gmail.com>
* kern/device.c (grub_device_iterate): Ignore errors during first scan.
Fixes amarsh bug.
2009-12-09 Bruce Dubbs <bruce.dubbs@gmail.com>
Remove miscellaneous files in distclean target.
* Makefile.in: Remove docs/{grub.info,version.texi,stamp-vti}
2009-12-09 Colin Watson <cjwatson@ubuntu.com>
* util/grub-mkconfig_lib.in: Don't set grub_probe or grub_mkrelpath
if they're already set. This resolves the conflict between my
grub-install change on 2009-10-06 and Felix' change on 2009-11-11,
fixing the --grub-probe option again.
* util/sparc64/ieee1275/grub-install.in: Revert the last piece of my
change on 2009-10-06, so that we now once again source
`${libdir}/grub/grub-mkconfig_lib' after options have been parsed.
2009-12-08 Robert Millan <rmh.grub@aybabtu.com>
* conf/common.rmk [sparc64-ieee1275] (grub_mkdevicemap_SOURCES): Use
`util/ieee1275/ofpath.c' and `util/ieee1275/devicemap.c' instead of
`util/devicemap.c'.
2009-12-08 Carles Pina i Estany <carles@pina.cat>
* include/grub/misc.h (grub_printf_): New declaration.
* kern/misc.c (grub_printf_): New definition.
* normal/main.c (grub_normal_reader_init): Use `grub_printf_' and `N_'
instead of `grub_printf' and `_'.
* normal/menu_entry.c (store_completion): Likewise.
(run): Likewise.
(grub_menu_entry_run): Likewise.
* normal/menu_text.c (grub_wait_after_message): Likewise.
(notify_booting): Likewise.
(notify_fallback): Likewise.
(notify_execution_failure): Likewise.
2009-12-07 Colin Watson <cjwatson@ubuntu.com>
* configure.ac: Check for vasprintf.
* util/misc.c (asprintf): Move allocation from here ...
(vasprintf): ... to here. New function.
(xasprintf): New function.
* include/grub/util/misc.h (vasprintf, xasprintf): Add
prototypes.
* util/getroot.c (grub_util_get_grub_dev): Use xasprintf.
* util/grub-mkfont.c (write_font): Likewise.
* util/grub-probe.c (probe): Likewise.
* util/hostdisk.c (make_device_name): Likewise.
2009-12-06 David S. Miller <davem@sunset.davemloft.net>
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Recognize
anything even prefixed with 'cdrom' as a cdrom.
2009-12-06 Felix Zielcke <fzielcke@z-51.de>
* util/misc.c (make_system_path_relative_to_its_root): Correctly cope with
mount points.
2009-12-05 Carles Pina i Estany <carles@pina.cat>
* gettext/gettext.c: Include `<grub/list.h>'. Define grub_gettext_msg,
grub_gettext_msg_list.
(grub_gettext_gettranslation_from_position): Return const char *
and not char *.
(grub_gettext_translate): Add the translated strings into a list,
returns from the list if existing there.
(grub_gettext_init_ext): Add \n at the end of grub_dprintf string.
(grub_gettext_delete_list): Delete the list.
(grub_gettext_env_write_lang): Call grub_gettext_delete_list when
lang environment variable is changed.
(GRUB_MOD_FINI): Call grub_gettext_delete_list.
2009-12-05 Vladimir Serbinenko <phcoder@gmail.com> 2009-12-05 Vladimir Serbinenko <phcoder@gmail.com>
Rename kernel.mod to kernel.img. Rename kernel.mod to kernel.img.

View file

@ -1,22 +0,0 @@
2009-12-02 Vladimir Serbinenko <phcoder@gmail.com>
libpciaccess support.
* Makefile.in (LIBPCIACCESS): New variable.
(enable_grub_emu_pci): Likewise.
* conf/any-emu.rmk (grub_emu_SOURCES) [enable_grub_emu_pci]: Add
util/pci.c and commands/lspci.c.
(grub_emu_LDFLAGS) [enable_grub_emu_pci]: Add $(LIBPCIACCESS).
* configure.ac (grub-emu-pci): New option.
* include/grub/i386/pci.h (grub_pci_device_map_range): New function.
(grub_pci_device_unmap_range): Likewise.
* include/grub/pci.h [GRUB_UTIL]: Include grub/pciutils.h.
(grub_pci_device) [!GRUB_UTIL]: New structure. All users updated.
(grub_pci_address_t) [!GRUB_UTIL]: New type.
(grub_pci_device_t) [!GRUB_UTIL]: Likewise.
(grub_pci_get_bus) [!GRUB_UTIL]: New function.
(grub_pci_get_device) [!GRUB_UTIL]: Likewise.
(grub_pci_get_function) [!GRUB_UTIL]: Likewise.
* include/grub/pciutils.h: New file.
* util/pci.c: Likewise.

View file

@ -141,7 +141,9 @@ CLEANFILES =
MOSTLYCLEANFILES = MOSTLYCLEANFILES =
DISTCLEANFILES = config.status config.cache config.log config.h \ DISTCLEANFILES = config.status config.cache config.log config.h \
Makefile stamp-h include/grub/cpu include/grub/machine \ Makefile stamp-h include/grub/cpu include/grub/machine \
gensymlist.sh genkernsyms.sh build_env.mk gensymlist.sh genkernsyms.sh build_env.mk \
docs/grub.info docs/version.texi docs/stamp-vti
MAINTAINER_CLEANFILES = $(srcdir)/configure $(addprefix $(srcdir)/,$(MKFILES)) \ MAINTAINER_CLEANFILES = $(srcdir)/configure $(addprefix $(srcdir)/,$(MKFILES)) \
$(srcdir)/DISTLIST $(srcdir)/config.h.in $(srcdir)/stamp-h.in $(INFOS) $(srcdir)/DISTLIST $(srcdir)/config.h.in $(srcdir)/stamp-h.in $(INFOS)

View file

@ -38,18 +38,18 @@ grub_cmd_hexdump (grub_extcmd_t cmd, int argc, char **args)
struct grub_arg_list *state = cmd->state; struct grub_arg_list *state = cmd->state;
char buf[GRUB_DISK_SECTOR_SIZE * 4]; char buf[GRUB_DISK_SECTOR_SIZE * 4];
grub_ssize_t size, length; grub_ssize_t size, length;
grub_addr_t skip; grub_disk_addr_t skip;
int namelen; int namelen;
if (argc != 1) if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
namelen = grub_strlen (args[0]); namelen = grub_strlen (args[0]);
skip = (state[0].set) ? grub_strtoul (state[0].arg, 0, 0) : 0; skip = (state[0].set) ? grub_strtoull (state[0].arg, 0, 0) : 0;
length = (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 256; length = (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 256;
if (!grub_strcmp (args[0], "(mem)")) if (!grub_strcmp (args[0], "(mem)"))
hexdump (skip, (char *) skip, length); hexdump (skip, (char *) (grub_addr_t) skip, length);
else if ((args[0][0] == '(') && (args[0][namelen - 1] == ')')) else if ((args[0][0] == '(') && (args[0][namelen - 1] == ')'))
{ {
grub_disk_t disk; grub_disk_t disk;

View file

@ -3,7 +3,13 @@
sbin_UTILITIES += grub-mkdevicemap sbin_UTILITIES += grub-mkdevicemap
grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \ grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \
util/deviceiter.c \ util/deviceiter.c \
util/devicemap.c util/misc.c util/misc.c
ifeq ($(target_cpu)-$(platform), sparc64-ieee1275)
grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c
else
grub_mkdevicemap_SOURCES += util/devicemap.c
endif
# For grub-mkelfimage. # For grub-mkelfimage.
bin_UTILITIES += grub-mkelfimage bin_UTILITIES += grub-mkelfimage

View file

@ -209,7 +209,7 @@ else
fi fi
# Check for functions. # Check for functions.
AC_CHECK_FUNCS(posix_memalign memalign asprintf) AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf)
# For grub-mkisofs # For grub-mkisofs
AC_HEADER_MAJOR AC_HEADER_MAJOR

View file

@ -169,7 +169,7 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
else else
{ {
grub_free (data); grub_free (data);
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot get C/H/S values"); return grub_error (GRUB_ERR_BAD_DEVICE, "%s cannot get C/H/S values", disk->name);
} }
} }
@ -252,7 +252,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
1024 /* cylinders */ * 1024 /* cylinders */ *
256 /* heads */ * 256 /* heads */ *
63 /* spt */) 63 /* spt */)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk"); return grub_error (GRUB_ERR_OUT_OF_RANGE, "%s out of disk", disk->name);
soff = ((grub_uint32_t) sector) % data->sectors + 1; soff = ((grub_uint32_t) sector) % data->sectors + 1;
head = ((grub_uint32_t) sector) / data->sectors; head = ((grub_uint32_t) sector) / data->sectors;
@ -260,7 +260,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
coff = head / data->heads; coff = head / data->heads;
if (coff >= data->cylinders) if (coff >= data->cylinders)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk"); return grub_error (GRUB_ERR_OUT_OF_RANGE, "%s out of disk", disk->name);
if (grub_biosdisk_rw_standard (cmd + 0x02, data->drive, if (grub_biosdisk_rw_standard (cmd + 0x02, data->drive,
coff, hoff, soff, size, segment)) coff, hoff, soff, size, segment))
@ -268,9 +268,9 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
switch (cmd) switch (cmd)
{ {
case GRUB_BIOSDISK_READ: case GRUB_BIOSDISK_READ:
return grub_error (GRUB_ERR_READ_ERROR, "biosdisk read error"); return grub_error (GRUB_ERR_READ_ERROR, "%s read error", disk->name);
case GRUB_BIOSDISK_WRITE: case GRUB_BIOSDISK_WRITE:
return grub_error (GRUB_ERR_WRITE_ERROR, "biosdisk write error"); return grub_error (GRUB_ERR_WRITE_ERROR, "%s write error", disk->name);
} }
} }
} }

View file

@ -107,7 +107,7 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
} }
if (! grub_strcmp (alias->type, "block") && if (! grub_strcmp (alias->type, "block") &&
grub_strcmp (alias->name, "cdrom")) grub_strncmp (alias->name, "cdrom", 5))
ret = hook (alias->name); ret = hook (alias->name);
return ret; return ret;
} }

View file

@ -63,7 +63,7 @@ fixup (struct grub_ntfs_data *data, char *buf, int len, char *magic)
static grub_err_t read_mft (struct grub_ntfs_data *data, char *buf, static grub_err_t read_mft (struct grub_ntfs_data *data, char *buf,
grub_uint32_t mftno); grub_uint32_t mftno);
static grub_err_t read_attr (struct grub_ntfs_attr *at, char *dest, static grub_err_t read_attr (struct grub_ntfs_attr *at, char *dest,
grub_uint32_t ofs, grub_uint32_t len, grub_disk_addr_t ofs, grub_size_t len,
int cached, int cached,
void void
NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t
@ -72,7 +72,7 @@ static grub_err_t read_attr (struct grub_ntfs_attr *at, char *dest,
unsigned length)); unsigned length));
static grub_err_t read_data (struct grub_ntfs_attr *at, char *pa, char *dest, static grub_err_t read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
grub_uint32_t ofs, grub_uint32_t len, grub_disk_addr_t ofs, grub_size_t len,
int cached, int cached,
void void
NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t
@ -260,9 +260,9 @@ locate_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft,
} }
static char * static char *
read_run_data (char *run, int nn, grub_uint32_t * val, int sig) read_run_data (char *run, int nn, grub_disk_addr_t * val, int sig)
{ {
grub_uint32_t r, v; grub_disk_addr_t r, v;
r = 0; r = 0;
v = 1; v = 1;
@ -284,7 +284,7 @@ grub_err_t
grub_ntfs_read_run_list (struct grub_ntfs_rlst * ctx) grub_ntfs_read_run_list (struct grub_ntfs_rlst * ctx)
{ {
int c1, c2; int c1, c2;
grub_uint32_t val; grub_disk_addr_t val;
char *run; char *run;
run = ctx->cur_run; run = ctx->cur_run;
@ -335,25 +335,25 @@ grub_ntfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t block)
struct grub_ntfs_rlst *ctx; struct grub_ntfs_rlst *ctx;
ctx = (struct grub_ntfs_rlst *) node; ctx = (struct grub_ntfs_rlst *) node;
if ((grub_uint32_t) block >= ctx->next_vcn) if (block >= ctx->next_vcn)
{ {
if (grub_ntfs_read_run_list (ctx)) if (grub_ntfs_read_run_list (ctx))
return -1; return -1;
return ctx->curr_lcn; return ctx->curr_lcn;
} }
else else
return (ctx->flags & RF_BLNK) ? 0 : ((grub_uint32_t) block - return (ctx->flags & RF_BLNK) ? 0 : (block -
ctx->curr_vcn + ctx->curr_lcn); ctx->curr_vcn + ctx->curr_lcn);
} }
static grub_err_t static grub_err_t
read_data (struct grub_ntfs_attr *at, char *pa, char *dest, grub_uint32_t ofs, read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
grub_uint32_t len, int cached, grub_disk_addr_t ofs, grub_size_t len, int cached,
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned offset,
unsigned length)) unsigned length))
{ {
grub_uint32_t vcn; grub_disk_addr_t vcn;
struct grub_ntfs_rlst cc, *ctx; struct grub_ntfs_rlst cc, *ctx;
if (len == 0) if (len == 0)
@ -388,7 +388,7 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest, grub_uint32_t ofs,
{ {
if ((ofs & (~(COM_LEN - 1))) == at->save_pos) if ((ofs & (~(COM_LEN - 1))) == at->save_pos)
{ {
grub_uint32_t n; grub_disk_addr_t n;
n = COM_LEN - (ofs - at->save_pos); n = COM_LEN - (ofs - at->save_pos);
if (n > len) if (n > len)
@ -411,11 +411,11 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest, grub_uint32_t ofs,
at->save_pos = 1; at->save_pos = 1;
} }
vcn = ctx->target_vcn = (ofs / COM_LEN) * (COM_SEC / ctx->comp.spc); vcn = ctx->target_vcn = (ofs >> COM_LOG_LEN) * (COM_SEC / ctx->comp.spc);
ctx->target_vcn &= ~0xF; ctx->target_vcn &= ~0xF;
} }
else else
vcn = ctx->target_vcn = (ofs >> BLK_SHR) / ctx->comp.spc; vcn = ctx->target_vcn = grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, 0);
ctx->next_vcn = u32at (pa, 0x10); ctx->next_vcn = u32at (pa, 0x10);
ctx->curr_lcn = 0; ctx->curr_lcn = 0;
@ -427,11 +427,13 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest, grub_uint32_t ofs,
if (at->flags & AF_GPOS) if (at->flags & AF_GPOS)
{ {
grub_uint32_t st0, st1; grub_disk_addr_t st0, st1;
grub_uint32_t m;
grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, &m);
st0 = st0 =
(ctx->target_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc + (ctx->target_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc + m;
((ofs >> BLK_SHR) % ctx->comp.spc);
st1 = st0 + 1; st1 = st0 + 1;
if (st1 == if (st1 ==
(ctx->next_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc) (ctx->next_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc)
@ -462,8 +464,8 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest, grub_uint32_t ofs,
} }
static grub_err_t static grub_err_t
read_attr (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs, read_attr (struct grub_ntfs_attr *at, char *dest, grub_disk_addr_t ofs,
grub_uint32_t len, int cached, grub_size_t len, int cached,
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned offset,
unsigned length)) unsigned length))
@ -479,9 +481,9 @@ read_attr (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs,
if (at->flags & AF_ALST) if (at->flags & AF_ALST)
{ {
char *pa; char *pa;
grub_uint32_t vcn; grub_disk_addr_t vcn;
vcn = ofs / (at->mft->data->spc << BLK_SHR); vcn = grub_divmod64 (ofs, at->mft->data->spc << BLK_SHR, 0);
pa = at->attr_nxt + u16at (at->attr_nxt, 4); pa = at->attr_nxt + u16at (at->attr_nxt, 4);
while (pa < at->attr_end) while (pa < at->attr_end)
{ {
@ -508,7 +510,7 @@ static grub_err_t
read_mft (struct grub_ntfs_data *data, char *buf, grub_uint32_t mftno) read_mft (struct grub_ntfs_data *data, char *buf, grub_uint32_t mftno)
{ {
if (read_attr if (read_attr
(&data->mmft.attr, buf, mftno * (data->mft_size << BLK_SHR), (&data->mmft.attr, buf, mftno * ((grub_disk_addr_t) data->mft_size << BLK_SHR),
data->mft_size << BLK_SHR, 0, 0)) data->mft_size << BLK_SHR, 0, 0))
return grub_error (GRUB_ERR_BAD_FS, "Read MFT 0x%X fails", mftno); return grub_error (GRUB_ERR_BAD_FS, "Read MFT 0x%X fails", mftno);
return fixup (data, buf, data->mft_size, "FILE"); return fixup (data, buf, data->mft_size, "FILE");
@ -640,7 +642,8 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
unsigned char *bitmap; unsigned char *bitmap;
struct grub_ntfs_attr attr, *at; struct grub_ntfs_attr attr, *at;
char *cur_pos, *indx, *bmp; char *cur_pos, *indx, *bmp;
int bitmap_len, ret = 0; int ret = 0;
grub_size_t bitmap_len;
struct grub_ntfs_file *mft; struct grub_ntfs_file *mft;
mft = (struct grub_ntfs_file *) dir; mft = (struct grub_ntfs_file *) dir;
@ -744,14 +747,14 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
if (bitmap) if (bitmap)
{ {
grub_uint32_t v, i; grub_disk_addr_t v, i;
indx = grub_malloc (mft->data->idx_size << BLK_SHR); indx = grub_malloc (mft->data->idx_size << BLK_SHR);
if (indx == NULL) if (indx == NULL)
goto done; goto done;
v = 1; v = 1;
for (i = 0; i < (grub_uint32_t) bitmap_len * 8; i++) for (i = 0; i < (grub_disk_addr_t)bitmap_len * 8; i++)
{ {
if (*bitmap & v) if (*bitmap & v)
{ {

View file

@ -209,7 +209,7 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
} }
} }
nn = (16 - (ctx->target_vcn & 0xF)) / cpb; nn = (16 - (unsigned) (ctx->target_vcn & 0xF)) / cpb;
if (nn > num) if (nn > num)
nn = num; nn = num;
num -= nn; num -= nn;

View file

@ -17,6 +17,7 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/list.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/mm.h> #include <grub/mm.h>
@ -41,6 +42,16 @@ static int grub_gettext_max;
static const char *(*grub_gettext_original) (const char *s); static const char *(*grub_gettext_original) (const char *s);
struct grub_gettext_msg
{
struct grub_gettext_msg *next;
const char *name;
const char *translated;
};
struct grub_gettext_msg *grub_gettext_msg_list = NULL;
#define GETTEXT_MAGIC_NUMBER 0 #define GETTEXT_MAGIC_NUMBER 0
#define GETTEXT_FILE_FORMAT 4 #define GETTEXT_FILE_FORMAT 4
#define GETTEXT_NUMBER_OF_STRINGS 8 #define GETTEXT_NUMBER_OF_STRINGS 8
@ -79,7 +90,7 @@ grub_gettext_getstring_from_offset (grub_uint32_t offset,
translation[length] = '\0'; translation[length] = '\0';
} }
static char * static const char *
grub_gettext_gettranslation_from_position (int position) grub_gettext_gettranslation_from_position (int position)
{ {
int offsettranslation; int offsettranslation;
@ -130,9 +141,18 @@ static const char *
grub_gettext_translate (const char *orig) grub_gettext_translate (const char *orig)
{ {
char *current_string; char *current_string;
char *ret; const char *ret;
int min, max, current; int min, max, current;
int found = 0;
struct grub_gettext_msg *cur;
cur = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_gettext_msg_list),
orig);
if (cur)
return cur->translated;
if (fd_mo == 0) if (fd_mo == 0)
return orig; return orig;
@ -142,7 +162,7 @@ grub_gettext_translate (const char *orig)
current = (max + min) / 2; current = (max + min) / 2;
while (current != min && current != max) while (current != min && current != max && found == 0)
{ {
current_string = grub_gettext_getstring_from_position (current); current_string = grub_gettext_getstring_from_position (current);
@ -160,13 +180,31 @@ grub_gettext_translate (const char *orig)
else if (grub_strcmp (current_string, orig) == 0) else if (grub_strcmp (current_string, orig) == 0)
{ {
grub_free (current_string); grub_free (current_string);
return grub_gettext_gettranslation_from_position (current); found = 1;
} }
current = (max + min) / 2; current = (max + min) / 2;
} }
ret = grub_malloc (grub_strlen (orig) + 1); ret = found ? grub_gettext_gettranslation_from_position (current) : orig;
grub_strcpy (ret, orig);
if (found)
{
cur = grub_zalloc (sizeof (*cur));
if (cur)
{
cur->name = grub_strdup (orig);
if (cur->name)
{
cur->translated = ret;
grub_list_push (GRUB_AS_LIST_P (&grub_gettext_msg_list),
GRUB_AS_LIST (cur));
}
}
else
grub_errno = GRUB_ERR_NONE;
}
return ret; return ret;
} }
@ -222,7 +260,7 @@ grub_gettext_init_ext (const char *lang)
locale_dir = grub_env_get ("locale_dir"); locale_dir = grub_env_get ("locale_dir");
if (locale_dir == NULL) if (locale_dir == NULL)
{ {
grub_dprintf ("gettext", "locale_dir variable is not set up."); grub_dprintf ("gettext", "locale_dir variable is not set up.\n");
return; return;
} }
@ -259,12 +297,29 @@ grub_gettext_init_ext (const char *lang)
} }
} }
static void
grub_gettext_delete_list ()
{
struct grub_gettext_msg *item;
while ((item =
grub_list_pop (GRUB_AS_LIST_P (&grub_gettext_msg_list))) != 0)
{
char *original = (char *) ((struct grub_gettext_msg *) item)->name;
grub_free (original);
// Don't delete the translated message because could be in use.
}
}
static char * static char *
grub_gettext_env_write_lang (struct grub_env_var *var grub_gettext_env_write_lang (struct grub_env_var *var
__attribute__ ((unused)), const char *val) __attribute__ ((unused)), const char *val)
{ {
grub_gettext_init_ext (val); grub_gettext_init_ext (val);
grub_gettext_delete_list ();
return grub_strdup (val); return grub_strdup (val);
} }
@ -307,5 +362,7 @@ GRUB_MOD_FINI (gettext)
if (fd_mo != 0) if (fd_mo != 0)
grub_file_close (fd_mo); grub_file_close (fd_mo);
grub_gettext_delete_list ();
grub_gettext = grub_gettext_original; grub_gettext = grub_gettext_original;
} }

View file

@ -171,6 +171,7 @@ char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n);
void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s); grub_size_t EXPORT_FUNC(grub_strlen) (const char *s);
int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void EXPORT_FUNC(grub_real_dprintf) (const char *file, void EXPORT_FUNC(grub_real_dprintf) (const char *file,
const int line, const int line,
const char *condition, const char *condition,

View file

@ -73,6 +73,7 @@
#define MAX_IDX (16384 >> BLK_SHR) #define MAX_IDX (16384 >> BLK_SHR)
#define COM_LEN 4096 #define COM_LEN 4096
#define COM_LOG_LEN 12
#define COM_SEC (COM_LEN >> BLK_SHR) #define COM_SEC (COM_LEN >> BLK_SHR)
#define AF_ALST 1 #define AF_ALST 1
@ -164,7 +165,7 @@ struct grub_ntfs_comp
struct grub_ntfs_rlst struct grub_ntfs_rlst
{ {
int flags; int flags;
grub_uint32_t target_vcn, curr_vcn, next_vcn, curr_lcn; grub_disk_addr_t target_vcn, curr_vcn, next_vcn, curr_lcn;
char *cur_run; char *cur_run;
struct grub_ntfs_attr *attr; struct grub_ntfs_attr *attr;
struct grub_ntfs_comp comp; struct grub_ntfs_comp comp;

View file

@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include <setjmp.h> #include <setjmp.h>
#include <unistd.h> #include <unistd.h>
@ -57,12 +58,20 @@ void grub_util_write_image (const char *img, size_t size, FILE *out);
void grub_util_write_image_at (const void *img, size_t size, off_t offset, void grub_util_write_image_at (const void *img, size_t size, off_t offset,
FILE *out); FILE *out);
#ifndef HAVE_VASPRINTF
int vasprintf (char **buf, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF #ifndef HAVE_ASPRINTF
int asprintf (char **buf, const char *fmt, ...); int asprintf (char **buf, const char *fmt, ...);
#endif #endif
char *xasprintf (const char *fmt, ...);
#ifdef __MINGW32__ #ifdef __MINGW32__
#define fseeko fseeko64 #define fseeko fseeko64

View file

@ -109,6 +109,8 @@ grub_device_iterate (int (*hook) (const char *name))
(void) grub_partition_iterate (dev->disk, iterate_partition); (void) grub_partition_iterate (dev->disk, iterate_partition);
grub_device_close (dev); grub_device_close (dev);
grub_errno = GRUB_ERR_NONE;
p = ents; p = ents;
while (p != NULL) while (p != NULL)
{ {

View file

@ -126,6 +126,19 @@ grub_printf (const char *fmt, ...)
return ret; return ret;
} }
int
grub_printf_ (const char *fmt, ...)
{
va_list ap;
int ret;
va_start (ap, fmt);
ret = grub_vprintf (_(fmt), ap);
va_end (ap);
return ret;
}
#if defined (APPLE_CC) && ! defined (GRUB_UTIL) #if defined (APPLE_CC) && ! defined (GRUB_UTIL)
int int
grub_err_printf (const char *fmt, ...) grub_err_printf (const char *fmt, ...)

View file

@ -355,7 +355,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
{ {
char *tail; char *tail;
grub_strtoul (option, &tail, 0); grub_strtoull (option, &tail, 0);
if (tail == 0 || tail == option || *tail != '\0' || grub_errno) if (tail == 0 || tail == option || *tail != '\0' || grub_errno)
{ {
grub_error (GRUB_ERR_BAD_ARGUMENT, grub_error (GRUB_ERR_BAD_ARGUMENT,

View file

@ -509,7 +509,7 @@ grub_normal_reader_init (void)
grub_normal_init_page (); grub_normal_init_page ();
grub_setcursor (1); grub_setcursor (1);
grub_printf (_("\ grub_printf_ (N_("\
[ Minimal BASH-like line editing is supported. For the first word, TAB\n\ [ Minimal BASH-like line editing is supported. For the first word, TAB\n\
lists possible command completions. Anywhere else TAB lists possible\n\ lists possible command completions. Anywhere else TAB lists possible\n\
device/file completions.%s ]\n\n"), device/file completions.%s ]\n\n"),

View file

@ -837,7 +837,7 @@ store_completion (const char *item, grub_completion_type_t type, int count)
grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
grub_printf (" "); grub_printf (" ");
grub_printf (_("Possible %s are:"), what); grub_printf_ (N_("Possible %s are:"), what);
grub_printf ("\n "); grub_printf ("\n ");
} }
@ -1000,7 +1000,7 @@ run (struct screen *screen)
grub_cls (); grub_cls ();
grub_printf (" "); grub_printf (" ");
grub_printf (_("Booting a command list")); grub_printf_ (N_("Booting a command list"));
grub_printf ("\n\n"); grub_printf ("\n\n");
@ -1182,6 +1182,6 @@ grub_menu_entry_run (grub_menu_entry_t entry)
grub_print_error (); grub_print_error ();
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
grub_putchar ('\n'); grub_putchar ('\n');
grub_printf (_("Press any key to continue...")); grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey (); (void) grub_getkey ();
} }

View file

@ -40,7 +40,7 @@ void
grub_wait_after_message (void) grub_wait_after_message (void)
{ {
grub_putchar ('\n'); grub_putchar ('\n');
grub_printf (_("Press any key to continue...")); grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey (); (void) grub_getkey ();
grub_putchar ('\n'); grub_putchar ('\n');
} }
@ -206,7 +206,7 @@ entry is highlighted.");
if (nested) if (nested)
{ {
grub_printf ("\n "); grub_printf ("\n ");
grub_printf (_("ESC to return previous menu.")); grub_printf_ (N_("ESC to return previous menu."));
} }
} }
} }
@ -627,7 +627,7 @@ notify_booting (grub_menu_entry_t entry,
void *userdata __attribute__((unused))) void *userdata __attribute__((unused)))
{ {
grub_printf (" "); grub_printf (" ");
grub_printf (_("Booting \'%s\'"), entry->title); grub_printf_ (N_("Booting \'%s\'"), entry->title);
grub_printf ("\n\n"); grub_printf ("\n\n");
} }
@ -639,7 +639,7 @@ notify_fallback (grub_menu_entry_t entry,
void *userdata __attribute__((unused))) void *userdata __attribute__((unused)))
{ {
grub_printf ("\n "); grub_printf ("\n ");
grub_printf (_("Falling back to \'%s\'"), entry->title); grub_printf_ (N_("Falling back to \'%s\'"), entry->title);
grub_printf ("\n\n"); grub_printf ("\n\n");
grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS);
} }
@ -655,7 +655,7 @@ notify_execution_failure (void *userdata __attribute__((unused)))
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
} }
grub_printf ("\n "); grub_printf ("\n ");
grub_printf (_("Failed to boot default entries.\n")); grub_printf_ (N_("Failed to boot default entries.\n"));
grub_wait_after_message (); grub_wait_after_message ();
} }

View file

@ -546,7 +546,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q) if (q)
*q = ','; *q = ',';
asprintf (&grub_dev, "md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else if (os_dev[7] == '/' && os_dev[8] == 'd') else if (os_dev[7] == '/' && os_dev[8] == 'd')
@ -561,7 +561,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q) if (q)
*q = ','; *q = ',';
asprintf (&grub_dev, "md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else if (os_dev[7] >= '0' && os_dev[7] <= '9') else if (os_dev[7] >= '0' && os_dev[7] <= '9')
@ -574,7 +574,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q) if (q)
*q = ','; *q = ',';
asprintf (&grub_dev, "md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9') else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
@ -587,7 +587,7 @@ grub_util_get_grub_dev (const char *os_dev)
if (q) if (q)
*q = ','; *q = ',';
asprintf (&grub_dev, "md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else else

View file

@ -107,7 +107,7 @@ create_envblk_file (const char *name)
if (! buf) if (! buf)
grub_util_error ("out of memory"); grub_util_error ("out of memory");
asprintf (&namenew, "%s.new", name); namenew = xasprintf ("%s.new", name);
fp = fopen (namenew, "wb"); fp = fopen (namenew, "wb");
if (! fp) if (! fp)
grub_util_error ("cannot open the file %s", namenew); grub_util_error ("cannot open the file %s", namenew);

View file

@ -85,7 +85,7 @@ execute_command (char *name, int n, char **args)
#define BUF_SIZE 32256 #define BUF_SIZE 32256
static grub_off_t skip, leng; static grub_disk_addr_t skip, leng;
static void static void
read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
@ -140,7 +140,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
if (skip > file->size) if (skip > file->size)
{ {
grub_util_error ("invalid skip value %d."); grub_util_error ("invalid skip value %lld.", (unsigned long long) skip);
return; return;
} }

View file

@ -24,8 +24,12 @@ bindir=@bindir@
sbindir=@sbindir@ sbindir=@sbindir@
pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"` pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` if test "x$grub_probe" = x; then
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
fi
if test "x$grub_mkrelpath" = x; then
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
fi
grub_warn () grub_warn ()
{ {

View file

@ -366,7 +366,7 @@ write_font (struct grub_font_info *font_info, char *output_file)
if (! style_name[0]) if (! style_name[0])
strcpy (style_name, " Regular"); strcpy (style_name, " Regular");
asprintf (&font_name, "%s %s %d", font_info->name, &style_name[1], font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
font_info->size); font_info->size);
write_string_section ("NAME", font_name, &offset, file); write_string_section ("NAME", font_name, &offset, file);

View file

@ -254,7 +254,7 @@ probe (const char *path, char *device_name)
filebuf_via_sys = grub_util_read_image (path); filebuf_via_sys = grub_util_read_image (path);
rel_path = make_system_path_relative_to_its_root (path); rel_path = make_system_path_relative_to_its_root (path);
asprintf (&grub_path, "(%s)%s", drive_name, rel_path); grub_path = xasprintf ("(%s)%s", drive_name, rel_path);
free (rel_path); free (rel_path);
grub_util_info ("reading %s via GRUB facilities", grub_path); grub_util_info ("reading %s via GRUB facilities", grub_path);
file = grub_file_open (grub_path); file = grub_file_open (grub_path);

View file

@ -679,12 +679,12 @@ make_device_name (int drive, int dos_part, int bsd_part)
char *bsd_part_str = NULL; char *bsd_part_str = NULL;
if (dos_part >= 0) if (dos_part >= 0)
asprintf (&dos_part_str, ",%d", dos_part + 1); dos_part_str = xasprintf (",%d", dos_part + 1);
if (bsd_part >= 0) if (bsd_part >= 0)
asprintf (&bsd_part_str, ",%c", dos_part + 'a'); bsd_part_str = xasprintf (",%c", dos_part + 'a');
asprintf (&ret, "%s%s%s", map[drive].drive, ret = xasprintf ("%s%s%s", map[drive].drive,
dos_part_str ? : "", dos_part_str ? : "",
bsd_part_str ? : ""); bsd_part_str ? : "");

View file

@ -370,6 +370,19 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
{ {
} }
#ifndef HAVE_VASPRINTF
int
vasprintf (char **buf, const char *fmt, va_list ap)
{
/* Should be large enough. */
*buf = xmalloc (512);
return vsprintf (*buf, fmt, ap);
}
#endif
#ifndef HAVE_ASPRINTF #ifndef HAVE_ASPRINTF
int int
@ -378,11 +391,8 @@ asprintf (char **buf, const char *fmt, ...)
int status; int status;
va_list ap; va_list ap;
/* Should be large enough. */
*buf = xmalloc (512);
va_start (ap, fmt); va_start (ap, fmt);
status = vsprintf (*buf, fmt, ap); status = vasprintf (*buf, fmt, ap);
va_end (ap); va_end (ap);
return status; return status;
@ -390,6 +400,23 @@ asprintf (char **buf, const char *fmt, ...)
#endif #endif
char *
xasprintf (const char *fmt, ...)
{
va_list ap;
char *result;
va_start (ap, fmt);
if (vasprintf (&result, fmt, ap) < 0)
{
if (errno == ENOMEM)
grub_util_error ("out of memory");
return NULL;
}
return result;
}
#ifdef __MINGW32__ #ifdef __MINGW32__
void sync (void) void sync (void)
@ -500,7 +527,17 @@ make_system_path_relative_to_its_root (const char *path)
/* buf is another filesystem; we found it. */ /* buf is another filesystem; we found it. */
if (st.st_dev != num) if (st.st_dev != num)
{
/* offset == 0 means path given is the mount point. */
if (offset == 0)
{
free (buf);
free (buf2);
return strdup ("/");
}
else
break; break;
}
offset = p - buf; offset = p - buf;
/* offset == 1 means root directory. */ /* offset == 1 means root directory. */

View file

@ -52,7 +52,7 @@ grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
{ {
void *addr; void *addr;
int err; int err;
err = pci_device_map_range(dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr); err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
if (err) if (err)
grub_util_error ("mapping 0x%x failed (error %d)\n", base, err); grub_util_error ("mapping 0x%x failed (error %d)\n", base, err);
return addr; return addr;

View file

@ -31,9 +31,6 @@ target_cpu=@target_cpu@
platform=@platform@ platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
# for make_system_path_relative_to_its_root()
. ${libdir}/grub/grub-mkconfig_lib
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
@ -120,6 +117,9 @@ for option in "$@"; do
esac esac
done 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; then
echo "install_device not specified." 1>&2 echo "install_device not specified." 1>&2
usage usage