上次對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出其他磁盤信息,隨後將一一展示,而且也會推到社區。