git: ccf7b62bd88c - main - loader: allow fs modules to use ioctl()

From: Toomas Soome <tsoome_at_FreeBSD.org>
Date: Mon, 03 Mar 2025 21:53:41 UTC
The branch main has been updated by tsoome:

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

commit ccf7b62bd88c6c8beba915eab058f99212a32d35
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2025-03-03 21:52:55 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2025-03-03 21:52:55 +0000

    loader: allow fs modules to use ioctl()
    
    Currently only directly opened disk device is allowed to access
    ioctl() - that is, when file has F_RAW flag set.
    
    The problem is, file systems might need to determine the device parameters,
    and we could use already opened device descriptor to communicate this
    information.
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D49077
---
 stand/libsa/ioctl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/stand/libsa/ioctl.c b/stand/libsa/ioctl.c
index 0c8613499ceb..cc592a454812 100644
--- a/stand/libsa/ioctl.c
+++ b/stand/libsa/ioctl.c
@@ -70,12 +70,12 @@ ioctl(int fd, u_long cmd, void *arg)
 		errno = EBADF;
 		return (-1);
 	}
-	if (f->f_flags & F_RAW) {
+	if (f->f_dev == NULL)
+		errno = EIO;
+	else
 		errno = (f->f_dev->dv_ioctl)(f, cmd, arg);
-		if (errno)
-			return (-1);
-		return (0);
-	}
-	errno = EIO;
-	return (-1);
+
+	if (errno != 0)
+		return (-1);
+	return (0);
 }