The Linux Channel

Videos :: Linux Kernel FileSystems Subsystem

Written by: Kiran Kankipati - Published: 16-Dec-2017

Watch Video: 272 Linux Kernel FileSystems Subsystem - Intro - register_filesystem() unregister_filesystem() APIs - struct file_system_type data-structure - Ep1

* Click the image above to watch this video on Youtube ↗

File system ::
Linux Kernel Source:
/fs/filesystems.c ::
register_filesystem(), unregister_filesystem() APIs ::
struct file_system_type data-structure ::

Linux Kernel - ext4 filesystem type:
static struct file_system_type ext2_fs_type ::
static struct file_system_type ext3_fs_type ::
static struct file_system_type ext4_fs_type ::
static int __init ext4_init_fs(void) ::

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;

Watch Video: 276 Linux Kernel FileSystems Subsystem - Intro inodes - struct inode datastructure - Ep2

* Click the image above to watch this video on Youtube ↗

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 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;

Watch Video: 327 Linux Kernel FileSystems Subsystem - Role of VFS (Virtual File System) - Episode 3

* Click the image above to watch this video on Youtube ↗

Virtual file system ::
Linux Kernel Storage Stack Diagram ::
Image - Linux Virtual File System ::

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

Watch Video: 330 Linux Kernel FileSystems Subsystem - Tracing VFS APIs: vfs_mknod(), vfs_mkdir(), vfs_rename() - Ep4

* Click the image above to watch this video on Youtube ↗

Virtual file system ::

Linux Kernel:
fs/namei.c - vfs_mknod(), vfs_mkdir(), vfs_rename() ::

Suggested Topics:

Linux Kernel programming :: Video Episodes
 Linux Kernel Networking Sub-system ↗

 Linux Kernel struct ethhdr data-structure ↗

 Linux Kernel sk_buff data-structure - Episode-1 to Episode-10 ↗

 Linux Kernel net_device data-structure ↗

 Linux Kernel Architecture - Generic ↗

 Linux Kernel TCP Congestion Control Algorithms ↗

 Linux Kernel struct iphdr data-structure ↗

 Linux Kernel struct tcphdr data-structure ↗

 Linux Kernel dst_entry data-structure ↗

 Linux Kernel - Containers and Namespaces ↗

 Linux Kernel FileSystems Subsystem ↗

 Linux Kernel Programming - Device Drivers ↗

 Linux Kernel struct udphdr data-structure ↗

 Linux Kernel struct socket and struct sock data-structure ↗

 Linux Kernel /proc Interface ↗

 Linux Kernel Network Programming - struct net - struct netns_ipv4 - /proc/sys/net/ipv4 ↗

 Linux Kernel Compilation ↗

 Linux Kernel Programming ↗

 Linux Operating System - User-space Processes ↗

 Linux ioctl() API interface ↗

 Linux Kernel sk_buff data-structure - Episode-11 to Episode-18 ↗

 Linux Kernel Network Programming ↗


Join The Linux Channel :: Facebook Group

* This website is driven by AI.

Join a course:

💎 Linux Kernel and Systems Software: PDF Brochure

💎 Linux and Network Software Developer: PDF Brochure

💗 Help shape the future: Sponsor/Donate

Recommended Topics:
Featured Video:

* Click the image above to watch this video on Youtube ↗

Trending Video:

* Click the image above to watch this video on Youtube ↗

TUTORIALS :: UDP sample socket code for Systems and Network software developers:

Linux Kernel TCP Congestion Control Algorithms:
Linux Kernel Programming - Device Drivers:

Research :: Content Delivery Networks (CDN):
CDN Networks

Recommended Video:

* Click the image above to watch this video on Youtube ↗

The Linux Channel - v8.8 :: Updated: 30-Mar-2018 :: © 2018 :: Author: Kiran Kankipati
Your IP: :: Browser: CCBot/2.0 (