merge trunk

This commit is contained in:
Colin Watson 2011-01-04 15:51:41 +00:00
commit 92882f28b6
101 changed files with 6425 additions and 580 deletions

View file

@ -30,7 +30,7 @@ CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
# gentrigtables
gentrigtables: gentrigtables.c
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(CPPFLAGS) -lm $<
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(CPPFLAGS) $< -lm
CLEANFILES += gentrigtables
# trigtables.c
@ -237,9 +237,9 @@ command.lst: $(MARKER_FILES)
(for pp in $^; do \
b=`basename $$pp .marker`; \
sed -n \
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" \
-e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" $$pp; \
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
done) | sort -u > $@
platform_DATA += command.lst
CLEANFILES += command.lst

View file

@ -27,6 +27,8 @@ kernel = {
i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200';
ldadd = '$(LDADD_KERNEL)';
i386_coreboot_ldflags = '-Wl,-Ttext=0x8200';
i386_multiboot_ldflags = '-Wl,-Ttext=0x8200';
i386_ieee1275_ldflags = '-Wl,-Ttext=0x10000';
@ -39,10 +41,6 @@ kernel = {
emu_cflags = '$(CFLAGS_GNULIB)';
emu_cppflags = '$(CPPFLAGS_GNULIB)';
mips_ldadd = '-lgcc';
powerpc_ldadd = '-lgcc';
sparc64_ldadd = '-lgcc';
i386_pc_startup = kern/i386/pc/startup.S;
i386_efi_startup = kern/i386/efi/startup.S;
x86_64_efi_startup = kern/x86_64/efi/startup.S;
@ -164,6 +162,7 @@ kernel = {
emu = disk/host.c;
emu = gnulib/progname.c;
emu = gnulib/error.c;
emu = kern/emu/cache.S;
emu = kern/emu/console.c;
emu = kern/emu/getroot.c;
emu = kern/emu/hostdisk.c;
@ -210,7 +209,6 @@ program = {
name = grub-emu-lite;
emu = kern/emu/lite.c;
emu = kern/emu/cache.S;
emu_nodist = symlist.c;
ldadd = 'kernel.img$(EXEEXT)';
@ -302,7 +300,8 @@ image = {
mips_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
objcopyflags = '-O binary';
ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000';
ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
ldadd = '-lgcc';
cflags = '-static-libgcc';
enable = mips;
};
@ -315,7 +314,8 @@ image = {
mips_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
objcopyflags = '-O binary';
ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000';
ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
ldadd = '-lgcc';
cflags = '-static-libgcc';
enable = mips;
};
@ -1007,6 +1007,19 @@ module = {
common = fs/xfs.c;
};
module = {
name = zfs;
common = fs/zfs/zfs.c;
common = fs/zfs/zfs_lzjb.c;
common = fs/zfs/zfs_sha256.c;
common = fs/zfs/zfs_fletcher.c;
};
module = {
name = zfsinfo;
common = fs/zfs/zfsinfo.c;
};
module = {
name = pxe;
i386_pc = fs/i386/pc/pxe.c;

View file

@ -459,6 +459,8 @@ fd_probe_error_string: .asciz "Floppy"
1:
/* perform read */
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
movw %bx, %es
xorw %bx, %bx
movw $0x201, %ax
movb $0, %ch
movb $0, %dh

View file

@ -90,7 +90,14 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook)
/* Check if there is a device present. */
if (id >> 16 == 0xFFFF)
continue;
{
if (dev.function == 0)
/* Devices are required to implement function 0, so if
it's missing then there is no device here. */
break;
else
continue;
}
#ifdef GRUB_MACHINE_MIPS_YEELOONG
/* Skip ghosts. */

View file

@ -36,6 +36,7 @@ typedef uint8_t grub_uint8_t;
#ifndef GRUB_DSDT_TEST
#include <grub/misc.h>
#include <grub/time.h>
#include <grub/cpu/io.h>
#endif
@ -324,6 +325,8 @@ grub_acpi_halt (void)
}
}
grub_millisleep (1500);
grub_printf ("ACPI shutdown failed\n");
}
#endif

View file

@ -1,7 +1,7 @@
/* echo.c - Command to display a line of text */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007 Free Software Foundation, Inc.
* Copyright (C) 2006,2007,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@
#include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/term.h>
static const struct grub_arg_option options[] =
{
@ -43,8 +44,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
for (i = 0; i < argc; i++)
{
char *arg = *args;
/* Unescaping results in a string no longer than the original. */
char *unescaped = grub_malloc (grub_strlen (arg) + 1);
char *p = unescaped;
args++;
if (!unescaped)
return grub_errno;
while (*arg)
{
/* In case `-e' is used, parse backslashes. */
@ -57,11 +64,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
switch (*arg)
{
case '\\':
grub_printf ("\\");
*p++ = '\\';
break;
case 'a':
grub_printf ("\a");
*p++ = '\a';
break;
case 'c':
@ -69,23 +76,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
break;
case 'f':
grub_printf ("\f");
*p++ = '\f';
break;
case 'n':
grub_printf ("\n");
*p++ = '\n';
break;
case 'r':
grub_printf ("\r");
*p++ = '\r';
break;
case 't':
grub_printf ("\t");
*p++ = '\t';
break;
case 'v':
grub_printf ("\v");
*p++ = '\v';
break;
}
arg++;
@ -94,10 +101,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
/* This was not an escaped character, or escaping is not
enabled. */
grub_printf ("%c", *arg);
*p++ = *arg;
arg++;
}
*p = '\0';
grub_xputs (unescaped);
grub_free (unescaped);
/* If another argument follows, insert a space. */
if (i != argc - 1)
grub_printf (" " );
@ -106,6 +117,8 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
if (newline)
grub_printf ("\n");
grub_refresh ();
return 0;
}

View file

@ -177,9 +177,6 @@ legacy_file (const char *filename)
grub_free (suffix);
grub_free (entrysrc);
if (menu && menu->size)
grub_show_menu (menu, 1);
return GRUB_ERR_NONE;
}
@ -194,8 +191,8 @@ grub_cmd_legacy_source (struct grub_command *cmd,
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
extractor = (cmd->name[0] == 'e');
new_env = (cmd->name[extractor ? sizeof ("extract_legacy_entries_") - 1
: sizeof ("legacy_") - 1] == 'c');
new_env = (cmd->name[extractor ? (sizeof ("extract_legacy_entries_") - 1)
: (sizeof ("legacy_") - 1)] == 'c');
if (new_env)
grub_cls ();
@ -207,8 +204,15 @@ grub_cmd_legacy_source (struct grub_command *cmd,
ret = legacy_file (args[0]);
if (new_env && !extractor)
grub_env_context_close ();
if (new_env)
{
grub_menu_t menu;
menu = grub_env_get_menu ();
if (menu && menu->size)
grub_show_menu (menu, 1);
if (!extractor)
grub_env_context_close ();
}
if (extractor)
grub_env_extractor_close (!new_env);
@ -761,12 +765,12 @@ GRUB_MOD_INIT(legacycfg)
= grub_register_command ("extract_legacy_entries_source",
grub_cmd_legacy_source,
N_("FILE"),
N_("Parse legacy config in same context taking onl entries"));
N_("Parse legacy config in same context taking only menu entries"));
cmd_configfile_extract
= grub_register_command ("extract_legacy_entries_configfile",
grub_cmd_legacy_source,
N_("FILE"),
N_("Parse legacy config in new context taking onl entries"));
N_("Parse legacy config in new context taking only menu entries"));
cmd_kernel = grub_register_command ("legacy_kernel",
grub_cmd_legacy_kernel,

View file

@ -206,20 +206,6 @@ setparams_prefix (int argc, char **args)
char *p;
char *result;
grub_size_t len = 10;
static const char *escape_characters = "\"\\";
auto char *strescpy (char *, const char *, const char *);
char * strescpy (char *d, const char *s, const char *escapes)
{
while (*s)
{
if (grub_strchr (escapes, *s))
*d++ = '\\';
*d++ = *s++;
}
*d = '\0';
return d;
}
/* Count resulting string length */
for (i = 0; i < argc; i++)
@ -227,7 +213,7 @@ setparams_prefix (int argc, char **args)
len += 3; /* 3 = 1 space + 2 quotes */
p = args[i];
while (*p)
len += grub_strchr (escape_characters, *p++) ? 2 : 1;
len += (*p++ == '\'' ? 3 : 1);
}
result = grub_malloc (len + 2);
@ -235,17 +221,17 @@ setparams_prefix (int argc, char **args)
return 0;
grub_strcpy (result, "setparams");
i = 9;
p = result + 9;
for (j = 0; j < argc; j++)
{
result[i++] = ' ';
result[i++] = '"';
i = strescpy (result + i, args[j], escape_characters) - result;
result[i++] = '"';
*p++ = ' ';
*p++ = '\'';
p = grub_strchrsub (p, args[j], '\'', "'\\''");
*p++ = '\'';
}
result[i++] = '\n';
result[i] = '\0';
*p++ = '\n';
*p = '\0';
return result;
}

View file

