Skip to contentSkip to conversation

selftests/landlock: print st_ino as unsigned long long

PATCH In review Sasha Levin 3 participants 3 messages Nov 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/landlock: print st_ino as unsigned long long

On 32-bit architectures with a 64-bit ino_t, st_ino is an unsigned long long, and printing it with %lu warns:

fs_test.c:10511:57: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__ino64_t' {aka 'long long unsigned int'} [-Wformat=]

Cast it to unsigned long long and print it with %llu.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 tools/testing/selftests/landlock/fs_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/landlock/fs_test.c +2 -1
index f725882fa4a78..a2dc9a7f0481a 100644
@@ -10508,7 +10508,8 @@ TEST_F(trace_layout1, check_rule_fs_fields)
 	ASSERT_EQ(0, stat(dir_s1d1, &dir_stat));
 	snprintf(expected_dev, sizeof(expected_dev), "%u:%u",
 		 major(dir_stat.st_dev), minor(dir_stat.st_dev));
-	snprintf(expected_ino, sizeof(expected_ino), "%lu", dir_stat.st_ino);
+	snprintf(expected_ino, sizeof(expected_ino), "%llu",
+		 (unsigned long long)dir_stat.st_ino);
 
 	set_cap(_metadata, CAP_DAC_OVERRIDE);
 	ASSERT_EQ(0, tracefs_clear());
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

On 32-bit architectures with a 64-bit ino_t, st_ino is an unsigned long long, and printing it with %lu warns:

fs_test.c:10511:57: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__ino64_t' {aka 'long long unsigned int'} [-Wformat=]

Cast it to unsigned long long and print it with %llu.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Sasha Levin
Quoted 36 lines · Sasha Levin

On 32-bit architectures with a 64-bit ino_t, st_ino is an unsigned long long, and printing it with %lu warns:

fs_test.c:10511:57: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__ino64_t' {aka 'long long unsigned int'} [-Wformat=]

Cast it to unsigned long long and print it with %llu.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 tools/testing/selftests/landlock/fs_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/landlock/fs_test.c +2 -1
index f725882fa4a78..a2dc9a7f0481a 100644
@@ -10508,7 +10508,8 @@ TEST_F(trace_layout1, check_rule_fs_fields)
 	ASSERT_EQ(0, stat(dir_s1d1, &dir_stat));
 	snprintf(expected_dev, sizeof(expected_dev), "%u:%u",
 		 major(dir_stat.st_dev), minor(dir_stat.st_dev));
-	snprintf(expected_ino, sizeof(expected_ino), "%lu", dir_stat.st_ino);
+	snprintf(expected_ino, sizeof(expected_ino), "%llu",
+		 (unsigned long long)dir_stat.st_ino);
 
 	set_cap(_metadata, CAP_DAC_OVERRIDE);
 	ASSERT_EQ(0, tracefs_clear());
Signature · 1 line
2.53.0

Thank you!
–Günther