linux文件系统源码学习——目录项对象

目录项对象

dentry结构体表示目录项对象,该对象只存在于内存中,不写在磁盘上,结构体的定义在linux/dcache.h中。包含了其父目录项,目录对应的inode,目录项名称。d_count变量记录了这个目录项对应的文件是否正在被使用,被多少个使用者使用。inode结构体中有一个i_dentry的链表,记录了指向该inode的所有目录项对象,dentry相当于一种缓存,它保存在dcache中,对应的inode对象也会保存在缓存中,在文件读取的过程中,首先查找dcache缓存查看是否有对应的目录项对象缓存,如果命中的话,就不需要重新创建dentry对象,否则就需要创建dentry对象,并创建inode对象。

struct dentry {
	/* RCU lookup touched fields */
	unsigned int d_flags;		/* protected by d_lock */
	seqcount_t d_seq;		/* per dentry seqlock */
	struct hlist_bl_node d_hash;	/* lookup hash list */
	struct dentry *d_parent;	/* parent directory */
	struct qstr d_name;
	struct inode *d_inode;		/* Where the name belongs to - NULL is
					 * negative */
	unsigned char d_iname[DNAME_INLINE_LEN];	/* small names */

	/* Ref lookup also touches following */
	unsigned int d_count;		/* protected by d_lock */
	spinlock_t d_lock;		/* per dentry lock */
	const struct dentry_operations *d_op;
	struct super_block *d_sb;	/* The root of the dentry tree */
	unsigned long d_time;		/* used by d_revalidate */
	void *d_fsdata;			/* fs-specific data */

	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 */
};

关于dentry的操作,保存在dentry_operations中,

struct dentry_operations {
	int (*d_revalidate)(struct dentry *, struct nameidata *);
	验证dentry是否有效,默认都是有效的
	int (*d_hash)(const struct dentry *, const struct inode *,
			struct qstr *);
    为目录项生成哈希值
	int (*d_compare)(const struct dentry *, const struct inode *,
			const struct dentry *, const struct inode *,
			unsigned int, const char *, const struct qstr *);
	
	int (*d_delete)(const struct dentry *);
	d_count=0时,调用删除方法,释放目录项对象
	void (*d_release)(struct dentry *);
	
	void (*d_iput)(struct dentry *, struct inode *);
	char *(*d_dname)(struct dentry *, char *, int);
	struct vfsmount *(*d_automount)(struct path *);
	int (*d_manage)(struct dentry *, bool);
} ____cacheline_aligned;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值