linux(4): Move translate_vnhook_major_minor() into the Linux common module

This commit is contained in:
Dmitry Chagin 2023-04-28 11:54:58 +03:00
parent 2a38f51c5b
commit 6072eea0c3
3 changed files with 29 additions and 24 deletions

View file

@ -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,

View file

@ -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)
{

View file

@ -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)