user1235126
user1235126

Reputation: 21

Why do VFS functions get both structs inode and file?

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

Answers (1)

myaut
myaut

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:

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);

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

Related Questions