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