免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4038 | 回复: 3
打印 上一主题 下一主题

[我觉得奇怪]open方法为什么定义在file_operations,而不是inode_operations? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-14 16:43 |只看该作者 |倒序浏览
  定义在file_operations, 那只有打开操作已经完毕了, 才能调用这个open方法。。 象ext2和ext3文件系统, 其open方法都定义为generic_file_open (见ext2_file_operations和ext3_file_operations的定义):

  1. int generic_file_open(struct inode * inode, struct file * filp)
  2. {
  3.         if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
  4.                 return -EFBIG;
  5.         return 0;
  6. }
复制代码



而vfat的open干脆设置为NULL, 表示不实现。 我用模块把ext3的open设置为NULL, 系统还是正常工作。

在vfs.txt中说:

  open: called by the VFS when an inode should be opened. When the VFS
        opens a file, it creates a new "struct file". It then calls the
        open method for the newly allocated file structure. You might
        think that the open method really belongs in
        "struct inode_operations", and you may be right. I think it's
        done the way it is because it makes filesystems simpler to
        implement. The open() method is a good place to initialize the
        "private_data" member in the file structure if you want to point
        to a device structure


作者对我这种疑问, 只说了一个理由:简单! 可我怎么就看不出来比放在inode_operations简单在哪里啊~

论坛徽章:
0
2 [报告]
发表于 2006-06-15 15:16 |只看该作者
顶    

论坛徽章:
0
3 [报告]
发表于 2006-06-17 01:02 |只看该作者

回复 1楼 leviathan.alan 的帖子

open方法对设备驱动的编写很有用的,可用于设备初始化,向file结构中加入private数据。如果放入inode_operations中,设备驱动就要编写两套函operations,一个用于读写设备文件,一个用于inode的打开设备文件。
将open,read,write,close放入同一个operations中,个人觉得很有道理,呵呵

论坛徽章:
0
4 [报告]
发表于 2006-06-17 09:54 |只看该作者
Solaris,HP-UX,AIX等就简单多了,只有vnode operations操作集,简单明了,linux则有2个操作集,一个inode操作集,一个file操作集。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP