Skip to contentSkip to conversation

erofs-utils: tar: avoid linux-like hard-coded makedev()

PATCH New Gao Xiang 1 participant 1 message Mar 6 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: tar: avoid linux-like hard-coded makedev()

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.

Fixes 95d315fd7958 ("erofs-utils: introduce tarerofs")
Cc Derek McGowan <[email protected]>
---
 lib/tar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/tar.c +4 -1
index eca29f54c06f..26461f8cdbc9 100644
@@ -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));
Signature · 1 line
2.43.5