UBIFS 磁盘结构 之 superblock

来源:互联网 发布:美发教学软件 编辑:程序博客网 时间:2024/05/16 04:57

   上次对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 0x6101831crc 0xbed305dfnode_type 6 (UBIFS_SB_NODE)group_type 0 (UBIFS_NO_NODE_GROUP)sqnum 1len 4096UUID 1DA95E73-43EE-43C2-B75E-1FE46FE5035Akey_hash 0 (UBIFS_KEY_HASH_R5)key_fmt 0 (UBIFS_SIMPLE_KEY_FMT)flags 0big_lpt 0space_fixup 0min_io_size 8leb_size 130944leb_cnt 28max_leb_cnt 28max_bud_bytes 392832log_lebs 3lpt_lebs 2orph_lebs 2jhead_cnt 1fanout 8lsave_cnt 256default_compr 1rp_size 117849rp_uid 0rp_gid 0fmt_version 4time_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出其他磁盘信息,随后将一一展示,而且也会推到社区。


      



0 0