• <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成人网人人软件 | 久久www免费人成看国产片| 久久亚洲AV成人无码电影| 欧美亚洲日本久久精品| 久久这里只精品国产99热| 狠狠色丁香婷婷久久综合五月| 欧美久久综合性欧美| 午夜精品久久久内射近拍高清| 国产精品久久午夜夜伦鲁鲁| 日韩美女18网站久久精品 | 久久精品国产只有精品66| 久久精品中文騷妇女内射| 狠狠色婷婷久久一区二区 | 国产成人精品久久一区二区三区av | 亚洲va国产va天堂va久久| 久久综合久久伊人| 91久久精品视频| 久久久久女教师免费一区| 韩国三级大全久久网站| 麻豆亚洲AV永久无码精品久久| 久久天天日天天操综合伊人av | 一本综合久久国产二区| 国产精久久一区二区三区| 久久久久综合网久久| AV色综合久久天堂AV色综合在| 精品国产乱码久久久久久人妻| 亚洲精品第一综合99久久| 亚洲欧美日韩久久精品| 精品无码人妻久久久久久| 国产成人精品综合久久久| 九九热久久免费视频| 久久免费大片| 久久亚洲国产精品成人AV秋霞| 久久精品国产亚洲AV不卡| 午夜不卡久久精品无码免费|