@ -87,7 +87,6 @@ set_matches (char **varnames, char *str, grub_size_t nmatches,
static grub_err_t
grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args)
{
int argn = 0;
regex_t regex;
int ret;
grub_size_t s;

View file

@ -266,7 +266,6 @@ match_files (const char *prefix, const char *suffix, const char *end,
const regex_t *regexp)
{
int i;
int error;
char **files;
unsigned nfile;
char *dir;
@ -440,8 +439,6 @@ wildcard_expand (const char *s, char ***strs)
else if (*start == '/') /* no device part */
{
char **r;
unsigned n;
char *root;
char *prefix;

View file

@ -624,6 +624,11 @@ GRUB_MOD_INIT(biosdisk)
((cdrp->media_type & GRUB_BIOSDISK_CDTYPE_MASK)
== GRUB_BIOSDISK_CDTYPE_NO_EMUL))
cd_drive = cdrp->drive_no;
/* Since diskboot.S rejects devices over 0x90 it must be a CD booted with
cdboot.S
*/
if (grub_boot_drive >= 0x90)
cd_drive = grub_boot_drive;
grub_disk_dev_register (&grub_biosdisk_dev);
}

View file

@ -762,5 +762,6 @@ GRUB_MOD_INIT(lvm)
GRUB_MOD_FINI(lvm)
{
grub_disk_dev_unregister (&grub_lvm_dev);
vg_list = NULL;
/* FIXME: free the lvm list. */
}

View file

@ -105,7 +105,7 @@ static grub_err_t
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{
grub_disk_addr_t sector;
grub_disk_addr_t sector = 0;
grub_uint64_t size;
struct grub_raid_super_1x sb;
grub_uint8_t minor_version;
@ -123,6 +123,9 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
for (minor_version = 0; minor_version < 3; ++minor_version)
{
if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0)
continue;
switch (minor_version)
{
case 0:

View file

@ -170,6 +170,8 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
/* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk);
if (size == GRUB_DISK_SIZE_UNKNOWN)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))

View file

@ -522,14 +522,16 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
/* We found more members of the array than the array
actually has according to its superblock. This shouldn't
happen normally. */
grub_dprintf ("raid", "array->nr_devs > array->total_devs (%d)?!?",
array->total_devs);
return grub_error (GRUB_ERR_BAD_DEVICE,
"superfluous RAID member (%d found)",
array->total_devs);
if (array->members[new_array->index].device != NULL)
/* We found multiple devices with the same number. Again,
this shouldn't happen. */
grub_dprintf ("raid", "Found two disks with the number %d?!?",
new_array->number);
return grub_error (GRUB_ERR_BAD_DEVICE,
"found two disks with the number %d",
new_array->number);
if (new_array->disk_size < array->disk_size)
array->disk_size = new_array->disk_size;

View file

@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk)
rblock = (struct grub_affs_rblock *) rootblock;
/* Read the rootblock. */
grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0,
grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0,
GRUB_DISK_SECTOR_SIZE * 16, rootblock);
if (grub_errno)
goto fail;
@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk)
data->disk = disk;
data->htsize = grub_be_to_cpu32 (rblock->htsize);
data->diropen.data = data;
data->diropen.block = (disk->total_sectors >> 1);
data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock);
grub_free (rootblock);
@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label)
{
/* The rootblock maps quite well on a file header block, it's
something we can use here. */
grub_disk_read (data->disk, disk->total_sectors >> 1,
grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock),
data->blocksize * (GRUB_DISK_SECTOR_SIZE
- GRUB_AFFS_FILE_LOCATION),
sizeof (file), &file);
@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs =
.read = grub_affs_read,
.close = grub_affs_close,
.label = grub_affs_label,
#ifdef GRUB_UTIL
.reserved_first_sector = 0,
#endif
.next = 0
};

View file

@ -51,7 +51,7 @@ grub_btrfs_mount (grub_disk_t disk)
&data->sblock) != GRUB_ERR_NONE)
goto fail;
if (grub_strncmp ((char *) data->sblock.signature, BTRFS_SIGNATURE, sizeof (BTRFS_SIGNATURE) - 1))
if (grub_memcmp ((char *) data->sblock.signature, BTRFS_SIGNATURE, sizeof (BTRFS_SIGNATURE) - 1))
{
grub_error (GRUB_ERR_BAD_FS, "not a Btrfs filesystem");
goto fail;

View file

@ -354,6 +354,9 @@ static struct grub_fs grub_cpio_fs = {
.open = grub_cpio_open,
.read = grub_cpio_read,
.close = grub_cpio_close,
#ifdef GRUB_UTIL
.reserved_first_sector = 0,
#endif
};
#ifdef MODE_USTAR

View file

@ -229,7 +229,7 @@ struct grub_ext2_inode
};
grub_uint32_t version;
grub_uint32_t acl;
grub_uint32_t dir_acl;
grub_uint32_t size_high;
grub_uint32_t fragment_addr;
grub_uint32_t osd2[3];
};
@ -470,10 +470,41 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
blknr = grub_le_to_cpu32 (indir[rblock % perblock]);
}
/* triple indirect. */
else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * (blksz / 4 + 1)
+ (blksz / 4) * (blksz / 4) * (blksz / 4 + 1))
{
unsigned int perblock = blksz / 4;
unsigned int rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4
* (blksz / 4 + 1));
grub_uint32_t indir[blksz / 4];
if (grub_disk_read (data->disk,
((grub_disk_addr_t)
grub_le_to_cpu32 (inode->blocks.triple_indir_block))
<< log2_blksz,
0, blksz, indir))
return grub_errno;
if (grub_disk_read (data->disk,
((grub_disk_addr_t)
grub_le_to_cpu32 (indir[(rblock / perblock) / perblock]))
<< log2_blksz,
0, blksz, indir))
return grub_errno;
if (grub_disk_read (data->disk,
((grub_disk_addr_t)
grub_le_to_cpu32 (indir[(rblock / perblock) % perblock]))
<< log2_blksz,
0, blksz, indir))
return grub_errno;
blknr = grub_le_to_cpu32 (indir[rblock % perblock]);
}
else
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"ext2fs doesn't support triple indirect blocks");
"ext2fs doesn't support quadruple indirect blocks");
}
return blknr;
@ -485,11 +516,12 @@ static grub_ssize_t
grub_ext2_read_file (grub_fshelp_node_t node,
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
grub_off_t pos, grub_size_t len, char *buf)
{
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_ext2_read_block,
node->inode.size,
grub_cpu_to_le32 (node->inode.size)
| (((grub_off_t) grub_cpu_to_le32 (node->inode.size_high)) << 32),
LOG2_EXT2_BLOCK_SIZE (node->data));
}
@ -756,6 +788,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
grub_free (fdiro);
file->size = grub_le_to_cpu32 (data->inode->size);
file->size |= ((grub_off_t) grub_le_to_cpu32 (data->inode->size_high)) << 32;
file->data = data;
file->offset = 0;

View file

@ -178,7 +178,7 @@ enum grub_hfsplus_filetype
/* Internal representation of a catalog key. */
struct grub_hfsplus_catkey_internal
{
int parent;
grub_uint32_t parent;
char *name;
};
@ -520,9 +520,12 @@ grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya,
int i;
int diff;
diff = grub_be_to_cpu32 (catkey_a->parent) - catkey_b->parent;
if (diff)
return diff;
/* Safe unsigned comparison */
grub_uint32_t aparent = grub_be_to_cpu32 (catkey_a->parent);
if (aparent > catkey_b->parent)
return 1;
if (aparent < catkey_b->parent)
return -1;
/* Change the filename in keya so the endianness is correct. */
for (i = 0; i < grub_be_to_cpu16 (catkey_a->namelen); i++)
@ -555,15 +558,21 @@ grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya,
{
struct grub_hfsplus_extkey *extkey_a = &keya->extkey;
struct grub_hfsplus_extkey_internal *extkey_b = &keyb->extkey;
int diff;
grub_uint32_t akey;
diff = grub_be_to_cpu32 (extkey_a->fileid) - extkey_b->fileid;
if (diff)
return diff;
diff = grub_be_to_cpu32 (extkey_a->start) - extkey_b->start;
return diff;
/* Safe unsigned comparison */
akey = grub_be_to_cpu32 (extkey_a->fileid);
if (akey > extkey_b->fileid)
return 1;
if (akey < extkey_b->fileid)
return -1;
akey = grub_be_to_cpu32 (extkey_a->start);
if (akey > extkey_b->start)
return 1;
if (akey < extkey_b->start)
return -1;
return 0;
}
static char *

View file

@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs =
.read = grub_sfs_read,
.close = grub_sfs_close,
.label = grub_sfs_label,
#ifdef GRUB_UTIL
.reserved_first_sector = 0,
#endif
.next = 0
};

View file

