STRUCT FILE(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 β€” a spinlock_t that protects f_ep and f_flags. huge caveat: it must not be taken from IRQ context. like, do not do that. periodt.
  • f_mode β€” the FMODE_* 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 for f_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 when CONFIG_SECURITY is 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 when CONFIG_EPOLL says 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 the SLAB_TYPESAFE_BY_RCU file 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:


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