Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Oct 2021 01:16:21 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 9c81001f8d16 - stable/12 - loader: userboot/test should accept more than one disk
Message-ID:  <202110080116.1981GLVf010446@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=9c81001f8d16cd80952f47a326bdf664180e3941

commit 9c81001f8d16cd80952f47a326bdf664180e3941
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2019-11-03 09:14:29 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-10-08 01:15:58 +0000

    loader: userboot/test should accept more than one disk
    
    allow to specify multiple -d options, test -d disk1 -d disk2 ..
    
    (cherry picked from commit bcbb1e60a1c181310a7ce36af2c202fa789d03e5)
---
 stand/userboot/test/test.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/stand/userboot/test/test.c b/stand/userboot/test/test.c
index f2fee82663d6..4dc67548c546 100644
--- a/stand/userboot/test/test.c
+++ b/stand/userboot/test/test.c
@@ -50,10 +50,11 @@ char *host_base = NULL;
 struct termios term, oldterm;
 char *image;
 size_t image_size;
-int disk_fd = -1;
 
 uint64_t regs[16];
 uint64_t pc;
+int *disk_fd;
+int disk_index = -1;
 
 void test_exit(void *arg, int v);
 
@@ -250,9 +251,9 @@ test_diskread(void *arg, int unit, uint64_t offset, void *dst, size_t size,
 {
 	ssize_t n;
 
-	if (unit != 0 || disk_fd == -1)
+	if (unit > disk_index || disk_fd[unit] == -1)
 		return (EIO);
-	n = pread(disk_fd, dst, size, offset);
+	n = pread(disk_fd[unit], dst, size, offset);
 	if (n < 0)
 		return (errno);
 	*resid_return = size - n;
@@ -264,14 +265,14 @@ test_diskioctl(void *arg, int unit, u_long cmd, void *data)
 {
 	struct stat sb;
 
-	if (unit != 0 || disk_fd == -1)
+	if (unit > disk_index || disk_fd[unit] == -1)
 		return (EBADF);
 	switch (cmd) {
 	case DIOCGSECTORSIZE:
 		*(u_int *)data = 512;
 		break;
 	case DIOCGMEDIASIZE:
-		if (fstat(disk_fd, &sb) == 0)
+		if (fstat(disk_fd[unit], &sb) == 0)
 			*(off_t *)data = sb.st_size;
 		else
 			return (ENOTTY);
@@ -429,7 +430,6 @@ main(int argc, char** argv)
 	void *h;
 	void (*func)(struct loader_callbacks *, void *, int, int) __dead2;
 	int opt;
-	char *disk_image = NULL;
 	const char *userboot_obj = "/boot/userboot.so";
 
 	while ((opt = getopt(argc, argv, "b:d:h:")) != -1) {
@@ -439,7 +439,12 @@ main(int argc, char** argv)
 			break;
 
 		case 'd':
-			disk_image = optarg;
+			disk_index++;
+			disk_fd = reallocarray(disk_fd, disk_index + 1,
+			    sizeof (int));
+			disk_fd[disk_index] = open(optarg, O_RDONLY);
+			if (disk_fd[disk_index] < 0)
+				err(1, "Can't open disk image '%s'", optarg);
 			break;
 
 		case 'h':
@@ -464,11 +469,6 @@ main(int argc, char** argv)
 
 	image_size = 128*1024*1024;
 	image = malloc(image_size);
-	if (disk_image) {
-		disk_fd = open(disk_image, O_RDONLY);
-		if (disk_fd < 0)
-			err(1, "Can't open disk image '%s'", disk_image);
-	}
 
 	tcgetattr(0, &term);
 	oldterm = term;
@@ -476,5 +476,5 @@ main(int argc, char** argv)
 	term.c_lflag &= ~(ICANON|ECHO);
 	tcsetattr(0, TCSAFLUSH, &term);
 
-	func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0);
+	func(&cb, NULL, USERBOOT_VERSION_3, disk_index + 1);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110080116.1981GLVf010446>