Handle big-endian mdraid.

* Makefile.util.def (libgrubkern): Add mdraid_linux_be.c.
	* grub-core/Makefile.core.def (mdraid09_be): New module.
	* grub-core/disk/mdraid_linux.c: Use grub_md_to_cpu* and grub_cpu_to_md*
	rather than grub_le_to_cpu* and grub_cpu_to_le*.
	* grub-core/disk/mdraid_linux_be.c: New file.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-03-26 16:10:40 +02:00
parent 3c0eae66fa
commit 22e6a774f9
5 changed files with 59 additions and 13 deletions

View file

@ -1,3 +1,13 @@
2012-03-26 Vladimir Serbinenko <phcoder@gmail.com>
Handle big-endian mdraid.
* Makefile.util.def (libgrubkern): Add mdraid_linux_be.c.
* grub-core/Makefile.core.def (mdraid09_be): New module.
* grub-core/disk/mdraid_linux.c: Use grub_md_to_cpu* and grub_cpu_to_md*
rather than grub_le_to_cpu* and grub_cpu_to_le*.
* grub-core/disk/mdraid_linux_be.c: New file.
2012-03-26 Vladimir Serbinenko <phcoder@gmail.com> 2012-03-26 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/gettext/gettext.c (GRUB_MOD_INIT): Handle errors. * grub-core/gettext/gettext.c (GRUB_MOD_INIT): Handle errors.

View file

