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