Skip to content

Commit f79e6eb

Browse files
geertubrauner
authored andcommitted
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: d95e49b ("samples: add a mountinfo program to demonstrate statmount()/listmount()") Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 22eb23b commit f79e6eb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

samples/vfs/mountinfo.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static bool ext_format;
3232
* There are no bindings in glibc for listmount() and statmount() (yet),
3333
* make our own here.
3434
*/
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)
3838
{
3939
struct mnt_id_req req = {
4040
.size = MNT_ID_REQ_SIZE_VER0,
@@ -50,9 +50,8 @@ static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,
5050
return syscall(__NR_statmount, &req, buf, bufsize, flags);
5151
}
5252

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)
5655
{
5756
struct mnt_id_req req = {
5857
.size = MNT_ID_REQ_SIZE_VER0,
@@ -68,7 +67,7 @@ static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
6867
return syscall(__NR_listmount, &req, list, num, flags);
6968
}
7069

71-
static void show_mnt_attrs(uint64_t flags)
70+
static void show_mnt_attrs(__u64 flags)
7271
{
7372
printf("%s", flags & MOUNT_ATTR_RDONLY ? "ro" : "rw");
7473

@@ -112,7 +111,7 @@ static void show_propagation(struct statmount *sm)
112111
printf(" unbindable");
113112
}
114113

115-
static void show_sb_flags(uint64_t flags)
114+
static void show_sb_flags(__u64 flags)
116115
{
117116
printf("%s", flags & MS_RDONLY ? "ro" : "rw");
118117
if (flags & MS_SYNCHRONOUS)
@@ -125,15 +124,15 @@ static void show_sb_flags(uint64_t flags)
125124
printf(",lazytime");
126125
}
127126

128-
static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
127+
static int dump_mountinfo(__u64 mnt_id, __u64 mnt_ns_id)
129128
{
130129
int ret;
131130
struct statmount *buf = alloca(STATMOUNT_BUFSIZE);
132-
const uint64_t 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;
131+
const __u64 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;
137136

138137
ret = statmount(mnt_id, mnt_ns_id, mask, buf, STATMOUNT_BUFSIZE, 0);
139138
if (ret < 0) {
@@ -142,7 +141,7 @@ static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
142141
}
143142

144143
if (ext_format)
145-
printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
144+
printf("0x%llx 0x%llx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
146145

147146
printf("%u %u %u:%u %s %s ", buf->mnt_id_old, buf->mnt_parent_id_old,
148147
buf->sb_dev_major, buf->sb_dev_minor,
@@ -166,10 +165,10 @@ static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
166165
return 0;
167166
}
168167

169-
static int dump_mounts(uint64_t mnt_ns_id)
168+
static int dump_mounts(__u64 mnt_ns_id)
170169
{
171-
uint64_t mntid[MAXMOUNTS];
172-
uint64_t last_mnt_id = 0;
170+
__u64 mntid[MAXMOUNTS];
171+
__u64 last_mnt_id = 0;
173172
ssize_t count;
174173
int i;
175174

0 commit comments

Comments
 (0)