blob: d47e9569b3de058550822bd4e9adfc274fb0955b [file] [log] [blame]
Artem Bityutskiy1e517642008-07-14 19:08:37 +03001/*
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
Artem Bityutskiy963f0cf2009-03-26 12:51:21 +020039/*
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 */
Artem Bityutskiy1e517642008-07-14 19:08:37 +030049#define UBIFS_FORMAT_VERSION 4
50
Artem Bityutskiy963f0cf2009-03-26 12:51:21 +020051/*
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
Artem Bityutskiy1e517642008-07-14 19:08:37 +030064/* 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
Artem Bityutskiy062e4fe2008-10-26 16:58:25 +020076/*
77 * If compressed data length is less than %UBIFS_MIN_COMPRESS_DIFF bytes
Artem Bityutskiy963f0cf2009-03-26 12:51:21 +020078 * shorter than uncompressed data length, UBIFS prefers to leave this data
Artem Bityutskiy062e4fe2008-10-26 16:58:25 +020079 * node uncompress, because it'll be read faster.
80 */
81#define UBIFS_MIN_COMPRESS_DIFF 64
82
Artem Bityutskiy1e517642008-07-14 19:08:37 +030083/* 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
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300107
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 */
Artem Bityutskiya5cb5622008-09-03 18:26:47 +0300118#define UBIFS_MIN_FANOUT 3
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300119
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
Artem Bityutskiyd6d14002009-09-15 14:44:06 +0300138/* 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
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300145/*
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 */
155enum {
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 */
176enum {
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 */
193enum {
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 */
203enum {
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 */
225enum {
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/*
Artem Bityutskiyb364b412008-07-25 14:38:51 +0300266 * Minimum number of main area logical eraseblocks (buds, 3 for the index, 1
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300267 * for GC, 1 for deletions, and at least 1 for committed data).
268 */
Artem Bityutskiyb364b412008-07-25 14:38:51 +0300269#define UBIFS_MIN_MAIN_LEBS (UBIFS_MIN_BUD_LEBS + 6)
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300270
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)
289/* Extended attribute entry nodes are identical to directory entry nodes */
290#define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ
291/* Only this does not have to be multiple of 8 bytes */
292#define UBIFS_BRANCH_SZ sizeof(struct ubifs_branch)
293
294/* Maximum node sizes (N.B. these are guaranteed to be multiples of 8) */
295#define UBIFS_MAX_DATA_NODE_SZ (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)
296#define UBIFS_MAX_INO_NODE_SZ (UBIFS_INO_NODE_SZ + UBIFS_MAX_INO_DATA)
297#define UBIFS_MAX_DENT_NODE_SZ (UBIFS_DENT_NODE_SZ + UBIFS_MAX_NLEN + 1)
298#define UBIFS_MAX_XENT_NODE_SZ UBIFS_MAX_DENT_NODE_SZ
299
300/* The largest UBIFS node */
301#define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ
302
303/*
Richard Weinberger6a5e98a2016-09-19 22:05:18 +0200304 * xattr name of UBIFS encryption context, we don't use a prefix
305 * nor a long name to not waste space on the flash.
306 */
307#define UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT "c"
308
309
310/*
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300311 * On-flash inode flags.
312 *
313 * UBIFS_COMPR_FL: use compression for this inode
314 * UBIFS_SYNC_FL: I/O on this inode has to be synchronous
315 * UBIFS_IMMUTABLE_FL: inode is immutable
316 * UBIFS_APPEND_FL: writes to the inode may only append data
317 * UBIFS_DIRSYNC_FL: I/O on this directory inode has to be synchronous
318 * UBIFS_XATTR_FL: this inode is the inode for an extended attribute value
319 *
320 * Note, these are on-flash flags which correspond to ioctl flags
321 * (@FS_COMPR_FL, etc). They have the same values now, but generally, do not
322 * have to be the same.
323 */
324enum {
325 UBIFS_COMPR_FL = 0x01,
326 UBIFS_SYNC_FL = 0x02,
327 UBIFS_IMMUTABLE_FL = 0x04,
328 UBIFS_APPEND_FL = 0x08,
329 UBIFS_DIRSYNC_FL = 0x10,
330 UBIFS_XATTR_FL = 0x20,
331};
332
333/* Inode flag bits used by UBIFS */
334#define UBIFS_FL_MASK 0x0000001F
335
336/*
337 * UBIFS compression algorithms.
338 *
339 * UBIFS_COMPR_NONE: no compression
340 * UBIFS_COMPR_LZO: LZO compression
341 * UBIFS_COMPR_ZLIB: ZLIB compression
342 * UBIFS_COMPR_TYPES_CNT: count of supported compression types
343 */
344enum {
345 UBIFS_COMPR_NONE,
346 UBIFS_COMPR_LZO,
347 UBIFS_COMPR_ZLIB,
348 UBIFS_COMPR_TYPES_CNT,
349};
350
351/*
352 * UBIFS node types.
353 *
354 * UBIFS_INO_NODE: inode node
355 * UBIFS_DATA_NODE: data node
356 * UBIFS_DENT_NODE: directory entry node
357 * UBIFS_XENT_NODE: extended attribute node
358 * UBIFS_TRUN_NODE: truncation node
359 * UBIFS_PAD_NODE: padding node
360 * UBIFS_SB_NODE: superblock node
361 * UBIFS_MST_NODE: master node
362 * UBIFS_REF_NODE: LEB reference node
363 * UBIFS_IDX_NODE: index node
364 * UBIFS_CS_NODE: commit start node
365 * UBIFS_ORPH_NODE: orphan node
366 * UBIFS_NODE_TYPES_CNT: count of supported node types
367 *
368 * Note, we index arrays by these numbers, so keep them low and contiguous.
369 * Node type constants for inodes, direntries and so on have to be the same as
370 * corresponding key type constants.
371 */
372enum {
373 UBIFS_INO_NODE,
374 UBIFS_DATA_NODE,
375 UBIFS_DENT_NODE,
376 UBIFS_XENT_NODE,
377 UBIFS_TRUN_NODE,
378 UBIFS_PAD_NODE,
379 UBIFS_SB_NODE,
380 UBIFS_MST_NODE,
381 UBIFS_REF_NODE,
382 UBIFS_IDX_NODE,
383 UBIFS_CS_NODE,
384 UBIFS_ORPH_NODE,
385 UBIFS_NODE_TYPES_CNT,
386};
387
388/*
389 * Master node flags.
390 *
391 * UBIFS_MST_DIRTY: rebooted uncleanly - master node is dirty
392 * UBIFS_MST_NO_ORPHS: no orphan inodes present
393 * UBIFS_MST_RCVRY: written by recovery
394 */
395enum {
396 UBIFS_MST_DIRTY = 1,
397 UBIFS_MST_NO_ORPHS = 2,
398 UBIFS_MST_RCVRY = 4,
399};
400
401/*
402 * Node group type (used by recovery to recover whole group or none).
403 *
404 * UBIFS_NO_NODE_GROUP: this node is not part of a group
405 * UBIFS_IN_NODE_GROUP: this node is a part of a group
406 * UBIFS_LAST_OF_NODE_GROUP: this node is the last in a group
407 */
408enum {
409 UBIFS_NO_NODE_GROUP = 0,
410 UBIFS_IN_NODE_GROUP,
411 UBIFS_LAST_OF_NODE_GROUP,
412};
413
414/*
415 * Superblock flags.
416 *
417 * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set
Matthew L. Creech9f58d352011-05-05 16:33:20 -0400418 * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300419 */
420enum {
421 UBIFS_FLG_BIGLPT = 0x02,
Matthew L. Creech9f58d352011-05-05 16:33:20 -0400422 UBIFS_FLG_SPACE_FIXUP = 0x04,
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300423};
424
425/**
426 * struct ubifs_ch - common header node.
427 * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
428 * @crc: CRC-32 checksum of the node header
429 * @sqnum: sequence number
430 * @len: full node length
431 * @node_type: node type
432 * @group_type: node group type
433 * @padding: reserved for future, zeroes
434 *
435 * Every UBIFS node starts with this common part. If the node has a key, the
436 * key always goes next.
437 */
438struct ubifs_ch {
439 __le32 magic;
440 __le32 crc;
441 __le64 sqnum;
442 __le32 len;
443 __u8 node_type;
444 __u8 group_type;
445 __u8 padding[2];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200446} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300447
448/**
449 * union ubifs_dev_desc - device node descriptor.
450 * @new: new type device descriptor
451 * @huge: huge type device descriptor
452 *
453 * This data structure describes major/minor numbers of a device node. In an
454 * inode is a device node then its data contains an object of this type. UBIFS
455 * uses standard Linux "new" and "huge" device node encodings.
456 */
457union ubifs_dev_desc {
458 __le32 new;
459 __le64 huge;
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200460} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300461
462/**
463 * struct ubifs_ino_node - inode node.
464 * @ch: common header
465 * @key: node key
466 * @creat_sqnum: sequence number at time of creation
467 * @size: inode size in bytes (amount of uncompressed data)
468 * @atime_sec: access time seconds
469 * @ctime_sec: creation time seconds
470 * @mtime_sec: modification time seconds
471 * @atime_nsec: access time nanoseconds
472 * @ctime_nsec: creation time nanoseconds
473 * @mtime_nsec: modification time nanoseconds
474 * @nlink: number of hard links
475 * @uid: owner ID
476 * @gid: group ID
477 * @mode: access flags
478 * @flags: per-inode flags (%UBIFS_COMPR_FL, %UBIFS_SYNC_FL, etc)
479 * @data_len: inode data length
480 * @xattr_cnt: count of extended attributes this inode has
481 * @xattr_size: summarized size of all extended attributes in bytes
482 * @padding1: reserved for future, zeroes
483 * @xattr_names: sum of lengths of all extended attribute names belonging to
484 * this inode
485 * @compr_type: compression type used for this inode
486 * @padding2: reserved for future, zeroes
487 * @data: data attached to the inode
488 *
489 * Note, even though inode compression type is defined by @compr_type, some
490 * nodes of this inode may be compressed with different compressor - this
491 * happens if compression type is changed while the inode already has data
492 * nodes. But @compr_type will be use for further writes to the inode.
493 *
494 * Note, do not forget to amend 'zero_ino_node_unused()' function when changing
495 * the padding fields.
496 */
497struct ubifs_ino_node {
498 struct ubifs_ch ch;
499 __u8 key[UBIFS_MAX_KEY_LEN];
500 __le64 creat_sqnum;
501 __le64 size;
502 __le64 atime_sec;
503 __le64 ctime_sec;
504 __le64 mtime_sec;
505 __le32 atime_nsec;
506 __le32 ctime_nsec;
507 __le32 mtime_nsec;
508 __le32 nlink;
509 __le32 uid;
510 __le32 gid;
511 __le32 mode;
512 __le32 flags;
513 __le32 data_len;
514 __le32 xattr_cnt;
515 __le32 xattr_size;
516 __u8 padding1[4]; /* Watch 'zero_ino_node_unused()' if changing! */
517 __le32 xattr_names;
518 __le16 compr_type;
519 __u8 padding2[26]; /* Watch 'zero_ino_node_unused()' if changing! */
520 __u8 data[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200521} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300522
523/**
524 * struct ubifs_dent_node - directory entry node.
525 * @ch: common header
526 * @key: node key
527 * @inum: target inode number
528 * @padding1: reserved for future, zeroes
529 * @type: type of the target inode (%UBIFS_ITYPE_REG, %UBIFS_ITYPE_DIR, etc)
530 * @nlen: name length
531 * @padding2: reserved for future, zeroes
532 * @name: zero-terminated name
533 *
534 * Note, do not forget to amend 'zero_dent_node_unused()' function when
535 * changing the padding fields.
536 */
537struct ubifs_dent_node {
538 struct ubifs_ch ch;
539 __u8 key[UBIFS_MAX_KEY_LEN];
540 __le64 inum;
541 __u8 padding1;
542 __u8 type;
543 __le16 nlen;
544 __u8 padding2[4]; /* Watch 'zero_dent_node_unused()' if changing! */
545 __u8 name[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200546} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300547
548/**
549 * struct ubifs_data_node - data node.
550 * @ch: common header
551 * @key: node key
552 * @size: uncompressed data size in bytes
553 * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc)
554 * @padding: reserved for future, zeroes
555 * @data: data
556 *
557 * Note, do not forget to amend 'zero_data_node_unused()' function when
558 * changing the padding fields.
559 */
560struct ubifs_data_node {
561 struct ubifs_ch ch;
562 __u8 key[UBIFS_MAX_KEY_LEN];
563 __le32 size;
564 __le16 compr_type;
565 __u8 padding[2]; /* Watch 'zero_data_node_unused()' if changing! */
566 __u8 data[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200567} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300568
569/**
570 * struct ubifs_trun_node - truncation node.
571 * @ch: common header
572 * @inum: truncated inode number
573 * @padding: reserved for future, zeroes
574 * @old_size: size before truncation
575 * @new_size: size after truncation
576 *
577 * This node exists only in the journal and never goes to the main area. Note,
578 * do not forget to amend 'zero_trun_node_unused()' function when changing the
579 * padding fields.
580 */
581struct ubifs_trun_node {
582 struct ubifs_ch ch;
583 __le32 inum;
584 __u8 padding[12]; /* Watch 'zero_trun_node_unused()' if changing! */
585 __le64 old_size;
586 __le64 new_size;
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200587} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300588
589/**
590 * struct ubifs_pad_node - padding node.
591 * @ch: common header
592 * @pad_len: how many bytes after this node are unused (because padded)
593 * @padding: reserved for future, zeroes
594 */
595struct ubifs_pad_node {
596 struct ubifs_ch ch;
597 __le32 pad_len;
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200598} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300599
600/**
601 * struct ubifs_sb_node - superblock node.
602 * @ch: common header
603 * @padding: reserved for future, zeroes
604 * @key_hash: type of hash function used in keys
605 * @key_fmt: format of the key
606 * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
607 * @min_io_size: minimal input/output unit size
608 * @leb_size: logical eraseblock size in bytes
609 * @leb_cnt: count of LEBs used by file-system
610 * @max_leb_cnt: maximum count of LEBs used by file-system
611 * @max_bud_bytes: maximum amount of data stored in buds
612 * @log_lebs: log size in logical eraseblocks
613 * @lpt_lebs: number of LEBs used for lprops table
614 * @orph_lebs: number of LEBs used for recording orphans
615 * @jhead_cnt: count of journal heads
616 * @fanout: tree fanout (max. number of links per indexing node)
617 * @lsave_cnt: number of LEB numbers in LPT's save table
618 * @fmt_version: UBIFS on-flash format version
619 * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
620 * @padding1: reserved for future, zeroes
621 * @rp_uid: reserve pool UID
622 * @rp_gid: reserve pool GID
623 * @rp_size: size of the reserved pool in bytes
624 * @padding2: reserved for future, zeroes
625 * @time_gran: time granularity in nanoseconds
626 * @uuid: UUID generated when the file system image was created
Artem Bityutskiy963f0cf2009-03-26 12:51:21 +0200627 * @ro_compat_version: UBIFS R/O compatibility version
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300628 */
629struct ubifs_sb_node {
630 struct ubifs_ch ch;
631 __u8 padding[2];
632 __u8 key_hash;
633 __u8 key_fmt;
634 __le32 flags;
635 __le32 min_io_size;
636 __le32 leb_size;
637 __le32 leb_cnt;
638 __le32 max_leb_cnt;
639 __le64 max_bud_bytes;
640 __le32 log_lebs;
641 __le32 lpt_lebs;
642 __le32 orph_lebs;
643 __le32 jhead_cnt;
644 __le32 fanout;
645 __le32 lsave_cnt;
646 __le32 fmt_version;
647 __le16 default_compr;
648 __u8 padding1[2];
649 __le32 rp_uid;
650 __le32 rp_gid;
651 __le64 rp_size;
652 __le32 time_gran;
653 __u8 uuid[16];
Artem Bityutskiy963f0cf2009-03-26 12:51:21 +0200654 __le32 ro_compat_version;
655 __u8 padding2[3968];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200656} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300657
658/**
659 * struct ubifs_mst_node - master node.
660 * @ch: common header
661 * @highest_inum: highest inode number in the committed index
662 * @cmt_no: commit number
663 * @flags: various flags (%UBIFS_MST_DIRTY, etc)
664 * @log_lnum: start of the log
665 * @root_lnum: LEB number of the root indexing node
666 * @root_offs: offset within @root_lnum
667 * @root_len: root indexing node length
668 * @gc_lnum: LEB reserved for garbage collection (%-1 value means the LEB was
669 * not reserved and should be reserved on mount)
670 * @ihead_lnum: LEB number of index head
671 * @ihead_offs: offset of index head
672 * @index_size: size of index on flash
673 * @total_free: total free space in bytes
674 * @total_dirty: total dirty space in bytes
675 * @total_used: total used space in bytes (includes only data LEBs)
676 * @total_dead: total dead space in bytes (includes only data LEBs)
677 * @total_dark: total dark space in bytes (includes only data LEBs)
678 * @lpt_lnum: LEB number of LPT root nnode
679 * @lpt_offs: offset of LPT root nnode
680 * @nhead_lnum: LEB number of LPT head
681 * @nhead_offs: offset of LPT head
682 * @ltab_lnum: LEB number of LPT's own lprops table
683 * @ltab_offs: offset of LPT's own lprops table
684 * @lsave_lnum: LEB number of LPT's save table (big model only)
685 * @lsave_offs: offset of LPT's save table (big model only)
686 * @lscan_lnum: LEB number of last LPT scan
687 * @empty_lebs: number of empty logical eraseblocks
688 * @idx_lebs: number of indexing logical eraseblocks
689 * @leb_cnt: count of LEBs used by file-system
690 * @padding: reserved for future, zeroes
691 */
692struct ubifs_mst_node {
693 struct ubifs_ch ch;
694 __le64 highest_inum;
695 __le64 cmt_no;
696 __le32 flags;
697 __le32 log_lnum;
698 __le32 root_lnum;
699 __le32 root_offs;
700 __le32 root_len;
701 __le32 gc_lnum;
702 __le32 ihead_lnum;
703 __le32 ihead_offs;
704 __le64 index_size;
705 __le64 total_free;
706 __le64 total_dirty;
707 __le64 total_used;
708 __le64 total_dead;
709 __le64 total_dark;
710 __le32 lpt_lnum;
711 __le32 lpt_offs;
712 __le32 nhead_lnum;
713 __le32 nhead_offs;
714 __le32 ltab_lnum;
715 __le32 ltab_offs;
716 __le32 lsave_lnum;
717 __le32 lsave_offs;
718 __le32 lscan_lnum;
719 __le32 empty_lebs;
720 __le32 idx_lebs;
721 __le32 leb_cnt;
722 __u8 padding[344];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200723} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300724
725/**
726 * struct ubifs_ref_node - logical eraseblock reference node.
727 * @ch: common header
728 * @lnum: the referred logical eraseblock number
729 * @offs: start offset in the referred LEB
730 * @jhead: journal head number
731 * @padding: reserved for future, zeroes
732 */
733struct ubifs_ref_node {
734 struct ubifs_ch ch;
735 __le32 lnum;
736 __le32 offs;
737 __le32 jhead;
738 __u8 padding[28];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200739} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300740
741/**
742 * struct ubifs_branch - key/reference/length branch
743 * @lnum: LEB number of the target node
744 * @offs: offset within @lnum
745 * @len: target node length
746 * @key: key
747 */
748struct ubifs_branch {
749 __le32 lnum;
750 __le32 offs;
751 __le32 len;
752 __u8 key[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200753} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300754
755/**
756 * struct ubifs_idx_node - indexing node.
757 * @ch: common header
758 * @child_cnt: number of child index nodes
759 * @level: tree level
760 * @branches: LEB number / offset / length / key branches
761 */
762struct ubifs_idx_node {
763 struct ubifs_ch ch;
764 __le16 child_cnt;
765 __le16 level;
766 __u8 branches[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200767} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300768
769/**
770 * struct ubifs_cs_node - commit start node.
771 * @ch: common header
772 * @cmt_no: commit number
773 */
774struct ubifs_cs_node {
775 struct ubifs_ch ch;
776 __le64 cmt_no;
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200777} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300778
779/**
780 * struct ubifs_orph_node - orphan node.
781 * @ch: common header
782 * @cmt_no: commit number (also top bit is set on the last node of the commit)
783 * @inos: inode numbers of orphans
784 */
785struct ubifs_orph_node {
786 struct ubifs_ch ch;
787 __le64 cmt_no;
788 __le64 inos[];
Artem Bityutskiycc64f772011-03-25 15:37:35 +0200789} __packed;
Artem Bityutskiy1e517642008-07-14 19:08:37 +0300790
791#endif /* __UBIFS_MEDIA_H__ */