summaryrefslogtreecommitdiff
path: root/stand/userboot/test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'stand/userboot/test/test.c')
-rw-r--r--stand/userboot/test/test.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/stand/userboot/test/test.c b/stand/userboot/test/test.c
index 301069a4d9537..baf1b6243c1fe 100644
--- a/stand/userboot/test/test.c
+++ b/stand/userboot/test/test.c
@@ -261,6 +261,21 @@ test_diskread(void *arg, int unit, uint64_t offset, void *dst, size_t size,
}
int
+test_diskwrite(void *arg, int unit, uint64_t offset, void *src, size_t size,
+ size_t *resid_return)
+{
+ ssize_t n;
+
+ if (unit > disk_index || disk_fd[unit] == -1)
+ return (EIO);
+ n = pwrite(disk_fd[unit], src, size, offset);
+ if (n < 0)
+ return (errno);
+ *resid_return = size - n;
+ return (0);
+}
+
+int
test_diskioctl(void *arg, int unit, u_long cmd, void *data)
{
struct stat sb;
@@ -399,6 +414,7 @@ struct loader_callbacks cb = {
.stat = test_stat,
.diskread = test_diskread,
+ .diskwrite = test_diskwrite,
.diskioctl = test_diskioctl,
.copyin = test_copyin,
@@ -431,8 +447,9 @@ main(int argc, char** argv)
void (*func)(struct loader_callbacks *, void *, int, int) __dead2;
int opt;
const char *userboot_obj = "/boot/userboot.so";
+ int oflag = O_RDONLY;
- while ((opt = getopt(argc, argv, "b:d:h:")) != -1) {
+ while ((opt = getopt(argc, argv, "wb:d:h:")) != -1) {
switch (opt) {
case 'b':
userboot_obj = optarg;
@@ -442,7 +459,7 @@ main(int argc, char** argv)
disk_index++;
disk_fd = reallocarray(disk_fd, disk_index + 1,
sizeof (int));
- disk_fd[disk_index] = open(optarg, O_RDONLY);
+ disk_fd[disk_index] = open(optarg, oflag);
if (disk_fd[disk_index] < 0)
err(1, "Can't open disk image '%s'", optarg);
break;
@@ -451,6 +468,10 @@ main(int argc, char** argv)
host_base = optarg;
break;
+ case 'w':
+ oflag = O_RDWR;
+ break;
+
case '?':
usage();
}