samples/vfs/test-list-all-mounts.c
Source file repositories/reference/linux-study-clean/samples/vfs/test-list-all-mounts.c
File Facts
- System
- Linux kernel
- Corpus path
samples/vfs/test-list-all-mounts.c- Extension
.c- Size
- 4647 bytes
- Lines
- 174
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hlimits.hlinux/types.hinttypes.hstdio.h../../tools/testing/selftests/pidfd/pidfd.hsamples-vfs.h
Detected Declarations
function __statmountfunction sys_listmountfunction main
Annotated Snippet
if (nr_mounts <= 0) {
int fd_mntns_next;
printf("Finished listing %u mounts for mount namespace %" PRIu64 "\n\n",
info.nr_mounts, (uint64_t)info.mnt_ns_id);
fd_mntns_next = ioctl(fd_mntns, NS_MNT_GET_NEXT, &info);
if (fd_mntns_next < 0) {
if (errno == ENOENT) {
printf("Finished listing all mount namespaces\n");
exit(0);
}
die_errno("ioctl(NS_MNT_GET_NEXT) failed");
}
close(fd_mntns);
fd_mntns = fd_mntns_next;
last_mnt_id = 0;
printf("Listing %u mounts for mount namespace %" PRIu64 "\n",
info.nr_mounts, (uint64_t)info.mnt_ns_id);
goto next;
}
for (size_t cur = 0; cur < nr_mounts; cur++) {
struct statmount *stmnt;
last_mnt_id = list[cur];
stmnt = sys_statmount(last_mnt_id, info.mnt_ns_id,
STATMOUNT_SB_BASIC |
STATMOUNT_MNT_BASIC |
STATMOUNT_MNT_ROOT |
STATMOUNT_MNT_POINT |
STATMOUNT_MNT_NS_ID |
STATMOUNT_MNT_OPTS |
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",
(uint64_t)stmnt->mnt_id,
(uint64_t)stmnt->mnt_parent_id,
(stmnt->mask & STATMOUNT_FS_TYPE) ? stmnt->str + stmnt->fs_type : "",
(stmnt->mask & STATMOUNT_MNT_ROOT) ? stmnt->str + stmnt->mnt_root : "",
(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[%zu]:\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[%zu]:\t%s\n", idx, idmap);
idmap += strlen(idmap) + 1;
}
}
printf("\n");
free(stmnt);
}
}
exit(0);
}
Annotation
- Immediate include surface: `errno.h`, `limits.h`, `linux/types.h`, `inttypes.h`, `stdio.h`, `../../tools/testing/selftests/pidfd/pidfd.h`, `samples-vfs.h`.
- Detected declarations: `function __statmount`, `function sys_listmount`, `function main`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.