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

Chinaunix

標(biāo)題: [我覺得奇怪]open方法為什么定義在file_operations,而不是inode_operations? [打印本頁]

作者: leviathan.alan    時間: 2006-06-14 16:43
標(biāo)題: [我覺得奇怪]open方法為什么定義在file_operations,而不是inode_operations?
  定義在file_operations, 那只有打開操作已經(jīng)完畢了, 才能調(diào)用這個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. }
復(fù)制代碼



而vfat的open干脆設(shè)置為NULL, 表示不實(shí)現(xiàn)。 我用模塊把ext3的open設(shè)置為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簡單在哪里啊~
作者: leviathan.alan    時間: 2006-06-15 15:16
頂    
作者: strongzgy    時間: 2006-06-17 01:02
標(biāo)題: 回復(fù) 1樓 leviathan.alan 的帖子
open方法對設(shè)備驅(qū)動的編寫很有用的,可用于設(shè)備初始化,向file結(jié)構(gòu)中加入private數(shù)據(jù)。如果放入inode_operations中,設(shè)備驅(qū)動就要編寫兩套函operations,一個用于讀寫設(shè)備文件,一個用于inode的打開設(shè)備文件。
將open,read,write,close放入同一個operations中,個人覺得很有道理,呵呵
作者: 圓點(diǎn)坐標(biāo)    時間: 2006-06-17 09:54
Solaris,HP-UX,AIX等就簡單多了,只有vnode operations操作集,簡單明了,linux則有2個操作集,一個inode操作集,一個file操作集。




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2