@ -34,9 +34,6 @@
#define U32 grub_le_to_cpu32
#define U64 grub_le_to_cpu64
#define GRUB_UDF_LOG2_BLKSZ 2
#define GRUB_UDF_BLKSZ 2048
#define GRUB_UDF_TAG_IDENT_PVD 0x0001
#define GRUB_UDF_TAG_IDENT_AVDP 0x0002
#define GRUB_UDF_TAG_IDENT_VDP 0x0003
@ -336,6 +333,13 @@ struct grub_udf_lvd
grub_uint8_t part_maps[1608];
} __attribute__ ((packed));
struct grub_udf_aed
{
struct grub_udf_tag tag;
grub_uint32_t prev_ae;
grub_uint32_t ae_len;
} __attribute__ ((packed));
struct grub_udf_data
{
grub_disk_t disk;
@ -343,7 +347,7 @@ struct grub_udf_data
struct grub_udf_pd pds[GRUB_UDF_MAX_PDS];
struct grub_udf_partmap *pms[GRUB_UDF_MAX_PMS];
struct grub_udf_long_ad root_icb;
int npd, npm;
int npd, npm, lbshift;
};
struct grub_fshelp_node
@ -389,7 +393,7 @@ grub_udf_read_icb (struct grub_udf_data *data,
if (grub_errno)
return grub_errno;
if (grub_disk_read (data->disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (data->disk, block << data->lbshift, 0,
sizeof (struct grub_udf_file_entry),
&node->fe))
return grub_errno;
@ -406,19 +410,26 @@ grub_udf_read_icb (struct grub_udf_data *data,
static grub_disk_addr_t
grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
{
char *buf = NULL;
char *ptr;
int len;
grub_ssize_t len;
grub_disk_addr_t filebytes;
if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE)
switch (U16 (node->fe.tag.tag_ident))
{
case GRUB_UDF_TAG_IDENT_FE:
ptr = (char *) &node->fe.ext_attr[0] + U32 (node->fe.ext_attr_length);
len = U32 (node->fe.alloc_descs_length);
}
else
{
break;
case GRUB_UDF_TAG_IDENT_EFE:
ptr = (char *) &node->efe.ext_attr[0] + U32 (node->efe.ext_attr_length);
len = U32 (node->efe.alloc_descs_length);
break;
default:
grub_error (GRUB_ERR_BAD_FS, "invalid file entry");
return 0;
}
if ((U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
@ -426,43 +437,115 @@ grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
{
struct grub_udf_short_ad *ad = (struct grub_udf_short_ad *) ptr;
len /= sizeof (struct grub_udf_short_ad);
filebytes = fileblock * GRUB_UDF_BLKSZ;
while (len > 0)
filebytes = fileblock * U32 (node->data->lvd.bsize);
while (len >= (grub_ssize_t) sizeof (struct grub_udf_short_ad))
{
if (filebytes < U32 (ad->length))
return ((U32 (ad->position) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data,
node->part_ref,
ad->position)
+ (filebytes / GRUB_UDF_BLKSZ)));
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
grub_uint32_t adtype = U32 (ad->length) >> 30;
if (adtype == 3)
{
struct grub_udf_aed *extension;
grub_disk_addr_t sec = grub_udf_get_block(node->data,
node->part_ref,
ad->position);
if (!buf)
{
buf = grub_malloc (U32 (node->data->lvd.bsize));
if (!buf)
return 0;
}
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
0, adlen, buf))
goto fail;
filebytes -= U32 (ad->length);
extension = (struct grub_udf_aed *) buf;
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
{
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
goto fail;
}
len = U32 (extension->ae_len);
ad = (struct grub_udf_short_ad *)
(buf + sizeof (struct grub_udf_aed));
continue;
}
if (filebytes < adlen)
{
grub_uint32_t ad_pos = ad->position;
grub_free (buf);
return ((U32 (ad_pos) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data, node->part_ref, ad_pos)
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
+ node->data->lbshift))));
}
filebytes -= adlen;
ad++;
len--;
len -= sizeof (struct grub_udf_short_ad);
}
}
else
{
struct grub_udf_long_ad *ad = (struct grub_udf_long_ad *) ptr;
len /= sizeof (struct grub_udf_long_ad);
filebytes = fileblock * GRUB_UDF_BLKSZ;
while (len > 0)
filebytes = fileblock * U32 (node->data->lvd.bsize);
while (len >= (grub_ssize_t) sizeof (struct grub_udf_long_ad))
{
if (filebytes < U32 (ad->length))
return ((U32 (ad->block.block_num) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data,
ad->block.part_ref,
ad->block.block_num)
+ (filebytes / GRUB_UDF_BLKSZ)));
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
grub_uint32_t adtype = U32 (ad->length) >> 30;
if (adtype == 3)
{
struct grub_udf_aed *extension;
grub_disk_addr_t sec = grub_udf_get_block(node->data,
ad->block.part_ref,
ad->block.block_num);
if (!buf)
{
buf = grub_malloc (U32 (node->data->lvd.bsize));
if (!buf)
return 0;
}
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
0, adlen, buf))
goto fail;
filebytes -= U32 (ad->length);
extension = (struct grub_udf_aed *) buf;
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
{
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
goto fail;
}
len = U32 (extension->ae_len);
ad = (struct grub_udf_long_ad *)
(buf + sizeof (struct grub_udf_aed));
continue;
}
if (filebytes < adlen)
{
grub_uint32_t ad_block_num = ad->block.block_num;
grub_uint32_t ad_part_ref = ad->block.part_ref;
grub_free (buf);
return ((U32 (ad_block_num) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data, ad_part_ref,
ad_block_num)
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
+ node->data->lbshift))));
}
filebytes -= adlen;
ad++;
len--;
len -= sizeof (struct grub_udf_long_ad);
}
}
fail:
if (buf)
grub_free (buf);
return 0;
}
@ -471,7 +554,7 @@ grub_udf_read_file (grub_fshelp_node_t node,
void NESTED_FUNC_ATTR
(*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
grub_off_t pos, grub_size_t len, char *buf)
{
switch (U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
{
@ -496,21 +579,21 @@ grub_udf_read_file (grub_fshelp_node_t node,
}
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_udf_read_block,
U64 (node->fe.file_size),
GRUB_UDF_LOG2_BLKSZ);
pos, len, buf, grub_udf_read_block,
U64 (node->fe.file_size),
node->data->lbshift);
}
static int sblocklist[] = { 256, 512, 0 };
static unsigned sblocklist[] = { 256, 512, 0 };
static struct grub_udf_data *
grub_udf_mount (grub_disk_t disk)
{
struct grub_udf_data *data = 0;
struct grub_udf_fileset root_fs;
int *sblklist = sblocklist;
grub_uint32_t block;
int i;
unsigned *sblklist;
grub_uint32_t block, vblock;
int i, lbshift;
data = grub_malloc (sizeof (struct grub_udf_data));
if (!data)
@ -518,12 +601,48 @@ grub_udf_mount (grub_disk_t disk)
data->disk = disk;
/* Search for Anchor Volume Descriptor Pointer (AVDP)
* and determine logical block size. */
block = 0;
for (lbshift = 0; lbshift < 4; lbshift++)
{
for (sblklist = sblocklist; *sblklist; sblklist++)
{
struct grub_udf_avdp avdp;
if (grub_disk_read (disk, *sblklist << lbshift, 0,
sizeof (struct grub_udf_avdp), &avdp))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if (U16 (avdp.tag.tag_ident) == GRUB_UDF_TAG_IDENT_AVDP &&
U32 (avdp.tag.tag_location) == *sblklist)
{
block = U32 (avdp.vds.start);
break;
}
}
if (block)
break;
}
if (!block)
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
data->lbshift = lbshift;
/* Search for Volume Recognition Sequence (VRS). */
for (block = 16;; block++)
for (vblock = (32767 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1;;
vblock += (2047 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1)
{
struct grub_udf_vrs vrs;
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (disk, vblock << lbshift, 0,
sizeof (struct grub_udf_vrs), &vrs))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
@ -545,39 +664,13 @@ grub_udf_mount (grub_disk_t disk)
}
}
/* Search for Anchor Volume Descriptor Pointer (AVDP). */
while (1)
{
struct grub_udf_avdp avdp;
if (grub_disk_read (disk, *sblklist << GRUB_UDF_LOG2_BLKSZ, 0,
sizeof (struct grub_udf_avdp), &avdp))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if (U16 (avdp.tag.tag_ident) == GRUB_UDF_TAG_IDENT_AVDP)
{
block = U32 (avdp.vds.start);
break;
}
sblklist++;
if (*sblklist == 0)
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
}
data->npd = data->npm = 0;
/* Locate Partition Descriptor (PD) and Logical Volume Descriptor (LVD). */
while (1)
{
struct grub_udf_tag tag;
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_tag), &tag))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
@ -593,7 +686,7 @@ grub_udf_mount (grub_disk_t disk)
goto fail;
}
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_pd),
&data->pds[data->npd]))
{
@ -609,7 +702,7 @@ grub_udf_mount (grub_disk_t disk)
struct grub_udf_partmap *ppm;
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_lvd),
&data->lvd))
{
@ -673,7 +766,7 @@ grub_udf_mount (grub_disk_t disk)
if (grub_errno)
goto fail;
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_fileset), &root_fs))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
@ -695,6 +788,43 @@ fail:
return 0;
}
static char *
read_string (grub_uint8_t *raw, grub_size_t sz)
{
grub_uint16_t *utf16 = NULL;
char *ret;
grub_size_t utf16len = 0;
if (raw[0] != 8 && raw[0] != 16)
return NULL;
if (raw[0] == 8)
{
unsigned i;
utf16len = sz - 1;
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
if (!utf16)
return NULL;
for (i = 0; i < utf16len; i++)
utf16[i] = raw[i + 1];
}
if (raw[0] == 16)
{
unsigned i;
utf16len = (sz - 1) / 2;
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
if (!utf16)
return NULL;
for (i = 0; i < utf16len; i++)
utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2];
}
ret = grub_malloc (utf16len * 3 + 1);
if (ret)
*grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0';
grub_free (utf16);
return ret;
}
static int
grub_udf_iterate_dir (grub_fshelp_node_t dir,
int NESTED_FUNC_ATTR
@ -704,7 +834,7 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
{
grub_fshelp_node_t child;
struct grub_udf_file_ident dirent;
grub_uint32_t offset = 0;
grub_off_t offset = 0;
child = grub_malloc (sizeof (struct grub_fshelp_node));
if (!child)
@ -729,57 +859,47 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
return 0;
}
child = grub_malloc (sizeof (struct grub_fshelp_node));
if (!child)
return 0;
if (grub_udf_read_icb (dir->data, &dirent.icb, child))
return 0;
offset += sizeof (dirent) + U16 (dirent.imp_use_length);
if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT)
if (!(dirent.characteristics & GRUB_UDF_FID_CHAR_DELETED))
{
/* This is the parent directory. */
if (hook ("..", GRUB_FSHELP_DIR, child))
return 1;
}
else
{
enum grub_fshelp_filetype type;
grub_uint8_t raw[dirent.file_ident_length];
grub_uint16_t utf16[dirent.file_ident_length - 1];
grub_uint8_t filename[dirent.file_ident_length * 2];
grub_size_t utf16len = 0;
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
if ((grub_udf_read_file (dir, 0, offset,
dirent.file_ident_length,
(char *) raw))
!= dirent.file_ident_length)
child = grub_malloc (sizeof (struct grub_fshelp_node));
if (!child)
return 0;
if (raw[0] == 8)
if (grub_udf_read_icb (dir->data, &dirent.icb, child))
return 0;
if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT)
{
unsigned i;
utf16len = dirent.file_ident_length - 1;
for (i = 0; i < utf16len; i++)
utf16[i] = raw[i + 1];
/* This is the parent directory. */
if (hook ("..", GRUB_FSHELP_DIR, child))
return 1;
}
if (raw[0] == 16)
else
{
unsigned i;
utf16len = (dirent.file_ident_length - 1) / 2;
for (i = 0; i < utf16len; i++)
utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2];
}
if (raw[0] == 8 || raw[0] == 16)
{
*grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0';
if (hook ((char *) filename, type, child))
return 1;
enum grub_fshelp_filetype type;
char *filename;
grub_uint8_t raw[dirent.file_ident_length];
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
if ((grub_udf_read_file (dir, 0, offset,
dirent.file_ident_length,
(char *) raw))
!= dirent.file_ident_length)
return 0;
filename = read_string (raw, dirent.file_ident_length);
if (!filename)
grub_print_error ();
if (filename && hook (filename, type, child))
{
grub_free (filename);
return 1;
}
grub_free (filename);
}
}
@ -908,7 +1028,7 @@ grub_udf_label (grub_device_t device, char **label)
if (data)
{
*label = grub_strdup ((char *) &data->lvd.ident[1]);
*label = read_string (data->lvd.ident, sizeof (data->lvd.ident));
grub_free (data);
}
else

View file

@ -808,6 +808,9 @@ static struct grub_fs grub_xfs_fs =
.close = grub_xfs_close,
.label = grub_xfs_label,
.uuid = grub_xfs_uuid,
#ifdef GRUB_UTIL
.reserved_first_sector = 0,
#endif
.next = 0
};

