]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
samples/vfs: add STATMOUNT_MNT_{G,U}IDMAP
authorChristian Brauner <brauner@kernel.org>
Tue, 4 Feb 2025 11:27:49 +0000 (12:27 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 12 Feb 2025 11:12:27 +0000 (12:12 +0100)
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>
samples/vfs/samples-vfs.h
samples/vfs/test-list-all-mounts.c

index 103e1e7c4cec25d4ea8b65e5496175c380878806..498baf581b563ddd9884e93d0477e41e8b41e5fe 100644 (file)
@@ -42,7 +42,11 @@ struct statmount {
        __u32 opt_array;        /* [str] Array of nul terminated fs options */
        __u32 opt_sec_num;      /* Number of security options */
        __u32 opt_sec_array;    /* [str] Array of nul terminated security options */
-       __u64 __spare2[46];
+       __u32 mnt_uidmap_num;   /* Number of uid mappings */
+       __u32 mnt_uidmap;       /* [str] Array of uid mappings */
+       __u32 mnt_gidmap_num;   /* Number of gid mappings */
+       __u32 mnt_gidmap;       /* [str] Array of gid mappings */
+       __u64 __spare2[44];
        char str[];             /* Variable size part containing strings */
 };
 
@@ -158,6 +162,14 @@ struct mnt_ns_info {
 #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
 #endif
 
+#ifndef STATMOUNT_MNT_UIDMAP
+#define STATMOUNT_MNT_UIDMAP           0x00002000U     /* Want/got uidmap... */
+#endif
+
+#ifndef STATMOUNT_MNT_GIDMAP
+#define STATMOUNT_MNT_GIDMAP           0x00004000U     /* Want/got gidmap... */
+#endif
+
 #ifndef MOUNT_ATTR_RDONLY
 #define MOUNT_ATTR_RDONLY      0x00000001 /* Mount read-only */
 #endif
index ce272ded8a79ae87847b898ebd201a66c4863601..bb3b83d8f1d7cdfab83d61fe4144c6dca4ee334d 100644 (file)
@@ -128,14 +128,16 @@ next:
                                              STATMOUNT_MNT_POINT |
                                              STATMOUNT_MNT_NS_ID |
                                              STATMOUNT_MNT_OPTS |
-                                             STATMOUNT_FS_TYPE, 0);
+                                             STATMOUNT_FS_TYPE |
+                                             STATMOUNT_MNT_UIDMAP |
+                                             STATMOUNT_MNT_GIDMAP, 0);
                        if (!stmnt) {
                                printf("Failed to statmount(%" PRIu64 ") in mount namespace(%" PRIu64 ")\n",
                                       (uint64_t)last_mnt_id, (uint64_t)info.mnt_ns_id);
                                continue;
                        }
 
-                       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",
+                       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",
                               (uint64_t)stmnt->mnt_id,
                               (uint64_t)stmnt->mnt_parent_id,
                               (stmnt->mask & STATMOUNT_FS_TYPE)   ? stmnt->str + stmnt->fs_type   : "",
@@ -143,6 +145,26 @@ next:
                               (stmnt->mask & STATMOUNT_MNT_POINT) ? stmnt->str + stmnt->mnt_point : "",
                               (stmnt->mask & STATMOUNT_MNT_OPTS)  ? stmnt->str + stmnt->mnt_opts  : "");
 
+                       if (stmnt->mask & STATMOUNT_MNT_UIDMAP) {
+                               const char *idmap = stmnt->str + stmnt->mnt_uidmap;
+
+                               for (size_t idx = 0; idx < stmnt->mnt_uidmap_num; idx++) {
+                                       printf("mnt_uidmap[%lu]:\t%s\n", idx, idmap);
+                                       idmap += strlen(idmap) + 1;
+                               }
+                       }
+
+                       if (stmnt->mask & STATMOUNT_MNT_GIDMAP) {
+                               const char *idmap = stmnt->str + stmnt->mnt_gidmap;
+
+                               for (size_t idx = 0; idx < stmnt->mnt_gidmap_num; idx++) {
+                                       printf("mnt_gidmap[%lu]:\t%s\n", idx, idmap);
+                                       idmap += strlen(idmap) + 1;
+                               }
+                       }
+
+                       printf("\n");
+
                        free(stmnt);
                }
        }