Reputation: 21
It appears that struct file
contains a struct inode *
, yet both are passed to the VFS functions. Why not simply pass struct file *
alone?
For e.g. int (*open) (struct inode *, struct file *);
Upvotes: 2
Views: 373
Reputation: 11504
Short answer: for historical reasons.
They started to remove struct inode*
from file_operations
arguments in Linux 2.1 -- i.e. take a look at 2.1.60 commit:
@@ -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);
I don't know why they didn't do that for (*open)()
- probably because at the time we open file, initialization of struct file*
is not completed.
In modern kernel do_dentry_open()
does that before calling (*open)()
, so it is rudimentary feature.
Upvotes: 2