2543
grub-core/fs/zfs/zfs.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,84 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
* Copyright 2007 Sun Microsystems, 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/err.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/dl.h>
#include <grub/types.h>
#include <grub/zfs/zfs.h>
#include <grub/zfs/zio.h>
#include <grub/zfs/dnode.h>
#include <grub/zfs/uberblock_impl.h>
#include <grub/zfs/vdev_impl.h>
#include <grub/zfs/zio_checksum.h>
#include <grub/zfs/zap_impl.h>
#include <grub/zfs/zap_leaf.h>
#include <grub/zfs/zfs_znode.h>
#include <grub/zfs/dmu.h>
#include <grub/zfs/dmu_objset.h>
#include <grub/zfs/dsl_dir.h>
#include <grub/zfs/dsl_dataset.h>
void
fletcher_2(const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
zio_cksum_t *zcp)
{
const grub_uint64_t *ip = buf;
const grub_uint64_t *ipend = ip + (size / sizeof (grub_uint64_t));
grub_uint64_t a0, b0, a1, b1;
for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2)
{
a0 += grub_zfs_to_cpu64 (ip[0], endian);
a1 += grub_zfs_to_cpu64 (ip[1], endian);
b0 += a0;
b1 += a1;
}
zcp->zc_word[0] = grub_cpu_to_zfs64 (a0, endian);
zcp->zc_word[1] = grub_cpu_to_zfs64 (a1, endian);
zcp->zc_word[2] = grub_cpu_to_zfs64 (b0, endian);
zcp->zc_word[3] = grub_cpu_to_zfs64 (b1, endian);
}
void
fletcher_4 (const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
zio_cksum_t *zcp)
{
const grub_uint32_t *ip = buf;
const grub_uint32_t *ipend = ip + (size / sizeof (grub_uint32_t));
grub_uint64_t a, b, c, d;
for (a = b = c = d = 0; ip < ipend; ip++)
{
a += grub_zfs_to_cpu32 (ip[0], endian);;
b += a;
c += b;
d += c;
}
zcp->zc_word[0] = grub_cpu_to_zfs64 (a, endian);
zcp->zc_word[1] = grub_cpu_to_zfs64 (b, endian);
zcp->zc_word[2] = grub_cpu_to_zfs64 (c, endian);
zcp->zc_word[3] = grub_cpu_to_zfs64 (d, endian);
}

View file

@ -0,0 +1,93 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
* Copyright 2007 Sun Microsystems, 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/err.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/dl.h>
#include <grub/types.h>
#include <grub/zfs/zfs.h>
#include <grub/zfs/zio.h>
#include <grub/zfs/dnode.h>
#include <grub/zfs/uberblock_impl.h>
#include <grub/zfs/vdev_impl.h>
#include <grub/zfs/zio_checksum.h>
#include <grub/zfs/zap_impl.h>
#include <grub/zfs/zap_leaf.h>
#include <grub/zfs/zfs_znode.h>
#include <grub/zfs/dmu.h>
#include <grub/zfs/dmu_objset.h>
#include <grub/zfs/dsl_dir.h>
#include <grub/zfs/dsl_dataset.h>
#define MATCH_BITS 6
#define MATCH_MIN 3
#define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
/*
* Decompression Entry - lzjb
*/
#ifndef NBBY
#define NBBY 8
#endif
grub_err_t
lzjb_decompress (void *s_start, void *d_start, grub_size_t s_len,
grub_size_t d_len);
grub_err_t
lzjb_decompress (void *s_start, void *d_start, grub_size_t s_len,
grub_size_t d_len)
{
grub_uint8_t *src = s_start;
grub_uint8_t *dst = d_start;
grub_uint8_t *d_end = (grub_uint8_t *) d_start + d_len;
grub_uint8_t *s_end = (grub_uint8_t *) s_start + s_len;
grub_uint8_t *cpy, copymap = 0;
int copymask = 1 << (NBBY - 1);
while (dst < d_end && src < s_end)
{
if ((copymask <<= 1) == (1 << NBBY))
{
copymask = 1;
copymap = *src++;
}
if (src >= s_end)
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
if (copymap & copymask)
{
int mlen = (src[0] >> (NBBY - MATCH_BITS)) + MATCH_MIN;
int offset = ((src[0] << NBBY) | src[1]) & OFFSET_MASK;
src += 2;
cpy = dst - offset;
if (src > s_end || cpy < (grub_uint8_t *) d_start)
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
while (--mlen >= 0 && dst < d_end)
*dst++ = *cpy++;
}
else
*dst++ = *src++;
}
if (dst < d_end)
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
return GRUB_ERR_NONE;
}

View file

@ -0,0 +1,143 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
* Copyright 2007 Sun Microsystems, 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/err.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/dl.h>
#include <grub/types.h>
#include <grub/zfs/zfs.h>
#include <grub/zfs/zio.h>
#include <grub/zfs/dnode.h>
#include <grub/zfs/uberblock_impl.h>
#include <grub/zfs/vdev_impl.h>
#include <grub/zfs/zio_checksum.h>
#include <grub/zfs/zap_impl.h>
#include <grub/zfs/zap_leaf.h>
#include <grub/zfs/zfs_znode.h>
#include <grub/zfs/dmu.h>
#include <grub/zfs/dmu_objset.h>
#include <grub/zfs/dsl_dir.h>
#include <grub/zfs/dsl_dataset.h>
/*
* SHA-256 checksum, as specified in FIPS 180-2, available at:
* http://csrc.nist.gov/cryptval
*
* This is a very compact implementation of SHA-256.
* It is designed to be simple and portable, not to be fast.
*/
/*
* The literal definitions according to FIPS180-2 would be:
*
* Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
* Maj(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
*
* We use logical equivalents which require one less op.
*/
#define Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define Maj(x, y, z) (((x) & (y)) ^ ((z) & ((x) ^ (y))))
#define Rot32(x, s) (((x) >> s) | ((x) << (32 - s)))
#define SIGMA0(x) (Rot32(x, 2) ^ Rot32(x, 13) ^ Rot32(x, 22))
#define SIGMA1(x) (Rot32(x, 6) ^ Rot32(x, 11) ^ Rot32(x, 25))
#define sigma0(x) (Rot32(x, 7) ^ Rot32(x, 18) ^ ((x) >> 3))
#define sigma1(x) (Rot32(x, 17) ^ Rot32(x, 19) ^ ((x) >> 10))
static const grub_uint32_t SHA256_K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
static void
SHA256Transform(grub_uint32_t *H, const grub_uint8_t *cp)
{
grub_uint32_t a, b, c, d, e, f, g, h, t, T1, T2, W[64];
for (t = 0; t < 16; t++, cp += 4)
W[t] = (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
for (t = 16; t < 64; t++)
W[t] = sigma1(W[t - 2]) + W[t - 7] +
sigma0(W[t - 15]) + W[t - 16];
a = H[0]; b = H[1]; c = H[2]; d = H[3];
e = H[4]; f = H[5]; g = H[6]; h = H[7];
for (t = 0; t < 64; t++) {
T1 = h + SIGMA1(e) + Ch(e, f, g) + SHA256_K[t] + W[t];
T2 = SIGMA0(a) + Maj(a, b, c);
h = g; g = f; f = e; e = d + T1;
d = c; c = b; b = a; a = T1 + T2;
}
H[0] += a; H[1] += b; H[2] += c; H[3] += d;
H[4] += e; H[5] += f; H[6] += g; H[7] += h;
}
void
zio_checksum_SHA256(const void *buf, grub_uint64_t size,
grub_zfs_endian_t endian, zio_cksum_t *zcp)
{
grub_uint32_t H[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
grub_uint8_t pad[128];
unsigned padsize = size & 63;
unsigned i;
for (i = 0; i < size - padsize; i += 64)
SHA256Transform(H, (grub_uint8_t *)buf + i);
for (i = 0; i < padsize; i++)
pad[i] = ((grub_uint8_t *)buf)[i];
for (pad[padsize++] = 0x80; (padsize & 63) != 56; padsize++)
pad[padsize] = 0;
for (i = 0; i < 8; i++)
pad[padsize++] = (size << 3) >> (56 - 8 * i);
for (i = 0; i < padsize; i += 64)
SHA256Transform(H, pad + i);
zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1],
endian);
zcp->zc_word[1] = grub_cpu_to_zfs64 ((grub_uint64_t)H[2] << 32 | H[3],
endian);
zcp->zc_word[2] = grub_cpu_to_zfs64 ((grub_uint64_t)H[4] << 32 | H[5],
endian);
zcp->zc_word[3] = grub_cpu_to_zfs64 ((grub_uint64_t)H[6] << 32 | H[7],
endian);
}

412
grub-core/fs/zfs/zfsinfo.c Normal file
View file

