亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1790 | 回復: 3
打印 上一主題 下一主題

[我覺得奇怪]open方法為什么定義在file_operations,而不是inode_operations? [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2006-06-14 16:43 |只看該作者 |倒序瀏覽
  定義在file_operations, 那只有打開操作已經完畢了, 才能調用這個open方法。。 象ext2和ext3文件系統(tǒng), 其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, 表示不實現(xiàn)。 我用模塊把ext3的open設置為NULL, 系統(tǒng)還是正常工作。

在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 [報告]
發(fā)表于 2006-06-15 15:16 |只看該作者
頂    

論壇徽章:
0
3 [報告]
發(fā)表于 2006-06-17 01:02 |只看該作者

回復 1樓 leviathan.alan 的帖子

open方法對設備驅動的編寫很有用的,可用于設備初始化,向file結構中加入private數(shù)據(jù)。如果放入inode_operations中,設備驅動就要編寫兩套函operations,一個用于讀寫設備文件,一個用于inode的打開設備文件。
將open,read,write,close放入同一個operations中,個人覺得很有道理,呵呵

論壇徽章:
0
4 [報告]
發(fā)表于 2006-06-17 09:54 |只看該作者
Solaris,HP-UX,AIX等就簡單多了,只有vnode operations操作集,簡單明了,linux則有2個操作集,一個inode操作集,一個file操作集。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP