struct grub_diskfilter_pv_id *id,
grub_disk_addr_t *start_sector)
{
- grub_disk_addr_t sector = 0;
grub_uint64_t size;
- struct grub_raid_super_1x sb;
grub_uint8_t minor_version;
size = grub_disk_get_size (disk);
for (minor_version = 0; minor_version < 3; ++minor_version)
{
+ grub_disk_addr_t sector = 0;
+ struct grub_raid_super_1x sb;
+ grub_uint16_t role;
+ grub_uint32_t level;
+ struct grub_diskfilter_vg *array;
+ char *uuid;
+
if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0)
continue;
&sb))
return NULL;
- if (grub_le_to_cpu32 (sb.magic) != SB_MAGIC
+ if (sb.magic != grub_cpu_to_le32_compile_time (SB_MAGIC)
|| grub_le_to_cpu64 (sb.super_offset) != sector)
continue;
- {
- grub_uint64_t sb_size;
- struct grub_raid_super_1x *real_sb;
- grub_uint32_t level;
-
- if (grub_le_to_cpu32 (sb.major_version) != 1)
- {
- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "Unsupported RAID version: %d",
- grub_le_to_cpu32 (sb.major_version));
- return NULL;
- }
-
- level = grub_le_to_cpu32 (sb.level);
-
- /* Multipath. */
- if ((int) level == -4)
- level = 1;
-
- if (level != 0 && level != 1 && level != 4 &&
- level != 5 && level != 6 && level != 10)
- {
- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "Unsupported RAID level: %d", sb.level);
- return NULL;
- }
-
- /* 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)
+ if (sb.major_version != grub_cpu_to_le32_compile_time (1))
+ /* Unsupported version. */
+ return NULL;
+
+ level = grub_le_to_cpu32 (sb.level);
+
+ /* Multipath. */
+ if ((int) level == -4)
+ level = 1;
+
+ if (level != 0 && level != 1 && level != 4 &&
+ level != 5 && level != 6 && level != 10)
+ {
+ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+ "Unsupported RAID level: %d", sb.level);
return NULL;
+ }
+
+ if (grub_le_to_cpu32 (sb.dev_number) >=
+ grub_le_to_cpu32 (sb.max_dev))
+ /* Spares aren't implemented. */
+ return NULL;
+
+ if (grub_le_to_cpu32 (sb.dev_number)
+ >= grub_le_to_cpu32 (sb.raid_disks))
+ /* Spares aren't implemented. */
+ return NULL;
+
+ if (grub_disk_read (disk, sector,
+ (char *) &sb.dev_roles[sb.dev_number]
+ - (char *) &sb,
+ sizeof (role), &role))
+ return NULL;
+
+ id->uuidlen = 0;
+ id->id = grub_le_to_cpu16 (role);
+
+ uuid = grub_malloc (16);
+ if (!uuid)
+ return NULL;
+
+ grub_memcpy (uuid, sb.set_uuid, 16);
+
+ *start_sector = grub_le_to_cpu64 (sb.data_offset);
+
+ array = grub_diskfilter_make_raid (16, uuid,
+ grub_le_to_cpu32 (sb.raid_disks),
+ sb.set_name,
+ (sb.size)
+ ? grub_le_to_cpu64 (sb.size)
+ : grub_le_to_cpu64 (sb.data_size),
+ grub_le_to_cpu32 (sb.chunksize),
+ grub_le_to_cpu32 (sb.layout),
+ grub_le_to_cpu32 (sb.level));
- if (grub_disk_read (disk, sector, 0, sb_size, real_sb))
- {
- grub_free (real_sb);
- return NULL;
- }
-
- struct grub_diskfilter_vg *array;
- char *uuid;
-
- if (grub_le_to_cpu32 (real_sb->dev_number) >=
- grub_le_to_cpu32 (real_sb->max_dev))
- {
- grub_error (GRUB_ERR_OUT_OF_RANGE,
- "spares aren't implemented");
- return NULL;
- }
-
- id->uuidlen = 0;
- id->id = grub_le_to_cpu16
- (real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]);
-
- uuid = grub_malloc (16);
- if (!uuid)
- {
- grub_free (real_sb);
- return NULL;
- }
-
- grub_memcpy (uuid, real_sb->set_uuid, 16);
-
- *start_sector = grub_le_to_cpu64 (real_sb->data_offset);
-
- if (grub_le_to_cpu32 (real_sb->dev_number)
- >= grub_le_to_cpu32 (real_sb->raid_disks))
- {
- grub_error (GRUB_ERR_OUT_OF_RANGE,
- "spares aren't implemented");
- return NULL;
- }
-
- array = grub_diskfilter_make_raid (16, uuid,
- grub_le_to_cpu32 (real_sb->raid_disks),
- real_sb->set_name,
- (real_sb->size)
- ? grub_le_to_cpu64 (real_sb->size)
- : grub_le_to_cpu64 (real_sb->data_size),
- grub_le_to_cpu32 (real_sb->chunksize),
- grub_le_to_cpu32 (real_sb->layout),
- grub_le_to_cpu32 (real_sb->level));
-
- grub_free (real_sb);
- return array;
- }
+ return array;
}
- grub_error (GRUB_ERR_OUT_OF_RANGE, "not 1.x raid");
+ /* not 1.x raid. */
return NULL;
}
/* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk);
if (size == GRUB_DISK_SIZE_UNKNOWN)
- {
- grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
- return NULL;
- }
+ /* not 0.9x raid. */
+ return NULL;
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
return NULL;
/* Look whether there is a mdraid 0.90 superblock. */
- if (grub_le_to_cpu32 (sb.md_magic) != SB_MAGIC)
- {
- grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
- return NULL;
- }
+ if (sb.md_magic != grub_cpu_to_le32_compile_time (SB_MAGIC))
+ /* not 0.9x raid. */
+ return NULL;
- if (grub_le_to_cpu32 (sb.major_version) != 0
- || grub_le_to_cpu32 (sb.minor_version) != 90)
- {
- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "unsupported RAID version: %d.%d",
- grub_le_to_cpu32 (sb.major_version),
- grub_le_to_cpu32 (sb.minor_version));
- return NULL;
- }
+ if (sb.major_version != grub_cpu_to_le32_compile_time (0)
+ || sb.minor_version != grub_cpu_to_le32_compile_time (90))
+ /* Unsupported version. */
+ return NULL;
/* FIXME: Check the checksum. */
}
if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff
|| grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe)
- {
- grub_error (GRUB_ERR_OUT_OF_RANGE,
- "spares aren't implemented");
- return NULL;
- }
+ /* Spares aren't implemented. */
+ return NULL;
uuid = grub_malloc (16);
if (!uuid)