@ -0,0 +1,412 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
* Copyright 2008 Sun Microsystems, 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/zfs/zfs.h>
#include <grub/device.h>
#include <grub/file.h>
#include <grub/command.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/dl.h>
#include <grub/env.h>
static inline void
print_tabs (int n)
{
int i;
for (i = 0; i < n; i++)
grub_printf (" ");
}
static grub_err_t
print_state (char *nvlist, int tab)
{
grub_uint64_t ival;
int isok = 1;
print_tabs (tab);
grub_printf ("State: ");
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_REMOVED, &ival))
{
grub_printf ("removed ");
isok = 0;
}
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_FAULTED, &ival))
{
grub_printf ("faulted ");
isok = 0;
}
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_OFFLINE, &ival))
{
grub_printf ("offline ");
isok = 0;
}
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_FAULTED, &ival))
grub_printf ("degraded ");
if (isok)
grub_printf ("online");
grub_printf ("\n");
return GRUB_ERR_NONE;
}
static grub_err_t
print_vdev_info (char *nvlist, int tab)
{
char *type = 0;
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
if (!type)
{
print_tabs (tab);
grub_printf ("Incorrect VDEV: no type available\n");
return grub_errno;
}
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
{
char *bootpath = 0;
char *path = 0;
char *devid = 0;
print_tabs (tab);
grub_printf ("Leaf VDEV\n");
print_state (nvlist, tab);
bootpath =
grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_PHYS_PATH);
print_tabs (tab);
if (!bootpath)
grub_printf ("Bootpath: unavailable\n");
else
grub_printf ("Bootpath: %s\n", bootpath);
path = grub_zfs_nvlist_lookup_string (nvlist, "path");
print_tabs (tab);
if (!path)
grub_printf ("Path: unavailable\n");
else
grub_printf ("Path: %s\n", path);
devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
print_tabs (tab);
if (!devid)
grub_printf ("Devid: unavailable\n");
else
grub_printf ("Devid: %s\n", devid);
grub_free (bootpath);
grub_free (devid);
grub_free (path);
return GRUB_ERR_NONE;
}
if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0)
{
int nelm, i;
nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm
(nvlist, ZPOOL_CONFIG_CHILDREN);
print_tabs (tab);
if (nelm <= 0)
{
grub_printf ("Incorrect mirror VDEV\n");
return GRUB_ERR_NONE;
}
grub_printf ("Mirror VDEV with %d children\n", nelm);
print_state (nvlist, tab);
for (i = 0; i < nelm; i++)
{
char *child;
child = grub_zfs_nvlist_lookup_nvlist_array
(nvlist, ZPOOL_CONFIG_CHILDREN, i);
print_tabs (tab);
if (!child)
{
grub_printf ("Mirror VDEV element %d isn't correct\n", i);
continue;
}
grub_printf ("Mirror VDEV element %d:\n", i);
print_vdev_info (child, tab + 1);
grub_free (child);
}
}
print_tabs (tab);
grub_printf ("Unknown VDEV type: %s\n", type);
return GRUB_ERR_NONE;
}
static grub_err_t
get_bootpath (char *nvlist, char **bootpath, char **devid)
{
char *type = 0;
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
if (!type)
return grub_errno;
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
{
*bootpath = grub_zfs_nvlist_lookup_string (nvlist,
ZPOOL_CONFIG_PHYS_PATH);
*devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
if (!*bootpath || !*devid)
{
grub_free (*bootpath);
grub_free (*devid);
*bootpath = 0;
*devid = 0;
}
return GRUB_ERR_NONE;
}
if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0)
{
int nelm, i;
nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm
(nvlist, ZPOOL_CONFIG_CHILDREN);
for (i = 0; i < nelm; i++)
{
char *child;
child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
ZPOOL_CONFIG_CHILDREN,
i);
get_bootpath (child, bootpath, devid);
grub_free (child);
if (*bootpath && *devid)
return GRUB_ERR_NONE;
}
}
return GRUB_ERR_NONE;
}
static char *poolstates[] = {
[POOL_STATE_ACTIVE] = "active",
[POOL_STATE_EXPORTED] = "exported",
[POOL_STATE_DESTROYED] = "destroyed",
[POOL_STATE_SPARE] = "reserved for hot spare",
[POOL_STATE_L2CACHE] = "level 2 ARC device",
[POOL_STATE_UNINITIALIZED] = "uninitialized",
[POOL_STATE_UNAVAIL] = "unavailable",
[POOL_STATE_POTENTIALLY_ACTIVE] = "potentially active"
};
static grub_err_t
grub_cmd_zfsinfo (grub_command_t cmd __attribute__ ((unused)), int argc,
char **args)
{
grub_device_t dev;
char *devname;
grub_err_t err;
char *nvlist = 0;
char *nv = 0;
char *poolname;
grub_uint64_t guid;
grub_uint64_t pool_state;
int found;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
{
devname = grub_strdup (args[0] + 1);
if (devname)
devname[grub_strlen (devname) - 1] = 0;
}
else
devname = grub_strdup (args[0]);
if (!devname)
return grub_errno;
dev = grub_device_open (devname);
grub_free (devname);
if (!dev)
return grub_errno;
err = grub_zfs_fetch_nvlist (dev, &nvlist);
grub_device_close (dev);
if (err)
return err;
poolname = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_POOL_NAME);
if (!poolname)
grub_printf ("Pool name: unavailable\n");
else
grub_printf ("Pool name: %s\n", poolname);
found =
grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_GUID, &guid);
if (!found)
grub_printf ("Pool GUID: unavailable\n");
else
grub_printf ("Pool GUID: %016llx\n", (long long unsigned) guid);
found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STATE,
&pool_state);
if (!found)
grub_printf ("Unable to retrieve pool state\n");
else if (pool_state >= ARRAY_SIZE (poolstates))
grub_printf ("Unrecognized pool state\n");
else
grub_printf ("Pool state: %s\n", poolstates[pool_state]);
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
if (!nv)
grub_printf ("No vdev tree available\n");
else
print_vdev_info (nv, 1);
grub_free (nv);
grub_free (nvlist);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_zfs_bootfs (grub_command_t cmd __attribute__ ((unused)), int argc,
char **args)
{
grub_device_t dev;
char *devname;
grub_err_t err;
char *nvlist = 0;
char *nv = 0;
char *bootpath = 0, *devid = 0;
char *fsname;
char *bootfs;
char *poolname;
grub_uint64_t mdnobj;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "filesystem name required");
devname = grub_file_get_device_name (args[0]);
if (grub_errno)
return grub_errno;
dev = grub_device_open (devname);
grub_free (devname);
if (!dev)
return grub_errno;
err = grub_zfs_fetch_nvlist (dev, &nvlist);
fsname = grub_strchr (args[0], ')');
if (fsname)
fsname++;
else
fsname = args[0];
if (!err)
err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
grub_device_close (dev);
if (err)
return err;
poolname = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_POOL_NAME);
if (!poolname)
{
if (!grub_errno)
grub_error (GRUB_ERR_BAD_FS, "No poolname found");
return grub_errno;
}
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
if (nv)
get_bootpath (nv, &bootpath, &devid);
grub_free (nv);
grub_free (nvlist);
if (bootpath && devid)
{
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu bootpath=%s diskdevid=%s",
poolname, (unsigned long long) mdnobj,
bootpath, devid);
if (!bootfs)
return grub_errno;
}
else
{
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu",
poolname, (unsigned long long) mdnobj);
if (!bootfs)
return grub_errno;
}
if (argc >= 2)
grub_env_set (args[1], bootfs);
else
grub_printf ("%s\n", bootfs);
grub_free (bootfs);
grub_free (poolname);
grub_free (bootpath);
grub_free (devid);
return GRUB_ERR_NONE;
}
static grub_command_t cmd_info, cmd_bootfs;
GRUB_MOD_INIT (zfsinfo)
{
cmd_info = grub_register_command ("zfsinfo", grub_cmd_zfsinfo,
"zfsinfo DEVICE",
"Print ZFS info about DEVICE.");
cmd_bootfs = grub_register_command ("zfs-bootfs", grub_cmd_zfs_bootfs,
"zfs-bootfs FILESYSTEM [VARIABLE]",
"Print ZFS-BOOTFSOBJ or set it to VARIABLE");
}
GRUB_MOD_FINI (zfsinfo)
{
grub_unregister_command (cmd_info);
grub_unregister_command (cmd_bootfs);
}

View file

@ -35,7 +35,7 @@ deps=`grep ^$modname: $moddep | sed s@^.*:@@`
rm -f $tmpfile $outfile
# stripout .modname and .moddeps sections from input module
objcopy -R .modname -R .moddeps $infile $tmpfile
@OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile
# Attach .modname and .moddeps sections
t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
@ -45,9 +45,9 @@ t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
for dep in $deps; do printf "$dep\0" >> $t2; done
if test -n "$deps"; then
objcopy --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
@OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
else
objcopy --add-section .modname=$t1 $tmpfile
@OBJCOPY@ --add-section .modname=$t1 $tmpfile
fi
rm -f $t1 $t2

View file

@ -261,24 +261,16 @@ grub_mofile_open (const char *filename)
return fd_mo;
}
/* Returning grub_file_t would be more natural, but grub_mofile_open assigns
to fd_mo anyway ... */
static void
grub_gettext_init_ext (const char *lang)
grub_mofile_open_lang (const char *locale_dir, const char *locale)
{
char *mo_file;
char *locale_dir;
locale_dir = grub_env_get ("locale_dir");
if (locale_dir == NULL)
{
grub_dprintf ("gettext", "locale_dir variable is not set up.\n");
return;
}
fd_mo = NULL;
/* mo_file e.g.: /boot/grub/locale/ca.mo */
mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, lang);
mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, locale);
if (!mo_file)
return;
@ -295,6 +287,38 @@ grub_gettext_init_ext (const char *lang)
return;
fd_mo = grub_mofile_open (mo_file);
}
}
static void
grub_gettext_init_ext (const char *locale)
{
char *locale_dir;
locale_dir = grub_env_get ("locale_dir");
if (locale_dir == NULL)
{
grub_dprintf ("gettext", "locale_dir variable is not set up.\n");
return;
}
fd_mo = NULL;
grub_mofile_open_lang (locale_dir, locale);
/* ll_CC didn't work, so try ll. */
if (fd_mo == NULL)
{
char *lang = grub_strdup (locale);
char *underscore = grub_strchr (lang, '_');
if (underscore)
{
*underscore = '\0';
grub_mofile_open_lang (locale_dir, lang);
}
grub_free (lang);
}
if (fd_mo)
{

View file

@ -212,19 +212,18 @@ test_header (grub_file_t file)
gzio->data_offset = grub_file_tell (gzio->file);
grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4);
if (grub_file_seekable (gzio->file))
{
if (grub_file_read (gzio->file, &orig_len, 4) != 4)
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format");
return 0;
}
}
/* FIXME: this does not handle files whose original size is over 4GB.
But how can we know the real original size? */
file->size = grub_le_to_cpu32 (orig_len);
/* FIXME: don't do this on not easily seekable files. */
{
grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4);
if (grub_file_read (gzio->file, &orig_len, 4) != 4)
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format");
return 0;
}
/* FIXME: this does not handle files whose original size is over 4GB.
But how can we know the real original size? */
file->size = grub_le_to_cpu32 (orig_len);
}
initialize_tables (file);

View file

