Skip to content

Commit fa204a6

Browse files
committed
samples/vfs: add STATMOUNT_MNT_{G,U}IDMAP
Illustrate how to use STATMOUNT_MNT_{G,U}IDMAP. Link: https://lore.kernel.org/r/20250204-work-mnt_idmap-statmount-v2-4-007720f39f2e@kernel.org Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a496dfe commit fa204a6

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

samples/vfs/samples-vfs.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ struct statmount {
4242
__u32 opt_array; /* [str] Array of nul terminated fs options */
4343
__u32 opt_sec_num; /* Number of security options */
4444
__u32 opt_sec_array; /* [str] Array of nul terminated security options */
45-
__u64 __spare2[46];
45+
__u32 mnt_uidmap_num; /* Number of uid mappings */
46+
__u32 mnt_uidmap; /* [str] Array of uid mappings */
47+
__u32 mnt_gidmap_num; /* Number of gid mappings */
48+
__u32 mnt_gidmap; /* [str] Array of gid mappings */
49+
__u64 __spare2[44];
4650
char str[]; /* Variable size part containing strings */
4751
};
4852

@@ -158,6 +162,14 @@ struct mnt_ns_info {
158162
#define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
159163
#endif
160164

165+
#ifndef STATMOUNT_MNT_UIDMAP
166+
#define STATMOUNT_MNT_UIDMAP 0x00002000U /* Want/got uidmap... */
167+
#endif
168+
169+
#ifndef STATMOUNT_MNT_GIDMAP
170+
#define STATMOUNT_MNT_GIDMAP 0x00004000U /* Want/got gidmap... */
171+
#endif
172+
161173
#ifndef MOUNT_ATTR_RDONLY
162174
#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
163175
#endif

samples/vfs/test-list-all-mounts.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,43 @@ int main(int argc, char *argv[])
128128
STATMOUNT_MNT_POINT |
129129
STATMOUNT_MNT_NS_ID |
130130
STATMOUNT_MNT_OPTS |
131-
STATMOUNT_FS_TYPE, 0);
131+
STATMOUNT_FS_TYPE |
132+
STATMOUNT_MNT_UIDMAP |
133+
STATMOUNT_MNT_GIDMAP, 0);
132134
if (!stmnt) {
133135
printf("Failed to statmount(%" PRIu64 ") in mount namespace(%" PRIu64 ")\n",
134136
(uint64_t)last_mnt_id, (uint64_t)info.mnt_ns_id);
135137
continue;
136138
}
137139

138-
printf("mnt_id:\t\t%" PRIu64 "\nmnt_parent_id:\t%" PRIu64 "\nfs_type:\t%s\nmnt_root:\t%s\nmnt_point:\t%s\nmnt_opts:\t%s\n\n",
140+
printf("mnt_id:\t\t%" PRIu64 "\nmnt_parent_id:\t%" PRIu64 "\nfs_type:\t%s\nmnt_root:\t%s\nmnt_point:\t%s\nmnt_opts:\t%s\n",
139141
(uint64_t)stmnt->mnt_id,
140142
(uint64_t)stmnt->mnt_parent_id,
141143
(stmnt->mask & STATMOUNT_FS_TYPE) ? stmnt->str + stmnt->fs_type : "",
142144
(stmnt->mask & STATMOUNT_MNT_ROOT) ? stmnt->str + stmnt->mnt_root : "",
143145
(stmnt->mask & STATMOUNT_MNT_POINT) ? stmnt->str + stmnt->mnt_point : "",
144146
(stmnt->mask & STATMOUNT_MNT_OPTS) ? stmnt->str + stmnt->mnt_opts : "");
145147

148+
if (stmnt->mask & STATMOUNT_MNT_UIDMAP) {
149+
const char *idmap = stmnt->str + stmnt->mnt_uidmap;
150+
151+
for (size_t idx = 0; idx < stmnt->mnt_uidmap_num; idx++) {
152+
printf("mnt_uidmap[%lu]:\t%s\n", idx, idmap);
153+
idmap += strlen(idmap) + 1;
154+
}
155+
}
156+
157+
if (stmnt->mask & STATMOUNT_MNT_GIDMAP) {
158+
const char *idmap = stmnt->str + stmnt->mnt_gidmap;
159+
160+
for (size_t idx = 0; idx < stmnt->mnt_gidmap_num; idx++) {
161+
printf("mnt_gidmap[%lu]:\t%s\n", idx, idmap);
162+
idmap += strlen(idmap) + 1;
163+
}
164+
}
165+
166+
printf("\n");
167+
146168
free(stmnt);
147169
}
148170
}

0 commit comments

Comments
 (0)