ubifs-media.h 22 KB

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