ext2
物理数据结构
ext2文件系统中,存取的最小单位是块,在格式化分区为ext2时,可以指定块大小。
一个分区大小为4GB,块大小为4KB的 ext2物理数据结构为:
ext2内存数据结构
根据vfs的通用文件模型的要求,需要在内存中实现4个对象及其ops
1.超级块对象 super_block 和 super_operations
2.索引节点对象 inode (index node) 和 inode_operations
3.目录项对象 dentry 和 dentry_operations
4.文件对象 file 和 file_operations
1.注册文件系统 file_system_type
fs/ext2/super.cstatic struct file_system_type ext2_fs_type = {
.owner = THIS_MODULE,
.name = "ext2",
.mount = ext2_mount,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
在init_ext2_fs函数中注册
register_filesystem(&ext2_fs_type);
2.实现super_block 和 super_operations
在执行mount的时候,会填充super_block及其ops,如下
在ext2_mount()->ext2_fill_super()
sb->s_fs_info = ext2_sb_info
sb->s_op = &ext2_sops;
fs/ext2/super.c
static const struct super_operations ext2_sops = {
.alloc_inode = ext2_alloc_inode,
.destroy_inode = ext2_destroy_inode,
.write_inode = ext2_write_inode,
.evict_inode = ext2_evict_inode,
.put_super = ext2_put_super,
.write_super = ext2_write_super,
.sync_fs = ext2_sync_fs,
.statfs = ext2_statfs,
.remount_fs = ext2_remount,
.show_options = ext2_show_options,
#ifdef CONFIG_QUOTA
.quota_read = ext2_quota_read,
.quota_write = ext2_quota_write,
#endif
};
3.实现inode (index node) 和 inode_operations
fs/ext2/namei.c
const struct inode_operations ext2_dir_inode_operations = {
.create = ext2_create,
.lookup = ext2_lookup,
.link = ext2_link,
.unlink = ext2_unlink,
.symlink = ext2_symlink,
.mkdir = ext2_mkdir,
.rmdir = ext2_rmdir,
.mknod = ext2_mknod,
.rename = ext2_rename,
#ifdef CONFIG_EXT2_FS_XATTR
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = ext2_listxattr,
.removexattr = generic_removexattr,
#endif
.setattr = ext2_setattr,
.check_acl = ext2_check_acl,
};
4.实现dentry 和 dentry_operations
5.实现file 和 file_operations
fs/ext2/file.cconst struct file_operations ext2_file_operations = {
.llseek = generic_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
.unlocked_ioctl = ext2_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = ext2_compat_ioctl,
#endif
.mmap = generic_file_mmap,
.open = dquot_file_open,
.release = ext2_release_file,
.fsync = ext2_fsync,
.splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
};