2015-03-13 27 views
2

看來,struct file包含struct inode *,但都被傳遞給VFS功能。爲什麼不單純通過struct file *爲什麼VFS函數同時獲得結構inode和文件?

例如, int (*open) (struct inode *, struct file *);

+0

什麼樣的功能? 'vfs_read'沒有做到這一點:'vfs_read(結構文件*文件,字符__user * buf中,爲size_t計數,參數loff_t * POS)' – myaut 2015-03-13 13:01:00

+0

更specfic,我wnated知道爲什麼開()在file_operations結構既有的inode並翻轉。 int(* open)(struct inode *,struct file *); – user1235126 2015-03-13 13:51:31

+0

文件操作'open()'很少被文件系統使用。看到http://www.tldp.org/LDP/lki/lki-3.html – 2015-03-13 15:34:54

回答

2

簡短回答:由於歷史原因

他們開始從file_operations參數在Linux 2.1的刪除struct inode* - 即看一看2.1.60承諾:

http://repo.or.cz/w/davej-history.git/blobdiff/1018aab0cbe3c20a69685bfa5d217d3535067686..be6cc637f086b24887a11bd4bcc7445220c9b0ff:/include/linux/fs.h

@@ -533,9 +534,9 @@ struct super_block { 
typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t); 

struct file_operations { 
-  long long (*llseek) (struct file *, long long, int); 
-  long (*read) (struct inode *, struct file *, char *, unsigned long); 
-  long (*write) (struct inode *, struct file *, const char *, unsigned long); 
+  loff_t (*llseek) (struct file *, loff_t, int); 
+  ssize_t (*read) (struct file *, char *, size_t, loff_t *); 
+  ssize_t (*write) (struct file *, const char *, size_t, loff_t *); 
     int (*readdir) (struct file *, void *, filldir_t); 
     unsigned int (*poll) (struct file *, poll_table *); 
     int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 

我不知道爲什麼他們沒有做對於(*open)() - 可能是因爲在我們打開文件的時候,struct file*初始化未完成。

在現代性的核心do_dentry_open()這是否叫(*open)(),所以它是最基本的功能之前。

+0

大部分的外商投資企業系統的open()什麼也不做的實現。只有Coda在打開文件時使用緩存文件() – 2015-03-13 17:05:30

相關問題