ubifs-media.h 23 KB

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