162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * This file is part of UBIFS. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2006-2008 Nokia Corporation 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Authors: Artem Bityutskiy (Битюцкий Артём) 862306a36Sopenharmony_ci * Adrian Hunter 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef __UBIFS_H__ 1262306a36Sopenharmony_ci#define __UBIFS_H__ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <asm/div64.h> 1562306a36Sopenharmony_ci#include <linux/statfs.h> 1662306a36Sopenharmony_ci#include <linux/fs.h> 1762306a36Sopenharmony_ci#include <linux/err.h> 1862306a36Sopenharmony_ci#include <linux/sched.h> 1962306a36Sopenharmony_ci#include <linux/slab.h> 2062306a36Sopenharmony_ci#include <linux/vmalloc.h> 2162306a36Sopenharmony_ci#include <linux/spinlock.h> 2262306a36Sopenharmony_ci#include <linux/mutex.h> 2362306a36Sopenharmony_ci#include <linux/rwsem.h> 2462306a36Sopenharmony_ci#include <linux/mtd/ubi.h> 2562306a36Sopenharmony_ci#include <linux/pagemap.h> 2662306a36Sopenharmony_ci#include <linux/backing-dev.h> 2762306a36Sopenharmony_ci#include <linux/security.h> 2862306a36Sopenharmony_ci#include <linux/xattr.h> 2962306a36Sopenharmony_ci#include <linux/random.h> 3062306a36Sopenharmony_ci#include <linux/sysfs.h> 3162306a36Sopenharmony_ci#include <linux/completion.h> 3262306a36Sopenharmony_ci#include <crypto/hash_info.h> 3362306a36Sopenharmony_ci#include <crypto/hash.h> 3462306a36Sopenharmony_ci#include <crypto/algapi.h> 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#include <linux/fscrypt.h> 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#include "ubifs-media.h" 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* Version of this UBIFS implementation */ 4162306a36Sopenharmony_ci#define UBIFS_VERSION 1 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* UBIFS file system VFS magic number */ 4462306a36Sopenharmony_ci#define UBIFS_SUPER_MAGIC 0x24051905 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/* Number of UBIFS blocks per VFS page */ 4762306a36Sopenharmony_ci#define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE) 4862306a36Sopenharmony_ci#define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* "File system end of life" sequence number watermark */ 5162306a36Sopenharmony_ci#define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL 5262306a36Sopenharmony_ci#define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* 5562306a36Sopenharmony_ci * Minimum amount of LEBs reserved for the index. At present the index needs at 5662306a36Sopenharmony_ci * least 2 LEBs: one for the index head and one for in-the-gaps method (which 5762306a36Sopenharmony_ci * currently does not cater for the index head and so excludes it from 5862306a36Sopenharmony_ci * consideration). 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_ci#define MIN_INDEX_LEBS 2 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* Minimum amount of data UBIFS writes to the flash */ 6362306a36Sopenharmony_ci#define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* 6662306a36Sopenharmony_ci * Currently we do not support inode number overlapping and re-using, so this 6762306a36Sopenharmony_ci * watermark defines dangerous inode number level. This should be fixed later, 6862306a36Sopenharmony_ci * although it is difficult to exceed current limit. Another option is to use 6962306a36Sopenharmony_ci * 64-bit inode numbers, but this means more overhead. 7062306a36Sopenharmony_ci */ 7162306a36Sopenharmony_ci#define INUM_WARN_WATERMARK 0xFFF00000 7262306a36Sopenharmony_ci#define INUM_WATERMARK 0xFFFFFF00 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* Maximum number of entries in each LPT (LEB category) heap */ 7562306a36Sopenharmony_ci#define LPT_HEAP_SZ 256 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* 7862306a36Sopenharmony_ci * Background thread name pattern. The numbers are UBI device and volume 7962306a36Sopenharmony_ci * numbers. 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_ci#define BGT_NAME_PATTERN "ubifs_bgt%d_%d" 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/* Maximum possible inode number (only 32-bit inodes are supported now) */ 8462306a36Sopenharmony_ci#define MAX_INUM 0xFFFFFFFF 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* Number of non-data journal heads */ 8762306a36Sopenharmony_ci#define NONDATA_JHEADS_CNT 2 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* Shorter names for journal head numbers for internal usage */ 9062306a36Sopenharmony_ci#define GCHD UBIFS_GC_HEAD 9162306a36Sopenharmony_ci#define BASEHD UBIFS_BASE_HEAD 9262306a36Sopenharmony_ci#define DATAHD UBIFS_DATA_HEAD 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* 'No change' value for 'ubifs_change_lp()' */ 9562306a36Sopenharmony_ci#define LPROPS_NC 0x80000001 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* 9862306a36Sopenharmony_ci * There is no notion of truncation key because truncation nodes do not exist 9962306a36Sopenharmony_ci * in TNC. However, when replaying, it is handy to introduce fake "truncation" 10062306a36Sopenharmony_ci * keys for truncation nodes because the code becomes simpler. So we define 10162306a36Sopenharmony_ci * %UBIFS_TRUN_KEY type. 10262306a36Sopenharmony_ci * 10362306a36Sopenharmony_ci * But otherwise, out of the journal reply scope, the truncation keys are 10462306a36Sopenharmony_ci * invalid. 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_ci#define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT 10762306a36Sopenharmony_ci#define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/* 11062306a36Sopenharmony_ci * How much a directory entry/extended attribute entry adds to the parent/host 11162306a36Sopenharmony_ci * inode. 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_ci#define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8) 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/* How much an extended attribute adds to the host inode */ 11662306a36Sopenharmony_ci#define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci/* 11962306a36Sopenharmony_ci * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered 12062306a36Sopenharmony_ci * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are 12162306a36Sopenharmony_ci * considered "young". This is used by shrinker when selecting znode to trim 12262306a36Sopenharmony_ci * off. 12362306a36Sopenharmony_ci */ 12462306a36Sopenharmony_ci#define OLD_ZNODE_AGE 20 12562306a36Sopenharmony_ci#define YOUNG_ZNODE_AGE 5 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci/* 12862306a36Sopenharmony_ci * Some compressors, like LZO, may end up with more data then the input buffer. 12962306a36Sopenharmony_ci * So UBIFS always allocates larger output buffer, to be sure the compressor 13062306a36Sopenharmony_ci * will not corrupt memory in case of worst case compression. 13162306a36Sopenharmony_ci */ 13262306a36Sopenharmony_ci#define WORST_COMPR_FACTOR 2 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION 13562306a36Sopenharmony_ci#define UBIFS_CIPHER_BLOCK_SIZE FSCRYPT_CONTENTS_ALIGNMENT 13662306a36Sopenharmony_ci#else 13762306a36Sopenharmony_ci#define UBIFS_CIPHER_BLOCK_SIZE 0 13862306a36Sopenharmony_ci#endif 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci/* 14162306a36Sopenharmony_ci * How much memory is needed for a buffer where we compress a data node. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_ci#define COMPRESSED_DATA_NODE_BUF_SZ \ 14462306a36Sopenharmony_ci (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/* Maximum expected tree height for use by bottom_up_buf */ 14762306a36Sopenharmony_ci#define BOTTOM_UP_HEIGHT 64 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci/* Maximum number of data nodes to bulk-read */ 15062306a36Sopenharmony_ci#define UBIFS_MAX_BULK_READ 32 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_AUTHENTICATION 15362306a36Sopenharmony_ci#define UBIFS_HASH_ARR_SZ UBIFS_MAX_HASH_LEN 15462306a36Sopenharmony_ci#define UBIFS_HMAC_ARR_SZ UBIFS_MAX_HMAC_LEN 15562306a36Sopenharmony_ci#else 15662306a36Sopenharmony_ci#define UBIFS_HASH_ARR_SZ 0 15762306a36Sopenharmony_ci#define UBIFS_HMAC_ARR_SZ 0 15862306a36Sopenharmony_ci#endif 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/* 16162306a36Sopenharmony_ci * The UBIFS sysfs directory name pattern and maximum name length (3 for "ubi" 16262306a36Sopenharmony_ci * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. 16362306a36Sopenharmony_ci */ 16462306a36Sopenharmony_ci#define UBIFS_DFS_DIR_NAME "ubi%d_%d" 16562306a36Sopenharmony_ci#define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1) 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/* 16862306a36Sopenharmony_ci * Lockdep classes for UBIFS inode @ui_mutex. 16962306a36Sopenharmony_ci */ 17062306a36Sopenharmony_cienum { 17162306a36Sopenharmony_ci WB_MUTEX_1 = 0, 17262306a36Sopenharmony_ci WB_MUTEX_2 = 1, 17362306a36Sopenharmony_ci WB_MUTEX_3 = 2, 17462306a36Sopenharmony_ci WB_MUTEX_4 = 3, 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci/* 17862306a36Sopenharmony_ci * Znode flags (actually, bit numbers which store the flags). 17962306a36Sopenharmony_ci * 18062306a36Sopenharmony_ci * DIRTY_ZNODE: znode is dirty 18162306a36Sopenharmony_ci * COW_ZNODE: znode is being committed and a new instance of this znode has to 18262306a36Sopenharmony_ci * be created before changing this znode 18362306a36Sopenharmony_ci * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is 18462306a36Sopenharmony_ci * still in the commit list and the ongoing commit operation 18562306a36Sopenharmony_ci * will commit it, and delete this znode after it is done 18662306a36Sopenharmony_ci */ 18762306a36Sopenharmony_cienum { 18862306a36Sopenharmony_ci DIRTY_ZNODE = 0, 18962306a36Sopenharmony_ci COW_ZNODE = 1, 19062306a36Sopenharmony_ci OBSOLETE_ZNODE = 2, 19162306a36Sopenharmony_ci}; 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* 19462306a36Sopenharmony_ci * Commit states. 19562306a36Sopenharmony_ci * 19662306a36Sopenharmony_ci * COMMIT_RESTING: commit is not wanted 19762306a36Sopenharmony_ci * COMMIT_BACKGROUND: background commit has been requested 19862306a36Sopenharmony_ci * COMMIT_REQUIRED: commit is required 19962306a36Sopenharmony_ci * COMMIT_RUNNING_BACKGROUND: background commit is running 20062306a36Sopenharmony_ci * COMMIT_RUNNING_REQUIRED: commit is running and it is required 20162306a36Sopenharmony_ci * COMMIT_BROKEN: commit failed 20262306a36Sopenharmony_ci */ 20362306a36Sopenharmony_cienum { 20462306a36Sopenharmony_ci COMMIT_RESTING = 0, 20562306a36Sopenharmony_ci COMMIT_BACKGROUND, 20662306a36Sopenharmony_ci COMMIT_REQUIRED, 20762306a36Sopenharmony_ci COMMIT_RUNNING_BACKGROUND, 20862306a36Sopenharmony_ci COMMIT_RUNNING_REQUIRED, 20962306a36Sopenharmony_ci COMMIT_BROKEN, 21062306a36Sopenharmony_ci}; 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci/* 21362306a36Sopenharmony_ci * 'ubifs_scan_a_node()' return values. 21462306a36Sopenharmony_ci * 21562306a36Sopenharmony_ci * SCANNED_GARBAGE: scanned garbage 21662306a36Sopenharmony_ci * SCANNED_EMPTY_SPACE: scanned empty space 21762306a36Sopenharmony_ci * SCANNED_A_NODE: scanned a valid node 21862306a36Sopenharmony_ci * SCANNED_A_CORRUPT_NODE: scanned a corrupted node 21962306a36Sopenharmony_ci * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length 22062306a36Sopenharmony_ci * 22162306a36Sopenharmony_ci * Greater than zero means: 'scanned that number of padding bytes' 22262306a36Sopenharmony_ci */ 22362306a36Sopenharmony_cienum { 22462306a36Sopenharmony_ci SCANNED_GARBAGE = 0, 22562306a36Sopenharmony_ci SCANNED_EMPTY_SPACE = -1, 22662306a36Sopenharmony_ci SCANNED_A_NODE = -2, 22762306a36Sopenharmony_ci SCANNED_A_CORRUPT_NODE = -3, 22862306a36Sopenharmony_ci SCANNED_A_BAD_PAD_NODE = -4, 22962306a36Sopenharmony_ci}; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci/* 23262306a36Sopenharmony_ci * LPT cnode flag bits. 23362306a36Sopenharmony_ci * 23462306a36Sopenharmony_ci * DIRTY_CNODE: cnode is dirty 23562306a36Sopenharmony_ci * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted), 23662306a36Sopenharmony_ci * so it can (and must) be freed when the commit is finished 23762306a36Sopenharmony_ci * COW_CNODE: cnode is being committed and must be copied before writing 23862306a36Sopenharmony_ci */ 23962306a36Sopenharmony_cienum { 24062306a36Sopenharmony_ci DIRTY_CNODE = 0, 24162306a36Sopenharmony_ci OBSOLETE_CNODE = 1, 24262306a36Sopenharmony_ci COW_CNODE = 2, 24362306a36Sopenharmony_ci}; 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci/* 24662306a36Sopenharmony_ci * Dirty flag bits (lpt_drty_flgs) for LPT special nodes. 24762306a36Sopenharmony_ci * 24862306a36Sopenharmony_ci * LTAB_DIRTY: ltab node is dirty 24962306a36Sopenharmony_ci * LSAVE_DIRTY: lsave node is dirty 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_cienum { 25262306a36Sopenharmony_ci LTAB_DIRTY = 1, 25362306a36Sopenharmony_ci LSAVE_DIRTY = 2, 25462306a36Sopenharmony_ci}; 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci/* 25762306a36Sopenharmony_ci * Return codes used by the garbage collector. 25862306a36Sopenharmony_ci * @LEB_FREED: the logical eraseblock was freed and is ready to use 25962306a36Sopenharmony_ci * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit 26062306a36Sopenharmony_ci * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes 26162306a36Sopenharmony_ci */ 26262306a36Sopenharmony_cienum { 26362306a36Sopenharmony_ci LEB_FREED, 26462306a36Sopenharmony_ci LEB_FREED_IDX, 26562306a36Sopenharmony_ci LEB_RETAINED, 26662306a36Sopenharmony_ci}; 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci/* 26962306a36Sopenharmony_ci * Action taken upon a failed ubifs_assert(). 27062306a36Sopenharmony_ci * @ASSACT_REPORT: just report the failed assertion 27162306a36Sopenharmony_ci * @ASSACT_RO: switch to read-only mode 27262306a36Sopenharmony_ci * @ASSACT_PANIC: call BUG() and possible panic the kernel 27362306a36Sopenharmony_ci */ 27462306a36Sopenharmony_cienum { 27562306a36Sopenharmony_ci ASSACT_REPORT = 0, 27662306a36Sopenharmony_ci ASSACT_RO, 27762306a36Sopenharmony_ci ASSACT_PANIC, 27862306a36Sopenharmony_ci}; 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci/** 28162306a36Sopenharmony_ci * struct ubifs_old_idx - index node obsoleted since last commit start. 28262306a36Sopenharmony_ci * @rb: rb-tree node 28362306a36Sopenharmony_ci * @lnum: LEB number of obsoleted index node 28462306a36Sopenharmony_ci * @offs: offset of obsoleted index node 28562306a36Sopenharmony_ci */ 28662306a36Sopenharmony_cistruct ubifs_old_idx { 28762306a36Sopenharmony_ci struct rb_node rb; 28862306a36Sopenharmony_ci int lnum; 28962306a36Sopenharmony_ci int offs; 29062306a36Sopenharmony_ci}; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci/* The below union makes it easier to deal with keys */ 29362306a36Sopenharmony_ciunion ubifs_key { 29462306a36Sopenharmony_ci uint8_t u8[UBIFS_SK_LEN]; 29562306a36Sopenharmony_ci uint32_t u32[UBIFS_SK_LEN/4]; 29662306a36Sopenharmony_ci uint64_t u64[UBIFS_SK_LEN/8]; 29762306a36Sopenharmony_ci __le32 j32[UBIFS_SK_LEN/4]; 29862306a36Sopenharmony_ci}; 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci/** 30162306a36Sopenharmony_ci * struct ubifs_scan_node - UBIFS scanned node information. 30262306a36Sopenharmony_ci * @list: list of scanned nodes 30362306a36Sopenharmony_ci * @key: key of node scanned (if it has one) 30462306a36Sopenharmony_ci * @sqnum: sequence number 30562306a36Sopenharmony_ci * @type: type of node scanned 30662306a36Sopenharmony_ci * @offs: offset with LEB of node scanned 30762306a36Sopenharmony_ci * @len: length of node scanned 30862306a36Sopenharmony_ci * @node: raw node 30962306a36Sopenharmony_ci */ 31062306a36Sopenharmony_cistruct ubifs_scan_node { 31162306a36Sopenharmony_ci struct list_head list; 31262306a36Sopenharmony_ci union ubifs_key key; 31362306a36Sopenharmony_ci unsigned long long sqnum; 31462306a36Sopenharmony_ci int type; 31562306a36Sopenharmony_ci int offs; 31662306a36Sopenharmony_ci int len; 31762306a36Sopenharmony_ci void *node; 31862306a36Sopenharmony_ci}; 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci/** 32162306a36Sopenharmony_ci * struct ubifs_scan_leb - UBIFS scanned LEB information. 32262306a36Sopenharmony_ci * @lnum: logical eraseblock number 32362306a36Sopenharmony_ci * @nodes_cnt: number of nodes scanned 32462306a36Sopenharmony_ci * @nodes: list of struct ubifs_scan_node 32562306a36Sopenharmony_ci * @endpt: end point (and therefore the start of empty space) 32662306a36Sopenharmony_ci * @buf: buffer containing entire LEB scanned 32762306a36Sopenharmony_ci */ 32862306a36Sopenharmony_cistruct ubifs_scan_leb { 32962306a36Sopenharmony_ci int lnum; 33062306a36Sopenharmony_ci int nodes_cnt; 33162306a36Sopenharmony_ci struct list_head nodes; 33262306a36Sopenharmony_ci int endpt; 33362306a36Sopenharmony_ci void *buf; 33462306a36Sopenharmony_ci}; 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_ci/** 33762306a36Sopenharmony_ci * struct ubifs_gced_idx_leb - garbage-collected indexing LEB. 33862306a36Sopenharmony_ci * @list: list 33962306a36Sopenharmony_ci * @lnum: LEB number 34062306a36Sopenharmony_ci * @unmap: OK to unmap this LEB 34162306a36Sopenharmony_ci * 34262306a36Sopenharmony_ci * This data structure is used to temporary store garbage-collected indexing 34362306a36Sopenharmony_ci * LEBs - they are not released immediately, but only after the next commit. 34462306a36Sopenharmony_ci * This is needed to guarantee recoverability. 34562306a36Sopenharmony_ci */ 34662306a36Sopenharmony_cistruct ubifs_gced_idx_leb { 34762306a36Sopenharmony_ci struct list_head list; 34862306a36Sopenharmony_ci int lnum; 34962306a36Sopenharmony_ci int unmap; 35062306a36Sopenharmony_ci}; 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci/** 35362306a36Sopenharmony_ci * struct ubifs_inode - UBIFS in-memory inode description. 35462306a36Sopenharmony_ci * @vfs_inode: VFS inode description object 35562306a36Sopenharmony_ci * @creat_sqnum: sequence number at time of creation 35662306a36Sopenharmony_ci * @del_cmtno: commit number corresponding to the time the inode was deleted, 35762306a36Sopenharmony_ci * protected by @c->commit_sem; 35862306a36Sopenharmony_ci * @xattr_size: summarized size of all extended attributes in bytes 35962306a36Sopenharmony_ci * @xattr_cnt: count of extended attributes this inode has 36062306a36Sopenharmony_ci * @xattr_names: sum of lengths of all extended attribute names belonging to 36162306a36Sopenharmony_ci * this inode 36262306a36Sopenharmony_ci * @dirty: non-zero if the inode is dirty 36362306a36Sopenharmony_ci * @xattr: non-zero if this is an extended attribute inode 36462306a36Sopenharmony_ci * @bulk_read: non-zero if bulk-read should be used 36562306a36Sopenharmony_ci * @ui_mutex: serializes inode write-back with the rest of VFS operations, 36662306a36Sopenharmony_ci * serializes "clean <-> dirty" state changes, serializes bulk-read, 36762306a36Sopenharmony_ci * protects @dirty, @bulk_read, @ui_size, and @xattr_size 36862306a36Sopenharmony_ci * @xattr_sem: serilizes write operations (remove|set|create) on xattr 36962306a36Sopenharmony_ci * @ui_lock: protects @synced_i_size 37062306a36Sopenharmony_ci * @synced_i_size: synchronized size of inode, i.e. the value of inode size 37162306a36Sopenharmony_ci * currently stored on the flash; used only for regular file 37262306a36Sopenharmony_ci * inodes 37362306a36Sopenharmony_ci * @ui_size: inode size used by UBIFS when writing to flash 37462306a36Sopenharmony_ci * @flags: inode flags (@UBIFS_COMPR_FL, etc) 37562306a36Sopenharmony_ci * @compr_type: default compression type used for this inode 37662306a36Sopenharmony_ci * @last_page_read: page number of last page read (for bulk read) 37762306a36Sopenharmony_ci * @read_in_a_row: number of consecutive pages read in a row (for bulk read) 37862306a36Sopenharmony_ci * @data_len: length of the data attached to the inode 37962306a36Sopenharmony_ci * @data: inode's data 38062306a36Sopenharmony_ci * 38162306a36Sopenharmony_ci * @ui_mutex exists for two main reasons. At first it prevents inodes from 38262306a36Sopenharmony_ci * being written back while UBIFS changing them, being in the middle of an VFS 38362306a36Sopenharmony_ci * operation. This way UBIFS makes sure the inode fields are consistent. For 38462306a36Sopenharmony_ci * example, in 'ubifs_rename()' we change 4 inodes simultaneously, and 38562306a36Sopenharmony_ci * write-back must not write any of them before we have finished. 38662306a36Sopenharmony_ci * 38762306a36Sopenharmony_ci * The second reason is budgeting - UBIFS has to budget all operations. If an 38862306a36Sopenharmony_ci * operation is going to mark an inode dirty, it has to allocate budget for 38962306a36Sopenharmony_ci * this. It cannot just mark it dirty because there is no guarantee there will 39062306a36Sopenharmony_ci * be enough flash space to write the inode back later. This means UBIFS has 39162306a36Sopenharmony_ci * to have full control over inode "clean <-> dirty" transitions (and pages 39262306a36Sopenharmony_ci * actually). But unfortunately, VFS marks inodes dirty in many places, and it 39362306a36Sopenharmony_ci * does not ask the file-system if it is allowed to do so (there is a notifier, 39462306a36Sopenharmony_ci * but it is not enough), i.e., there is no mechanism to synchronize with this. 39562306a36Sopenharmony_ci * So UBIFS has its own inode dirty flag and its own mutex to serialize 39662306a36Sopenharmony_ci * "clean <-> dirty" transitions. 39762306a36Sopenharmony_ci * 39862306a36Sopenharmony_ci * The @synced_i_size field is used to make sure we never write pages which are 39962306a36Sopenharmony_ci * beyond last synchronized inode size. See 'ubifs_writepage()' for more 40062306a36Sopenharmony_ci * information. 40162306a36Sopenharmony_ci * 40262306a36Sopenharmony_ci * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses 40362306a36Sopenharmony_ci * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot 40462306a36Sopenharmony_ci * make sure @inode->i_size is always changed under @ui_mutex, because it 40562306a36Sopenharmony_ci * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would 40662306a36Sopenharmony_ci * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields 40762306a36Sopenharmony_ci * are changed under @ui_mutex, so they do not need "shadow" fields. Note, one 40862306a36Sopenharmony_ci * could consider to rework locking and base it on "shadow" fields. 40962306a36Sopenharmony_ci */ 41062306a36Sopenharmony_cistruct ubifs_inode { 41162306a36Sopenharmony_ci struct inode vfs_inode; 41262306a36Sopenharmony_ci unsigned long long creat_sqnum; 41362306a36Sopenharmony_ci unsigned long long del_cmtno; 41462306a36Sopenharmony_ci unsigned int xattr_size; 41562306a36Sopenharmony_ci unsigned int xattr_cnt; 41662306a36Sopenharmony_ci unsigned int xattr_names; 41762306a36Sopenharmony_ci unsigned int dirty:1; 41862306a36Sopenharmony_ci unsigned int xattr:1; 41962306a36Sopenharmony_ci unsigned int bulk_read:1; 42062306a36Sopenharmony_ci unsigned int compr_type:2; 42162306a36Sopenharmony_ci struct mutex ui_mutex; 42262306a36Sopenharmony_ci struct rw_semaphore xattr_sem; 42362306a36Sopenharmony_ci spinlock_t ui_lock; 42462306a36Sopenharmony_ci loff_t synced_i_size; 42562306a36Sopenharmony_ci loff_t ui_size; 42662306a36Sopenharmony_ci int flags; 42762306a36Sopenharmony_ci pgoff_t last_page_read; 42862306a36Sopenharmony_ci pgoff_t read_in_a_row; 42962306a36Sopenharmony_ci int data_len; 43062306a36Sopenharmony_ci void *data; 43162306a36Sopenharmony_ci}; 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_ci/** 43462306a36Sopenharmony_ci * struct ubifs_unclean_leb - records a LEB recovered under read-only mode. 43562306a36Sopenharmony_ci * @list: list 43662306a36Sopenharmony_ci * @lnum: LEB number of recovered LEB 43762306a36Sopenharmony_ci * @endpt: offset where recovery ended 43862306a36Sopenharmony_ci * 43962306a36Sopenharmony_ci * This structure records a LEB identified during recovery that needs to be 44062306a36Sopenharmony_ci * cleaned but was not because UBIFS was mounted read-only. The information 44162306a36Sopenharmony_ci * is used to clean the LEB when remounting to read-write mode. 44262306a36Sopenharmony_ci */ 44362306a36Sopenharmony_cistruct ubifs_unclean_leb { 44462306a36Sopenharmony_ci struct list_head list; 44562306a36Sopenharmony_ci int lnum; 44662306a36Sopenharmony_ci int endpt; 44762306a36Sopenharmony_ci}; 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci/* 45062306a36Sopenharmony_ci * LEB properties flags. 45162306a36Sopenharmony_ci * 45262306a36Sopenharmony_ci * LPROPS_UNCAT: not categorized 45362306a36Sopenharmony_ci * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index 45462306a36Sopenharmony_ci * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index 45562306a36Sopenharmony_ci * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index 45662306a36Sopenharmony_ci * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs 45762306a36Sopenharmony_ci * LPROPS_EMPTY: LEB is empty, not taken 45862306a36Sopenharmony_ci * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken 45962306a36Sopenharmony_ci * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken 46062306a36Sopenharmony_ci * LPROPS_CAT_MASK: mask for the LEB categories above 46162306a36Sopenharmony_ci * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media) 46262306a36Sopenharmony_ci * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash) 46362306a36Sopenharmony_ci */ 46462306a36Sopenharmony_cienum { 46562306a36Sopenharmony_ci LPROPS_UNCAT = 0, 46662306a36Sopenharmony_ci LPROPS_DIRTY = 1, 46762306a36Sopenharmony_ci LPROPS_DIRTY_IDX = 2, 46862306a36Sopenharmony_ci LPROPS_FREE = 3, 46962306a36Sopenharmony_ci LPROPS_HEAP_CNT = 3, 47062306a36Sopenharmony_ci LPROPS_EMPTY = 4, 47162306a36Sopenharmony_ci LPROPS_FREEABLE = 5, 47262306a36Sopenharmony_ci LPROPS_FRDI_IDX = 6, 47362306a36Sopenharmony_ci LPROPS_CAT_MASK = 15, 47462306a36Sopenharmony_ci LPROPS_TAKEN = 16, 47562306a36Sopenharmony_ci LPROPS_INDEX = 32, 47662306a36Sopenharmony_ci}; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci/** 47962306a36Sopenharmony_ci * struct ubifs_lprops - logical eraseblock properties. 48062306a36Sopenharmony_ci * @free: amount of free space in bytes 48162306a36Sopenharmony_ci * @dirty: amount of dirty space in bytes 48262306a36Sopenharmony_ci * @flags: LEB properties flags (see above) 48362306a36Sopenharmony_ci * @lnum: LEB number 48462306a36Sopenharmony_ci * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE) 48562306a36Sopenharmony_ci * @hpos: heap position in heap of same-category lprops (other categories) 48662306a36Sopenharmony_ci */ 48762306a36Sopenharmony_cistruct ubifs_lprops { 48862306a36Sopenharmony_ci int free; 48962306a36Sopenharmony_ci int dirty; 49062306a36Sopenharmony_ci int flags; 49162306a36Sopenharmony_ci int lnum; 49262306a36Sopenharmony_ci union { 49362306a36Sopenharmony_ci struct list_head list; 49462306a36Sopenharmony_ci int hpos; 49562306a36Sopenharmony_ci }; 49662306a36Sopenharmony_ci}; 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci/** 49962306a36Sopenharmony_ci * struct ubifs_lpt_lprops - LPT logical eraseblock properties. 50062306a36Sopenharmony_ci * @free: amount of free space in bytes 50162306a36Sopenharmony_ci * @dirty: amount of dirty space in bytes 50262306a36Sopenharmony_ci * @tgc: trivial GC flag (1 => unmap after commit end) 50362306a36Sopenharmony_ci * @cmt: commit flag (1 => reserved for commit) 50462306a36Sopenharmony_ci */ 50562306a36Sopenharmony_cistruct ubifs_lpt_lprops { 50662306a36Sopenharmony_ci int free; 50762306a36Sopenharmony_ci int dirty; 50862306a36Sopenharmony_ci unsigned tgc:1; 50962306a36Sopenharmony_ci unsigned cmt:1; 51062306a36Sopenharmony_ci}; 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci/** 51362306a36Sopenharmony_ci * struct ubifs_lp_stats - statistics of eraseblocks in the main area. 51462306a36Sopenharmony_ci * @empty_lebs: number of empty LEBs 51562306a36Sopenharmony_ci * @taken_empty_lebs: number of taken LEBs 51662306a36Sopenharmony_ci * @idx_lebs: number of indexing LEBs 51762306a36Sopenharmony_ci * @total_free: total free space in bytes (includes all LEBs) 51862306a36Sopenharmony_ci * @total_dirty: total dirty space in bytes (includes all LEBs) 51962306a36Sopenharmony_ci * @total_used: total used space in bytes (does not include index LEBs) 52062306a36Sopenharmony_ci * @total_dead: total dead space in bytes (does not include index LEBs) 52162306a36Sopenharmony_ci * @total_dark: total dark space in bytes (does not include index LEBs) 52262306a36Sopenharmony_ci * 52362306a36Sopenharmony_ci * The @taken_empty_lebs field counts the LEBs that are in the transient state 52462306a36Sopenharmony_ci * of having been "taken" for use but not yet written to. @taken_empty_lebs is 52562306a36Sopenharmony_ci * needed to account correctly for @gc_lnum, otherwise @empty_lebs could be 52662306a36Sopenharmony_ci * used by itself (in which case 'unused_lebs' would be a better name). In the 52762306a36Sopenharmony_ci * case of @gc_lnum, it is "taken" at mount time or whenever a LEB is retained 52862306a36Sopenharmony_ci * by GC, but unlike other empty LEBs that are "taken", it may not be written 52962306a36Sopenharmony_ci * straight away (i.e. before the next commit start or unmount), so either 53062306a36Sopenharmony_ci * @gc_lnum must be specially accounted for, or the current approach followed 53162306a36Sopenharmony_ci * i.e. count it under @taken_empty_lebs. 53262306a36Sopenharmony_ci * 53362306a36Sopenharmony_ci * @empty_lebs includes @taken_empty_lebs. 53462306a36Sopenharmony_ci * 53562306a36Sopenharmony_ci * @total_used, @total_dead and @total_dark fields do not account indexing 53662306a36Sopenharmony_ci * LEBs. 53762306a36Sopenharmony_ci */ 53862306a36Sopenharmony_cistruct ubifs_lp_stats { 53962306a36Sopenharmony_ci int empty_lebs; 54062306a36Sopenharmony_ci int taken_empty_lebs; 54162306a36Sopenharmony_ci int idx_lebs; 54262306a36Sopenharmony_ci long long total_free; 54362306a36Sopenharmony_ci long long total_dirty; 54462306a36Sopenharmony_ci long long total_used; 54562306a36Sopenharmony_ci long long total_dead; 54662306a36Sopenharmony_ci long long total_dark; 54762306a36Sopenharmony_ci}; 54862306a36Sopenharmony_ci 54962306a36Sopenharmony_cistruct ubifs_nnode; 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ci/** 55262306a36Sopenharmony_ci * struct ubifs_cnode - LEB Properties Tree common node. 55362306a36Sopenharmony_ci * @parent: parent nnode 55462306a36Sopenharmony_ci * @cnext: next cnode to commit 55562306a36Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) 55662306a36Sopenharmony_ci * @iip: index in parent 55762306a36Sopenharmony_ci * @level: level in the tree (zero for pnodes, greater than zero for nnodes) 55862306a36Sopenharmony_ci * @num: node number 55962306a36Sopenharmony_ci */ 56062306a36Sopenharmony_cistruct ubifs_cnode { 56162306a36Sopenharmony_ci struct ubifs_nnode *parent; 56262306a36Sopenharmony_ci struct ubifs_cnode *cnext; 56362306a36Sopenharmony_ci unsigned long flags; 56462306a36Sopenharmony_ci int iip; 56562306a36Sopenharmony_ci int level; 56662306a36Sopenharmony_ci int num; 56762306a36Sopenharmony_ci}; 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ci/** 57062306a36Sopenharmony_ci * struct ubifs_pnode - LEB Properties Tree leaf node. 57162306a36Sopenharmony_ci * @parent: parent nnode 57262306a36Sopenharmony_ci * @cnext: next cnode to commit 57362306a36Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) 57462306a36Sopenharmony_ci * @iip: index in parent 57562306a36Sopenharmony_ci * @level: level in the tree (always zero for pnodes) 57662306a36Sopenharmony_ci * @num: node number 57762306a36Sopenharmony_ci * @lprops: LEB properties array 57862306a36Sopenharmony_ci */ 57962306a36Sopenharmony_cistruct ubifs_pnode { 58062306a36Sopenharmony_ci struct ubifs_nnode *parent; 58162306a36Sopenharmony_ci struct ubifs_cnode *cnext; 58262306a36Sopenharmony_ci unsigned long flags; 58362306a36Sopenharmony_ci int iip; 58462306a36Sopenharmony_ci int level; 58562306a36Sopenharmony_ci int num; 58662306a36Sopenharmony_ci struct ubifs_lprops lprops[UBIFS_LPT_FANOUT]; 58762306a36Sopenharmony_ci}; 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_ci/** 59062306a36Sopenharmony_ci * struct ubifs_nbranch - LEB Properties Tree internal node branch. 59162306a36Sopenharmony_ci * @lnum: LEB number of child 59262306a36Sopenharmony_ci * @offs: offset of child 59362306a36Sopenharmony_ci * @nnode: nnode child 59462306a36Sopenharmony_ci * @pnode: pnode child 59562306a36Sopenharmony_ci * @cnode: cnode child 59662306a36Sopenharmony_ci */ 59762306a36Sopenharmony_cistruct ubifs_nbranch { 59862306a36Sopenharmony_ci int lnum; 59962306a36Sopenharmony_ci int offs; 60062306a36Sopenharmony_ci union { 60162306a36Sopenharmony_ci struct ubifs_nnode *nnode; 60262306a36Sopenharmony_ci struct ubifs_pnode *pnode; 60362306a36Sopenharmony_ci struct ubifs_cnode *cnode; 60462306a36Sopenharmony_ci }; 60562306a36Sopenharmony_ci}; 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_ci/** 60862306a36Sopenharmony_ci * struct ubifs_nnode - LEB Properties Tree internal node. 60962306a36Sopenharmony_ci * @parent: parent nnode 61062306a36Sopenharmony_ci * @cnext: next cnode to commit 61162306a36Sopenharmony_ci * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE) 61262306a36Sopenharmony_ci * @iip: index in parent 61362306a36Sopenharmony_ci * @level: level in the tree (always greater than zero for nnodes) 61462306a36Sopenharmony_ci * @num: node number 61562306a36Sopenharmony_ci * @nbranch: branches to child nodes 61662306a36Sopenharmony_ci */ 61762306a36Sopenharmony_cistruct ubifs_nnode { 61862306a36Sopenharmony_ci struct ubifs_nnode *parent; 61962306a36Sopenharmony_ci struct ubifs_cnode *cnext; 62062306a36Sopenharmony_ci unsigned long flags; 62162306a36Sopenharmony_ci int iip; 62262306a36Sopenharmony_ci int level; 62362306a36Sopenharmony_ci int num; 62462306a36Sopenharmony_ci struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT]; 62562306a36Sopenharmony_ci}; 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci/** 62862306a36Sopenharmony_ci * struct ubifs_lpt_heap - heap of categorized lprops. 62962306a36Sopenharmony_ci * @arr: heap array 63062306a36Sopenharmony_ci * @cnt: number in heap 63162306a36Sopenharmony_ci * @max_cnt: maximum number allowed in heap 63262306a36Sopenharmony_ci * 63362306a36Sopenharmony_ci * There are %LPROPS_HEAP_CNT heaps. 63462306a36Sopenharmony_ci */ 63562306a36Sopenharmony_cistruct ubifs_lpt_heap { 63662306a36Sopenharmony_ci struct ubifs_lprops **arr; 63762306a36Sopenharmony_ci int cnt; 63862306a36Sopenharmony_ci int max_cnt; 63962306a36Sopenharmony_ci}; 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ci/* 64262306a36Sopenharmony_ci * Return codes for LPT scan callback function. 64362306a36Sopenharmony_ci * 64462306a36Sopenharmony_ci * LPT_SCAN_CONTINUE: continue scanning 64562306a36Sopenharmony_ci * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory 64662306a36Sopenharmony_ci * LPT_SCAN_STOP: stop scanning 64762306a36Sopenharmony_ci */ 64862306a36Sopenharmony_cienum { 64962306a36Sopenharmony_ci LPT_SCAN_CONTINUE = 0, 65062306a36Sopenharmony_ci LPT_SCAN_ADD = 1, 65162306a36Sopenharmony_ci LPT_SCAN_STOP = 2, 65262306a36Sopenharmony_ci}; 65362306a36Sopenharmony_ci 65462306a36Sopenharmony_cistruct ubifs_info; 65562306a36Sopenharmony_ci 65662306a36Sopenharmony_ci/* Callback used by the 'ubifs_lpt_scan_nolock()' function */ 65762306a36Sopenharmony_citypedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c, 65862306a36Sopenharmony_ci const struct ubifs_lprops *lprops, 65962306a36Sopenharmony_ci int in_tree, void *data); 66062306a36Sopenharmony_ci 66162306a36Sopenharmony_ci/** 66262306a36Sopenharmony_ci * struct ubifs_wbuf - UBIFS write-buffer. 66362306a36Sopenharmony_ci * @c: UBIFS file-system description object 66462306a36Sopenharmony_ci * @buf: write-buffer (of min. flash I/O unit size) 66562306a36Sopenharmony_ci * @lnum: logical eraseblock number the write-buffer points to 66662306a36Sopenharmony_ci * @offs: write-buffer offset in this logical eraseblock 66762306a36Sopenharmony_ci * @avail: number of bytes available in the write-buffer 66862306a36Sopenharmony_ci * @used: number of used bytes in the write-buffer 66962306a36Sopenharmony_ci * @size: write-buffer size (in [@c->min_io_size, @c->max_write_size] range) 67062306a36Sopenharmony_ci * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep 67162306a36Sopenharmony_ci * up by 'mutex_lock_nested()). 67262306a36Sopenharmony_ci * @sync_callback: write-buffer synchronization callback 67362306a36Sopenharmony_ci * @io_mutex: serializes write-buffer I/O 67462306a36Sopenharmony_ci * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes 67562306a36Sopenharmony_ci * fields 67662306a36Sopenharmony_ci * @timer: write-buffer timer 67762306a36Sopenharmony_ci * @no_timer: non-zero if this write-buffer does not have a timer 67862306a36Sopenharmony_ci * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing 67962306a36Sopenharmony_ci * @next_ino: points to the next position of the following inode number 68062306a36Sopenharmony_ci * @inodes: stores the inode numbers of the nodes which are in wbuf 68162306a36Sopenharmony_ci * 68262306a36Sopenharmony_ci * The write-buffer synchronization callback is called when the write-buffer is 68362306a36Sopenharmony_ci * synchronized in order to notify how much space was wasted due to 68462306a36Sopenharmony_ci * write-buffer padding and how much free space is left in the LEB. 68562306a36Sopenharmony_ci * 68662306a36Sopenharmony_ci * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under 68762306a36Sopenharmony_ci * spin-lock or mutex because they are written under both mutex and spin-lock. 68862306a36Sopenharmony_ci * @buf is appended to under mutex but overwritten under both mutex and 68962306a36Sopenharmony_ci * spin-lock. Thus the data between @buf and @buf + @used can be read under 69062306a36Sopenharmony_ci * spinlock. 69162306a36Sopenharmony_ci */ 69262306a36Sopenharmony_cistruct ubifs_wbuf { 69362306a36Sopenharmony_ci struct ubifs_info *c; 69462306a36Sopenharmony_ci void *buf; 69562306a36Sopenharmony_ci int lnum; 69662306a36Sopenharmony_ci int offs; 69762306a36Sopenharmony_ci int avail; 69862306a36Sopenharmony_ci int used; 69962306a36Sopenharmony_ci int size; 70062306a36Sopenharmony_ci int jhead; 70162306a36Sopenharmony_ci int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); 70262306a36Sopenharmony_ci struct mutex io_mutex; 70362306a36Sopenharmony_ci spinlock_t lock; 70462306a36Sopenharmony_ci struct hrtimer timer; 70562306a36Sopenharmony_ci unsigned int no_timer:1; 70662306a36Sopenharmony_ci unsigned int need_sync:1; 70762306a36Sopenharmony_ci int next_ino; 70862306a36Sopenharmony_ci ino_t *inodes; 70962306a36Sopenharmony_ci}; 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/** 71262306a36Sopenharmony_ci * struct ubifs_bud - bud logical eraseblock. 71362306a36Sopenharmony_ci * @lnum: logical eraseblock number 71462306a36Sopenharmony_ci * @start: where the (uncommitted) bud data starts 71562306a36Sopenharmony_ci * @jhead: journal head number this bud belongs to 71662306a36Sopenharmony_ci * @list: link in the list buds belonging to the same journal head 71762306a36Sopenharmony_ci * @rb: link in the tree of all buds 71862306a36Sopenharmony_ci * @log_hash: the log hash from the commit start node up to this bud 71962306a36Sopenharmony_ci */ 72062306a36Sopenharmony_cistruct ubifs_bud { 72162306a36Sopenharmony_ci int lnum; 72262306a36Sopenharmony_ci int start; 72362306a36Sopenharmony_ci int jhead; 72462306a36Sopenharmony_ci struct list_head list; 72562306a36Sopenharmony_ci struct rb_node rb; 72662306a36Sopenharmony_ci struct shash_desc *log_hash; 72762306a36Sopenharmony_ci}; 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci/** 73062306a36Sopenharmony_ci * struct ubifs_jhead - journal head. 73162306a36Sopenharmony_ci * @wbuf: head's write-buffer 73262306a36Sopenharmony_ci * @buds_list: list of bud LEBs belonging to this journal head 73362306a36Sopenharmony_ci * @grouped: non-zero if UBIFS groups nodes when writing to this journal head 73462306a36Sopenharmony_ci * @log_hash: the log hash from the commit start node up to this journal head 73562306a36Sopenharmony_ci * 73662306a36Sopenharmony_ci * Note, the @buds list is protected by the @c->buds_lock. 73762306a36Sopenharmony_ci */ 73862306a36Sopenharmony_cistruct ubifs_jhead { 73962306a36Sopenharmony_ci struct ubifs_wbuf wbuf; 74062306a36Sopenharmony_ci struct list_head buds_list; 74162306a36Sopenharmony_ci unsigned int grouped:1; 74262306a36Sopenharmony_ci struct shash_desc *log_hash; 74362306a36Sopenharmony_ci}; 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ci/** 74662306a36Sopenharmony_ci * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. 74762306a36Sopenharmony_ci * @key: key 74862306a36Sopenharmony_ci * @znode: znode address in memory 74962306a36Sopenharmony_ci * @lnum: LEB number of the target node (indexing node or data node) 75062306a36Sopenharmony_ci * @offs: target node offset within @lnum 75162306a36Sopenharmony_ci * @len: target node length 75262306a36Sopenharmony_ci * @hash: the hash of the target node 75362306a36Sopenharmony_ci */ 75462306a36Sopenharmony_cistruct ubifs_zbranch { 75562306a36Sopenharmony_ci union ubifs_key key; 75662306a36Sopenharmony_ci union { 75762306a36Sopenharmony_ci struct ubifs_znode *znode; 75862306a36Sopenharmony_ci void *leaf; 75962306a36Sopenharmony_ci }; 76062306a36Sopenharmony_ci int lnum; 76162306a36Sopenharmony_ci int offs; 76262306a36Sopenharmony_ci int len; 76362306a36Sopenharmony_ci u8 hash[UBIFS_HASH_ARR_SZ]; 76462306a36Sopenharmony_ci}; 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci/** 76762306a36Sopenharmony_ci * struct ubifs_znode - in-memory representation of an indexing node. 76862306a36Sopenharmony_ci * @parent: parent znode or NULL if it is the root 76962306a36Sopenharmony_ci * @cnext: next znode to commit 77062306a36Sopenharmony_ci * @cparent: parent node for this commit 77162306a36Sopenharmony_ci * @ciip: index in cparent's zbranch array 77262306a36Sopenharmony_ci * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE) 77362306a36Sopenharmony_ci * @time: last access time (seconds) 77462306a36Sopenharmony_ci * @level: level of the entry in the TNC tree 77562306a36Sopenharmony_ci * @child_cnt: count of child znodes 77662306a36Sopenharmony_ci * @iip: index in parent's zbranch array 77762306a36Sopenharmony_ci * @alt: lower bound of key range has altered i.e. child inserted at slot 0 77862306a36Sopenharmony_ci * @lnum: LEB number of the corresponding indexing node 77962306a36Sopenharmony_ci * @offs: offset of the corresponding indexing node 78062306a36Sopenharmony_ci * @len: length of the corresponding indexing node 78162306a36Sopenharmony_ci * @zbranch: array of znode branches (@c->fanout elements) 78262306a36Sopenharmony_ci * 78362306a36Sopenharmony_ci * Note! The @lnum, @offs, and @len fields are not really needed - we have them 78462306a36Sopenharmony_ci * only for internal consistency check. They could be removed to save some RAM. 78562306a36Sopenharmony_ci */ 78662306a36Sopenharmony_cistruct ubifs_znode { 78762306a36Sopenharmony_ci struct ubifs_znode *parent; 78862306a36Sopenharmony_ci struct ubifs_znode *cnext; 78962306a36Sopenharmony_ci struct ubifs_znode *cparent; 79062306a36Sopenharmony_ci int ciip; 79162306a36Sopenharmony_ci unsigned long flags; 79262306a36Sopenharmony_ci time64_t time; 79362306a36Sopenharmony_ci int level; 79462306a36Sopenharmony_ci int child_cnt; 79562306a36Sopenharmony_ci int iip; 79662306a36Sopenharmony_ci int alt; 79762306a36Sopenharmony_ci int lnum; 79862306a36Sopenharmony_ci int offs; 79962306a36Sopenharmony_ci int len; 80062306a36Sopenharmony_ci struct ubifs_zbranch zbranch[]; 80162306a36Sopenharmony_ci}; 80262306a36Sopenharmony_ci 80362306a36Sopenharmony_ci/** 80462306a36Sopenharmony_ci * struct bu_info - bulk-read information. 80562306a36Sopenharmony_ci * @key: first data node key 80662306a36Sopenharmony_ci * @zbranch: zbranches of data nodes to bulk read 80762306a36Sopenharmony_ci * @buf: buffer to read into 80862306a36Sopenharmony_ci * @buf_len: buffer length 80962306a36Sopenharmony_ci * @gc_seq: GC sequence number to detect races with GC 81062306a36Sopenharmony_ci * @cnt: number of data nodes for bulk read 81162306a36Sopenharmony_ci * @blk_cnt: number of data blocks including holes 81262306a36Sopenharmony_ci * @oef: end of file reached 81362306a36Sopenharmony_ci */ 81462306a36Sopenharmony_cistruct bu_info { 81562306a36Sopenharmony_ci union ubifs_key key; 81662306a36Sopenharmony_ci struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ]; 81762306a36Sopenharmony_ci void *buf; 81862306a36Sopenharmony_ci int buf_len; 81962306a36Sopenharmony_ci int gc_seq; 82062306a36Sopenharmony_ci int cnt; 82162306a36Sopenharmony_ci int blk_cnt; 82262306a36Sopenharmony_ci int eof; 82362306a36Sopenharmony_ci}; 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_ci/** 82662306a36Sopenharmony_ci * struct ubifs_node_range - node length range description data structure. 82762306a36Sopenharmony_ci * @len: fixed node length 82862306a36Sopenharmony_ci * @min_len: minimum possible node length 82962306a36Sopenharmony_ci * @max_len: maximum possible node length 83062306a36Sopenharmony_ci * 83162306a36Sopenharmony_ci * If @max_len is %0, the node has fixed length @len. 83262306a36Sopenharmony_ci */ 83362306a36Sopenharmony_cistruct ubifs_node_range { 83462306a36Sopenharmony_ci union { 83562306a36Sopenharmony_ci int len; 83662306a36Sopenharmony_ci int min_len; 83762306a36Sopenharmony_ci }; 83862306a36Sopenharmony_ci int max_len; 83962306a36Sopenharmony_ci}; 84062306a36Sopenharmony_ci 84162306a36Sopenharmony_ci/** 84262306a36Sopenharmony_ci * struct ubifs_compressor - UBIFS compressor description structure. 84362306a36Sopenharmony_ci * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc) 84462306a36Sopenharmony_ci * @cc: cryptoapi compressor handle 84562306a36Sopenharmony_ci * @comp_mutex: mutex used during compression 84662306a36Sopenharmony_ci * @decomp_mutex: mutex used during decompression 84762306a36Sopenharmony_ci * @name: compressor name 84862306a36Sopenharmony_ci * @capi_name: cryptoapi compressor name 84962306a36Sopenharmony_ci */ 85062306a36Sopenharmony_cistruct ubifs_compressor { 85162306a36Sopenharmony_ci int compr_type; 85262306a36Sopenharmony_ci struct crypto_comp *cc; 85362306a36Sopenharmony_ci struct mutex *comp_mutex; 85462306a36Sopenharmony_ci struct mutex *decomp_mutex; 85562306a36Sopenharmony_ci const char *name; 85662306a36Sopenharmony_ci const char *capi_name; 85762306a36Sopenharmony_ci}; 85862306a36Sopenharmony_ci 85962306a36Sopenharmony_ci/** 86062306a36Sopenharmony_ci * struct ubifs_budget_req - budget requirements of an operation. 86162306a36Sopenharmony_ci * 86262306a36Sopenharmony_ci * @fast: non-zero if the budgeting should try to acquire budget quickly and 86362306a36Sopenharmony_ci * should not try to call write-back 86462306a36Sopenharmony_ci * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields 86562306a36Sopenharmony_ci * have to be re-calculated 86662306a36Sopenharmony_ci * @new_page: non-zero if the operation adds a new page 86762306a36Sopenharmony_ci * @dirtied_page: non-zero if the operation makes a page dirty 86862306a36Sopenharmony_ci * @new_dent: non-zero if the operation adds a new directory entry 86962306a36Sopenharmony_ci * @mod_dent: non-zero if the operation removes or modifies an existing 87062306a36Sopenharmony_ci * directory entry 87162306a36Sopenharmony_ci * @new_ino: non-zero if the operation adds a new inode 87262306a36Sopenharmony_ci * @new_ino_d: how much data newly created inode contains 87362306a36Sopenharmony_ci * @dirtied_ino: how many inodes the operation makes dirty 87462306a36Sopenharmony_ci * @dirtied_ino_d: how much data dirtied inode contains 87562306a36Sopenharmony_ci * @idx_growth: how much the index will supposedly grow 87662306a36Sopenharmony_ci * @data_growth: how much new data the operation will supposedly add 87762306a36Sopenharmony_ci * @dd_growth: how much data that makes other data dirty the operation will 87862306a36Sopenharmony_ci * supposedly add 87962306a36Sopenharmony_ci * 88062306a36Sopenharmony_ci * @idx_growth, @data_growth and @dd_growth are not used in budget request. The 88162306a36Sopenharmony_ci * budgeting subsystem caches index and data growth values there to avoid 88262306a36Sopenharmony_ci * re-calculating them when the budget is released. However, if @idx_growth is 88362306a36Sopenharmony_ci * %-1, it is calculated by the release function using other fields. 88462306a36Sopenharmony_ci * 88562306a36Sopenharmony_ci * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d 88662306a36Sopenharmony_ci * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made 88762306a36Sopenharmony_ci * dirty by the re-name operation. 88862306a36Sopenharmony_ci * 88962306a36Sopenharmony_ci * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to 89062306a36Sopenharmony_ci * make sure the amount of inode data which contribute to @new_ino_d and 89162306a36Sopenharmony_ci * @dirtied_ino_d fields are aligned. 89262306a36Sopenharmony_ci */ 89362306a36Sopenharmony_cistruct ubifs_budget_req { 89462306a36Sopenharmony_ci unsigned int fast:1; 89562306a36Sopenharmony_ci unsigned int recalculate:1; 89662306a36Sopenharmony_ci#ifndef UBIFS_DEBUG 89762306a36Sopenharmony_ci unsigned int new_page:1; 89862306a36Sopenharmony_ci unsigned int dirtied_page:1; 89962306a36Sopenharmony_ci unsigned int new_dent:1; 90062306a36Sopenharmony_ci unsigned int mod_dent:1; 90162306a36Sopenharmony_ci unsigned int new_ino:1; 90262306a36Sopenharmony_ci unsigned int new_ino_d:13; 90362306a36Sopenharmony_ci unsigned int dirtied_ino:4; 90462306a36Sopenharmony_ci unsigned int dirtied_ino_d:15; 90562306a36Sopenharmony_ci#else 90662306a36Sopenharmony_ci /* Not bit-fields to check for overflows */ 90762306a36Sopenharmony_ci unsigned int new_page; 90862306a36Sopenharmony_ci unsigned int dirtied_page; 90962306a36Sopenharmony_ci unsigned int new_dent; 91062306a36Sopenharmony_ci unsigned int mod_dent; 91162306a36Sopenharmony_ci unsigned int new_ino; 91262306a36Sopenharmony_ci unsigned int new_ino_d; 91362306a36Sopenharmony_ci unsigned int dirtied_ino; 91462306a36Sopenharmony_ci unsigned int dirtied_ino_d; 91562306a36Sopenharmony_ci#endif 91662306a36Sopenharmony_ci int idx_growth; 91762306a36Sopenharmony_ci int data_growth; 91862306a36Sopenharmony_ci int dd_growth; 91962306a36Sopenharmony_ci}; 92062306a36Sopenharmony_ci 92162306a36Sopenharmony_ci/** 92262306a36Sopenharmony_ci * struct ubifs_orphan - stores the inode number of an orphan. 92362306a36Sopenharmony_ci * @rb: rb-tree node of rb-tree of orphans sorted by inode number 92462306a36Sopenharmony_ci * @list: list head of list of orphans in order added 92562306a36Sopenharmony_ci * @new_list: list head of list of orphans added since the last commit 92662306a36Sopenharmony_ci * @child_list: list of xattr children if this orphan hosts xattrs, list head 92762306a36Sopenharmony_ci * if this orphan is a xattr, not used otherwise. 92862306a36Sopenharmony_ci * @cnext: next orphan to commit 92962306a36Sopenharmony_ci * @dnext: next orphan to delete 93062306a36Sopenharmony_ci * @inum: inode number 93162306a36Sopenharmony_ci * @new: %1 => added since the last commit, otherwise %0 93262306a36Sopenharmony_ci * @cmt: %1 => commit pending, otherwise %0 93362306a36Sopenharmony_ci * @del: %1 => delete pending, otherwise %0 93462306a36Sopenharmony_ci */ 93562306a36Sopenharmony_cistruct ubifs_orphan { 93662306a36Sopenharmony_ci struct rb_node rb; 93762306a36Sopenharmony_ci struct list_head list; 93862306a36Sopenharmony_ci struct list_head new_list; 93962306a36Sopenharmony_ci struct list_head child_list; 94062306a36Sopenharmony_ci struct ubifs_orphan *cnext; 94162306a36Sopenharmony_ci struct ubifs_orphan *dnext; 94262306a36Sopenharmony_ci ino_t inum; 94362306a36Sopenharmony_ci unsigned new:1; 94462306a36Sopenharmony_ci unsigned cmt:1; 94562306a36Sopenharmony_ci unsigned del:1; 94662306a36Sopenharmony_ci}; 94762306a36Sopenharmony_ci 94862306a36Sopenharmony_ci/** 94962306a36Sopenharmony_ci * struct ubifs_mount_opts - UBIFS-specific mount options information. 95062306a36Sopenharmony_ci * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast) 95162306a36Sopenharmony_ci * @bulk_read: enable/disable bulk-reads (%0 default, %1 disable, %2 enable) 95262306a36Sopenharmony_ci * @chk_data_crc: enable/disable CRC data checking when reading data nodes 95362306a36Sopenharmony_ci * (%0 default, %1 disable, %2 enable) 95462306a36Sopenharmony_ci * @override_compr: override default compressor (%0 - do not override and use 95562306a36Sopenharmony_ci * superblock compressor, %1 - override and use compressor 95662306a36Sopenharmony_ci * specified in @compr_type) 95762306a36Sopenharmony_ci * @compr_type: compressor type to override the superblock compressor with 95862306a36Sopenharmony_ci * (%UBIFS_COMPR_NONE, etc) 95962306a36Sopenharmony_ci */ 96062306a36Sopenharmony_cistruct ubifs_mount_opts { 96162306a36Sopenharmony_ci unsigned int unmount_mode:2; 96262306a36Sopenharmony_ci unsigned int bulk_read:2; 96362306a36Sopenharmony_ci unsigned int chk_data_crc:2; 96462306a36Sopenharmony_ci unsigned int override_compr:1; 96562306a36Sopenharmony_ci unsigned int compr_type:2; 96662306a36Sopenharmony_ci}; 96762306a36Sopenharmony_ci 96862306a36Sopenharmony_ci/** 96962306a36Sopenharmony_ci * struct ubifs_budg_info - UBIFS budgeting information. 97062306a36Sopenharmony_ci * @idx_growth: amount of bytes budgeted for index growth 97162306a36Sopenharmony_ci * @data_growth: amount of bytes budgeted for cached data 97262306a36Sopenharmony_ci * @dd_growth: amount of bytes budgeted for cached data that will make 97362306a36Sopenharmony_ci * other data dirty 97462306a36Sopenharmony_ci * @uncommitted_idx: amount of bytes were budgeted for growth of the index, but 97562306a36Sopenharmony_ci * which still have to be taken into account because the index 97662306a36Sopenharmony_ci * has not been committed so far 97762306a36Sopenharmony_ci * @old_idx_sz: size of index on flash 97862306a36Sopenharmony_ci * @min_idx_lebs: minimum number of LEBs required for the index 97962306a36Sopenharmony_ci * @nospace: non-zero if the file-system does not have flash space (used as 98062306a36Sopenharmony_ci * optimization) 98162306a36Sopenharmony_ci * @nospace_rp: the same as @nospace, but additionally means that even reserved 98262306a36Sopenharmony_ci * pool is full 98362306a36Sopenharmony_ci * @page_budget: budget for a page (constant, never changed after mount) 98462306a36Sopenharmony_ci * @inode_budget: budget for an inode (constant, never changed after mount) 98562306a36Sopenharmony_ci * @dent_budget: budget for a directory entry (constant, never changed after 98662306a36Sopenharmony_ci * mount) 98762306a36Sopenharmony_ci */ 98862306a36Sopenharmony_cistruct ubifs_budg_info { 98962306a36Sopenharmony_ci long long idx_growth; 99062306a36Sopenharmony_ci long long data_growth; 99162306a36Sopenharmony_ci long long dd_growth; 99262306a36Sopenharmony_ci long long uncommitted_idx; 99362306a36Sopenharmony_ci unsigned long long old_idx_sz; 99462306a36Sopenharmony_ci int min_idx_lebs; 99562306a36Sopenharmony_ci unsigned int nospace:1; 99662306a36Sopenharmony_ci unsigned int nospace_rp:1; 99762306a36Sopenharmony_ci int page_budget; 99862306a36Sopenharmony_ci int inode_budget; 99962306a36Sopenharmony_ci int dent_budget; 100062306a36Sopenharmony_ci}; 100162306a36Sopenharmony_ci 100262306a36Sopenharmony_ci/** 100362306a36Sopenharmony_ci * ubifs_stats_info - per-FS statistics information. 100462306a36Sopenharmony_ci * @magic_errors: number of bad magic numbers (will be reset with a new mount). 100562306a36Sopenharmony_ci * @node_errors: number of bad nodes (will be reset with a new mount). 100662306a36Sopenharmony_ci * @crc_errors: number of bad crcs (will be reset with a new mount). 100762306a36Sopenharmony_ci */ 100862306a36Sopenharmony_cistruct ubifs_stats_info { 100962306a36Sopenharmony_ci unsigned int magic_errors; 101062306a36Sopenharmony_ci unsigned int node_errors; 101162306a36Sopenharmony_ci unsigned int crc_errors; 101262306a36Sopenharmony_ci}; 101362306a36Sopenharmony_ci 101462306a36Sopenharmony_cistruct ubifs_debug_info; 101562306a36Sopenharmony_ci 101662306a36Sopenharmony_ci/** 101762306a36Sopenharmony_ci * struct ubifs_info - UBIFS file-system description data structure 101862306a36Sopenharmony_ci * (per-superblock). 101962306a36Sopenharmony_ci * @vfs_sb: VFS @struct super_block object 102062306a36Sopenharmony_ci * @sup_node: The super block node as read from the device 102162306a36Sopenharmony_ci * 102262306a36Sopenharmony_ci * @highest_inum: highest used inode number 102362306a36Sopenharmony_ci * @max_sqnum: current global sequence number 102462306a36Sopenharmony_ci * @cmt_no: commit number of the last successfully completed commit, protected 102562306a36Sopenharmony_ci * by @commit_sem 102662306a36Sopenharmony_ci * @cnt_lock: protects @highest_inum and @max_sqnum counters 102762306a36Sopenharmony_ci * @fmt_version: UBIFS on-flash format version 102862306a36Sopenharmony_ci * @ro_compat_version: R/O compatibility version 102962306a36Sopenharmony_ci * @uuid: UUID from super block 103062306a36Sopenharmony_ci * 103162306a36Sopenharmony_ci * @lhead_lnum: log head logical eraseblock number 103262306a36Sopenharmony_ci * @lhead_offs: log head offset 103362306a36Sopenharmony_ci * @ltail_lnum: log tail logical eraseblock number (offset is always 0) 103462306a36Sopenharmony_ci * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and 103562306a36Sopenharmony_ci * @bud_bytes 103662306a36Sopenharmony_ci * @min_log_bytes: minimum required number of bytes in the log 103762306a36Sopenharmony_ci * @cmt_bud_bytes: used during commit to temporarily amount of bytes in 103862306a36Sopenharmony_ci * committed buds 103962306a36Sopenharmony_ci * 104062306a36Sopenharmony_ci * @buds: tree of all buds indexed by bud LEB number 104162306a36Sopenharmony_ci * @bud_bytes: how many bytes of flash is used by buds 104262306a36Sopenharmony_ci * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud 104362306a36Sopenharmony_ci * lists 104462306a36Sopenharmony_ci * @jhead_cnt: count of journal heads 104562306a36Sopenharmony_ci * @jheads: journal heads (head zero is base head) 104662306a36Sopenharmony_ci * @max_bud_bytes: maximum number of bytes allowed in buds 104762306a36Sopenharmony_ci * @bg_bud_bytes: number of bud bytes when background commit is initiated 104862306a36Sopenharmony_ci * @old_buds: buds to be released after commit ends 104962306a36Sopenharmony_ci * @max_bud_cnt: maximum number of buds 105062306a36Sopenharmony_ci * 105162306a36Sopenharmony_ci * @commit_sem: synchronizes committer with other processes 105262306a36Sopenharmony_ci * @cmt_state: commit state 105362306a36Sopenharmony_ci * @cs_lock: commit state lock 105462306a36Sopenharmony_ci * @cmt_wq: wait queue to sleep on if the log is full and a commit is running 105562306a36Sopenharmony_ci * 105662306a36Sopenharmony_ci * @big_lpt: flag that LPT is too big to write whole during commit 105762306a36Sopenharmony_ci * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up 105862306a36Sopenharmony_ci * @double_hash: flag indicating that we can do lookups by hash 105962306a36Sopenharmony_ci * @encrypted: flag indicating that this file system contains encrypted files 106062306a36Sopenharmony_ci * @no_chk_data_crc: do not check CRCs when reading data nodes (except during 106162306a36Sopenharmony_ci * recovery) 106262306a36Sopenharmony_ci * @bulk_read: enable bulk-reads 106362306a36Sopenharmony_ci * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc) 106462306a36Sopenharmony_ci * @rw_incompat: the media is not R/W compatible 106562306a36Sopenharmony_ci * @assert_action: action to take when a ubifs_assert() fails 106662306a36Sopenharmony_ci * @authenticated: flag indigating the FS is mounted in authenticated mode 106762306a36Sopenharmony_ci * 106862306a36Sopenharmony_ci * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and 106962306a36Sopenharmony_ci * @calc_idx_sz 107062306a36Sopenharmony_ci * @zroot: zbranch which points to the root index node and znode 107162306a36Sopenharmony_ci * @cnext: next znode to commit 107262306a36Sopenharmony_ci * @enext: next znode to commit to empty space 107362306a36Sopenharmony_ci * @gap_lebs: array of LEBs used by the in-gaps commit method 107462306a36Sopenharmony_ci * @cbuf: commit buffer 107562306a36Sopenharmony_ci * @ileb_buf: buffer for commit in-the-gaps method 107662306a36Sopenharmony_ci * @ileb_len: length of data in ileb_buf 107762306a36Sopenharmony_ci * @ihead_lnum: LEB number of index head 107862306a36Sopenharmony_ci * @ihead_offs: offset of index head 107962306a36Sopenharmony_ci * @ilebs: pre-allocated index LEBs 108062306a36Sopenharmony_ci * @ileb_cnt: number of pre-allocated index LEBs 108162306a36Sopenharmony_ci * @ileb_nxt: next pre-allocated index LEBs 108262306a36Sopenharmony_ci * @old_idx: tree of index nodes obsoleted since the last commit start 108362306a36Sopenharmony_ci * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c 108462306a36Sopenharmony_ci * 108562306a36Sopenharmony_ci * @mst_node: master node 108662306a36Sopenharmony_ci * @mst_offs: offset of valid master node 108762306a36Sopenharmony_ci * 108862306a36Sopenharmony_ci * @max_bu_buf_len: maximum bulk-read buffer length 108962306a36Sopenharmony_ci * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu 109062306a36Sopenharmony_ci * @bu: pre-allocated bulk-read information 109162306a36Sopenharmony_ci * 109262306a36Sopenharmony_ci * @write_reserve_mutex: protects @write_reserve_buf 109362306a36Sopenharmony_ci * @write_reserve_buf: on the write path we allocate memory, which might 109462306a36Sopenharmony_ci * sometimes be unavailable, in which case we use this 109562306a36Sopenharmony_ci * write reserve buffer 109662306a36Sopenharmony_ci * 109762306a36Sopenharmony_ci * @log_lebs: number of logical eraseblocks in the log 109862306a36Sopenharmony_ci * @log_bytes: log size in bytes 109962306a36Sopenharmony_ci * @log_last: last LEB of the log 110062306a36Sopenharmony_ci * @lpt_lebs: number of LEBs used for lprops table 110162306a36Sopenharmony_ci * @lpt_first: first LEB of the lprops table area 110262306a36Sopenharmony_ci * @lpt_last: last LEB of the lprops table area 110362306a36Sopenharmony_ci * @orph_lebs: number of LEBs used for the orphan area 110462306a36Sopenharmony_ci * @orph_first: first LEB of the orphan area 110562306a36Sopenharmony_ci * @orph_last: last LEB of the orphan area 110662306a36Sopenharmony_ci * @main_lebs: count of LEBs in the main area 110762306a36Sopenharmony_ci * @main_first: first LEB of the main area 110862306a36Sopenharmony_ci * @main_bytes: main area size in bytes 110962306a36Sopenharmony_ci * 111062306a36Sopenharmony_ci * @key_hash_type: type of the key hash 111162306a36Sopenharmony_ci * @key_hash: direntry key hash function 111262306a36Sopenharmony_ci * @key_fmt: key format 111362306a36Sopenharmony_ci * @key_len: key length 111462306a36Sopenharmony_ci * @hash_len: The length of the index node hashes 111562306a36Sopenharmony_ci * @fanout: fanout of the index tree (number of links per indexing node) 111662306a36Sopenharmony_ci * 111762306a36Sopenharmony_ci * @min_io_size: minimal input/output unit size 111862306a36Sopenharmony_ci * @min_io_shift: number of bits in @min_io_size minus one 111962306a36Sopenharmony_ci * @max_write_size: maximum amount of bytes the underlying flash can write at a 112062306a36Sopenharmony_ci * time (MTD write buffer size) 112162306a36Sopenharmony_ci * @max_write_shift: number of bits in @max_write_size minus one 112262306a36Sopenharmony_ci * @leb_size: logical eraseblock size in bytes 112362306a36Sopenharmony_ci * @leb_start: starting offset of logical eraseblocks within physical 112462306a36Sopenharmony_ci * eraseblocks 112562306a36Sopenharmony_ci * @half_leb_size: half LEB size 112662306a36Sopenharmony_ci * @idx_leb_size: how many bytes of an LEB are effectively available when it is 112762306a36Sopenharmony_ci * used to store indexing nodes (@leb_size - @max_idx_node_sz) 112862306a36Sopenharmony_ci * @leb_cnt: count of logical eraseblocks 112962306a36Sopenharmony_ci * @max_leb_cnt: maximum count of logical eraseblocks 113062306a36Sopenharmony_ci * @ro_media: the underlying UBI volume is read-only 113162306a36Sopenharmony_ci * @ro_mount: the file-system was mounted as read-only 113262306a36Sopenharmony_ci * @ro_error: UBIFS switched to R/O mode because an error happened 113362306a36Sopenharmony_ci * 113462306a36Sopenharmony_ci * @dirty_pg_cnt: number of dirty pages (not used) 113562306a36Sopenharmony_ci * @dirty_zn_cnt: number of dirty znodes 113662306a36Sopenharmony_ci * @clean_zn_cnt: number of clean znodes 113762306a36Sopenharmony_ci * 113862306a36Sopenharmony_ci * @space_lock: protects @bi and @lst 113962306a36Sopenharmony_ci * @lst: lprops statistics 114062306a36Sopenharmony_ci * @bi: budgeting information 114162306a36Sopenharmony_ci * @calc_idx_sz: temporary variable which is used to calculate new index size 114262306a36Sopenharmony_ci * (contains accurate new index size at end of TNC commit start) 114362306a36Sopenharmony_ci * 114462306a36Sopenharmony_ci * @ref_node_alsz: size of the LEB reference node aligned to the min. flash 114562306a36Sopenharmony_ci * I/O unit 114662306a36Sopenharmony_ci * @mst_node_alsz: master node aligned size 114762306a36Sopenharmony_ci * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary 114862306a36Sopenharmony_ci * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary 114962306a36Sopenharmony_ci * @max_inode_sz: maximum possible inode size in bytes 115062306a36Sopenharmony_ci * @max_znode_sz: size of znode in bytes 115162306a36Sopenharmony_ci * 115262306a36Sopenharmony_ci * @leb_overhead: how many bytes are wasted in an LEB when it is filled with 115362306a36Sopenharmony_ci * data nodes of maximum size - used in free space reporting 115462306a36Sopenharmony_ci * @dead_wm: LEB dead space watermark 115562306a36Sopenharmony_ci * @dark_wm: LEB dark space watermark 115662306a36Sopenharmony_ci * @block_cnt: count of 4KiB blocks on the FS 115762306a36Sopenharmony_ci * 115862306a36Sopenharmony_ci * @ranges: UBIFS node length ranges 115962306a36Sopenharmony_ci * @ubi: UBI volume descriptor 116062306a36Sopenharmony_ci * @di: UBI device information 116162306a36Sopenharmony_ci * @vi: UBI volume information 116262306a36Sopenharmony_ci * 116362306a36Sopenharmony_ci * @orph_tree: rb-tree of orphan inode numbers 116462306a36Sopenharmony_ci * @orph_list: list of orphan inode numbers in order added 116562306a36Sopenharmony_ci * @orph_new: list of orphan inode numbers added since last commit 116662306a36Sopenharmony_ci * @orph_cnext: next orphan to commit 116762306a36Sopenharmony_ci * @orph_dnext: next orphan to delete 116862306a36Sopenharmony_ci * @orphan_lock: lock for orph_tree and orph_new 116962306a36Sopenharmony_ci * @orph_buf: buffer for orphan nodes 117062306a36Sopenharmony_ci * @new_orphans: number of orphans since last commit 117162306a36Sopenharmony_ci * @cmt_orphans: number of orphans being committed 117262306a36Sopenharmony_ci * @tot_orphans: number of orphans in the rb_tree 117362306a36Sopenharmony_ci * @max_orphans: maximum number of orphans allowed 117462306a36Sopenharmony_ci * @ohead_lnum: orphan head LEB number 117562306a36Sopenharmony_ci * @ohead_offs: orphan head offset 117662306a36Sopenharmony_ci * @no_orphs: non-zero if there are no orphans 117762306a36Sopenharmony_ci * 117862306a36Sopenharmony_ci * @bgt: UBIFS background thread 117962306a36Sopenharmony_ci * @bgt_name: background thread name 118062306a36Sopenharmony_ci * @need_bgt: if background thread should run 118162306a36Sopenharmony_ci * @need_wbuf_sync: if write-buffers have to be synchronized 118262306a36Sopenharmony_ci * 118362306a36Sopenharmony_ci * @gc_lnum: LEB number used for garbage collection 118462306a36Sopenharmony_ci * @sbuf: a buffer of LEB size used by GC and replay for scanning 118562306a36Sopenharmony_ci * @idx_gc: list of index LEBs that have been garbage collected 118662306a36Sopenharmony_ci * @idx_gc_cnt: number of elements on the idx_gc list 118762306a36Sopenharmony_ci * @gc_seq: incremented for every non-index LEB garbage collected 118862306a36Sopenharmony_ci * @gced_lnum: last non-index LEB that was garbage collected 118962306a36Sopenharmony_ci * 119062306a36Sopenharmony_ci * @infos_list: links all 'ubifs_info' objects 119162306a36Sopenharmony_ci * @umount_mutex: serializes shrinker and un-mount 119262306a36Sopenharmony_ci * @shrinker_run_no: shrinker run number 119362306a36Sopenharmony_ci * 119462306a36Sopenharmony_ci * @space_bits: number of bits needed to record free or dirty space 119562306a36Sopenharmony_ci * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT 119662306a36Sopenharmony_ci * @lpt_offs_bits: number of bits needed to record an offset in the LPT 119762306a36Sopenharmony_ci * @lpt_spc_bits: number of bits needed to space in the LPT 119862306a36Sopenharmony_ci * @pcnt_bits: number of bits needed to record pnode or nnode number 119962306a36Sopenharmony_ci * @lnum_bits: number of bits needed to record LEB number 120062306a36Sopenharmony_ci * @nnode_sz: size of on-flash nnode 120162306a36Sopenharmony_ci * @pnode_sz: size of on-flash pnode 120262306a36Sopenharmony_ci * @ltab_sz: size of on-flash LPT lprops table 120362306a36Sopenharmony_ci * @lsave_sz: size of on-flash LPT save table 120462306a36Sopenharmony_ci * @pnode_cnt: number of pnodes 120562306a36Sopenharmony_ci * @nnode_cnt: number of nnodes 120662306a36Sopenharmony_ci * @lpt_hght: height of the LPT 120762306a36Sopenharmony_ci * @pnodes_have: number of pnodes in memory 120862306a36Sopenharmony_ci * 120962306a36Sopenharmony_ci * @lp_mutex: protects lprops table and all the other lprops-related fields 121062306a36Sopenharmony_ci * @lpt_lnum: LEB number of the root nnode of the LPT 121162306a36Sopenharmony_ci * @lpt_offs: offset of the root nnode of the LPT 121262306a36Sopenharmony_ci * @nhead_lnum: LEB number of LPT head 121362306a36Sopenharmony_ci * @nhead_offs: offset of LPT head 121462306a36Sopenharmony_ci * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab 121562306a36Sopenharmony_ci * @dirty_nn_cnt: number of dirty nnodes 121662306a36Sopenharmony_ci * @dirty_pn_cnt: number of dirty pnodes 121762306a36Sopenharmony_ci * @check_lpt_free: flag that indicates LPT GC may be needed 121862306a36Sopenharmony_ci * @lpt_sz: LPT size 121962306a36Sopenharmony_ci * @lpt_nod_buf: buffer for an on-flash nnode or pnode 122062306a36Sopenharmony_ci * @lpt_buf: buffer of LEB size used by LPT 122162306a36Sopenharmony_ci * @nroot: address in memory of the root nnode of the LPT 122262306a36Sopenharmony_ci * @lpt_cnext: next LPT node to commit 122362306a36Sopenharmony_ci * @lpt_heap: array of heaps of categorized lprops 122462306a36Sopenharmony_ci * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at 122562306a36Sopenharmony_ci * previous commit start 122662306a36Sopenharmony_ci * @uncat_list: list of un-categorized LEBs 122762306a36Sopenharmony_ci * @empty_list: list of empty LEBs 122862306a36Sopenharmony_ci * @freeable_list: list of freeable non-index LEBs (free + dirty == @leb_size) 122962306a36Sopenharmony_ci * @frdi_idx_list: list of freeable index LEBs (free + dirty == @leb_size) 123062306a36Sopenharmony_ci * @freeable_cnt: number of freeable LEBs in @freeable_list 123162306a36Sopenharmony_ci * @in_a_category_cnt: count of lprops which are in a certain category, which 123262306a36Sopenharmony_ci * basically meants that they were loaded from the flash 123362306a36Sopenharmony_ci * 123462306a36Sopenharmony_ci * @ltab_lnum: LEB number of LPT's own lprops table 123562306a36Sopenharmony_ci * @ltab_offs: offset of LPT's own lprops table 123662306a36Sopenharmony_ci * @ltab: LPT's own lprops table 123762306a36Sopenharmony_ci * @ltab_cmt: LPT's own lprops table (commit copy) 123862306a36Sopenharmony_ci * @lsave_cnt: number of LEB numbers in LPT's save table 123962306a36Sopenharmony_ci * @lsave_lnum: LEB number of LPT's save table 124062306a36Sopenharmony_ci * @lsave_offs: offset of LPT's save table 124162306a36Sopenharmony_ci * @lsave: LPT's save table 124262306a36Sopenharmony_ci * @lscan_lnum: LEB number of last LPT scan 124362306a36Sopenharmony_ci * 124462306a36Sopenharmony_ci * @rp_size: size of the reserved pool in bytes 124562306a36Sopenharmony_ci * @report_rp_size: size of the reserved pool reported to user-space 124662306a36Sopenharmony_ci * @rp_uid: reserved pool user ID 124762306a36Sopenharmony_ci * @rp_gid: reserved pool group ID 124862306a36Sopenharmony_ci * 124962306a36Sopenharmony_ci * @hash_tfm: the hash transformation used for hashing nodes 125062306a36Sopenharmony_ci * @hmac_tfm: the HMAC transformation for this filesystem 125162306a36Sopenharmony_ci * @hmac_desc_len: length of the HMAC used for authentication 125262306a36Sopenharmony_ci * @auth_key_name: the authentication key name 125362306a36Sopenharmony_ci * @auth_hash_name: the name of the hash algorithm used for authentication 125462306a36Sopenharmony_ci * @auth_hash_algo: the authentication hash used for this fs 125562306a36Sopenharmony_ci * @log_hash: the log hash from the commit start node up to the latest reference 125662306a36Sopenharmony_ci * node. 125762306a36Sopenharmony_ci * 125862306a36Sopenharmony_ci * @empty: %1 if the UBI device is empty 125962306a36Sopenharmony_ci * @need_recovery: %1 if the file-system needs recovery 126062306a36Sopenharmony_ci * @replaying: %1 during journal replay 126162306a36Sopenharmony_ci * @mounting: %1 while mounting 126262306a36Sopenharmony_ci * @probing: %1 while attempting to mount if SB_SILENT mount flag is set 126362306a36Sopenharmony_ci * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode 126462306a36Sopenharmony_ci * @replay_list: temporary list used during journal replay 126562306a36Sopenharmony_ci * @replay_buds: list of buds to replay 126662306a36Sopenharmony_ci * @cs_sqnum: sequence number of first node in the log (commit start node) 126762306a36Sopenharmony_ci * @unclean_leb_list: LEBs to recover when re-mounting R/O mounted FS to R/W 126862306a36Sopenharmony_ci * mode 126962306a36Sopenharmony_ci * @rcvrd_mst_node: recovered master node to write when re-mounting R/O mounted 127062306a36Sopenharmony_ci * FS to R/W mode 127162306a36Sopenharmony_ci * @size_tree: inode size information for recovery 127262306a36Sopenharmony_ci * @mount_opts: UBIFS-specific mount options 127362306a36Sopenharmony_ci * 127462306a36Sopenharmony_ci * @dbg: debugging-related information 127562306a36Sopenharmony_ci * @stats: statistics exported over sysfs 127662306a36Sopenharmony_ci * 127762306a36Sopenharmony_ci * @kobj: kobject for /sys/fs/ubifs/ 127862306a36Sopenharmony_ci * @kobj_unregister: completion to unregister sysfs kobject 127962306a36Sopenharmony_ci */ 128062306a36Sopenharmony_cistruct ubifs_info { 128162306a36Sopenharmony_ci struct super_block *vfs_sb; 128262306a36Sopenharmony_ci struct ubifs_sb_node *sup_node; 128362306a36Sopenharmony_ci 128462306a36Sopenharmony_ci ino_t highest_inum; 128562306a36Sopenharmony_ci unsigned long long max_sqnum; 128662306a36Sopenharmony_ci unsigned long long cmt_no; 128762306a36Sopenharmony_ci spinlock_t cnt_lock; 128862306a36Sopenharmony_ci int fmt_version; 128962306a36Sopenharmony_ci int ro_compat_version; 129062306a36Sopenharmony_ci unsigned char uuid[16]; 129162306a36Sopenharmony_ci 129262306a36Sopenharmony_ci int lhead_lnum; 129362306a36Sopenharmony_ci int lhead_offs; 129462306a36Sopenharmony_ci int ltail_lnum; 129562306a36Sopenharmony_ci struct mutex log_mutex; 129662306a36Sopenharmony_ci int min_log_bytes; 129762306a36Sopenharmony_ci long long cmt_bud_bytes; 129862306a36Sopenharmony_ci 129962306a36Sopenharmony_ci struct rb_root buds; 130062306a36Sopenharmony_ci long long bud_bytes; 130162306a36Sopenharmony_ci spinlock_t buds_lock; 130262306a36Sopenharmony_ci int jhead_cnt; 130362306a36Sopenharmony_ci struct ubifs_jhead *jheads; 130462306a36Sopenharmony_ci long long max_bud_bytes; 130562306a36Sopenharmony_ci long long bg_bud_bytes; 130662306a36Sopenharmony_ci struct list_head old_buds; 130762306a36Sopenharmony_ci int max_bud_cnt; 130862306a36Sopenharmony_ci 130962306a36Sopenharmony_ci struct rw_semaphore commit_sem; 131062306a36Sopenharmony_ci int cmt_state; 131162306a36Sopenharmony_ci spinlock_t cs_lock; 131262306a36Sopenharmony_ci wait_queue_head_t cmt_wq; 131362306a36Sopenharmony_ci 131462306a36Sopenharmony_ci struct kobject kobj; 131562306a36Sopenharmony_ci struct completion kobj_unregister; 131662306a36Sopenharmony_ci 131762306a36Sopenharmony_ci unsigned int big_lpt:1; 131862306a36Sopenharmony_ci unsigned int space_fixup:1; 131962306a36Sopenharmony_ci unsigned int double_hash:1; 132062306a36Sopenharmony_ci unsigned int encrypted:1; 132162306a36Sopenharmony_ci unsigned int no_chk_data_crc:1; 132262306a36Sopenharmony_ci unsigned int bulk_read:1; 132362306a36Sopenharmony_ci unsigned int default_compr:2; 132462306a36Sopenharmony_ci unsigned int rw_incompat:1; 132562306a36Sopenharmony_ci unsigned int assert_action:2; 132662306a36Sopenharmony_ci unsigned int authenticated:1; 132762306a36Sopenharmony_ci unsigned int superblock_need_write:1; 132862306a36Sopenharmony_ci 132962306a36Sopenharmony_ci struct mutex tnc_mutex; 133062306a36Sopenharmony_ci struct ubifs_zbranch zroot; 133162306a36Sopenharmony_ci struct ubifs_znode *cnext; 133262306a36Sopenharmony_ci struct ubifs_znode *enext; 133362306a36Sopenharmony_ci int *gap_lebs; 133462306a36Sopenharmony_ci void *cbuf; 133562306a36Sopenharmony_ci void *ileb_buf; 133662306a36Sopenharmony_ci int ileb_len; 133762306a36Sopenharmony_ci int ihead_lnum; 133862306a36Sopenharmony_ci int ihead_offs; 133962306a36Sopenharmony_ci int *ilebs; 134062306a36Sopenharmony_ci int ileb_cnt; 134162306a36Sopenharmony_ci int ileb_nxt; 134262306a36Sopenharmony_ci struct rb_root old_idx; 134362306a36Sopenharmony_ci int *bottom_up_buf; 134462306a36Sopenharmony_ci 134562306a36Sopenharmony_ci struct ubifs_mst_node *mst_node; 134662306a36Sopenharmony_ci int mst_offs; 134762306a36Sopenharmony_ci 134862306a36Sopenharmony_ci int max_bu_buf_len; 134962306a36Sopenharmony_ci struct mutex bu_mutex; 135062306a36Sopenharmony_ci struct bu_info bu; 135162306a36Sopenharmony_ci 135262306a36Sopenharmony_ci struct mutex write_reserve_mutex; 135362306a36Sopenharmony_ci void *write_reserve_buf; 135462306a36Sopenharmony_ci 135562306a36Sopenharmony_ci int log_lebs; 135662306a36Sopenharmony_ci long long log_bytes; 135762306a36Sopenharmony_ci int log_last; 135862306a36Sopenharmony_ci int lpt_lebs; 135962306a36Sopenharmony_ci int lpt_first; 136062306a36Sopenharmony_ci int lpt_last; 136162306a36Sopenharmony_ci int orph_lebs; 136262306a36Sopenharmony_ci int orph_first; 136362306a36Sopenharmony_ci int orph_last; 136462306a36Sopenharmony_ci int main_lebs; 136562306a36Sopenharmony_ci int main_first; 136662306a36Sopenharmony_ci long long main_bytes; 136762306a36Sopenharmony_ci 136862306a36Sopenharmony_ci uint8_t key_hash_type; 136962306a36Sopenharmony_ci uint32_t (*key_hash)(const char *str, int len); 137062306a36Sopenharmony_ci int key_fmt; 137162306a36Sopenharmony_ci int key_len; 137262306a36Sopenharmony_ci int hash_len; 137362306a36Sopenharmony_ci int fanout; 137462306a36Sopenharmony_ci 137562306a36Sopenharmony_ci int min_io_size; 137662306a36Sopenharmony_ci int min_io_shift; 137762306a36Sopenharmony_ci int max_write_size; 137862306a36Sopenharmony_ci int max_write_shift; 137962306a36Sopenharmony_ci int leb_size; 138062306a36Sopenharmony_ci int leb_start; 138162306a36Sopenharmony_ci int half_leb_size; 138262306a36Sopenharmony_ci int idx_leb_size; 138362306a36Sopenharmony_ci int leb_cnt; 138462306a36Sopenharmony_ci int max_leb_cnt; 138562306a36Sopenharmony_ci unsigned int ro_media:1; 138662306a36Sopenharmony_ci unsigned int ro_mount:1; 138762306a36Sopenharmony_ci unsigned int ro_error:1; 138862306a36Sopenharmony_ci 138962306a36Sopenharmony_ci atomic_long_t dirty_pg_cnt; 139062306a36Sopenharmony_ci atomic_long_t dirty_zn_cnt; 139162306a36Sopenharmony_ci atomic_long_t clean_zn_cnt; 139262306a36Sopenharmony_ci 139362306a36Sopenharmony_ci spinlock_t space_lock; 139462306a36Sopenharmony_ci struct ubifs_lp_stats lst; 139562306a36Sopenharmony_ci struct ubifs_budg_info bi; 139662306a36Sopenharmony_ci unsigned long long calc_idx_sz; 139762306a36Sopenharmony_ci 139862306a36Sopenharmony_ci int ref_node_alsz; 139962306a36Sopenharmony_ci int mst_node_alsz; 140062306a36Sopenharmony_ci int min_idx_node_sz; 140162306a36Sopenharmony_ci int max_idx_node_sz; 140262306a36Sopenharmony_ci long long max_inode_sz; 140362306a36Sopenharmony_ci int max_znode_sz; 140462306a36Sopenharmony_ci 140562306a36Sopenharmony_ci int leb_overhead; 140662306a36Sopenharmony_ci int dead_wm; 140762306a36Sopenharmony_ci int dark_wm; 140862306a36Sopenharmony_ci int block_cnt; 140962306a36Sopenharmony_ci 141062306a36Sopenharmony_ci struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT]; 141162306a36Sopenharmony_ci struct ubi_volume_desc *ubi; 141262306a36Sopenharmony_ci struct ubi_device_info di; 141362306a36Sopenharmony_ci struct ubi_volume_info vi; 141462306a36Sopenharmony_ci 141562306a36Sopenharmony_ci struct rb_root orph_tree; 141662306a36Sopenharmony_ci struct list_head orph_list; 141762306a36Sopenharmony_ci struct list_head orph_new; 141862306a36Sopenharmony_ci struct ubifs_orphan *orph_cnext; 141962306a36Sopenharmony_ci struct ubifs_orphan *orph_dnext; 142062306a36Sopenharmony_ci spinlock_t orphan_lock; 142162306a36Sopenharmony_ci void *orph_buf; 142262306a36Sopenharmony_ci int new_orphans; 142362306a36Sopenharmony_ci int cmt_orphans; 142462306a36Sopenharmony_ci int tot_orphans; 142562306a36Sopenharmony_ci int max_orphans; 142662306a36Sopenharmony_ci int ohead_lnum; 142762306a36Sopenharmony_ci int ohead_offs; 142862306a36Sopenharmony_ci int no_orphs; 142962306a36Sopenharmony_ci 143062306a36Sopenharmony_ci struct task_struct *bgt; 143162306a36Sopenharmony_ci char bgt_name[sizeof(BGT_NAME_PATTERN) + 9]; 143262306a36Sopenharmony_ci int need_bgt; 143362306a36Sopenharmony_ci int need_wbuf_sync; 143462306a36Sopenharmony_ci 143562306a36Sopenharmony_ci int gc_lnum; 143662306a36Sopenharmony_ci void *sbuf; 143762306a36Sopenharmony_ci struct list_head idx_gc; 143862306a36Sopenharmony_ci int idx_gc_cnt; 143962306a36Sopenharmony_ci int gc_seq; 144062306a36Sopenharmony_ci int gced_lnum; 144162306a36Sopenharmony_ci 144262306a36Sopenharmony_ci struct list_head infos_list; 144362306a36Sopenharmony_ci struct mutex umount_mutex; 144462306a36Sopenharmony_ci unsigned int shrinker_run_no; 144562306a36Sopenharmony_ci 144662306a36Sopenharmony_ci int space_bits; 144762306a36Sopenharmony_ci int lpt_lnum_bits; 144862306a36Sopenharmony_ci int lpt_offs_bits; 144962306a36Sopenharmony_ci int lpt_spc_bits; 145062306a36Sopenharmony_ci int pcnt_bits; 145162306a36Sopenharmony_ci int lnum_bits; 145262306a36Sopenharmony_ci int nnode_sz; 145362306a36Sopenharmony_ci int pnode_sz; 145462306a36Sopenharmony_ci int ltab_sz; 145562306a36Sopenharmony_ci int lsave_sz; 145662306a36Sopenharmony_ci int pnode_cnt; 145762306a36Sopenharmony_ci int nnode_cnt; 145862306a36Sopenharmony_ci int lpt_hght; 145962306a36Sopenharmony_ci int pnodes_have; 146062306a36Sopenharmony_ci 146162306a36Sopenharmony_ci struct mutex lp_mutex; 146262306a36Sopenharmony_ci int lpt_lnum; 146362306a36Sopenharmony_ci int lpt_offs; 146462306a36Sopenharmony_ci int nhead_lnum; 146562306a36Sopenharmony_ci int nhead_offs; 146662306a36Sopenharmony_ci int lpt_drty_flgs; 146762306a36Sopenharmony_ci int dirty_nn_cnt; 146862306a36Sopenharmony_ci int dirty_pn_cnt; 146962306a36Sopenharmony_ci int check_lpt_free; 147062306a36Sopenharmony_ci long long lpt_sz; 147162306a36Sopenharmony_ci void *lpt_nod_buf; 147262306a36Sopenharmony_ci void *lpt_buf; 147362306a36Sopenharmony_ci struct ubifs_nnode *nroot; 147462306a36Sopenharmony_ci struct ubifs_cnode *lpt_cnext; 147562306a36Sopenharmony_ci struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT]; 147662306a36Sopenharmony_ci struct ubifs_lpt_heap dirty_idx; 147762306a36Sopenharmony_ci struct list_head uncat_list; 147862306a36Sopenharmony_ci struct list_head empty_list; 147962306a36Sopenharmony_ci struct list_head freeable_list; 148062306a36Sopenharmony_ci struct list_head frdi_idx_list; 148162306a36Sopenharmony_ci int freeable_cnt; 148262306a36Sopenharmony_ci int in_a_category_cnt; 148362306a36Sopenharmony_ci 148462306a36Sopenharmony_ci int ltab_lnum; 148562306a36Sopenharmony_ci int ltab_offs; 148662306a36Sopenharmony_ci struct ubifs_lpt_lprops *ltab; 148762306a36Sopenharmony_ci struct ubifs_lpt_lprops *ltab_cmt; 148862306a36Sopenharmony_ci int lsave_cnt; 148962306a36Sopenharmony_ci int lsave_lnum; 149062306a36Sopenharmony_ci int lsave_offs; 149162306a36Sopenharmony_ci int *lsave; 149262306a36Sopenharmony_ci int lscan_lnum; 149362306a36Sopenharmony_ci 149462306a36Sopenharmony_ci long long rp_size; 149562306a36Sopenharmony_ci long long report_rp_size; 149662306a36Sopenharmony_ci kuid_t rp_uid; 149762306a36Sopenharmony_ci kgid_t rp_gid; 149862306a36Sopenharmony_ci 149962306a36Sopenharmony_ci struct crypto_shash *hash_tfm; 150062306a36Sopenharmony_ci struct crypto_shash *hmac_tfm; 150162306a36Sopenharmony_ci int hmac_desc_len; 150262306a36Sopenharmony_ci char *auth_key_name; 150362306a36Sopenharmony_ci char *auth_hash_name; 150462306a36Sopenharmony_ci enum hash_algo auth_hash_algo; 150562306a36Sopenharmony_ci 150662306a36Sopenharmony_ci struct shash_desc *log_hash; 150762306a36Sopenharmony_ci 150862306a36Sopenharmony_ci /* The below fields are used only during mounting and re-mounting */ 150962306a36Sopenharmony_ci unsigned int empty:1; 151062306a36Sopenharmony_ci unsigned int need_recovery:1; 151162306a36Sopenharmony_ci unsigned int replaying:1; 151262306a36Sopenharmony_ci unsigned int mounting:1; 151362306a36Sopenharmony_ci unsigned int remounting_rw:1; 151462306a36Sopenharmony_ci unsigned int probing:1; 151562306a36Sopenharmony_ci struct list_head replay_list; 151662306a36Sopenharmony_ci struct list_head replay_buds; 151762306a36Sopenharmony_ci unsigned long long cs_sqnum; 151862306a36Sopenharmony_ci struct list_head unclean_leb_list; 151962306a36Sopenharmony_ci struct ubifs_mst_node *rcvrd_mst_node; 152062306a36Sopenharmony_ci struct rb_root size_tree; 152162306a36Sopenharmony_ci struct ubifs_mount_opts mount_opts; 152262306a36Sopenharmony_ci 152362306a36Sopenharmony_ci struct ubifs_debug_info *dbg; 152462306a36Sopenharmony_ci struct ubifs_stats_info *stats; 152562306a36Sopenharmony_ci}; 152662306a36Sopenharmony_ci 152762306a36Sopenharmony_ciextern struct list_head ubifs_infos; 152862306a36Sopenharmony_ciextern spinlock_t ubifs_infos_lock; 152962306a36Sopenharmony_ciextern atomic_long_t ubifs_clean_zn_cnt; 153062306a36Sopenharmony_ciextern const struct super_operations ubifs_super_operations; 153162306a36Sopenharmony_ciextern const struct address_space_operations ubifs_file_address_operations; 153262306a36Sopenharmony_ciextern const struct file_operations ubifs_file_operations; 153362306a36Sopenharmony_ciextern const struct inode_operations ubifs_file_inode_operations; 153462306a36Sopenharmony_ciextern const struct file_operations ubifs_dir_operations; 153562306a36Sopenharmony_ciextern const struct inode_operations ubifs_dir_inode_operations; 153662306a36Sopenharmony_ciextern const struct inode_operations ubifs_symlink_inode_operations; 153762306a36Sopenharmony_ciextern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; 153862306a36Sopenharmony_ciextern int ubifs_default_version; 153962306a36Sopenharmony_ci 154062306a36Sopenharmony_ci/* auth.c */ 154162306a36Sopenharmony_cistatic inline int ubifs_authenticated(const struct ubifs_info *c) 154262306a36Sopenharmony_ci{ 154362306a36Sopenharmony_ci return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated; 154462306a36Sopenharmony_ci} 154562306a36Sopenharmony_ci 154662306a36Sopenharmony_cistruct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c); 154762306a36Sopenharmony_cistatic inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c) 154862306a36Sopenharmony_ci{ 154962306a36Sopenharmony_ci return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL; 155062306a36Sopenharmony_ci} 155162306a36Sopenharmony_ci 155262306a36Sopenharmony_cistatic inline int ubifs_shash_init(const struct ubifs_info *c, 155362306a36Sopenharmony_ci struct shash_desc *desc) 155462306a36Sopenharmony_ci{ 155562306a36Sopenharmony_ci if (ubifs_authenticated(c)) 155662306a36Sopenharmony_ci return crypto_shash_init(desc); 155762306a36Sopenharmony_ci else 155862306a36Sopenharmony_ci return 0; 155962306a36Sopenharmony_ci} 156062306a36Sopenharmony_ci 156162306a36Sopenharmony_cistatic inline int ubifs_shash_update(const struct ubifs_info *c, 156262306a36Sopenharmony_ci struct shash_desc *desc, const void *buf, 156362306a36Sopenharmony_ci unsigned int len) 156462306a36Sopenharmony_ci{ 156562306a36Sopenharmony_ci int err = 0; 156662306a36Sopenharmony_ci 156762306a36Sopenharmony_ci if (ubifs_authenticated(c)) { 156862306a36Sopenharmony_ci err = crypto_shash_update(desc, buf, len); 156962306a36Sopenharmony_ci if (err < 0) 157062306a36Sopenharmony_ci return err; 157162306a36Sopenharmony_ci } 157262306a36Sopenharmony_ci 157362306a36Sopenharmony_ci return 0; 157462306a36Sopenharmony_ci} 157562306a36Sopenharmony_ci 157662306a36Sopenharmony_cistatic inline int ubifs_shash_final(const struct ubifs_info *c, 157762306a36Sopenharmony_ci struct shash_desc *desc, u8 *out) 157862306a36Sopenharmony_ci{ 157962306a36Sopenharmony_ci return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0; 158062306a36Sopenharmony_ci} 158162306a36Sopenharmony_ci 158262306a36Sopenharmony_ciint __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf, 158362306a36Sopenharmony_ci u8 *hash); 158462306a36Sopenharmony_cistatic inline int ubifs_node_calc_hash(const struct ubifs_info *c, 158562306a36Sopenharmony_ci const void *buf, u8 *hash) 158662306a36Sopenharmony_ci{ 158762306a36Sopenharmony_ci if (ubifs_authenticated(c)) 158862306a36Sopenharmony_ci return __ubifs_node_calc_hash(c, buf, hash); 158962306a36Sopenharmony_ci else 159062306a36Sopenharmony_ci return 0; 159162306a36Sopenharmony_ci} 159262306a36Sopenharmony_ci 159362306a36Sopenharmony_ciint ubifs_prepare_auth_node(struct ubifs_info *c, void *node, 159462306a36Sopenharmony_ci struct shash_desc *inhash); 159562306a36Sopenharmony_ci 159662306a36Sopenharmony_ci/** 159762306a36Sopenharmony_ci * ubifs_check_hash - compare two hashes 159862306a36Sopenharmony_ci * @c: UBIFS file-system description object 159962306a36Sopenharmony_ci * @expected: first hash 160062306a36Sopenharmony_ci * @got: second hash 160162306a36Sopenharmony_ci * 160262306a36Sopenharmony_ci * Compare two hashes @expected and @got. Returns 0 when they are equal, a 160362306a36Sopenharmony_ci * negative error code otherwise. 160462306a36Sopenharmony_ci */ 160562306a36Sopenharmony_cistatic inline int ubifs_check_hash(const struct ubifs_info *c, 160662306a36Sopenharmony_ci const u8 *expected, const u8 *got) 160762306a36Sopenharmony_ci{ 160862306a36Sopenharmony_ci return crypto_memneq(expected, got, c->hash_len); 160962306a36Sopenharmony_ci} 161062306a36Sopenharmony_ci 161162306a36Sopenharmony_ci/** 161262306a36Sopenharmony_ci * ubifs_check_hmac - compare two HMACs 161362306a36Sopenharmony_ci * @c: UBIFS file-system description object 161462306a36Sopenharmony_ci * @expected: first HMAC 161562306a36Sopenharmony_ci * @got: second HMAC 161662306a36Sopenharmony_ci * 161762306a36Sopenharmony_ci * Compare two hashes @expected and @got. Returns 0 when they are equal, a 161862306a36Sopenharmony_ci * negative error code otherwise. 161962306a36Sopenharmony_ci */ 162062306a36Sopenharmony_cistatic inline int ubifs_check_hmac(const struct ubifs_info *c, 162162306a36Sopenharmony_ci const u8 *expected, const u8 *got) 162262306a36Sopenharmony_ci{ 162362306a36Sopenharmony_ci return crypto_memneq(expected, got, c->hmac_desc_len); 162462306a36Sopenharmony_ci} 162562306a36Sopenharmony_ci 162662306a36Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_AUTHENTICATION 162762306a36Sopenharmony_civoid ubifs_bad_hash(const struct ubifs_info *c, const void *node, 162862306a36Sopenharmony_ci const u8 *hash, int lnum, int offs); 162962306a36Sopenharmony_ci#else 163062306a36Sopenharmony_cistatic inline void ubifs_bad_hash(const struct ubifs_info *c, const void *node, 163162306a36Sopenharmony_ci const u8 *hash, int lnum, int offs) {}; 163262306a36Sopenharmony_ci#endif 163362306a36Sopenharmony_ci 163462306a36Sopenharmony_ciint __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf, 163562306a36Sopenharmony_ci const u8 *expected); 163662306a36Sopenharmony_cistatic inline int ubifs_node_check_hash(const struct ubifs_info *c, 163762306a36Sopenharmony_ci const void *buf, const u8 *expected) 163862306a36Sopenharmony_ci{ 163962306a36Sopenharmony_ci if (ubifs_authenticated(c)) 164062306a36Sopenharmony_ci return __ubifs_node_check_hash(c, buf, expected); 164162306a36Sopenharmony_ci else 164262306a36Sopenharmony_ci return 0; 164362306a36Sopenharmony_ci} 164462306a36Sopenharmony_ci 164562306a36Sopenharmony_ciint ubifs_init_authentication(struct ubifs_info *c); 164662306a36Sopenharmony_civoid __ubifs_exit_authentication(struct ubifs_info *c); 164762306a36Sopenharmony_cistatic inline void ubifs_exit_authentication(struct ubifs_info *c) 164862306a36Sopenharmony_ci{ 164962306a36Sopenharmony_ci if (ubifs_authenticated(c)) 165062306a36Sopenharmony_ci __ubifs_exit_authentication(c); 165162306a36Sopenharmony_ci} 165262306a36Sopenharmony_ci 165362306a36Sopenharmony_ci/** 165462306a36Sopenharmony_ci * ubifs_branch_hash - returns a pointer to the hash of a branch 165562306a36Sopenharmony_ci * @c: UBIFS file-system description object 165662306a36Sopenharmony_ci * @br: branch to get the hash from 165762306a36Sopenharmony_ci * 165862306a36Sopenharmony_ci * This returns a pointer to the hash of a branch. Since the key already is a 165962306a36Sopenharmony_ci * dynamically sized object we cannot use a struct member here. 166062306a36Sopenharmony_ci */ 166162306a36Sopenharmony_cistatic inline u8 *ubifs_branch_hash(struct ubifs_info *c, 166262306a36Sopenharmony_ci struct ubifs_branch *br) 166362306a36Sopenharmony_ci{ 166462306a36Sopenharmony_ci return (void *)br + sizeof(*br) + c->key_len; 166562306a36Sopenharmony_ci} 166662306a36Sopenharmony_ci 166762306a36Sopenharmony_ci/** 166862306a36Sopenharmony_ci * ubifs_copy_hash - copy a hash 166962306a36Sopenharmony_ci * @c: UBIFS file-system description object 167062306a36Sopenharmony_ci * @from: source hash 167162306a36Sopenharmony_ci * @to: destination hash 167262306a36Sopenharmony_ci * 167362306a36Sopenharmony_ci * With authentication this copies a hash, otherwise does nothing. 167462306a36Sopenharmony_ci */ 167562306a36Sopenharmony_cistatic inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from, 167662306a36Sopenharmony_ci u8 *to) 167762306a36Sopenharmony_ci{ 167862306a36Sopenharmony_ci if (ubifs_authenticated(c)) 167962306a36Sopenharmony_ci memcpy(to, from, c->hash_len); 168062306a36Sopenharmony_ci} 168162306a36Sopenharmony_ci 168262306a36Sopenharmony_ciint __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf, 168362306a36Sopenharmony_ci int len, int ofs_hmac); 168462306a36Sopenharmony_cistatic inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf, 168562306a36Sopenharmony_ci int len, int ofs_hmac) 168662306a36Sopenharmony_ci{ 168762306a36Sopenharmony_ci if (ubifs_authenticated(c)) 168862306a36Sopenharmony_ci return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac); 168962306a36Sopenharmony_ci else 169062306a36Sopenharmony_ci return 0; 169162306a36Sopenharmony_ci} 169262306a36Sopenharmony_ci 169362306a36Sopenharmony_ciint __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf, 169462306a36Sopenharmony_ci int len, int ofs_hmac); 169562306a36Sopenharmony_cistatic inline int ubifs_node_verify_hmac(const struct ubifs_info *c, 169662306a36Sopenharmony_ci const void *buf, int len, int ofs_hmac) 169762306a36Sopenharmony_ci{ 169862306a36Sopenharmony_ci if (ubifs_authenticated(c)) 169962306a36Sopenharmony_ci return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac); 170062306a36Sopenharmony_ci else 170162306a36Sopenharmony_ci return 0; 170262306a36Sopenharmony_ci} 170362306a36Sopenharmony_ci 170462306a36Sopenharmony_ci/** 170562306a36Sopenharmony_ci * ubifs_auth_node_sz - returns the size of an authentication node 170662306a36Sopenharmony_ci * @c: UBIFS file-system description object 170762306a36Sopenharmony_ci * 170862306a36Sopenharmony_ci * This function returns the size of an authentication node which can 170962306a36Sopenharmony_ci * be 0 for unauthenticated filesystems or the real size of an auth node 171062306a36Sopenharmony_ci * authentication is enabled. 171162306a36Sopenharmony_ci */ 171262306a36Sopenharmony_cistatic inline int ubifs_auth_node_sz(const struct ubifs_info *c) 171362306a36Sopenharmony_ci{ 171462306a36Sopenharmony_ci if (ubifs_authenticated(c)) 171562306a36Sopenharmony_ci return sizeof(struct ubifs_auth_node) + c->hmac_desc_len; 171662306a36Sopenharmony_ci else 171762306a36Sopenharmony_ci return 0; 171862306a36Sopenharmony_ci} 171962306a36Sopenharmony_ciint ubifs_sb_verify_signature(struct ubifs_info *c, 172062306a36Sopenharmony_ci const struct ubifs_sb_node *sup); 172162306a36Sopenharmony_cibool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac); 172262306a36Sopenharmony_ci 172362306a36Sopenharmony_ciint ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac); 172462306a36Sopenharmony_ci 172562306a36Sopenharmony_ciint __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src, 172662306a36Sopenharmony_ci struct shash_desc *target); 172762306a36Sopenharmony_cistatic inline int ubifs_shash_copy_state(const struct ubifs_info *c, 172862306a36Sopenharmony_ci struct shash_desc *src, 172962306a36Sopenharmony_ci struct shash_desc *target) 173062306a36Sopenharmony_ci{ 173162306a36Sopenharmony_ci if (ubifs_authenticated(c)) 173262306a36Sopenharmony_ci return __ubifs_shash_copy_state(c, src, target); 173362306a36Sopenharmony_ci else 173462306a36Sopenharmony_ci return 0; 173562306a36Sopenharmony_ci} 173662306a36Sopenharmony_ci 173762306a36Sopenharmony_ci/* io.c */ 173862306a36Sopenharmony_civoid ubifs_ro_mode(struct ubifs_info *c, int err); 173962306a36Sopenharmony_ciint ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs, 174062306a36Sopenharmony_ci int len, int even_ebadmsg); 174162306a36Sopenharmony_ciint ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, 174262306a36Sopenharmony_ci int len); 174362306a36Sopenharmony_ciint ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len); 174462306a36Sopenharmony_ciint ubifs_leb_unmap(struct ubifs_info *c, int lnum); 174562306a36Sopenharmony_ciint ubifs_leb_map(struct ubifs_info *c, int lnum); 174662306a36Sopenharmony_ciint ubifs_is_mapped(const struct ubifs_info *c, int lnum); 174762306a36Sopenharmony_ciint ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len); 174862306a36Sopenharmony_ciint ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs); 174962306a36Sopenharmony_ciint ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf); 175062306a36Sopenharmony_ciint ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, 175162306a36Sopenharmony_ci int lnum, int offs); 175262306a36Sopenharmony_ciint ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, 175362306a36Sopenharmony_ci int lnum, int offs); 175462306a36Sopenharmony_ciint ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, 175562306a36Sopenharmony_ci int offs); 175662306a36Sopenharmony_ciint ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum, 175762306a36Sopenharmony_ci int offs, int hmac_offs); 175862306a36Sopenharmony_ciint ubifs_check_node(const struct ubifs_info *c, const void *buf, int len, 175962306a36Sopenharmony_ci int lnum, int offs, int quiet, int must_chk_crc); 176062306a36Sopenharmony_civoid ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad); 176162306a36Sopenharmony_civoid ubifs_crc_node(struct ubifs_info *c, void *buf, int len); 176262306a36Sopenharmony_civoid ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); 176362306a36Sopenharmony_ciint ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len, 176462306a36Sopenharmony_ci int hmac_offs, int pad); 176562306a36Sopenharmony_civoid ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); 176662306a36Sopenharmony_ciint ubifs_io_init(struct ubifs_info *c); 176762306a36Sopenharmony_civoid ubifs_pad(const struct ubifs_info *c, void *buf, int pad); 176862306a36Sopenharmony_ciint ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf); 176962306a36Sopenharmony_ciint ubifs_bg_wbufs_sync(struct ubifs_info *c); 177062306a36Sopenharmony_civoid ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum); 177162306a36Sopenharmony_ciint ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode); 177262306a36Sopenharmony_ci 177362306a36Sopenharmony_ci/* scan.c */ 177462306a36Sopenharmony_cistruct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, 177562306a36Sopenharmony_ci int offs, void *sbuf, int quiet); 177662306a36Sopenharmony_civoid ubifs_scan_destroy(struct ubifs_scan_leb *sleb); 177762306a36Sopenharmony_ciint ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, 177862306a36Sopenharmony_ci int offs, int quiet); 177962306a36Sopenharmony_cistruct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum, 178062306a36Sopenharmony_ci int offs, void *sbuf); 178162306a36Sopenharmony_civoid ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, 178262306a36Sopenharmony_ci int lnum, int offs); 178362306a36Sopenharmony_ciint ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb, 178462306a36Sopenharmony_ci void *buf, int offs); 178562306a36Sopenharmony_civoid ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, 178662306a36Sopenharmony_ci void *buf); 178762306a36Sopenharmony_ci 178862306a36Sopenharmony_ci/* log.c */ 178962306a36Sopenharmony_civoid ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud); 179062306a36Sopenharmony_civoid ubifs_create_buds_lists(struct ubifs_info *c); 179162306a36Sopenharmony_ciint ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs); 179262306a36Sopenharmony_cistruct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum); 179362306a36Sopenharmony_cistruct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum); 179462306a36Sopenharmony_ciint ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum); 179562306a36Sopenharmony_ciint ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum); 179662306a36Sopenharmony_ciint ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum); 179762306a36Sopenharmony_ciint ubifs_consolidate_log(struct ubifs_info *c); 179862306a36Sopenharmony_ci 179962306a36Sopenharmony_ci/* journal.c */ 180062306a36Sopenharmony_ciint ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, 180162306a36Sopenharmony_ci const struct fscrypt_name *nm, const struct inode *inode, 180262306a36Sopenharmony_ci int deletion, int xent); 180362306a36Sopenharmony_ciint ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, 180462306a36Sopenharmony_ci const union ubifs_key *key, const void *buf, int len); 180562306a36Sopenharmony_ciint ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode); 180662306a36Sopenharmony_ciint ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode); 180762306a36Sopenharmony_ciint ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir, 180862306a36Sopenharmony_ci const struct inode *fst_inode, 180962306a36Sopenharmony_ci const struct fscrypt_name *fst_nm, 181062306a36Sopenharmony_ci const struct inode *snd_dir, 181162306a36Sopenharmony_ci const struct inode *snd_inode, 181262306a36Sopenharmony_ci const struct fscrypt_name *snd_nm, int sync); 181362306a36Sopenharmony_ciint ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, 181462306a36Sopenharmony_ci const struct inode *old_inode, 181562306a36Sopenharmony_ci const struct fscrypt_name *old_nm, 181662306a36Sopenharmony_ci const struct inode *new_dir, 181762306a36Sopenharmony_ci const struct inode *new_inode, 181862306a36Sopenharmony_ci const struct fscrypt_name *new_nm, 181962306a36Sopenharmony_ci const struct inode *whiteout, int sync); 182062306a36Sopenharmony_ciint ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, 182162306a36Sopenharmony_ci loff_t old_size, loff_t new_size); 182262306a36Sopenharmony_ciint ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host, 182362306a36Sopenharmony_ci const struct inode *inode, const struct fscrypt_name *nm); 182462306a36Sopenharmony_ciint ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1, 182562306a36Sopenharmony_ci const struct inode *inode2); 182662306a36Sopenharmony_ci 182762306a36Sopenharmony_ci/* budget.c */ 182862306a36Sopenharmony_ciint ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req); 182962306a36Sopenharmony_civoid ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req); 183062306a36Sopenharmony_civoid ubifs_release_dirty_inode_budget(struct ubifs_info *c, 183162306a36Sopenharmony_ci struct ubifs_inode *ui); 183262306a36Sopenharmony_ciint ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode, 183362306a36Sopenharmony_ci struct ubifs_budget_req *req); 183462306a36Sopenharmony_civoid ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode, 183562306a36Sopenharmony_ci struct ubifs_budget_req *req); 183662306a36Sopenharmony_civoid ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode, 183762306a36Sopenharmony_ci struct ubifs_budget_req *req); 183862306a36Sopenharmony_cilong long ubifs_get_free_space(struct ubifs_info *c); 183962306a36Sopenharmony_cilong long ubifs_get_free_space_nolock(struct ubifs_info *c); 184062306a36Sopenharmony_ciint ubifs_calc_min_idx_lebs(struct ubifs_info *c); 184162306a36Sopenharmony_civoid ubifs_convert_page_budget(struct ubifs_info *c); 184262306a36Sopenharmony_cilong long ubifs_reported_space(const struct ubifs_info *c, long long free); 184362306a36Sopenharmony_cilong long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); 184462306a36Sopenharmony_ci 184562306a36Sopenharmony_ci/* find.c */ 184662306a36Sopenharmony_ciint ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs, 184762306a36Sopenharmony_ci int squeeze); 184862306a36Sopenharmony_ciint ubifs_find_free_leb_for_idx(struct ubifs_info *c); 184962306a36Sopenharmony_ciint ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp, 185062306a36Sopenharmony_ci int min_space, int pick_free); 185162306a36Sopenharmony_ciint ubifs_find_dirty_idx_leb(struct ubifs_info *c); 185262306a36Sopenharmony_ciint ubifs_save_dirty_idx_lnums(struct ubifs_info *c); 185362306a36Sopenharmony_ci 185462306a36Sopenharmony_ci/* tnc.c */ 185562306a36Sopenharmony_ciint ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, 185662306a36Sopenharmony_ci struct ubifs_znode **zn, int *n); 185762306a36Sopenharmony_ciint ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key, 185862306a36Sopenharmony_ci void *node, const struct fscrypt_name *nm); 185962306a36Sopenharmony_ciint ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, 186062306a36Sopenharmony_ci void *node, uint32_t secondary_hash); 186162306a36Sopenharmony_ciint ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key, 186262306a36Sopenharmony_ci void *node, int *lnum, int *offs); 186362306a36Sopenharmony_ciint ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, 186462306a36Sopenharmony_ci int offs, int len, const u8 *hash); 186562306a36Sopenharmony_ciint ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key, 186662306a36Sopenharmony_ci int old_lnum, int old_offs, int lnum, int offs, int len); 186762306a36Sopenharmony_ciint ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, 186862306a36Sopenharmony_ci int lnum, int offs, int len, const u8 *hash, 186962306a36Sopenharmony_ci const struct fscrypt_name *nm); 187062306a36Sopenharmony_ciint ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key); 187162306a36Sopenharmony_ciint ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, 187262306a36Sopenharmony_ci const struct fscrypt_name *nm); 187362306a36Sopenharmony_ciint ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, 187462306a36Sopenharmony_ci uint32_t cookie); 187562306a36Sopenharmony_ciint ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key, 187662306a36Sopenharmony_ci union ubifs_key *to_key); 187762306a36Sopenharmony_ciint ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum); 187862306a36Sopenharmony_cistruct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c, 187962306a36Sopenharmony_ci union ubifs_key *key, 188062306a36Sopenharmony_ci const struct fscrypt_name *nm); 188162306a36Sopenharmony_civoid ubifs_tnc_close(struct ubifs_info *c); 188262306a36Sopenharmony_ciint ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level, 188362306a36Sopenharmony_ci int lnum, int offs, int is_idx); 188462306a36Sopenharmony_ciint ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level, 188562306a36Sopenharmony_ci int lnum, int offs); 188662306a36Sopenharmony_ci/* Shared by tnc.c for tnc_commit.c */ 188762306a36Sopenharmony_civoid destroy_old_idx(struct ubifs_info *c); 188862306a36Sopenharmony_ciint is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level, 188962306a36Sopenharmony_ci int lnum, int offs); 189062306a36Sopenharmony_ciint insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode); 189162306a36Sopenharmony_ciint ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu); 189262306a36Sopenharmony_ciint ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu); 189362306a36Sopenharmony_ci 189462306a36Sopenharmony_ci/* tnc_misc.c */ 189562306a36Sopenharmony_cistruct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c, 189662306a36Sopenharmony_ci struct ubifs_znode *zr, 189762306a36Sopenharmony_ci struct ubifs_znode *znode); 189862306a36Sopenharmony_ciint ubifs_search_zbranch(const struct ubifs_info *c, 189962306a36Sopenharmony_ci const struct ubifs_znode *znode, 190062306a36Sopenharmony_ci const union ubifs_key *key, int *n); 190162306a36Sopenharmony_cistruct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode); 190262306a36Sopenharmony_cistruct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c, 190362306a36Sopenharmony_ci struct ubifs_znode *znode); 190462306a36Sopenharmony_cilong ubifs_destroy_tnc_subtree(const struct ubifs_info *c, 190562306a36Sopenharmony_ci struct ubifs_znode *zr); 190662306a36Sopenharmony_cistruct ubifs_znode *ubifs_load_znode(struct ubifs_info *c, 190762306a36Sopenharmony_ci struct ubifs_zbranch *zbr, 190862306a36Sopenharmony_ci struct ubifs_znode *parent, int iip); 190962306a36Sopenharmony_ciint ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr, 191062306a36Sopenharmony_ci void *node); 191162306a36Sopenharmony_ci 191262306a36Sopenharmony_ci/* tnc_commit.c */ 191362306a36Sopenharmony_ciint ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot); 191462306a36Sopenharmony_ciint ubifs_tnc_end_commit(struct ubifs_info *c); 191562306a36Sopenharmony_ci 191662306a36Sopenharmony_ci/* shrinker.c */ 191762306a36Sopenharmony_ciunsigned long ubifs_shrink_scan(struct shrinker *shrink, 191862306a36Sopenharmony_ci struct shrink_control *sc); 191962306a36Sopenharmony_ciunsigned long ubifs_shrink_count(struct shrinker *shrink, 192062306a36Sopenharmony_ci struct shrink_control *sc); 192162306a36Sopenharmony_ci 192262306a36Sopenharmony_ci/* commit.c */ 192362306a36Sopenharmony_ciint ubifs_bg_thread(void *info); 192462306a36Sopenharmony_civoid ubifs_commit_required(struct ubifs_info *c); 192562306a36Sopenharmony_civoid ubifs_request_bg_commit(struct ubifs_info *c); 192662306a36Sopenharmony_ciint ubifs_run_commit(struct ubifs_info *c); 192762306a36Sopenharmony_civoid ubifs_recovery_commit(struct ubifs_info *c); 192862306a36Sopenharmony_ciint ubifs_gc_should_commit(struct ubifs_info *c); 192962306a36Sopenharmony_civoid ubifs_wait_for_commit(struct ubifs_info *c); 193062306a36Sopenharmony_ci 193162306a36Sopenharmony_ci/* master.c */ 193262306a36Sopenharmony_ciint ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2); 193362306a36Sopenharmony_ciint ubifs_read_master(struct ubifs_info *c); 193462306a36Sopenharmony_ciint ubifs_write_master(struct ubifs_info *c); 193562306a36Sopenharmony_ci 193662306a36Sopenharmony_ci/* sb.c */ 193762306a36Sopenharmony_ciint ubifs_read_superblock(struct ubifs_info *c); 193862306a36Sopenharmony_ciint ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup); 193962306a36Sopenharmony_ciint ubifs_fixup_free_space(struct ubifs_info *c); 194062306a36Sopenharmony_ciint ubifs_enable_encryption(struct ubifs_info *c); 194162306a36Sopenharmony_ci 194262306a36Sopenharmony_ci/* replay.c */ 194362306a36Sopenharmony_ciint ubifs_validate_entry(struct ubifs_info *c, 194462306a36Sopenharmony_ci const struct ubifs_dent_node *dent); 194562306a36Sopenharmony_ciint ubifs_replay_journal(struct ubifs_info *c); 194662306a36Sopenharmony_ci 194762306a36Sopenharmony_ci/* gc.c */ 194862306a36Sopenharmony_ciint ubifs_garbage_collect(struct ubifs_info *c, int anyway); 194962306a36Sopenharmony_ciint ubifs_gc_start_commit(struct ubifs_info *c); 195062306a36Sopenharmony_ciint ubifs_gc_end_commit(struct ubifs_info *c); 195162306a36Sopenharmony_civoid ubifs_destroy_idx_gc(struct ubifs_info *c); 195262306a36Sopenharmony_ciint ubifs_get_idx_gc_leb(struct ubifs_info *c); 195362306a36Sopenharmony_ciint ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp); 195462306a36Sopenharmony_ci 195562306a36Sopenharmony_ci/* orphan.c */ 195662306a36Sopenharmony_ciint ubifs_add_orphan(struct ubifs_info *c, ino_t inum); 195762306a36Sopenharmony_civoid ubifs_delete_orphan(struct ubifs_info *c, ino_t inum); 195862306a36Sopenharmony_ciint ubifs_orphan_start_commit(struct ubifs_info *c); 195962306a36Sopenharmony_ciint ubifs_orphan_end_commit(struct ubifs_info *c); 196062306a36Sopenharmony_ciint ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only); 196162306a36Sopenharmony_ciint ubifs_clear_orphans(struct ubifs_info *c); 196262306a36Sopenharmony_ci 196362306a36Sopenharmony_ci/* lpt.c */ 196462306a36Sopenharmony_ciint ubifs_calc_lpt_geom(struct ubifs_info *c); 196562306a36Sopenharmony_ciint ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, 196662306a36Sopenharmony_ci int *lpt_lebs, int *big_lpt, u8 *hash); 196762306a36Sopenharmony_ciint ubifs_lpt_init(struct ubifs_info *c, int rd, int wr); 196862306a36Sopenharmony_cistruct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum); 196962306a36Sopenharmony_cistruct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum); 197062306a36Sopenharmony_ciint ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum, 197162306a36Sopenharmony_ci ubifs_lpt_scan_callback scan_cb, void *data); 197262306a36Sopenharmony_ci 197362306a36Sopenharmony_ci/* Shared by lpt.c for lpt_commit.c */ 197462306a36Sopenharmony_civoid ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave); 197562306a36Sopenharmony_civoid ubifs_pack_ltab(struct ubifs_info *c, void *buf, 197662306a36Sopenharmony_ci struct ubifs_lpt_lprops *ltab); 197762306a36Sopenharmony_civoid ubifs_pack_pnode(struct ubifs_info *c, void *buf, 197862306a36Sopenharmony_ci struct ubifs_pnode *pnode); 197962306a36Sopenharmony_civoid ubifs_pack_nnode(struct ubifs_info *c, void *buf, 198062306a36Sopenharmony_ci struct ubifs_nnode *nnode); 198162306a36Sopenharmony_cistruct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c, 198262306a36Sopenharmony_ci struct ubifs_nnode *parent, int iip); 198362306a36Sopenharmony_cistruct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c, 198462306a36Sopenharmony_ci struct ubifs_nnode *parent, int iip); 198562306a36Sopenharmony_cistruct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i); 198662306a36Sopenharmony_ciint ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip); 198762306a36Sopenharmony_civoid ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty); 198862306a36Sopenharmony_civoid ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode); 198962306a36Sopenharmony_ciuint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits); 199062306a36Sopenharmony_cistruct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght); 199162306a36Sopenharmony_ci/* Needed only in debugging code in lpt_commit.c */ 199262306a36Sopenharmony_ciint ubifs_unpack_nnode(const struct ubifs_info *c, void *buf, 199362306a36Sopenharmony_ci struct ubifs_nnode *nnode); 199462306a36Sopenharmony_ciint ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash); 199562306a36Sopenharmony_ci 199662306a36Sopenharmony_ci/* lpt_commit.c */ 199762306a36Sopenharmony_ciint ubifs_lpt_start_commit(struct ubifs_info *c); 199862306a36Sopenharmony_ciint ubifs_lpt_end_commit(struct ubifs_info *c); 199962306a36Sopenharmony_ciint ubifs_lpt_post_commit(struct ubifs_info *c); 200062306a36Sopenharmony_civoid ubifs_lpt_free(struct ubifs_info *c, int wr_only); 200162306a36Sopenharmony_ci 200262306a36Sopenharmony_ci/* lprops.c */ 200362306a36Sopenharmony_ciconst struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, 200462306a36Sopenharmony_ci const struct ubifs_lprops *lp, 200562306a36Sopenharmony_ci int free, int dirty, int flags, 200662306a36Sopenharmony_ci int idx_gc_cnt); 200762306a36Sopenharmony_civoid ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst); 200862306a36Sopenharmony_civoid ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, 200962306a36Sopenharmony_ci int cat); 201062306a36Sopenharmony_civoid ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, 201162306a36Sopenharmony_ci struct ubifs_lprops *new_lprops); 201262306a36Sopenharmony_civoid ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops); 201362306a36Sopenharmony_ciint ubifs_categorize_lprops(const struct ubifs_info *c, 201462306a36Sopenharmony_ci const struct ubifs_lprops *lprops); 201562306a36Sopenharmony_ciint ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, 201662306a36Sopenharmony_ci int flags_set, int flags_clean, int idx_gc_cnt); 201762306a36Sopenharmony_ciint ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, 201862306a36Sopenharmony_ci int flags_set, int flags_clean); 201962306a36Sopenharmony_ciint ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp); 202062306a36Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c); 202162306a36Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c); 202262306a36Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c); 202362306a36Sopenharmony_ciconst struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c); 202462306a36Sopenharmony_ciint ubifs_calc_dark(const struct ubifs_info *c, int spc); 202562306a36Sopenharmony_ci 202662306a36Sopenharmony_ci/* file.c */ 202762306a36Sopenharmony_ciint ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync); 202862306a36Sopenharmony_ciint ubifs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, 202962306a36Sopenharmony_ci struct iattr *attr); 203062306a36Sopenharmony_ciint ubifs_update_time(struct inode *inode, int flags); 203162306a36Sopenharmony_ci 203262306a36Sopenharmony_ci/* dir.c */ 203362306a36Sopenharmony_cistruct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, 203462306a36Sopenharmony_ci umode_t mode, bool is_xattr); 203562306a36Sopenharmony_ciint ubifs_getattr(struct mnt_idmap *idmap, const struct path *path, 203662306a36Sopenharmony_ci struct kstat *stat, u32 request_mask, unsigned int flags); 203762306a36Sopenharmony_ciint ubifs_check_dir_empty(struct inode *dir); 203862306a36Sopenharmony_ci 203962306a36Sopenharmony_ci/* xattr.c */ 204062306a36Sopenharmony_ciint ubifs_xattr_set(struct inode *host, const char *name, const void *value, 204162306a36Sopenharmony_ci size_t size, int flags, bool check_lock); 204262306a36Sopenharmony_cissize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf, 204362306a36Sopenharmony_ci size_t size); 204462306a36Sopenharmony_ci 204562306a36Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_XATTR 204662306a36Sopenharmony_ciextern const struct xattr_handler *ubifs_xattr_handlers[]; 204762306a36Sopenharmony_cissize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); 204862306a36Sopenharmony_civoid ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum); 204962306a36Sopenharmony_ciint ubifs_purge_xattrs(struct inode *host); 205062306a36Sopenharmony_ci#else 205162306a36Sopenharmony_ci#define ubifs_listxattr NULL 205262306a36Sopenharmony_ci#define ubifs_xattr_handlers NULL 205362306a36Sopenharmony_cistatic inline void ubifs_evict_xattr_inode(struct ubifs_info *c, 205462306a36Sopenharmony_ci ino_t xattr_inum) { } 205562306a36Sopenharmony_cistatic inline int ubifs_purge_xattrs(struct inode *host) 205662306a36Sopenharmony_ci{ 205762306a36Sopenharmony_ci return 0; 205862306a36Sopenharmony_ci} 205962306a36Sopenharmony_ci#endif 206062306a36Sopenharmony_ci 206162306a36Sopenharmony_ci#ifdef CONFIG_UBIFS_FS_SECURITY 206262306a36Sopenharmony_ciextern int ubifs_init_security(struct inode *dentry, struct inode *inode, 206362306a36Sopenharmony_ci const struct qstr *qstr); 206462306a36Sopenharmony_ci#else 206562306a36Sopenharmony_cistatic inline int ubifs_init_security(struct inode *dentry, 206662306a36Sopenharmony_ci struct inode *inode, const struct qstr *qstr) 206762306a36Sopenharmony_ci{ 206862306a36Sopenharmony_ci return 0; 206962306a36Sopenharmony_ci} 207062306a36Sopenharmony_ci#endif 207162306a36Sopenharmony_ci 207262306a36Sopenharmony_ci 207362306a36Sopenharmony_ci/* super.c */ 207462306a36Sopenharmony_cistruct inode *ubifs_iget(struct super_block *sb, unsigned long inum); 207562306a36Sopenharmony_ci 207662306a36Sopenharmony_ci/* recovery.c */ 207762306a36Sopenharmony_ciint ubifs_recover_master_node(struct ubifs_info *c); 207862306a36Sopenharmony_ciint ubifs_write_rcvrd_mst_node(struct ubifs_info *c); 207962306a36Sopenharmony_cistruct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum, 208062306a36Sopenharmony_ci int offs, void *sbuf, int jhead); 208162306a36Sopenharmony_cistruct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum, 208262306a36Sopenharmony_ci int offs, void *sbuf); 208362306a36Sopenharmony_ciint ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf); 208462306a36Sopenharmony_ciint ubifs_clean_lebs(struct ubifs_info *c, void *sbuf); 208562306a36Sopenharmony_ciint ubifs_rcvry_gc_commit(struct ubifs_info *c); 208662306a36Sopenharmony_ciint ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key, 208762306a36Sopenharmony_ci int deletion, loff_t new_size); 208862306a36Sopenharmony_ciint ubifs_recover_size(struct ubifs_info *c, bool in_place); 208962306a36Sopenharmony_civoid ubifs_destroy_size_tree(struct ubifs_info *c); 209062306a36Sopenharmony_ci 209162306a36Sopenharmony_ci/* ioctl.c */ 209262306a36Sopenharmony_ciint ubifs_fileattr_get(struct dentry *dentry, struct fileattr *fa); 209362306a36Sopenharmony_ciint ubifs_fileattr_set(struct mnt_idmap *idmap, 209462306a36Sopenharmony_ci struct dentry *dentry, struct fileattr *fa); 209562306a36Sopenharmony_cilong ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 209662306a36Sopenharmony_civoid ubifs_set_inode_flags(struct inode *inode); 209762306a36Sopenharmony_ci#ifdef CONFIG_COMPAT 209862306a36Sopenharmony_cilong ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 209962306a36Sopenharmony_ci#endif 210062306a36Sopenharmony_ci 210162306a36Sopenharmony_ci/* compressor.c */ 210262306a36Sopenharmony_ciint __init ubifs_compressors_init(void); 210362306a36Sopenharmony_civoid ubifs_compressors_exit(void); 210462306a36Sopenharmony_civoid ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len, 210562306a36Sopenharmony_ci void *out_buf, int *out_len, int *compr_type); 210662306a36Sopenharmony_ciint ubifs_decompress(const struct ubifs_info *c, const void *buf, int len, 210762306a36Sopenharmony_ci void *out, int *out_len, int compr_type); 210862306a36Sopenharmony_ci 210962306a36Sopenharmony_ci/* sysfs.c */ 211062306a36Sopenharmony_ciint ubifs_sysfs_init(void); 211162306a36Sopenharmony_civoid ubifs_sysfs_exit(void); 211262306a36Sopenharmony_ciint ubifs_sysfs_register(struct ubifs_info *c); 211362306a36Sopenharmony_civoid ubifs_sysfs_unregister(struct ubifs_info *c); 211462306a36Sopenharmony_ci 211562306a36Sopenharmony_ci#include "debug.h" 211662306a36Sopenharmony_ci#include "misc.h" 211762306a36Sopenharmony_ci#include "key.h" 211862306a36Sopenharmony_ci 211962306a36Sopenharmony_ci#ifndef CONFIG_FS_ENCRYPTION 212062306a36Sopenharmony_cistatic inline int ubifs_encrypt(const struct inode *inode, 212162306a36Sopenharmony_ci struct ubifs_data_node *dn, 212262306a36Sopenharmony_ci unsigned int in_len, unsigned int *out_len, 212362306a36Sopenharmony_ci int block) 212462306a36Sopenharmony_ci{ 212562306a36Sopenharmony_ci struct ubifs_info *c = inode->i_sb->s_fs_info; 212662306a36Sopenharmony_ci ubifs_assert(c, 0); 212762306a36Sopenharmony_ci return -EOPNOTSUPP; 212862306a36Sopenharmony_ci} 212962306a36Sopenharmony_cistatic inline int ubifs_decrypt(const struct inode *inode, 213062306a36Sopenharmony_ci struct ubifs_data_node *dn, 213162306a36Sopenharmony_ci unsigned int *out_len, int block) 213262306a36Sopenharmony_ci{ 213362306a36Sopenharmony_ci struct ubifs_info *c = inode->i_sb->s_fs_info; 213462306a36Sopenharmony_ci ubifs_assert(c, 0); 213562306a36Sopenharmony_ci return -EOPNOTSUPP; 213662306a36Sopenharmony_ci} 213762306a36Sopenharmony_ci#else 213862306a36Sopenharmony_ci/* crypto.c */ 213962306a36Sopenharmony_ciint ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn, 214062306a36Sopenharmony_ci unsigned int in_len, unsigned int *out_len, int block); 214162306a36Sopenharmony_ciint ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn, 214262306a36Sopenharmony_ci unsigned int *out_len, int block); 214362306a36Sopenharmony_ci#endif 214462306a36Sopenharmony_ci 214562306a36Sopenharmony_ciextern const struct fscrypt_operations ubifs_crypt_operations; 214662306a36Sopenharmony_ci 214762306a36Sopenharmony_ci/* Normal UBIFS messages */ 214862306a36Sopenharmony_ci__printf(2, 3) 214962306a36Sopenharmony_civoid ubifs_msg(const struct ubifs_info *c, const char *fmt, ...); 215062306a36Sopenharmony_ci__printf(2, 3) 215162306a36Sopenharmony_civoid ubifs_err(const struct ubifs_info *c, const char *fmt, ...); 215262306a36Sopenharmony_ci__printf(2, 3) 215362306a36Sopenharmony_civoid ubifs_warn(const struct ubifs_info *c, const char *fmt, ...); 215462306a36Sopenharmony_ci/* 215562306a36Sopenharmony_ci * A conditional variant of 'ubifs_err()' which doesn't output anything 215662306a36Sopenharmony_ci * if probing (ie. SB_SILENT set). 215762306a36Sopenharmony_ci */ 215862306a36Sopenharmony_ci#define ubifs_errc(c, fmt, ...) \ 215962306a36Sopenharmony_cido { \ 216062306a36Sopenharmony_ci if (!(c)->probing) \ 216162306a36Sopenharmony_ci ubifs_err(c, fmt, ##__VA_ARGS__); \ 216262306a36Sopenharmony_ci} while (0) 216362306a36Sopenharmony_ci 216462306a36Sopenharmony_ci#endif /* !__UBIFS_H__ */ 2165