ubifs-media.h 26 KB

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