tools/testing/selftests/proc/fd-001-lookup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/fd-001-lookup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/fd-001-lookup.c- Extension
.c- Size
- 3678 bytes
- Lines
- 169
- 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.hdirent.herrno.hlimits.hsched.hstdio.hunistd.hsys/types.hsys/stat.hfcntl.hproc.h
Detected Declarations
function test_lookup_passfunction test_lookup_failfunction test_lookupfunction main
Annotated Snippet
if (de) {
unsigned long long fd_ull;
unsigned int fd;
char *end;
assert(de->d_type == DT_LNK);
fd_ull = xstrtoull(de->d_name, &end);
assert(*end == '\0');
assert(fd_ull == (unsigned int)fd_ull);
fd = fd_ull;
if (fd == dirfd(d))
goto next;
close(fd);
}
closedir(d);
} while (de);
/* Now fdtable is clean. */
fd = open("/", O_PATH|O_DIRECTORY);
assert(fd == 0);
test_lookup(fd);
close(fd);
/* Clean again! */
fd = open("/", O_PATH|O_DIRECTORY);
assert(fd == 0);
/* Default RLIMIT_NOFILE-1 */
target_fd = 1023;
while (target_fd > 0) {
if (dup2(fd, target_fd) == target_fd)
break;
target_fd /= 2;
}
assert(target_fd > 0);
close(fd);
test_lookup(target_fd);
close(target_fd);
return 0;
}
Annotation
- Immediate include surface: `assert.h`, `dirent.h`, `errno.h`, `limits.h`, `sched.h`, `stdio.h`, `unistd.h`, `sys/types.h`.
- Detected declarations: `function test_lookup_pass`, `function test_lookup_fail`, `function test_lookup`, `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.