ubifs-media.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * This file is part of UBIFS.
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. *
  8. * Authors: Artem Bityutskiy (Битюцкий Артём)
  9. * Adrian Hunter
  10. */
  11. /*
  12. * This file describes UBIFS on-flash format and contains definitions of all the
  13. * relevant data structures and constants.
  14. *
  15. * All UBIFS on-flash objects are stored in the form of nodes. All nodes start
  16. * with the UBIFS node magic number and have the same common header. Nodes
  17. * always sit at 8-byte aligned positions on the media and node header sizes are
  18. * also 8-byte aligned (except for the indexing node and the padding node).
  19. */
  20. #ifndef __UBIFS_MEDIA_H__
  21. #define __UBIFS_MEDIA_H__
  22. /* UBIFS node magic number (must not have the padding byte first or last) */
  23. #define UBIFS_NODE_MAGIC 0x06101831
  24. /*
  25. * UBIFS on-flash format version. This version is increased when the on-flash
  26. * format is changing. If this happens, UBIFS is will support older versions as
  27. * well. But older UBIFS code will not support newer formats. Format changes
  28. * will be rare and only when absolutely necessary, e.g. to fix a bug or to add
  29. * a new feature.
  30. *
  31. * UBIFS went into mainline kernel with format version 4. The older formats
  32. * were development formats.
  33. */
  34. #define UBIFS_FORMAT_VERSION 4
  35. /*
  36. * Read-only compatibility version. If the UBIFS format is changed, older UBIFS
  37. * implementations will not be able to mount newer formats in read-write mode.
  38. * However, depending on the change, it may be possible to mount newer formats
  39. * in R/O mode. This is indicated by the R/O compatibility version which is
  40. * stored in the super-block.
  41. *
  42. * This is needed to support boot-loaders which only need R/O mounting. With
  43. * this flag it is possible to do UBIFS format changes without a need to update
  44. * boot-loaders.
  45. */
  46. #define UBIFS_RO_COMPAT_VERSION 0
  47. /* Minimum logical eraseblock size in bytes */
  48. #define UBIFS_MIN_LEB_SZ (15*1024)
  49. /* Initial CRC32 value used when calculating CRC checksums */
  50. #define UBIFS_CRC32_INIT 0xFFFFFFFFU
  51. /*
  52. * UBIFS does not try to compress data if its length is less than the below
  53. * constant.
  54. */
  55. #define UBIFS_MIN_COMPR_LEN 128
  56. /*
  57. * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes
  58. * shorter than uncompressed data length, UBIFS prefers to leave this data
  59. * node uncompress, because it'll be read faster.
  60. */
  61. #define UBIFS_MIN_COMPRESS_DIFF 64
  62. /* Root inode number */
  63. #define UBIFS_ROOT_INO 1
  64. /* Lowest inode number used for regular inodes (not UBIFS-only internal ones) */
  65. #define UBIFS_FIRST_INO 64
  66. /*
  67. * Maximum file name and extended attribute length (must be a multiple of 8,
  68. * minus 1).
  69. */
  70. #define UBIFS_MAX_NLEN 255
  71. /* Maximum number of data journal heads */
  72. #define UBIFS_MAX_JHEADS 1
  73. /*
  74. * Size of UBIFS data block. Note, UBIFS is not a block oriented file-system,
  75. * which means that it does not treat the underlying media as consisting of
  76. * blocks like in case of hard drives. Do not be confused. UBIFS block is just
  77. * the maximum amount of data which one data node can have or which can be
  78. * attached to an inode node.
  79. */
  80. #define UBIFS_BLOCK_SIZE 4096
  81. #define UBIFS_BLOCK_SHIFT 12
  82. /* UBIFS padding byte pattern (must not be first or last byte of node magic) */
  83. #define UBIFS_PADDING_BYTE 0xCE
  84. /* Maximum possible key length */
  85. #define UBIFS_MAX_KEY_LEN 16
  86. /* Key length ("simple" format) */
  87. #define UBIFS_SK_LEN 8
  88. /* Minimum index tree fanout */
  89. #define UBIFS_MIN_FANOUT 3
  90. /* Maximum number of levels in UBIFS indexing B-tree */
  91. #define UBIFS_MAX_LEVELS 512
  92. /* Maximum amount of data attached to an inode in bytes */
  93. #define UBIFS_MAX_INO_DATA UBIFS_BLOCK_SIZE
  94. /* LEB Properties Tree fanout (must be power of 2) and fanout shift */
  95. #define UBIFS_LPT_FANOUT 4
  96. #define UBIFS_LPT_FANOUT_SHIFT 2
  97. /* LEB Properties Tree bit field sizes */
  98. #define UBIFS_LPT_CRC_BITS 16
  99. #define UBIFS_LPT_CRC_BYTES 2
  100. #define UBIFS_LPT_TYPE_BITS 4
  101. /* The key is always at the same position in all keyed nodes */
  102. #define UBIFS_KEY_OFFSET offsetof(struct ubifs_ino_node, key)
  103. /* Garbage collector journal head number */
  104. #define UBIFS_GC_HEAD 0
  105. /* Base journal head number */
  106. #define UBIFS_BASE_HEAD 1
  107. /* Data journal head number */
  108. #define UBIFS_DATA_HEAD 2
  109. /*
  110. * LEB Properties Tree node types.
  111. *
  112. * UBIFS_LPT_PNODE: LPT leaf node (contains LEB properties)
  113. * UBIFS_LPT_NNODE: LPT internal node
  114. * UBIFS_LPT_LTAB: LPT's own lprops table
  115. * UBIFS_LPT_LSAVE: LPT's save table (big model only)
  116. * UBIFS_LPT_NODE_CNT: count of LPT node types
  117. * UBIFS_LPT_NOT_A_NODE: all ones (15 for 4 bits) is never a valid node type
  118. */
  119. enum {
  120. UBIFS_LPT_PNODE,
  121. UBIFS_LPT_NNODE,
  122. UBIFS_LPT_LTAB,
  123. UBIFS_LPT_LSAVE,
  124. UBIFS_LPT_NODE_CNT,
  125. UBIFS_LPT_NOT_A_NODE = (1 << UBIFS_LPT_TYPE_BITS) - 1,
  126. };
  127. /*
  128. * UBIFS inode types.
  129. *
  130. * UBIFS_ITYPE_REG: regular file
  131. * UBIFS_ITYPE_DIR: directory
  132. * UBIFS_ITYPE_LNK: soft link
  133. * UBIFS_ITYPE_BLK: block device node
  134. * UBIFS_ITYPE_CHR: character device node
  135. * UBIFS_ITYPE_FIFO: fifo
  136. * UBIFS_ITYPE_SOCK: socket
  137. * UBIFS_ITYPES_CNT: count of supported file types
  138. */
  139. enum {
  140. UBIFS_ITYPE_REG,
  141. UBIFS_ITYPE_DIR,
  142. UBIFS_ITYPE_LNK,
  143. UBIFS_ITYPE_BLK,
  144. UBIFS_ITYPE_CHR,
  145. UBIFS_ITYPE_FIFO,
  146. UBIFS_ITYPE_SOCK,
  147. UBIFS_ITYPES_CNT,
  148. };
  149. /*
  150. * Supported key hash functions.
  151. *
  152. * UBIFS_KEY_HASH_R5: R5 hash
  153. * UBIFS_KEY_HASH_TEST: test hash which just returns first 4 bytes of the name
  154. */
  155. enum {
  156. UBIFS_KEY_HASH_R5,
  157. UBIFS_KEY_HASH_TEST,
  158. };
  159. /*
  160. * Supported key formats.
  161. *
  162. * UBIFS_SIMPLE_KEY_FMT: simple key format
  163. */
  164. enum {
  165. UBIFS_SIMPLE_KEY_FMT,
  166. };
  167. /*
  168. * The simple key format uses 29 bits for storing UBIFS block number and hash
  169. * value.
  170. */
  171. #define UBIFS_S_KEY_BLOCK_BITS 29
  172. #define UBIFS_S_KEY_BLOCK_MASK 0x1FFFFFFF
  173. #define UBIFS_S_KEY_HASH_BITS UBIFS_S_KEY_BLOCK_BITS
  174. #define UBIFS_S_KEY_HASH_MASK UBIFS_S_KEY_BLOCK_MASK
  175. /*
  176. * Key types.
  177. *
  178. * UBIFS_INO_KEY: inode node key
  179. * UBIFS_DATA_KEY: data node key
  180. * UBIFS_DENT_KEY: directory entry node key
  181. * UBIFS_XENT_KEY: extended attribute entry key
  182. * UBIFS_KEY_TYPES_CNT: number of supported key types
  183. */
  184. enum {
  185. UBIFS_INO_KEY,
  186. UBIFS_DATA_KEY,
  187. UBIFS_DENT_KEY,
  188. UBIFS_XENT_KEY,
  189. UBIFS_KEY_TYPES_CNT,
  190. };
  191. /* Count of LEBs reserved for the superblock area */
  192. #define UBIFS_SB_LEBS 1
  193. /* Count of LEBs reserved for the master area */
  194. #define UBIFS_MST_LEBS 2
  195. /* First LEB of the superblock area */
  196. #define UBIFS_SB_LNUM 0
  197. /* First LEB of the master area */
  198. #define UBIFS_MST_LNUM (UBIFS_SB_LNUM + UBIFS_SB_LEBS)
  199. /* First LEB of the log area */
  200. #define UBIFS_LOG_LNUM (UBIFS_MST_LNUM + UBIFS_MST_LEBS)
  201. /*
  202. * The below constants define the absolute minimum values for various UBIFS
  203. * media areas. Many of them actually depend of flash geometry and the FS
  204. * configuration (number of journal heads, orphan LEBs, etc). This means that
  205. * the smallest volume size which can be used for UBIFS cannot be pre-defined
  206. * by these constants. The file-system that meets the below limitation will not
  207. * necessarily mount. UBIFS does run-time calculations and validates the FS
  208. * size.
  209. */
  210. /* Minimum number of logical eraseblocks in the log */
  211. #define UBIFS_MIN_LOG_LEBS 2
  212. /* Minimum number of bud logical eraseblocks (one for each head) */
  213. #define UBIFS_MIN_BUD_LEBS 3
  214. /* Minimum number of journal logical eraseblocks */
  215. #define UBIFS_MIN_JNL_LEBS (UBIFS_MIN_LOG_LEBS + UBIFS_MIN_BUD_LEBS)
  216. /* Minimum number of LPT area logical eraseblocks */
  217. #define UBIFS_MIN_LPT_LEBS 2
  218. /* Minimum number of orphan area logical eraseblocks */
  219. #define UBIFS_MIN_ORPH_LEBS 1
  220. /*
  221. * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1
  222. * for GC, 1 for deletions, and at least 1 for committed data).
  223. */
  224. #define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6)
  225. /* Minimum number of logical eraseblocks */
  226. #define UBIFS_MIN_LEB_CNT (UBIFS_SB_LEBS + UBIFS_MST_LEBS + \
  227. UBIFS_MIN_LOG_LEBS + UBIFS_MIN_LPT_LEBS + \
  228. UBIFS_MIN_ORPH_LEBS + UBIFS_MIN_MAIN_LEBS)
  229. /* Node sizes (N.B. these are guaranteed to be multiples of 8) */
  230. #define UBIFS_CH_SZ sizeof(struct ubifs_ch)
  231. #define UBIFS_INO_NODE_SZ sizeof(struct ubifs_ino_node)
  232. #define UBIFS_DATA_NODE_SZ sizeof(struct ubifs_data_node)
  233. #define UBIFS_DENT_NODE_SZ sizeof(struct ubifs_dent_node)
  234. #define UBIFS_TRUN_NODE_SZ sizeof(struct ubifs_trun_node)
  235. #define UBIFS_PAD_NODE_SZ sizeof(struct ubifs_pad_node)
  236. #define UBIFS_SB_NODE_SZ sizeof(struct ubifs_sb_node)
  237. #define UBIFS_MST_NODE_SZ sizeof(struct ubifs_mst_node)
  238. #define UBIFS_REF_NODE_SZ sizeof(struct ubifs_ref_node)
  239. #define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node)
  240. #define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node)
  241. #define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node)
  242. /* Extended attribute entry nodes are identical to directory entry nodes */
  243. #define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ
  244. /* Only this does not have to be multiple of 8 bytes */
  245. #define UBIFS_BRANCH_SZ sizeof(struct ubifs_branch)
  246. /* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */
  247. #define UBIFS_MAX_DATA_NODE_SZ (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)
  248. #define UBIFS_MAX_INO_NODE_SZ (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA)
  249. #define UBIFS_MAX_DENT_NODE_SZ (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1)
  250. #define UBIFS_MAX_XENT_NODE_SZ UBIFS_MAX_DENT_NODE_SZ
  251. /* The largest UBIFS node */
  252. #define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ
  253. /*
  254. * On-flash inode flags.
  255. *
  256. * UBIFS_COMPR_FL: use compression for this inode
  257. * UBIFS_SYNC_FL: I/O on this inode has to be synchronous
  258. * UBIFS_IMMUTABLE_FL: inode is immutable
  259. * UBIFS_APPEND_FL: writes to the inode may only append data
  260. * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous
  261. * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value
  262. *
  263. * Note, these are on-flash flags which correspond to ioctl flags
  264. * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not
  265. * have to be the same.
  266. */
  267. enum {
  268. UBIFS_COMPR_FL = 0x01,
  269. UBIFS_SYNC_FL = 0x02,
  270. UBIFS_IMMUTABLE_FL = 0x04,
  271. UBIFS_APPEND_FL = 0x08,
  272. UBIFS_DIRSYNC_FL = 0x10,
  273. UBIFS_XATTR_FL = 0x20,
  274. };
  275. /* Inode flag bits used by UBIFS */
  276. #define UBIFS_FL_MASK 0x0000001F
  277. /*
  278. * UBIFS compression algorithms.
  279. *
  280. * UBIFS_COMPR_NONE: no compression
  281. * UBIFS_COMPR_LZO: LZO compression
  282. * UBIFS_COMPR_ZLIB: ZLIB compression
  283. * UBIFS_COMPR_TYPES_CNT: count of supported compression types
  284. */
  285. enum {
  286. UBIFS_COMPR_NONE,
  287. UBIFS_COMPR_LZO,
  288. UBIFS_COMPR_ZLIB,
  289. UBIFS_COMPR_TYPES_CNT,
  290. };
  291. /*
  292. * UBIFS node types.
  293. *
  294. * UBIFS_INO_NODE: inode node
  295. * UBIFS_DATA_NODE: data node
  296. * UBIFS_DENT_NODE: directory entry node
  297. * UBIFS_XENT_NODE: extended attribute node
  298. * UBIFS_TRUN_NODE: truncation node
  299. * UBIFS_PAD_NODE: padding node
  300. * UBIFS_SB_NODE: superblock node
  301. * UBIFS_MST_NODE: master node
  302. * UBIFS_REF_NODE: LEB reference node
  303. * UBIFS_IDX_NODE: index node
  304. * UBIFS_CS_NODE: commit start node
  305. * UBIFS_ORPH_NODE: orphan node
  306. * UBIFS_NODE_TYPES_CNT: count of supported node types
  307. *
  308. * Note, we index arrays by these numbers, so keep them low and contiguous.
  309. * Node type constants for inodes, direntries and so on have to be the same as
  310. * corresponding key type constants.
  311. */
  312. enum {
  313. UBIFS_INO_NODE,
  314. UBIFS_DATA_NODE,
  315. UBIFS_DENT_NODE,
  316. UBIFS_XENT_NODE,
  317. UBIFS_TRUN_NODE,
  318. UBIFS_PAD_NODE,
  319. UBIFS_SB_NODE,
  320. UBIFS_MST_NODE,
  321. UBIFS_REF_NODE,
  322. UBIFS_IDX_NODE,
  323. UBIFS_CS_NODE,
  324. UBIFS_ORPH_NODE,
  325. UBIFS_NODE_TYPES_CNT,
  326. };
  327. /*
  328. * Master node flags.
  329. *
  330. * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty
  331. * UBIFS_MST_NO_ORPHS: no orphan inodes present
  332. * UBIFS_MST_RCVRY: written by recovery
  333. */
  334. enum {
  335. UBIFS_MST_DIRTY = 1,
  336. UBIFS_MST_NO_ORPHS = 2,
  337. UBIFS_MST_RCVRY = 4,
  338. };
  339. /*
  340. * Node group type (used by recovery to recover whole group or none).
  341. *
  342. * UBIFS_NO_NODE_GROUP: this node is not part of a group
  343. * UBIFS_IN_NODE_GROUP: this node is a part of a group
  344. * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group
  345. */
  346. enum {
  347. UBIFS_NO_NODE_GROUP = 0,
  348. UBIFS_IN_NODE_GROUP,
  349. UBIFS_LAST_OF_NODE_GROUP,
  350. };
  351. /*
  352. * Superblock flags.
  353. *
  354. * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set
  355. * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed
  356. */
  357. enum {
  358. UBIFS_FLG_BIGLPT = 0x02,
  359. UBIFS_FLG_SPACE_FIXUP = 0x04,
  360. };
  361. /**
  362. * struct ubifs_ch - common header node.
  363. * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
  364. * @crc: CRC-32 checksum of the node header
  365. * @sqnum: sequence number
  366. * @len: full node length
  367. * @node_type: node type
  368. * @group_type: node group type
  369. * @padding: reserved for future, zeroes
  370. *
  371. * Every UBIFS node starts with this common part. If the node has a key, the
  372. * key always goes next.
  373. */
  374. struct ubifs_ch {
  375. __le32 magic;
  376. __le32 crc;
  377. __le64 sqnum;
  378. __le32 len;
  379. __u8 node_type;
  380. __u8 group_type;
  381. __u8 padding[2];
  382. } __packed;
  383. /**
  384. * union ubifs_dev_desc - device node descriptor.
  385. * @new: new type device descriptor
  386. * @huge: huge type device descriptor
  387. *
  388. * This data structure describes major/minor numbers of a device node. In an
  389. * inode is a device node then its data contains an object of this type. UBIFS
  390. * uses standard Linux "new" and "huge" device node encodings.
  391. */
  392. union ubifs_dev_desc {
  393. __le32 new;
  394. __le64 huge;
  395. } __packed;
  396. /**
  397. * struct ubifs_ino_node - inode node.
  398. * @ch: common header
  399. * @key: node key
  400. * @creat_sqnum: sequence number at time of creation
  401. * @size: inode size in bytes (amount of uncompressed data)
  402. * @atime_sec: access time seconds
  403. * @ctime_sec: creation time seconds
  404. * @mtime_sec: modification time seconds
  405. * @atime_nsec: access time nanoseconds
  406. * @ctime_nsec: creation time nanoseconds
  407. * @mtime_nsec: modification time nanoseconds
  408. * @nlink: number of hard links
  409. * @uid: owner ID
  410. * @gid: group ID
  411. * @mode: access flags
  412. * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc)
  413. * @data_len: inode data length
  414. * @xattr_cnt: count of extended attributes this inode has
  415. * @xattr_size: summarized size of all extended attributes in bytes
  416. * @padding1: reserved for future, zeroes
  417. * @xattr_names: sum of lengths of all extended attribute names belonging to
  418. * this inode
  419. * @compr_type: compression type used for this inode
  420. * @padding2: reserved for future, zeroes
  421. * @data: data attached to the inode
  422. *
  423. * Note, even though inode compression type is defined by @compr_type, some
  424. * nodes of this inode may be compressed with different compressor - this
  425. * happens if compression type is changed while the inode already has data
  426. * nodes. But @compr_type will be use for further writes to the inode.
  427. *
  428. * Note, do not forget to amend 'zero_ino_node_unused()' function when changing
  429. * the padding fields.
  430. */
  431. struct ubifs_ino_node {
  432. struct ubifs_ch ch;
  433. __u8 key[UBIFS_MAX_KEY_LEN];
  434. __le64 creat_sqnum;
  435. __le64 size;
  436. __le64 atime_sec;
  437. __le64 ctime_sec;
  438. __le64 mtime_sec;
  439. __le32 atime_nsec;
  440. __le32 ctime_nsec;
  441. __le32 mtime_nsec;
  442. __le32 nlink;
  443. __le32 uid;
  444. __le32 gid;
  445. __le32 mode;
  446. __le32 flags;
  447. __le32 data_len;
  448. __le32 xattr_cnt;
  449. __le32 xattr_size;
  450. __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */
  451. __le32 xattr_names;
  452. __le16 compr_type;
  453. __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */
  454. __u8 data[];
  455. } __packed;
  456. /**
  457. * struct ubifs_dent_node - directory entry node.
  458. * @ch: common header
  459. * @key: node key
  460. * @inum: target inode number
  461. * @padding1: reserved for future, zeroes
  462. * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc)
  463. * @nlen: name length
  464. * @padding2: reserved for future, zeroes
  465. * @name: zero-terminated name
  466. *
  467. * Note, do not forget to amend 'zero_dent_node_unused()' function when
  468. * changing the padding fields.
  469. */
  470. struct ubifs_dent_node {
  471. struct ubifs_ch ch;
  472. __u8 key[UBIFS_MAX_KEY_LEN];
  473. __le64 inum;
  474. __u8 padding1;
  475. __u8 type;
  476. __le16 nlen;
  477. __u8 padding2[4]; /* Watch 'zero_dent_node_unused()' if changing! */
  478. #ifndef __UBOOT__
  479. __u8 name[];
  480. #else
  481. char name[];
  482. #endif
  483. } __packed;
  484. /**
  485. * struct ubifs_data_node - data node.
  486. * @ch: common header
  487. * @key: node key
  488. * @size: uncompressed data size in bytes
  489. * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc)
  490. * @padding: reserved for future, zeroes
  491. * @data: data
  492. *
  493. * Note, do not forget to amend 'zero_data_node_unused()' function when
  494. * changing the padding fields.
  495. */
  496. struct ubifs_data_node {
  497. struct ubifs_ch ch;
  498. __u8 key[UBIFS_MAX_KEY_LEN];
  499. __le32 size;
  500. __le16 compr_type;
  501. __u8 padding[2]; /* Watch 'zero_data_node_unused()' if changing! */
  502. __u8 data[];
  503. } __packed;
  504. /**
  505. * struct ubifs_trun_node - truncation node.
  506. * @ch: common header
  507. * @inum: truncated inode number
  508. * @padding: reserved for future, zeroes
  509. * @old_size: size before truncation
  510. * @new_size: size after truncation
  511. *
  512. * This node exists only in the journal and never goes to the main area. Note,
  513. * do not forget to amend 'zero_trun_node_unused()' function when changing the
  514. * padding fields.
  515. */
  516. struct ubifs_trun_node {
  517. struct ubifs_ch ch;
  518. __le32 inum;
  519. __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */
  520. __le64 old_size;
  521. __le64 new_size;
  522. } __packed;
  523. /**
  524. * struct ubifs_pad_node - padding node.
  525. * @ch: common header
  526. * @pad_len: how many bytes after this node are unused (because padded)
  527. * @padding: reserved for future, zeroes
  528. */
  529. struct ubifs_pad_node {
  530. struct ubifs_ch ch;
  531. __le32 pad_len;
  532. } __packed;
  533. /**
  534. * struct ubifs_sb_node - superblock node.
  535. * @ch: common header
  536. * @padding: reserved for future, zeroes
  537. * @key_hash: type of hash function used in keys
  538. * @key_fmt: format of the key
  539. * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
  540. * @min_io_size: minimal input/output unit size
  541. * @leb_size: logical eraseblock size in bytes
  542. * @leb_cnt: count of LEBs used by file-system
  543. * @max_leb_cnt: maximum count of LEBs used by file-system
  544. * @max_bud_bytes: maximum amount of data stored in buds
  545. * @log_lebs: log size in logical eraseblocks
  546. * @lpt_lebs: number of LEBs used for lprops table
  547. * @orph_lebs: number of LEBs used for recording orphans
  548. * @jhead_cnt: count of journal heads
  549. * @fanout: tree fanout (max. number of links per indexing node)
  550. * @lsave_cnt: number of LEB numbers in LPT's save table
  551. * @fmt_version: UBIFS on-flash format version
  552. * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  553. * @padding1: reserved for future, zeroes
  554. * @rp_uid: reserve pool UID
  555. * @rp_gid: reserve pool GID
  556. * @rp_size: size of the reserved pool in bytes
  557. * @padding2: reserved for future, zeroes
  558. * @time_gran: time granularity in nanoseconds
  559. * @uuid: UUID generated when the file system image was created
  560. * @ro_compat_version: UBIFS R/O compatibility version
  561. */
  562. struct ubifs_sb_node {
  563. struct ubifs_ch ch;
  564. __u8 padding[2];
  565. __u8 key_hash;
  566. __u8 key_fmt;
  567. __le32 flags;
  568. __le32 min_io_size;
  569. __le32 leb_size;
  570. __le32 leb_cnt;
  571. __le32 max_leb_cnt;
  572. __le64 max_bud_bytes;
  573. __le32 log_lebs;
  574. __le32 lpt_lebs;
  575. __le32 orph_lebs;
  576. __le32 jhead_cnt;
  577. __le32 fanout;
  578. __le32 lsave_cnt;
  579. __le32 fmt_version;
  580. __le16 default_compr;
  581. __u8 padding1[2];
  582. __le32 rp_uid;
  583. __le32 rp_gid;
  584. __le64 rp_size;
  585. __le32 time_gran;
  586. __u8 uuid[16];
  587. __le32 ro_compat_version;
  588. __u8 padding2[3968];
  589. } __packed;
  590. /**
  591. * struct ubifs_mst_node - master node.
  592. * @ch: common header
  593. * @highest_inum: highest inode number in the committed index
  594. * @cmt_no: commit number
  595. * @flags: various flags (%UBIFS_MST_DIRTY, etc)
  596. * @log_lnum: start of the log
  597. * @root_lnum: LEB number of the root indexing node
  598. * @root_offs: offset within @root_lnum
  599. * @root_len: root indexing node length
  600. * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was
  601. * not reserved and should be reserved on mount)
  602. * @ihead_lnum: LEB number of index head
  603. * @ihead_offs: offset of index head
  604. * @index_size: size of index on flash
  605. * @total_free: total free space in bytes
  606. * @total_dirty: total dirty space in bytes
  607. * @total_used: total used space in bytes (includes only data LEBs)
  608. * @total_dead: total dead space in bytes (includes only data LEBs)
  609. * @total_dark: total dark space in bytes (includes only data LEBs)
  610. * @lpt_lnum: LEB number of LPT root nnode
  611. * @lpt_offs: offset of LPT root nnode
  612. * @nhead_lnum: LEB number of LPT head
  613. * @nhead_offs: offset of LPT head
  614. * @ltab_lnum: LEB number of LPT's own lprops table
  615. * @ltab_offs: offset of LPT's own lprops table
  616. * @lsave_lnum: LEB number of LPT's save table (big model only)
  617. * @lsave_offs: offset of LPT's save table (big model only)
  618. * @lscan_lnum: LEB number of last LPT scan
  619. * @empty_lebs: number of empty logical eraseblocks
  620. * @idx_lebs: number of indexing logical eraseblocks
  621. * @leb_cnt: count of LEBs used by file-system
  622. * @padding: reserved for future, zeroes
  623. */
  624. struct ubifs_mst_node {
  625. struct ubifs_ch ch;
  626. __le64 highest_inum;
  627. __le64 cmt_no;
  628. __le32 flags;
  629. __le32 log_lnum;
  630. __le32 root_lnum;
  631. __le32 root_offs;
  632. __le32 root_len;
  633. __le32 gc_lnum;
  634. __le32 ihead_lnum;
  635. __le32 ihead_offs;
  636. __le64 index_size;
  637. __le64 total_free;
  638. __le64 total_dirty;
  639. __le64 total_used;
  640. __le64 total_dead;
  641. __le64 total_dark;
  642. __le32 lpt_lnum;
  643. __le32 lpt_offs;
  644. __le32 nhead_lnum;
  645. __le32 nhead_offs;
  646. __le32 ltab_lnum;
  647. __le32 ltab_offs;
  648. __le32 lsave_lnum;
  649. __le32 lsave_offs;
  650. __le32 lscan_lnum;
  651. __le32 empty_lebs;
  652. __le32 idx_lebs;
  653. __le32 leb_cnt;
  654. __u8 padding[344];
  655. } __packed;
  656. /**
  657. * struct ubifs_ref_node - logical eraseblock reference node.
  658. * @ch: common header
  659. * @lnum: the referred logical eraseblock number
  660. * @offs: start offset in the referred LEB
  661. * @jhead: journal head number
  662. * @padding: reserved for future, zeroes
  663. */
  664. struct ubifs_ref_node {
  665. struct ubifs_ch ch;
  666. __le32 lnum;
  667. __le32 offs;
  668. __le32 jhead;
  669. __u8 padding[28];
  670. } __packed;
  671. /**
  672. * struct ubifs_branch - key/reference/length branch
  673. * @lnum: LEB number of the target node
  674. * @offs: offset within @lnum
  675. * @len: target node length
  676. * @key: key
  677. */
  678. struct ubifs_branch {
  679. __le32 lnum;
  680. __le32 offs;
  681. __le32 len;
  682. #ifndef __UBOOT__
  683. __u8 key[];
  684. #else
  685. char key[];
  686. #endif
  687. } __packed;
  688. /**
  689. * struct ubifs_idx_node - indexing node.
  690. * @ch: common header
  691. * @child_cnt: number of child index nodes
  692. * @level: tree level
  693. * @branches: LEB number / offset / length / key branches
  694. */
  695. struct ubifs_idx_node {
  696. struct ubifs_ch ch;
  697. __le16 child_cnt;
  698. __le16 level;
  699. #ifndef __UBOOT__
  700. __u8 branches[];
  701. #else
  702. char branches[];
  703. #endif
  704. } __packed;
  705. /**
  706. * struct ubifs_cs_node - commit start node.
  707. * @ch: common header
  708. * @cmt_no: commit number
  709. */
  710. struct ubifs_cs_node {
  711. struct ubifs_ch ch;
  712. __le64 cmt_no;
  713. } __packed;
  714. /**
  715. * struct ubifs_orph_node - orphan node.
  716. * @ch: common header
  717. * @cmt_no: commit number (also top bit is set on the last node of the commit)
  718. * @inos: inode numbers of orphans
  719. */
  720. struct ubifs_orph_node {
  721. struct ubifs_ch ch;
  722. __le64 cmt_no;
  723. __le64 inos[];
  724. } __packed;
  725. #endif /* __UBIFS_MEDIA_H__ */