merge with mainline

This commit is contained in:
BVK Chaitanya 2010-07-22 22:39:42 +05:30
commit a281e2e80a
18 changed files with 654 additions and 163 deletions

View file

@ -1,5 +1,6 @@
00_header 00_header
10_* 10_*
20_linux_xen
30_os-prober 30_os-prober
40_custom 40_custom
41_custom 41_custom

130
ChangeLog
View file

@ -1,3 +1,133 @@
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* bus/usb/emu/usb.c (grub_usb_poll_devices): Add a dummy
implementation of this so that grub-emu links again, with a note
that this should support hotplugging in the future.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* kern/emu/getroot.c (grub_util_get_grub_dev): Use xasprintf.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* disk/loopback.c (grub_cmd_loopback): Don't leak a grub_file_t
handle on failure.
(grub_loopback_close): Remove empty function.
(grub_loopback_dev): Remove close method.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
Disable EFI cursor when the EFI console becomes inactive.
* term/efi/console.c (grub_efi_console_init): New function.
(grub_efi_console_fini): New function.
(grub_console_term_output): Register init and fini methods.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell-tester.in: Remove bashism and declare as
sh script.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* disk/loopback.c (grub_loopback): Replace filename with file.
(delete_loopback): Handle new semantics.
(grub_cmd_loopback): Likewise.
(grub_loopback_iterate): Likewise.
(grub_loopback_close): Likewise.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* util/i386/efi/grub-install.in: Revert to platform-specific behaviour
with -p "".
Reported by: Tito Keitel.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* docs/grub.texi (Naming convention): Document new naming convention.
2010-07-20 Vadim Solomin <vadic052@gmail.com>
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
Generate device.map in something closer to the old ordering.
* util/deviceiter.c (struct device): New declaration.
(compare_file_names): Rename to ...
(compare_devices): ... this. Sort by kernel name in preference to
the stable by-id name, but keep the latter as a fallback comparison.
Update header comment.
(grub_util_iterate_devices) [__linux__]: Construct and sort an array
of `struct device' rather than of plain file names.
2010-07-20 Thomas Frauendorfer <Thomas.Frauendorfer@googlemail.com>
* lib/i386/relocator_asm.S [! __x86_64__]: Don't try to disable amd64
on i386.
2010-07-20 Vladimir Serbinenko <phcoder@gmail.com>
* commands/acpi.c (setup_common_tables): Use sizeof instead of
hardcoding size.
(setv1table): Likewise.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* disk/raid.c (insert_array): Use md/%s to name mdadm 1.x devices,
removing the homehost if present.
* kern/emu/getroot.c (get_mdadm_name) [__linux__]: New function.
(grub_util_get_grub_dev): Use md/%s to name mdadm 1.x devices,
removing the homehost if present.
(grub_util_get_grub_dev) [__linux__]: Get the array name from mdadm
if possible.
* util/i386/pc/grub-setup.c (main): Handle md/* devices.
* disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Add start_sector
parameter. Set its pointer target to 0.
* disk/mdraid_linux.c (grub_mdraid_detect): Add start_sector
parameter. Set its pointer target to 0 for 0.9 metadata, or to the
`data_offset' value from the superblock for 1.x metadata.
* disk/raid.c (grub_raid_read): Offset reads by the start sector of
data on the device.
(insert_array): Record the start sector of data on the device.
(grub_raid_register): Pass start_sector parameters to
grub_raid_list->detect and insert_array.
* include/grub/raid.h (struct grub_raid_array): Add start_sector
member.
(struct grub_raid): Add start_sector parameter to `detect'.
* disk/mdraid_linux.c (struct grub_raid_super_1x): Remove
__attribute__ ((packed)), leaving a comment.
(grub_mdraid_detect): Split out 0.9 and 1.x detection to ...
(grub_mdraid_detect_09): ... here and ...
(grub_mdraid_detect_1x): ... here.
2010-07-20 Peter Henn <peter.henn@web.de>
* disk/mdraid_linux.c (grub_mdraid_detect): Fix calculation of 1.x
chunk size and disk size, which are already given as sector counts
as distinct from the 0.90 units. Fetch the correct device number
from the role table instead of using the table index.
2010-07-20 Felix Zielcke <fzielcke@z-51.de>
* disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Set array->name to NULL.
* disk/mdraid_linux.c (grub_raid_super_1x): New structure.
(WriteMostly1): New macro.
Set array->name to NULL for metadata format 0.90. Add support for
metadata 1.x. Fix some comments.
* disk/raid.c (): Add support for name based RAID arrays. Fix a
few comments.
* util/getroot.c (grub_util_get_grub_dev): Add support for
/dev/md/name style devices.
2010-07-20 Colin Watson <cjwatson@ubuntu.com>
* .bzrignore: Ignore 20_linux_xen.
2010-07-17 Colin Watson <cjwatson@ubuntu.com>
* util/import_unicode.py: Remove unnecessary imports.
2010-07-17 Aleš Nesrsta <starous@volny.cz> 2010-07-17 Aleš Nesrsta <starous@volny.cz>
Hotplugging and USB hub support. Hotplugging and USB hub support.

View file

@ -78,6 +78,12 @@ grub_libusb_devices (void)
return GRUB_USB_ERR_NONE; return GRUB_USB_ERR_NONE;
} }
void
grub_usb_poll_devices (void)
{
/* TODO: recheck grub_usb_devs */
}
int int
grub_usb_iterate (int (*hook) (grub_usb_device_t dev)) grub_usb_iterate (int (*hook) (grub_usb_device_t dev))

View file

@ -325,7 +325,8 @@ setup_common_tables (void)
/* If it's FADT correct DSDT and FACS addresses. */ /* If it's FADT correct DSDT and FACS addresses. */
fadt = (struct grub_acpi_fadt *) cur->addr; fadt = (struct grub_acpi_fadt *) cur->addr;
if (grub_memcmp (fadt->hdr.signature, "FACP", 4) == 0) if (grub_memcmp (fadt->hdr.signature, "FACP",
sizeof (fadt->hdr.signature)) == 0)
{ {
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt); fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
fadt->facs_addr = facs_addr; fadt->facs_addr = facs_addr;
@ -351,16 +352,16 @@ setup_common_tables (void)
rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr; rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables; playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt_entry = (grub_uint32_t *)(rsdt + 1); rsdt_entry = (grub_uint32_t *) (rsdt + 1);
/* Fill RSDT header. */ /* Fill RSDT header. */
grub_memcpy (&(rsdt->signature), "RSDT", 4); grub_memcpy (&(rsdt->signature), "RSDT", 4);
rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables; rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt->revision = 1; rsdt->revision = 1;
grub_memcpy (&(rsdt->oemid), root_oemid, 6); grub_memcpy (&(rsdt->oemid), root_oemid, sizeof (rsdt->oemid));
grub_memcpy (&(rsdt->oemtable), root_oemtable, 4); grub_memcpy (&(rsdt->oemtable), root_oemtable, sizeof (rsdt->oemtable));
rsdt->oemrev = root_oemrev; rsdt->oemrev = root_oemrev;
grub_memcpy (&(rsdt->creator_id), root_creator_id, 6); grub_memcpy (&(rsdt->creator_id), root_creator_id, sizeof (rsdt->creator_id));
rsdt->creator_rev = root_creator_rev; rsdt->creator_rev = root_creator_rev;
for (cur = acpi_tables; cur; cur = cur->next) for (cur = acpi_tables; cur; cur = cur->next)
@ -378,7 +379,8 @@ setv1table (void)
/* Create RSDP. */ /* Create RSDP. */
rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr; rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v10); playground_ptr += sizeof (struct grub_acpi_rsdp_v10);
grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ", 8); grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ",
sizeof (rsdpv1_new->signature));
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid)); grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
rsdpv1_new->revision = 0; rsdpv1_new->revision = 0;
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr); rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);

View file

@ -89,7 +89,8 @@ struct grub_nv_super
} __attribute__ ((packed)); } __attribute__ ((packed));
static grub_err_t static grub_err_t
grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array) grub_dmraid_nv_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;
struct grub_nv_super sb; struct grub_nv_super sb;
@ -132,6 +133,7 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
"unsupported RAID level: %d", sb.array.raid_level); "unsupported RAID level: %d", sb.array.raid_level);
} }
array->name = NULL;
array->number = 0; array->number = 0;
array->total_devs = sb.array.total_volumes; array->total_devs = sb.array.total_volumes;
array->chunk_size = sb.array.stripe_block_size; array->chunk_size = sb.array.stripe_block_size;
@ -144,6 +146,8 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
grub_memcpy (array->uuid, (char *) &sb.array.signature, grub_memcpy (array->uuid, (char *) &sb.array.signature,
sizeof (sb.array.signature)); sizeof (sb.array.signature));
*start_sector = 0;
return 0; return 0;
} }

View file

@ -28,7 +28,7 @@
struct grub_loopback struct grub_loopback
{ {
char *devname; char *devname;
char *filename; grub_file_t file;
int has_partitions; int has_partitions;
struct grub_loopback *next; struct grub_loopback *next;
}; };
@ -63,7 +63,7 @@ delete_loopback (const char *name)
*prev = dev->next; *prev = dev->next;
grub_free (dev->devname); grub_free (dev->devname);
grub_free (dev->filename); grub_file_close (dev->file);
grub_free (dev); grub_free (dev);
return 0; return 0;
@ -76,6 +76,7 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
struct grub_arg_list *state = ctxt->state; struct grub_arg_list *state = ctxt->state;
grub_file_t file; grub_file_t file;
struct grub_loopback *newdev; struct grub_loopback *newdev;
grub_err_t ret;
if (argc < 1) if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
@ -91,9 +92,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
if (! file) if (! file)
return grub_errno; return grub_errno;
/* Close the file, the only reason for opening it is validation. */
grub_file_close (file);
/* First try to replace the old device. */ /* First try to replace the old device. */
for (newdev = loopback_list; newdev; newdev = newdev->next) for (newdev = loopback_list; newdev; newdev = newdev->next)
if (grub_strcmp (newdev->devname, args[0]) == 0) if (grub_strcmp (newdev->devname, args[0]) == 0)
@ -103,10 +101,10 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
{ {
char *newname = grub_strdup (args[1]); char *newname = grub_strdup (args[1]);
if (! newname) if (! newname)
return grub_errno; goto fail;
grub_free (newdev->filename); grub_file_close (newdev->file);
newdev->filename = newname; newdev->file = file;
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
@ -117,22 +115,16 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
/* Unable to replace it, make a new entry. */ /* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback)); newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev) if (! newdev)
return grub_errno; goto fail;
newdev->devname = grub_strdup (args[0]); newdev->devname = grub_strdup (args[0]);
if (! newdev->devname) if (! newdev->devname)
{ {
grub_free (newdev); grub_free (newdev);
return grub_errno; goto fail;
} }
newdev->filename = grub_strdup (args[1]); newdev->file = file;
if (! newdev->filename)
{
grub_free (newdev->devname);
grub_free (newdev);
return grub_errno;
}
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
@ -142,6 +134,11 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
loopback_list = newdev; loopback_list = newdev;
return 0; return 0;
fail:
ret = grub_errno;
grub_file_close (file);
return ret;
} }
@ -160,7 +157,6 @@ grub_loopback_iterate (int (*hook) (const char *name))
static grub_err_t static grub_err_t
grub_loopback_open (const char *name, grub_disk_t disk) grub_loopback_open (const char *name, grub_disk_t disk)
{ {
grub_file_t file;
struct grub_loopback *dev; struct grub_loopback *dev;
for (dev = loopback_list; dev; dev = dev->next) for (dev = loopback_list; dev; dev = dev->next)
@ -170,29 +166,17 @@ grub_loopback_open (const char *name, grub_disk_t disk)
if (! dev) if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
file = grub_file_open (dev->filename);
if (! file)
return grub_errno;
/* Use the filesize for the disk size, round up to a complete sector. */ /* Use the filesize for the disk size, round up to a complete sector. */
disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1) disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1)
/ GRUB_DISK_SECTOR_SIZE); / GRUB_DISK_SECTOR_SIZE);
disk->id = (unsigned long) dev; disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions; disk->has_partitions = dev->has_partitions;
disk->data = file; disk->data = dev->file;
return 0; return 0;
} }
static void
grub_loopback_close (grub_disk_t disk)
{
grub_file_t file = (grub_file_t) disk->data;
grub_file_close (file);
}
static grub_err_t static grub_err_t
grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector, grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf) grub_size_t size, char *buf)
@ -234,7 +218,6 @@ static struct grub_disk_dev grub_loopback_dev =
.id = GRUB_DISK_DEVICE_LOOPBACK_ID, .id = GRUB_DISK_DEVICE_LOOPBACK_ID,
.iterate = grub_loopback_iterate, .iterate = grub_loopback_iterate,
.open = grub_loopback_open, .open = grub_loopback_open,
.close = grub_loopback_close,
.read = grub_loopback_read, .read = grub_loopback_read,
.write = grub_loopback_write, .write = grub_loopback_write,
.next = 0 .next = 0

View file

@ -1,7 +1,7 @@
/* mdraid_linux.c - module to handle linux softraid. */ /* mdraid_linux.c - module to handle Linux Software RAID. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc. * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -159,63 +159,254 @@ struct grub_raid_super_09
struct grub_raid_disk_09 this_disk; struct grub_raid_disk_09 this_disk;
} __attribute__ ((packed)); } __attribute__ ((packed));
static grub_err_t /*
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) * The version-1 superblock :
* All numeric fields are little-endian.
*
* Total size: 256 bytes plus 2 per device.
* 1K allows 384 devices.
*/
struct grub_raid_super_1x
{
/* Constant array information - 128 bytes. */
grub_uint32_t magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian. */
grub_uint32_t major_version; /* 1. */
grub_uint32_t feature_map; /* Bit 0 set if 'bitmap_offset' is meaningful. */
grub_uint32_t pad0; /* Always set to 0 when writing. */
grub_uint8_t set_uuid[16]; /* User-space generated. */
char set_name[32]; /* Set and interpreted by user-space. */
grub_uint64_t ctime; /* Lo 40 bits are seconds, top 24 are microseconds or 0. */
grub_uint32_t level; /* -4 (multipath), -1 (linear), 0,1,4,5. */
grub_uint32_t layout; /* only for raid5 and raid10 currently. */
grub_uint64_t size; /* Used size of component devices, in 512byte sectors. */
grub_uint32_t chunksize; /* In 512byte sectors. */
grub_uint32_t raid_disks;
grub_uint32_t bitmap_offset; /* Sectors after start of superblock that bitmap starts
* NOTE: signed, so bitmap can be before superblock
* only meaningful of feature_map[0] is set.
*/
/* These are only valid with feature bit '4'. */
grub_uint32_t new_level; /* New level we are reshaping to. */
grub_uint64_t reshape_position; /* Next address in array-space for reshape. */
grub_uint32_t delta_disks; /* Change in number of raid_disks. */
grub_uint32_t new_layout; /* New layout. */
grub_uint32_t new_chunk; /* New chunk size (512byte sectors). */
grub_uint8_t pad1[128 - 124]; /* Set to 0 when written. */
/* Constant this-device information - 64 bytes. */
grub_uint64_t data_offset; /* Sector start of data, often 0. */
grub_uint64_t data_size; /* Sectors in this device that can be used for data. */
grub_uint64_t super_offset; /* Sector start of this superblock. */
grub_uint64_t recovery_offset; /* Sectors before this offset (from data_offset) have been recovered. */
grub_uint32_t dev_number; /* Permanent identifier of this device - not role in raid. */
grub_uint32_t cnt_corrected_read; /* Number of read errors that were corrected by re-writing. */
grub_uint8_t device_uuid[16]; /* User-space setable, ignored by kernel. */
grub_uint8_t devflags; /* Per-device flags. Only one defined... */
grub_uint8_t pad2[64 - 57]; /* Set to 0 when writing. */
/* Array state information - 64 bytes. */
grub_uint64_t utime; /* 40 bits second, 24 btes microseconds. */
grub_uint64_t events; /* Incremented when superblock updated. */
grub_uint64_t resync_offset; /* Data before this offset (from data_offset) known to be in sync. */
grub_uint32_t sb_csum; /* Checksum upto devs[max_dev]. */
grub_uint32_t max_dev; /* Size of devs[] array to consider. */
grub_uint8_t pad3[64 - 32]; /* Set to 0 when writing. */
/* Device state information. Indexed by dev_number.
* 2 bytes per device.
* Note there are no per-device state flags. State information is rolled
* into the 'roles' value. If a device is spare or faulty, then it doesn't
* have a meaningful role.
*/
grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */
};
/* Could be __attribute__ ((packed)), but since all members in this struct
are already appropriately aligned, we can omit this and avoid suboptimal
assembly in some cases. */
#define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */
static grub_err_t
grub_mdraid_detect_09 (grub_disk_addr_t sector,
struct grub_raid_super_09 *sb,
struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{ {
grub_disk_addr_t sector;
grub_uint64_t size;
struct grub_raid_super_09 sb;
grub_uint32_t *uuid; grub_uint32_t *uuid;
/* The sector where the RAID superblock is stored, if available. */ if (sb->major_version != 0 || sb->minor_version != 90)
size = grub_disk_get_size (disk);
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
return grub_errno;
/* Look whether there is a RAID superblock. */
if (sb.md_magic != SB_MAGIC)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
/* FIXME: Also support version 1.0. */
if (sb.major_version != 0 || sb.minor_version != 90)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID version: %d.%d", "unsupported RAID version: %d.%d",
sb.major_version, sb.minor_version); sb->major_version, sb->minor_version);
/* FIXME: Check the checksum. */ /* FIXME: Check the checksum. */
/* Multipath. */ /* Multipath. */
if ((int) sb.level == -4) if ((int) sb->level == -4)
sb.level = 1; sb->level = 1;
if (sb.level != 0 && sb.level != 1 && sb.level != 4 && if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
sb.level != 5 && sb.level != 6 && sb.level != 10) sb->level != 5 && sb->level != 6 && sb->level != 10)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID level: %d", sb.level); "unsupported RAID level: %d", sb->level);
array->number = sb.md_minor; array->name = NULL;
array->level = sb.level; array->number = sb->md_minor;
array->layout = sb.layout; array->level = sb->level;
array->total_devs = sb.raid_disks; array->layout = sb->layout;
array->disk_size = (sb.size) ? sb.size * 2 : sector; array->total_devs = sb->raid_disks;
array->chunk_size = sb.chunk_size >> 9; array->disk_size = (sb->size) ? sb->size * 2 : sector;
array->index = sb.this_disk.number; array->chunk_size = sb->chunk_size >> 9;
array->index = sb->this_disk.number;
array->uuid_len = 16; array->uuid_len = 16;
array->uuid = grub_malloc (16); array->uuid = grub_malloc (16);
if (!array->uuid) if (!array->uuid)
return grub_errno; return grub_errno;
uuid = (grub_uint32_t *) array->uuid; uuid = (grub_uint32_t *) array->uuid;
uuid[0] = sb.set_uuid0; uuid[0] = sb->set_uuid0;
uuid[1] = sb.set_uuid1; uuid[1] = sb->set_uuid1;
uuid[2] = sb.set_uuid2; uuid[2] = sb->set_uuid2;
uuid[3] = sb.set_uuid3; uuid[3] = sb->set_uuid3;
*start_sector = 0;
return 0; return 0;
} }
static grub_err_t
grub_mdraid_detect_1x (grub_disk_t disk, grub_disk_addr_t sector,
struct grub_raid_super_1x *sb,
struct grub_raid_array *array,
grub_disk_addr_t *start_sector)
{
grub_uint64_t sb_size;
struct grub_raid_super_1x *real_sb;
if (sb->major_version != 1)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unsupported RAID version: %d",
sb->major_version);
/* Multipath. */
if ((int) sb->level == -4)
sb->level = 1;
if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
sb->level != 5 && sb->level != 6 && sb->level != 10)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unsupported RAID level: %d", sb->level);
/* 1.x superblocks don't have a fixed size on disk. So we have to
read it again now that we now the max device count. */
sb_size = sizeof (struct grub_raid_super_1x) + 2 * grub_le_to_cpu32 (sb->max_dev);
real_sb = grub_malloc (sb_size);
if (! real_sb)
return grub_errno;
if (grub_disk_read (disk, sector, 0, sb_size, real_sb))
{
grub_free (real_sb);
return grub_errno;
}
array->name = grub_strdup (real_sb->set_name);
if (! array->name)
{
grub_free (real_sb);
return grub_errno;
}
array->number = 0;
array->level = grub_le_to_cpu32 (real_sb->level);
array->layout = grub_le_to_cpu32 (real_sb->layout);
array->total_devs = grub_le_to_cpu32 (real_sb->raid_disks);
array->disk_size = grub_le_to_cpu64 (real_sb->size);
array->chunk_size = grub_le_to_cpu32 (real_sb->chunksize);
if (grub_le_to_cpu32 (real_sb->dev_number) <
grub_le_to_cpu32 (real_sb->max_dev))
array->index = grub_le_to_cpu16
(real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]);
else
array->index = 0xffff; /* disk will be later not used! */
array->uuid_len = 16;
array->uuid = grub_malloc (16);
if (!array->uuid)
{
grub_free (real_sb);
return grub_errno;
}
grub_memcpy (array->uuid, real_sb->set_uuid, 16);
*start_sector = real_sb->data_offset;
grub_free (real_sb);
return 0;
}
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_uint64_t size;
struct grub_raid_super_09 sb_09;
struct grub_raid_super_1x sb_1x;
grub_uint8_t minor_version;
/* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk);
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb_09))
return grub_errno;
/* Look whether there is a mdraid 0.90 superblock. */
if (sb_09.md_magic == SB_MAGIC)
return grub_mdraid_detect_09 (sector, &sb_09, array, start_sector);
/* Check for an 1.x superblock.
* It's always aligned to a 4K boundary
* and depending on the minor version it can be:
* 0: At least 8K, but less than 12K, from end of device
* 1: At start of device
* 2: 4K from start of device.
*/
for (minor_version = 0; minor_version < 3; ++minor_version)
{
switch (minor_version)
{
case 0:
sector = (size - 8 * 2) & ~(4 * 2 - 1);
break;
case 1:
sector = 0;
break;
case 2:
sector = 4 * 2;
break;
}
if (grub_disk_read (disk, sector, 0, sizeof (struct grub_raid_super_1x),
&sb_1x))
return grub_errno;
if (sb_1x.magic == SB_MAGIC)
return grub_mdraid_detect_1x (disk, sector, &sb_1x, array,
start_sector);
}
/* Neither 0.90 nor 1.x. */
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
}
static struct grub_raid grub_mdraid_dev = { static struct grub_raid grub_mdraid_dev = {
.name = "mdraid", .name = "mdraid",
.detect = grub_mdraid_detect, .detect = grub_mdraid_detect,

View file

@ -1,7 +1,7 @@
/* raid.c - module to read RAID arrays. */ /* raid.c - module to read RAID arrays. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -254,7 +254,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[k], err = grub_disk_read (array->device[k],
read_sector + j * far_ofs + b, array->start_sector[k] +
read_sector + j * far_ofs + b,
0, 0,
read_size << GRUB_DISK_SECTOR_BITS, read_size << GRUB_DISK_SECTOR_BITS,
buf); buf);
@ -366,7 +367,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[disknr], err = grub_disk_read (array->device[disknr],
read_sector + b, 0, array->start_sector[disknr] +
read_sector + b, 0,
read_size << GRUB_DISK_SECTOR_BITS, read_size << GRUB_DISK_SECTOR_BITS,
buf); buf);
@ -475,12 +477,12 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)),
static grub_err_t static grub_err_t
insert_array (grub_disk_t disk, struct grub_raid_array *new_array, insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
const char *scanner_name) grub_disk_addr_t start_sector, const char *scanner_name)
{ {
struct grub_raid_array *array = 0, *p; struct grub_raid_array *array = 0, *p;
/* See whether the device is part of an array we have already seen a /* See whether the device is part of an array we have already seen a
device from. */ device from. */
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
if ((p->uuid_len == new_array->uuid_len) && if ((p->uuid_len == new_array->uuid_len) &&
(! grub_memcmp (p->uuid, new_array->uuid, p->uuid_len))) (! grub_memcmp (p->uuid, new_array->uuid, p->uuid_len)))
@ -491,7 +493,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
/* Do some checks before adding the device to the array. */ /* Do some checks before adding the device to the array. */
/* FIXME: Check whether the update time of the superblocks are /* FIXME: Check whether the update time of the superblocks are
the same. */ the same. */
if (array->total_devs == array->nr_devs) if (array->total_devs == array->nr_devs)
/* We found more members of the array than the array /* We found more members of the array than the array
@ -502,7 +504,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
if (array->device[new_array->index] != NULL) if (array->device[new_array->index] != NULL)
/* We found multiple devices with the same number. Again, /* We found multiple devices with the same number. Again,
this shouldn't happen.*/ this shouldn't happen. */
grub_dprintf ("raid", "Found two disks with the number %d?!?", grub_dprintf ("raid", "Found two disks with the number %d?!?",
new_array->number); new_array->number);
@ -524,46 +526,72 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
*array = *new_array; *array = *new_array;
array->nr_devs = 0; array->nr_devs = 0;
grub_memset (&array->device, 0, sizeof (array->device)); grub_memset (&array->device, 0, sizeof (array->device));
grub_memset (&array->start_sector, 0, sizeof (array->start_sector));
/* Check whether we don't have multiple arrays with the same number. */ if (array->name)
goto skip_duplicate_check;
/* Check whether we don't have multiple arrays with the same number. */
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
{ {
if (p->number == array->number) if (p->number == array->number)
break; break;
} }
if (p) if (p)
{ {
/* The number is already in use, so we need to find an new number. */ /* The number is already in use, so we need to find a new one. */
int i = 0; int i = 0;
while (1) while (1)
{ {
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
{ {
if (p->number == i) if (p->number == i)
break; break;
} }
if (!p) if (! p)
{ {
/* We found an unused number. */ /* We found an unused number. */
array->number = i; array->number = i;
break; break;
} }
i++; i++;
} }
} }
skip_duplicate_check:
array->name = grub_xasprintf ("md%d", array->number); /* mdraid 1.x superblocks have only a name stored not a number.
Use it directly as GRUB device. */
if (! array->name) if (! array->name)
{ {
grub_free (array->uuid); array->name = grub_xasprintf ("md%d", array->number);
grub_free (array); if (! array->name)
{
grub_free (array->uuid);
grub_free (array);
return grub_errno; return grub_errno;
} }
}
else
{
/* Strip off the homehost if present. */
char *colon = grub_strchr (array->name, ':');
char *new_name = grub_xasprintf ("md/%s",
colon ? colon + 1 : array->name);
if (! new_name)
{
grub_free (array->uuid);
grub_free (array);
return grub_errno;
}
grub_free (array->name);
array->name = new_name;
}
grub_dprintf ("raid", "Found array %s (%s)\n", array->name, grub_dprintf ("raid", "Found array %s (%s)\n", array->name,
scanner_name); scanner_name);
@ -580,6 +608,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
/* Add the device to the array. */ /* Add the device to the array. */
array->device[new_array->index] = disk; array->device[new_array->index] = disk;
array->start_sector[new_array->index] = start_sector;
array->nr_devs++; array->nr_devs++;
return 0; return 0;
@ -621,6 +650,7 @@ grub_raid_register (grub_raid_t raid)
{ {
grub_disk_t disk; grub_disk_t disk;
struct grub_raid_array array; struct grub_raid_array array;
grub_disk_addr_t start_sector;
grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name); grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name);
@ -629,8 +659,8 @@ grub_raid_register (grub_raid_t raid)
return 0; return 0;
if ((disk->total_sectors != GRUB_ULONG_MAX) && if ((disk->total_sectors != GRUB_ULONG_MAX) &&
(! grub_raid_list->detect (disk, &array)) && (! grub_raid_list->detect (disk, &array, &start_sector)) &&
(! insert_array (disk, &array, grub_raid_list->name))) (! insert_array (disk, &array, start_sector, grub_raid_list->name)))
return 0; return 0;
/* This error usually means it's not raid, no need to display /* This error usually means it's not raid, no need to display

View file

@ -444,12 +444,13 @@ disk. The number @samp{0} is the drive number, which is counted from
disk. disk.
@example @example
(hd0,2) (hd0,msdos2)
@end example @end example
Here, @samp{hd} means it is a hard disk drive. The first integer Here, @samp{hd} means it is a hard disk drive. The first integer
@samp{0} indicates the drive number, that is, the first hard disk, while @samp{0} indicates the drive number, that is, the first hard disk,
the second integer, @samp{1}, indicates the partition number (or the the string @samp{msdos} indicates the partition scheme, while
the second integer, @samp{2}, indicates the partition number (or the
@sc{pc} slice number in the BSD terminology). The partition numbers are @sc{pc} slice number in the BSD terminology). The partition numbers are
counted from @emph{one}, not from zero (as was the case in previous counted from @emph{one}, not from zero (as was the case in previous
versions of GRUB). This expression means the second partition of the versions of GRUB). This expression means the second partition of the
@ -457,7 +458,7 @@ first hard disk drive. In this case, GRUB uses one partition of the
disk, instead of the whole disk. disk, instead of the whole disk.
@example @example
(hd0,5) (hd0,msdos5)
@end example @end example
This specifies the first @dfn{extended partition} of the first hard disk This specifies the first @dfn{extended partition} of the first hard disk
@ -466,18 +467,15 @@ counted from @samp{5}, regardless of the actual number of primary
partitions on your hard disk. partitions on your hard disk.
@example @example
(hd1,a) (hd1,msdos1,bsd1)
@end example @end example
This means the BSD @samp{a} partition of the second hard disk. If you This means the BSD @samp{a} partition on first @sc{pc} slice number
need to specify which @sc{pc} slice number should be used, use something of the second hard disk.
like this: @samp{(hd1,1,a)}. If the @sc{pc} slice number is omitted,
GRUB searches for the first @sc{pc} slice which has a BSD @samp{a}
partition.
Of course, to actually access the disks or partitions with GRUB, you Of course, to actually access the disks or partitions with GRUB, you
need to use the device specification in a command, like @samp{set need to use the device specification in a command, like @samp{set
root=(fd0)} or @samp{parttool (hd0,3) hidden-}. To help you find out root=(fd0)} or @samp{parttool (hd0,msdos3) hidden-}. To help you find out
which number specifies a partition you want, the GRUB command-line which number specifies a partition you want, the GRUB command-line
(@pxref{Command-line interface}) options have argument (@pxref{Command-line interface}) options have argument
completion. This means that, for example, you only need to type completion. This means that, for example, you only need to type
@ -501,7 +499,7 @@ Now the question is, how to specify a file? Again, consider an
example: example:
@example @example
(hd0,1)/vmlinuz (hd0,msdos1)/vmlinuz
@end example @end example
This specifies the file named @samp{vmlinuz}, found on the first This specifies the file named @samp{vmlinuz}, found on the first

View file

@ -1,7 +1,7 @@
/* raid.h - On disk structures for RAID. */ /* raid.h - On disk structures for RAID. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. * Copyright (C) 2006,2007,2008,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -51,6 +51,8 @@ struct grub_raid_array
char *name; /* That will be "md<number>". */ char *name; /* That will be "md<number>". */
unsigned int nr_devs; /* The number of devices we've found so far. */ unsigned int nr_devs; /* The number of devices we've found so far. */
grub_disk_t device[GRUB_RAID_MAX_DEVICES]; /* Array of total_devs devices. */ grub_disk_t device[GRUB_RAID_MAX_DEVICES]; /* Array of total_devs devices. */
grub_disk_addr_t start_sector[GRUB_RAID_MAX_DEVICES];
/* Start of each device, in 512 byte sectors. */
struct grub_raid_array *next; struct grub_raid_array *next;
}; };
@ -58,7 +60,8 @@ struct grub_raid
{ {
const char *name; const char *name;
grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array); grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector);
struct grub_raid *next; struct grub_raid *next;
}; };

View file

@ -1,7 +1,7 @@
/* getroot.c - Get root device */ /* getroot.c - Get root device */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -36,6 +36,11 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#ifdef __linux__
# include <sys/types.h>
# include <sys/wait.h>
#endif
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/emu/misc.h> #include <grub/emu/misc.h>
@ -516,10 +521,89 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused)))
return GRUB_DEV_ABSTRACTION_NONE; return GRUB_DEV_ABSTRACTION_NONE;
} }
#ifdef __linux__
static char *
get_mdadm_name (const char *os_dev)
{
int mdadm_pipe[2];
pid_t mdadm_pid;
char *name = NULL;
if (pipe (mdadm_pipe) < 0)
{
grub_util_warn ("Unable to create pipe for mdadm: %s", strerror (errno));
return NULL;
}
mdadm_pid = fork ();
if (mdadm_pid < 0)
grub_util_warn ("Unable to fork mdadm: %s", strerror (errno));
else if (mdadm_pid == 0)
{
/* Child. */
char *argv[5];
close (mdadm_pipe[0]);
dup2 (mdadm_pipe[1], STDOUT_FILENO);
close (mdadm_pipe[1]);
/* execvp has inconvenient types, hence the casts. None of these
strings will actually be modified. */
argv[0] = (char *) "mdadm";
argv[1] = (char *) "--detail";
argv[2] = (char *) "--export";
argv[3] = (char *) os_dev;
argv[4] = NULL;
execvp ("mdadm", argv);
exit (127);
}
else
{
/* Parent. Read mdadm's output. */
FILE *mdadm;
char *buf = NULL;
size_t len = 0;
close (mdadm_pipe[1]);
mdadm = fdopen (mdadm_pipe[0], "r");
if (! mdadm)
{
grub_util_warn ("Unable to open stream from mdadm: %s",
strerror (errno));
goto out;
}
while (getline (&buf, &len, mdadm) > 0)
{
if (strncmp (buf, "MD_NAME=", sizeof ("MD_NAME=") - 1) == 0)
{
char *name_start, *colon;
size_t name_len;
free (name);
name_start = buf + sizeof ("MD_NAME=") - 1;
/* Strip off the homehost if present. */
colon = strchr (name_start, ':');
name = strdup (colon ? colon + 1 : name_start);
name_len = strlen (name);
if (name[name_len - 1] == '\n')
name[name_len - 1] = '\0';
}
}
out:
close (mdadm_pipe[0]);
waitpid (mdadm_pid, NULL, 0);
}
return name;
}
#endif /* __linux__ */
char * char *
grub_util_get_grub_dev (const char *os_dev) grub_util_get_grub_dev (const char *os_dev)
{ {
char *grub_dev; char *grub_dev = NULL;
switch (grub_util_get_dev_abstraction (os_dev)) switch (grub_util_get_dev_abstraction (os_dev))
{ {
@ -600,9 +684,36 @@ grub_util_get_grub_dev (const char *os_dev)
grub_dev = xasprintf ("md%s", p); grub_dev = xasprintf ("md%s", p);
free (p); free (p);
} }
else if (os_dev[7] == '/')
{
/* mdraid 1.x with a free name. */
char *p , *q;
p = strdup (os_dev + sizeof ("/dev/md/") - 1);
q = strchr (p, 'p');
if (q)
*q = ',';
grub_dev = xasprintf ("md/%s", p);
free (p);
}
else else
grub_util_error ("unknown kind of RAID device `%s'", os_dev); grub_util_error ("unknown kind of RAID device `%s'", os_dev);
#ifdef __linux__
{
char *mdadm_name = get_mdadm_name (os_dev);
if (mdadm_name)
{
free (grub_dev);
grub_dev = xasprintf ("md/%s", mdadm_name);
free (mdadm_name);
}
}
#endif /* __linux__ */
break; break;
default: /* GRUB_DEV_ABSTRACTION_NONE */ default: /* GRUB_DEV_ABSTRACTION_NONE */

