Linux Kernel FileSystems Sub-system - Introduction inodes - struct inode data-structureLinux Kernel FileSystems Sub-system - Introduction inodes - struct inode data-structure

Wiki File system ↗

Linux Kernel Source:
/fs/inode.c ↗
struct inode ↗

Linux Kernel – filesystem type specific inode handlers:
/fs/ext4/inode.c ↗
/fs/btrfs/inode.c ↗
/fs/ext2/inode.c ↗

Here is the struct inode (/include/linux/fs.h) from the Kernel-source version 6.5.9 for quick reference:

struct inode {
	umode_t			i_mode;
	unsigned short		i_opflags;
	kuid_t			i_uid;
	kgid_t			i_gid;
	unsigned int		i_flags;

	struct posix_acl	*i_acl;
	struct posix_acl	*i_default_acl;

	const struct inode_operations	*i_op;
	struct super_block	*i_sb;
	struct address_space	*i_mapping;

	void			*i_security;

	/* Stat data, not accessed from path walking */
	unsigned long		i_ino;
	 * Filesystems may only read i_nlink directly.  They shall use the
	 * following functions for modification:
	 *    (set|clear|inc|drop)_nlink
	 *    inode_(inc|dec)_link_count
	union {
		const unsigned int i_nlink;
		unsigned int __i_nlink;
	dev_t			i_rdev;
	loff_t			i_size;
	struct timespec64	i_atime;
	struct timespec64	i_mtime;
	struct timespec64	i_ctime;
	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
	unsigned short          i_bytes;
	u8			i_blkbits;
	u8			i_write_hint;
	blkcnt_t		i_blocks;

	seqcount_t		i_size_seqcount;

	/* Misc */
	unsigned long		i_state;
	struct rw_semaphore	i_rwsem;

	unsigned long		dirtied_when;	/* jiffies of first dirtying */
	unsigned long		dirtied_time_when;

	struct hlist_node	i_hash;
	struct list_head	i_io_list;	/* backing dev IO list */
	struct bdi_writeback	*i_wb;		/* the associated cgroup wb */

	/* foreign inode detection, see wbc_detach_inode() */
	int			i_wb_frn_winner;
	u16			i_wb_frn_avg_time;
	u16			i_wb_frn_history;
	struct list_head	i_lru;		/* inode LRU list */
	struct list_head	i_sb_list;
	struct list_head	i_wb_list;	/* backing dev writeback list */
	union {
		struct hlist_head	i_dentry;
		struct rcu_head		i_rcu;
	atomic64_t		i_version;
	atomic64_t		i_sequence; /* see futex */
	atomic_t		i_count;
	atomic_t		i_dio_count;
	atomic_t		i_writecount;
#if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING)
	atomic_t		i_readcount; /* struct files open RO */
	union {
		const struct file_operations	*i_fop;	/* former ->i_op->default_file_ops */
		void (*free_inode)(struct inode *);
	struct file_lock_context	*i_flctx;
	struct address_space	i_data;
	struct list_head	i_devices;
	union {
		struct pipe_inode_info	*i_pipe;
		struct cdev		*i_cdev;
		char			*i_link;
		unsigned		i_dir_seq;

	__u32			i_generation;

	__u32			i_fsnotify_mask; /* all events this inode cares about */
	struct fsnotify_mark_connector __rcu	*i_fsnotify_marks;

	struct fscrypt_info	*i_crypt_info;

	struct fsverity_info	*i_verity_info;

	void			*i_private; /* fs or device private pointer */
} __randomize_layout;