tools/testing/selftests/bpf/prog_tests/test_bpffs.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_bpffs.c- Extension
.c- Size
- 4334 bytes
- Lines
- 165
- 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
stdio.hsched.hsys/mount.hsys/stat.hsys/types.htest_progs.h
Detected Declarations
function read_iterfunction fnfunction test_test_bpffs
Annotated Snippet
if (strstr(buf, "iter")) {
close(fd);
return 0;
}
}
close(fd);
return -1;
}
static int fn(void)
{
struct stat a, b, c;
int err, map;
err = unshare(CLONE_NEWNS);
if (!ASSERT_OK(err, "unshare"))
goto out;
err = mount("", "/", "", MS_REC | MS_PRIVATE, NULL);
if (!ASSERT_OK(err, "mount /"))
goto out;
err = mkdir(TDIR, 0777);
/* If the directory already exists we can carry on. It may be left over
* from a previous run.
*/
if ((err && errno != EEXIST) && !ASSERT_OK(err, "mkdir " TDIR))
goto out;
err = mount("none", TDIR, "tmpfs", 0, NULL);
if (!ASSERT_OK(err, "mount tmpfs"))
goto out;
err = mkdir(TDIR "/fs1", 0777);
if (!ASSERT_OK(err, "mkdir " TDIR "/fs1"))
goto out;
err = mkdir(TDIR "/fs2", 0777);
if (!ASSERT_OK(err, "mkdir " TDIR "/fs2"))
goto out;
err = mount("bpf", TDIR "/fs1", "bpf", 0, NULL);
if (!ASSERT_OK(err, "mount bpffs " TDIR "/fs1"))
goto out;
err = mount("bpf", TDIR "/fs2", "bpf", 0, NULL);
if (!ASSERT_OK(err, "mount bpffs " TDIR "/fs2"))
goto out;
err = read_iter(TDIR "/fs1/maps.debug");
if (!ASSERT_OK(err, "reading " TDIR "/fs1/maps.debug"))
goto out;
err = read_iter(TDIR "/fs2/progs.debug");
if (!ASSERT_OK(err, "reading " TDIR "/fs2/progs.debug"))
goto out;
err = mkdir(TDIR "/fs1/a", 0777);
if (!ASSERT_OK(err, "creating " TDIR "/fs1/a"))
goto out;
err = mkdir(TDIR "/fs1/a/1", 0777);
if (!ASSERT_OK(err, "creating " TDIR "/fs1/a/1"))
goto out;
err = mkdir(TDIR "/fs1/b", 0777);
if (!ASSERT_OK(err, "creating " TDIR "/fs1/b"))
goto out;
map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 4, 1, NULL);
if (!ASSERT_GT(map, 0, "create_map(ARRAY)"))
goto out;
err = bpf_obj_pin(map, TDIR "/fs1/c");
if (!ASSERT_OK(err, "pin map"))
goto out;
close(map);
/* Check that RENAME_EXCHANGE works for directories. */
err = stat(TDIR "/fs1/a", &a);
if (!ASSERT_OK(err, "stat(" TDIR "/fs1/a)"))
goto out;
err = renameat2(0, TDIR "/fs1/a", 0, TDIR "/fs1/b", RENAME_EXCHANGE);
if (!ASSERT_OK(err, "renameat2(/fs1/a, /fs1/b, RENAME_EXCHANGE)"))
goto out;
err = stat(TDIR "/fs1/b", &b);
if (!ASSERT_OK(err, "stat(" TDIR "/fs1/b)"))
goto out;
if (!ASSERT_EQ(a.st_ino, b.st_ino, "b should have a's inode"))
goto out;
err = access(TDIR "/fs1/b/1", F_OK);
if (!ASSERT_OK(err, "access(" TDIR "/fs1/b/1)"))
goto out;
/* Check that RENAME_EXCHANGE works for mixed file types. */
err = stat(TDIR "/fs1/c", &c);
Annotation
- Immediate include surface: `stdio.h`, `sched.h`, `sys/mount.h`, `sys/stat.h`, `sys/types.h`, `test_progs.h`.
- Detected declarations: `function read_iter`, `function fn`, `function test_test_bpffs`.
- 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.