fs/file_table.c
Source file repositories/reference/linux-study-clean/fs/file_table.c
File Facts
- System
- Linux kernel
- Corpus path
fs/file_table.c- Extension
.c- Size
- 17166 bytes
- Lines
- 668
- 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/string.hlinux/slab.hlinux/file.hlinux/init.hlinux/module.hlinux/fs.hlinux/filelock.hlinux/security.hlinux/cred.hlinux/eventpoll.hlinux/rcupdate.hlinux/mount.hlinux/capability.hlinux/cdev.hlinux/fsnotify.hlinux/sysctl.hlinux/percpu_counter.hlinux/percpu.hlinux/task_work.hlinux/swap.hlinux/kmemleak.hlinux/atomic.hasm/runtime-const.hinternal.h
Detected Declarations
struct backing_filefunction backing_file_set_user_pathfunction backing_file_set_securityfunction backing_file_freefunction file_freefunction get_nr_filesfunction get_max_filesfunction proc_nr_filesfunction init_fs_stat_sysctlsfunction init_filefunction __fputfunction alloc_empty_filefunction init_backing_filefunction alloc_empty_filefunction file_init_pathfunction alloc_path_pseudofunction __fputfunction delayed_fputfunction ____fputfunction flush_delayed_fputfunction __fput_deferredfunction fputfunction umountfunction __fput_syncfunction fputfunction files_initfunction files_maxfiles_initmodule init init_fs_stat_sysctlsexport backing_file_user_pathexport backing_file_set_user_pathexport get_max_filesexport alloc_empty_backing_fileexport alloc_file_pseudoexport alloc_file_pseudo_noaccountexport flush_delayed_fputexport fputexport __fput_sync
Annotated Snippet
* @fop: the 'struct file_operations' for the new file
*/
static void file_init_path(struct file *file, const struct path *path,
const struct file_operations *fop)
{
file->__f_path = *path;
file->f_inode = path->dentry->d_inode;
file->f_mapping = path->dentry->d_inode->i_mapping;
file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
file->f_sb_err = file_sample_sb_err(file);
if (fop->llseek)
file->f_mode |= FMODE_LSEEK;
if ((file->f_mode & FMODE_READ) &&
likely(fop->read || fop->read_iter))
file->f_mode |= FMODE_CAN_READ;
if ((file->f_mode & FMODE_WRITE) &&
likely(fop->write || fop->write_iter))
file->f_mode |= FMODE_CAN_WRITE;
file->f_iocb_flags = iocb_flags(file);
file->f_mode |= FMODE_OPENED;
file->f_op = fop;
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
i_readcount_inc(path->dentry->d_inode);
}
/**
* alloc_file - allocate and initialize a 'struct file'
*
* @path: the (dentry, vfsmount) pair for the new file
* @flags: O_... flags with which the new file will be opened
* @fop: the 'struct file_operations' for the new file
*/
static struct file *alloc_file(const struct path *path, int flags,
const struct file_operations *fop)
{
struct file *file;
file = alloc_empty_file(flags, current_cred());
if (!IS_ERR(file))
file_init_path(file, path, fop);
return file;
}
static inline int alloc_path_pseudo(const char *name, struct inode *inode,
struct vfsmount *mnt, struct path *path)
{
if (WARN_ON_ONCE(S_ISDIR(inode->i_mode)))
return -EINVAL;
path->dentry = d_alloc_pseudo(mnt->mnt_sb, &QSTR(name));
if (!path->dentry)
return -ENOMEM;
path->mnt = mntget(mnt);
d_instantiate(path->dentry, inode);
return 0;
}
struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt,
const char *name, int flags,
const struct file_operations *fops)
{
int ret;
struct path path;
struct file *file;
ret = alloc_path_pseudo(name, inode, mnt, &path);
if (ret)
return ERR_PTR(ret);
file = alloc_file(&path, flags, fops);
if (IS_ERR(file)) {
ihold(inode);
path_put(&path);
return file;
}
/*
* Disable all fsnotify events for pseudo files by default.
* They may be enabled by caller with file_set_fsnotify_mode().
*/
file_set_fsnotify_mode(file, FMODE_NONOTIFY);
return file;
}
EXPORT_SYMBOL(alloc_file_pseudo);
struct file *alloc_file_pseudo_noaccount(struct inode *inode,
struct vfsmount *mnt, const char *name,
int flags,
const struct file_operations *fops)
{
int ret;
struct path path;
Annotation
- Immediate include surface: `linux/string.h`, `linux/slab.h`, `linux/file.h`, `linux/init.h`, `linux/module.h`, `linux/fs.h`, `linux/filelock.h`, `linux/security.h`.
- Detected declarations: `struct backing_file`, `function backing_file_set_user_path`, `function backing_file_set_security`, `function backing_file_free`, `function file_free`, `function get_nr_files`, `function get_max_files`, `function proc_nr_files`, `function init_fs_stat_sysctls`, `function init_file`.
- 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.