- 论坛徽章:
- 0
|
本帖最后由 xiongweixie 于 2013-01-16 04:06 编辑
调用顺序如下
syscall_define3->do_Sys_open->do_filp_open->path_openat->
path_init, link_path_walk, do_last.
在path_init中就将 dentry 跟 inode 赋值给 nd (nameidata的数据结构)了。
path_init 中有三个大的条件判断:- if (flags & LOOKUP_ROOT){ //是否找root
- ...
- }
- ...
- if (*name=='/') { //是否为根目录
- ...
- }else if (dfd == AT_FDCWD) { //是否当前目录,cwd current work directory
- ...
- }else { ///应该是进入这里,正常的话
- struct dentry *dentry;
- file = fget_raw_light(dfd, &fput_needed); //在这里
- retval = -EBADF;
- if (!file)
- goto out_fail;
- dentry = file->f_path.dentry; // 这里就file里就有文件的dentry了,说明inode也已经找到了,fget_raw_light 这个函数干的这个事情?
- ...
- }
复制代码- struct file *fget_raw_light(unsigned int fd, int *fput_needed)
- {
- struct file *file;
- struct files_struct *files = current->files;
- *fput_needed = 0;
- if (atomic_read(&files->count) == 1) {
- file = fcheck_files(files, fd);
- } else {
- rcu_read_lock(); ///rcu 是否为 这个 Linux 2.6 内核中新的锁机制 RCU(Read-Copy Update)
- file = fcheck_files(files, fd);
- if (file) {
- if (atomic_long_inc_not_zero(&file->f_count))
- *fput_needed = 1;
- else
- /* Didn't get the reference, someone's freed */
- file = NULL;
- }
- rcu_read_unlock();
- }
- return file;
- }
复制代码 这里没有看到文件如何被打开的?
疑问1,请问内核是如何获得文件的dentry跟inode的呢? 应该是根据文件的路径一层一层的进来的,但是没有看到有循环。
疑问2,inode如果是根据文件路径获得的。为啥没用到inode number呢?根据inode number获取inode的方式,在内核的哪里用到了呢?源码在哪? 方法如下: 文件系统根据 一个inode table的表格,查到inode number, 然后 inode number 然后获得inode,跟硬盘中的信息对上的。 inode 结构中有 i_rdev, i_size, i_bytes, i_blocks 等磁盘的信息。
谢谢各位~ |
|