Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40524
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-20 09:37
个人简介

欢迎同道中人一起学习交流

文章分类

全部博文(26)

文章存档

2015年(26)

我的朋友

分类: LINUX

2015-04-25 18:01:23

声明:本文为原创
#####请转贴时保留以下内容######
作者GTT
本文档归属http://oldtown.cublog.cn/.转载请注明出处!
请提出宝贵意见Mail:mtloveft@hotmail.com
Linux Version:2.6.33
提示本文是关于file system 实现的介绍
 
目录项的数据结构定义如下

struct dentry {
    atomic_t d_count;
    unsigned int d_flags; /* protected by d_lock */
    spinlock_t d_lock; /* per dentry lock */
    int d_mounted;
    struct inode *d_inode; /* Where the name belongs to - NULL is negative */
    /* The next three fields are touched by __d_lookup. Place them here so they all fit in a cache line. */
    struct hlist_node d_hash; /* lookup hash list */
    struct dentry *d_parent; /* parent directory */
    struct qstr d_name;

    struct list_head d_lru; /* LRU list */
    /* d_child and d_rcu can share memory */
    union {
        struct list_head d_child; /* child of parent list */
         struct rcu_head d_rcu;
    } d_u;
    struct list_head d_subdirs; /* our children */
    struct list_head d_alias; /* inode alias list */
    unsigned long d_time; /* used by d_revalidate */
    const struct dentry_operations *d_op;
    struct super_block *d_sb; /* The root of the dentry tree */
    void *d_fsdata; /* fs-specific data */

    unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
};

 
其中对目录项的操作VFT的定义如下

struct dentry_operations {
    int (*d_revalidate) (struct dentry *, struct nameidata *);
    int (*d_hash) (struct dentry *, struct qstr *);
    int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
    int (*d_delete) (struct dentry *);
    void (*d_release) (struct dentry *);
    void (*d_iput) (struct dentry *, struct inode *);
    char * (*d_dname) (struct dentry *, char *, int);
};

 
目录项的目的是方便查找文件。一个路径的各个组成部分,不管是目录还是普通的文件,都是一个目录项对象。如在路径/root/gtt/fsTest.c中,目录 /, root, gtt和文件 fsTest.c都对应一个目录项对象。
也就是,目录下可以有多个子目录和子文件。那又是怎么管理子文件和子目录的呢?
管理结构图如下
 
d_subdirs是链表头,所有的子目录和子文件都通过d_child这个字段加入到父目录的链表上。
而d_parent这个指针又是指向父目录的。
 
 
 
中画了directory cache,是怎么管理和利用的呢?
结构图如下
系统中定义了dentry_hashtable这个hash表,然后根据hash值把inode加入到这个散列的hash表里。
加入时是利用d_hash这个字段。
是不是和上篇文章基本一样?
 
后续文章请再稍等等,


阅读(353) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~