linux内核dentry结构分析

dentry,即directory entry,目录项,就是多个文件或者目录的链接,通过这个链接可以找寻到目录之下的文件或者是目录项。dentry在文件系统里是极其重要的一个概念,dentry结构体在linux内核里也是用处广泛,这个结构体定义在include/linux/dcache.h里,我们来看一下结构体的定义。
struct dentry {
	atomic_t d_count;
	unsigned int d_flags;		/* protected by d_lock */
	spinlock_t d_lock;		/* per dentry lock */
	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 */
	struct dentry_operations *d_op;
	struct super_block *d_sb;	/* The root of the dentry tree */
	void *d_fsdata;			/* fs-specific data */
#ifdef CONFIG_PROFILING
	struct dcookie_struct *d_cookie; /* cookie, if any */
#endif
	int d_mounted;
	unsigned char d_iname[DNAME_INLINE_LEN_MIN];	/* small names */
};


下边逐个解释下。
atomic_t d_count;
d_count是dentry的引用计数,多一个引用会在数值上加一,当少一个会减一,为零时会释放。
unsigned int d_flags;
dentry状态位。
spinlock_t d_lock;
每一个目录结构体都有一个自旋锁。
struct inode *d_inode;
目录的inode。
struct hlist_node d_hash;
哈希链表节点,dentry被放在哈希链表dentry_cache上,方便寻找。
struct dentry *d_parent;
父目录指针。
struct qstr d_name;
文件或者是目录的名
struct list_head d_lru;
lru链表
union {
struct list_head d_child; /* child of parent list */
struct rcu_head d_rcu;
} d_u;
父目录中目录项的指针。
struct list_head d_subdirs;
目录中子项的指针。
struct list_head d_alias;
相关索引节点的指针
unsigned long d_time;
最近使用时间
struct dentry_operations *d_op;
目录操作函数集合
struct super_block *d_sb;
目录的超级块指针
void *d_fsdata;
私有数据。
int d_mounted;
对于安装点而言表示是否被挂载文件系统,是不是一个挂载点。
unsigned char d_iname[DNAME_INLINE_LEN_MIN];
短的文件名

你可能感兴趣的:(文件系统)