stand: Move i386_devdesc to a union
Rather than have the magic, hand-crafted fields that have to align with fields in other structures at the end of i386_devdesc, make it into anonymous union and adjust the code accordingly. This is safer and similar to what CAM does. Sponsored by: Netflix Reviewed by: kevans, tsoome (prior version) Differential Revision: https://reviews.freebsd.org/D35965
This commit is contained in:
parent
bec11d9631
commit
f197c0bf3e
@ -27,25 +27,23 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "disk.h"
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
#include "libzfs.h"
|
||||
#endif
|
||||
/*
|
||||
* i386 fully-qualified device descriptor.
|
||||
*/
|
||||
struct i386_devdesc {
|
||||
struct devdesc dd; /* Must be first. */
|
||||
struct i386_devdesc
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
int slice;
|
||||
int partition;
|
||||
off_t offset;
|
||||
} biosdisk;
|
||||
struct
|
||||
{
|
||||
uint64_t pool_guid;
|
||||
uint64_t root_guid;
|
||||
} zfs;
|
||||
} d_kind;
|
||||
struct devdesc dd;
|
||||
struct disk_devdesc disk;
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
struct zfs_devdesc zfs;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -308,8 +308,8 @@ extract_currdev(void)
|
||||
new_currdev.dd.d_unit = 0;
|
||||
} else {
|
||||
/* we don't know what our boot device is */
|
||||
new_currdev.d_kind.biosdisk.slice = -1;
|
||||
new_currdev.d_kind.biosdisk.partition = 0;
|
||||
new_currdev.disk.d_slice = -1;
|
||||
new_currdev.disk.d_partition = 0;
|
||||
biosdev = -1;
|
||||
}
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
@ -322,8 +322,8 @@ extract_currdev(void)
|
||||
zargs->size >=
|
||||
offsetof(struct zfs_boot_args, primary_pool)) {
|
||||
/* sufficient data is provided */
|
||||
new_currdev.d_kind.zfs.pool_guid = zargs->pool;
|
||||
new_currdev.d_kind.zfs.root_guid = zargs->root;
|
||||
new_currdev.zfs.pool_guid = zargs->pool;
|
||||
new_currdev.zfs.root_guid = zargs->root;
|
||||
if (zargs->size >= sizeof(*zargs) &&
|
||||
zargs->primary_vdev != 0) {
|
||||
sprintf(buf, "%llu", zargs->primary_pool);
|
||||
@ -333,8 +333,8 @@ extract_currdev(void)
|
||||
}
|
||||
} else {
|
||||
/* old style zfsboot block */
|
||||
new_currdev.d_kind.zfs.pool_guid = kargs->zfspool;
|
||||
new_currdev.d_kind.zfs.root_guid = 0;
|
||||
new_currdev.zfs.pool_guid = kargs->zfspool;
|
||||
new_currdev.zfs.root_guid = 0;
|
||||
}
|
||||
new_currdev.dd.d_dev = &zfs_dev;
|
||||
|
||||
@ -350,14 +350,12 @@ extract_currdev(void)
|
||||
#endif
|
||||
} else if ((initial_bootdev & B_MAGICMASK) != B_DEVMAGIC) {
|
||||
/* The passed-in boot device is bad */
|
||||
new_currdev.d_kind.biosdisk.slice = -1;
|
||||
new_currdev.d_kind.biosdisk.partition = 0;
|
||||
new_currdev.disk.d_slice = -1;
|
||||
new_currdev.disk.d_partition = 0;
|
||||
biosdev = -1;
|
||||
} else {
|
||||
new_currdev.d_kind.biosdisk.slice =
|
||||
B_SLICE(initial_bootdev) - 1;
|
||||
new_currdev.d_kind.biosdisk.partition =
|
||||
B_PARTITION(initial_bootdev);
|
||||
new_currdev.disk.d_slice = B_SLICE(initial_bootdev) - 1;
|
||||
new_currdev.disk.d_partition = B_PARTITION(initial_bootdev);
|
||||
biosdev = initial_bootinfo->bi_bios_dev;
|
||||
|
||||
/*
|
||||
|
@ -467,8 +467,8 @@ load(void)
|
||||
|
||||
if (bdev->dd.d_dev->dv_type == DEVT_ZFS) {
|
||||
zfsargs.size = sizeof(zfsargs);
|
||||
zfsargs.pool = bdev->d_kind.zfs.pool_guid;
|
||||
zfsargs.root = bdev->d_kind.zfs.root_guid;
|
||||
zfsargs.pool = bdev->zfs.pool_guid;
|
||||
zfsargs.root = bdev->zfs.root_guid;
|
||||
#ifdef LOADER_GELI_SUPPORT
|
||||
export_geli_boot_data(&zfsargs.gelidata);
|
||||
#endif
|
||||
@ -481,8 +481,8 @@ load(void)
|
||||
__exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK),
|
||||
bootdev,
|
||||
KARGS_FLAGS_ZFS | KARGS_FLAGS_EXTARG,
|
||||
(uint32_t)bdev->d_kind.zfs.pool_guid,
|
||||
(uint32_t)(bdev->d_kind.zfs.pool_guid >> 32),
|
||||
(uint32_t)bdev->zfs.pool_guid,
|
||||
(uint32_t)(bdev->zfs.pool_guid >> 32),
|
||||
VTOP(&bootinfo),
|
||||
zfsargs);
|
||||
} else {
|
||||
@ -528,13 +528,12 @@ mount_root(char *arg)
|
||||
free(bdev);
|
||||
bdev = ddesc;
|
||||
if (bdev->dd.d_dev->dv_type == DEVT_DISK) {
|
||||
if (bdev->d_kind.biosdisk.partition == -1)
|
||||
if (bdev->disk.d_partition == -1)
|
||||
part = 0xff;
|
||||
else
|
||||
part = bdev->d_kind.biosdisk.partition;
|
||||
part = bdev->disk.d_partition;
|
||||
bootdev = MAKEBOOTDEV(dev_maj[bdev->dd.d_dev->dv_type],
|
||||
bdev->d_kind.biosdisk.slice + 1,
|
||||
bdev->dd.d_unit, part);
|
||||
bdev->disk.d_slice + 1, bdev->dd.d_unit, part);
|
||||
bootinfo.bi_bios_dev = bd_unit2bios(bdev);
|
||||
}
|
||||
strncpy(boot_devname, root, sizeof (boot_devname));
|
||||
@ -714,8 +713,8 @@ i386_zfs_probe(void)
|
||||
if (pool_guid != 0 && bdev == NULL) {
|
||||
bdev = malloc(sizeof (struct i386_devdesc));
|
||||
bzero(bdev, sizeof (struct i386_devdesc));
|
||||
bdev->dd.d_dev = &zfs_dev;
|
||||
bdev->d_kind.zfs.pool_guid = pool_guid;
|
||||
bdev->zfs.dd.d_dev = &zfs_dev;
|
||||
bdev->zfs.pool_guid = pool_guid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user