git: 228dfdb7f210 - stable/13 - stand/kboot: hostdisk isn't a DEVT_DISK, use a different value.

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

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

commit 228dfdb7f2105c7e89d1b708c973e0f88d899475
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-10-22 15:09:23 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:36 +0000

    stand/kboot: hostdisk isn't a DEVT_DISK, use a different value.
    
    We assume in all the code that a DEVT_DISK uses common/disk.c and/or
    common/part.c and we can access a struct disk_devdesc. hostdisk.c
    opens raw devices directly, so has no such structures. Define a
    kboot-specific DEVT_HOSTDISK and use that instead.
    
    In addition, disk_fmtdev assumes it is working with a struct
    disk_devdesc, so write hostdisk_fmtdev as well.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit 2cb90a7b2efc41e791c589e17127f63ccf24167c)
---
 stand/kboot/hostdisk.c | 14 ++++++++++----
 stand/kboot/kboot.h    |  2 ++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/stand/kboot/hostdisk.c b/stand/kboot/hostdisk.c
index 487f24fde821..852785497989 100644
--- a/stand/kboot/hostdisk.c
+++ b/stand/kboot/hostdisk.c
@@ -28,9 +28,8 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <stdarg.h>
-#include "bootstrap.h"
 #include "host_syscall.h"
-#include "disk.h"
+#include "kboot.h"
 
 static int hostdisk_init(void);
 static int hostdisk_strategy(void *devdata, int flag, daddr_t dblk,
@@ -39,10 +38,11 @@ static int hostdisk_open(struct open_file *f, ...);
 static int hostdisk_close(struct open_file *f);
 static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data);
 static int hostdisk_print(int verbose);
+static char *hostdisk_fmtdev(struct devdesc *vdev);
 
 struct devsw hostdisk = {
 	.dv_name = "/dev",
-	.dv_type = DEVT_DISK,
+	.dv_type = DEVT_HOSTDISK,
 	.dv_init = hostdisk_init,
 	.dv_strategy = hostdisk_strategy,
 	.dv_open = hostdisk_open,
@@ -50,7 +50,7 @@ struct devsw hostdisk = {
 	.dv_ioctl = hostdisk_ioctl,
 	.dv_print = hostdisk_print,
 	.dv_cleanup = nullsys,
-	.dv_fmtdev = disk_fmtdev,
+	.dv_fmtdev = hostdisk_fmtdev,
 };
 
 static int
@@ -136,3 +136,9 @@ hostdisk_print(int verbose)
 	snprintf(line, sizeof(line), "    /dev%d:   Host disk\n", 0);
 	return (pager_output(line));
 }
+
+static char *
+hostdisk_fmtdev(struct devdesc *vdev)
+{
+	return (vdev->d_opendata);
+}
diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h
index 13c9f9ad3032..679d645d8ff0 100644
--- a/stand/kboot/kboot.h
+++ b/stand/kboot/kboot.h
@@ -7,6 +7,8 @@
 #ifndef KBOOT_H
 #define KBOOT_H
 
+#define DEVT_HOSTDISK 1234
+
 void do_init(void);
 uint64_t kboot_get_phys_load_segment(void);
 uint8_t kboot_get_kernel_machine_bits(void);