mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide
@ 2026-04-04  8:08 Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 1/6] selftests/nolibc: add some tests for makedev() and friends Thomas Weißschuh
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

Handle all possible values of minor and major numbers.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Stay compatible with applications expecting makedev(), major() or
  minor() to be macros.
- Link to v1: https://patch.msgid.link/20260331-nolibc-makedev-v1-0-ee79ee31e4d6@weissschuh.net

---
Thomas Weißschuh (6):
      selftests/nolibc: add some tests for makedev() and friends
      selftests/nolibc: add a test for stat().st_rdev
      tools/nolibc: move the logic of makedev() and friends into functions
      tools/nolibc: make dev_t 64 bits wide
      tools/nolibc: handle all major and minor numbers in makedev() and friends
      tools/nolibc: use makedev() in fstatat()

 tools/include/nolibc/std.h                   |  2 +-
 tools/include/nolibc/sys/stat.h              |  9 +++------
 tools/include/nolibc/sys/sysmacros.h         | 25 +++++++++++++++++++++----
 tools/testing/selftests/nolibc/nolibc-test.c |  7 +++++++
 4 files changed, 32 insertions(+), 11 deletions(-)
---
base-commit: 3b6f598c904f5f18506383ca279896d84a5d4f00
change-id: 20260331-nolibc-makedev-a002250090bd

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/6] selftests/nolibc: add some tests for makedev() and friends
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 2/6] selftests/nolibc: add a test for stat().st_rdev Thomas Weißschuh
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

These functions/macros are about to be changed.

Add some tests to make sure they continue working.
As they only handle small dev_t values, only test those for now.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index e6fef6eb1db1..4a9b6eb9e477 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1680,6 +1680,9 @@ int run_stdlib(int min, int max)
 		CASE_TEST(memchr_foobar6_o);        EXPECT_STREQ(1, memchr("foobar", 'o', 6), "oobar"); break;
 		CASE_TEST(memchr_foobar3_b);        EXPECT_STRZR(1, memchr("foobar", 'b', 3)); break;
 		CASE_TEST(time_types);              EXPECT_ZR(is_nolibc, test_time_types()); break;
+		CASE_TEST(makedev);                 EXPECT_EQ(1, makedev(0x12, 0x34), 0x1234); break;
+		CASE_TEST(major);                   EXPECT_EQ(1, major(0x1234), 0x12); break;
+		CASE_TEST(minor);                   EXPECT_EQ(1, minor(0x1234), 0x34); break;
 
 		case __LINE__:
 			return ret; /* must be last */

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/6] selftests/nolibc: add a test for stat().st_rdev
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 1/6] selftests/nolibc: add some tests for makedev() and friends Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 3/6] tools/nolibc: move the logic of makedev() and friends into functions Thomas Weißschuh
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

The handling of 'dev_t' values is about to be changed.

Add a test to make sure they are returned correctly from stat().

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 4a9b6eb9e477..88d076f67402 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1485,6 +1485,7 @@ int run_syscall(int min, int max)
 		CASE_TEST(select_fault);      EXPECT_SYSER(1, select(1, (void *)1, NULL, NULL, 0), -1, EFAULT); break;
 		CASE_TEST(stat_blah);         EXPECT_SYSER(1, stat("/proc/self/blah", &stat_buf), -1, ENOENT); break;
 		CASE_TEST(stat_fault);        EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break;
+		CASE_TEST(stat_rdev);         EXPECT_SYSZR(1, ({ int ret = stat("/dev/null", &stat_buf); ret ?: stat_buf.st_rdev != makedev(1, 3); })); break;
 		CASE_TEST(stat_timestamps);   EXPECT_SYSZR(1, test_stat_timestamps()); break;
 		CASE_TEST(symlink_root);      EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break;
 		CASE_TEST(timer);             EXPECT_SYSZR(1, test_timer()); break;

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 3/6] tools/nolibc: move the logic of makedev() and friends into functions
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 1/6] selftests/nolibc: add some tests for makedev() and friends Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 2/6] selftests/nolibc: add a test for stat().st_rdev Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 4/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

Functions make it easier to keep the input and output types straight and
avoid duplicate evaluations of their arguments.

Also these functions will become a bit more complex to handle full
64-bit 'dev_t' which is easier to read in a function.

Still stay compatible with code which expects these to be macros.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys/sysmacros.h | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/include/nolibc/sys/sysmacros.h b/tools/include/nolibc/sys/sysmacros.h
index 37c33f030f02..347a95341ea2 100644
--- a/tools/include/nolibc/sys/sysmacros.h
+++ b/tools/include/nolibc/sys/sysmacros.h
@@ -13,8 +13,25 @@
 #include "../std.h"
 
 /* WARNING, it only deals with the 4096 first majors and 256 first minors */
