ubifs-media.h 21 KB

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