git: cffdb3f5e2da - stable/13 - stand: Move i386_devdesc to a union

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:11:51 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=cffdb3f5e2da60f21bf9ef52c4791ee1d46b7d44

commit cffdb3f5e2da60f21bf9ef52c4791ee1d46b7d44
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-08-11 15:04:08 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:30 +0000

    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
    
    (cherry picked from commit f197c0bf3e075286ccea32cd12023f3317474c5a)
---
 stand/i386/libi386/libi386.h | 28 +++++++++++++---------------
 stand/i386/loader/main.c     | 22 ++++++++++------------
 stand/i386/zfsboot/zfsboot.c | 19 +++++++++----------
 3 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/stand/i386/libi386/libi386.h b/stand/i386/libi386/libi386.h
index a52a1190e7ec..9c7a452a03ad 100644
--- a/stand/i386/libi386/libi386.h
+++ b/stand/i386/libi386/libi386.h
@@ -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. */
-    union 
-    {
-	struct 
+struct i386_devdesc
+{
+	union
 	{
-	    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
+	};
 };
 
 /*
diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c
index cb716d7a9f21..29c40921a85a 100644
--- a/stand/i386/loader/main.c
+++ b/stand/i386/loader/main.c
@@ -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;
 
 		/*
diff --git a/stand/i386/zfsboot/zfsboot.c b/stand/i386/zfsboot/zfsboot.c
index 8dd3066f15e5..b68d80e802c2 100644
--- a/stand/i386/zfsboot/zfsboot.c
+++ b/stand/i386/zfsboot/zfsboot.c
@@ -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;
 		}
 	}
 }