VIDEOS 》 Linux Kernel FileSystems Subsystem

File system :: https://en.wikipedia.org/wiki/File_system
Linux Kernel Source:
/fs/filesystems.c :: http://elixir.free-electrons.com/linux/latest/source/fs/filesystems.c
register_filesystem(), unregister_filesystem() APIs :: http://elixir.free-electrons.com/linux/latest/source/fs/filesystems.c#L71
struct file_system_type data-structure :: http://elixir.free-electrons.com/linux/latest/source/include/linux/fs.h#L2068

Linux Kernel - ext4 filesystem type:
static struct file_system_type ext2_fs_type :: http://elixir.free-electrons.com/linux/latest/source/fs/ext4/super.c#L117
static struct file_system_type ext3_fs_type :: http://elixir.free-electrons.com/linux/latest/source/fs/ext4/super.c#L132
static struct file_system_type ext4_fs_type :: http://elixir.free-electrons.com/linux/latest/source/fs/ext4/super.c#L5774
static int __init ext4_init_fs(void) :: http://elixir.free-electrons.com/linux/latest/source/fs/ext4/super.c#L5786

Here is the register_filesystem(), unregister_filesystem() APIs (/fs/filesystems.c) from the Kernel-source version 4.14 for quick reference:

 *	register_filesystem - register a new filesystem
 *	@fs: the file system structure
 *	Adds the file system passed to the list of file systems the kernel
 *	is aware of for mount and other syscalls. Returns 0 on success,
 *	or a negative errno code on an error.
 *	The &struct file_system_type that is passed is linked into the kernel 
 *	structures and must not be freed until the file system has been
 *	unregistered.
int register_filesystem(struct file_system_type * fs)
	int res = 0;
	struct file_system_type ** p;

	BUG_ON(strchr(fs->name, '.'));
	if (fs->next)
		return -EBUSY;
	p = find_filesystem(fs->name, strlen(fs->name));
	if (*p)
		res = -EBUSY;
		*p = fs;
	return res;


 *	unregister_filesystem - unregister a file system
 *	@fs: filesystem to unregister
 *	Remove a file system that was previously successfully registered
 *	with the kernel. An error is returned if the file system is not found.
 *	Zero is returned on a success.
 *	Once this function has returned the &struct file_system_type structure
 *	may be freed or reused.
