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