-#define makedev(major, minor) ((dev_t)((((major) & 0xfff) << 8) | ((minor) & 0xff)))
-#define major(dev) ((unsigned int)(((dev) >> 8) & 0xfff))
-#define minor(dev) ((unsigned int)((dev) & 0xff))
+static __inline__ dev_t __nolibc_makedev(unsigned int maj, unsigned int min)
+{
+	return ((maj & 0xfff) << 8) | (min & 0xff);
+}
+
+#define makedev(maj, min) __nolibc_makedev(maj, min)
+
+static __inline__ unsigned int __nolibc_major(dev_t dev)
+{
+	return (dev >> 8) & 0xfff;
+}
+
+#define major(dev) __nolibc_major(dev)
+
+static __inline__ unsigned int __nolibc_minor(dev_t dev)
+{
+	return dev & 0xff;
+}
+
+#define minor(dev) __nolibc_minor(dev)
 
 #endif /* _NOLIBC_SYS_SYSMACROS_H */

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 4/6] tools/nolibc: make dev_t 64 bits wide
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-04-04  8:08 ` [PATCH v2 3/6] tools/nolibc: move the logic of makedev() and friends into functions Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 5/6] tools/nolibc: handle all major and minor numbers in makedev() and friends Thomas Weißschuh
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

statx() returns both 32-bit minor and major numbers. For both of them to
fit into the 'dev_t' in 'struct stat', that needs to be 64 bits wide.

The other uses of 'dev_t' in nolibc are makedev() and friends and
mknod(). makedev() and friends are going to be adapted in an upcoming
commit and mknod() will silently truncate 'dev_t' to 'unsigned int' in
the kernel, similar to other libcs.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/std.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/nolibc/std.h b/tools/include/nolibc/std.h
index b9a116123902..dc2dc46f8ca8 100644
--- a/tools/include/nolibc/std.h
+++ b/tools/include/nolibc/std.h
@@ -19,7 +19,7 @@
 #include <linux/types.h>
 
 /* those are commonly provided by sys/types.h */
-typedef unsigned int          dev_t;
+typedef uint64_t              dev_t;
 typedef uint64_t              ino_t;
 typedef unsigned int         mode_t;
 typedef   signed int          pid_t;

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 5/6] tools/nolibc: handle all major and minor numbers in makedev() and friends
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2026-04-04  8:08 ` [PATCH v2 4/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:08 ` [PATCH v2 6/6] tools/nolibc: use makedev() in fstatat() Thomas Weißschuh
  2026-04-04  8:26 ` [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Willy Tarreau
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

Remove the limitation of only handling small major and minor numbers.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys/sysmacros.h         | 8 ++++----
 tools/testing/selftests/nolibc/nolibc-test.c | 3 +++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/include/nolibc/sys/sysmacros.h b/tools/include/nolibc/sys/sysmacros.h
index 347a95341ea2..ff9dd85ca59c 100644
--- a/tools/include/nolibc/sys/sysmacros.h
+++ b/tools/include/nolibc/sys/sysmacros.h
@@ -12,24 +12,24 @@
 
 #include "../std.h"
 
-/* WARNING, it only deals with the 4096 first majors and 256 first minors */
 static __inline__ dev_t __nolibc_makedev(unsigned int maj, unsigned int min)
 {
-	return ((maj & 0xfff) << 8) | (min & 0xff);
+	return (((dev_t)maj & ~0xfff) << 32) | ((maj & 0xfff) << 8) |
+	       (((dev_t)min & ~0xff) << 12) | (min & 0xff);
 }
 
 #define makedev(maj, min) __nolibc_makedev(maj, min)
 
 static __inline__ unsigned int __nolibc_major(dev_t dev)
 {
-	return (dev >> 8) & 0xfff;
+	return ((dev >> 32) & ~0xfff) | ((dev >> 8) & 0xfff);
 }
 
 #define major(dev) __nolibc_major(dev)
 
 static __inline__ unsigned int __nolibc_minor(dev_t dev)
 {
-	return dev & 0xff;
+	return ((dev >> 12) & ~0xff) | (dev & 0xff);
 }
 
 #define minor(dev) __nolibc_minor(dev)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 88d076f67402..7606a8b68d28 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1684,6 +1684,9 @@ int run_stdlib(int min, int max)
 		CASE_TEST(makedev);                 EXPECT_EQ(1, makedev(0x12, 0x34), 0x1234); break;
 		CASE_TEST(major);                   EXPECT_EQ(1, major(0x1234), 0x12); break;
 		CASE_TEST(minor);                   EXPECT_EQ(1, minor(0x1234), 0x34); break;
+		CASE_TEST(makedev_big);             EXPECT_EQ(1, makedev(0x11223344, 0x55667788), 0x1122355667734488); break;
+		CASE_TEST(major_big);               EXPECT_EQ(1, major(0x1122355667734488), 0x11223344); break;
+		CASE_TEST(minor_big);               EXPECT_EQ(1, minor(0x1122355667734488), 0x55667788); break;
 
 		case __LINE__:
 			return ret; /* must be last */

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 6/6] tools/nolibc: use makedev() in fstatat()
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
                   ` (4 preceding siblings ...)
  2026-04-04  8:08 ` [PATCH v2 5/6] tools/nolibc: handle all major and minor numbers in makedev() and friends Thomas Weißschuh
@ 2026-04-04  8:08 ` Thomas Weißschuh
  2026-04-04  8:26 ` [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Willy Tarreau
  6 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-04  8:08 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh

fstatat() contains two open-coded copies of makedev() to handle minor
numbers >= 256. Now that the regular makedev() handles both large minor
and major numbers correctly use the common function.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys/stat.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/tools/include/nolibc/sys/stat.h b/tools/include/nolibc/sys/stat.h
index b2ef34a617ca..07ae715ff253 100644
--- a/tools/include/nolibc/sys/stat.h
+++ b/tools/include/nolibc/sys/stat.h
@@ -13,6 +13,7 @@
 #include "../arch.h"
 #include "../types.h"
 #include "../sys.h"
+#include "../sys/sysmacros.h"
 
 /*
  * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
@@ -49,17 +50,13 @@ int fstatat(int fd, const char *path, struct stat *buf, int flag)
 	if (ret == -1)
 		return ret;
 
-	buf->st_dev          = ((statx.stx_dev_minor & 0xff)
-			       | (statx.stx_dev_major << 8)
-			       | ((statx.stx_dev_minor & ~0xff) << 12));
+	buf->st_dev          = makedev(statx.stx_dev_major, statx.stx_dev_minor);
 	buf->st_ino          = statx.stx_ino;
 	buf->st_mode         = statx.stx_mode;
 	buf->st_nlink        = statx.stx_nlink;
 	buf->st_uid          = statx.stx_uid;
 	buf->st_gid          = statx.stx_gid;
-	buf->st_rdev         = ((statx.stx_rdev_minor & 0xff)
-			       | (statx.stx_rdev_major << 8)
-			       | ((statx.stx_rdev_minor & ~0xff) << 12));
+	buf->st_rdev         = makedev(statx.stx_rdev_major, statx.stx_rdev_minor);
 	buf->st_size         = statx.stx_size;
 	buf->st_blksize      = statx.stx_blksize;
 	buf->st_blocks       = statx.stx_blocks;

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide
  2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
                   ` (5 preceding siblings ...)
  2026-04-04  8:08 ` [PATCH v2 6/6] tools/nolibc: use makedev() in fstatat() Thomas Weißschuh
@ 2026-04-04  8:26 ` Willy Tarreau
  6 siblings, 0 replies; 8+ messages in thread
From: Willy Tarreau @ 2026-04-04  8:26 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-kernel

Hi Thomas,

On Sat, Apr 04, 2026 at 10:08:17AM +0200, Thomas Weißschuh wrote:
> Handle all possible values of minor and major numbers.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Changes in v2:
> - Stay compatible with applications expecting makedev(), major() or
>   minor() to be macros.
> - Link to v1: https://patch.msgid.link/20260331-nolibc-makedev-v1-0-ee79ee31e4d6@weissschuh.net

Thanks for this. Your series looks good to me. I was also initially
concerned by the loss of macros but you addressed it in this series
so everything's fine from my perspective.

Acked-by: Willy Tarreau <w@1wt.eu>

Thanks,
willy

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-04  8:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-04  8:08 [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 1/6] selftests/nolibc: add some tests for makedev() and friends Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 2/6] selftests/nolibc: add a test for stat().st_rdev Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 3/6] tools/nolibc: move the logic of makedev() and friends into functions Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 4/6] tools/nolibc: make dev_t 64 bits wide Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 5/6] tools/nolibc: handle all major and minor numbers in makedev() and friends Thomas Weißschuh
2026-04-04  8:08 ` [PATCH v2 6/6] tools/nolibc: use makedev() in fstatat() Thomas Weißschuh
2026-04-04  8:26 ` [PATCH v2 0/6] tools/nolibc: make dev_t 64 bits wide Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®