Remove nested functions from device iterators.
* include/grub/arc/arc.h (grub_arc_iterate_devs_hook_t): New type. (grub_arc_iterate_devs): Add hook_data argument. * include/grub/ata.h (grub_ata_dev_iterate_hook_t): New type. (struct grub_ata_dev.iterate): Add hook_data argument. * include/grub/device.h (grub_device_iterate_hook_t): New type. (grub_device_iterate): Add hook_data argument. * include/grub/disk.h (grub_disk_dev_iterate_hook_t): New type. (struct grub_disk_dev.iterate): Add hook_data argument. (grub_disk_dev_iterate): Likewise. * include/grub/gpt_partition.h (grub_gpt_partition_map_iterate): Likewise. * include/grub/msdos_partition.h (grub_partition_msdos_iterate): Likewise. * include/grub/partition.h (grub_partition_iterate_hook_t): New type. (struct grub_partition_map.iterate): Add hook_data argument. (grub_partition_iterate): Likewise. * include/grub/scsi.h (grub_scsi_dev_iterate_hook_t): New type. (struct grub_scsi_dev.iterate): Add hook_data argument. Update all callers.
This commit is contained in:
parent
6c0314d638
commit
25239370fd
50 changed files with 1455 additions and 1165 deletions
|
@ -41,8 +41,7 @@ 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))
|
||||
grub_partition_iterate_hook_t hook, void *hook_data)
|
||||
{
|
||||
struct grub_partition_bsd_disk_label label;
|
||||
struct grub_partition p;
|
||||
|
@ -116,7 +115,7 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd,
|
|||
|
||||
p.start -= delta;
|
||||
|
||||
if (hook (disk, &p))
|
||||
if (hook (disk, &p, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -124,14 +123,14 @@ iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd,
|
|||
|
||||
static grub_err_t
|
||||
bsdlabel_partition_map_iterate (grub_disk_t disk,
|
||||
int (*hook) (grub_disk_t disk,
|
||||
const grub_partition_t partition))
|
||||
grub_partition_iterate_hook_t hook,
|
||||
void *hook_data)
|
||||
{
|
||||
|
||||
if (disk->partition && grub_strcmp (disk->partition->partmap->name, "msdos")
|
||||
== 0 && disk->partition->msdostype == GRUB_PC_PARTITION_TYPE_FREEBSD)
|
||||
return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1,
|
||||
&grub_bsdlabel_partition_map, hook);
|
||||
&grub_bsdlabel_partition_map, hook, hook_data);
|
||||
|
||||
if (disk->partition
|
||||
&& (grub_strcmp (disk->partition->partmap->name, "msdos") == 0
|
||||
|
@ -141,7 +140,44 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
|
|||
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);
|
||||
&grub_bsdlabel_partition_map, hook, hook_data);
|
||||
}
|
||||
|
||||
/* Context for netopenbsdlabel_partition_map_iterate. */
|
||||
struct netopenbsdlabel_ctx
|
||||
{
|
||||
grub_uint8_t type;
|
||||
struct grub_partition_map *pmap;
|
||||
grub_partition_iterate_hook_t hook;
|
||||
void *hook_data;
|
||||
int count;
|
||||
};
|
||||
|
||||
/* Helper for netopenbsdlabel_partition_map_iterate. */
|
||||
static int
|
||||
check_msdos (grub_disk_t dsk, const grub_partition_t partition, void *data)
|
||||
{
|
||||
struct netopenbsdlabel_ctx *ctx = data;
|
||||
grub_err_t err;
|
||||
|
||||
if (partition->msdostype != ctx->type)
|
||||
return 0;
|
||||
|
||||
err = iterate_real (dsk, partition->start
|
||||
+ GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, ctx->pmap,
|
||||
ctx->hook, ctx->hook_data);
|
||||
if (err == GRUB_ERR_NONE)
|
||||
{
|
||||
ctx->count++;
|
||||
return 1;
|
||||
}
|
||||
if (err == GRUB_ERR_BAD_PART_TABLE)
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return 0;
|
||||
}
|
||||
grub_print_error ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is a total breakage. Even when net-/openbsd label is inside partition
|
||||
|
@ -150,45 +186,26 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
|
|||
static grub_err_t
|
||||
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_partition_iterate_hook_t hook,
|
||||
void *hook_data)
|
||||
{
|
||||
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 netopenbsdlabel_ctx ctx = {
|
||||
.type = type,
|
||||
.pmap = pmap,
|
||||
.hook = hook,
|
||||
.hook_data = hook_data,
|
||||
.count = count
|
||||
};
|
||||
grub_err_t err;
|
||||
err = grub_partition_msdos_iterate (disk, check_msdos);
|
||||
|
||||
err = grub_partition_msdos_iterate (disk, check_msdos, &ctx);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -200,24 +217,24 @@ netopenbsdlabel_partition_map_iterate (grub_disk_t disk, grub_uint8_t type,
|
|||
|
||||
static grub_err_t
|
||||
netbsdlabel_partition_map_iterate (grub_disk_t disk,
|
||||
int (*hook) (grub_disk_t disk,
|
||||
const grub_partition_t partition))
|
||||
grub_partition_iterate_hook_t hook,
|
||||
void *hook_data)
|
||||
{
|
||||
return netopenbsdlabel_partition_map_iterate (disk,
|
||||
GRUB_PC_PARTITION_TYPE_NETBSD,
|
||||
&grub_netbsdlabel_partition_map,
|
||||
hook);
|
||||
hook, hook_data);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
openbsdlabel_partition_map_iterate (grub_disk_t disk,
|
||||
int (*hook) (grub_disk_t disk,
|
||||
const grub_partition_t partition))
|
||||
grub_partition_iterate_hook_t hook,
|
||||
void *hook_data)
|
||||
{
|
||||
return netopenbsdlabel_partition_map_iterate (disk,
|
||||
GRUB_PC_PARTITION_TYPE_OPENBSD,
|
||||
&grub_openbsdlabel_partition_map,
|
||||
hook);
|
||||
hook, hook_data);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue