From c8ec30a0a4458c9ca53b603a78ac27b3f5ec69fa Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Sun, 8 Nov 2009 01:57:17 +0100 Subject: [PATCH 01/45] 2009-11-06 Felix Zielcke * 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. --- ChangeLog.raid | 11 +++ disk/dmraid_nvidia.c | 3 +- disk/mdraid_linux.c | 193 +++++++++++++++++++++++++++++++++++++++++-- disk/raid.c | 74 +++++++++-------- util/getroot.c | 14 ++++ 5 files changed, 252 insertions(+), 43 deletions(-) create mode 100644 ChangeLog.raid diff --git a/ChangeLog.raid b/ChangeLog.raid new file mode 100644 index 000000000..090e1edc7 --- /dev/null +++ b/ChangeLog.raid @@ -0,0 +1,11 @@ +2009-11-06 Felix Zielcke + + * 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. diff --git a/disk/dmraid_nvidia.c b/disk/dmraid_nvidia.c index 84dfad8c4..ed89854b3 100644 --- a/disk/dmraid_nvidia.c +++ b/disk/dmraid_nvidia.c @@ -1,7 +1,7 @@ /* dmraid_nvidia.c - module to handle Nvidia fakeraid. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -132,6 +132,7 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array) "Unsupported RAID level: %d", sb.array.raid_level); } + array->name = NULL; array->number = 0; array->total_devs = sb.array.total_volumes; array->chunk_size = sb.array.stripe_block_size; diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index 29a21b4c7..275267f72 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -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 - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -159,32 +159,146 @@ struct grub_raid_super_09 struct grub_raid_disk_09 this_disk; } __attribute__ ((packed)); +/* + * 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. */ +} __attribute__ ((packed)); + +#define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */ + static grub_err_t grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) { grub_disk_addr_t sector; - grub_uint64_t size; + grub_uint64_t size, sb_size; struct grub_raid_super_09 sb; + struct grub_raid_super_1x *sb_1x; grub_uint32_t *uuid; + grub_uint8_t minor_version; - /* The sector where the RAID superblock is stored, if available. */ + /* 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)) return grub_errno; - /* Look whether there is a RAID superblock. */ - if (sb.md_magic != SB_MAGIC) + /* Look whether there is a mdraid 0.90 superblock. */ + if (sb.md_magic == SB_MAGIC) + goto superblock_0_90; + + /* 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. + */ + + sb_1x = grub_malloc (sizeof (struct grub_raid_super_1x)); + if (!sb_1x) + return grub_errno; + + 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)) + { + grub_free (sb_1x); + return grub_errno; + } + + if (sb_1x->magic == SB_MAGIC) + goto superblock_1_x; + } + + /* Neither 0.90 nor 1.x. */ + if (grub_le_to_cpu32 (sb_1x->magic) != SB_MAGIC) return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid"); - /* FIXME: Also support version 1.0. */ +superblock_0_90: + if (sb.major_version != 0 || sb.minor_version != 90) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Unsupported RAID version: %d.%d", sb.major_version, sb.minor_version); - /* FIXME: Check the checksum. */ + /* FIXME: Check the checksum. */ /* Multipath. */ if ((int) sb.level == -4) @@ -195,6 +309,7 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Unsupported RAID level: %d", sb.level); + array->name = NULL; array->number = sb.md_minor; array->level = sb.level; array->layout = sb.layout; @@ -205,7 +320,10 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) array->uuid_len = 16; array->uuid = grub_malloc (16); if (!array->uuid) - return grub_errno; + { + grub_free (sb_1x); + return grub_errno; + } uuid = (grub_uint32_t *) array->uuid; uuid[0] = sb.set_uuid0; @@ -214,6 +332,63 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) uuid[3] = sb.set_uuid3; return 0; + + superblock_1_x: + + if (sb_1x->major_version != 1) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Unsupported RAID version: %d", + sb_1x->major_version); + /* Multipath. */ + if ((int) sb_1x->level == -4) + sb_1x->level = 1; + + if (sb_1x->level != 0 && sb_1x->level != 1 && sb_1x->level != 4 && + sb_1x->level != 5 && sb_1x->level != 6 && sb_1x->level != 10) + { + grub_free (sb_1x); + 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_1x->max_dev); + sb_1x = grub_realloc (sb_1x, sb_size); + if (! sb_1x) + return grub_errno; + + if (grub_disk_read (disk, sector, 0, sb_size, sb_1x)) + { + grub_free (sb_1x); + return grub_errno; + } + + array->name = grub_strdup (sb_1x->set_name); + if (! array->name) + { + grub_free (sb_1x); + return grub_errno; + } + + array->number = 0; + array->level = grub_le_to_cpu32 (sb_1x->level); + array->layout = grub_le_to_cpu32 (sb_1x->layout); + array->total_devs = grub_le_to_cpu32 (sb_1x->raid_disks); + array->disk_size = grub_le_to_cpu64 (sb_1x->size) * 2; + array->chunk_size = grub_le_to_cpu32 (sb_1x->chunksize) >> 9; + array->index = grub_le_to_cpu32 (sb_1x->dev_number); + array->uuid_len = 16; + array->uuid = grub_malloc (16); + if (!array->uuid) + { + grub_free (sb_1x); + return grub_errno; + } + + grub_memcpy (array->uuid, sb_1x->set_uuid, 16); + + grub_free (sb_1x); + return 0; } static struct grub_raid grub_mdraid_dev = { diff --git a/disk/raid.c b/disk/raid.c index c720fb36c..b88741744 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -1,7 +1,7 @@ /* raid.c - module to read RAID arrays. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -480,7 +480,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, struct grub_raid_array *array = 0, *p; /* 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) if ((p->uuid_len == new_array->uuid_len) && (! grub_memcmp (p->uuid, new_array->uuid, p->uuid_len))) @@ -491,7 +491,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* Do some checks before adding the device to the array. */ /* FIXME: Check whether the update time of the superblocks are - the same. */ + the same. */ if (array->total_devs == array->nr_devs) /* We found more members of the array than the array @@ -502,7 +502,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, if (array->device[new_array->index] != NULL) /* 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?!?", new_array->number); @@ -525,47 +525,55 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, array->nr_devs = 0; grub_memset (&array->device, 0, sizeof (array->device)); - /* 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) { - if (p->number == array->number) - break; + if (p->number == array->number) + break; } 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; - while (1) - { - for (p = array_list; p != NULL; p = p->next) - { - if (p->number == i) - break; - } + while (1) + { + for (p = array_list; p != NULL; p = p->next) + { + if (p->number == i) + break; + } - if (!p) - { - /* We found an unused number. */ - array->number = i; - break; - } + if (! p) + { + /* We found an unused number. */ + array->number = i; + break; + } - i++; - } - } - - array->name = grub_malloc (13); + i++; + } + } + skip_duplicate_check: + /* mdraid 1.x superblocks have only a name stored not a number. + Use it directly as GRUB device. */ if (! array->name) - { - grub_free (array->uuid); - grub_free (array); + { + array->name = grub_malloc (13); + if (! array->name) + { + grub_free (array->uuid); + grub_free (array); - return grub_errno; - } - - grub_sprintf (array->name, "md%d", array->number); + return grub_errno; + } + grub_sprintf (array->name, "md%d", array->number); + } + else + grub_sprintf (array->name, "%s", array->name); grub_dprintf ("raid", "Found array %s (%s)\n", array->name, scanner_name); diff --git a/util/getroot.c b/util/getroot.c index 120ab13b1..618d76158 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -498,6 +498,20 @@ grub_util_get_grub_dev (const char *os_dev) asprintf (&grub_dev, "md%s", 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 = ','; + + asprintf (&grub_dev, "%s", p); + free (p); + } else grub_util_error ("Unknown kind of RAID device `%s'", os_dev); From c6622adb31fc8666a2cfe07fc6f44cd82eec3585 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Wed, 11 Nov 2009 23:17:59 +0100 Subject: [PATCH 02/45] make autogen.sh and gendistlist.sh executable --- autogen.sh | 0 gendistlist.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 autogen.sh mode change 100644 => 100755 gendistlist.sh diff --git a/autogen.sh b/autogen.sh old mode 100644 new mode 100755 diff --git a/gendistlist.sh b/gendistlist.sh old mode 100644 new mode 100755 From 4e962809b57b5018e00ca982d55a012c6e6674d7 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Mon, 16 Nov 2009 21:46:43 +0100 Subject: [PATCH 03/45] 2009-11-16 Felix Zielcke * disk/mdraid_linux.c: Fix the unsupported RAID version error with metadata 1.x. --- ChangeLog.raid | 5 +++++ disk/mdraid_linux.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index 090e1edc7..645f7e7f1 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,8 @@ +2009-11-16 Felix Zielcke + + * disk/mdraid_linux.c: Fix the unsupported RAID version error + with metadata 1.x. + 2009-11-06 Felix Zielcke * disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Set array->name to NULL. diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index 275267f72..026adb380 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -346,9 +346,9 @@ superblock_0_90: if (sb_1x->level != 0 && sb_1x->level != 1 && sb_1x->level != 4 && sb_1x->level != 5 && sb_1x->level != 6 && sb_1x->level != 10) { - grub_free (sb_1x); return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "Unsupported RAID level: %d", sb.level); + "Unsupported RAID level: %d", sb_1x->level); + grub_free (sb_1x); } /* 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. */ From 8bcaed961a8e08081c22a511c70c1fdddfa297a3 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Mon, 16 Nov 2009 21:52:10 +0100 Subject: [PATCH 04/45] 2009-11-16 Felix Zielcke * disk/mdraid_linux.c (grub_mdraid_detect): Remove a wrong call of free(). --- ChangeLog.raid | 9 +++++++-- disk/mdraid_linux.c | 3 --- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index 645f7e7f1..854702f41 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,7 +1,12 @@ 2009-11-16 Felix Zielcke - * disk/mdraid_linux.c: Fix the unsupported RAID version error - with metadata 1.x. + * disk/mdraid_linux.c (grub_mdraid_detect): Remove a wrong call + of free(). + +2009-11-16 Felix Zielcke + + * disk/mdraid_linux.c (grub_mdraid_detect): Fix the unsupported + RAID version error with metadata 1.x. 2009-11-06 Felix Zielcke diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index 026adb380..8670710b3 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -320,10 +320,7 @@ superblock_0_90: array->uuid_len = 16; array->uuid = grub_malloc (16); if (!array->uuid) - { - grub_free (sb_1x); return grub_errno; - } uuid = (grub_uint32_t *) array->uuid; uuid[0] = sb.set_uuid0; From 51bd7ea32acf7349d72ce61cfa9f93f7486f9723 Mon Sep 17 00:00:00 2001 From: Felix Zielcke Date: Fri, 18 Dec 2009 20:57:22 +0100 Subject: [PATCH 05/45] Set correct chunksize with metadata 1.x --- disk/mdraid_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index 8670710b3..79363d143 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -372,7 +372,7 @@ superblock_0_90: array->layout = grub_le_to_cpu32 (sb_1x->layout); array->total_devs = grub_le_to_cpu32 (sb_1x->raid_disks); array->disk_size = grub_le_to_cpu64 (sb_1x->size) * 2; - array->chunk_size = grub_le_to_cpu32 (sb_1x->chunksize) >> 9; + array->chunk_size = grub_le_to_cpu32 (sb_1x->chunksize); array->index = grub_le_to_cpu32 (sb_1x->dev_number); array->uuid_len = 16; array->uuid = grub_malloc (16); From 3b97788878888b16960c3723d86875a01abc3f2f Mon Sep 17 00:00:00 2001 From: Peter Henn Date: Tue, 1 Jun 2010 18:40:03 +0100 Subject: [PATCH 06/45] * 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. --- ChangeLog.raid | 7 +++++++ disk/mdraid_linux.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index 854702f41..989f0bc09 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,10 @@ +2009-12-15 Peter Henn + + * 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. + 2009-11-16 Felix Zielcke * disk/mdraid_linux.c (grub_mdraid_detect): Remove a wrong call diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index d29803719..08e10ab45 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -371,9 +371,12 @@ superblock_0_90: array->level = grub_le_to_cpu32 (sb_1x->level); array->layout = grub_le_to_cpu32 (sb_1x->layout); array->total_devs = grub_le_to_cpu32 (sb_1x->raid_disks); - array->disk_size = grub_le_to_cpu64 (sb_1x->size) * 2; + array->disk_size = grub_le_to_cpu64 (sb_1x->size); array->chunk_size = grub_le_to_cpu32 (sb_1x->chunksize); - array->index = grub_le_to_cpu32 (sb_1x->dev_number); + if (grub_le_to_cpu32 (sb_1x->dev_number) < grub_le_to_cpu32 (sb_1x->max_dev)) + array->index = grub_le_to_cpu16 (sb_1x->dev_roles[grub_le_to_cpu32 (sb_1x->dev_number)]); + else + array->index = 0xffff; /* disk will be later not used! */ array->uuid_len = 16; array->uuid = grub_malloc (16); if (!array->uuid) From e726afa89d8fabd1c962655b7a1e2d0bdbaa0e3d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 1 Jun 2010 18:40:45 +0100 Subject: [PATCH 07/45] fix indentation --- disk/raid.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/disk/raid.c b/disk/raid.c index 07ae606b9..d6a1f1d48 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -562,16 +562,16 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, Use it directly as GRUB device. */ if (! array->name) { - array->name = grub_malloc (13); - if (! array->name) - { - grub_free (array->uuid); - grub_free (array); + array->name = grub_malloc (13); + if (! array->name) + { + grub_free (array->uuid); + grub_free (array); - return grub_errno; - } - grub_sprintf (array->name, "md%d", array->number); - } + return grub_errno; + } + grub_sprintf (array->name, "md%d", array->number); + } else grub_sprintf (array->name, "%s", array->name); From 5771289a14bc26e3145917b79910026c6bc298b6 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 17 Jul 2010 19:27:18 +0100 Subject: [PATCH 08/45] * util/import_unicode.py: Remove unnecessary imports. --- ChangeLog | 4 ++++ util/import_unicode.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f2e9356f..8ebb35067 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-17 Colin Watson + + * util/import_unicode.py: Remove unnecessary imports. + 2010-07-17 Aleš Nesrsta Hotplugging and USB hub support. diff --git a/util/import_unicode.py b/util/import_unicode.py index 1ee162d3f..8d17e7ef6 100644 --- a/util/import_unicode.py +++ b/util/import_unicode.py @@ -18,8 +18,6 @@ import re import sys -import os -import datetime if len (sys.argv) < 3: print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) From 139ab97dc3035212e28d7890f6ec0773ca5103ee Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 18 Jul 2010 15:53:14 +0100 Subject: [PATCH 09/45] * 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. --- ChangeLog.raid | 11 +++++ disk/raid.c | 9 +++- kern/emu/getroot.c | 101 +++++++++++++++++++++++++++++++++++++- util/i386/pc/grub-setup.c | 4 +- 4 files changed, 120 insertions(+), 5 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index 989f0bc09..c546a7632 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,14 @@ +2010-07-18 Colin Watson + + * 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. + 2009-12-15 Peter Henn * disk/mdraid_linux.c (grub_mdraid_detect): Fix calculation of 1.x diff --git a/disk/raid.c b/disk/raid.c index 87e713f30..1dc361e8e 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -563,7 +563,14 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, if (! array->name) array->name = grub_xasprintf ("md%d", array->number); else - array->name = grub_xasprintf ("%s", array->name); + { + /* Strip off the homehost if present. */ + char *colon = grub_strchr (array->name, ':'); + char *new_name = grub_xasprintf ("md/%s", + colon ? colon + 1 : array->name); + grub_free (array->name); + array->name = new_name; + } grub_dprintf ("raid", "Found array %s (%s)\n", array->name, scanner_name); diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 5b0849a98..2d7469c9d 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -36,6 +36,11 @@ #include #endif +#ifdef __linux__ +# include +# include +#endif + #include #include #include @@ -516,10 +521,89 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) 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 * grub_util_get_grub_dev (const char *os_dev) { - char *grub_dev; + char *grub_dev = NULL; switch (grub_util_get_dev_abstraction (os_dev)) { @@ -611,12 +695,25 @@ grub_util_get_grub_dev (const char *os_dev) if (q) *q = ','; - asprintf (&grub_dev, "%s", p); + asprintf (&grub_dev, "md/%s", p); free (p); } else 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); + asprintf (&grub_dev, "md/%s", mdadm_name); + free (mdadm_name); + } + } +#endif /* __linux__ */ + break; default: /* GRUB_DEV_ABSTRACTION_NONE */ diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 8b2f52bb4..524572fad 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -812,14 +812,14 @@ main (int argc, char *argv[]) must_embed = 1; 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. */ must_embed = 1; } 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; int i; From 1c785436daacfd914f8066fdb639fc22bd17ddbe Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 18 Jul 2010 18:31:10 +0100 Subject: [PATCH 10/45] * 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'. --- ChangeLog.raid | 16 ++++++++++++++++ disk/dmraid_nvidia.c | 5 ++++- disk/mdraid_linux.c | 7 ++++++- disk/raid.c | 15 ++++++++++----- include/grub/raid.h | 5 ++++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index c546a7632..a66bd6905 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,19 @@ +2010-07-18 Colin Watson + + * 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'. + 2010-07-18 Colin Watson * disk/raid.c (insert_array): Use md/%s to name mdadm 1.x devices, diff --git a/disk/dmraid_nvidia.c b/disk/dmraid_nvidia.c index 3e4ae33be..d3f45935c 100644 --- a/disk/dmraid_nvidia.c +++ b/disk/dmraid_nvidia.c @@ -89,7 +89,8 @@ struct grub_nv_super } __attribute__ ((packed)); 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; struct grub_nv_super sb; @@ -145,6 +146,8 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array) grub_memcpy (array->uuid, (char *) &sb.array.signature, sizeof (sb.array.signature)); + *start_sector = 0; + return 0; } diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index 08e10ab45..b97e458ce 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -229,7 +229,8 @@ struct grub_raid_super_1x #define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */ static grub_err_t -grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array) +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, sb_size; @@ -328,6 +329,8 @@ superblock_0_90: uuid[2] = sb.set_uuid2; uuid[3] = sb.set_uuid3; + *start_sector = 0; + return 0; superblock_1_x: @@ -387,6 +390,8 @@ superblock_0_90: grub_memcpy (array->uuid, sb_1x->set_uuid, 16); + *start_sector = sb_1x->data_offset; + grub_free (sb_1x); return 0; } diff --git a/disk/raid.c b/disk/raid.c index 1dc361e8e..30d4b7ac4 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -254,7 +254,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector, grub_errno = GRUB_ERR_NONE; err = grub_disk_read (array->device[k], - read_sector + j * far_ofs + b, + array->start_sector[k] + + read_sector + j * far_ofs + b, 0, read_size << GRUB_DISK_SECTOR_BITS, buf); @@ -366,7 +367,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector, grub_errno = GRUB_ERR_NONE; 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, buf); @@ -475,7 +477,7 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)), static grub_err_t 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; @@ -524,6 +526,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, *array = *new_array; array->nr_devs = 0; grub_memset (&array->device, 0, sizeof (array->device)); + grub_memset (&array->start_sector, 0, sizeof (array->start_sector)); if (array->name) goto skip_duplicate_check; @@ -587,6 +590,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* Add the device to the array. */ array->device[new_array->index] = disk; + array->start_sector[new_array->index] = start_sector; array->nr_devs++; return 0; @@ -628,6 +632,7 @@ grub_raid_register (grub_raid_t raid) { grub_disk_t disk; struct grub_raid_array array; + grub_disk_addr_t start_sector; grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name); @@ -636,8 +641,8 @@ grub_raid_register (grub_raid_t raid) return 0; if ((disk->total_sectors != GRUB_ULONG_MAX) && - (! grub_raid_list->detect (disk, &array)) && - (! insert_array (disk, &array, grub_raid_list->name))) + (! grub_raid_list->detect (disk, &array, &start_sector)) && + (! insert_array (disk, &array, start_sector, grub_raid_list->name))) return 0; /* This error usually means it's not raid, no need to display diff --git a/include/grub/raid.h b/include/grub/raid.h index 8fa4c3814..00df9c10c 100644 --- a/include/grub/raid.h +++ b/include/grub/raid.h @@ -51,6 +51,8 @@ struct grub_raid_array char *name; /* That will be "md". */ 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_addr_t start_sector[GRUB_RAID_MAX_DEVICES]; + /* Start of each device, in 512 byte sectors. */ struct grub_raid_array *next; }; @@ -58,7 +60,8 @@ struct grub_raid { 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; }; From 68ac8c8d151cc3dc41c3e5ca578f6fea2a5941fe Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Jul 2010 11:35:16 +0100 Subject: [PATCH 11/45] * 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. * disk/raid.c (insert_array): Check for grub_xasprintf returning NULL. --- ChangeLog.raid | 10 ++ disk/mdraid_linux.c | 261 +++++++++++++++++++++++--------------------- disk/raid.c | 20 +++- 3 files changed, 165 insertions(+), 126 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index a66bd6905..d91f584c0 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,13 @@ +2010-07-19 Colin Watson + + * 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. + * disk/raid.c (insert_array): Check for grub_xasprintf returning + NULL. + 2010-07-18 Colin Watson * disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Add start_sector diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index b97e458ce..b1199c6ef 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -224,31 +224,152 @@ struct grub_raid_super_1x * have a meaningful role. */ grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */ -} __attribute__ ((packed)); +}; +/* 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_uint32_t *uuid; + + if (sb->major_version != 0 || sb->minor_version != 90) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "unsupported RAID version: %d.%d", + sb->major_version, sb->minor_version); + + /* FIXME: Check the checksum. */ + + /* 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); + + array->name = NULL; + array->number = sb->md_minor; + array->level = sb->level; + array->layout = sb->layout; + array->total_devs = sb->raid_disks; + array->disk_size = (sb->size) ? sb->size * 2 : sector; + array->chunk_size = sb->chunk_size >> 9; + array->index = sb->this_disk.number; + array->uuid_len = 16; + array->uuid = grub_malloc (16); + if (!array->uuid) + return grub_errno; + + uuid = (grub_uint32_t *) array->uuid; + uuid[0] = sb->set_uuid0; + uuid[1] = sb->set_uuid1; + uuid[2] = sb->set_uuid2; + uuid[3] = sb->set_uuid3; + + *start_sector = 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, sb_size; - struct grub_raid_super_09 sb; - struct grub_raid_super_1x *sb_1x; - grub_uint32_t *uuid; + 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)) + 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.md_magic == SB_MAGIC) - goto superblock_0_90; + 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 @@ -258,10 +379,6 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, * 2: 4K from start of device. */ - sb_1x = grub_malloc (sizeof (struct grub_raid_super_1x)); - if (!sb_1x) - return grub_errno; - for (minor_version = 0; minor_version < 3; ++minor_version) { switch (minor_version) @@ -277,123 +394,17 @@ grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array, break; } - if (grub_disk_read - (disk, sector, 0, sizeof (struct grub_raid_super_1x), sb_1x)) - { - grub_free (sb_1x); - return grub_errno; - } + if (grub_disk_read (disk, sector, 0, sizeof (struct grub_raid_super_1x), + &sb_1x)) + return grub_errno; - if (sb_1x->magic == SB_MAGIC) - goto superblock_1_x; + if (sb_1x.magic == SB_MAGIC) + return grub_mdraid_detect_1x (disk, sector, &sb_1x, array, + start_sector); } /* Neither 0.90 nor 1.x. */ - if (grub_le_to_cpu32 (sb_1x->magic) != SB_MAGIC) - return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid"); - -superblock_0_90: - - if (sb.major_version != 0 || sb.minor_version != 90) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported RAID version: %d.%d", - sb.major_version, sb.minor_version); - - /* FIXME: Check the checksum. */ - - /* 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); - - array->name = NULL; - array->number = sb.md_minor; - array->level = sb.level; - array->layout = sb.layout; - array->total_devs = sb.raid_disks; - array->disk_size = (sb.size) ? sb.size * 2 : sector; - array->chunk_size = sb.chunk_size >> 9; - array->index = sb.this_disk.number; - array->uuid_len = 16; - array->uuid = grub_malloc (16); - if (!array->uuid) - return grub_errno; - - uuid = (grub_uint32_t *) array->uuid; - uuid[0] = sb.set_uuid0; - uuid[1] = sb.set_uuid1; - uuid[2] = sb.set_uuid2; - uuid[3] = sb.set_uuid3; - - *start_sector = 0; - - return 0; - - superblock_1_x: - - if (sb_1x->major_version != 1) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "Unsupported RAID version: %d", - sb_1x->major_version); - /* Multipath. */ - if ((int) sb_1x->level == -4) - sb_1x->level = 1; - - if (sb_1x->level != 0 && sb_1x->level != 1 && sb_1x->level != 4 && - sb_1x->level != 5 && sb_1x->level != 6 && sb_1x->level != 10) - { - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "Unsupported RAID level: %d", sb_1x->level); - grub_free (sb_1x); - } - /* 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_1x->max_dev); - sb_1x = grub_realloc (sb_1x, sb_size); - if (! sb_1x) - return grub_errno; - - if (grub_disk_read (disk, sector, 0, sb_size, sb_1x)) - { - grub_free (sb_1x); - return grub_errno; - } - - array->name = grub_strdup (sb_1x->set_name); - if (! array->name) - { - grub_free (sb_1x); - return grub_errno; - } - - array->number = 0; - array->level = grub_le_to_cpu32 (sb_1x->level); - array->layout = grub_le_to_cpu32 (sb_1x->layout); - array->total_devs = grub_le_to_cpu32 (sb_1x->raid_disks); - array->disk_size = grub_le_to_cpu64 (sb_1x->size); - array->chunk_size = grub_le_to_cpu32 (sb_1x->chunksize); - if (grub_le_to_cpu32 (sb_1x->dev_number) < grub_le_to_cpu32 (sb_1x->max_dev)) - array->index = grub_le_to_cpu16 (sb_1x->dev_roles[grub_le_to_cpu32 (sb_1x->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 (sb_1x); - return grub_errno; - } - - grub_memcpy (array->uuid, sb_1x->set_uuid, 16); - - *start_sector = sb_1x->data_offset; - - grub_free (sb_1x); - return 0; + return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid"); } static struct grub_raid grub_mdraid_dev = { diff --git a/disk/raid.c b/disk/raid.c index 30d4b7ac4..2f70e256f 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -564,13 +564,31 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* mdraid 1.x superblocks have only a name stored not a number. Use it directly as GRUB device. */ if (! array->name) - array->name = grub_xasprintf ("md%d", array->number); + { + array->name = grub_xasprintf ("md%d", array->number); + if (! array->name) + { + grub_free (array->uuid); + grub_free (array); + + 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; } From 31cfe714f21c325f9acf3e3213f7a1361e8b5bfd Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 11:10:49 +0100 Subject: [PATCH 12/45] * disk/mdraid_linux.c: Update copyright years. * disk/raid.c: Likewise. * include/grub/raid.h: Likewise. * kern/emu/getroot.c: Likewise. --- ChangeLog.raid | 7 +++++++ disk/mdraid_linux.c | 2 +- disk/raid.c | 2 +- include/grub/raid.h | 2 +- kern/emu/getroot.c | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog.raid b/ChangeLog.raid index d91f584c0..10215f7fd 100644 --- a/ChangeLog.raid +++ b/ChangeLog.raid @@ -1,3 +1,10 @@ +2010-07-20 Colin Watson + + * disk/mdraid_linux.c: Update copyright years. + * disk/raid.c: Likewise. + * include/grub/raid.h: Likewise. + * kern/emu/getroot.c: Likewise. + 2010-07-19 Colin Watson * disk/mdraid_linux.c (struct grub_raid_super_1x): Remove diff --git a/disk/mdraid_linux.c b/disk/mdraid_linux.c index b1199c6ef..d5a0aad47 100644 --- a/disk/mdraid_linux.c +++ b/disk/mdraid_linux.c @@ -1,7 +1,7 @@ /* mdraid_linux.c - module to handle Linux Software RAID. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/disk/raid.c b/disk/raid.c index 2f70e256f..43d2a29ff 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -1,7 +1,7 @@ /* raid.c - module to read RAID arrays. */ /* * 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 * it under the terms of the GNU General Public License as published by diff --git a/include/grub/raid.h b/include/grub/raid.h index 00df9c10c..711a7f79c 100644 --- a/include/grub/raid.h +++ b/include/grub/raid.h @@ -1,7 +1,7 @@ /* raid.h - On disk structures for RAID. */ /* * 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 * it under the terms of the GNU General Public License as published by diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 2d7469c9d..9f89bf657 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -1,7 +1,7 @@ /* getroot.c - Get root device */ /* * 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 * it under the terms of the GNU General Public License as published by From 4b761da90280153c13ff850c9e0e1b19daf719b1 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 11:20:23 +0100 Subject: [PATCH 13/45] * .bzrignore: Ignore 20_linux_xen. --- .bzrignore | 1 + ChangeLog | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.bzrignore b/.bzrignore index daf9da53a..32b96b154 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,5 +1,6 @@ 00_header 10_* +20_linux_xen 30_os-prober 40_custom 41_custom diff --git a/ChangeLog b/ChangeLog index 8ebb35067..200058f29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-20 Colin Watson + + * .bzrignore: Ignore 20_linux_xen. + 2010-07-17 Colin Watson * util/import_unicode.py: Remove unnecessary imports. From 39d824e8f9379e957b3389c63419ffa787a80aa1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 20 Jul 2010 14:42:32 +0200 Subject: [PATCH 14/45] * commands/acpi.c (setup_common_tables): Use sizeof instead of hardcoding size. (setv1table): Likewise. --- ChangeLog | 6 ++++++ commands/acpi.c | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index fab3ecb22..66d810e91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-20 Vladimir Serbinenko + + * commands/acpi.c (setup_common_tables): Use sizeof instead of + hardcoding size. + (setv1table): Likewise. + 2010-07-20 Colin Watson * disk/raid.c (insert_array): Use md/%s to name mdadm 1.x devices, diff --git a/commands/acpi.c b/commands/acpi.c index 5bbfd008b..884ddf000 100644 --- a/commands/acpi.c +++ b/commands/acpi.c @@ -325,7 +325,8 @@ setup_common_tables (void) /* If it's FADT correct DSDT and FACS addresses. */ 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->facs_addr = facs_addr; @@ -351,16 +352,16 @@ setup_common_tables (void) rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr; 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. */ grub_memcpy (&(rsdt->signature), "RSDT", 4); rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables; rsdt->revision = 1; - grub_memcpy (&(rsdt->oemid), root_oemid, 6); - grub_memcpy (&(rsdt->oemtable), root_oemtable, 4); + grub_memcpy (&(rsdt->oemid), root_oemid, sizeof (rsdt->oemid)); + grub_memcpy (&(rsdt->oemtable), root_oemtable, sizeof (rsdt->oemtable)); 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; for (cur = acpi_tables; cur; cur = cur->next) @@ -378,7 +379,8 @@ setv1table (void) /* Create RSDP. */ rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr; 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)); rsdpv1_new->revision = 0; rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr); From a29d6a4bc516c1f7cb0f142714ad4b85e9b3a1b2 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Tue, 20 Jul 2010 15:59:56 +0200 Subject: [PATCH 15/45] * lib/i386/relocator_asm.S [! __x86_64__]: Don't try to disable amd64 on i386. --- ChangeLog | 5 +++++ lib/i386/relocator_asm.S | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 66d810e91..d5e655b90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-07-20 Thomas Frauendorfer + + * lib/i386/relocator_asm.S [! __x86_64__]: Don't try to disable amd64 + on i386. + 2010-07-20 Vladimir Serbinenko * commands/acpi.c (setup_common_tables): Use sizeof instead of diff --git a/lib/i386/relocator_asm.S b/lib/i386/relocator_asm.S index 6b803db13..22490a3f8 100644 --- a/lib/i386/relocator_asm.S +++ b/lib/i386/relocator_asm.S @@ -157,11 +157,13 @@ LOCAL(cont1): andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax movl %eax, %cr0 +#ifdef __x86_64__ /* Disable amd64. */ movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx rdmsr andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax wrmsr +#endif /* Turn off PAE. */ movl %cr4, %eax From ab8ba957608a44a6f6ccf3a9f6055dd71f853f78 Mon Sep 17 00:00:00 2001 From: Vadim Solomin Date: Tue, 20 Jul 2010 17:14:00 +0100 Subject: [PATCH 16/45] 2010-07-20 Vadim Solomin 2010-07-20 Colin Watson 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. Also-By: Colin Watson --- ChangeLog | 13 ++++++++++ util/deviceiter.c | 66 +++++++++++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5e655b90..aa4d0b530 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-07-20 Vadim Solomin +2010-07-20 Colin Watson + + 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 * lib/i386/relocator_asm.S [! __x86_64__]: Don't try to disable amd64 diff --git a/util/deviceiter.c b/util/deviceiter.c index bbcc00a91..1cf511934 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -467,13 +467,30 @@ clear_seen_devices (void) } #ifdef __linux__ -/* Like strcmp, but doesn't require a cast for use as a qsort comparator. */ -static int -compare_file_names (const void *a, const void *b) +struct device { - const char *left = *(const char **) a; - const char *right = *(const char **) b; - return strcmp (left, right); + char *stable; + char *kernel; +}; + +/* 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__ */ @@ -507,10 +524,10 @@ grub_util_iterate_devices (int NESTED_FUNC_ATTR (*hook) (const char *, int), if (dir) { struct dirent *entry; - char **names; - size_t names_len = 0, names_max = 1024, i; + struct device *devs; + 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 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. */ if (strncmp (entry->d_name, "md-", sizeof ("md-") - 1) == 0) continue; - if (names_len >= names_max) + if (devs_len >= devs_max) { - names_max *= 2; - names = xrealloc (names, names_max * sizeof (*names)); + devs_max *= 2; + 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 - 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); + qsort (devs, devs_len, sizeof (*devs), &compare_devices); closedir (dir); /* 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 (path)) + if (check_device_readable_unique (devs[i].stable)) { - if (hook (path, 0)) + if (hook (devs[i].stable, 0)) goto out; } - free (path); - free (names[i]); + free (devs[i].stable); + free (devs[i].kernel); } - free (names); + free (devs); } } From 64a638b0d9d428a757c2d067131d2fbf1e88b2ec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 20 Jul 2010 20:22:52 +0200 Subject: [PATCH 17/45] * docs/grub.texi (Naming convention): Document new naming convention. --- ChangeLog | 4 ++++ docs/grub.texi | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa4d0b530..8fccf3490 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-20 Vladimir Serbinenko + + * docs/grub.texi (Naming convention): Document new naming convention. + 2010-07-20 Vadim Solomin 2010-07-20 Colin Watson diff --git a/docs/grub.texi b/docs/grub.texi index 5d412ecd4..a191ef9ef 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -444,12 +444,13 @@ disk. The number @samp{0} is the drive number, which is counted from disk. @example -(hd0,2) +(hd0,msdos2) @end example 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 -the second integer, @samp{1}, indicates the partition number (or the +@samp{0} indicates the drive number, that is, the first hard disk, +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 counted from @emph{one}, not from zero (as was the case in previous 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. @example -(hd0,5) +(hd0,msdos5) @end example 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. @example -(hd1,a) +(hd1,msdos1,bsd1) @end example -This means the BSD @samp{a} partition of the second hard disk. If you -need to specify which @sc{pc} slice number should be used, use something -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. +This means the BSD @samp{a} partition on first @sc{pc} slice number +of the second hard disk. Of course, to actually access the disks or partitions with GRUB, you 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 (@pxref{Command-line interface}) options have argument 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 -(hd0,1)/vmlinuz +(hd0,msdos1)/vmlinuz @end example This specifies the file named @samp{vmlinuz}, found on the first From a6a11f3cac8703b662c7a8424fea21a1e2c3ffd0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 20 Jul 2010 20:36:11 +0200 Subject: [PATCH 18/45] * util/i386/efi/grub-install.in: Revert to platform-specific behaviour with -p "". Reported by: Tito Keitel. --- ChangeLog | 6 ++++++ util/i386/efi/grub-install.in | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8fccf3490..2e6853371 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-20 Vladimir Serbinenko + + * util/i386/efi/grub-install.in: Revert to platform-specific behaviour + with -p "". + Reported by: Tito Keitel. + 2010-07-20 Vladimir Serbinenko * docs/grub.texi (Naming convention): Document new naming convention. diff --git a/util/i386/efi/grub-install.in b/util/i386/efi/grub-install.in index 269317cd0..d8554a328 100644 --- a/util/i386/efi/grub-install.in +++ b/util/i386/efi/grub-install.in @@ -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. 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. echo "Installation finished. No error reported." From afaec079d13d3c71976c449d7f1cc7f1c3a65a6a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 20 Jul 2010 21:56:00 +0200 Subject: [PATCH 19/45] * 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. --- ChangeLog | 8 ++++++++ disk/loopback.c | 33 ++++++++------------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e6853371..2fc4a9793 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-07-20 Vladimir Serbinenko + + * 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 * util/i386/efi/grub-install.in: Revert to platform-specific behaviour diff --git a/disk/loopback.c b/disk/loopback.c index 1b525e05f..4990da710 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -28,7 +28,7 @@ struct grub_loopback { char *devname; - char *filename; + grub_file_t file; int has_partitions; struct grub_loopback *next; }; @@ -63,7 +63,7 @@ delete_loopback (const char *name) *prev = dev->next; grub_free (dev->devname); - grub_free (dev->filename); + grub_file_close (dev->file); grub_free (dev); return 0; @@ -91,9 +91,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) if (! file) 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. */ for (newdev = loopback_list; newdev; newdev = newdev->next) if (grub_strcmp (newdev->devname, args[0]) == 0) @@ -105,8 +102,8 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) if (! newname) return grub_errno; - grub_free (newdev->filename); - newdev->filename = newname; + grub_file_close (newdev->file); + newdev->file = file; /* Set has_partitions when `--partitions' was used. */ newdev->has_partitions = state[1].set; @@ -126,13 +123,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) return grub_errno; } - newdev->filename = grub_strdup (args[1]); - if (! newdev->filename) - { - grub_free (newdev->devname); - grub_free (newdev); - return grub_errno; - } + newdev->file = file; /* Set has_partitions when `--partitions' was used. */ newdev->has_partitions = state[1].set; @@ -160,7 +151,6 @@ grub_loopback_iterate (int (*hook) (const char *name)) static grub_err_t grub_loopback_open (const char *name, grub_disk_t disk) { - grub_file_t file; struct grub_loopback *dev; for (dev = loopback_list; dev; dev = dev->next) @@ -170,27 +160,20 @@ grub_loopback_open (const char *name, grub_disk_t disk) if (! dev) 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. */ - 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); disk->id = (unsigned long) dev; disk->has_partitions = dev->has_partitions; - disk->data = file; + disk->data = dev->file; return 0; } static void -grub_loopback_close (grub_disk_t disk) +grub_loopback_close (grub_disk_t disk __attribute__ ((unused))) { - grub_file_t file = (grub_file_t) disk->data; - - grub_file_close (file); } static grub_err_t From 5e3bec6716529da996700270d51bca17232da01c Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 20 Jul 2010 22:10:23 +0200 Subject: [PATCH 20/45] * tests/util/grub-shell-tester.in: Remove bashism and declare as sh script. --- ChangeLog | 5 +++++ tests/util/grub-shell-tester.in | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fc4a9793..5e3b7ff04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-07-20 Vladimir Serbinenko + + * tests/util/grub-shell-tester.in: Remove bashism and declare as + sh script. + 2010-07-20 Vladimir Serbinenko * disk/loopback.c (grub_loopback): Replace filename with file. diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index e9507c8f5..ed34a5e17 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -1,4 +1,4 @@ -#! /bin/bash -e +#! /bin/sh -e # Compares GRUB script output with BASH output. # Copyright (C) 2009,2010 Free Software Foundation, Inc. @@ -84,7 +84,7 @@ done if [ "x${source}" = x ] ; then tmpfile=`mktemp` - while read; do + while read REPLY; do echo $REPLY >> ${tmpfile} done source=${tmpfile} From dd8ff5c9e9aae0cbfe27b6195ba3a256ba454351 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 22:00:18 +0100 Subject: [PATCH 21/45] 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. --- ChangeLog | 8 ++++++++ term/efi/console.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5e3b7ff04..681b6fd24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-07-20 Colin Watson + + 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 * tests/util/grub-shell-tester.in: Remove bashism and declare as diff --git a/term/efi/console.c b/term/efi/console.c index d3240590b..dca002910 100644 --- a/term/efi/console.c +++ b/term/efi/console.c @@ -311,6 +311,20 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), 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 = { .name = "console", @@ -321,6 +335,8 @@ static struct grub_term_input grub_console_term_input = static struct grub_term_output grub_console_term_output = { .name = "console", + .init = grub_efi_console_init, + .fini = grub_efi_console_fini, .putchar = grub_console_putchar, .getwh = grub_console_getwh, .getxy = grub_console_getxy, From efc9d7f175cd1750d286be0aeec8414084394226 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 22:14:26 +0100 Subject: [PATCH 22/45] * 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. --- ChangeLog | 7 +++++++ disk/loopback.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 681b6fd24..482874788 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-07-20 Colin Watson + + * 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 Disable EFI cursor when the EFI console becomes inactive. diff --git a/disk/loopback.c b/disk/loopback.c index 4990da710..509e9e33f 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -76,6 +76,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) struct grub_arg_list *state = state = cmd->state; grub_file_t file; struct grub_loopback *newdev; + grub_err_t ret; if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); @@ -100,7 +101,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) { char *newname = grub_strdup (args[1]); if (! newname) - return grub_errno; + goto fail; grub_file_close (newdev->file); newdev->file = file; @@ -114,13 +115,13 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) /* Unable to replace it, make a new entry. */ newdev = grub_malloc (sizeof (struct grub_loopback)); if (! newdev) - return grub_errno; + goto fail; newdev->devname = grub_strdup (args[0]); if (! newdev->devname) { grub_free (newdev); - return grub_errno; + goto fail; } newdev->file = file; @@ -133,6 +134,11 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args) loopback_list = newdev; return 0; + +fail: + ret = grub_errno; + grub_file_close (file); + return ret; } @@ -171,11 +177,6 @@ grub_loopback_open (const char *name, grub_disk_t disk) return 0; } -static void -grub_loopback_close (grub_disk_t disk __attribute__ ((unused))) -{ -} - static grub_err_t grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf) @@ -217,7 +218,6 @@ static struct grub_disk_dev grub_loopback_dev = .id = GRUB_DISK_DEVICE_LOOPBACK_ID, .iterate = grub_loopback_iterate, .open = grub_loopback_open, - .close = grub_loopback_close, .read = grub_loopback_read, .write = grub_loopback_write, .next = 0 From b26f1c116062715690eb91dc301cdbd844d8f793 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 23:09:45 +0100 Subject: [PATCH 23/45] * kern/emu/getroot.c (grub_util_get_grub_dev): Use xasprintf. --- ChangeLog | 4 ++++ kern/emu/getroot.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 482874788..0d06dee3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-20 Colin Watson + + * kern/emu/getroot.c (grub_util_get_grub_dev): Use xasprintf. + 2010-07-20 Colin Watson * disk/loopback.c (grub_cmd_loopback): Don't leak a grub_file_t diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 9f89bf657..58dbac9b4 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -695,7 +695,7 @@ grub_util_get_grub_dev (const char *os_dev) if (q) *q = ','; - asprintf (&grub_dev, "md/%s", p); + grub_dev = xasprintf ("md/%s", p); free (p); } else @@ -708,7 +708,7 @@ grub_util_get_grub_dev (const char *os_dev) if (mdadm_name) { free (grub_dev); - asprintf (&grub_dev, "md/%s", mdadm_name); + grub_dev = xasprintf ("md/%s", mdadm_name); free (mdadm_name); } } From c03507dfb87adb5ab6e5eb619ab9dd9d3d30642c Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Jul 2010 23:16:32 +0100 Subject: [PATCH 24/45] * 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. --- ChangeLog | 6 ++++++ bus/usb/emu/usb.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0d06dee3b..c05891b96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-20 Colin Watson + + * 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 * kern/emu/getroot.c (grub_util_get_grub_dev): Use xasprintf. diff --git a/bus/usb/emu/usb.c b/bus/usb/emu/usb.c index 187857b5b..7d52decb2 100644 --- a/bus/usb/emu/usb.c +++ b/bus/usb/emu/usb.c @@ -78,6 +78,12 @@ grub_libusb_devices (void) return GRUB_USB_ERR_NONE; } +void +grub_usb_poll_devices (void) +{ + /* TODO: recheck grub_usb_devs */ +} + int grub_usb_iterate (int (*hook) (grub_usb_device_t dev)) From a9600892c190269c25613fede79892a17f0490e0 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 22 Jul 2010 09:38:06 +0100 Subject: [PATCH 25/45] * disk/raid.c (insert_array): Don't count named arrays when looking for unused array numbers. Reported and tested by: maru. --- ChangeLog | 6 ++++++ disk/raid.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c05891b96..e3677b0e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-22 Colin Watson + + * disk/raid.c (insert_array): Don't count named arrays when looking + for unused array numbers. + Reported and tested by: maru. + 2010-07-20 Colin Watson * bus/usb/emu/usb.c (grub_usb_poll_devices): Add a dummy diff --git a/disk/raid.c b/disk/raid.c index 43d2a29ff..7dfd4bd81 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -533,7 +533,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, /* Check whether we don't have multiple arrays with the same number. */ for (p = array_list; p != NULL; p = p->next) { - if (p->number == array->number) + if (! p->name && p->number == array->number) break; } @@ -546,7 +546,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, { for (p = array_list; p != NULL; p = p->next) { - if (p->number == i) + if (! p->name && p->number == i) break; } From 697e053c44e75734ad4ae7520e63a80a83df4059 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 22 Jul 2010 09:44:19 +0100 Subject: [PATCH 26/45] real name for Michael Guntsche --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e3677b0e2..e0c2096bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ * disk/raid.c (insert_array): Don't count named arrays when looking for unused array numbers. - Reported and tested by: maru. + Reported and tested by: Michael Guntsche. 2010-07-20 Colin Watson From 0ac33bf5eb13bd185c903ac29a3ec36f0502c74f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 21 Jul 2010 06:44:38 +0200 Subject: [PATCH 27/45] * util/grub.d/00_header.in: Remove compatibility with terminal.mod prior to terminal_input/terminal_output separation. It's been over 1.5 years and those versions weren't widely deployed. --- ChangeLog | 6 ++++++ util/grub.d/00_header.in | 12 ++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0c2096bb..de1edebb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,12 @@ (grub_efi_console_fini): New function. (grub_console_term_output): Register init and fini methods. +2010-07-20 Vladimir Serbinenko + + * util/grub.d/00_header.in: Remove compatibility with terminal.mod + prior to terminal_input/terminal_output separation. It's been over 1.5 + years and those versions weren't widely deployed. + 2010-07-20 Vladimir Serbinenko * tests/util/grub-shell-tester.in: Remove bashism and declare as diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 75c8b0fa2..2f39650e9 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -137,11 +137,7 @@ case x${GRUB_TERMINAL_INPUT} in ;; x*) cat << EOF -if terminal_input ${GRUB_TERMINAL_INPUT} ; then true ; else - # For backward compatibility with versions of terminal.mod that don't - # understand terminal_input - terminal ${GRUB_TERMINAL_INPUT} -fi +terminal_input ${GRUB_TERMINAL_INPUT} EOF ;; esac @@ -152,11 +148,7 @@ case x${GRUB_TERMINAL_OUTPUT} in ;; x*) cat << EOF -if terminal_output ${GRUB_TERMINAL_OUTPUT} ; then true ; else - # For backward compatibility with versions of terminal.mod that don't - # understand terminal_output - terminal ${GRUB_TERMINAL_OUTPUT} -fi +terminal_output ${GRUB_TERMINAL_OUTPUT} EOF ;; esac From 463711215f2420d12fad9b45d9a02b8a01668651 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 28 Jul 2010 18:25:48 +0300 Subject: [PATCH 28/45] * util/ieee1275/grub-install.in: Don't use empty grub_device. Reported by: Lennart Sorensen. --- ChangeLog | 17 +++++++++++------ util/ieee1275/grub-install.in | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index de1edebb1..a2b6a2bc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-07-28 Vladimir Serbinenko + + * util/ieee1275/grub-install.in: Don't use empty grub_device. + Reported by: Lennart Sorensen. + +2010-07-20 Vladimir Serbinenko + + * util/grub.d/00_header.in: Remove compatibility with terminal.mod + prior to terminal_input/terminal_output separation. It's been over 1.5 + years and those versions weren't widely deployed. + 2010-07-22 Colin Watson * disk/raid.c (insert_array): Don't count named arrays when looking @@ -29,12 +40,6 @@ (grub_efi_console_fini): New function. (grub_console_term_output): Register init and fini methods. -2010-07-20 Vladimir Serbinenko - - * util/grub.d/00_header.in: Remove compatibility with terminal.mod - prior to terminal_input/terminal_output separation. It's been over 1.5 - years and those versions weren't widely deployed. - 2010-07-20 Vladimir Serbinenko * tests/util/grub-shell-tester.in: Remove bashism and declare as diff --git a/util/ieee1275/grub-install.in b/util/ieee1275/grub-install.in index 98fd5d65a..98de5f348 100644 --- a/util/ieee1275/grub-install.in +++ b/util/ieee1275/grub-install.in @@ -212,7 +212,7 @@ fi # this command is allowed to fail (--target=fs already grants us that the # filesystem will be accessible). partmap_module= -for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do +for x in `$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`; do partmap_module="$partmap_module part_$x"; done From 9f841f5cbfcdf52cb7a5e0f51e5239466f6fd67f Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 29 Jul 2010 15:06:39 +0200 Subject: [PATCH 29/45] 2010-07-29 Robert Millan * configure.ac: Remove grub-mkisofs checks. --- ChangeLog | 4 ++++ configure.ac | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2b6a2bc1..af48d4039 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-29 Robert Millan + + * configure.ac: Remove grub-mkisofs checks. + 2010-07-28 Vladimir Serbinenko * util/ieee1275/grub-install.in: Don't use empty grub_device. diff --git a/configure.ac b/configure.ac index 55c2625cb..aa7f3a151 100644 --- a/configure.ac +++ b/configure.ac @@ -249,13 +249,6 @@ fi # Check for functions. AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf) -# For grub-mkisofs -AC_HEADER_MAJOR -AC_HEADER_DIRENT -AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid) -AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h) -AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h limits.h) - # For opendisk() and getrawpartition() on NetBSD. # Used in util/deviceiter.c and in util/hostdisk.c. AC_CHECK_HEADER([util.h], [ From 0806b63c0964c456e667415a1d8d3fa8521ac14b Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Thu, 29 Jul 2010 18:46:42 +0200 Subject: [PATCH 30/45] 2010-07-29 Robert Millan * util/grub-probe.c (PRINT_FS_LABEL): New enum value. (probe): Handle `PRINT_FS_LABEL'. (main): Handle `-t fs_label'. --- ChangeLog | 6 ++++++ util/grub-probe.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index af48d4039..94b6741d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-29 Robert Millan + + * util/grub-probe.c (PRINT_FS_LABEL): New enum value. + (probe): Handle `PRINT_FS_LABEL'. + (main): Handle `-t fs_label'. + 2010-07-29 Robert Millan * configure.ac: Remove grub-mkisofs checks. diff --git a/util/grub-probe.c b/util/grub-probe.c index dff87907a..56cbc5592 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -50,6 +50,7 @@ enum { PRINT_FS, PRINT_FS_UUID, + PRINT_FS_LABEL, PRINT_DRIVE, PRINT_DEVICE, PRINT_PARTMAP, @@ -291,6 +292,16 @@ probe (const char *path, char *device_name) printf ("%s\n", uuid); } + else if (print == PRINT_FS_LABEL) + { + char *label; + if (! fs->label) + grub_util_error ("%s does not support labels", fs->name); + + fs->label (dev, &label); + + printf ("%s\n", label); + } end: if (dev) @@ -326,7 +337,7 @@ Probe device information for a given path (or device, if the -d option is given) \n\ -d, --device given argument is a system device, not a path\n\ -m, --device-map=FILE use FILE as the device map [default=%s]\n\ - -t, --target=(fs|fs_uuid|drive|device|partmap|abstraction)\n\ + -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction)\n\ print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ @@ -375,6 +386,8 @@ main (int argc, char *argv[]) print = PRINT_FS; else if (!strcmp (optarg, "fs_uuid")) print = PRINT_FS_UUID; + else if (!strcmp (optarg, "fs_label")) + print = PRINT_FS_LABEL; else if (!strcmp (optarg, "drive")) print = PRINT_DRIVE; else if (!strcmp (optarg, "device")) From f7790cdd5d0b97b2246478ec15efb25898fbb253 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 30 Jul 2010 11:27:02 +0200 Subject: [PATCH 31/45] 2010-07-30 Robert Millan * include/grub/emu/misc.h (grub_make_system_path_relative_to_its_root) (xmalloc, xrealloc, xstrdup, xasprintf): Add `warn_unused_result' attribute. * include/grub/misc.h (grub_strdup, grub_strndup, grub_strlen) (grub_xasprintf, grub_xvasprintf): Likewise. * include/grub/emu/misc.h (xasprintf): Remove duplicate prototype. --- ChangeLog | 9 +++++++++ include/grub/emu/misc.h | 11 +++++------ include/grub/misc.h | 10 +++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94b6741d3..4026428a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-07-30 Robert Millan + + * include/grub/emu/misc.h (grub_make_system_path_relative_to_its_root) + (xmalloc, xrealloc, xstrdup, xasprintf): Add + `warn_unused_result' attribute. + * include/grub/misc.h (grub_strdup, grub_strndup, grub_strlen) + (grub_xasprintf, grub_xvasprintf): Likewise. + * include/grub/emu/misc.h (xasprintf): Remove duplicate prototype. + 2010-07-29 Robert Millan * util/grub-probe.c (PRINT_FS_LABEL): New enum value. diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index f34cd4287..07257e511 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -26,12 +26,12 @@ extern const char *program_name; void grub_init_all (void); void grub_fini_all (void); -char *grub_make_system_path_relative_to_its_root (const char *path); +char *grub_make_system_path_relative_to_its_root (const char *path) __attribute__ ((warn_unused_result)); -void * EXPORT_FUNC(xmalloc) (grub_size_t size); -void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size); -char * EXPORT_FUNC(xstrdup) (const char *str); -char * EXPORT_FUNC(xasprintf) (const char *fmt, ...); +void * EXPORT_FUNC(xmalloc) (grub_size_t size) __attribute__ ((warn_unused_result)); +void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) __attribute__ ((warn_unused_result)); +char * EXPORT_FUNC(xstrdup) (const char *str) __attribute__ ((warn_unused_result)); +char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((warn_unused_result)); void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...); void EXPORT_FUNC(grub_util_info) (const char *fmt, ...); @@ -45,7 +45,6 @@ int EXPORT_FUNC(vasprintf) (char **buf, const char *fmt, va_list ap); int EXPORT_FUNC(asprintf) (char **buf, const char *fmt, ...); #endif -char * EXPORT_FUNC(xasprintf) (const char *fmt, ...); extern char * canonicalize_file_name (const char *path); #ifdef HAVE_DEVICE_MAPPER diff --git a/include/grub/misc.h b/include/grub/misc.h index 9194ca8ad..eab01b0fb 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -231,10 +231,10 @@ grub_strtol (const char *str, char **end, int base) } } -char *EXPORT_FUNC(grub_strdup) (const char *s); -char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n); +char *EXPORT_FUNC(grub_strdup) (const char *s) __attribute__ ((warn_unused_result)); +char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n) __attribute__ ((warn_unused_result)); void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); -grub_size_t EXPORT_FUNC(grub_strlen) (const char *s); +grub_size_t EXPORT_FUNC(grub_strlen) (const char *s) __attribute__ ((warn_unused_result)); int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -261,8 +261,8 @@ int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...) int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, va_list args); char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args); + __attribute__ ((format (printf, 1, 2))) __attribute__ ((warn_unused_result)); +char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) __attribute__ ((warn_unused_result)); void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, From a184f9c80105bafacccbfaea596d406db3bce362 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 30 Jul 2010 21:43:12 +0200 Subject: [PATCH 32/45] 2010-07-30 Robert Millan Enable `grub-probe -t device' resolution on ZFS. * configure.ac: Check for getfsstat(), libzfs and libnvpair. * include/grub/util/libnvpair.h: New file. * include/grub/util/libzfs.h: New file. * kern/emu/getroot.c: Include `' and `'. [HAVE_LIBZFS && HAVE_LIBNVPAIR]: Include `' and `'. [HAVE_GETFSSTAT]: Include `'. (find_mount_point_from_dir): New static function. [HAVE_LIBZFS && HAVE_LIBNVPAIR] (find_root_device_from_libzfs): New function. [HAVE_LIBZFS && HAVE_LIBNVPAIR] (grub_guess_root_device): Use find_root_device_from_libzfs() before ressorting to find_root_device(). * include/grub/util/misc.h (grub_util_init_libzfs): New function prototype. * util/misc.c: Include `'. (grub_util_init_libzfs): New function. [HAVE_LIBZFS] (libzfs_handle): New global variable. [HAVE_LIBZFS] (fini_libzfs): New static function. (grub_util_init_libzfs): New function. * util/grub-probe.c (main): Call grub_util_init_libzfs(). --- ChangeLog | 28 ++++++ configure.ac | 11 ++- include/grub/util/libnvpair.h | 31 +++++++ include/grub/util/libzfs.h | 39 +++++++++ include/grub/util/misc.h | 1 + kern/emu/getroot.c | 155 ++++++++++++++++++++++++++++++++++ util/grub-probe.c | 1 + util/misc.c | 20 +++++ 8 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 include/grub/util/libnvpair.h create mode 100644 include/grub/util/libzfs.h diff --git a/ChangeLog b/ChangeLog index 4026428a7..041f9cadd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2010-07-30 Robert Millan + + Enable `grub-probe -t device' resolution on ZFS. + + * configure.ac: Check for getfsstat(), libzfs and libnvpair. + * include/grub/util/libnvpair.h: New file. + * include/grub/util/libzfs.h: New file. + + * kern/emu/getroot.c: Include `' and `'. + [HAVE_LIBZFS && HAVE_LIBNVPAIR]: Include `' and + `'. + [HAVE_GETFSSTAT]: Include `'. + + (find_mount_point_from_dir): New static function. + [HAVE_LIBZFS && HAVE_LIBNVPAIR] (find_root_device_from_libzfs): New + function. + [HAVE_LIBZFS && HAVE_LIBNVPAIR] (grub_guess_root_device): Use + find_root_device_from_libzfs() before ressorting to find_root_device(). + + * include/grub/util/misc.h (grub_util_init_libzfs): New function + prototype. + * util/misc.c: Include `'. + (grub_util_init_libzfs): New function. + [HAVE_LIBZFS] (libzfs_handle): New global variable. + [HAVE_LIBZFS] (fini_libzfs): New static function. + (grub_util_init_libzfs): New function. + * util/grub-probe.c (main): Call grub_util_init_libzfs(). + 2010-07-30 Robert Millan * include/grub/emu/misc.h (grub_make_system_path_relative_to_its_root) diff --git a/configure.ac b/configure.ac index aa7f3a151..cc97c7f77 100644 --- a/configure.ac +++ b/configure.ac @@ -247,7 +247,7 @@ else fi # Check for functions. -AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf) +AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf getfsstat) # For opendisk() and getrawpartition() on NetBSD. # Used in util/deviceiter.c and in util/hostdisk.c. @@ -799,6 +799,15 @@ if test x"$device_mapper_excuse" = x ; then [device_mapper_excuse="need devmapper library"]) fi +AC_CHECK_LIB([zfs], [libzfs_init], + [LDFLAGS="$LDFLAGS -lzfs" + AC_DEFINE([HAVE_LIBZFS], [1], + [Define to 1 if you have the ZFS library.])],) +AC_CHECK_LIB([nvpair], [nvlist_print], + [LDFLAGS="$LDFLAGS -lnvpair" + AC_DEFINE([HAVE_LIBNVPAIR], [1], + [Define to 1 if you have the NVPAIR library.])],) + AC_SUBST(ASFLAGS) # Output files. diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h new file mode 100644 index 000000000..c4fe174ea --- /dev/null +++ b/include/grub/util/libnvpair.h @@ -0,0 +1,31 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_LIBNVPAIR_UTIL_HEADER +#define GRUB_LIBNVPAIR_UTIL_HEADER 1 + +#include /* FILE */ + +typedef void nvlist_t; + +int nvlist_lookup_string (nvlist_t *, const char *, char **); +int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **); +int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *); +void nvlist_print (FILE *, nvlist_t *); + +#endif diff --git a/include/grub/util/libzfs.h b/include/grub/util/libzfs.h new file mode 100644 index 000000000..a17c47e20 --- /dev/null +++ b/include/grub/util/libzfs.h @@ -0,0 +1,39 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_LIBZFS_UTIL_HEADER +#define GRUB_LIBZFS_UTIL_HEADER 1 + +#include + +typedef void libzfs_handle_t; +typedef void zpool_handle_t; + +extern libzfs_handle_t *libzfs_init (); +extern void libzfs_fini (libzfs_handle_t *); + +extern zpool_handle_t *zpool_open (libzfs_handle_t *, const char *); +extern void zpool_close (zpool_handle_t *); + +extern int zpool_get_physpath (zpool_handle_t *, const char *); + +extern nvlist_t *zpool_get_config (zpool_handle_t *, nvlist_t **); + +extern libzfs_handle_t *libzfs_handle; + +#endif diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 48dfbb868..699b9cf2c 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -59,5 +59,6 @@ char *make_system_path_relative_to_its_root (const char *path); char *canonicalize_file_name (const char *path); void grub_util_init_nls (void); +void grub_util_init_libzfs (void); #endif /* ! GRUB_UTIL_MISC_HEADER */ diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 58dbac9b4..f2f6311ff 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -20,11 +20,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -41,6 +43,15 @@ # include #endif +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) +# include +# include +#endif + +#ifdef HAVE_GETFSSTAT +# include +#endif + #include #include #include @@ -86,6 +97,62 @@ xgetcwd (void) return path; } +static char * +find_mount_point_from_dir (const char *dir) +{ + struct stat st; + typeof (st.st_dev) fs; + char *prev, *next, *slash, *statdir; + + if (stat (dir, &st) == -1) + error (1, errno, "stat (%s)", dir); + + fs = st.st_dev; + + prev = xstrdup (dir); + + while (1) + { + /* Remove last slash. */ + next = xstrdup (prev); + slash = strrchr (next, '/'); + if (! slash) + { + free (next); + free (prev); + return NULL; + } + *slash = '\0'; + + /* A next empty string counts as /. */ + if (next[0] == '\0') + statdir = "/"; + else + statdir = next; + + if (stat (statdir, &st) == -1) + error (1, errno, "stat (%s)", next); + + if (st.st_dev != fs) + { + /* Found mount point. */ + free (next); + return prev; + } + + free (prev); + prev = next; + + /* We've already seen an empty string, which means we + reached /. Nothing left to do. */ + if (prev[0] == '\0') + { + free (prev); + return xstrdup ("/"); + } + } +} + #ifdef __linux__ /* Statting something on a btrfs filesystem always returns a virtual device @@ -166,6 +233,88 @@ find_root_device_from_mountinfo (const char *dir) #endif /* __linux__ */ +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + +/* ZFS has similar problems to those of btrfs (see above). */ +static char * +find_root_device_from_libzfs (const char *dir) +{ + char *device = NULL; + char *poolname = NULL; + char *poolfs = NULL; + char *mnt_point; + char *slash; + + mnt_point = find_mount_point_from_dir (dir); + +#ifdef HAVE_GETFSSTAT + { + int mnt_count = getfsstat (NULL, 0, MNT_WAIT); + if (mnt_count == -1) + error (1, errno, "getfsstat"); + + struct statfs *mnt = xmalloc (mnt_count * sizeof (*mnt)); + + mnt_count = getfsstat (mnt, mnt_count * sizeof (*mnt), MNT_WAIT); + if (mnt_count == -1) + error (1, errno, "getfsstat"); + + unsigned int i; + for (i = 0; i < (unsigned) mnt_count; i++) + if (!strcmp (mnt[i].f_fstypename, "zfs") + && !strcmp (mnt[i].f_mntonname, mnt_point)) + { + poolname = xstrdup (mnt[i].f_mntfromname); + break; + } + + free (mnt); + } +#endif + + if (! poolname) + return NULL; + + slash = strchr (poolname, '/'); + if (slash) + { + *slash = '\0'; + poolfs = slash + 1; + } + + { + zpool_handle_t *zpool; + nvlist_t *nvlist; + nvlist_t **nvlist_array; + unsigned int nvlist_count; + + zpool = zpool_open (libzfs_handle, poolname); + nvlist = zpool_get_config (zpool, NULL); + + if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0) + error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")"); + + if (nvlist_lookup_nvlist_array (nvlist, "children", &nvlist_array, &nvlist_count) != 0) + error (1, errno, "nvlist_lookup_nvlist_array (\"children\")"); + + do + { + assert (nvlist_count > 0); + } while (nvlist_lookup_nvlist_array (nvlist_array[0], "children", + &nvlist_array, &nvlist_count) == 0); + + if (nvlist_lookup_string (nvlist_array[0], "path", &device) != 0) + error (1, errno, "nvlist_lookup_string (\"path\")"); + + zpool_close (zpool); + } + + free (poolname); + + return device; +} +#endif + #ifdef __MINGW32__ static char * @@ -458,6 +607,12 @@ grub_guess_root_device (const char *dir) return os_dev; #endif /* __linux__ */ +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + os_dev = find_root_device_from_libzfs (dir); + if (os_dev) + return os_dev; +#endif + if (stat (dir, &st) < 0) grub_util_error ("cannot stat `%s'", dir); diff --git a/util/grub-probe.c b/util/grub-probe.c index 56cbc5592..52f2b3747 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -359,6 +359,7 @@ main (int argc, char *argv[]) set_program_name (argv[0]); grub_util_init_nls (); + grub_util_init_libzfs (); /* Check for options. */ while (1) diff --git a/util/misc.c b/util/misc.c index 91bc25a55..0859197bf 100644 --- a/util/misc.c +++ b/util/misc.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -293,6 +294,25 @@ grub_util_init_nls (void) textdomain (PACKAGE); #endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */ } + +#ifdef HAVE_LIBZFS +libzfs_handle_t *libzfs_handle; + +static void +fini_libzfs (void) +{ + libzfs_fini (libzfs_handle); +} +#endif + +void +grub_util_init_libzfs (void) +{ +#ifdef HAVE_LIBZFS + libzfs_handle = libzfs_init (); + atexit (fini_libzfs); +#endif +} #endif int From c9a00aeeaa0d9c4d6b254fe2e221b67b951a48e7 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 30 Jul 2010 22:01:10 +0200 Subject: [PATCH 33/45] 2010-07-30 Robert Millan * include/grub/emu/misc.h: Add missing license header. --- ChangeLog | 4 ++++ include/grub/emu/misc.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 041f9cadd..86aba2914 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-30 Robert Millan + + * include/grub/emu/misc.h: Add missing license header. + 2010-07-30 Robert Millan Enable `grub-probe -t device' resolution on ZFS. diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index 07257e511..dc48d91a8 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #ifndef GRUB_EMU_MISC_H #define GRUB_EMU_MISC_H 1 From 3169f4c76a37a1545d7382a5dd483e36d00da5c3 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 31 Jul 2010 12:22:01 +0200 Subject: [PATCH 34/45] 2010-07-31 Robert Millan * configure.ac: Check for `libzfs.h' and `libnvpair.h'. * include/grub/util/libnvpair.h: Include `'. [HAVE_LIBNVPAIR_H]: Include `' instead of declaring libnvpair prototypes ourselves. * include/grub/util/libzfs.h: Include `'. [HAVE_LIBZFS_H]: Include `' instead of declaring libzfs prototypes ourselves. (libzfs_handle): Moved to ... * include/grub/util/misc.h (libzfs_handle): ... here. Include `'. --- ChangeLog | 15 +++++++++++++++ configure.ac | 3 ++- include/grub/util/libnvpair.h | 8 ++++++++ include/grub/util/libzfs.h | 8 +++++++- include/grub/util/misc.h | 3 +++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86aba2914..58b821da9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-07-31 Robert Millan + + * configure.ac: Check for `libzfs.h' and `libnvpair.h'. + + * include/grub/util/libnvpair.h: Include `'. + [HAVE_LIBNVPAIR_H]: Include `' instead of + declaring libnvpair prototypes ourselves. + * include/grub/util/libzfs.h: Include `'. + [HAVE_LIBZFS_H]: Include `' instead of + declaring libzfs prototypes ourselves. + + (libzfs_handle): Moved to ... + * include/grub/util/misc.h (libzfs_handle): ... here. + Include `'. + 2010-07-30 Robert Millan * include/grub/emu/misc.h: Add missing license header. diff --git a/configure.ac b/configure.ac index cc97c7f77..6169a2fb5 100644 --- a/configure.ac +++ b/configure.ac @@ -246,8 +246,9 @@ else AC_PATH_PROG(HELP2MAN, help2man) fi -# Check for functions. +# Check for functions and headers. AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf getfsstat) +AC_CHECK_HEADERS(libzfs.h libnvpair.h) # For opendisk() and getrawpartition() on NetBSD. # Used in util/deviceiter.c and in util/hostdisk.c. diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h index c4fe174ea..26f7e9d0f 100644 --- a/include/grub/util/libnvpair.h +++ b/include/grub/util/libnvpair.h @@ -19,6 +19,12 @@ #ifndef GRUB_LIBNVPAIR_UTIL_HEADER #define GRUB_LIBNVPAIR_UTIL_HEADER 1 +#include + +#ifdef HAVE_LIBNVPAIR_H +#include +#else /* ! HAVE_LIBNVPAIR_H */ + #include /* FILE */ typedef void nvlist_t; @@ -28,4 +34,6 @@ int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **); int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *); void nvlist_print (FILE *, nvlist_t *); +#endif /* ! HAVE_LIBNVPAIR_H */ + #endif diff --git a/include/grub/util/libzfs.h b/include/grub/util/libzfs.h index a17c47e20..9fbfd40d1 100644 --- a/include/grub/util/libzfs.h +++ b/include/grub/util/libzfs.h @@ -19,6 +19,12 @@ #ifndef GRUB_LIBZFS_UTIL_HEADER #define GRUB_LIBZFS_UTIL_HEADER 1 +#include + +#ifdef HAVE_LIBZFS_H +#include +#else /* ! HAVE_LIBZFS_H */ + #include typedef void libzfs_handle_t; @@ -34,6 +40,6 @@ extern int zpool_get_physpath (zpool_handle_t *, const char *); extern nvlist_t *zpool_get_config (zpool_handle_t *, nvlist_t **); -extern libzfs_handle_t *libzfs_handle; +#endif /* ! HAVE_LIBZFS_H */ #endif diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 699b9cf2c..3614c79c2 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -29,6 +29,7 @@ #include #include #include +#include char *grub_util_get_path (const char *dir, const char *file); size_t grub_util_get_fp_size (FILE *fp); @@ -59,6 +60,8 @@ char *make_system_path_relative_to_its_root (const char *path); char *canonicalize_file_name (const char *path); void grub_util_init_nls (void); + void grub_util_init_libzfs (void); +extern libzfs_handle_t *libzfs_handle; #endif /* ! GRUB_UTIL_MISC_HEADER */ From 8072efebf210fbc610ae852750e3f400305dfc69 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 31 Jul 2010 18:45:57 +0200 Subject: [PATCH 35/45] 2010-07-31 Robert Millan * kern/emu/misc.c: Add missing license header. --- ChangeLog | 4 ++++ kern/emu/misc.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 58b821da9..24303ff17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-31 Robert Millan + + * kern/emu/misc.c: Add missing license header. + 2010-07-31 Robert Millan * configure.ac: Check for `libzfs.h' and `libnvpair.h'. diff --git a/kern/emu/misc.c b/kern/emu/misc.c index 38395fca8..851da7a07 100644 --- a/kern/emu/misc.c +++ b/kern/emu/misc.c @@ -1,3 +1,21 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + #include #include From 3710bb6b96ba84767e9315b8eecfd31c8b2386de Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 1 Aug 2010 02:14:07 +0200 Subject: [PATCH 36/45] 2010-07-31 Robert Millan * util/grub.d/10_kfreebsd.in: Make module handling more generic. --- ChangeLog | 4 ++++ util/grub.d/10_kfreebsd.in | 25 ++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24303ff17..249256083 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-07-31 Robert Millan + + * util/grub.d/10_kfreebsd.in: Make module handling more generic. + 2010-07-31 Robert Millan * kern/emu/misc.c: Add missing license header. diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 9915abdf1..f32da3013 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -51,6 +51,10 @@ kfreebsd_entry () if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi + if [ -z "${prepare_module_dir_cache}" ]; then + prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")" + fi + printf '%s\n' "${prepare_boot_cache}" cat << EOF echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})' @@ -63,9 +67,10 @@ EOF EOF fi - if test -n "${acpi_ko}" ; then + if test -e "${module_dir}/acpi.ko" ; then + printf '%s\n' "${prepare_module_dir_cache}" cat << EOF - kfreebsd_module_elf ${acpi_ko_rel_dirname}/${acpi_ko_basename} + kfreebsd_module_elf ${module_dir_rel}/acpi.ko EOF fi @@ -103,19 +108,17 @@ while [ "x$list" != "x" ] ; do version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"` alt_version=`echo $version | sed -e "s,\.old$,,g"` - acpi_ko= - for i in "/lib/modules/${version}/acpi.ko" "/lib/modules/${alt_version}/acpi.ko" \ - "/boot/kernel/acpi.ko"; do + module_dir= + for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \ + "/boot/kernel"; do if test -e "$i" ; then - acpi_ko="$i" + module_dir="$i" break fi done - if test -n "${acpi_ko}" ; then - echo "Found ACPI module: ${acpi_ko}" >&2 - acpi_ko_basename=`basename ${acpi_ko}` - acpi_ko_dirname=`dirname ${acpi_ko}` - acpi_ko_rel_dirname=`make_system_path_relative_to_its_root $acpi_ko_dirname` + if test -n "${module_dir}" ; then + echo "Found kernel module directory: ${module_dir}" >&2 + module_dir_rel=$(make_system_path_relative_to_its_root $module_dir) fi kfreebsd_entry "${OS}" "${version}" From ebf53056b8e17487c9f56effe9130f5772a93e02 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 1 Aug 2010 14:47:14 +0200 Subject: [PATCH 37/45] 2010-08-01 Robert Millan * kern/emu/getroot.c: Include `'. --- ChangeLog | 4 ++++ kern/emu/getroot.c | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 249256083..f34ed35c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-08-01 Robert Millan + + * kern/emu/getroot.c: Include `'. + 2010-07-31 Robert Millan * util/grub.d/10_kfreebsd.in: Make module handling more generic. diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index f2f6311ff..6caae08e6 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef __GNU__ #include From ce04ef47e2ef22cc3886b88beba2e58e8d115702 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 1 Aug 2010 08:54:10 -0500 Subject: [PATCH 38/45] * util/grub.d/20_linux_xen.in: Don't use UUID for LVM root (matching util/grub.d/10_linux.in). Fixes Debian bug #591093. --- ChangeLog | 5 +++++ util/grub.d/20_linux_xen.in | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f34ed35c9..abe698574 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-08-01 Colin Watson + + * util/grub.d/20_linux_xen.in: Don't use UUID for LVM root (matching + util/grub.d/10_linux.in). Fixes Debian bug #591093. + 2010-08-01 Robert Millan * kern/emu/getroot.c: Include `'. diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 8612c96b0..e631c0a4a 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -44,7 +44,8 @@ case ${GRUB_DEVICE} in esac if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ - || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then LINUX_ROOT_DEVICE=${GRUB_DEVICE} else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} From deb0caa38ebc69aa7135d56896a6e61d0642ba3c Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sun, 1 Aug 2010 15:23:44 +0200 Subject: [PATCH 39/45] 2010-08-01 Robert Millan Prevent accidental use of uninitialized libzfs_handle. * util/grub-probe.c (main): Move grub_util_init_libzfs() call to ... * kern/emu/getroot.c (find_root_device_from_libzfs): ... here. * util/misc.c (grub_util_init_libzfs): Make this function idempotent. --- ChangeLog | 8 ++++++++ kern/emu/getroot.c | 2 ++ util/grub-probe.c | 1 - util/misc.c | 7 +++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index abe698574..20094fec8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-08-01 Robert Millan + + Prevent accidental use of uninitialized libzfs_handle. + + * util/grub-probe.c (main): Move grub_util_init_libzfs() call to ... + * kern/emu/getroot.c (find_root_device_from_libzfs): ... here. + * util/misc.c (grub_util_init_libzfs): Make this function idempotent. + 2010-08-01 Colin Watson * util/grub.d/20_linux_xen.in: Don't use UUID for LVM root (matching diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index 6caae08e6..f8eda2294 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -289,6 +289,8 @@ find_root_device_from_libzfs (const char *dir) nvlist_t **nvlist_array; unsigned int nvlist_count; + grub_util_init_libzfs (); + zpool = zpool_open (libzfs_handle, poolname); nvlist = zpool_get_config (zpool, NULL); diff --git a/util/grub-probe.c b/util/grub-probe.c index 52f2b3747..56cbc5592 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -359,7 +359,6 @@ main (int argc, char *argv[]) set_program_name (argv[0]); grub_util_init_nls (); - grub_util_init_libzfs (); /* Check for options. */ while (1) diff --git a/util/misc.c b/util/misc.c index 0859197bf..2eff256bf 100644 --- a/util/misc.c +++ b/util/misc.c @@ -309,8 +309,11 @@ void grub_util_init_libzfs (void) { #ifdef HAVE_LIBZFS - libzfs_handle = libzfs_init (); - atexit (fini_libzfs); + if (! libzfs_handle) + { + libzfs_handle = libzfs_init (); + atexit (fini_libzfs); + } #endif } #endif From 7decd202a72cbed9d1e1d445d6fbea9532703866 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sun, 1 Aug 2010 09:44:36 -0500 Subject: [PATCH 40/45] * kern/misc.c (grub_memset): Optimise to reduce cache stalls. Also-By: Colin Watson --- ChangeLog | 5 +++++ kern/misc.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20094fec8..d00fd9d51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-08-01 Vladimir Serbinenko +2010-08-01 Colin Watson + + * kern/misc.c (grub_memset): Optimise to reduce cache stalls. + 2010-08-01 Robert Millan Prevent accidental use of uninitialized libzfs_handle. diff --git a/kern/misc.c b/kern/misc.c index c13c96e30..b37ef230c 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -518,12 +518,39 @@ grub_strndup (const char *s, grub_size_t n) } void * -grub_memset (void *s, int c, grub_size_t n) +grub_memset (void *s, int c, grub_size_t len) { - unsigned char *p = (unsigned char *) s; + void *p = s; + grub_uint8_t pattern8 = c; - while (n--) - *p++ = (unsigned char) c; + if (len >= 3 * sizeof (unsigned long)) + { + unsigned long patternl = 0; + grub_size_t i; + + for (i = 0; i < sizeof (unsigned long); i++) + patternl |= ((unsigned long) pattern8) << (8 * i); + + while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1))) + { + *(grub_uint8_t *) p = pattern8; + p = (grub_uint8_t *) p + 1; + len--; + } + while (len >= sizeof (unsigned long)) + { + *(unsigned long *) p = patternl; + p = (unsigned long *) p + 1; + len -= sizeof (unsigned long); + } + } + + while (len > 0) + { + *(grub_uint8_t *) p = pattern8; + p = (grub_uint8_t *) p + 1; + len--; + } return s; } From 2cfb45df5ed7be7b55c69dc0f809343e189afdb9 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 1 Aug 2010 11:25:09 -0500 Subject: [PATCH 41/45] * docs/grub.texi (Simple configuration): Document GRUB_CMDLINE_XEN and GRUB_CMDLINE_XEN_DEFAULT. Recommend setting GRUB_GFXPAYLOAD_LINUX=text rather than unsetting it in order to disable gfxpayload. (Shell-like scripting): Add real content. (Serial terminal): Suggest `terminal_input serial; terminal_output serial' rather than putting the two commands on separate lines, since console input will be inoperative after the first command. (menuentry): Document --class, --users, and --hotkey options. (terminfo): Describe what `visually-ordered UTF-8' means (thanks, Vladimir Serbinenko). --- ChangeLog | 14 ++++ docs/grub.texi | 182 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 186 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index d00fd9d51..1c1533841 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-08-01 Colin Watson + + * docs/grub.texi (Simple configuration): Document GRUB_CMDLINE_XEN + and GRUB_CMDLINE_XEN_DEFAULT. Recommend setting + GRUB_GFXPAYLOAD_LINUX=text rather than unsetting it in order to + disable gfxpayload. + (Shell-like scripting): Add real content. + (Serial terminal): Suggest `terminal_input serial; terminal_output + serial' rather than putting the two commands on separate lines, + since console input will be inoperative after the first command. + (menuentry): Document --class, --users, and --hotkey options. + (terminfo): Describe what `visually-ordered UTF-8' means (thanks, + Vladimir Serbinenko). + 2010-08-01 Vladimir Serbinenko 2010-08-01 Colin Watson diff --git a/docs/grub.texi b/docs/grub.texi index a191ef9ef..583cf98cb 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1062,6 +1062,11 @@ only to the default menu entry, after those listed in As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for NetBSD. +@item GRUB_CMDLINE_XEN +@itemx GRUB_CMDLINE_XEN_DEFAULT +As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for +Linux and Xen. + @item GRUB_DISABLE_LINUX_UUID Normally, @command{grub-mkconfig} will generate menu entries that use universally-unique identifiers (UUIDs) to identify the root filesystem to @@ -1113,8 +1118,8 @@ try several modes in sequence. Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the -boot sequence. If you have problems, simply unset this option and GRUB will -tell Linux to boot in normal text mode. +boot sequence. If you have problems, set this option to @samp{text} and +GRUB will tell Linux to boot in normal text mode. @item GRUB_DISABLE_OS_PROBER Normally, @command{grub-mkconfig} will try to use the external @@ -1143,6 +1148,142 @@ that file, making sure to leave at least the first two lines intact. @node Shell-like scripting @section Writing full configuration files directly +@c Some of this section is derived from the GNU Bash manual page, also +@c copyrighted by the FSF. + +@file{grub.cfg} is written in GRUB's built-in scripting language, which has +a syntax quite similar to that of GNU Bash and other Bourne shell +derivatives. + +@heading Words + +A @dfn{word} is a sequence of characters considered as a single unit by +GRUB. Words are separated by @dfn{metacharacters}, which are the following +plus space, tab, and newline: + +@example +@{ @} | & $ ; < > +@end example + +Quoting may be used to include metacharacters in words; see below. + +@heading Reserved words + +Reserved words have a special meaning to GRUB. The following words are +recognised as reserved when unquoted and either the first word of a simple +command or the third word of a @code{for} command: + +@example +! [[ ]] @{ @} +case do done elif else esac fi for function +if in menuentry select then time until while +@end example + +Not all of these reserved words have a useful purpose yet; some are reserved +for future expansion. + +@heading Quoting + +Quoting is used to remove the special meaning of certain characters or +words. It can be used to treat metacharacters as part of a word, to prevent +reserved words from being recognised as such, and to prevent variable +expansion. + +There are three quoting mechanisms: the escape character, single quotes, and +double quotes. + +A non-quoted backslash (\) is the @dfn{escape character}. It preserves the +literal value of the next character that follows, with the exception of +newline. + +Enclosing characters in single quotes preserves the literal value of each +character within the quotes. A single quote may not occur between single +quotes, even when preceded by a backslash. + +Enclosing characters in double quotes preserves the literal value of all +characters within the quotes, with the exception of @samp{$} and @samp{\}. +The @samp{$} character retains its special meaning within double quotes. +The backslash retains its special meaning only when followed by one of the +following characters: @samp{$}, @samp{"}, @samp{\}, or newline. A +backslash-newline pair is treated as a line continuation (that is, it is +removed from the input stream and effectively ignored). A double quote may +be quoted within double quotes by preceding it with a backslash. + +@heading Variable expansion + +The @samp{$} character introduces variable expansion. The variable name to +be expanded may be enclosed in braces, which are optional but serve to +protect the variable to be expanded from characters immediately following it +which could be interpreted as part of the name. + +Normal variable names begin with an alphabetic character, followed by zero +or more alphanumeric characters. + +Positional variable names consist of one or more digits. These are reserved +for future expansion. + +The special variable name @samp{?} expands to the exit status of the most +recently executed command. + +@heading Comments + +A word beginning with @samp{#} causes that word and all remaining characters +on that line to be ignored. + +@heading Simple commands + +A @dfn{simple command} is a sequence of words separated by spaces or tabs +and terminated by a semicolon or a newline. The first word specifies the +command to be executed. The remaining words are passed as arguments to the +invoked command. + +The return value of a simple command is its exit status. + +@heading Compound commands + +A @dfn{compound command} is one of the following: + +@table @asis +@item for @var{name} in @var{word} @dots{}; do @var{list}; done +The list of words following @code{in} is expanded, generating a list of +items. The variable @var{name} is set to each element of this list in turn, +and @var{list} is executed each time. The return value is the exit status +of the last command that executes. If the expansion of the items following +@code{in} results in an empty list, no commands are executed, and the return +status is 0. + +@item if @var{list}; then @var{list}; [elif @var{list}; then @var{list};] @dots{} [else @var{list};] fi +The @code{if} @var{list} is executed. If its exit status is zero, the +@code{then} @var{list} is executed. Otherwise, each @code{elif} @var{list} +is executed in turn, and if its exit status is zero, the corresponding +@code{then} @var{list} is executed and the command completes. Otherwise, +the @code{else} @var{list} is executed, if present. The exit status is the +exit status of the last command executed, or zero if no condition tested +true. + +@item while @var{cond}; do @var{list}; done +@itemx until @var{cond}; do @var{list}; done +The @code{while} command continuously executes the @code{do} @var{list} as +long as the last command in @var{cond} returns an exit status of zero. The +@code{until} command is identical to the @code{while} command, except that +the test is negated; the @code{do} @var{list} is executed as long as the +last command in @var{cond} returns a non-zero exit status. The exit status +of the @code{while} and @code{until} commands is the exit status of the last +@code{do} @var{list} command executed, or zero if none was executed. + +@item function @var{name} @{ @var{command}; @dots{} @} +This defines a function named @var{name}. The @dfn{body} of the function is +the list of commands within braces, each of which must be terminated with a +semicolon or a newline. This list of commands will be executed whenever +@var{name} is specified as the name of a simple command. Function +definitions do not affect the exit status in @code{$?}. When executed, the +exit status of a function is the exit status of the last command executed in +the body. + +@item menuentry @var{title} [@option{--class=class} @dots{}] [@option{--users=users}] [@option{--hotkey=key}] @{ @var{command}; @dots{} @} +@xref{menuentry}. +@end table + @node Embedded configuration @section Embedding a configuration file into GRUB @@ -1308,8 +1449,7 @@ simple. Here is an example: @example @group grub> @kbd{serial --unit=0 --speed=9600} -grub> @kbd{terminal_input serial} -grub> @kbd{terminal_output serial} +grub> @kbd{terminal_input serial; terminal_output serial} @end group @end example @@ -1320,11 +1460,14 @@ command accepts many other options, so please refer to @ref{serial}, for more details. The commands @command{terminal_input} (@pxref{terminal_input}) and -@command{terminal_output} (@pxref{terminal_output} choose which type of +@command{terminal_output} (@pxref{terminal_output}) choose which type of terminal you want to use. In the case above, the terminal will be a serial terminal, but you can also pass @code{console} to the command, as @samp{terminal serial console}. In this case, a terminal in which -you press any key will be selected as a GRUB terminal. +you press any key will be selected as a GRUB terminal. In the example above, +note that you need to put both commands on the same command line, as you +will lose the ability to type commands on the console after the first +command. However, note that GRUB assumes that your terminal emulator is compatible with VT100 by default. This is true for most terminal @@ -1789,9 +1932,26 @@ These commands can only be used in the menu: @node menuentry @subsection menuentry -@deffn Command title name @dots{} -Start a new boot entry, and set its name to the contents of the rest of -the line, starting with the first non-space character. +@deffn Command menuentry @var{title} @ + [@option{--class=class} @dots{}] [@option{--users=users}] @ + [@option{--hotkey=key}] @ + @{ @var{command}; @dots{} @} +This defines a GRUB menu entry named @var{title}. When this entry is +selected from the menu, GRUB will set the @var{chosen} environment variable +to @var{title}, execute the list of commands given within braces, and if the +last command in the list returned successfully and a kernel was loaded it +will execute the @command{boot} command. + +The @option{--class} option may be used any number of times to group menu +entries into classes. Menu themes may display different classes using +different styles. + +The @option{--users} option grants specific users access to specific menu +entries. @xref{Security}. + +The @option{--hotkey} option associates a hotkey with a menu entry. +@var{key} may be a single letter, or one of the aliases @samp{backspace}, +@samp{tab}, or @samp{delete}. @end deffn @@ -1885,7 +2045,9 @@ The @option{-a} (@option{--ascii}), @option{-u} (@option{--utf8}), and @option{-v} (@option{--visual-utf8}) options control how non-ASCII text is displayed. @option{-a} specifies an ASCII-only terminal; @option{-u} specifies logically-ordered UTF-8; and @option{-v} specifies -visually-ordered UTF-8. +"visually-ordered UTF-8" (in other words, arranged such that a terminal +emulator without bidirectional text support will display right-to-left text +in the proper order; this is not really proper UTF-8, but a workaround). If no option or terminal type is specified, the current terminal type is printed. From 6eea041aa4dae2be3ffe42786dce894d8d89dfba Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 1 Aug 2010 11:28:12 -0500 Subject: [PATCH 42/45] * script/yylex.l (NAME): Remove [:digit:], redundant with [:alnum:]. --- ChangeLog | 4 ++++ script/yylex.l | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1c1533841..83ac0b37b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-08-01 Colin Watson + + * script/yylex.l (NAME): Remove [:digit:], redundant with [:alnum:]. + 2010-08-01 Colin Watson * docs/grub.texi (Simple configuration): Document GRUB_CMDLINE_XEN diff --git a/script/yylex.l b/script/yylex.l index 7d4ea9e4e..e9659832b 100644 --- a/script/yylex.l +++ b/script/yylex.l @@ -116,7 +116,7 @@ COMMENT #.*$ CHAR [^{}|&$;<> \t\n\'\"\\] DIGITS [[:digit:]]+ -NAME [[:alpha:]_][[:alnum:][:digit:]_]* +NAME [[:alpha:]_][[:alnum:]_]* ESC \\. VARIABLE ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|$\?|$\{\?\} From ea9be8eadb4d899eb6bc740b360de292695aacf9 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 1 Aug 2010 11:30:03 -0500 Subject: [PATCH 43/45] * util/grub-mkrescue.in: Remove ${efi_dir} after building efi.img. --- ChangeLog | 4 ++++ util/grub-mkrescue.in | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 83ac0b37b..9729f71d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-08-01 Colin Watson + + * util/grub-mkrescue.in: Remove ${efi_dir} after building efi.img. + 2010-08-01 Colin Watson * script/yylex.l (NAME): Remove [:digit:], redundant with [:alnum:]. diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index e498acee7..b7d9eb4eb 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -296,6 +296,7 @@ if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img :: mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/ + rm -rf ${efi_dir} grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" fi From 8687cf071e646a5c949b7cbcf14f6ea9334ec466 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 1 Aug 2010 16:11:27 +0200 Subject: [PATCH 44/45] * kern/emu/getroot.c (find_mount_point_from_dir): Compile only if [HAVE_LIBZFS && HAVE_LIBNVPAIR] --- ChangeLog | 7 ++++++- kern/emu/getroot.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9729f71d8..2e8c0daa5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-08-01 Vladimir Serbinenko + + * kern/emu/getroot.c (find_mount_point_from_dir): Compile only if + [HAVE_LIBZFS && HAVE_LIBNVPAIR] + 2010-08-01 Colin Watson * util/grub-mkrescue.in: Remove ${efi_dir} after building efi.img. @@ -41,7 +46,7 @@ 2010-08-01 Robert Millan * kern/emu/getroot.c: Include `'. - + 2010-07-31 Robert Millan * util/grub.d/10_kfreebsd.in: Make module handling more generic. diff --git a/kern/emu/getroot.c b/kern/emu/getroot.c index f8eda2294..032608d1b 100644 --- a/kern/emu/getroot.c +++ b/kern/emu/getroot.c @@ -98,6 +98,8 @@ xgetcwd (void) return path; } +#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + static char * find_mount_point_from_dir (const char *dir) { @@ -154,6 +156,8 @@ find_mount_point_from_dir (const char *dir) } } +#endif + #ifdef __linux__ /* Statting something on a btrfs filesystem always returns a virtual device From 553df63d76cf4a5b6fa63042021320e5b6d6a5d4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 1 Aug 2010 21:01:05 +0200 Subject: [PATCH 45/45] * lib/arg.c (grub_arg_show_help): Add the necessary spacing. --- ChangeLog | 4 ++++ lib/arg.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e8c0daa5..bc6b8fd18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-08-01 Vladimir Serbinenko + + * lib/arg.c (grub_arg_show_help): Add the necessary spacing. + 2010-08-01 Vladimir Serbinenko * kern/emu/getroot.c (find_mount_point_from_dir): Compile only if diff --git a/lib/arg.c b/lib/arg.c index 400314d30..a9b8a520e 100644 --- a/lib/arg.c +++ b/lib/arg.c @@ -144,8 +144,10 @@ grub_arg_show_help (grub_extcmd_t cmd) } } - /* FIXME: add spacing back. */ - grub_xputs (_(opt->doc)); + while (spacing--) + grub_xputs (" "); + + grub_printf ("%s\n", _(opt->doc)); switch (opt->shortarg) {