fs/d_path.c
Source file repositories/reference/linux-study-clean/fs/d_path.c
File Facts
- System
- Linux kernel
- Corpus path
fs/d_path.c- Extension
.c- Size
- 11760 bytes
- Lines
- 450
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/syscalls.hlinux/export.hlinux/uaccess.hlinux/fs_struct.hlinux/fs.hlinux/slab.hlinux/prefetch.hmount.hinternal.h
Detected Declarations
syscall getcwdstruct prepend_bufferfunction prepend_charfunction prepend_copyfunction prependfunction prepend_copyfunction __prepend_pathfunction prepend_pathfunction get_fs_root_rcufunction get_fs_root_and_pwd_rcuexport d_pathexport dentry_path_raw
Annotated Snippet
SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
{
int error;
struct path pwd, root;
char *page = __getname();
if (!page)
return -ENOMEM;
rcu_read_lock();
get_fs_root_and_pwd_rcu(current->fs, &root, &pwd);
if (unlikely(d_unlinked(pwd.dentry))) {
rcu_read_unlock();
error = -ENOENT;
} else {
unsigned len;
DECLARE_BUFFER(b, page, PATH_MAX);
prepend_char(&b, 0);
if (unlikely(prepend_path(&pwd, &root, &b) > 0))
prepend(&b, "(unreachable)", 13);
rcu_read_unlock();
len = PATH_MAX - b.len;
if (unlikely(len > PATH_MAX))
error = -ENAMETOOLONG;
else if (unlikely(len > size))
error = -ERANGE;
else if (copy_to_user(buf, b.buf, len))
error = -EFAULT;
else
error = len;
}
__putname(page);
return error;
}
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/export.h`, `linux/uaccess.h`, `linux/fs_struct.h`, `linux/fs.h`, `linux/slab.h`, `linux/prefetch.h`, `mount.h`.
- Detected declarations: `syscall getcwd`, `struct prepend_buffer`, `function prepend_char`, `function prepend_copy`, `function prepend`, `function prepend_copy`, `function __prepend_path`, `function prepend_path`, `function get_fs_root_rcu`, `function get_fs_root_and_pwd_rcu`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.