18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file is part of UBIFS.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2006-2008 Nokia Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors: Artem Bityutskiy (Битюцкий Артём)
88c2ecf20Sopenharmony_ci *          Adrian Hunter
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __UBIFS_H__
128c2ecf20Sopenharmony_ci#define __UBIFS_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <asm/div64.h>
158c2ecf20Sopenharmony_ci#include <linux/statfs.h>
168c2ecf20Sopenharmony_ci#include <linux/fs.h>
178c2ecf20Sopenharmony_ci#include <linux/err.h>
188c2ecf20Sopenharmony_ci#include <linux/sched.h>
198c2ecf20Sopenharmony_ci#include <linux/slab.h>
208c2ecf20Sopenharmony_ci#include <linux/vmalloc.h>
218c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
228c2ecf20Sopenharmony_ci#include <linux/mutex.h>
238c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
248c2ecf20Sopenharmony_ci#include <linux/mtd/ubi.h>
258c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
268c2ecf20Sopenharmony_ci#include <linux/backing-dev.h>
278c2ecf20Sopenharmony_ci#include <linux/security.h>
288c2ecf20Sopenharmony_ci#include <linux/xattr.h>
298c2ecf20Sopenharmony_ci#include <linux/random.h>
308c2ecf20Sopenharmony_ci#include <crypto/hash_info.h>
318c2ecf20Sopenharmony_ci#include <crypto/hash.h>
328c2ecf20Sopenharmony_ci#include <crypto/algapi.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/fscrypt.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include "ubifs-media.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* Version of this UBIFS implementation */
398c2ecf20Sopenharmony_ci#define UBIFS_VERSION 1
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* UBIFS file system VFS magic number */
428c2ecf20Sopenharmony_ci#define UBIFS_SUPER_MAGIC 0x24051905
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* Number of UBIFS blocks per VFS page */
458c2ecf20Sopenharmony_ci#define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE)
468c2ecf20Sopenharmony_ci#define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* "File system end of life" sequence number watermark */
498c2ecf20Sopenharmony_ci#define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
508c2ecf20Sopenharmony_ci#define SQNUM_WATERMARK      0xFFFFFFFFFF000000ULL
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/*
538c2ecf20Sopenharmony_ci * Minimum amount of LEBs reserved for the index. At present the index needs at
548c2ecf20Sopenharmony_ci * least 2 LEBs: one for the index head and one for in-the-gaps method (which
558c2ecf20Sopenharmony_ci * currently does not cater for the index head and so excludes it from
568c2ecf20Sopenharmony_ci * consideration).
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_ci#define MIN_INDEX_LEBS 2
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Minimum amount of data UBIFS writes to the flash */
618c2ecf20Sopenharmony_ci#define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/*
648c2ecf20Sopenharmony_ci * Currently we do not support inode number overlapping and re-using, so this
658c2ecf20Sopenharmony_ci * watermark defines dangerous inode number level. This should be fixed later,
668c2ecf20Sopenharmony_ci * although it is difficult to exceed current limit. Another option is to use
678c2ecf20Sopenharmony_ci * 64-bit inode numbers, but this means more overhead.
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_ci#define INUM_WARN_WATERMARK 0xFFF00000
708c2ecf20Sopenharmony_ci#define INUM_WATERMARK      0xFFFFFF00
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Maximum number of entries in each LPT (LEB category) heap */
738c2ecf20Sopenharmony_ci#define LPT_HEAP_SZ 256
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/*
768c2ecf20Sopenharmony_ci * Background thread name pattern. The numbers are UBI device and volume
778c2ecf20Sopenharmony_ci * numbers.
788c2ecf20Sopenharmony_ci */
798c2ecf20Sopenharmony_ci#define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* Maximum possible inode number (only 32-bit inodes are supported now) */
828c2ecf20Sopenharmony_ci#define MAX_INUM 0xFFFFFFFF
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* Number of non-data journal heads */
858c2ecf20Sopenharmony_ci#define NONDATA_JHEADS_CNT 2
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* Shorter names for journal head numbers for internal usage */
888c2ecf20Sopenharmony_ci#define GCHD   UBIFS_GC_HEAD
898c2ecf20Sopenharmony_ci#define BASEHD UBIFS_BASE_HEAD
908c2ecf20Sopenharmony_ci#define DATAHD UBIFS_DATA_HEAD
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* 'No change' value for 'ubifs_change_lp()' */
938c2ecf20Sopenharmony_ci#define LPROPS_NC 0x80000001
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/*
968c2ecf20Sopenharmony_ci * There is no notion of truncation key because truncation nodes do not exist
978c2ecf20Sopenharmony_ci * in TNC. However, when replaying, it is handy to introduce fake "truncation"
988c2ecf20Sopenharmony_ci * keys for truncation nodes because the code becomes simpler. So we define
998c2ecf20Sopenharmony_ci * %UBIFS_TRUN_KEY type.
1008c2ecf20Sopenharmony_ci *
1018c2ecf20Sopenharmony_ci * But otherwise, out of the journal reply scope, the truncation keys are
1028c2ecf20Sopenharmony_ci * invalid.
1038c2ecf20Sopenharmony_ci */
1048c2ecf20Sopenharmony_ci#define UBIFS_TRUN_KEY    UBIFS_KEY_TYPES_CNT
1058c2ecf20Sopenharmony_ci#define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/*
1088c2ecf20Sopenharmony_ci * How much a directory entry/extended attribute entry adds to the parent/host
1098c2ecf20Sopenharmony_ci * inode.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_ci#define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* How much an extended attribute adds to the host inode */
1148c2ecf20Sopenharmony_ci#define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ci * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered
1188c2ecf20Sopenharmony_ci * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are
1198c2ecf20Sopenharmony_ci * considered "young". This is used by shrinker when selecting znode to trim
1208c2ecf20Sopenharmony_ci * off.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define OLD_ZNODE_AGE 20
1238c2ecf20Sopenharmony_ci#define YOUNG_ZNODE_AGE 5
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/*
1268c2ecf20Sopenharmony_ci * Some compressors, like LZO, may end up with more data then the input buffer.
1278c2ecf20Sopenharmony_ci * So UBIFS always allocates larger output buffer, to be sure the compressor
1288c2ecf20Sopenharmony_ci * will not corrupt memory in case of worst case compression.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ci#define WORST_COMPR_FACTOR 2
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION
1338c2ecf20Sopenharmony_ci#define UBIFS_CIPHER_BLOCK_SIZE FS_CRYPTO_BLOCK_SIZE
1348c2ecf20Sopenharmony_ci#else
1358c2ecf20Sopenharmony_ci#define UBIFS_CIPHER_BLOCK_SIZE 0
1368c2ecf20Sopenharmony_ci#endif
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/*
1398c2ecf20Sopenharmony_ci * How much memory is needed for a buffer where we compress a data node.
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_ci#define COMPRESSED_DATA_NODE_BUF_SZ \
1428c2ecf20Sopenharmony_ci	(UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/* Maximum expected tree height for use by bottom_up_buf */
1458c2ecf20Sopenharmony_ci#define BOTTOM_UP_HEIGHT 64
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* Maximum number of data nodes to bulk-read */
1488c2ecf20Sopenharmony_ci#define UBIFS_MAX_BULK_READ 32
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_AUTHENTICATION
1518c2ecf20Sopenharmony_ci#define UBIFS_HASH_ARR_SZ UBIFS_MAX_HASH_LEN
1528c2ecf20Sopenharmony_ci#define UBIFS_HMAC_ARR_SZ UBIFS_MAX_HMAC_LEN
1538c2ecf20Sopenharmony_ci#else
1548c2ecf20Sopenharmony_ci#define UBIFS_HASH_ARR_SZ 0
1558c2ecf20Sopenharmony_ci#define UBIFS_HMAC_ARR_SZ 0
1568c2ecf20Sopenharmony_ci#endif
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/*
1598c2ecf20Sopenharmony_ci * Lockdep classes for UBIFS inode @ui_mutex.
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_cienum {
1628c2ecf20Sopenharmony_ci	WB_MUTEX_1 = 0,
1638c2ecf20Sopenharmony_ci	WB_MUTEX_2 = 1,
1648c2ecf20Sopenharmony_ci	WB_MUTEX_3 = 2,
1658c2ecf20Sopenharmony_ci	WB_MUTEX_4 = 3,
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/*
1698c2ecf20Sopenharmony_ci * Znode flags (actually, bit numbers which store the flags).
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci * DIRTY_ZNODE: znode is dirty
1728c2ecf20Sopenharmony_ci * COW_ZNODE: znode is being committed and a new instance of this znode has to
1738c2ecf20Sopenharmony_ci *            be created before changing this znode
1748c2ecf20Sopenharmony_ci * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is
1758c2ecf20Sopenharmony_ci *                 still in the commit list and the ongoing commit operation
1768c2ecf20Sopenharmony_ci *                 will commit it, and delete this znode after it is done
1778c2ecf20Sopenharmony_ci */
1788c2ecf20Sopenharmony_cienum {
1798c2ecf20Sopenharmony_ci	DIRTY_ZNODE    = 0,
1808c2ecf20Sopenharmony_ci	COW_ZNODE      = 1,
1818c2ecf20Sopenharmony_ci	OBSOLETE_ZNODE = 2,
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/*
1858c2ecf20Sopenharmony_ci * Commit states.
1868c2ecf20Sopenharmony_ci *
1878c2ecf20Sopenharmony_ci * COMMIT_RESTING: commit is not wanted
1888c2ecf20Sopenharmony_ci * COMMIT_BACKGROUND: background commit has been requested
1898c2ecf20Sopenharmony_ci * COMMIT_REQUIRED: commit is required
1908c2ecf20Sopenharmony_ci * COMMIT_RUNNING_BACKGROUND: background commit is running
1918c2ecf20Sopenharmony_ci * COMMIT_RUNNING_REQUIRED: commit is running and it is required
1928c2ecf20Sopenharmony_ci * COMMIT_BROKEN: commit failed
1938c2ecf20Sopenharmony_ci */
1948c2ecf20Sopenharmony_cienum {
1958c2ecf20Sopenharmony_ci	COMMIT_RESTING = 0,
1968c2ecf20Sopenharmony_ci	COMMIT_BACKGROUND,
1978c2ecf20Sopenharmony_ci	COMMIT_REQUIRED,
1988c2ecf20Sopenharmony_ci	COMMIT_RUNNING_BACKGROUND,
1998c2ecf20Sopenharmony_ci	COMMIT_RUNNING_REQUIRED,
2008c2ecf20Sopenharmony_ci	COMMIT_BROKEN,
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/*
2048c2ecf20Sopenharmony_ci * 'ubifs_scan_a_node()' return values.
2058c2ecf20Sopenharmony_ci *
2068c2ecf20Sopenharmony_ci * SCANNED_GARBAGE:  scanned garbage
2078c2ecf20Sopenharmony_ci * SCANNED_EMPTY_SPACE: scanned empty space
2088c2ecf20Sopenharmony_ci * SCANNED_A_NODE: scanned a valid node
2098c2ecf20Sopenharmony_ci * SCANNED_A_CORRUPT_NODE: scanned a corrupted node
2108c2ecf20Sopenharmony_ci * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length
2118c2ecf20Sopenharmony_ci *
2128c2ecf20Sopenharmony_ci * Greater than zero means: 'scanned that number of padding bytes'
2138c2ecf20Sopenharmony_ci */
2148c2ecf20Sopenharmony_cienum {
2158c2ecf20Sopenharmony_ci	SCANNED_GARBAGE        = 0,
2168c2ecf20Sopenharmony_ci	SCANNED_EMPTY_SPACE    = -1,
2178c2ecf20Sopenharmony_ci	SCANNED_A_NODE         = -2,
2188c2ecf20Sopenharmony_ci	SCANNED_A_CORRUPT_NODE = -3,
2198c2ecf20Sopenharmony_ci	SCANNED_A_BAD_PAD_NODE = -4,
2208c2ecf20Sopenharmony_ci};
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/*
2238c2ecf20Sopenharmony_ci * LPT cnode flag bits.
2248c2ecf20Sopenharmony_ci *
2258c2ecf20Sopenharmony_ci * DIRTY_CNODE: cnode is dirty
2268c2ecf20Sopenharmony_ci * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted),
2278c2ecf20Sopenharmony_ci *                 so it can (and must) be freed when the commit is finished
2288c2ecf20Sopenharmony_ci * COW_CNODE: cnode is being committed and must be copied before writing
2298c2ecf20Sopenharmony_ci */
2308c2ecf20Sopenharmony_cienum {
2318c2ecf20Sopenharmony_ci	DIRTY_CNODE    = 0,
2328c2ecf20Sopenharmony_ci	OBSOLETE_CNODE = 1,
2338c2ecf20Sopenharmony_ci	COW_CNODE      = 2,
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci/*
2378c2ecf20Sopenharmony_ci * Dirty flag bits (lpt_drty_flgs) for LPT special nodes.
2388c2ecf20Sopenharmony_ci *
2398c2ecf20Sopenharmony_ci * LTAB_DIRTY: ltab node is dirty
2408c2ecf20Sopenharmony_ci * LSAVE_DIRTY: lsave node is dirty
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_cienum {
2438c2ecf20Sopenharmony_ci	LTAB_DIRTY  = 1,
2448c2ecf20Sopenharmony_ci	LSAVE_DIRTY = 2,
2458c2ecf20Sopenharmony_ci};
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/*
2488c2ecf20Sopenharmony_ci * Return codes used by the garbage collector.
2498c2ecf20Sopenharmony_ci * @LEB_FREED: the logical eraseblock was freed and is ready to use
2508c2ecf20Sopenharmony_ci * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit
2518c2ecf20Sopenharmony_ci * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes
2528c2ecf20Sopenharmony_ci */
2538c2ecf20Sopenharmony_cienum {
2548c2ecf20Sopenharmony_ci	LEB_FREED,
2558c2ecf20Sopenharmony_ci	LEB_FREED_IDX,
2568c2ecf20Sopenharmony_ci	LEB_RETAINED,
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/*
2608c2ecf20Sopenharmony_ci * Action taken upon a failed ubifs_assert().
2618c2ecf20Sopenharmony_ci * @ASSACT_REPORT: just report the failed assertion
2628c2ecf20Sopenharmony_ci * @ASSACT_RO: switch to read-only mode
2638c2ecf20Sopenharmony_ci * @ASSACT_PANIC: call BUG() and possible panic the kernel
2648c2ecf20Sopenharmony_ci */
2658c2ecf20Sopenharmony_cienum {
2668c2ecf20Sopenharmony_ci	ASSACT_REPORT = 0,
2678c2ecf20Sopenharmony_ci	ASSACT_RO,
2688c2ecf20Sopenharmony_ci	ASSACT_PANIC,
2698c2ecf20Sopenharmony_ci};
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci/**
2728c2ecf20Sopenharmony_ci * struct ubifs_old_idx - index node obsoleted since last commit start.
2738c2ecf20Sopenharmony_ci * @rb: rb-tree node
2748c2ecf20Sopenharmony_ci * @lnum: LEB number of obsoleted index node
2758c2ecf20Sopenharmony_ci * @offs: offset of obsoleted index node
2768c2ecf20Sopenharmony_ci */
2778c2ecf20Sopenharmony_cistruct ubifs_old_idx {
2788c2ecf20Sopenharmony_ci	struct rb_node rb;
2798c2ecf20Sopenharmony_ci	int lnum;
2808c2ecf20Sopenharmony_ci	int offs;
2818c2ecf20Sopenharmony_ci};
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/* The below union makes it easier to deal with keys */
2848c2ecf20Sopenharmony_ciunion ubifs_key {
2858c2ecf20Sopenharmony_ci	uint8_t u8[UBIFS_SK_LEN];
2868c2ecf20Sopenharmony_ci	uint32_t u32[UBIFS_SK_LEN/4];
2878c2ecf20Sopenharmony_ci	uint64_t u64[UBIFS_SK_LEN/8];
2888c2ecf20Sopenharmony_ci	__le32 j32[UBIFS_SK_LEN/4];
2898c2ecf20Sopenharmony_ci};
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/**
2928c2ecf20Sopenharmony_ci * struct ubifs_scan_node - UBIFS scanned node information.
2938c2ecf20Sopenharmony_ci * @list: list of scanned nodes
2948c2ecf20Sopenharmony_ci * @key: key of node scanned (if it has one)
2958c2ecf20Sopenharmony_ci * @sqnum: sequence number
2968c2ecf20Sopenharmony_ci * @type: type of node scanned
2978c2ecf20Sopenharmony_ci * @offs: offset with LEB of node scanned
2988c2ecf20Sopenharmony_ci * @len: length of node scanned
2998c2ecf20Sopenharmony_ci * @node: raw node
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_cistruct ubifs_scan_node {
3028c2ecf20Sopenharmony_ci	struct list_head list;
3038c2ecf20Sopenharmony_ci	union ubifs_key key;
3048c2ecf20Sopenharmony_ci	unsigned long long sqnum;
3058c2ecf20Sopenharmony_ci	int type;
3068c2ecf20Sopenharmony_ci	int offs;
3078c2ecf20Sopenharmony_ci	int len;
3088c2ecf20Sopenharmony_ci	void *node;
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci/**
3128c2ecf20Sopenharmony_ci * struct ubifs_scan_leb - UBIFS scanned LEB information.
3138c2ecf20Sopenharmony_ci * @lnum: logical eraseblock number
3148c2ecf20Sopenharmony_ci * @nodes_cnt: number of nodes scanned
3158c2ecf20Sopenharmony_ci * @nodes: list of struct ubifs_scan_node
3168c2ecf20Sopenharmony_ci * @endpt: end point (and therefore the start of empty space)
3178c2ecf20Sopenharmony_ci * @buf: buffer containing entire LEB scanned
3188c2ecf20Sopenharmony_ci */
3198c2ecf20Sopenharmony_cistruct ubifs_scan_leb {
3208c2ecf20Sopenharmony_ci	int lnum;
3218c2ecf20Sopenharmony_ci	int nodes_cnt;
3228c2ecf20Sopenharmony_ci	struct list_head nodes;
3238c2ecf20Sopenharmony_ci	int endpt;
3248c2ecf20Sopenharmony_ci	void *buf;
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/**
3288c2ecf20Sopenharmony_ci * struct ubifs_gced_idx_leb - garbage-collected indexing LEB.
3298c2ecf20Sopenharmony_ci * @list: list
3308c2ecf20Sopenharmony_ci * @lnum: LEB number
3318c2ecf20Sopenharmony_ci * @unmap: OK to unmap this LEB
3328c2ecf20Sopenharmony_ci *
3338c2ecf20Sopenharmony_ci * This data structure is used to temporary store garbage-collected indexing
3348c2ecf20Sopenharmony_ci * LEBs - they are not released immediately, but only after the next commit.
3358c2ecf20Sopenharmony_ci * This is needed to guarantee recoverability.
3368c2ecf20Sopenharmony_ci */
3378c2ecf20Sopenharmony_cistruct ubifs_gced_idx_leb {
3388c2ecf20Sopenharmony_ci	struct list_head list;
3398c2ecf20Sopenharmony_ci	int lnum;
3408c2ecf20Sopenharmony_ci	int unmap;
3418c2ecf20Sopenharmony_ci};
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/**
3448c2ecf20Sopenharmony_ci * struct ubifs_inode - UBIFS in-memory inode description.
3458c2ecf20Sopenharmony_ci * @vfs_inode: VFS inode description object
3468c2ecf20Sopenharmony_ci * @creat_sqnum: sequence number at time of creation
3478c2ecf20Sopenharmony_ci * @del_cmtno: commit number corresponding to the time the inode was deleted,
3488c2ecf20Sopenharmony_ci *             protected by @c->commit_sem;
3498c2ecf20Sopenharmony_ci * @xattr_size: summarized size of all extended attributes in bytes
3508c2ecf20Sopenharmony_ci * @xattr_cnt: count of extended attributes this inode has
3518c2ecf20Sopenharmony_ci * @xattr_names: sum of lengths of all extended attribute names belonging to
3528c2ecf20Sopenharmony_ci *               this inode
3538c2ecf20Sopenharmony_ci * @dirty: non-zero if the inode is dirty
3548c2ecf20Sopenharmony_ci * @xattr: non-zero if this is an extended attribute inode
3558c2ecf20Sopenharmony_ci * @bulk_read: non-zero if bulk-read should be used
3568c2ecf20Sopenharmony_ci * @ui_mutex: serializes inode write-back with the rest of VFS operations,
3578c2ecf20Sopenharmony_ci *            serializes "clean <-> dirty" state changes, serializes bulk-read,
3588c2ecf20Sopenharmony_ci *            protects @dirty, @bulk_read, @ui_size, and @xattr_size
3598c2ecf20Sopenharmony_ci * @xattr_sem: serilizes write operations (remove|set|create) on xattr
3608c2ecf20Sopenharmony_ci * @ui_lock: protects @synced_i_size
3618c2ecf20Sopenharmony_ci * @synced_i_size: synchronized size of inode, i.e. the value of inode size
3628c2ecf20Sopenharmony_ci *                 currently stored on the flash; used only for regular file
3638c2ecf20Sopenharmony_ci *                 inodes
3648c2ecf20Sopenharmony_ci * @ui_size: inode size used by UBIFS when writing to flash
3658c2ecf20Sopenharmony_ci * @flags: inode flags (@UBIFS_COMPR_FL, etc)
3668c2ecf20Sopenharmony_ci * @compr_type: default compression type used for this inode
3678c2ecf20Sopenharmony_ci * @last_page_read: page number of last page read (for bulk read)
3688c2ecf20Sopenharmony_ci * @read_in_a_row: number of consecutive pages read in a row (for bulk read)
3698c2ecf20Sopenharmony_ci * @data_len: length of the data attached to the inode
3708c2ecf20Sopenharmony_ci * @data: inode's data
3718c2ecf20Sopenharmony_ci *
3728c2ecf20Sopenharmony_ci * @ui_mutex exists for two main reasons. At first it prevents inodes from
3738c2ecf20Sopenharmony_ci * being written back while UBIFS changing them, being in the middle of an VFS
3748c2ecf20Sopenharmony_ci * operation. This way UBIFS makes sure the inode fields are consistent. For
3758c2ecf20Sopenharmony_ci * example, in 'ubifs_rename()' we change 4 inodes simultaneously, and
3768c2ecf20Sopenharmony_ci * write-back must not write any of them before we have finished.
3778c2ecf20Sopenharmony_ci *
3788c2ecf20Sopenharmony_ci * The second reason is budgeting - UBIFS has to budget all operations. If an
3798c2ecf20Sopenharmony_ci * operation is going to mark an inode dirty, it has to allocate budget for
3808c2ecf20Sopenharmony_ci * this. It cannot just mark it dirty because there is no guarantee there will
3818c2ecf20Sopenharmony_ci * be enough flash space to write the inode back later. This means UBIFS has
3828c2ecf20Sopenharmony_ci * to have full control over inode "clean <-> dirty" transitions (and pages
3838c2ecf20Sopenharmony_ci * actually). But unfortunately, VFS marks inodes dirty in many places, and it
3848c2ecf20Sopenharmony_ci * does not ask the file-system if it is allowed to do so (there is a notifier,
3858c2ecf20Sopenharmony_ci * but it is not enough), i.e., there is no mechanism to synchronize with this.
3868c2ecf20Sopenharmony_ci * So UBIFS has its own inode dirty flag and its own mutex to serialize
3878c2ecf20Sopenharmony_ci * "clean <-> dirty" transitions.
3888c2ecf20Sopenharmony_ci *
3898c2ecf20Sopenharmony_ci * The @synced_i_size field is used to make sure we never write pages which are
3908c2ecf20Sopenharmony_ci * beyond last synchronized inode size. See 'ubifs_writepage()' for more
3918c2ecf20Sopenharmony_ci * information.
3928c2ecf20Sopenharmony_ci *
3938c2ecf20Sopenharmony_ci * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
3948c2ecf20Sopenharmony_ci * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
3958c2ecf20Sopenharmony_ci * make sure @inode->i_size is always changed under @ui_mutex, because it
3968c2ecf20Sopenharmony_ci * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
3978c2ecf20Sopenharmony_ci * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
3988c2ecf20Sopenharmony_ci * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one
3998c2ecf20Sopenharmony_ci * could consider to rework locking and base it on "shadow" fields.
4008c2ecf20Sopenharmony_ci */
4018c2ecf20Sopenharmony_cistruct ubifs_inode {
4028c2ecf20Sopenharmony_ci	struct inode vfs_inode;
4038c2ecf20Sopenharmony_ci	unsigned long long creat_sqnum;
4048c2ecf20Sopenharmony_ci	unsigned long long del_cmtno;
4058c2ecf20Sopenharmony_ci	unsigned int xattr_size;
4068c2ecf20Sopenharmony_ci	unsigned int xattr_cnt;
4078c2ecf20Sopenharmony_ci	unsigned int xattr_names;
4088c2ecf20Sopenharmony_ci	unsigned int dirty:1;
4098c2ecf20Sopenharmony_ci	unsigned int xattr:1;
4108c2ecf20Sopenharmony_ci	unsigned int bulk_read:1;
4118c2ecf20Sopenharmony_ci	unsigned int compr_type:2;
4128c2ecf20Sopenharmony_ci	struct mutex ui_mutex;
4138c2ecf20Sopenharmony_ci	struct rw_semaphore xattr_sem;
4148c2ecf20Sopenharmony_ci	spinlock_t ui_lock;
4158c2ecf20Sopenharmony_ci	loff_t synced_i_size;
4168c2ecf20Sopenharmony_ci	loff_t ui_size;
4178c2ecf20Sopenharmony_ci	int flags;
4188c2ecf20Sopenharmony_ci	pgoff_t last_page_read;
4198c2ecf20Sopenharmony_ci	pgoff_t read_in_a_row;
4208c2ecf20Sopenharmony_ci	int data_len;
4218c2ecf20Sopenharmony_ci	void *data;
4228c2ecf20Sopenharmony_ci};
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci/**
4258c2ecf20Sopenharmony_ci * struct ubifs_unclean_leb - records a LEB recovered under read-only mode.
4268c2ecf20Sopenharmony_ci * @list: list
4278c2ecf20Sopenharmony_ci * @lnum: LEB number of recovered LEB
4288c2ecf20Sopenharmony_ci * @endpt: offset where recovery ended
4298c2ecf20Sopenharmony_ci *
4308c2ecf20Sopenharmony_ci * This structure records a LEB identified during recovery that needs to be
4318c2ecf20Sopenharmony_ci * cleaned but was not because UBIFS was mounted read-only. The information
4328c2ecf20Sopenharmony_ci * is used to clean the LEB when remounting to read-write mode.
4338c2ecf20Sopenharmony_ci */
4348c2ecf20Sopenharmony_cistruct ubifs_unclean_leb {
4358c2ecf20Sopenharmony_ci	struct list_head list;
4368c2ecf20Sopenharmony_ci	int lnum;
4378c2ecf20Sopenharmony_ci	int endpt;
4388c2ecf20Sopenharmony_ci};
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci/*
4418c2ecf20Sopenharmony_ci * LEB properties flags.
4428c2ecf20Sopenharmony_ci *
4438c2ecf20Sopenharmony_ci * LPROPS_UNCAT: not categorized
4448c2ecf20Sopenharmony_ci * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index
4458c2ecf20Sopenharmony_ci * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index
4468c2ecf20Sopenharmony_ci * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index
4478c2ecf20Sopenharmony_ci * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs
4488c2ecf20Sopenharmony_ci * LPROPS_EMPTY: LEB is empty, not taken
4498c2ecf20Sopenharmony_ci * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken
4508c2ecf20Sopenharmony_ci * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken
4518c2ecf20Sopenharmony_ci * LPROPS_CAT_MASK: mask for the LEB categories above
4528c2ecf20Sopenharmony_ci * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media)
4538c2ecf20Sopenharmony_ci * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash)
4548c2ecf20Sopenharmony_ci */
4558c2ecf20Sopenharmony_cienum {
4568c2ecf20Sopenharmony_ci	LPROPS_UNCAT     =  0,
4578c2ecf20Sopenharmony_ci	LPROPS_DIRTY     =  1,
4588c2ecf20Sopenharmony_ci	LPROPS_DIRTY_IDX =  2,
4598c2ecf20Sopenharmony_ci	LPROPS_FREE      =  3,
4608c2ecf20Sopenharmony_ci	LPROPS_HEAP_CNT  =  3,
4618c2ecf20Sopenharmony_ci	LPROPS_EMPTY     =  4,
4628c2ecf20Sopenharmony_ci	LPROPS_FREEABLE  =  5,
4638c2ecf20Sopenharmony_ci	LPROPS_FRDI_IDX  =  6,
4648c2ecf20Sopenharmony_ci	LPROPS_CAT_MASK  = 15,
4658c2ecf20Sopenharmony_ci	LPROPS_TAKEN     = 16,
4668c2ecf20Sopenharmony_ci	LPROPS_INDEX     = 32,
4678c2ecf20Sopenharmony_ci};
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci/**
4708c2ecf20Sopenharmony_ci * struct ubifs_lprops - logical eraseblock properties.
4718c2ecf20Sopenharmony_ci * @free: amount of free space in bytes
4728c2ecf20Sopenharmony_ci * @dirty: amount of dirty space in bytes
4738c2ecf20Sopenharmony_ci * @flags: LEB properties flags (see above)
4748c2ecf20Sopenharmony_ci * @lnum: LEB number
4758c2ecf20Sopenharmony_ci * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE)
4768c2ecf20Sopenharmony_ci * @hpos: heap position in heap of same-category lprops (other categories)
4778c2ecf20Sopenharmony_ci */
4788c2ecf20Sopenharmony_cistruct ubifs_lprops {
4798c2ecf20Sopenharmony_ci	int free;
4808c2ecf20Sopenharmony_ci	int dirty;
4818c2ecf20Sopenharmony_ci	int flags;
4828c2ecf20Sopenharmony_ci	int lnum;
4838c2ecf20Sopenharmony_ci	union {
4848c2ecf20Sopenharmony_ci		struct list_head list;
4858c2ecf20Sopenharmony_ci		int hpos;
4868c2ecf20Sopenharmony_ci	};
4878c2ecf20Sopenharmony_ci};
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci/**
4908c2ecf20Sopenharmony_ci * struct ubifs_lpt_lprops - LPT logical eraseblock properties.
4918c2ecf20Sopenharmony_ci * @free: amount of free space in bytes
4928c2ecf20Sopenharmony_ci * @dirty: amount of dirty space in bytes
4938c2ecf20Sopenharmony_ci * @tgc: trivial GC flag (1 => unmap after commit end)
4948c2ecf20Sopenharmony_ci * @cmt: commit flag (1 => reserved for commit)
4958c2ecf20Sopenharmony_ci */
4968c2ecf20Sopenharmony_cistruct ubifs_lpt_lprops {
4978c2ecf20Sopenharmony_ci	int free;
4988c2ecf20Sopenharmony_ci	int dirty;
4998c2ecf20Sopenharmony_ci	unsigned tgc:1;
5008c2ecf20Sopenharmony_ci	unsigned cmt:1;
5018c2ecf20Sopenharmony_ci};
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci/**
5048c2ecf20Sopenharmony_ci * struct ubifs_lp_stats - statistics of eraseblocks in the main area.
5058c2ecf20Sopenharmony_ci * @empty_lebs: number of empty LEBs
5068c2ecf20Sopenharmony_ci * @taken_empty_lebs: number of taken LEBs
5078c2ecf20Sopenharmony_ci * @idx_lebs: number of indexing LEBs
5088c2ecf20Sopenharmony_ci * @total_free: total free space in bytes (includes all LEBs)
5098c2ecf20Sopenharmony_ci * @total_dirty: total dirty space in bytes (includes all LEBs)
5108c2ecf20Sopenharmony_ci * @total_used: total used space in bytes (does not include index LEBs)
5118c2ecf20Sopenharmony_ci * @total_dead: total dead space in bytes (does not include index LEBs)
5128c2ecf20Sopenharmony_ci * @total_dark: total dark space in bytes (does not include index LEBs)
5138c2ecf20Sopenharmony_ci *
5148c2ecf20Sopenharmony_ci * The @taken_empty_lebs field counts the LEBs that are in the transient state
5158c2ecf20Sopenharmony_ci * of having been "taken" for use but not yet written to. @taken_empty_lebs is
5168c2ecf20Sopenharmony_ci * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be
5178c2ecf20Sopenharmony_ci * used by itself (in which case 'unused_lebs' would be a better name). In the
5188c2ecf20Sopenharmony_ci * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained
5198c2ecf20Sopenharmony_ci * by GC, but unlike other empty LEBs that are "taken", it may not be written
5208c2ecf20Sopenharmony_ci * straight away (i.e. before the next commit start or unmount), so either
5218c2ecf20Sopenharmony_ci * @gc_lnum must be specially accounted for, or the current approach followed
5228c2ecf20Sopenharmony_ci * i.e. count it under @taken_empty_lebs.
5238c2ecf20Sopenharmony_ci *
5248c2ecf20Sopenharmony_ci * @empty_lebs includes @taken_empty_lebs.
5258c2ecf20Sopenharmony_ci *
5268c2ecf20Sopenharmony_ci * @total_used, @total_dead and @total_dark fields do not account indexing
5278c2ecf20Sopenharmony_ci * LEBs.
5288c2ecf20Sopenharmony_ci */
5298c2ecf20Sopenharmony_cistruct ubifs_lp_stats {
5308c2ecf20Sopenharmony_ci	int empty_lebs;
5318c2ecf20Sopenharmony_ci	int taken_empty_lebs;
5328c2ecf20Sopenharmony_ci	int idx_lebs;
5338c2ecf20Sopenharmony_ci	long long total_free;
5348c2ecf20Sopenharmony_ci	long long total_dirty;
5358c2ecf20Sopenharmony_ci	long long total_used;
5368c2ecf20Sopenharmony_ci	long long total_dead;
5378c2ecf20Sopenharmony_ci	long long total_dark;
5388c2ecf20Sopenharmony_ci};
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_cistruct ubifs_nnode;
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci/**
5438c2ecf20Sopenharmony_ci * struct ubifs_cnode - LEB Properties Tree common node.
5448c2ecf20Sopenharmony_ci * @parent: parent nnode
5458c2ecf20Sopenharmony_ci * @cnext: next cnode to commit
5468c2ecf20Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
5478c2ecf20Sopenharmony_ci * @iip: index in parent
5488c2ecf20Sopenharmony_ci * @level: level in the tree (zero for pnodes, greater than zero for nnodes)
5498c2ecf20Sopenharmony_ci * @num: node number
5508c2ecf20Sopenharmony_ci */
5518c2ecf20Sopenharmony_cistruct ubifs_cnode {
5528c2ecf20Sopenharmony_ci	struct ubifs_nnode *parent;
5538c2ecf20Sopenharmony_ci	struct ubifs_cnode *cnext;
5548c2ecf20Sopenharmony_ci	unsigned long flags;
5558c2ecf20Sopenharmony_ci	int iip;
5568c2ecf20Sopenharmony_ci	int level;
5578c2ecf20Sopenharmony_ci	int num;
5588c2ecf20Sopenharmony_ci};
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci/**
5618c2ecf20Sopenharmony_ci * struct ubifs_pnode - LEB Properties Tree leaf node.
5628c2ecf20Sopenharmony_ci * @parent: parent nnode
5638c2ecf20Sopenharmony_ci * @cnext: next cnode to commit
5648c2ecf20Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
5658c2ecf20Sopenharmony_ci * @iip: index in parent
5668c2ecf20Sopenharmony_ci * @level: level in the tree (always zero for pnodes)
5678c2ecf20Sopenharmony_ci * @num: node number
5688c2ecf20Sopenharmony_ci * @lprops: LEB properties array
5698c2ecf20Sopenharmony_ci */
5708c2ecf20Sopenharmony_cistruct ubifs_pnode {
5718c2ecf20Sopenharmony_ci	struct ubifs_nnode *parent;
5728c2ecf20Sopenharmony_ci	struct ubifs_cnode *cnext;
5738c2ecf20Sopenharmony_ci	unsigned long flags;
5748c2ecf20Sopenharmony_ci	int iip;
5758c2ecf20Sopenharmony_ci	int level;
5768c2ecf20Sopenharmony_ci	int num;
5778c2ecf20Sopenharmony_ci	struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
5788c2ecf20Sopenharmony_ci};
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci/**
5818c2ecf20Sopenharmony_ci * struct ubifs_nbranch - LEB Properties Tree internal node branch.
5828c2ecf20Sopenharmony_ci * @lnum: LEB number of child
5838c2ecf20Sopenharmony_ci * @offs: offset of child
5848c2ecf20Sopenharmony_ci * @nnode: nnode child
5858c2ecf20Sopenharmony_ci * @pnode: pnode child
5868c2ecf20Sopenharmony_ci * @cnode: cnode child
5878c2ecf20Sopenharmony_ci */
5888c2ecf20Sopenharmony_cistruct ubifs_nbranch {
5898c2ecf20Sopenharmony_ci	int lnum;
5908c2ecf20Sopenharmony_ci	int offs;
5918c2ecf20Sopenharmony_ci	union {
5928c2ecf20Sopenharmony_ci		struct ubifs_nnode *nnode;
5938c2ecf20Sopenharmony_ci		struct ubifs_pnode *pnode;
5948c2ecf20Sopenharmony_ci		struct ubifs_cnode *cnode;
5958c2ecf20Sopenharmony_ci	};
5968c2ecf20Sopenharmony_ci};
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci/**
5998c2ecf20Sopenharmony_ci * struct ubifs_nnode - LEB Properties Tree internal node.
6008c2ecf20Sopenharmony_ci * @parent: parent nnode
6018c2ecf20Sopenharmony_ci * @cnext: next cnode to commit
6028c2ecf20Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
6038c2ecf20Sopenharmony_ci * @iip: index in parent
6048c2ecf20Sopenharmony_ci * @level: level in the tree (always greater than zero for nnodes)
6058c2ecf20Sopenharmony_ci * @num: node number
6068c2ecf20Sopenharmony_ci * @nbranch: branches to child nodes
6078c2ecf20Sopenharmony_ci */
6088c2ecf20Sopenharmony_cistruct ubifs_nnode {
6098c2ecf20Sopenharmony_ci	struct ubifs_nnode *parent;
6108c2ecf20Sopenharmony_ci	struct ubifs_cnode *cnext;
6118c2ecf20Sopenharmony_ci	unsigned long flags;
6128c2ecf20Sopenharmony_ci	int iip;
6138c2ecf20Sopenharmony_ci	int level;
6148c2ecf20Sopenharmony_ci	int num;
6158c2ecf20Sopenharmony_ci	struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
6168c2ecf20Sopenharmony_ci};
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci/**
6198c2ecf20Sopenharmony_ci * struct ubifs_lpt_heap - heap of categorized lprops.
6208c2ecf20Sopenharmony_ci * @arr: heap array
6218c2ecf20Sopenharmony_ci * @cnt: number in heap
6228c2ecf20Sopenharmony_ci * @max_cnt: maximum number allowed in heap
6238c2ecf20Sopenharmony_ci *
6248c2ecf20Sopenharmony_ci * There are %LPROPS_HEAP_CNT heaps.
6258c2ecf20Sopenharmony_ci */
6268c2ecf20Sopenharmony_cistruct ubifs_lpt_heap {
6278c2ecf20Sopenharmony_ci	struct ubifs_lprops **arr;
6288c2ecf20Sopenharmony_ci	int cnt;
6298c2ecf20Sopenharmony_ci	int max_cnt;
6308c2ecf20Sopenharmony_ci};
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci/*
6338c2ecf20Sopenharmony_ci * Return codes for LPT scan callback function.
6348c2ecf20Sopenharmony_ci *
6358c2ecf20Sopenharmony_ci * LPT_SCAN_CONTINUE: continue scanning
6368c2ecf20Sopenharmony_ci * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory
6378c2ecf20Sopenharmony_ci * LPT_SCAN_STOP: stop scanning
6388c2ecf20Sopenharmony_ci */
6398c2ecf20Sopenharmony_cienum {
6408c2ecf20Sopenharmony_ci	LPT_SCAN_CONTINUE = 0,
6418c2ecf20Sopenharmony_ci	LPT_SCAN_ADD = 1,
6428c2ecf20Sopenharmony_ci	LPT_SCAN_STOP = 2,
6438c2ecf20Sopenharmony_ci};
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_cistruct ubifs_info;
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci/* Callback used by the 'ubifs_lpt_scan_nolock()' function */
6488c2ecf20Sopenharmony_citypedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
6498c2ecf20Sopenharmony_ci				       const struct ubifs_lprops *lprops,
6508c2ecf20Sopenharmony_ci				       int in_tree, void *data);
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci/**
6538c2ecf20Sopenharmony_ci * struct ubifs_wbuf - UBIFS write-buffer.
6548c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
6558c2ecf20Sopenharmony_ci * @buf: write-buffer (of min. flash I/O unit size)
6568c2ecf20Sopenharmony_ci * @lnum: logical eraseblock number the write-buffer points to
6578c2ecf20Sopenharmony_ci * @offs: write-buffer offset in this logical eraseblock
6588c2ecf20Sopenharmony_ci * @avail: number of bytes available in the write-buffer
6598c2ecf20Sopenharmony_ci * @used:  number of used bytes in the write-buffer
6608c2ecf20Sopenharmony_ci * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range)
6618c2ecf20Sopenharmony_ci * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
6628c2ecf20Sopenharmony_ci *         up by 'mutex_lock_nested()).
6638c2ecf20Sopenharmony_ci * @sync_callback: write-buffer synchronization callback
6648c2ecf20Sopenharmony_ci * @io_mutex: serializes write-buffer I/O
6658c2ecf20Sopenharmony_ci * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
6668c2ecf20Sopenharmony_ci *        fields
6678c2ecf20Sopenharmony_ci * @timer: write-buffer timer
6688c2ecf20Sopenharmony_ci * @no_timer: non-zero if this write-buffer does not have a timer
6698c2ecf20Sopenharmony_ci * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing
6708c2ecf20Sopenharmony_ci * @next_ino: points to the next position of the following inode number
6718c2ecf20Sopenharmony_ci * @inodes: stores the inode numbers of the nodes which are in wbuf
6728c2ecf20Sopenharmony_ci *
6738c2ecf20Sopenharmony_ci * The write-buffer synchronization callback is called when the write-buffer is
6748c2ecf20Sopenharmony_ci * synchronized in order to notify how much space was wasted due to
6758c2ecf20Sopenharmony_ci * write-buffer padding and how much free space is left in the LEB.
6768c2ecf20Sopenharmony_ci *
6778c2ecf20Sopenharmony_ci * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under
6788c2ecf20Sopenharmony_ci * spin-lock or mutex because they are written under both mutex and spin-lock.
6798c2ecf20Sopenharmony_ci * @buf is appended to under mutex but overwritten under both mutex and
6808c2ecf20Sopenharmony_ci * spin-lock. Thus the data between @buf and @buf + @used can be read under
6818c2ecf20Sopenharmony_ci * spinlock.
6828c2ecf20Sopenharmony_ci */
6838c2ecf20Sopenharmony_cistruct ubifs_wbuf {
6848c2ecf20Sopenharmony_ci	struct ubifs_info *c;
6858c2ecf20Sopenharmony_ci	void *buf;
6868c2ecf20Sopenharmony_ci	int lnum;
6878c2ecf20Sopenharmony_ci	int offs;
6888c2ecf20Sopenharmony_ci	int avail;
6898c2ecf20Sopenharmony_ci	int used;
6908c2ecf20Sopenharmony_ci	int size;
6918c2ecf20Sopenharmony_ci	int jhead;
6928c2ecf20Sopenharmony_ci	int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
6938c2ecf20Sopenharmony_ci	struct mutex io_mutex;
6948c2ecf20Sopenharmony_ci	spinlock_t lock;
6958c2ecf20Sopenharmony_ci	struct hrtimer timer;
6968c2ecf20Sopenharmony_ci	unsigned int no_timer:1;
6978c2ecf20Sopenharmony_ci	unsigned int need_sync:1;
6988c2ecf20Sopenharmony_ci	int next_ino;
6998c2ecf20Sopenharmony_ci	ino_t *inodes;
7008c2ecf20Sopenharmony_ci};
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci/**
7038c2ecf20Sopenharmony_ci * struct ubifs_bud - bud logical eraseblock.
7048c2ecf20Sopenharmony_ci * @lnum: logical eraseblock number
7058c2ecf20Sopenharmony_ci * @start: where the (uncommitted) bud data starts
7068c2ecf20Sopenharmony_ci * @jhead: journal head number this bud belongs to
7078c2ecf20Sopenharmony_ci * @list: link in the list buds belonging to the same journal head
7088c2ecf20Sopenharmony_ci * @rb: link in the tree of all buds
7098c2ecf20Sopenharmony_ci * @log_hash: the log hash from the commit start node up to this bud
7108c2ecf20Sopenharmony_ci */
7118c2ecf20Sopenharmony_cistruct ubifs_bud {
7128c2ecf20Sopenharmony_ci	int lnum;
7138c2ecf20Sopenharmony_ci	int start;
7148c2ecf20Sopenharmony_ci	int jhead;
7158c2ecf20Sopenharmony_ci	struct list_head list;
7168c2ecf20Sopenharmony_ci	struct rb_node rb;
7178c2ecf20Sopenharmony_ci	struct shash_desc *log_hash;
7188c2ecf20Sopenharmony_ci};
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci/**
7218c2ecf20Sopenharmony_ci * struct ubifs_jhead - journal head.
7228c2ecf20Sopenharmony_ci * @wbuf: head's write-buffer
7238c2ecf20Sopenharmony_ci * @buds_list: list of bud LEBs belonging to this journal head
7248c2ecf20Sopenharmony_ci * @grouped: non-zero if UBIFS groups nodes when writing to this journal head
7258c2ecf20Sopenharmony_ci * @log_hash: the log hash from the commit start node up to this journal head
7268c2ecf20Sopenharmony_ci *
7278c2ecf20Sopenharmony_ci * Note, the @buds list is protected by the @c->buds_lock.
7288c2ecf20Sopenharmony_ci */
7298c2ecf20Sopenharmony_cistruct ubifs_jhead {
7308c2ecf20Sopenharmony_ci	struct ubifs_wbuf wbuf;
7318c2ecf20Sopenharmony_ci	struct list_head buds_list;
7328c2ecf20Sopenharmony_ci	unsigned int grouped:1;
7338c2ecf20Sopenharmony_ci	struct shash_desc *log_hash;
7348c2ecf20Sopenharmony_ci};
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci/**
7378c2ecf20Sopenharmony_ci * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
7388c2ecf20Sopenharmony_ci * @key: key
7398c2ecf20Sopenharmony_ci * @znode: znode address in memory
7408c2ecf20Sopenharmony_ci * @lnum: LEB number of the target node (indexing node or data node)
7418c2ecf20Sopenharmony_ci * @offs: target node offset within @lnum
7428c2ecf20Sopenharmony_ci * @len: target node length
7438c2ecf20Sopenharmony_ci * @hash: the hash of the target node
7448c2ecf20Sopenharmony_ci */
7458c2ecf20Sopenharmony_cistruct ubifs_zbranch {
7468c2ecf20Sopenharmony_ci	union ubifs_key key;
7478c2ecf20Sopenharmony_ci	union {
7488c2ecf20Sopenharmony_ci		struct ubifs_znode *znode;
7498c2ecf20Sopenharmony_ci		void *leaf;
7508c2ecf20Sopenharmony_ci	};
7518c2ecf20Sopenharmony_ci	int lnum;
7528c2ecf20Sopenharmony_ci	int offs;
7538c2ecf20Sopenharmony_ci	int len;
7548c2ecf20Sopenharmony_ci	u8 hash[UBIFS_HASH_ARR_SZ];
7558c2ecf20Sopenharmony_ci};
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci/**
7588c2ecf20Sopenharmony_ci * struct ubifs_znode - in-memory representation of an indexing node.
7598c2ecf20Sopenharmony_ci * @parent: parent znode or NULL if it is the root
7608c2ecf20Sopenharmony_ci * @cnext: next znode to commit
7618c2ecf20Sopenharmony_ci * @cparent: parent node for this commit
7628c2ecf20Sopenharmony_ci * @ciip: index in cparent's zbranch array
7638c2ecf20Sopenharmony_ci * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE)
7648c2ecf20Sopenharmony_ci * @time: last access time (seconds)
7658c2ecf20Sopenharmony_ci * @level: level of the entry in the TNC tree
7668c2ecf20Sopenharmony_ci * @child_cnt: count of child znodes
7678c2ecf20Sopenharmony_ci * @iip: index in parent's zbranch array
7688c2ecf20Sopenharmony_ci * @alt: lower bound of key range has altered i.e. child inserted at slot 0
7698c2ecf20Sopenharmony_ci * @lnum: LEB number of the corresponding indexing node
7708c2ecf20Sopenharmony_ci * @offs: offset of the corresponding indexing node
7718c2ecf20Sopenharmony_ci * @len: length  of the corresponding indexing node
7728c2ecf20Sopenharmony_ci * @zbranch: array of znode branches (@c->fanout elements)
7738c2ecf20Sopenharmony_ci *
7748c2ecf20Sopenharmony_ci * Note! The @lnum, @offs, and @len fields are not really needed - we have them
7758c2ecf20Sopenharmony_ci * only for internal consistency check. They could be removed to save some RAM.
7768c2ecf20Sopenharmony_ci */
7778c2ecf20Sopenharmony_cistruct ubifs_znode {
7788c2ecf20Sopenharmony_ci	struct ubifs_znode *parent;
7798c2ecf20Sopenharmony_ci	struct ubifs_znode *cnext;
7808c2ecf20Sopenharmony_ci	struct ubifs_znode *cparent;
7818c2ecf20Sopenharmony_ci	int ciip;
7828c2ecf20Sopenharmony_ci	unsigned long flags;
7838c2ecf20Sopenharmony_ci	time64_t time;
7848c2ecf20Sopenharmony_ci	int level;
7858c2ecf20Sopenharmony_ci	int child_cnt;
7868c2ecf20Sopenharmony_ci	int iip;
7878c2ecf20Sopenharmony_ci	int alt;
7888c2ecf20Sopenharmony_ci	int lnum;
7898c2ecf20Sopenharmony_ci	int offs;
7908c2ecf20Sopenharmony_ci	int len;
7918c2ecf20Sopenharmony_ci	struct ubifs_zbranch zbranch[];
7928c2ecf20Sopenharmony_ci};
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci/**
7958c2ecf20Sopenharmony_ci * struct bu_info - bulk-read information.
7968c2ecf20Sopenharmony_ci * @key: first data node key
7978c2ecf20Sopenharmony_ci * @zbranch: zbranches of data nodes to bulk read
7988c2ecf20Sopenharmony_ci * @buf: buffer to read into
7998c2ecf20Sopenharmony_ci * @buf_len: buffer length
8008c2ecf20Sopenharmony_ci * @gc_seq: GC sequence number to detect races with GC
8018c2ecf20Sopenharmony_ci * @cnt: number of data nodes for bulk read
8028c2ecf20Sopenharmony_ci * @blk_cnt: number of data blocks including holes
8038c2ecf20Sopenharmony_ci * @oef: end of file reached
8048c2ecf20Sopenharmony_ci */
8058c2ecf20Sopenharmony_cistruct bu_info {
8068c2ecf20Sopenharmony_ci	union ubifs_key key;
8078c2ecf20Sopenharmony_ci	struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
8088c2ecf20Sopenharmony_ci	void *buf;
8098c2ecf20Sopenharmony_ci	int buf_len;
8108c2ecf20Sopenharmony_ci	int gc_seq;
8118c2ecf20Sopenharmony_ci	int cnt;
8128c2ecf20Sopenharmony_ci	int blk_cnt;
8138c2ecf20Sopenharmony_ci	int eof;
8148c2ecf20Sopenharmony_ci};
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/**
8178c2ecf20Sopenharmony_ci * struct ubifs_node_range - node length range description data structure.
8188c2ecf20Sopenharmony_ci * @len: fixed node length
8198c2ecf20Sopenharmony_ci * @min_len: minimum possible node length
8208c2ecf20Sopenharmony_ci * @max_len: maximum possible node length
8218c2ecf20Sopenharmony_ci *
8228c2ecf20Sopenharmony_ci * If @max_len is %0, the node has fixed length @len.
8238c2ecf20Sopenharmony_ci */
8248c2ecf20Sopenharmony_cistruct ubifs_node_range {
8258c2ecf20Sopenharmony_ci	union {
8268c2ecf20Sopenharmony_ci		int len;
8278c2ecf20Sopenharmony_ci		int min_len;
8288c2ecf20Sopenharmony_ci	};
8298c2ecf20Sopenharmony_ci	int max_len;
8308c2ecf20Sopenharmony_ci};
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci/**
8338c2ecf20Sopenharmony_ci * struct ubifs_compressor - UBIFS compressor description structure.
8348c2ecf20Sopenharmony_ci * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc)
8358c2ecf20Sopenharmony_ci * @cc: cryptoapi compressor handle
8368c2ecf20Sopenharmony_ci * @comp_mutex: mutex used during compression
8378c2ecf20Sopenharmony_ci * @decomp_mutex: mutex used during decompression
8388c2ecf20Sopenharmony_ci * @name: compressor name
8398c2ecf20Sopenharmony_ci * @capi_name: cryptoapi compressor name
8408c2ecf20Sopenharmony_ci */
8418c2ecf20Sopenharmony_cistruct ubifs_compressor {
8428c2ecf20Sopenharmony_ci	int compr_type;
8438c2ecf20Sopenharmony_ci	struct crypto_comp *cc;
8448c2ecf20Sopenharmony_ci	struct mutex *comp_mutex;
8458c2ecf20Sopenharmony_ci	struct mutex *decomp_mutex;
8468c2ecf20Sopenharmony_ci	const char *name;
8478c2ecf20Sopenharmony_ci	const char *capi_name;
8488c2ecf20Sopenharmony_ci};
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci/**
8518c2ecf20Sopenharmony_ci * struct ubifs_budget_req - budget requirements of an operation.
8528c2ecf20Sopenharmony_ci *
8538c2ecf20Sopenharmony_ci * @fast: non-zero if the budgeting should try to acquire budget quickly and
8548c2ecf20Sopenharmony_ci *        should not try to call write-back
8558c2ecf20Sopenharmony_ci * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields
8568c2ecf20Sopenharmony_ci *               have to be re-calculated
8578c2ecf20Sopenharmony_ci * @new_page: non-zero if the operation adds a new page
8588c2ecf20Sopenharmony_ci * @dirtied_page: non-zero if the operation makes a page dirty
8598c2ecf20Sopenharmony_ci * @new_dent: non-zero if the operation adds a new directory entry
8608c2ecf20Sopenharmony_ci * @mod_dent: non-zero if the operation removes or modifies an existing
8618c2ecf20Sopenharmony_ci *            directory entry
8628c2ecf20Sopenharmony_ci * @new_ino: non-zero if the operation adds a new inode
8638c2ecf20Sopenharmony_ci * @new_ino_d: how much data newly created inode contains
8648c2ecf20Sopenharmony_ci * @dirtied_ino: how many inodes the operation makes dirty
8658c2ecf20Sopenharmony_ci * @dirtied_ino_d: how much data dirtied inode contains
8668c2ecf20Sopenharmony_ci * @idx_growth: how much the index will supposedly grow
8678c2ecf20Sopenharmony_ci * @data_growth: how much new data the operation will supposedly add
8688c2ecf20Sopenharmony_ci * @dd_growth: how much data that makes other data dirty the operation will
8698c2ecf20Sopenharmony_ci *             supposedly add
8708c2ecf20Sopenharmony_ci *
8718c2ecf20Sopenharmony_ci * @idx_growth, @data_growth and @dd_growth are not used in budget request. The
8728c2ecf20Sopenharmony_ci * budgeting subsystem caches index and data growth values there to avoid
8738c2ecf20Sopenharmony_ci * re-calculating them when the budget is released. However, if @idx_growth is
8748c2ecf20Sopenharmony_ci * %-1, it is calculated by the release function using other fields.
8758c2ecf20Sopenharmony_ci *
8768c2ecf20Sopenharmony_ci * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
8778c2ecf20Sopenharmony_ci * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
8788c2ecf20Sopenharmony_ci * dirty by the re-name operation.
8798c2ecf20Sopenharmony_ci *
8808c2ecf20Sopenharmony_ci * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
8818c2ecf20Sopenharmony_ci * make sure the amount of inode data which contribute to @new_ino_d and
8828c2ecf20Sopenharmony_ci * @dirtied_ino_d fields are aligned.
8838c2ecf20Sopenharmony_ci */
8848c2ecf20Sopenharmony_cistruct ubifs_budget_req {
8858c2ecf20Sopenharmony_ci	unsigned int fast:1;
8868c2ecf20Sopenharmony_ci	unsigned int recalculate:1;
8878c2ecf20Sopenharmony_ci#ifndef UBIFS_DEBUG
8888c2ecf20Sopenharmony_ci	unsigned int new_page:1;
8898c2ecf20Sopenharmony_ci	unsigned int dirtied_page:1;
8908c2ecf20Sopenharmony_ci	unsigned int new_dent:1;
8918c2ecf20Sopenharmony_ci	unsigned int mod_dent:1;
8928c2ecf20Sopenharmony_ci	unsigned int new_ino:1;
8938c2ecf20Sopenharmony_ci	unsigned int new_ino_d:13;
8948c2ecf20Sopenharmony_ci	unsigned int dirtied_ino:4;
8958c2ecf20Sopenharmony_ci	unsigned int dirtied_ino_d:15;
8968c2ecf20Sopenharmony_ci#else
8978c2ecf20Sopenharmony_ci	/* Not bit-fields to check for overflows */
8988c2ecf20Sopenharmony_ci	unsigned int new_page;
8998c2ecf20Sopenharmony_ci	unsigned int dirtied_page;
9008c2ecf20Sopenharmony_ci	unsigned int new_dent;
9018c2ecf20Sopenharmony_ci	unsigned int mod_dent;
9028c2ecf20Sopenharmony_ci	unsigned int new_ino;
9038c2ecf20Sopenharmony_ci	unsigned int new_ino_d;
9048c2ecf20Sopenharmony_ci	unsigned int dirtied_ino;
9058c2ecf20Sopenharmony_ci	unsigned int dirtied_ino_d;
9068c2ecf20Sopenharmony_ci#endif
9078c2ecf20Sopenharmony_ci	int idx_growth;
9088c2ecf20Sopenharmony_ci	int data_growth;
9098c2ecf20Sopenharmony_ci	int dd_growth;
9108c2ecf20Sopenharmony_ci};
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci/**
9138c2ecf20Sopenharmony_ci * struct ubifs_orphan - stores the inode number of an orphan.
9148c2ecf20Sopenharmony_ci * @rb: rb-tree node of rb-tree of orphans sorted by inode number
9158c2ecf20Sopenharmony_ci * @list: list head of list of orphans in order added
9168c2ecf20Sopenharmony_ci * @new_list: list head of list of orphans added since the last commit
9178c2ecf20Sopenharmony_ci * @child_list: list of xattr childs if this orphan hosts xattrs, list head
9188c2ecf20Sopenharmony_ci * if this orphan is a xattr, not used otherwise.
9198c2ecf20Sopenharmony_ci * @cnext: next orphan to commit
9208c2ecf20Sopenharmony_ci * @dnext: next orphan to delete
9218c2ecf20Sopenharmony_ci * @inum: inode number
9228c2ecf20Sopenharmony_ci * @new: %1 => added since the last commit, otherwise %0
9238c2ecf20Sopenharmony_ci * @cmt: %1 => commit pending, otherwise %0
9248c2ecf20Sopenharmony_ci * @del: %1 => delete pending, otherwise %0
9258c2ecf20Sopenharmony_ci */
9268c2ecf20Sopenharmony_cistruct ubifs_orphan {
9278c2ecf20Sopenharmony_ci	struct rb_node rb;
9288c2ecf20Sopenharmony_ci	struct list_head list;
9298c2ecf20Sopenharmony_ci	struct list_head new_list;
9308c2ecf20Sopenharmony_ci	struct list_head child_list;
9318c2ecf20Sopenharmony_ci	struct ubifs_orphan *cnext;
9328c2ecf20Sopenharmony_ci	struct ubifs_orphan *dnext;
9338c2ecf20Sopenharmony_ci	ino_t inum;
9348c2ecf20Sopenharmony_ci	unsigned new:1;
9358c2ecf20Sopenharmony_ci	unsigned cmt:1;
9368c2ecf20Sopenharmony_ci	unsigned del:1;
9378c2ecf20Sopenharmony_ci};
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci/**
9408c2ecf20Sopenharmony_ci * struct ubifs_mount_opts - UBIFS-specific mount options information.
9418c2ecf20Sopenharmony_ci * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
9428c2ecf20Sopenharmony_ci * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable)
9438c2ecf20Sopenharmony_ci * @chk_data_crc: enable/disable CRC data checking when reading data nodes
9448c2ecf20Sopenharmony_ci *                (%0 default, %1 disable, %2 enable)
9458c2ecf20Sopenharmony_ci * @override_compr: override default compressor (%0 - do not override and use
9468c2ecf20Sopenharmony_ci *                  superblock compressor, %1 - override and use compressor
9478c2ecf20Sopenharmony_ci *                  specified in @compr_type)
9488c2ecf20Sopenharmony_ci * @compr_type: compressor type to override the superblock compressor with
9498c2ecf20Sopenharmony_ci *              (%UBIFS_COMPR_NONE, etc)
9508c2ecf20Sopenharmony_ci */
9518c2ecf20Sopenharmony_cistruct ubifs_mount_opts {
9528c2ecf20Sopenharmony_ci	unsigned int unmount_mode:2;
9538c2ecf20Sopenharmony_ci	unsigned int bulk_read:2;
9548c2ecf20Sopenharmony_ci	unsigned int chk_data_crc:2;
9558c2ecf20Sopenharmony_ci	unsigned int override_compr:1;
9568c2ecf20Sopenharmony_ci	unsigned int compr_type:2;
9578c2ecf20Sopenharmony_ci};
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci/**
9608c2ecf20Sopenharmony_ci * struct ubifs_budg_info - UBIFS budgeting information.
9618c2ecf20Sopenharmony_ci * @idx_growth: amount of bytes budgeted for index growth
9628c2ecf20Sopenharmony_ci * @data_growth: amount of bytes budgeted for cached data
9638c2ecf20Sopenharmony_ci * @dd_growth: amount of bytes budgeted for cached data that will make
9648c2ecf20Sopenharmony_ci *             other data dirty
9658c2ecf20Sopenharmony_ci * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but
9668c2ecf20Sopenharmony_ci *                   which still have to be taken into account because the index
9678c2ecf20Sopenharmony_ci *                   has not been committed so far
9688c2ecf20Sopenharmony_ci * @old_idx_sz: size of index on flash
9698c2ecf20Sopenharmony_ci * @min_idx_lebs: minimum number of LEBs required for the index
9708c2ecf20Sopenharmony_ci * @nospace: non-zero if the file-system does not have flash space (used as
9718c2ecf20Sopenharmony_ci *           optimization)
9728c2ecf20Sopenharmony_ci * @nospace_rp: the same as @nospace, but additionally means that even reserved
9738c2ecf20Sopenharmony_ci *              pool is full
9748c2ecf20Sopenharmony_ci * @page_budget: budget for a page (constant, never changed after mount)
9758c2ecf20Sopenharmony_ci * @inode_budget: budget for an inode (constant, never changed after mount)
9768c2ecf20Sopenharmony_ci * @dent_budget: budget for a directory entry (constant, never changed after
9778c2ecf20Sopenharmony_ci *               mount)
9788c2ecf20Sopenharmony_ci */
9798c2ecf20Sopenharmony_cistruct ubifs_budg_info {
9808c2ecf20Sopenharmony_ci	long long idx_growth;
9818c2ecf20Sopenharmony_ci	long long data_growth;
9828c2ecf20Sopenharmony_ci	long long dd_growth;
9838c2ecf20Sopenharmony_ci	long long uncommitted_idx;
9848c2ecf20Sopenharmony_ci	unsigned long long old_idx_sz;
9858c2ecf20Sopenharmony_ci	int min_idx_lebs;
9868c2ecf20Sopenharmony_ci	unsigned int nospace:1;
9878c2ecf20Sopenharmony_ci	unsigned int nospace_rp:1;
9888c2ecf20Sopenharmony_ci	int page_budget;
9898c2ecf20Sopenharmony_ci	int inode_budget;
9908c2ecf20Sopenharmony_ci	int dent_budget;
9918c2ecf20Sopenharmony_ci};
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_cistruct ubifs_debug_info;
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci/**
9968c2ecf20Sopenharmony_ci * struct ubifs_info - UBIFS file-system description data structure
9978c2ecf20Sopenharmony_ci * (per-superblock).
9988c2ecf20Sopenharmony_ci * @vfs_sb: VFS @struct super_block object
9998c2ecf20Sopenharmony_ci * @sup_node: The super block node as read from the device
10008c2ecf20Sopenharmony_ci *
10018c2ecf20Sopenharmony_ci * @highest_inum: highest used inode number
10028c2ecf20Sopenharmony_ci * @max_sqnum: current global sequence number
10038c2ecf20Sopenharmony_ci * @cmt_no: commit number of the last successfully completed commit, protected
10048c2ecf20Sopenharmony_ci *          by @commit_sem
10058c2ecf20Sopenharmony_ci * @cnt_lock: protects @highest_inum and @max_sqnum counters
10068c2ecf20Sopenharmony_ci * @fmt_version: UBIFS on-flash format version
10078c2ecf20Sopenharmony_ci * @ro_compat_version: R/O compatibility version
10088c2ecf20Sopenharmony_ci * @uuid: UUID from super block
10098c2ecf20Sopenharmony_ci *
10108c2ecf20Sopenharmony_ci * @lhead_lnum: log head logical eraseblock number
10118c2ecf20Sopenharmony_ci * @lhead_offs: log head offset
10128c2ecf20Sopenharmony_ci * @ltail_lnum: log tail logical eraseblock number (offset is always 0)
10138c2ecf20Sopenharmony_ci * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and
10148c2ecf20Sopenharmony_ci *             @bud_bytes
10158c2ecf20Sopenharmony_ci * @min_log_bytes: minimum required number of bytes in the log
10168c2ecf20Sopenharmony_ci * @cmt_bud_bytes: used during commit to temporarily amount of bytes in
10178c2ecf20Sopenharmony_ci *                 committed buds
10188c2ecf20Sopenharmony_ci *
10198c2ecf20Sopenharmony_ci * @buds: tree of all buds indexed by bud LEB number
10208c2ecf20Sopenharmony_ci * @bud_bytes: how many bytes of flash is used by buds
10218c2ecf20Sopenharmony_ci * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud
10228c2ecf20Sopenharmony_ci *             lists
10238c2ecf20Sopenharmony_ci * @jhead_cnt: count of journal heads
10248c2ecf20Sopenharmony_ci * @jheads: journal heads (head zero is base head)
10258c2ecf20Sopenharmony_ci * @max_bud_bytes: maximum number of bytes allowed in buds
10268c2ecf20Sopenharmony_ci * @bg_bud_bytes: number of bud bytes when background commit is initiated
10278c2ecf20Sopenharmony_ci * @old_buds: buds to be released after commit ends
10288c2ecf20Sopenharmony_ci * @max_bud_cnt: maximum number of buds
10298c2ecf20Sopenharmony_ci *
10308c2ecf20Sopenharmony_ci * @commit_sem: synchronizes committer with other processes
10318c2ecf20Sopenharmony_ci * @cmt_state: commit state
10328c2ecf20Sopenharmony_ci * @cs_lock: commit state lock
10338c2ecf20Sopenharmony_ci * @cmt_wq: wait queue to sleep on if the log is full and a commit is running
10348c2ecf20Sopenharmony_ci *
10358c2ecf20Sopenharmony_ci * @big_lpt: flag that LPT is too big to write whole during commit
10368c2ecf20Sopenharmony_ci * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up
10378c2ecf20Sopenharmony_ci * @double_hash: flag indicating that we can do lookups by hash
10388c2ecf20Sopenharmony_ci * @encrypted: flag indicating that this file system contains encrypted files
10398c2ecf20Sopenharmony_ci * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
10408c2ecf20Sopenharmony_ci *                   recovery)
10418c2ecf20Sopenharmony_ci * @bulk_read: enable bulk-reads
10428c2ecf20Sopenharmony_ci * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
10438c2ecf20Sopenharmony_ci * @rw_incompat: the media is not R/W compatible
10448c2ecf20Sopenharmony_ci * @assert_action: action to take when a ubifs_assert() fails
10458c2ecf20Sopenharmony_ci * @authenticated: flag indigating the FS is mounted in authenticated mode
10468c2ecf20Sopenharmony_ci *
10478c2ecf20Sopenharmony_ci * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
10488c2ecf20Sopenharmony_ci *             @calc_idx_sz
10498c2ecf20Sopenharmony_ci * @zroot: zbranch which points to the root index node and znode
10508c2ecf20Sopenharmony_ci * @cnext: next znode to commit
10518c2ecf20Sopenharmony_ci * @enext: next znode to commit to empty space
10528c2ecf20Sopenharmony_ci * @gap_lebs: array of LEBs used by the in-gaps commit method
10538c2ecf20Sopenharmony_ci * @cbuf: commit buffer
10548c2ecf20Sopenharmony_ci * @ileb_buf: buffer for commit in-the-gaps method
10558c2ecf20Sopenharmony_ci * @ileb_len: length of data in ileb_buf
10568c2ecf20Sopenharmony_ci * @ihead_lnum: LEB number of index head
10578c2ecf20Sopenharmony_ci * @ihead_offs: offset of index head
10588c2ecf20Sopenharmony_ci * @ilebs: pre-allocated index LEBs
10598c2ecf20Sopenharmony_ci * @ileb_cnt: number of pre-allocated index LEBs
10608c2ecf20Sopenharmony_ci * @ileb_nxt: next pre-allocated index LEBs
10618c2ecf20Sopenharmony_ci * @old_idx: tree of index nodes obsoleted since the last commit start
10628c2ecf20Sopenharmony_ci * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c
10638c2ecf20Sopenharmony_ci *
10648c2ecf20Sopenharmony_ci * @mst_node: master node
10658c2ecf20Sopenharmony_ci * @mst_offs: offset of valid master node
10668c2ecf20Sopenharmony_ci *
10678c2ecf20Sopenharmony_ci * @max_bu_buf_len: maximum bulk-read buffer length
10688c2ecf20Sopenharmony_ci * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu
10698c2ecf20Sopenharmony_ci * @bu: pre-allocated bulk-read information
10708c2ecf20Sopenharmony_ci *
10718c2ecf20Sopenharmony_ci * @write_reserve_mutex: protects @write_reserve_buf
10728c2ecf20Sopenharmony_ci * @write_reserve_buf: on the write path we allocate memory, which might
10738c2ecf20Sopenharmony_ci *                     sometimes be unavailable, in which case we use this
10748c2ecf20Sopenharmony_ci *                     write reserve buffer
10758c2ecf20Sopenharmony_ci *
10768c2ecf20Sopenharmony_ci * @log_lebs: number of logical eraseblocks in the log
10778c2ecf20Sopenharmony_ci * @log_bytes: log size in bytes
10788c2ecf20Sopenharmony_ci * @log_last: last LEB of the log
10798c2ecf20Sopenharmony_ci * @lpt_lebs: number of LEBs used for lprops table
10808c2ecf20Sopenharmony_ci * @lpt_first: first LEB of the lprops table area
10818c2ecf20Sopenharmony_ci * @lpt_last: last LEB of the lprops table area
10828c2ecf20Sopenharmony_ci * @orph_lebs: number of LEBs used for the orphan area
10838c2ecf20Sopenharmony_ci * @orph_first: first LEB of the orphan area
10848c2ecf20Sopenharmony_ci * @orph_last: last LEB of the orphan area
10858c2ecf20Sopenharmony_ci * @main_lebs: count of LEBs in the main area
10868c2ecf20Sopenharmony_ci * @main_first: first LEB of the main area
10878c2ecf20Sopenharmony_ci * @main_bytes: main area size in bytes
10888c2ecf20Sopenharmony_ci *
10898c2ecf20Sopenharmony_ci * @key_hash_type: type of the key hash
10908c2ecf20Sopenharmony_ci * @key_hash: direntry key hash function
10918c2ecf20Sopenharmony_ci * @key_fmt: key format
10928c2ecf20Sopenharmony_ci * @key_len: key length
10938c2ecf20Sopenharmony_ci * @hash_len: The length of the index node hashes
10948c2ecf20Sopenharmony_ci * @fanout: fanout of the index tree (number of links per indexing node)
10958c2ecf20Sopenharmony_ci *
10968c2ecf20Sopenharmony_ci * @min_io_size: minimal input/output unit size
10978c2ecf20Sopenharmony_ci * @min_io_shift: number of bits in @min_io_size minus one
10988c2ecf20Sopenharmony_ci * @max_write_size: maximum amount of bytes the underlying flash can write at a
10998c2ecf20Sopenharmony_ci *                  time (MTD write buffer size)
11008c2ecf20Sopenharmony_ci * @max_write_shift: number of bits in @max_write_size minus one
11018c2ecf20Sopenharmony_ci * @leb_size: logical eraseblock size in bytes
11028c2ecf20Sopenharmony_ci * @leb_start: starting offset of logical eraseblocks within physical
11038c2ecf20Sopenharmony_ci *             eraseblocks
11048c2ecf20Sopenharmony_ci * @half_leb_size: half LEB size
11058c2ecf20Sopenharmony_ci * @idx_leb_size: how many bytes of an LEB are effectively available when it is
11068c2ecf20Sopenharmony_ci *                used to store indexing nodes (@leb_size - @max_idx_node_sz)
11078c2ecf20Sopenharmony_ci * @leb_cnt: count of logical eraseblocks
11088c2ecf20Sopenharmony_ci * @max_leb_cnt: maximum count of logical eraseblocks
11098c2ecf20Sopenharmony_ci * @ro_media: the underlying UBI volume is read-only
11108c2ecf20Sopenharmony_ci * @ro_mount: the file-system was mounted as read-only
11118c2ecf20Sopenharmony_ci * @ro_error: UBIFS switched to R/O mode because an error happened
11128c2ecf20Sopenharmony_ci *
11138c2ecf20Sopenharmony_ci * @dirty_pg_cnt: number of dirty pages (not used)
11148c2ecf20Sopenharmony_ci * @dirty_zn_cnt: number of dirty znodes
11158c2ecf20Sopenharmony_ci * @clean_zn_cnt: number of clean znodes
11168c2ecf20Sopenharmony_ci *
11178c2ecf20Sopenharmony_ci * @space_lock: protects @bi and @lst
11188c2ecf20Sopenharmony_ci * @lst: lprops statistics
11198c2ecf20Sopenharmony_ci * @bi: budgeting information
11208c2ecf20Sopenharmony_ci * @calc_idx_sz: temporary variable which is used to calculate new index size
11218c2ecf20Sopenharmony_ci *               (contains accurate new index size at end of TNC commit start)
11228c2ecf20Sopenharmony_ci *
11238c2ecf20Sopenharmony_ci * @ref_node_alsz: size of the LEB reference node aligned to the min. flash
11248c2ecf20Sopenharmony_ci *                 I/O unit
11258c2ecf20Sopenharmony_ci * @mst_node_alsz: master node aligned size
11268c2ecf20Sopenharmony_ci * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary
11278c2ecf20Sopenharmony_ci * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary
11288c2ecf20Sopenharmony_ci * @max_inode_sz: maximum possible inode size in bytes
11298c2ecf20Sopenharmony_ci * @max_znode_sz: size of znode in bytes
11308c2ecf20Sopenharmony_ci *
11318c2ecf20Sopenharmony_ci * @leb_overhead: how many bytes are wasted in an LEB when it is filled with
11328c2ecf20Sopenharmony_ci *                data nodes of maximum size - used in free space reporting
11338c2ecf20Sopenharmony_ci * @dead_wm: LEB dead space watermark
11348c2ecf20Sopenharmony_ci * @dark_wm: LEB dark space watermark
11358c2ecf20Sopenharmony_ci * @block_cnt: count of 4KiB blocks on the FS
11368c2ecf20Sopenharmony_ci *
11378c2ecf20Sopenharmony_ci * @ranges: UBIFS node length ranges
11388c2ecf20Sopenharmony_ci * @ubi: UBI volume descriptor
11398c2ecf20Sopenharmony_ci * @di: UBI device information
11408c2ecf20Sopenharmony_ci * @vi: UBI volume information
11418c2ecf20Sopenharmony_ci *
11428c2ecf20Sopenharmony_ci * @orph_tree: rb-tree of orphan inode numbers
11438c2ecf20Sopenharmony_ci * @orph_list: list of orphan inode numbers in order added
11448c2ecf20Sopenharmony_ci * @orph_new: list of orphan inode numbers added since last commit
11458c2ecf20Sopenharmony_ci * @orph_cnext: next orphan to commit
11468c2ecf20Sopenharmony_ci * @orph_dnext: next orphan to delete
11478c2ecf20Sopenharmony_ci * @orphan_lock: lock for orph_tree and orph_new
11488c2ecf20Sopenharmony_ci * @orph_buf: buffer for orphan nodes
11498c2ecf20Sopenharmony_ci * @new_orphans: number of orphans since last commit
11508c2ecf20Sopenharmony_ci * @cmt_orphans: number of orphans being committed
11518c2ecf20Sopenharmony_ci * @tot_orphans: number of orphans in the rb_tree
11528c2ecf20Sopenharmony_ci * @max_orphans: maximum number of orphans allowed
11538c2ecf20Sopenharmony_ci * @ohead_lnum: orphan head LEB number
11548c2ecf20Sopenharmony_ci * @ohead_offs: orphan head offset
11558c2ecf20Sopenharmony_ci * @no_orphs: non-zero if there are no orphans
11568c2ecf20Sopenharmony_ci *
11578c2ecf20Sopenharmony_ci * @bgt: UBIFS background thread
11588c2ecf20Sopenharmony_ci * @bgt_name: background thread name
11598c2ecf20Sopenharmony_ci * @need_bgt: if background thread should run
11608c2ecf20Sopenharmony_ci * @need_wbuf_sync: if write-buffers have to be synchronized
11618c2ecf20Sopenharmony_ci *
11628c2ecf20Sopenharmony_ci * @gc_lnum: LEB number used for garbage collection
11638c2ecf20Sopenharmony_ci * @sbuf: a buffer of LEB size used by GC and replay for scanning
11648c2ecf20Sopenharmony_ci * @idx_gc: list of index LEBs that have been garbage collected
11658c2ecf20Sopenharmony_ci * @idx_gc_cnt: number of elements on the idx_gc list
11668c2ecf20Sopenharmony_ci * @gc_seq: incremented for every non-index LEB garbage collected
11678c2ecf20Sopenharmony_ci * @gced_lnum: last non-index LEB that was garbage collected
11688c2ecf20Sopenharmony_ci *
11698c2ecf20Sopenharmony_ci * @infos_list: links all 'ubifs_info' objects
11708c2ecf20Sopenharmony_ci * @umount_mutex: serializes shrinker and un-mount
11718c2ecf20Sopenharmony_ci * @shrinker_run_no: shrinker run number
11728c2ecf20Sopenharmony_ci *
11738c2ecf20Sopenharmony_ci * @space_bits: number of bits needed to record free or dirty space
11748c2ecf20Sopenharmony_ci * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT
11758c2ecf20Sopenharmony_ci * @lpt_offs_bits: number of bits needed to record an offset in the LPT
11768c2ecf20Sopenharmony_ci * @lpt_spc_bits: number of bits needed to space in the LPT
11778c2ecf20Sopenharmony_ci * @pcnt_bits: number of bits needed to record pnode or nnode number
11788c2ecf20Sopenharmony_ci * @lnum_bits: number of bits needed to record LEB number
11798c2ecf20Sopenharmony_ci * @nnode_sz: size of on-flash nnode
11808c2ecf20Sopenharmony_ci * @pnode_sz: size of on-flash pnode
11818c2ecf20Sopenharmony_ci * @ltab_sz: size of on-flash LPT lprops table
11828c2ecf20Sopenharmony_ci * @lsave_sz: size of on-flash LPT save table
11838c2ecf20Sopenharmony_ci * @pnode_cnt: number of pnodes
11848c2ecf20Sopenharmony_ci * @nnode_cnt: number of nnodes
11858c2ecf20Sopenharmony_ci * @lpt_hght: height of the LPT
11868c2ecf20Sopenharmony_ci * @pnodes_have: number of pnodes in memory
11878c2ecf20Sopenharmony_ci *
11888c2ecf20Sopenharmony_ci * @lp_mutex: protects lprops table and all the other lprops-related fields
11898c2ecf20Sopenharmony_ci * @lpt_lnum: LEB number of the root nnode of the LPT
11908c2ecf20Sopenharmony_ci * @lpt_offs: offset of the root nnode of the LPT
11918c2ecf20Sopenharmony_ci * @nhead_lnum: LEB number of LPT head
11928c2ecf20Sopenharmony_ci * @nhead_offs: offset of LPT head
11938c2ecf20Sopenharmony_ci * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab
11948c2ecf20Sopenharmony_ci * @dirty_nn_cnt: number of dirty nnodes
11958c2ecf20Sopenharmony_ci * @dirty_pn_cnt: number of dirty pnodes
11968c2ecf20Sopenharmony_ci * @check_lpt_free: flag that indicates LPT GC may be needed
11978c2ecf20Sopenharmony_ci * @lpt_sz: LPT size
11988c2ecf20Sopenharmony_ci * @lpt_nod_buf: buffer for an on-flash nnode or pnode
11998c2ecf20Sopenharmony_ci * @lpt_buf: buffer of LEB size used by LPT
12008c2ecf20Sopenharmony_ci * @nroot: address in memory of the root nnode of the LPT
12018c2ecf20Sopenharmony_ci * @lpt_cnext: next LPT node to commit
12028c2ecf20Sopenharmony_ci * @lpt_heap: array of heaps of categorized lprops
12038c2ecf20Sopenharmony_ci * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at
12048c2ecf20Sopenharmony_ci *             previous commit start
12058c2ecf20Sopenharmony_ci * @uncat_list: list of un-categorized LEBs
12068c2ecf20Sopenharmony_ci * @empty_list: list of empty LEBs
12078c2ecf20Sopenharmony_ci * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size)
12088c2ecf20Sopenharmony_ci * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size)
12098c2ecf20Sopenharmony_ci * @freeable_cnt: number of freeable LEBs in @freeable_list
12108c2ecf20Sopenharmony_ci * @in_a_category_cnt: count of lprops which are in a certain category, which
12118c2ecf20Sopenharmony_ci *                     basically meants that they were loaded from the flash
12128c2ecf20Sopenharmony_ci *
12138c2ecf20Sopenharmony_ci * @ltab_lnum: LEB number of LPT's own lprops table
12148c2ecf20Sopenharmony_ci * @ltab_offs: offset of LPT's own lprops table
12158c2ecf20Sopenharmony_ci * @ltab: LPT's own lprops table
12168c2ecf20Sopenharmony_ci * @ltab_cmt: LPT's own lprops table (commit copy)
12178c2ecf20Sopenharmony_ci * @lsave_cnt: number of LEB numbers in LPT's save table
12188c2ecf20Sopenharmony_ci * @lsave_lnum: LEB number of LPT's save table
12198c2ecf20Sopenharmony_ci * @lsave_offs: offset of LPT's save table
12208c2ecf20Sopenharmony_ci * @lsave: LPT's save table
12218c2ecf20Sopenharmony_ci * @lscan_lnum: LEB number of last LPT scan
12228c2ecf20Sopenharmony_ci *
12238c2ecf20Sopenharmony_ci * @rp_size: size of the reserved pool in bytes
12248c2ecf20Sopenharmony_ci * @report_rp_size: size of the reserved pool reported to user-space
12258c2ecf20Sopenharmony_ci * @rp_uid: reserved pool user ID
12268c2ecf20Sopenharmony_ci * @rp_gid: reserved pool group ID
12278c2ecf20Sopenharmony_ci *
12288c2ecf20Sopenharmony_ci * @hash_tfm: the hash transformation used for hashing nodes
12298c2ecf20Sopenharmony_ci * @hmac_tfm: the HMAC transformation for this filesystem
12308c2ecf20Sopenharmony_ci * @hmac_desc_len: length of the HMAC used for authentication
12318c2ecf20Sopenharmony_ci * @auth_key_name: the authentication key name
12328c2ecf20Sopenharmony_ci * @auth_hash_name: the name of the hash algorithm used for authentication
12338c2ecf20Sopenharmony_ci * @auth_hash_algo: the authentication hash used for this fs
12348c2ecf20Sopenharmony_ci * @log_hash: the log hash from the commit start node up to the latest reference
12358c2ecf20Sopenharmony_ci *            node.
12368c2ecf20Sopenharmony_ci *
12378c2ecf20Sopenharmony_ci * @empty: %1 if the UBI device is empty
12388c2ecf20Sopenharmony_ci * @need_recovery: %1 if the file-system needs recovery
12398c2ecf20Sopenharmony_ci * @replaying: %1 during journal replay
12408c2ecf20Sopenharmony_ci * @mounting: %1 while mounting
12418c2ecf20Sopenharmony_ci * @probing: %1 while attempting to mount if SB_SILENT mount flag is set
12428c2ecf20Sopenharmony_ci * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode
12438c2ecf20Sopenharmony_ci * @replay_list: temporary list used during journal replay
12448c2ecf20Sopenharmony_ci * @replay_buds: list of buds to replay
12458c2ecf20Sopenharmony_ci * @cs_sqnum: sequence number of first node in the log (commit start node)
12468c2ecf20Sopenharmony_ci * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W
12478c2ecf20Sopenharmony_ci *                    mode
12488c2ecf20Sopenharmony_ci * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted
12498c2ecf20Sopenharmony_ci *                  FS to R/W mode
12508c2ecf20Sopenharmony_ci * @size_tree: inode size information for recovery
12518c2ecf20Sopenharmony_ci * @mount_opts: UBIFS-specific mount options
12528c2ecf20Sopenharmony_ci *
12538c2ecf20Sopenharmony_ci * @dbg: debugging-related information
12548c2ecf20Sopenharmony_ci */
12558c2ecf20Sopenharmony_cistruct ubifs_info {
12568c2ecf20Sopenharmony_ci	struct super_block *vfs_sb;
12578c2ecf20Sopenharmony_ci	struct ubifs_sb_node *sup_node;
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci	ino_t highest_inum;
12608c2ecf20Sopenharmony_ci	unsigned long long max_sqnum;
12618c2ecf20Sopenharmony_ci	unsigned long long cmt_no;
12628c2ecf20Sopenharmony_ci	spinlock_t cnt_lock;
12638c2ecf20Sopenharmony_ci	int fmt_version;
12648c2ecf20Sopenharmony_ci	int ro_compat_version;
12658c2ecf20Sopenharmony_ci	unsigned char uuid[16];
12668c2ecf20Sopenharmony_ci
12678c2ecf20Sopenharmony_ci	int lhead_lnum;
12688c2ecf20Sopenharmony_ci	int lhead_offs;
12698c2ecf20Sopenharmony_ci	int ltail_lnum;
12708c2ecf20Sopenharmony_ci	struct mutex log_mutex;
12718c2ecf20Sopenharmony_ci	int min_log_bytes;
12728c2ecf20Sopenharmony_ci	long long cmt_bud_bytes;
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci	struct rb_root buds;
12758c2ecf20Sopenharmony_ci	long long bud_bytes;
12768c2ecf20Sopenharmony_ci	spinlock_t buds_lock;
12778c2ecf20Sopenharmony_ci	int jhead_cnt;
12788c2ecf20Sopenharmony_ci	struct ubifs_jhead *jheads;
12798c2ecf20Sopenharmony_ci	long long max_bud_bytes;
12808c2ecf20Sopenharmony_ci	long long bg_bud_bytes;
12818c2ecf20Sopenharmony_ci	struct list_head old_buds;
12828c2ecf20Sopenharmony_ci	int max_bud_cnt;
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci	struct rw_semaphore commit_sem;
12858c2ecf20Sopenharmony_ci	int cmt_state;
12868c2ecf20Sopenharmony_ci	spinlock_t cs_lock;
12878c2ecf20Sopenharmony_ci	wait_queue_head_t cmt_wq;
12888c2ecf20Sopenharmony_ci
12898c2ecf20Sopenharmony_ci	unsigned int big_lpt:1;
12908c2ecf20Sopenharmony_ci	unsigned int space_fixup:1;
12918c2ecf20Sopenharmony_ci	unsigned int double_hash:1;
12928c2ecf20Sopenharmony_ci	unsigned int encrypted:1;
12938c2ecf20Sopenharmony_ci	unsigned int no_chk_data_crc:1;
12948c2ecf20Sopenharmony_ci	unsigned int bulk_read:1;
12958c2ecf20Sopenharmony_ci	unsigned int default_compr:2;
12968c2ecf20Sopenharmony_ci	unsigned int rw_incompat:1;
12978c2ecf20Sopenharmony_ci	unsigned int assert_action:2;
12988c2ecf20Sopenharmony_ci	unsigned int authenticated:1;
12998c2ecf20Sopenharmony_ci	unsigned int superblock_need_write:1;
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_ci	struct mutex tnc_mutex;
13028c2ecf20Sopenharmony_ci	struct ubifs_zbranch zroot;
13038c2ecf20Sopenharmony_ci	struct ubifs_znode *cnext;
13048c2ecf20Sopenharmony_ci	struct ubifs_znode *enext;
13058c2ecf20Sopenharmony_ci	int *gap_lebs;
13068c2ecf20Sopenharmony_ci	void *cbuf;
13078c2ecf20Sopenharmony_ci	void *ileb_buf;
13088c2ecf20Sopenharmony_ci	int ileb_len;
13098c2ecf20Sopenharmony_ci	int ihead_lnum;
13108c2ecf20Sopenharmony_ci	int ihead_offs;
13118c2ecf20Sopenharmony_ci	int *ilebs;
13128c2ecf20Sopenharmony_ci	int ileb_cnt;
13138c2ecf20Sopenharmony_ci	int ileb_nxt;
13148c2ecf20Sopenharmony_ci	struct rb_root old_idx;
13158c2ecf20Sopenharmony_ci	int *bottom_up_buf;
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci	struct ubifs_mst_node *mst_node;
13188c2ecf20Sopenharmony_ci	int mst_offs;
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci	int max_bu_buf_len;
13218c2ecf20Sopenharmony_ci	struct mutex bu_mutex;
13228c2ecf20Sopenharmony_ci	struct bu_info bu;
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci	struct mutex write_reserve_mutex;
13258c2ecf20Sopenharmony_ci	void *write_reserve_buf;
13268c2ecf20Sopenharmony_ci
13278c2ecf20Sopenharmony_ci	int log_lebs;
13288c2ecf20Sopenharmony_ci	long long log_bytes;
13298c2ecf20Sopenharmony_ci	int log_last;
13308c2ecf20Sopenharmony_ci	int lpt_lebs;
13318c2ecf20Sopenharmony_ci	int lpt_first;
13328c2ecf20Sopenharmony_ci	int lpt_last;
13338c2ecf20Sopenharmony_ci	int orph_lebs;
13348c2ecf20Sopenharmony_ci	int orph_first;
13358c2ecf20Sopenharmony_ci	int orph_last;
13368c2ecf20Sopenharmony_ci	int main_lebs;
13378c2ecf20Sopenharmony_ci	int main_first;
13388c2ecf20Sopenharmony_ci	long long main_bytes;
13398c2ecf20Sopenharmony_ci
13408c2ecf20Sopenharmony_ci	uint8_t key_hash_type;
13418c2ecf20Sopenharmony_ci	uint32_t (*key_hash)(const char *str, int len);
13428c2ecf20Sopenharmony_ci	int key_fmt;
13438c2ecf20Sopenharmony_ci	int key_len;
13448c2ecf20Sopenharmony_ci	int hash_len;
13458c2ecf20Sopenharmony_ci	int fanout;
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci	int min_io_size;
13488c2ecf20Sopenharmony_ci	int min_io_shift;
13498c2ecf20Sopenharmony_ci	int max_write_size;
13508c2ecf20Sopenharmony_ci	int max_write_shift;
13518c2ecf20Sopenharmony_ci	int leb_size;
13528c2ecf20Sopenharmony_ci	int leb_start;
13538c2ecf20Sopenharmony_ci	int half_leb_size;
13548c2ecf20Sopenharmony_ci	int idx_leb_size;
13558c2ecf20Sopenharmony_ci	int leb_cnt;
13568c2ecf20Sopenharmony_ci	int max_leb_cnt;
13578c2ecf20Sopenharmony_ci	unsigned int ro_media:1;
13588c2ecf20Sopenharmony_ci	unsigned int ro_mount:1;
13598c2ecf20Sopenharmony_ci	unsigned int ro_error:1;
13608c2ecf20Sopenharmony_ci
13618c2ecf20Sopenharmony_ci	atomic_long_t dirty_pg_cnt;
13628c2ecf20Sopenharmony_ci	atomic_long_t dirty_zn_cnt;
13638c2ecf20Sopenharmony_ci	atomic_long_t clean_zn_cnt;
13648c2ecf20Sopenharmony_ci
13658c2ecf20Sopenharmony_ci	spinlock_t space_lock;
13668c2ecf20Sopenharmony_ci	struct ubifs_lp_stats lst;
13678c2ecf20Sopenharmony_ci	struct ubifs_budg_info bi;
13688c2ecf20Sopenharmony_ci	unsigned long long calc_idx_sz;
13698c2ecf20Sopenharmony_ci
13708c2ecf20Sopenharmony_ci	int ref_node_alsz;
13718c2ecf20Sopenharmony_ci	int mst_node_alsz;
13728c2ecf20Sopenharmony_ci	int min_idx_node_sz;
13738c2ecf20Sopenharmony_ci	int max_idx_node_sz;
13748c2ecf20Sopenharmony_ci	long long max_inode_sz;
13758c2ecf20Sopenharmony_ci	int max_znode_sz;
13768c2ecf20Sopenharmony_ci
13778c2ecf20Sopenharmony_ci	int leb_overhead;
13788c2ecf20Sopenharmony_ci	int dead_wm;
13798c2ecf20Sopenharmony_ci	int dark_wm;
13808c2ecf20Sopenharmony_ci	int block_cnt;
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci	struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
13838c2ecf20Sopenharmony_ci	struct ubi_volume_desc *ubi;
13848c2ecf20Sopenharmony_ci	struct ubi_device_info di;
13858c2ecf20Sopenharmony_ci	struct ubi_volume_info vi;
13868c2ecf20Sopenharmony_ci
13878c2ecf20Sopenharmony_ci	struct rb_root orph_tree;
13888c2ecf20Sopenharmony_ci	struct list_head orph_list;
13898c2ecf20Sopenharmony_ci	struct list_head orph_new;
13908c2ecf20Sopenharmony_ci	struct ubifs_orphan *orph_cnext;
13918c2ecf20Sopenharmony_ci	struct ubifs_orphan *orph_dnext;
13928c2ecf20Sopenharmony_ci	spinlock_t orphan_lock;
13938c2ecf20Sopenharmony_ci	void *orph_buf;
13948c2ecf20Sopenharmony_ci	int new_orphans;
13958c2ecf20Sopenharmony_ci	int cmt_orphans;
13968c2ecf20Sopenharmony_ci	int tot_orphans;
13978c2ecf20Sopenharmony_ci	int max_orphans;
13988c2ecf20Sopenharmony_ci	int ohead_lnum;
13998c2ecf20Sopenharmony_ci	int ohead_offs;
14008c2ecf20Sopenharmony_ci	int no_orphs;
14018c2ecf20Sopenharmony_ci
14028c2ecf20Sopenharmony_ci	struct task_struct *bgt;
14038c2ecf20Sopenharmony_ci	char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
14048c2ecf20Sopenharmony_ci	int need_bgt;
14058c2ecf20Sopenharmony_ci	int need_wbuf_sync;
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci	int gc_lnum;
14088c2ecf20Sopenharmony_ci	void *sbuf;
14098c2ecf20Sopenharmony_ci	struct list_head idx_gc;
14108c2ecf20Sopenharmony_ci	int idx_gc_cnt;
14118c2ecf20Sopenharmony_ci	int gc_seq;
14128c2ecf20Sopenharmony_ci	int gced_lnum;
14138c2ecf20Sopenharmony_ci
14148c2ecf20Sopenharmony_ci	struct list_head infos_list;
14158c2ecf20Sopenharmony_ci	struct mutex umount_mutex;
14168c2ecf20Sopenharmony_ci	unsigned int shrinker_run_no;
14178c2ecf20Sopenharmony_ci
14188c2ecf20Sopenharmony_ci	int space_bits;
14198c2ecf20Sopenharmony_ci	int lpt_lnum_bits;
14208c2ecf20Sopenharmony_ci	int lpt_offs_bits;
14218c2ecf20Sopenharmony_ci	int lpt_spc_bits;
14228c2ecf20Sopenharmony_ci	int pcnt_bits;
14238c2ecf20Sopenharmony_ci	int lnum_bits;
14248c2ecf20Sopenharmony_ci	int nnode_sz;
14258c2ecf20Sopenharmony_ci	int pnode_sz;
14268c2ecf20Sopenharmony_ci	int ltab_sz;
14278c2ecf20Sopenharmony_ci	int lsave_sz;
14288c2ecf20Sopenharmony_ci	int pnode_cnt;
14298c2ecf20Sopenharmony_ci	int nnode_cnt;
14308c2ecf20Sopenharmony_ci	int lpt_hght;
14318c2ecf20Sopenharmony_ci	int pnodes_have;
14328c2ecf20Sopenharmony_ci
14338c2ecf20Sopenharmony_ci	struct mutex lp_mutex;
14348c2ecf20Sopenharmony_ci	int lpt_lnum;
14358c2ecf20Sopenharmony_ci	int lpt_offs;
14368c2ecf20Sopenharmony_ci	int nhead_lnum;
14378c2ecf20Sopenharmony_ci	int nhead_offs;
14388c2ecf20Sopenharmony_ci	int lpt_drty_flgs;
14398c2ecf20Sopenharmony_ci	int dirty_nn_cnt;
14408c2ecf20Sopenharmony_ci	int dirty_pn_cnt;
14418c2ecf20Sopenharmony_ci	int check_lpt_free;
14428c2ecf20Sopenharmony_ci	long long lpt_sz;
14438c2ecf20Sopenharmony_ci	void *lpt_nod_buf;
14448c2ecf20Sopenharmony_ci	void *lpt_buf;
14458c2ecf20Sopenharmony_ci	struct ubifs_nnode *nroot;
14468c2ecf20Sopenharmony_ci	struct ubifs_cnode *lpt_cnext;
14478c2ecf20Sopenharmony_ci	struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
14488c2ecf20Sopenharmony_ci	struct ubifs_lpt_heap dirty_idx;
14498c2ecf20Sopenharmony_ci	struct list_head uncat_list;
14508c2ecf20Sopenharmony_ci	struct list_head empty_list;
14518c2ecf20Sopenharmony_ci	struct list_head freeable_list;
14528c2ecf20Sopenharmony_ci	struct list_head frdi_idx_list;
14538c2ecf20Sopenharmony_ci	int freeable_cnt;
14548c2ecf20Sopenharmony_ci	int in_a_category_cnt;
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_ci	int ltab_lnum;
14578c2ecf20Sopenharmony_ci	int ltab_offs;
14588c2ecf20Sopenharmony_ci	struct ubifs_lpt_lprops *ltab;
14598c2ecf20Sopenharmony_ci	struct ubifs_lpt_lprops *ltab_cmt;
14608c2ecf20Sopenharmony_ci	int lsave_cnt;
14618c2ecf20Sopenharmony_ci	int lsave_lnum;
14628c2ecf20Sopenharmony_ci	int lsave_offs;
14638c2ecf20Sopenharmony_ci	int *lsave;
14648c2ecf20Sopenharmony_ci	int lscan_lnum;
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	long long rp_size;
14678c2ecf20Sopenharmony_ci	long long report_rp_size;
14688c2ecf20Sopenharmony_ci	kuid_t rp_uid;
14698c2ecf20Sopenharmony_ci	kgid_t rp_gid;
14708c2ecf20Sopenharmony_ci
14718c2ecf20Sopenharmony_ci	struct crypto_shash *hash_tfm;
14728c2ecf20Sopenharmony_ci	struct crypto_shash *hmac_tfm;
14738c2ecf20Sopenharmony_ci	int hmac_desc_len;
14748c2ecf20Sopenharmony_ci	char *auth_key_name;
14758c2ecf20Sopenharmony_ci	char *auth_hash_name;
14768c2ecf20Sopenharmony_ci	enum hash_algo auth_hash_algo;
14778c2ecf20Sopenharmony_ci
14788c2ecf20Sopenharmony_ci	struct shash_desc *log_hash;
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci	/* The below fields are used only during mounting and re-mounting */
14818c2ecf20Sopenharmony_ci	unsigned int empty:1;
14828c2ecf20Sopenharmony_ci	unsigned int need_recovery:1;
14838c2ecf20Sopenharmony_ci	unsigned int replaying:1;
14848c2ecf20Sopenharmony_ci	unsigned int mounting:1;
14858c2ecf20Sopenharmony_ci	unsigned int remounting_rw:1;
14868c2ecf20Sopenharmony_ci	unsigned int probing:1;
14878c2ecf20Sopenharmony_ci	struct list_head replay_list;
14888c2ecf20Sopenharmony_ci	struct list_head replay_buds;
14898c2ecf20Sopenharmony_ci	unsigned long long cs_sqnum;
14908c2ecf20Sopenharmony_ci	struct list_head unclean_leb_list;
14918c2ecf20Sopenharmony_ci	struct ubifs_mst_node *rcvrd_mst_node;
14928c2ecf20Sopenharmony_ci	struct rb_root size_tree;
14938c2ecf20Sopenharmony_ci	struct ubifs_mount_opts mount_opts;
14948c2ecf20Sopenharmony_ci
14958c2ecf20Sopenharmony_ci	struct ubifs_debug_info *dbg;
14968c2ecf20Sopenharmony_ci};
14978c2ecf20Sopenharmony_ci
14988c2ecf20Sopenharmony_ciextern struct list_head ubifs_infos;
14998c2ecf20Sopenharmony_ciextern spinlock_t ubifs_infos_lock;
15008c2ecf20Sopenharmony_ciextern atomic_long_t ubifs_clean_zn_cnt;
15018c2ecf20Sopenharmony_ciextern const struct super_operations ubifs_super_operations;
15028c2ecf20Sopenharmony_ciextern const struct address_space_operations ubifs_file_address_operations;
15038c2ecf20Sopenharmony_ciextern const struct file_operations ubifs_file_operations;
15048c2ecf20Sopenharmony_ciextern const struct inode_operations ubifs_file_inode_operations;
15058c2ecf20Sopenharmony_ciextern const struct file_operations ubifs_dir_operations;
15068c2ecf20Sopenharmony_ciextern const struct inode_operations ubifs_dir_inode_operations;
15078c2ecf20Sopenharmony_ciextern const struct inode_operations ubifs_symlink_inode_operations;
15088c2ecf20Sopenharmony_ciextern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
15098c2ecf20Sopenharmony_ciextern int ubifs_default_version;
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci/* auth.c */
15128c2ecf20Sopenharmony_cistatic inline int ubifs_authenticated(const struct ubifs_info *c)
15138c2ecf20Sopenharmony_ci{
15148c2ecf20Sopenharmony_ci	return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated;
15158c2ecf20Sopenharmony_ci}
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_cistruct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c);
15188c2ecf20Sopenharmony_cistatic inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c)
15198c2ecf20Sopenharmony_ci{
15208c2ecf20Sopenharmony_ci	return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL;
15218c2ecf20Sopenharmony_ci}
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_cistatic inline int ubifs_shash_init(const struct ubifs_info *c,
15248c2ecf20Sopenharmony_ci				   struct shash_desc *desc)
15258c2ecf20Sopenharmony_ci{
15268c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
15278c2ecf20Sopenharmony_ci		return crypto_shash_init(desc);
15288c2ecf20Sopenharmony_ci	else
15298c2ecf20Sopenharmony_ci		return 0;
15308c2ecf20Sopenharmony_ci}
15318c2ecf20Sopenharmony_ci
15328c2ecf20Sopenharmony_cistatic inline int ubifs_shash_update(const struct ubifs_info *c,
15338c2ecf20Sopenharmony_ci				      struct shash_desc *desc, const void *buf,
15348c2ecf20Sopenharmony_ci				      unsigned int len)
15358c2ecf20Sopenharmony_ci{
15368c2ecf20Sopenharmony_ci	int err = 0;
15378c2ecf20Sopenharmony_ci
15388c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c)) {
15398c2ecf20Sopenharmony_ci		err = crypto_shash_update(desc, buf, len);
15408c2ecf20Sopenharmony_ci		if (err < 0)
15418c2ecf20Sopenharmony_ci			return err;
15428c2ecf20Sopenharmony_ci	}
15438c2ecf20Sopenharmony_ci
15448c2ecf20Sopenharmony_ci	return 0;
15458c2ecf20Sopenharmony_ci}
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_cistatic inline int ubifs_shash_final(const struct ubifs_info *c,
15488c2ecf20Sopenharmony_ci				    struct shash_desc *desc, u8 *out)
15498c2ecf20Sopenharmony_ci{
15508c2ecf20Sopenharmony_ci	return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0;
15518c2ecf20Sopenharmony_ci}
15528c2ecf20Sopenharmony_ci
15538c2ecf20Sopenharmony_ciint __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf,
15548c2ecf20Sopenharmony_ci			  u8 *hash);
15558c2ecf20Sopenharmony_cistatic inline int ubifs_node_calc_hash(const struct ubifs_info *c,
15568c2ecf20Sopenharmony_ci					const void *buf, u8 *hash)
15578c2ecf20Sopenharmony_ci{
15588c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
15598c2ecf20Sopenharmony_ci		return __ubifs_node_calc_hash(c, buf, hash);
15608c2ecf20Sopenharmony_ci	else
15618c2ecf20Sopenharmony_ci		return 0;
15628c2ecf20Sopenharmony_ci}
15638c2ecf20Sopenharmony_ci
15648c2ecf20Sopenharmony_ciint ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
15658c2ecf20Sopenharmony_ci			     struct shash_desc *inhash);
15668c2ecf20Sopenharmony_ci
15678c2ecf20Sopenharmony_ci/**
15688c2ecf20Sopenharmony_ci * ubifs_check_hash - compare two hashes
15698c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
15708c2ecf20Sopenharmony_ci * @expected: first hash
15718c2ecf20Sopenharmony_ci * @got: second hash
15728c2ecf20Sopenharmony_ci *
15738c2ecf20Sopenharmony_ci * Compare two hashes @expected and @got. Returns 0 when they are equal, a
15748c2ecf20Sopenharmony_ci * negative error code otherwise.
15758c2ecf20Sopenharmony_ci */
15768c2ecf20Sopenharmony_cistatic inline int ubifs_check_hash(const struct ubifs_info *c,
15778c2ecf20Sopenharmony_ci				   const u8 *expected, const u8 *got)
15788c2ecf20Sopenharmony_ci{
15798c2ecf20Sopenharmony_ci	return crypto_memneq(expected, got, c->hash_len);
15808c2ecf20Sopenharmony_ci}
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ci/**
15838c2ecf20Sopenharmony_ci * ubifs_check_hmac - compare two HMACs
15848c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
15858c2ecf20Sopenharmony_ci * @expected: first HMAC
15868c2ecf20Sopenharmony_ci * @got: second HMAC
15878c2ecf20Sopenharmony_ci *
15888c2ecf20Sopenharmony_ci * Compare two hashes @expected and @got. Returns 0 when they are equal, a
15898c2ecf20Sopenharmony_ci * negative error code otherwise.
15908c2ecf20Sopenharmony_ci */
15918c2ecf20Sopenharmony_cistatic inline int ubifs_check_hmac(const struct ubifs_info *c,
15928c2ecf20Sopenharmony_ci				   const u8 *expected, const u8 *got)
15938c2ecf20Sopenharmony_ci{
15948c2ecf20Sopenharmony_ci	return crypto_memneq(expected, got, c->hmac_desc_len);
15958c2ecf20Sopenharmony_ci}
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_AUTHENTICATION
15988c2ecf20Sopenharmony_civoid ubifs_bad_hash(const struct ubifs_info *c, const void *node,
15998c2ecf20Sopenharmony_ci		    const u8 *hash, int lnum, int offs);
16008c2ecf20Sopenharmony_ci#else
16018c2ecf20Sopenharmony_cistatic inline void ubifs_bad_hash(const struct ubifs_info *c, const void *node,
16028c2ecf20Sopenharmony_ci				  const u8 *hash, int lnum, int offs) {};
16038c2ecf20Sopenharmony_ci#endif
16048c2ecf20Sopenharmony_ci
16058c2ecf20Sopenharmony_ciint __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf,
16068c2ecf20Sopenharmony_ci			  const u8 *expected);
16078c2ecf20Sopenharmony_cistatic inline int ubifs_node_check_hash(const struct ubifs_info *c,
16088c2ecf20Sopenharmony_ci					const void *buf, const u8 *expected)
16098c2ecf20Sopenharmony_ci{
16108c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16118c2ecf20Sopenharmony_ci		return __ubifs_node_check_hash(c, buf, expected);
16128c2ecf20Sopenharmony_ci	else
16138c2ecf20Sopenharmony_ci		return 0;
16148c2ecf20Sopenharmony_ci}
16158c2ecf20Sopenharmony_ci
16168c2ecf20Sopenharmony_ciint ubifs_init_authentication(struct ubifs_info *c);
16178c2ecf20Sopenharmony_civoid __ubifs_exit_authentication(struct ubifs_info *c);
16188c2ecf20Sopenharmony_cistatic inline void ubifs_exit_authentication(struct ubifs_info *c)
16198c2ecf20Sopenharmony_ci{
16208c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16218c2ecf20Sopenharmony_ci		__ubifs_exit_authentication(c);
16228c2ecf20Sopenharmony_ci}
16238c2ecf20Sopenharmony_ci
16248c2ecf20Sopenharmony_ci/**
16258c2ecf20Sopenharmony_ci * ubifs_branch_hash - returns a pointer to the hash of a branch
16268c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
16278c2ecf20Sopenharmony_ci * @br: branch to get the hash from
16288c2ecf20Sopenharmony_ci *
16298c2ecf20Sopenharmony_ci * This returns a pointer to the hash of a branch. Since the key already is a
16308c2ecf20Sopenharmony_ci * dynamically sized object we cannot use a struct member here.
16318c2ecf20Sopenharmony_ci */
16328c2ecf20Sopenharmony_cistatic inline u8 *ubifs_branch_hash(struct ubifs_info *c,
16338c2ecf20Sopenharmony_ci				    struct ubifs_branch *br)
16348c2ecf20Sopenharmony_ci{
16358c2ecf20Sopenharmony_ci	return (void *)br + sizeof(*br) + c->key_len;
16368c2ecf20Sopenharmony_ci}
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_ci/**
16398c2ecf20Sopenharmony_ci * ubifs_copy_hash - copy a hash
16408c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
16418c2ecf20Sopenharmony_ci * @from: source hash
16428c2ecf20Sopenharmony_ci * @to: destination hash
16438c2ecf20Sopenharmony_ci *
16448c2ecf20Sopenharmony_ci * With authentication this copies a hash, otherwise does nothing.
16458c2ecf20Sopenharmony_ci */
16468c2ecf20Sopenharmony_cistatic inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from,
16478c2ecf20Sopenharmony_ci				   u8 *to)
16488c2ecf20Sopenharmony_ci{
16498c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16508c2ecf20Sopenharmony_ci		memcpy(to, from, c->hash_len);
16518c2ecf20Sopenharmony_ci}
16528c2ecf20Sopenharmony_ci
16538c2ecf20Sopenharmony_ciint __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
16548c2ecf20Sopenharmony_ci			      int len, int ofs_hmac);
16558c2ecf20Sopenharmony_cistatic inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
16568c2ecf20Sopenharmony_ci					  int len, int ofs_hmac)
16578c2ecf20Sopenharmony_ci{
16588c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16598c2ecf20Sopenharmony_ci		return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
16608c2ecf20Sopenharmony_ci	else
16618c2ecf20Sopenharmony_ci		return 0;
16628c2ecf20Sopenharmony_ci}
16638c2ecf20Sopenharmony_ci
16648c2ecf20Sopenharmony_ciint __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
16658c2ecf20Sopenharmony_ci			     int len, int ofs_hmac);
16668c2ecf20Sopenharmony_cistatic inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
16678c2ecf20Sopenharmony_ci					 const void *buf, int len, int ofs_hmac)
16688c2ecf20Sopenharmony_ci{
16698c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16708c2ecf20Sopenharmony_ci		return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
16718c2ecf20Sopenharmony_ci	else
16728c2ecf20Sopenharmony_ci		return 0;
16738c2ecf20Sopenharmony_ci}
16748c2ecf20Sopenharmony_ci
16758c2ecf20Sopenharmony_ci/**
16768c2ecf20Sopenharmony_ci * ubifs_auth_node_sz - returns the size of an authentication node
16778c2ecf20Sopenharmony_ci * @c: UBIFS file-system description object
16788c2ecf20Sopenharmony_ci *
16798c2ecf20Sopenharmony_ci * This function returns the size of an authentication node which can
16808c2ecf20Sopenharmony_ci * be 0 for unauthenticated filesystems or the real size of an auth node
16818c2ecf20Sopenharmony_ci * authentication is enabled.
16828c2ecf20Sopenharmony_ci */
16838c2ecf20Sopenharmony_cistatic inline int ubifs_auth_node_sz(const struct ubifs_info *c)
16848c2ecf20Sopenharmony_ci{
16858c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
16868c2ecf20Sopenharmony_ci		return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
16878c2ecf20Sopenharmony_ci	else
16888c2ecf20Sopenharmony_ci		return 0;
16898c2ecf20Sopenharmony_ci}
16908c2ecf20Sopenharmony_ciint ubifs_sb_verify_signature(struct ubifs_info *c,
16918c2ecf20Sopenharmony_ci			      const struct ubifs_sb_node *sup);
16928c2ecf20Sopenharmony_cibool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac);
16938c2ecf20Sopenharmony_ci
16948c2ecf20Sopenharmony_ciint ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac);
16958c2ecf20Sopenharmony_ci
16968c2ecf20Sopenharmony_ciint __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
16978c2ecf20Sopenharmony_ci			     struct shash_desc *target);
16988c2ecf20Sopenharmony_cistatic inline int ubifs_shash_copy_state(const struct ubifs_info *c,
16998c2ecf20Sopenharmony_ci					   struct shash_desc *src,
17008c2ecf20Sopenharmony_ci					   struct shash_desc *target)
17018c2ecf20Sopenharmony_ci{
17028c2ecf20Sopenharmony_ci	if (ubifs_authenticated(c))
17038c2ecf20Sopenharmony_ci		return __ubifs_shash_copy_state(c, src, target);
17048c2ecf20Sopenharmony_ci	else
17058c2ecf20Sopenharmony_ci		return 0;
17068c2ecf20Sopenharmony_ci}
17078c2ecf20Sopenharmony_ci
17088c2ecf20Sopenharmony_ci/* io.c */
17098c2ecf20Sopenharmony_civoid ubifs_ro_mode(struct ubifs_info *c, int err);
17108c2ecf20Sopenharmony_ciint ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
17118c2ecf20Sopenharmony_ci		   int len, int even_ebadmsg);
17128c2ecf20Sopenharmony_ciint ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
17138c2ecf20Sopenharmony_ci		    int len);
17148c2ecf20Sopenharmony_ciint ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
17158c2ecf20Sopenharmony_ciint ubifs_leb_unmap(struct ubifs_info *c, int lnum);
17168c2ecf20Sopenharmony_ciint ubifs_leb_map(struct ubifs_info *c, int lnum);
17178c2ecf20Sopenharmony_ciint ubifs_is_mapped(const struct ubifs_info *c, int lnum);
17188c2ecf20Sopenharmony_ciint ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
17198c2ecf20Sopenharmony_ciint ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
17208c2ecf20Sopenharmony_ciint ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
17218c2ecf20Sopenharmony_ciint ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
17228c2ecf20Sopenharmony_ci		    int lnum, int offs);
17238c2ecf20Sopenharmony_ciint ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
17248c2ecf20Sopenharmony_ci			 int lnum, int offs);
17258c2ecf20Sopenharmony_ciint ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
17268c2ecf20Sopenharmony_ci		     int offs);
17278c2ecf20Sopenharmony_ciint ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
17288c2ecf20Sopenharmony_ci			  int offs, int hmac_offs);
17298c2ecf20Sopenharmony_ciint ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
17308c2ecf20Sopenharmony_ci		     int lnum, int offs, int quiet, int must_chk_crc);
17318c2ecf20Sopenharmony_civoid ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
17328c2ecf20Sopenharmony_civoid ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
17338c2ecf20Sopenharmony_civoid ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
17348c2ecf20Sopenharmony_ciint ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
17358c2ecf20Sopenharmony_ci			    int hmac_offs, int pad);
17368c2ecf20Sopenharmony_civoid ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
17378c2ecf20Sopenharmony_ciint ubifs_io_init(struct ubifs_info *c);
17388c2ecf20Sopenharmony_civoid ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
17398c2ecf20Sopenharmony_ciint ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
17408c2ecf20Sopenharmony_ciint ubifs_bg_wbufs_sync(struct ubifs_info *c);
17418c2ecf20Sopenharmony_civoid ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
17428c2ecf20Sopenharmony_ciint ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
17438c2ecf20Sopenharmony_ci
17448c2ecf20Sopenharmony_ci/* scan.c */
17458c2ecf20Sopenharmony_cistruct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
17468c2ecf20Sopenharmony_ci				  int offs, void *sbuf, int quiet);
17478c2ecf20Sopenharmony_civoid ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
17488c2ecf20Sopenharmony_ciint ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
17498c2ecf20Sopenharmony_ci		      int offs, int quiet);
17508c2ecf20Sopenharmony_cistruct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
17518c2ecf20Sopenharmony_ci					int offs, void *sbuf);
17528c2ecf20Sopenharmony_civoid ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
17538c2ecf20Sopenharmony_ci		    int lnum, int offs);
17548c2ecf20Sopenharmony_ciint ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
17558c2ecf20Sopenharmony_ci		   void *buf, int offs);
17568c2ecf20Sopenharmony_civoid ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
17578c2ecf20Sopenharmony_ci			      void *buf);
17588c2ecf20Sopenharmony_ci
17598c2ecf20Sopenharmony_ci/* log.c */
17608c2ecf20Sopenharmony_civoid ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
17618c2ecf20Sopenharmony_civoid ubifs_create_buds_lists(struct ubifs_info *c);
17628c2ecf20Sopenharmony_ciint ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
17638c2ecf20Sopenharmony_cistruct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
17648c2ecf20Sopenharmony_cistruct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
17658c2ecf20Sopenharmony_ciint ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
17668c2ecf20Sopenharmony_ciint ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
17678c2ecf20Sopenharmony_ciint ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
17688c2ecf20Sopenharmony_ciint ubifs_consolidate_log(struct ubifs_info *c);
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci/* journal.c */
17718c2ecf20Sopenharmony_ciint ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
17728c2ecf20Sopenharmony_ci		     const struct fscrypt_name *nm, const struct inode *inode,
17738c2ecf20Sopenharmony_ci		     int deletion, int xent);
17748c2ecf20Sopenharmony_ciint ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
17758c2ecf20Sopenharmony_ci			 const union ubifs_key *key, const void *buf, int len);
17768c2ecf20Sopenharmony_ciint ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
17778c2ecf20Sopenharmony_ciint ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
17788c2ecf20Sopenharmony_ciint ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
17798c2ecf20Sopenharmony_ci		      const struct inode *fst_inode,
17808c2ecf20Sopenharmony_ci		      const struct fscrypt_name *fst_nm,
17818c2ecf20Sopenharmony_ci		      const struct inode *snd_dir,
17828c2ecf20Sopenharmony_ci		      const struct inode *snd_inode,
17838c2ecf20Sopenharmony_ci		      const struct fscrypt_name *snd_nm, int sync);
17848c2ecf20Sopenharmony_ciint ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
17858c2ecf20Sopenharmony_ci		     const struct inode *old_inode,
17868c2ecf20Sopenharmony_ci		     const struct fscrypt_name *old_nm,
17878c2ecf20Sopenharmony_ci		     const struct inode *new_dir,
17888c2ecf20Sopenharmony_ci		     const struct inode *new_inode,
17898c2ecf20Sopenharmony_ci		     const struct fscrypt_name *new_nm,
17908c2ecf20Sopenharmony_ci		     const struct inode *whiteout, int sync);
17918c2ecf20Sopenharmony_ciint ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
17928c2ecf20Sopenharmony_ci		       loff_t old_size, loff_t new_size);
17938c2ecf20Sopenharmony_ciint ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
17948c2ecf20Sopenharmony_ci			   const struct inode *inode, const struct fscrypt_name *nm);
17958c2ecf20Sopenharmony_ciint ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
17968c2ecf20Sopenharmony_ci			   const struct inode *inode2);
17978c2ecf20Sopenharmony_ci
17988c2ecf20Sopenharmony_ci/* budget.c */
17998c2ecf20Sopenharmony_ciint ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
18008c2ecf20Sopenharmony_civoid ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
18018c2ecf20Sopenharmony_civoid ubifs_release_dirty_inode_budget(struct ubifs_info *c,
18028c2ecf20Sopenharmony_ci				      struct ubifs_inode *ui);
18038c2ecf20Sopenharmony_ciint ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
18048c2ecf20Sopenharmony_ci			  struct ubifs_budget_req *req);
18058c2ecf20Sopenharmony_civoid ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
18068c2ecf20Sopenharmony_ci				struct ubifs_budget_req *req);
18078c2ecf20Sopenharmony_civoid ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
18088c2ecf20Sopenharmony_ci			 struct ubifs_budget_req *req);
18098c2ecf20Sopenharmony_cilong long ubifs_get_free_space(struct ubifs_info *c);
18108c2ecf20Sopenharmony_cilong long ubifs_get_free_space_nolock(struct ubifs_info *c);
18118c2ecf20Sopenharmony_ciint ubifs_calc_min_idx_lebs(struct ubifs_info *c);
18128c2ecf20Sopenharmony_civoid ubifs_convert_page_budget(struct ubifs_info *c);
18138c2ecf20Sopenharmony_cilong long ubifs_reported_space(const struct ubifs_info *c, long long free);
18148c2ecf20Sopenharmony_cilong long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
18158c2ecf20Sopenharmony_ci
18168c2ecf20Sopenharmony_ci/* find.c */
18178c2ecf20Sopenharmony_ciint ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
18188c2ecf20Sopenharmony_ci			  int squeeze);
18198c2ecf20Sopenharmony_ciint ubifs_find_free_leb_for_idx(struct ubifs_info *c);
18208c2ecf20Sopenharmony_ciint ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
18218c2ecf20Sopenharmony_ci			 int min_space, int pick_free);
18228c2ecf20Sopenharmony_ciint ubifs_find_dirty_idx_leb(struct ubifs_info *c);
18238c2ecf20Sopenharmony_ciint ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
18248c2ecf20Sopenharmony_ci
18258c2ecf20Sopenharmony_ci/* tnc.c */
18268c2ecf20Sopenharmony_ciint ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
18278c2ecf20Sopenharmony_ci			struct ubifs_znode **zn, int *n);
18288c2ecf20Sopenharmony_ciint ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
18298c2ecf20Sopenharmony_ci			void *node, const struct fscrypt_name *nm);
18308c2ecf20Sopenharmony_ciint ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
18318c2ecf20Sopenharmony_ci			void *node, uint32_t secondary_hash);
18328c2ecf20Sopenharmony_ciint ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
18338c2ecf20Sopenharmony_ci		     void *node, int *lnum, int *offs);
18348c2ecf20Sopenharmony_ciint ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
18358c2ecf20Sopenharmony_ci		  int offs, int len, const u8 *hash);
18368c2ecf20Sopenharmony_ciint ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
18378c2ecf20Sopenharmony_ci		      int old_lnum, int old_offs, int lnum, int offs, int len);
18388c2ecf20Sopenharmony_ciint ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
18398c2ecf20Sopenharmony_ci		     int lnum, int offs, int len, const u8 *hash,
18408c2ecf20Sopenharmony_ci		     const struct fscrypt_name *nm);
18418c2ecf20Sopenharmony_ciint ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
18428c2ecf20Sopenharmony_ciint ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
18438c2ecf20Sopenharmony_ci			const struct fscrypt_name *nm);
18448c2ecf20Sopenharmony_ciint ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key,
18458c2ecf20Sopenharmony_ci			uint32_t cookie);
18468c2ecf20Sopenharmony_ciint ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
18478c2ecf20Sopenharmony_ci			   union ubifs_key *to_key);
18488c2ecf20Sopenharmony_ciint ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
18498c2ecf20Sopenharmony_cistruct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
18508c2ecf20Sopenharmony_ci					   union ubifs_key *key,
18518c2ecf20Sopenharmony_ci					   const struct fscrypt_name *nm);
18528c2ecf20Sopenharmony_civoid ubifs_tnc_close(struct ubifs_info *c);
18538c2ecf20Sopenharmony_ciint ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
18548c2ecf20Sopenharmony_ci		       int lnum, int offs, int is_idx);
18558c2ecf20Sopenharmony_ciint ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
18568c2ecf20Sopenharmony_ci			 int lnum, int offs);
18578c2ecf20Sopenharmony_ci/* Shared by tnc.c for tnc_commit.c */
18588c2ecf20Sopenharmony_civoid destroy_old_idx(struct ubifs_info *c);
18598c2ecf20Sopenharmony_ciint is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
18608c2ecf20Sopenharmony_ci		       int lnum, int offs);
18618c2ecf20Sopenharmony_ciint insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
18628c2ecf20Sopenharmony_ciint ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
18638c2ecf20Sopenharmony_ciint ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
18648c2ecf20Sopenharmony_ci
18658c2ecf20Sopenharmony_ci/* tnc_misc.c */
18668c2ecf20Sopenharmony_cistruct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c,
18678c2ecf20Sopenharmony_ci					      struct ubifs_znode *zr,
18688c2ecf20Sopenharmony_ci					      struct ubifs_znode *znode);
18698c2ecf20Sopenharmony_ciint ubifs_search_zbranch(const struct ubifs_info *c,
18708c2ecf20Sopenharmony_ci			 const struct ubifs_znode *znode,
18718c2ecf20Sopenharmony_ci			 const union ubifs_key *key, int *n);
18728c2ecf20Sopenharmony_cistruct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
18738c2ecf20Sopenharmony_cistruct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c,
18748c2ecf20Sopenharmony_ci					     struct ubifs_znode *znode);
18758c2ecf20Sopenharmony_cilong ubifs_destroy_tnc_subtree(const struct ubifs_info *c,
18768c2ecf20Sopenharmony_ci			       struct ubifs_znode *zr);
18778c2ecf20Sopenharmony_cistruct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
18788c2ecf20Sopenharmony_ci				     struct ubifs_zbranch *zbr,
18798c2ecf20Sopenharmony_ci				     struct ubifs_znode *parent, int iip);
18808c2ecf20Sopenharmony_ciint ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
18818c2ecf20Sopenharmony_ci			void *node);
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_ci/* tnc_commit.c */
18848c2ecf20Sopenharmony_ciint ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
18858c2ecf20Sopenharmony_ciint ubifs_tnc_end_commit(struct ubifs_info *c);
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ci/* shrinker.c */
18888c2ecf20Sopenharmony_ciunsigned long ubifs_shrink_scan(struct shrinker *shrink,
18898c2ecf20Sopenharmony_ci				struct shrink_control *sc);
18908c2ecf20Sopenharmony_ciunsigned long ubifs_shrink_count(struct shrinker *shrink,
18918c2ecf20Sopenharmony_ci				 struct shrink_control *sc);
18928c2ecf20Sopenharmony_ci
18938c2ecf20Sopenharmony_ci/* commit.c */
18948c2ecf20Sopenharmony_ciint ubifs_bg_thread(void *info);
18958c2ecf20Sopenharmony_civoid ubifs_commit_required(struct ubifs_info *c);
18968c2ecf20Sopenharmony_civoid ubifs_request_bg_commit(struct ubifs_info *c);
18978c2ecf20Sopenharmony_ciint ubifs_run_commit(struct ubifs_info *c);
18988c2ecf20Sopenharmony_civoid ubifs_recovery_commit(struct ubifs_info *c);
18998c2ecf20Sopenharmony_ciint ubifs_gc_should_commit(struct ubifs_info *c);
19008c2ecf20Sopenharmony_civoid ubifs_wait_for_commit(struct ubifs_info *c);
19018c2ecf20Sopenharmony_ci
19028c2ecf20Sopenharmony_ci/* master.c */
19038c2ecf20Sopenharmony_ciint ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2);
19048c2ecf20Sopenharmony_ciint ubifs_read_master(struct ubifs_info *c);
19058c2ecf20Sopenharmony_ciint ubifs_write_master(struct ubifs_info *c);
19068c2ecf20Sopenharmony_ci
19078c2ecf20Sopenharmony_ci/* sb.c */
19088c2ecf20Sopenharmony_ciint ubifs_read_superblock(struct ubifs_info *c);
19098c2ecf20Sopenharmony_ciint ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
19108c2ecf20Sopenharmony_ciint ubifs_fixup_free_space(struct ubifs_info *c);
19118c2ecf20Sopenharmony_ciint ubifs_enable_encryption(struct ubifs_info *c);
19128c2ecf20Sopenharmony_ci
19138c2ecf20Sopenharmony_ci/* replay.c */
19148c2ecf20Sopenharmony_ciint ubifs_validate_entry(struct ubifs_info *c,
19158c2ecf20Sopenharmony_ci			 const struct ubifs_dent_node *dent);
19168c2ecf20Sopenharmony_ciint ubifs_replay_journal(struct ubifs_info *c);
19178c2ecf20Sopenharmony_ci
19188c2ecf20Sopenharmony_ci/* gc.c */
19198c2ecf20Sopenharmony_ciint ubifs_garbage_collect(struct ubifs_info *c, int anyway);
19208c2ecf20Sopenharmony_ciint ubifs_gc_start_commit(struct ubifs_info *c);
19218c2ecf20Sopenharmony_ciint ubifs_gc_end_commit(struct ubifs_info *c);
19228c2ecf20Sopenharmony_civoid ubifs_destroy_idx_gc(struct ubifs_info *c);
19238c2ecf20Sopenharmony_ciint ubifs_get_idx_gc_leb(struct ubifs_info *c);
19248c2ecf20Sopenharmony_ciint ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
19258c2ecf20Sopenharmony_ci
19268c2ecf20Sopenharmony_ci/* orphan.c */
19278c2ecf20Sopenharmony_ciint ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
19288c2ecf20Sopenharmony_civoid ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
19298c2ecf20Sopenharmony_ciint ubifs_orphan_start_commit(struct ubifs_info *c);
19308c2ecf20Sopenharmony_ciint ubifs_orphan_end_commit(struct ubifs_info *c);
19318c2ecf20Sopenharmony_ciint ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
19328c2ecf20Sopenharmony_ciint ubifs_clear_orphans(struct ubifs_info *c);
19338c2ecf20Sopenharmony_ci
19348c2ecf20Sopenharmony_ci/* lpt.c */
19358c2ecf20Sopenharmony_ciint ubifs_calc_lpt_geom(struct ubifs_info *c);
19368c2ecf20Sopenharmony_ciint ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
19378c2ecf20Sopenharmony_ci			  int *lpt_lebs, int *big_lpt, u8 *hash);
19388c2ecf20Sopenharmony_ciint ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
19398c2ecf20Sopenharmony_cistruct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
19408c2ecf20Sopenharmony_cistruct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
19418c2ecf20Sopenharmony_ciint ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
19428c2ecf20Sopenharmony_ci			  ubifs_lpt_scan_callback scan_cb, void *data);
19438c2ecf20Sopenharmony_ci
19448c2ecf20Sopenharmony_ci/* Shared by lpt.c for lpt_commit.c */
19458c2ecf20Sopenharmony_civoid ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
19468c2ecf20Sopenharmony_civoid ubifs_pack_ltab(struct ubifs_info *c, void *buf,
19478c2ecf20Sopenharmony_ci		     struct ubifs_lpt_lprops *ltab);
19488c2ecf20Sopenharmony_civoid ubifs_pack_pnode(struct ubifs_info *c, void *buf,
19498c2ecf20Sopenharmony_ci		      struct ubifs_pnode *pnode);
19508c2ecf20Sopenharmony_civoid ubifs_pack_nnode(struct ubifs_info *c, void *buf,
19518c2ecf20Sopenharmony_ci		      struct ubifs_nnode *nnode);
19528c2ecf20Sopenharmony_cistruct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
19538c2ecf20Sopenharmony_ci				    struct ubifs_nnode *parent, int iip);
19548c2ecf20Sopenharmony_cistruct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
19558c2ecf20Sopenharmony_ci				    struct ubifs_nnode *parent, int iip);
19568c2ecf20Sopenharmony_cistruct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i);
19578c2ecf20Sopenharmony_ciint ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
19588c2ecf20Sopenharmony_civoid ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
19598c2ecf20Sopenharmony_civoid ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
19608c2ecf20Sopenharmony_ciuint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits);
19618c2ecf20Sopenharmony_cistruct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
19628c2ecf20Sopenharmony_ci/* Needed only in debugging code in lpt_commit.c */
19638c2ecf20Sopenharmony_ciint ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
19648c2ecf20Sopenharmony_ci		       struct ubifs_nnode *nnode);
19658c2ecf20Sopenharmony_ciint ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash);
19668c2ecf20Sopenharmony_ci
19678c2ecf20Sopenharmony_ci/* lpt_commit.c */
19688c2ecf20Sopenharmony_ciint ubifs_lpt_start_commit(struct ubifs_info *c);
19698c2ecf20Sopenharmony_ciint ubifs_lpt_end_commit(struct ubifs_info *c);
19708c2ecf20Sopenharmony_ciint ubifs_lpt_post_commit(struct ubifs_info *c);
19718c2ecf20Sopenharmony_civoid ubifs_lpt_free(struct ubifs_info *c, int wr_only);
19728c2ecf20Sopenharmony_ci
19738c2ecf20Sopenharmony_ci/* lprops.c */
19748c2ecf20Sopenharmony_ciconst struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
19758c2ecf20Sopenharmony_ci					   const struct ubifs_lprops *lp,
19768c2ecf20Sopenharmony_ci					   int free, int dirty, int flags,
19778c2ecf20Sopenharmony_ci					   int idx_gc_cnt);
19788c2ecf20Sopenharmony_civoid ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
19798c2ecf20Sopenharmony_civoid ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
19808c2ecf20Sopenharmony_ci		      int cat);
19818c2ecf20Sopenharmony_civoid ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
19828c2ecf20Sopenharmony_ci		       struct ubifs_lprops *new_lprops);
19838c2ecf20Sopenharmony_civoid ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
19848c2ecf20Sopenharmony_ciint ubifs_categorize_lprops(const struct ubifs_info *c,
19858c2ecf20Sopenharmony_ci			    const struct ubifs_lprops *lprops);
19868c2ecf20Sopenharmony_ciint ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
19878c2ecf20Sopenharmony_ci			int flags_set, int flags_clean, int idx_gc_cnt);
19888c2ecf20Sopenharmony_ciint ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
19898c2ecf20Sopenharmony_ci			int flags_set, int flags_clean);
19908c2ecf20Sopenharmony_ciint ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
19918c2ecf20Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
19928c2ecf20Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
19938c2ecf20Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
19948c2ecf20Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
19958c2ecf20Sopenharmony_ciint ubifs_calc_dark(const struct ubifs_info *c, int spc);
19968c2ecf20Sopenharmony_ci
19978c2ecf20Sopenharmony_ci/* file.c */
19988c2ecf20Sopenharmony_ciint ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
19998c2ecf20Sopenharmony_ciint ubifs_setattr(struct dentry *dentry, struct iattr *attr);
20008c2ecf20Sopenharmony_ciint ubifs_update_time(struct inode *inode, struct timespec64 *time, int flags);
20018c2ecf20Sopenharmony_ci
20028c2ecf20Sopenharmony_ci/* dir.c */
20038c2ecf20Sopenharmony_cistruct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
20048c2ecf20Sopenharmony_ci			      umode_t mode);
20058c2ecf20Sopenharmony_ciint ubifs_getattr(const struct path *path, struct kstat *stat,
20068c2ecf20Sopenharmony_ci		  u32 request_mask, unsigned int flags);
20078c2ecf20Sopenharmony_ciint ubifs_check_dir_empty(struct inode *dir);
20088c2ecf20Sopenharmony_ci
20098c2ecf20Sopenharmony_ci/* xattr.c */
20108c2ecf20Sopenharmony_ciextern const struct xattr_handler *ubifs_xattr_handlers[];
20118c2ecf20Sopenharmony_cissize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
20128c2ecf20Sopenharmony_ciint ubifs_xattr_set(struct inode *host, const char *name, const void *value,
20138c2ecf20Sopenharmony_ci		    size_t size, int flags, bool check_lock);
20148c2ecf20Sopenharmony_cissize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
20158c2ecf20Sopenharmony_ci			size_t size);
20168c2ecf20Sopenharmony_ci
20178c2ecf20Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_XATTR
20188c2ecf20Sopenharmony_civoid ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
20198c2ecf20Sopenharmony_ciint ubifs_purge_xattrs(struct inode *host);
20208c2ecf20Sopenharmony_ci#else
20218c2ecf20Sopenharmony_cistatic inline void ubifs_evict_xattr_inode(struct ubifs_info *c,
20228c2ecf20Sopenharmony_ci					   ino_t xattr_inum) { }
20238c2ecf20Sopenharmony_cistatic inline int ubifs_purge_xattrs(struct inode *host)
20248c2ecf20Sopenharmony_ci{
20258c2ecf20Sopenharmony_ci	return 0;
20268c2ecf20Sopenharmony_ci}
20278c2ecf20Sopenharmony_ci#endif
20288c2ecf20Sopenharmony_ci
20298c2ecf20Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_SECURITY
20308c2ecf20Sopenharmony_ciextern int ubifs_init_security(struct inode *dentry, struct inode *inode,
20318c2ecf20Sopenharmony_ci			const struct qstr *qstr);
20328c2ecf20Sopenharmony_ci#else
20338c2ecf20Sopenharmony_cistatic inline int ubifs_init_security(struct inode *dentry,
20348c2ecf20Sopenharmony_ci			struct inode *inode, const struct qstr *qstr)
20358c2ecf20Sopenharmony_ci{
20368c2ecf20Sopenharmony_ci	return 0;
20378c2ecf20Sopenharmony_ci}
20388c2ecf20Sopenharmony_ci#endif
20398c2ecf20Sopenharmony_ci
20408c2ecf20Sopenharmony_ci
20418c2ecf20Sopenharmony_ci/* super.c */
20428c2ecf20Sopenharmony_cistruct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
20438c2ecf20Sopenharmony_ci
20448c2ecf20Sopenharmony_ci/* recovery.c */
20458c2ecf20Sopenharmony_ciint ubifs_recover_master_node(struct ubifs_info *c);
20468c2ecf20Sopenharmony_ciint ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
20478c2ecf20Sopenharmony_cistruct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
20488c2ecf20Sopenharmony_ci					 int offs, void *sbuf, int jhead);
20498c2ecf20Sopenharmony_cistruct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
20508c2ecf20Sopenharmony_ci					     int offs, void *sbuf);
20518c2ecf20Sopenharmony_ciint ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
20528c2ecf20Sopenharmony_ciint ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
20538c2ecf20Sopenharmony_ciint ubifs_rcvry_gc_commit(struct ubifs_info *c);
20548c2ecf20Sopenharmony_ciint ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
20558c2ecf20Sopenharmony_ci			     int deletion, loff_t new_size);
20568c2ecf20Sopenharmony_ciint ubifs_recover_size(struct ubifs_info *c, bool in_place);
20578c2ecf20Sopenharmony_civoid ubifs_destroy_size_tree(struct ubifs_info *c);
20588c2ecf20Sopenharmony_ci
20598c2ecf20Sopenharmony_ci/* ioctl.c */
20608c2ecf20Sopenharmony_cilong ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
20618c2ecf20Sopenharmony_civoid ubifs_set_inode_flags(struct inode *inode);
20628c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
20638c2ecf20Sopenharmony_cilong ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
20648c2ecf20Sopenharmony_ci#endif
20658c2ecf20Sopenharmony_ci
20668c2ecf20Sopenharmony_ci/* compressor.c */
20678c2ecf20Sopenharmony_ciint __init ubifs_compressors_init(void);
20688c2ecf20Sopenharmony_civoid ubifs_compressors_exit(void);
20698c2ecf20Sopenharmony_civoid ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
20708c2ecf20Sopenharmony_ci		    void *out_buf, int *out_len, int *compr_type);
20718c2ecf20Sopenharmony_ciint ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
20728c2ecf20Sopenharmony_ci		     void *out, int *out_len, int compr_type);
20738c2ecf20Sopenharmony_ci
20748c2ecf20Sopenharmony_ci#include "debug.h"
20758c2ecf20Sopenharmony_ci#include "misc.h"
20768c2ecf20Sopenharmony_ci#include "key.h"
20778c2ecf20Sopenharmony_ci
20788c2ecf20Sopenharmony_ci#ifndef CONFIG_FS_ENCRYPTION
20798c2ecf20Sopenharmony_cistatic inline int ubifs_encrypt(const struct inode *inode,
20808c2ecf20Sopenharmony_ci				struct ubifs_data_node *dn,
20818c2ecf20Sopenharmony_ci				unsigned int in_len, unsigned int *out_len,
20828c2ecf20Sopenharmony_ci				int block)
20838c2ecf20Sopenharmony_ci{
20848c2ecf20Sopenharmony_ci	struct ubifs_info *c = inode->i_sb->s_fs_info;
20858c2ecf20Sopenharmony_ci	ubifs_assert(c, 0);
20868c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
20878c2ecf20Sopenharmony_ci}
20888c2ecf20Sopenharmony_cistatic inline int ubifs_decrypt(const struct inode *inode,
20898c2ecf20Sopenharmony_ci				struct ubifs_data_node *dn,
20908c2ecf20Sopenharmony_ci				unsigned int *out_len, int block)
20918c2ecf20Sopenharmony_ci{
20928c2ecf20Sopenharmony_ci	struct ubifs_info *c = inode->i_sb->s_fs_info;
20938c2ecf20Sopenharmony_ci	ubifs_assert(c, 0);
20948c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
20958c2ecf20Sopenharmony_ci}
20968c2ecf20Sopenharmony_ci#else
20978c2ecf20Sopenharmony_ci/* crypto.c */
20988c2ecf20Sopenharmony_ciint ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
20998c2ecf20Sopenharmony_ci		  unsigned int in_len, unsigned int *out_len, int block);
21008c2ecf20Sopenharmony_ciint ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
21018c2ecf20Sopenharmony_ci		  unsigned int *out_len, int block);
21028c2ecf20Sopenharmony_ci#endif
21038c2ecf20Sopenharmony_ci
21048c2ecf20Sopenharmony_ciextern const struct fscrypt_operations ubifs_crypt_operations;
21058c2ecf20Sopenharmony_ci
21068c2ecf20Sopenharmony_ci/* Normal UBIFS messages */
21078c2ecf20Sopenharmony_ci__printf(2, 3)
21088c2ecf20Sopenharmony_civoid ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
21098c2ecf20Sopenharmony_ci__printf(2, 3)
21108c2ecf20Sopenharmony_civoid ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
21118c2ecf20Sopenharmony_ci__printf(2, 3)
21128c2ecf20Sopenharmony_civoid ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
21138c2ecf20Sopenharmony_ci/*
21148c2ecf20Sopenharmony_ci * A conditional variant of 'ubifs_err()' which doesn't output anything
21158c2ecf20Sopenharmony_ci * if probing (ie. SB_SILENT set).
21168c2ecf20Sopenharmony_ci */
21178c2ecf20Sopenharmony_ci#define ubifs_errc(c, fmt, ...)						\
21188c2ecf20Sopenharmony_cido {									\
21198c2ecf20Sopenharmony_ci	if (!(c)->probing)						\
21208c2ecf20Sopenharmony_ci		ubifs_err(c, fmt, ##__VA_ARGS__);			\
21218c2ecf20Sopenharmony_ci} while (0)
21228c2ecf20Sopenharmony_ci
21238c2ecf20Sopenharmony_ci#endif /* !__UBIFS_H__ */
2124