• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            proc文件系統情景分析

            情景1:
               int fd=open("/proc");
            open->sys_open->do_filp_open
            當open的flags包含CREAT標志時->do_path_lookup(dfd, pathname, LOOKUP_PARENT, &nd);
            不包含CREAT標志時->path_lookup_open->{
            struct file *filp = get_empty_filp();
             nd->intent.open.file = filp;

            }->do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd);{
            if (*name=='/') {
               nd->path = fs->root;
             }
             }-> path_walk(name, nd);->link_path_walk(name, nd);->__link_path_walk(name, nd);->{
            last_component:
            err = do_lookup(nd, &this, &next); // this代表proc字符串 this.name == "proc",nd->path包含根目錄的dentry,和vfsmount信息,next 為待查找到的proc對應的path結構,通過next返回。
            //通過下面對do_lookup函數的分析可知,do_lookup函數返回時,next->dentry代表proc文件系統的根目錄dentry結構,
            next->vfsmount代表proc文件系統的vfsmount
              inode = next.dentry->d_inode;
              if ((lookup_flags & LOOKUP_FOLLOW)
                  && inode && inode->i_op && inode->i_op->follow_link) {
               err = do_follow_link(&next, nd);
               if (err)
                goto return_err;
               inode = nd->path.dentry->d_inode;
              } else
               path_to_nameidata(&next, nd);->{
            path_to_nameidata(struct path *path, struct nameidata *nd)
            if (nd->path.mnt != path->mnt)
              mntput(nd->path.mnt);
             nd->path.mnt = path->mnt;
             nd->path.dentry = path->dentry;
            }
              err = -ENOENT;
              if (!inode)
               break;
              if (lookup_flags & LOOKUP_DIRECTORY) {
               err = -ENOTDIR;
               if (!inode->i_op || !inode->i_op->lookup)
                break;
              }
              goto return_base;
            return_base:
              return 0; //返回到link_path_walk,一路返回到do_filp_open(),下面再來看下do_filp_open相關部分代碼
            }
            do_filp_open(){
             if (!(flag & O_CREAT)) {
              error = path_lookup_open(dfd, pathname, lookup_flags(flag),
                  &nd, flag);
              if (error)
               return ERR_PTR(error);
              goto ok;
             }
            ok:filp = nameidata_to_filp(&nd, open_flag);
            return filp;
            }

            struct file *nameidata_to_filp(struct nameidata *nd, int flags)
            {
             struct file *filp;

             /* Pick up the filp from the open intent */
             filp = nd->intent.open.file; //這個file是我們在path_lookup_open中分配的
             /* Has the filesystem initialised the file for us? */
             if (filp->f_path.dentry == NULL)
              filp = __dentry_open(nd->path.dentry, nd->path.mnt, flags, filp,
                     NULL);
             -> static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
                 int flags, struct file *f,
                 int (*open)(struct inode *, struct file *)){
            inode = dentry->d_inode;
            f->f_path.dentry = dentry;
            //在這里將為打開/proc而分配的file結構與查找到的dentry結構掛鉤
             f->f_path.mnt = mnt;
            f->f_op = fops_get(inode->i_fop);
            //將inode->i_fop復制到file結構體f_op字段
            }
             else
              path_put(&nd->path);
             return filp;
            }

            static int do_lookup(struct nameidata *nd, struct qstr *name,
                   struct path *path)
            //// name代表proc字符串 name.name == "proc",nd->path包含根目錄的dentry,和vfsmount信息,path為待查找到的proc對應的path結構,通過此指針返回。
            {
             struct vfsmount *mnt = nd->path.mnt;
             struct dentry *dentry = __d_lookup(nd->path.dentry, name);
            done:
             path->mnt = mnt;
             path->dentry = dentry;
             __follow_mount(path); ->{
               struct vfsmount *mounted = lookup_mnt(path->mnt, path->dentry);
               path->mnt = mounted;
              path->dentry = dget(mounted->mnt_root);
            //這里path代表了proc文件系統的根目錄

            }
             return 0; //返回到__link_path_walk繼續分析
            }
            情景2 ls /proc
            readdir("/proc") -> sys_getdents64()->vfs_readdir(struct file *file){
            //file結構代表 /proc,file->f_path.dentry已指向/proc dentry結構 file->f_op已指向/proc inode節點的file_operations結構
            (file->f_op->readdir(file, buf, filler); --> static int proc_root_readdir(struct file * filp,  void * dirent, filldir_t filldir)
            {
            //由于這個函數比較大,放在下面分析
               }
            }
            在proc文件系統安裝注冊過程中,/proc inode的file_operations定義為:
            /*
             * This is the root "inode" in the /proc tree..
             */
            struct proc_dir_entry proc_root = {
             .low_ino = PROC_ROOT_INO,
             .namelen = 5,
             .name  = "/proc",
             .mode  = S_IFDIR | S_IRUGO | S_IXUGO,
             .nlink  = 2,
             .count  = ATOMIC_INIT(1),
             .proc_iops = &proc_root_inode_operations,
             .proc_fops = &proc_root_operations,
             .parent  = &proc_root,
            };
            /*
             * The root /proc directory is special, as it has the
             * <pid> directories. Thus we don't use the generic
             * directory handling functions for that..
             */
            static const struct file_operations proc_root_operations = {
             .read   = generic_read_dir,
             .readdir  = proc_root_readdir,
            };

            static int proc_root_readdir(struct file * filp,
             void * dirent, filldir_t filldir)
            {
             unsigned int nr = filp->f_pos;
             int ret;

             lock_kernel();

             if (nr < FIRST_PROCESS_ENTRY) {
              int error = proc_readdir(filp, dirent, filldir);
              if (error <= 0) {
               unlock_kernel();
               return error;
              }
              filp->f_pos = FIRST_PROCESS_ENTRY;
             }
             unlock_kernel();

             ret = proc_pid_readdir(filp, dirent, filldir);
             return ret;
            }

            posted on 2010-12-17 10:28 lstar 閱讀(368) 評論(0)  編輯 收藏 引用

            導航

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            常用鏈接

            留言簿

            文章檔案

            搜索

            最新評論

            久久国产AVJUST麻豆| 精品久久久无码21p发布| 99久久亚洲综合精品成人| 国产精品午夜久久| 亚洲午夜久久久影院| 精品久久久久久国产三级| 人妻精品久久无码区| 久久最新免费视频| 成人妇女免费播放久久久| 亚洲午夜久久久| 精品久久久无码中文字幕| 久久国产精品无码一区二区三区| 久久久久久久久久免免费精品 | 久久亚洲国产欧洲精品一| 久久国产三级无码一区二区| WWW婷婷AV久久久影片| 久久久久久综合网天天| 很黄很污的网站久久mimi色| 久久精品无码午夜福利理论片 | 久久国产一片免费观看| 久久精品人成免费| 色综合久久中文字幕无码| 久久久久久久免费视频| 久久精品国产黑森林| 国产成人无码精品久久久久免费| 国内精品久久久久影院优| 久久久这里有精品| 久久精品国产AV一区二区三区| 亚洲伊人久久成综合人影院 | 亚洲人成伊人成综合网久久久| 亚洲精品WWW久久久久久| 久久亚洲高清综合| 久久人人爽人爽人人爽av| 亚洲国产成人乱码精品女人久久久不卡 | 日本久久久久久中文字幕| 99久久久精品| 91久久精品国产免费直播| 国产免费久久精品99久久| 久久精品无码免费不卡| 亚洲综合久久夜AV | 久久国产精品成人片免费|