aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_util.c
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2023-04-28 08:55:05 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2023-06-29 08:15:49 +0000
commit5e424fec72aafe1154ae23cd0674193e757a4d2a (patch)
tree71e9a04f94564d53463fb2872bf8d5f84dbd926c /sys/compat/linux/linux_util.c
parentb971d6aec11597dfdad36a53680c869062b7ba64 (diff)
linux(4): Uniformly dev_t arguments translation
The two main uses of dev_t are in struct stat and as a parameter of the mknod system calls. As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit quantity with 12 bits set asaid for the major number and 20 for the minor number. The in-kernel dev_t encoded as MMMmmmmm, where M is a hex digit of the major number and m is a hex digit of the minor number. The user-space dev_t encoded as mmmM MMmm, where M and m is the major and minor numbers accordingly. This is downward compatible with legacy systems where dev_t is 16 bits wide, encoded as MMmm. In glibc dev_t is a 64-bit quantity, with 32-bit major and minor numbers, encoded as MMMM Mmmm mmmM MMmm. This is downward compatible with the Linux kernel and with legacy systems where dev_t is 16 bits wide. In the FreeBSD dev_t is a 64-bit quantity. The major and minor numbers are encoded as MMMmmmMm, therefore conversion of the device numbers between Linux user-space and FreeBSD kernel required. (cherry picked from commit 166e2e5a9e87d32dbfc7838903904673873f1e71)
Diffstat (limited to 'sys/compat/linux/linux_util.c')
-rw-r--r--sys/compat/linux/linux_util.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c
index 5995ac5e18af..498320937fd3 100644
--- a/sys/compat/linux/linux_util.c
+++ b/sys/compat/linux/linux_util.c
@@ -35,6 +35,7 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/types.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
@@ -248,7 +249,7 @@ translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
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);
+ sb->st_rdev = makedev(major, minor);
}
char *