[PATCH] erofs-utils: tar: avoid linux-like hard-coded makedev()
Gao Xiang
hsiangkao at linux.alibaba.com
Fri Mar 6 18:17:57 AEDT 2026
This code needs a way to construct a valid st_rdev (dev_t) from major
and minor device numbers, so that erofs_new_encode_dev() can later
convert the dev_t into the EROFS on-disk rdev format.
But it never uses makedev() to generate dev_t; instead,
erofs_new_encode_dev() uses major()/minor(), so the usage is unpaired
and the original one works only on the Linux platform and non-portable.
Reported-by: Kern Walster <kern.walster at gmail.com>
Closes: https://github.com/erofs/go-erofs/pull/9#issuecomment-4008973934
Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Cc: Derek McGowan <derek at mcg.dev>
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
lib/tar.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/tar.c b/lib/tar.c
index eca29f54c06f..26461f8cdbc9 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -11,6 +11,9 @@
#include "erofs/xattr.h"
#include "erofs/blobchunk.h"
#include "erofs/importer.h"
+#if defined(HAVE_SYS_SYSMACROS_H)
+#include <sys/sysmacros.h>
+#endif
#if defined(HAVE_ZLIB)
#include <zlib.h>
#endif
@@ -957,7 +960,7 @@ out_eot:
goto out;
}
- st.st_rdev = (major << 8) | (minor & 0xff) | ((minor & ~0xff) << 12);
+ st.st_rdev = makedev(major, minor);
} else if (th->typeflag == '1' || th->typeflag == '2') {
if (!eh.link)
eh.link = strndup(th->linkname, sizeof(th->linkname));
--
2.43.5
More information about the Linux-erofs
mailing list