]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdio: Fix wrong computation of dev_t
authorAndrei Tatar <andrei@unikraft.io>
Thu, 6 Feb 2025 11:28:50 +0000 (12:28 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Mon, 10 Feb 2025 10:46:41 +0000 (10:46 +0000)
Previously posix-fdio would compute the value of a dev_t from a
major/minor number pair wrong by naive bit shifting. The correct
computation is more involved and should use makedev() defined in
<sys/sysmacros.h>.
This change fixes this oversight, making stat() output correct.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1578

lib/posix-fdio/fdstat.c

index 8638c341625282d7d049ee95c9261e46213d744e..26f24a9cf2050283e4e5dee40cdcaa9ce2b4f3ae 100644 (file)
@@ -7,6 +7,7 @@
 /* Internal syscalls for manipulating file metadata */
 
 #include <string.h>
+#include <sys/sysmacros.h>
 
 #include <uk/posix-fdio.h>
 #include <uk/posix-time.h>
        .tv_nsec = (ts).tv_nsec \
 })
 
-static inline
-dev_t nums2dev(__u32 major, __u32 minor)
-{
-       return ((dev_t)major << 32) | minor;
-}
-
 static inline
 void timecpy(struct timespec *d, const struct uk_statx_timestamp *s)
 {
@@ -37,8 +32,8 @@ void uk_fdio_statx_cpyout(struct stat *s, const struct uk_statx *sx)
        unsigned int mask = sx->stx_mask;
 
        memset(s, 0, sizeof(*s));
-       s->st_dev = nums2dev(sx->stx_dev_major, sx->stx_dev_minor);
-       s->st_rdev = nums2dev(sx->stx_rdev_major, sx->stx_rdev_minor);
+       s->st_dev = makedev(sx->stx_dev_major, sx->stx_dev_minor);
+       s->st_rdev = makedev(sx->stx_rdev_major, sx->stx_rdev_minor);
        s->st_blksize = sx->stx_blksize;
        if (mask & UK_STATX_INO)
                s->st_ino = sx->stx_ino;