Vídeos :: 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 ↗ Refer:
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;
write_lock(&file_systems_lock);
p = find_filesystem(fs->name, strlen(fs->name));
if (*p)
res = -EBUSY;
else
*p = fs;
write_unlock(&file_systems_lock);
return res;
}
EXPORT_SYMBOL(register_filesystem);
/**
* 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;
write_lock(&file_systems_lock);
tmp = &file_systems;
while (*tmp) {
if (fs == *tmp) {
*tmp = fs->next;
fs->next = NULL;
write_unlock(&file_systems_lock);
synchronize_rcu();
return 0;
}
tmp = &(*tmp)->next;
}
write_unlock(&file_systems_lock);
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_BINARY_MOUNTDATA 2
#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 ↗ Refer:
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;
#ifdef CONFIG_FS_POSIX_ACL
struct posix_acl *i_acl;
struct posix_acl *i_default_acl;
#endif
const struct inode_operations *i_op;
struct super_block *i_sb;
struct address_space *i_mapping;
#ifdef CONFIG_SECURITY
void *i_security;
#endif
/* 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;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_t i_size_seqcount;
#endif
/* 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 */
#ifdef CONFIG_CGROUP_WRITEBACK
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;
#endif
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;
#ifdef CONFIG_IMA
atomic_t i_readcount; /* struct files open RO */
#endif
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;
#ifdef CONFIG_FSNOTIFY
__u32 i_fsnotify_mask; /* all events this inode cares about */
struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
#endif
#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
struct fscrypt_info *i_crypt_info;
#endif
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 ↗ Refer:
Wiki:
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

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 ↗ Refer:
Wiki:
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: