Support net-/openbsd labels inside logical partitions

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-20 21:30:11 +02:00
parent 43de930c20
commit 4b98e0d7c7
3 changed files with 45 additions and 21 deletions

View file

@ -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

View file

@ -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)

View file

@ -22,6 +22,8 @@
#include <grub/symbol.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/disk.h>
#include <grub/partition.h>
/* 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 */