EXT4文件系统学习(12)VFS之文件系统对象file_system_type

Linux支持各种不同的文件系统,但是上层应用只需使用open(),read(),write()等系统调用就可以对磁盘文件进行操作,而不需关心具体文件系统的细节问题。为此提出了虚拟文件系统VFS,作为中间层屏蔽了底层不同文件系统之间的差异,向上提供统一的接口,虚拟文件系统根据不同的文件系统构造出超级块,inode和direntry等,这些结构在VFS中是一致的。

文件系统对象

每一个文件系统驱动程序都有一个文件系统对象,定义如下:

include/linux/fs.h

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_USERNS_DEV_MOUNT	16 /* A userns mount does not imply MNT_NODEV */
#define FS_USERNS_VISIBLE	32	/* FS must already be visible */
#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;
};

调用register_filesystem注册时文件系统对象,所以的文件系统对象通过struct file_system_type * next指针链接成链表,全部结构体变量static struct file_system_type *file_systems指向链表的头部。

register_filesystem在作用是把文件系统对象加入到链表中且防止重复。

ext4的file_system_type结构体成员赋值如下:

static struct file_system_type ext4_fs_type = {
	.owner		= THIS_MODULE,
	.name		= "ext4",
	.mount		= ext4_mount,
	.kill_sb	= kill_block_super,
	.fs_flags	= FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext4");

ext4文件系统注册:

fs/ext4/super.c
module_init(ext4_init_fs)
	register_as_ext3();开了宏CONFIG_EXT4_USE_FOR_EXT23会兼容ext3和ext2
	register_as_ext2();
	err = register_filesystem(&ext4_fs_type);

下一篇介绍VFS的超级块。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值