xref: /openbmc/linux/fs/ubifs/ubifs.h (revision 553dea4d)
11e51764aSArtem Bityutskiy /*
21e51764aSArtem Bityutskiy  * This file is part of UBIFS.
31e51764aSArtem Bityutskiy  *
41e51764aSArtem Bityutskiy  * Copyright (C) 2006-2008 Nokia Corporation
51e51764aSArtem Bityutskiy  *
61e51764aSArtem Bityutskiy  * This program is free software; you can redistribute it and/or modify it
71e51764aSArtem Bityutskiy  * under the terms of the GNU General Public License version 2 as published by
81e51764aSArtem Bityutskiy  * the Free Software Foundation.
91e51764aSArtem Bityutskiy  *
101e51764aSArtem Bityutskiy  * This program is distributed in the hope that it will be useful, but WITHOUT
111e51764aSArtem Bityutskiy  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
121e51764aSArtem Bityutskiy  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
131e51764aSArtem Bityutskiy  * more details.
141e51764aSArtem Bityutskiy  *
151e51764aSArtem Bityutskiy  * You should have received a copy of the GNU General Public License along with
161e51764aSArtem Bityutskiy  * this program; if not, write to the Free Software Foundation, Inc., 51
171e51764aSArtem Bityutskiy  * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
181e51764aSArtem Bityutskiy  *
191e51764aSArtem Bityutskiy  * Authors: Artem Bityutskiy (Битюцкий Артём)
201e51764aSArtem Bityutskiy  *          Adrian Hunter
211e51764aSArtem Bityutskiy  */
221e51764aSArtem Bityutskiy 
231e51764aSArtem Bityutskiy #ifndef __UBIFS_H__
241e51764aSArtem Bityutskiy #define __UBIFS_H__
251e51764aSArtem Bityutskiy 
261e51764aSArtem Bityutskiy #include <asm/div64.h>
271e51764aSArtem Bityutskiy #include <linux/statfs.h>
281e51764aSArtem Bityutskiy #include <linux/fs.h>
291e51764aSArtem Bityutskiy #include <linux/err.h>
301e51764aSArtem Bityutskiy #include <linux/sched.h>
311e51764aSArtem Bityutskiy #include <linux/vmalloc.h>
321e51764aSArtem Bityutskiy #include <linux/spinlock.h>
331e51764aSArtem Bityutskiy #include <linux/mutex.h>
341e51764aSArtem Bityutskiy #include <linux/rwsem.h>
351e51764aSArtem Bityutskiy #include <linux/mtd/ubi.h>
361e51764aSArtem Bityutskiy #include <linux/pagemap.h>
371e51764aSArtem Bityutskiy #include <linux/backing-dev.h>
381e51764aSArtem Bityutskiy #include "ubifs-media.h"
391e51764aSArtem Bityutskiy 
401e51764aSArtem Bityutskiy /* Version of this UBIFS implementation */
411e51764aSArtem Bityutskiy #define UBIFS_VERSION 1
421e51764aSArtem Bityutskiy 
431e51764aSArtem Bityutskiy /* Normal UBIFS messages */
441e51764aSArtem Bityutskiy #define ubifs_msg(fmt, ...) \
451e51764aSArtem Bityutskiy 		printk(KERN_NOTICE "UBIFS: " fmt "\n", ##__VA_ARGS__)
461e51764aSArtem Bityutskiy /* UBIFS error messages */
471e51764aSArtem Bityutskiy #define ubifs_err(fmt, ...)                                                  \
481e51764aSArtem Bityutskiy 	printk(KERN_ERR "UBIFS error (pid %d): %s: " fmt "\n", current->pid, \
491e51764aSArtem Bityutskiy 	       __func__, ##__VA_ARGS__)
501e51764aSArtem Bityutskiy /* UBIFS warning messages */
511e51764aSArtem Bityutskiy #define ubifs_warn(fmt, ...)                                         \
521e51764aSArtem Bityutskiy 	printk(KERN_WARNING "UBIFS warning (pid %d): %s: " fmt "\n", \
531e51764aSArtem Bityutskiy 	       current->pid, __func__, ##__VA_ARGS__)
541e51764aSArtem Bityutskiy 
551e51764aSArtem Bityutskiy /* UBIFS file system VFS magic number */
561e51764aSArtem Bityutskiy #define UBIFS_SUPER_MAGIC 0x24051905
571e51764aSArtem Bityutskiy 
581e51764aSArtem Bityutskiy /* Number of UBIFS blocks per VFS page */
591e51764aSArtem Bityutskiy #define UBIFS_BLOCKS_PER_PAGE (PAGE_CACHE_SIZE / UBIFS_BLOCK_SIZE)
601e51764aSArtem Bityutskiy #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_CACHE_SHIFT - UBIFS_BLOCK_SHIFT)
611e51764aSArtem Bityutskiy 
621e51764aSArtem Bityutskiy /* "File system end of life" sequence number watermark */
631e51764aSArtem Bityutskiy #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
641e51764aSArtem Bityutskiy #define SQNUM_WATERMARK      0xFFFFFFFFFF000000ULL
651e51764aSArtem Bityutskiy 
661e51764aSArtem Bityutskiy /* Minimum amount of data UBIFS writes to the flash */
671e51764aSArtem Bityutskiy #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
681e51764aSArtem Bityutskiy 
691e51764aSArtem Bityutskiy /*
701e51764aSArtem Bityutskiy  * Currently we do not support inode number overlapping and re-using, so this
711e51764aSArtem Bityutskiy  * watermark defines dangerous inode number level. This should be fixed later,
721e51764aSArtem Bityutskiy  * although it is difficult to exceed current limit. Another option is to use
731e51764aSArtem Bityutskiy  * 64-bit inode numbers, but this means more overhead.
741e51764aSArtem Bityutskiy  */
751e51764aSArtem Bityutskiy #define INUM_WARN_WATERMARK 0xFFF00000
761e51764aSArtem Bityutskiy #define INUM_WATERMARK      0xFFFFFF00
771e51764aSArtem Bityutskiy 
781e51764aSArtem Bityutskiy /* Largest key size supported in this implementation */
791e51764aSArtem Bityutskiy #define CUR_MAX_KEY_LEN UBIFS_SK_LEN
801e51764aSArtem Bityutskiy 
811e51764aSArtem Bityutskiy /* Maximum number of entries in each LPT (LEB category) heap */
821e51764aSArtem Bityutskiy #define LPT_HEAP_SZ 256
831e51764aSArtem Bityutskiy 
841e51764aSArtem Bityutskiy /*
851e51764aSArtem Bityutskiy  * Background thread name pattern. The numbers are UBI device and volume
861e51764aSArtem Bityutskiy  * numbers.
871e51764aSArtem Bityutskiy  */
881e51764aSArtem Bityutskiy #define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
891e51764aSArtem Bityutskiy 
901e51764aSArtem Bityutskiy /* Default write-buffer synchronization timeout (5 secs) */
911e51764aSArtem Bityutskiy #define DEFAULT_WBUF_TIMEOUT (5 * HZ)
921e51764aSArtem Bityutskiy 
931e51764aSArtem Bityutskiy /* Maximum possible inode number (only 32-bit inodes are supported now) */
941e51764aSArtem Bityutskiy #define MAX_INUM 0xFFFFFFFF
951e51764aSArtem Bityutskiy 
961e51764aSArtem Bityutskiy /* Number of non-data journal heads */
971e51764aSArtem Bityutskiy #define NONDATA_JHEADS_CNT 2
981e51764aSArtem Bityutskiy 
991e51764aSArtem Bityutskiy /* Garbage collector head */
1001e51764aSArtem Bityutskiy #define GCHD   0
1011e51764aSArtem Bityutskiy /* Base journal head number */
1021e51764aSArtem Bityutskiy #define BASEHD 1
1031e51764aSArtem Bityutskiy /* First "general purpose" journal head */
1041e51764aSArtem Bityutskiy #define DATAHD 2
1051e51764aSArtem Bityutskiy 
1061e51764aSArtem Bityutskiy /* 'No change' value for 'ubifs_change_lp()' */
1071e51764aSArtem Bityutskiy #define LPROPS_NC 0x80000001
1081e51764aSArtem Bityutskiy 
1091e51764aSArtem Bityutskiy /*
1101e51764aSArtem Bityutskiy  * There is no notion of truncation key because truncation nodes do not exist
1111e51764aSArtem Bityutskiy  * in TNC. However, when replaying, it is handy to introduce fake "truncation"
1121e51764aSArtem Bityutskiy  * keys for truncation nodes because the code becomes simpler. So we define
1131e51764aSArtem Bityutskiy  * %UBIFS_TRUN_KEY type.
1141e51764aSArtem Bityutskiy  */
1151e51764aSArtem Bityutskiy #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT
1161e51764aSArtem Bityutskiy 
1171e51764aSArtem Bityutskiy /*
1181e51764aSArtem Bityutskiy  * How much a directory entry/extended attribute entry adds to the parent/host
1191e51764aSArtem Bityutskiy  * inode.
1201e51764aSArtem Bityutskiy  */
1211e51764aSArtem Bityutskiy #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
1221e51764aSArtem Bityutskiy 
1231e51764aSArtem Bityutskiy /* How much an extended attribute adds to the host inode */
1241e51764aSArtem Bityutskiy #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
1251e51764aSArtem Bityutskiy 
1261e51764aSArtem Bityutskiy /*
1271e51764aSArtem Bityutskiy  * Znodes which were not touched for 'OLD_ZNODE_AGE' seconds are considered
1281e51764aSArtem Bityutskiy  * "old", and znode which were touched last 'YOUNG_ZNODE_AGE' seconds ago are
1291e51764aSArtem Bityutskiy  * considered "young". This is used by shrinker when selecting znode to trim
1301e51764aSArtem Bityutskiy  * off.
1311e51764aSArtem Bityutskiy  */
1321e51764aSArtem Bityutskiy #define OLD_ZNODE_AGE 20
1331e51764aSArtem Bityutskiy #define YOUNG_ZNODE_AGE 5
1341e51764aSArtem Bityutskiy 
1351e51764aSArtem Bityutskiy /*
1361e51764aSArtem Bityutskiy  * Some compressors, like LZO, may end up with more data then the input buffer.
1371e51764aSArtem Bityutskiy  * So UBIFS always allocates larger output buffer, to be sure the compressor
1381e51764aSArtem Bityutskiy  * will not corrupt memory in case of worst case compression.
1391e51764aSArtem Bityutskiy  */
1401e51764aSArtem Bityutskiy #define WORST_COMPR_FACTOR 2
1411e51764aSArtem Bityutskiy 
1421e51764aSArtem Bityutskiy /* Maximum expected tree height for use by bottom_up_buf */
1431e51764aSArtem Bityutskiy #define BOTTOM_UP_HEIGHT 64
1441e51764aSArtem Bityutskiy 
1454793e7c5SAdrian Hunter /* Maximum number of data nodes to bulk-read */
1464793e7c5SAdrian Hunter #define UBIFS_MAX_BULK_READ 32
1474793e7c5SAdrian Hunter 
1481e51764aSArtem Bityutskiy /*
1491e51764aSArtem Bityutskiy  * Lockdep classes for UBIFS inode @ui_mutex.
1501e51764aSArtem Bityutskiy  */
1511e51764aSArtem Bityutskiy enum {
1521e51764aSArtem Bityutskiy 	WB_MUTEX_1 = 0,
1531e51764aSArtem Bityutskiy 	WB_MUTEX_2 = 1,
1541e51764aSArtem Bityutskiy 	WB_MUTEX_3 = 2,
1551e51764aSArtem Bityutskiy };
1561e51764aSArtem Bityutskiy 
1571e51764aSArtem Bityutskiy /*
1581e51764aSArtem Bityutskiy  * Znode flags (actually, bit numbers which store the flags).
1591e51764aSArtem Bityutskiy  *
1601e51764aSArtem Bityutskiy  * DIRTY_ZNODE: znode is dirty
1611e51764aSArtem Bityutskiy  * COW_ZNODE: znode is being committed and a new instance of this znode has to
1621e51764aSArtem Bityutskiy  *            be created before changing this znode
1631e51764aSArtem Bityutskiy  * OBSOLETE_ZNODE: znode is obsolete, which means it was deleted, but it is
1641e51764aSArtem Bityutskiy  *                 still in the commit list and the ongoing commit operation
1651e51764aSArtem Bityutskiy  *                 will commit it, and delete this znode after it is done
1661e51764aSArtem Bityutskiy  */
1671e51764aSArtem Bityutskiy enum {
1681e51764aSArtem Bityutskiy 	DIRTY_ZNODE    = 0,
1691e51764aSArtem Bityutskiy 	COW_ZNODE      = 1,
1701e51764aSArtem Bityutskiy 	OBSOLETE_ZNODE = 2,
1711e51764aSArtem Bityutskiy };
1721e51764aSArtem Bityutskiy 
1731e51764aSArtem Bityutskiy /*
1741e51764aSArtem Bityutskiy  * Commit states.
1751e51764aSArtem Bityutskiy  *
1761e51764aSArtem Bityutskiy  * COMMIT_RESTING: commit is not wanted
1771e51764aSArtem Bityutskiy  * COMMIT_BACKGROUND: background commit has been requested
1781e51764aSArtem Bityutskiy  * COMMIT_REQUIRED: commit is required
1791e51764aSArtem Bityutskiy  * COMMIT_RUNNING_BACKGROUND: background commit is running
1801e51764aSArtem Bityutskiy  * COMMIT_RUNNING_REQUIRED: commit is running and it is required
1811e51764aSArtem Bityutskiy  * COMMIT_BROKEN: commit failed
1821e51764aSArtem Bityutskiy  */
1831e51764aSArtem Bityutskiy enum {
1841e51764aSArtem Bityutskiy 	COMMIT_RESTING = 0,
1851e51764aSArtem Bityutskiy 	COMMIT_BACKGROUND,
1861e51764aSArtem Bityutskiy 	COMMIT_REQUIRED,
1871e51764aSArtem Bityutskiy 	COMMIT_RUNNING_BACKGROUND,
1881e51764aSArtem Bityutskiy 	COMMIT_RUNNING_REQUIRED,
1891e51764aSArtem Bityutskiy 	COMMIT_BROKEN,
1901e51764aSArtem Bityutskiy };
1911e51764aSArtem Bityutskiy 
1921e51764aSArtem Bityutskiy /*
1931e51764aSArtem Bityutskiy  * 'ubifs_scan_a_node()' return values.
1941e51764aSArtem Bityutskiy  *
1951e51764aSArtem Bityutskiy  * SCANNED_GARBAGE:  scanned garbage
1961e51764aSArtem Bityutskiy  * SCANNED_EMPTY_SPACE: scanned empty space
1971e51764aSArtem Bityutskiy  * SCANNED_A_NODE: scanned a valid node
1981e51764aSArtem Bityutskiy  * SCANNED_A_CORRUPT_NODE: scanned a corrupted node
1991e51764aSArtem Bityutskiy  * SCANNED_A_BAD_PAD_NODE: scanned a padding node with invalid pad length
2001e51764aSArtem Bityutskiy  *
2011e51764aSArtem Bityutskiy  * Greater than zero means: 'scanned that number of padding bytes'
2021e51764aSArtem Bityutskiy  */
2031e51764aSArtem Bityutskiy enum {
2041e51764aSArtem Bityutskiy 	SCANNED_GARBAGE        = 0,
2051e51764aSArtem Bityutskiy 	SCANNED_EMPTY_SPACE    = -1,
2061e51764aSArtem Bityutskiy 	SCANNED_A_NODE         = -2,
2071e51764aSArtem Bityutskiy 	SCANNED_A_CORRUPT_NODE = -3,
2081e51764aSArtem Bityutskiy 	SCANNED_A_BAD_PAD_NODE = -4,
2091e51764aSArtem Bityutskiy };
2101e51764aSArtem Bityutskiy 
2111e51764aSArtem Bityutskiy /*
2121e51764aSArtem Bityutskiy  * LPT cnode flag bits.
2131e51764aSArtem Bityutskiy  *
2141e51764aSArtem Bityutskiy  * DIRTY_CNODE: cnode is dirty
2151e51764aSArtem Bityutskiy  * COW_CNODE: cnode is being committed and must be copied before writing
2161e51764aSArtem Bityutskiy  * OBSOLETE_CNODE: cnode is being committed and has been copied (or deleted),
2171e51764aSArtem Bityutskiy  * so it can (and must) be freed when the commit is finished
2181e51764aSArtem Bityutskiy  */
2191e51764aSArtem Bityutskiy enum {
2201e51764aSArtem Bityutskiy 	DIRTY_CNODE    = 0,
2211e51764aSArtem Bityutskiy 	COW_CNODE      = 1,
2221e51764aSArtem Bityutskiy 	OBSOLETE_CNODE = 2,
2231e51764aSArtem Bityutskiy };
2241e51764aSArtem Bityutskiy 
2251e51764aSArtem Bityutskiy /*
2261e51764aSArtem Bityutskiy  * Dirty flag bits (lpt_drty_flgs) for LPT special nodes.
2271e51764aSArtem Bityutskiy  *
2281e51764aSArtem Bityutskiy  * LTAB_DIRTY: ltab node is dirty
2291e51764aSArtem Bityutskiy  * LSAVE_DIRTY: lsave node is dirty
2301e51764aSArtem Bityutskiy  */
2311e51764aSArtem Bityutskiy enum {
2321e51764aSArtem Bityutskiy 	LTAB_DIRTY  = 1,
2331e51764aSArtem Bityutskiy 	LSAVE_DIRTY = 2,
2341e51764aSArtem Bityutskiy };
2351e51764aSArtem Bityutskiy 
2361e51764aSArtem Bityutskiy /*
2371e51764aSArtem Bityutskiy  * Return codes used by the garbage collector.
2381e51764aSArtem Bityutskiy  * @LEB_FREED: the logical eraseblock was freed and is ready to use
2391e51764aSArtem Bityutskiy  * @LEB_FREED_IDX: indexing LEB was freed and can be used only after the commit
2401e51764aSArtem Bityutskiy  * @LEB_RETAINED: the logical eraseblock was freed and retained for GC purposes
2411e51764aSArtem Bityutskiy  */
2421e51764aSArtem Bityutskiy enum {
2431e51764aSArtem Bityutskiy 	LEB_FREED,
2441e51764aSArtem Bityutskiy 	LEB_FREED_IDX,
2451e51764aSArtem Bityutskiy 	LEB_RETAINED,
2461e51764aSArtem Bityutskiy };
2471e51764aSArtem Bityutskiy 
2481e51764aSArtem Bityutskiy /**
2491e51764aSArtem Bityutskiy  * struct ubifs_old_idx - index node obsoleted since last commit start.
2501e51764aSArtem Bityutskiy  * @rb: rb-tree node
2511e51764aSArtem Bityutskiy  * @lnum: LEB number of obsoleted index node
2521e51764aSArtem Bityutskiy  * @offs: offset of obsoleted index node
2531e51764aSArtem Bityutskiy  */
2541e51764aSArtem Bityutskiy struct ubifs_old_idx {
2551e51764aSArtem Bityutskiy 	struct rb_node rb;
2561e51764aSArtem Bityutskiy 	int lnum;
2571e51764aSArtem Bityutskiy 	int offs;
2581e51764aSArtem Bityutskiy };
2591e51764aSArtem Bityutskiy 
2601e51764aSArtem Bityutskiy /* The below union makes it easier to deal with keys */
2611e51764aSArtem Bityutskiy union ubifs_key {
2621e51764aSArtem Bityutskiy 	uint8_t u8[CUR_MAX_KEY_LEN];
2631e51764aSArtem Bityutskiy 	uint32_t u32[CUR_MAX_KEY_LEN/4];
2641e51764aSArtem Bityutskiy 	uint64_t u64[CUR_MAX_KEY_LEN/8];
2651e51764aSArtem Bityutskiy 	__le32 j32[CUR_MAX_KEY_LEN/4];
2661e51764aSArtem Bityutskiy };
2671e51764aSArtem Bityutskiy 
2681e51764aSArtem Bityutskiy /**
2691e51764aSArtem Bityutskiy  * struct ubifs_scan_node - UBIFS scanned node information.
2701e51764aSArtem Bityutskiy  * @list: list of scanned nodes
2711e51764aSArtem Bityutskiy  * @key: key of node scanned (if it has one)
2721e51764aSArtem Bityutskiy  * @sqnum: sequence number
2731e51764aSArtem Bityutskiy  * @type: type of node scanned
2741e51764aSArtem Bityutskiy  * @offs: offset with LEB of node scanned
2751e51764aSArtem Bityutskiy  * @len: length of node scanned
2761e51764aSArtem Bityutskiy  * @node: raw node
2771e51764aSArtem Bityutskiy  */
2781e51764aSArtem Bityutskiy struct ubifs_scan_node {
2791e51764aSArtem Bityutskiy 	struct list_head list;
2801e51764aSArtem Bityutskiy 	union ubifs_key key;
2811e51764aSArtem Bityutskiy 	unsigned long long sqnum;
2821e51764aSArtem Bityutskiy 	int type;
2831e51764aSArtem Bityutskiy 	int offs;
2841e51764aSArtem Bityutskiy 	int len;
2851e51764aSArtem Bityutskiy 	void *node;
2861e51764aSArtem Bityutskiy };
2871e51764aSArtem Bityutskiy 
2881e51764aSArtem Bityutskiy /**
2891e51764aSArtem Bityutskiy  * struct ubifs_scan_leb - UBIFS scanned LEB information.
2901e51764aSArtem Bityutskiy  * @lnum: logical eraseblock number
2911e51764aSArtem Bityutskiy  * @nodes_cnt: number of nodes scanned
2921e51764aSArtem Bityutskiy  * @nodes: list of struct ubifs_scan_node
2931e51764aSArtem Bityutskiy  * @endpt: end point (and therefore the start of empty space)
2941e51764aSArtem Bityutskiy  * @ecc: read returned -EBADMSG
2951e51764aSArtem Bityutskiy  * @buf: buffer containing entire LEB scanned
2961e51764aSArtem Bityutskiy  */
2971e51764aSArtem Bityutskiy struct ubifs_scan_leb {
2981e51764aSArtem Bityutskiy 	int lnum;
2991e51764aSArtem Bityutskiy 	int nodes_cnt;
3001e51764aSArtem Bityutskiy 	struct list_head nodes;
3011e51764aSArtem Bityutskiy 	int endpt;
3021e51764aSArtem Bityutskiy 	int ecc;
3031e51764aSArtem Bityutskiy 	void *buf;
3041e51764aSArtem Bityutskiy };
3051e51764aSArtem Bityutskiy 
3061e51764aSArtem Bityutskiy /**
3071e51764aSArtem Bityutskiy  * struct ubifs_gced_idx_leb - garbage-collected indexing LEB.
3081e51764aSArtem Bityutskiy  * @list: list
3091e51764aSArtem Bityutskiy  * @lnum: LEB number
3101e51764aSArtem Bityutskiy  * @unmap: OK to unmap this LEB
3111e51764aSArtem Bityutskiy  *
3121e51764aSArtem Bityutskiy  * This data structure is used to temporary store garbage-collected indexing
3131e51764aSArtem Bityutskiy  * LEBs - they are not released immediately, but only after the next commit.
3141e51764aSArtem Bityutskiy  * This is needed to guarantee recoverability.
3151e51764aSArtem Bityutskiy  */
3161e51764aSArtem Bityutskiy struct ubifs_gced_idx_leb {
3171e51764aSArtem Bityutskiy 	struct list_head list;
3181e51764aSArtem Bityutskiy 	int lnum;
3191e51764aSArtem Bityutskiy 	int unmap;
3201e51764aSArtem Bityutskiy };
3211e51764aSArtem Bityutskiy 
3221e51764aSArtem Bityutskiy /**
3231e51764aSArtem Bityutskiy  * struct ubifs_inode - UBIFS in-memory inode description.
3241e51764aSArtem Bityutskiy  * @vfs_inode: VFS inode description object
3251e51764aSArtem Bityutskiy  * @creat_sqnum: sequence number at time of creation
326de94eb55SArtem Bityutskiy  * @del_cmtno: commit number corresponding to the time the inode was deleted,
327de94eb55SArtem Bityutskiy  *             protected by @c->commit_sem;
3281e51764aSArtem Bityutskiy  * @xattr_size: summarized size of all extended attributes in bytes
3291e51764aSArtem Bityutskiy  * @xattr_cnt: count of extended attributes this inode has
3301e51764aSArtem Bityutskiy  * @xattr_names: sum of lengths of all extended attribute names belonging to
3311e51764aSArtem Bityutskiy  *               this inode
3321e51764aSArtem Bityutskiy  * @dirty: non-zero if the inode is dirty
3331e51764aSArtem Bityutskiy  * @xattr: non-zero if this is an extended attribute inode
334625bf371SArtem Bityutskiy  * @bulk_read: non-zero if bulk-read should be used
3351e51764aSArtem Bityutskiy  * @ui_mutex: serializes inode write-back with the rest of VFS operations,
3364793e7c5SAdrian Hunter  *            serializes "clean <-> dirty" state changes, serializes bulk-read,
337ba60ecabSArtem Bityutskiy  *            protects @dirty, @bulk_read, @ui_size, and @xattr_size
3381e51764aSArtem Bityutskiy  * @ui_lock: protects @synced_i_size
3391e51764aSArtem Bityutskiy  * @synced_i_size: synchronized size of inode, i.e. the value of inode size
3401e51764aSArtem Bityutskiy  *                 currently stored on the flash; used only for regular file
3411e51764aSArtem Bityutskiy  *                 inodes
3421e51764aSArtem Bityutskiy  * @ui_size: inode size used by UBIFS when writing to flash
3431e51764aSArtem Bityutskiy  * @flags: inode flags (@UBIFS_COMPR_FL, etc)
3441e51764aSArtem Bityutskiy  * @compr_type: default compression type used for this inode
3454793e7c5SAdrian Hunter  * @last_page_read: page number of last page read (for bulk read)
3464793e7c5SAdrian Hunter  * @read_in_a_row: number of consecutive pages read in a row (for bulk read)
3471e51764aSArtem Bityutskiy  * @data_len: length of the data attached to the inode
3481e51764aSArtem Bityutskiy  * @data: inode's data
3491e51764aSArtem Bityutskiy  *
3501e51764aSArtem Bityutskiy  * @ui_mutex exists for two main reasons. At first it prevents inodes from
3511e51764aSArtem Bityutskiy  * being written back while UBIFS changing them, being in the middle of an VFS
3521e51764aSArtem Bityutskiy  * operation. This way UBIFS makes sure the inode fields are consistent. For
3531e51764aSArtem Bityutskiy  * example, in 'ubifs_rename()' we change 3 inodes simultaneously, and
3541e51764aSArtem Bityutskiy  * write-back must not write any of them before we have finished.
3551e51764aSArtem Bityutskiy  *
3561e51764aSArtem Bityutskiy  * The second reason is budgeting - UBIFS has to budget all operations. If an
3571e51764aSArtem Bityutskiy  * operation is going to mark an inode dirty, it has to allocate budget for
3581e51764aSArtem Bityutskiy  * this. It cannot just mark it dirty because there is no guarantee there will
3591e51764aSArtem Bityutskiy  * be enough flash space to write the inode back later. This means UBIFS has
3601e51764aSArtem Bityutskiy  * to have full control over inode "clean <-> dirty" transitions (and pages
3611e51764aSArtem Bityutskiy  * actually). But unfortunately, VFS marks inodes dirty in many places, and it
3621e51764aSArtem Bityutskiy  * does not ask the file-system if it is allowed to do so (there is a notifier,
3631e51764aSArtem Bityutskiy  * but it is not enough), i.e., there is no mechanism to synchronize with this.
3641e51764aSArtem Bityutskiy  * So UBIFS has its own inode dirty flag and its own mutex to serialize
3651e51764aSArtem Bityutskiy  * "clean <-> dirty" transitions.
3661e51764aSArtem Bityutskiy  *
3671e51764aSArtem Bityutskiy  * The @synced_i_size field is used to make sure we never write pages which are
3681e51764aSArtem Bityutskiy  * beyond last synchronized inode size. See 'ubifs_writepage()' for more
3691e51764aSArtem Bityutskiy  * information.
3701e51764aSArtem Bityutskiy  *
3711e51764aSArtem Bityutskiy  * The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses
3721e51764aSArtem Bityutskiy  * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot
3731e51764aSArtem Bityutskiy  * make sure @inode->i_size is always changed under @ui_mutex, because it
3741e51764aSArtem Bityutskiy  * cannot call 'vmtruncate()' with @ui_mutex locked, because it would deadlock
3751e51764aSArtem Bityutskiy  * with 'ubifs_writepage()' (see file.c). All the other inode fields are
3761e51764aSArtem Bityutskiy  * changed under @ui_mutex, so they do not need "shadow" fields. Note, one
3771e51764aSArtem Bityutskiy  * could consider to rework locking and base it on "shadow" fields.
3781e51764aSArtem Bityutskiy  */
3791e51764aSArtem Bityutskiy struct ubifs_inode {
3801e51764aSArtem Bityutskiy 	struct inode vfs_inode;
3811e51764aSArtem Bityutskiy 	unsigned long long creat_sqnum;
382de94eb55SArtem Bityutskiy 	unsigned long long del_cmtno;
3831e51764aSArtem Bityutskiy 	unsigned int xattr_size;
3841e51764aSArtem Bityutskiy 	unsigned int xattr_cnt;
3851e51764aSArtem Bityutskiy 	unsigned int xattr_names;
3861e51764aSArtem Bityutskiy 	unsigned int dirty:1;
3871e51764aSArtem Bityutskiy 	unsigned int xattr:1;
388625bf371SArtem Bityutskiy 	unsigned int bulk_read:1;
389a1dc080cSArtem Bityutskiy 	unsigned int compr_type:2;
3901e51764aSArtem Bityutskiy 	struct mutex ui_mutex;
3911e51764aSArtem Bityutskiy 	spinlock_t ui_lock;
3921e51764aSArtem Bityutskiy 	loff_t synced_i_size;
3931e51764aSArtem Bityutskiy 	loff_t ui_size;
3941e51764aSArtem Bityutskiy 	int flags;
3954793e7c5SAdrian Hunter 	pgoff_t last_page_read;
3964793e7c5SAdrian Hunter 	pgoff_t read_in_a_row;
3971e51764aSArtem Bityutskiy 	int data_len;
3981e51764aSArtem Bityutskiy 	void *data;
3991e51764aSArtem Bityutskiy };
4001e51764aSArtem Bityutskiy 
4011e51764aSArtem Bityutskiy /**
4021e51764aSArtem Bityutskiy  * struct ubifs_unclean_leb - records a LEB recovered under read-only mode.
4031e51764aSArtem Bityutskiy  * @list: list
4041e51764aSArtem Bityutskiy  * @lnum: LEB number of recovered LEB
4051e51764aSArtem Bityutskiy  * @endpt: offset where recovery ended
4061e51764aSArtem Bityutskiy  *
4071e51764aSArtem Bityutskiy  * This structure records a LEB identified during recovery that needs to be
4081e51764aSArtem Bityutskiy  * cleaned but was not because UBIFS was mounted read-only. The information
4091e51764aSArtem Bityutskiy  * is used to clean the LEB when remounting to read-write mode.
4101e51764aSArtem Bityutskiy  */
4111e51764aSArtem Bityutskiy struct ubifs_unclean_leb {
4121e51764aSArtem Bityutskiy 	struct list_head list;
4131e51764aSArtem Bityutskiy 	int lnum;
4141e51764aSArtem Bityutskiy 	int endpt;
4151e51764aSArtem Bityutskiy };
4161e51764aSArtem Bityutskiy 
4171e51764aSArtem Bityutskiy /*
4181e51764aSArtem Bityutskiy  * LEB properties flags.
4191e51764aSArtem Bityutskiy  *
4201e51764aSArtem Bityutskiy  * LPROPS_UNCAT: not categorized
4211e51764aSArtem Bityutskiy  * LPROPS_DIRTY: dirty > 0, not index
4221e51764aSArtem Bityutskiy  * LPROPS_DIRTY_IDX: dirty + free > UBIFS_CH_SZ and index
4231e51764aSArtem Bityutskiy  * LPROPS_FREE: free > 0, not empty, not index
4241e51764aSArtem Bityutskiy  * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs
4251e51764aSArtem Bityutskiy  * LPROPS_EMPTY: LEB is empty, not taken
4261e51764aSArtem Bityutskiy  * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken
4271e51764aSArtem Bityutskiy  * LPROPS_FRDI_IDX: free + dirty == leb_size and index, may be taken
4281e51764aSArtem Bityutskiy  * LPROPS_CAT_MASK: mask for the LEB categories above
4291e51764aSArtem Bityutskiy  * LPROPS_TAKEN: LEB was taken (this flag is not saved on the media)
4301e51764aSArtem Bityutskiy  * LPROPS_INDEX: LEB contains indexing nodes (this flag also exists on flash)
4311e51764aSArtem Bityutskiy  */
4321e51764aSArtem Bityutskiy enum {
4331e51764aSArtem Bityutskiy 	LPROPS_UNCAT     =  0,
4341e51764aSArtem Bityutskiy 	LPROPS_DIRTY     =  1,
4351e51764aSArtem Bityutskiy 	LPROPS_DIRTY_IDX =  2,
4361e51764aSArtem Bityutskiy 	LPROPS_FREE      =  3,
4371e51764aSArtem Bityutskiy 	LPROPS_HEAP_CNT  =  3,
4381e51764aSArtem Bityutskiy 	LPROPS_EMPTY     =  4,
4391e51764aSArtem Bityutskiy 	LPROPS_FREEABLE  =  5,
4401e51764aSArtem Bityutskiy 	LPROPS_FRDI_IDX  =  6,
4411e51764aSArtem Bityutskiy 	LPROPS_CAT_MASK  = 15,
4421e51764aSArtem Bityutskiy 	LPROPS_TAKEN     = 16,
4431e51764aSArtem Bityutskiy 	LPROPS_INDEX     = 32,
4441e51764aSArtem Bityutskiy };
4451e51764aSArtem Bityutskiy 
4461e51764aSArtem Bityutskiy /**
4471e51764aSArtem Bityutskiy  * struct ubifs_lprops - logical eraseblock properties.
4481e51764aSArtem Bityutskiy  * @free: amount of free space in bytes
4491e51764aSArtem Bityutskiy  * @dirty: amount of dirty space in bytes
4501e51764aSArtem Bityutskiy  * @flags: LEB properties flags (see above)
4511e51764aSArtem Bityutskiy  * @lnum: LEB number
4521e51764aSArtem Bityutskiy  * @list: list of same-category lprops (for LPROPS_EMPTY and LPROPS_FREEABLE)
4531e51764aSArtem Bityutskiy  * @hpos: heap position in heap of same-category lprops (other categories)
4541e51764aSArtem Bityutskiy  */
4551e51764aSArtem Bityutskiy struct ubifs_lprops {
4561e51764aSArtem Bityutskiy 	int free;
4571e51764aSArtem Bityutskiy 	int dirty;
4581e51764aSArtem Bityutskiy 	int flags;
4591e51764aSArtem Bityutskiy 	int lnum;
4601e51764aSArtem Bityutskiy 	union {
4611e51764aSArtem Bityutskiy 		struct list_head list;
4621e51764aSArtem Bityutskiy 		int hpos;
4631e51764aSArtem Bityutskiy 	};
4641e51764aSArtem Bityutskiy };
4651e51764aSArtem Bityutskiy 
4661e51764aSArtem Bityutskiy /**
4671e51764aSArtem Bityutskiy  * struct ubifs_lpt_lprops - LPT logical eraseblock properties.
4681e51764aSArtem Bityutskiy  * @free: amount of free space in bytes
4691e51764aSArtem Bityutskiy  * @dirty: amount of dirty space in bytes
4701e51764aSArtem Bityutskiy  * @tgc: trivial GC flag (1 => unmap after commit end)
4711e51764aSArtem Bityutskiy  * @cmt: commit flag (1 => reserved for commit)
4721e51764aSArtem Bityutskiy  */
4731e51764aSArtem Bityutskiy struct ubifs_lpt_lprops {
4741e51764aSArtem Bityutskiy 	int free;
4751e51764aSArtem Bityutskiy 	int dirty;
4761e51764aSArtem Bityutskiy 	unsigned tgc : 1;
4771e51764aSArtem Bityutskiy 	unsigned cmt : 1;
4781e51764aSArtem Bityutskiy };
4791e51764aSArtem Bityutskiy 
4801e51764aSArtem Bityutskiy /**
4811e51764aSArtem Bityutskiy  * struct ubifs_lp_stats - statistics of eraseblocks in the main area.
4821e51764aSArtem Bityutskiy  * @empty_lebs: number of empty LEBs
4831e51764aSArtem Bityutskiy  * @taken_empty_lebs: number of taken LEBs
4841e51764aSArtem Bityutskiy  * @idx_lebs: number of indexing LEBs
4851e51764aSArtem Bityutskiy  * @total_free: total free space in bytes
4861e51764aSArtem Bityutskiy  * @total_dirty: total dirty space in bytes
4871e51764aSArtem Bityutskiy  * @total_used: total used space in bytes (includes only data LEBs)
4881e51764aSArtem Bityutskiy  * @total_dead: total dead space in bytes (includes only data LEBs)
4891e51764aSArtem Bityutskiy  * @total_dark: total dark space in bytes (includes only data LEBs)
4901e51764aSArtem Bityutskiy  *
4911e51764aSArtem Bityutskiy  * N.B. total_dirty and total_used are different to other total_* fields,
4921e51764aSArtem Bityutskiy  * because they account _all_ LEBs, not just data LEBs.
4931e51764aSArtem Bityutskiy  *
4941e51764aSArtem Bityutskiy  * 'taken_empty_lebs' counts the LEBs that are in the transient state of having
4951e51764aSArtem Bityutskiy  * been 'taken' for use but not yet written to. 'taken_empty_lebs' is needed
4961e51764aSArtem Bityutskiy  * to account correctly for gc_lnum, otherwise 'empty_lebs' could be used
4971e51764aSArtem Bityutskiy  * by itself (in which case 'unused_lebs' would be a better name). In the case
4981e51764aSArtem Bityutskiy  * of gc_lnum, it is 'taken' at mount time or whenever a LEB is retained by GC,
4991e51764aSArtem Bityutskiy  * but unlike other empty LEBs that are 'taken', it may not be written straight
5001e51764aSArtem Bityutskiy  * away (i.e. before the next commit start or unmount), so either gc_lnum must
5011e51764aSArtem Bityutskiy  * be specially accounted for, or the current approach followed i.e. count it
5021e51764aSArtem Bityutskiy  * under 'taken_empty_lebs'.
5031e51764aSArtem Bityutskiy  */
5041e51764aSArtem Bityutskiy struct ubifs_lp_stats {
5051e51764aSArtem Bityutskiy 	int empty_lebs;
5061e51764aSArtem Bityutskiy 	int taken_empty_lebs;
5071e51764aSArtem Bityutskiy 	int idx_lebs;
5081e51764aSArtem Bityutskiy 	long long total_free;
5091e51764aSArtem Bityutskiy 	long long total_dirty;
5101e51764aSArtem Bityutskiy 	long long total_used;
5111e51764aSArtem Bityutskiy 	long long total_dead;
5121e51764aSArtem Bityutskiy 	long long total_dark;
5131e51764aSArtem Bityutskiy };
5141e51764aSArtem Bityutskiy 
5151e51764aSArtem Bityutskiy struct ubifs_nnode;
5161e51764aSArtem Bityutskiy 
5171e51764aSArtem Bityutskiy /**
5181e51764aSArtem Bityutskiy  * struct ubifs_cnode - LEB Properties Tree common node.
5191e51764aSArtem Bityutskiy  * @parent: parent nnode
5201e51764aSArtem Bityutskiy  * @cnext: next cnode to commit
5211e51764aSArtem Bityutskiy  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
5221e51764aSArtem Bityutskiy  * @iip: index in parent
5231e51764aSArtem Bityutskiy  * @level: level in the tree (zero for pnodes, greater than zero for nnodes)
5241e51764aSArtem Bityutskiy  * @num: node number
5251e51764aSArtem Bityutskiy  */
5261e51764aSArtem Bityutskiy struct ubifs_cnode {
5271e51764aSArtem Bityutskiy 	struct ubifs_nnode *parent;
5281e51764aSArtem Bityutskiy 	struct ubifs_cnode *cnext;
5291e51764aSArtem Bityutskiy 	unsigned long flags;
5301e51764aSArtem Bityutskiy 	int iip;
5311e51764aSArtem Bityutskiy 	int level;
5321e51764aSArtem Bityutskiy 	int num;
5331e51764aSArtem Bityutskiy };
5341e51764aSArtem Bityutskiy 
5351e51764aSArtem Bityutskiy /**
5361e51764aSArtem Bityutskiy  * struct ubifs_pnode - LEB Properties Tree leaf node.
5371e51764aSArtem Bityutskiy  * @parent: parent nnode
5381e51764aSArtem Bityutskiy  * @cnext: next cnode to commit
5391e51764aSArtem Bityutskiy  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
5401e51764aSArtem Bityutskiy  * @iip: index in parent
5411e51764aSArtem Bityutskiy  * @level: level in the tree (always zero for pnodes)
5421e51764aSArtem Bityutskiy  * @num: node number
5431e51764aSArtem Bityutskiy  * @lprops: LEB properties array
5441e51764aSArtem Bityutskiy  */
5451e51764aSArtem Bityutskiy struct ubifs_pnode {
5461e51764aSArtem Bityutskiy 	struct ubifs_nnode *parent;
5471e51764aSArtem Bityutskiy 	struct ubifs_cnode *cnext;
5481e51764aSArtem Bityutskiy 	unsigned long flags;
5491e51764aSArtem Bityutskiy 	int iip;
5501e51764aSArtem Bityutskiy 	int level;
5511e51764aSArtem Bityutskiy 	int num;
5521e51764aSArtem Bityutskiy 	struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
5531e51764aSArtem Bityutskiy };
5541e51764aSArtem Bityutskiy 
5551e51764aSArtem Bityutskiy /**
5561e51764aSArtem Bityutskiy  * struct ubifs_nbranch - LEB Properties Tree internal node branch.
5571e51764aSArtem Bityutskiy  * @lnum: LEB number of child
5581e51764aSArtem Bityutskiy  * @offs: offset of child
5591e51764aSArtem Bityutskiy  * @nnode: nnode child
5601e51764aSArtem Bityutskiy  * @pnode: pnode child
5611e51764aSArtem Bityutskiy  * @cnode: cnode child
5621e51764aSArtem Bityutskiy  */
5631e51764aSArtem Bityutskiy struct ubifs_nbranch {
5641e51764aSArtem Bityutskiy 	int lnum;
5651e51764aSArtem Bityutskiy 	int offs;
5661e51764aSArtem Bityutskiy 	union {
5671e51764aSArtem Bityutskiy 		struct ubifs_nnode *nnode;
5681e51764aSArtem Bityutskiy 		struct ubifs_pnode *pnode;
5691e51764aSArtem Bityutskiy 		struct ubifs_cnode *cnode;
5701e51764aSArtem Bityutskiy 	};
5711e51764aSArtem Bityutskiy };
5721e51764aSArtem Bityutskiy 
5731e51764aSArtem Bityutskiy /**
5741e51764aSArtem Bityutskiy  * struct ubifs_nnode - LEB Properties Tree internal node.
5751e51764aSArtem Bityutskiy  * @parent: parent nnode
5761e51764aSArtem Bityutskiy  * @cnext: next cnode to commit
5771e51764aSArtem Bityutskiy  * @flags: flags (%DIRTY_LPT_NODE or %OBSOLETE_LPT_NODE)
5781e51764aSArtem Bityutskiy  * @iip: index in parent
5791e51764aSArtem Bityutskiy  * @level: level in the tree (always greater than zero for nnodes)
5801e51764aSArtem Bityutskiy  * @num: node number
5811e51764aSArtem Bityutskiy  * @nbranch: branches to child nodes
5821e51764aSArtem Bityutskiy  */
5831e51764aSArtem Bityutskiy struct ubifs_nnode {
5841e51764aSArtem Bityutskiy 	struct ubifs_nnode *parent;
5851e51764aSArtem Bityutskiy 	struct ubifs_cnode *cnext;
5861e51764aSArtem Bityutskiy 	unsigned long flags;
5871e51764aSArtem Bityutskiy 	int iip;
5881e51764aSArtem Bityutskiy 	int level;
5891e51764aSArtem Bityutskiy 	int num;
5901e51764aSArtem Bityutskiy 	struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
5911e51764aSArtem Bityutskiy };
5921e51764aSArtem Bityutskiy 
5931e51764aSArtem Bityutskiy /**
5941e51764aSArtem Bityutskiy  * struct ubifs_lpt_heap - heap of categorized lprops.
5951e51764aSArtem Bityutskiy  * @arr: heap array
5961e51764aSArtem Bityutskiy  * @cnt: number in heap
5971e51764aSArtem Bityutskiy  * @max_cnt: maximum number allowed in heap
5981e51764aSArtem Bityutskiy  *
5991e51764aSArtem Bityutskiy  * There are %LPROPS_HEAP_CNT heaps.
6001e51764aSArtem Bityutskiy  */
6011e51764aSArtem Bityutskiy struct ubifs_lpt_heap {
6021e51764aSArtem Bityutskiy 	struct ubifs_lprops **arr;
6031e51764aSArtem Bityutskiy 	int cnt;
6041e51764aSArtem Bityutskiy 	int max_cnt;
6051e51764aSArtem Bityutskiy };
6061e51764aSArtem Bityutskiy 
6071e51764aSArtem Bityutskiy /*
6081e51764aSArtem Bityutskiy  * Return codes for LPT scan callback function.
6091e51764aSArtem Bityutskiy  *
6101e51764aSArtem Bityutskiy  * LPT_SCAN_CONTINUE: continue scanning
6111e51764aSArtem Bityutskiy  * LPT_SCAN_ADD: add the LEB properties scanned to the tree in memory
6121e51764aSArtem Bityutskiy  * LPT_SCAN_STOP: stop scanning
6131e51764aSArtem Bityutskiy  */
6141e51764aSArtem Bityutskiy enum {
6151e51764aSArtem Bityutskiy 	LPT_SCAN_CONTINUE = 0,
6161e51764aSArtem Bityutskiy 	LPT_SCAN_ADD = 1,
6171e51764aSArtem Bityutskiy 	LPT_SCAN_STOP = 2,
6181e51764aSArtem Bityutskiy };
6191e51764aSArtem Bityutskiy 
6201e51764aSArtem Bityutskiy struct ubifs_info;
6211e51764aSArtem Bityutskiy 
6221e51764aSArtem Bityutskiy /* Callback used by the 'ubifs_lpt_scan_nolock()' function */
6231e51764aSArtem Bityutskiy typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
6241e51764aSArtem Bityutskiy 				       const struct ubifs_lprops *lprops,
6251e51764aSArtem Bityutskiy 				       int in_tree, void *data);
6261e51764aSArtem Bityutskiy 
6271e51764aSArtem Bityutskiy /**
6281e51764aSArtem Bityutskiy  * struct ubifs_wbuf - UBIFS write-buffer.
6291e51764aSArtem Bityutskiy  * @c: UBIFS file-system description object
6301e51764aSArtem Bityutskiy  * @buf: write-buffer (of min. flash I/O unit size)
6311e51764aSArtem Bityutskiy  * @lnum: logical eraseblock number the write-buffer points to
6321e51764aSArtem Bityutskiy  * @offs: write-buffer offset in this logical eraseblock
6331e51764aSArtem Bityutskiy  * @avail: number of bytes available in the write-buffer
6341e51764aSArtem Bityutskiy  * @used:  number of used bytes in the write-buffer
6351e51764aSArtem Bityutskiy  * @dtype: type of data stored in this LEB (%UBI_LONGTERM, %UBI_SHORTTERM,
6361e51764aSArtem Bityutskiy  * %UBI_UNKNOWN)
6371e51764aSArtem Bityutskiy  * @jhead: journal head the mutex belongs to (note, needed only to shut lockdep
6381e51764aSArtem Bityutskiy  *         up by 'mutex_lock_nested()).
6391e51764aSArtem Bityutskiy  * @sync_callback: write-buffer synchronization callback
6401e51764aSArtem Bityutskiy  * @io_mutex: serializes write-buffer I/O
6411e51764aSArtem Bityutskiy  * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes
6421e51764aSArtem Bityutskiy  *        fields
6431e51764aSArtem Bityutskiy  * @timer: write-buffer timer
6441e51764aSArtem Bityutskiy  * @timeout: timer expire interval in jiffies
6451e51764aSArtem Bityutskiy  * @need_sync: it is set if its timer expired and needs sync
6461e51764aSArtem Bityutskiy  * @next_ino: points to the next position of the following inode number
6471e51764aSArtem Bityutskiy  * @inodes: stores the inode numbers of the nodes which are in wbuf
6481e51764aSArtem Bityutskiy  *
6491e51764aSArtem Bityutskiy  * The write-buffer synchronization callback is called when the write-buffer is
6501e51764aSArtem Bityutskiy  * synchronized in order to notify how much space was wasted due to
6511e51764aSArtem Bityutskiy  * write-buffer padding and how much free space is left in the LEB.
6521e51764aSArtem Bityutskiy  *
6531e51764aSArtem Bityutskiy  * Note: the fields @buf, @lnum, @offs, @avail and @used can be read under
6541e51764aSArtem Bityutskiy  * spin-lock or mutex because they are written under both mutex and spin-lock.
6551e51764aSArtem Bityutskiy  * @buf is appended to under mutex but overwritten under both mutex and
6561e51764aSArtem Bityutskiy  * spin-lock. Thus the data between @buf and @buf + @used can be read under
6571e51764aSArtem Bityutskiy  * spinlock.
6581e51764aSArtem Bityutskiy  */
6591e51764aSArtem Bityutskiy struct ubifs_wbuf {
6601e51764aSArtem Bityutskiy 	struct ubifs_info *c;
6611e51764aSArtem Bityutskiy 	void *buf;
6621e51764aSArtem Bityutskiy 	int lnum;
6631e51764aSArtem Bityutskiy 	int offs;
6641e51764aSArtem Bityutskiy 	int avail;
6651e51764aSArtem Bityutskiy 	int used;
6661e51764aSArtem Bityutskiy 	int dtype;
6671e51764aSArtem Bityutskiy 	int jhead;
6681e51764aSArtem Bityutskiy 	int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
6691e51764aSArtem Bityutskiy 	struct mutex io_mutex;
6701e51764aSArtem Bityutskiy 	spinlock_t lock;
6711e51764aSArtem Bityutskiy 	struct timer_list timer;
6721e51764aSArtem Bityutskiy 	int timeout;
6731e51764aSArtem Bityutskiy 	int need_sync;
6741e51764aSArtem Bityutskiy 	int next_ino;
6751e51764aSArtem Bityutskiy 	ino_t *inodes;
6761e51764aSArtem Bityutskiy };
6771e51764aSArtem Bityutskiy 
6781e51764aSArtem Bityutskiy /**
6791e51764aSArtem Bityutskiy  * struct ubifs_bud - bud logical eraseblock.
6801e51764aSArtem Bityutskiy  * @lnum: logical eraseblock number
6811e51764aSArtem Bityutskiy  * @start: where the (uncommitted) bud data starts
6821e51764aSArtem Bityutskiy  * @jhead: journal head number this bud belongs to
6831e51764aSArtem Bityutskiy  * @list: link in the list buds belonging to the same journal head
6841e51764aSArtem Bityutskiy  * @rb: link in the tree of all buds
6851e51764aSArtem Bityutskiy  */
6861e51764aSArtem Bityutskiy struct ubifs_bud {
6871e51764aSArtem Bityutskiy 	int lnum;
6881e51764aSArtem Bityutskiy 	int start;
6891e51764aSArtem Bityutskiy 	int jhead;
6901e51764aSArtem Bityutskiy 	struct list_head list;
6911e51764aSArtem Bityutskiy 	struct rb_node rb;
6921e51764aSArtem Bityutskiy };
6931e51764aSArtem Bityutskiy 
6941e51764aSArtem Bityutskiy /**
6951e51764aSArtem Bityutskiy  * struct ubifs_jhead - journal head.
6961e51764aSArtem Bityutskiy  * @wbuf: head's write-buffer
6971e51764aSArtem Bityutskiy  * @buds_list: list of bud LEBs belonging to this journal head
6981e51764aSArtem Bityutskiy  *
6991e51764aSArtem Bityutskiy  * Note, the @buds list is protected by the @c->buds_lock.
7001e51764aSArtem Bityutskiy  */
7011e51764aSArtem Bityutskiy struct ubifs_jhead {
7021e51764aSArtem Bityutskiy 	struct ubifs_wbuf wbuf;
7031e51764aSArtem Bityutskiy 	struct list_head buds_list;
7041e51764aSArtem Bityutskiy };
7051e51764aSArtem Bityutskiy 
7061e51764aSArtem Bityutskiy /**
7071e51764aSArtem Bityutskiy  * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
7081e51764aSArtem Bityutskiy  * @key: key
7091e51764aSArtem Bityutskiy  * @znode: znode address in memory
710be61678bSArtem Bityutskiy  * @lnum: LEB number of the target node (indexing node or data node)
711be61678bSArtem Bityutskiy  * @offs: target node offset within @lnum
7121e51764aSArtem Bityutskiy  * @len: target node length
7131e51764aSArtem Bityutskiy  */
7141e51764aSArtem Bityutskiy struct ubifs_zbranch {
7151e51764aSArtem Bityutskiy 	union ubifs_key key;
7161e51764aSArtem Bityutskiy 	union {
7171e51764aSArtem Bityutskiy 		struct ubifs_znode *znode;
7181e51764aSArtem Bityutskiy 		void *leaf;
7191e51764aSArtem Bityutskiy 	};
7201e51764aSArtem Bityutskiy 	int lnum;
7211e51764aSArtem Bityutskiy 	int offs;
7221e51764aSArtem Bityutskiy 	int len;
7231e51764aSArtem Bityutskiy };
7241e51764aSArtem Bityutskiy 
7251e51764aSArtem Bityutskiy /**
7261e51764aSArtem Bityutskiy  * struct ubifs_znode - in-memory representation of an indexing node.
7271e51764aSArtem Bityutskiy  * @parent: parent znode or NULL if it is the root
7281e51764aSArtem Bityutskiy  * @cnext: next znode to commit
7291e51764aSArtem Bityutskiy  * @flags: znode flags (%DIRTY_ZNODE, %COW_ZNODE or %OBSOLETE_ZNODE)
7301e51764aSArtem Bityutskiy  * @time: last access time (seconds)
7311e51764aSArtem Bityutskiy  * @level: level of the entry in the TNC tree
7321e51764aSArtem Bityutskiy  * @child_cnt: count of child znodes
7331e51764aSArtem Bityutskiy  * @iip: index in parent's zbranch array
7341e51764aSArtem Bityutskiy  * @alt: lower bound of key range has altered i.e. child inserted at slot 0
7351e51764aSArtem Bityutskiy  * @lnum: LEB number of the corresponding indexing node
7361e51764aSArtem Bityutskiy  * @offs: offset of the corresponding indexing node
7371e51764aSArtem Bityutskiy  * @len: length  of the corresponding indexing node
7381e51764aSArtem Bityutskiy  * @zbranch: array of znode branches (@c->fanout elements)
7391e51764aSArtem Bityutskiy  */
7401e51764aSArtem Bityutskiy struct ubifs_znode {
7411e51764aSArtem Bityutskiy 	struct ubifs_znode *parent;
7421e51764aSArtem Bityutskiy 	struct ubifs_znode *cnext;
7431e51764aSArtem Bityutskiy 	unsigned long flags;
7441e51764aSArtem Bityutskiy 	unsigned long time;
7451e51764aSArtem Bityutskiy 	int level;
7461e51764aSArtem Bityutskiy 	int child_cnt;
7471e51764aSArtem Bityutskiy 	int iip;
7481e51764aSArtem Bityutskiy 	int alt;
7491e51764aSArtem Bityutskiy #ifdef CONFIG_UBIFS_FS_DEBUG
7501e51764aSArtem Bityutskiy 	int lnum, offs, len;
7511e51764aSArtem Bityutskiy #endif
7521e51764aSArtem Bityutskiy 	struct ubifs_zbranch zbranch[];
7531e51764aSArtem Bityutskiy };
7541e51764aSArtem Bityutskiy 
7551e51764aSArtem Bityutskiy /**
75639ce81ceSArtem Bityutskiy  * struct bu_info - bulk-read information.
7574793e7c5SAdrian Hunter  * @key: first data node key
7584793e7c5SAdrian Hunter  * @zbranch: zbranches of data nodes to bulk read
7594793e7c5SAdrian Hunter  * @buf: buffer to read into
7604793e7c5SAdrian Hunter  * @buf_len: buffer length
7614793e7c5SAdrian Hunter  * @gc_seq: GC sequence number to detect races with GC
7624793e7c5SAdrian Hunter  * @cnt: number of data nodes for bulk read
7634793e7c5SAdrian Hunter  * @blk_cnt: number of data blocks including holes
7644793e7c5SAdrian Hunter  * @oef: end of file reached
7654793e7c5SAdrian Hunter  */
7664793e7c5SAdrian Hunter struct bu_info {
7674793e7c5SAdrian Hunter 	union ubifs_key key;
7684793e7c5SAdrian Hunter 	struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
7694793e7c5SAdrian Hunter 	void *buf;
7704793e7c5SAdrian Hunter 	int buf_len;
7714793e7c5SAdrian Hunter 	int gc_seq;
7724793e7c5SAdrian Hunter 	int cnt;
7734793e7c5SAdrian Hunter 	int blk_cnt;
7744793e7c5SAdrian Hunter 	int eof;
7754793e7c5SAdrian Hunter };
7764793e7c5SAdrian Hunter 
7774793e7c5SAdrian Hunter /**
7781e51764aSArtem Bityutskiy  * struct ubifs_node_range - node length range description data structure.
7791e51764aSArtem Bityutskiy  * @len: fixed node length
7801e51764aSArtem Bityutskiy  * @min_len: minimum possible node length
7811e51764aSArtem Bityutskiy  * @max_len: maximum possible node length
7821e51764aSArtem Bityutskiy  *
7831e51764aSArtem Bityutskiy  * If @max_len is %0, the node has fixed length @len.
7841e51764aSArtem Bityutskiy  */
7851e51764aSArtem Bityutskiy struct ubifs_node_range {
7861e51764aSArtem Bityutskiy 	union {
7871e51764aSArtem Bityutskiy 		int len;
7881e51764aSArtem Bityutskiy 		int min_len;
7891e51764aSArtem Bityutskiy 	};
7901e51764aSArtem Bityutskiy 	int max_len;
7911e51764aSArtem Bityutskiy };
7921e51764aSArtem Bityutskiy 
7931e51764aSArtem Bityutskiy /**
7941e51764aSArtem Bityutskiy  * struct ubifs_compressor - UBIFS compressor description structure.
7951e51764aSArtem Bityutskiy  * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc)
7961e51764aSArtem Bityutskiy  * @cc: cryptoapi compressor handle
7971e51764aSArtem Bityutskiy  * @comp_mutex: mutex used during compression
7981e51764aSArtem Bityutskiy  * @decomp_mutex: mutex used during decompression
7991e51764aSArtem Bityutskiy  * @name: compressor name
8001e51764aSArtem Bityutskiy  * @capi_name: cryptoapi compressor name
8011e51764aSArtem Bityutskiy  */
8021e51764aSArtem Bityutskiy struct ubifs_compressor {
8031e51764aSArtem Bityutskiy 	int compr_type;
8041e51764aSArtem Bityutskiy 	struct crypto_comp *cc;
8051e51764aSArtem Bityutskiy 	struct mutex *comp_mutex;
8061e51764aSArtem Bityutskiy 	struct mutex *decomp_mutex;
8071e51764aSArtem Bityutskiy 	const char *name;
8081e51764aSArtem Bityutskiy 	const char *capi_name;
8091e51764aSArtem Bityutskiy };
8101e51764aSArtem Bityutskiy 
8111e51764aSArtem Bityutskiy /**
8121e51764aSArtem Bityutskiy  * struct ubifs_budget_req - budget requirements of an operation.
8131e51764aSArtem Bityutskiy  *
814de94eb55SArtem Bityutskiy  * @fast: non-zero if the budgeting should try to acquire budget quickly and
8151e51764aSArtem Bityutskiy  *        should not try to call write-back
8161e51764aSArtem Bityutskiy  * @recalculate: non-zero if @idx_growth, @data_growth, and @dd_growth fields
8171e51764aSArtem Bityutskiy  *               have to be re-calculated
8181e51764aSArtem Bityutskiy  * @new_page: non-zero if the operation adds a new page
8191e51764aSArtem Bityutskiy  * @dirtied_page: non-zero if the operation makes a page dirty
8201e51764aSArtem Bityutskiy  * @new_dent: non-zero if the operation adds a new directory entry
8211e51764aSArtem Bityutskiy  * @mod_dent: non-zero if the operation removes or modifies an existing
8221e51764aSArtem Bityutskiy  *            directory entry
8231e51764aSArtem Bityutskiy  * @new_ino: non-zero if the operation adds a new inode
8241e51764aSArtem Bityutskiy  * @new_ino_d: now much data newly created inode contains
8251e51764aSArtem Bityutskiy  * @dirtied_ino: how many inodes the operation makes dirty
8261e51764aSArtem Bityutskiy  * @dirtied_ino_d: now much data dirtied inode contains
8271e51764aSArtem Bityutskiy  * @idx_growth: how much the index will supposedly grow
8281e51764aSArtem Bityutskiy  * @data_growth: how much new data the operation will supposedly add
8291e51764aSArtem Bityutskiy  * @dd_growth: how much data that makes other data dirty the operation will
8301e51764aSArtem Bityutskiy  *             supposedly add
8311e51764aSArtem Bityutskiy  *
8321e51764aSArtem Bityutskiy  * @idx_growth, @data_growth and @dd_growth are not used in budget request. The
8331e51764aSArtem Bityutskiy  * budgeting subsystem caches index and data growth values there to avoid
8341e51764aSArtem Bityutskiy  * re-calculating them when the budget is released. However, if @idx_growth is
8351e51764aSArtem Bityutskiy  * %-1, it is calculated by the release function using other fields.
8361e51764aSArtem Bityutskiy  *
8371e51764aSArtem Bityutskiy  * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
8381e51764aSArtem Bityutskiy  * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
8391e51764aSArtem Bityutskiy  * dirty by the re-name operation.
840dab4b4d2SArtem Bityutskiy  *
841dab4b4d2SArtem Bityutskiy  * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
842dab4b4d2SArtem Bityutskiy  * make sure the amount of inode data which contribute to @new_ino_d and
843dab4b4d2SArtem Bityutskiy  * @dirtied_ino_d fields are aligned.
8441e51764aSArtem Bityutskiy  */
8451e51764aSArtem Bityutskiy struct ubifs_budget_req {
8461e51764aSArtem Bityutskiy 	unsigned int fast:1;
8471e51764aSArtem Bityutskiy 	unsigned int recalculate:1;
848547000daSArtem Bityutskiy #ifndef UBIFS_DEBUG
8491e51764aSArtem Bityutskiy 	unsigned int new_page:1;
8501e51764aSArtem Bityutskiy 	unsigned int dirtied_page:1;
8511e51764aSArtem Bityutskiy 	unsigned int new_dent:1;
8521e51764aSArtem Bityutskiy 	unsigned int mod_dent:1;
8531e51764aSArtem Bityutskiy 	unsigned int new_ino:1;
8541e51764aSArtem Bityutskiy 	unsigned int new_ino_d:13;
8551e51764aSArtem Bityutskiy 	unsigned int dirtied_ino:4;
8561e51764aSArtem Bityutskiy 	unsigned int dirtied_ino_d:15;
8571e51764aSArtem Bityutskiy #else
8581e51764aSArtem Bityutskiy 	/* Not bit-fields to check for overflows */
859547000daSArtem Bityutskiy 	unsigned int new_page;
860547000daSArtem Bityutskiy 	unsigned int dirtied_page;
861547000daSArtem Bityutskiy 	unsigned int new_dent;
862547000daSArtem Bityutskiy 	unsigned int mod_dent;
863547000daSArtem Bityutskiy 	unsigned int new_ino;
864547000daSArtem Bityutskiy 	unsigned int new_ino_d;
8651e51764aSArtem Bityutskiy 	unsigned int dirtied_ino;
8661e51764aSArtem Bityutskiy 	unsigned int dirtied_ino_d;
8671e51764aSArtem Bityutskiy #endif
8681e51764aSArtem Bityutskiy 	int idx_growth;
8691e51764aSArtem Bityutskiy 	int data_growth;
8701e51764aSArtem Bityutskiy 	int dd_growth;
8711e51764aSArtem Bityutskiy };
8721e51764aSArtem Bityutskiy 
8731e51764aSArtem Bityutskiy /**
8741e51764aSArtem Bityutskiy  * struct ubifs_orphan - stores the inode number of an orphan.
8751e51764aSArtem Bityutskiy  * @rb: rb-tree node of rb-tree of orphans sorted by inode number
8761e51764aSArtem Bityutskiy  * @list: list head of list of orphans in order added
8771e51764aSArtem Bityutskiy  * @new_list: list head of list of orphans added since the last commit
8781e51764aSArtem Bityutskiy  * @cnext: next orphan to commit
8791e51764aSArtem Bityutskiy  * @dnext: next orphan to delete
8801e51764aSArtem Bityutskiy  * @inum: inode number
8811e51764aSArtem Bityutskiy  * @new: %1 => added since the last commit, otherwise %0
8821e51764aSArtem Bityutskiy  */
8831e51764aSArtem Bityutskiy struct ubifs_orphan {
8841e51764aSArtem Bityutskiy 	struct rb_node rb;
8851e51764aSArtem Bityutskiy 	struct list_head list;
8861e51764aSArtem Bityutskiy 	struct list_head new_list;
8871e51764aSArtem Bityutskiy 	struct ubifs_orphan *cnext;
8881e51764aSArtem Bityutskiy 	struct ubifs_orphan *dnext;
8891e51764aSArtem Bityutskiy 	ino_t inum;
8901e51764aSArtem Bityutskiy 	int new;
8911e51764aSArtem Bityutskiy };
8921e51764aSArtem Bityutskiy 
8931e51764aSArtem Bityutskiy /**
8941e51764aSArtem Bityutskiy  * struct ubifs_mount_opts - UBIFS-specific mount options information.
8951e51764aSArtem Bityutskiy  * @unmount_mode: selected unmount mode (%0 default, %1 normal, %2 fast)
896553dea4dSArtem Bityutskiy  * @bulk_read: enable/disable bulk-reads (%0 default, %1 disabe, %2 enable)
897553dea4dSArtem Bityutskiy  * @chk_data_crc: enable/disable CRC data checking when reading data nodes
898553dea4dSArtem Bityutskiy  *                (%0 default, %1 disabe, %2 enable)
899553dea4dSArtem Bityutskiy  * @override_compr: override default compressor (%0 - do not override and use
900553dea4dSArtem Bityutskiy  *                  superblock compressor, %1 - override and use compressor
901553dea4dSArtem Bityutskiy  *                  specified in @compr_type)
902553dea4dSArtem Bityutskiy  * @compr_type: compressor type to override the superblock compressor with
903553dea4dSArtem Bityutskiy  *              (%UBIFS_COMPR_NONE, etc)
9041e51764aSArtem Bityutskiy  */
9051e51764aSArtem Bityutskiy struct ubifs_mount_opts {
9061e51764aSArtem Bityutskiy 	unsigned int unmount_mode:2;
9074793e7c5SAdrian Hunter 	unsigned int bulk_read:2;
9082953e73fSAdrian Hunter 	unsigned int chk_data_crc:2;
909553dea4dSArtem Bityutskiy 	unsigned int override_compr:1;
910553dea4dSArtem Bityutskiy 	unsigned int compr_type:2;
9111e51764aSArtem Bityutskiy };
9121e51764aSArtem Bityutskiy 
9131e51764aSArtem Bityutskiy /**
9141e51764aSArtem Bityutskiy  * struct ubifs_info - UBIFS file-system description data structure
9151e51764aSArtem Bityutskiy  * (per-superblock).
9161e51764aSArtem Bityutskiy  * @vfs_sb: VFS @struct super_block object
917de94eb55SArtem Bityutskiy  * @bdi: backing device info object to make VFS happy and disable read-ahead
9181e51764aSArtem Bityutskiy  *
9191e51764aSArtem Bityutskiy  * @highest_inum: highest used inode number
9201e51764aSArtem Bityutskiy  * @max_sqnum: current global sequence number
921014eb04bSArtem Bityutskiy  * @cmt_no: commit number of the last successfully completed commit, protected
922014eb04bSArtem Bityutskiy  *          by @commit_sem
92381ffa38eSAdrian Hunter  * @cnt_lock: protects @highest_inum and @max_sqnum counters
9241e51764aSArtem Bityutskiy  * @fmt_version: UBIFS on-flash format version
9251e51764aSArtem Bityutskiy  * @uuid: UUID from super block
9261e51764aSArtem Bityutskiy  *
9271e51764aSArtem Bityutskiy  * @lhead_lnum: log head logical eraseblock number
9281e51764aSArtem Bityutskiy  * @lhead_offs: log head offset
9291e51764aSArtem Bityutskiy  * @ltail_lnum: log tail logical eraseblock number (offset is always 0)
9301e51764aSArtem Bityutskiy  * @log_mutex: protects the log, @lhead_lnum, @lhead_offs, @ltail_lnum, and
9311e51764aSArtem Bityutskiy  *             @bud_bytes
9321e51764aSArtem Bityutskiy  * @min_log_bytes: minimum required number of bytes in the log
9331e51764aSArtem Bityutskiy  * @cmt_bud_bytes: used during commit to temporarily amount of bytes in
9341e51764aSArtem Bityutskiy  *                 committed buds
9351e51764aSArtem Bityutskiy  *
9361e51764aSArtem Bityutskiy  * @buds: tree of all buds indexed by bud LEB number
9371e51764aSArtem Bityutskiy  * @bud_bytes: how many bytes of flash is used by buds
9381e51764aSArtem Bityutskiy  * @buds_lock: protects the @buds tree, @bud_bytes, and per-journal head bud
9391e51764aSArtem Bityutskiy  *             lists
9401e51764aSArtem Bityutskiy  * @jhead_cnt: count of journal heads
9411e51764aSArtem Bityutskiy  * @jheads: journal heads (head zero is base head)
9421e51764aSArtem Bityutskiy  * @max_bud_bytes: maximum number of bytes allowed in buds
9431e51764aSArtem Bityutskiy  * @bg_bud_bytes: number of bud bytes when background commit is initiated
9441e51764aSArtem Bityutskiy  * @old_buds: buds to be released after commit ends
9451e51764aSArtem Bityutskiy  * @max_bud_cnt: maximum number of buds
9461e51764aSArtem Bityutskiy  *
9471e51764aSArtem Bityutskiy  * @commit_sem: synchronizes committer with other processes
9481e51764aSArtem Bityutskiy  * @cmt_state: commit state
9491e51764aSArtem Bityutskiy  * @cs_lock: commit state lock
9501e51764aSArtem Bityutskiy  * @cmt_wq: wait queue to sleep on if the log is full and a commit is running
951625bf371SArtem Bityutskiy  *
9521e51764aSArtem Bityutskiy  * @fast_unmount: do not run journal commit before un-mounting
9531e51764aSArtem Bityutskiy  * @big_lpt: flag that LPT is too big to write whole during commit
954625bf371SArtem Bityutskiy  * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
955625bf371SArtem Bityutskiy  *                   recovery)
956625bf371SArtem Bityutskiy  * @bulk_read: enable bulk-reads
957a1dc080cSArtem Bityutskiy  * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
9581e51764aSArtem Bityutskiy  *
9591e51764aSArtem Bityutskiy  * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
9601e51764aSArtem Bityutskiy  *             @calc_idx_sz
9611e51764aSArtem Bityutskiy  * @zroot: zbranch which points to the root index node and znode
9621e51764aSArtem Bityutskiy  * @cnext: next znode to commit
9631e51764aSArtem Bityutskiy  * @enext: next znode to commit to empty space
9641e51764aSArtem Bityutskiy  * @gap_lebs: array of LEBs used by the in-gaps commit method
9651e51764aSArtem Bityutskiy  * @cbuf: commit buffer
9661e51764aSArtem Bityutskiy  * @ileb_buf: buffer for commit in-the-gaps method
9671e51764aSArtem Bityutskiy  * @ileb_len: length of data in ileb_buf
9681e51764aSArtem Bityutskiy  * @ihead_lnum: LEB number of index head
9691e51764aSArtem Bityutskiy  * @ihead_offs: offset of index head
9701e51764aSArtem Bityutskiy  * @ilebs: pre-allocated index LEBs
9711e51764aSArtem Bityutskiy  * @ileb_cnt: number of pre-allocated index LEBs
9721e51764aSArtem Bityutskiy  * @ileb_nxt: next pre-allocated index LEBs
9731e51764aSArtem Bityutskiy  * @old_idx: tree of index nodes obsoleted since the last commit start
9741e51764aSArtem Bityutskiy  * @bottom_up_buf: a buffer which is used by 'dirty_cow_bottom_up()' in tnc.c
9751e51764aSArtem Bityutskiy  * @new_ihead_lnum: used by debugging to check ihead_lnum
9761e51764aSArtem Bityutskiy  * @new_ihead_offs: used by debugging to check ihead_offs
9771e51764aSArtem Bityutskiy  *
9781e51764aSArtem Bityutskiy  * @mst_node: master node
9791e51764aSArtem Bityutskiy  * @mst_offs: offset of valid master node
9801e51764aSArtem Bityutskiy  * @mst_mutex: protects the master node area, @mst_node, and @mst_offs
9813477d204SArtem Bityutskiy  *
9826c0c42cdSArtem Bityutskiy  * @max_bu_buf_len: maximum bulk-read buffer length
9833477d204SArtem Bityutskiy  * @bu_mutex: protects the pre-allocated bulk-read buffer and @c->bu
9843477d204SArtem Bityutskiy  * @bu: pre-allocated bulk-read information
9851e51764aSArtem Bityutskiy  *
9861e51764aSArtem Bityutskiy  * @log_lebs: number of logical eraseblocks in the log
9871e51764aSArtem Bityutskiy  * @log_bytes: log size in bytes
9881e51764aSArtem Bityutskiy  * @log_last: last LEB of the log
9891e51764aSArtem Bityutskiy  * @lpt_lebs: number of LEBs used for lprops table
9901e51764aSArtem Bityutskiy  * @lpt_first: first LEB of the lprops table area
9911e51764aSArtem Bityutskiy  * @lpt_last: last LEB of the lprops table area
9921e51764aSArtem Bityutskiy  * @orph_lebs: number of LEBs used for the orphan area
9931e51764aSArtem Bityutskiy  * @orph_first: first LEB of the orphan area
9941e51764aSArtem Bityutskiy  * @orph_last: last LEB of the orphan area
9951e51764aSArtem Bityutskiy  * @main_lebs: count of LEBs in the main area
9961e51764aSArtem Bityutskiy  * @main_first: first LEB of the main area
9971e51764aSArtem Bityutskiy  * @main_bytes: main area size in bytes
9981e51764aSArtem Bityutskiy  *
9991e51764aSArtem Bityutskiy  * @key_hash_type: type of the key hash
10001e51764aSArtem Bityutskiy  * @key_hash: direntry key hash function
10011e51764aSArtem Bityutskiy  * @key_fmt: key format
10021e51764aSArtem Bityutskiy  * @key_len: key length
10031e51764aSArtem Bityutskiy  * @fanout: fanout of the index tree (number of links per indexing node)
10041e51764aSArtem Bityutskiy  *
10051e51764aSArtem Bityutskiy  * @min_io_size: minimal input/output unit size
10061e51764aSArtem Bityutskiy  * @min_io_shift: number of bits in @min_io_size minus one
10071e51764aSArtem Bityutskiy  * @leb_size: logical eraseblock size in bytes
10081e51764aSArtem Bityutskiy  * @half_leb_size: half LEB size
10091e51764aSArtem Bityutskiy  * @leb_cnt: count of logical eraseblocks
10101e51764aSArtem Bityutskiy  * @max_leb_cnt: maximum count of logical eraseblocks
10111e51764aSArtem Bityutskiy  * @old_leb_cnt: count of logical eraseblocks before re-size
10121e51764aSArtem Bityutskiy  * @ro_media: the underlying UBI volume is read-only
10131e51764aSArtem Bityutskiy  *
10141e51764aSArtem Bityutskiy  * @dirty_pg_cnt: number of dirty pages (not used)
10151e51764aSArtem Bityutskiy  * @dirty_zn_cnt: number of dirty znodes
10161e51764aSArtem Bityutskiy  * @clean_zn_cnt: number of clean znodes
10171e51764aSArtem Bityutskiy  *
10181e51764aSArtem Bityutskiy  * @budg_idx_growth: amount of bytes budgeted for index growth
10191e51764aSArtem Bityutskiy  * @budg_data_growth: amount of bytes budgeted for cached data
10201e51764aSArtem Bityutskiy  * @budg_dd_growth: amount of bytes budgeted for cached data that will make
10211e51764aSArtem Bityutskiy  *                  other data dirty
10221e51764aSArtem Bityutskiy  * @budg_uncommitted_idx: amount of bytes were budgeted for growth of the index,
10231e51764aSArtem Bityutskiy  *                        but which still have to be taken into account because
10241e51764aSArtem Bityutskiy  *                        the index has not been committed so far
10251e51764aSArtem Bityutskiy  * @space_lock: protects @budg_idx_growth, @budg_data_growth, @budg_dd_growth,
1026ba60ecabSArtem Bityutskiy  *              @budg_uncommited_idx, @min_idx_lebs, @old_idx_sz, @lst,
1027ba60ecabSArtem Bityutskiy  *              @nospace, and @nospace_rp;
10281e51764aSArtem Bityutskiy  * @min_idx_lebs: minimum number of LEBs required for the index
10291e51764aSArtem Bityutskiy  * @old_idx_sz: size of index on flash
10301e51764aSArtem Bityutskiy  * @calc_idx_sz: temporary variable which is used to calculate new index size
10311e51764aSArtem Bityutskiy  *               (contains accurate new index size at end of TNC commit start)
10321e51764aSArtem Bityutskiy  * @lst: lprops statistics
1033ba60ecabSArtem Bityutskiy  * @nospace: non-zero if the file-system does not have flash space (used as
1034ba60ecabSArtem Bityutskiy  *           optimization)
1035ba60ecabSArtem Bityutskiy  * @nospace_rp: the same as @nospace, but additionally means that even reserved
1036ba60ecabSArtem Bityutskiy  *              pool is full
10371e51764aSArtem Bityutskiy  *
10381e51764aSArtem Bityutskiy  * @page_budget: budget for a page
10391e51764aSArtem Bityutskiy  * @inode_budget: budget for an inode
10401e51764aSArtem Bityutskiy  * @dent_budget: budget for a directory entry
10411e51764aSArtem Bityutskiy  *
10421e51764aSArtem Bityutskiy  * @ref_node_alsz: size of the LEB reference node aligned to the min. flash
10431e51764aSArtem Bityutskiy  * I/O unit
10441e51764aSArtem Bityutskiy  * @mst_node_alsz: master node aligned size
10451e51764aSArtem Bityutskiy  * @min_idx_node_sz: minimum indexing node aligned on 8-bytes boundary
10461e51764aSArtem Bityutskiy  * @max_idx_node_sz: maximum indexing node aligned on 8-bytes boundary
10471e51764aSArtem Bityutskiy  * @max_inode_sz: maximum possible inode size in bytes
10481e51764aSArtem Bityutskiy  * @max_znode_sz: size of znode in bytes
10499bbb5726SArtem Bityutskiy  *
10509bbb5726SArtem Bityutskiy  * @leb_overhead: how many bytes are wasted in an LEB when it is filled with
10519bbb5726SArtem Bityutskiy  *                data nodes of maximum size - used in free space reporting
10521e51764aSArtem Bityutskiy  * @dead_wm: LEB dead space watermark
10531e51764aSArtem Bityutskiy  * @dark_wm: LEB dark space watermark
10541e51764aSArtem Bityutskiy  * @block_cnt: count of 4KiB blocks on the FS
10551e51764aSArtem Bityutskiy  *
10561e51764aSArtem Bityutskiy  * @ranges: UBIFS node length ranges
10571e51764aSArtem Bityutskiy  * @ubi: UBI volume descriptor
10581e51764aSArtem Bityutskiy  * @di: UBI device information
10591e51764aSArtem Bityutskiy  * @vi: UBI volume information
10601e51764aSArtem Bityutskiy  *
10611e51764aSArtem Bityutskiy  * @orph_tree: rb-tree of orphan inode numbers
10621e51764aSArtem Bityutskiy  * @orph_list: list of orphan inode numbers in order added
10631e51764aSArtem Bityutskiy  * @orph_new: list of orphan inode numbers added since last commit
10641e51764aSArtem Bityutskiy  * @orph_cnext: next orphan to commit
10651e51764aSArtem Bityutskiy  * @orph_dnext: next orphan to delete
10661e51764aSArtem Bityutskiy  * @orphan_lock: lock for orph_tree and orph_new
10671e51764aSArtem Bityutskiy  * @orph_buf: buffer for orphan nodes
10681e51764aSArtem Bityutskiy  * @new_orphans: number of orphans since last commit
10691e51764aSArtem Bityutskiy  * @cmt_orphans: number of orphans being committed
10701e51764aSArtem Bityutskiy  * @tot_orphans: number of orphans in the rb_tree
10711e51764aSArtem Bityutskiy  * @max_orphans: maximum number of orphans allowed
10721e51764aSArtem Bityutskiy  * @ohead_lnum: orphan head LEB number
10731e51764aSArtem Bityutskiy  * @ohead_offs: orphan head offset
10741e51764aSArtem Bityutskiy  * @no_orphs: non-zero if there are no orphans
10751e51764aSArtem Bityutskiy  *
10761e51764aSArtem Bityutskiy  * @bgt: UBIFS background thread
10771e51764aSArtem Bityutskiy  * @bgt_name: background thread name
10781e51764aSArtem Bityutskiy  * @need_bgt: if background thread should run
10791e51764aSArtem Bityutskiy  * @need_wbuf_sync: if write-buffers have to be synchronized
10801e51764aSArtem Bityutskiy  *
10811e51764aSArtem Bityutskiy  * @gc_lnum: LEB number used for garbage collection
10821e51764aSArtem Bityutskiy  * @sbuf: a buffer of LEB size used by GC and replay for scanning
10831e51764aSArtem Bityutskiy  * @idx_gc: list of index LEBs that have been garbage collected
10841e51764aSArtem Bityutskiy  * @idx_gc_cnt: number of elements on the idx_gc list
1085601c0bc4SAdrian Hunter  * @gc_seq: incremented for every non-index LEB garbage collected
1086601c0bc4SAdrian Hunter  * @gced_lnum: last non-index LEB that was garbage collected
10871e51764aSArtem Bityutskiy  *
10881e51764aSArtem Bityutskiy  * @infos_list: links all 'ubifs_info' objects
10891e51764aSArtem Bityutskiy  * @umount_mutex: serializes shrinker and un-mount
10901e51764aSArtem Bityutskiy  * @shrinker_run_no: shrinker run number
10911e51764aSArtem Bityutskiy  *
10921e51764aSArtem Bityutskiy  * @space_bits: number of bits needed to record free or dirty space
10931e51764aSArtem Bityutskiy  * @lpt_lnum_bits: number of bits needed to record a LEB number in the LPT
10941e51764aSArtem Bityutskiy  * @lpt_offs_bits: number of bits needed to record an offset in the LPT
10951e51764aSArtem Bityutskiy  * @lpt_spc_bits: number of bits needed to space in the LPT
10961e51764aSArtem Bityutskiy  * @pcnt_bits: number of bits needed to record pnode or nnode number
10971e51764aSArtem Bityutskiy  * @lnum_bits: number of bits needed to record LEB number
10981e51764aSArtem Bityutskiy  * @nnode_sz: size of on-flash nnode
10991e51764aSArtem Bityutskiy  * @pnode_sz: size of on-flash pnode
11001e51764aSArtem Bityutskiy  * @ltab_sz: size of on-flash LPT lprops table
11011e51764aSArtem Bityutskiy  * @lsave_sz: size of on-flash LPT save table
11021e51764aSArtem Bityutskiy  * @pnode_cnt: number of pnodes
11031e51764aSArtem Bityutskiy  * @nnode_cnt: number of nnodes
11041e51764aSArtem Bityutskiy  * @lpt_hght: height of the LPT
11051e51764aSArtem Bityutskiy  * @pnodes_have: number of pnodes in memory
11061e51764aSArtem Bityutskiy  *
11071e51764aSArtem Bityutskiy  * @lp_mutex: protects lprops table and all the other lprops-related fields
11081e51764aSArtem Bityutskiy  * @lpt_lnum: LEB number of the root nnode of the LPT
11091e51764aSArtem Bityutskiy  * @lpt_offs: offset of the root nnode of the LPT
11101e51764aSArtem Bityutskiy  * @nhead_lnum: LEB number of LPT head
11111e51764aSArtem Bityutskiy  * @nhead_offs: offset of LPT head
11121e51764aSArtem Bityutskiy  * @lpt_drty_flgs: dirty flags for LPT special nodes e.g. ltab
11131e51764aSArtem Bityutskiy  * @dirty_nn_cnt: number of dirty nnodes
11141e51764aSArtem Bityutskiy  * @dirty_pn_cnt: number of dirty pnodes
111573944a6dSAdrian Hunter  * @check_lpt_free: flag that indicates LPT GC may be needed
11161e51764aSArtem Bityutskiy  * @lpt_sz: LPT size
11171e51764aSArtem Bityutskiy  * @lpt_nod_buf: buffer for an on-flash nnode or pnode
11181e51764aSArtem Bityutskiy  * @lpt_buf: buffer of LEB size used by LPT
11191e51764aSArtem Bityutskiy  * @nroot: address in memory of the root nnode of the LPT
11201e51764aSArtem Bityutskiy  * @lpt_cnext: next LPT node to commit
11211e51764aSArtem Bityutskiy  * @lpt_heap: array of heaps of categorized lprops
11221e51764aSArtem Bityutskiy  * @dirty_idx: a (reverse sorted) copy of the LPROPS_DIRTY_IDX heap as at
11231e51764aSArtem Bityutskiy  *             previous commit start
11241e51764aSArtem Bityutskiy  * @uncat_list: list of un-categorized LEBs
11251e51764aSArtem Bityutskiy  * @empty_list: list of empty LEBs
11261e51764aSArtem Bityutskiy  * @freeable_list: list of freeable non-index LEBs (free + dirty == leb_size)
11271e51764aSArtem Bityutskiy  * @frdi_idx_list: list of freeable index LEBs (free + dirty == leb_size)
11281e51764aSArtem Bityutskiy  * @freeable_cnt: number of freeable LEBs in @freeable_list
11291e51764aSArtem Bityutskiy  *
11301e51764aSArtem Bityutskiy  * @ltab_lnum: LEB number of LPT's own lprops table
11311e51764aSArtem Bityutskiy  * @ltab_offs: offset of LPT's own lprops table
11321e51764aSArtem Bityutskiy  * @ltab: LPT's own lprops table
11331e51764aSArtem Bityutskiy  * @ltab_cmt: LPT's own lprops table (commit copy)
11341e51764aSArtem Bityutskiy  * @lsave_cnt: number of LEB numbers in LPT's save table
11351e51764aSArtem Bityutskiy  * @lsave_lnum: LEB number of LPT's save table
11361e51764aSArtem Bityutskiy  * @lsave_offs: offset of LPT's save table
11371e51764aSArtem Bityutskiy  * @lsave: LPT's save table
11381e51764aSArtem Bityutskiy  * @lscan_lnum: LEB number of last LPT scan
11391e51764aSArtem Bityutskiy  *
11401e51764aSArtem Bityutskiy  * @rp_size: size of the reserved pool in bytes
11411e51764aSArtem Bityutskiy  * @report_rp_size: size of the reserved pool reported to user-space
11421e51764aSArtem Bityutskiy  * @rp_uid: reserved pool user ID
11431e51764aSArtem Bityutskiy  * @rp_gid: reserved pool group ID
11441e51764aSArtem Bityutskiy  *
11451e51764aSArtem Bityutskiy  * @empty: if the UBI device is empty
11461e51764aSArtem Bityutskiy  * @replay_tree: temporary tree used during journal replay
11471e51764aSArtem Bityutskiy  * @replay_list: temporary list used during journal replay
11481e51764aSArtem Bityutskiy  * @replay_buds: list of buds to replay
11491e51764aSArtem Bityutskiy  * @cs_sqnum: sequence number of first node in the log (commit start node)
11501e51764aSArtem Bityutskiy  * @replay_sqnum: sequence number of node currently being replayed
11511e51764aSArtem Bityutskiy  * @need_recovery: file-system needs recovery
11521e51764aSArtem Bityutskiy  * @replaying: set to %1 during journal replay
11531e51764aSArtem Bityutskiy  * @unclean_leb_list: LEBs to recover when mounting ro to rw
11541e51764aSArtem Bityutskiy  * @rcvrd_mst_node: recovered master node to write when mounting ro to rw
11551e51764aSArtem Bityutskiy  * @size_tree: inode size information for recovery
11561e51764aSArtem Bityutskiy  * @remounting_rw: set while remounting from ro to rw (sb flags have MS_RDONLY)
11572953e73fSAdrian Hunter  * @always_chk_crc: always check CRCs (while mounting and remounting rw)
11581e51764aSArtem Bityutskiy  * @mount_opts: UBIFS-specific mount options
11591e51764aSArtem Bityutskiy  *
11601e51764aSArtem Bityutskiy  * @dbg_buf: a buffer of LEB size used for debugging purposes
11611e51764aSArtem Bityutskiy  * @old_zroot: old index root - used by 'dbg_check_old_index()'
11621e51764aSArtem Bityutskiy  * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
11631e51764aSArtem Bityutskiy  * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
11641e51764aSArtem Bityutskiy  * @failure_mode: failure mode for recovery testing
11651e51764aSArtem Bityutskiy  * @fail_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
11661e51764aSArtem Bityutskiy  * @fail_timeout: time in jiffies when delay of failure mode expires
11671e51764aSArtem Bityutskiy  * @fail_cnt: current number of calls to failure mode I/O functions
11681e51764aSArtem Bityutskiy  * @fail_cnt_max: number of calls by which to delay failure mode
11691e51764aSArtem Bityutskiy  */
11701e51764aSArtem Bityutskiy struct ubifs_info {
11711e51764aSArtem Bityutskiy 	struct super_block *vfs_sb;
11721e51764aSArtem Bityutskiy 	struct backing_dev_info bdi;
11731e51764aSArtem Bityutskiy 
11741e51764aSArtem Bityutskiy 	ino_t highest_inum;
11751e51764aSArtem Bityutskiy 	unsigned long long max_sqnum;
11761e51764aSArtem Bityutskiy 	unsigned long long cmt_no;
11771e51764aSArtem Bityutskiy 	spinlock_t cnt_lock;
11781e51764aSArtem Bityutskiy 	int fmt_version;
11791e51764aSArtem Bityutskiy 	unsigned char uuid[16];
11801e51764aSArtem Bityutskiy 
11811e51764aSArtem Bityutskiy 	int lhead_lnum;
11821e51764aSArtem Bityutskiy 	int lhead_offs;
11831e51764aSArtem Bityutskiy 	int ltail_lnum;
11841e51764aSArtem Bityutskiy 	struct mutex log_mutex;
11851e51764aSArtem Bityutskiy 	int min_log_bytes;
11861e51764aSArtem Bityutskiy 	long long cmt_bud_bytes;
11871e51764aSArtem Bityutskiy 
11881e51764aSArtem Bityutskiy 	struct rb_root buds;
11891e51764aSArtem Bityutskiy 	long long bud_bytes;
11901e51764aSArtem Bityutskiy 	spinlock_t buds_lock;
11911e51764aSArtem Bityutskiy 	int jhead_cnt;
11921e51764aSArtem Bityutskiy 	struct ubifs_jhead *jheads;
11931e51764aSArtem Bityutskiy 	long long max_bud_bytes;
11941e51764aSArtem Bityutskiy 	long long bg_bud_bytes;
11951e51764aSArtem Bityutskiy 	struct list_head old_buds;
11961e51764aSArtem Bityutskiy 	int max_bud_cnt;
11971e51764aSArtem Bityutskiy 
11981e51764aSArtem Bityutskiy 	struct rw_semaphore commit_sem;
11991e51764aSArtem Bityutskiy 	int cmt_state;
12001e51764aSArtem Bityutskiy 	spinlock_t cs_lock;
12011e51764aSArtem Bityutskiy 	wait_queue_head_t cmt_wq;
1202625bf371SArtem Bityutskiy 
12031e51764aSArtem Bityutskiy 	unsigned int fast_unmount:1;
12041e51764aSArtem Bityutskiy 	unsigned int big_lpt:1;
1205625bf371SArtem Bityutskiy 	unsigned int no_chk_data_crc:1;
1206625bf371SArtem Bityutskiy 	unsigned int bulk_read:1;
1207a1dc080cSArtem Bityutskiy 	unsigned int default_compr:2;
12081e51764aSArtem Bityutskiy 
12091e51764aSArtem Bityutskiy 	struct mutex tnc_mutex;
12101e51764aSArtem Bityutskiy 	struct ubifs_zbranch zroot;
12111e51764aSArtem Bityutskiy 	struct ubifs_znode *cnext;
12121e51764aSArtem Bityutskiy 	struct ubifs_znode *enext;
12131e51764aSArtem Bityutskiy 	int *gap_lebs;
12141e51764aSArtem Bityutskiy 	void *cbuf;
12151e51764aSArtem Bityutskiy 	void *ileb_buf;
12161e51764aSArtem Bityutskiy 	int ileb_len;
12171e51764aSArtem Bityutskiy 	int ihead_lnum;
12181e51764aSArtem Bityutskiy 	int ihead_offs;
12191e51764aSArtem Bityutskiy 	int *ilebs;
12201e51764aSArtem Bityutskiy 	int ileb_cnt;
12211e51764aSArtem Bityutskiy 	int ileb_nxt;
12221e51764aSArtem Bityutskiy 	struct rb_root old_idx;
12231e51764aSArtem Bityutskiy 	int *bottom_up_buf;
12241e51764aSArtem Bityutskiy #ifdef CONFIG_UBIFS_FS_DEBUG
12251e51764aSArtem Bityutskiy 	int new_ihead_lnum;
12261e51764aSArtem Bityutskiy 	int new_ihead_offs;
12271e51764aSArtem Bityutskiy #endif
12281e51764aSArtem Bityutskiy 
12291e51764aSArtem Bityutskiy 	struct ubifs_mst_node *mst_node;
12301e51764aSArtem Bityutskiy 	int mst_offs;
12311e51764aSArtem Bityutskiy 	struct mutex mst_mutex;
12323477d204SArtem Bityutskiy 
12336c0c42cdSArtem Bityutskiy 	int max_bu_buf_len;
12343477d204SArtem Bityutskiy 	struct mutex bu_mutex;
12353477d204SArtem Bityutskiy 	struct bu_info bu;
12361e51764aSArtem Bityutskiy 
12371e51764aSArtem Bityutskiy 	int log_lebs;
12381e51764aSArtem Bityutskiy 	long long log_bytes;
12391e51764aSArtem Bityutskiy 	int log_last;
12401e51764aSArtem Bityutskiy 	int lpt_lebs;
12411e51764aSArtem Bityutskiy 	int lpt_first;
12421e51764aSArtem Bityutskiy 	int lpt_last;
12431e51764aSArtem Bityutskiy 	int orph_lebs;
12441e51764aSArtem Bityutskiy 	int orph_first;
12451e51764aSArtem Bityutskiy 	int orph_last;
12461e51764aSArtem Bityutskiy 	int main_lebs;
12471e51764aSArtem Bityutskiy 	int main_first;
12481e51764aSArtem Bityutskiy 	long long main_bytes;
12491e51764aSArtem Bityutskiy 
12501e51764aSArtem Bityutskiy 	uint8_t key_hash_type;
12511e51764aSArtem Bityutskiy 	uint32_t (*key_hash)(const char *str, int len);
12521e51764aSArtem Bityutskiy 	int key_fmt;
12531e51764aSArtem Bityutskiy 	int key_len;
12541e51764aSArtem Bityutskiy 	int fanout;
12551e51764aSArtem Bityutskiy 
12561e51764aSArtem Bityutskiy 	int min_io_size;
12571e51764aSArtem Bityutskiy 	int min_io_shift;
12581e51764aSArtem Bityutskiy 	int leb_size;
12591e51764aSArtem Bityutskiy 	int half_leb_size;
12601e51764aSArtem Bityutskiy 	int leb_cnt;
12611e51764aSArtem Bityutskiy 	int max_leb_cnt;
12621e51764aSArtem Bityutskiy 	int old_leb_cnt;
12631e51764aSArtem Bityutskiy 	int ro_media;
12641e51764aSArtem Bityutskiy 
12651e51764aSArtem Bityutskiy 	atomic_long_t dirty_pg_cnt;
12661e51764aSArtem Bityutskiy 	atomic_long_t dirty_zn_cnt;
12671e51764aSArtem Bityutskiy 	atomic_long_t clean_zn_cnt;
12681e51764aSArtem Bityutskiy 
12691e51764aSArtem Bityutskiy 	long long budg_idx_growth;
12701e51764aSArtem Bityutskiy 	long long budg_data_growth;
12711e51764aSArtem Bityutskiy 	long long budg_dd_growth;
12721e51764aSArtem Bityutskiy 	long long budg_uncommitted_idx;
12731e51764aSArtem Bityutskiy 	spinlock_t space_lock;
12741e51764aSArtem Bityutskiy 	int min_idx_lebs;
12751e51764aSArtem Bityutskiy 	unsigned long long old_idx_sz;
12761e51764aSArtem Bityutskiy 	unsigned long long calc_idx_sz;
12771e51764aSArtem Bityutskiy 	struct ubifs_lp_stats lst;
1278ba60ecabSArtem Bityutskiy 	unsigned int nospace:1;
1279ba60ecabSArtem Bityutskiy 	unsigned int nospace_rp:1;
12801e51764aSArtem Bityutskiy 
12811e51764aSArtem Bityutskiy 	int page_budget;
12821e51764aSArtem Bityutskiy 	int inode_budget;
12831e51764aSArtem Bityutskiy 	int dent_budget;
12841e51764aSArtem Bityutskiy 
12851e51764aSArtem Bityutskiy 	int ref_node_alsz;
12861e51764aSArtem Bityutskiy 	int mst_node_alsz;
12871e51764aSArtem Bityutskiy 	int min_idx_node_sz;
12881e51764aSArtem Bityutskiy 	int max_idx_node_sz;
12891e51764aSArtem Bityutskiy 	long long max_inode_sz;
12901e51764aSArtem Bityutskiy 	int max_znode_sz;
12919bbb5726SArtem Bityutskiy 
12929bbb5726SArtem Bityutskiy 	int leb_overhead;
12931e51764aSArtem Bityutskiy 	int dead_wm;
12941e51764aSArtem Bityutskiy 	int dark_wm;
12951e51764aSArtem Bityutskiy 	int block_cnt;
12961e51764aSArtem Bityutskiy 
12971e51764aSArtem Bityutskiy 	struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
12981e51764aSArtem Bityutskiy 	struct ubi_volume_desc *ubi;
12991e51764aSArtem Bityutskiy 	struct ubi_device_info di;
13001e51764aSArtem Bityutskiy 	struct ubi_volume_info vi;
13011e51764aSArtem Bityutskiy 
13021e51764aSArtem Bityutskiy 	struct rb_root orph_tree;
13031e51764aSArtem Bityutskiy 	struct list_head orph_list;
13041e51764aSArtem Bityutskiy 	struct list_head orph_new;
13051e51764aSArtem Bityutskiy 	struct ubifs_orphan *orph_cnext;
13061e51764aSArtem Bityutskiy 	struct ubifs_orphan *orph_dnext;
13071e51764aSArtem Bityutskiy 	spinlock_t orphan_lock;
13081e51764aSArtem Bityutskiy 	void *orph_buf;
13091e51764aSArtem Bityutskiy 	int new_orphans;
13101e51764aSArtem Bityutskiy 	int cmt_orphans;
13111e51764aSArtem Bityutskiy 	int tot_orphans;
13121e51764aSArtem Bityutskiy 	int max_orphans;
13131e51764aSArtem Bityutskiy 	int ohead_lnum;
13141e51764aSArtem Bityutskiy 	int ohead_offs;
13151e51764aSArtem Bityutskiy 	int no_orphs;
13161e51764aSArtem Bityutskiy 
13171e51764aSArtem Bityutskiy 	struct task_struct *bgt;
13181e51764aSArtem Bityutskiy 	char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
13191e51764aSArtem Bityutskiy 	int need_bgt;
13201e51764aSArtem Bityutskiy 	int need_wbuf_sync;
13211e51764aSArtem Bityutskiy 
13221e51764aSArtem Bityutskiy 	int gc_lnum;
13231e51764aSArtem Bityutskiy 	void *sbuf;
13241e51764aSArtem Bityutskiy 	struct list_head idx_gc;
13251e51764aSArtem Bityutskiy 	int idx_gc_cnt;
1326601c0bc4SAdrian Hunter 	volatile int gc_seq;
1327601c0bc4SAdrian Hunter 	volatile int gced_lnum;
13281e51764aSArtem Bityutskiy 
13291e51764aSArtem Bityutskiy 	struct list_head infos_list;
13301e51764aSArtem Bityutskiy 	struct mutex umount_mutex;
13311e51764aSArtem Bityutskiy 	unsigned int shrinker_run_no;
13321e51764aSArtem Bityutskiy 
13331e51764aSArtem Bityutskiy 	int space_bits;
13341e51764aSArtem Bityutskiy 	int lpt_lnum_bits;
13351e51764aSArtem Bityutskiy 	int lpt_offs_bits;
13361e51764aSArtem Bityutskiy 	int lpt_spc_bits;
13371e51764aSArtem Bityutskiy 	int pcnt_bits;
13381e51764aSArtem Bityutskiy 	int lnum_bits;
13391e51764aSArtem Bityutskiy 	int nnode_sz;
13401e51764aSArtem Bityutskiy 	int pnode_sz;
13411e51764aSArtem Bityutskiy 	int ltab_sz;
13421e51764aSArtem Bityutskiy 	int lsave_sz;
13431e51764aSArtem Bityutskiy 	int pnode_cnt;
13441e51764aSArtem Bityutskiy 	int nnode_cnt;
13451e51764aSArtem Bityutskiy 	int lpt_hght;
13461e51764aSArtem Bityutskiy 	int pnodes_have;
13471e51764aSArtem Bityutskiy 
13481e51764aSArtem Bityutskiy 	struct mutex lp_mutex;
13491e51764aSArtem Bityutskiy 	int lpt_lnum;
13501e51764aSArtem Bityutskiy 	int lpt_offs;
13511e51764aSArtem Bityutskiy 	int nhead_lnum;
13521e51764aSArtem Bityutskiy 	int nhead_offs;
13531e51764aSArtem Bityutskiy 	int lpt_drty_flgs;
13541e51764aSArtem Bityutskiy 	int dirty_nn_cnt;
13551e51764aSArtem Bityutskiy 	int dirty_pn_cnt;
135673944a6dSAdrian Hunter 	int check_lpt_free;
13571e51764aSArtem Bityutskiy 	long long lpt_sz;
13581e51764aSArtem Bityutskiy 	void *lpt_nod_buf;
13591e51764aSArtem Bityutskiy 	void *lpt_buf;
13601e51764aSArtem Bityutskiy 	struct ubifs_nnode *nroot;
13611e51764aSArtem Bityutskiy 	struct ubifs_cnode *lpt_cnext;
13621e51764aSArtem Bityutskiy 	struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
13631e51764aSArtem Bityutskiy 	struct ubifs_lpt_heap dirty_idx;
13641e51764aSArtem Bityutskiy 	struct list_head uncat_list;
13651e51764aSArtem Bityutskiy 	struct list_head empty_list;
13661e51764aSArtem Bityutskiy 	struct list_head freeable_list;
13671e51764aSArtem Bityutskiy 	struct list_head frdi_idx_list;
13681e51764aSArtem Bityutskiy 	int freeable_cnt;
13691e51764aSArtem Bityutskiy 
13701e51764aSArtem Bityutskiy 	int ltab_lnum;
13711e51764aSArtem Bityutskiy 	int ltab_offs;
13721e51764aSArtem Bityutskiy 	struct ubifs_lpt_lprops *ltab;
13731e51764aSArtem Bityutskiy 	struct ubifs_lpt_lprops *ltab_cmt;
13741e51764aSArtem Bityutskiy 	int lsave_cnt;
13751e51764aSArtem Bityutskiy 	int lsave_lnum;
13761e51764aSArtem Bityutskiy 	int lsave_offs;
13771e51764aSArtem Bityutskiy 	int *lsave;
13781e51764aSArtem Bityutskiy 	int lscan_lnum;
13791e51764aSArtem Bityutskiy 
13801e51764aSArtem Bityutskiy 	long long rp_size;
13811e51764aSArtem Bityutskiy 	long long report_rp_size;
13821e51764aSArtem Bityutskiy 	uid_t rp_uid;
13831e51764aSArtem Bityutskiy 	gid_t rp_gid;
13841e51764aSArtem Bityutskiy 
13851e51764aSArtem Bityutskiy 	/* The below fields are used only during mounting and re-mounting */
13861e51764aSArtem Bityutskiy 	int empty;
13871e51764aSArtem Bityutskiy 	struct rb_root replay_tree;
13881e51764aSArtem Bityutskiy 	struct list_head replay_list;
13891e51764aSArtem Bityutskiy 	struct list_head replay_buds;
13901e51764aSArtem Bityutskiy 	unsigned long long cs_sqnum;
13911e51764aSArtem Bityutskiy 	unsigned long long replay_sqnum;
13921e51764aSArtem Bityutskiy 	int need_recovery;
13931e51764aSArtem Bityutskiy 	int replaying;
13941e51764aSArtem Bityutskiy 	struct list_head unclean_leb_list;
13951e51764aSArtem Bityutskiy 	struct ubifs_mst_node *rcvrd_mst_node;
13961e51764aSArtem Bityutskiy 	struct rb_root size_tree;
13971e51764aSArtem Bityutskiy 	int remounting_rw;
13982953e73fSAdrian Hunter 	int always_chk_crc;
13991e51764aSArtem Bityutskiy 	struct ubifs_mount_opts mount_opts;
14001e51764aSArtem Bityutskiy 
14011e51764aSArtem Bityutskiy #ifdef CONFIG_UBIFS_FS_DEBUG
14021e51764aSArtem Bityutskiy 	void *dbg_buf;
14031e51764aSArtem Bityutskiy 	struct ubifs_zbranch old_zroot;
14041e51764aSArtem Bityutskiy 	int old_zroot_level;
14051e51764aSArtem Bityutskiy 	unsigned long long old_zroot_sqnum;
14061e51764aSArtem Bityutskiy 	int failure_mode;
14071e51764aSArtem Bityutskiy 	int fail_delay;
14081e51764aSArtem Bityutskiy 	unsigned long fail_timeout;
14091e51764aSArtem Bityutskiy 	unsigned int fail_cnt;
14101e51764aSArtem Bityutskiy 	unsigned int fail_cnt_max;
141173944a6dSAdrian Hunter 	long long chk_lpt_sz;
141273944a6dSAdrian Hunter 	long long chk_lpt_sz2;
141373944a6dSAdrian Hunter 	long long chk_lpt_wastage;
141473944a6dSAdrian Hunter 	int chk_lpt_lebs;
141573944a6dSAdrian Hunter 	int new_nhead_lnum;
141673944a6dSAdrian Hunter 	int new_nhead_offs;
14171e51764aSArtem Bityutskiy #endif
14181e51764aSArtem Bityutskiy };
14191e51764aSArtem Bityutskiy 
14201e51764aSArtem Bityutskiy extern struct list_head ubifs_infos;
14211e51764aSArtem Bityutskiy extern spinlock_t ubifs_infos_lock;
14221e51764aSArtem Bityutskiy extern atomic_long_t ubifs_clean_zn_cnt;
14231e51764aSArtem Bityutskiy extern struct kmem_cache *ubifs_inode_slab;
14241e51764aSArtem Bityutskiy extern struct super_operations ubifs_super_operations;
14251e51764aSArtem Bityutskiy extern struct address_space_operations ubifs_file_address_operations;
14261e51764aSArtem Bityutskiy extern struct file_operations ubifs_file_operations;
14271e51764aSArtem Bityutskiy extern struct inode_operations ubifs_file_inode_operations;
14281e51764aSArtem Bityutskiy extern struct file_operations ubifs_dir_operations;
14291e51764aSArtem Bityutskiy extern struct inode_operations ubifs_dir_inode_operations;
14301e51764aSArtem Bityutskiy extern struct inode_operations ubifs_symlink_inode_operations;
14311e51764aSArtem Bityutskiy extern struct backing_dev_info ubifs_backing_dev_info;
14321e51764aSArtem Bityutskiy extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
14331e51764aSArtem Bityutskiy 
14341e51764aSArtem Bityutskiy /* io.c */
1435ff46d7b3SAdrian Hunter void ubifs_ro_mode(struct ubifs_info *c, int err);
14361e51764aSArtem Bityutskiy int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
14371e51764aSArtem Bityutskiy int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs,
14381e51764aSArtem Bityutskiy 			   int dtype);
14391e51764aSArtem Bityutskiy int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
14401e51764aSArtem Bityutskiy int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
14411e51764aSArtem Bityutskiy 		    int lnum, int offs);
14421e51764aSArtem Bityutskiy int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
14431e51764aSArtem Bityutskiy 			 int lnum, int offs);
14441e51764aSArtem Bityutskiy int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
14451e51764aSArtem Bityutskiy 		     int offs, int dtype);
14461e51764aSArtem Bityutskiy int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
14472953e73fSAdrian Hunter 		     int offs, int quiet, int chk_crc);
14481e51764aSArtem Bityutskiy void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
14491e51764aSArtem Bityutskiy void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
14501e51764aSArtem Bityutskiy int ubifs_io_init(struct ubifs_info *c);
14511e51764aSArtem Bityutskiy void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
14521e51764aSArtem Bityutskiy int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
14531e51764aSArtem Bityutskiy int ubifs_bg_wbufs_sync(struct ubifs_info *c);
14541e51764aSArtem Bityutskiy void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
14551e51764aSArtem Bityutskiy int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
14561e51764aSArtem Bityutskiy 
14571e51764aSArtem Bityutskiy /* scan.c */
14581e51764aSArtem Bityutskiy struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
14591e51764aSArtem Bityutskiy 				  int offs, void *sbuf);
14601e51764aSArtem Bityutskiy void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
14611e51764aSArtem Bityutskiy int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
14621e51764aSArtem Bityutskiy 		      int offs, int quiet);
14631e51764aSArtem Bityutskiy struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
14641e51764aSArtem Bityutskiy 					int offs, void *sbuf);
14651e51764aSArtem Bityutskiy void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
14661e51764aSArtem Bityutskiy 		    int lnum, int offs);
14671e51764aSArtem Bityutskiy int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
14681e51764aSArtem Bityutskiy 		   void *buf, int offs);
14691e51764aSArtem Bityutskiy void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
14701e51764aSArtem Bityutskiy 			      void *buf);
14711e51764aSArtem Bityutskiy 
14721e51764aSArtem Bityutskiy /* log.c */
14731e51764aSArtem Bityutskiy void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
14741e51764aSArtem Bityutskiy void ubifs_create_buds_lists(struct ubifs_info *c);
14751e51764aSArtem Bityutskiy int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
14761e51764aSArtem Bityutskiy struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
14771e51764aSArtem Bityutskiy struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
14781e51764aSArtem Bityutskiy int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
14791e51764aSArtem Bityutskiy int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
14801e51764aSArtem Bityutskiy int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
14811e51764aSArtem Bityutskiy int ubifs_consolidate_log(struct ubifs_info *c);
14821e51764aSArtem Bityutskiy 
14831e51764aSArtem Bityutskiy /* journal.c */
14841e51764aSArtem Bityutskiy int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
14851e51764aSArtem Bityutskiy 		     const struct qstr *nm, const struct inode *inode,
14861e51764aSArtem Bityutskiy 		     int deletion, int xent);
14871e51764aSArtem Bityutskiy int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
14881e51764aSArtem Bityutskiy 			 const union ubifs_key *key, const void *buf, int len);
14891f28681aSArtem Bityutskiy int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
1490de94eb55SArtem Bityutskiy int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
14911e51764aSArtem Bityutskiy int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
14921e51764aSArtem Bityutskiy 		     const struct dentry *old_dentry,
14931e51764aSArtem Bityutskiy 		     const struct inode *new_dir,
14941e51764aSArtem Bityutskiy 		     const struct dentry *new_dentry, int sync);
14951e51764aSArtem Bityutskiy int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
14961e51764aSArtem Bityutskiy 		       loff_t old_size, loff_t new_size);
14971e51764aSArtem Bityutskiy int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
14981e51764aSArtem Bityutskiy 			   const struct inode *inode, const struct qstr *nm);
14991e51764aSArtem Bityutskiy int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
15001e51764aSArtem Bityutskiy 			   const struct inode *inode2);
15011e51764aSArtem Bityutskiy 
15021e51764aSArtem Bityutskiy /* budget.c */
15031e51764aSArtem Bityutskiy int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
15041e51764aSArtem Bityutskiy void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
15051e51764aSArtem Bityutskiy void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
15061e51764aSArtem Bityutskiy 				      struct ubifs_inode *ui);
15071e51764aSArtem Bityutskiy int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
15081e51764aSArtem Bityutskiy 			  struct ubifs_budget_req *req);
15091e51764aSArtem Bityutskiy void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
15101e51764aSArtem Bityutskiy 				struct ubifs_budget_req *req);
15111e51764aSArtem Bityutskiy void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
15121e51764aSArtem Bityutskiy 			 struct ubifs_budget_req *req);
15137dad181bSArtem Bityutskiy long long ubifs_get_free_space(struct ubifs_info *c);
15141e51764aSArtem Bityutskiy int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
15151e51764aSArtem Bityutskiy void ubifs_convert_page_budget(struct ubifs_info *c);
15164b5f2762SArtem Bityutskiy long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free);
15171e51764aSArtem Bityutskiy long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
15181e51764aSArtem Bityutskiy 
15191e51764aSArtem Bityutskiy /* find.c */
15201e51764aSArtem Bityutskiy int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *free,
15211e51764aSArtem Bityutskiy 			  int squeeze);
15221e51764aSArtem Bityutskiy int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
15231e51764aSArtem Bityutskiy int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
15241e51764aSArtem Bityutskiy 			 int min_space, int pick_free);
15251e51764aSArtem Bityutskiy int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
15261e51764aSArtem Bityutskiy int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
15271e51764aSArtem Bityutskiy 
15281e51764aSArtem Bityutskiy /* tnc.c */
15291e51764aSArtem Bityutskiy int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
15301e51764aSArtem Bityutskiy 			struct ubifs_znode **zn, int *n);
15311e51764aSArtem Bityutskiy int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
15321e51764aSArtem Bityutskiy 			void *node, const struct qstr *nm);
15331e51764aSArtem Bityutskiy int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
15341e51764aSArtem Bityutskiy 		     void *node, int *lnum, int *offs);
15351e51764aSArtem Bityutskiy int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
15361e51764aSArtem Bityutskiy 		  int offs, int len);
15371e51764aSArtem Bityutskiy int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
15381e51764aSArtem Bityutskiy 		      int old_lnum, int old_offs, int lnum, int offs, int len);
15391e51764aSArtem Bityutskiy int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
15401e51764aSArtem Bityutskiy 		     int lnum, int offs, int len, const struct qstr *nm);
15411e51764aSArtem Bityutskiy int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
15421e51764aSArtem Bityutskiy int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
15431e51764aSArtem Bityutskiy 			const struct qstr *nm);
15441e51764aSArtem Bityutskiy int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
15451e51764aSArtem Bityutskiy 			   union ubifs_key *to_key);
15461e51764aSArtem Bityutskiy int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
15471e51764aSArtem Bityutskiy struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
15481e51764aSArtem Bityutskiy 					   union ubifs_key *key,
15491e51764aSArtem Bityutskiy 					   const struct qstr *nm);
15501e51764aSArtem Bityutskiy void ubifs_tnc_close(struct ubifs_info *c);
15511e51764aSArtem Bityutskiy int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
15521e51764aSArtem Bityutskiy 		       int lnum, int offs, int is_idx);
15531e51764aSArtem Bityutskiy int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
15541e51764aSArtem Bityutskiy 			 int lnum, int offs);
15551e51764aSArtem Bityutskiy /* Shared by tnc.c for tnc_commit.c */
15561e51764aSArtem Bityutskiy void destroy_old_idx(struct ubifs_info *c);
15571e51764aSArtem Bityutskiy int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
15581e51764aSArtem Bityutskiy 		       int lnum, int offs);
15591e51764aSArtem Bityutskiy int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
15604793e7c5SAdrian Hunter int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
15614793e7c5SAdrian Hunter int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
15621e51764aSArtem Bityutskiy 
15631e51764aSArtem Bityutskiy /* tnc_misc.c */
15641e51764aSArtem Bityutskiy struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr,
15651e51764aSArtem Bityutskiy 					      struct ubifs_znode *znode);
15661e51764aSArtem Bityutskiy int ubifs_search_zbranch(const struct ubifs_info *c,
15671e51764aSArtem Bityutskiy 			 const struct ubifs_znode *znode,
15681e51764aSArtem Bityutskiy 			 const union ubifs_key *key, int *n);
15691e51764aSArtem Bityutskiy struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
15701e51764aSArtem Bityutskiy struct ubifs_znode *ubifs_tnc_postorder_next(struct ubifs_znode *znode);
15711e51764aSArtem Bityutskiy long ubifs_destroy_tnc_subtree(struct ubifs_znode *zr);
15721e51764aSArtem Bityutskiy struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
15731e51764aSArtem Bityutskiy 				     struct ubifs_zbranch *zbr,
15741e51764aSArtem Bityutskiy 				     struct ubifs_znode *parent, int iip);
15751e51764aSArtem Bityutskiy int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
15761e51764aSArtem Bityutskiy 			void *node);
15771e51764aSArtem Bityutskiy 
15781e51764aSArtem Bityutskiy /* tnc_commit.c */
15791e51764aSArtem Bityutskiy int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
15801e51764aSArtem Bityutskiy int ubifs_tnc_end_commit(struct ubifs_info *c);
15811e51764aSArtem Bityutskiy 
15821e51764aSArtem Bityutskiy /* shrinker.c */
15831e51764aSArtem Bityutskiy int ubifs_shrinker(int nr_to_scan, gfp_t gfp_mask);
15841e51764aSArtem Bityutskiy 
15851e51764aSArtem Bityutskiy /* commit.c */
15861e51764aSArtem Bityutskiy int ubifs_bg_thread(void *info);
15871e51764aSArtem Bityutskiy void ubifs_commit_required(struct ubifs_info *c);
15881e51764aSArtem Bityutskiy void ubifs_request_bg_commit(struct ubifs_info *c);
15891e51764aSArtem Bityutskiy int ubifs_run_commit(struct ubifs_info *c);
15901e51764aSArtem Bityutskiy void ubifs_recovery_commit(struct ubifs_info *c);
15911e51764aSArtem Bityutskiy int ubifs_gc_should_commit(struct ubifs_info *c);
15921e51764aSArtem Bityutskiy void ubifs_wait_for_commit(struct ubifs_info *c);
15931e51764aSArtem Bityutskiy 
15941e51764aSArtem Bityutskiy /* master.c */
15951e51764aSArtem Bityutskiy int ubifs_read_master(struct ubifs_info *c);
15961e51764aSArtem Bityutskiy int ubifs_write_master(struct ubifs_info *c);
15971e51764aSArtem Bityutskiy 
15981e51764aSArtem Bityutskiy /* sb.c */
15991e51764aSArtem Bityutskiy int ubifs_read_superblock(struct ubifs_info *c);
16001e51764aSArtem Bityutskiy struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c);
16011e51764aSArtem Bityutskiy int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
16021e51764aSArtem Bityutskiy 
16031e51764aSArtem Bityutskiy /* replay.c */
16041e51764aSArtem Bityutskiy int ubifs_validate_entry(struct ubifs_info *c,
16051e51764aSArtem Bityutskiy 			 const struct ubifs_dent_node *dent);
16061e51764aSArtem Bityutskiy int ubifs_replay_journal(struct ubifs_info *c);
16071e51764aSArtem Bityutskiy 
16081e51764aSArtem Bityutskiy /* gc.c */
16091e51764aSArtem Bityutskiy int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
16101e51764aSArtem Bityutskiy int ubifs_gc_start_commit(struct ubifs_info *c);
16111e51764aSArtem Bityutskiy int ubifs_gc_end_commit(struct ubifs_info *c);
16121e51764aSArtem Bityutskiy void ubifs_destroy_idx_gc(struct ubifs_info *c);
16131e51764aSArtem Bityutskiy int ubifs_get_idx_gc_leb(struct ubifs_info *c);
16141e51764aSArtem Bityutskiy int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
16151e51764aSArtem Bityutskiy 
16161e51764aSArtem Bityutskiy /* orphan.c */
16171e51764aSArtem Bityutskiy int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
16181e51764aSArtem Bityutskiy void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
16191e51764aSArtem Bityutskiy int ubifs_orphan_start_commit(struct ubifs_info *c);
16201e51764aSArtem Bityutskiy int ubifs_orphan_end_commit(struct ubifs_info *c);
16211e51764aSArtem Bityutskiy int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
16221e51764aSArtem Bityutskiy 
16231e51764aSArtem Bityutskiy /* lpt.c */
16241e51764aSArtem Bityutskiy int ubifs_calc_lpt_geom(struct ubifs_info *c);
16251e51764aSArtem Bityutskiy int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
16261e51764aSArtem Bityutskiy 			  int *lpt_lebs, int *big_lpt);
16271e51764aSArtem Bityutskiy int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
16281e51764aSArtem Bityutskiy struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
16291e51764aSArtem Bityutskiy struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
16301e51764aSArtem Bityutskiy int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
16311e51764aSArtem Bityutskiy 			  ubifs_lpt_scan_callback scan_cb, void *data);
16321e51764aSArtem Bityutskiy 
16331e51764aSArtem Bityutskiy /* Shared by lpt.c for lpt_commit.c */
16341e51764aSArtem Bityutskiy void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
16351e51764aSArtem Bityutskiy void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
16361e51764aSArtem Bityutskiy 		     struct ubifs_lpt_lprops *ltab);
16371e51764aSArtem Bityutskiy void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
16381e51764aSArtem Bityutskiy 		      struct ubifs_pnode *pnode);
16391e51764aSArtem Bityutskiy void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
16401e51764aSArtem Bityutskiy 		      struct ubifs_nnode *nnode);
16411e51764aSArtem Bityutskiy struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
16421e51764aSArtem Bityutskiy 				    struct ubifs_nnode *parent, int iip);
16431e51764aSArtem Bityutskiy struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
16441e51764aSArtem Bityutskiy 				    struct ubifs_nnode *parent, int iip);
16451e51764aSArtem Bityutskiy int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
16461e51764aSArtem Bityutskiy void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
16471e51764aSArtem Bityutskiy void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
16481e51764aSArtem Bityutskiy uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits);
16491e51764aSArtem Bityutskiy struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
16501e51764aSArtem Bityutskiy 
16511e51764aSArtem Bityutskiy /* lpt_commit.c */
16521e51764aSArtem Bityutskiy int ubifs_lpt_start_commit(struct ubifs_info *c);
16531e51764aSArtem Bityutskiy int ubifs_lpt_end_commit(struct ubifs_info *c);
16541e51764aSArtem Bityutskiy int ubifs_lpt_post_commit(struct ubifs_info *c);
16551e51764aSArtem Bityutskiy void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
16561e51764aSArtem Bityutskiy 
16571e51764aSArtem Bityutskiy /* lprops.c */
16581e51764aSArtem Bityutskiy const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
16591e51764aSArtem Bityutskiy 					   const struct ubifs_lprops *lp,
16601e51764aSArtem Bityutskiy 					   int free, int dirty, int flags,
16611e51764aSArtem Bityutskiy 					   int idx_gc_cnt);
16621e51764aSArtem Bityutskiy void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *stats);
16631e51764aSArtem Bityutskiy void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
16641e51764aSArtem Bityutskiy 		      int cat);
16651e51764aSArtem Bityutskiy void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
16661e51764aSArtem Bityutskiy 		       struct ubifs_lprops *new_lprops);
16671e51764aSArtem Bityutskiy void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
16681e51764aSArtem Bityutskiy int ubifs_categorize_lprops(const struct ubifs_info *c,
16691e51764aSArtem Bityutskiy 			    const struct ubifs_lprops *lprops);
16701e51764aSArtem Bityutskiy int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
16711e51764aSArtem Bityutskiy 			int flags_set, int flags_clean, int idx_gc_cnt);
16721e51764aSArtem Bityutskiy int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
16731e51764aSArtem Bityutskiy 			int flags_set, int flags_clean);
16741e51764aSArtem Bityutskiy int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
16751e51764aSArtem Bityutskiy const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
16761e51764aSArtem Bityutskiy const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
16771e51764aSArtem Bityutskiy const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
16781e51764aSArtem Bityutskiy const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
16791e51764aSArtem Bityutskiy 
16801e51764aSArtem Bityutskiy /* file.c */
16811e51764aSArtem Bityutskiy int ubifs_fsync(struct file *file, struct dentry *dentry, int datasync);
16821e51764aSArtem Bityutskiy int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
16831e51764aSArtem Bityutskiy 
16841e51764aSArtem Bityutskiy /* dir.c */
16851e51764aSArtem Bityutskiy struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir,
16861e51764aSArtem Bityutskiy 			      int mode);
16871e51764aSArtem Bityutskiy int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
16881e51764aSArtem Bityutskiy 		  struct kstat *stat);
16891e51764aSArtem Bityutskiy 
16901e51764aSArtem Bityutskiy /* xattr.c */
16911e51764aSArtem Bityutskiy int ubifs_setxattr(struct dentry *dentry, const char *name,
16921e51764aSArtem Bityutskiy 		   const void *value, size_t size, int flags);
16931e51764aSArtem Bityutskiy ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
16941e51764aSArtem Bityutskiy 		       size_t size);
16951e51764aSArtem Bityutskiy ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
16961e51764aSArtem Bityutskiy int ubifs_removexattr(struct dentry *dentry, const char *name);
16971e51764aSArtem Bityutskiy 
16981e51764aSArtem Bityutskiy /* super.c */
16991e51764aSArtem Bityutskiy struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
17001e51764aSArtem Bityutskiy 
17011e51764aSArtem Bityutskiy /* recovery.c */
17021e51764aSArtem Bityutskiy int ubifs_recover_master_node(struct ubifs_info *c);
17031e51764aSArtem Bityutskiy int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
17041e51764aSArtem Bityutskiy struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
17051e51764aSArtem Bityutskiy 					 int offs, void *sbuf, int grouped);
17061e51764aSArtem Bityutskiy struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
17071e51764aSArtem Bityutskiy 					     int offs, void *sbuf);
17081e51764aSArtem Bityutskiy int ubifs_recover_inl_heads(const struct ubifs_info *c, void *sbuf);
17091e51764aSArtem Bityutskiy int ubifs_clean_lebs(const struct ubifs_info *c, void *sbuf);
17101e51764aSArtem Bityutskiy int ubifs_rcvry_gc_commit(struct ubifs_info *c);
17111e51764aSArtem Bityutskiy int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
17121e51764aSArtem Bityutskiy 			     int deletion, loff_t new_size);
17131e51764aSArtem Bityutskiy int ubifs_recover_size(struct ubifs_info *c);
17141e51764aSArtem Bityutskiy void ubifs_destroy_size_tree(struct ubifs_info *c);
17151e51764aSArtem Bityutskiy 
17161e51764aSArtem Bityutskiy /* ioctl.c */
17171e51764aSArtem Bityutskiy long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
17181e51764aSArtem Bityutskiy void ubifs_set_inode_flags(struct inode *inode);
17191e51764aSArtem Bityutskiy #ifdef CONFIG_COMPAT
17201e51764aSArtem Bityutskiy long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
17211e51764aSArtem Bityutskiy #endif
17221e51764aSArtem Bityutskiy 
17231e51764aSArtem Bityutskiy /* compressor.c */
17241e51764aSArtem Bityutskiy int __init ubifs_compressors_init(void);
17251e51764aSArtem Bityutskiy void __exit ubifs_compressors_exit(void);
17261e51764aSArtem Bityutskiy void ubifs_compress(const void *in_buf, int in_len, void *out_buf, int *out_len,
17271e51764aSArtem Bityutskiy 		    int *compr_type);
17281e51764aSArtem Bityutskiy int ubifs_decompress(const void *buf, int len, void *out, int *out_len,
17291e51764aSArtem Bityutskiy 		     int compr_type);
17301e51764aSArtem Bityutskiy 
17311e51764aSArtem Bityutskiy #include "debug.h"
17321e51764aSArtem Bityutskiy #include "misc.h"
17331e51764aSArtem Bityutskiy #include "key.h"
17341e51764aSArtem Bityutskiy 
17351e51764aSArtem Bityutskiy #endif /* !__UBIFS_H__ */
1736