Unverified Commit f79e6eb8 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Christian Brauner
Browse files

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: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20250106134802.1019911-1-geert+renesas@glider.be


Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 22eb23b8
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ static bool ext_format;
 * There are no bindings in glibc for listmount() and statmount() (yet),
 * make our own here.
 */
static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,
static int statmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 mask,
		     struct statmount *buf, size_t bufsize,
		     unsigned int flags)
{
@@ -50,9 +50,8 @@ static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,
	return syscall(__NR_statmount, &req, buf, bufsize, flags);
}

static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
			 uint64_t last_mnt_id, uint64_t list[], size_t num,
			 unsigned int flags)
static ssize_t listmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 last_mnt_id,
			 __u64 list[], size_t num, unsigned int flags)
{
	struct mnt_id_req req = {
		.size = MNT_ID_REQ_SIZE_VER0,
@@ -68,7 +67,7 @@ static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
	return syscall(__NR_listmount, &req, list, num, flags);
}

static void show_mnt_attrs(uint64_t flags)
static void show_mnt_attrs(__u64 flags)
{
	printf("%s", flags & MOUNT_ATTR_RDONLY ? "ro" : "rw");

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

static void show_sb_flags(uint64_t flags)
static void show_sb_flags(__u64 flags)
{
	printf("%s", flags & MS_RDONLY ? "ro" : "rw");
	if (flags & MS_SYNCHRONOUS)
@@ -125,11 +124,11 @@ static void show_sb_flags(uint64_t flags)
		printf(",lazytime");
}

static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
static int dump_mountinfo(__u64 mnt_id, __u64 mnt_ns_id)
{
	int ret;
	struct statmount *buf = alloca(STATMOUNT_BUFSIZE);
	const uint64_t mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
	const __u64 mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
			   STATMOUNT_PROPAGATE_FROM | STATMOUNT_FS_TYPE |
			   STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT |
			   STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE |
@@ -142,7 +141,7 @@ static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
	}

	if (ext_format)
		printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
		printf("0x%llx 0x%llx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);

	printf("%u %u %u:%u %s %s ", buf->mnt_id_old, buf->mnt_parent_id_old,
				   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)
	return 0;
}

static int dump_mounts(uint64_t mnt_ns_id)
static int dump_mounts(__u64 mnt_ns_id)
{
	uint64_t mntid[MAXMOUNTS];
	uint64_t last_mnt_id = 0;
	__u64 mntid[MAXMOUNTS];
	__u64 last_mnt_id = 0;
	ssize_t count;
	int i;