• <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 閱讀(365) 評論(0)  編輯 收藏 引用

            導航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統計

            常用鏈接

            留言簿

            文章檔案

            搜索

            最新評論

            99久久国产热无码精品免费| 久久久噜噜噜久久| 久久久精品人妻一区二区三区四 | 久久久久国产一区二区| 久久天天躁狠狠躁夜夜2020| 免费精品久久天干天干| 99久久精品国产麻豆| 久久人人爽人人爽人人片AV麻豆 | 99久久精品国内| 久久精品国产亚洲一区二区三区| 中文字幕精品久久久久人妻| 999久久久无码国产精品| 久久精品国产亚洲5555| 久久亚洲精品成人AV| 久久综合狠狠综合久久97色| 久久精品毛片免费观看| 久久久精品久久久久影院| 一本伊大人香蕉久久网手机| 久久精品一本到99热免费| 国内精品伊人久久久影院| 国产精品一区二区久久精品无码 | 久久久久亚洲精品日久生情 | 青青国产成人久久91网| 少妇内射兰兰久久| 久久99热这里只频精品6| 精品无码人妻久久久久久| 好属妞这里只有精品久久| 午夜精品久久久久久久| 久久久久久精品久久久久| 亚洲国产成人久久精品99| 久久青青国产| 日日狠狠久久偷偷色综合96蜜桃| 国产—久久香蕉国产线看观看| 精品久久777| 99热成人精品免费久久| 色综合色天天久久婷婷基地| 国产成人久久精品激情| 国产精品18久久久久久vr| 久久av无码专区亚洲av桃花岛| 亚洲午夜久久久影院| 国产婷婷成人久久Av免费高清|