int unregister_filesystem(struct file_system_type * fs)
	struct file_system_type ** tmp;

	tmp = &file_systems;
	while (*tmp) {
		if (fs == *tmp) {
			*tmp = fs->next;
			fs->next = NULL;
			return 0;
		tmp = &(*tmp)->next;

	return -EINVAL;

Here is the struct file_system_type data-structure (/include/linux/fs.h) from the Kernel-source version 4.14 for quick reference:

struct file_system_type {
	const char *name;
	int fs_flags;
#define FS_REQUIRES_DEV		1 
#define FS_HAS_SUBTYPE		4
#define FS_USERNS_MOUNT		8	/* Can be mounted by userns root */
#define FS_RENAME_DOES_D_MOVE	32768	/* FS will handle d_move() during rename() internally. */
	struct dentry *(*mount) (struct file_system_type *, int,
		       const char *, void *);
	void (*kill_sb) (struct super_block *);
	struct module *owner;
	struct file_system_type * next;
	struct hlist_head fs_supers;

	struct lock_class_key s_lock_key;
	struct lock_class_key s_umount_key;
	struct lock_class_key s_vfs_rename_key;
	struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];

	struct lock_class_key i_lock_key;
	struct lock_class_key i_mutex_key;
	struct lock_class_key i_mutex_dir_key;

Linux Kernel Source:
/fs/inode.c :: http://elixir.free-electrons.com/linux/latest/source/fs/inode.c
struct inode :: http://elixir.free-electrons.com/linux/latest/source/include/linux/fs.h#L570

Linux Kernel - filesystem type specific inode handlers:
/fs/ext4/inode.c :: http://elixir.free-electrons.com/linux/latest/source/fs/ext4/inode.c
/fs/btrfs/inode.c :: http://elixir.free-electrons.com/linux/latest/source/fs/btrfs/inode.c
/fs/ext2/inode.c :: http://elixir.free-electrons.com/linux/latest/source/fs/ext2/inode.c

Here is the struct inode (/include/linux/fs.h) from the Kernel-source version 4.14 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 timespec		i_atime;
	struct timespec		i_mtime;
	struct timespec		i_ctime;
	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
	unsigned short          i_bytes;
	unsigned int		i_blkbits;
	enum rw_hint		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;
	u64			i_version;
	atomic_t		i_count;
	atomic_t		i_dio_count;
	atomic_t		i_writecount;
	atomic_t		i_readcount; /* struct files open RO */
	const struct file_operations	*i_fop;	/* former ->i_op->default_file_ops */
	struct file_lock_context	*i_flctx;
	struct address_space	i_data;
	struct list_head	i_devices;
	union {
		struct pipe_inode_info	*i_pipe;
		struct block_device	*i_bdev;
		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;

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

Virtual file system :: https://en.wikipedia.org/wiki/Virtual_file_system
Linux Kernel Storage Stack Diagram :: https://upload.wikimedia.org/wikipedia/commons/3/30/IO_stack_of_the_Linux_kernel.svg
Image - Linux Virtual File System :: https://www.ibm.com/developerworks/library/l-virtual-filesystem-switch/figure2.gif

Wiki - Linux Kernel Storage Stack Diagram
Linux Kernel Storage Stack Diagram
Image - Linux Virtual File System
Image - Linux Virtual File System

Virtual file system :: https://en.wikipedia.org/wiki/Virtual_file_system

Linux Kernel:
fs/namei.c - vfs_mknod(), vfs_mkdir(), vfs_rename() :: https://elixir.bootlin.com/linux/latest/source/fs/namei.c

Suggested Topics:

Video Episodes :: Linux Kernel programming

Linux Kernel Programming ↗
Saturday' 13-Mar-2021

Linux Kernel FileSystems Subsystem ↗
Saturday' 13-Mar-2021

Linux Operating System - User-space Processes ↗
Saturday' 14-May-2022

Linux Kernel /proc Interface ↗
Wednesday' 18-May-2022
/proc is one of the most popular kernel to user-space interface which you can leverage to add an interface to your Kernel code such as Kernel modules, Kernel Device Drivers, etc. Personally I prefer /proc interface than other alternatives such as /sysfs, ioctl() and so on for my personal Kernel modules/stack. So here is my detailed multi-episode Youtube video series on /sysfs Interface. I also conduct sessions/classes on Systems and Network software programming and architecture.

Linux ioctl() API interface ↗
Saturday' 13-Mar-2021
Watch detailed videos and read topics on Linux Kernel Programming and Linux ioctl() API interface

Linux Kernel Compilation ↗
Wednesday' 18-May-2022

Linux Kernel Programming - Device Drivers ↗
Saturday' 13-Mar-2021
Watch detailed videos and read topics on Linux Kernel Programming - Device Drivers

What is purpose of Kernel Development - Example SMOAD Networks SDWAN Orchestrator Firewall Kernel Engine ↗
Monday' 18-Jul-2022
Often aspiring students may have this question, that what is the purpose of Linux Kernel Development. Since Linux Kernel is very mature and it has almost everything one would need. Usually, we need custom kernel development in the case of any new driver development for new upcoming hardware. And this happens on and on. But at times we may also come across few features/modules/components which are already provided by the Linux Kernel which are not adequate or atleast not the way we exactly intended to use. So, this is the real-world example, sometimes no matter what Linux Kernel provides as a part of stock Kernel/OS features, sometimes we have to write our own custom kernel stack or module(s) which can specifically cater our exact needs.

Linux Kernel - Containers and Namespaces ↗
Saturday' 13-Mar-2021

Linux Kernel /sysfs Interface ↗
Saturday' 14-May-2022
/sysfs is one of the most popular kernel to user-space interface which you can leverage to add an interface to your Kernel code such as Kernel modules, Kernel Device Drivers, etc. Although personally I prefer /proc interface than other alternatives such as /sysfs, ioctl() and so on for my personal Kernel modules/stack. So here is my detailed multi-episode Youtube video series on /sysfs Interface.

Linux Kernel Architecture ↗
Wednesday' 18-May-2022

Join The Linux Channel :: Facebook Group ↗

Visit The Linux Channel :: on Youtube ↗

💗 Help shape the future: Sponsor/Donate

Recommended Topics:
Featured Video:
Watch on Youtube - [995//0] 262 Linux Kernel struct socket and struct sock data-structure - Introduction and code-walk - Ep1 ↗

Apache web-server installation ↗
Saturday' 13-Mar-2021

TCP Link Bonding vs Multipath TCP (MPTCP) ↗
Saturday' 13-Mar-2021

Tracking code changes in Linux Kernel Source code ↗
Saturday' 13-Mar-2021

Linux Kernel struct iphdr data-structure ↗
Saturday' 13-Mar-2021

MySQL database server installation ↗
Saturday' 13-Mar-2021

Building my own Userspace Network Stack - Platform/OS and Hardware Independent ↗
Saturday' 13-Mar-2021

PHP installation ↗
Saturday' 13-Mar-2021

Weekly News Digest - Week 01 - June 2020 ↗
Saturday' 13-Mar-2021
> UDOO BOLT GEAR AMD Ryzen Embedded V1605B Mini PC with Arduino Subsystem Launched for $399 > Systemd Will Change How Your Linux Home Directory Works > How to Manage Systemd Services on a Linux System > Linux 5.7 Kernel Released With New Apple Driver, Official Intel Gen12 Graphics > 8GB Raspberry Pi 4 on sale now at $75 > Bye Raspbian! Long Live Raspberry Pi OS! > Ultra-narrow DipDuino Arduino Compatible Board is a Perfect Breadboard Companion

Linux Kernel sk_buff data-structure - Episode-11 to Episode-18 ↗
Saturday' 13-Mar-2021

iPerf tool - for network channel analysis, bandwidth tests and system & network benchmarking ↗
Saturday' 13-Mar-2021

Trending Video:
Watch on Youtube - [456//0] 264 Linux Kernel struct ethhdr data-structure - Introduction, code-walk, eth_hdr(), skb_mac_header() APIs - Ep1 ↗

Oracle VM VirtualBox ↗
Saturday' 13-Mar-2021

Recommended Video:
Watch on Youtube - [447//0] x221 When to use | Multiprocessing Multithreading | Architecture | Big Picture #SystemsProgramming ↗