tools/testing/selftests/mount/nosymfollow-test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mount/nosymfollow-test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mount/nosymfollow-test.c- Extension
.c- Size
- 4515 bytes
- Lines
- 219
- 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
errno.hfcntl.hlimits.hsched.hstdarg.hstdbool.hstdio.hstdlib.hstring.hsys/mount.hsys/stat.hsys/types.hsys/vfs.hunistd.h
Detected Declarations
function diefunction vmaybe_write_filefunction maybe_write_filefunction write_filefunction create_and_enter_nsfunction setup_symlinkfunction test_link_traversalfunction test_readlinkfunction test_realpathfunction test_statfsfunction run_testsfunction main
Annotated Snippet
if (written >= 0) {
die("short write to %s\n", filename);
} else {
die("write to %s failed: %s\n",
filename, strerror(errno));
}
}
if (close(fd) != 0)
die("close of %s failed: %s\n", filename, strerror(errno));
}
static void maybe_write_file(char *filename, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vmaybe_write_file(true, filename, fmt, ap);
va_end(ap);
}
static void write_file(char *filename, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vmaybe_write_file(false, filename, fmt, ap);
va_end(ap);
}
static void create_and_enter_ns(void)
{
uid_t uid = getuid();
gid_t gid = getgid();
if (unshare(CLONE_NEWUSER) != 0)
die("unshare(CLONE_NEWUSER) failed: %s\n", strerror(errno));
maybe_write_file("/proc/self/setgroups", "deny");
write_file("/proc/self/uid_map", "0 %d 1", uid);
write_file("/proc/self/gid_map", "0 %d 1", gid);
if (setgid(0) != 0)
die("setgid(0) failed %s\n", strerror(errno));
if (setuid(0) != 0)
die("setuid(0) failed %s\n", strerror(errno));
if (unshare(CLONE_NEWNS) != 0)
die("unshare(CLONE_NEWNS) failed: %s\n", strerror(errno));
}
static void setup_symlink(void)
{
int data, err;
data = creat(DATA, O_RDWR);
if (data < 0)
die("creat failed: %s\n", strerror(errno));
err = symlink(DATA, LINK);
if (err < 0)
die("symlink failed: %s\n", strerror(errno));
if (close(data) != 0)
die("close of %s failed: %s\n", DATA, strerror(errno));
}
static void test_link_traversal(bool nosymfollow)
{
int link;
link = open(LINK, 0, O_RDWR);
if (nosymfollow) {
if ((link != -1 || errno != ELOOP)) {
die("link traversal unexpected result: %d, %s\n",
link, strerror(errno));
}
} else {
if (link < 0)
die("link traversal failed: %s\n", strerror(errno));
if (close(link) != 0)
die("close of link failed: %s\n", strerror(errno));
}
}
static void test_readlink(void)
{
char buf[4096];
ssize_t ret;
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `limits.h`, `sched.h`, `stdarg.h`, `stdbool.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `function die`, `function vmaybe_write_file`, `function maybe_write_file`, `function write_file`, `function create_and_enter_ns`, `function setup_symlink`, `function test_link_traversal`, `function test_readlink`, `function test_realpath`, `function test_statfs`.
- 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.