@ -222,7 +222,8 @@ grub_xzio_open (grub_file_t io)
xzio->buf.out_pos = 0;
xzio->buf.out_size = XZBUFSIZ;
if (!test_header (file) || !(grub_file_seekable (io) && test_footer (file)))
/* FIXME: don't test footer on not easily seekable files. */
if (!test_header (file) || !test_footer (file))
{
grub_errno = GRUB_ERR_NONE;
grub_file_seek (io, 0);

View file

@ -171,11 +171,12 @@ grub_elf32_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */
grub_size_t
grub_elf32_size (grub_elf_t elf, Elf32_Addr *base)
grub_elf32_size (grub_elf_t elf, Elf32_Addr *base, grub_uint32_t *max_align)
{
Elf32_Addr segments_start = (Elf32_Addr) -1;
Elf32_Addr segments_end = 0;
int nr_phdrs = 0;
grub_uint32_t curr_align = 1;
/* Run through the program headers to calculate the total memory size we
* should claim. */
@ -192,6 +193,8 @@ grub_elf32_size (grub_elf_t elf, Elf32_Addr *base)
segments_start = phdr->p_paddr;
if (phdr->p_paddr + phdr->p_memsz > segments_end)
segments_end = phdr->p_paddr + phdr->p_memsz;
if (curr_align < phdr->p_align)
curr_align = phdr->p_align;
return 0;
}
@ -215,7 +218,8 @@ grub_elf32_size (grub_elf_t elf, Elf32_Addr *base)
if (base)
*base = segments_start;
if (max_align)
*max_align = curr_align;
return segments_end - segments_start;
}
@ -290,7 +294,6 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,
return err;
}
/* 64-bit */
@ -357,16 +360,17 @@ grub_elf64_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */
grub_size_t
grub_elf64_size (grub_elf_t elf, Elf64_Addr *base)
grub_elf64_size (grub_elf_t elf, Elf64_Addr *base, grub_uint64_t *max_align)
{
Elf64_Addr segments_start = (Elf64_Addr) -1;
Elf64_Addr segments_end = 0;
int nr_phdrs = 0;
grub_uint64_t curr_align = 1;
/* Run through the program headers to calculate the total memory size we
* should claim. */
auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf64_Phdr *phdr, void *_arg);
int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf __attribute__ ((unused)),
int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf __attribute__ ((unused)),
Elf64_Phdr *phdr,
void *_arg __attribute__ ((unused)))
{
@ -378,6 +382,8 @@ grub_elf64_size (grub_elf_t elf, Elf64_Addr *base)
segments_start = phdr->p_paddr;
if (phdr->p_paddr + phdr->p_memsz > segments_end)
segments_end = phdr->p_paddr + phdr->p_memsz;
if (curr_align < phdr->p_align)
curr_align = phdr->p_align;
return 0;
}
@ -401,11 +407,11 @@ grub_elf64_size (grub_elf_t elf, Elf64_Addr *base)
if (base)
*base = segments_start;
if (max_align)
*max_align = curr_align;
return segments_end - segments_start;
}
/* Load every loadable segment into memory specified by `_load_hook'. */
grub_err_t
grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,

View file

@ -151,8 +151,6 @@ LOCAL (codestart):
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx
movl reed_solomon_redundancy, %ecx
leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax
testl %edx, %edx
jz post_reed_solomon
call EXT_C (grub_reed_solomon_recover)
jmp post_reed_solomon
@ -224,6 +222,7 @@ multiboot_trampoline:
movb $0xFF, %dh
/* enter the usual booting */
call prot_to_real
jmp LOCAL (codestart)
post_reed_solomon:
@ -649,7 +648,7 @@ FUNCTION(grub_console_getkey)
jae 2f
movl %edx, %eax
leal LOCAL(bypass_table), %edi
movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx
movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) >> 1), %ecx
repne scasw
jz 3f

View file

@ -223,6 +223,8 @@ grub_halt (void)
grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG)
& ~GRUB_CPU_LOONGSON_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG);
grub_millisleep (1500);
grub_printf ("Shutdown failed\n");
grub_refresh ();
while (1);
@ -239,6 +241,8 @@ grub_reboot (void)
{
grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT);
grub_millisleep (1500);
grub_printf ("Reboot failed\n");
grub_refresh ();
while (1);

View file

@ -322,24 +322,23 @@ struct legacy_command legacy_commands[] =
char *
grub_legacy_escape (const char *in, grub_size_t len)
{
const char *ptr;
char *ret, *outptr;
char *ptr;
char *ret;
char saved;
int overhead = 0;
for (ptr = in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'' || *ptr == '\\')
overhead++;
for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'')
overhead += 3;
ret = grub_malloc (ptr - in + overhead + 1);
if (!ret)
return NULL;
outptr = ret;
for (ptr = in; ptr < in + len && *ptr; ptr++)
{
if (*ptr == '\'' || *ptr == '\\')
*outptr++ = '\\';
*outptr++ = *ptr;
}
*outptr++ = 0;
ptr = (char*)in;
saved = ptr[len];
ptr[len] = '\0';
grub_strchrsub (ret, ptr, '\'', "'\\''");
ptr[len] = saved;
return ret;
}
@ -622,12 +621,13 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
{
for (; *ptr && grub_isspace (*ptr); ptr++);
for (; *ptr && !grub_isspace (*ptr); ptr++)
if (*ptr == '\\' || *ptr == '\'')
overhead++;
if (*ptr == '\'')
overhead += 3;
if (*ptr)
ptr++;
overhead += 3;
}
outptr0 = args[i] = grub_malloc (overhead + (ptr - curarg));
if (!outptr0)
return NULL;
@ -641,9 +641,15 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
*outptr++ = '\'';
for (; *ptr && !grub_isspace (*ptr); ptr++)
{
if (*ptr == '\\' || *ptr == '\'')
*outptr++ = '\\';
*outptr++ = *ptr;
if (*ptr == '\'')
{
*outptr++ = '\'';
*outptr++ = '\\';
*outptr++ = '\'';
*outptr++ = '\'';
}
else
*outptr++ = *ptr;
}
*outptr++ = '\'';
if (*ptr)

View file

@ -25,6 +25,12 @@
#include <grub/dl.h>
#include <grub/crypto.h>
#ifdef GRUB_CPU_WORDS_BIGENDIAN
#define WORDS_BIGENDIAN
#else
#undef WORDS_BIGENDIAN
#endif
#define __GNU_LIBRARY__
#define DIM ARRAY_SIZE

View file

@ -32,4 +32,10 @@ typedef grub_uint16_t uint16_t;
typedef grub_uint32_t uint32_t;
typedef grub_uint64_t uint64_t;
#ifdef GRUB_CPU_WORDS_BIGENDIAN
#define WORDS_BIGENDIAN
#else
#undef WORDS_BIGENDIAN
#endif
#endif

View file

@ -18,6 +18,8 @@
#ifdef TEST
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define xmalloc malloc
#define grub_memset memset
#define grub_memcpy memcpy
@ -25,8 +27,6 @@
#ifndef STANDALONE
#ifdef TEST
#include <string.h>
#include <stdlib.h>
typedef unsigned int grub_size_t;
typedef unsigned char grub_uint8_t;
typedef unsigned short grub_uint16_t;
@ -45,6 +45,7 @@ typedef unsigned char grub_uint8_t;
typedef unsigned short grub_uint16_t;
#else
#include <grub/types.h>
#include <grub/misc.h>
#endif
void
grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs);
@ -59,7 +60,9 @@ typedef grub_uint16_t gf_double_t;
static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000;
static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100;
#else
#if defined (STANDALONE)
static char *scratch;
#endif
static grub_uint8_t gf_invert[256];
#endif
@ -207,11 +210,12 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol)
#ifndef STANDALONE
chosen = xmalloc (n * sizeof (int));
grub_memset (chosen, -1, n * sizeof (int));
#else
chosen = (void *) scratch;
scratch += n;
scratch += n * sizeof (int);
#endif
for (i = 0; i < n; i++)
chosen[i] = -1;
for (i = 0; i < m; i++)
sol[i] = 0;
gauss_eliminate (eq, n, m, chosen);
@ -228,7 +232,7 @@ gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol)
#ifndef STANDALONE
free (chosen);
#else
scratch -= n;
scratch -= n * sizeof (int);
#endif
}
@ -370,6 +374,10 @@ decode_block (gf_single_t *ptr, grub_size_t s,
grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
gf_single_t m[ds + rr];
/* Nothing to do. */
if (!ds || !rr)
continue;
for (j = 0; j < (int) ds; j++)
m[j] = ptr[SECTOR_SIZE * j + i];
for (j = 0; j < (int) rr; j++)
@ -412,6 +420,10 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
gf_single_t *ptr = buffer;
gf_single_t *rptr = ptr + s;
/* Nothing to do. */
if (!rs)
return;
while (s > 0)
{
grub_size_t tt;
@ -421,8 +433,8 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
tt = cs + crs;
if (tt > MAX_BLOCK_SIZE)
{
cs = (cs * MAX_BLOCK_SIZE) / tt;
crs = (crs * MAX_BLOCK_SIZE) / tt;
cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512;
crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512;
}
encode_block (ptr, cs, rptr, crs);
ptr += cs;
@ -439,6 +451,10 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs)
gf_single_t *ptr = ptr_;
gf_single_t *rptr = ptr + s;
/* Nothing to do. */
if (!rs)
return;
#if defined (STANDALONE)
init_inverts ();
#endif
@ -452,8 +468,8 @@ grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs)
tt = cs + crs;
if (tt > MAX_BLOCK_SIZE)
{
cs = cs * MAX_BLOCK_SIZE / tt;
crs = crs * MAX_BLOCK_SIZE / tt;
cs = ((cs * (MAX_BLOCK_SIZE / 512)) / tt) * 512;
crs = ((crs * (MAX_BLOCK_SIZE / 512)) / tt) * 512;
}
decode_block (ptr, cs, rptr, crs);
ptr += cs;
@ -485,14 +501,10 @@ main (int argc, char **argv)
fseek (in, 0, SEEK_END);
s = ftell (in);
fseek (in, 0, SEEK_SET);
rs = 1024 * ((s + MAX_BLOCK_SIZE - 1) / (MAX_BLOCK_SIZE - 1024));
rs = s / 3;
buf = xmalloc (s + rs + SECTOR_SIZE);
fread (buf, 1, s, in);
s = 0x5fbb;
rs = 0x6af9;
#if 0
grub_reed_solomon_add_redundancy (buf, s, rs);
out = fopen ("tst_rs.bin", "wb");
@ -504,9 +516,6 @@ main (int argc, char **argv)
out = fopen ("tst_dam.bin", "wb");
fwrite (buf, 1, s + rs, out);
fclose (out);
#endif
s = 0x5fbb;
rs = 0x6af9;
grub_reed_solomon_recover (buf, s, rs);
out = fopen ("tst_rec.bin", "wb");

View file

@ -597,7 +597,8 @@ malloc_in_range (struct grub_relocator *rel,
events[N].hancestor = pa;
N++;
events[N].type = REG_BEG_END;
events[N].pos = grub_vtop (p + p->size) - sizeof (*r);
events[N].pos = grub_vtop (p + p->size) - sizeof (*r)
- sizeof (struct grub_mm_header);
N++;
}
else

View file

