Chinaunix首页 | 论坛 | 博客
  • 博客访问: 627785
  • 博文数量: 155
  • 博客积分: 5688
  • 博客等级: 大校
  • 技术积分: 2134
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 15:12
文章分类

全部博文(155)

文章存档

2011年(58)

2010年(97)

分类: LINUX

2010-08-16 21:06:58

声明:本文为原创
#####请转贴时保留以下内容######
作者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这个字段。
是不是和上篇文章基本一样?
 
后续文章请再稍等等,


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

mychz20112011-07-26 09:59:55

感觉这里有点问题,目录下面的文件不一定有目录项,索引节点直接存储文件的位置,为什么还要目录项。