UBIFS 磁盘结构 之 superblock

   上次对UBIFS做了简单的介绍,也引出了一些主题. 下面这段时间首先来介绍一下UBIFS的磁盘结构。

今天是第一部分,super block。

   首先,每个文件系统都有一个superblock,在UBIFS中,也不例外。那么在UBIFS中,superblock会

放在磁盘的那个位置呢?没有错,就是第一个leb(logic erase block)。

   其次,那么ubifs 的super block里面存了哪些数据?很简单,看一下ubifs-media.h里面的数据结构

/**
 * struct ubifs_sb_node - superblock node.
 * @ch: common header
 * @padding: reserved for future, zeroes
 * @key_hash: type of hash function used in keys
 * @key_fmt: format of the key
 * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
 * @min_io_size: minimal input/output unit size
 * @leb_size: logical eraseblock size in bytes
 * @leb_cnt: count of LEBs used by file-system
 * @max_leb_cnt: maximum count of LEBs used by file-system
 * @max_bud_bytes: maximum amount of data stored in buds
 * @log_lebs: log size in logical eraseblocks
 * @lpt_lebs: number of LEBs used for lprops table
 * @orph_lebs: number of LEBs used for recording orphans
 * @jhead_cnt: count of journal heads
 * @fanout: tree fanout (max. number of links per indexing node)
 * @lsave_cnt: number of LEB numbers in LPT's save table
 * @fmt_version: UBIFS on-flash format version
 * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
 * @padding1: reserved for future, zeroes
 * @rp_uid: reserve pool UID
 * @rp_gid: reserve pool GID
 * @rp_size: size of the reserved pool in bytes
 * @padding2: reserved for future, zeroes
 * @time_gran: time granularity in nanoseconds
 * @uuid: UUID generated when the file system image was created
 * @ro_compat_version: UBIFS R/O compatibility version
 */
struct ubifs_sb_node {
        struct ubifs_ch ch;
        __u8 padding[2];
        __u8 key_hash;
        __u8 key_fmt;
        __le32 flags;
        __le32 min_io_size;
        __le32 leb_size;
        __le32 leb_cnt;
        __le32 max_leb_cnt;
        __le64 max_bud_bytes;
        __le32 log_lebs;
        __le32 lpt_lebs;
        __le32 orph_lebs;
        __le32 jhead_cnt;
        __le32 fanout;
        __le32 lsave_cnt;
        __le32 fmt_version;
        __le16 default_compr;
        __u8 padding1[2];
        __le32 rp_uid;
        __le32 rp_gid;
        __le64 rp_size;
        __le32 time_gran;
        __u8 uuid[16];
        __le32 ro_compat_version;
        __u8 padding2[3968];
};
这个数据结构就是ubifs最后存到flash里面的node结构,要想查看ubi设备里面的superblock

也是非常简单的,只需要从ubi0_0的0地址开始独处相应长度的数据就可以了。我开发了一个

ubifs-dump 工具,可以dump出ubifs的各个区域的数据。(还未提交到社区)。下面来看一下

dump出来的结果吧:

UBIFS SUPER BLOCK: 
	Common header: 
	magic 				0x6101831
	crc 				0xbed305df
	node_type 			6 (UBIFS_SB_NODE)
	group_type 			0 (UBIFS_NO_NODE_GROUP)
	sqnum 				1
	len 				4096
		UUID 				1DA95E73-43EE-43C2-B75E-1FE46FE5035A
		key_hash 			0 (UBIFS_KEY_HASH_R5)
		key_fmt 			0 (UBIFS_SIMPLE_KEY_FMT)
		flags 				0
		big_lpt 			0
		space_fixup 			0
		min_io_size 			8
		leb_size 			130944
		leb_cnt 			28
		max_leb_cnt 			28
		max_bud_bytes 			392832
		log_lebs 			3
		lpt_lebs 			2
		orph_lebs 			2
		jhead_cnt 			1
		fanout 				8
		lsave_cnt 			256
		default_compr 			1
		rp_size 			117849
		rp_uid 				0
		rp_gid 				0
		fmt_version 			4
		time_gran 			1000000000
  这就是一个最简单的super block的数据信息。其中第一部分就是ubifs 的common header。

每一个存到flash的数据结构都是一个node,而每一个node都有一个header。这个super

block的header如上所示。

magic是ubifs_node_magic, 定义在ubifs-media.h里面,用来识别一个ubifs的node。

值为0x6101831。

       crc是用来数据自检的,就是这个node的数据内容的crc值。可以有效的check读出来的

数据。

node_type表明这个node的类型,在这里是6 也就是UBIFS_SB_NODE。 完整的

node type定义在ubifs-media.h

enum {
        UBIFS_INO_NODE,
        UBIFS_DATA_NODE,
        UBIFS_DENT_NODE,
        UBIFS_XENT_NODE,
        UBIFS_TRUN_NODE,
        UBIFS_PAD_NODE,
        UBIFS_SB_NODE,
        UBIFS_MST_NODE,
        UBIFS_REF_NODE,
        UBIFS_IDX_NODE,
        UBIFS_CS_NODE,
        UBIFS_ORPH_NODE,
        UBIFS_NODE_TYPES_CNT,
};
     node_group, 用于数据恢复用的, 以后会详细解释

     sqnum,每一个写到flash的node都会有一个sqnum。当然superblock就是1.

     len, 这个node的长度,superblock的长度为4096。当然其实是没有这么多数据的,

所以里面有padding2,就是为了4096的长度。


以上就是一个common header的内容,这是每一个node都会有的header,下面进入

正题,ubifs super block里面到底包含哪些信息:

      UUID 是用来唯一确定当前文件系统的id。

      key_hash和key_fmt是管理indexing的key相关的信息。

      flags 包含各种文件系统的信息。

      big_lpt 和space_fixup 都包含在flags里面

      min_io_size: 表示最小io大小,其实是mtd->writesize


ubifs-dump工具还可以dump出其他磁盘信息,随后将一一展示,而且也会推到社区。


      



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要解开ubifs文件,你需要使用相应的工具和库来处理ubifs文件系统。Python本身没有直接支持ubifs文件的解析和操作的库,但你可以使用其他语言编写的库来实现。一个常用的工具是ubireader,它是一个用于解析和操作ubifs文件系统的开源工具。你可以使用ubireader库来读取和提取ubifs文件系统中的文件和目录。你可以在Python中使用subprocess模块来调用ubireader工具,并通过解析其输出来获取所需的文件内容。以下是一个示例代码,展示了如何使用ubireader来解析ubifs文件系统中的文件: ```python import subprocess def extract_ubifs_file(ubifs_file, target_file): # 调用ubireader工具来提取ubifs文件系统中的文件 command = f"ubireader_extract_files {ubifs_file} {target_file}" subprocess.run(command, shell=True) # 调用函数来解析ubifs文件系统中的文件 extract_ubifs_file("example.ubifs", "example.txt") ``` 请注意,你需要先安装ubireader工具,并将其添加到系统的环境变量中,以便在Python中调用。此外,你还需要根据你的具体需求来修改代码中的文件路径和目标文件名。 希望这可以帮助到你解开ubifs文件。如果你有任何其他问题,请随时提问。 #### 引用[.reference_title] - *1* *2* *3* [UBIFS文件系统](https://blog.csdn.net/renlonggg/article/details/103610509)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值