@ -53,6 +53,7 @@ library = {
common = grub-core/disk/loopback.c; common = grub-core/disk/loopback.c;
common = grub-core/disk/lvm.c; common = grub-core/disk/lvm.c;
common = grub-core/disk/mdraid_linux.c; common = grub-core/disk/mdraid_linux.c;
common = grub-core/disk/mdraid_linux_be.c;
common = grub-core/disk/mdraid1x_linux.c; common = grub-core/disk/mdraid1x_linux.c;
common = grub-core/disk/raid5_recover.c; common = grub-core/disk/raid5_recover.c;
common = grub-core/disk/raid6_recover.c; common = grub-core/disk/raid6_recover.c;

View file

@ -892,6 +892,11 @@ module = {
common = disk/mdraid_linux.c; common = disk/mdraid_linux.c;
}; };
module = {
name = mdraid09_be;
common = disk/mdraid_linux_be.c;
};
module = { module = {
name = mdraid1x; name = mdraid1x;
common = disk/mdraid1x_linux.c; common = disk/mdraid1x_linux.c;

View file

@ -29,6 +29,22 @@
GRUB_MOD_LICENSE ("GPLv3+"); GRUB_MOD_LICENSE ("GPLv3+");
#ifdef MODE_BIGENDIAN
#define grub_md_to_cpu64 grub_be_to_cpu64
#define grub_md_to_cpu32 grub_be_to_cpu32
#define grub_md_to_cpu16 grub_be_to_cpu16
#define grub_cpu_to_md64_compile_time grub_cpu_to_be64
#define grub_cpu_to_md32_compile_time grub_cpu_to_be32
#define grub_cpu_to_md16_compile_time grub_cpu_to_be16
#else
#define grub_md_to_cpu64 grub_le_to_cpu64
#define grub_md_to_cpu32 grub_le_to_cpu32
#define grub_md_to_cpu16 grub_le_to_cpu16
#define grub_cpu_to_md64_compile_time grub_cpu_to_le64
#define grub_cpu_to_md32_compile_time grub_cpu_to_le32
#define grub_cpu_to_md16_compile_time grub_cpu_to_le16
#endif
#define RESERVED_BYTES (64 * 1024) #define RESERVED_BYTES (64 * 1024)
#define RESERVED_SECTORS (RESERVED_BYTES / 512) #define RESERVED_SECTORS (RESERVED_BYTES / 512)
@ -183,23 +199,23 @@ grub_mdraid_detect (grub_disk_t disk,
return NULL; return NULL;
/* Look whether there is a mdraid 0.90 superblock. */ /* Look whether there is a mdraid 0.90 superblock. */
if (sb.md_magic != grub_cpu_to_le32_compile_time (SB_MAGIC)) if (sb.md_magic != grub_cpu_to_md32_compile_time (SB_MAGIC))
/* not 0.9x raid. */ /* not 0.9x raid. */
return NULL; return NULL;
if (sb.major_version != grub_cpu_to_le32_compile_time (0) if (sb.major_version != grub_cpu_to_md32_compile_time (0)
|| sb.minor_version != grub_cpu_to_le32_compile_time (90)) || sb.minor_version != grub_cpu_to_md32_compile_time (90))
/* Unsupported version. */ /* Unsupported version. */
return NULL; return NULL;
/* No need for explicit check that sb.size is 0 (unspecified) since /* No need for explicit check that sb.size is 0 (unspecified) since
0 >= non-0 is false. */ 0 >= non-0 is false. */
if (((grub_disk_addr_t) grub_le_to_cpu32 (sb.size)) * 2 >= size) if (((grub_disk_addr_t) grub_md_to_cpu32 (sb.size)) * 2 >= size)
return NULL; return NULL;
/* FIXME: Check the checksum. */ /* FIXME: Check the checksum. */
level = grub_le_to_cpu32 (sb.level); level = grub_md_to_cpu32 (sb.level);
/* Multipath. */ /* Multipath. */
if ((int) level == -4) if ((int) level == -4)
level = 1; level = 1;
@ -211,8 +227,8 @@ grub_mdraid_detect (grub_disk_t disk,
"unsupported RAID level: %d", level); "unsupported RAID level: %d", level);
return NULL; return NULL;
} }
if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff if (grub_md_to_cpu32 (sb.this_disk.number) == 0xffff
|| grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe) || grub_md_to_cpu32 (sb.this_disk.number) == 0xfffe)
/* Spares aren't implemented. */ /* Spares aren't implemented. */
return NULL; return NULL;
@ -228,32 +244,44 @@ grub_mdraid_detect (grub_disk_t disk,
*start_sector = 0; *start_sector = 0;
id->uuidlen = 0; id->uuidlen = 0;
id->id = grub_le_to_cpu32 (sb.this_disk.number); id->id = grub_md_to_cpu32 (sb.this_disk.number);
char buf[32]; char buf[32];
grub_snprintf (buf, sizeof (buf), "md%d", grub_le_to_cpu32 (sb.md_minor)); grub_snprintf (buf, sizeof (buf), "md%d", grub_md_to_cpu32 (sb.md_minor));
return grub_diskfilter_make_raid (16, (char *) uuid, return grub_diskfilter_make_raid (16, (char *) uuid,
grub_le_to_cpu32 (sb.raid_disks), buf, grub_md_to_cpu32 (sb.raid_disks), buf,
(sb.size) ? ((grub_disk_addr_t) (sb.size) ? ((grub_disk_addr_t)
grub_le_to_cpu32 (sb.size)) * 2 grub_md_to_cpu32 (sb.size)) * 2
: sector, : sector,
grub_le_to_cpu32 (sb.chunk_size) >> 9, grub_md_to_cpu32 (sb.chunk_size) >> 9,
grub_le_to_cpu32 (sb.layout), grub_md_to_cpu32 (sb.layout),
level); level);
} }
static struct grub_diskfilter grub_mdraid_dev = { static struct grub_diskfilter grub_mdraid_dev = {
#ifdef MODE_BIGENDIAN
.name = "mdraid09_be",
#else
.name = "mdraid09", .name = "mdraid09",
#endif
.detect = grub_mdraid_detect, .detect = grub_mdraid_detect,
.next = 0 .next = 0
}; };
#ifdef MODE_BIGENDIAN
GRUB_MOD_INIT (mdraid09_be)
#else
GRUB_MOD_INIT (mdraid09) GRUB_MOD_INIT (mdraid09)
#endif
{ {
grub_diskfilter_register (&grub_mdraid_dev); grub_diskfilter_register (&grub_mdraid_dev);
} }
#ifdef MODE_BIGENDIAN
GRUB_MOD_FINI (mdraid09_be)
#else
GRUB_MOD_FINI (mdraid09) GRUB_MOD_FINI (mdraid09)
#endif
{ {
grub_diskfilter_unregister (&grub_mdraid_dev); grub_diskfilter_unregister (&grub_mdraid_dev);
} }

View file

@ -0,0 +1,2 @@
#define MODE_BIGENDIAN 1
#include "mdraid_linux.c"