ubifs-media.h 23 KB

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