STRUCT FILE(9)
π struct file(9) β like, the whole entire file vibe π
okay so this is struct file, from the Kernel API Manual, bestie β yes it's struct file(9) and yes it's a big deal. it's the thing that represents a file in the kernel, and we're gonna go through literally every single member together because i refuse to let you fail this vibe check π«Ά
β¨ SYNOPSIS β¨
here's the whole struct, exactly as it lives, don't touch anything:
struct file {
spinlock_t f_lock;
fmode_t f_mode;
const struct file_operations *f_op;
struct address_space *f_mapping;
void *private_data;
struct inode *f_inode;
unsigned int f_flags;
unsigned int f_iocb_flags;
const struct cred *f_cred;
struct fown_struct *f_owner;
union {
const struct path f_path;
struct path __f_path;
};
union {
struct mutex f_pos_lock;
u64 f_pipe;
};
loff_t f_pos;
#ifdef CONFIG_SECURITY;
void *f_security;
#endif;
errseq_t f_wb_err;
errseq_t f_sb_err;
#ifdef CONFIG_EPOLL;
struct hlist_head *f_ep;
#endif;
union {
struct callback_head f_task_work;
struct llist_node f_llist;
struct file_ra_state f_ra;
freeptr_t f_freeptr;
};
file_ref_t f_ref;
};
πΈ Members πΈ
f_lockβ aspinlock_tthat protectsf_epandf_flags. huge caveat: it must not be taken from IRQ context. like, do not do that. periodt.f_modeβ theFMODE_*flags, and these babies show up in hotpaths so treat them with respect π₯f_opβ the file operations. the whole personality of the file tbh.f_mappingβ the contents of a cacheable, mappable object.private_dataβ filesystem or driver specific data. it's giving "your stuff goes here" β¨f_inodeβ the cached inode.f_flagsβ file flags.f_iocb_flagsβ iocb flags.f_credβ stashed credentials of whoever created/opened this file. lowkey the receipts πf_ownerβ file owner.{unnamed_union}β anonymous. (yes that's its whole description, we love a mysterious icon π)f_pathβ path of the file.__f_pathβ writable alias forf_path, and listen: ONLY for core VFS, and only before the file gets open. no cap, do not go playing with this π{unnamed_union}β anonymous. another one. iconic.f_pos_lockβ the lock protecting the file position.f_pipeβ specific to pipes πf_posβ file position.f_securityβ LSM security context of this file. (only around whenCONFIG_SECURITYis in the building)f_wb_errβ writeback error.f_sb_errβ per sb writeback errors.f_epβ link of all epoll hooks for this file. (hangs out only whenCONFIG_EPOLLsays so){unnamed_union}β anonymous. third one, slay.f_task_workβ task work entry point.f_llistβ work queue entrypoint.f_raβ the file's readahead state.f_freeptrβ pointer used by theSLAB_TYPESAFE_BY_RCUfile cache β and bestie, don't touch. literally. do not.f_refβ reference count. the main character of lifetime management fr fr π
π SEE ALSO π
Kernel file ./include/linux/fs.h β plus, like, a whole friend group of cross-references:
enum positive_aop_returns(9)struct address_space(9)struct file_ra_state(9)i_uid_into_vfsuid(9)i_uid_needs_update(9)i_uid_update(9)i_gid_into_vfsgid(9)i_gid_needs_update(9)i_gid_update(9)inode_fsuid_set(9)inode_fsgid_set(9)fsuidgid_has_mapping(9)inode_set_ctime(9)file_write_started(9)file_write_not_started(9)struct renamedata(9)is_mgtime(9)iput_if_not_last(9)is_idmapped_mnt(9)file_start_write(9)file_end_write(9)kiocb_start_write(9)kiocb_end_write(9)name_is_dot_dotdot(9)name_contains_dotdot(9)inode_dio_begin(9)inode_dio_end(9)generic_ci_validate_strict_name(9)
okay that's the whole page, every last flag and field accounted for π this one came from ./include/linux and it's dated October 2026 β so yeah, go forth and read those struct files, bestie, you ate πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms