【发布时间】:2012-03-12 17:49:24
【问题描述】:
我正在关注 open() 系统调用,以了解在创建文件期间 struct file_operations 和 struct file 何时连接.
主要路径如下:
sys_open -> do_sys_open -> do_filp_open -> nameidata_to_filp -> __dentry_open
在 __dentry_open 中
static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
int flags, struct file *f,
int (*open)(struct inode *, struct file *),
const struct cred *cred)
{
struct inode *inode;
int error;
f->f_flags = flags;
f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK |
FMODE_PREAD | FMODE_PWRITE;
inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
error = __get_file_write_access(inode, mnt);
if (error)
goto cleanup_file;
if (!special_file(inode->i_mode))
file_take_write(f);
}
f->f_mapping = inode->i_mapping;
f->f_path.dentry = dentry;
f->f_path.mnt = mnt;
f->f_pos = 0;
f->f_op = fops_get(inode->i_fop);//I think it is here that they get connected
file_move(f, &inode->i_sb->s_files);
error = security_dentry_open(f);
...
但是,inode 中的 i_fop 何时以及在哪个函数中被初始化?
【问题讨论】:
标签: c linux linux-kernel