ubifs-media.h 25 KB

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