View file

@ -157,11 +157,13 @@ LOCAL(cont1):
andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
movl %eax, %cr0 movl %eax, %cr0
#ifdef __x86_64__
/* Disable amd64. */ /* Disable amd64. */
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
rdmsr rdmsr
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
wrmsr wrmsr
#endif
/* Turn off PAE. */ /* Turn off PAE. */
movl %cr4, %eax movl %cr4, %eax

View file

@ -311,6 +311,20 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
efi_call_2 (o->enable_cursor, o, on); efi_call_2 (o->enable_cursor, o, on);
} }
static grub_err_t
grub_efi_console_init (struct grub_term_output *term)
{
grub_console_setcursor (term, 1);
return 0;
}
static grub_err_t
grub_efi_console_fini (struct grub_term_output *term)
{
grub_console_setcursor (term, 0);
return 0;
}
static struct grub_term_input grub_console_term_input = static struct grub_term_input grub_console_term_input =
{ {
.name = "console", .name = "console",
@ -321,6 +335,8 @@ static struct grub_term_input grub_console_term_input =
static struct grub_term_output grub_console_term_output = static struct grub_term_output grub_console_term_output =
{ {
.name = "console", .name = "console",
.init = grub_efi_console_init,
.fini = grub_efi_console_fini,
.putchar = grub_console_putchar, .putchar = grub_console_putchar,
.getwh = grub_console_getwh, .getwh = grub_console_getwh,
.getxy = grub_console_getxy, .getxy = grub_console_getxy,

View file

@ -1,4 +1,4 @@
#! /bin/bash -e #! /bin/sh -e
# Compares GRUB script output with BASH output. # Compares GRUB script output with BASH output.
# Copyright (C) 2009,2010 Free Software Foundation, Inc. # Copyright (C) 2009,2010 Free Software Foundation, Inc.
@ -84,7 +84,7 @@ done
if [ "x${source}" = x ] ; then if [ "x${source}" = x ] ; then
tmpfile=`mktemp` tmpfile=`mktemp`
while read; do while read REPLY; do
echo $REPLY >> ${tmpfile} echo $REPLY >> ${tmpfile}
done done
source=${tmpfile} source=${tmpfile}

View file

@ -467,13 +467,30 @@ clear_seen_devices (void)
} }
#ifdef __linux__ #ifdef __linux__
/* Like strcmp, but doesn't require a cast for use as a qsort comparator. */ struct device
static int
compare_file_names (const void *a, const void *b)
{ {
const char *left = *(const char **) a; char *stable;
const char *right = *(const char **) b; char *kernel;
return strcmp (left, right); };
/* Sort by the kernel name for preference since that most closely matches
older device.map files, but sort by stable by-id names as a fallback.
This is because /dev/disk/by-id/ usually has a few alternative
identifications of devices (e.g. ATA vs. SATA).
check_device_readable_unique will ensure that we only get one for any
given disk, but sort the list so that the choice of which one we get is
stable. */
static int
compare_devices (const void *a, const void *b)
{
const struct device *left = (const struct device *) a;
const struct device *right = (const struct device *) b;
int ret;
ret = strcmp (left->kernel, right->kernel);
if (ret)
return ret;
else
return strcmp (left->stable, right->stable);
} }
#endif /* __linux__ */ #endif /* __linux__ */
@ -507,10 +524,10 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
if (dir) if (dir)
{ {
struct dirent *entry; struct dirent *entry;
char **names; struct device *devs;
size_t names_len = 0, names_max = 1024, i; size_t devs_len = 0, devs_max = 1024, i;
names = xmalloc (names_max * sizeof (*names)); devs = xmalloc (devs_max * sizeof (*devs));
/* Dump all the directory entries into names, resizing if /* Dump all the directory entries into names, resizing if
necessary. */ necessary. */
@ -526,35 +543,34 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int),
/* Skip RAID entries; they are handled by upper layers. */ /* Skip RAID entries; they are handled by upper layers. */
if (strncmp (entry->d_name, "md-", sizeof ("md-") - 1) == 0) if (strncmp (entry->d_name, "md-", sizeof ("md-") - 1) == 0)
continue; continue;
if (names_len >= names_max) if (devs_len >= devs_max)
{ {
names_max *= 2; devs_max *= 2;
names = xrealloc (names, names_max * sizeof (*names)); devs = xrealloc (devs, devs_max * sizeof (*devs));
} }
names[names_len++] = xasprintf (entry->d_name); devs[devs_len].stable =
xasprintf ("/dev/disk/by-id/%s", entry->d_name);
devs[devs_len].kernel =
canonicalize_file_name (devs[devs_len].stable);
devs_len++;
} }
/* /dev/disk/by-id/ usually has a few alternative identifications of qsort (devs, devs_len, sizeof (*devs), &compare_devices);
devices (e.g. ATA vs. SATA). check_device_readable_unique will
ensure that we only get one for any given disk, but sort the list
so that the choice of which one we get is stable. */
qsort (names, names_len, sizeof (*names), &compare_file_names);
closedir (dir); closedir (dir);
/* Now add all the devices in sorted order. */ /* Now add all the devices in sorted order. */
for (i = 0; i < names_len; ++i) for (i = 0; i < devs_len; ++i)
{ {
char *path = xasprintf ("/dev/disk/by-id/%s", names[i]); if (check_device_readable_unique (devs[i].stable))
if (check_device_readable_unique (path))
{ {
if (hook (path, 0)) if (hook (devs[i].stable, 0))
goto out; goto out;
} }
free (path); free (devs[i].stable);
free (names[i]); free (devs[i].kernel);
} }
free (names); free (devs);
} }
} }

