tools/testing/selftests/proc/read.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/read.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/read.c- Extension
.c- Size
- 3548 bytes
- Lines
- 149
- 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
assert.herrno.hsys/types.hdirent.hstdbool.hstdlib.hstdio.hstring.hsys/stat.hsys/vfs.hfcntl.hunistd.hproc.h
Detected Declarations
function f_regfunction f_reg_writefunction f_lnkfunction ffunction main
Annotated Snippet
switch (de->d_type) {
DIR *dd;
int fd;
case DT_REG:
if (level == 0 && streq(de->d_name, "sysrq-trigger")) {
f_reg_write(d, de->d_name, "h", 1);
} else if (level == 1 && streq(de->d_name, "clear_refs")) {
f_reg_write(d, de->d_name, "1", 1);
} else if (level == 3 && streq(de->d_name, "clear_refs")) {
f_reg_write(d, de->d_name, "1", 1);
} else {
f_reg(d, de->d_name);
}
break;
case DT_DIR:
fd = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY);
if (fd == -1)
continue;
dd = fdopendir(fd);
if (!dd)
continue;
f(dd, level + 1);
closedir(dd);
break;
case DT_LNK:
f_lnk(d, de->d_name);
break;
default:
assert(0);
}
}
}
int main(void)
{
DIR *d;
struct statfs sfs;
d = opendir("/proc");
if (!d)
return 4;
/* Ensure /proc is proc. */
if (fstatfs(dirfd(d), &sfs) == -1) {
return 1;
}
if (sfs.f_type != 0x9fa0) {
fprintf(stderr, "error: unexpected f_type %lx\n", (long)sfs.f_type);
return 2;
}
f(d, 0);
return 0;
}
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `sys/types.h`, `dirent.h`, `stdbool.h`, `stdlib.h`, `stdio.h`, `string.h`.
- Detected declarations: `function f_reg`, `function f_reg_write`, `function f_lnk`, `function f`, `function main`.
- 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.