From 2cb90a7b2efc41e791c589e17127f63ccf24167c Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sat, 22 Oct 2022 09:09:23 -0600 Subject: [PATCH] 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 --- 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 #include -#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);