From b3e76e3d9e2262c4b79e81e63e09bfe62c1f6baa Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 22 Feb 2024 08:17:48 -0700 Subject: [PATCH] kboot: Implement write support for hostdisk Don't assume that strategy is only called for read. Check the passed flag for F_READ or F_WRITE and fail if it is neither. Open the disks for writing and call host_read/host_write depending on that flag. Sponsored by: Netflix Reviewed by: kevans, gallatin Differential Revision: https://reviews.freebsd.org/D44016 --- stand/kboot/kboot/hostdisk.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stand/kboot/kboot/hostdisk.c b/stand/kboot/kboot/hostdisk.c index 423151983523..a9117d4c1c9d 100644 --- a/stand/kboot/kboot/hostdisk.c +++ b/stand/kboot/kboot/hostdisk.c @@ -305,7 +305,6 @@ hostdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size, struct devdesc *desc = devdata; daddr_t pos; int n; - int64_t off; uint64_t res; uint32_t posl, posh; @@ -313,12 +312,14 @@ hostdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size, posl = pos & 0xffffffffu; posh = (pos >> 32) & 0xffffffffu; - if ((off = host_llseek(desc->d_unit, posh, posl, &res, 0)) < 0) { - printf("Seek error on fd %d to %ju (dblk %ju) returns %jd\n", - desc->d_unit, (uintmax_t)pos, (uintmax_t)dblk, (intmax_t)off); + if (host_llseek(desc->d_unit, posh, posl, &res, 0) < 0) return (EIO); - } - n = host_read(desc->d_unit, buf, size); + if (flag & F_READ) + n = host_read(desc->d_unit, buf, size); + else if (flag & F_WRITE) + n = host_write(desc->d_unit, buf, size); + else + return (EINVAL); if (n < 0) return (EIO); @@ -339,7 +340,7 @@ hostdisk_open(struct open_file *f, ...) va_end(vl); fn = dev2hd(desc)->hd_dev; - desc->d_unit = host_open(fn, O_RDONLY, 0); + desc->d_unit = host_open(fn, O_RDWR, 0); if (desc->d_unit <= 0) { printf("hostdisk_open: couldn't open %s: %d\n", fn, errno); return (ENOENT);