LDD3之scull--从open系统调用到模块的scull_open执行流程分析

本帖的主要内容提供一个从系统调用open到内核中该文件实际的open方法的调用流程分析,基本上列出来从open系统调用到scull_open过程中调用的函数。

在这个过程中很多调用以及函数实现的细节还并不是很清楚。希望在随后的研究过程中,以及和别人的交流中,把这个调用流程丰富起来。

int open(const char *pathname, int flags, mode_t mode); --系统调用
                            ||
                            \/
long sys_open(const char __user *filename, int flags, int mode) -- fs/open.c
/*对应内核中的open接口函数*/
                            ||
                            \/
long do_sys_open(int dfd, const char __user *filename, int flags, int mode) --fs/open.c
/*用户空间的filename被拷贝到内核空间,获取当前可用的文件描述符*/
                            ||
                            \/
static struct file *do_filp_open(int dfd, const char *filename, int flags, int mode) --fs/open.c
                            ||
                            \/
int open_namei(int dfd, const char *pathname, int flag,
  int mode, struct nameidata *nd)
/*获取该文件对应的nameidata结构.该函数执行完毕,接着调用下面函数。这两个函数是顺序被do_filp_open调用*/
                            ||
                            \/
struct file *nameidata_to_filp(struct nameidata *nd, int flags) --fs/open.c
/*将nameidata 结构转换为打开的struct file结构*/
                            ||
                            \/
static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
     int flags, struct file *f,
     int (*open)(struct inode *, struct file *)) --fs/open.c
                            ||
                            \/
open = f->f_op->open;
open(inode, f);    --fs/open.c
/*以上两行代码分别完成了open系统调用时执行实际文件对应内核的open方法,即scull_open*/


open->sys_oepn->do_sys_open 从open到sys_open是系统调用产生了中断,查找到了系统调用表,open函数对应的系统调用表里面的就是sys_open函数
 
( The fd is not get in file_operations open function, which just do some initialization. If you do not need initialization or do it somewhere else, we can omit it.)
 
====
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值