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
|
@ -101,8 +101,8 @@ fail:
|
|||
|
||||
static grub_err_t
|
||||
acorn_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)
|
||||
{
|
||||
struct grub_partition part;
|
||||
struct linux_part map[LINUX_MAP_ENTRIES];
|
||||
|
@ -127,7 +127,7 @@ acorn_partition_map_iterate (grub_disk_t disk,
|
|||
part.offset = 6;
|
||||
part.number = part.index = i;
|
||||
|
||||
if (hook (disk, &part))
|
||||
if (hook (disk, &part, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,8 +87,8 @@ amiga_partition_map_checksum (void *buf, grub_size_t sz)
|
|||
|
||||
static grub_err_t
|
||||
amiga_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)
|
||||
{
|
||||
struct grub_partition part;
|
||||
struct grub_amiga_rdsk rdsk;
|
||||
|
@ -145,7 +145,7 @@ amiga_partition_map_iterate (grub_disk_t disk,
|
|||
part.index = 0;
|
||||
part.partmap = &grub_amiga_partition_map;
|
||||
|
||||
if (hook (disk, &part))
|
||||
if (hook (disk, &part, hook_data))
|
||||
return grub_errno;
|
||||
|
||||
next = grub_be_to_cpu32 (apart.next);
|
||||
|
|
|
@ -101,8 +101,8 @@ static struct grub_partition_map grub_apple_partition_map;
|
|||
|
||||
static grub_err_t
|
||||
apple_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)
|
||||
{
|
||||
struct grub_partition part;
|
||||
struct grub_apple_header aheader;
|
||||
|
@ -163,7 +163,7 @@ apple_partition_map_iterate (grub_disk_t disk,
|
|||
grub_be_to_cpu32 (apart.first_phys_block),
|
||||
grub_be_to_cpu32 (apart.blockcnt));
|
||||
|
||||
if (hook (disk, &part))
|
||||
if (hook (disk, &part, hook_data))
|
||||
return grub_errno;
|
||||
|
||||
pos += grub_be_to_cpu16 (aheader.blocksize);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -64,8 +64,7 @@ grub_dvh_is_valid (grub_uint32_t *label)
|
|||
|
||||
static grub_err_t
|
||||
dvh_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)
|
||||
{
|
||||
struct grub_partition p;
|
||||
union
|
||||
|
@ -101,7 +100,7 @@ dvh_partition_map_iterate (grub_disk_t disk,
|
|||
p.start = grub_be_to_cpu32 (block.dvh.parts[partnum].start);
|
||||
p.len = grub_be_to_cpu32 (block.dvh.parts[partnum].length);
|
||||
p.number = p.index = partnum;
|
||||
if (hook (disk, &p))
|
||||
if (hook (disk, &p, hook_data))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ static struct grub_partition_map grub_gpt_partition_map;
|
|||
|
||||
grub_err_t
|
||||
grub_gpt_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)
|
||||
{
|
||||
struct grub_partition part;
|
||||
struct grub_gpt_header gpt;
|
||||
|
@ -113,7 +113,7 @@ grub_gpt_partition_map_iterate (grub_disk_t disk,
|
|||
(unsigned long long) part.start,
|
||||
(unsigned long long) part.len);
|
||||
|
||||
if (hook (disk, &part))
|
||||
if (hook (disk, &part, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -129,71 +129,81 @@ grub_gpt_partition_map_iterate (grub_disk_t disk,
|
|||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
/* Context for gpt_partition_map_embed. */
|
||||
struct gpt_partition_map_embed_ctx
|
||||
{
|
||||
grub_disk_addr_t start, len;
|
||||
};
|
||||
|
||||
/* Helper for gpt_partition_map_embed. */
|
||||
static int
|
||||
find_usable_region (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p, void *data)
|
||||
{
|
||||
struct gpt_partition_map_embed_ctx *ctx = data;
|
||||
struct grub_gpt_partentry gptdata;
|
||||
grub_partition_t p2;
|
||||
|
||||
p2 = disk->partition;
|
||||
disk->partition = p->parent;
|
||||
if (grub_disk_read (disk, p->offset, p->index,
|
||||
sizeof (gptdata), &gptdata))
|
||||
{
|
||||
disk->partition = p2;
|
||||
return 0;
|
||||
}
|
||||
disk->partition = p2;
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
ctx->start = p->start;
|
||||
ctx->len = p->len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
gpt_partition_map_embed (struct grub_disk *disk_, unsigned int *nsectors,
|
||||
gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
|
||||
unsigned int max_nsectors,
|
||||
grub_embed_type_t embed_type,
|
||||
grub_disk_addr_t **sectors)
|
||||
{
|
||||
grub_disk_addr_t start = 0, len = 0;
|
||||
struct gpt_partition_map_embed_ctx ctx = {
|
||||
.start = 0,
|
||||
.len = 0
|
||||
};
|
||||
unsigned i;
|
||||
grub_err_t err;
|
||||
|
||||
auto int NESTED_FUNC_ATTR find_usable_region (grub_disk_t disk,
|
||||
const grub_partition_t p);
|
||||
int NESTED_FUNC_ATTR find_usable_region (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_gpt_partentry gptdata;
|
||||
grub_partition_t p2;
|
||||
|
||||
p2 = disk->partition;
|
||||
disk->partition = p->parent;
|
||||
if (grub_disk_read (disk, p->offset, p->index,
|
||||
sizeof (gptdata), &gptdata))
|
||||
{
|
||||
disk->partition = p2;
|
||||
return 0;
|
||||
}
|
||||
disk->partition = p2;
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
start = p->start;
|
||||
len = p->len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (embed_type != GRUB_EMBED_PCBIOS)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"GPT currently supports only PC-BIOS embedding");
|
||||
|
||||
err = grub_gpt_partition_map_iterate (disk_, find_usable_region);
|
||||
err = grub_gpt_partition_map_iterate (disk, find_usable_region, &ctx);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (len == 0)
|
||||
if (ctx.len == 0)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
N_("this GPT partition label contains no BIOS Boot Partition;"
|
||||
" embedding won't be possible"));
|
||||
|
||||
if (len < *nsectors)
|
||||
if (ctx.len < *nsectors)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
N_("your BIOS Boot Partition is too small;"
|
||||
" embedding won't be possible"));
|
||||
|
||||
*nsectors = len;
|
||||
*nsectors = ctx.len;
|
||||
if (*nsectors > max_nsectors)
|
||||
*nsectors = max_nsectors;
|
||||
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
|
||||
if (!*sectors)
|
||||
return grub_errno;
|
||||
for (i = 0; i < *nsectors; i++)
|
||||
(*sectors)[i] = start + i;
|
||||
(*sectors)[i] = ctx.start + i;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -100,8 +100,8 @@ struct embed_signature embed_signatures[] =
|
|||
|
||||
grub_err_t
|
||||
grub_partition_msdos_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)
|
||||
{
|
||||
struct grub_partition p;
|
||||
struct grub_msdos_partition_mbr mbr;
|
||||
|
@ -186,7 +186,7 @@ grub_partition_msdos_iterate (grub_disk_t disk,
|
|||
{
|
||||
p.number++;
|
||||
|
||||
if (hook (disk, &p))
|
||||
if (hook (disk, &p, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
else if (p.number < 4)
|
||||
|
|
|
@ -31,8 +31,8 @@ static struct grub_partition_map grub_plan_partition_map;
|
|||
|
||||
static grub_err_t
|
||||
plan_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)
|
||||
{
|
||||
struct grub_partition p;
|
||||
int ptr = 0;
|
||||
|
@ -92,7 +92,7 @@ plan_partition_map_iterate (grub_disk_t disk,
|
|||
if (c != '\n')
|
||||
break;
|
||||
p.len -= p.start;
|
||||
if (hook (disk, &p))
|
||||
if (hook (disk, &p, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
if (p.number == 0)
|
||||
|
|
|
@ -86,8 +86,7 @@ grub_sun_is_valid (grub_uint16_t *label)
|
|||
|
||||
static grub_err_t
|
||||
sun_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)
|
||||
{
|
||||
struct grub_partition p;
|
||||
union
|
||||
|
@ -128,7 +127,7 @@ sun_partition_map_iterate (grub_disk_t disk,
|
|||
p.number = p.index = partnum;
|
||||
if (p.len)
|
||||
{
|
||||
if (hook (disk, &p))
|
||||
if (hook (disk, &p, hook_data))
|
||||
partnum = GRUB_PARTMAP_SUN_MAX_PARTS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ grub_sun_is_valid (grub_uint16_t *label)
|
|||
|
||||
static grub_err_t
|
||||
sun_pc_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)
|
||||
{
|
||||
grub_partition_t p;
|
||||
union
|
||||
|
@ -122,7 +122,7 @@ sun_pc_partition_map_iterate (grub_disk_t disk,
|
|||
p->number = partnum;
|
||||
if (p->len)
|
||||
{
|
||||
if (hook (disk, p))
|
||||
if (hook (disk, p, hook_data))
|
||||
partnum = GRUB_PARTMAP_SUN_PC_MAX_PARTS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue