Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/vfs/mountinfo: Use __u64 instead of uint64_t

On 32-bit (e.g. arm32, m68k):

samples/vfs/mountinfo.c: In function ‘dump_mountinfo’:
samples/vfs/mountinfo.c:145:29: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
145 | printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
| ~~^ ~~~~~~~~~
| | |
| long unsigned int uint64_t {aka long long unsigned int}
| %llx
samples/vfs/mountinfo.c:145:35: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
145 | printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
| ~~^ ~~~~~~
| | |
| long unsigned int uint64_t {aka long long unsigned int}
| %llx

Just using "%llx" instead of "%lx" is not sufficient, as uint64_t is
"long unsigned int" on some 64-bit platforms like arm64. Hence also
replace "uint64_t" by "__u64", which matches what most other samples
are already using.

Fixes: d95e49bf8bcdc7c1 ("samples: add a mountinfo program to demonstrate statmount()/listmount()")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20250106134802.1019911-1-geert+renesas@glider.be
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Geert Uytterhoeven and committed by
Christian Brauner
f79e6eb8 22eb23b8

+17 -18
+17 -18
samples/vfs/mountinfo.c
··· 32 32 * There are no bindings in glibc for listmount() and statmount() (yet), 33 33 * make our own here. 34 34 */ 35 - static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask, 36 - struct statmount *buf, size_t bufsize, 37 - unsigned int flags) 35 + static int statmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 mask, 36 + struct statmount *buf, size_t bufsize, 37 + unsigned int flags) 38 38 { 39 39 struct mnt_id_req req = { 40 40 .size = MNT_ID_REQ_SIZE_VER0, ··· 50 50 return syscall(__NR_statmount, &req, buf, bufsize, flags); 51 51 } 52 52 53 - static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id, 54 - uint64_t last_mnt_id, uint64_t list[], size_t num, 55 - unsigned int flags) 53 + static ssize_t listmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 last_mnt_id, 54 + __u64 list[], size_t num, unsigned int flags) 56 55 { 57 56 struct mnt_id_req req = { 58 57 .size = MNT_ID_REQ_SIZE_VER0, ··· 67 68 return syscall(__NR_listmount, &req, list, num, flags); 68 69 } 69 70 70 - static void show_mnt_attrs(uint64_t flags) 71 + static void show_mnt_attrs(__u64 flags) 71 72 { 72 73 printf("%s", flags & MOUNT_ATTR_RDONLY ? "ro" : "rw"); 73 74 ··· 111 112 printf(" unbindable"); 112 113 } 113 114 114 - static void show_sb_flags(uint64_t flags) 115 + static void show_sb_flags(__u64 flags) 115 116 { 116 117 printf("%s", flags & MS_RDONLY ? "ro" : "rw"); 117 118 if (flags & MS_SYNCHRONOUS) ··· 124 125 printf(",lazytime"); 125 126 } 126 127 127 - static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id) 128 + static int dump_mountinfo(__u64 mnt_id, __u64 mnt_ns_id) 128 129 { 129 130 int ret; 130 131 struct statmount *buf = alloca(STATMOUNT_BUFSIZE); 131 - const uint64_t mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC | 132 - STATMOUNT_PROPAGATE_FROM | STATMOUNT_FS_TYPE | 133 - STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | 134 - STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE | 135 - STATMOUNT_SB_SOURCE; 132 + const __u64 mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC | 133 + STATMOUNT_PROPAGATE_FROM | STATMOUNT_FS_TYPE | 134 + STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | 135 + STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE | 136 + STATMOUNT_SB_SOURCE; 136 137 137 138 ret = statmount(mnt_id, mnt_ns_id, mask, buf, STATMOUNT_BUFSIZE, 0); 138 139 if (ret < 0) { ··· 141 142 } 142 143 143 144 if (ext_format) 144 - printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id); 145 + printf("0x%llx 0x%llx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id); 145 146 146 147 printf("%u %u %u:%u %s %s ", buf->mnt_id_old, buf->mnt_parent_id_old, 147 148 buf->sb_dev_major, buf->sb_dev_minor, ··· 165 166 return 0; 166 167 } 167 168 168 - static int dump_mounts(uint64_t mnt_ns_id) 169 + static int dump_mounts(__u64 mnt_ns_id) 169 170 { 170 - uint64_t mntid[MAXMOUNTS]; 171 - uint64_t last_mnt_id = 0; 171 + __u64 mntid[MAXMOUNTS]; 172 + __u64 last_mnt_id = 0; 172 173 ssize_t count; 173 174 int i; 174 175