View file

@ -246,7 +246,7 @@ devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_ma
# The order in this list is critical. Be careful when modifying it. # The order in this list is critical. Be careful when modifying it.
modules="$modules $fs_module $partmap_module $devabstraction_module" modules="$modules $fs_module $partmap_module $devabstraction_module"
$grub_mkimage -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1 $grub_mkimage -p "" -O ${target_cpu}-efi --output=${grubdir}/grub.efi $modules || exit 1
# Prompt the user to check if the device map is correct. # Prompt the user to check if the device map is correct.
echo "Installation finished. No error reported." echo "Installation finished. No error reported."

View file

@ -812,14 +812,14 @@ main (int argc, char *argv[])
must_embed = 1; must_embed = 1;
if (root_dev[0] == 'm' && root_dev[1] == 'd' if (root_dev[0] == 'm' && root_dev[1] == 'd'
&& root_dev[2] >= '0' && root_dev[2] <= '9') && ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/'))
{ {
/* FIXME: we can avoid this on RAID1. */ /* FIXME: we can avoid this on RAID1. */
must_embed = 1; must_embed = 1;
} }
if (dest_dev[0] == 'm' && dest_dev[1] == 'd' if (dest_dev[0] == 'm' && dest_dev[1] == 'd'
&& dest_dev[2] >= '0' && dest_dev[2] <= '9') && ((dest_dev[2] >= '0' && dest_dev[2] <= '9') || dest_dev[2] == '/'))
{ {
char **devicelist; char **devicelist;
int i; int i;

View file

@ -18,8 +18,6 @@
import re import re
import sys import sys
import os
import datetime
if len (sys.argv) < 3: if len (sys.argv) < 3:
print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])