jffs2文件系统[4]--六种内核结构-jffs2_raw_node_ref,jffs2_inode_cache

六种内核结构-jffs2_raw_node_ref,jffs2_inode_cache

jffs2_raw_node_ref

内核数据结构

/*
  This is all we need to keep in-core for each raw node during normal
  operation. As and when we do read_inode on a particular inode, we can
  scan the nodes which are listed for it and build up a proper map of
  which nodes are currently valid. JFFSv1 always used to keep that whole
  map in core for each inode.
*/
struct jffs2_raw_node_ref
{
	struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
		for this object. If this _is_ the last, it points to the inode_cache,
		xattr_ref or xattr_datum instead. The common part of those structures
		has NULL in the first word. See jffs2_raw_ref_to_ic() below */
	uint32_t flash_offset;
#undef TEST_TOTLEN
#ifdef TEST_TOTLEN
	uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */
#endif
};

这个数据结构文件系统时挂载构建,存在内核里,并不在flash上。flash_offset,这个数据实体在flash的位置;__totlen,这个变量在最新的内核已经没有在使用了;一个文件所有的数据实体组成了一个循环链表。链表尾的next_in_ino指向jffs2_inode_cache,而jffs2_inode_cache代表着一个文件。

jffs2_inode_cache

内核数据结构

struct jffs2_inode_cache {
	/* First part of structure is shared with other objects which
	   can terminate the raw node refs' next_in_ino list -- which
	   currently struct jffs2_xattr_datum and struct jffs2_xattr_ref. */

	struct jffs2_full_dirent *scan_dents; /* Used during scan to hold
		temporary lists of dirents, and later must be set to
		NULL to mark the end of the raw_node_ref->next_in_ino
		chain. */
	struct jffs2_raw_node_ref *nodes;
	uint8_t class;	/* It's used for identification */

	/* end of shared structure */

	uint8_t flags;
	uint16_t state;
	uint32_t ino;
	struct jffs2_inode_cache *next;
#ifdef CONFIG_JFFS2_FS_XATTR
	struct jffs2_xattr_ref *xref;
#endif
	uint32_t pino_nlink;	/* Directories store parent inode
				   here; other inodes store nlink.
				   Zero always means that it's
				   completely unlinked. */
};

nodes是上个结构体next_no_ino域链表首;scan_dents是jffs2_raw_dirent的上层结构链表地址;ino是该文件的唯一标识;pino_nlink为文件的硬连接。

四个数据结构关系

一个文件只有两个数据实体:jffs2_raw_dirent,jffs_raw_inode。这两个数据实体的内核描述符为jffs2_raw_node_ref。而文件的内核描述符为jffs2_inode_cache。一个文件的数据实体的描述符在jffs2_inode_cache的node域。通过jffs2_raw_node_ref的flash_offset得到数据实体的flash位置,由这个位置读出这个数据实体,再通过数据实体获取文件名(dirent)或者文件数据(inode)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值