Linux vfs各种operation操作介绍

文章详细介绍了ext4文件系统对普通文件和目录文件的不同操作结构,包括file_operations和inode_operations中的方法定义。同时,通过例子展示了VFS在ls命令(打开目录和遍历)、mkdir命令(创建目录)以及cd命令(改变工作目录)中的调用路径,强调了内核如何通过这些操作实现文件系统的功能。
1.ext4文件系统定义的各种操作
//普通文件操作
const struct file_operations ext4_file_operations = {
    .llseek     = ext4_llseek,
    .read_iter  = generic_file_read_iter,
    .write_iter = ext4_file_write_iter,
    .unlocked_ioctl = ext4_ioctl,
#ifdef CONFIG_COMPAT
    .compat_ioctl   = ext4_compat_ioctl,
#endif
    .mmap       = ext4_file_mmap,
    .open       = ext4_file_open,
    .release    = ext4_release_file,
    .fsync      = ext4_sync_file,
    .splice_read    = generic_file_splice_read,
    .splice_write   = iter_file_splice_write,
    .fallocate  = ext4_fallocate,
};

//目录文件操作
const struct file_operations ext4_dir_operations = {
    .llseek     = ext4_dir_llseek,
    .read       = generic_read_dir,
    .iterate    = ext4_readdir,
    .unlocked_ioctl = ext4_ioctl,
#ifdef CONFIG_COMPAT
    .compat_ioctl   = ext4_compat_ioctl,
#endif
    .fsync      = ext4_sync_file,
    .open       = ext4_dir_open,
    .release    = ext4_release_dir,
};    

//普通文件inode操作
const struct inode_operations ext4_file_inode_operations = {                                                                                                                                                        
    .setattr    = ext4_setattr,
    .getattr    = ext4_getattr,
    .setxattr   = generic_setxattr,
    .getxattr   = generic_getxattr,
    .listxattr  = ext4_listxattr,
    .removexattr    = generic_removexattr,
    .get_acl    = ext4_get_acl,
    .set_acl    = ext4_set_acl,
    .fiemap     = ext4_fiemap,
};


/*
 * 目录文件的inode操作
 */
const struct inode_operations ext4_dir_inode_operations = {                                                                                                                                                         
    .create     = ext4_cre
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值