From: Andrei Tatar Date: Thu, 6 Feb 2025 11:28:50 +0000 (+0100) Subject: lib/posix-fdio: Fix wrong computation of dev_t X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=3fb282676952ff865fc8ed32ae50b2a862c3a69a;p=unikraft%2Funikraft.git lib/posix-fdio: Fix wrong computation of dev_t 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 . This change fixes this oversight, making stat() output correct. Signed-off-by: Andrei Tatar Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1578 --- diff --git a/lib/posix-fdio/fdstat.c b/lib/posix-fdio/fdstat.c index 8638c3416..26f24a9cf 100644 --- a/lib/posix-fdio/fdstat.c +++ b/lib/posix-fdio/fdstat.c @@ -7,6 +7,7 @@ /* Internal syscalls for manipulating file metadata */ #include +#include #include #include @@ -19,12 +20,6 @@ .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;