@ -521,6 +521,8 @@ grub_netbsd_list_modules (void)
/* This function would be here but it's under different license. */
#include "bsd_pagetable.c"
static grub_uint32_t freebsd_bootdev, freebsd_biosdev;
static grub_err_t
grub_freebsd_boot (void)
{
@ -528,7 +530,6 @@ grub_freebsd_boot (void)
grub_uint8_t *p, *p0;
grub_addr_t p_target;
grub_size_t p_size = 0;
grub_uint32_t bootdev, biosdev, unit, slice, part;
grub_err_t err;
grub_size_t tag_buf_len = 0;
@ -564,11 +565,7 @@ grub_freebsd_boot (void)
bi.version = FREEBSD_BOOTINFO_VERSION;
bi.length = sizeof (bi);
grub_bsd_get_device (&biosdev, &unit, &slice, &part);
bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) +
(unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT));
bi.boot_device = biosdev;
bi.boot_device = freebsd_biosdev;
p_size = 0;
grub_env_iterate (iterate_env_count);
@ -741,7 +738,7 @@ grub_freebsd_boot (void)
state.ebp = stack_target;
stack[0] = entry; /* "Return" address. */
stack[1] = bootflags | FREEBSD_RB_BOOTINFO;
stack[2] = bootdev;
stack[2] = freebsd_bootdev;
stack[3] = 0;
stack[4] = 0;
stack[5] = 0;
@ -1371,6 +1368,8 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE)
{
grub_uint32_t unit, slice, part;
kern_end = ALIGN_PAGE (kern_end);
if (is_elf_kernel)
{
@ -1414,6 +1413,10 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
if (err)
return err;
}
grub_bsd_get_device (&freebsd_biosdev, &unit, &slice, &part);
freebsd_bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) +
(unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT));
grub_loader_set (grub_freebsd_boot, grub_bsd_unload, 0);
}
@ -1611,7 +1614,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
char *buf = 0, *curr, *next;
int len;
if (kernel_type == KERNEL_TYPE_NONE)
if (! grub_loader_is_loaded ())
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"you need to load the kernel first");
@ -1844,7 +1847,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
grub_file_t file = 0;
grub_err_t err;
if (kernel_type == KERNEL_TYPE_NONE)
if (! grub_loader_is_loaded ())
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"you need to load the kernel first");

View file

@ -511,7 +511,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file,
grub_err_t err;
Elf_Ehdr e;
Elf_Shdr *s;
char *shdr;
char *shdr = NULL;
err = read_headers (file, &e, &shdr);
if (err)

View file

@ -655,7 +655,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
params->type_of_loader = (LINUX_LOADER_ID_GRUB << 4);
params->type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE;
/* These two are used (instead of cmd_line_ptr) by older versions of Linux,
and otherwise ignored. */

View file

@ -141,7 +141,7 @@ grub_multiboot_load (grub_file_t file)
}
if (header->bss_end_addr)
grub_memset ((grub_uint32_t *) source + load_size, 0,
grub_memset ((grub_uint8_t *) source + load_size, 0,
header->bss_end_addr - header->load_addr - load_size);
grub_multiboot_payload_eip = header->entry_addr;
@ -441,7 +441,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
if (err)
return err;
ptrorig = get_virtual_current_address (ch);
ptrdest = (grub_addr_t) get_virtual_current_address (ch);
ptrdest = get_physical_target_address (ch);
*target = ptrdest;
@ -641,6 +641,7 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
return grub_errno;
newmod->start = start;
newmod->size = size;
newmod->next = 0;
for (i = 0; i < argc; i++)
len += grub_strlen (argv[i]) + 1;

View file

@ -91,7 +91,7 @@ grub_linux_load32 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)
/* Linux's entry point incorrectly contains a virtual address. */
entry_addr = elf->ehdr.ehdr32.e_entry;
linux_size = grub_elf32_size (elf, &base);
linux_size = grub_elf32_size (elf, &base, 0);
if (linux_size == 0)
return grub_errno;
target_addr = base;
@ -146,7 +146,7 @@ grub_linux_load64 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)
/* Linux's entry point incorrectly contains a virtual address. */
entry_addr = elf->ehdr.ehdr64.e_entry;
linux_size = grub_elf64_size (elf, &base);
linux_size = grub_elf64_size (elf, &base, 0);
if (linux_size == 0)
return grub_errno;
target_addr = base;

View file

@ -26,6 +26,7 @@
#include <grub/ieee1275/ieee1275.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/memory.h>
#define ELF32_LOADMASK (0xc0000000UL)
#define ELF64_LOADMASK (0xc000000000000000ULL)
@ -45,6 +46,51 @@ static char *linux_args;
typedef void (*kernel_entry_t) (void *, unsigned long, int (void *),
unsigned long, unsigned long);
static grub_addr_t
grub_linux_claimmap_iterate (grub_addr_t target, grub_size_t size,
grub_size_t align)
{
grub_addr_t found_addr = (grub_addr_t) -1;
auto int NESTED_FUNC_ATTR alloc_mem (grub_uint64_t addr, grub_uint64_t len,
grub_memory_type_t type);
int NESTED_FUNC_ATTR alloc_mem (grub_uint64_t addr, grub_uint64_t len,
grub_memory_type_t type)
{
grub_uint64_t end = addr + len;
addr = ALIGN_UP (addr, align);
target = ALIGN_UP (target, align);
/* Target above the memory chunk. */
if (type != GRUB_MEMORY_AVAILABLE || target > end)
return 0;
/* Target inside the memory chunk. */
if (target >= addr && target < end && size <= end - target)
{
if (grub_claimmap (target, size) == GRUB_ERR_NONE)
{
found_addr = target;
return 1;
}
}
/* Target below the memory chunk. */
if (target < addr && addr + size <= end)
{
if (grub_claimmap (addr, size) == GRUB_ERR_NONE)
{
found_addr = addr;
return 1;
}
}
return 0;
}
grub_machine_mmap_iterate (alloc_mem);
return found_addr;
}
static grub_err_t
grub_linux_boot (void)
{
@ -102,34 +148,30 @@ grub_linux_unload (void)
static grub_err_t
grub_linux_load32 (grub_elf_t elf)
{
Elf32_Addr entry;
int found_addr = 0;
Elf32_Addr base_addr;
grub_addr_t seg_addr;
grub_uint32_t align;
int offset;
/* Linux's entry point incorrectly contains a virtual address. */
entry = elf->ehdr.ehdr32.e_entry & ~ELF32_LOADMASK;
if (entry == 0)
entry = 0x01400000;
linux_size = grub_elf32_size (elf, 0);
linux_size = grub_elf32_size (elf, &base_addr, &align);
if (linux_size == 0)
return grub_errno;
/* Pad it; the kernel scribbles over memory beyond its load address. */
linux_size += 0x100000;
offset = elf->ehdr.ehdr32.e_entry - base_addr;
/* Linux's incorrectly contains a virtual address. */
base_addr &= ~ELF32_LOADMASK;
/* On some systems, firmware occupies the memory we're trying to use.
* Happily, Linux can be loaded anywhere (it relocates itself). Iterate
* until we find an open area. */
for (linux_addr = entry; linux_addr < entry + 200 * 0x100000; linux_addr += 0x100000)
{
grub_dprintf ("loader", "Attempting to claim at 0x%x, size 0x%x.\n",
linux_addr, linux_size);
found_addr = grub_claimmap (linux_addr, linux_size);
if (found_addr != -1)
break;
}
if (found_addr == -1)
seg_addr = grub_linux_claimmap_iterate (base_addr & ~ELF32_LOADMASK, linux_size, align);
if (seg_addr == (grub_addr_t) -1)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't claim memory");
linux_addr = seg_addr + offset;
/* Now load the segments into the area we claimed. */
auto grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load);
grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load)
@ -141,9 +183,7 @@ grub_linux_load32 (grub_elf_t elf)
}
*do_load = 1;
/* Linux's program headers incorrectly contain virtual addresses.
* Translate those to physical, and offset to the area we claimed. */
*addr = (phdr->p_paddr & ~ELF32_LOADMASK) + linux_addr;
*addr = (phdr->p_paddr - base_addr) + seg_addr;
return 0;
}
return grub_elf32_load (elf, offset_phdr, 0, 0);
@ -152,34 +192,30 @@ grub_linux_load32 (grub_elf_t elf)
static grub_err_t
grub_linux_load64 (grub_elf_t elf)
{
Elf64_Addr entry;
int found_addr = 0;
Elf64_Addr base_addr;
grub_addr_t seg_addr;
grub_uint64_t align;
int offset;
/* Linux's entry point incorrectly contains a virtual address. */
entry = elf->ehdr.ehdr64.e_entry & ~ELF64_LOADMASK;
if (entry == 0)
entry = 0x01400000;
linux_size = grub_elf64_size (elf, 0);
linux_size = grub_elf64_size (elf, &base_addr, &align);
if (linux_size == 0)
return grub_errno;
/* Pad it; the kernel scribbles over memory beyond its load address. */
linux_size += 0x100000;
offset = elf->ehdr.ehdr64.e_entry - base_addr;
/* Linux's incorrectly contains a virtual address. */
base_addr &= ~ELF64_LOADMASK;
/* On some systems, firmware occupies the memory we're trying to use.
* Happily, Linux can be loaded anywhere (it relocates itself). Iterate
* until we find an open area. */
for (linux_addr = entry; linux_addr < entry + 200 * 0x100000; linux_addr += 0x100000)
{
grub_dprintf ("loader", "Attempting to claim at 0x%x, size 0x%x.\n",
linux_addr, linux_size);
found_addr = grub_claimmap (linux_addr, linux_size);
if (found_addr != -1)
break;
}
if (found_addr == -1)
seg_addr = grub_linux_claimmap_iterate (base_addr & ~ELF64_LOADMASK, linux_size, align);
if (seg_addr == (grub_addr_t) -1)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't claim memory");
linux_addr = seg_addr + offset;
/* Now load the segments into the area we claimed. */
auto grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load);
grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load)
@ -190,9 +226,8 @@ grub_linux_load64 (grub_elf_t elf)
return 0;
}
*do_load = 1;
/* Linux's program headers incorrectly contain virtual addresses.
* Translate those to physical, and offset to the area we claimed. */
*addr = (phdr->p_paddr & ~ELF64_LOADMASK) + linux_addr;
*addr = (phdr->p_paddr - base_addr) + seg_addr;
return 0;
}
return grub_elf64_load (elf, offset_phdr, 0, 0);
@ -287,7 +322,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
grub_ssize_t size;
grub_addr_t first_addr;
grub_addr_t addr;
int found_addr = 0;
if (argc == 0)
{
@ -311,20 +345,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
/* Attempt to claim at a series of addresses until successful in
the same way that grub_rescue_cmd_linux does. */
for (addr = first_addr; addr < first_addr + 200 * 0x100000; addr += 0x100000)
{
grub_dprintf ("loader", "Attempting to claim at 0x%x, size 0x%x.\n",
addr, size);
found_addr = grub_claimmap (addr, size);
if (found_addr != -1)
break;
}
if (found_addr == -1)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot claim memory");
goto fail;
}
addr = grub_linux_claimmap_iterate (first_addr, size, 0x100000);
if (addr == (grub_addr_t) -1)
goto fail;
grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size);

