162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * ext4.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 1992, 1993, 1994, 1995 662306a36Sopenharmony_ci * Remy Card (card@masi.ibp.fr) 762306a36Sopenharmony_ci * Laboratoire MASI - Institut Blaise Pascal 862306a36Sopenharmony_ci * Universite Pierre et Marie Curie (Paris VI) 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * from 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * linux/include/linux/minix_fs.h 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * Copyright (C) 1991, 1992 Linus Torvalds 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef _EXT4_H 1862306a36Sopenharmony_ci#define _EXT4_H 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <linux/refcount.h> 2162306a36Sopenharmony_ci#include <linux/types.h> 2262306a36Sopenharmony_ci#include <linux/blkdev.h> 2362306a36Sopenharmony_ci#include <linux/magic.h> 2462306a36Sopenharmony_ci#include <linux/jbd2.h> 2562306a36Sopenharmony_ci#include <linux/quota.h> 2662306a36Sopenharmony_ci#include <linux/rwsem.h> 2762306a36Sopenharmony_ci#include <linux/rbtree.h> 2862306a36Sopenharmony_ci#include <linux/seqlock.h> 2962306a36Sopenharmony_ci#include <linux/mutex.h> 3062306a36Sopenharmony_ci#include <linux/timer.h> 3162306a36Sopenharmony_ci#include <linux/wait.h> 3262306a36Sopenharmony_ci#include <linux/sched/signal.h> 3362306a36Sopenharmony_ci#include <linux/blockgroup_lock.h> 3462306a36Sopenharmony_ci#include <linux/percpu_counter.h> 3562306a36Sopenharmony_ci#include <linux/ratelimit.h> 3662306a36Sopenharmony_ci#include <crypto/hash.h> 3762306a36Sopenharmony_ci#include <linux/falloc.h> 3862306a36Sopenharmony_ci#include <linux/percpu-rwsem.h> 3962306a36Sopenharmony_ci#include <linux/fiemap.h> 4062306a36Sopenharmony_ci#ifdef __KERNEL__ 4162306a36Sopenharmony_ci#include <linux/compat.h> 4262306a36Sopenharmony_ci#endif 4362306a36Sopenharmony_ci#include <uapi/linux/ext4.h> 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#include <linux/fscrypt.h> 4662306a36Sopenharmony_ci#include <linux/fsverity.h> 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#include <linux/compiler.h> 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* 5162306a36Sopenharmony_ci * The fourth extended filesystem constants/structures 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* 5562306a36Sopenharmony_ci * with AGGRESSIVE_CHECK allocator runs consistency checks over 5662306a36Sopenharmony_ci * structures. these checks slow things down a lot 5762306a36Sopenharmony_ci */ 5862306a36Sopenharmony_ci#define AGGRESSIVE_CHECK__ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* 6162306a36Sopenharmony_ci * with DOUBLE_CHECK defined mballoc creates persistent in-core 6262306a36Sopenharmony_ci * bitmaps, maintains and uses them to check for double allocations 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_ci#define DOUBLE_CHECK__ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* 6762306a36Sopenharmony_ci * Define EXT4FS_DEBUG to produce debug messages 6862306a36Sopenharmony_ci */ 6962306a36Sopenharmony_ci#undef EXT4FS_DEBUG 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci/* 7262306a36Sopenharmony_ci * Debug code 7362306a36Sopenharmony_ci */ 7462306a36Sopenharmony_ci#ifdef EXT4FS_DEBUG 7562306a36Sopenharmony_ci#define ext4_debug(f, a...) \ 7662306a36Sopenharmony_ci do { \ 7762306a36Sopenharmony_ci printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \ 7862306a36Sopenharmony_ci __FILE__, __LINE__, __func__); \ 7962306a36Sopenharmony_ci printk(KERN_DEBUG f, ## a); \ 8062306a36Sopenharmony_ci } while (0) 8162306a36Sopenharmony_ci#else 8262306a36Sopenharmony_ci#define ext4_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 8362306a36Sopenharmony_ci#endif 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci /* 8662306a36Sopenharmony_ci * Turn on EXT_DEBUG to enable ext4_ext_show_path/leaf/move in extents.c 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_ci#define EXT_DEBUG__ 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* 9162306a36Sopenharmony_ci * Dynamic printk for controlled extents debugging. 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_ci#ifdef CONFIG_EXT4_DEBUG 9462306a36Sopenharmony_ci#define ext_debug(ino, fmt, ...) \ 9562306a36Sopenharmony_ci pr_debug("[%s/%d] EXT4-fs (%s): ino %lu: (%s, %d): %s:" fmt, \ 9662306a36Sopenharmony_ci current->comm, task_pid_nr(current), \ 9762306a36Sopenharmony_ci ino->i_sb->s_id, ino->i_ino, __FILE__, __LINE__, \ 9862306a36Sopenharmony_ci __func__, ##__VA_ARGS__) 9962306a36Sopenharmony_ci#else 10062306a36Sopenharmony_ci#define ext_debug(ino, fmt, ...) no_printk(fmt, ##__VA_ARGS__) 10162306a36Sopenharmony_ci#endif 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define ASSERT(assert) \ 10462306a36Sopenharmony_cido { \ 10562306a36Sopenharmony_ci if (unlikely(!(assert))) { \ 10662306a36Sopenharmony_ci printk(KERN_EMERG \ 10762306a36Sopenharmony_ci "Assertion failure in %s() at %s:%d: '%s'\n", \ 10862306a36Sopenharmony_ci __func__, __FILE__, __LINE__, #assert); \ 10962306a36Sopenharmony_ci BUG(); \ 11062306a36Sopenharmony_ci } \ 11162306a36Sopenharmony_ci} while (0) 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* data type for block offset of block group */ 11462306a36Sopenharmony_citypedef int ext4_grpblk_t; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/* data type for filesystem-wide blocks number */ 11762306a36Sopenharmony_citypedef unsigned long long ext4_fsblk_t; 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* data type for file logical block number */ 12062306a36Sopenharmony_citypedef __u32 ext4_lblk_t; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* data type for block group number */ 12362306a36Sopenharmony_citypedef unsigned int ext4_group_t; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cienum SHIFT_DIRECTION { 12662306a36Sopenharmony_ci SHIFT_LEFT = 0, 12762306a36Sopenharmony_ci SHIFT_RIGHT, 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* 13162306a36Sopenharmony_ci * For each criteria, mballoc has slightly different way of finding 13262306a36Sopenharmony_ci * the required blocks nad usually, higher the criteria the slower the 13362306a36Sopenharmony_ci * allocation. We start at lower criterias and keep falling back to 13462306a36Sopenharmony_ci * higher ones if we are not able to find any blocks. Lower (earlier) 13562306a36Sopenharmony_ci * criteria are faster. 13662306a36Sopenharmony_ci */ 13762306a36Sopenharmony_cienum criteria { 13862306a36Sopenharmony_ci /* 13962306a36Sopenharmony_ci * Used when number of blocks needed is a power of 2. This 14062306a36Sopenharmony_ci * doesn't trigger any disk IO except prefetch and is the 14162306a36Sopenharmony_ci * fastest criteria. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_ci CR_POWER2_ALIGNED, 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci /* 14662306a36Sopenharmony_ci * Tries to lookup in-memory data structures to find the most 14762306a36Sopenharmony_ci * suitable group that satisfies goal request. No disk IO 14862306a36Sopenharmony_ci * except block prefetch. 14962306a36Sopenharmony_ci */ 15062306a36Sopenharmony_ci CR_GOAL_LEN_FAST, 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci /* 15362306a36Sopenharmony_ci * Same as CR_GOAL_LEN_FAST but is allowed to reduce the goal 15462306a36Sopenharmony_ci * length to the best available length for faster allocation. 15562306a36Sopenharmony_ci */ 15662306a36Sopenharmony_ci CR_BEST_AVAIL_LEN, 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci /* 15962306a36Sopenharmony_ci * Reads each block group sequentially, performing disk IO if 16062306a36Sopenharmony_ci * necessary, to find find_suitable block group. Tries to 16162306a36Sopenharmony_ci * allocate goal length but might trim the request if nothing 16262306a36Sopenharmony_ci * is found after enough tries. 16362306a36Sopenharmony_ci */ 16462306a36Sopenharmony_ci CR_GOAL_LEN_SLOW, 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci /* 16762306a36Sopenharmony_ci * Finds the first free set of blocks and allocates 16862306a36Sopenharmony_ci * those. This is only used in rare cases when 16962306a36Sopenharmony_ci * CR_GOAL_LEN_SLOW also fails to allocate anything. 17062306a36Sopenharmony_ci */ 17162306a36Sopenharmony_ci CR_ANY_FREE, 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci /* 17462306a36Sopenharmony_ci * Number of criterias defined. 17562306a36Sopenharmony_ci */ 17662306a36Sopenharmony_ci EXT4_MB_NUM_CRS 17762306a36Sopenharmony_ci}; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci/* 18062306a36Sopenharmony_ci * Flags used in mballoc's allocation_context flags field. 18162306a36Sopenharmony_ci * 18262306a36Sopenharmony_ci * Also used to show what's going on for debugging purposes when the 18362306a36Sopenharmony_ci * flag field is exported via the traceport interface 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci/* prefer goal again. length */ 18762306a36Sopenharmony_ci#define EXT4_MB_HINT_MERGE 0x0001 18862306a36Sopenharmony_ci/* blocks already reserved */ 18962306a36Sopenharmony_ci#define EXT4_MB_HINT_RESERVED 0x0002 19062306a36Sopenharmony_ci/* metadata is being allocated */ 19162306a36Sopenharmony_ci#define EXT4_MB_HINT_METADATA 0x0004 19262306a36Sopenharmony_ci/* first blocks in the file */ 19362306a36Sopenharmony_ci#define EXT4_MB_HINT_FIRST 0x0008 19462306a36Sopenharmony_ci/* search for the best chunk */ 19562306a36Sopenharmony_ci#define EXT4_MB_HINT_BEST 0x0010 19662306a36Sopenharmony_ci/* data is being allocated */ 19762306a36Sopenharmony_ci#define EXT4_MB_HINT_DATA 0x0020 19862306a36Sopenharmony_ci/* don't preallocate (for tails) */ 19962306a36Sopenharmony_ci#define EXT4_MB_HINT_NOPREALLOC 0x0040 20062306a36Sopenharmony_ci/* allocate for locality group */ 20162306a36Sopenharmony_ci#define EXT4_MB_HINT_GROUP_ALLOC 0x0080 20262306a36Sopenharmony_ci/* allocate goal blocks or none */ 20362306a36Sopenharmony_ci#define EXT4_MB_HINT_GOAL_ONLY 0x0100 20462306a36Sopenharmony_ci/* goal is meaningful */ 20562306a36Sopenharmony_ci#define EXT4_MB_HINT_TRY_GOAL 0x0200 20662306a36Sopenharmony_ci/* blocks already pre-reserved by delayed allocation */ 20762306a36Sopenharmony_ci#define EXT4_MB_DELALLOC_RESERVED 0x0400 20862306a36Sopenharmony_ci/* We are doing stream allocation */ 20962306a36Sopenharmony_ci#define EXT4_MB_STREAM_ALLOC 0x0800 21062306a36Sopenharmony_ci/* Use reserved root blocks if needed */ 21162306a36Sopenharmony_ci#define EXT4_MB_USE_ROOT_BLOCKS 0x1000 21262306a36Sopenharmony_ci/* Use blocks from reserved pool */ 21362306a36Sopenharmony_ci#define EXT4_MB_USE_RESERVED 0x2000 21462306a36Sopenharmony_ci/* Do strict check for free blocks while retrying block allocation */ 21562306a36Sopenharmony_ci#define EXT4_MB_STRICT_CHECK 0x4000 21662306a36Sopenharmony_ci/* Large fragment size list lookup succeeded at least once for cr = 0 */ 21762306a36Sopenharmony_ci#define EXT4_MB_CR_POWER2_ALIGNED_OPTIMIZED 0x8000 21862306a36Sopenharmony_ci/* Avg fragment size rb tree lookup succeeded at least once for cr = 1 */ 21962306a36Sopenharmony_ci#define EXT4_MB_CR_GOAL_LEN_FAST_OPTIMIZED 0x00010000 22062306a36Sopenharmony_ci/* Avg fragment size rb tree lookup succeeded at least once for cr = 1.5 */ 22162306a36Sopenharmony_ci#define EXT4_MB_CR_BEST_AVAIL_LEN_OPTIMIZED 0x00020000 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_cistruct ext4_allocation_request { 22462306a36Sopenharmony_ci /* target inode for block we're allocating */ 22562306a36Sopenharmony_ci struct inode *inode; 22662306a36Sopenharmony_ci /* how many blocks we want to allocate */ 22762306a36Sopenharmony_ci unsigned int len; 22862306a36Sopenharmony_ci /* logical block in target inode */ 22962306a36Sopenharmony_ci ext4_lblk_t logical; 23062306a36Sopenharmony_ci /* the closest logical allocated block to the left */ 23162306a36Sopenharmony_ci ext4_lblk_t lleft; 23262306a36Sopenharmony_ci /* the closest logical allocated block to the right */ 23362306a36Sopenharmony_ci ext4_lblk_t lright; 23462306a36Sopenharmony_ci /* phys. target (a hint) */ 23562306a36Sopenharmony_ci ext4_fsblk_t goal; 23662306a36Sopenharmony_ci /* phys. block for the closest logical allocated block to the left */ 23762306a36Sopenharmony_ci ext4_fsblk_t pleft; 23862306a36Sopenharmony_ci /* phys. block for the closest logical allocated block to the right */ 23962306a36Sopenharmony_ci ext4_fsblk_t pright; 24062306a36Sopenharmony_ci /* flags. see above EXT4_MB_HINT_* */ 24162306a36Sopenharmony_ci unsigned int flags; 24262306a36Sopenharmony_ci}; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci/* 24562306a36Sopenharmony_ci * Logical to physical block mapping, used by ext4_map_blocks() 24662306a36Sopenharmony_ci * 24762306a36Sopenharmony_ci * This structure is used to pass requests into ext4_map_blocks() as 24862306a36Sopenharmony_ci * well as to store the information returned by ext4_map_blocks(). It 24962306a36Sopenharmony_ci * takes less room on the stack than a struct buffer_head. 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_ci#define EXT4_MAP_NEW BIT(BH_New) 25262306a36Sopenharmony_ci#define EXT4_MAP_MAPPED BIT(BH_Mapped) 25362306a36Sopenharmony_ci#define EXT4_MAP_UNWRITTEN BIT(BH_Unwritten) 25462306a36Sopenharmony_ci#define EXT4_MAP_BOUNDARY BIT(BH_Boundary) 25562306a36Sopenharmony_ci#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ 25662306a36Sopenharmony_ci EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY) 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_cistruct ext4_map_blocks { 25962306a36Sopenharmony_ci ext4_fsblk_t m_pblk; 26062306a36Sopenharmony_ci ext4_lblk_t m_lblk; 26162306a36Sopenharmony_ci unsigned int m_len; 26262306a36Sopenharmony_ci unsigned int m_flags; 26362306a36Sopenharmony_ci}; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci/* 26662306a36Sopenharmony_ci * Block validity checking, system zone rbtree. 26762306a36Sopenharmony_ci */ 26862306a36Sopenharmony_cistruct ext4_system_blocks { 26962306a36Sopenharmony_ci struct rb_root root; 27062306a36Sopenharmony_ci struct rcu_head rcu; 27162306a36Sopenharmony_ci}; 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci/* 27462306a36Sopenharmony_ci * Flags for ext4_io_end->flags 27562306a36Sopenharmony_ci */ 27662306a36Sopenharmony_ci#define EXT4_IO_END_UNWRITTEN 0x0001 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_cistruct ext4_io_end_vec { 27962306a36Sopenharmony_ci struct list_head list; /* list of io_end_vec */ 28062306a36Sopenharmony_ci loff_t offset; /* offset in the file */ 28162306a36Sopenharmony_ci ssize_t size; /* size of the extent */ 28262306a36Sopenharmony_ci}; 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci/* 28562306a36Sopenharmony_ci * For converting unwritten extents on a work queue. 'handle' is used for 28662306a36Sopenharmony_ci * buffered writeback. 28762306a36Sopenharmony_ci */ 28862306a36Sopenharmony_citypedef struct ext4_io_end { 28962306a36Sopenharmony_ci struct list_head list; /* per-file finished IO list */ 29062306a36Sopenharmony_ci handle_t *handle; /* handle reserved for extent 29162306a36Sopenharmony_ci * conversion */ 29262306a36Sopenharmony_ci struct inode *inode; /* file being written to */ 29362306a36Sopenharmony_ci struct bio *bio; /* Linked list of completed 29462306a36Sopenharmony_ci * bios covering the extent */ 29562306a36Sopenharmony_ci unsigned int flag; /* unwritten or not */ 29662306a36Sopenharmony_ci refcount_t count; /* reference counter */ 29762306a36Sopenharmony_ci struct list_head list_vec; /* list of ext4_io_end_vec */ 29862306a36Sopenharmony_ci} ext4_io_end_t; 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_cistruct ext4_io_submit { 30162306a36Sopenharmony_ci struct writeback_control *io_wbc; 30262306a36Sopenharmony_ci struct bio *io_bio; 30362306a36Sopenharmony_ci ext4_io_end_t *io_end; 30462306a36Sopenharmony_ci sector_t io_next_block; 30562306a36Sopenharmony_ci}; 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci/* 30862306a36Sopenharmony_ci * Special inodes numbers 30962306a36Sopenharmony_ci */ 31062306a36Sopenharmony_ci#define EXT4_BAD_INO 1 /* Bad blocks inode */ 31162306a36Sopenharmony_ci#define EXT4_ROOT_INO 2 /* Root inode */ 31262306a36Sopenharmony_ci#define EXT4_USR_QUOTA_INO 3 /* User quota inode */ 31362306a36Sopenharmony_ci#define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */ 31462306a36Sopenharmony_ci#define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */ 31562306a36Sopenharmony_ci#define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */ 31662306a36Sopenharmony_ci#define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */ 31762306a36Sopenharmony_ci#define EXT4_JOURNAL_INO 8 /* Journal inode */ 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/* First non-reserved inode for old ext4 filesystems */ 32062306a36Sopenharmony_ci#define EXT4_GOOD_OLD_FIRST_INO 11 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci/* 32362306a36Sopenharmony_ci * Maximal count of links to a file 32462306a36Sopenharmony_ci */ 32562306a36Sopenharmony_ci#define EXT4_LINK_MAX 65000 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci/* 32862306a36Sopenharmony_ci * Macro-instructions used to manage several block sizes 32962306a36Sopenharmony_ci */ 33062306a36Sopenharmony_ci#define EXT4_MIN_BLOCK_SIZE 1024 33162306a36Sopenharmony_ci#define EXT4_MAX_BLOCK_SIZE 65536 33262306a36Sopenharmony_ci#define EXT4_MIN_BLOCK_LOG_SIZE 10 33362306a36Sopenharmony_ci#define EXT4_MAX_BLOCK_LOG_SIZE 16 33462306a36Sopenharmony_ci#define EXT4_MAX_CLUSTER_LOG_SIZE 30 33562306a36Sopenharmony_ci#ifdef __KERNEL__ 33662306a36Sopenharmony_ci# define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize) 33762306a36Sopenharmony_ci#else 33862306a36Sopenharmony_ci# define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size) 33962306a36Sopenharmony_ci#endif 34062306a36Sopenharmony_ci#define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32)) 34162306a36Sopenharmony_ci#define EXT4_CLUSTER_SIZE(s) (EXT4_BLOCK_SIZE(s) << \ 34262306a36Sopenharmony_ci EXT4_SB(s)->s_cluster_bits) 34362306a36Sopenharmony_ci#ifdef __KERNEL__ 34462306a36Sopenharmony_ci# define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 34562306a36Sopenharmony_ci# define EXT4_CLUSTER_BITS(s) (EXT4_SB(s)->s_cluster_bits) 34662306a36Sopenharmony_ci#else 34762306a36Sopenharmony_ci# define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 34862306a36Sopenharmony_ci#endif 34962306a36Sopenharmony_ci#ifdef __KERNEL__ 35062306a36Sopenharmony_ci#define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits) 35162306a36Sopenharmony_ci#define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size) 35262306a36Sopenharmony_ci#define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino) 35362306a36Sopenharmony_ci#else 35462306a36Sopenharmony_ci#define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 35562306a36Sopenharmony_ci EXT4_GOOD_OLD_INODE_SIZE : \ 35662306a36Sopenharmony_ci (s)->s_inode_size) 35762306a36Sopenharmony_ci#define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 35862306a36Sopenharmony_ci EXT4_GOOD_OLD_FIRST_INO : \ 35962306a36Sopenharmony_ci (s)->s_first_ino) 36062306a36Sopenharmony_ci#endif 36162306a36Sopenharmony_ci#define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 36262306a36Sopenharmony_ci#define EXT4_MAX_BLOCKS(size, offset, blkbits) \ 36362306a36Sopenharmony_ci ((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \ 36462306a36Sopenharmony_ci blkbits)) 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ci/* Translate a block number to a cluster number */ 36762306a36Sopenharmony_ci#define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) 36862306a36Sopenharmony_ci/* Translate a cluster number to a block number */ 36962306a36Sopenharmony_ci#define EXT4_C2B(sbi, cluster) ((cluster) << (sbi)->s_cluster_bits) 37062306a36Sopenharmony_ci/* Translate # of blks to # of clusters */ 37162306a36Sopenharmony_ci#define EXT4_NUM_B2C(sbi, blks) (((blks) + (sbi)->s_cluster_ratio - 1) >> \ 37262306a36Sopenharmony_ci (sbi)->s_cluster_bits) 37362306a36Sopenharmony_ci/* Mask out the low bits to get the starting block of the cluster */ 37462306a36Sopenharmony_ci#define EXT4_PBLK_CMASK(s, pblk) ((pblk) & \ 37562306a36Sopenharmony_ci ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 37662306a36Sopenharmony_ci#define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \ 37762306a36Sopenharmony_ci ~((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 37862306a36Sopenharmony_ci/* Fill in the low bits to get the last block of the cluster */ 37962306a36Sopenharmony_ci#define EXT4_LBLK_CFILL(sbi, lblk) ((lblk) | \ 38062306a36Sopenharmony_ci ((ext4_lblk_t) (sbi)->s_cluster_ratio - 1)) 38162306a36Sopenharmony_ci/* Get the cluster offset */ 38262306a36Sopenharmony_ci#define EXT4_PBLK_COFF(s, pblk) ((pblk) & \ 38362306a36Sopenharmony_ci ((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 38462306a36Sopenharmony_ci#define EXT4_LBLK_COFF(s, lblk) ((lblk) & \ 38562306a36Sopenharmony_ci ((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci/* 38862306a36Sopenharmony_ci * Structure of a blocks group descriptor 38962306a36Sopenharmony_ci */ 39062306a36Sopenharmony_cistruct ext4_group_desc 39162306a36Sopenharmony_ci{ 39262306a36Sopenharmony_ci __le32 bg_block_bitmap_lo; /* Blocks bitmap block */ 39362306a36Sopenharmony_ci __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */ 39462306a36Sopenharmony_ci __le32 bg_inode_table_lo; /* Inodes table block */ 39562306a36Sopenharmony_ci __le16 bg_free_blocks_count_lo;/* Free blocks count */ 39662306a36Sopenharmony_ci __le16 bg_free_inodes_count_lo;/* Free inodes count */ 39762306a36Sopenharmony_ci __le16 bg_used_dirs_count_lo; /* Directories count */ 39862306a36Sopenharmony_ci __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 39962306a36Sopenharmony_ci __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ 40062306a36Sopenharmony_ci __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */ 40162306a36Sopenharmony_ci __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */ 40262306a36Sopenharmony_ci __le16 bg_itable_unused_lo; /* Unused inodes count */ 40362306a36Sopenharmony_ci __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 40462306a36Sopenharmony_ci __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 40562306a36Sopenharmony_ci __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ 40662306a36Sopenharmony_ci __le32 bg_inode_table_hi; /* Inodes table block MSB */ 40762306a36Sopenharmony_ci __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ 40862306a36Sopenharmony_ci __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 40962306a36Sopenharmony_ci __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 41062306a36Sopenharmony_ci __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 41162306a36Sopenharmony_ci __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ 41262306a36Sopenharmony_ci __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */ 41362306a36Sopenharmony_ci __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */ 41462306a36Sopenharmony_ci __u32 bg_reserved; 41562306a36Sopenharmony_ci}; 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci#define EXT4_BG_INODE_BITMAP_CSUM_HI_END \ 41862306a36Sopenharmony_ci (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \ 41962306a36Sopenharmony_ci sizeof(__le16)) 42062306a36Sopenharmony_ci#define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \ 42162306a36Sopenharmony_ci (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \ 42262306a36Sopenharmony_ci sizeof(__le16)) 42362306a36Sopenharmony_ci 42462306a36Sopenharmony_ci/* 42562306a36Sopenharmony_ci * Structure of a flex block group info 42662306a36Sopenharmony_ci */ 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_cistruct flex_groups { 42962306a36Sopenharmony_ci atomic64_t free_clusters; 43062306a36Sopenharmony_ci atomic_t free_inodes; 43162306a36Sopenharmony_ci atomic_t used_dirs; 43262306a36Sopenharmony_ci}; 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci#define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 43562306a36Sopenharmony_ci#define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 43662306a36Sopenharmony_ci#define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ci/* 43962306a36Sopenharmony_ci * Macro-instructions used to manage group descriptors 44062306a36Sopenharmony_ci */ 44162306a36Sopenharmony_ci#define EXT4_MIN_DESC_SIZE 32 44262306a36Sopenharmony_ci#define EXT4_MIN_DESC_SIZE_64BIT 64 44362306a36Sopenharmony_ci#define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE 44462306a36Sopenharmony_ci#define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size) 44562306a36Sopenharmony_ci#ifdef __KERNEL__ 44662306a36Sopenharmony_ci# define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group) 44762306a36Sopenharmony_ci# define EXT4_CLUSTERS_PER_GROUP(s) (EXT4_SB(s)->s_clusters_per_group) 44862306a36Sopenharmony_ci# define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block) 44962306a36Sopenharmony_ci# define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group) 45062306a36Sopenharmony_ci# define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits) 45162306a36Sopenharmony_ci#else 45262306a36Sopenharmony_ci# define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 45362306a36Sopenharmony_ci# define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s)) 45462306a36Sopenharmony_ci# define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 45562306a36Sopenharmony_ci#endif 45662306a36Sopenharmony_ci 45762306a36Sopenharmony_ci/* 45862306a36Sopenharmony_ci * Constants relative to the data blocks 45962306a36Sopenharmony_ci */ 46062306a36Sopenharmony_ci#define EXT4_NDIR_BLOCKS 12 46162306a36Sopenharmony_ci#define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS 46262306a36Sopenharmony_ci#define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) 46362306a36Sopenharmony_ci#define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) 46462306a36Sopenharmony_ci#define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci/* 46762306a36Sopenharmony_ci * Inode flags 46862306a36Sopenharmony_ci */ 46962306a36Sopenharmony_ci#define EXT4_SECRM_FL 0x00000001 /* Secure deletion */ 47062306a36Sopenharmony_ci#define EXT4_UNRM_FL 0x00000002 /* Undelete */ 47162306a36Sopenharmony_ci#define EXT4_COMPR_FL 0x00000004 /* Compress file */ 47262306a36Sopenharmony_ci#define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */ 47362306a36Sopenharmony_ci#define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */ 47462306a36Sopenharmony_ci#define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */ 47562306a36Sopenharmony_ci#define EXT4_NODUMP_FL 0x00000040 /* do not dump file */ 47662306a36Sopenharmony_ci#define EXT4_NOATIME_FL 0x00000080 /* do not update atime */ 47762306a36Sopenharmony_ci/* Reserved for compression usage... */ 47862306a36Sopenharmony_ci#define EXT4_DIRTY_FL 0x00000100 47962306a36Sopenharmony_ci#define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 48062306a36Sopenharmony_ci#define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */ 48162306a36Sopenharmony_ci /* nb: was previously EXT2_ECOMPR_FL */ 48262306a36Sopenharmony_ci#define EXT4_ENCRYPT_FL 0x00000800 /* encrypted file */ 48362306a36Sopenharmony_ci/* End compression flags --- maybe not all used */ 48462306a36Sopenharmony_ci#define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */ 48562306a36Sopenharmony_ci#define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */ 48662306a36Sopenharmony_ci#define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 48762306a36Sopenharmony_ci#define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 48862306a36Sopenharmony_ci#define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 48962306a36Sopenharmony_ci#define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 49062306a36Sopenharmony_ci#define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 49162306a36Sopenharmony_ci#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 49262306a36Sopenharmony_ci#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */ 49362306a36Sopenharmony_ci#define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 49462306a36Sopenharmony_ci/* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */ 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci#define EXT4_DAX_FL 0x02000000 /* Inode is DAX */ 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci#define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ 49962306a36Sopenharmony_ci#define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 50062306a36Sopenharmony_ci#define EXT4_CASEFOLD_FL 0x40000000 /* Casefolded directory */ 50162306a36Sopenharmony_ci#define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci/* User modifiable flags */ 50462306a36Sopenharmony_ci#define EXT4_FL_USER_MODIFIABLE (EXT4_SECRM_FL | \ 50562306a36Sopenharmony_ci EXT4_UNRM_FL | \ 50662306a36Sopenharmony_ci EXT4_COMPR_FL | \ 50762306a36Sopenharmony_ci EXT4_SYNC_FL | \ 50862306a36Sopenharmony_ci EXT4_IMMUTABLE_FL | \ 50962306a36Sopenharmony_ci EXT4_APPEND_FL | \ 51062306a36Sopenharmony_ci EXT4_NODUMP_FL | \ 51162306a36Sopenharmony_ci EXT4_NOATIME_FL | \ 51262306a36Sopenharmony_ci EXT4_JOURNAL_DATA_FL | \ 51362306a36Sopenharmony_ci EXT4_NOTAIL_FL | \ 51462306a36Sopenharmony_ci EXT4_DIRSYNC_FL | \ 51562306a36Sopenharmony_ci EXT4_TOPDIR_FL | \ 51662306a36Sopenharmony_ci EXT4_EXTENTS_FL | \ 51762306a36Sopenharmony_ci 0x00400000 /* EXT4_EOFBLOCKS_FL */ | \ 51862306a36Sopenharmony_ci EXT4_DAX_FL | \ 51962306a36Sopenharmony_ci EXT4_PROJINHERIT_FL | \ 52062306a36Sopenharmony_ci EXT4_CASEFOLD_FL) 52162306a36Sopenharmony_ci 52262306a36Sopenharmony_ci/* User visible flags */ 52362306a36Sopenharmony_ci#define EXT4_FL_USER_VISIBLE (EXT4_FL_USER_MODIFIABLE | \ 52462306a36Sopenharmony_ci EXT4_DIRTY_FL | \ 52562306a36Sopenharmony_ci EXT4_COMPRBLK_FL | \ 52662306a36Sopenharmony_ci EXT4_NOCOMPR_FL | \ 52762306a36Sopenharmony_ci EXT4_ENCRYPT_FL | \ 52862306a36Sopenharmony_ci EXT4_INDEX_FL | \ 52962306a36Sopenharmony_ci EXT4_VERITY_FL | \ 53062306a36Sopenharmony_ci EXT4_INLINE_DATA_FL) 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci/* Flags that should be inherited by new inodes from their parent. */ 53362306a36Sopenharmony_ci#define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ 53462306a36Sopenharmony_ci EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ 53562306a36Sopenharmony_ci EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ 53662306a36Sopenharmony_ci EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\ 53762306a36Sopenharmony_ci EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\ 53862306a36Sopenharmony_ci EXT4_DAX_FL) 53962306a36Sopenharmony_ci 54062306a36Sopenharmony_ci/* Flags that are appropriate for regular files (all but dir-specific ones). */ 54162306a36Sopenharmony_ci#define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL |\ 54262306a36Sopenharmony_ci EXT4_PROJINHERIT_FL)) 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci/* Flags that are appropriate for non-directories/regular files. */ 54562306a36Sopenharmony_ci#define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci/* The only flags that should be swapped */ 54862306a36Sopenharmony_ci#define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL) 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci/* Flags which are mutually exclusive to DAX */ 55162306a36Sopenharmony_ci#define EXT4_DAX_MUT_EXCL (EXT4_VERITY_FL | EXT4_ENCRYPT_FL |\ 55262306a36Sopenharmony_ci EXT4_JOURNAL_DATA_FL | EXT4_INLINE_DATA_FL) 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_ci/* Mask out flags that are inappropriate for the given type of inode. */ 55562306a36Sopenharmony_cistatic inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) 55662306a36Sopenharmony_ci{ 55762306a36Sopenharmony_ci if (S_ISDIR(mode)) 55862306a36Sopenharmony_ci return flags; 55962306a36Sopenharmony_ci else if (S_ISREG(mode)) 56062306a36Sopenharmony_ci return flags & EXT4_REG_FLMASK; 56162306a36Sopenharmony_ci else 56262306a36Sopenharmony_ci return flags & EXT4_OTHER_FLMASK; 56362306a36Sopenharmony_ci} 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci/* 56662306a36Sopenharmony_ci * Inode flags used for atomic set/get 56762306a36Sopenharmony_ci */ 56862306a36Sopenharmony_cienum { 56962306a36Sopenharmony_ci EXT4_INODE_SECRM = 0, /* Secure deletion */ 57062306a36Sopenharmony_ci EXT4_INODE_UNRM = 1, /* Undelete */ 57162306a36Sopenharmony_ci EXT4_INODE_COMPR = 2, /* Compress file */ 57262306a36Sopenharmony_ci EXT4_INODE_SYNC = 3, /* Synchronous updates */ 57362306a36Sopenharmony_ci EXT4_INODE_IMMUTABLE = 4, /* Immutable file */ 57462306a36Sopenharmony_ci EXT4_INODE_APPEND = 5, /* writes to file may only append */ 57562306a36Sopenharmony_ci EXT4_INODE_NODUMP = 6, /* do not dump file */ 57662306a36Sopenharmony_ci EXT4_INODE_NOATIME = 7, /* do not update atime */ 57762306a36Sopenharmony_ci/* Reserved for compression usage... */ 57862306a36Sopenharmony_ci EXT4_INODE_DIRTY = 8, 57962306a36Sopenharmony_ci EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */ 58062306a36Sopenharmony_ci EXT4_INODE_NOCOMPR = 10, /* Don't compress */ 58162306a36Sopenharmony_ci EXT4_INODE_ENCRYPT = 11, /* Encrypted file */ 58262306a36Sopenharmony_ci/* End compression flags --- maybe not all used */ 58362306a36Sopenharmony_ci EXT4_INODE_INDEX = 12, /* hash-indexed directory */ 58462306a36Sopenharmony_ci EXT4_INODE_IMAGIC = 13, /* AFS directory */ 58562306a36Sopenharmony_ci EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */ 58662306a36Sopenharmony_ci EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */ 58762306a36Sopenharmony_ci EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */ 58862306a36Sopenharmony_ci EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/ 58962306a36Sopenharmony_ci EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */ 59062306a36Sopenharmony_ci EXT4_INODE_EXTENTS = 19, /* Inode uses extents */ 59162306a36Sopenharmony_ci EXT4_INODE_VERITY = 20, /* Verity protected inode */ 59262306a36Sopenharmony_ci EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */ 59362306a36Sopenharmony_ci/* 22 was formerly EXT4_INODE_EOFBLOCKS */ 59462306a36Sopenharmony_ci EXT4_INODE_DAX = 25, /* Inode is DAX */ 59562306a36Sopenharmony_ci EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */ 59662306a36Sopenharmony_ci EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */ 59762306a36Sopenharmony_ci EXT4_INODE_CASEFOLD = 30, /* Casefolded directory */ 59862306a36Sopenharmony_ci EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ 59962306a36Sopenharmony_ci}; 60062306a36Sopenharmony_ci 60162306a36Sopenharmony_ci/* 60262306a36Sopenharmony_ci * Since it's pretty easy to mix up bit numbers and hex values, we use a 60362306a36Sopenharmony_ci * build-time check to make sure that EXT4_XXX_FL is consistent with respect to 60462306a36Sopenharmony_ci * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost 60562306a36Sopenharmony_ci * any extra space in the compiled kernel image, otherwise, the build will fail. 60662306a36Sopenharmony_ci * It's important that these values are the same, since we are using 60762306a36Sopenharmony_ci * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent 60862306a36Sopenharmony_ci * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk 60962306a36Sopenharmony_ci * values found in ext2, ext3 and ext4 filesystems, and of course the values 61062306a36Sopenharmony_ci * defined in e2fsprogs. 61162306a36Sopenharmony_ci * 61262306a36Sopenharmony_ci * It's not paranoia if the Murphy's Law really *is* out to get you. :-) 61362306a36Sopenharmony_ci */ 61462306a36Sopenharmony_ci#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1U << EXT4_INODE_##FLAG)) 61562306a36Sopenharmony_ci#define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) 61662306a36Sopenharmony_ci 61762306a36Sopenharmony_cistatic inline void ext4_check_flag_values(void) 61862306a36Sopenharmony_ci{ 61962306a36Sopenharmony_ci CHECK_FLAG_VALUE(SECRM); 62062306a36Sopenharmony_ci CHECK_FLAG_VALUE(UNRM); 62162306a36Sopenharmony_ci CHECK_FLAG_VALUE(COMPR); 62262306a36Sopenharmony_ci CHECK_FLAG_VALUE(SYNC); 62362306a36Sopenharmony_ci CHECK_FLAG_VALUE(IMMUTABLE); 62462306a36Sopenharmony_ci CHECK_FLAG_VALUE(APPEND); 62562306a36Sopenharmony_ci CHECK_FLAG_VALUE(NODUMP); 62662306a36Sopenharmony_ci CHECK_FLAG_VALUE(NOATIME); 62762306a36Sopenharmony_ci CHECK_FLAG_VALUE(DIRTY); 62862306a36Sopenharmony_ci CHECK_FLAG_VALUE(COMPRBLK); 62962306a36Sopenharmony_ci CHECK_FLAG_VALUE(NOCOMPR); 63062306a36Sopenharmony_ci CHECK_FLAG_VALUE(ENCRYPT); 63162306a36Sopenharmony_ci CHECK_FLAG_VALUE(INDEX); 63262306a36Sopenharmony_ci CHECK_FLAG_VALUE(IMAGIC); 63362306a36Sopenharmony_ci CHECK_FLAG_VALUE(JOURNAL_DATA); 63462306a36Sopenharmony_ci CHECK_FLAG_VALUE(NOTAIL); 63562306a36Sopenharmony_ci CHECK_FLAG_VALUE(DIRSYNC); 63662306a36Sopenharmony_ci CHECK_FLAG_VALUE(TOPDIR); 63762306a36Sopenharmony_ci CHECK_FLAG_VALUE(HUGE_FILE); 63862306a36Sopenharmony_ci CHECK_FLAG_VALUE(EXTENTS); 63962306a36Sopenharmony_ci CHECK_FLAG_VALUE(VERITY); 64062306a36Sopenharmony_ci CHECK_FLAG_VALUE(EA_INODE); 64162306a36Sopenharmony_ci CHECK_FLAG_VALUE(INLINE_DATA); 64262306a36Sopenharmony_ci CHECK_FLAG_VALUE(PROJINHERIT); 64362306a36Sopenharmony_ci CHECK_FLAG_VALUE(CASEFOLD); 64462306a36Sopenharmony_ci CHECK_FLAG_VALUE(RESERVED); 64562306a36Sopenharmony_ci} 64662306a36Sopenharmony_ci 64762306a36Sopenharmony_ci#if defined(__KERNEL__) && defined(CONFIG_COMPAT) 64862306a36Sopenharmony_cistruct compat_ext4_new_group_input { 64962306a36Sopenharmony_ci u32 group; 65062306a36Sopenharmony_ci compat_u64 block_bitmap; 65162306a36Sopenharmony_ci compat_u64 inode_bitmap; 65262306a36Sopenharmony_ci compat_u64 inode_table; 65362306a36Sopenharmony_ci u32 blocks_count; 65462306a36Sopenharmony_ci u16 reserved_blocks; 65562306a36Sopenharmony_ci u16 unused; 65662306a36Sopenharmony_ci}; 65762306a36Sopenharmony_ci#endif 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ci/* The struct ext4_new_group_input in kernel space, with free_blocks_count */ 66062306a36Sopenharmony_cistruct ext4_new_group_data { 66162306a36Sopenharmony_ci __u32 group; 66262306a36Sopenharmony_ci __u64 block_bitmap; 66362306a36Sopenharmony_ci __u64 inode_bitmap; 66462306a36Sopenharmony_ci __u64 inode_table; 66562306a36Sopenharmony_ci __u32 blocks_count; 66662306a36Sopenharmony_ci __u16 reserved_blocks; 66762306a36Sopenharmony_ci __u16 mdata_blocks; 66862306a36Sopenharmony_ci __u32 free_clusters_count; 66962306a36Sopenharmony_ci}; 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci/* Indexes used to index group tables in ext4_new_group_data */ 67262306a36Sopenharmony_cienum { 67362306a36Sopenharmony_ci BLOCK_BITMAP = 0, /* block bitmap */ 67462306a36Sopenharmony_ci INODE_BITMAP, /* inode bitmap */ 67562306a36Sopenharmony_ci INODE_TABLE, /* inode tables */ 67662306a36Sopenharmony_ci GROUP_TABLE_COUNT, 67762306a36Sopenharmony_ci}; 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ci/* 68062306a36Sopenharmony_ci * Flags used by ext4_map_blocks() 68162306a36Sopenharmony_ci */ 68262306a36Sopenharmony_ci /* Allocate any needed blocks and/or convert an unwritten 68362306a36Sopenharmony_ci extent to be an initialized ext4 */ 68462306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CREATE 0x0001 68562306a36Sopenharmony_ci /* Request the creation of an unwritten extent */ 68662306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002 68762306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\ 68862306a36Sopenharmony_ci EXT4_GET_BLOCKS_CREATE) 68962306a36Sopenharmony_ci /* Caller is from the delayed allocation writeout path 69062306a36Sopenharmony_ci * finally doing the actual allocation of delayed blocks */ 69162306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004 69262306a36Sopenharmony_ci /* caller is from the direct IO path, request to creation of an 69362306a36Sopenharmony_ci unwritten extents if not allocated, split the unwritten 69462306a36Sopenharmony_ci extent if blocks has been preallocated already*/ 69562306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_PRE_IO 0x0008 69662306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CONVERT 0x0010 69762306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\ 69862306a36Sopenharmony_ci EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 69962306a36Sopenharmony_ci /* Convert extent to initialized after IO complete */ 70062306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\ 70162306a36Sopenharmony_ci EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 70262306a36Sopenharmony_ci /* Eventual metadata allocation (due to growing extent tree) 70362306a36Sopenharmony_ci * should not fail, so try to use reserved blocks for that.*/ 70462306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020 70562306a36Sopenharmony_ci /* Don't normalize allocation size (used for fallocate) */ 70662306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040 70762306a36Sopenharmony_ci /* Convert written extents to unwritten */ 70862306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100 70962306a36Sopenharmony_ci /* Write zeros to newly created written extents */ 71062306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_ZERO 0x0200 71162306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CREATE_ZERO (EXT4_GET_BLOCKS_CREATE |\ 71262306a36Sopenharmony_ci EXT4_GET_BLOCKS_ZERO) 71362306a36Sopenharmony_ci /* Caller will submit data before dropping transaction handle. This 71462306a36Sopenharmony_ci * allows jbd2 to avoid submitting data before commit. */ 71562306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400 71662306a36Sopenharmony_ci /* Caller is in the atomic contex, find extent if it has been cached */ 71762306a36Sopenharmony_ci#define EXT4_GET_BLOCKS_CACHED_NOWAIT 0x0800 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci/* 72062306a36Sopenharmony_ci * The bit position of these flags must not overlap with any of the 72162306a36Sopenharmony_ci * EXT4_GET_BLOCKS_*. They are used by ext4_find_extent(), 72262306a36Sopenharmony_ci * read_extent_tree_block(), ext4_split_extent_at(), 72362306a36Sopenharmony_ci * ext4_ext_insert_extent(), and ext4_ext_create_new_leaf(). 72462306a36Sopenharmony_ci * EXT4_EX_NOCACHE is used to indicate that the we shouldn't be 72562306a36Sopenharmony_ci * caching the extents when reading from the extent tree while a 72662306a36Sopenharmony_ci * truncate or punch hole operation is in progress. 72762306a36Sopenharmony_ci */ 72862306a36Sopenharmony_ci#define EXT4_EX_NOCACHE 0x40000000 72962306a36Sopenharmony_ci#define EXT4_EX_FORCE_CACHE 0x20000000 73062306a36Sopenharmony_ci#define EXT4_EX_NOFAIL 0x10000000 73162306a36Sopenharmony_ci 73262306a36Sopenharmony_ci/* 73362306a36Sopenharmony_ci * Flags used by ext4_free_blocks 73462306a36Sopenharmony_ci */ 73562306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_METADATA 0x0001 73662306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_FORGET 0x0002 73762306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_VALIDATED 0x0004 73862306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008 73962306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010 74062306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020 74162306a36Sopenharmony_ci#define EXT4_FREE_BLOCKS_RERESERVE_CLUSTER 0x0040 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_ci#if defined(__KERNEL__) && defined(CONFIG_COMPAT) 74462306a36Sopenharmony_ci/* 74562306a36Sopenharmony_ci * ioctl commands in 32 bit emulation 74662306a36Sopenharmony_ci */ 74762306a36Sopenharmony_ci#define EXT4_IOC32_GETVERSION _IOR('f', 3, int) 74862306a36Sopenharmony_ci#define EXT4_IOC32_SETVERSION _IOW('f', 4, int) 74962306a36Sopenharmony_ci#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int) 75062306a36Sopenharmony_ci#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int) 75162306a36Sopenharmony_ci#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 75262306a36Sopenharmony_ci#define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input) 75362306a36Sopenharmony_ci#define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 75462306a36Sopenharmony_ci#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 75562306a36Sopenharmony_ci#endif 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci/* Max physical block we can address w/o extents */ 75862306a36Sopenharmony_ci#define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_ci/* Max logical block we can support */ 76162306a36Sopenharmony_ci#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFE 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci/* 76462306a36Sopenharmony_ci * Structure of an inode on the disk 76562306a36Sopenharmony_ci */ 76662306a36Sopenharmony_cistruct ext4_inode { 76762306a36Sopenharmony_ci __le16 i_mode; /* File mode */ 76862306a36Sopenharmony_ci __le16 i_uid; /* Low 16 bits of Owner Uid */ 76962306a36Sopenharmony_ci __le32 i_size_lo; /* Size in bytes */ 77062306a36Sopenharmony_ci __le32 i_atime; /* Access time */ 77162306a36Sopenharmony_ci __le32 i_ctime; /* Inode Change time */ 77262306a36Sopenharmony_ci __le32 i_mtime; /* Modification time */ 77362306a36Sopenharmony_ci __le32 i_dtime; /* Deletion Time */ 77462306a36Sopenharmony_ci __le16 i_gid; /* Low 16 bits of Group Id */ 77562306a36Sopenharmony_ci __le16 i_links_count; /* Links count */ 77662306a36Sopenharmony_ci __le32 i_blocks_lo; /* Blocks count */ 77762306a36Sopenharmony_ci __le32 i_flags; /* File flags */ 77862306a36Sopenharmony_ci union { 77962306a36Sopenharmony_ci struct { 78062306a36Sopenharmony_ci __le32 l_i_version; 78162306a36Sopenharmony_ci } linux1; 78262306a36Sopenharmony_ci struct { 78362306a36Sopenharmony_ci __u32 h_i_translator; 78462306a36Sopenharmony_ci } hurd1; 78562306a36Sopenharmony_ci struct { 78662306a36Sopenharmony_ci __u32 m_i_reserved1; 78762306a36Sopenharmony_ci } masix1; 78862306a36Sopenharmony_ci } osd1; /* OS dependent 1 */ 78962306a36Sopenharmony_ci __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ 79062306a36Sopenharmony_ci __le32 i_generation; /* File version (for NFS) */ 79162306a36Sopenharmony_ci __le32 i_file_acl_lo; /* File ACL */ 79262306a36Sopenharmony_ci __le32 i_size_high; 79362306a36Sopenharmony_ci __le32 i_obso_faddr; /* Obsoleted fragment address */ 79462306a36Sopenharmony_ci union { 79562306a36Sopenharmony_ci struct { 79662306a36Sopenharmony_ci __le16 l_i_blocks_high; /* were l_i_reserved1 */ 79762306a36Sopenharmony_ci __le16 l_i_file_acl_high; 79862306a36Sopenharmony_ci __le16 l_i_uid_high; /* these 2 fields */ 79962306a36Sopenharmony_ci __le16 l_i_gid_high; /* were reserved2[0] */ 80062306a36Sopenharmony_ci __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */ 80162306a36Sopenharmony_ci __le16 l_i_reserved; 80262306a36Sopenharmony_ci } linux2; 80362306a36Sopenharmony_ci struct { 80462306a36Sopenharmony_ci __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 80562306a36Sopenharmony_ci __u16 h_i_mode_high; 80662306a36Sopenharmony_ci __u16 h_i_uid_high; 80762306a36Sopenharmony_ci __u16 h_i_gid_high; 80862306a36Sopenharmony_ci __u32 h_i_author; 80962306a36Sopenharmony_ci } hurd2; 81062306a36Sopenharmony_ci struct { 81162306a36Sopenharmony_ci __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 81262306a36Sopenharmony_ci __le16 m_i_file_acl_high; 81362306a36Sopenharmony_ci __u32 m_i_reserved2[2]; 81462306a36Sopenharmony_ci } masix2; 81562306a36Sopenharmony_ci } osd2; /* OS dependent 2 */ 81662306a36Sopenharmony_ci __le16 i_extra_isize; 81762306a36Sopenharmony_ci __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ 81862306a36Sopenharmony_ci __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 81962306a36Sopenharmony_ci __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 82062306a36Sopenharmony_ci __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 82162306a36Sopenharmony_ci __le32 i_crtime; /* File Creation time */ 82262306a36Sopenharmony_ci __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 82362306a36Sopenharmony_ci __le32 i_version_hi; /* high 32 bits for 64-bit version */ 82462306a36Sopenharmony_ci __le32 i_projid; /* Project ID */ 82562306a36Sopenharmony_ci}; 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ci#define EXT4_EPOCH_BITS 2 82862306a36Sopenharmony_ci#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) 82962306a36Sopenharmony_ci#define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci/* 83262306a36Sopenharmony_ci * Extended fields will fit into an inode if the filesystem was formatted 83362306a36Sopenharmony_ci * with large inodes (-I 256 or larger) and there are not currently any EAs 83462306a36Sopenharmony_ci * consuming all of the available space. For new inodes we always reserve 83562306a36Sopenharmony_ci * enough space for the kernel's known extended fields, but for inodes 83662306a36Sopenharmony_ci * created with an old kernel this might not have been the case. None of 83762306a36Sopenharmony_ci * the extended inode fields is critical for correct filesystem operation. 83862306a36Sopenharmony_ci * This macro checks if a certain field fits in the inode. Note that 83962306a36Sopenharmony_ci * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize 84062306a36Sopenharmony_ci */ 84162306a36Sopenharmony_ci#define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \ 84262306a36Sopenharmony_ci ((offsetof(typeof(*ext4_inode), field) + \ 84362306a36Sopenharmony_ci sizeof((ext4_inode)->field)) \ 84462306a36Sopenharmony_ci <= (EXT4_GOOD_OLD_INODE_SIZE + \ 84562306a36Sopenharmony_ci (einode)->i_extra_isize)) \ 84662306a36Sopenharmony_ci 84762306a36Sopenharmony_ci/* 84862306a36Sopenharmony_ci * We use an encoding that preserves the times for extra epoch "00": 84962306a36Sopenharmony_ci * 85062306a36Sopenharmony_ci * extra msb of adjust for signed 85162306a36Sopenharmony_ci * epoch 32-bit 32-bit tv_sec to 85262306a36Sopenharmony_ci * bits time decoded 64-bit tv_sec 64-bit tv_sec valid time range 85362306a36Sopenharmony_ci * 0 0 1 -0x80000000..-0x00000001 0x000000000 1901-12-13..1969-12-31 85462306a36Sopenharmony_ci * 0 0 0 0x000000000..0x07fffffff 0x000000000 1970-01-01..2038-01-19 85562306a36Sopenharmony_ci * 0 1 1 0x080000000..0x0ffffffff 0x100000000 2038-01-19..2106-02-07 85662306a36Sopenharmony_ci * 0 1 0 0x100000000..0x17fffffff 0x100000000 2106-02-07..2174-02-25 85762306a36Sopenharmony_ci * 1 0 1 0x180000000..0x1ffffffff 0x200000000 2174-02-25..2242-03-16 85862306a36Sopenharmony_ci * 1 0 0 0x200000000..0x27fffffff 0x200000000 2242-03-16..2310-04-04 85962306a36Sopenharmony_ci * 1 1 1 0x280000000..0x2ffffffff 0x300000000 2310-04-04..2378-04-22 86062306a36Sopenharmony_ci * 1 1 0 0x300000000..0x37fffffff 0x300000000 2378-04-22..2446-05-10 86162306a36Sopenharmony_ci * 86262306a36Sopenharmony_ci * Note that previous versions of the kernel on 64-bit systems would 86362306a36Sopenharmony_ci * incorrectly use extra epoch bits 1,1 for dates between 1901 and 86462306a36Sopenharmony_ci * 1970. e2fsck will correct this, assuming that it is run on the 86562306a36Sopenharmony_ci * affected filesystem before 2242. 86662306a36Sopenharmony_ci */ 86762306a36Sopenharmony_ci 86862306a36Sopenharmony_cistatic inline __le32 ext4_encode_extra_time(struct timespec64 ts) 86962306a36Sopenharmony_ci{ 87062306a36Sopenharmony_ci u32 extra = ((ts.tv_sec - (s32)ts.tv_sec) >> 32) & EXT4_EPOCH_MASK; 87162306a36Sopenharmony_ci return cpu_to_le32(extra | (ts.tv_nsec << EXT4_EPOCH_BITS)); 87262306a36Sopenharmony_ci} 87362306a36Sopenharmony_ci 87462306a36Sopenharmony_cistatic inline struct timespec64 ext4_decode_extra_time(__le32 base, 87562306a36Sopenharmony_ci __le32 extra) 87662306a36Sopenharmony_ci{ 87762306a36Sopenharmony_ci struct timespec64 ts = { .tv_sec = (signed)le32_to_cpu(base) }; 87862306a36Sopenharmony_ci 87962306a36Sopenharmony_ci if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) 88062306a36Sopenharmony_ci ts.tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 88162306a36Sopenharmony_ci ts.tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 88262306a36Sopenharmony_ci return ts; 88362306a36Sopenharmony_ci} 88462306a36Sopenharmony_ci 88562306a36Sopenharmony_ci#define EXT4_INODE_SET_XTIME_VAL(xtime, inode, raw_inode, ts) \ 88662306a36Sopenharmony_cido { \ 88762306a36Sopenharmony_ci if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ 88862306a36Sopenharmony_ci (raw_inode)->xtime = cpu_to_le32((ts).tv_sec); \ 88962306a36Sopenharmony_ci (raw_inode)->xtime ## _extra = ext4_encode_extra_time(ts); \ 89062306a36Sopenharmony_ci } else \ 89162306a36Sopenharmony_ci (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (ts).tv_sec, S32_MIN, S32_MAX)); \ 89262306a36Sopenharmony_ci} while (0) 89362306a36Sopenharmony_ci 89462306a36Sopenharmony_ci#define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 89562306a36Sopenharmony_ci EXT4_INODE_SET_XTIME_VAL(xtime, inode, raw_inode, (inode)->xtime) 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ci#define EXT4_INODE_SET_CTIME(inode, raw_inode) \ 89862306a36Sopenharmony_ci EXT4_INODE_SET_XTIME_VAL(i_ctime, inode, raw_inode, inode_get_ctime(inode)) 89962306a36Sopenharmony_ci 90062306a36Sopenharmony_ci#define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 90162306a36Sopenharmony_ci if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 90262306a36Sopenharmony_ci EXT4_INODE_SET_XTIME_VAL(xtime, &((einode)->vfs_inode), \ 90362306a36Sopenharmony_ci raw_inode, (einode)->xtime) 90462306a36Sopenharmony_ci 90562306a36Sopenharmony_ci#define EXT4_INODE_GET_XTIME_VAL(xtime, inode, raw_inode) \ 90662306a36Sopenharmony_ci (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra) ? \ 90762306a36Sopenharmony_ci ext4_decode_extra_time((raw_inode)->xtime, \ 90862306a36Sopenharmony_ci (raw_inode)->xtime ## _extra) : \ 90962306a36Sopenharmony_ci (struct timespec64) { \ 91062306a36Sopenharmony_ci .tv_sec = (signed)le32_to_cpu((raw_inode)->xtime) \ 91162306a36Sopenharmony_ci }) 91262306a36Sopenharmony_ci 91362306a36Sopenharmony_ci#define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 91462306a36Sopenharmony_cido { \ 91562306a36Sopenharmony_ci (inode)->xtime = EXT4_INODE_GET_XTIME_VAL(xtime, inode, raw_inode); \ 91662306a36Sopenharmony_ci} while (0) 91762306a36Sopenharmony_ci 91862306a36Sopenharmony_ci#define EXT4_INODE_GET_CTIME(inode, raw_inode) \ 91962306a36Sopenharmony_cido { \ 92062306a36Sopenharmony_ci inode_set_ctime_to_ts(inode, \ 92162306a36Sopenharmony_ci EXT4_INODE_GET_XTIME_VAL(i_ctime, inode, raw_inode)); \ 92262306a36Sopenharmony_ci} while (0) 92362306a36Sopenharmony_ci 92462306a36Sopenharmony_ci#define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 92562306a36Sopenharmony_cido { \ 92662306a36Sopenharmony_ci if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 92762306a36Sopenharmony_ci (einode)->xtime = \ 92862306a36Sopenharmony_ci EXT4_INODE_GET_XTIME_VAL(xtime, &(einode->vfs_inode), \ 92962306a36Sopenharmony_ci raw_inode); \ 93062306a36Sopenharmony_ci else \ 93162306a36Sopenharmony_ci (einode)->xtime = (struct timespec64){0, 0}; \ 93262306a36Sopenharmony_ci} while (0) 93362306a36Sopenharmony_ci 93462306a36Sopenharmony_ci#define i_disk_version osd1.linux1.l_i_version 93562306a36Sopenharmony_ci 93662306a36Sopenharmony_ci#if defined(__KERNEL__) || defined(__linux__) 93762306a36Sopenharmony_ci#define i_reserved1 osd1.linux1.l_i_reserved1 93862306a36Sopenharmony_ci#define i_file_acl_high osd2.linux2.l_i_file_acl_high 93962306a36Sopenharmony_ci#define i_blocks_high osd2.linux2.l_i_blocks_high 94062306a36Sopenharmony_ci#define i_uid_low i_uid 94162306a36Sopenharmony_ci#define i_gid_low i_gid 94262306a36Sopenharmony_ci#define i_uid_high osd2.linux2.l_i_uid_high 94362306a36Sopenharmony_ci#define i_gid_high osd2.linux2.l_i_gid_high 94462306a36Sopenharmony_ci#define i_checksum_lo osd2.linux2.l_i_checksum_lo 94562306a36Sopenharmony_ci 94662306a36Sopenharmony_ci#elif defined(__GNU__) 94762306a36Sopenharmony_ci 94862306a36Sopenharmony_ci#define i_translator osd1.hurd1.h_i_translator 94962306a36Sopenharmony_ci#define i_uid_high osd2.hurd2.h_i_uid_high 95062306a36Sopenharmony_ci#define i_gid_high osd2.hurd2.h_i_gid_high 95162306a36Sopenharmony_ci#define i_author osd2.hurd2.h_i_author 95262306a36Sopenharmony_ci 95362306a36Sopenharmony_ci#elif defined(__masix__) 95462306a36Sopenharmony_ci 95562306a36Sopenharmony_ci#define i_reserved1 osd1.masix1.m_i_reserved1 95662306a36Sopenharmony_ci#define i_file_acl_high osd2.masix2.m_i_file_acl_high 95762306a36Sopenharmony_ci#define i_reserved2 osd2.masix2.m_i_reserved2 95862306a36Sopenharmony_ci 95962306a36Sopenharmony_ci#endif /* defined(__KERNEL__) || defined(__linux__) */ 96062306a36Sopenharmony_ci 96162306a36Sopenharmony_ci#include "extents_status.h" 96262306a36Sopenharmony_ci#include "fast_commit.h" 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_ci/* 96562306a36Sopenharmony_ci * Lock subclasses for i_data_sem in the ext4_inode_info structure. 96662306a36Sopenharmony_ci * 96762306a36Sopenharmony_ci * These are needed to avoid lockdep false positives when we need to 96862306a36Sopenharmony_ci * allocate blocks to the quota inode during ext4_map_blocks(), while 96962306a36Sopenharmony_ci * holding i_data_sem for a normal (non-quota) inode. Since we don't 97062306a36Sopenharmony_ci * do quota tracking for the quota inode, this avoids deadlock (as 97162306a36Sopenharmony_ci * well as infinite recursion, since it isn't turtles all the way 97262306a36Sopenharmony_ci * down...) 97362306a36Sopenharmony_ci * 97462306a36Sopenharmony_ci * I_DATA_SEM_NORMAL - Used for most inodes 97562306a36Sopenharmony_ci * I_DATA_SEM_OTHER - Used by move_inode.c for the second normal inode 97662306a36Sopenharmony_ci * where the second inode has larger inode number 97762306a36Sopenharmony_ci * than the first 97862306a36Sopenharmony_ci * I_DATA_SEM_QUOTA - Used for quota inodes only 97962306a36Sopenharmony_ci * I_DATA_SEM_EA - Used for ea_inodes only 98062306a36Sopenharmony_ci */ 98162306a36Sopenharmony_cienum { 98262306a36Sopenharmony_ci I_DATA_SEM_NORMAL = 0, 98362306a36Sopenharmony_ci I_DATA_SEM_OTHER, 98462306a36Sopenharmony_ci I_DATA_SEM_QUOTA, 98562306a36Sopenharmony_ci I_DATA_SEM_EA 98662306a36Sopenharmony_ci}; 98762306a36Sopenharmony_ci 98862306a36Sopenharmony_ci 98962306a36Sopenharmony_ci/* 99062306a36Sopenharmony_ci * fourth extended file system inode data in memory 99162306a36Sopenharmony_ci */ 99262306a36Sopenharmony_cistruct ext4_inode_info { 99362306a36Sopenharmony_ci __le32 i_data[15]; /* unconverted */ 99462306a36Sopenharmony_ci __u32 i_dtime; 99562306a36Sopenharmony_ci ext4_fsblk_t i_file_acl; 99662306a36Sopenharmony_ci 99762306a36Sopenharmony_ci /* 99862306a36Sopenharmony_ci * i_block_group is the number of the block group which contains 99962306a36Sopenharmony_ci * this file's inode. Constant across the lifetime of the inode, 100062306a36Sopenharmony_ci * it is used for making block allocation decisions - we try to 100162306a36Sopenharmony_ci * place a file's data blocks near its inode block, and new inodes 100262306a36Sopenharmony_ci * near to their parent directory's inode. 100362306a36Sopenharmony_ci */ 100462306a36Sopenharmony_ci ext4_group_t i_block_group; 100562306a36Sopenharmony_ci ext4_lblk_t i_dir_start_lookup; 100662306a36Sopenharmony_ci#if (BITS_PER_LONG < 64) 100762306a36Sopenharmony_ci unsigned long i_state_flags; /* Dynamic state flags */ 100862306a36Sopenharmony_ci#endif 100962306a36Sopenharmony_ci unsigned long i_flags; 101062306a36Sopenharmony_ci 101162306a36Sopenharmony_ci /* 101262306a36Sopenharmony_ci * Extended attributes can be read independently of the main file 101362306a36Sopenharmony_ci * data. Taking i_rwsem even when reading would cause contention 101462306a36Sopenharmony_ci * between readers of EAs and writers of regular file data, so 101562306a36Sopenharmony_ci * instead we synchronize on xattr_sem when reading or changing 101662306a36Sopenharmony_ci * EAs. 101762306a36Sopenharmony_ci */ 101862306a36Sopenharmony_ci struct rw_semaphore xattr_sem; 101962306a36Sopenharmony_ci 102062306a36Sopenharmony_ci /* 102162306a36Sopenharmony_ci * Inodes with EXT4_STATE_ORPHAN_FILE use i_orphan_idx. Otherwise 102262306a36Sopenharmony_ci * i_orphan is used. 102362306a36Sopenharmony_ci */ 102462306a36Sopenharmony_ci union { 102562306a36Sopenharmony_ci struct list_head i_orphan; /* unlinked but open inodes */ 102662306a36Sopenharmony_ci unsigned int i_orphan_idx; /* Index in orphan file */ 102762306a36Sopenharmony_ci }; 102862306a36Sopenharmony_ci 102962306a36Sopenharmony_ci /* Fast commit related info */ 103062306a36Sopenharmony_ci 103162306a36Sopenharmony_ci /* For tracking dentry create updates */ 103262306a36Sopenharmony_ci struct list_head i_fc_dilist; 103362306a36Sopenharmony_ci struct list_head i_fc_list; /* 103462306a36Sopenharmony_ci * inodes that need fast commit 103562306a36Sopenharmony_ci * protected by sbi->s_fc_lock. 103662306a36Sopenharmony_ci */ 103762306a36Sopenharmony_ci 103862306a36Sopenharmony_ci /* Start of lblk range that needs to be committed in this fast commit */ 103962306a36Sopenharmony_ci ext4_lblk_t i_fc_lblk_start; 104062306a36Sopenharmony_ci 104162306a36Sopenharmony_ci /* End of lblk range that needs to be committed in this fast commit */ 104262306a36Sopenharmony_ci ext4_lblk_t i_fc_lblk_len; 104362306a36Sopenharmony_ci 104462306a36Sopenharmony_ci /* Number of ongoing updates on this inode */ 104562306a36Sopenharmony_ci atomic_t i_fc_updates; 104662306a36Sopenharmony_ci 104762306a36Sopenharmony_ci /* Fast commit wait queue for this inode */ 104862306a36Sopenharmony_ci wait_queue_head_t i_fc_wait; 104962306a36Sopenharmony_ci 105062306a36Sopenharmony_ci /* Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len */ 105162306a36Sopenharmony_ci struct mutex i_fc_lock; 105262306a36Sopenharmony_ci 105362306a36Sopenharmony_ci /* 105462306a36Sopenharmony_ci * i_disksize keeps track of what the inode size is ON DISK, not 105562306a36Sopenharmony_ci * in memory. During truncate, i_size is set to the new size by 105662306a36Sopenharmony_ci * the VFS prior to calling ext4_truncate(), but the filesystem won't 105762306a36Sopenharmony_ci * set i_disksize to 0 until the truncate is actually under way. 105862306a36Sopenharmony_ci * 105962306a36Sopenharmony_ci * The intent is that i_disksize always represents the blocks which 106062306a36Sopenharmony_ci * are used by this file. This allows recovery to restart truncate 106162306a36Sopenharmony_ci * on orphans if we crash during truncate. We actually write i_disksize 106262306a36Sopenharmony_ci * into the on-disk inode when writing inodes out, instead of i_size. 106362306a36Sopenharmony_ci * 106462306a36Sopenharmony_ci * The only time when i_disksize and i_size may be different is when 106562306a36Sopenharmony_ci * a truncate is in progress. The only things which change i_disksize 106662306a36Sopenharmony_ci * are ext4_get_block (growth) and ext4_truncate (shrinkth). 106762306a36Sopenharmony_ci */ 106862306a36Sopenharmony_ci loff_t i_disksize; 106962306a36Sopenharmony_ci 107062306a36Sopenharmony_ci /* 107162306a36Sopenharmony_ci * i_data_sem is for serialising ext4_truncate() against 107262306a36Sopenharmony_ci * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's 107362306a36Sopenharmony_ci * data tree are chopped off during truncate. We can't do that in 107462306a36Sopenharmony_ci * ext4 because whenever we perform intermediate commits during 107562306a36Sopenharmony_ci * truncate, the inode and all the metadata blocks *must* be in a 107662306a36Sopenharmony_ci * consistent state which allows truncation of the orphans to restart 107762306a36Sopenharmony_ci * during recovery. Hence we must fix the get_block-vs-truncate race 107862306a36Sopenharmony_ci * by other means, so we have i_data_sem. 107962306a36Sopenharmony_ci */ 108062306a36Sopenharmony_ci struct rw_semaphore i_data_sem; 108162306a36Sopenharmony_ci struct inode vfs_inode; 108262306a36Sopenharmony_ci struct jbd2_inode *jinode; 108362306a36Sopenharmony_ci 108462306a36Sopenharmony_ci spinlock_t i_raw_lock; /* protects updates to the raw inode */ 108562306a36Sopenharmony_ci 108662306a36Sopenharmony_ci /* 108762306a36Sopenharmony_ci * File creation time. Its function is same as that of 108862306a36Sopenharmony_ci * struct timespec64 i_{a,c,m}time in the generic inode. 108962306a36Sopenharmony_ci */ 109062306a36Sopenharmony_ci struct timespec64 i_crtime; 109162306a36Sopenharmony_ci 109262306a36Sopenharmony_ci /* mballoc */ 109362306a36Sopenharmony_ci atomic_t i_prealloc_active; 109462306a36Sopenharmony_ci struct rb_root i_prealloc_node; 109562306a36Sopenharmony_ci rwlock_t i_prealloc_lock; 109662306a36Sopenharmony_ci 109762306a36Sopenharmony_ci /* extents status tree */ 109862306a36Sopenharmony_ci struct ext4_es_tree i_es_tree; 109962306a36Sopenharmony_ci rwlock_t i_es_lock; 110062306a36Sopenharmony_ci struct list_head i_es_list; 110162306a36Sopenharmony_ci unsigned int i_es_all_nr; /* protected by i_es_lock */ 110262306a36Sopenharmony_ci unsigned int i_es_shk_nr; /* protected by i_es_lock */ 110362306a36Sopenharmony_ci ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for 110462306a36Sopenharmony_ci extents to shrink. Protected by 110562306a36Sopenharmony_ci i_es_lock */ 110662306a36Sopenharmony_ci 110762306a36Sopenharmony_ci /* ialloc */ 110862306a36Sopenharmony_ci ext4_group_t i_last_alloc_group; 110962306a36Sopenharmony_ci 111062306a36Sopenharmony_ci /* allocation reservation info for delalloc */ 111162306a36Sopenharmony_ci /* In case of bigalloc, this refer to clusters rather than blocks */ 111262306a36Sopenharmony_ci unsigned int i_reserved_data_blocks; 111362306a36Sopenharmony_ci 111462306a36Sopenharmony_ci /* pending cluster reservations for bigalloc file systems */ 111562306a36Sopenharmony_ci struct ext4_pending_tree i_pending_tree; 111662306a36Sopenharmony_ci 111762306a36Sopenharmony_ci /* on-disk additional length */ 111862306a36Sopenharmony_ci __u16 i_extra_isize; 111962306a36Sopenharmony_ci 112062306a36Sopenharmony_ci /* Indicate the inline data space. */ 112162306a36Sopenharmony_ci u16 i_inline_off; 112262306a36Sopenharmony_ci u16 i_inline_size; 112362306a36Sopenharmony_ci 112462306a36Sopenharmony_ci#ifdef CONFIG_QUOTA 112562306a36Sopenharmony_ci /* quota space reservation, managed internally by quota code */ 112662306a36Sopenharmony_ci qsize_t i_reserved_quota; 112762306a36Sopenharmony_ci#endif 112862306a36Sopenharmony_ci 112962306a36Sopenharmony_ci /* Lock protecting lists below */ 113062306a36Sopenharmony_ci spinlock_t i_completed_io_lock; 113162306a36Sopenharmony_ci /* 113262306a36Sopenharmony_ci * Completed IOs that need unwritten extents handling and have 113362306a36Sopenharmony_ci * transaction reserved 113462306a36Sopenharmony_ci */ 113562306a36Sopenharmony_ci struct list_head i_rsv_conversion_list; 113662306a36Sopenharmony_ci struct work_struct i_rsv_conversion_work; 113762306a36Sopenharmony_ci atomic_t i_unwritten; /* Nr. of inflight conversions pending */ 113862306a36Sopenharmony_ci 113962306a36Sopenharmony_ci spinlock_t i_block_reservation_lock; 114062306a36Sopenharmony_ci 114162306a36Sopenharmony_ci /* 114262306a36Sopenharmony_ci * Transactions that contain inode's metadata needed to complete 114362306a36Sopenharmony_ci * fsync and fdatasync, respectively. 114462306a36Sopenharmony_ci */ 114562306a36Sopenharmony_ci tid_t i_sync_tid; 114662306a36Sopenharmony_ci tid_t i_datasync_tid; 114762306a36Sopenharmony_ci 114862306a36Sopenharmony_ci#ifdef CONFIG_QUOTA 114962306a36Sopenharmony_ci struct dquot __rcu *i_dquot[MAXQUOTAS]; 115062306a36Sopenharmony_ci#endif 115162306a36Sopenharmony_ci 115262306a36Sopenharmony_ci /* Precomputed uuid+inum+igen checksum for seeding inode checksums */ 115362306a36Sopenharmony_ci __u32 i_csum_seed; 115462306a36Sopenharmony_ci 115562306a36Sopenharmony_ci kprojid_t i_projid; 115662306a36Sopenharmony_ci}; 115762306a36Sopenharmony_ci 115862306a36Sopenharmony_ci/* 115962306a36Sopenharmony_ci * File system states 116062306a36Sopenharmony_ci */ 116162306a36Sopenharmony_ci#define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 116262306a36Sopenharmony_ci#define EXT4_ERROR_FS 0x0002 /* Errors detected */ 116362306a36Sopenharmony_ci#define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ 116462306a36Sopenharmony_ci#define EXT4_FC_REPLAY 0x0020 /* Fast commit replay ongoing */ 116562306a36Sopenharmony_ci 116662306a36Sopenharmony_ci/* 116762306a36Sopenharmony_ci * Misc. filesystem flags 116862306a36Sopenharmony_ci */ 116962306a36Sopenharmony_ci#define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ 117062306a36Sopenharmony_ci#define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ 117162306a36Sopenharmony_ci#define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ 117262306a36Sopenharmony_ci 117362306a36Sopenharmony_ci/* 117462306a36Sopenharmony_ci * Mount flags set via mount options or defaults 117562306a36Sopenharmony_ci */ 117662306a36Sopenharmony_ci#define EXT4_MOUNT_NO_MBCACHE 0x00001 /* Do not use mbcache */ 117762306a36Sopenharmony_ci#define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 117862306a36Sopenharmony_ci#define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 117962306a36Sopenharmony_ci#define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 118062306a36Sopenharmony_ci#define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 118162306a36Sopenharmony_ci#define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 118262306a36Sopenharmony_ci#define EXT4_MOUNT_ERRORS_MASK 0x00070 118362306a36Sopenharmony_ci#define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 118462306a36Sopenharmony_ci#define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 118562306a36Sopenharmony_ci#ifdef CONFIG_FS_DAX 118662306a36Sopenharmony_ci#define EXT4_MOUNT_DAX_ALWAYS 0x00200 /* Direct Access */ 118762306a36Sopenharmony_ci#else 118862306a36Sopenharmony_ci#define EXT4_MOUNT_DAX_ALWAYS 0 118962306a36Sopenharmony_ci#endif 119062306a36Sopenharmony_ci#define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 119162306a36Sopenharmony_ci#define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 119262306a36Sopenharmony_ci#define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 119362306a36Sopenharmony_ci#define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 119462306a36Sopenharmony_ci#define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 119562306a36Sopenharmony_ci#define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 119662306a36Sopenharmony_ci#define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 119762306a36Sopenharmony_ci#define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 119862306a36Sopenharmony_ci#define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 119962306a36Sopenharmony_ci#define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 120062306a36Sopenharmony_ci#define EXT4_MOUNT_QUOTA 0x40000 /* Some quota option set */ 120162306a36Sopenharmony_ci#define EXT4_MOUNT_USRQUOTA 0x80000 /* "old" user quota, 120262306a36Sopenharmony_ci * enable enforcement for hidden 120362306a36Sopenharmony_ci * quota files */ 120462306a36Sopenharmony_ci#define EXT4_MOUNT_GRPQUOTA 0x100000 /* "old" group quota, enable 120562306a36Sopenharmony_ci * enforcement for hidden quota 120662306a36Sopenharmony_ci * files */ 120762306a36Sopenharmony_ci#define EXT4_MOUNT_PRJQUOTA 0x200000 /* Enable project quota 120862306a36Sopenharmony_ci * enforcement */ 120962306a36Sopenharmony_ci#define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */ 121062306a36Sopenharmony_ci#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 121162306a36Sopenharmony_ci#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 121262306a36Sopenharmony_ci#define EXT4_MOUNT_WARN_ON_ERROR 0x2000000 /* Trigger WARN_ON on error */ 121362306a36Sopenharmony_ci#define EXT4_MOUNT_NO_PREFETCH_BLOCK_BITMAPS 0x4000000 121462306a36Sopenharmony_ci#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 121562306a36Sopenharmony_ci#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 121662306a36Sopenharmony_ci#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */ 121762306a36Sopenharmony_ci#define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */ 121862306a36Sopenharmony_ci#define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */ 121962306a36Sopenharmony_ci 122062306a36Sopenharmony_ci/* 122162306a36Sopenharmony_ci * Mount flags set either automatically (could not be set by mount option) 122262306a36Sopenharmony_ci * based on per file system feature or property or in special cases such as 122362306a36Sopenharmony_ci * distinguishing between explicit mount option definition and default. 122462306a36Sopenharmony_ci */ 122562306a36Sopenharmony_ci#define EXT4_MOUNT2_EXPLICIT_DELALLOC 0x00000001 /* User explicitly 122662306a36Sopenharmony_ci specified delalloc */ 122762306a36Sopenharmony_ci#define EXT4_MOUNT2_STD_GROUP_SIZE 0x00000002 /* We have standard group 122862306a36Sopenharmony_ci size of blocksize * 8 122962306a36Sopenharmony_ci blocks */ 123062306a36Sopenharmony_ci#define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated 123162306a36Sopenharmony_ci file systems */ 123262306a36Sopenharmony_ci#define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly 123362306a36Sopenharmony_ci specified journal checksum */ 123462306a36Sopenharmony_ci 123562306a36Sopenharmony_ci#define EXT4_MOUNT2_JOURNAL_FAST_COMMIT 0x00000010 /* Journal fast commit */ 123662306a36Sopenharmony_ci#define EXT4_MOUNT2_DAX_NEVER 0x00000020 /* Do not allow Direct Access */ 123762306a36Sopenharmony_ci#define EXT4_MOUNT2_DAX_INODE 0x00000040 /* For printing options only */ 123862306a36Sopenharmony_ci#define EXT4_MOUNT2_MB_OPTIMIZE_SCAN 0x00000080 /* Optimize group 123962306a36Sopenharmony_ci * scanning in mballoc 124062306a36Sopenharmony_ci */ 124162306a36Sopenharmony_ci#define EXT4_MOUNT2_ABORT 0x00000100 /* Abort filesystem */ 124262306a36Sopenharmony_ci 124362306a36Sopenharmony_ci#define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ 124462306a36Sopenharmony_ci ~EXT4_MOUNT_##opt 124562306a36Sopenharmony_ci#define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \ 124662306a36Sopenharmony_ci EXT4_MOUNT_##opt 124762306a36Sopenharmony_ci#define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \ 124862306a36Sopenharmony_ci EXT4_MOUNT_##opt) 124962306a36Sopenharmony_ci 125062306a36Sopenharmony_ci#define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \ 125162306a36Sopenharmony_ci ~EXT4_MOUNT2_##opt 125262306a36Sopenharmony_ci#define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \ 125362306a36Sopenharmony_ci EXT4_MOUNT2_##opt 125462306a36Sopenharmony_ci#define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \ 125562306a36Sopenharmony_ci EXT4_MOUNT2_##opt) 125662306a36Sopenharmony_ci 125762306a36Sopenharmony_ci#define ext4_test_and_set_bit __test_and_set_bit_le 125862306a36Sopenharmony_ci#define ext4_set_bit __set_bit_le 125962306a36Sopenharmony_ci#define ext4_test_and_clear_bit __test_and_clear_bit_le 126062306a36Sopenharmony_ci#define ext4_clear_bit __clear_bit_le 126162306a36Sopenharmony_ci#define ext4_test_bit test_bit_le 126262306a36Sopenharmony_ci#define ext4_find_next_zero_bit find_next_zero_bit_le 126362306a36Sopenharmony_ci#define ext4_find_next_bit find_next_bit_le 126462306a36Sopenharmony_ci 126562306a36Sopenharmony_ciextern void mb_set_bits(void *bm, int cur, int len); 126662306a36Sopenharmony_ci 126762306a36Sopenharmony_ci/* 126862306a36Sopenharmony_ci * Maximal mount counts between two filesystem checks 126962306a36Sopenharmony_ci */ 127062306a36Sopenharmony_ci#define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 127162306a36Sopenharmony_ci#define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 127262306a36Sopenharmony_ci 127362306a36Sopenharmony_ci/* 127462306a36Sopenharmony_ci * Behaviour when detecting errors 127562306a36Sopenharmony_ci */ 127662306a36Sopenharmony_ci#define EXT4_ERRORS_CONTINUE 1 /* Continue execution */ 127762306a36Sopenharmony_ci#define EXT4_ERRORS_RO 2 /* Remount fs read-only */ 127862306a36Sopenharmony_ci#define EXT4_ERRORS_PANIC 3 /* Panic */ 127962306a36Sopenharmony_ci#define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 128062306a36Sopenharmony_ci 128162306a36Sopenharmony_ci/* Metadata checksum algorithm codes */ 128262306a36Sopenharmony_ci#define EXT4_CRC32C_CHKSUM 1 128362306a36Sopenharmony_ci 128462306a36Sopenharmony_ci#define EXT4_LABEL_MAX 16 128562306a36Sopenharmony_ci 128662306a36Sopenharmony_ci/* 128762306a36Sopenharmony_ci * Structure of the super block 128862306a36Sopenharmony_ci */ 128962306a36Sopenharmony_cistruct ext4_super_block { 129062306a36Sopenharmony_ci/*00*/ __le32 s_inodes_count; /* Inodes count */ 129162306a36Sopenharmony_ci __le32 s_blocks_count_lo; /* Blocks count */ 129262306a36Sopenharmony_ci __le32 s_r_blocks_count_lo; /* Reserved blocks count */ 129362306a36Sopenharmony_ci __le32 s_free_blocks_count_lo; /* Free blocks count */ 129462306a36Sopenharmony_ci/*10*/ __le32 s_free_inodes_count; /* Free inodes count */ 129562306a36Sopenharmony_ci __le32 s_first_data_block; /* First Data Block */ 129662306a36Sopenharmony_ci __le32 s_log_block_size; /* Block size */ 129762306a36Sopenharmony_ci __le32 s_log_cluster_size; /* Allocation cluster size */ 129862306a36Sopenharmony_ci/*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ 129962306a36Sopenharmony_ci __le32 s_clusters_per_group; /* # Clusters per group */ 130062306a36Sopenharmony_ci __le32 s_inodes_per_group; /* # Inodes per group */ 130162306a36Sopenharmony_ci __le32 s_mtime; /* Mount time */ 130262306a36Sopenharmony_ci/*30*/ __le32 s_wtime; /* Write time */ 130362306a36Sopenharmony_ci __le16 s_mnt_count; /* Mount count */ 130462306a36Sopenharmony_ci __le16 s_max_mnt_count; /* Maximal mount count */ 130562306a36Sopenharmony_ci __le16 s_magic; /* Magic signature */ 130662306a36Sopenharmony_ci __le16 s_state; /* File system state */ 130762306a36Sopenharmony_ci __le16 s_errors; /* Behaviour when detecting errors */ 130862306a36Sopenharmony_ci __le16 s_minor_rev_level; /* minor revision level */ 130962306a36Sopenharmony_ci/*40*/ __le32 s_lastcheck; /* time of last check */ 131062306a36Sopenharmony_ci __le32 s_checkinterval; /* max. time between checks */ 131162306a36Sopenharmony_ci __le32 s_creator_os; /* OS */ 131262306a36Sopenharmony_ci __le32 s_rev_level; /* Revision level */ 131362306a36Sopenharmony_ci/*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 131462306a36Sopenharmony_ci __le16 s_def_resgid; /* Default gid for reserved blocks */ 131562306a36Sopenharmony_ci /* 131662306a36Sopenharmony_ci * These fields are for EXT4_DYNAMIC_REV superblocks only. 131762306a36Sopenharmony_ci * 131862306a36Sopenharmony_ci * Note: the difference between the compatible feature set and 131962306a36Sopenharmony_ci * the incompatible feature set is that if there is a bit set 132062306a36Sopenharmony_ci * in the incompatible feature set that the kernel doesn't 132162306a36Sopenharmony_ci * know about, it should refuse to mount the filesystem. 132262306a36Sopenharmony_ci * 132362306a36Sopenharmony_ci * e2fsck's requirements are more strict; if it doesn't know 132462306a36Sopenharmony_ci * about a feature in either the compatible or incompatible 132562306a36Sopenharmony_ci * feature set, it must abort and not try to meddle with 132662306a36Sopenharmony_ci * things it doesn't understand... 132762306a36Sopenharmony_ci */ 132862306a36Sopenharmony_ci __le32 s_first_ino; /* First non-reserved inode */ 132962306a36Sopenharmony_ci __le16 s_inode_size; /* size of inode structure */ 133062306a36Sopenharmony_ci __le16 s_block_group_nr; /* block group # of this superblock */ 133162306a36Sopenharmony_ci __le32 s_feature_compat; /* compatible feature set */ 133262306a36Sopenharmony_ci/*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 133362306a36Sopenharmony_ci __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 133462306a36Sopenharmony_ci/*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 133562306a36Sopenharmony_ci/*78*/ char s_volume_name[EXT4_LABEL_MAX]; /* volume name */ 133662306a36Sopenharmony_ci/*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */ 133762306a36Sopenharmony_ci/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 133862306a36Sopenharmony_ci /* 133962306a36Sopenharmony_ci * Performance hints. Directory preallocation should only 134062306a36Sopenharmony_ci * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. 134162306a36Sopenharmony_ci */ 134262306a36Sopenharmony_ci __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 134362306a36Sopenharmony_ci __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 134462306a36Sopenharmony_ci __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 134562306a36Sopenharmony_ci /* 134662306a36Sopenharmony_ci * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. 134762306a36Sopenharmony_ci */ 134862306a36Sopenharmony_ci/*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 134962306a36Sopenharmony_ci/*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 135062306a36Sopenharmony_ci __le32 s_journal_dev; /* device number of journal file */ 135162306a36Sopenharmony_ci __le32 s_last_orphan; /* start of list of inodes to delete */ 135262306a36Sopenharmony_ci __le32 s_hash_seed[4]; /* HTREE hash seed */ 135362306a36Sopenharmony_ci __u8 s_def_hash_version; /* Default hash version to use */ 135462306a36Sopenharmony_ci __u8 s_jnl_backup_type; 135562306a36Sopenharmony_ci __le16 s_desc_size; /* size of group descriptor */ 135662306a36Sopenharmony_ci/*100*/ __le32 s_default_mount_opts; 135762306a36Sopenharmony_ci __le32 s_first_meta_bg; /* First metablock block group */ 135862306a36Sopenharmony_ci __le32 s_mkfs_time; /* When the filesystem was created */ 135962306a36Sopenharmony_ci __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ 136062306a36Sopenharmony_ci /* 64bit support valid if EXT4_FEATURE_INCOMPAT_64BIT */ 136162306a36Sopenharmony_ci/*150*/ __le32 s_blocks_count_hi; /* Blocks count */ 136262306a36Sopenharmony_ci __le32 s_r_blocks_count_hi; /* Reserved blocks count */ 136362306a36Sopenharmony_ci __le32 s_free_blocks_count_hi; /* Free blocks count */ 136462306a36Sopenharmony_ci __le16 s_min_extra_isize; /* All inodes have at least # bytes */ 136562306a36Sopenharmony_ci __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ 136662306a36Sopenharmony_ci __le32 s_flags; /* Miscellaneous flags */ 136762306a36Sopenharmony_ci __le16 s_raid_stride; /* RAID stride */ 136862306a36Sopenharmony_ci __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ 136962306a36Sopenharmony_ci __le64 s_mmp_block; /* Block for multi-mount protection */ 137062306a36Sopenharmony_ci __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 137162306a36Sopenharmony_ci __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 137262306a36Sopenharmony_ci __u8 s_checksum_type; /* metadata checksum algorithm used */ 137362306a36Sopenharmony_ci __u8 s_encryption_level; /* versioning level for encryption */ 137462306a36Sopenharmony_ci __u8 s_reserved_pad; /* Padding to next 32bits */ 137562306a36Sopenharmony_ci __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 137662306a36Sopenharmony_ci __le32 s_snapshot_inum; /* Inode number of active snapshot */ 137762306a36Sopenharmony_ci __le32 s_snapshot_id; /* sequential ID of active snapshot */ 137862306a36Sopenharmony_ci __le64 s_snapshot_r_blocks_count; /* reserved blocks for active 137962306a36Sopenharmony_ci snapshot's future use */ 138062306a36Sopenharmony_ci __le32 s_snapshot_list; /* inode number of the head of the 138162306a36Sopenharmony_ci on-disk snapshot list */ 138262306a36Sopenharmony_ci#define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count) 138362306a36Sopenharmony_ci __le32 s_error_count; /* number of fs errors */ 138462306a36Sopenharmony_ci __le32 s_first_error_time; /* first time an error happened */ 138562306a36Sopenharmony_ci __le32 s_first_error_ino; /* inode involved in first error */ 138662306a36Sopenharmony_ci __le64 s_first_error_block; /* block involved of first error */ 138762306a36Sopenharmony_ci __u8 s_first_error_func[32] __nonstring; /* function where the error happened */ 138862306a36Sopenharmony_ci __le32 s_first_error_line; /* line number where error happened */ 138962306a36Sopenharmony_ci __le32 s_last_error_time; /* most recent time of an error */ 139062306a36Sopenharmony_ci __le32 s_last_error_ino; /* inode involved in last error */ 139162306a36Sopenharmony_ci __le32 s_last_error_line; /* line number where error happened */ 139262306a36Sopenharmony_ci __le64 s_last_error_block; /* block involved of last error */ 139362306a36Sopenharmony_ci __u8 s_last_error_func[32] __nonstring; /* function where the error happened */ 139462306a36Sopenharmony_ci#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts) 139562306a36Sopenharmony_ci __u8 s_mount_opts[64]; 139662306a36Sopenharmony_ci __le32 s_usr_quota_inum; /* inode for tracking user quota */ 139762306a36Sopenharmony_ci __le32 s_grp_quota_inum; /* inode for tracking group quota */ 139862306a36Sopenharmony_ci __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ 139962306a36Sopenharmony_ci __le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */ 140062306a36Sopenharmony_ci __u8 s_encrypt_algos[4]; /* Encryption algorithms in use */ 140162306a36Sopenharmony_ci __u8 s_encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ 140262306a36Sopenharmony_ci __le32 s_lpf_ino; /* Location of the lost+found inode */ 140362306a36Sopenharmony_ci __le32 s_prj_quota_inum; /* inode for tracking project quota */ 140462306a36Sopenharmony_ci __le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */ 140562306a36Sopenharmony_ci __u8 s_wtime_hi; 140662306a36Sopenharmony_ci __u8 s_mtime_hi; 140762306a36Sopenharmony_ci __u8 s_mkfs_time_hi; 140862306a36Sopenharmony_ci __u8 s_lastcheck_hi; 140962306a36Sopenharmony_ci __u8 s_first_error_time_hi; 141062306a36Sopenharmony_ci __u8 s_last_error_time_hi; 141162306a36Sopenharmony_ci __u8 s_first_error_errcode; 141262306a36Sopenharmony_ci __u8 s_last_error_errcode; 141362306a36Sopenharmony_ci __le16 s_encoding; /* Filename charset encoding */ 141462306a36Sopenharmony_ci __le16 s_encoding_flags; /* Filename charset encoding flags */ 141562306a36Sopenharmony_ci __le32 s_orphan_file_inum; /* Inode for tracking orphan inodes */ 141662306a36Sopenharmony_ci __le32 s_reserved[94]; /* Padding to the end of the block */ 141762306a36Sopenharmony_ci __le32 s_checksum; /* crc32c(superblock) */ 141862306a36Sopenharmony_ci}; 141962306a36Sopenharmony_ci 142062306a36Sopenharmony_ci#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) 142162306a36Sopenharmony_ci 142262306a36Sopenharmony_ci#ifdef __KERNEL__ 142362306a36Sopenharmony_ci 142462306a36Sopenharmony_ci/* Number of quota types we support */ 142562306a36Sopenharmony_ci#define EXT4_MAXQUOTAS 3 142662306a36Sopenharmony_ci 142762306a36Sopenharmony_ci#define EXT4_ENC_UTF8_12_1 1 142862306a36Sopenharmony_ci 142962306a36Sopenharmony_ci/* Types of ext4 journal triggers */ 143062306a36Sopenharmony_cienum ext4_journal_trigger_type { 143162306a36Sopenharmony_ci EXT4_JTR_ORPHAN_FILE, 143262306a36Sopenharmony_ci EXT4_JTR_NONE /* This must be the last entry for indexing to work! */ 143362306a36Sopenharmony_ci}; 143462306a36Sopenharmony_ci 143562306a36Sopenharmony_ci#define EXT4_JOURNAL_TRIGGER_COUNT EXT4_JTR_NONE 143662306a36Sopenharmony_ci 143762306a36Sopenharmony_cistruct ext4_journal_trigger { 143862306a36Sopenharmony_ci struct jbd2_buffer_trigger_type tr_triggers; 143962306a36Sopenharmony_ci struct super_block *sb; 144062306a36Sopenharmony_ci}; 144162306a36Sopenharmony_ci 144262306a36Sopenharmony_cistatic inline struct ext4_journal_trigger *EXT4_TRIGGER( 144362306a36Sopenharmony_ci struct jbd2_buffer_trigger_type *trigger) 144462306a36Sopenharmony_ci{ 144562306a36Sopenharmony_ci return container_of(trigger, struct ext4_journal_trigger, tr_triggers); 144662306a36Sopenharmony_ci} 144762306a36Sopenharmony_ci 144862306a36Sopenharmony_ci#define EXT4_ORPHAN_BLOCK_MAGIC 0x0b10ca04 144962306a36Sopenharmony_ci 145062306a36Sopenharmony_ci/* Structure at the tail of orphan block */ 145162306a36Sopenharmony_cistruct ext4_orphan_block_tail { 145262306a36Sopenharmony_ci __le32 ob_magic; 145362306a36Sopenharmony_ci __le32 ob_checksum; 145462306a36Sopenharmony_ci}; 145562306a36Sopenharmony_ci 145662306a36Sopenharmony_cistatic inline int ext4_inodes_per_orphan_block(struct super_block *sb) 145762306a36Sopenharmony_ci{ 145862306a36Sopenharmony_ci return (sb->s_blocksize - sizeof(struct ext4_orphan_block_tail)) / 145962306a36Sopenharmony_ci sizeof(u32); 146062306a36Sopenharmony_ci} 146162306a36Sopenharmony_ci 146262306a36Sopenharmony_cistruct ext4_orphan_block { 146362306a36Sopenharmony_ci atomic_t ob_free_entries; /* Number of free orphan entries in block */ 146462306a36Sopenharmony_ci struct buffer_head *ob_bh; /* Buffer for orphan block */ 146562306a36Sopenharmony_ci}; 146662306a36Sopenharmony_ci 146762306a36Sopenharmony_ci/* 146862306a36Sopenharmony_ci * Info about orphan file. 146962306a36Sopenharmony_ci */ 147062306a36Sopenharmony_cistruct ext4_orphan_info { 147162306a36Sopenharmony_ci int of_blocks; /* Number of orphan blocks in a file */ 147262306a36Sopenharmony_ci __u32 of_csum_seed; /* Checksum seed for orphan file */ 147362306a36Sopenharmony_ci struct ext4_orphan_block *of_binfo; /* Array with info about orphan 147462306a36Sopenharmony_ci * file blocks */ 147562306a36Sopenharmony_ci}; 147662306a36Sopenharmony_ci 147762306a36Sopenharmony_ci/* 147862306a36Sopenharmony_ci * fourth extended-fs super-block data in memory 147962306a36Sopenharmony_ci */ 148062306a36Sopenharmony_cistruct ext4_sb_info { 148162306a36Sopenharmony_ci unsigned long s_desc_size; /* Size of a group descriptor in bytes */ 148262306a36Sopenharmony_ci unsigned long s_inodes_per_block;/* Number of inodes per block */ 148362306a36Sopenharmony_ci unsigned long s_blocks_per_group;/* Number of blocks in a group */ 148462306a36Sopenharmony_ci unsigned long s_clusters_per_group; /* Number of clusters in a group */ 148562306a36Sopenharmony_ci unsigned long s_inodes_per_group;/* Number of inodes in a group */ 148662306a36Sopenharmony_ci unsigned long s_itb_per_group; /* Number of inode table blocks per group */ 148762306a36Sopenharmony_ci unsigned long s_gdb_count; /* Number of group descriptor blocks */ 148862306a36Sopenharmony_ci unsigned long s_desc_per_block; /* Number of group descriptors per block */ 148962306a36Sopenharmony_ci ext4_group_t s_groups_count; /* Number of groups in the fs */ 149062306a36Sopenharmony_ci ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */ 149162306a36Sopenharmony_ci unsigned long s_overhead; /* # of fs overhead clusters */ 149262306a36Sopenharmony_ci unsigned int s_cluster_ratio; /* Number of blocks per cluster */ 149362306a36Sopenharmony_ci unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */ 149462306a36Sopenharmony_ci loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */ 149562306a36Sopenharmony_ci struct buffer_head * s_sbh; /* Buffer containing the super block */ 149662306a36Sopenharmony_ci struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */ 149762306a36Sopenharmony_ci struct buffer_head * __rcu *s_group_desc; 149862306a36Sopenharmony_ci unsigned int s_mount_opt; 149962306a36Sopenharmony_ci unsigned int s_mount_opt2; 150062306a36Sopenharmony_ci unsigned long s_mount_flags; 150162306a36Sopenharmony_ci unsigned int s_def_mount_opt; 150262306a36Sopenharmony_ci unsigned int s_def_mount_opt2; 150362306a36Sopenharmony_ci ext4_fsblk_t s_sb_block; 150462306a36Sopenharmony_ci atomic64_t s_resv_clusters; 150562306a36Sopenharmony_ci kuid_t s_resuid; 150662306a36Sopenharmony_ci kgid_t s_resgid; 150762306a36Sopenharmony_ci unsigned short s_mount_state; 150862306a36Sopenharmony_ci unsigned short s_pad; 150962306a36Sopenharmony_ci int s_addr_per_block_bits; 151062306a36Sopenharmony_ci int s_desc_per_block_bits; 151162306a36Sopenharmony_ci int s_inode_size; 151262306a36Sopenharmony_ci int s_first_ino; 151362306a36Sopenharmony_ci unsigned int s_inode_readahead_blks; 151462306a36Sopenharmony_ci unsigned int s_inode_goal; 151562306a36Sopenharmony_ci u32 s_hash_seed[4]; 151662306a36Sopenharmony_ci int s_def_hash_version; 151762306a36Sopenharmony_ci int s_hash_unsigned; /* 3 if hash should be unsigned, 0 if not */ 151862306a36Sopenharmony_ci struct percpu_counter s_freeclusters_counter; 151962306a36Sopenharmony_ci struct percpu_counter s_freeinodes_counter; 152062306a36Sopenharmony_ci struct percpu_counter s_dirs_counter; 152162306a36Sopenharmony_ci struct percpu_counter s_dirtyclusters_counter; 152262306a36Sopenharmony_ci struct percpu_counter s_sra_exceeded_retry_limit; 152362306a36Sopenharmony_ci struct blockgroup_lock *s_blockgroup_lock; 152462306a36Sopenharmony_ci struct proc_dir_entry *s_proc; 152562306a36Sopenharmony_ci struct kobject s_kobj; 152662306a36Sopenharmony_ci struct completion s_kobj_unregister; 152762306a36Sopenharmony_ci struct super_block *s_sb; 152862306a36Sopenharmony_ci struct buffer_head *s_mmp_bh; 152962306a36Sopenharmony_ci 153062306a36Sopenharmony_ci /* Journaling */ 153162306a36Sopenharmony_ci struct journal_s *s_journal; 153262306a36Sopenharmony_ci unsigned long s_ext4_flags; /* Ext4 superblock flags */ 153362306a36Sopenharmony_ci struct mutex s_orphan_lock; /* Protects on disk list changes */ 153462306a36Sopenharmony_ci struct list_head s_orphan; /* List of orphaned inodes in on disk 153562306a36Sopenharmony_ci list */ 153662306a36Sopenharmony_ci struct ext4_orphan_info s_orphan_info; 153762306a36Sopenharmony_ci unsigned long s_commit_interval; 153862306a36Sopenharmony_ci u32 s_max_batch_time; 153962306a36Sopenharmony_ci u32 s_min_batch_time; 154062306a36Sopenharmony_ci struct block_device *s_journal_bdev; 154162306a36Sopenharmony_ci#ifdef CONFIG_QUOTA 154262306a36Sopenharmony_ci /* Names of quota files with journalled quota */ 154362306a36Sopenharmony_ci char __rcu *s_qf_names[EXT4_MAXQUOTAS]; 154462306a36Sopenharmony_ci int s_jquota_fmt; /* Format of quota to use */ 154562306a36Sopenharmony_ci#endif 154662306a36Sopenharmony_ci unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */ 154762306a36Sopenharmony_ci struct ext4_system_blocks __rcu *s_system_blks; 154862306a36Sopenharmony_ci 154962306a36Sopenharmony_ci#ifdef EXTENTS_STATS 155062306a36Sopenharmony_ci /* ext4 extents stats */ 155162306a36Sopenharmony_ci unsigned long s_ext_min; 155262306a36Sopenharmony_ci unsigned long s_ext_max; 155362306a36Sopenharmony_ci unsigned long s_depth_max; 155462306a36Sopenharmony_ci spinlock_t s_ext_stats_lock; 155562306a36Sopenharmony_ci unsigned long s_ext_blocks; 155662306a36Sopenharmony_ci unsigned long s_ext_extents; 155762306a36Sopenharmony_ci#endif 155862306a36Sopenharmony_ci 155962306a36Sopenharmony_ci /* for buddy allocator */ 156062306a36Sopenharmony_ci struct ext4_group_info ** __rcu *s_group_info; 156162306a36Sopenharmony_ci struct inode *s_buddy_cache; 156262306a36Sopenharmony_ci spinlock_t s_md_lock; 156362306a36Sopenharmony_ci unsigned short *s_mb_offsets; 156462306a36Sopenharmony_ci unsigned int *s_mb_maxs; 156562306a36Sopenharmony_ci unsigned int s_group_info_size; 156662306a36Sopenharmony_ci unsigned int s_mb_free_pending; 156762306a36Sopenharmony_ci struct list_head s_freed_data_list; /* List of blocks to be freed 156862306a36Sopenharmony_ci after commit completed */ 156962306a36Sopenharmony_ci struct list_head s_discard_list; 157062306a36Sopenharmony_ci struct work_struct s_discard_work; 157162306a36Sopenharmony_ci atomic_t s_retry_alloc_pending; 157262306a36Sopenharmony_ci struct list_head *s_mb_avg_fragment_size; 157362306a36Sopenharmony_ci rwlock_t *s_mb_avg_fragment_size_locks; 157462306a36Sopenharmony_ci struct list_head *s_mb_largest_free_orders; 157562306a36Sopenharmony_ci rwlock_t *s_mb_largest_free_orders_locks; 157662306a36Sopenharmony_ci 157762306a36Sopenharmony_ci /* tunables */ 157862306a36Sopenharmony_ci unsigned long s_stripe; 157962306a36Sopenharmony_ci unsigned int s_mb_max_linear_groups; 158062306a36Sopenharmony_ci unsigned int s_mb_stream_request; 158162306a36Sopenharmony_ci unsigned int s_mb_max_to_scan; 158262306a36Sopenharmony_ci unsigned int s_mb_min_to_scan; 158362306a36Sopenharmony_ci unsigned int s_mb_stats; 158462306a36Sopenharmony_ci unsigned int s_mb_order2_reqs; 158562306a36Sopenharmony_ci unsigned int s_mb_group_prealloc; 158662306a36Sopenharmony_ci unsigned int s_max_dir_size_kb; 158762306a36Sopenharmony_ci /* where last allocation was done - for stream allocation */ 158862306a36Sopenharmony_ci unsigned long s_mb_last_group; 158962306a36Sopenharmony_ci unsigned long s_mb_last_start; 159062306a36Sopenharmony_ci unsigned int s_mb_prefetch; 159162306a36Sopenharmony_ci unsigned int s_mb_prefetch_limit; 159262306a36Sopenharmony_ci unsigned int s_mb_best_avail_max_trim_order; 159362306a36Sopenharmony_ci 159462306a36Sopenharmony_ci /* stats for buddy allocator */ 159562306a36Sopenharmony_ci atomic_t s_bal_reqs; /* number of reqs with len > 1 */ 159662306a36Sopenharmony_ci atomic_t s_bal_success; /* we found long enough chunks */ 159762306a36Sopenharmony_ci atomic_t s_bal_allocated; /* in blocks */ 159862306a36Sopenharmony_ci atomic_t s_bal_ex_scanned; /* total extents scanned */ 159962306a36Sopenharmony_ci atomic_t s_bal_cX_ex_scanned[EXT4_MB_NUM_CRS]; /* total extents scanned */ 160062306a36Sopenharmony_ci atomic_t s_bal_groups_scanned; /* number of groups scanned */ 160162306a36Sopenharmony_ci atomic_t s_bal_goals; /* goal hits */ 160262306a36Sopenharmony_ci atomic_t s_bal_len_goals; /* len goal hits */ 160362306a36Sopenharmony_ci atomic_t s_bal_breaks; /* too long searches */ 160462306a36Sopenharmony_ci atomic_t s_bal_2orders; /* 2^order hits */ 160562306a36Sopenharmony_ci atomic_t s_bal_p2_aligned_bad_suggestions; 160662306a36Sopenharmony_ci atomic_t s_bal_goal_fast_bad_suggestions; 160762306a36Sopenharmony_ci atomic_t s_bal_best_avail_bad_suggestions; 160862306a36Sopenharmony_ci atomic64_t s_bal_cX_groups_considered[EXT4_MB_NUM_CRS]; 160962306a36Sopenharmony_ci atomic64_t s_bal_cX_hits[EXT4_MB_NUM_CRS]; 161062306a36Sopenharmony_ci atomic64_t s_bal_cX_failed[EXT4_MB_NUM_CRS]; /* cX loop didn't find blocks */ 161162306a36Sopenharmony_ci atomic_t s_mb_buddies_generated; /* number of buddies generated */ 161262306a36Sopenharmony_ci atomic64_t s_mb_generation_time; 161362306a36Sopenharmony_ci atomic_t s_mb_lost_chunks; 161462306a36Sopenharmony_ci atomic_t s_mb_preallocated; 161562306a36Sopenharmony_ci atomic_t s_mb_discarded; 161662306a36Sopenharmony_ci atomic_t s_lock_busy; 161762306a36Sopenharmony_ci 161862306a36Sopenharmony_ci /* locality groups */ 161962306a36Sopenharmony_ci struct ext4_locality_group __percpu *s_locality_groups; 162062306a36Sopenharmony_ci 162162306a36Sopenharmony_ci /* for write statistics */ 162262306a36Sopenharmony_ci unsigned long s_sectors_written_start; 162362306a36Sopenharmony_ci u64 s_kbytes_written; 162462306a36Sopenharmony_ci 162562306a36Sopenharmony_ci /* the size of zero-out chunk */ 162662306a36Sopenharmony_ci unsigned int s_extent_max_zeroout_kb; 162762306a36Sopenharmony_ci 162862306a36Sopenharmony_ci unsigned int s_log_groups_per_flex; 162962306a36Sopenharmony_ci struct flex_groups * __rcu *s_flex_groups; 163062306a36Sopenharmony_ci ext4_group_t s_flex_groups_allocated; 163162306a36Sopenharmony_ci 163262306a36Sopenharmony_ci /* workqueue for reserved extent conversions (buffered io) */ 163362306a36Sopenharmony_ci struct workqueue_struct *rsv_conversion_wq; 163462306a36Sopenharmony_ci 163562306a36Sopenharmony_ci /* timer for periodic error stats printing */ 163662306a36Sopenharmony_ci struct timer_list s_err_report; 163762306a36Sopenharmony_ci 163862306a36Sopenharmony_ci /* Lazy inode table initialization info */ 163962306a36Sopenharmony_ci struct ext4_li_request *s_li_request; 164062306a36Sopenharmony_ci /* Wait multiplier for lazy initialization thread */ 164162306a36Sopenharmony_ci unsigned int s_li_wait_mult; 164262306a36Sopenharmony_ci 164362306a36Sopenharmony_ci /* Kernel thread for multiple mount protection */ 164462306a36Sopenharmony_ci struct task_struct *s_mmp_tsk; 164562306a36Sopenharmony_ci 164662306a36Sopenharmony_ci /* record the last minlen when FITRIM is called. */ 164762306a36Sopenharmony_ci unsigned long s_last_trim_minblks; 164862306a36Sopenharmony_ci 164962306a36Sopenharmony_ci /* Reference to checksum algorithm driver via cryptoapi */ 165062306a36Sopenharmony_ci struct crypto_shash *s_chksum_driver; 165162306a36Sopenharmony_ci 165262306a36Sopenharmony_ci /* Precomputed FS UUID checksum for seeding other checksums */ 165362306a36Sopenharmony_ci __u32 s_csum_seed; 165462306a36Sopenharmony_ci 165562306a36Sopenharmony_ci /* Reclaim extents from extent status tree */ 165662306a36Sopenharmony_ci struct shrinker s_es_shrinker; 165762306a36Sopenharmony_ci struct list_head s_es_list; /* List of inodes with reclaimable extents */ 165862306a36Sopenharmony_ci long s_es_nr_inode; 165962306a36Sopenharmony_ci struct ext4_es_stats s_es_stats; 166062306a36Sopenharmony_ci struct mb_cache *s_ea_block_cache; 166162306a36Sopenharmony_ci struct mb_cache *s_ea_inode_cache; 166262306a36Sopenharmony_ci spinlock_t s_es_lock ____cacheline_aligned_in_smp; 166362306a36Sopenharmony_ci 166462306a36Sopenharmony_ci /* Journal triggers for checksum computation */ 166562306a36Sopenharmony_ci struct ext4_journal_trigger s_journal_triggers[EXT4_JOURNAL_TRIGGER_COUNT]; 166662306a36Sopenharmony_ci 166762306a36Sopenharmony_ci /* Ratelimit ext4 messages. */ 166862306a36Sopenharmony_ci struct ratelimit_state s_err_ratelimit_state; 166962306a36Sopenharmony_ci struct ratelimit_state s_warning_ratelimit_state; 167062306a36Sopenharmony_ci struct ratelimit_state s_msg_ratelimit_state; 167162306a36Sopenharmony_ci atomic_t s_warning_count; 167262306a36Sopenharmony_ci atomic_t s_msg_count; 167362306a36Sopenharmony_ci 167462306a36Sopenharmony_ci /* Encryption policy for '-o test_dummy_encryption' */ 167562306a36Sopenharmony_ci struct fscrypt_dummy_policy s_dummy_enc_policy; 167662306a36Sopenharmony_ci 167762306a36Sopenharmony_ci /* 167862306a36Sopenharmony_ci * Barrier between writepages ops and changing any inode's JOURNAL_DATA 167962306a36Sopenharmony_ci * or EXTENTS flag or between writepages ops and changing DELALLOC or 168062306a36Sopenharmony_ci * DIOREAD_NOLOCK mount options on remount. 168162306a36Sopenharmony_ci */ 168262306a36Sopenharmony_ci struct percpu_rw_semaphore s_writepages_rwsem; 168362306a36Sopenharmony_ci struct dax_device *s_daxdev; 168462306a36Sopenharmony_ci u64 s_dax_part_off; 168562306a36Sopenharmony_ci#ifdef CONFIG_EXT4_DEBUG 168662306a36Sopenharmony_ci unsigned long s_simulate_fail; 168762306a36Sopenharmony_ci#endif 168862306a36Sopenharmony_ci /* Record the errseq of the backing block device */ 168962306a36Sopenharmony_ci errseq_t s_bdev_wb_err; 169062306a36Sopenharmony_ci spinlock_t s_bdev_wb_lock; 169162306a36Sopenharmony_ci 169262306a36Sopenharmony_ci /* Information about errors that happened during this mount */ 169362306a36Sopenharmony_ci spinlock_t s_error_lock; 169462306a36Sopenharmony_ci int s_add_error_count; 169562306a36Sopenharmony_ci int s_first_error_code; 169662306a36Sopenharmony_ci __u32 s_first_error_line; 169762306a36Sopenharmony_ci __u32 s_first_error_ino; 169862306a36Sopenharmony_ci __u64 s_first_error_block; 169962306a36Sopenharmony_ci const char *s_first_error_func; 170062306a36Sopenharmony_ci time64_t s_first_error_time; 170162306a36Sopenharmony_ci int s_last_error_code; 170262306a36Sopenharmony_ci __u32 s_last_error_line; 170362306a36Sopenharmony_ci __u32 s_last_error_ino; 170462306a36Sopenharmony_ci __u64 s_last_error_block; 170562306a36Sopenharmony_ci const char *s_last_error_func; 170662306a36Sopenharmony_ci time64_t s_last_error_time; 170762306a36Sopenharmony_ci /* 170862306a36Sopenharmony_ci * If we are in a context where we cannot update the on-disk 170962306a36Sopenharmony_ci * superblock, we queue the work here. This is used to update 171062306a36Sopenharmony_ci * the error information in the superblock, and for periodic 171162306a36Sopenharmony_ci * updates of the superblock called from the commit callback 171262306a36Sopenharmony_ci * function. 171362306a36Sopenharmony_ci */ 171462306a36Sopenharmony_ci struct work_struct s_sb_upd_work; 171562306a36Sopenharmony_ci 171662306a36Sopenharmony_ci /* Ext4 fast commit sub transaction ID */ 171762306a36Sopenharmony_ci atomic_t s_fc_subtid; 171862306a36Sopenharmony_ci 171962306a36Sopenharmony_ci /* 172062306a36Sopenharmony_ci * After commit starts, the main queue gets locked, and the further 172162306a36Sopenharmony_ci * updates get added in the staging queue. 172262306a36Sopenharmony_ci */ 172362306a36Sopenharmony_ci#define FC_Q_MAIN 0 172462306a36Sopenharmony_ci#define FC_Q_STAGING 1 172562306a36Sopenharmony_ci struct list_head s_fc_q[2]; /* Inodes staged for fast commit 172662306a36Sopenharmony_ci * that have data changes in them. 172762306a36Sopenharmony_ci */ 172862306a36Sopenharmony_ci struct list_head s_fc_dentry_q[2]; /* directory entry updates */ 172962306a36Sopenharmony_ci unsigned int s_fc_bytes; 173062306a36Sopenharmony_ci /* 173162306a36Sopenharmony_ci * Main fast commit lock. This lock protects accesses to the 173262306a36Sopenharmony_ci * following fields: 173362306a36Sopenharmony_ci * ei->i_fc_list, s_fc_dentry_q, s_fc_q, s_fc_bytes, s_fc_bh. 173462306a36Sopenharmony_ci */ 173562306a36Sopenharmony_ci spinlock_t s_fc_lock; 173662306a36Sopenharmony_ci struct buffer_head *s_fc_bh; 173762306a36Sopenharmony_ci struct ext4_fc_stats s_fc_stats; 173862306a36Sopenharmony_ci tid_t s_fc_ineligible_tid; 173962306a36Sopenharmony_ci#ifdef CONFIG_EXT4_DEBUG 174062306a36Sopenharmony_ci int s_fc_debug_max_replay; 174162306a36Sopenharmony_ci#endif 174262306a36Sopenharmony_ci struct ext4_fc_replay_state s_fc_replay_state; 174362306a36Sopenharmony_ci}; 174462306a36Sopenharmony_ci 174562306a36Sopenharmony_cistatic inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 174662306a36Sopenharmony_ci{ 174762306a36Sopenharmony_ci return sb->s_fs_info; 174862306a36Sopenharmony_ci} 174962306a36Sopenharmony_cistatic inline struct ext4_inode_info *EXT4_I(struct inode *inode) 175062306a36Sopenharmony_ci{ 175162306a36Sopenharmony_ci return container_of(inode, struct ext4_inode_info, vfs_inode); 175262306a36Sopenharmony_ci} 175362306a36Sopenharmony_ci 175462306a36Sopenharmony_cistatic inline int ext4_writepages_down_read(struct super_block *sb) 175562306a36Sopenharmony_ci{ 175662306a36Sopenharmony_ci percpu_down_read(&EXT4_SB(sb)->s_writepages_rwsem); 175762306a36Sopenharmony_ci return memalloc_nofs_save(); 175862306a36Sopenharmony_ci} 175962306a36Sopenharmony_ci 176062306a36Sopenharmony_cistatic inline void ext4_writepages_up_read(struct super_block *sb, int ctx) 176162306a36Sopenharmony_ci{ 176262306a36Sopenharmony_ci memalloc_nofs_restore(ctx); 176362306a36Sopenharmony_ci percpu_up_read(&EXT4_SB(sb)->s_writepages_rwsem); 176462306a36Sopenharmony_ci} 176562306a36Sopenharmony_ci 176662306a36Sopenharmony_cistatic inline int ext4_writepages_down_write(struct super_block *sb) 176762306a36Sopenharmony_ci{ 176862306a36Sopenharmony_ci percpu_down_write(&EXT4_SB(sb)->s_writepages_rwsem); 176962306a36Sopenharmony_ci return memalloc_nofs_save(); 177062306a36Sopenharmony_ci} 177162306a36Sopenharmony_ci 177262306a36Sopenharmony_cistatic inline void ext4_writepages_up_write(struct super_block *sb, int ctx) 177362306a36Sopenharmony_ci{ 177462306a36Sopenharmony_ci memalloc_nofs_restore(ctx); 177562306a36Sopenharmony_ci percpu_up_write(&EXT4_SB(sb)->s_writepages_rwsem); 177662306a36Sopenharmony_ci} 177762306a36Sopenharmony_ci 177862306a36Sopenharmony_cistatic inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 177962306a36Sopenharmony_ci{ 178062306a36Sopenharmony_ci return ino == EXT4_ROOT_INO || 178162306a36Sopenharmony_ci (ino >= EXT4_FIRST_INO(sb) && 178262306a36Sopenharmony_ci ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 178362306a36Sopenharmony_ci} 178462306a36Sopenharmony_ci 178562306a36Sopenharmony_ci/* 178662306a36Sopenharmony_ci * Returns: sbi->field[index] 178762306a36Sopenharmony_ci * Used to access an array element from the following sbi fields which require 178862306a36Sopenharmony_ci * rcu protection to avoid dereferencing an invalid pointer due to reassignment 178962306a36Sopenharmony_ci * - s_group_desc 179062306a36Sopenharmony_ci * - s_group_info 179162306a36Sopenharmony_ci * - s_flex_group 179262306a36Sopenharmony_ci */ 179362306a36Sopenharmony_ci#define sbi_array_rcu_deref(sbi, field, index) \ 179462306a36Sopenharmony_ci({ \ 179562306a36Sopenharmony_ci typeof(*((sbi)->field)) _v; \ 179662306a36Sopenharmony_ci rcu_read_lock(); \ 179762306a36Sopenharmony_ci _v = ((typeof(_v)*)rcu_dereference((sbi)->field))[index]; \ 179862306a36Sopenharmony_ci rcu_read_unlock(); \ 179962306a36Sopenharmony_ci _v; \ 180062306a36Sopenharmony_ci}) 180162306a36Sopenharmony_ci 180262306a36Sopenharmony_ci/* 180362306a36Sopenharmony_ci * run-time mount flags 180462306a36Sopenharmony_ci */ 180562306a36Sopenharmony_cienum { 180662306a36Sopenharmony_ci EXT4_MF_MNTDIR_SAMPLED, 180762306a36Sopenharmony_ci EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */ 180862306a36Sopenharmony_ci}; 180962306a36Sopenharmony_ci 181062306a36Sopenharmony_cistatic inline void ext4_set_mount_flag(struct super_block *sb, int bit) 181162306a36Sopenharmony_ci{ 181262306a36Sopenharmony_ci set_bit(bit, &EXT4_SB(sb)->s_mount_flags); 181362306a36Sopenharmony_ci} 181462306a36Sopenharmony_ci 181562306a36Sopenharmony_cistatic inline void ext4_clear_mount_flag(struct super_block *sb, int bit) 181662306a36Sopenharmony_ci{ 181762306a36Sopenharmony_ci clear_bit(bit, &EXT4_SB(sb)->s_mount_flags); 181862306a36Sopenharmony_ci} 181962306a36Sopenharmony_ci 182062306a36Sopenharmony_cistatic inline int ext4_test_mount_flag(struct super_block *sb, int bit) 182162306a36Sopenharmony_ci{ 182262306a36Sopenharmony_ci return test_bit(bit, &EXT4_SB(sb)->s_mount_flags); 182362306a36Sopenharmony_ci} 182462306a36Sopenharmony_ci 182562306a36Sopenharmony_ci 182662306a36Sopenharmony_ci/* 182762306a36Sopenharmony_ci * Simulate_fail codes 182862306a36Sopenharmony_ci */ 182962306a36Sopenharmony_ci#define EXT4_SIM_BBITMAP_EIO 1 183062306a36Sopenharmony_ci#define EXT4_SIM_BBITMAP_CRC 2 183162306a36Sopenharmony_ci#define EXT4_SIM_IBITMAP_EIO 3 183262306a36Sopenharmony_ci#define EXT4_SIM_IBITMAP_CRC 4 183362306a36Sopenharmony_ci#define EXT4_SIM_INODE_EIO 5 183462306a36Sopenharmony_ci#define EXT4_SIM_INODE_CRC 6 183562306a36Sopenharmony_ci#define EXT4_SIM_DIRBLOCK_EIO 7 183662306a36Sopenharmony_ci#define EXT4_SIM_DIRBLOCK_CRC 8 183762306a36Sopenharmony_ci 183862306a36Sopenharmony_cistatic inline bool ext4_simulate_fail(struct super_block *sb, 183962306a36Sopenharmony_ci unsigned long code) 184062306a36Sopenharmony_ci{ 184162306a36Sopenharmony_ci#ifdef CONFIG_EXT4_DEBUG 184262306a36Sopenharmony_ci struct ext4_sb_info *sbi = EXT4_SB(sb); 184362306a36Sopenharmony_ci 184462306a36Sopenharmony_ci if (unlikely(sbi->s_simulate_fail == code)) { 184562306a36Sopenharmony_ci sbi->s_simulate_fail = 0; 184662306a36Sopenharmony_ci return true; 184762306a36Sopenharmony_ci } 184862306a36Sopenharmony_ci#endif 184962306a36Sopenharmony_ci return false; 185062306a36Sopenharmony_ci} 185162306a36Sopenharmony_ci 185262306a36Sopenharmony_cistatic inline void ext4_simulate_fail_bh(struct super_block *sb, 185362306a36Sopenharmony_ci struct buffer_head *bh, 185462306a36Sopenharmony_ci unsigned long code) 185562306a36Sopenharmony_ci{ 185662306a36Sopenharmony_ci if (!IS_ERR(bh) && ext4_simulate_fail(sb, code)) 185762306a36Sopenharmony_ci clear_buffer_uptodate(bh); 185862306a36Sopenharmony_ci} 185962306a36Sopenharmony_ci 186062306a36Sopenharmony_ci/* 186162306a36Sopenharmony_ci * Error number codes for s_{first,last}_error_errno 186262306a36Sopenharmony_ci * 186362306a36Sopenharmony_ci * Linux errno numbers are architecture specific, so we need to translate 186462306a36Sopenharmony_ci * them into something which is architecture independent. We don't define 186562306a36Sopenharmony_ci * codes for all errno's; just the ones which are most likely to be the cause 186662306a36Sopenharmony_ci * of an ext4_error() call. 186762306a36Sopenharmony_ci */ 186862306a36Sopenharmony_ci#define EXT4_ERR_UNKNOWN 1 186962306a36Sopenharmony_ci#define EXT4_ERR_EIO 2 187062306a36Sopenharmony_ci#define EXT4_ERR_ENOMEM 3 187162306a36Sopenharmony_ci#define EXT4_ERR_EFSBADCRC 4 187262306a36Sopenharmony_ci#define EXT4_ERR_EFSCORRUPTED 5 187362306a36Sopenharmony_ci#define EXT4_ERR_ENOSPC 6 187462306a36Sopenharmony_ci#define EXT4_ERR_ENOKEY 7 187562306a36Sopenharmony_ci#define EXT4_ERR_EROFS 8 187662306a36Sopenharmony_ci#define EXT4_ERR_EFBIG 9 187762306a36Sopenharmony_ci#define EXT4_ERR_EEXIST 10 187862306a36Sopenharmony_ci#define EXT4_ERR_ERANGE 11 187962306a36Sopenharmony_ci#define EXT4_ERR_EOVERFLOW 12 188062306a36Sopenharmony_ci#define EXT4_ERR_EBUSY 13 188162306a36Sopenharmony_ci#define EXT4_ERR_ENOTDIR 14 188262306a36Sopenharmony_ci#define EXT4_ERR_ENOTEMPTY 15 188362306a36Sopenharmony_ci#define EXT4_ERR_ESHUTDOWN 16 188462306a36Sopenharmony_ci#define EXT4_ERR_EFAULT 17 188562306a36Sopenharmony_ci 188662306a36Sopenharmony_ci/* 188762306a36Sopenharmony_ci * Inode dynamic state flags 188862306a36Sopenharmony_ci */ 188962306a36Sopenharmony_cienum { 189062306a36Sopenharmony_ci EXT4_STATE_NEW, /* inode is newly created */ 189162306a36Sopenharmony_ci EXT4_STATE_XATTR, /* has in-inode xattrs */ 189262306a36Sopenharmony_ci EXT4_STATE_NO_EXPAND, /* No space for expansion */ 189362306a36Sopenharmony_ci EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */ 189462306a36Sopenharmony_ci EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */ 189562306a36Sopenharmony_ci EXT4_STATE_NEWENTRY, /* File just added to dir */ 189662306a36Sopenharmony_ci EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ 189762306a36Sopenharmony_ci EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ 189862306a36Sopenharmony_ci EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ 189962306a36Sopenharmony_ci EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 190062306a36Sopenharmony_ci EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */ 190162306a36Sopenharmony_ci EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */ 190262306a36Sopenharmony_ci}; 190362306a36Sopenharmony_ci 190462306a36Sopenharmony_ci#define EXT4_INODE_BIT_FNS(name, field, offset) \ 190562306a36Sopenharmony_cistatic inline int ext4_test_inode_##name(struct inode *inode, int bit) \ 190662306a36Sopenharmony_ci{ \ 190762306a36Sopenharmony_ci return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 190862306a36Sopenharmony_ci} \ 190962306a36Sopenharmony_cistatic inline void ext4_set_inode_##name(struct inode *inode, int bit) \ 191062306a36Sopenharmony_ci{ \ 191162306a36Sopenharmony_ci set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 191262306a36Sopenharmony_ci} \ 191362306a36Sopenharmony_cistatic inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ 191462306a36Sopenharmony_ci{ \ 191562306a36Sopenharmony_ci clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 191662306a36Sopenharmony_ci} 191762306a36Sopenharmony_ci 191862306a36Sopenharmony_ci/* Add these declarations here only so that these functions can be 191962306a36Sopenharmony_ci * found by name. Otherwise, they are very hard to locate. */ 192062306a36Sopenharmony_cistatic inline int ext4_test_inode_flag(struct inode *inode, int bit); 192162306a36Sopenharmony_cistatic inline void ext4_set_inode_flag(struct inode *inode, int bit); 192262306a36Sopenharmony_cistatic inline void ext4_clear_inode_flag(struct inode *inode, int bit); 192362306a36Sopenharmony_ciEXT4_INODE_BIT_FNS(flag, flags, 0) 192462306a36Sopenharmony_ci 192562306a36Sopenharmony_ci/* Add these declarations here only so that these functions can be 192662306a36Sopenharmony_ci * found by name. Otherwise, they are very hard to locate. */ 192762306a36Sopenharmony_cistatic inline int ext4_test_inode_state(struct inode *inode, int bit); 192862306a36Sopenharmony_cistatic inline void ext4_set_inode_state(struct inode *inode, int bit); 192962306a36Sopenharmony_cistatic inline void ext4_clear_inode_state(struct inode *inode, int bit); 193062306a36Sopenharmony_ci#if (BITS_PER_LONG < 64) 193162306a36Sopenharmony_ciEXT4_INODE_BIT_FNS(state, state_flags, 0) 193262306a36Sopenharmony_ci 193362306a36Sopenharmony_cistatic inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 193462306a36Sopenharmony_ci{ 193562306a36Sopenharmony_ci (ei)->i_state_flags = 0; 193662306a36Sopenharmony_ci} 193762306a36Sopenharmony_ci#else 193862306a36Sopenharmony_ciEXT4_INODE_BIT_FNS(state, flags, 32) 193962306a36Sopenharmony_ci 194062306a36Sopenharmony_cistatic inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 194162306a36Sopenharmony_ci{ 194262306a36Sopenharmony_ci /* We depend on the fact that callers will set i_flags */ 194362306a36Sopenharmony_ci} 194462306a36Sopenharmony_ci#endif 194562306a36Sopenharmony_ci#else 194662306a36Sopenharmony_ci/* Assume that user mode programs are passing in an ext4fs superblock, not 194762306a36Sopenharmony_ci * a kernel struct super_block. This will allow us to call the feature-test 194862306a36Sopenharmony_ci * macros from user land. */ 194962306a36Sopenharmony_ci#define EXT4_SB(sb) (sb) 195062306a36Sopenharmony_ci#endif 195162306a36Sopenharmony_ci 195262306a36Sopenharmony_cistatic inline bool ext4_verity_in_progress(struct inode *inode) 195362306a36Sopenharmony_ci{ 195462306a36Sopenharmony_ci return IS_ENABLED(CONFIG_FS_VERITY) && 195562306a36Sopenharmony_ci ext4_test_inode_state(inode, EXT4_STATE_VERITY_IN_PROGRESS); 195662306a36Sopenharmony_ci} 195762306a36Sopenharmony_ci 195862306a36Sopenharmony_ci#define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime 195962306a36Sopenharmony_ci 196062306a36Sopenharmony_ci/* 196162306a36Sopenharmony_ci * Codes for operating systems 196262306a36Sopenharmony_ci */ 196362306a36Sopenharmony_ci#define EXT4_OS_LINUX 0 196462306a36Sopenharmony_ci#define EXT4_OS_HURD 1 196562306a36Sopenharmony_ci#define EXT4_OS_MASIX 2 196662306a36Sopenharmony_ci#define EXT4_OS_FREEBSD 3 196762306a36Sopenharmony_ci#define EXT4_OS_LITES 4 196862306a36Sopenharmony_ci 196962306a36Sopenharmony_ci/* 197062306a36Sopenharmony_ci * Revision levels 197162306a36Sopenharmony_ci */ 197262306a36Sopenharmony_ci#define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */ 197362306a36Sopenharmony_ci#define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 197462306a36Sopenharmony_ci 197562306a36Sopenharmony_ci#define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV 197662306a36Sopenharmony_ci 197762306a36Sopenharmony_ci#define EXT4_GOOD_OLD_INODE_SIZE 128 197862306a36Sopenharmony_ci 197962306a36Sopenharmony_ci#define EXT4_EXTRA_TIMESTAMP_MAX (((s64)1 << 34) - 1 + S32_MIN) 198062306a36Sopenharmony_ci#define EXT4_NON_EXTRA_TIMESTAMP_MAX S32_MAX 198162306a36Sopenharmony_ci#define EXT4_TIMESTAMP_MIN S32_MIN 198262306a36Sopenharmony_ci 198362306a36Sopenharmony_ci/* 198462306a36Sopenharmony_ci * Feature set definitions 198562306a36Sopenharmony_ci */ 198662306a36Sopenharmony_ci 198762306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 198862306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002 198962306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 199062306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008 199162306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010 199262306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 199362306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 199462306a36Sopenharmony_ci/* 199562306a36Sopenharmony_ci * The reason why "FAST_COMMIT" is a compat feature is that, FS becomes 199662306a36Sopenharmony_ci * incompatible only if fast commit blocks are present in the FS. Since we 199762306a36Sopenharmony_ci * clear the journal (and thus the fast commit blocks), we don't mark FS as 199862306a36Sopenharmony_ci * incompatible. We also have a JBD2 incompat feature, which gets set when 199962306a36Sopenharmony_ci * there are fast commit blocks present in the journal. 200062306a36Sopenharmony_ci */ 200162306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_FAST_COMMIT 0x0400 200262306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800 200362306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_ORPHAN_FILE 0x1000 /* Orphan file exists */ 200462306a36Sopenharmony_ci 200562306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 200662306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 200762306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 200862306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 200962306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 201062306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 201162306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 201262306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 201362306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 201462306a36Sopenharmony_ci/* 201562306a36Sopenharmony_ci * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When 201662306a36Sopenharmony_ci * METADATA_CSUM is set, group descriptor checksums use the same algorithm as 201762306a36Sopenharmony_ci * all other data structures' checksums. However, the METADATA_CSUM and 201862306a36Sopenharmony_ci * GDT_CSUM bits are mutually exclusive. 201962306a36Sopenharmony_ci */ 202062306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 202162306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000 202262306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_PROJECT 0x2000 202362306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_VERITY 0x8000 202462306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT 0x10000 /* Orphan file may be 202562306a36Sopenharmony_ci non-empty */ 202662306a36Sopenharmony_ci 202762306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 202862306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 202962306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 203062306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 203162306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010 203262306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ 203362306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 203462306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 203562306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 203662306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */ 203762306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */ 203862306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 203962306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ 204062306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */ 204162306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 204262306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_CASEFOLD 0x20000 204362306a36Sopenharmony_ci 204462306a36Sopenharmony_ciextern void ext4_update_dynamic_rev(struct super_block *sb); 204562306a36Sopenharmony_ci 204662306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \ 204762306a36Sopenharmony_cistatic inline bool ext4_has_feature_##name(struct super_block *sb) \ 204862306a36Sopenharmony_ci{ \ 204962306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 205062306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname)) != 0); \ 205162306a36Sopenharmony_ci} \ 205262306a36Sopenharmony_cistatic inline void ext4_set_feature_##name(struct super_block *sb) \ 205362306a36Sopenharmony_ci{ \ 205462306a36Sopenharmony_ci ext4_update_dynamic_rev(sb); \ 205562306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_compat |= \ 205662306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 205762306a36Sopenharmony_ci} \ 205862306a36Sopenharmony_cistatic inline void ext4_clear_feature_##name(struct super_block *sb) \ 205962306a36Sopenharmony_ci{ \ 206062306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_compat &= \ 206162306a36Sopenharmony_ci ~cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 206262306a36Sopenharmony_ci} 206362306a36Sopenharmony_ci 206462306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_FUNCS(name, flagname) \ 206562306a36Sopenharmony_cistatic inline bool ext4_has_feature_##name(struct super_block *sb) \ 206662306a36Sopenharmony_ci{ \ 206762306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 206862306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname)) != 0); \ 206962306a36Sopenharmony_ci} \ 207062306a36Sopenharmony_cistatic inline void ext4_set_feature_##name(struct super_block *sb) \ 207162306a36Sopenharmony_ci{ \ 207262306a36Sopenharmony_ci ext4_update_dynamic_rev(sb); \ 207362306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_ro_compat |= \ 207462306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 207562306a36Sopenharmony_ci} \ 207662306a36Sopenharmony_cistatic inline void ext4_clear_feature_##name(struct super_block *sb) \ 207762306a36Sopenharmony_ci{ \ 207862306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_ro_compat &= \ 207962306a36Sopenharmony_ci ~cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 208062306a36Sopenharmony_ci} 208162306a36Sopenharmony_ci 208262306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_FUNCS(name, flagname) \ 208362306a36Sopenharmony_cistatic inline bool ext4_has_feature_##name(struct super_block *sb) \ 208462306a36Sopenharmony_ci{ \ 208562306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 208662306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname)) != 0); \ 208762306a36Sopenharmony_ci} \ 208862306a36Sopenharmony_cistatic inline void ext4_set_feature_##name(struct super_block *sb) \ 208962306a36Sopenharmony_ci{ \ 209062306a36Sopenharmony_ci ext4_update_dynamic_rev(sb); \ 209162306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_incompat |= \ 209262306a36Sopenharmony_ci cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 209362306a36Sopenharmony_ci} \ 209462306a36Sopenharmony_cistatic inline void ext4_clear_feature_##name(struct super_block *sb) \ 209562306a36Sopenharmony_ci{ \ 209662306a36Sopenharmony_ci EXT4_SB(sb)->s_es->s_feature_incompat &= \ 209762306a36Sopenharmony_ci ~cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 209862306a36Sopenharmony_ci} 209962306a36Sopenharmony_ci 210062306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(dir_prealloc, DIR_PREALLOC) 210162306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(imagic_inodes, IMAGIC_INODES) 210262306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(journal, HAS_JOURNAL) 210362306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(xattr, EXT_ATTR) 210462306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE) 210562306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX) 210662306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2) 210762306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(fast_commit, FAST_COMMIT) 210862306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(stable_inodes, STABLE_INODES) 210962306a36Sopenharmony_ciEXT4_FEATURE_COMPAT_FUNCS(orphan_file, ORPHAN_FILE) 211062306a36Sopenharmony_ci 211162306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super, SPARSE_SUPER) 211262306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(large_file, LARGE_FILE) 211362306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(btree_dir, BTREE_DIR) 211462306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(huge_file, HUGE_FILE) 211562306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(gdt_csum, GDT_CSUM) 211662306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(dir_nlink, DIR_NLINK) 211762306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(extra_isize, EXTRA_ISIZE) 211862306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(quota, QUOTA) 211962306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(bigalloc, BIGALLOC) 212062306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(metadata_csum, METADATA_CSUM) 212162306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(readonly, READONLY) 212262306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(project, PROJECT) 212362306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(verity, VERITY) 212462306a36Sopenharmony_ciEXT4_FEATURE_RO_COMPAT_FUNCS(orphan_present, ORPHAN_PRESENT) 212562306a36Sopenharmony_ci 212662306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(compression, COMPRESSION) 212762306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(filetype, FILETYPE) 212862306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(journal_needs_recovery, RECOVER) 212962306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(journal_dev, JOURNAL_DEV) 213062306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(meta_bg, META_BG) 213162306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(extents, EXTENTS) 213262306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT) 213362306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(mmp, MMP) 213462306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(flex_bg, FLEX_BG) 213562306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(ea_inode, EA_INODE) 213662306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(dirdata, DIRDATA) 213762306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(csum_seed, CSUM_SEED) 213862306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(largedir, LARGEDIR) 213962306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(inline_data, INLINE_DATA) 214062306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(encrypt, ENCRYPT) 214162306a36Sopenharmony_ciEXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD) 214262306a36Sopenharmony_ci 214362306a36Sopenharmony_ci#define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 214462306a36Sopenharmony_ci#define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 214562306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_META_BG) 214662306a36Sopenharmony_ci#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 214762306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 214862306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 214962306a36Sopenharmony_ci 215062306a36Sopenharmony_ci#define EXT3_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 215162306a36Sopenharmony_ci#define EXT3_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 215262306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_RECOVER| \ 215362306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_META_BG) 215462306a36Sopenharmony_ci#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 215562306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 215662306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 215762306a36Sopenharmony_ci 215862306a36Sopenharmony_ci#define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_EXT_ATTR| \ 215962306a36Sopenharmony_ci EXT4_FEATURE_COMPAT_ORPHAN_FILE) 216062306a36Sopenharmony_ci#define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 216162306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_RECOVER| \ 216262306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_META_BG| \ 216362306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_EXTENTS| \ 216462306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_64BIT| \ 216562306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_FLEX_BG| \ 216662306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_EA_INODE| \ 216762306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_MMP | \ 216862306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ 216962306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_ENCRYPT | \ 217062306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_CASEFOLD | \ 217162306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_CSUM_SEED | \ 217262306a36Sopenharmony_ci EXT4_FEATURE_INCOMPAT_LARGEDIR) 217362306a36Sopenharmony_ci#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 217462306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 217562306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ 217662306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ 217762306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 217862306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 217962306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\ 218062306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_BIGALLOC |\ 218162306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\ 218262306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_QUOTA |\ 218362306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_PROJECT |\ 218462306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_VERITY |\ 218562306a36Sopenharmony_ci EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT) 218662306a36Sopenharmony_ci 218762306a36Sopenharmony_ci#define EXTN_FEATURE_FUNCS(ver) \ 218862306a36Sopenharmony_cistatic inline bool ext4_has_unknown_ext##ver##_compat_features(struct super_block *sb) \ 218962306a36Sopenharmony_ci{ \ 219062306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 219162306a36Sopenharmony_ci cpu_to_le32(~EXT##ver##_FEATURE_COMPAT_SUPP)) != 0); \ 219262306a36Sopenharmony_ci} \ 219362306a36Sopenharmony_cistatic inline bool ext4_has_unknown_ext##ver##_ro_compat_features(struct super_block *sb) \ 219462306a36Sopenharmony_ci{ \ 219562306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 219662306a36Sopenharmony_ci cpu_to_le32(~EXT##ver##_FEATURE_RO_COMPAT_SUPP)) != 0); \ 219762306a36Sopenharmony_ci} \ 219862306a36Sopenharmony_cistatic inline bool ext4_has_unknown_ext##ver##_incompat_features(struct super_block *sb) \ 219962306a36Sopenharmony_ci{ \ 220062306a36Sopenharmony_ci return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 220162306a36Sopenharmony_ci cpu_to_le32(~EXT##ver##_FEATURE_INCOMPAT_SUPP)) != 0); \ 220262306a36Sopenharmony_ci} 220362306a36Sopenharmony_ci 220462306a36Sopenharmony_ciEXTN_FEATURE_FUNCS(2) 220562306a36Sopenharmony_ciEXTN_FEATURE_FUNCS(3) 220662306a36Sopenharmony_ciEXTN_FEATURE_FUNCS(4) 220762306a36Sopenharmony_ci 220862306a36Sopenharmony_cistatic inline bool ext4_has_compat_features(struct super_block *sb) 220962306a36Sopenharmony_ci{ 221062306a36Sopenharmony_ci return (EXT4_SB(sb)->s_es->s_feature_compat != 0); 221162306a36Sopenharmony_ci} 221262306a36Sopenharmony_cistatic inline bool ext4_has_ro_compat_features(struct super_block *sb) 221362306a36Sopenharmony_ci{ 221462306a36Sopenharmony_ci return (EXT4_SB(sb)->s_es->s_feature_ro_compat != 0); 221562306a36Sopenharmony_ci} 221662306a36Sopenharmony_cistatic inline bool ext4_has_incompat_features(struct super_block *sb) 221762306a36Sopenharmony_ci{ 221862306a36Sopenharmony_ci return (EXT4_SB(sb)->s_es->s_feature_incompat != 0); 221962306a36Sopenharmony_ci} 222062306a36Sopenharmony_ci 222162306a36Sopenharmony_ciextern int ext4_feature_set_ok(struct super_block *sb, int readonly); 222262306a36Sopenharmony_ci 222362306a36Sopenharmony_ci/* 222462306a36Sopenharmony_ci * Superblock flags 222562306a36Sopenharmony_ci */ 222662306a36Sopenharmony_ci#define EXT4_FLAGS_RESIZING 0 222762306a36Sopenharmony_ci#define EXT4_FLAGS_SHUTDOWN 1 222862306a36Sopenharmony_ci#define EXT4_FLAGS_BDEV_IS_DAX 2 222962306a36Sopenharmony_ci 223062306a36Sopenharmony_cistatic inline int ext4_forced_shutdown(struct super_block *sb) 223162306a36Sopenharmony_ci{ 223262306a36Sopenharmony_ci return test_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags); 223362306a36Sopenharmony_ci} 223462306a36Sopenharmony_ci 223562306a36Sopenharmony_ci/* 223662306a36Sopenharmony_ci * Default values for user and/or group using reserved blocks 223762306a36Sopenharmony_ci */ 223862306a36Sopenharmony_ci#define EXT4_DEF_RESUID 0 223962306a36Sopenharmony_ci#define EXT4_DEF_RESGID 0 224062306a36Sopenharmony_ci 224162306a36Sopenharmony_ci/* 224262306a36Sopenharmony_ci * Default project ID 224362306a36Sopenharmony_ci */ 224462306a36Sopenharmony_ci#define EXT4_DEF_PROJID 0 224562306a36Sopenharmony_ci 224662306a36Sopenharmony_ci#define EXT4_DEF_INODE_READAHEAD_BLKS 32 224762306a36Sopenharmony_ci 224862306a36Sopenharmony_ci/* 224962306a36Sopenharmony_ci * Default mount options 225062306a36Sopenharmony_ci */ 225162306a36Sopenharmony_ci#define EXT4_DEFM_DEBUG 0x0001 225262306a36Sopenharmony_ci#define EXT4_DEFM_BSDGROUPS 0x0002 225362306a36Sopenharmony_ci#define EXT4_DEFM_XATTR_USER 0x0004 225462306a36Sopenharmony_ci#define EXT4_DEFM_ACL 0x0008 225562306a36Sopenharmony_ci#define EXT4_DEFM_UID16 0x0010 225662306a36Sopenharmony_ci#define EXT4_DEFM_JMODE 0x0060 225762306a36Sopenharmony_ci#define EXT4_DEFM_JMODE_DATA 0x0020 225862306a36Sopenharmony_ci#define EXT4_DEFM_JMODE_ORDERED 0x0040 225962306a36Sopenharmony_ci#define EXT4_DEFM_JMODE_WBACK 0x0060 226062306a36Sopenharmony_ci#define EXT4_DEFM_NOBARRIER 0x0100 226162306a36Sopenharmony_ci#define EXT4_DEFM_BLOCK_VALIDITY 0x0200 226262306a36Sopenharmony_ci#define EXT4_DEFM_DISCARD 0x0400 226362306a36Sopenharmony_ci#define EXT4_DEFM_NODELALLOC 0x0800 226462306a36Sopenharmony_ci 226562306a36Sopenharmony_ci/* 226662306a36Sopenharmony_ci * Default journal batch times 226762306a36Sopenharmony_ci */ 226862306a36Sopenharmony_ci#define EXT4_DEF_MIN_BATCH_TIME 0 226962306a36Sopenharmony_ci#define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ 227062306a36Sopenharmony_ci 227162306a36Sopenharmony_ci/* 227262306a36Sopenharmony_ci * Minimum number of groups in a flexgroup before we separate out 227362306a36Sopenharmony_ci * directories into the first block group of a flexgroup 227462306a36Sopenharmony_ci */ 227562306a36Sopenharmony_ci#define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4 227662306a36Sopenharmony_ci 227762306a36Sopenharmony_ci/* 227862306a36Sopenharmony_ci * Structure of a directory entry 227962306a36Sopenharmony_ci */ 228062306a36Sopenharmony_ci#define EXT4_NAME_LEN 255 228162306a36Sopenharmony_ci/* 228262306a36Sopenharmony_ci * Base length of the ext4 directory entry excluding the name length 228362306a36Sopenharmony_ci */ 228462306a36Sopenharmony_ci#define EXT4_BASE_DIR_LEN (sizeof(struct ext4_dir_entry_2) - EXT4_NAME_LEN) 228562306a36Sopenharmony_ci 228662306a36Sopenharmony_cistruct ext4_dir_entry { 228762306a36Sopenharmony_ci __le32 inode; /* Inode number */ 228862306a36Sopenharmony_ci __le16 rec_len; /* Directory entry length */ 228962306a36Sopenharmony_ci __le16 name_len; /* Name length */ 229062306a36Sopenharmony_ci char name[EXT4_NAME_LEN]; /* File name */ 229162306a36Sopenharmony_ci}; 229262306a36Sopenharmony_ci 229362306a36Sopenharmony_ci 229462306a36Sopenharmony_ci/* 229562306a36Sopenharmony_ci * Encrypted Casefolded entries require saving the hash on disk. This structure 229662306a36Sopenharmony_ci * followed ext4_dir_entry_2's name[name_len] at the next 4 byte aligned 229762306a36Sopenharmony_ci * boundary. 229862306a36Sopenharmony_ci */ 229962306a36Sopenharmony_cistruct ext4_dir_entry_hash { 230062306a36Sopenharmony_ci __le32 hash; 230162306a36Sopenharmony_ci __le32 minor_hash; 230262306a36Sopenharmony_ci}; 230362306a36Sopenharmony_ci 230462306a36Sopenharmony_ci/* 230562306a36Sopenharmony_ci * The new version of the directory entry. Since EXT4 structures are 230662306a36Sopenharmony_ci * stored in intel byte order, and the name_len field could never be 230762306a36Sopenharmony_ci * bigger than 255 chars, it's safe to reclaim the extra byte for the 230862306a36Sopenharmony_ci * file_type field. 230962306a36Sopenharmony_ci */ 231062306a36Sopenharmony_cistruct ext4_dir_entry_2 { 231162306a36Sopenharmony_ci __le32 inode; /* Inode number */ 231262306a36Sopenharmony_ci __le16 rec_len; /* Directory entry length */ 231362306a36Sopenharmony_ci __u8 name_len; /* Name length */ 231462306a36Sopenharmony_ci __u8 file_type; /* See file type macros EXT4_FT_* below */ 231562306a36Sopenharmony_ci char name[EXT4_NAME_LEN]; /* File name */ 231662306a36Sopenharmony_ci}; 231762306a36Sopenharmony_ci 231862306a36Sopenharmony_ci/* 231962306a36Sopenharmony_ci * Access the hashes at the end of ext4_dir_entry_2 232062306a36Sopenharmony_ci */ 232162306a36Sopenharmony_ci#define EXT4_DIRENT_HASHES(entry) \ 232262306a36Sopenharmony_ci ((struct ext4_dir_entry_hash *) \ 232362306a36Sopenharmony_ci (((void *)(entry)) + \ 232462306a36Sopenharmony_ci ((8 + (entry)->name_len + EXT4_DIR_ROUND) & ~EXT4_DIR_ROUND))) 232562306a36Sopenharmony_ci#define EXT4_DIRENT_HASH(entry) le32_to_cpu(EXT4_DIRENT_HASHES(de)->hash) 232662306a36Sopenharmony_ci#define EXT4_DIRENT_MINOR_HASH(entry) \ 232762306a36Sopenharmony_ci le32_to_cpu(EXT4_DIRENT_HASHES(de)->minor_hash) 232862306a36Sopenharmony_ci 232962306a36Sopenharmony_cistatic inline bool ext4_hash_in_dirent(const struct inode *inode) 233062306a36Sopenharmony_ci{ 233162306a36Sopenharmony_ci return IS_CASEFOLDED(inode) && IS_ENCRYPTED(inode); 233262306a36Sopenharmony_ci} 233362306a36Sopenharmony_ci 233462306a36Sopenharmony_ci/* 233562306a36Sopenharmony_ci * This is a bogus directory entry at the end of each leaf block that 233662306a36Sopenharmony_ci * records checksums. 233762306a36Sopenharmony_ci */ 233862306a36Sopenharmony_cistruct ext4_dir_entry_tail { 233962306a36Sopenharmony_ci __le32 det_reserved_zero1; /* Pretend to be unused */ 234062306a36Sopenharmony_ci __le16 det_rec_len; /* 12 */ 234162306a36Sopenharmony_ci __u8 det_reserved_zero2; /* Zero name length */ 234262306a36Sopenharmony_ci __u8 det_reserved_ft; /* 0xDE, fake file type */ 234362306a36Sopenharmony_ci __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */ 234462306a36Sopenharmony_ci}; 234562306a36Sopenharmony_ci 234662306a36Sopenharmony_ci#define EXT4_DIRENT_TAIL(block, blocksize) \ 234762306a36Sopenharmony_ci ((struct ext4_dir_entry_tail *)(((void *)(block)) + \ 234862306a36Sopenharmony_ci ((blocksize) - \ 234962306a36Sopenharmony_ci sizeof(struct ext4_dir_entry_tail)))) 235062306a36Sopenharmony_ci 235162306a36Sopenharmony_ci/* 235262306a36Sopenharmony_ci * Ext4 directory file types. Only the low 3 bits are used. The 235362306a36Sopenharmony_ci * other bits are reserved for now. 235462306a36Sopenharmony_ci */ 235562306a36Sopenharmony_ci#define EXT4_FT_UNKNOWN 0 235662306a36Sopenharmony_ci#define EXT4_FT_REG_FILE 1 235762306a36Sopenharmony_ci#define EXT4_FT_DIR 2 235862306a36Sopenharmony_ci#define EXT4_FT_CHRDEV 3 235962306a36Sopenharmony_ci#define EXT4_FT_BLKDEV 4 236062306a36Sopenharmony_ci#define EXT4_FT_FIFO 5 236162306a36Sopenharmony_ci#define EXT4_FT_SOCK 6 236262306a36Sopenharmony_ci#define EXT4_FT_SYMLINK 7 236362306a36Sopenharmony_ci 236462306a36Sopenharmony_ci#define EXT4_FT_MAX 8 236562306a36Sopenharmony_ci 236662306a36Sopenharmony_ci#define EXT4_FT_DIR_CSUM 0xDE 236762306a36Sopenharmony_ci 236862306a36Sopenharmony_ci/* 236962306a36Sopenharmony_ci * EXT4_DIR_PAD defines the directory entries boundaries 237062306a36Sopenharmony_ci * 237162306a36Sopenharmony_ci * NOTE: It must be a multiple of 4 237262306a36Sopenharmony_ci */ 237362306a36Sopenharmony_ci#define EXT4_DIR_PAD 4 237462306a36Sopenharmony_ci#define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1) 237562306a36Sopenharmony_ci#define EXT4_MAX_REC_LEN ((1<<16)-1) 237662306a36Sopenharmony_ci 237762306a36Sopenharmony_ci/* 237862306a36Sopenharmony_ci * The rec_len is dependent on the type of directory. Directories that are 237962306a36Sopenharmony_ci * casefolded and encrypted need to store the hash as well, so we add room for 238062306a36Sopenharmony_ci * ext4_extended_dir_entry_2. For all entries related to '.' or '..' you should 238162306a36Sopenharmony_ci * pass NULL for dir, as those entries do not use the extra fields. 238262306a36Sopenharmony_ci */ 238362306a36Sopenharmony_cistatic inline unsigned int ext4_dir_rec_len(__u8 name_len, 238462306a36Sopenharmony_ci const struct inode *dir) 238562306a36Sopenharmony_ci{ 238662306a36Sopenharmony_ci int rec_len = (name_len + 8 + EXT4_DIR_ROUND); 238762306a36Sopenharmony_ci 238862306a36Sopenharmony_ci if (dir && ext4_hash_in_dirent(dir)) 238962306a36Sopenharmony_ci rec_len += sizeof(struct ext4_dir_entry_hash); 239062306a36Sopenharmony_ci return (rec_len & ~EXT4_DIR_ROUND); 239162306a36Sopenharmony_ci} 239262306a36Sopenharmony_ci 239362306a36Sopenharmony_ci/* 239462306a36Sopenharmony_ci * If we ever get support for fs block sizes > page_size, we'll need 239562306a36Sopenharmony_ci * to remove the #if statements in the next two functions... 239662306a36Sopenharmony_ci */ 239762306a36Sopenharmony_cistatic inline unsigned int 239862306a36Sopenharmony_ciext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) 239962306a36Sopenharmony_ci{ 240062306a36Sopenharmony_ci unsigned len = le16_to_cpu(dlen); 240162306a36Sopenharmony_ci 240262306a36Sopenharmony_ci#if (PAGE_SIZE >= 65536) 240362306a36Sopenharmony_ci if (len == EXT4_MAX_REC_LEN || len == 0) 240462306a36Sopenharmony_ci return blocksize; 240562306a36Sopenharmony_ci return (len & 65532) | ((len & 3) << 16); 240662306a36Sopenharmony_ci#else 240762306a36Sopenharmony_ci return len; 240862306a36Sopenharmony_ci#endif 240962306a36Sopenharmony_ci} 241062306a36Sopenharmony_ci 241162306a36Sopenharmony_cistatic inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) 241262306a36Sopenharmony_ci{ 241362306a36Sopenharmony_ci BUG_ON((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)); 241462306a36Sopenharmony_ci#if (PAGE_SIZE >= 65536) 241562306a36Sopenharmony_ci if (len < 65536) 241662306a36Sopenharmony_ci return cpu_to_le16(len); 241762306a36Sopenharmony_ci if (len == blocksize) { 241862306a36Sopenharmony_ci if (blocksize == 65536) 241962306a36Sopenharmony_ci return cpu_to_le16(EXT4_MAX_REC_LEN); 242062306a36Sopenharmony_ci else 242162306a36Sopenharmony_ci return cpu_to_le16(0); 242262306a36Sopenharmony_ci } 242362306a36Sopenharmony_ci return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); 242462306a36Sopenharmony_ci#else 242562306a36Sopenharmony_ci return cpu_to_le16(len); 242662306a36Sopenharmony_ci#endif 242762306a36Sopenharmony_ci} 242862306a36Sopenharmony_ci 242962306a36Sopenharmony_ci/* 243062306a36Sopenharmony_ci * Hash Tree Directory indexing 243162306a36Sopenharmony_ci * (c) Daniel Phillips, 2001 243262306a36Sopenharmony_ci */ 243362306a36Sopenharmony_ci 243462306a36Sopenharmony_ci#define is_dx(dir) (ext4_has_feature_dir_index((dir)->i_sb) && \ 243562306a36Sopenharmony_ci ext4_test_inode_flag((dir), EXT4_INODE_INDEX)) 243662306a36Sopenharmony_ci#define EXT4_DIR_LINK_MAX(dir) unlikely((dir)->i_nlink >= EXT4_LINK_MAX && \ 243762306a36Sopenharmony_ci !(ext4_has_feature_dir_nlink((dir)->i_sb) && is_dx(dir))) 243862306a36Sopenharmony_ci#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 243962306a36Sopenharmony_ci 244062306a36Sopenharmony_ci/* Legal values for the dx_root hash_version field: */ 244162306a36Sopenharmony_ci 244262306a36Sopenharmony_ci#define DX_HASH_LEGACY 0 244362306a36Sopenharmony_ci#define DX_HASH_HALF_MD4 1 244462306a36Sopenharmony_ci#define DX_HASH_TEA 2 244562306a36Sopenharmony_ci#define DX_HASH_LEGACY_UNSIGNED 3 244662306a36Sopenharmony_ci#define DX_HASH_HALF_MD4_UNSIGNED 4 244762306a36Sopenharmony_ci#define DX_HASH_TEA_UNSIGNED 5 244862306a36Sopenharmony_ci#define DX_HASH_SIPHASH 6 244962306a36Sopenharmony_ci 245062306a36Sopenharmony_cistatic inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc, 245162306a36Sopenharmony_ci const void *address, unsigned int length) 245262306a36Sopenharmony_ci{ 245362306a36Sopenharmony_ci struct { 245462306a36Sopenharmony_ci struct shash_desc shash; 245562306a36Sopenharmony_ci char ctx[4]; 245662306a36Sopenharmony_ci } desc; 245762306a36Sopenharmony_ci 245862306a36Sopenharmony_ci BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx)); 245962306a36Sopenharmony_ci 246062306a36Sopenharmony_ci desc.shash.tfm = sbi->s_chksum_driver; 246162306a36Sopenharmony_ci *(u32 *)desc.ctx = crc; 246262306a36Sopenharmony_ci 246362306a36Sopenharmony_ci BUG_ON(crypto_shash_update(&desc.shash, address, length)); 246462306a36Sopenharmony_ci 246562306a36Sopenharmony_ci return *(u32 *)desc.ctx; 246662306a36Sopenharmony_ci} 246762306a36Sopenharmony_ci 246862306a36Sopenharmony_ci#ifdef __KERNEL__ 246962306a36Sopenharmony_ci 247062306a36Sopenharmony_ci/* hash info structure used by the directory hash */ 247162306a36Sopenharmony_cistruct dx_hash_info 247262306a36Sopenharmony_ci{ 247362306a36Sopenharmony_ci u32 hash; 247462306a36Sopenharmony_ci u32 minor_hash; 247562306a36Sopenharmony_ci int hash_version; 247662306a36Sopenharmony_ci u32 *seed; 247762306a36Sopenharmony_ci}; 247862306a36Sopenharmony_ci 247962306a36Sopenharmony_ci 248062306a36Sopenharmony_ci/* 32 and 64 bit signed EOF for dx directories */ 248162306a36Sopenharmony_ci#define EXT4_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1) 248262306a36Sopenharmony_ci#define EXT4_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1) 248362306a36Sopenharmony_ci 248462306a36Sopenharmony_ci 248562306a36Sopenharmony_ci/* 248662306a36Sopenharmony_ci * Control parameters used by ext4_htree_next_block 248762306a36Sopenharmony_ci */ 248862306a36Sopenharmony_ci#define HASH_NB_ALWAYS 1 248962306a36Sopenharmony_ci 249062306a36Sopenharmony_cistruct ext4_filename { 249162306a36Sopenharmony_ci const struct qstr *usr_fname; 249262306a36Sopenharmony_ci struct fscrypt_str disk_name; 249362306a36Sopenharmony_ci struct dx_hash_info hinfo; 249462306a36Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION 249562306a36Sopenharmony_ci struct fscrypt_str crypto_buf; 249662306a36Sopenharmony_ci#endif 249762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 249862306a36Sopenharmony_ci struct fscrypt_str cf_name; 249962306a36Sopenharmony_ci#endif 250062306a36Sopenharmony_ci}; 250162306a36Sopenharmony_ci 250262306a36Sopenharmony_ci#define fname_name(p) ((p)->disk_name.name) 250362306a36Sopenharmony_ci#define fname_usr_name(p) ((p)->usr_fname->name) 250462306a36Sopenharmony_ci#define fname_len(p) ((p)->disk_name.len) 250562306a36Sopenharmony_ci 250662306a36Sopenharmony_ci/* 250762306a36Sopenharmony_ci * Describe an inode's exact location on disk and in memory 250862306a36Sopenharmony_ci */ 250962306a36Sopenharmony_cistruct ext4_iloc 251062306a36Sopenharmony_ci{ 251162306a36Sopenharmony_ci struct buffer_head *bh; 251262306a36Sopenharmony_ci unsigned long offset; 251362306a36Sopenharmony_ci ext4_group_t block_group; 251462306a36Sopenharmony_ci}; 251562306a36Sopenharmony_ci 251662306a36Sopenharmony_cistatic inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc) 251762306a36Sopenharmony_ci{ 251862306a36Sopenharmony_ci return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); 251962306a36Sopenharmony_ci} 252062306a36Sopenharmony_ci 252162306a36Sopenharmony_cistatic inline bool ext4_is_quota_file(struct inode *inode) 252262306a36Sopenharmony_ci{ 252362306a36Sopenharmony_ci return IS_NOQUOTA(inode) && 252462306a36Sopenharmony_ci !(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL); 252562306a36Sopenharmony_ci} 252662306a36Sopenharmony_ci 252762306a36Sopenharmony_ci/* 252862306a36Sopenharmony_ci * This structure is stuffed into the struct file's private_data field 252962306a36Sopenharmony_ci * for directories. It is where we put information so that we can do 253062306a36Sopenharmony_ci * readdir operations in hash tree order. 253162306a36Sopenharmony_ci */ 253262306a36Sopenharmony_cistruct dir_private_info { 253362306a36Sopenharmony_ci struct rb_root root; 253462306a36Sopenharmony_ci struct rb_node *curr_node; 253562306a36Sopenharmony_ci struct fname *extra_fname; 253662306a36Sopenharmony_ci loff_t last_pos; 253762306a36Sopenharmony_ci __u32 curr_hash; 253862306a36Sopenharmony_ci __u32 curr_minor_hash; 253962306a36Sopenharmony_ci __u32 next_hash; 254062306a36Sopenharmony_ci}; 254162306a36Sopenharmony_ci 254262306a36Sopenharmony_ci/* calculate the first block number of the group */ 254362306a36Sopenharmony_cistatic inline ext4_fsblk_t 254462306a36Sopenharmony_ciext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no) 254562306a36Sopenharmony_ci{ 254662306a36Sopenharmony_ci return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + 254762306a36Sopenharmony_ci le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 254862306a36Sopenharmony_ci} 254962306a36Sopenharmony_ci 255062306a36Sopenharmony_ci/* 255162306a36Sopenharmony_ci * Special error return code only used by dx_probe() and its callers. 255262306a36Sopenharmony_ci */ 255362306a36Sopenharmony_ci#define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1)) 255462306a36Sopenharmony_ci 255562306a36Sopenharmony_ci/* htree levels for ext4 */ 255662306a36Sopenharmony_ci#define EXT4_HTREE_LEVEL_COMPAT 2 255762306a36Sopenharmony_ci#define EXT4_HTREE_LEVEL 3 255862306a36Sopenharmony_ci 255962306a36Sopenharmony_cistatic inline int ext4_dir_htree_level(struct super_block *sb) 256062306a36Sopenharmony_ci{ 256162306a36Sopenharmony_ci return ext4_has_feature_largedir(sb) ? 256262306a36Sopenharmony_ci EXT4_HTREE_LEVEL : EXT4_HTREE_LEVEL_COMPAT; 256362306a36Sopenharmony_ci} 256462306a36Sopenharmony_ci 256562306a36Sopenharmony_ci/* 256662306a36Sopenharmony_ci * Timeout and state flag for lazy initialization inode thread. 256762306a36Sopenharmony_ci */ 256862306a36Sopenharmony_ci#define EXT4_DEF_LI_WAIT_MULT 10 256962306a36Sopenharmony_ci#define EXT4_DEF_LI_MAX_START_DELAY 5 257062306a36Sopenharmony_ci#define EXT4_LAZYINIT_QUIT 0x0001 257162306a36Sopenharmony_ci#define EXT4_LAZYINIT_RUNNING 0x0002 257262306a36Sopenharmony_ci 257362306a36Sopenharmony_ci/* 257462306a36Sopenharmony_ci * Lazy inode table initialization info 257562306a36Sopenharmony_ci */ 257662306a36Sopenharmony_cistruct ext4_lazy_init { 257762306a36Sopenharmony_ci unsigned long li_state; 257862306a36Sopenharmony_ci struct list_head li_request_list; 257962306a36Sopenharmony_ci struct mutex li_list_mtx; 258062306a36Sopenharmony_ci}; 258162306a36Sopenharmony_ci 258262306a36Sopenharmony_cienum ext4_li_mode { 258362306a36Sopenharmony_ci EXT4_LI_MODE_PREFETCH_BBITMAP, 258462306a36Sopenharmony_ci EXT4_LI_MODE_ITABLE, 258562306a36Sopenharmony_ci}; 258662306a36Sopenharmony_ci 258762306a36Sopenharmony_cistruct ext4_li_request { 258862306a36Sopenharmony_ci struct super_block *lr_super; 258962306a36Sopenharmony_ci enum ext4_li_mode lr_mode; 259062306a36Sopenharmony_ci ext4_group_t lr_first_not_zeroed; 259162306a36Sopenharmony_ci ext4_group_t lr_next_group; 259262306a36Sopenharmony_ci struct list_head lr_request; 259362306a36Sopenharmony_ci unsigned long lr_next_sched; 259462306a36Sopenharmony_ci unsigned long lr_timeout; 259562306a36Sopenharmony_ci}; 259662306a36Sopenharmony_ci 259762306a36Sopenharmony_cistruct ext4_features { 259862306a36Sopenharmony_ci struct kobject f_kobj; 259962306a36Sopenharmony_ci struct completion f_kobj_unregister; 260062306a36Sopenharmony_ci}; 260162306a36Sopenharmony_ci 260262306a36Sopenharmony_ci/* 260362306a36Sopenharmony_ci * This structure will be used for multiple mount protection. It will be 260462306a36Sopenharmony_ci * written into the block number saved in the s_mmp_block field in the 260562306a36Sopenharmony_ci * superblock. Programs that check MMP should assume that if 260662306a36Sopenharmony_ci * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe 260762306a36Sopenharmony_ci * to use the filesystem, regardless of how old the timestamp is. 260862306a36Sopenharmony_ci */ 260962306a36Sopenharmony_ci#define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ 261062306a36Sopenharmony_ci#define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ 261162306a36Sopenharmony_ci#define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ 261262306a36Sopenharmony_ci#define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ 261362306a36Sopenharmony_ci 261462306a36Sopenharmony_cistruct mmp_struct { 261562306a36Sopenharmony_ci __le32 mmp_magic; /* Magic number for MMP */ 261662306a36Sopenharmony_ci __le32 mmp_seq; /* Sequence no. updated periodically */ 261762306a36Sopenharmony_ci 261862306a36Sopenharmony_ci /* 261962306a36Sopenharmony_ci * mmp_time, mmp_nodename & mmp_bdevname are only used for information 262062306a36Sopenharmony_ci * purposes and do not affect the correctness of the algorithm 262162306a36Sopenharmony_ci */ 262262306a36Sopenharmony_ci __le64 mmp_time; /* Time last updated */ 262362306a36Sopenharmony_ci char mmp_nodename[64]; /* Node which last updated MMP block */ 262462306a36Sopenharmony_ci char mmp_bdevname[32]; /* Bdev which last updated MMP block */ 262562306a36Sopenharmony_ci 262662306a36Sopenharmony_ci /* 262762306a36Sopenharmony_ci * mmp_check_interval is used to verify if the MMP block has been 262862306a36Sopenharmony_ci * updated on the block device. The value is updated based on the 262962306a36Sopenharmony_ci * maximum time to write the MMP block during an update cycle. 263062306a36Sopenharmony_ci */ 263162306a36Sopenharmony_ci __le16 mmp_check_interval; 263262306a36Sopenharmony_ci 263362306a36Sopenharmony_ci __le16 mmp_pad1; 263462306a36Sopenharmony_ci __le32 mmp_pad2[226]; 263562306a36Sopenharmony_ci __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */ 263662306a36Sopenharmony_ci}; 263762306a36Sopenharmony_ci 263862306a36Sopenharmony_ci/* arguments passed to the mmp thread */ 263962306a36Sopenharmony_cistruct mmpd_data { 264062306a36Sopenharmony_ci struct buffer_head *bh; /* bh from initial read_mmp_block() */ 264162306a36Sopenharmony_ci struct super_block *sb; /* super block of the fs */ 264262306a36Sopenharmony_ci}; 264362306a36Sopenharmony_ci 264462306a36Sopenharmony_ci/* 264562306a36Sopenharmony_ci * Check interval multiplier 264662306a36Sopenharmony_ci * The MMP block is written every update interval and initially checked every 264762306a36Sopenharmony_ci * update interval x the multiplier (the value is then adapted based on the 264862306a36Sopenharmony_ci * write latency). The reason is that writes can be delayed under load and we 264962306a36Sopenharmony_ci * don't want readers to incorrectly assume that the filesystem is no longer 265062306a36Sopenharmony_ci * in use. 265162306a36Sopenharmony_ci */ 265262306a36Sopenharmony_ci#define EXT4_MMP_CHECK_MULT 2UL 265362306a36Sopenharmony_ci 265462306a36Sopenharmony_ci/* 265562306a36Sopenharmony_ci * Minimum interval for MMP checking in seconds. 265662306a36Sopenharmony_ci */ 265762306a36Sopenharmony_ci#define EXT4_MMP_MIN_CHECK_INTERVAL 5UL 265862306a36Sopenharmony_ci 265962306a36Sopenharmony_ci/* 266062306a36Sopenharmony_ci * Maximum interval for MMP checking in seconds. 266162306a36Sopenharmony_ci */ 266262306a36Sopenharmony_ci#define EXT4_MMP_MAX_CHECK_INTERVAL 300UL 266362306a36Sopenharmony_ci 266462306a36Sopenharmony_ci/* 266562306a36Sopenharmony_ci * Function prototypes 266662306a36Sopenharmony_ci */ 266762306a36Sopenharmony_ci 266862306a36Sopenharmony_ci/* 266962306a36Sopenharmony_ci * Ok, these declarations are also in <linux/kernel.h> but none of the 267062306a36Sopenharmony_ci * ext4 source programs needs to include it so they are duplicated here. 267162306a36Sopenharmony_ci */ 267262306a36Sopenharmony_ci# define NORET_TYPE /**/ 267362306a36Sopenharmony_ci# define ATTRIB_NORET __attribute__((noreturn)) 267462306a36Sopenharmony_ci# define NORET_AND noreturn, 267562306a36Sopenharmony_ci 267662306a36Sopenharmony_ci/* bitmap.c */ 267762306a36Sopenharmony_ciextern unsigned int ext4_count_free(char *bitmap, unsigned numchars); 267862306a36Sopenharmony_civoid ext4_inode_bitmap_csum_set(struct super_block *sb, 267962306a36Sopenharmony_ci struct ext4_group_desc *gdp, 268062306a36Sopenharmony_ci struct buffer_head *bh, int sz); 268162306a36Sopenharmony_ciint ext4_inode_bitmap_csum_verify(struct super_block *sb, 268262306a36Sopenharmony_ci struct ext4_group_desc *gdp, 268362306a36Sopenharmony_ci struct buffer_head *bh, int sz); 268462306a36Sopenharmony_civoid ext4_block_bitmap_csum_set(struct super_block *sb, 268562306a36Sopenharmony_ci struct ext4_group_desc *gdp, 268662306a36Sopenharmony_ci struct buffer_head *bh); 268762306a36Sopenharmony_ciint ext4_block_bitmap_csum_verify(struct super_block *sb, 268862306a36Sopenharmony_ci struct ext4_group_desc *gdp, 268962306a36Sopenharmony_ci struct buffer_head *bh); 269062306a36Sopenharmony_ci 269162306a36Sopenharmony_ci/* balloc.c */ 269262306a36Sopenharmony_ciextern void ext4_get_group_no_and_offset(struct super_block *sb, 269362306a36Sopenharmony_ci ext4_fsblk_t blocknr, 269462306a36Sopenharmony_ci ext4_group_t *blockgrpp, 269562306a36Sopenharmony_ci ext4_grpblk_t *offsetp); 269662306a36Sopenharmony_ciextern ext4_group_t ext4_get_group_number(struct super_block *sb, 269762306a36Sopenharmony_ci ext4_fsblk_t block); 269862306a36Sopenharmony_ci 269962306a36Sopenharmony_ciextern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group); 270062306a36Sopenharmony_ciextern unsigned long ext4_bg_num_gdb(struct super_block *sb, 270162306a36Sopenharmony_ci ext4_group_t group); 270262306a36Sopenharmony_ciextern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 270362306a36Sopenharmony_ci ext4_fsblk_t goal, 270462306a36Sopenharmony_ci unsigned int flags, 270562306a36Sopenharmony_ci unsigned long *count, 270662306a36Sopenharmony_ci int *errp); 270762306a36Sopenharmony_ciextern int ext4_claim_free_clusters(struct ext4_sb_info *sbi, 270862306a36Sopenharmony_ci s64 nclusters, unsigned int flags); 270962306a36Sopenharmony_ciextern ext4_fsblk_t ext4_count_free_clusters(struct super_block *); 271062306a36Sopenharmony_ciextern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 271162306a36Sopenharmony_ci ext4_group_t block_group, 271262306a36Sopenharmony_ci struct buffer_head ** bh); 271362306a36Sopenharmony_ciextern struct ext4_group_info *ext4_get_group_info(struct super_block *sb, 271462306a36Sopenharmony_ci ext4_group_t group); 271562306a36Sopenharmony_ciextern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 271662306a36Sopenharmony_ci 271762306a36Sopenharmony_ciextern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb, 271862306a36Sopenharmony_ci ext4_group_t block_group, 271962306a36Sopenharmony_ci bool ignore_locked); 272062306a36Sopenharmony_ciextern int ext4_wait_block_bitmap(struct super_block *sb, 272162306a36Sopenharmony_ci ext4_group_t block_group, 272262306a36Sopenharmony_ci struct buffer_head *bh); 272362306a36Sopenharmony_ciextern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb, 272462306a36Sopenharmony_ci ext4_group_t block_group); 272562306a36Sopenharmony_ciextern unsigned ext4_free_clusters_after_init(struct super_block *sb, 272662306a36Sopenharmony_ci ext4_group_t block_group, 272762306a36Sopenharmony_ci struct ext4_group_desc *gdp); 272862306a36Sopenharmony_ciext4_fsblk_t ext4_inode_to_goal_block(struct inode *); 272962306a36Sopenharmony_ci 273062306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 273162306a36Sopenharmony_ciextern int ext4_fname_setup_ci_filename(struct inode *dir, 273262306a36Sopenharmony_ci const struct qstr *iname, 273362306a36Sopenharmony_ci struct ext4_filename *fname); 273462306a36Sopenharmony_ci#endif 273562306a36Sopenharmony_ci 273662306a36Sopenharmony_ci/* ext4 encryption related stuff goes here crypto.c */ 273762306a36Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION 273862306a36Sopenharmony_ciextern const struct fscrypt_operations ext4_cryptops; 273962306a36Sopenharmony_ci 274062306a36Sopenharmony_ciint ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, 274162306a36Sopenharmony_ci int lookup, struct ext4_filename *fname); 274262306a36Sopenharmony_ci 274362306a36Sopenharmony_ciint ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, 274462306a36Sopenharmony_ci struct ext4_filename *fname); 274562306a36Sopenharmony_ci 274662306a36Sopenharmony_civoid ext4_fname_free_filename(struct ext4_filename *fname); 274762306a36Sopenharmony_ci 274862306a36Sopenharmony_ciint ext4_ioctl_get_encryption_pwsalt(struct file *filp, void __user *arg); 274962306a36Sopenharmony_ci 275062306a36Sopenharmony_ci#else /* !CONFIG_FS_ENCRYPTION */ 275162306a36Sopenharmony_cistatic inline int ext4_fname_setup_filename(struct inode *dir, 275262306a36Sopenharmony_ci const struct qstr *iname, 275362306a36Sopenharmony_ci int lookup, 275462306a36Sopenharmony_ci struct ext4_filename *fname) 275562306a36Sopenharmony_ci{ 275662306a36Sopenharmony_ci int err = 0; 275762306a36Sopenharmony_ci fname->usr_fname = iname; 275862306a36Sopenharmony_ci fname->disk_name.name = (unsigned char *) iname->name; 275962306a36Sopenharmony_ci fname->disk_name.len = iname->len; 276062306a36Sopenharmony_ci 276162306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 276262306a36Sopenharmony_ci err = ext4_fname_setup_ci_filename(dir, iname, fname); 276362306a36Sopenharmony_ci#endif 276462306a36Sopenharmony_ci 276562306a36Sopenharmony_ci return err; 276662306a36Sopenharmony_ci} 276762306a36Sopenharmony_ci 276862306a36Sopenharmony_cistatic inline int ext4_fname_prepare_lookup(struct inode *dir, 276962306a36Sopenharmony_ci struct dentry *dentry, 277062306a36Sopenharmony_ci struct ext4_filename *fname) 277162306a36Sopenharmony_ci{ 277262306a36Sopenharmony_ci return ext4_fname_setup_filename(dir, &dentry->d_name, 1, fname); 277362306a36Sopenharmony_ci} 277462306a36Sopenharmony_ci 277562306a36Sopenharmony_cistatic inline void ext4_fname_free_filename(struct ext4_filename *fname) 277662306a36Sopenharmony_ci{ 277762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 277862306a36Sopenharmony_ci kfree(fname->cf_name.name); 277962306a36Sopenharmony_ci fname->cf_name.name = NULL; 278062306a36Sopenharmony_ci#endif 278162306a36Sopenharmony_ci} 278262306a36Sopenharmony_ci 278362306a36Sopenharmony_cistatic inline int ext4_ioctl_get_encryption_pwsalt(struct file *filp, 278462306a36Sopenharmony_ci void __user *arg) 278562306a36Sopenharmony_ci{ 278662306a36Sopenharmony_ci return -EOPNOTSUPP; 278762306a36Sopenharmony_ci} 278862306a36Sopenharmony_ci#endif /* !CONFIG_FS_ENCRYPTION */ 278962306a36Sopenharmony_ci 279062306a36Sopenharmony_ci/* dir.c */ 279162306a36Sopenharmony_ciextern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *, 279262306a36Sopenharmony_ci struct file *, 279362306a36Sopenharmony_ci struct ext4_dir_entry_2 *, 279462306a36Sopenharmony_ci struct buffer_head *, char *, int, 279562306a36Sopenharmony_ci unsigned int); 279662306a36Sopenharmony_ci#define ext4_check_dir_entry(dir, filp, de, bh, buf, size, offset) \ 279762306a36Sopenharmony_ci unlikely(__ext4_check_dir_entry(__func__, __LINE__, (dir), (filp), \ 279862306a36Sopenharmony_ci (de), (bh), (buf), (size), (offset))) 279962306a36Sopenharmony_ciextern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 280062306a36Sopenharmony_ci __u32 minor_hash, 280162306a36Sopenharmony_ci struct ext4_dir_entry_2 *dirent, 280262306a36Sopenharmony_ci struct fscrypt_str *ent_name); 280362306a36Sopenharmony_ciextern void ext4_htree_free_dir_info(struct dir_private_info *p); 280462306a36Sopenharmony_ciextern int ext4_find_dest_de(struct inode *dir, struct inode *inode, 280562306a36Sopenharmony_ci struct buffer_head *bh, 280662306a36Sopenharmony_ci void *buf, int buf_size, 280762306a36Sopenharmony_ci struct ext4_filename *fname, 280862306a36Sopenharmony_ci struct ext4_dir_entry_2 **dest_de); 280962306a36Sopenharmony_civoid ext4_insert_dentry(struct inode *dir, struct inode *inode, 281062306a36Sopenharmony_ci struct ext4_dir_entry_2 *de, 281162306a36Sopenharmony_ci int buf_size, 281262306a36Sopenharmony_ci struct ext4_filename *fname); 281362306a36Sopenharmony_cistatic inline void ext4_update_dx_flag(struct inode *inode) 281462306a36Sopenharmony_ci{ 281562306a36Sopenharmony_ci if (!ext4_has_feature_dir_index(inode->i_sb) && 281662306a36Sopenharmony_ci ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) { 281762306a36Sopenharmony_ci /* ext4_iget() should have caught this... */ 281862306a36Sopenharmony_ci WARN_ON_ONCE(ext4_has_feature_metadata_csum(inode->i_sb)); 281962306a36Sopenharmony_ci ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); 282062306a36Sopenharmony_ci } 282162306a36Sopenharmony_ci} 282262306a36Sopenharmony_cistatic const unsigned char ext4_filetype_table[] = { 282362306a36Sopenharmony_ci DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 282462306a36Sopenharmony_ci}; 282562306a36Sopenharmony_ci 282662306a36Sopenharmony_cistatic inline unsigned char get_dtype(struct super_block *sb, int filetype) 282762306a36Sopenharmony_ci{ 282862306a36Sopenharmony_ci if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) 282962306a36Sopenharmony_ci return DT_UNKNOWN; 283062306a36Sopenharmony_ci 283162306a36Sopenharmony_ci return ext4_filetype_table[filetype]; 283262306a36Sopenharmony_ci} 283362306a36Sopenharmony_ciextern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, 283462306a36Sopenharmony_ci void *buf, int buf_size); 283562306a36Sopenharmony_ci 283662306a36Sopenharmony_ci/* fsync.c */ 283762306a36Sopenharmony_ciextern int ext4_sync_file(struct file *, loff_t, loff_t, int); 283862306a36Sopenharmony_ci 283962306a36Sopenharmony_ci/* hash.c */ 284062306a36Sopenharmony_ciextern int ext4fs_dirhash(const struct inode *dir, const char *name, int len, 284162306a36Sopenharmony_ci struct dx_hash_info *hinfo); 284262306a36Sopenharmony_ci 284362306a36Sopenharmony_ci/* ialloc.c */ 284462306a36Sopenharmony_ciextern int ext4_mark_inode_used(struct super_block *sb, int ino); 284562306a36Sopenharmony_ciextern struct inode *__ext4_new_inode(struct mnt_idmap *, handle_t *, 284662306a36Sopenharmony_ci struct inode *, umode_t, 284762306a36Sopenharmony_ci const struct qstr *qstr, __u32 goal, 284862306a36Sopenharmony_ci uid_t *owner, __u32 i_flags, 284962306a36Sopenharmony_ci int handle_type, unsigned int line_no, 285062306a36Sopenharmony_ci int nblocks); 285162306a36Sopenharmony_ci 285262306a36Sopenharmony_ci#define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \ 285362306a36Sopenharmony_ci __ext4_new_inode(&nop_mnt_idmap, (handle), (dir), (mode), (qstr), \ 285462306a36Sopenharmony_ci (goal), (owner), i_flags, 0, 0, 0) 285562306a36Sopenharmony_ci#define ext4_new_inode_start_handle(idmap, dir, mode, qstr, goal, owner, \ 285662306a36Sopenharmony_ci type, nblocks) \ 285762306a36Sopenharmony_ci __ext4_new_inode((idmap), NULL, (dir), (mode), (qstr), (goal), (owner), \ 285862306a36Sopenharmony_ci 0, (type), __LINE__, (nblocks)) 285962306a36Sopenharmony_ci 286062306a36Sopenharmony_ci 286162306a36Sopenharmony_ciextern void ext4_free_inode(handle_t *, struct inode *); 286262306a36Sopenharmony_ciextern struct inode * ext4_orphan_get(struct super_block *, unsigned long); 286362306a36Sopenharmony_ciextern unsigned long ext4_count_free_inodes(struct super_block *); 286462306a36Sopenharmony_ciextern unsigned long ext4_count_dirs(struct super_block *); 286562306a36Sopenharmony_ciextern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap); 286662306a36Sopenharmony_ciextern int ext4_init_inode_table(struct super_block *sb, 286762306a36Sopenharmony_ci ext4_group_t group, int barrier); 286862306a36Sopenharmony_ciextern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 286962306a36Sopenharmony_ci 287062306a36Sopenharmony_ci/* fast_commit.c */ 287162306a36Sopenharmony_ciint ext4_fc_info_show(struct seq_file *seq, void *v); 287262306a36Sopenharmony_civoid ext4_fc_init(struct super_block *sb, journal_t *journal); 287362306a36Sopenharmony_civoid ext4_fc_init_inode(struct inode *inode); 287462306a36Sopenharmony_civoid ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start, 287562306a36Sopenharmony_ci ext4_lblk_t end); 287662306a36Sopenharmony_civoid __ext4_fc_track_unlink(handle_t *handle, struct inode *inode, 287762306a36Sopenharmony_ci struct dentry *dentry); 287862306a36Sopenharmony_civoid __ext4_fc_track_link(handle_t *handle, struct inode *inode, 287962306a36Sopenharmony_ci struct dentry *dentry); 288062306a36Sopenharmony_civoid ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry); 288162306a36Sopenharmony_civoid ext4_fc_track_link(handle_t *handle, struct dentry *dentry); 288262306a36Sopenharmony_civoid __ext4_fc_track_create(handle_t *handle, struct inode *inode, 288362306a36Sopenharmony_ci struct dentry *dentry); 288462306a36Sopenharmony_civoid ext4_fc_track_create(handle_t *handle, struct dentry *dentry); 288562306a36Sopenharmony_civoid ext4_fc_track_inode(handle_t *handle, struct inode *inode); 288662306a36Sopenharmony_civoid ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handle); 288762306a36Sopenharmony_civoid ext4_fc_start_update(struct inode *inode); 288862306a36Sopenharmony_civoid ext4_fc_stop_update(struct inode *inode); 288962306a36Sopenharmony_civoid ext4_fc_del(struct inode *inode); 289062306a36Sopenharmony_cibool ext4_fc_replay_check_excluded(struct super_block *sb, ext4_fsblk_t block); 289162306a36Sopenharmony_civoid ext4_fc_replay_cleanup(struct super_block *sb); 289262306a36Sopenharmony_ciint ext4_fc_commit(journal_t *journal, tid_t commit_tid); 289362306a36Sopenharmony_ciint __init ext4_fc_init_dentry_cache(void); 289462306a36Sopenharmony_civoid ext4_fc_destroy_dentry_cache(void); 289562306a36Sopenharmony_ciint ext4_fc_record_regions(struct super_block *sb, int ino, 289662306a36Sopenharmony_ci ext4_lblk_t lblk, ext4_fsblk_t pblk, 289762306a36Sopenharmony_ci int len, int replay); 289862306a36Sopenharmony_ci 289962306a36Sopenharmony_ci/* mballoc.c */ 290062306a36Sopenharmony_ciextern const struct seq_operations ext4_mb_seq_groups_ops; 290162306a36Sopenharmony_ciextern const struct seq_operations ext4_mb_seq_structs_summary_ops; 290262306a36Sopenharmony_ciextern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset); 290362306a36Sopenharmony_ciextern int ext4_mb_init(struct super_block *); 290462306a36Sopenharmony_ciextern int ext4_mb_release(struct super_block *); 290562306a36Sopenharmony_ciextern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 290662306a36Sopenharmony_ci struct ext4_allocation_request *, int *); 290762306a36Sopenharmony_ciextern void ext4_discard_preallocations(struct inode *, unsigned int); 290862306a36Sopenharmony_ciextern int __init ext4_init_mballoc(void); 290962306a36Sopenharmony_ciextern void ext4_exit_mballoc(void); 291062306a36Sopenharmony_ciextern ext4_group_t ext4_mb_prefetch(struct super_block *sb, 291162306a36Sopenharmony_ci ext4_group_t group, 291262306a36Sopenharmony_ci unsigned int nr, int *cnt); 291362306a36Sopenharmony_ciextern void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group, 291462306a36Sopenharmony_ci unsigned int nr); 291562306a36Sopenharmony_ci 291662306a36Sopenharmony_ciextern void ext4_free_blocks(handle_t *handle, struct inode *inode, 291762306a36Sopenharmony_ci struct buffer_head *bh, ext4_fsblk_t block, 291862306a36Sopenharmony_ci unsigned long count, int flags); 291962306a36Sopenharmony_ciextern int ext4_mb_alloc_groupinfo(struct super_block *sb, 292062306a36Sopenharmony_ci ext4_group_t ngroups); 292162306a36Sopenharmony_ciextern int ext4_mb_add_groupinfo(struct super_block *sb, 292262306a36Sopenharmony_ci ext4_group_t i, struct ext4_group_desc *desc); 292362306a36Sopenharmony_ciextern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, 292462306a36Sopenharmony_ci ext4_fsblk_t block, unsigned long count); 292562306a36Sopenharmony_ciextern int ext4_trim_fs(struct super_block *, struct fstrim_range *); 292662306a36Sopenharmony_ciextern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid); 292762306a36Sopenharmony_ciextern void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, 292862306a36Sopenharmony_ci int len, int state); 292962306a36Sopenharmony_cistatic inline bool ext4_mb_cr_expensive(enum criteria cr) 293062306a36Sopenharmony_ci{ 293162306a36Sopenharmony_ci return cr >= CR_GOAL_LEN_SLOW; 293262306a36Sopenharmony_ci} 293362306a36Sopenharmony_ci 293462306a36Sopenharmony_ci/* inode.c */ 293562306a36Sopenharmony_civoid ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, 293662306a36Sopenharmony_ci struct ext4_inode_info *ei); 293762306a36Sopenharmony_ciint ext4_inode_is_fast_symlink(struct inode *inode); 293862306a36Sopenharmony_cistruct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); 293962306a36Sopenharmony_cistruct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); 294062306a36Sopenharmony_ciint ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, 294162306a36Sopenharmony_ci bool wait, struct buffer_head **bhs); 294262306a36Sopenharmony_ciint ext4_get_block_unwritten(struct inode *inode, sector_t iblock, 294362306a36Sopenharmony_ci struct buffer_head *bh_result, int create); 294462306a36Sopenharmony_ciint ext4_get_block(struct inode *inode, sector_t iblock, 294562306a36Sopenharmony_ci struct buffer_head *bh_result, int create); 294662306a36Sopenharmony_ciint ext4_da_get_block_prep(struct inode *inode, sector_t iblock, 294762306a36Sopenharmony_ci struct buffer_head *bh, int create); 294862306a36Sopenharmony_ciint ext4_walk_page_buffers(handle_t *handle, 294962306a36Sopenharmony_ci struct inode *inode, 295062306a36Sopenharmony_ci struct buffer_head *head, 295162306a36Sopenharmony_ci unsigned from, 295262306a36Sopenharmony_ci unsigned to, 295362306a36Sopenharmony_ci int *partial, 295462306a36Sopenharmony_ci int (*fn)(handle_t *handle, struct inode *inode, 295562306a36Sopenharmony_ci struct buffer_head *bh)); 295662306a36Sopenharmony_ciint do_journal_get_write_access(handle_t *handle, struct inode *inode, 295762306a36Sopenharmony_ci struct buffer_head *bh); 295862306a36Sopenharmony_ci#define FALL_BACK_TO_NONDELALLOC 1 295962306a36Sopenharmony_ci#define CONVERT_INLINE_DATA 2 296062306a36Sopenharmony_ci 296162306a36Sopenharmony_citypedef enum { 296262306a36Sopenharmony_ci EXT4_IGET_NORMAL = 0, 296362306a36Sopenharmony_ci EXT4_IGET_SPECIAL = 0x0001, /* OK to iget a system inode */ 296462306a36Sopenharmony_ci EXT4_IGET_HANDLE = 0x0002, /* Inode # is from a handle */ 296562306a36Sopenharmony_ci EXT4_IGET_BAD = 0x0004, /* Allow to iget a bad inode */ 296662306a36Sopenharmony_ci EXT4_IGET_EA_INODE = 0x0008 /* Inode should contain an EA value */ 296762306a36Sopenharmony_ci} ext4_iget_flags; 296862306a36Sopenharmony_ci 296962306a36Sopenharmony_ciextern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, 297062306a36Sopenharmony_ci ext4_iget_flags flags, const char *function, 297162306a36Sopenharmony_ci unsigned int line); 297262306a36Sopenharmony_ci 297362306a36Sopenharmony_ci#define ext4_iget(sb, ino, flags) \ 297462306a36Sopenharmony_ci __ext4_iget((sb), (ino), (flags), __func__, __LINE__) 297562306a36Sopenharmony_ci 297662306a36Sopenharmony_ciextern int ext4_write_inode(struct inode *, struct writeback_control *); 297762306a36Sopenharmony_ciextern int ext4_setattr(struct mnt_idmap *, struct dentry *, 297862306a36Sopenharmony_ci struct iattr *); 297962306a36Sopenharmony_ciextern u32 ext4_dio_alignment(struct inode *inode); 298062306a36Sopenharmony_ciextern int ext4_getattr(struct mnt_idmap *, const struct path *, 298162306a36Sopenharmony_ci struct kstat *, u32, unsigned int); 298262306a36Sopenharmony_ciextern void ext4_evict_inode(struct inode *); 298362306a36Sopenharmony_ciextern void ext4_clear_inode(struct inode *); 298462306a36Sopenharmony_ciextern int ext4_file_getattr(struct mnt_idmap *, const struct path *, 298562306a36Sopenharmony_ci struct kstat *, u32, unsigned int); 298662306a36Sopenharmony_ciextern void ext4_dirty_inode(struct inode *, int); 298762306a36Sopenharmony_ciextern int ext4_change_inode_journal_flag(struct inode *, int); 298862306a36Sopenharmony_ciextern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *); 298962306a36Sopenharmony_ciextern int ext4_get_fc_inode_loc(struct super_block *sb, unsigned long ino, 299062306a36Sopenharmony_ci struct ext4_iloc *iloc); 299162306a36Sopenharmony_ciextern int ext4_inode_attach_jinode(struct inode *inode); 299262306a36Sopenharmony_ciextern int ext4_can_truncate(struct inode *inode); 299362306a36Sopenharmony_ciextern int ext4_truncate(struct inode *); 299462306a36Sopenharmony_ciextern int ext4_break_layouts(struct inode *); 299562306a36Sopenharmony_ciextern int ext4_punch_hole(struct file *file, loff_t offset, loff_t length); 299662306a36Sopenharmony_ciextern void ext4_set_inode_flags(struct inode *, bool init); 299762306a36Sopenharmony_ciextern int ext4_alloc_da_blocks(struct inode *inode); 299862306a36Sopenharmony_ciextern void ext4_set_aops(struct inode *inode); 299962306a36Sopenharmony_ciextern int ext4_writepage_trans_blocks(struct inode *); 300062306a36Sopenharmony_ciextern int ext4_normal_submit_inode_data_buffers(struct jbd2_inode *jinode); 300162306a36Sopenharmony_ciextern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); 300262306a36Sopenharmony_ciextern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 300362306a36Sopenharmony_ci loff_t lstart, loff_t lend); 300462306a36Sopenharmony_ciextern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); 300562306a36Sopenharmony_ciextern qsize_t *ext4_get_reserved_space(struct inode *inode); 300662306a36Sopenharmony_ciextern int ext4_get_projid(struct inode *inode, kprojid_t *projid); 300762306a36Sopenharmony_ciextern void ext4_da_release_space(struct inode *inode, int to_free); 300862306a36Sopenharmony_ciextern void ext4_da_update_reserve_space(struct inode *inode, 300962306a36Sopenharmony_ci int used, int quota_claim); 301062306a36Sopenharmony_ciextern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, 301162306a36Sopenharmony_ci ext4_fsblk_t pblk, ext4_lblk_t len); 301262306a36Sopenharmony_ci 301362306a36Sopenharmony_ci/* indirect.c */ 301462306a36Sopenharmony_ciextern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 301562306a36Sopenharmony_ci struct ext4_map_blocks *map, int flags); 301662306a36Sopenharmony_ciextern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 301762306a36Sopenharmony_ciextern void ext4_ind_truncate(handle_t *, struct inode *inode); 301862306a36Sopenharmony_ciextern int ext4_ind_remove_space(handle_t *handle, struct inode *inode, 301962306a36Sopenharmony_ci ext4_lblk_t start, ext4_lblk_t end); 302062306a36Sopenharmony_ci 302162306a36Sopenharmony_ci/* ioctl.c */ 302262306a36Sopenharmony_ciextern long ext4_ioctl(struct file *, unsigned int, unsigned long); 302362306a36Sopenharmony_ciextern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long); 302462306a36Sopenharmony_ciint ext4_fileattr_set(struct mnt_idmap *idmap, 302562306a36Sopenharmony_ci struct dentry *dentry, struct fileattr *fa); 302662306a36Sopenharmony_ciint ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa); 302762306a36Sopenharmony_ciextern void ext4_reset_inode_seed(struct inode *inode); 302862306a36Sopenharmony_ciint ext4_update_overhead(struct super_block *sb, bool force); 302962306a36Sopenharmony_ciint ext4_force_shutdown(struct super_block *sb, u32 flags); 303062306a36Sopenharmony_ci 303162306a36Sopenharmony_ci/* migrate.c */ 303262306a36Sopenharmony_ciextern int ext4_ext_migrate(struct inode *); 303362306a36Sopenharmony_ciextern int ext4_ind_migrate(struct inode *inode); 303462306a36Sopenharmony_ci 303562306a36Sopenharmony_ci/* namei.c */ 303662306a36Sopenharmony_ciextern int ext4_init_new_dir(handle_t *handle, struct inode *dir, 303762306a36Sopenharmony_ci struct inode *inode); 303862306a36Sopenharmony_ciextern int ext4_dirblock_csum_verify(struct inode *inode, 303962306a36Sopenharmony_ci struct buffer_head *bh); 304062306a36Sopenharmony_ciextern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 304162306a36Sopenharmony_ci __u32 start_minor_hash, __u32 *next_hash); 304262306a36Sopenharmony_ciextern int ext4_search_dir(struct buffer_head *bh, 304362306a36Sopenharmony_ci char *search_buf, 304462306a36Sopenharmony_ci int buf_size, 304562306a36Sopenharmony_ci struct inode *dir, 304662306a36Sopenharmony_ci struct ext4_filename *fname, 304762306a36Sopenharmony_ci unsigned int offset, 304862306a36Sopenharmony_ci struct ext4_dir_entry_2 **res_dir); 304962306a36Sopenharmony_ciextern int ext4_generic_delete_entry(struct inode *dir, 305062306a36Sopenharmony_ci struct ext4_dir_entry_2 *de_del, 305162306a36Sopenharmony_ci struct buffer_head *bh, 305262306a36Sopenharmony_ci void *entry_buf, 305362306a36Sopenharmony_ci int buf_size, 305462306a36Sopenharmony_ci int csum_size); 305562306a36Sopenharmony_ciextern bool ext4_empty_dir(struct inode *inode); 305662306a36Sopenharmony_ci 305762306a36Sopenharmony_ci/* resize.c */ 305862306a36Sopenharmony_ciextern void ext4_kvfree_array_rcu(void *to_free); 305962306a36Sopenharmony_ciextern int ext4_group_add(struct super_block *sb, 306062306a36Sopenharmony_ci struct ext4_new_group_data *input); 306162306a36Sopenharmony_ciextern int ext4_group_extend(struct super_block *sb, 306262306a36Sopenharmony_ci struct ext4_super_block *es, 306362306a36Sopenharmony_ci ext4_fsblk_t n_blocks_count); 306462306a36Sopenharmony_ciextern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 306562306a36Sopenharmony_ciextern unsigned int ext4_list_backups(struct super_block *sb, 306662306a36Sopenharmony_ci unsigned int *three, unsigned int *five, 306762306a36Sopenharmony_ci unsigned int *seven); 306862306a36Sopenharmony_ci 306962306a36Sopenharmony_ci/* super.c */ 307062306a36Sopenharmony_ciextern struct buffer_head *ext4_sb_bread(struct super_block *sb, 307162306a36Sopenharmony_ci sector_t block, blk_opf_t op_flags); 307262306a36Sopenharmony_ciextern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, 307362306a36Sopenharmony_ci sector_t block); 307462306a36Sopenharmony_ciextern void ext4_read_bh_nowait(struct buffer_head *bh, blk_opf_t op_flags, 307562306a36Sopenharmony_ci bh_end_io_t *end_io); 307662306a36Sopenharmony_ciextern int ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags, 307762306a36Sopenharmony_ci bh_end_io_t *end_io); 307862306a36Sopenharmony_ciextern int ext4_read_bh_lock(struct buffer_head *bh, blk_opf_t op_flags, bool wait); 307962306a36Sopenharmony_ciextern void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block); 308062306a36Sopenharmony_ciextern int ext4_seq_options_show(struct seq_file *seq, void *offset); 308162306a36Sopenharmony_ciextern int ext4_calculate_overhead(struct super_block *sb); 308262306a36Sopenharmony_ciextern __le32 ext4_superblock_csum(struct super_block *sb, 308362306a36Sopenharmony_ci struct ext4_super_block *es); 308462306a36Sopenharmony_ciextern void ext4_superblock_csum_set(struct super_block *sb); 308562306a36Sopenharmony_ciextern int ext4_alloc_flex_bg_array(struct super_block *sb, 308662306a36Sopenharmony_ci ext4_group_t ngroup); 308762306a36Sopenharmony_ciextern const char *ext4_decode_error(struct super_block *sb, int errno, 308862306a36Sopenharmony_ci char nbuf[16]); 308962306a36Sopenharmony_ciextern void ext4_mark_group_bitmap_corrupted(struct super_block *sb, 309062306a36Sopenharmony_ci ext4_group_t block_group, 309162306a36Sopenharmony_ci unsigned int flags); 309262306a36Sopenharmony_ciextern unsigned int ext4_num_base_meta_blocks(struct super_block *sb, 309362306a36Sopenharmony_ci ext4_group_t block_group); 309462306a36Sopenharmony_ci 309562306a36Sopenharmony_ciextern __printf(7, 8) 309662306a36Sopenharmony_civoid __ext4_error(struct super_block *, const char *, unsigned int, bool, 309762306a36Sopenharmony_ci int, __u64, const char *, ...); 309862306a36Sopenharmony_ciextern __printf(6, 7) 309962306a36Sopenharmony_civoid __ext4_error_inode(struct inode *, const char *, unsigned int, 310062306a36Sopenharmony_ci ext4_fsblk_t, int, const char *, ...); 310162306a36Sopenharmony_ciextern __printf(5, 6) 310262306a36Sopenharmony_civoid __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t, 310362306a36Sopenharmony_ci const char *, ...); 310462306a36Sopenharmony_ciextern void __ext4_std_error(struct super_block *, const char *, 310562306a36Sopenharmony_ci unsigned int, int); 310662306a36Sopenharmony_ciextern __printf(4, 5) 310762306a36Sopenharmony_civoid __ext4_warning(struct super_block *, const char *, unsigned int, 310862306a36Sopenharmony_ci const char *, ...); 310962306a36Sopenharmony_ciextern __printf(4, 5) 311062306a36Sopenharmony_civoid __ext4_warning_inode(const struct inode *inode, const char *function, 311162306a36Sopenharmony_ci unsigned int line, const char *fmt, ...); 311262306a36Sopenharmony_ciextern __printf(3, 4) 311362306a36Sopenharmony_civoid __ext4_msg(struct super_block *, const char *, const char *, ...); 311462306a36Sopenharmony_ciextern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp, 311562306a36Sopenharmony_ci const char *, unsigned int, const char *); 311662306a36Sopenharmony_ciextern __printf(7, 8) 311762306a36Sopenharmony_civoid __ext4_grp_locked_error(const char *, unsigned int, 311862306a36Sopenharmony_ci struct super_block *, ext4_group_t, 311962306a36Sopenharmony_ci unsigned long, ext4_fsblk_t, 312062306a36Sopenharmony_ci const char *, ...); 312162306a36Sopenharmony_ci 312262306a36Sopenharmony_ci#define EXT4_ERROR_INODE(inode, fmt, a...) \ 312362306a36Sopenharmony_ci ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a) 312462306a36Sopenharmony_ci 312562306a36Sopenharmony_ci#define EXT4_ERROR_INODE_ERR(inode, err, fmt, a...) \ 312662306a36Sopenharmony_ci __ext4_error_inode((inode), __func__, __LINE__, 0, (err), (fmt), ## a) 312762306a36Sopenharmony_ci 312862306a36Sopenharmony_ci#define ext4_error_inode_block(inode, block, err, fmt, a...) \ 312962306a36Sopenharmony_ci __ext4_error_inode((inode), __func__, __LINE__, (block), (err), \ 313062306a36Sopenharmony_ci (fmt), ## a) 313162306a36Sopenharmony_ci 313262306a36Sopenharmony_ci#define EXT4_ERROR_FILE(file, block, fmt, a...) \ 313362306a36Sopenharmony_ci ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a) 313462306a36Sopenharmony_ci 313562306a36Sopenharmony_ci#define ext4_abort(sb, err, fmt, a...) \ 313662306a36Sopenharmony_ci __ext4_error((sb), __func__, __LINE__, true, (err), 0, (fmt), ## a) 313762306a36Sopenharmony_ci 313862306a36Sopenharmony_ci#ifdef CONFIG_PRINTK 313962306a36Sopenharmony_ci 314062306a36Sopenharmony_ci#define ext4_error_inode(inode, func, line, block, fmt, ...) \ 314162306a36Sopenharmony_ci __ext4_error_inode(inode, func, line, block, 0, fmt, ##__VA_ARGS__) 314262306a36Sopenharmony_ci#define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 314362306a36Sopenharmony_ci __ext4_error_inode((inode), (func), (line), (block), \ 314462306a36Sopenharmony_ci (err), (fmt), ##__VA_ARGS__) 314562306a36Sopenharmony_ci#define ext4_error_file(file, func, line, block, fmt, ...) \ 314662306a36Sopenharmony_ci __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__) 314762306a36Sopenharmony_ci#define ext4_error(sb, fmt, ...) \ 314862306a36Sopenharmony_ci __ext4_error((sb), __func__, __LINE__, false, 0, 0, (fmt), \ 314962306a36Sopenharmony_ci ##__VA_ARGS__) 315062306a36Sopenharmony_ci#define ext4_error_err(sb, err, fmt, ...) \ 315162306a36Sopenharmony_ci __ext4_error((sb), __func__, __LINE__, false, (err), 0, (fmt), \ 315262306a36Sopenharmony_ci ##__VA_ARGS__) 315362306a36Sopenharmony_ci#define ext4_warning(sb, fmt, ...) \ 315462306a36Sopenharmony_ci __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 315562306a36Sopenharmony_ci#define ext4_warning_inode(inode, fmt, ...) \ 315662306a36Sopenharmony_ci __ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__) 315762306a36Sopenharmony_ci#define ext4_msg(sb, level, fmt, ...) \ 315862306a36Sopenharmony_ci __ext4_msg(sb, level, fmt, ##__VA_ARGS__) 315962306a36Sopenharmony_ci#define dump_mmp_msg(sb, mmp, msg) \ 316062306a36Sopenharmony_ci __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg) 316162306a36Sopenharmony_ci#define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 316262306a36Sopenharmony_ci __ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino, block, \ 316362306a36Sopenharmony_ci fmt, ##__VA_ARGS__) 316462306a36Sopenharmony_ci 316562306a36Sopenharmony_ci#else 316662306a36Sopenharmony_ci 316762306a36Sopenharmony_ci#define ext4_error_inode(inode, func, line, block, fmt, ...) \ 316862306a36Sopenharmony_cido { \ 316962306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 317062306a36Sopenharmony_ci __ext4_error_inode(inode, "", 0, block, 0, " "); \ 317162306a36Sopenharmony_ci} while (0) 317262306a36Sopenharmony_ci#define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 317362306a36Sopenharmony_cido { \ 317462306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 317562306a36Sopenharmony_ci __ext4_error_inode(inode, "", 0, block, err, " "); \ 317662306a36Sopenharmony_ci} while (0) 317762306a36Sopenharmony_ci#define ext4_error_file(file, func, line, block, fmt, ...) \ 317862306a36Sopenharmony_cido { \ 317962306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 318062306a36Sopenharmony_ci __ext4_error_file(file, "", 0, block, " "); \ 318162306a36Sopenharmony_ci} while (0) 318262306a36Sopenharmony_ci#define ext4_error(sb, fmt, ...) \ 318362306a36Sopenharmony_cido { \ 318462306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 318562306a36Sopenharmony_ci __ext4_error(sb, "", 0, false, 0, 0, " "); \ 318662306a36Sopenharmony_ci} while (0) 318762306a36Sopenharmony_ci#define ext4_error_err(sb, err, fmt, ...) \ 318862306a36Sopenharmony_cido { \ 318962306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 319062306a36Sopenharmony_ci __ext4_error(sb, "", 0, false, err, 0, " "); \ 319162306a36Sopenharmony_ci} while (0) 319262306a36Sopenharmony_ci#define ext4_warning(sb, fmt, ...) \ 319362306a36Sopenharmony_cido { \ 319462306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 319562306a36Sopenharmony_ci __ext4_warning(sb, "", 0, " "); \ 319662306a36Sopenharmony_ci} while (0) 319762306a36Sopenharmony_ci#define ext4_warning_inode(inode, fmt, ...) \ 319862306a36Sopenharmony_cido { \ 319962306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 320062306a36Sopenharmony_ci __ext4_warning_inode(inode, "", 0, " "); \ 320162306a36Sopenharmony_ci} while (0) 320262306a36Sopenharmony_ci#define ext4_msg(sb, level, fmt, ...) \ 320362306a36Sopenharmony_cido { \ 320462306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 320562306a36Sopenharmony_ci __ext4_msg(sb, "", " "); \ 320662306a36Sopenharmony_ci} while (0) 320762306a36Sopenharmony_ci#define dump_mmp_msg(sb, mmp, msg) \ 320862306a36Sopenharmony_ci __dump_mmp_msg(sb, mmp, "", 0, "") 320962306a36Sopenharmony_ci#define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 321062306a36Sopenharmony_cido { \ 321162306a36Sopenharmony_ci no_printk(fmt, ##__VA_ARGS__); \ 321262306a36Sopenharmony_ci __ext4_grp_locked_error("", 0, sb, grp, ino, block, " "); \ 321362306a36Sopenharmony_ci} while (0) 321462306a36Sopenharmony_ci 321562306a36Sopenharmony_ci#endif 321662306a36Sopenharmony_ci 321762306a36Sopenharmony_ciextern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 321862306a36Sopenharmony_ci struct ext4_group_desc *bg); 321962306a36Sopenharmony_ciextern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 322062306a36Sopenharmony_ci struct ext4_group_desc *bg); 322162306a36Sopenharmony_ciextern ext4_fsblk_t ext4_inode_table(struct super_block *sb, 322262306a36Sopenharmony_ci struct ext4_group_desc *bg); 322362306a36Sopenharmony_ciextern __u32 ext4_free_group_clusters(struct super_block *sb, 322462306a36Sopenharmony_ci struct ext4_group_desc *bg); 322562306a36Sopenharmony_ciextern __u32 ext4_free_inodes_count(struct super_block *sb, 322662306a36Sopenharmony_ci struct ext4_group_desc *bg); 322762306a36Sopenharmony_ciextern __u32 ext4_used_dirs_count(struct super_block *sb, 322862306a36Sopenharmony_ci struct ext4_group_desc *bg); 322962306a36Sopenharmony_ciextern __u32 ext4_itable_unused_count(struct super_block *sb, 323062306a36Sopenharmony_ci struct ext4_group_desc *bg); 323162306a36Sopenharmony_ciextern void ext4_block_bitmap_set(struct super_block *sb, 323262306a36Sopenharmony_ci struct ext4_group_desc *bg, ext4_fsblk_t blk); 323362306a36Sopenharmony_ciextern void ext4_inode_bitmap_set(struct super_block *sb, 323462306a36Sopenharmony_ci struct ext4_group_desc *bg, ext4_fsblk_t blk); 323562306a36Sopenharmony_ciextern void ext4_inode_table_set(struct super_block *sb, 323662306a36Sopenharmony_ci struct ext4_group_desc *bg, ext4_fsblk_t blk); 323762306a36Sopenharmony_ciextern void ext4_free_group_clusters_set(struct super_block *sb, 323862306a36Sopenharmony_ci struct ext4_group_desc *bg, 323962306a36Sopenharmony_ci __u32 count); 324062306a36Sopenharmony_ciextern void ext4_free_inodes_set(struct super_block *sb, 324162306a36Sopenharmony_ci struct ext4_group_desc *bg, __u32 count); 324262306a36Sopenharmony_ciextern void ext4_used_dirs_set(struct super_block *sb, 324362306a36Sopenharmony_ci struct ext4_group_desc *bg, __u32 count); 324462306a36Sopenharmony_ciextern void ext4_itable_unused_set(struct super_block *sb, 324562306a36Sopenharmony_ci struct ext4_group_desc *bg, __u32 count); 324662306a36Sopenharmony_ciextern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group, 324762306a36Sopenharmony_ci struct ext4_group_desc *gdp); 324862306a36Sopenharmony_ciextern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group, 324962306a36Sopenharmony_ci struct ext4_group_desc *gdp); 325062306a36Sopenharmony_ciextern int ext4_register_li_request(struct super_block *sb, 325162306a36Sopenharmony_ci ext4_group_t first_not_zeroed); 325262306a36Sopenharmony_ci 325362306a36Sopenharmony_cistatic inline int ext4_has_metadata_csum(struct super_block *sb) 325462306a36Sopenharmony_ci{ 325562306a36Sopenharmony_ci WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) && 325662306a36Sopenharmony_ci !EXT4_SB(sb)->s_chksum_driver); 325762306a36Sopenharmony_ci 325862306a36Sopenharmony_ci return ext4_has_feature_metadata_csum(sb) && 325962306a36Sopenharmony_ci (EXT4_SB(sb)->s_chksum_driver != NULL); 326062306a36Sopenharmony_ci} 326162306a36Sopenharmony_ci 326262306a36Sopenharmony_cistatic inline int ext4_has_group_desc_csum(struct super_block *sb) 326362306a36Sopenharmony_ci{ 326462306a36Sopenharmony_ci return ext4_has_feature_gdt_csum(sb) || ext4_has_metadata_csum(sb); 326562306a36Sopenharmony_ci} 326662306a36Sopenharmony_ci 326762306a36Sopenharmony_ci#define ext4_read_incompat_64bit_val(es, name) \ 326862306a36Sopenharmony_ci (((es)->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT) \ 326962306a36Sopenharmony_ci ? (ext4_fsblk_t)le32_to_cpu(es->name##_hi) << 32 : 0) | \ 327062306a36Sopenharmony_ci le32_to_cpu(es->name##_lo)) 327162306a36Sopenharmony_ci 327262306a36Sopenharmony_cistatic inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 327362306a36Sopenharmony_ci{ 327462306a36Sopenharmony_ci return ext4_read_incompat_64bit_val(es, s_blocks_count); 327562306a36Sopenharmony_ci} 327662306a36Sopenharmony_ci 327762306a36Sopenharmony_cistatic inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) 327862306a36Sopenharmony_ci{ 327962306a36Sopenharmony_ci return ext4_read_incompat_64bit_val(es, s_r_blocks_count); 328062306a36Sopenharmony_ci} 328162306a36Sopenharmony_ci 328262306a36Sopenharmony_cistatic inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es) 328362306a36Sopenharmony_ci{ 328462306a36Sopenharmony_ci return ext4_read_incompat_64bit_val(es, s_free_blocks_count); 328562306a36Sopenharmony_ci} 328662306a36Sopenharmony_ci 328762306a36Sopenharmony_cistatic inline void ext4_blocks_count_set(struct ext4_super_block *es, 328862306a36Sopenharmony_ci ext4_fsblk_t blk) 328962306a36Sopenharmony_ci{ 329062306a36Sopenharmony_ci es->s_blocks_count_lo = cpu_to_le32((u32)blk); 329162306a36Sopenharmony_ci es->s_blocks_count_hi = cpu_to_le32(blk >> 32); 329262306a36Sopenharmony_ci} 329362306a36Sopenharmony_ci 329462306a36Sopenharmony_cistatic inline void ext4_free_blocks_count_set(struct ext4_super_block *es, 329562306a36Sopenharmony_ci ext4_fsblk_t blk) 329662306a36Sopenharmony_ci{ 329762306a36Sopenharmony_ci es->s_free_blocks_count_lo = cpu_to_le32((u32)blk); 329862306a36Sopenharmony_ci es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32); 329962306a36Sopenharmony_ci} 330062306a36Sopenharmony_ci 330162306a36Sopenharmony_cistatic inline void ext4_r_blocks_count_set(struct ext4_super_block *es, 330262306a36Sopenharmony_ci ext4_fsblk_t blk) 330362306a36Sopenharmony_ci{ 330462306a36Sopenharmony_ci es->s_r_blocks_count_lo = cpu_to_le32((u32)blk); 330562306a36Sopenharmony_ci es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32); 330662306a36Sopenharmony_ci} 330762306a36Sopenharmony_ci 330862306a36Sopenharmony_cistatic inline loff_t ext4_isize(struct super_block *sb, 330962306a36Sopenharmony_ci struct ext4_inode *raw_inode) 331062306a36Sopenharmony_ci{ 331162306a36Sopenharmony_ci if (ext4_has_feature_largedir(sb) || 331262306a36Sopenharmony_ci S_ISREG(le16_to_cpu(raw_inode->i_mode))) 331362306a36Sopenharmony_ci return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | 331462306a36Sopenharmony_ci le32_to_cpu(raw_inode->i_size_lo); 331562306a36Sopenharmony_ci 331662306a36Sopenharmony_ci return (loff_t) le32_to_cpu(raw_inode->i_size_lo); 331762306a36Sopenharmony_ci} 331862306a36Sopenharmony_ci 331962306a36Sopenharmony_cistatic inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) 332062306a36Sopenharmony_ci{ 332162306a36Sopenharmony_ci raw_inode->i_size_lo = cpu_to_le32(i_size); 332262306a36Sopenharmony_ci raw_inode->i_size_high = cpu_to_le32(i_size >> 32); 332362306a36Sopenharmony_ci} 332462306a36Sopenharmony_ci 332562306a36Sopenharmony_ci/* 332662306a36Sopenharmony_ci * Reading s_groups_count requires using smp_rmb() afterwards. See 332762306a36Sopenharmony_ci * the locking protocol documented in the comments of ext4_group_add() 332862306a36Sopenharmony_ci * in resize.c 332962306a36Sopenharmony_ci */ 333062306a36Sopenharmony_cistatic inline ext4_group_t ext4_get_groups_count(struct super_block *sb) 333162306a36Sopenharmony_ci{ 333262306a36Sopenharmony_ci ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 333362306a36Sopenharmony_ci 333462306a36Sopenharmony_ci smp_rmb(); 333562306a36Sopenharmony_ci return ngroups; 333662306a36Sopenharmony_ci} 333762306a36Sopenharmony_ci 333862306a36Sopenharmony_cistatic inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 333962306a36Sopenharmony_ci ext4_group_t block_group) 334062306a36Sopenharmony_ci{ 334162306a36Sopenharmony_ci return block_group >> sbi->s_log_groups_per_flex; 334262306a36Sopenharmony_ci} 334362306a36Sopenharmony_ci 334462306a36Sopenharmony_cistatic inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) 334562306a36Sopenharmony_ci{ 334662306a36Sopenharmony_ci return 1 << sbi->s_log_groups_per_flex; 334762306a36Sopenharmony_ci} 334862306a36Sopenharmony_ci 334962306a36Sopenharmony_ci#define ext4_std_error(sb, errno) \ 335062306a36Sopenharmony_cido { \ 335162306a36Sopenharmony_ci if ((errno)) \ 335262306a36Sopenharmony_ci __ext4_std_error((sb), __func__, __LINE__, (errno)); \ 335362306a36Sopenharmony_ci} while (0) 335462306a36Sopenharmony_ci 335562306a36Sopenharmony_ci#ifdef CONFIG_SMP 335662306a36Sopenharmony_ci/* Each CPU can accumulate percpu_counter_batch clusters in their local 335762306a36Sopenharmony_ci * counters. So we need to make sure we have free clusters more 335862306a36Sopenharmony_ci * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. 335962306a36Sopenharmony_ci */ 336062306a36Sopenharmony_ci#define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) 336162306a36Sopenharmony_ci#else 336262306a36Sopenharmony_ci#define EXT4_FREECLUSTERS_WATERMARK 0 336362306a36Sopenharmony_ci#endif 336462306a36Sopenharmony_ci 336562306a36Sopenharmony_ci/* Update i_disksize. Requires i_rwsem to avoid races with truncate */ 336662306a36Sopenharmony_cistatic inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) 336762306a36Sopenharmony_ci{ 336862306a36Sopenharmony_ci WARN_ON_ONCE(S_ISREG(inode->i_mode) && 336962306a36Sopenharmony_ci !inode_is_locked(inode)); 337062306a36Sopenharmony_ci down_write(&EXT4_I(inode)->i_data_sem); 337162306a36Sopenharmony_ci if (newsize > EXT4_I(inode)->i_disksize) 337262306a36Sopenharmony_ci WRITE_ONCE(EXT4_I(inode)->i_disksize, newsize); 337362306a36Sopenharmony_ci up_write(&EXT4_I(inode)->i_data_sem); 337462306a36Sopenharmony_ci} 337562306a36Sopenharmony_ci 337662306a36Sopenharmony_ci/* Update i_size, i_disksize. Requires i_rwsem to avoid races with truncate */ 337762306a36Sopenharmony_cistatic inline int ext4_update_inode_size(struct inode *inode, loff_t newsize) 337862306a36Sopenharmony_ci{ 337962306a36Sopenharmony_ci int changed = 0; 338062306a36Sopenharmony_ci 338162306a36Sopenharmony_ci if (newsize > inode->i_size) { 338262306a36Sopenharmony_ci i_size_write(inode, newsize); 338362306a36Sopenharmony_ci changed = 1; 338462306a36Sopenharmony_ci } 338562306a36Sopenharmony_ci if (newsize > EXT4_I(inode)->i_disksize) { 338662306a36Sopenharmony_ci ext4_update_i_disksize(inode, newsize); 338762306a36Sopenharmony_ci changed |= 2; 338862306a36Sopenharmony_ci } 338962306a36Sopenharmony_ci return changed; 339062306a36Sopenharmony_ci} 339162306a36Sopenharmony_ci 339262306a36Sopenharmony_ciint ext4_update_disksize_before_punch(struct inode *inode, loff_t offset, 339362306a36Sopenharmony_ci loff_t len); 339462306a36Sopenharmony_ci 339562306a36Sopenharmony_cistruct ext4_group_info { 339662306a36Sopenharmony_ci unsigned long bb_state; 339762306a36Sopenharmony_ci#ifdef AGGRESSIVE_CHECK 339862306a36Sopenharmony_ci unsigned long bb_check_counter; 339962306a36Sopenharmony_ci#endif 340062306a36Sopenharmony_ci struct rb_root bb_free_root; 340162306a36Sopenharmony_ci ext4_grpblk_t bb_first_free; /* first free block */ 340262306a36Sopenharmony_ci ext4_grpblk_t bb_free; /* total free blocks */ 340362306a36Sopenharmony_ci ext4_grpblk_t bb_fragments; /* nr of freespace fragments */ 340462306a36Sopenharmony_ci int bb_avg_fragment_size_order; /* order of average 340562306a36Sopenharmony_ci fragment in BG */ 340662306a36Sopenharmony_ci ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */ 340762306a36Sopenharmony_ci ext4_group_t bb_group; /* Group number */ 340862306a36Sopenharmony_ci struct list_head bb_prealloc_list; 340962306a36Sopenharmony_ci#ifdef DOUBLE_CHECK 341062306a36Sopenharmony_ci void *bb_bitmap; 341162306a36Sopenharmony_ci#endif 341262306a36Sopenharmony_ci struct rw_semaphore alloc_sem; 341362306a36Sopenharmony_ci struct list_head bb_avg_fragment_size_node; 341462306a36Sopenharmony_ci struct list_head bb_largest_free_order_node; 341562306a36Sopenharmony_ci ext4_grpblk_t bb_counters[]; /* Nr of free power-of-two-block 341662306a36Sopenharmony_ci * regions, index is order. 341762306a36Sopenharmony_ci * bb_counters[3] = 5 means 341862306a36Sopenharmony_ci * 5 free 8-block regions. */ 341962306a36Sopenharmony_ci}; 342062306a36Sopenharmony_ci 342162306a36Sopenharmony_ci#define EXT4_GROUP_INFO_NEED_INIT_BIT 0 342262306a36Sopenharmony_ci#define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 342362306a36Sopenharmony_ci#define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2 342462306a36Sopenharmony_ci#define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3 342562306a36Sopenharmony_ci#define EXT4_GROUP_INFO_BBITMAP_CORRUPT \ 342662306a36Sopenharmony_ci (1 << EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT) 342762306a36Sopenharmony_ci#define EXT4_GROUP_INFO_IBITMAP_CORRUPT \ 342862306a36Sopenharmony_ci (1 << EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT) 342962306a36Sopenharmony_ci#define EXT4_GROUP_INFO_BBITMAP_READ_BIT 4 343062306a36Sopenharmony_ci 343162306a36Sopenharmony_ci#define EXT4_MB_GRP_NEED_INIT(grp) \ 343262306a36Sopenharmony_ci (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 343362306a36Sopenharmony_ci#define EXT4_MB_GRP_BBITMAP_CORRUPT(grp) \ 343462306a36Sopenharmony_ci (test_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 343562306a36Sopenharmony_ci#define EXT4_MB_GRP_IBITMAP_CORRUPT(grp) \ 343662306a36Sopenharmony_ci (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 343762306a36Sopenharmony_ci 343862306a36Sopenharmony_ci#define EXT4_MB_GRP_WAS_TRIMMED(grp) \ 343962306a36Sopenharmony_ci (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 344062306a36Sopenharmony_ci#define EXT4_MB_GRP_SET_TRIMMED(grp) \ 344162306a36Sopenharmony_ci (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 344262306a36Sopenharmony_ci#define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \ 344362306a36Sopenharmony_ci (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 344462306a36Sopenharmony_ci#define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \ 344562306a36Sopenharmony_ci (test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state))) 344662306a36Sopenharmony_ci 344762306a36Sopenharmony_ci#define EXT4_MAX_CONTENTION 8 344862306a36Sopenharmony_ci#define EXT4_CONTENTION_THRESHOLD 2 344962306a36Sopenharmony_ci 345062306a36Sopenharmony_cistatic inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb, 345162306a36Sopenharmony_ci ext4_group_t group) 345262306a36Sopenharmony_ci{ 345362306a36Sopenharmony_ci return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group); 345462306a36Sopenharmony_ci} 345562306a36Sopenharmony_ci 345662306a36Sopenharmony_ci/* 345762306a36Sopenharmony_ci * Returns true if the filesystem is busy enough that attempts to 345862306a36Sopenharmony_ci * access the block group locks has run into contention. 345962306a36Sopenharmony_ci */ 346062306a36Sopenharmony_cistatic inline int ext4_fs_is_busy(struct ext4_sb_info *sbi) 346162306a36Sopenharmony_ci{ 346262306a36Sopenharmony_ci return (atomic_read(&sbi->s_lock_busy) > EXT4_CONTENTION_THRESHOLD); 346362306a36Sopenharmony_ci} 346462306a36Sopenharmony_ci 346562306a36Sopenharmony_cistatic inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 346662306a36Sopenharmony_ci{ 346762306a36Sopenharmony_ci spinlock_t *lock = ext4_group_lock_ptr(sb, group); 346862306a36Sopenharmony_ci if (spin_trylock(lock)) 346962306a36Sopenharmony_ci /* 347062306a36Sopenharmony_ci * We're able to grab the lock right away, so drop the 347162306a36Sopenharmony_ci * lock contention counter. 347262306a36Sopenharmony_ci */ 347362306a36Sopenharmony_ci atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, -1, 0); 347462306a36Sopenharmony_ci else { 347562306a36Sopenharmony_ci /* 347662306a36Sopenharmony_ci * The lock is busy, so bump the contention counter, 347762306a36Sopenharmony_ci * and then wait on the spin lock. 347862306a36Sopenharmony_ci */ 347962306a36Sopenharmony_ci atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, 1, 348062306a36Sopenharmony_ci EXT4_MAX_CONTENTION); 348162306a36Sopenharmony_ci spin_lock(lock); 348262306a36Sopenharmony_ci } 348362306a36Sopenharmony_ci} 348462306a36Sopenharmony_ci 348562306a36Sopenharmony_cistatic inline void ext4_unlock_group(struct super_block *sb, 348662306a36Sopenharmony_ci ext4_group_t group) 348762306a36Sopenharmony_ci{ 348862306a36Sopenharmony_ci spin_unlock(ext4_group_lock_ptr(sb, group)); 348962306a36Sopenharmony_ci} 349062306a36Sopenharmony_ci 349162306a36Sopenharmony_ci#ifdef CONFIG_QUOTA 349262306a36Sopenharmony_cistatic inline bool ext4_quota_capable(struct super_block *sb) 349362306a36Sopenharmony_ci{ 349462306a36Sopenharmony_ci return (test_opt(sb, QUOTA) || ext4_has_feature_quota(sb)); 349562306a36Sopenharmony_ci} 349662306a36Sopenharmony_ci 349762306a36Sopenharmony_cistatic inline bool ext4_is_quota_journalled(struct super_block *sb) 349862306a36Sopenharmony_ci{ 349962306a36Sopenharmony_ci struct ext4_sb_info *sbi = EXT4_SB(sb); 350062306a36Sopenharmony_ci 350162306a36Sopenharmony_ci return (ext4_has_feature_quota(sb) || 350262306a36Sopenharmony_ci sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]); 350362306a36Sopenharmony_ci} 350462306a36Sopenharmony_ciint ext4_enable_quotas(struct super_block *sb); 350562306a36Sopenharmony_ci#endif 350662306a36Sopenharmony_ci 350762306a36Sopenharmony_ci/* 350862306a36Sopenharmony_ci * Block validity checking 350962306a36Sopenharmony_ci */ 351062306a36Sopenharmony_ci#define ext4_check_indirect_blockref(inode, bh) \ 351162306a36Sopenharmony_ci ext4_check_blockref(__func__, __LINE__, inode, \ 351262306a36Sopenharmony_ci (__le32 *)(bh)->b_data, \ 351362306a36Sopenharmony_ci EXT4_ADDR_PER_BLOCK((inode)->i_sb)) 351462306a36Sopenharmony_ci 351562306a36Sopenharmony_ci#define ext4_ind_check_inode(inode) \ 351662306a36Sopenharmony_ci ext4_check_blockref(__func__, __LINE__, inode, \ 351762306a36Sopenharmony_ci EXT4_I(inode)->i_data, \ 351862306a36Sopenharmony_ci EXT4_NDIR_BLOCKS) 351962306a36Sopenharmony_ci 352062306a36Sopenharmony_ci/* 352162306a36Sopenharmony_ci * Inodes and files operations 352262306a36Sopenharmony_ci */ 352362306a36Sopenharmony_ci 352462306a36Sopenharmony_ci/* dir.c */ 352562306a36Sopenharmony_ciextern const struct file_operations ext4_dir_operations; 352662306a36Sopenharmony_ci 352762306a36Sopenharmony_ci/* file.c */ 352862306a36Sopenharmony_ciextern const struct inode_operations ext4_file_inode_operations; 352962306a36Sopenharmony_ciextern const struct file_operations ext4_file_operations; 353062306a36Sopenharmony_ciextern loff_t ext4_llseek(struct file *file, loff_t offset, int origin); 353162306a36Sopenharmony_ci 353262306a36Sopenharmony_ci/* inline.c */ 353362306a36Sopenharmony_ciextern int ext4_get_max_inline_size(struct inode *inode); 353462306a36Sopenharmony_ciextern int ext4_find_inline_data_nolock(struct inode *inode); 353562306a36Sopenharmony_ciextern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode); 353662306a36Sopenharmony_ci 353762306a36Sopenharmony_ciint ext4_readpage_inline(struct inode *inode, struct folio *folio); 353862306a36Sopenharmony_ciextern int ext4_try_to_write_inline_data(struct address_space *mapping, 353962306a36Sopenharmony_ci struct inode *inode, 354062306a36Sopenharmony_ci loff_t pos, unsigned len, 354162306a36Sopenharmony_ci struct page **pagep); 354262306a36Sopenharmony_ciint ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, 354362306a36Sopenharmony_ci unsigned copied, struct folio *folio); 354462306a36Sopenharmony_ciextern int ext4_da_write_inline_data_begin(struct address_space *mapping, 354562306a36Sopenharmony_ci struct inode *inode, 354662306a36Sopenharmony_ci loff_t pos, unsigned len, 354762306a36Sopenharmony_ci struct page **pagep, 354862306a36Sopenharmony_ci void **fsdata); 354962306a36Sopenharmony_ciextern int ext4_try_add_inline_entry(handle_t *handle, 355062306a36Sopenharmony_ci struct ext4_filename *fname, 355162306a36Sopenharmony_ci struct inode *dir, struct inode *inode); 355262306a36Sopenharmony_ciextern int ext4_try_create_inline_dir(handle_t *handle, 355362306a36Sopenharmony_ci struct inode *parent, 355462306a36Sopenharmony_ci struct inode *inode); 355562306a36Sopenharmony_ciextern int ext4_read_inline_dir(struct file *filp, 355662306a36Sopenharmony_ci struct dir_context *ctx, 355762306a36Sopenharmony_ci int *has_inline_data); 355862306a36Sopenharmony_ciextern int ext4_inlinedir_to_tree(struct file *dir_file, 355962306a36Sopenharmony_ci struct inode *dir, ext4_lblk_t block, 356062306a36Sopenharmony_ci struct dx_hash_info *hinfo, 356162306a36Sopenharmony_ci __u32 start_hash, __u32 start_minor_hash, 356262306a36Sopenharmony_ci int *has_inline_data); 356362306a36Sopenharmony_ciextern struct buffer_head *ext4_find_inline_entry(struct inode *dir, 356462306a36Sopenharmony_ci struct ext4_filename *fname, 356562306a36Sopenharmony_ci struct ext4_dir_entry_2 **res_dir, 356662306a36Sopenharmony_ci int *has_inline_data); 356762306a36Sopenharmony_ciextern int ext4_delete_inline_entry(handle_t *handle, 356862306a36Sopenharmony_ci struct inode *dir, 356962306a36Sopenharmony_ci struct ext4_dir_entry_2 *de_del, 357062306a36Sopenharmony_ci struct buffer_head *bh, 357162306a36Sopenharmony_ci int *has_inline_data); 357262306a36Sopenharmony_ciextern bool empty_inline_dir(struct inode *dir, int *has_inline_data); 357362306a36Sopenharmony_ciextern struct buffer_head *ext4_get_first_inline_block(struct inode *inode, 357462306a36Sopenharmony_ci struct ext4_dir_entry_2 **parent_de, 357562306a36Sopenharmony_ci int *retval); 357662306a36Sopenharmony_ciextern void *ext4_read_inline_link(struct inode *inode); 357762306a36Sopenharmony_ci 357862306a36Sopenharmony_cistruct iomap; 357962306a36Sopenharmony_ciextern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap); 358062306a36Sopenharmony_ci 358162306a36Sopenharmony_ciextern int ext4_inline_data_truncate(struct inode *inode, int *has_inline); 358262306a36Sopenharmony_ci 358362306a36Sopenharmony_ciextern int ext4_convert_inline_data(struct inode *inode); 358462306a36Sopenharmony_ci 358562306a36Sopenharmony_cistatic inline int ext4_has_inline_data(struct inode *inode) 358662306a36Sopenharmony_ci{ 358762306a36Sopenharmony_ci return ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA) && 358862306a36Sopenharmony_ci EXT4_I(inode)->i_inline_off; 358962306a36Sopenharmony_ci} 359062306a36Sopenharmony_ci 359162306a36Sopenharmony_ci/* namei.c */ 359262306a36Sopenharmony_ciextern const struct inode_operations ext4_dir_inode_operations; 359362306a36Sopenharmony_ciextern const struct inode_operations ext4_special_inode_operations; 359462306a36Sopenharmony_ciextern struct dentry *ext4_get_parent(struct dentry *child); 359562306a36Sopenharmony_ciextern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode, 359662306a36Sopenharmony_ci struct ext4_dir_entry_2 *de, 359762306a36Sopenharmony_ci int blocksize, int csum_size, 359862306a36Sopenharmony_ci unsigned int parent_ino, int dotdot_real_len); 359962306a36Sopenharmony_ciextern void ext4_initialize_dirent_tail(struct buffer_head *bh, 360062306a36Sopenharmony_ci unsigned int blocksize); 360162306a36Sopenharmony_ciextern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode, 360262306a36Sopenharmony_ci struct buffer_head *bh); 360362306a36Sopenharmony_ciextern int __ext4_unlink(struct inode *dir, const struct qstr *d_name, 360462306a36Sopenharmony_ci struct inode *inode, struct dentry *dentry); 360562306a36Sopenharmony_ciextern int __ext4_link(struct inode *dir, struct inode *inode, 360662306a36Sopenharmony_ci struct dentry *dentry); 360762306a36Sopenharmony_ci 360862306a36Sopenharmony_ci#define S_SHIFT 12 360962306a36Sopenharmony_cistatic const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { 361062306a36Sopenharmony_ci [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, 361162306a36Sopenharmony_ci [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, 361262306a36Sopenharmony_ci [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, 361362306a36Sopenharmony_ci [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, 361462306a36Sopenharmony_ci [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, 361562306a36Sopenharmony_ci [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, 361662306a36Sopenharmony_ci [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, 361762306a36Sopenharmony_ci}; 361862306a36Sopenharmony_ci 361962306a36Sopenharmony_cistatic inline void ext4_set_de_type(struct super_block *sb, 362062306a36Sopenharmony_ci struct ext4_dir_entry_2 *de, 362162306a36Sopenharmony_ci umode_t mode) { 362262306a36Sopenharmony_ci if (ext4_has_feature_filetype(sb)) 362362306a36Sopenharmony_ci de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 362462306a36Sopenharmony_ci} 362562306a36Sopenharmony_ci 362662306a36Sopenharmony_ci/* readpages.c */ 362762306a36Sopenharmony_ciextern int ext4_mpage_readpages(struct inode *inode, 362862306a36Sopenharmony_ci struct readahead_control *rac, struct folio *folio); 362962306a36Sopenharmony_ciextern int __init ext4_init_post_read_processing(void); 363062306a36Sopenharmony_ciextern void ext4_exit_post_read_processing(void); 363162306a36Sopenharmony_ci 363262306a36Sopenharmony_ci/* symlink.c */ 363362306a36Sopenharmony_ciextern const struct inode_operations ext4_encrypted_symlink_inode_operations; 363462306a36Sopenharmony_ciextern const struct inode_operations ext4_symlink_inode_operations; 363562306a36Sopenharmony_ciextern const struct inode_operations ext4_fast_symlink_inode_operations; 363662306a36Sopenharmony_ci 363762306a36Sopenharmony_ci/* sysfs.c */ 363862306a36Sopenharmony_ciextern void ext4_notify_error_sysfs(struct ext4_sb_info *sbi); 363962306a36Sopenharmony_ciextern int ext4_register_sysfs(struct super_block *sb); 364062306a36Sopenharmony_ciextern void ext4_unregister_sysfs(struct super_block *sb); 364162306a36Sopenharmony_ciextern int __init ext4_init_sysfs(void); 364262306a36Sopenharmony_ciextern void ext4_exit_sysfs(void); 364362306a36Sopenharmony_ci 364462306a36Sopenharmony_ci/* block_validity */ 364562306a36Sopenharmony_ciextern void ext4_release_system_zone(struct super_block *sb); 364662306a36Sopenharmony_ciextern int ext4_setup_system_zone(struct super_block *sb); 364762306a36Sopenharmony_ciextern int __init ext4_init_system_zone(void); 364862306a36Sopenharmony_ciextern void ext4_exit_system_zone(void); 364962306a36Sopenharmony_ciextern int ext4_inode_block_valid(struct inode *inode, 365062306a36Sopenharmony_ci ext4_fsblk_t start_blk, 365162306a36Sopenharmony_ci unsigned int count); 365262306a36Sopenharmony_ciextern int ext4_check_blockref(const char *, unsigned int, 365362306a36Sopenharmony_ci struct inode *, __le32 *, unsigned int); 365462306a36Sopenharmony_ciextern int ext4_sb_block_valid(struct super_block *sb, struct inode *inode, 365562306a36Sopenharmony_ci ext4_fsblk_t start_blk, unsigned int count); 365662306a36Sopenharmony_ci 365762306a36Sopenharmony_ci 365862306a36Sopenharmony_ci/* extents.c */ 365962306a36Sopenharmony_cistruct ext4_ext_path; 366062306a36Sopenharmony_cistruct ext4_extent; 366162306a36Sopenharmony_ci 366262306a36Sopenharmony_ci/* 366362306a36Sopenharmony_ci * Maximum number of logical blocks in a file; ext4_extent's ee_block is 366462306a36Sopenharmony_ci * __le32. 366562306a36Sopenharmony_ci */ 366662306a36Sopenharmony_ci#define EXT_MAX_BLOCKS 0xffffffff 366762306a36Sopenharmony_ci 366862306a36Sopenharmony_ciextern void ext4_ext_tree_init(handle_t *handle, struct inode *inode); 366962306a36Sopenharmony_ciextern int ext4_ext_index_trans_blocks(struct inode *inode, int extents); 367062306a36Sopenharmony_ciextern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, 367162306a36Sopenharmony_ci struct ext4_map_blocks *map, int flags); 367262306a36Sopenharmony_ciextern int ext4_ext_truncate(handle_t *, struct inode *); 367362306a36Sopenharmony_ciextern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, 367462306a36Sopenharmony_ci ext4_lblk_t end); 367562306a36Sopenharmony_ciextern void ext4_ext_init(struct super_block *); 367662306a36Sopenharmony_ciextern void ext4_ext_release(struct super_block *); 367762306a36Sopenharmony_ciextern long ext4_fallocate(struct file *file, int mode, loff_t offset, 367862306a36Sopenharmony_ci loff_t len); 367962306a36Sopenharmony_ciextern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode, 368062306a36Sopenharmony_ci loff_t offset, ssize_t len); 368162306a36Sopenharmony_ciextern int ext4_convert_unwritten_io_end_vec(handle_t *handle, 368262306a36Sopenharmony_ci ext4_io_end_t *io_end); 368362306a36Sopenharmony_ciextern int ext4_map_blocks(handle_t *handle, struct inode *inode, 368462306a36Sopenharmony_ci struct ext4_map_blocks *map, int flags); 368562306a36Sopenharmony_ciextern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, 368662306a36Sopenharmony_ci int num, 368762306a36Sopenharmony_ci struct ext4_ext_path *path); 368862306a36Sopenharmony_ciextern int ext4_ext_insert_extent(handle_t *, struct inode *, 368962306a36Sopenharmony_ci struct ext4_ext_path **, 369062306a36Sopenharmony_ci struct ext4_extent *, int); 369162306a36Sopenharmony_ciextern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, 369262306a36Sopenharmony_ci struct ext4_ext_path **, 369362306a36Sopenharmony_ci int flags); 369462306a36Sopenharmony_ciextern void ext4_free_ext_path(struct ext4_ext_path *); 369562306a36Sopenharmony_ciextern int ext4_ext_check_inode(struct inode *inode); 369662306a36Sopenharmony_ciextern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path); 369762306a36Sopenharmony_ciextern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 369862306a36Sopenharmony_ci __u64 start, __u64 len); 369962306a36Sopenharmony_ciextern int ext4_get_es_cache(struct inode *inode, 370062306a36Sopenharmony_ci struct fiemap_extent_info *fieinfo, 370162306a36Sopenharmony_ci __u64 start, __u64 len); 370262306a36Sopenharmony_ciextern int ext4_ext_precache(struct inode *inode); 370362306a36Sopenharmony_ciextern int ext4_swap_extents(handle_t *handle, struct inode *inode1, 370462306a36Sopenharmony_ci struct inode *inode2, ext4_lblk_t lblk1, 370562306a36Sopenharmony_ci ext4_lblk_t lblk2, ext4_lblk_t count, 370662306a36Sopenharmony_ci int mark_unwritten,int *err); 370762306a36Sopenharmony_ciextern int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu); 370862306a36Sopenharmony_ciextern int ext4_datasem_ensure_credits(handle_t *handle, struct inode *inode, 370962306a36Sopenharmony_ci int check_cred, int restart_cred, 371062306a36Sopenharmony_ci int revoke_cred); 371162306a36Sopenharmony_ciextern void ext4_ext_replay_shrink_inode(struct inode *inode, ext4_lblk_t end); 371262306a36Sopenharmony_ciextern int ext4_ext_replay_set_iblocks(struct inode *inode); 371362306a36Sopenharmony_ciextern int ext4_ext_replay_update_ex(struct inode *inode, ext4_lblk_t start, 371462306a36Sopenharmony_ci int len, int unwritten, ext4_fsblk_t pblk); 371562306a36Sopenharmony_ciextern int ext4_ext_clear_bb(struct inode *inode); 371662306a36Sopenharmony_ci 371762306a36Sopenharmony_ci 371862306a36Sopenharmony_ci/* move_extent.c */ 371962306a36Sopenharmony_ciextern void ext4_double_down_write_data_sem(struct inode *first, 372062306a36Sopenharmony_ci struct inode *second); 372162306a36Sopenharmony_ciextern void ext4_double_up_write_data_sem(struct inode *orig_inode, 372262306a36Sopenharmony_ci struct inode *donor_inode); 372362306a36Sopenharmony_ciextern int ext4_move_extents(struct file *o_filp, struct file *d_filp, 372462306a36Sopenharmony_ci __u64 start_orig, __u64 start_donor, 372562306a36Sopenharmony_ci __u64 len, __u64 *moved_len); 372662306a36Sopenharmony_ci 372762306a36Sopenharmony_ci/* page-io.c */ 372862306a36Sopenharmony_ciextern int __init ext4_init_pageio(void); 372962306a36Sopenharmony_ciextern void ext4_exit_pageio(void); 373062306a36Sopenharmony_ciextern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags); 373162306a36Sopenharmony_ciextern ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end); 373262306a36Sopenharmony_ciextern int ext4_put_io_end(ext4_io_end_t *io_end); 373362306a36Sopenharmony_ciextern void ext4_put_io_end_defer(ext4_io_end_t *io_end); 373462306a36Sopenharmony_ciextern void ext4_io_submit_init(struct ext4_io_submit *io, 373562306a36Sopenharmony_ci struct writeback_control *wbc); 373662306a36Sopenharmony_ciextern void ext4_end_io_rsv_work(struct work_struct *work); 373762306a36Sopenharmony_ciextern void ext4_io_submit(struct ext4_io_submit *io); 373862306a36Sopenharmony_ciint ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *page, 373962306a36Sopenharmony_ci size_t len); 374062306a36Sopenharmony_ciextern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end); 374162306a36Sopenharmony_ciextern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end); 374262306a36Sopenharmony_ci 374362306a36Sopenharmony_ci/* mmp.c */ 374462306a36Sopenharmony_ciextern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); 374562306a36Sopenharmony_ci 374662306a36Sopenharmony_ci/* mmp.c */ 374762306a36Sopenharmony_ciextern void ext4_stop_mmpd(struct ext4_sb_info *sbi); 374862306a36Sopenharmony_ci 374962306a36Sopenharmony_ci/* verity.c */ 375062306a36Sopenharmony_ciextern const struct fsverity_operations ext4_verityops; 375162306a36Sopenharmony_ci 375262306a36Sopenharmony_ci/* orphan.c */ 375362306a36Sopenharmony_ciextern int ext4_orphan_add(handle_t *, struct inode *); 375462306a36Sopenharmony_ciextern int ext4_orphan_del(handle_t *, struct inode *); 375562306a36Sopenharmony_ciextern void ext4_orphan_cleanup(struct super_block *sb, 375662306a36Sopenharmony_ci struct ext4_super_block *es); 375762306a36Sopenharmony_ciextern void ext4_release_orphan_info(struct super_block *sb); 375862306a36Sopenharmony_ciextern int ext4_init_orphan_info(struct super_block *sb); 375962306a36Sopenharmony_ciextern int ext4_orphan_file_empty(struct super_block *sb); 376062306a36Sopenharmony_ciextern void ext4_orphan_file_block_trigger( 376162306a36Sopenharmony_ci struct jbd2_buffer_trigger_type *triggers, 376262306a36Sopenharmony_ci struct buffer_head *bh, 376362306a36Sopenharmony_ci void *data, size_t size); 376462306a36Sopenharmony_ci 376562306a36Sopenharmony_ci/* 376662306a36Sopenharmony_ci * Add new method to test whether block and inode bitmaps are properly 376762306a36Sopenharmony_ci * initialized. With uninit_bg reading the block from disk is not enough 376862306a36Sopenharmony_ci * to mark the bitmap uptodate. We need to also zero-out the bitmap 376962306a36Sopenharmony_ci */ 377062306a36Sopenharmony_ci#define BH_BITMAP_UPTODATE BH_JBDPrivateStart 377162306a36Sopenharmony_ci 377262306a36Sopenharmony_cistatic inline int bitmap_uptodate(struct buffer_head *bh) 377362306a36Sopenharmony_ci{ 377462306a36Sopenharmony_ci return (buffer_uptodate(bh) && 377562306a36Sopenharmony_ci test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state)); 377662306a36Sopenharmony_ci} 377762306a36Sopenharmony_cistatic inline void set_bitmap_uptodate(struct buffer_head *bh) 377862306a36Sopenharmony_ci{ 377962306a36Sopenharmony_ci set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); 378062306a36Sopenharmony_ci} 378162306a36Sopenharmony_ci 378262306a36Sopenharmony_ci/* For ioend & aio unwritten conversion wait queues */ 378362306a36Sopenharmony_ci#define EXT4_WQ_HASH_SZ 37 378462306a36Sopenharmony_ci#define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\ 378562306a36Sopenharmony_ci EXT4_WQ_HASH_SZ]) 378662306a36Sopenharmony_ciextern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; 378762306a36Sopenharmony_ci 378862306a36Sopenharmony_ciextern int ext4_resize_begin(struct super_block *sb); 378962306a36Sopenharmony_ciextern int ext4_resize_end(struct super_block *sb, bool update_backups); 379062306a36Sopenharmony_ci 379162306a36Sopenharmony_cistatic inline void ext4_set_io_unwritten_flag(struct inode *inode, 379262306a36Sopenharmony_ci struct ext4_io_end *io_end) 379362306a36Sopenharmony_ci{ 379462306a36Sopenharmony_ci if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 379562306a36Sopenharmony_ci io_end->flag |= EXT4_IO_END_UNWRITTEN; 379662306a36Sopenharmony_ci atomic_inc(&EXT4_I(inode)->i_unwritten); 379762306a36Sopenharmony_ci } 379862306a36Sopenharmony_ci} 379962306a36Sopenharmony_ci 380062306a36Sopenharmony_cistatic inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) 380162306a36Sopenharmony_ci{ 380262306a36Sopenharmony_ci struct inode *inode = io_end->inode; 380362306a36Sopenharmony_ci 380462306a36Sopenharmony_ci if (io_end->flag & EXT4_IO_END_UNWRITTEN) { 380562306a36Sopenharmony_ci io_end->flag &= ~EXT4_IO_END_UNWRITTEN; 380662306a36Sopenharmony_ci /* Wake up anyone waiting on unwritten extent conversion */ 380762306a36Sopenharmony_ci if (atomic_dec_and_test(&EXT4_I(inode)->i_unwritten)) 380862306a36Sopenharmony_ci wake_up_all(ext4_ioend_wq(inode)); 380962306a36Sopenharmony_ci } 381062306a36Sopenharmony_ci} 381162306a36Sopenharmony_ci 381262306a36Sopenharmony_ciextern const struct iomap_ops ext4_iomap_ops; 381362306a36Sopenharmony_ciextern const struct iomap_ops ext4_iomap_overwrite_ops; 381462306a36Sopenharmony_ciextern const struct iomap_ops ext4_iomap_report_ops; 381562306a36Sopenharmony_ci 381662306a36Sopenharmony_cistatic inline int ext4_buffer_uptodate(struct buffer_head *bh) 381762306a36Sopenharmony_ci{ 381862306a36Sopenharmony_ci /* 381962306a36Sopenharmony_ci * If the buffer has the write error flag, we have failed 382062306a36Sopenharmony_ci * to write out data in the block. In this case, we don't 382162306a36Sopenharmony_ci * have to read the block because we may read the old data 382262306a36Sopenharmony_ci * successfully. 382362306a36Sopenharmony_ci */ 382462306a36Sopenharmony_ci if (buffer_write_io_error(bh)) 382562306a36Sopenharmony_ci set_buffer_uptodate(bh); 382662306a36Sopenharmony_ci return buffer_uptodate(bh); 382762306a36Sopenharmony_ci} 382862306a36Sopenharmony_ci 382962306a36Sopenharmony_ci#endif /* __KERNEL__ */ 383062306a36Sopenharmony_ci 383162306a36Sopenharmony_ci#define EFSBADCRC EBADMSG /* Bad CRC detected */ 383262306a36Sopenharmony_ci#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 383362306a36Sopenharmony_ci 383462306a36Sopenharmony_ci#endif /* _EXT4_H */ 3835