From 56a4b23d37ac352169f85fdbfab99d3c219cdbb2 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 00:49:45 +0200 Subject: [PATCH 01/12] fix several issues with nested labels --- Makefile.util.def | 3 + grub-core/Makefile.core.def | 10 +++ grub-core/partmap/bsdlabel.c | 120 +++++++++++++++++++++++++++---- grub-core/partmap/msdos.c | 12 +++- grub-core/partmap/netbsdlabel.c | 2 + grub-core/partmap/openbsdlabel.c | 2 + include/grub/partition.h | 4 ++ 7 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 grub-core/partmap/netbsdlabel.c create mode 100644 grub-core/partmap/openbsdlabel.c diff --git a/Makefile.util.def b/Makefile.util.def index 35bcd81b2..20224cf02 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -89,6 +89,9 @@ library = { common = grub-core/partmap/msdos.c; common = grub-core/partmap/sun.c; common = grub-core/partmap/sunpc.c; + common = grub-core/partmap/bsdlabel.c; + common = grub-core/partmap/netbsdlabel.c; + common = grub-core/partmap/openbsdlabel.c; common = grub-core/script/function.c; common = grub-core/script/lexer.c; common = grub-core/script/main.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 353b9d123..4f28c54f4 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1208,6 +1208,16 @@ module = { common = partmap/bsdlabel.c; }; +module = { + name = part_netbsd; + common = partmap/netbsdlabel.c; +}; + +module = { + name = part_openbsd; + common = partmap/openbsdlabel.c; +}; + module = { name = part_sunpc; common = partmap/sunpc.c; diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index a27b8eaec..3d481843a 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef GRUB_UTIL #include @@ -32,9 +33,9 @@ static struct grub_partition_map grub_bsdlabel_partition_map; static grub_err_t -bsdlabel_partition_map_iterate (grub_disk_t disk, - int (*hook) (grub_disk_t disk, - const grub_partition_t partition)) +iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition_bsd_disk_label label; struct grub_partition p; @@ -42,22 +43,27 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, unsigned pos; /* Read the BSD label. */ - if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, - 0, sizeof (label), &label)) + if (grub_disk_read (disk, sector, 0, sizeof (label), &label)) return grub_errno; /* Check if it is valid. */ if (label.magic != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); + { + grub_dprintf ("partition", + "bad signature (found 0x%08x, expected 0x%08x)\n", + label.magic, + grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)); + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); + } /* A kludge to determine a base of be.offset. */ if (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION - < grub_cpu_to_le16 (label.num_partitions)) + < grub_cpu_to_le16 (label.num_partitions) && freebsd) { struct grub_partition_bsd_entry whole_disk_be; - pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR - * GRUB_DISK_SECTOR_SIZE + sizeof (struct grub_partition_bsd_entry) + pos = sizeof (label) + sector * GRUB_DISK_SECTOR_SIZE + + sizeof (struct grub_partition_bsd_entry) * GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION; if (grub_disk_read (disk, pos / GRUB_DISK_SECTOR_SIZE, @@ -68,8 +74,10 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, delta = grub_le_to_cpu32 (whole_disk_be.offset); } - pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR - * GRUB_DISK_SECTOR_SIZE; + pos = sizeof (label) + sector * GRUB_DISK_SECTOR_SIZE; + + grub_dprintf ("partition", "bsdlabel with %d partitions detected\n", + grub_cpu_to_le16 (label.num_partitions)); for (p.number = 0; p.number < grub_cpu_to_le16 (label.num_partitions); @@ -124,24 +132,112 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, if (hook (disk, &p)) return grub_errno; } - return GRUB_ERR_NONE; } +#if !defined (NETBSDLABEL) && !defined (OPENBSDLABEL) + +static grub_err_t +bsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + + if (disk->partition && grub_strcmp (disk->partition->partmap->name, "msdos") + == 0 && disk->partition->msdostype == GRUB_PC_PARTITION_TYPE_FREEBSD) + { + grub_dprintf ("partition", "FreeBSD embedded iterating\n"); + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1, + hook); + } + + if (disk->partition + && (grub_strcmp (disk->partition->partmap->name, "msdos") == 0 + || grub_strcmp (disk->partition->partmap->name, "bsd") == 0 + || grub_strcmp (disk->partition->partmap->name, "netbsd") == 0 + || grub_strcmp (disk->partition->partmap->name, "openbsd") == 0)) + { + grub_dprintf ("partition", "no embedded iterating\n"); + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); + } + + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, hook); +} + +#else + +#ifdef OPENBSDLABEL +#define GRUB_PC_PARTITION_TYPE_BSD GRUB_PC_PARTITION_TYPE_OPENBSD +#else +#define GRUB_PC_PARTITION_TYPE_BSD GRUB_PC_PARTITION_TYPE_NETBSD +#endif + +static grub_err_t +bsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + grub_err_t err; + + if (disk->partition && grub_strcmp (disk->partition->partmap->name, "msdos") + == 0) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); + + { + struct grub_msdos_partition_mbr mbr; + unsigned i; + + err = grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr); + if (err) + return err; + + for (i = 0; i < ARRAY_SIZE (mbr.entries); i++) + if (mbr.entries[i].type == GRUB_PC_PARTITION_TYPE_BSD) + { + err = iterate_real (disk, mbr.entries[i].start + + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, hook); + if (err != GRUB_ERR_BAD_PART_TABLE) + return err; + } + } + + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no bsdlabel found"); +} + +#endif + /* Partition map type. */ static struct grub_partition_map grub_bsdlabel_partition_map = { +#if defined (OPENBSDLABEL) + .name = "openbsd", +#elif defined (NETBSDLABEL) + .name = "netbsd", +#else .name = "bsd", +#endif .iterate = bsdlabel_partition_map_iterate, }; +#if defined (OPENBSDLABEL) +GRUB_MOD_INIT(part_openbsd) +#elif defined (NETBSDLABEL) +GRUB_MOD_INIT(part_netbsd) +#else GRUB_MOD_INIT(part_bsd) +#endif { grub_partition_map_register (&grub_bsdlabel_partition_map); } +#if defined (OPENBSDLABEL) +GRUB_MOD_FINI(part_openbsd) +#elif defined (NETBSDLABEL) +GRUB_MOD_FINI(part_netbsd) +#else GRUB_MOD_FINI(part_bsd) +#endif { grub_partition_map_unregister (&grub_bsdlabel_partition_map); } diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 3898d09fa..02105e622 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -37,6 +37,15 @@ pc_partition_map_iterate (grub_disk_t disk, int labeln = 0; grub_disk_addr_t lastaddr; grub_disk_addr_t ext_offset; + grub_disk_addr_t delta = 0; + + if (disk->partition && disk->partition->partmap == &grub_msdos_partition_map) + { + if (disk->partition->msdostype == GRUB_PC_PARTITION_TYPE_LINUX_MINIX) + delta = disk->partition->offset; + else + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); + } p.offset = 0; ext_offset = 0; @@ -81,8 +90,9 @@ pc_partition_map_iterate (grub_disk_t disk, { e = mbr.entries + p.index; - p.start = p.offset + grub_le_to_cpu32 (e->start); + p.start = p.offset + grub_le_to_cpu32 (e->start) - delta; p.len = grub_le_to_cpu32 (e->length); + p.msdostype = e->type; grub_dprintf ("partition", "partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n", diff --git a/grub-core/partmap/netbsdlabel.c b/grub-core/partmap/netbsdlabel.c new file mode 100644 index 000000000..63c0166da --- /dev/null +++ b/grub-core/partmap/netbsdlabel.c @@ -0,0 +1,2 @@ +#define NETBSDLABEL 1 +#include "bsdlabel.c" diff --git a/grub-core/partmap/openbsdlabel.c b/grub-core/partmap/openbsdlabel.c new file mode 100644 index 000000000..4df075a9c --- /dev/null +++ b/grub-core/partmap/openbsdlabel.c @@ -0,0 +1,2 @@ +#define OPENBSDLABEL 1 +#include "bsdlabel.c" diff --git a/include/grub/partition.h b/include/grub/partition.h index 20705c527..d5398def7 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -65,6 +65,10 @@ struct grub_partition /* The type partition map. */ grub_partition_map_t partmap; + + /* The type of partition whne it's on MSDOS. + Used for embedding detection. */ + grub_uint8_t msdostype; }; grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk, From babad161fb20b59786d4809f7567f8972a393273 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 01:10:58 +0200 Subject: [PATCH 02/12] Reorganise net and openbsdlabel --- Makefile.util.def | 2 - grub-core/partmap/bsdlabel.c | 100 ++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 20224cf02..88207979d 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -90,8 +90,6 @@ library = { common = grub-core/partmap/sun.c; common = grub-core/partmap/sunpc.c; common = grub-core/partmap/bsdlabel.c; - common = grub-core/partmap/netbsdlabel.c; - common = grub-core/partmap/openbsdlabel.c; common = grub-core/script/function.c; common = grub-core/script/lexer.c; common = grub-core/script/main.c; diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index 3d481843a..6fdac94a1 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -30,10 +30,14 @@ #endif static struct grub_partition_map grub_bsdlabel_partition_map; +static struct grub_partition_map grub_netbsdlabel_partition_map; +static struct grub_partition_map grub_openbsdlabel_partition_map; + static grub_err_t iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, + struct grub_partition_map *pmap, int (*hook) (grub_disk_t disk, const grub_partition_t partition)) { @@ -96,7 +100,7 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, p.start = grub_le_to_cpu32 (be.offset); p.len = grub_le_to_cpu32 (be.size); - p.partmap = &grub_bsdlabel_partition_map; + p.partmap = pmap; grub_dprintf ("partition", "partition %d: type 0x%x, start 0x%llx, len 0x%llx\n", @@ -135,8 +139,6 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, return GRUB_ERR_NONE; } -#if !defined (NETBSDLABEL) && !defined (OPENBSDLABEL) - static grub_err_t bsdlabel_partition_map_iterate (grub_disk_t disk, int (*hook) (grub_disk_t disk, @@ -148,34 +150,28 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, { grub_dprintf ("partition", "FreeBSD embedded iterating\n"); return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1, - hook); + &grub_bsdlabel_partition_map, hook); } if (disk->partition && (grub_strcmp (disk->partition->partmap->name, "msdos") == 0 - || grub_strcmp (disk->partition->partmap->name, "bsd") == 0 - || grub_strcmp (disk->partition->partmap->name, "netbsd") == 0 - || grub_strcmp (disk->partition->partmap->name, "openbsd") == 0)) + || disk->partition->partmap == &grub_bsdlabel_partition_map + || disk->partition->partmap == &grub_netbsdlabel_partition_map + || disk->partition->partmap == &grub_openbsdlabel_partition_map)) { grub_dprintf ("partition", "no embedded iterating\n"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); } - return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, hook); + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, + &grub_bsdlabel_partition_map, hook); } -#else - -#ifdef OPENBSDLABEL -#define GRUB_PC_PARTITION_TYPE_BSD GRUB_PC_PARTITION_TYPE_OPENBSD -#else -#define GRUB_PC_PARTITION_TYPE_BSD GRUB_PC_PARTITION_TYPE_NETBSD -#endif - static grub_err_t -bsdlabel_partition_map_iterate (grub_disk_t disk, - int (*hook) (grub_disk_t disk, - const grub_partition_t partition)) +netopenbsdlabel_partition_map_iterate (grub_disk_t disk, grub_uint8_t type, + struct grub_partition_map *pmap, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { grub_err_t err; @@ -192,10 +188,11 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, return err; for (i = 0; i < ARRAY_SIZE (mbr.entries); i++) - if (mbr.entries[i].type == GRUB_PC_PARTITION_TYPE_BSD) + if (mbr.entries[i].type == type) { err = iterate_real (disk, mbr.entries[i].start - + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, hook); + + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, pmap, + hook); if (err != GRUB_ERR_BAD_PART_TABLE) return err; } @@ -204,40 +201,59 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, return grub_error (GRUB_ERR_BAD_PART_TABLE, "no bsdlabel found"); } -#endif +static grub_err_t +netbsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + return netopenbsdlabel_partition_map_iterate (disk, + GRUB_PC_PARTITION_TYPE_NETBSD, + &grub_netbsdlabel_partition_map, + hook); +} + +static grub_err_t +openbsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + return netopenbsdlabel_partition_map_iterate (disk, + GRUB_PC_PARTITION_TYPE_OPENBSD, + &grub_openbsdlabel_partition_map, + hook); +} + - -/* Partition map type. */ static struct grub_partition_map grub_bsdlabel_partition_map = { -#if defined (OPENBSDLABEL) - .name = "openbsd", -#elif defined (NETBSDLABEL) - .name = "netbsd", -#else .name = "bsd", -#endif .iterate = bsdlabel_partition_map_iterate, }; -#if defined (OPENBSDLABEL) -GRUB_MOD_INIT(part_openbsd) -#elif defined (NETBSDLABEL) -GRUB_MOD_INIT(part_netbsd) -#else +static struct grub_partition_map grub_openbsdlabel_partition_map = + { + .name = "openbsd", + .iterate = openbsdlabel_partition_map_iterate, + }; + +static struct grub_partition_map grub_netbsdlabel_partition_map = + { + .name = "netbsd", + .iterate = netbsdlabel_partition_map_iterate, + }; + + + GRUB_MOD_INIT(part_bsd) -#endif { grub_partition_map_register (&grub_bsdlabel_partition_map); + grub_partition_map_register (&grub_netbsdlabel_partition_map); + grub_partition_map_register (&grub_openbsdlabel_partition_map); } -#if defined (OPENBSDLABEL) -GRUB_MOD_FINI(part_openbsd) -#elif defined (NETBSDLABEL) -GRUB_MOD_FINI(part_netbsd) -#else GRUB_MOD_FINI(part_bsd) -#endif { grub_partition_map_unregister (&grub_bsdlabel_partition_map); + grub_partition_map_unregister (&grub_netbsdlabel_partition_map); + grub_partition_map_unregister (&grub_openbsdlabel_partition_map); } From 844d0fd5aab767a574236dd2c771f72e95780831 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 01:13:20 +0200 Subject: [PATCH 03/12] Remove excessive dprintfs --- grub-core/partmap/bsdlabel.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index 6fdac94a1..f25b9548e 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -52,13 +52,7 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, /* Check if it is valid. */ if (label.magic != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) - { - grub_dprintf ("partition", - "bad signature (found 0x%08x, expected 0x%08x)\n", - label.magic, - grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)); - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); - } + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); /* A kludge to determine a base of be.offset. */ if (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION @@ -80,9 +74,6 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, pos = sizeof (label) + sector * GRUB_DISK_SECTOR_SIZE; - grub_dprintf ("partition", "bsdlabel with %d partitions detected\n", - grub_cpu_to_le16 (label.num_partitions)); - for (p.number = 0; p.number < grub_cpu_to_le16 (label.num_partitions); p.number++, pos += sizeof (struct grub_partition_bsd_entry)) @@ -102,12 +93,6 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, p.len = grub_le_to_cpu32 (be.size); p.partmap = pmap; - grub_dprintf ("partition", - "partition %d: type 0x%x, start 0x%llx, len 0x%llx\n", - p.number, be.fs_type, - (unsigned long long) p.start, - (unsigned long long) p.len); - if (p.len == 0) continue; @@ -115,13 +100,6 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, { #ifdef GRUB_UTIL char *partname; -#endif - grub_dprintf ("partition", - "partition %d: invalid start (found 0x%llx, wanted >= 0x%llx)\n", - p.number, - (unsigned long long) p.start, - (unsigned long long) delta); -#ifdef GRUB_UTIL /* disk->partition != NULL as 0 < delta */ partname = grub_partition_get_name (disk->partition); grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)", @@ -147,21 +125,15 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, if (disk->partition && grub_strcmp (disk->partition->partmap->name, "msdos") == 0 && disk->partition->msdostype == GRUB_PC_PARTITION_TYPE_FREEBSD) - { - grub_dprintf ("partition", "FreeBSD embedded iterating\n"); - return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1, - &grub_bsdlabel_partition_map, hook); - } + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1, + &grub_bsdlabel_partition_map, hook); if (disk->partition && (grub_strcmp (disk->partition->partmap->name, "msdos") == 0 || disk->partition->partmap == &grub_bsdlabel_partition_map || disk->partition->partmap == &grub_netbsdlabel_partition_map || disk->partition->partmap == &grub_openbsdlabel_partition_map)) - { - grub_dprintf ("partition", "no embedded iterating\n"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); - } return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, &grub_bsdlabel_partition_map, hook); From 5b1d8b4832a17e2fbb2668d0c8d8cb097eac2fb8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 01:17:08 +0200 Subject: [PATCH 04/12] Remove leftover files --- grub-core/partmap/netbsdlabel.c | 2 -- grub-core/partmap/openbsdlabel.c | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 grub-core/partmap/netbsdlabel.c delete mode 100644 grub-core/partmap/openbsdlabel.c diff --git a/grub-core/partmap/netbsdlabel.c b/grub-core/partmap/netbsdlabel.c deleted file mode 100644 index 63c0166da..000000000 --- a/grub-core/partmap/netbsdlabel.c +++ /dev/null @@ -1,2 +0,0 @@ -#define NETBSDLABEL 1 -#include "bsdlabel.c" diff --git a/grub-core/partmap/openbsdlabel.c b/grub-core/partmap/openbsdlabel.c deleted file mode 100644 index 4df075a9c..000000000 --- a/grub-core/partmap/openbsdlabel.c +++ /dev/null @@ -1,2 +0,0 @@ -#define OPENBSDLABEL 1 -#include "bsdlabel.c" From 208b94005453b34ebc60d2e341bc03e573cc5ee9 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 01:19:11 +0200 Subject: [PATCH 05/12] Handle new names in grub-install --- util/grub-install.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/grub-install.in b/util/grub-install.in index e6521f069..02b05136b 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -332,7 +332,12 @@ fi # filesystem will be accessible). partmap_module= for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do - partmap_module="$partmap_module part_$x"; + case "$x" in + netbsd | openbsd) + partmap_module="$partmap_module part_bsd";; + *) + partmap_module="$partmap_module part_$x";; + esac done # Device abstraction module, if any (lvm, raid). From 7b111db538d28029d1c5c3d65d7ec4b83984d68e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 4 Sep 2010 01:31:13 +0200 Subject: [PATCH 06/12] resync MAkefile.core.def --- grub-core/Makefile.core.def | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 4f28c54f4..353b9d123 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1208,16 +1208,6 @@ module = { common = partmap/bsdlabel.c; }; -module = { - name = part_netbsd; - common = partmap/netbsdlabel.c; -}; - -module = { - name = part_openbsd; - common = partmap/openbsdlabel.c; -}; - module = { name = part_sunpc; common = partmap/sunpc.c; From 3fcb41054945f6bd8466a8d60e0f3761b2f478da Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Sep 2010 20:39:57 +0200 Subject: [PATCH 07/12] Fix a double device name --- grub-core/disk/efi/efidisk.c | 10 ++++++---- grub-core/kern/device.c | 10 ++-------- grub-core/normal/completion.c | 7 +------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index f9c6f3153..cb6c38884 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -731,7 +731,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) { /* This is a hard disk partition. */ grub_disk_t parent = 0; - char *partition_name = 0; + const grub_partition_t tpart = NULL; char *device_name; grub_efi_device_path_t *dup_dp, *dup_ldp; grub_efi_hard_drive_device_path_t hd; @@ -770,7 +770,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) if (grub_partition_get_start (part) == hd.partition_start && grub_partition_get_len (part) == hd.partition_size) { - partition_name = grub_partition_get_name (part); + tpart = part; return 1; } @@ -799,13 +799,15 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) grub_memcpy (&hd, ldp, sizeof (hd)); grub_partition_iterate (parent, find_partition); - if (! partition_name) + if (! tpart) { grub_disk_close (parent); return 0; } - device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); + device_name = grub_xasprintf ("%s,%s%d", parent->name, + tpart->partmap->name, + tpart->number + 1); grub_free (partition_name); grub_disk_close (parent); diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 4273fedfe..278ce9d72 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -135,28 +135,22 @@ grub_device_iterate (int (*hook) (const char *name)) int iterate_partition (grub_disk_t disk, const grub_partition_t partition) { - char *partition_name; struct part_ent *p; - partition_name = grub_partition_get_name (partition); - if (! partition_name) - return 1; p = grub_malloc (sizeof (*p)); if (!p) { - grub_free (partition_name); return 1; } - p->name = grub_xasprintf ("%s,%s", disk->name, partition_name); + p->name = grub_xasprintf ("%s,%s%d", disk->name, partition->partmap->name, + partition->number + 1); if (!p->name) { - grub_free (partition_name); grub_free (p); return 1; } - grub_free (partition_name); p->next = ents; ents = p; diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c index d127f9baf..3bccb43da 100644 --- a/grub-core/normal/completion.c +++ b/grub-core/normal/completion.c @@ -100,15 +100,10 @@ static int iterate_partition (grub_disk_t disk, const grub_partition_t p) { const char *disk_name = disk->name; - char *partition_name = grub_partition_get_name (p); char *name; int ret; - if (! partition_name) - return 1; - - name = grub_xasprintf ("%s,%s", disk_name, partition_name); - grub_free (partition_name); + name = grub_xasprintf ("%s,%s%d", disk_name, p->partmap->name, p->number + 1); if (! name) return 1; From 7051df3609797b1c1fa3f3ff1a1b83a3a3efdc15 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Sep 2010 21:02:51 +0200 Subject: [PATCH 08/12] Fix an issue with new interface for device names --- grub-core/kern/partition.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c index a2f5dd722..bd10774e8 100644 --- a/grub-core/kern/partition.c +++ b/grub-core/kern/partition.c @@ -188,7 +188,13 @@ grub_partition_iterate (struct grub_disk *disk, if (p.start != 0) { const struct grub_partition_map *partmap; + const char *name; + char *newname; dsk->partition = &p; + name = dsk->name; + dsk->name = newname = grub_xasprintf ("%s,%s%d", dsk->name, + p.partmap->name, + p.number + 1); FOR_PARTITION_MAPS(partmap) { grub_err_t err; @@ -198,6 +204,8 @@ grub_partition_iterate (struct grub_disk *disk, if (ret) break; } + grub_free (newname); + dsk->name = name; } dsk->partition = p.parent; return ret; From f256469360f2bbbdb930f282b411c939fe6c0a38 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Sep 2010 21:03:23 +0200 Subject: [PATCH 09/12] Fix minix issue --- grub-core/partmap/msdos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 02105e622..a378bb1cd 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -42,7 +42,7 @@ pc_partition_map_iterate (grub_disk_t disk, if (disk->partition && disk->partition->partmap == &grub_msdos_partition_map) { if (disk->partition->msdostype == GRUB_PC_PARTITION_TYPE_LINUX_MINIX) - delta = disk->partition->offset; + delta = disk->partition->start; else return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); } From 43de930c20205db14057a951d094c858cad9e14a Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 8 Sep 2010 21:22:41 +0200 Subject: [PATCH 10/12] Change to disk->name being raw name. It makes less hidden issues --- grub-core/disk/efi/efidisk.c | 9 +++++---- grub-core/kern/device.c | 12 +++++++++--- grub-core/kern/disk.c | 10 ++++++---- grub-core/kern/partition.c | 8 -------- grub-core/normal/completion.c | 8 +++++++- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index cb6c38884..9b99620d9 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -805,10 +805,11 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) return 0; } - device_name = grub_xasprintf ("%s,%s%d", parent->name, - tpart->partmap->name, - tpart->number + 1); - grub_free (partition_name); + { + char *partition_name = grub_partition_get_name (tpart); + device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); + grub_free (partition_name); + } grub_disk_close (parent); return device_name; diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 278ce9d72..6a004cbfb 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -136,7 +136,7 @@ grub_device_iterate (int (*hook) (const char *name)) int iterate_partition (grub_disk_t disk, const grub_partition_t partition) { struct part_ent *p; - + char *part_name; p = grub_malloc (sizeof (*p)); if (!p) @@ -144,8 +144,14 @@ grub_device_iterate (int (*hook) (const char *name)) return 1; } - p->name = grub_xasprintf ("%s,%s%d", disk->name, partition->partmap->name, - partition->number + 1); + part_name = grub_partition_get_name (partition); + if (!part_name) + { + grub_free (p); + return 1; + } + p->name = grub_xasprintf ("%s,%s", disk->name, part_name); + grub_free (part_name); if (!p->name) { grub_free (p); diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index ccd5f200f..c9cffafc5 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -248,10 +248,6 @@ grub_disk_open (const char *name) if (! disk) return 0; - disk->name = grub_strdup (name); - if (! disk->name) - goto fail; - p = find_part_sep (name); if (p) { @@ -263,7 +259,13 @@ grub_disk_open (const char *name) grub_memcpy (raw, name, len); raw[len] = '\0'; + disk->name = grub_strdup (raw); } + else + disk->name = grub_strdup (name); + if (! disk->name) + goto fail; + for (dev = grub_disk_dev_list; dev; dev = dev->next) { diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c index bd10774e8..a2f5dd722 100644 --- a/grub-core/kern/partition.c +++ b/grub-core/kern/partition.c @@ -188,13 +188,7 @@ grub_partition_iterate (struct grub_disk *disk, if (p.start != 0) { const struct grub_partition_map *partmap; - const char *name; - char *newname; dsk->partition = &p; - name = dsk->name; - dsk->name = newname = grub_xasprintf ("%s,%s%d", dsk->name, - p.partmap->name, - p.number + 1); FOR_PARTITION_MAPS(partmap) { grub_err_t err; @@ -204,8 +198,6 @@ grub_partition_iterate (struct grub_disk *disk, if (ret) break; } - grub_free (newname); - dsk->name = name; } dsk->partition = p.parent; return ret; diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c index 6b5a5b7bb..9098dc6de 100644 --- a/grub-core/normal/completion.c +++ b/grub-core/normal/completion.c @@ -102,8 +102,14 @@ iterate_partition (grub_disk_t disk, const grub_partition_t p) const char *disk_name = disk->name; char *name; int ret; + char *part_name; - name = grub_xasprintf ("%s,%s%d", disk_name, p->partmap->name, p->number + 1); + part_name = grub_partition_get_name (p); + if (! part_name) + return 1; + + name = grub_xasprintf ("%s,%s", disk_name, part_name); + grub_free (part_name); if (! name) return 1; From 4b98e0d7c70e5187cda278457432a6775e696b49 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 20 Sep 2010 21:30:11 +0200 Subject: [PATCH 11/12] Support net-/openbsd labels inside logical partitions --- grub-core/partmap/bsdlabel.c | 49 +++++++++++++++++++++++----------- grub-core/partmap/msdos.c | 10 +++---- include/grub/msdos_partition.h | 7 +++++ 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index f25b9548e..da5c6e3ab 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -145,32 +145,49 @@ netopenbsdlabel_partition_map_iterate (grub_disk_t disk, grub_uint8_t type, int (*hook) (grub_disk_t disk, const grub_partition_t partition)) { - grub_err_t err; + int count = 0; + + auto int check_msdos (grub_disk_t dsk, + const grub_partition_t partition); + + int check_msdos (grub_disk_t dsk, + const grub_partition_t partition) + { + grub_err_t err; + + if (partition->msdostype != type) + return 0; + + err = iterate_real (dsk, partition->start + + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, pmap, hook); + if (err == GRUB_ERR_NONE) + { + count++; + return 1; + } + if (err == GRUB_ERR_BAD_PART_TABLE) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + grub_print_error (); + return 0; + } if (disk->partition && grub_strcmp (disk->partition->partmap->name, "msdos") == 0) return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); { - struct grub_msdos_partition_mbr mbr; - unsigned i; + grub_err_t err; + err = grub_partition_msdos_iterate (disk, check_msdos); - err = grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr); if (err) return err; - - for (i = 0; i < ARRAY_SIZE (mbr.entries); i++) - if (mbr.entries[i].type == type) - { - err = iterate_real (disk, mbr.entries[i].start - + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, pmap, - hook); - if (err != GRUB_ERR_BAD_PART_TABLE) - return err; - } + if (!count) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no bsdlabel found"); } - - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no bsdlabel found"); + return GRUB_ERR_NONE; } static grub_err_t diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index a378bb1cd..c1805fe56 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -27,10 +27,10 @@ static struct grub_partition_map grub_msdos_partition_map; -static grub_err_t -pc_partition_map_iterate (grub_disk_t disk, - int (*hook) (grub_disk_t disk, - const grub_partition_t partition)) +grub_err_t +grub_partition_msdos_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition p; struct grub_msdos_partition_mbr mbr; @@ -148,7 +148,7 @@ pc_partition_map_iterate (grub_disk_t disk, static struct grub_partition_map grub_msdos_partition_map = { .name = "msdos", - .iterate = pc_partition_map_iterate, + .iterate = grub_partition_msdos_iterate, }; GRUB_MOD_INIT(part_msdos) diff --git a/include/grub/msdos_partition.h b/include/grub/msdos_partition.h index 650d78493..a6e3fda49 100644 --- a/include/grub/msdos_partition.h +++ b/include/grub/msdos_partition.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include /* The signature. */ #define GRUB_PC_PARTITION_SIGNATURE 0xaa55 @@ -114,4 +116,9 @@ grub_msdos_partition_is_extended (int type) || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED); } +grub_err_t +grub_partition_msdos_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)); + #endif /* ! GRUB_PC_PARTITION_HEADER */ From 65d973de1c7dfdb401e84efbcf7fb5f50b95d4e1 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 20 Sep 2010 21:34:20 +0200 Subject: [PATCH 12/12] Add the comment about net-/openbsdlabel --- grub-core/partmap/bsdlabel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/partmap/bsdlabel.c b/grub-core/partmap/bsdlabel.c index da5c6e3ab..eff3bbe44 100644 --- a/grub-core/partmap/bsdlabel.c +++ b/grub-core/partmap/bsdlabel.c @@ -139,6 +139,9 @@ bsdlabel_partition_map_iterate (grub_disk_t disk, &grub_bsdlabel_partition_map, hook); } +/* This is a total breakage. Even when net-/openbsd label is inside partition + it actually describes the whole disk. + */ static grub_err_t netopenbsdlabel_partition_map_iterate (grub_disk_t disk, grub_uint8_t type, struct grub_partition_map *pmap,