View file

@ -247,7 +247,7 @@ grub_linux_load64 (grub_elf_t elf)
linux_entry = elf->ehdr.ehdr64.e_entry;
linux_addr = 0x40004000;
off = 0x4000;
linux_size = grub_elf64_size (elf, 0);
linux_size = grub_elf64_size (elf, 0, 0);
if (linux_size == 0)
return grub_errno;

View file

@ -34,6 +34,10 @@
#include <grub/env.h>
#include <grub/i18n.h>
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
#include <grub/autoefi.h>
#endif
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
static int driversnum = 0;
@ -424,6 +428,12 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
if (ptr != grub_xnu_cmdline)
*(ptr - 1) = 0;
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
err = grub_efiemu_autocore ();
if (err)
return err;
#endif
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
grub_xnu_lock ();
@ -529,6 +539,12 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
if (ptr != grub_xnu_cmdline)
*(ptr - 1) = 0;
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
err = grub_efiemu_autocore ();
if (err)
return err;
#endif
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
grub_xnu_lock ();
@ -1198,6 +1214,10 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_file_t binfile = 0;
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
if (argc == 2)
{
/* User explicitly specified plist and binary. */
@ -1229,6 +1249,9 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)),
if (argc != 1 && argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory name required");
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
if (argc == 1)
return grub_xnu_scan_dir_for_kexts (args[0],
"console,root,local-root,network-root",
@ -1370,6 +1393,9 @@ grub_cmd_xnu_splash (grub_extcmd_context_t ctxt,
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
if (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].set &&
grub_strcmp (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].arg,
"stretch") == 0)

View file

@ -113,16 +113,6 @@ grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
count = 3;
code = c & GRUB_UINT8_3_TRAILINGBITS;
}
else if ((c & GRUB_UINT8_6_LEADINGBITS) == GRUB_UINT8_5_LEADINGBITS)
{
count = 4;
code = c & GRUB_UINT8_2_TRAILINGBITS;
}
else if ((c & GRUB_UINT8_7_LEADINGBITS) == GRUB_UINT8_6_LEADINGBITS)
{
count = 5;
code = c & GRUB_UINT8_1_TRAILINGBIT;
}
else
return -1;
}
@ -177,7 +167,7 @@ grub_ucs4_to_utf8 (grub_uint32_t *src, grub_size_t size,
/* No surrogates in UCS-4... */
*dest++ = '?';
}
else
else if (code < 0x10000)
{
if (dest + 2 >= destend)
break;
@ -185,6 +175,15 @@ grub_ucs4_to_utf8 (grub_uint32_t *src, grub_size_t size,
*dest++ = ((code >> 6) & 0x3F) | 0x80;
*dest++ = (code & 0x3F) | 0x80;
}
else
{
if (dest + 3 >= destend)
break;
*dest++ = (code >> 18) | 0xF0;
*dest++ = ((code >> 12) & 0x3F) | 0x80;
*dest++ = ((code >> 6) & 0x3F) | 0x80;
*dest++ = (code & 0x3F) | 0x80;
}
}
*dest = 0;
}
@ -212,8 +211,10 @@ grub_ucs4_to_utf8_alloc (grub_uint32_t *src, grub_size_t size)
|| (code >= 0xD800 && code <= 0xDBFF))
/* No surrogates in UCS-4... */
cnt++;
else
else if (code < 0x10000)
cnt += 3;
else
cnt += 4;
}
cnt++;
@ -273,16 +274,6 @@ grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize)
count = 3;
code = c & 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
count = 4;
code = c & 0x03;
}
else if ((c & 0xfe) == 0xfc)
{
count = 5;
code = c & 0x01;
}
else
return 0;
}
@ -375,16 +366,6 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
count = 3;
code = c & 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
count = 4;
code = c & 0x03;
}
else if ((c & 0xfe) == 0xfc)
{
count = 5;
code = c & 0x01;
}
else
{
/* invalid */

View file

@ -172,7 +172,7 @@ static void
print_up (int flag, struct per_term_screen *term_screen)
{
grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X
+ grub_term_entry_width (term_screen->term),
+ grub_term_border_width (term_screen->term),
GRUB_TERM_FIRST_ENTRY_Y);
if (flag)
@ -1163,37 +1163,35 @@ clear_completions_all (struct screen *screen)
static int
run (struct screen *screen)
{
int currline = 0;
char *nextline;
char *script;
int errs_before;
grub_menu_t menu;
char *dummy[1] = { NULL };
auto grub_err_t editor_getline (char **line, int cont);
grub_err_t editor_getline (char **line, int cont __attribute__ ((unused)))
{
struct line *linep = screen->lines + currline;
char *p;
auto char * editor_getsource (void);
char * editor_getsource (void)
{
int i;
int size = 0;
char *source;
if (currline > screen->num_lines)
{
*line = 0;
return 0;
}
for (i = 0; i < screen->num_lines; i++)
size += screen->lines[i].len + 1;
/* Trim down space characters. */
for (p = linep->buf + linep->len - 1;
p >= linep->buf && grub_isspace (*p);
p--)
;
*++p = '\0';
source = grub_malloc (size + 1);
if (! source)
return NULL;
linep->len = p - linep->buf;
for (p = linep->buf; grub_isspace (*p); p++)
;
*line = grub_strdup (p);
currline++;
return 0;
}
size = 0;
for (i = 0; i < screen->num_lines; i++)
{
grub_strcpy (source + size, screen->lines[i].buf);
size += screen->lines[i].len;
source[size++] = '\n';
}
source[size] = '\0';
return source;
}
grub_cls ();
grub_printf (" ");
@ -1212,12 +1210,11 @@ run (struct screen *screen)
}
/* Execute the script, line for line. */
while (currline < screen->num_lines)
{
editor_getline (&nextline, 0);
if (grub_normal_parse_line (nextline, editor_getline))
break;
}
script = editor_getsource ();
if (! script)
return 0;
grub_script_execute_sourcecode (script, 0, dummy);
grub_free (script);
if (errs_before != grub_err_printed_errors)
grub_wait_after_message ();

View file

@ -91,16 +91,16 @@ print_more (void)
grub_term_restore_pos (pos);
grub_free (pos);
/* Scroll one lines or an entire page, depending on the key. */
/* Scroll one line or an entire page, depending on the key. */
if (key == '\r' || key =='\n')
grub_normal_reset_more ();
else
{
static struct term_state *state;
for (state = term_states; state; state = state->next)
state->num_lines -= 2;
state->num_lines--;
}
else
grub_normal_reset_more ();
}
void

View file

@ -27,6 +27,7 @@ struct grub_amiga_rdsk
{
/* "RDSK". */
grub_uint8_t magic[4];
#define GRUB_AMIGA_RDSK_MAGIC "RDSK"
grub_uint32_t size;
grub_int32_t checksum;
grub_uint32_t scsihost;
@ -43,6 +44,7 @@ struct grub_amiga_partition
{
/* "PART". */
grub_uint8_t magic[4];
#define GRUB_AMIGA_PART_MAGIC "PART"
grub_int32_t size;
grub_int32_t checksum;
grub_uint32_t scsihost;
@ -87,7 +89,8 @@ amiga_partition_map_iterate (grub_disk_t disk,
if (grub_disk_read (disk, pos, 0, sizeof (rdsk), &rdsk))
return grub_errno;
if (grub_strcmp ((char *) rdsk.magic, "RDSK") == 0)
if (grub_memcmp (rdsk.magic, GRUB_AMIGA_RDSK_MAGIC,
sizeof (rdsk.magic)) == 0)
{
/* Found the first PART block. */
next = grub_be_to_cpu32 (rdsk.partitionlst);
@ -108,6 +111,9 @@ amiga_partition_map_iterate (grub_disk_t disk,
if (grub_disk_read (disk, next, 0, sizeof (apart), &apart))
return grub_errno;
if (grub_memcmp (apart.magic, GRUB_AMIGA_PART_MAGIC,
sizeof (apart.magic)) == 0)
/* Calculate the first block and the size of the partition. */
part.start = (grub_be_to_cpu32 (apart.lowcyl)
* grub_be_to_cpu32 (apart.heads)

View file

@ -257,6 +257,8 @@ grub_keyboard_controller_write (grub_uint8_t c)
grub_outb (c, KEYBOARD_REG_DATA);
}
#if !defined (GRUB_MACHINE_MIPS_YEELOONG) && !defined (GRUB_MACHINE_QEMU)
static grub_uint8_t
grub_keyboard_controller_read (void)
{
@ -265,6 +267,8 @@ grub_keyboard_controller_read (void)
return grub_inb (KEYBOARD_REG_DATA);
}
#endif
static int
write_mode (int mode)
{
@ -558,8 +562,13 @@ grub_keyboard_controller_init (struct grub_term_input *term __attribute__ ((unus
keyboard_controller_wait_until_ready ();
grub_inb (KEYBOARD_REG_DATA);
}
#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_QEMU)
grub_keyboard_controller_orig = 0;
grub_keyboard_orig_set = 2;
#else
grub_keyboard_controller_orig = grub_keyboard_controller_read ();
grub_keyboard_orig_set = query_mode ();
#endif
set_scancodes ();
keyboard_controller_led (led_status);

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007, 2008 Free Software Foundation, Inc.
* Copyright (C) 2007, 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
@ -27,18 +27,18 @@
static int grub_curr_x, grub_curr_y;
#define VGA_TEXT_SCREEN 0xb8000
#define VGA_TEXT_SCREEN ((grub_uint16_t *) 0xb8000)
static void
screen_write_char (int x, int y, short c)
{
((short *) VGA_TEXT_SCREEN)[y * COLS + x] = c;
VGA_TEXT_SCREEN[y * COLS + x] = c;
}
static short
screen_read_char (int x, int y)
{
return ((short *) VGA_TEXT_SCREEN)[y * COLS + x];
return VGA_TEXT_SCREEN[y * COLS + x];
}
static void
@ -120,7 +120,7 @@ grub_vga_text_cls (struct grub_term_output *term)
{
int i;
for (i = 0; i < ROWS * COLS; i++)
((short *) VGA_TEXT_SCREEN)[i] = ' ' | (grub_console_cur_color << 8);
VGA_TEXT_SCREEN[i] = ' ' | (grub_console_cur_color << 8);
grub_vga_text_gotoxy (term, 0, 0);
}