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