aboutsummaryrefslogtreecommitdiff
path: root/stand
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2024-02-22 15:17:48 +0000
committerWarner Losh <imp@FreeBSD.org>2024-02-22 16:31:55 +0000
commitb3e76e3d9e2262c4b79e81e63e09bfe62c1f6baa (patch)
tree9b4c47c8ecf8d62bff6a1a3f141d03c2f9e7d176 /stand
parente68136d3635ca75a056dc499485417d5eb9fc2f8 (diff)
downloadsrc-b3e76e3d9e2262c4b79e81e63e09bfe62c1f6baa.tar.gz
src-b3e76e3d9e2262c4b79e81e63e09bfe62c1f6baa.zip
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
Diffstat (limited to 'stand')
-rw-r--r--stand/kboot/kboot/hostdisk.c15
1 files 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);