fs/proc/generic.c
Source file repositories/reference/linux-study-clean/fs/proc/generic.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/generic.c- Extension
.c- Size
- 20247 bytes
- Lines
- 858
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cache.hlinux/errno.hlinux/time.hlinux/proc_fs.hlinux/stat.hlinux/mm.hlinux/module.hlinux/namei.hlinux/slab.hlinux/printk.hlinux/mount.hlinux/init.hlinux/idr.hlinux/bitops.hlinux/spinlock.hlinux/completion.hlinux/uaccess.hlinux/seq_file.hinternal.h
Detected Declarations
function pde_freefunction proc_matchfunction pde_subdir_insertfunction proc_setattrfunction proc_getattrfunction __xlate_proc_namefunction xlate_proc_namefunction proc_alloc_inumfunction proc_free_inumfunction proc_misc_d_revalidatefunction proc_misc_d_deletefunction readdirfunction proc_readdirfunction proc_net_d_revalidatefunction pde_set_flagsfunction proc_seq_openfunction proc_seq_releasefunction proc_single_openfunction intfunction proc_set_sizefunction proc_set_userfunction pde_putfunction pde_erasefunction remove_proc_entryfunction remove_proc_subtreefunction proc_removefunction proc_simple_writefunction impl_proc_make_permanentexport proc_symlinkexport _proc_mkdirexport proc_mkdir_dataexport proc_mkdir_modeexport proc_mkdirexport proc_create_mount_pointexport proc_create_dataexport proc_createexport proc_create_seq_privateexport proc_create_single_dataexport proc_set_sizeexport proc_set_userexport remove_proc_entryexport remove_proc_subtreeexport proc_get_parent_dataexport proc_remove
Annotated Snippet
static const struct file_operations proc_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate_shared = proc_readdir,
};
static int proc_net_d_revalidate(struct inode *dir, const struct qstr *name,
struct dentry *dentry, unsigned int flags)
{
return 0;
}
const struct dentry_operations proc_net_dentry_ops = {
.d_revalidate = proc_net_d_revalidate,
.d_delete = always_delete_dentry,
};
/*
* proc directories can do almost nothing..
*/
static const struct inode_operations proc_dir_inode_operations = {
.lookup = proc_lookup,
.getattr = proc_getattr,
.setattr = proc_setattr,
};
static void pde_set_flags(struct proc_dir_entry *pde)
{
const struct proc_ops *proc_ops = pde->proc_ops;
if (!proc_ops)
return;
if (proc_ops->proc_flags & PROC_ENTRY_PERMANENT)
pde->flags |= PROC_ENTRY_PERMANENT;
if (proc_ops->proc_read_iter)
pde->flags |= PROC_ENTRY_proc_read_iter;
#ifdef CONFIG_COMPAT
if (proc_ops->proc_compat_ioctl)
pde->flags |= PROC_ENTRY_proc_compat_ioctl;
#endif
if (proc_ops->proc_lseek)
pde->flags |= PROC_ENTRY_proc_lseek;
}
/* returns the registered entry, or frees dp and returns NULL on failure */
struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
struct proc_dir_entry *dp)
{
if (proc_alloc_inum(&dp->low_ino))
goto out_free_entry;
if (!S_ISDIR(dp->mode))
pde_set_flags(dp);
write_lock(&proc_subdir_lock);
dp->parent = dir;
if (pde_subdir_insert(dir, dp) == false) {
WARN(1, "proc_dir_entry '%s/%s' already registered\n",
dir->name, dp->name);
write_unlock(&proc_subdir_lock);
goto out_free_inum;
}
dir->nlink++;
write_unlock(&proc_subdir_lock);
return dp;
out_free_inum:
proc_free_inum(dp->low_ino);
out_free_entry:
pde_free(dp);
return NULL;
}
static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
const char *name,
umode_t mode,
nlink_t nlink)
{
struct proc_dir_entry *ent = NULL;
const char *fn;
struct qstr qstr;
if (xlate_proc_name(name, parent, &fn) != 0)
goto out;
qstr.name = fn;
qstr.len = strnlen(fn, NAME_MAX + 1);
if (qstr.len == 0) {
WARN(1, "empty name\n");
return NULL;
Annotation
- Immediate include surface: `linux/cache.h`, `linux/errno.h`, `linux/time.h`, `linux/proc_fs.h`, `linux/stat.h`, `linux/mm.h`, `linux/module.h`, `linux/namei.h`.
- Detected declarations: `function pde_free`, `function proc_match`, `function pde_subdir_insert`, `function proc_setattr`, `function proc_getattr`, `function __xlate_proc_name`, `function xlate_proc_name`, `function proc_alloc_inum`, `function proc_free_inum`, `function proc_misc_d_revalidate`.
- 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.