git: 6072eea0c375 - main - linux(4): Move translate_vnhook_major_minor() into the Linux common module

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Fri, 28 Apr 2023 08:57:07 UTC
The branch main has been updated by dchagin:

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

commit 6072eea0c375fc3ab0cf5bb494c75d1beac7b8ba
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-04-28 08:54:58 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-04-28 08:54:58 +0000

    linux(4): Move translate_vnhook_major_minor() into the Linux common module
---
 sys/compat/linux/linux_stats.c | 24 ------------------------
 sys/compat/linux/linux_util.c  | 26 ++++++++++++++++++++++++++
 sys/compat/linux/linux_util.h  |  3 +++
 3 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index 79937fd9fa86..219f4a602eb4 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -52,30 +52,6 @@ __FBSDID("$FreeBSD$");
 #include <compat/linux/linux_file.h>
 #include <compat/linux/linux_util.h>
 
-static void
-translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
-{
-	int major, minor;
-
-	if (vn_isdisk(vp)) {
-		sb->st_mode &= ~S_IFMT;
-		sb->st_mode |= S_IFBLK;
-	}
-
-	/*
-	 * Return the same st_dev for every devfs instance.  The reason
-	 * for this is to work around an idiosyncrasy of glibc getttynam()
-	 * implementation: it checks whether st_dev returned for fd 0
-	 * is the same as st_dev returned for the target of /proc/self/fd/0
-	 * symlink, and with linux chroots having their own devfs instance,
-	 * the check will fail if you chroot into it.
-	 */
-	if (rootdevmp != NULL && vp->v_mount->mnt_vfc == rootdevmp->mnt_vfc)
-		sb->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
-
-	if (linux_vn_get_major_minor(vp, &major, &minor) == 0)
-		sb->st_rdev = (major << 8 | minor);
-}
 
 static int
 linux_kern_statat(struct thread *td, int flag, int fd, const char *path,
diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c
index 6d82f87a3b31..dd739fde2551 100644
--- a/sys/compat/linux/linux_util.c
+++ b/sys/compat/linux/linux_util.c
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/namei.h>
 #include <sys/proc.h>
+#include <sys/stat.h>
 #include <sys/syscallsubr.h>
 #include <sys/vnode.h>
 
@@ -225,6 +226,31 @@ linux_vn_get_major_minor(const struct vnode *vp, int *major, int *minor)
 	return (error);
 }
 
+void
+translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
+{
+	int major, minor;
+
+	if (vn_isdisk(vp)) {
+		sb->st_mode &= ~S_IFMT;
+		sb->st_mode |= S_IFBLK;
+	}
+
+	/*
+	 * Return the same st_dev for every devfs instance.  The reason
+	 * for this is to work around an idiosyncrasy of glibc getttynam()
+	 * implementation: it checks whether st_dev returned for fd 0
+	 * is the same as st_dev returned for the target of /proc/self/fd/0
+	 * symlink, and with linux chroots having their own devfs instance,
+	 * the check will fail if you chroot into it.
+	 */
+	if (rootdevmp != NULL && vp->v_mount->mnt_vfc == rootdevmp->mnt_vfc)
+		sb->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
+
+	if (linux_vn_get_major_minor(vp, &major, &minor) == 0)
+		sb->st_rdev = (major << 8 | minor);
+}
+
 char *
 linux_get_char_devices(void)
 {
diff --git a/sys/compat/linux/linux_util.h b/sys/compat/linux/linux_util.h
index 37445ad0af27..f61aeea99136 100644
--- a/sys/compat/linux/linux_util.h
+++ b/sys/compat/linux/linux_util.h
@@ -105,6 +105,8 @@ struct linux_device_handler {
 	int	linux_char_device;
 };
 
+struct stat;
+
 int	linux_device_register_handler(struct linux_device_handler *h);
 int	linux_device_unregister_handler(struct linux_device_handler *h);
 char	*linux_driver_get_name_dev(device_t dev);
@@ -112,6 +114,7 @@ int	linux_driver_get_major_minor(const char *node, int *major, int *minor);
 int	linux_vn_get_major_minor(const struct vnode *vn, int *major, int *minor);
 char	*linux_get_char_devices(void);
 void	linux_free_get_char_devices(char *string);
+void	translate_vnhook_major_minor(struct vnode *vp, struct stat *sb);
 
 #if defined(KTR)