xref: /OK3568_Linux_fs/kernel/fs/ubifs/ubifs.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 #ifndef __UBIFS_H__
12*4882a593Smuzhiyun #define __UBIFS_H__
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <asm/div64.h>
15*4882a593Smuzhiyun #include <linux/statfs.h>
16*4882a593Smuzhiyun #include <linux/fs.h>
17*4882a593Smuzhiyun #include <linux/err.h>
18*4882a593Smuzhiyun #include <linux/sched.h>
19*4882a593Smuzhiyun #include <linux/slab.h>
20*4882a593Smuzhiyun #include <linux/vmalloc.h>
21*4882a593Smuzhiyun #include <linux/spinlock.h>
22*4882a593Smuzhiyun #include <linux/mutex.h>
23*4882a593Smuzhiyun #include <linux/rwsem.h>
24*4882a593Smuzhiyun #include <linux/mtd/ubi.h>
25*4882a593Smuzhiyun #include <linux/pagemap.h>
26*4882a593Smuzhiyun #include <linux/backing-dev.h>
27*4882a593Smuzhiyun #include <linux/security.h>
28*4882a593Smuzhiyun #include <linux/xattr.h>
29*4882a593Smuzhiyun #include <linux/random.h>
30*4882a593Smuzhiyun #include <crypto/hash_info.h>
31*4882a593Smuzhiyun #include <crypto/hash.h>
32*4882a593Smuzhiyun #include <crypto/algapi.h>
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include <linux/fscrypt.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #include "ubifs-media.h"
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /* Version of this UBIFS implementation */
39*4882a593Smuzhiyun #define UBIFS_VERSION 1
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* UBIFS file system VFS magic number */
42*4882a593Smuzhiyun #define UBIFS_SUPER_MAGIC 0x24051905
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* Number of UBIFS blocks per VFS page */
45*4882a593Smuzhiyun #define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE)
46*4882a593Smuzhiyun #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT)
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* "File system end of life" sequence number watermark */
49*4882a593Smuzhiyun #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
50*4882a593Smuzhiyun #define SQNUM_WATERMARK      0xFFFFFFFFFF000000ULL
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /*
53*4882a593Smuzhiyun  * Minimum amount of LEBs reserved for the index. At present the index needs at
54*4882a593Smuzhiyun  * least 2 LEBs: one for the index head and one for in-the-gaps method (which
55*4882a593Smuzhiyun  * currently does not cater for the index head and so excludes it from
56*4882a593Smuzhiyun  * consideration).
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun #define MIN_INDEX_LEBS 2
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* Minimum amount of data UBIFS writes to the flash */
61*4882a593Smuzhiyun #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun  * Currently we do not support inode number overlapping and re-using, so this
65*4882a593Smuzhiyun  * watermark defines dangerous inode number level. This should be fixed later,
66*4882a593Smuzhiyun  * although it is difficult to exceed current limit. Another option is to use
67*4882a593Smuzhiyun  * 64-bit inode numbers, but this means more overhead.
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun #define INUM_WARN_WATERMARK 0xFFF00000
70*4882a593Smuzhiyun #define INUM_WATERMARK      0xFFFFFF00
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /* Maximum number of entries in each LPT (LEB category) heap */
73*4882a593Smuzhiyun #define LPT_HEAP_SZ 256
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun  * Background thread name pattern. The numbers are UBI device and volume
77*4882a593Smuzhiyun  * numbers.
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun #define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* Maximum possible inode number (only 32-bit inodes are supported now) */
82*4882a593Smuzhiyun #define MAX_INUM 0xFFFFFFFF
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* Number of non-data journal heads */
85*4882a593Smuzhiyun #define NONDATA_JHEADS_CNT 2
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /* Shorter names for journal head numbers for internal usage */
88*4882a593Smuzhiyun #define GCHD   UBIFS_GC_HEAD
89*4882a593Smuzhiyun #define BASEHD UBIFS_BASE_HEAD
90*4882a593Smuzhiyun #define DATAHD UBIFS_DATA_HEAD
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /* 'No change' value for 'ubifs_change_lp()' */
93*4882a593Smuzhiyun #define LPROPS_NC 0x80000001
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun  * There is no notion of truncation key because truncation nodes do not exist
97*4882a593Smuzhiyun  * in TNC. However, when replaying, it is handy to introduce fake "truncation"
98*4882a593Smuzhiyun  * keys for truncation nodes because the code becomes simpler. So we define
99*4882a593Smuzhiyun  * %UBIFS_TRUN_KEY type.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * But otherwise, out of the journal reply scope, the truncation keys are
102*4882a593Smuzhiyun  * invalid.
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun #define UBIFS_TRUN_KEY    UBIFS_KEY_TYPES_CNT
105*4882a593Smuzhiyun #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /*
108*4882a593Smuzhiyun  * How much a directory entry/extended attribute entry adds to the parent/host
109*4882a593Smuzhiyun  * inode.
110*4882a593Smuzhiyun  */
111*4882a593Smuzhiyun #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun /* How much an extended attribute adds to the host inode */
114*4882a593Smuzhiyun #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /*
117*4882a593Smuzhiyun  * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered
118*4882a593Smuzhiyun  * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are
119*4882a593Smuzhiyun  * considered "young". This is used by shrinker when selecting znode to trim
120*4882a593Smuzhiyun  * off.
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun #define OLD_ZNODE_AGE 20
123*4882a593Smuzhiyun #define YOUNG_ZNODE_AGE 5
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun  * Some compressors, like LZO, may end up with more data then the input buffer.
127*4882a593Smuzhiyun  * So UBIFS always allocates larger output buffer, to be sure the compressor
128*4882a593Smuzhiyun  * will not corrupt memory in case of worst case compression.
129*4882a593Smuzhiyun  */
130*4882a593Smuzhiyun #define WORST_COMPR_FACTOR 2
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun #ifdef CONFIG_FS_ENCRYPTION
133*4882a593Smuzhiyun #define UBIFS_CIPHER_BLOCK_SIZE FS_CRYPTO_BLOCK_SIZE
134*4882a593Smuzhiyun #else
135*4882a593Smuzhiyun #define UBIFS_CIPHER_BLOCK_SIZE 0
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  * How much memory is needed for a buffer where we compress a data node.
140*4882a593Smuzhiyun  */
141*4882a593Smuzhiyun #define COMPRESSED_DATA_NODE_BUF_SZ \
142*4882a593Smuzhiyun 	(UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* Maximum expected tree height for use by bottom_up_buf */
145*4882a593Smuzhiyun #define BOTTOM_UP_HEIGHT 64
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun /* Maximum number of data nodes to bulk-read */
148*4882a593Smuzhiyun #define UBIFS_MAX_BULK_READ 32
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun #ifdef CONFIG_UBIFS_FS_AUTHENTICATION
151*4882a593Smuzhiyun #define UBIFS_HASH_ARR_SZ UBIFS_MAX_HASH_LEN
152*4882a593Smuzhiyun #define UBIFS_HMAC_ARR_SZ UBIFS_MAX_HMAC_LEN
153*4882a593Smuzhiyun #else
154*4882a593Smuzhiyun #define UBIFS_HASH_ARR_SZ 0
155*4882a593Smuzhiyun #define UBIFS_HMAC_ARR_SZ 0
156*4882a593Smuzhiyun #endif
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun /*
159*4882a593Smuzhiyun  * Lockdep classes for UBIFS inode @ui_mutex.
160*4882a593Smuzhiyun  */
161*4882a593Smuzhiyun enum {
162*4882a593Smuzhiyun 	WB_MUTEX_1 = 0,
163*4882a593Smuzhiyun 	WB_MUTEX_2 = 1,
164*4882a593Smuzhiyun 	WB_MUTEX_3 = 2,
165*4882a593Smuzhiyun 	WB_MUTEX_4 = 3,
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /*
169*4882a593Smuzhiyun  * Znode flags (actually, bit numbers which store the flags).
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * DIRTY_ZNODE: znode is dirty
172*4882a593Smuzhiyun  * COW_ZNODE: znode is being committed and a new instance of this znode has to
173*4882a593Smuzhiyun  *            be created before changing this znode
174*4882a593Smuzhiyun  * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is
175*4882a593Smuzhiyun  *                 still in the commit list and the ongoing commit operation
176*4882a593Smuzhiyun  *                 will commit it, and delete this znode after it is done
177*4882a593Smuzhiyun  */
178*4882a593Smuzhiyun enum {
179*4882a593Smuzhiyun 	DIRTY_ZNODE    = 0,
180*4882a593Smuzhiyun 	COW_ZNODE      = 1,
181*4882a593Smuzhiyun 	OBSOLETE_ZNODE = 2,
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun /*
185*4882a593Smuzhiyun  * Commit states.
186*4882a593Smuzhiyun  *
187*4882a593Smuzhiyun  * COMMIT_RESTING: commit is not wanted
188*4882a593Smuzhiyun  * COMMIT_BACKGROUND: background commit has been requested
189*4882a593Smuzhiyun  * COMMIT_REQUIRED: commit is required
190*4882a593Smuzhiyun  * COMMIT_RUNNING_BACKGROUND: background commit is running
191*4882a593Smuzhiyun  * COMMIT_RUNNING_REQUIRED: commit is running and it is required
192*4882a593Smuzhiyun  * COMMIT_BROKEN: commit failed
193*4882a593Smuzhiyun  */
194*4882a593Smuzhiyun enum {
195*4882a593Smuzhiyun 	COMMIT_RESTING = 0,
196*4882a593Smuzhiyun 	COMMIT_BACKGROUND,
197*4882a593Smuzhiyun 	COMMIT_REQUIRED,
198*4882a593Smuzhiyun 	COMMIT_RUNNING_BACKGROUND,
199*4882a593Smuzhiyun 	COMMIT_RUNNING_REQUIRED,
200*4882a593Smuzhiyun 	COMMIT_BROKEN,
201*4882a593Smuzhiyun };
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun /*
204*4882a593Smuzhiyun  * 'ubifs_scan_a_node()' return values.
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * SCANNED_GARBAGE:  scanned garbage
207*4882a593Smuzhiyun  * SCANNED_EMPTY_SPACE: scanned empty space
208*4882a593Smuzhiyun  * SCANNED_A_NODE: scanned a valid node
209*4882a593Smuzhiyun  * SCANNED_A_CORRUPT_NODE: scanned a corrupted node
210*4882a593Smuzhiyun  * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length
211*4882a593Smuzhiyun  *
212*4882a593Smuzhiyun  * Greater than zero means: 'scanned that number of padding bytes'
213*4882a593Smuzhiyun  */
214*4882a593Smuzhiyun enum {
215*4882a593Smuzhiyun 	SCANNED_GARBAGE        = 0,
216*4882a593Smuzhiyun 	SCANNED_EMPTY_SPACE    = -1,
217*4882a593Smuzhiyun 	SCANNED_A_NODE         = -2,
218*4882a593Smuzhiyun 	SCANNED_A_CORRUPT_NODE = -3,
219*4882a593Smuzhiyun 	SCANNED_A_BAD_PAD_NODE = -4,
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /*
223*4882a593Smuzhiyun  * LPT cnode flag bits.
224*4882a593Smuzhiyun  *
225*4882a593Smuzhiyun  * DIRTY_CNODE: cnode is dirty
226*4882a593Smuzhiyun  * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted),
227*4882a593Smuzhiyun  *                 so it can (and must) be freed when the commit is finished
228*4882a593Smuzhiyun  * COW_CNODE: cnode is being committed and must be copied before writing
229*4882a593Smuzhiyun  */
230*4882a593Smuzhiyun enum {
231*4882a593Smuzhiyun 	DIRTY_CNODE    = 0,
232*4882a593Smuzhiyun 	OBSOLETE_CNODE = 1,
233*4882a593Smuzhiyun 	COW_CNODE      = 2,
234*4882a593Smuzhiyun };
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun /*
237*4882a593Smuzhiyun  * Dirty flag bits (lpt_drty_flgs) for LPT special nodes.
238*4882a593Smuzhiyun  *
239*4882a593Smuzhiyun  * LTAB_DIRTY: ltab node is dirty
240*4882a593Smuzhiyun  * LSAVE_DIRTY: lsave node is dirty
241*4882a593Smuzhiyun  */
242*4882a593Smuzhiyun enum {
243*4882a593Smuzhiyun 	LTAB_DIRTY  = 1,
244*4882a593Smuzhiyun 	LSAVE_DIRTY = 2,
245*4882a593Smuzhiyun };
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun /*
248*4882a593Smuzhiyun  * Return codes used by the garbage collector.
249*4882a593Smuzhiyun  * @LEB_FREED: the logical eraseblock was freed and is ready to use
250*4882a593Smuzhiyun  * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit
251*4882a593Smuzhiyun  * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes
252*4882a593Smuzhiyun  */
253*4882a593Smuzhiyun enum {
254*4882a593Smuzhiyun 	LEB_FREED,
255*4882a593Smuzhiyun 	LEB_FREED_IDX,
256*4882a593Smuzhiyun 	LEB_RETAINED,
257*4882a593Smuzhiyun };
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun /*
260*4882a593Smuzhiyun  * Action taken upon a failed ubifs_assert().
261*4882a593Smuzhiyun  * @ASSACT_REPORT: just report the failed assertion
262*4882a593Smuzhiyun  * @ASSACT_RO: switch to read-only mode
263*4882a593Smuzhiyun  * @ASSACT_PANIC: call BUG() and possible panic the kernel
264*4882a593Smuzhiyun  */
265*4882a593Smuzhiyun enum {
266*4882a593Smuzhiyun 	ASSACT_REPORT = 0,
267*4882a593Smuzhiyun 	ASSACT_RO,
268*4882a593Smuzhiyun 	ASSACT_PANIC,
269*4882a593Smuzhiyun };
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun /**
272*4882a593Smuzhiyun  * struct ubifs_old_idx - index node obsoleted since last commit start.
273*4882a593Smuzhiyun  * @rb: rb-tree node
274*4882a593Smuzhiyun  * @lnum: LEB number of obsoleted index node
275*4882a593Smuzhiyun  * @offs: offset of obsoleted index node
276*4882a593Smuzhiyun  */
277*4882a593Smuzhiyun struct ubifs_old_idx {
278*4882a593Smuzhiyun 	struct rb_node rb;
279*4882a593Smuzhiyun 	int lnum;
280*4882a593Smuzhiyun 	int offs;
281*4882a593Smuzhiyun };
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun /* The below union makes it easier to deal with keys */
284*4882a593Smuzhiyun union ubifs_key {
285*4882a593Smuzhiyun 	uint8_t u8[UBIFS_SK_LEN];
286*4882a593Smuzhiyun 	uint32_t u32[UBIFS_SK_LEN/4];
287*4882a593Smuzhiyun 	uint64_t u64[UBIFS_SK_LEN/8];
288*4882a593Smuzhiyun 	__le32 j32[UBIFS_SK_LEN/4];
289*4882a593Smuzhiyun };
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun /**
292*4882a593Smuzhiyun  * struct ubifs_scan_node - UBIFS scanned node information.
293*4882a593Smuzhiyun  * @list: list of scanned nodes
294*4882a593Smuzhiyun  * @key: key of node scanned (if it has one)
295*4882a593Smuzhiyun  * @sqnum: sequence number
296*4882a593Smuzhiyun  * @type: type of node scanned
297*4882a593Smuzhiyun  * @offs: offset with LEB of node scanned
298*4882a593Smuzhiyun  * @len: length of node scanned
299*4882a593Smuzhiyun  * @node: raw node
300*4882a593Smuzhiyun  */
301*4882a593Smuzhiyun struct ubifs_scan_node {
302*4882a593Smuzhiyun 	struct list_head list;
303*4882a593Smuzhiyun 	union ubifs_key key;
304*4882a593Smuzhiyun 	unsigned long long sqnum;
305*4882a593Smuzhiyun 	int type;
306*4882a593Smuzhiyun 	int offs;
307*4882a593Smuzhiyun 	int len;
308*4882a593Smuzhiyun 	void *node;
309*4882a593Smuzhiyun };
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun /**
312*4882a593Smuzhiyun  * struct ubifs_scan_leb - UBIFS scanned LEB information.
313*4882a593Smuzhiyun  * @lnum: logical eraseblock number
314*4882a593Smuzhiyun  * @nodes_cnt: number of nodes scanned
315*4882a593Smuzhiyun  * @nodes: list of struct ubifs_scan_node
316*4882a593Smuzhiyun  * @endpt: end point (and therefore the start of empty space)
317*4882a593Smuzhiyun  * @buf: buffer containing entire LEB scanned
318*4882a593Smuzhiyun  */
319*4882a593Smuzhiyun struct ubifs_scan_leb {
320*4882a593Smuzhiyun 	int lnum;
321*4882a593Smuzhiyun 	int nodes_cnt;
322*4882a593Smuzhiyun 	struct list_head nodes;
323*4882a593Smuzhiyun 	int endpt;
324*4882a593Smuzhiyun 	void *buf;
325*4882a593Smuzhiyun };
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun /**
328*4882a593Smuzhiyun  * struct ubifs_gced_idx_leb - garbage-collected indexing LEB.
329*4882a593Smuzhiyun  * @list: list
330*4882a593Smuzhiyun  * @lnum: LEB number
331*4882a593Smuzhiyun  * @unmap: OK to unmap this LEB
332*4882a593Smuzhiyun  *
333*4882a593Smuzhiyun  * This data structure is used to temporary store garbage-collected indexing
334*4882a593Smuzhiyun  * LEBs - they are not released immediately, but only after the next commit.
335*4882a593Smuzhiyun  * This is needed to guarantee recoverability.
336*4882a593Smuzhiyun  */
337*4882a593Smuzhiyun struct ubifs_gced_idx_leb {
338*4882a593Smuzhiyun 	struct list_head list;
339*4882a593Smuzhiyun 	int lnum;
340*4882a593Smuzhiyun 	int unmap;
341*4882a593Smuzhiyun };
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun /**
344*4882a593Smuzhiyun  * struct ubifs_inode - UBIFS in-memory inode description.
345*4882a593Smuzhiyun  * @vfs_inode: VFS inode description object
346*4882a593Smuzhiyun  * @creat_sqnum: sequence number at time of creation
347*4882a593Smuzhiyun  * @del_cmtno: commit number corresponding to the time the inode was deleted,
348*4882a593Smuzhiyun  *             protected by @c->commit_sem;
349*4882a593Smuzhiyun  * @xattr_size: summarized size of all extended attributes in bytes
350*4882a593Smuzhiyun  * @xattr_cnt: count of extended attributes this inode has
351*4882a593Smuzhiyun  * @xattr_names: sum of lengths of all extended attribute names belonging to
352*4882a593Smuzhiyun  *               this inode
353*4882a593Smuzhiyun  * @dirty: non-zero if the inode is dirty
354*4882a593Smuzhiyun  * @xattr: non-zero if this is an extended attribute inode
355*4882a593Smuzhiyun  * @bulk_read: non-zero if bulk-read should be used
356*4882a593Smuzhiyun  * @ui_mutex: serializes inode write-back with the rest of VFS operations,
357*4882a593Smuzhiyun  *            serializes "clean <-> dirty" state changes, serializes bulk-read,
358*4882a593Smuzhiyun  *            protects @dirty, @bulk_read, @ui_size, and @xattr_size
359*4882a593Smuzhiyun  * @xattr_sem: serilizes write operations (remove|set|create) on xattr
360*4882a593Smuzhiyun  * @ui_lock: protects @synced_i_size
361*4882a593Smuzhiyun  * @synced_i_size: synchronized size of inode, i.e. the value of inode size
362*4882a593Smuzhiyun  *                 currently stored on the flash; used only for regular file
363*4882a593Smuzhiyun  *                 inodes
364*4882a593Smuzhiyun  * @ui_size: inode size used by UBIFS when writing to flash
365*4882a593Smuzhiyun  * @flags: inode flags (@UBIFS_COMPR_FL, etc)
366*4882a593Smuzhiyun  * @compr_type: default compression type used for this inode
367*4882a593Smuzhiyun  * @last_page_read: page number of last page read (for bulk read)
368*4882a593Smuzhiyun  * @read_in_a_row: number of consecutive pages read in a row (for bulk read)
369*4882a593Smuzhiyun  * @data_len: length of the data attached to the inode
370*4882a593Smuzhiyun  * @data: inode's data
371*4882a593Smuzhiyun  *
372*4882a593Smuzhiyun  * @ui_mutex exists for two main reasons. At first it prevents inodes from
373*4882a593Smuzhiyun  * being written back while UBIFS changing them, being in the middle of an VFS
374*4882a593Smuzhiyun  * operation. This way UBIFS makes sure the inode fields are consistent. For
375*4882a593Smuzhiyun  * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and
376*4882a593Smuzhiyun  * write-back must not write any of them before we have finished.
377*4882a593Smuzhiyun  *
378*4882a593Smuzhiyun  * The second reason is budgeting - UBIFS has to budget all operations. If an
379*4882a593Smuzhiyun  * operation is going to mark an inode dirty, it has to allocate budget for
380*4882a593Smuzhiyun  * this. It cannot just mark it dirty because there is no guarantee there will
381*4882a593Smuzhiyun  * be enough flash space to write the inode back later. This means UBIFS has
382*4882a593Smuzhiyun  * to have full control over inode "clean <-> dirty" transitions (and pages
383*4882a593Smuzhiyun  * actually). But unfortunately, VFS marks inodes dirty in many places, and it
384*4882a593Smuzhiyun  * does not ask the file-system if it is allowed to do so (there is a notifier,
385*4882a593Smuzhiyun  * but it is not enough), i.e., there is no mechanism to synchronize with this.
386*4882a593Smuzhiyun  * So UBIFS has its own inode dirty flag and its own mutex to serialize
387*4882a593Smuzhiyun  * "clean <-> dirty" transitions.
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * The @synced_i_size field is used to make sure we never write pages which are
390*4882a593Smuzhiyun  * beyond last synchronized inode size. See 'ubifs_writepage()' for more
391*4882a593Smuzhiyun  * information.
392*4882a593Smuzhiyun  *
393*4882a593Smuzhiyun  * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
394*4882a593Smuzhiyun  * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
395*4882a593Smuzhiyun  * make sure @inode->i_size is always changed under @ui_mutex, because it
396*4882a593Smuzhiyun  * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
397*4882a593Smuzhiyun  * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
398*4882a593Smuzhiyun  * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one
399*4882a593Smuzhiyun  * could consider to rework locking and base it on "shadow" fields.
400*4882a593Smuzhiyun  */
401*4882a593Smuzhiyun struct ubifs_inode {
402*4882a593Smuzhiyun 	struct inode vfs_inode;
403*4882a593Smuzhiyun 	unsigned long long creat_sqnum;
404*4882a593Smuzhiyun 	unsigned long long del_cmtno;
405*4882a593Smuzhiyun 	unsigned int xattr_size;
406*4882a593Smuzhiyun 	unsigned int xattr_cnt;
407*4882a593Smuzhiyun 	unsigned int xattr_names;
408*4882a593Smuzhiyun 	unsigned int dirty:1;
409*4882a593Smuzhiyun 	unsigned int xattr:1;
410*4882a593Smuzhiyun 	unsigned int bulk_read:1;
411*4882a593Smuzhiyun 	unsigned int compr_type:2;
412*4882a593Smuzhiyun 	struct mutex ui_mutex;
413*4882a593Smuzhiyun 	struct rw_semaphore xattr_sem;
414*4882a593Smuzhiyun 	spinlock_t ui_lock;
415*4882a593Smuzhiyun 	loff_t synced_i_size;
416*4882a593Smuzhiyun 	loff_t ui_size;
417*4882a593Smuzhiyun 	int flags;
418*4882a593Smuzhiyun 	pgoff_t last_page_read;
419*4882a593Smuzhiyun 	pgoff_t read_in_a_row;
420*4882a593Smuzhiyun 	int data_len;
421*4882a593Smuzhiyun 	void *data;
422*4882a593Smuzhiyun };
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun /**
425*4882a593Smuzhiyun  * struct ubifs_unclean_leb - records a LEB recovered under read-only mode.
426*4882a593Smuzhiyun  * @list: list
427*4882a593Smuzhiyun  * @lnum: LEB number of recovered LEB
428*4882a593Smuzhiyun  * @endpt: offset where recovery ended
429*4882a593Smuzhiyun  *
430*4882a593Smuzhiyun  * This structure records a LEB identified during recovery that needs to be
431*4882a593Smuzhiyun  * cleaned but was not because UBIFS was mounted read-only. The information
432*4882a593Smuzhiyun  * is used to clean the LEB when remounting to read-write mode.
433*4882a593Smuzhiyun  */
434*4882a593Smuzhiyun struct ubifs_unclean_leb {
435*4882a593Smuzhiyun 	struct list_head list;
436*4882a593Smuzhiyun 	int lnum;
437*4882a593Smuzhiyun 	int endpt;
438*4882a593Smuzhiyun };
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun /*
441*4882a593Smuzhiyun  * LEB properties flags.
442*4882a593Smuzhiyun  *
443*4882a593Smuzhiyun  * LPROPS_UNCAT: not categorized
444*4882a593Smuzhiyun  * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index
445*4882a593Smuzhiyun  * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index
446*4882a593Smuzhiyun  * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index
447*4882a593Smuzhiyun  * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs
448*4882a593Smuzhiyun  * LPROPS_EMPTY: LEB is empty, not taken
449*4882a593Smuzhiyun  * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken
450*4882a593Smuzhiyun  * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken
451*4882a593Smuzhiyun  * LPROPS_CAT_MASK: mask for the LEB categories above
452*4882a593Smuzhiyun  * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media)
453*4882a593Smuzhiyun  * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash)
454*4882a593Smuzhiyun  */
455*4882a593Smuzhiyun enum {
456*4882a593Smuzhiyun 	LPROPS_UNCAT     =  0,
457*4882a593Smuzhiyun 	LPROPS_DIRTY     =  1,
458*4882a593Smuzhiyun 	LPROPS_DIRTY_IDX =  2,
459*4882a593Smuzhiyun 	LPROPS_FREE      =  3,
460*4882a593Smuzhiyun 	LPROPS_HEAP_CNT  =  3,
461*4882a593Smuzhiyun 	LPROPS_EMPTY     =  4,
462*4882a593Smuzhiyun 	LPROPS_FREEABLE  =  5,
463*4882a593Smuzhiyun 	LPROPS_FRDI_IDX  =  6,
464*4882a593Smuzhiyun 	LPROPS_CAT_MASK  = 15,
465*4882a593Smuzhiyun 	LPROPS_TAKEN     = 16,
466*4882a593Smuzhiyun 	LPROPS_INDEX     = 32,
467*4882a593Smuzhiyun };
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun /**
470*4882a593Smuzhiyun  * struct ubifs_lprops - logical eraseblock properties.
471*4882a593Smuzhiyun  * @free: amount of free space in bytes
472*4882a593Smuzhiyun  * @dirty: amount of dirty space in bytes
473*4882a593Smuzhiyun  * @flags: LEB properties flags (see above)
474*4882a593Smuzhiyun  * @lnum: LEB number
475*4882a593Smuzhiyun  * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE)
476*4882a593Smuzhiyun  * @hpos: heap position in heap of same-category lprops (other categories)
477*4882a593Smuzhiyun  */
478*4882a593Smuzhiyun struct ubifs_lprops {
479*4882a593Smuzhiyun 	int free;
480*4882a593Smuzhiyun 	int dirty;
481*4882a593Smuzhiyun 	int flags;
482*4882a593Smuzhiyun 	int lnum;
483*4882a593Smuzhiyun 	union {
484*4882a593Smuzhiyun 		struct list_head list;
485*4882a593Smuzhiyun 		int hpos;
486*4882a593Smuzhiyun 	};
487*4882a593Smuzhiyun };
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun /**
490*4882a593Smuzhiyun  * struct ubifs_lpt_lprops - LPT logical eraseblock properties.
491*4882a593Smuzhiyun  * @free: amount of free space in bytes
492*4882a593Smuzhiyun  * @dirty: amount of dirty space in bytes
493*4882a593Smuzhiyun  * @tgc: trivial GC flag (1 => unmap after commit end)
494*4882a593Smuzhiyun  * @cmt: commit flag (1 => reserved for commit)
495*4882a593Smuzhiyun  */
496*4882a593Smuzhiyun struct ubifs_lpt_lprops {
497*4882a593Smuzhiyun 	int free;
498*4882a593Smuzhiyun 	int dirty;
499*4882a593Smuzhiyun 	unsigned tgc:1;
500*4882a593Smuzhiyun 	unsigned cmt:1;
501*4882a593Smuzhiyun };
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun /**
504*4882a593Smuzhiyun  * struct ubifs_lp_stats - statistics of eraseblocks in the main area.
505*4882a593Smuzhiyun  * @empty_lebs: number of empty LEBs
506*4882a593Smuzhiyun  * @taken_empty_lebs: number of taken LEBs
507*4882a593Smuzhiyun  * @idx_lebs: number of indexing LEBs
508*4882a593Smuzhiyun  * @total_free: total free space in bytes (includes all LEBs)
509*4882a593Smuzhiyun  * @total_dirty: total dirty space in bytes (includes all LEBs)
510*4882a593Smuzhiyun  * @total_used: total used space in bytes (does not include index LEBs)
511*4882a593Smuzhiyun  * @total_dead: total dead space in bytes (does not include index LEBs)
512*4882a593Smuzhiyun  * @total_dark: total dark space in bytes (does not include index LEBs)
513*4882a593Smuzhiyun  *
514*4882a593Smuzhiyun  * The @taken_empty_lebs field counts the LEBs that are in the transient state
515*4882a593Smuzhiyun  * of having been "taken" for use but not yet written to. @taken_empty_lebs is
516*4882a593Smuzhiyun  * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be
517*4882a593Smuzhiyun  * used by itself (in which case 'unused_lebs' would be a better name). In the
518*4882a593Smuzhiyun  * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained
519*4882a593Smuzhiyun  * by GC, but unlike other empty LEBs that are "taken", it may not be written
520*4882a593Smuzhiyun  * straight away (i.e. before the next commit start or unmount), so either
521*4882a593Smuzhiyun  * @gc_lnum must be specially accounted for, or the current approach followed
522*4882a593Smuzhiyun  * i.e. count it under @taken_empty_lebs.
523*4882a593Smuzhiyun  *
524*4882a593Smuzhiyun  * @empty_lebs includes @taken_empty_lebs.
525*4882a593Smuzhiyun  *
526*4882a593Smuzhiyun  * @total_used, @total_dead and @total_dark fields do not account indexing
527*4882a593Smuzhiyun  * LEBs.
528*4882a593Smuzhiyun  */
529*4882a593Smuzhiyun struct ubifs_lp_stats {
530*4882a593Smuzhiyun 	int empty_lebs;
531*4882a593Smuzhiyun 	int taken_empty_lebs;
532*4882a593Smuzhiyun 	int idx_lebs;
533*4882a593Smuzhiyun 	long long total_free;
534*4882a593Smuzhiyun 	long long total_dirty;
535*4882a593Smuzhiyun 	long long total_used;
536*4882a593Smuzhiyun 	long long total_dead;
537*4882a593Smuzhiyun 	long long total_dark;
538*4882a593Smuzhiyun };
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun struct ubifs_nnode;
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun /**
543*4882a593Smuzhiyun  * struct ubifs_cnode - LEB Properties Tree common node.
544*4882a593Smuzhiyun  * @parent: parent nnode
545*4882a593Smuzhiyun  * @cnext: next cnode to commit
546*4882a593Smuzhiyun  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
547*4882a593Smuzhiyun  * @iip: index in parent
548*4882a593Smuzhiyun  * @level: level in the tree (zero for pnodes, greater than zero for nnodes)
549*4882a593Smuzhiyun  * @num: node number
550*4882a593Smuzhiyun  */
551*4882a593Smuzhiyun struct ubifs_cnode {
552*4882a593Smuzhiyun 	struct ubifs_nnode *parent;
553*4882a593Smuzhiyun 	struct ubifs_cnode *cnext;
554*4882a593Smuzhiyun 	unsigned long flags;
555*4882a593Smuzhiyun 	int iip;
556*4882a593Smuzhiyun 	int level;
557*4882a593Smuzhiyun 	int num;
558*4882a593Smuzhiyun };
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun /**
561*4882a593Smuzhiyun  * struct ubifs_pnode - LEB Properties Tree leaf node.
562*4882a593Smuzhiyun  * @parent: parent nnode
563*4882a593Smuzhiyun  * @cnext: next cnode to commit
564*4882a593Smuzhiyun  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
565*4882a593Smuzhiyun  * @iip: index in parent
566*4882a593Smuzhiyun  * @level: level in the tree (always zero for pnodes)
567*4882a593Smuzhiyun  * @num: node number
568*4882a593Smuzhiyun  * @lprops: LEB properties array
569*4882a593Smuzhiyun  */
570*4882a593Smuzhiyun struct ubifs_pnode {
571*4882a593Smuzhiyun 	struct ubifs_nnode *parent;
572*4882a593Smuzhiyun 	struct ubifs_cnode *cnext;
573*4882a593Smuzhiyun 	unsigned long flags;
574*4882a593Smuzhiyun 	int iip;
575*4882a593Smuzhiyun 	int level;
576*4882a593Smuzhiyun 	int num;
577*4882a593Smuzhiyun 	struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
578*4882a593Smuzhiyun };
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun /**
581*4882a593Smuzhiyun  * struct ubifs_nbranch - LEB Properties Tree internal node branch.
582*4882a593Smuzhiyun  * @lnum: LEB number of child
583*4882a593Smuzhiyun  * @offs: offset of child
584*4882a593Smuzhiyun  * @nnode: nnode child
585*4882a593Smuzhiyun  * @pnode: pnode child
586*4882a593Smuzhiyun  * @cnode: cnode child
587*4882a593Smuzhiyun  */
588*4882a593Smuzhiyun struct ubifs_nbranch {
589*4882a593Smuzhiyun 	int lnum;
590*4882a593Smuzhiyun 	int offs;
591*4882a593Smuzhiyun 	union {
592*4882a593Smuzhiyun 		struct ubifs_nnode *nnode;
593*4882a593Smuzhiyun 		struct ubifs_pnode *pnode;
594*4882a593Smuzhiyun 		struct ubifs_cnode *cnode;
595*4882a593Smuzhiyun 	};
596*4882a593Smuzhiyun };
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun /**
599*4882a593Smuzhiyun  * struct ubifs_nnode - LEB Properties Tree internal node.
600*4882a593Smuzhiyun  * @parent: parent nnode
601*4882a593Smuzhiyun  * @cnext: next cnode to commit
602*4882a593Smuzhiyun  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
603*4882a593Smuzhiyun  * @iip: index in parent
604*4882a593Smuzhiyun  * @level: level in the tree (always greater than zero for nnodes)
605*4882a593Smuzhiyun  * @num: node number
606*4882a593Smuzhiyun  * @nbranch: branches to child nodes
607*4882a593Smuzhiyun  */
608*4882a593Smuzhiyun struct ubifs_nnode {
609*4882a593Smuzhiyun 	struct ubifs_nnode *parent;
610*4882a593Smuzhiyun 	struct ubifs_cnode *cnext;
611*4882a593Smuzhiyun 	unsigned long flags;
612*4882a593Smuzhiyun 	int iip;
613*4882a593Smuzhiyun 	int level;
614*4882a593Smuzhiyun 	int num;
615*4882a593Smuzhiyun 	struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
616*4882a593Smuzhiyun };
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun /**
619*4882a593Smuzhiyun  * struct ubifs_lpt_heap - heap of categorized lprops.
620*4882a593Smuzhiyun  * @arr: heap array
621*4882a593Smuzhiyun  * @cnt: number in heap
622*4882a593Smuzhiyun  * @max_cnt: maximum number allowed in heap
623*4882a593Smuzhiyun  *
624*4882a593Smuzhiyun  * There are %LPROPS_HEAP_CNT heaps.
625*4882a593Smuzhiyun  */
626*4882a593Smuzhiyun struct ubifs_lpt_heap {
627*4882a593Smuzhiyun 	struct ubifs_lprops **arr;
628*4882a593Smuzhiyun 	int cnt;
629*4882a593Smuzhiyun 	int max_cnt;
630*4882a593Smuzhiyun };
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun /*
633*4882a593Smuzhiyun  * Return codes for LPT scan callback function.
634*4882a593Smuzhiyun  *
635*4882a593Smuzhiyun  * LPT_SCAN_CONTINUE: continue scanning
636*4882a593Smuzhiyun  * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory
637*4882a593Smuzhiyun  * LPT_SCAN_STOP: stop scanning
638*4882a593Smuzhiyun  */
639*4882a593Smuzhiyun enum {
640*4882a593Smuzhiyun 	LPT_SCAN_CONTINUE = 0,
641*4882a593Smuzhiyun 	LPT_SCAN_ADD = 1,
642*4882a593Smuzhiyun 	LPT_SCAN_STOP = 2,
643*4882a593Smuzhiyun };
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun struct ubifs_info;
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun /* Callback used by the 'ubifs_lpt_scan_nolock()' function */
648*4882a593Smuzhiyun typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
649*4882a593Smuzhiyun 				       const struct ubifs_lprops *lprops,
650*4882a593Smuzhiyun 				       int in_tree, void *data);
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun /**
653*4882a593Smuzhiyun  * struct ubifs_wbuf - UBIFS write-buffer.
654*4882a593Smuzhiyun  * @c: UBIFS file-system description object
655*4882a593Smuzhiyun  * @buf: write-buffer (of min. flash I/O unit size)
656*4882a593Smuzhiyun  * @lnum: logical eraseblock number the write-buffer points to
657*4882a593Smuzhiyun  * @offs: write-buffer offset in this logical eraseblock
658*4882a593Smuzhiyun  * @avail: number of bytes available in the write-buffer
659*4882a593Smuzhiyun  * @used:  number of used bytes in the write-buffer
660*4882a593Smuzhiyun  * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range)
661*4882a593Smuzhiyun  * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
662*4882a593Smuzhiyun  *         up by 'mutex_lock_nested()).
663*4882a593Smuzhiyun  * @sync_callback: write-buffer synchronization callback
664*4882a593Smuzhiyun  * @io_mutex: serializes write-buffer I/O
665*4882a593Smuzhiyun  * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
666*4882a593Smuzhiyun  *        fields
667*4882a593Smuzhiyun  * @timer: write-buffer timer
668*4882a593Smuzhiyun  * @no_timer: non-zero if this write-buffer does not have a timer
669*4882a593Smuzhiyun  * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing
670*4882a593Smuzhiyun  * @next_ino: points to the next position of the following inode number
671*4882a593Smuzhiyun  * @inodes: stores the inode numbers of the nodes which are in wbuf
672*4882a593Smuzhiyun  *
673*4882a593Smuzhiyun  * The write-buffer synchronization callback is called when the write-buffer is
674*4882a593Smuzhiyun  * synchronized in order to notify how much space was wasted due to
675*4882a593Smuzhiyun  * write-buffer padding and how much free space is left in the LEB.
676*4882a593Smuzhiyun  *
677*4882a593Smuzhiyun  * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under
678*4882a593Smuzhiyun  * spin-lock or mutex because they are written under both mutex and spin-lock.
679*4882a593Smuzhiyun  * @buf is appended to under mutex but overwritten under both mutex and
680*4882a593Smuzhiyun  * spin-lock. Thus the data between @buf and @buf + @used can be read under
681*4882a593Smuzhiyun  * spinlock.
682*4882a593Smuzhiyun  */
683*4882a593Smuzhiyun struct ubifs_wbuf {
684*4882a593Smuzhiyun 	struct ubifs_info *c;
685*4882a593Smuzhiyun 	void *buf;
686*4882a593Smuzhiyun 	int lnum;
687*4882a593Smuzhiyun 	int offs;
688*4882a593Smuzhiyun 	int avail;
689*4882a593Smuzhiyun 	int used;
690*4882a593Smuzhiyun 	int size;
691*4882a593Smuzhiyun 	int jhead;
692*4882a593Smuzhiyun 	int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
693*4882a593Smuzhiyun 	struct mutex io_mutex;
694*4882a593Smuzhiyun 	spinlock_t lock;
695*4882a593Smuzhiyun 	struct hrtimer timer;
696*4882a593Smuzhiyun 	unsigned int no_timer:1;
697*4882a593Smuzhiyun 	unsigned int need_sync:1;
698*4882a593Smuzhiyun 	int next_ino;
699*4882a593Smuzhiyun 	ino_t *inodes;
700*4882a593Smuzhiyun };
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun /**
703*4882a593Smuzhiyun  * struct ubifs_bud - bud logical eraseblock.
704*4882a593Smuzhiyun  * @lnum: logical eraseblock number
705*4882a593Smuzhiyun  * @start: where the (uncommitted) bud data starts
706*4882a593Smuzhiyun  * @jhead: journal head number this bud belongs to
707*4882a593Smuzhiyun  * @list: link in the list buds belonging to the same journal head
708*4882a593Smuzhiyun  * @rb: link in the tree of all buds
709*4882a593Smuzhiyun  * @log_hash: the log hash from the commit start node up to this bud
710*4882a593Smuzhiyun  */
711*4882a593Smuzhiyun struct ubifs_bud {
712*4882a593Smuzhiyun 	int lnum;
713*4882a593Smuzhiyun 	int start;
714*4882a593Smuzhiyun 	int jhead;
715*4882a593Smuzhiyun 	struct list_head list;
716*4882a593Smuzhiyun 	struct rb_node rb;
717*4882a593Smuzhiyun 	struct shash_desc *log_hash;
718*4882a593Smuzhiyun };
719*4882a593Smuzhiyun 
720*4882a593Smuzhiyun /**
721*4882a593Smuzhiyun  * struct ubifs_jhead - journal head.
722*4882a593Smuzhiyun  * @wbuf: head's write-buffer
723*4882a593Smuzhiyun  * @buds_list: list of bud LEBs belonging to this journal head
724*4882a593Smuzhiyun  * @grouped: non-zero if UBIFS groups nodes when writing to this journal head
725*4882a593Smuzhiyun  * @log_hash: the log hash from the commit start node up to this journal head
726*4882a593Smuzhiyun  *
727*4882a593Smuzhiyun  * Note, the @buds list is protected by the @c->buds_lock.
728*4882a593Smuzhiyun  */
729*4882a593Smuzhiyun struct ubifs_jhead {
730*4882a593Smuzhiyun 	struct ubifs_wbuf wbuf;
731*4882a593Smuzhiyun 	struct list_head buds_list;
732*4882a593Smuzhiyun 	unsigned int grouped:1;
733*4882a593Smuzhiyun 	struct shash_desc *log_hash;
734*4882a593Smuzhiyun };
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun /**
737*4882a593Smuzhiyun  * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
738*4882a593Smuzhiyun  * @key: key
739*4882a593Smuzhiyun  * @znode: znode address in memory
740*4882a593Smuzhiyun  * @lnum: LEB number of the target node (indexing node or data node)
741*4882a593Smuzhiyun  * @offs: target node offset within @lnum
742*4882a593Smuzhiyun  * @len: target node length
743*4882a593Smuzhiyun  * @hash: the hash of the target node
744*4882a593Smuzhiyun  */
745*4882a593Smuzhiyun struct ubifs_zbranch {
746*4882a593Smuzhiyun 	union ubifs_key key;
747*4882a593Smuzhiyun 	union {
748*4882a593Smuzhiyun 		struct ubifs_znode *znode;
749*4882a593Smuzhiyun 		void *leaf;
750*4882a593Smuzhiyun 	};
751*4882a593Smuzhiyun 	int lnum;
752*4882a593Smuzhiyun 	int offs;
753*4882a593Smuzhiyun 	int len;
754*4882a593Smuzhiyun 	u8 hash[UBIFS_HASH_ARR_SZ];
755*4882a593Smuzhiyun };
756*4882a593Smuzhiyun 
757*4882a593Smuzhiyun /**
758*4882a593Smuzhiyun  * struct ubifs_znode - in-memory representation of an indexing node.
759*4882a593Smuzhiyun  * @parent: parent znode or NULL if it is the root
760*4882a593Smuzhiyun  * @cnext: next znode to commit
761*4882a593Smuzhiyun  * @cparent: parent node for this commit
762*4882a593Smuzhiyun  * @ciip: index in cparent's zbranch array
763*4882a593Smuzhiyun  * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE)
764*4882a593Smuzhiyun  * @time: last access time (seconds)
765*4882a593Smuzhiyun  * @level: level of the entry in the TNC tree
766*4882a593Smuzhiyun  * @child_cnt: count of child znodes
767*4882a593Smuzhiyun  * @iip: index in parent's zbranch array
768*4882a593Smuzhiyun  * @alt: lower bound of key range has altered i.e. child inserted at slot 0
769*4882a593Smuzhiyun  * @lnum: LEB number of the corresponding indexing node
770*4882a593Smuzhiyun  * @offs: offset of the corresponding indexing node
771*4882a593Smuzhiyun  * @len: length  of the corresponding indexing node
772*4882a593Smuzhiyun  * @zbranch: array of znode branches (@c->fanout elements)
773*4882a593Smuzhiyun  *
774*4882a593Smuzhiyun  * Note! The @lnum, @offs, and @len fields are not really needed - we have them
775*4882a593Smuzhiyun  * only for internal consistency check. They could be removed to save some RAM.
776*4882a593Smuzhiyun  */
777*4882a593Smuzhiyun struct ubifs_znode {
778*4882a593Smuzhiyun 	struct ubifs_znode *parent;
779*4882a593Smuzhiyun 	struct ubifs_znode *cnext;
780*4882a593Smuzhiyun 	struct ubifs_znode *cparent;
781*4882a593Smuzhiyun 	int ciip;
782*4882a593Smuzhiyun 	unsigned long flags;
783*4882a593Smuzhiyun 	time64_t time;
784*4882a593Smuzhiyun 	int level;
785*4882a593Smuzhiyun 	int child_cnt;
786*4882a593Smuzhiyun 	int iip;
787*4882a593Smuzhiyun 	int alt;
788*4882a593Smuzhiyun 	int lnum;
789*4882a593Smuzhiyun 	int offs;
790*4882a593Smuzhiyun 	int len;
791*4882a593Smuzhiyun 	struct ubifs_zbranch zbranch[];
792*4882a593Smuzhiyun };
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun /**
795*4882a593Smuzhiyun  * struct bu_info - bulk-read information.
796*4882a593Smuzhiyun  * @key: first data node key
797*4882a593Smuzhiyun  * @zbranch: zbranches of data nodes to bulk read
798*4882a593Smuzhiyun  * @buf: buffer to read into
799*4882a593Smuzhiyun  * @buf_len: buffer length
800*4882a593Smuzhiyun  * @gc_seq: GC sequence number to detect races with GC
801*4882a593Smuzhiyun  * @cnt: number of data nodes for bulk read
802*4882a593Smuzhiyun  * @blk_cnt: number of data blocks including holes
803*4882a593Smuzhiyun  * @oef: end of file reached
804*4882a593Smuzhiyun  */
805*4882a593Smuzhiyun struct bu_info {
806*4882a593Smuzhiyun 	union ubifs_key key;
807*4882a593Smuzhiyun 	struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
808*4882a593Smuzhiyun 	void *buf;
809*4882a593Smuzhiyun 	int buf_len;
810*4882a593Smuzhiyun 	int gc_seq;
811*4882a593Smuzhiyun 	int cnt;
812*4882a593Smuzhiyun 	int blk_cnt;
813*4882a593Smuzhiyun 	int eof;
814*4882a593Smuzhiyun };
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun /**
817*4882a593Smuzhiyun  * struct ubifs_node_range - node length range description data structure.
818*4882a593Smuzhiyun  * @len: fixed node length
819*4882a593Smuzhiyun  * @min_len: minimum possible node length
820*4882a593Smuzhiyun  * @max_len: maximum possible node length
821*4882a593Smuzhiyun  *
822*4882a593Smuzhiyun  * If @max_len is %0, the node has fixed length @len.
823*4882a593Smuzhiyun  */
824*4882a593Smuzhiyun struct ubifs_node_range {
825*4882a593Smuzhiyun 	union {
826*4882a593Smuzhiyun 		int len;
827*4882a593Smuzhiyun 		int min_len;
828*4882a593Smuzhiyun 	};
829*4882a593Smuzhiyun 	int max_len;
830*4882a593Smuzhiyun };
831*4882a593Smuzhiyun 
832*4882a593Smuzhiyun /**
833*4882a593Smuzhiyun  * struct ubifs_compressor - UBIFS compressor description structure.
834*4882a593Smuzhiyun  * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc)
835*4882a593Smuzhiyun  * @cc: cryptoapi compressor handle
836*4882a593Smuzhiyun  * @comp_mutex: mutex used during compression
837*4882a593Smuzhiyun  * @decomp_mutex: mutex used during decompression
838*4882a593Smuzhiyun  * @name: compressor name
839*4882a593Smuzhiyun  * @capi_name: cryptoapi compressor name
840*4882a593Smuzhiyun  */
841*4882a593Smuzhiyun struct ubifs_compressor {
842*4882a593Smuzhiyun 	int compr_type;
843*4882a593Smuzhiyun 	struct crypto_comp *cc;
844*4882a593Smuzhiyun 	struct mutex *comp_mutex;
845*4882a593Smuzhiyun 	struct mutex *decomp_mutex;
846*4882a593Smuzhiyun 	const char *name;
847*4882a593Smuzhiyun 	const char *capi_name;
848*4882a593Smuzhiyun };
849*4882a593Smuzhiyun 
850*4882a593Smuzhiyun /**
851*4882a593Smuzhiyun  * struct ubifs_budget_req - budget requirements of an operation.
852*4882a593Smuzhiyun  *
853*4882a593Smuzhiyun  * @fast: non-zero if the budgeting should try to acquire budget quickly and
854*4882a593Smuzhiyun  *        should not try to call write-back
855*4882a593Smuzhiyun  * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields
856*4882a593Smuzhiyun  *               have to be re-calculated
857*4882a593Smuzhiyun  * @new_page: non-zero if the operation adds a new page
858*4882a593Smuzhiyun  * @dirtied_page: non-zero if the operation makes a page dirty
859*4882a593Smuzhiyun  * @new_dent: non-zero if the operation adds a new directory entry
860*4882a593Smuzhiyun  * @mod_dent: non-zero if the operation removes or modifies an existing
861*4882a593Smuzhiyun  *            directory entry
862*4882a593Smuzhiyun  * @new_ino: non-zero if the operation adds a new inode
863*4882a593Smuzhiyun  * @new_ino_d: how much data newly created inode contains
864*4882a593Smuzhiyun  * @dirtied_ino: how many inodes the operation makes dirty
865*4882a593Smuzhiyun  * @dirtied_ino_d: how much data dirtied inode contains
866*4882a593Smuzhiyun  * @idx_growth: how much the index will supposedly grow
867*4882a593Smuzhiyun  * @data_growth: how much new data the operation will supposedly add
868*4882a593Smuzhiyun  * @dd_growth: how much data that makes other data dirty the operation will
869*4882a593Smuzhiyun  *             supposedly add
870*4882a593Smuzhiyun  *
871*4882a593Smuzhiyun  * @idx_growth, @data_growth and @dd_growth are not used in budget request. The
872*4882a593Smuzhiyun  * budgeting subsystem caches index and data growth values there to avoid
873*4882a593Smuzhiyun  * re-calculating them when the budget is released. However, if @idx_growth is
874*4882a593Smuzhiyun  * %-1, it is calculated by the release function using other fields.
875*4882a593Smuzhiyun  *
876*4882a593Smuzhiyun  * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
877*4882a593Smuzhiyun  * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
878*4882a593Smuzhiyun  * dirty by the re-name operation.
879*4882a593Smuzhiyun  *
880*4882a593Smuzhiyun  * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
881*4882a593Smuzhiyun  * make sure the amount of inode data which contribute to @new_ino_d and
882*4882a593Smuzhiyun  * @dirtied_ino_d fields are aligned.
883*4882a593Smuzhiyun  */
884*4882a593Smuzhiyun struct ubifs_budget_req {
885*4882a593Smuzhiyun 	unsigned int fast:1;
886*4882a593Smuzhiyun 	unsigned int recalculate:1;
887*4882a593Smuzhiyun #ifndef UBIFS_DEBUG
888*4882a593Smuzhiyun 	unsigned int new_page:1;
889*4882a593Smuzhiyun 	unsigned int dirtied_page:1;
890*4882a593Smuzhiyun 	unsigned int new_dent:1;
891*4882a593Smuzhiyun 	unsigned int mod_dent:1;
892*4882a593Smuzhiyun 	unsigned int new_ino:1;
893*4882a593Smuzhiyun 	unsigned int new_ino_d:13;
894*4882a593Smuzhiyun 	unsigned int dirtied_ino:4;
895*4882a593Smuzhiyun 	unsigned int dirtied_ino_d:15;
896*4882a593Smuzhiyun #else
897*4882a593Smuzhiyun 	/* Not bit-fields to check for overflows */
898*4882a593Smuzhiyun 	unsigned int new_page;
899*4882a593Smuzhiyun 	unsigned int dirtied_page;
900*4882a593Smuzhiyun 	unsigned int new_dent;
901*4882a593Smuzhiyun 	unsigned int mod_dent;
902*4882a593Smuzhiyun 	unsigned int new_ino;
903*4882a593Smuzhiyun 	unsigned int new_ino_d;
904*4882a593Smuzhiyun 	unsigned int dirtied_ino;
905*4882a593Smuzhiyun 	unsigned int dirtied_ino_d;
906*4882a593Smuzhiyun #endif
907*4882a593Smuzhiyun 	int idx_growth;
908*4882a593Smuzhiyun 	int data_growth;
909*4882a593Smuzhiyun 	int dd_growth;
910*4882a593Smuzhiyun };
911*4882a593Smuzhiyun 
912*4882a593Smuzhiyun /**
913*4882a593Smuzhiyun  * struct ubifs_orphan - stores the inode number of an orphan.
914*4882a593Smuzhiyun  * @rb: rb-tree node of rb-tree of orphans sorted by inode number
915*4882a593Smuzhiyun  * @list: list head of list of orphans in order added
916*4882a593Smuzhiyun  * @new_list: list head of list of orphans added since the last commit
917*4882a593Smuzhiyun  * @child_list: list of xattr childs if this orphan hosts xattrs, list head
918*4882a593Smuzhiyun  * if this orphan is a xattr, not used otherwise.
919*4882a593Smuzhiyun  * @cnext: next orphan to commit
920*4882a593Smuzhiyun  * @dnext: next orphan to delete
921*4882a593Smuzhiyun  * @inum: inode number
922*4882a593Smuzhiyun  * @new: %1 => added since the last commit, otherwise %0
923*4882a593Smuzhiyun  * @cmt: %1 => commit pending, otherwise %0
924*4882a593Smuzhiyun  * @del: %1 => delete pending, otherwise %0
925*4882a593Smuzhiyun  */
926*4882a593Smuzhiyun struct ubifs_orphan {
927*4882a593Smuzhiyun 	struct rb_node rb;
928*4882a593Smuzhiyun 	struct list_head list;
929*4882a593Smuzhiyun 	struct list_head new_list;
930*4882a593Smuzhiyun 	struct list_head child_list;
931*4882a593Smuzhiyun 	struct ubifs_orphan *cnext;
932*4882a593Smuzhiyun 	struct ubifs_orphan *dnext;
933*4882a593Smuzhiyun 	ino_t inum;
934*4882a593Smuzhiyun 	unsigned new:1;
935*4882a593Smuzhiyun 	unsigned cmt:1;
936*4882a593Smuzhiyun 	unsigned del:1;
937*4882a593Smuzhiyun };
938*4882a593Smuzhiyun 
939*4882a593Smuzhiyun /**
940*4882a593Smuzhiyun  * struct ubifs_mount_opts - UBIFS-specific mount options information.
941*4882a593Smuzhiyun  * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
942*4882a593Smuzhiyun  * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable)
943*4882a593Smuzhiyun  * @chk_data_crc: enable/disable CRC data checking when reading data nodes
944*4882a593Smuzhiyun  *                (%0 default, %1 disable, %2 enable)
945*4882a593Smuzhiyun  * @override_compr: override default compressor (%0 - do not override and use
946*4882a593Smuzhiyun  *                  superblock compressor, %1 - override and use compressor
947*4882a593Smuzhiyun  *                  specified in @compr_type)
948*4882a593Smuzhiyun  * @compr_type: compressor type to override the superblock compressor with
949*4882a593Smuzhiyun  *              (%UBIFS_COMPR_NONE, etc)
950*4882a593Smuzhiyun  */
951*4882a593Smuzhiyun struct ubifs_mount_opts {
952*4882a593Smuzhiyun 	unsigned int unmount_mode:2;
953*4882a593Smuzhiyun 	unsigned int bulk_read:2;
954*4882a593Smuzhiyun 	unsigned int chk_data_crc:2;
955*4882a593Smuzhiyun 	unsigned int override_compr:1;
956*4882a593Smuzhiyun 	unsigned int compr_type:2;
957*4882a593Smuzhiyun };
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun /**
960*4882a593Smuzhiyun  * struct ubifs_budg_info - UBIFS budgeting information.
961*4882a593Smuzhiyun  * @idx_growth: amount of bytes budgeted for index growth
962*4882a593Smuzhiyun  * @data_growth: amount of bytes budgeted for cached data
963*4882a593Smuzhiyun  * @dd_growth: amount of bytes budgeted for cached data that will make
964*4882a593Smuzhiyun  *             other data dirty
965*4882a593Smuzhiyun  * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but
966*4882a593Smuzhiyun  *                   which still have to be taken into account because the index
967*4882a593Smuzhiyun  *                   has not been committed so far
968*4882a593Smuzhiyun  * @old_idx_sz: size of index on flash
969*4882a593Smuzhiyun  * @min_idx_lebs: minimum number of LEBs required for the index
970*4882a593Smuzhiyun  * @nospace: non-zero if the file-system does not have flash space (used as
971*4882a593Smuzhiyun  *           optimization)
972*4882a593Smuzhiyun  * @nospace_rp: the same as @nospace, but additionally means that even reserved
973*4882a593Smuzhiyun  *              pool is full
974*4882a593Smuzhiyun  * @page_budget: budget for a page (constant, never changed after mount)
975*4882a593Smuzhiyun  * @inode_budget: budget for an inode (constant, never changed after mount)
976*4882a593Smuzhiyun  * @dent_budget: budget for a directory entry (constant, never changed after
977*4882a593Smuzhiyun  *               mount)
978*4882a593Smuzhiyun  */
979*4882a593Smuzhiyun struct ubifs_budg_info {
980*4882a593Smuzhiyun 	long long idx_growth;
981*4882a593Smuzhiyun 	long long data_growth;
982*4882a593Smuzhiyun 	long long dd_growth;
983*4882a593Smuzhiyun 	long long uncommitted_idx;
984*4882a593Smuzhiyun 	unsigned long long old_idx_sz;
985*4882a593Smuzhiyun 	int min_idx_lebs;
986*4882a593Smuzhiyun 	unsigned int nospace:1;
987*4882a593Smuzhiyun 	unsigned int nospace_rp:1;
988*4882a593Smuzhiyun 	int page_budget;
989*4882a593Smuzhiyun 	int inode_budget;
990*4882a593Smuzhiyun 	int dent_budget;
991*4882a593Smuzhiyun };
992*4882a593Smuzhiyun 
993*4882a593Smuzhiyun struct ubifs_debug_info;
994*4882a593Smuzhiyun 
995*4882a593Smuzhiyun /**
996*4882a593Smuzhiyun  * struct ubifs_info - UBIFS file-system description data structure
997*4882a593Smuzhiyun  * (per-superblock).
998*4882a593Smuzhiyun  * @vfs_sb: VFS @struct super_block object
999*4882a593Smuzhiyun  * @sup_node: The super block node as read from the device
1000*4882a593Smuzhiyun  *
1001*4882a593Smuzhiyun  * @highest_inum: highest used inode number
1002*4882a593Smuzhiyun  * @max_sqnum: current global sequence number
1003*4882a593Smuzhiyun  * @cmt_no: commit number of the last successfully completed commit, protected
1004*4882a593Smuzhiyun  *          by @commit_sem
1005*4882a593Smuzhiyun  * @cnt_lock: protects @highest_inum and @max_sqnum counters
1006*4882a593Smuzhiyun  * @fmt_version: UBIFS on-flash format version
1007*4882a593Smuzhiyun  * @ro_compat_version: R/O compatibility version
1008*4882a593Smuzhiyun  * @uuid: UUID from super block
1009*4882a593Smuzhiyun  *
1010*4882a593Smuzhiyun  * @lhead_lnum: log head logical eraseblock number
1011*4882a593Smuzhiyun  * @lhead_offs: log head offset
1012*4882a593Smuzhiyun  * @ltail_lnum: log tail logical eraseblock number (offset is always 0)
1013*4882a593Smuzhiyun  * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and
1014*4882a593Smuzhiyun  *             @bud_bytes
1015*4882a593Smuzhiyun  * @min_log_bytes: minimum required number of bytes in the log
1016*4882a593Smuzhiyun  * @cmt_bud_bytes: used during commit to temporarily amount of bytes in
1017*4882a593Smuzhiyun  *                 committed buds
1018*4882a593Smuzhiyun  *
1019*4882a593Smuzhiyun  * @buds: tree of all buds indexed by bud LEB number
1020*4882a593Smuzhiyun  * @bud_bytes: how many bytes of flash is used by buds
1021*4882a593Smuzhiyun  * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud
1022*4882a593Smuzhiyun  *             lists
1023*4882a593Smuzhiyun  * @jhead_cnt: count of journal heads
1024*4882a593Smuzhiyun  * @jheads: journal heads (head zero is base head)
1025*4882a593Smuzhiyun  * @max_bud_bytes: maximum number of bytes allowed in buds
1026*4882a593Smuzhiyun  * @bg_bud_bytes: number of bud bytes when background commit is initiated
1027*4882a593Smuzhiyun  * @old_buds: buds to be released after commit ends
1028*4882a593Smuzhiyun  * @max_bud_cnt: maximum number of buds
1029*4882a593Smuzhiyun  *
1030*4882a593Smuzhiyun  * @commit_sem: synchronizes committer with other processes
1031*4882a593Smuzhiyun  * @cmt_state: commit state
1032*4882a593Smuzhiyun  * @cs_lock: commit state lock
1033*4882a593Smuzhiyun  * @cmt_wq: wait queue to sleep on if the log is full and a commit is running
1034*4882a593Smuzhiyun  *
1035*4882a593Smuzhiyun  * @big_lpt: flag that LPT is too big to write whole during commit
1036*4882a593Smuzhiyun  * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up
1037*4882a593Smuzhiyun  * @double_hash: flag indicating that we can do lookups by hash
1038*4882a593Smuzhiyun  * @encrypted: flag indicating that this file system contains encrypted files
1039*4882a593Smuzhiyun  * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
1040*4882a593Smuzhiyun  *                   recovery)
1041*4882a593Smuzhiyun  * @bulk_read: enable bulk-reads
1042*4882a593Smuzhiyun  * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
1043*4882a593Smuzhiyun  * @rw_incompat: the media is not R/W compatible
1044*4882a593Smuzhiyun  * @assert_action: action to take when a ubifs_assert() fails
1045*4882a593Smuzhiyun  * @authenticated: flag indigating the FS is mounted in authenticated mode
1046*4882a593Smuzhiyun  *
1047*4882a593Smuzhiyun  * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
1048*4882a593Smuzhiyun  *             @calc_idx_sz
1049*4882a593Smuzhiyun  * @zroot: zbranch which points to the root index node and znode
1050*4882a593Smuzhiyun  * @cnext: next znode to commit
1051*4882a593Smuzhiyun  * @enext: next znode to commit to empty space
1052*4882a593Smuzhiyun  * @gap_lebs: array of LEBs used by the in-gaps commit method
1053*4882a593Smuzhiyun  * @cbuf: commit buffer
1054*4882a593Smuzhiyun  * @ileb_buf: buffer for commit in-the-gaps method
1055*4882a593Smuzhiyun  * @ileb_len: length of data in ileb_buf
1056*4882a593Smuzhiyun  * @ihead_lnum: LEB number of index head
1057*4882a593Smuzhiyun  * @ihead_offs: offset of index head
1058*4882a593Smuzhiyun  * @ilebs: pre-allocated index LEBs
1059*4882a593Smuzhiyun  * @ileb_cnt: number of pre-allocated index LEBs
1060*4882a593Smuzhiyun  * @ileb_nxt: next pre-allocated index LEBs
1061*4882a593Smuzhiyun  * @old_idx: tree of index nodes obsoleted since the last commit start
1062*4882a593Smuzhiyun  * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c
1063*4882a593Smuzhiyun  *
1064*4882a593Smuzhiyun  * @mst_node: master node
1065*4882a593Smuzhiyun  * @mst_offs: offset of valid master node
1066*4882a593Smuzhiyun  *
1067*4882a593Smuzhiyun  * @max_bu_buf_len: maximum bulk-read buffer length
1068*4882a593Smuzhiyun  * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu
1069*4882a593Smuzhiyun  * @bu: pre-allocated bulk-read information
1070*4882a593Smuzhiyun  *
1071*4882a593Smuzhiyun  * @write_reserve_mutex: protects @write_reserve_buf
1072*4882a593Smuzhiyun  * @write_reserve_buf: on the write path we allocate memory, which might
1073*4882a593Smuzhiyun  *                     sometimes be unavailable, in which case we use this
1074*4882a593Smuzhiyun  *                     write reserve buffer
1075*4882a593Smuzhiyun  *
1076*4882a593Smuzhiyun  * @log_lebs: number of logical eraseblocks in the log
1077*4882a593Smuzhiyun  * @log_bytes: log size in bytes
1078*4882a593Smuzhiyun  * @log_last: last LEB of the log
1079*4882a593Smuzhiyun  * @lpt_lebs: number of LEBs used for lprops table
1080*4882a593Smuzhiyun  * @lpt_first: first LEB of the lprops table area
1081*4882a593Smuzhiyun  * @lpt_last: last LEB of the lprops table area
1082*4882a593Smuzhiyun  * @orph_lebs: number of LEBs used for the orphan area
1083*4882a593Smuzhiyun  * @orph_first: first LEB of the orphan area
1084*4882a593Smuzhiyun  * @orph_last: last LEB of the orphan area
1085*4882a593Smuzhiyun  * @main_lebs: count of LEBs in the main area
1086*4882a593Smuzhiyun  * @main_first: first LEB of the main area
1087*4882a593Smuzhiyun  * @main_bytes: main area size in bytes
1088*4882a593Smuzhiyun  *
1089*4882a593Smuzhiyun  * @key_hash_type: type of the key hash
1090*4882a593Smuzhiyun  * @key_hash: direntry key hash function
1091*4882a593Smuzhiyun  * @key_fmt: key format
1092*4882a593Smuzhiyun  * @key_len: key length
1093*4882a593Smuzhiyun  * @hash_len: The length of the index node hashes
1094*4882a593Smuzhiyun  * @fanout: fanout of the index tree (number of links per indexing node)
1095*4882a593Smuzhiyun  *
1096*4882a593Smuzhiyun  * @min_io_size: minimal input/output unit size
1097*4882a593Smuzhiyun  * @min_io_shift: number of bits in @min_io_size minus one
1098*4882a593Smuzhiyun  * @max_write_size: maximum amount of bytes the underlying flash can write at a
1099*4882a593Smuzhiyun  *                  time (MTD write buffer size)
1100*4882a593Smuzhiyun  * @max_write_shift: number of bits in @max_write_size minus one
1101*4882a593Smuzhiyun  * @leb_size: logical eraseblock size in bytes
1102*4882a593Smuzhiyun  * @leb_start: starting offset of logical eraseblocks within physical
1103*4882a593Smuzhiyun  *             eraseblocks
1104*4882a593Smuzhiyun  * @half_leb_size: half LEB size
1105*4882a593Smuzhiyun  * @idx_leb_size: how many bytes of an LEB are effectively available when it is
1106*4882a593Smuzhiyun  *                used to store indexing nodes (@leb_size - @max_idx_node_sz)
1107*4882a593Smuzhiyun  * @leb_cnt: count of logical eraseblocks
1108*4882a593Smuzhiyun  * @max_leb_cnt: maximum count of logical eraseblocks
1109*4882a593Smuzhiyun  * @ro_media: the underlying UBI volume is read-only
1110*4882a593Smuzhiyun  * @ro_mount: the file-system was mounted as read-only
1111*4882a593Smuzhiyun  * @ro_error: UBIFS switched to R/O mode because an error happened
1112*4882a593Smuzhiyun  *
1113*4882a593Smuzhiyun  * @dirty_pg_cnt: number of dirty pages (not used)
1114*4882a593Smuzhiyun  * @dirty_zn_cnt: number of dirty znodes
1115*4882a593Smuzhiyun  * @clean_zn_cnt: number of clean znodes
1116*4882a593Smuzhiyun  *
1117*4882a593Smuzhiyun  * @space_lock: protects @bi and @lst
1118*4882a593Smuzhiyun  * @lst: lprops statistics
1119*4882a593Smuzhiyun  * @bi: budgeting information
1120*4882a593Smuzhiyun  * @calc_idx_sz: temporary variable which is used to calculate new index size
1121*4882a593Smuzhiyun  *               (contains accurate new index size at end of TNC commit start)
1122*4882a593Smuzhiyun  *
1123*4882a593Smuzhiyun  * @ref_node_alsz: size of the LEB reference node aligned to the min. flash
1124*4882a593Smuzhiyun  *                 I/O unit
1125*4882a593Smuzhiyun  * @mst_node_alsz: master node aligned size
1126*4882a593Smuzhiyun  * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary
1127*4882a593Smuzhiyun  * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary
1128*4882a593Smuzhiyun  * @max_inode_sz: maximum possible inode size in bytes
1129*4882a593Smuzhiyun  * @max_znode_sz: size of znode in bytes
1130*4882a593Smuzhiyun  *
1131*4882a593Smuzhiyun  * @leb_overhead: how many bytes are wasted in an LEB when it is filled with
1132*4882a593Smuzhiyun  *                data nodes of maximum size - used in free space reporting
1133*4882a593Smuzhiyun  * @dead_wm: LEB dead space watermark
1134*4882a593Smuzhiyun  * @dark_wm: LEB dark space watermark
1135*4882a593Smuzhiyun  * @block_cnt: count of 4KiB blocks on the FS
1136*4882a593Smuzhiyun  *
1137*4882a593Smuzhiyun  * @ranges: UBIFS node length ranges
1138*4882a593Smuzhiyun  * @ubi: UBI volume descriptor
1139*4882a593Smuzhiyun  * @di: UBI device information
1140*4882a593Smuzhiyun  * @vi: UBI volume information
1141*4882a593Smuzhiyun  *
1142*4882a593Smuzhiyun  * @orph_tree: rb-tree of orphan inode numbers
1143*4882a593Smuzhiyun  * @orph_list: list of orphan inode numbers in order added
1144*4882a593Smuzhiyun  * @orph_new: list of orphan inode numbers added since last commit
1145*4882a593Smuzhiyun  * @orph_cnext: next orphan to commit
1146*4882a593Smuzhiyun  * @orph_dnext: next orphan to delete
1147*4882a593Smuzhiyun  * @orphan_lock: lock for orph_tree and orph_new
1148*4882a593Smuzhiyun  * @orph_buf: buffer for orphan nodes
1149*4882a593Smuzhiyun  * @new_orphans: number of orphans since last commit
1150*4882a593Smuzhiyun  * @cmt_orphans: number of orphans being committed
1151*4882a593Smuzhiyun  * @tot_orphans: number of orphans in the rb_tree
1152*4882a593Smuzhiyun  * @max_orphans: maximum number of orphans allowed
1153*4882a593Smuzhiyun  * @ohead_lnum: orphan head LEB number
1154*4882a593Smuzhiyun  * @ohead_offs: orphan head offset
1155*4882a593Smuzhiyun  * @no_orphs: non-zero if there are no orphans
1156*4882a593Smuzhiyun  *
1157*4882a593Smuzhiyun  * @bgt: UBIFS background thread
1158*4882a593Smuzhiyun  * @bgt_name: background thread name
1159*4882a593Smuzhiyun  * @need_bgt: if background thread should run
1160*4882a593Smuzhiyun  * @need_wbuf_sync: if write-buffers have to be synchronized
1161*4882a593Smuzhiyun  *
1162*4882a593Smuzhiyun  * @gc_lnum: LEB number used for garbage collection
1163*4882a593Smuzhiyun  * @sbuf: a buffer of LEB size used by GC and replay for scanning
1164*4882a593Smuzhiyun  * @idx_gc: list of index LEBs that have been garbage collected
1165*4882a593Smuzhiyun  * @idx_gc_cnt: number of elements on the idx_gc list
1166*4882a593Smuzhiyun  * @gc_seq: incremented for every non-index LEB garbage collected
1167*4882a593Smuzhiyun  * @gced_lnum: last non-index LEB that was garbage collected
1168*4882a593Smuzhiyun  *
1169*4882a593Smuzhiyun  * @infos_list: links all 'ubifs_info' objects
1170*4882a593Smuzhiyun  * @umount_mutex: serializes shrinker and un-mount
1171*4882a593Smuzhiyun  * @shrinker_run_no: shrinker run number
1172*4882a593Smuzhiyun  *
1173*4882a593Smuzhiyun  * @space_bits: number of bits needed to record free or dirty space
1174*4882a593Smuzhiyun  * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT
1175*4882a593Smuzhiyun  * @lpt_offs_bits: number of bits needed to record an offset in the LPT
1176*4882a593Smuzhiyun  * @lpt_spc_bits: number of bits needed to space in the LPT
1177*4882a593Smuzhiyun  * @pcnt_bits: number of bits needed to record pnode or nnode number
1178*4882a593Smuzhiyun  * @lnum_bits: number of bits needed to record LEB number
1179*4882a593Smuzhiyun  * @nnode_sz: size of on-flash nnode
1180*4882a593Smuzhiyun  * @pnode_sz: size of on-flash pnode
1181*4882a593Smuzhiyun  * @ltab_sz: size of on-flash LPT lprops table
1182*4882a593Smuzhiyun  * @lsave_sz: size of on-flash LPT save table
1183*4882a593Smuzhiyun  * @pnode_cnt: number of pnodes
1184*4882a593Smuzhiyun  * @nnode_cnt: number of nnodes
1185*4882a593Smuzhiyun  * @lpt_hght: height of the LPT
1186*4882a593Smuzhiyun  * @pnodes_have: number of pnodes in memory
1187*4882a593Smuzhiyun  *
1188*4882a593Smuzhiyun  * @lp_mutex: protects lprops table and all the other lprops-related fields
1189*4882a593Smuzhiyun  * @lpt_lnum: LEB number of the root nnode of the LPT
1190*4882a593Smuzhiyun  * @lpt_offs: offset of the root nnode of the LPT
1191*4882a593Smuzhiyun  * @nhead_lnum: LEB number of LPT head
1192*4882a593Smuzhiyun  * @nhead_offs: offset of LPT head
1193*4882a593Smuzhiyun  * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab
1194*4882a593Smuzhiyun  * @dirty_nn_cnt: number of dirty nnodes
1195*4882a593Smuzhiyun  * @dirty_pn_cnt: number of dirty pnodes
1196*4882a593Smuzhiyun  * @check_lpt_free: flag that indicates LPT GC may be needed
1197*4882a593Smuzhiyun  * @lpt_sz: LPT size
1198*4882a593Smuzhiyun  * @lpt_nod_buf: buffer for an on-flash nnode or pnode
1199*4882a593Smuzhiyun  * @lpt_buf: buffer of LEB size used by LPT
1200*4882a593Smuzhiyun  * @nroot: address in memory of the root nnode of the LPT
1201*4882a593Smuzhiyun  * @lpt_cnext: next LPT node to commit
1202*4882a593Smuzhiyun  * @lpt_heap: array of heaps of categorized lprops
1203*4882a593Smuzhiyun  * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at
1204*4882a593Smuzhiyun  *             previous commit start
1205*4882a593Smuzhiyun  * @uncat_list: list of un-categorized LEBs
1206*4882a593Smuzhiyun  * @empty_list: list of empty LEBs
1207*4882a593Smuzhiyun  * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size)
1208*4882a593Smuzhiyun  * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size)
1209*4882a593Smuzhiyun  * @freeable_cnt: number of freeable LEBs in @freeable_list
1210*4882a593Smuzhiyun  * @in_a_category_cnt: count of lprops which are in a certain category, which
1211*4882a593Smuzhiyun  *                     basically meants that they were loaded from the flash
1212*4882a593Smuzhiyun  *
1213*4882a593Smuzhiyun  * @ltab_lnum: LEB number of LPT's own lprops table
1214*4882a593Smuzhiyun  * @ltab_offs: offset of LPT's own lprops table
1215*4882a593Smuzhiyun  * @ltab: LPT's own lprops table
1216*4882a593Smuzhiyun  * @ltab_cmt: LPT's own lprops table (commit copy)
1217*4882a593Smuzhiyun  * @lsave_cnt: number of LEB numbers in LPT's save table
1218*4882a593Smuzhiyun  * @lsave_lnum: LEB number of LPT's save table
1219*4882a593Smuzhiyun  * @lsave_offs: offset of LPT's save table
1220*4882a593Smuzhiyun  * @lsave: LPT's save table
1221*4882a593Smuzhiyun  * @lscan_lnum: LEB number of last LPT scan
1222*4882a593Smuzhiyun  *
1223*4882a593Smuzhiyun  * @rp_size: size of the reserved pool in bytes
1224*4882a593Smuzhiyun  * @report_rp_size: size of the reserved pool reported to user-space
1225*4882a593Smuzhiyun  * @rp_uid: reserved pool user ID
1226*4882a593Smuzhiyun  * @rp_gid: reserved pool group ID
1227*4882a593Smuzhiyun  *
1228*4882a593Smuzhiyun  * @hash_tfm: the hash transformation used for hashing nodes
1229*4882a593Smuzhiyun  * @hmac_tfm: the HMAC transformation for this filesystem
1230*4882a593Smuzhiyun  * @hmac_desc_len: length of the HMAC used for authentication
1231*4882a593Smuzhiyun  * @auth_key_name: the authentication key name
1232*4882a593Smuzhiyun  * @auth_hash_name: the name of the hash algorithm used for authentication
1233*4882a593Smuzhiyun  * @auth_hash_algo: the authentication hash used for this fs
1234*4882a593Smuzhiyun  * @log_hash: the log hash from the commit start node up to the latest reference
1235*4882a593Smuzhiyun  *            node.
1236*4882a593Smuzhiyun  *
1237*4882a593Smuzhiyun  * @empty: %1 if the UBI device is empty
1238*4882a593Smuzhiyun  * @need_recovery: %1 if the file-system needs recovery
1239*4882a593Smuzhiyun  * @replaying: %1 during journal replay
1240*4882a593Smuzhiyun  * @mounting: %1 while mounting
1241*4882a593Smuzhiyun  * @probing: %1 while attempting to mount if SB_SILENT mount flag is set
1242*4882a593Smuzhiyun  * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode
1243*4882a593Smuzhiyun  * @replay_list: temporary list used during journal replay
1244*4882a593Smuzhiyun  * @replay_buds: list of buds to replay
1245*4882a593Smuzhiyun  * @cs_sqnum: sequence number of first node in the log (commit start node)
1246*4882a593Smuzhiyun  * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W
1247*4882a593Smuzhiyun  *                    mode
1248*4882a593Smuzhiyun  * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted
1249*4882a593Smuzhiyun  *                  FS to R/W mode
1250*4882a593Smuzhiyun  * @size_tree: inode size information for recovery
1251*4882a593Smuzhiyun  * @mount_opts: UBIFS-specific mount options
1252*4882a593Smuzhiyun  *
1253*4882a593Smuzhiyun  * @dbg: debugging-related information
1254*4882a593Smuzhiyun  */
1255*4882a593Smuzhiyun struct ubifs_info {
1256*4882a593Smuzhiyun 	struct super_block *vfs_sb;
1257*4882a593Smuzhiyun 	struct ubifs_sb_node *sup_node;
1258*4882a593Smuzhiyun 
1259*4882a593Smuzhiyun 	ino_t highest_inum;
1260*4882a593Smuzhiyun 	unsigned long long max_sqnum;
1261*4882a593Smuzhiyun 	unsigned long long cmt_no;
1262*4882a593Smuzhiyun 	spinlock_t cnt_lock;
1263*4882a593Smuzhiyun 	int fmt_version;
1264*4882a593Smuzhiyun 	int ro_compat_version;
1265*4882a593Smuzhiyun 	unsigned char uuid[16];
1266*4882a593Smuzhiyun 
1267*4882a593Smuzhiyun 	int lhead_lnum;
1268*4882a593Smuzhiyun 	int lhead_offs;
1269*4882a593Smuzhiyun 	int ltail_lnum;
1270*4882a593Smuzhiyun 	struct mutex log_mutex;
1271*4882a593Smuzhiyun 	int min_log_bytes;
1272*4882a593Smuzhiyun 	long long cmt_bud_bytes;
1273*4882a593Smuzhiyun 
1274*4882a593Smuzhiyun 	struct rb_root buds;
1275*4882a593Smuzhiyun 	long long bud_bytes;
1276*4882a593Smuzhiyun 	spinlock_t buds_lock;
1277*4882a593Smuzhiyun 	int jhead_cnt;
1278*4882a593Smuzhiyun 	struct ubifs_jhead *jheads;
1279*4882a593Smuzhiyun 	long long max_bud_bytes;
1280*4882a593Smuzhiyun 	long long bg_bud_bytes;
1281*4882a593Smuzhiyun 	struct list_head old_buds;
1282*4882a593Smuzhiyun 	int max_bud_cnt;
1283*4882a593Smuzhiyun 
1284*4882a593Smuzhiyun 	struct rw_semaphore commit_sem;
1285*4882a593Smuzhiyun 	int cmt_state;
1286*4882a593Smuzhiyun 	spinlock_t cs_lock;
1287*4882a593Smuzhiyun 	wait_queue_head_t cmt_wq;
1288*4882a593Smuzhiyun 
1289*4882a593Smuzhiyun 	unsigned int big_lpt:1;
1290*4882a593Smuzhiyun 	unsigned int space_fixup:1;
1291*4882a593Smuzhiyun 	unsigned int double_hash:1;
1292*4882a593Smuzhiyun 	unsigned int encrypted:1;
1293*4882a593Smuzhiyun 	unsigned int no_chk_data_crc:1;
1294*4882a593Smuzhiyun 	unsigned int bulk_read:1;
1295*4882a593Smuzhiyun 	unsigned int default_compr:2;
1296*4882a593Smuzhiyun 	unsigned int rw_incompat:1;
1297*4882a593Smuzhiyun 	unsigned int assert_action:2;
1298*4882a593Smuzhiyun 	unsigned int authenticated:1;
1299*4882a593Smuzhiyun 	unsigned int superblock_need_write:1;
1300*4882a593Smuzhiyun 
1301*4882a593Smuzhiyun 	struct mutex tnc_mutex;
1302*4882a593Smuzhiyun 	struct ubifs_zbranch zroot;
1303*4882a593Smuzhiyun 	struct ubifs_znode *cnext;
1304*4882a593Smuzhiyun 	struct ubifs_znode *enext;
1305*4882a593Smuzhiyun 	int *gap_lebs;
1306*4882a593Smuzhiyun 	void *cbuf;
1307*4882a593Smuzhiyun 	void *ileb_buf;
1308*4882a593Smuzhiyun 	int ileb_len;
1309*4882a593Smuzhiyun 	int ihead_lnum;
1310*4882a593Smuzhiyun 	int ihead_offs;
1311*4882a593Smuzhiyun 	int *ilebs;
1312*4882a593Smuzhiyun 	int ileb_cnt;
1313*4882a593Smuzhiyun 	int ileb_nxt;
1314*4882a593Smuzhiyun 	struct rb_root old_idx;
1315*4882a593Smuzhiyun 	int *bottom_up_buf;
1316*4882a593Smuzhiyun 
1317*4882a593Smuzhiyun 	struct ubifs_mst_node *mst_node;
1318*4882a593Smuzhiyun 	int mst_offs;
1319*4882a593Smuzhiyun 
1320*4882a593Smuzhiyun 	int max_bu_buf_len;
1321*4882a593Smuzhiyun 	struct mutex bu_mutex;
1322*4882a593Smuzhiyun 	struct bu_info bu;
1323*4882a593Smuzhiyun 
1324*4882a593Smuzhiyun 	struct mutex write_reserve_mutex;
1325*4882a593Smuzhiyun 	void *write_reserve_buf;
1326*4882a593Smuzhiyun 
1327*4882a593Smuzhiyun 	int log_lebs;
1328*4882a593Smuzhiyun 	long long log_bytes;
1329*4882a593Smuzhiyun 	int log_last;
1330*4882a593Smuzhiyun 	int lpt_lebs;
1331*4882a593Smuzhiyun 	int lpt_first;
1332*4882a593Smuzhiyun 	int lpt_last;
1333*4882a593Smuzhiyun 	int orph_lebs;
1334*4882a593Smuzhiyun 	int orph_first;
1335*4882a593Smuzhiyun 	int orph_last;
1336*4882a593Smuzhiyun 	int main_lebs;
1337*4882a593Smuzhiyun 	int main_first;
1338*4882a593Smuzhiyun 	long long main_bytes;
1339*4882a593Smuzhiyun 
1340*4882a593Smuzhiyun 	uint8_t key_hash_type;
1341*4882a593Smuzhiyun 	uint32_t (*key_hash)(const char *str, int len);
1342*4882a593Smuzhiyun 	int key_fmt;
1343*4882a593Smuzhiyun 	int key_len;
1344*4882a593Smuzhiyun 	int hash_len;
1345*4882a593Smuzhiyun 	int fanout;
1346*4882a593Smuzhiyun 
1347*4882a593Smuzhiyun 	int min_io_size;
1348*4882a593Smuzhiyun 	int min_io_shift;
1349*4882a593Smuzhiyun 	int max_write_size;
1350*4882a593Smuzhiyun 	int max_write_shift;
1351*4882a593Smuzhiyun 	int leb_size;
1352*4882a593Smuzhiyun 	int leb_start;
1353*4882a593Smuzhiyun 	int half_leb_size;
1354*4882a593Smuzhiyun 	int idx_leb_size;
1355*4882a593Smuzhiyun 	int leb_cnt;
1356*4882a593Smuzhiyun 	int max_leb_cnt;
1357*4882a593Smuzhiyun 	unsigned int ro_media:1;
1358*4882a593Smuzhiyun 	unsigned int ro_mount:1;
1359*4882a593Smuzhiyun 	unsigned int ro_error:1;
1360*4882a593Smuzhiyun 
1361*4882a593Smuzhiyun 	atomic_long_t dirty_pg_cnt;
1362*4882a593Smuzhiyun 	atomic_long_t dirty_zn_cnt;
1363*4882a593Smuzhiyun 	atomic_long_t clean_zn_cnt;
1364*4882a593Smuzhiyun 
1365*4882a593Smuzhiyun 	spinlock_t space_lock;
1366*4882a593Smuzhiyun 	struct ubifs_lp_stats lst;
1367*4882a593Smuzhiyun 	struct ubifs_budg_info bi;
1368*4882a593Smuzhiyun 	unsigned long long calc_idx_sz;
1369*4882a593Smuzhiyun 
1370*4882a593Smuzhiyun 	int ref_node_alsz;
1371*4882a593Smuzhiyun 	int mst_node_alsz;
1372*4882a593Smuzhiyun 	int min_idx_node_sz;
1373*4882a593Smuzhiyun 	int max_idx_node_sz;
1374*4882a593Smuzhiyun 	long long max_inode_sz;
1375*4882a593Smuzhiyun 	int max_znode_sz;
1376*4882a593Smuzhiyun 
1377*4882a593Smuzhiyun 	int leb_overhead;
1378*4882a593Smuzhiyun 	int dead_wm;
1379*4882a593Smuzhiyun 	int dark_wm;
1380*4882a593Smuzhiyun 	int block_cnt;
1381*4882a593Smuzhiyun 
1382*4882a593Smuzhiyun 	struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
1383*4882a593Smuzhiyun 	struct ubi_volume_desc *ubi;
1384*4882a593Smuzhiyun 	struct ubi_device_info di;
1385*4882a593Smuzhiyun 	struct ubi_volume_info vi;
1386*4882a593Smuzhiyun 
1387*4882a593Smuzhiyun 	struct rb_root orph_tree;
1388*4882a593Smuzhiyun 	struct list_head orph_list;
1389*4882a593Smuzhiyun 	struct list_head orph_new;
1390*4882a593Smuzhiyun 	struct ubifs_orphan *orph_cnext;
1391*4882a593Smuzhiyun 	struct ubifs_orphan *orph_dnext;
1392*4882a593Smuzhiyun 	spinlock_t orphan_lock;
1393*4882a593Smuzhiyun 	void *orph_buf;
1394*4882a593Smuzhiyun 	int new_orphans;
1395*4882a593Smuzhiyun 	int cmt_orphans;
1396*4882a593Smuzhiyun 	int tot_orphans;
1397*4882a593Smuzhiyun 	int max_orphans;
1398*4882a593Smuzhiyun 	int ohead_lnum;
1399*4882a593Smuzhiyun 	int ohead_offs;
1400*4882a593Smuzhiyun 	int no_orphs;
1401*4882a593Smuzhiyun 
1402*4882a593Smuzhiyun 	struct task_struct *bgt;
1403*4882a593Smuzhiyun 	char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
1404*4882a593Smuzhiyun 	int need_bgt;
1405*4882a593Smuzhiyun 	int need_wbuf_sync;
1406*4882a593Smuzhiyun 
1407*4882a593Smuzhiyun 	int gc_lnum;
1408*4882a593Smuzhiyun 	void *sbuf;
1409*4882a593Smuzhiyun 	struct list_head idx_gc;
1410*4882a593Smuzhiyun 	int idx_gc_cnt;
1411*4882a593Smuzhiyun 	int gc_seq;
1412*4882a593Smuzhiyun 	int gced_lnum;
1413*4882a593Smuzhiyun 
1414*4882a593Smuzhiyun 	struct list_head infos_list;
1415*4882a593Smuzhiyun 	struct mutex umount_mutex;
1416*4882a593Smuzhiyun 	unsigned int shrinker_run_no;
1417*4882a593Smuzhiyun 
1418*4882a593Smuzhiyun 	int space_bits;
1419*4882a593Smuzhiyun 	int lpt_lnum_bits;
1420*4882a593Smuzhiyun 	int lpt_offs_bits;
1421*4882a593Smuzhiyun 	int lpt_spc_bits;
1422*4882a593Smuzhiyun 	int pcnt_bits;
1423*4882a593Smuzhiyun 	int lnum_bits;
1424*4882a593Smuzhiyun 	int nnode_sz;
1425*4882a593Smuzhiyun 	int pnode_sz;
1426*4882a593Smuzhiyun 	int ltab_sz;
1427*4882a593Smuzhiyun 	int lsave_sz;
1428*4882a593Smuzhiyun 	int pnode_cnt;
1429*4882a593Smuzhiyun 	int nnode_cnt;
1430*4882a593Smuzhiyun 	int lpt_hght;
1431*4882a593Smuzhiyun 	int pnodes_have;
1432*4882a593Smuzhiyun 
1433*4882a593Smuzhiyun 	struct mutex lp_mutex;
1434*4882a593Smuzhiyun 	int lpt_lnum;
1435*4882a593Smuzhiyun 	int lpt_offs;
1436*4882a593Smuzhiyun 	int nhead_lnum;
1437*4882a593Smuzhiyun 	int nhead_offs;
1438*4882a593Smuzhiyun 	int lpt_drty_flgs;
1439*4882a593Smuzhiyun 	int dirty_nn_cnt;
1440*4882a593Smuzhiyun 	int dirty_pn_cnt;
1441*4882a593Smuzhiyun 	int check_lpt_free;
1442*4882a593Smuzhiyun 	long long lpt_sz;
1443*4882a593Smuzhiyun 	void *lpt_nod_buf;
1444*4882a593Smuzhiyun 	void *lpt_buf;
1445*4882a593Smuzhiyun 	struct ubifs_nnode *nroot;
1446*4882a593Smuzhiyun 	struct ubifs_cnode *lpt_cnext;
1447*4882a593Smuzhiyun 	struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
1448*4882a593Smuzhiyun 	struct ubifs_lpt_heap dirty_idx;
1449*4882a593Smuzhiyun 	struct list_head uncat_list;
1450*4882a593Smuzhiyun 	struct list_head empty_list;
1451*4882a593Smuzhiyun 	struct list_head freeable_list;
1452*4882a593Smuzhiyun 	struct list_head frdi_idx_list;
1453*4882a593Smuzhiyun 	int freeable_cnt;
1454*4882a593Smuzhiyun 	int in_a_category_cnt;
1455*4882a593Smuzhiyun 
1456*4882a593Smuzhiyun 	int ltab_lnum;
1457*4882a593Smuzhiyun 	int ltab_offs;
1458*4882a593Smuzhiyun 	struct ubifs_lpt_lprops *ltab;
1459*4882a593Smuzhiyun 	struct ubifs_lpt_lprops *ltab_cmt;
1460*4882a593Smuzhiyun 	int lsave_cnt;
1461*4882a593Smuzhiyun 	int lsave_lnum;
1462*4882a593Smuzhiyun 	int lsave_offs;
1463*4882a593Smuzhiyun 	int *lsave;
1464*4882a593Smuzhiyun 	int lscan_lnum;
1465*4882a593Smuzhiyun 
1466*4882a593Smuzhiyun 	long long rp_size;
1467*4882a593Smuzhiyun 	long long report_rp_size;
1468*4882a593Smuzhiyun 	kuid_t rp_uid;
1469*4882a593Smuzhiyun 	kgid_t rp_gid;
1470*4882a593Smuzhiyun 
1471*4882a593Smuzhiyun 	struct crypto_shash *hash_tfm;
1472*4882a593Smuzhiyun 	struct crypto_shash *hmac_tfm;
1473*4882a593Smuzhiyun 	int hmac_desc_len;
1474*4882a593Smuzhiyun 	char *auth_key_name;
1475*4882a593Smuzhiyun 	char *auth_hash_name;
1476*4882a593Smuzhiyun 	enum hash_algo auth_hash_algo;
1477*4882a593Smuzhiyun 
1478*4882a593Smuzhiyun 	struct shash_desc *log_hash;
1479*4882a593Smuzhiyun 
1480*4882a593Smuzhiyun 	/* The below fields are used only during mounting and re-mounting */
1481*4882a593Smuzhiyun 	unsigned int empty:1;
1482*4882a593Smuzhiyun 	unsigned int need_recovery:1;
1483*4882a593Smuzhiyun 	unsigned int replaying:1;
1484*4882a593Smuzhiyun 	unsigned int mounting:1;
1485*4882a593Smuzhiyun 	unsigned int remounting_rw:1;
1486*4882a593Smuzhiyun 	unsigned int probing:1;
1487*4882a593Smuzhiyun 	struct list_head replay_list;
1488*4882a593Smuzhiyun 	struct list_head replay_buds;
1489*4882a593Smuzhiyun 	unsigned long long cs_sqnum;
1490*4882a593Smuzhiyun 	struct list_head unclean_leb_list;
1491*4882a593Smuzhiyun 	struct ubifs_mst_node *rcvrd_mst_node;
1492*4882a593Smuzhiyun 	struct rb_root size_tree;
1493*4882a593Smuzhiyun 	struct ubifs_mount_opts mount_opts;
1494*4882a593Smuzhiyun 
1495*4882a593Smuzhiyun 	struct ubifs_debug_info *dbg;
1496*4882a593Smuzhiyun };
1497*4882a593Smuzhiyun 
1498*4882a593Smuzhiyun extern struct list_head ubifs_infos;
1499*4882a593Smuzhiyun extern spinlock_t ubifs_infos_lock;
1500*4882a593Smuzhiyun extern atomic_long_t ubifs_clean_zn_cnt;
1501*4882a593Smuzhiyun extern const struct super_operations ubifs_super_operations;
1502*4882a593Smuzhiyun extern const struct address_space_operations ubifs_file_address_operations;
1503*4882a593Smuzhiyun extern const struct file_operations ubifs_file_operations;
1504*4882a593Smuzhiyun extern const struct inode_operations ubifs_file_inode_operations;
1505*4882a593Smuzhiyun extern const struct file_operations ubifs_dir_operations;
1506*4882a593Smuzhiyun extern const struct inode_operations ubifs_dir_inode_operations;
1507*4882a593Smuzhiyun extern const struct inode_operations ubifs_symlink_inode_operations;
1508*4882a593Smuzhiyun extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
1509*4882a593Smuzhiyun extern int ubifs_default_version;
1510*4882a593Smuzhiyun 
1511*4882a593Smuzhiyun /* auth.c */
ubifs_authenticated(const struct ubifs_info * c)1512*4882a593Smuzhiyun static inline int ubifs_authenticated(const struct ubifs_info *c)
1513*4882a593Smuzhiyun {
1514*4882a593Smuzhiyun 	return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated;
1515*4882a593Smuzhiyun }
1516*4882a593Smuzhiyun 
1517*4882a593Smuzhiyun struct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c);
ubifs_hash_get_desc(const struct ubifs_info * c)1518*4882a593Smuzhiyun static inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c)
1519*4882a593Smuzhiyun {
1520*4882a593Smuzhiyun 	return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL;
1521*4882a593Smuzhiyun }
1522*4882a593Smuzhiyun 
ubifs_shash_init(const struct ubifs_info * c,struct shash_desc * desc)1523*4882a593Smuzhiyun static inline int ubifs_shash_init(const struct ubifs_info *c,
1524*4882a593Smuzhiyun 				   struct shash_desc *desc)
1525*4882a593Smuzhiyun {
1526*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1527*4882a593Smuzhiyun 		return crypto_shash_init(desc);
1528*4882a593Smuzhiyun 	else
1529*4882a593Smuzhiyun 		return 0;
1530*4882a593Smuzhiyun }
1531*4882a593Smuzhiyun 
ubifs_shash_update(const struct ubifs_info * c,struct shash_desc * desc,const void * buf,unsigned int len)1532*4882a593Smuzhiyun static inline int ubifs_shash_update(const struct ubifs_info *c,
1533*4882a593Smuzhiyun 				      struct shash_desc *desc, const void *buf,
1534*4882a593Smuzhiyun 				      unsigned int len)
1535*4882a593Smuzhiyun {
1536*4882a593Smuzhiyun 	int err = 0;
1537*4882a593Smuzhiyun 
1538*4882a593Smuzhiyun 	if (ubifs_authenticated(c)) {
1539*4882a593Smuzhiyun 		err = crypto_shash_update(desc, buf, len);
1540*4882a593Smuzhiyun 		if (err < 0)
1541*4882a593Smuzhiyun 			return err;
1542*4882a593Smuzhiyun 	}
1543*4882a593Smuzhiyun 
1544*4882a593Smuzhiyun 	return 0;
1545*4882a593Smuzhiyun }
1546*4882a593Smuzhiyun 
ubifs_shash_final(const struct ubifs_info * c,struct shash_desc * desc,u8 * out)1547*4882a593Smuzhiyun static inline int ubifs_shash_final(const struct ubifs_info *c,
1548*4882a593Smuzhiyun 				    struct shash_desc *desc, u8 *out)
1549*4882a593Smuzhiyun {
1550*4882a593Smuzhiyun 	return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0;
1551*4882a593Smuzhiyun }
1552*4882a593Smuzhiyun 
1553*4882a593Smuzhiyun int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf,
1554*4882a593Smuzhiyun 			  u8 *hash);
ubifs_node_calc_hash(const struct ubifs_info * c,const void * buf,u8 * hash)1555*4882a593Smuzhiyun static inline int ubifs_node_calc_hash(const struct ubifs_info *c,
1556*4882a593Smuzhiyun 					const void *buf, u8 *hash)
1557*4882a593Smuzhiyun {
1558*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1559*4882a593Smuzhiyun 		return __ubifs_node_calc_hash(c, buf, hash);
1560*4882a593Smuzhiyun 	else
1561*4882a593Smuzhiyun 		return 0;
1562*4882a593Smuzhiyun }
1563*4882a593Smuzhiyun 
1564*4882a593Smuzhiyun int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
1565*4882a593Smuzhiyun 			     struct shash_desc *inhash);
1566*4882a593Smuzhiyun 
1567*4882a593Smuzhiyun /**
1568*4882a593Smuzhiyun  * ubifs_check_hash - compare two hashes
1569*4882a593Smuzhiyun  * @c: UBIFS file-system description object
1570*4882a593Smuzhiyun  * @expected: first hash
1571*4882a593Smuzhiyun  * @got: second hash
1572*4882a593Smuzhiyun  *
1573*4882a593Smuzhiyun  * Compare two hashes @expected and @got. Returns 0 when they are equal, a
1574*4882a593Smuzhiyun  * negative error code otherwise.
1575*4882a593Smuzhiyun  */
ubifs_check_hash(const struct ubifs_info * c,const u8 * expected,const u8 * got)1576*4882a593Smuzhiyun static inline int ubifs_check_hash(const struct ubifs_info *c,
1577*4882a593Smuzhiyun 				   const u8 *expected, const u8 *got)
1578*4882a593Smuzhiyun {
1579*4882a593Smuzhiyun 	return crypto_memneq(expected, got, c->hash_len);
1580*4882a593Smuzhiyun }
1581*4882a593Smuzhiyun 
1582*4882a593Smuzhiyun /**
1583*4882a593Smuzhiyun  * ubifs_check_hmac - compare two HMACs
1584*4882a593Smuzhiyun  * @c: UBIFS file-system description object
1585*4882a593Smuzhiyun  * @expected: first HMAC
1586*4882a593Smuzhiyun  * @got: second HMAC
1587*4882a593Smuzhiyun  *
1588*4882a593Smuzhiyun  * Compare two hashes @expected and @got. Returns 0 when they are equal, a
1589*4882a593Smuzhiyun  * negative error code otherwise.
1590*4882a593Smuzhiyun  */
ubifs_check_hmac(const struct ubifs_info * c,const u8 * expected,const u8 * got)1591*4882a593Smuzhiyun static inline int ubifs_check_hmac(const struct ubifs_info *c,
1592*4882a593Smuzhiyun 				   const u8 *expected, const u8 *got)
1593*4882a593Smuzhiyun {
1594*4882a593Smuzhiyun 	return crypto_memneq(expected, got, c->hmac_desc_len);
1595*4882a593Smuzhiyun }
1596*4882a593Smuzhiyun 
1597*4882a593Smuzhiyun void ubifs_bad_hash(const struct ubifs_info *c, const void *node,
1598*4882a593Smuzhiyun 		    const u8 *hash, int lnum, int offs);
1599*4882a593Smuzhiyun 
1600*4882a593Smuzhiyun int __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf,
1601*4882a593Smuzhiyun 			  const u8 *expected);
ubifs_node_check_hash(const struct ubifs_info * c,const void * buf,const u8 * expected)1602*4882a593Smuzhiyun static inline int ubifs_node_check_hash(const struct ubifs_info *c,
1603*4882a593Smuzhiyun 					const void *buf, const u8 *expected)
1604*4882a593Smuzhiyun {
1605*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1606*4882a593Smuzhiyun 		return __ubifs_node_check_hash(c, buf, expected);
1607*4882a593Smuzhiyun 	else
1608*4882a593Smuzhiyun 		return 0;
1609*4882a593Smuzhiyun }
1610*4882a593Smuzhiyun 
1611*4882a593Smuzhiyun int ubifs_init_authentication(struct ubifs_info *c);
1612*4882a593Smuzhiyun void __ubifs_exit_authentication(struct ubifs_info *c);
ubifs_exit_authentication(struct ubifs_info * c)1613*4882a593Smuzhiyun static inline void ubifs_exit_authentication(struct ubifs_info *c)
1614*4882a593Smuzhiyun {
1615*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1616*4882a593Smuzhiyun 		__ubifs_exit_authentication(c);
1617*4882a593Smuzhiyun }
1618*4882a593Smuzhiyun 
1619*4882a593Smuzhiyun /**
1620*4882a593Smuzhiyun  * ubifs_branch_hash - returns a pointer to the hash of a branch
1621*4882a593Smuzhiyun  * @c: UBIFS file-system description object
1622*4882a593Smuzhiyun  * @br: branch to get the hash from
1623*4882a593Smuzhiyun  *
1624*4882a593Smuzhiyun  * This returns a pointer to the hash of a branch. Since the key already is a
1625*4882a593Smuzhiyun  * dynamically sized object we cannot use a struct member here.
1626*4882a593Smuzhiyun  */
ubifs_branch_hash(struct ubifs_info * c,struct ubifs_branch * br)1627*4882a593Smuzhiyun static inline u8 *ubifs_branch_hash(struct ubifs_info *c,
1628*4882a593Smuzhiyun 				    struct ubifs_branch *br)
1629*4882a593Smuzhiyun {
1630*4882a593Smuzhiyun 	return (void *)br + sizeof(*br) + c->key_len;
1631*4882a593Smuzhiyun }
1632*4882a593Smuzhiyun 
1633*4882a593Smuzhiyun /**
1634*4882a593Smuzhiyun  * ubifs_copy_hash - copy a hash
1635*4882a593Smuzhiyun  * @c: UBIFS file-system description object
1636*4882a593Smuzhiyun  * @from: source hash
1637*4882a593Smuzhiyun  * @to: destination hash
1638*4882a593Smuzhiyun  *
1639*4882a593Smuzhiyun  * With authentication this copies a hash, otherwise does nothing.
1640*4882a593Smuzhiyun  */
ubifs_copy_hash(const struct ubifs_info * c,const u8 * from,u8 * to)1641*4882a593Smuzhiyun static inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from,
1642*4882a593Smuzhiyun 				   u8 *to)
1643*4882a593Smuzhiyun {
1644*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1645*4882a593Smuzhiyun 		memcpy(to, from, c->hash_len);
1646*4882a593Smuzhiyun }
1647*4882a593Smuzhiyun 
1648*4882a593Smuzhiyun int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1649*4882a593Smuzhiyun 			      int len, int ofs_hmac);
ubifs_node_insert_hmac(const struct ubifs_info * c,void * buf,int len,int ofs_hmac)1650*4882a593Smuzhiyun static inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1651*4882a593Smuzhiyun 					  int len, int ofs_hmac)
1652*4882a593Smuzhiyun {
1653*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1654*4882a593Smuzhiyun 		return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
1655*4882a593Smuzhiyun 	else
1656*4882a593Smuzhiyun 		return 0;
1657*4882a593Smuzhiyun }
1658*4882a593Smuzhiyun 
1659*4882a593Smuzhiyun int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
1660*4882a593Smuzhiyun 			     int len, int ofs_hmac);
ubifs_node_verify_hmac(const struct ubifs_info * c,const void * buf,int len,int ofs_hmac)1661*4882a593Smuzhiyun static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
1662*4882a593Smuzhiyun 					 const void *buf, int len, int ofs_hmac)
1663*4882a593Smuzhiyun {
1664*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1665*4882a593Smuzhiyun 		return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
1666*4882a593Smuzhiyun 	else
1667*4882a593Smuzhiyun 		return 0;
1668*4882a593Smuzhiyun }
1669*4882a593Smuzhiyun 
1670*4882a593Smuzhiyun /**
1671*4882a593Smuzhiyun  * ubifs_auth_node_sz - returns the size of an authentication node
1672*4882a593Smuzhiyun  * @c: UBIFS file-system description object
1673*4882a593Smuzhiyun  *
1674*4882a593Smuzhiyun  * This function returns the size of an authentication node which can
1675*4882a593Smuzhiyun  * be 0 for unauthenticated filesystems or the real size of an auth node
1676*4882a593Smuzhiyun  * authentication is enabled.
1677*4882a593Smuzhiyun  */
ubifs_auth_node_sz(const struct ubifs_info * c)1678*4882a593Smuzhiyun static inline int ubifs_auth_node_sz(const struct ubifs_info *c)
1679*4882a593Smuzhiyun {
1680*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1681*4882a593Smuzhiyun 		return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
1682*4882a593Smuzhiyun 	else
1683*4882a593Smuzhiyun 		return 0;
1684*4882a593Smuzhiyun }
1685*4882a593Smuzhiyun int ubifs_sb_verify_signature(struct ubifs_info *c,
1686*4882a593Smuzhiyun 			      const struct ubifs_sb_node *sup);
1687*4882a593Smuzhiyun bool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac);
1688*4882a593Smuzhiyun 
1689*4882a593Smuzhiyun int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac);
1690*4882a593Smuzhiyun 
1691*4882a593Smuzhiyun int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
1692*4882a593Smuzhiyun 			     struct shash_desc *target);
ubifs_shash_copy_state(const struct ubifs_info * c,struct shash_desc * src,struct shash_desc * target)1693*4882a593Smuzhiyun static inline int ubifs_shash_copy_state(const struct ubifs_info *c,
1694*4882a593Smuzhiyun 					   struct shash_desc *src,
1695*4882a593Smuzhiyun 					   struct shash_desc *target)
1696*4882a593Smuzhiyun {
1697*4882a593Smuzhiyun 	if (ubifs_authenticated(c))
1698*4882a593Smuzhiyun 		return __ubifs_shash_copy_state(c, src, target);
1699*4882a593Smuzhiyun 	else
1700*4882a593Smuzhiyun 		return 0;
1701*4882a593Smuzhiyun }
1702*4882a593Smuzhiyun 
1703*4882a593Smuzhiyun /* io.c */
1704*4882a593Smuzhiyun void ubifs_ro_mode(struct ubifs_info *c, int err);
1705*4882a593Smuzhiyun int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
1706*4882a593Smuzhiyun 		   int len, int even_ebadmsg);
1707*4882a593Smuzhiyun int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
1708*4882a593Smuzhiyun 		    int len);
1709*4882a593Smuzhiyun int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
1710*4882a593Smuzhiyun int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
1711*4882a593Smuzhiyun int ubifs_leb_map(struct ubifs_info *c, int lnum);
1712*4882a593Smuzhiyun int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
1713*4882a593Smuzhiyun int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
1714*4882a593Smuzhiyun int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
1715*4882a593Smuzhiyun int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
1716*4882a593Smuzhiyun int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
1717*4882a593Smuzhiyun 		    int lnum, int offs);
1718*4882a593Smuzhiyun int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
1719*4882a593Smuzhiyun 			 int lnum, int offs);
1720*4882a593Smuzhiyun int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
1721*4882a593Smuzhiyun 		     int offs);
1722*4882a593Smuzhiyun int ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
1723*4882a593Smuzhiyun 			  int offs, int hmac_offs);
1724*4882a593Smuzhiyun int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
1725*4882a593Smuzhiyun 		     int offs, int quiet, int must_chk_crc);
1726*4882a593Smuzhiyun void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
1727*4882a593Smuzhiyun void ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
1728*4882a593Smuzhiyun void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
1729*4882a593Smuzhiyun int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
1730*4882a593Smuzhiyun 			    int hmac_offs, int pad);
1731*4882a593Smuzhiyun void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
1732*4882a593Smuzhiyun int ubifs_io_init(struct ubifs_info *c);
1733*4882a593Smuzhiyun void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
1734*4882a593Smuzhiyun int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
1735*4882a593Smuzhiyun int ubifs_bg_wbufs_sync(struct ubifs_info *c);
1736*4882a593Smuzhiyun void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
1737*4882a593Smuzhiyun int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
1738*4882a593Smuzhiyun 
1739*4882a593Smuzhiyun /* scan.c */
1740*4882a593Smuzhiyun struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
1741*4882a593Smuzhiyun 				  int offs, void *sbuf, int quiet);
1742*4882a593Smuzhiyun void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
1743*4882a593Smuzhiyun int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
1744*4882a593Smuzhiyun 		      int offs, int quiet);
1745*4882a593Smuzhiyun struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
1746*4882a593Smuzhiyun 					int offs, void *sbuf);
1747*4882a593Smuzhiyun void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1748*4882a593Smuzhiyun 		    int lnum, int offs);
1749*4882a593Smuzhiyun int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1750*4882a593Smuzhiyun 		   void *buf, int offs);
1751*4882a593Smuzhiyun void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
1752*4882a593Smuzhiyun 			      void *buf);
1753*4882a593Smuzhiyun 
1754*4882a593Smuzhiyun /* log.c */
1755*4882a593Smuzhiyun void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
1756*4882a593Smuzhiyun void ubifs_create_buds_lists(struct ubifs_info *c);
1757*4882a593Smuzhiyun int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
1758*4882a593Smuzhiyun struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
1759*4882a593Smuzhiyun struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
1760*4882a593Smuzhiyun int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
1761*4882a593Smuzhiyun int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
1762*4882a593Smuzhiyun int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
1763*4882a593Smuzhiyun int ubifs_consolidate_log(struct ubifs_info *c);
1764*4882a593Smuzhiyun 
1765*4882a593Smuzhiyun /* journal.c */
1766*4882a593Smuzhiyun int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
1767*4882a593Smuzhiyun 		     const struct fscrypt_name *nm, const struct inode *inode,
1768*4882a593Smuzhiyun 		     int deletion, int xent);
1769*4882a593Smuzhiyun int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
1770*4882a593Smuzhiyun 			 const union ubifs_key *key, const void *buf, int len);
1771*4882a593Smuzhiyun int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
1772*4882a593Smuzhiyun int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
1773*4882a593Smuzhiyun int ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
1774*4882a593Smuzhiyun 		      const struct inode *fst_inode,
1775*4882a593Smuzhiyun 		      const struct fscrypt_name *fst_nm,
1776*4882a593Smuzhiyun 		      const struct inode *snd_dir,
1777*4882a593Smuzhiyun 		      const struct inode *snd_inode,
1778*4882a593Smuzhiyun 		      const struct fscrypt_name *snd_nm, int sync);
1779*4882a593Smuzhiyun int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
1780*4882a593Smuzhiyun 		     const struct inode *old_inode,
1781*4882a593Smuzhiyun 		     const struct fscrypt_name *old_nm,
1782*4882a593Smuzhiyun 		     const struct inode *new_dir,
1783*4882a593Smuzhiyun 		     const struct inode *new_inode,
1784*4882a593Smuzhiyun 		     const struct fscrypt_name *new_nm,
1785*4882a593Smuzhiyun 		     const struct inode *whiteout, int sync);
1786*4882a593Smuzhiyun int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1787*4882a593Smuzhiyun 		       loff_t old_size, loff_t new_size);
1788*4882a593Smuzhiyun int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
1789*4882a593Smuzhiyun 			   const struct inode *inode, const struct fscrypt_name *nm);
1790*4882a593Smuzhiyun int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
1791*4882a593Smuzhiyun 			   const struct inode *inode2);
1792*4882a593Smuzhiyun 
1793*4882a593Smuzhiyun /* budget.c */
1794*4882a593Smuzhiyun int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
1795*4882a593Smuzhiyun void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
1796*4882a593Smuzhiyun void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
1797*4882a593Smuzhiyun 				      struct ubifs_inode *ui);
1798*4882a593Smuzhiyun int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
1799*4882a593Smuzhiyun 			  struct ubifs_budget_req *req);
1800*4882a593Smuzhiyun void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
1801*4882a593Smuzhiyun 				struct ubifs_budget_req *req);
1802*4882a593Smuzhiyun void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1803*4882a593Smuzhiyun 			 struct ubifs_budget_req *req);
1804*4882a593Smuzhiyun long long ubifs_get_free_space(struct ubifs_info *c);
1805*4882a593Smuzhiyun long long ubifs_get_free_space_nolock(struct ubifs_info *c);
1806*4882a593Smuzhiyun int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1807*4882a593Smuzhiyun void ubifs_convert_page_budget(struct ubifs_info *c);
1808*4882a593Smuzhiyun long long ubifs_reported_space(const struct ubifs_info *c, long long free);
1809*4882a593Smuzhiyun long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1810*4882a593Smuzhiyun 
1811*4882a593Smuzhiyun /* find.c */
1812*4882a593Smuzhiyun int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
1813*4882a593Smuzhiyun 			  int squeeze);
1814*4882a593Smuzhiyun int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
1815*4882a593Smuzhiyun int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
1816*4882a593Smuzhiyun 			 int min_space, int pick_free);
1817*4882a593Smuzhiyun int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
1818*4882a593Smuzhiyun int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
1819*4882a593Smuzhiyun 
1820*4882a593Smuzhiyun /* tnc.c */
1821*4882a593Smuzhiyun int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
1822*4882a593Smuzhiyun 			struct ubifs_znode **zn, int *n);
1823*4882a593Smuzhiyun int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
1824*4882a593Smuzhiyun 			void *node, const struct fscrypt_name *nm);
1825*4882a593Smuzhiyun int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
1826*4882a593Smuzhiyun 			void *node, uint32_t secondary_hash);
1827*4882a593Smuzhiyun int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
1828*4882a593Smuzhiyun 		     void *node, int *lnum, int *offs);
1829*4882a593Smuzhiyun int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
1830*4882a593Smuzhiyun 		  int offs, int len, const u8 *hash);
1831*4882a593Smuzhiyun int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
1832*4882a593Smuzhiyun 		      int old_lnum, int old_offs, int lnum, int offs, int len);
1833*4882a593Smuzhiyun int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
1834*4882a593Smuzhiyun 		     int lnum, int offs, int len, const u8 *hash,
1835*4882a593Smuzhiyun 		     const struct fscrypt_name *nm);
1836*4882a593Smuzhiyun int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
1837*4882a593Smuzhiyun int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
1838*4882a593Smuzhiyun 			const struct fscrypt_name *nm);
1839*4882a593Smuzhiyun int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key,
1840*4882a593Smuzhiyun 			uint32_t cookie);
1841*4882a593Smuzhiyun int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
1842*4882a593Smuzhiyun 			   union ubifs_key *to_key);
1843*4882a593Smuzhiyun int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
1844*4882a593Smuzhiyun struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
1845*4882a593Smuzhiyun 					   union ubifs_key *key,
1846*4882a593Smuzhiyun 					   const struct fscrypt_name *nm);
1847*4882a593Smuzhiyun void ubifs_tnc_close(struct ubifs_info *c);
1848*4882a593Smuzhiyun int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
1849*4882a593Smuzhiyun 		       int lnum, int offs, int is_idx);
1850*4882a593Smuzhiyun int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
1851*4882a593Smuzhiyun 			 int lnum, int offs);
1852*4882a593Smuzhiyun /* Shared by tnc.c for tnc_commit.c */
1853*4882a593Smuzhiyun void destroy_old_idx(struct ubifs_info *c);
1854*4882a593Smuzhiyun int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
1855*4882a593Smuzhiyun 		       int lnum, int offs);
1856*4882a593Smuzhiyun int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
1857*4882a593Smuzhiyun int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
1858*4882a593Smuzhiyun int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
1859*4882a593Smuzhiyun 
1860*4882a593Smuzhiyun /* tnc_misc.c */
1861*4882a593Smuzhiyun struct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c,
1862*4882a593Smuzhiyun 					      struct ubifs_znode *zr,
1863*4882a593Smuzhiyun 					      struct ubifs_znode *znode);
1864*4882a593Smuzhiyun int ubifs_search_zbranch(const struct ubifs_info *c,
1865*4882a593Smuzhiyun 			 const struct ubifs_znode *znode,
1866*4882a593Smuzhiyun 			 const union ubifs_key *key, int *n);
1867*4882a593Smuzhiyun struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
1868*4882a593Smuzhiyun struct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c,
1869*4882a593Smuzhiyun 					     struct ubifs_znode *znode);
1870*4882a593Smuzhiyun long ubifs_destroy_tnc_subtree(const struct ubifs_info *c,
1871*4882a593Smuzhiyun 			       struct ubifs_znode *zr);
1872*4882a593Smuzhiyun struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
1873*4882a593Smuzhiyun 				     struct ubifs_zbranch *zbr,
1874*4882a593Smuzhiyun 				     struct ubifs_znode *parent, int iip);
1875*4882a593Smuzhiyun int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1876*4882a593Smuzhiyun 			void *node);
1877*4882a593Smuzhiyun 
1878*4882a593Smuzhiyun /* tnc_commit.c */
1879*4882a593Smuzhiyun int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
1880*4882a593Smuzhiyun int ubifs_tnc_end_commit(struct ubifs_info *c);
1881*4882a593Smuzhiyun 
1882*4882a593Smuzhiyun /* shrinker.c */
1883*4882a593Smuzhiyun unsigned long ubifs_shrink_scan(struct shrinker *shrink,
1884*4882a593Smuzhiyun 				struct shrink_control *sc);
1885*4882a593Smuzhiyun unsigned long ubifs_shrink_count(struct shrinker *shrink,
1886*4882a593Smuzhiyun 				 struct shrink_control *sc);
1887*4882a593Smuzhiyun 
1888*4882a593Smuzhiyun /* commit.c */
1889*4882a593Smuzhiyun int ubifs_bg_thread(void *info);
1890*4882a593Smuzhiyun void ubifs_commit_required(struct ubifs_info *c);
1891*4882a593Smuzhiyun void ubifs_request_bg_commit(struct ubifs_info *c);
1892*4882a593Smuzhiyun int ubifs_run_commit(struct ubifs_info *c);
1893*4882a593Smuzhiyun void ubifs_recovery_commit(struct ubifs_info *c);
1894*4882a593Smuzhiyun int ubifs_gc_should_commit(struct ubifs_info *c);
1895*4882a593Smuzhiyun void ubifs_wait_for_commit(struct ubifs_info *c);
1896*4882a593Smuzhiyun 
1897*4882a593Smuzhiyun /* master.c */
1898*4882a593Smuzhiyun int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2);
1899*4882a593Smuzhiyun int ubifs_read_master(struct ubifs_info *c);
1900*4882a593Smuzhiyun int ubifs_write_master(struct ubifs_info *c);
1901*4882a593Smuzhiyun 
1902*4882a593Smuzhiyun /* sb.c */
1903*4882a593Smuzhiyun int ubifs_read_superblock(struct ubifs_info *c);
1904*4882a593Smuzhiyun int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
1905*4882a593Smuzhiyun int ubifs_fixup_free_space(struct ubifs_info *c);
1906*4882a593Smuzhiyun int ubifs_enable_encryption(struct ubifs_info *c);
1907*4882a593Smuzhiyun 
1908*4882a593Smuzhiyun /* replay.c */
1909*4882a593Smuzhiyun int ubifs_validate_entry(struct ubifs_info *c,
1910*4882a593Smuzhiyun 			 const struct ubifs_dent_node *dent);
1911*4882a593Smuzhiyun int ubifs_replay_journal(struct ubifs_info *c);
1912*4882a593Smuzhiyun 
1913*4882a593Smuzhiyun /* gc.c */
1914*4882a593Smuzhiyun int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
1915*4882a593Smuzhiyun int ubifs_gc_start_commit(struct ubifs_info *c);
1916*4882a593Smuzhiyun int ubifs_gc_end_commit(struct ubifs_info *c);
1917*4882a593Smuzhiyun void ubifs_destroy_idx_gc(struct ubifs_info *c);
1918*4882a593Smuzhiyun int ubifs_get_idx_gc_leb(struct ubifs_info *c);
1919*4882a593Smuzhiyun int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
1920*4882a593Smuzhiyun 
1921*4882a593Smuzhiyun /* orphan.c */
1922*4882a593Smuzhiyun int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
1923*4882a593Smuzhiyun void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
1924*4882a593Smuzhiyun int ubifs_orphan_start_commit(struct ubifs_info *c);
1925*4882a593Smuzhiyun int ubifs_orphan_end_commit(struct ubifs_info *c);
1926*4882a593Smuzhiyun int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
1927*4882a593Smuzhiyun int ubifs_clear_orphans(struct ubifs_info *c);
1928*4882a593Smuzhiyun 
1929*4882a593Smuzhiyun /* lpt.c */
1930*4882a593Smuzhiyun int ubifs_calc_lpt_geom(struct ubifs_info *c);
1931*4882a593Smuzhiyun int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
1932*4882a593Smuzhiyun 			  int *lpt_lebs, int *big_lpt, u8 *hash);
1933*4882a593Smuzhiyun int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
1934*4882a593Smuzhiyun struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
1935*4882a593Smuzhiyun struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
1936*4882a593Smuzhiyun int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
1937*4882a593Smuzhiyun 			  ubifs_lpt_scan_callback scan_cb, void *data);
1938*4882a593Smuzhiyun 
1939*4882a593Smuzhiyun /* Shared by lpt.c for lpt_commit.c */
1940*4882a593Smuzhiyun void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
1941*4882a593Smuzhiyun void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
1942*4882a593Smuzhiyun 		     struct ubifs_lpt_lprops *ltab);
1943*4882a593Smuzhiyun void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
1944*4882a593Smuzhiyun 		      struct ubifs_pnode *pnode);
1945*4882a593Smuzhiyun void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
1946*4882a593Smuzhiyun 		      struct ubifs_nnode *nnode);
1947*4882a593Smuzhiyun struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
1948*4882a593Smuzhiyun 				    struct ubifs_nnode *parent, int iip);
1949*4882a593Smuzhiyun struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
1950*4882a593Smuzhiyun 				    struct ubifs_nnode *parent, int iip);
1951*4882a593Smuzhiyun struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i);
1952*4882a593Smuzhiyun int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
1953*4882a593Smuzhiyun void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
1954*4882a593Smuzhiyun void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
1955*4882a593Smuzhiyun uint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits);
1956*4882a593Smuzhiyun struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
1957*4882a593Smuzhiyun /* Needed only in debugging code in lpt_commit.c */
1958*4882a593Smuzhiyun int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1959*4882a593Smuzhiyun 		       struct ubifs_nnode *nnode);
1960*4882a593Smuzhiyun int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash);
1961*4882a593Smuzhiyun 
1962*4882a593Smuzhiyun /* lpt_commit.c */
1963*4882a593Smuzhiyun int ubifs_lpt_start_commit(struct ubifs_info *c);
1964*4882a593Smuzhiyun int ubifs_lpt_end_commit(struct ubifs_info *c);
1965*4882a593Smuzhiyun int ubifs_lpt_post_commit(struct ubifs_info *c);
1966*4882a593Smuzhiyun void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
1967*4882a593Smuzhiyun 
1968*4882a593Smuzhiyun /* lprops.c */
1969*4882a593Smuzhiyun const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
1970*4882a593Smuzhiyun 					   const struct ubifs_lprops *lp,
1971*4882a593Smuzhiyun 					   int free, int dirty, int flags,
1972*4882a593Smuzhiyun 					   int idx_gc_cnt);
1973*4882a593Smuzhiyun void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
1974*4882a593Smuzhiyun void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
1975*4882a593Smuzhiyun 		      int cat);
1976*4882a593Smuzhiyun void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
1977*4882a593Smuzhiyun 		       struct ubifs_lprops *new_lprops);
1978*4882a593Smuzhiyun void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
1979*4882a593Smuzhiyun int ubifs_categorize_lprops(const struct ubifs_info *c,
1980*4882a593Smuzhiyun 			    const struct ubifs_lprops *lprops);
1981*4882a593Smuzhiyun int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1982*4882a593Smuzhiyun 			int flags_set, int flags_clean, int idx_gc_cnt);
1983*4882a593Smuzhiyun int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1984*4882a593Smuzhiyun 			int flags_set, int flags_clean);
1985*4882a593Smuzhiyun int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
1986*4882a593Smuzhiyun const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
1987*4882a593Smuzhiyun const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
1988*4882a593Smuzhiyun const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
1989*4882a593Smuzhiyun const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
1990*4882a593Smuzhiyun int ubifs_calc_dark(const struct ubifs_info *c, int spc);
1991*4882a593Smuzhiyun 
1992*4882a593Smuzhiyun /* file.c */
1993*4882a593Smuzhiyun int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
1994*4882a593Smuzhiyun int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
1995*4882a593Smuzhiyun int ubifs_update_time(struct inode *inode, struct timespec64 *time, int flags);
1996*4882a593Smuzhiyun 
1997*4882a593Smuzhiyun /* dir.c */
1998*4882a593Smuzhiyun struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
1999*4882a593Smuzhiyun 			      umode_t mode);
2000*4882a593Smuzhiyun int ubifs_getattr(const struct path *path, struct kstat *stat,
2001*4882a593Smuzhiyun 		  u32 request_mask, unsigned int flags);
2002*4882a593Smuzhiyun int ubifs_check_dir_empty(struct inode *dir);
2003*4882a593Smuzhiyun 
2004*4882a593Smuzhiyun /* xattr.c */
2005*4882a593Smuzhiyun extern const struct xattr_handler *ubifs_xattr_handlers[];
2006*4882a593Smuzhiyun ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
2007*4882a593Smuzhiyun int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
2008*4882a593Smuzhiyun 		    size_t size, int flags, bool check_lock);
2009*4882a593Smuzhiyun ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
2010*4882a593Smuzhiyun 			size_t size);
2011*4882a593Smuzhiyun 
2012*4882a593Smuzhiyun #ifdef CONFIG_UBIFS_FS_XATTR
2013*4882a593Smuzhiyun void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
2014*4882a593Smuzhiyun int ubifs_purge_xattrs(struct inode *host);
2015*4882a593Smuzhiyun #else
ubifs_evict_xattr_inode(struct ubifs_info * c,ino_t xattr_inum)2016*4882a593Smuzhiyun static inline void ubifs_evict_xattr_inode(struct ubifs_info *c,
2017*4882a593Smuzhiyun 					   ino_t xattr_inum) { }
ubifs_purge_xattrs(struct inode * host)2018*4882a593Smuzhiyun static inline int ubifs_purge_xattrs(struct inode *host)
2019*4882a593Smuzhiyun {
2020*4882a593Smuzhiyun 	return 0;
2021*4882a593Smuzhiyun }
2022*4882a593Smuzhiyun #endif
2023*4882a593Smuzhiyun 
2024*4882a593Smuzhiyun #ifdef CONFIG_UBIFS_FS_SECURITY
2025*4882a593Smuzhiyun extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
2026*4882a593Smuzhiyun 			const struct qstr *qstr);
2027*4882a593Smuzhiyun #else
ubifs_init_security(struct inode * dentry,struct inode * inode,const struct qstr * qstr)2028*4882a593Smuzhiyun static inline int ubifs_init_security(struct inode *dentry,
2029*4882a593Smuzhiyun 			struct inode *inode, const struct qstr *qstr)
2030*4882a593Smuzhiyun {
2031*4882a593Smuzhiyun 	return 0;
2032*4882a593Smuzhiyun }
2033*4882a593Smuzhiyun #endif
2034*4882a593Smuzhiyun 
2035*4882a593Smuzhiyun 
2036*4882a593Smuzhiyun /* super.c */
2037*4882a593Smuzhiyun struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
2038*4882a593Smuzhiyun 
2039*4882a593Smuzhiyun /* recovery.c */
2040*4882a593Smuzhiyun int ubifs_recover_master_node(struct ubifs_info *c);
2041*4882a593Smuzhiyun int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
2042*4882a593Smuzhiyun struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
2043*4882a593Smuzhiyun 					 int offs, void *sbuf, int jhead);
2044*4882a593Smuzhiyun struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
2045*4882a593Smuzhiyun 					     int offs, void *sbuf);
2046*4882a593Smuzhiyun int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
2047*4882a593Smuzhiyun int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
2048*4882a593Smuzhiyun int ubifs_rcvry_gc_commit(struct ubifs_info *c);
2049*4882a593Smuzhiyun int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
2050*4882a593Smuzhiyun 			     int deletion, loff_t new_size);
2051*4882a593Smuzhiyun int ubifs_recover_size(struct ubifs_info *c, bool in_place);
2052*4882a593Smuzhiyun void ubifs_destroy_size_tree(struct ubifs_info *c);
2053*4882a593Smuzhiyun 
2054*4882a593Smuzhiyun /* ioctl.c */
2055*4882a593Smuzhiyun long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2056*4882a593Smuzhiyun void ubifs_set_inode_flags(struct inode *inode);
2057*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
2058*4882a593Smuzhiyun long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2059*4882a593Smuzhiyun #endif
2060*4882a593Smuzhiyun 
2061*4882a593Smuzhiyun /* compressor.c */
2062*4882a593Smuzhiyun int __init ubifs_compressors_init(void);
2063*4882a593Smuzhiyun void ubifs_compressors_exit(void);
2064*4882a593Smuzhiyun void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
2065*4882a593Smuzhiyun 		    void *out_buf, int *out_len, int *compr_type);
2066*4882a593Smuzhiyun int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
2067*4882a593Smuzhiyun 		     void *out, int *out_len, int compr_type);
2068*4882a593Smuzhiyun 
2069*4882a593Smuzhiyun #include "debug.h"
2070*4882a593Smuzhiyun #include "misc.h"
2071*4882a593Smuzhiyun #include "key.h"
2072*4882a593Smuzhiyun 
2073*4882a593Smuzhiyun #ifndef CONFIG_FS_ENCRYPTION
ubifs_encrypt(const struct inode * inode,struct ubifs_data_node * dn,unsigned int in_len,unsigned int * out_len,int block)2074*4882a593Smuzhiyun static inline int ubifs_encrypt(const struct inode *inode,
2075*4882a593Smuzhiyun 				struct ubifs_data_node *dn,
2076*4882a593Smuzhiyun 				unsigned int in_len, unsigned int *out_len,
2077*4882a593Smuzhiyun 				int block)
2078*4882a593Smuzhiyun {
2079*4882a593Smuzhiyun 	struct ubifs_info *c = inode->i_sb->s_fs_info;
2080*4882a593Smuzhiyun 	ubifs_assert(c, 0);
2081*4882a593Smuzhiyun 	return -EOPNOTSUPP;
2082*4882a593Smuzhiyun }
ubifs_decrypt(const struct inode * inode,struct ubifs_data_node * dn,unsigned int * out_len,int block)2083*4882a593Smuzhiyun static inline int ubifs_decrypt(const struct inode *inode,
2084*4882a593Smuzhiyun 				struct ubifs_data_node *dn,
2085*4882a593Smuzhiyun 				unsigned int *out_len, int block)
2086*4882a593Smuzhiyun {
2087*4882a593Smuzhiyun 	struct ubifs_info *c = inode->i_sb->s_fs_info;
2088*4882a593Smuzhiyun 	ubifs_assert(c, 0);
2089*4882a593Smuzhiyun 	return -EOPNOTSUPP;
2090*4882a593Smuzhiyun }
2091*4882a593Smuzhiyun #else
2092*4882a593Smuzhiyun /* crypto.c */
2093*4882a593Smuzhiyun int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
2094*4882a593Smuzhiyun 		  unsigned int in_len, unsigned int *out_len, int block);
2095*4882a593Smuzhiyun int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
2096*4882a593Smuzhiyun 		  unsigned int *out_len, int block);
2097*4882a593Smuzhiyun #endif
2098*4882a593Smuzhiyun 
2099*4882a593Smuzhiyun extern const struct fscrypt_operations ubifs_crypt_operations;
2100*4882a593Smuzhiyun 
2101*4882a593Smuzhiyun /* Normal UBIFS messages */
2102*4882a593Smuzhiyun __printf(2, 3)
2103*4882a593Smuzhiyun void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
2104*4882a593Smuzhiyun __printf(2, 3)
2105*4882a593Smuzhiyun void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
2106*4882a593Smuzhiyun __printf(2, 3)
2107*4882a593Smuzhiyun void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
2108*4882a593Smuzhiyun /*
2109*4882a593Smuzhiyun  * A conditional variant of 'ubifs_err()' which doesn't output anything
2110*4882a593Smuzhiyun  * if probing (ie. SB_SILENT set).
2111*4882a593Smuzhiyun  */
2112*4882a593Smuzhiyun #define ubifs_errc(c, fmt, ...)						\
2113*4882a593Smuzhiyun do {									\
2114*4882a593Smuzhiyun 	if (!(c)->probing)						\
2115*4882a593Smuzhiyun 		ubifs_err(c, fmt, ##__VA_ARGS__);			\
2116*4882a593Smuzhiyun } while (0)
2117*4882a593Smuzhiyun 
2118*4882a593Smuzhiyun #endif /* !__UBIFS_H__ */
2119