tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c- Extension
.c- Size
- 12714 bytes
- Lines
- 726
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- 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
fcntl.hlinux/mount.hlinux/stat.hsched.hstdio.hstring.hsys/mount.hsys/stat.hsys/types.hsys/wait.hunistd.h../utils.h../wrappers.hempty_mntns.hkselftest_harness.h
Detected Declarations
function Copyrightfunction FIXTURE
Annotated Snippet
if (fd >= 0) {
close(fd);
_exit(9);
}
if (errno != ENOENT)
_exit(10);
/*
* Use the new mount API to create tmpfs and get a mount fd.
* We need the fd because after attaching the tmpfs on top of
* "/", path resolution of "/" still returns the process root
* (nullfs) without following the overmount. The mount fd
* lets us fchdir + chroot into the tmpfs.
*/
fsfd = sys_fsopen("tmpfs", 0);
if (fsfd < 0)
_exit(11);
if (sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "size", "1M", 0)) {
close(fsfd);
_exit(12);
}
if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) {
close(fsfd);
_exit(13);
}
mntfd = sys_fsmount(fsfd, 0, 0);
close(fsfd);
if (mntfd < 0)
_exit(14);
if (sys_move_mount(mntfd, "", AT_FDCWD, "/",
MOVE_MOUNT_F_EMPTY_PATH)) {
close(mntfd);
_exit(15);
}
if (count_mounts() != 2) {
close(mntfd);
_exit(16);
}
/* Enter the tmpfs via the mount fd */
if (fchdir(mntfd)) {
close(mntfd);
_exit(17);
}
if (chroot(".")) {
close(mntfd);
_exit(18);
}
close(mntfd);
/* Verify "/" now resolves to tmpfs */
root_id = get_unique_mnt_id("/");
if (!root_id)
_exit(19);
sm = statmount_alloc(root_id, 0, STATMOUNT_FS_TYPE, 0);
if (!sm)
_exit(20);
if (!(sm->mask & STATMOUNT_FS_TYPE))
_exit(21);
if (strcmp(sm->str + sm->fs_type, "tmpfs") != 0)
_exit(22);
free(sm);
/* Verify tmpfs is writable */
fd = open("/testfile", O_CREAT | O_RDWR, 0644);
if (fd < 0)
_exit(23);
if (write(fd, "test", 4) != 4) {
close(fd);
_exit(24);
}
close(fd);
if (access("/testfile", F_OK))
_exit(25);
_exit(0);
Annotation
- Immediate include surface: `fcntl.h`, `linux/mount.h`, `linux/stat.h`, `sched.h`, `stdio.h`, `string.h`, `sys/mount.h`, `sys/stat.h`.
- Detected declarations: `function Copyright`, `function FIXTURE`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.