fs/proc/fd.c
Source file repositories/reference/linux-study-clean/fs/proc/fd.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/fd.c- Extension
.c- Size
- 9104 bytes
- Lines
- 408
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/sched/signal.hlinux/errno.hlinux/dcache.hlinux/path.hlinux/fdtable.hlinux/namei.hlinux/pid.hlinux/ptrace.hlinux/bitmap.hlinux/security.hlinux/file.hlinux/seq_file.hlinux/fs.hlinux/filelock.hlinux/proc_fs.h../mount.hinternal.hfd.h
Detected Declarations
struct fd_datafunction seq_showfunction seq_fdinfo_openfunction proc_fdinfo_permissionfunction tid_fd_modefunction tid_fd_update_inodefunction tid_fd_revalidatefunction proc_fd_linkfunction proc_readfd_commonfunction proc_readfd_countfunction proc_fd_iteratefunction proc_fd_permissionfunction proc_fd_getattrfunction proc_lookupfdinfofunction proc_fdinfo_iterate
Annotated Snippet
static const struct file_operations proc_fdinfo_file_operations = {
.open = seq_fdinfo_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static bool tid_fd_mode(struct task_struct *task, unsigned fd, fmode_t *mode)
{
struct file *file;
file = fget_task(task, fd);
if (file) {
*mode = file->f_mode;
fput(file);
}
return !!file;
}
static void tid_fd_update_inode(struct task_struct *task, struct inode *inode,
fmode_t f_mode)
{
task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid);
if (S_ISLNK(inode->i_mode)) {
unsigned i_mode = S_IFLNK;
if (f_mode & FMODE_READ)
i_mode |= S_IRUSR | S_IXUSR;
if (f_mode & FMODE_WRITE)
i_mode |= S_IWUSR | S_IXUSR;
inode->i_mode = i_mode;
}
security_task_to_inode(task, inode);
}
static int tid_fd_revalidate(struct inode *dir, const struct qstr *name,
struct dentry *dentry, unsigned int flags)
{
struct task_struct *task;
struct inode *inode;
unsigned int fd;
if (flags & LOOKUP_RCU)
return -ECHILD;
inode = d_inode(dentry);
task = get_proc_task(inode);
fd = proc_fd(inode);
if (task) {
fmode_t f_mode;
if (tid_fd_mode(task, fd, &f_mode)) {
tid_fd_update_inode(task, inode, f_mode);
put_task_struct(task);
return 1;
}
put_task_struct(task);
}
return 0;
}
static const struct dentry_operations tid_fd_dentry_operations = {
.d_revalidate = tid_fd_revalidate,
.d_delete = pid_delete_dentry,
};
static int proc_fd_link(struct dentry *dentry, struct path *path,
struct task_struct *task)
{
int ret = -ENOENT;
unsigned int fd = proc_fd(d_inode(dentry));
struct file *fd_file;
fd_file = fget_task(task, fd);
if (fd_file) {
*path = fd_file->f_path;
path_get(&fd_file->f_path);
ret = 0;
fput(fd_file);
}
return ret;
}
struct fd_data {
fmode_t mode;
unsigned fd;
};
static struct dentry *proc_fd_instantiate(struct dentry *dentry,
Annotation
- Immediate include surface: `linux/sched/signal.h`, `linux/errno.h`, `linux/dcache.h`, `linux/path.h`, `linux/fdtable.h`, `linux/namei.h`, `linux/pid.h`, `linux/ptrace.h`.
- Detected declarations: `struct fd_data`, `function seq_show`, `function seq_fdinfo_open`, `function proc_fdinfo_permission`, `function tid_fd_mode`, `function tid_fd_update_inode`, `function tid_fd_revalidate`, `function proc_fd_link`, `function proc_readfd_common`, `function proc_readfd_count`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- 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.