• <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文件系統(tǒng)情景分析

            情景1:
               int fd=open("/proc");
            open->sys_open->do_filp_open
            當(dāng)open的flags包含CREAT標(biāo)志時(shí)->do_path_lookup(dfd, pathname, LOOKUP_PARENT, &nd);
            不包含CREAT標(biāo)志時(shí)->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對(duì)應(yīng)的path結(jié)構(gòu),通過next返回。
            //通過下面對(duì)do_lookup函數(shù)的分析可知,do_lookup函數(shù)返回時(shí),next->dentry代表proc文件系統(tǒng)的根目錄dentry結(jié)構(gòu),
            next->vfsmount代表proc文件系統(tǒng)的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相關(guān)部分代碼
            }
            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; //這個(gè)file是我們?cè)?font color=#000000>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結(jié)構(gòu)與查找到的dentry結(jié)構(gòu)掛鉤
             f->f_path.mnt = mnt;
            f->f_op = fops_get(inode->i_fop);
            //將inode->i_fop復(fù)制到file結(jié)構(gòu)體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對(duì)應(yīng)的path結(jié)構(gòu),通過此指針返回。
            {
             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文件系統(tǒng)的根目錄

            }
             return 0; //返回到__link_path_walk繼續(xù)分析
            }
            情景2 ls /proc
            readdir("/proc") -> sys_getdents64()->vfs_readdir(struct file *file){
            //file結(jié)構(gòu)代表 /proc,file->f_path.dentry已指向/proc dentry結(jié)構(gòu) file->f_op已指向/proc inode節(jié)點(diǎn)的file_operations結(jié)構(gòu)
            (file->f_op->readdir(file, buf, filler); --> static int proc_root_readdir(struct file * filp,  void * dirent, filldir_t filldir)
            {
            //由于這個(gè)函數(shù)比較大,放在下面分析
               }
            }
            在proc文件系統(tǒng)安裝注冊(cè)過程中,/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) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

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

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案

            搜索

            最新評(píng)論

            久久精品国产亚洲AV无码麻豆| 深夜久久AAAAA级毛片免费看| 蜜桃麻豆WWW久久囤产精品| 成人亚洲欧美久久久久| 久久久精品午夜免费不卡| AV无码久久久久不卡网站下载| 久久w5ww成w人免费| 日韩精品久久久久久久电影蜜臀| 亚洲AV无码1区2区久久| 亚洲中文字幕无码久久2017| 狠狠色噜噜色狠狠狠综合久久| 伊人久久久AV老熟妇色| 国产成人精品综合久久久| 久久精品国产亚洲av麻豆小说| 久久国产精品99精品国产| 久久综合中文字幕| 麻豆久久| 久久久久国产精品熟女影院| 国产精品久久自在自线观看| 中文字幕成人精品久久不卡| 久久精品亚洲乱码伦伦中文| 一本色道久久88综合日韩精品 | 久久久久免费精品国产| 久久久亚洲AV波多野结衣| 久久久久久久久无码精品亚洲日韩 | 欧美久久天天综合香蕉伊| 国产精品99久久久久久宅男| 一级做a爰片久久毛片免费陪| 一本久久a久久精品综合夜夜| 狠狠色综合网站久久久久久久高清| 久久久精品国产亚洲成人满18免费网站| 国产成人无码久久久精品一| 久久久久久久精品妇女99| 亚洲国产日韩欧美久久| 国产精品成人99久久久久91gav| 成人妇女免费播放久久久| 国产亚洲婷婷香蕉久久精品| 九九99精品久久久久久| 久久九九有精品国产23百花影院| 狠狠色丁香久久婷婷综| 久久国产成人精品麻豆|