1f5166768STheodore Ts'o // SPDX-License-Identifier: GPL-2.0 23dcf5451SChristoph Hellwig /* 33dcf5451SChristoph Hellwig * ext4.h 43dcf5451SChristoph Hellwig * 53dcf5451SChristoph Hellwig * Copyright (C) 1992, 1993, 1994, 1995 63dcf5451SChristoph Hellwig * Remy Card (card@masi.ibp.fr) 73dcf5451SChristoph Hellwig * Laboratoire MASI - Institut Blaise Pascal 83dcf5451SChristoph Hellwig * Universite Pierre et Marie Curie (Paris VI) 93dcf5451SChristoph Hellwig * 103dcf5451SChristoph Hellwig * from 113dcf5451SChristoph Hellwig * 123dcf5451SChristoph Hellwig * linux/include/linux/minix_fs.h 133dcf5451SChristoph Hellwig * 143dcf5451SChristoph Hellwig * Copyright (C) 1991, 1992 Linus Torvalds 153dcf5451SChristoph Hellwig */ 163dcf5451SChristoph Hellwig 173dcf5451SChristoph Hellwig #ifndef _EXT4_H 183dcf5451SChristoph Hellwig #define _EXT4_H 193dcf5451SChristoph Hellwig 203dcf5451SChristoph Hellwig #include <linux/types.h> 213dcf5451SChristoph Hellwig #include <linux/blkdev.h> 223dcf5451SChristoph Hellwig #include <linux/magic.h> 232ccb5fb9SAneesh Kumar K.V #include <linux/jbd2.h> 2460e58e0fSMingming Cao #include <linux/quota.h> 25d444c3c3STheodore Ts'o #include <linux/rwsem.h> 26d444c3c3STheodore Ts'o #include <linux/rbtree.h> 27d444c3c3STheodore Ts'o #include <linux/seqlock.h> 28d444c3c3STheodore Ts'o #include <linux/mutex.h> 29ca0faba0STheodore Ts'o #include <linux/timer.h> 30a4dad1aeSDavid Turner #include <linux/version.h> 31ca0faba0STheodore Ts'o #include <linux/wait.h> 32174cd4b1SIngo Molnar #include <linux/sched/signal.h> 33ca0faba0STheodore Ts'o #include <linux/blockgroup_lock.h> 34ca0faba0STheodore Ts'o #include <linux/percpu_counter.h> 35efbed4dcSTheodore Ts'o #include <linux/ratelimit.h> 360441984aSDarrick J. Wong #include <crypto/hash.h> 37a633f5a3SLukas Czerner #include <linux/falloc.h> 38c8585c6fSDaeho Jeong #include <linux/percpu-rwsem.h> 3910c5db28SChristoph Hellwig #include <linux/fiemap.h> 404d92dc0fSBen Hutchings #ifdef __KERNEL__ 414d92dc0fSBen Hutchings #include <linux/compat.h> 424d92dc0fSBen Hutchings #endif 433dcf5451SChristoph Hellwig 44734f0d24SDave Chinner #include <linux/fscrypt.h> 45c93d8f88SEric Biggers #include <linux/fsverity.h> 46734f0d24SDave Chinner 47072ebb3bSTheodore Ts'o #include <linux/compiler.h> 48072ebb3bSTheodore Ts'o 493dcf5451SChristoph Hellwig /* 508a35694eSShen Feng * The fourth extended filesystem constants/structures 513dcf5451SChristoph Hellwig */ 523dcf5451SChristoph Hellwig 533dcf5451SChristoph Hellwig /* 54a2821e34SAihua Zhang * with AGGRESSIVE_CHECK allocator runs consistency checks over 55a2821e34SAihua Zhang * structures. these checks slow things down a lot 56a2821e34SAihua Zhang */ 57a2821e34SAihua Zhang #define AGGRESSIVE_CHECK__ 58a2821e34SAihua Zhang 59a2821e34SAihua Zhang /* 60a2821e34SAihua Zhang * with DOUBLE_CHECK defined mballoc creates persistent in-core 61a2821e34SAihua Zhang * bitmaps, maintains and uses them to check for double allocations 62a2821e34SAihua Zhang */ 63a2821e34SAihua Zhang #define DOUBLE_CHECK__ 64a2821e34SAihua Zhang 65a2821e34SAihua Zhang /* 663dcf5451SChristoph Hellwig * Define EXT4FS_DEBUG to produce debug messages 673dcf5451SChristoph Hellwig */ 683dcf5451SChristoph Hellwig #undef EXT4FS_DEBUG 693dcf5451SChristoph Hellwig 703dcf5451SChristoph Hellwig /* 713dcf5451SChristoph Hellwig * Debug code 723dcf5451SChristoph Hellwig */ 733dcf5451SChristoph Hellwig #ifdef EXT4FS_DEBUG 743dcf5451SChristoph Hellwig #define ext4_debug(f, a...) \ 753dcf5451SChristoph Hellwig do { \ 763dcf5451SChristoph Hellwig printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \ 774db9c54aSStoyan Gaydarov __FILE__, __LINE__, __func__); \ 783dcf5451SChristoph Hellwig printk(KERN_DEBUG f, ## a); \ 793dcf5451SChristoph Hellwig } while (0) 803dcf5451SChristoph Hellwig #else 81ace36ad4SJoe Perches #define ext4_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 823dcf5451SChristoph Hellwig #endif 833dcf5451SChristoph Hellwig 844a092d73STheodore Ts'o /* 8570aa1554SRitesh Harjani * Turn on EXT_DEBUG to enable ext4_ext_show_path/leaf/move in extents.c 864a092d73STheodore Ts'o */ 874a092d73STheodore Ts'o #define EXT_DEBUG__ 8870aa1554SRitesh Harjani 8970aa1554SRitesh Harjani /* 9070aa1554SRitesh Harjani * Dynamic printk for controlled extents debugging. 9170aa1554SRitesh Harjani */ 9270aa1554SRitesh Harjani #ifdef CONFIG_EXT4_DEBUG 9370aa1554SRitesh Harjani #define ext_debug(ino, fmt, ...) \ 9470aa1554SRitesh Harjani pr_debug("[%s/%d] EXT4-fs (%s): ino %lu: (%s, %d): %s:" fmt, \ 9570aa1554SRitesh Harjani current->comm, task_pid_nr(current), \ 9670aa1554SRitesh Harjani ino->i_sb->s_id, ino->i_ino, __FILE__, __LINE__, \ 9770aa1554SRitesh Harjani __func__, ##__VA_ARGS__) 984a092d73STheodore Ts'o #else 9970aa1554SRitesh Harjani #define ext_debug(ino, fmt, ...) no_printk(fmt, ##__VA_ARGS__) 1004a092d73STheodore Ts'o #endif 1014a092d73STheodore Ts'o 102d444c3c3STheodore Ts'o /* data type for block offset of block group */ 103d444c3c3STheodore Ts'o typedef int ext4_grpblk_t; 104d444c3c3STheodore Ts'o 105d444c3c3STheodore Ts'o /* data type for filesystem-wide blocks number */ 106d444c3c3STheodore Ts'o typedef unsigned long long ext4_fsblk_t; 107d444c3c3STheodore Ts'o 108d444c3c3STheodore Ts'o /* data type for file logical block number */ 109d444c3c3STheodore Ts'o typedef __u32 ext4_lblk_t; 110d444c3c3STheodore Ts'o 111d444c3c3STheodore Ts'o /* data type for block group number */ 112d444c3c3STheodore Ts'o typedef unsigned int ext4_group_t; 113d444c3c3STheodore Ts'o 114331573feSNamjae Jeon enum SHIFT_DIRECTION { 115331573feSNamjae Jeon SHIFT_LEFT = 0, 116331573feSNamjae Jeon SHIFT_RIGHT, 117331573feSNamjae Jeon }; 118331573feSNamjae Jeon 119296c355cSTheodore Ts'o /* 120296c355cSTheodore Ts'o * Flags used in mballoc's allocation_context flags field. 121296c355cSTheodore Ts'o * 122296c355cSTheodore Ts'o * Also used to show what's going on for debugging purposes when the 123296c355cSTheodore Ts'o * flag field is exported via the traceport interface 124296c355cSTheodore Ts'o */ 125d444c3c3STheodore Ts'o 1263dcf5451SChristoph Hellwig /* prefer goal again. length */ 1270ef90db9STheodore Ts'o #define EXT4_MB_HINT_MERGE 0x0001 1283dcf5451SChristoph Hellwig /* blocks already reserved */ 1290ef90db9STheodore Ts'o #define EXT4_MB_HINT_RESERVED 0x0002 1303dcf5451SChristoph Hellwig /* metadata is being allocated */ 1310ef90db9STheodore Ts'o #define EXT4_MB_HINT_METADATA 0x0004 1323dcf5451SChristoph Hellwig /* first blocks in the file */ 1330ef90db9STheodore Ts'o #define EXT4_MB_HINT_FIRST 0x0008 1343dcf5451SChristoph Hellwig /* search for the best chunk */ 1350ef90db9STheodore Ts'o #define EXT4_MB_HINT_BEST 0x0010 1363dcf5451SChristoph Hellwig /* data is being allocated */ 1370ef90db9STheodore Ts'o #define EXT4_MB_HINT_DATA 0x0020 1383dcf5451SChristoph Hellwig /* don't preallocate (for tails) */ 1390ef90db9STheodore Ts'o #define EXT4_MB_HINT_NOPREALLOC 0x0040 1403dcf5451SChristoph Hellwig /* allocate for locality group */ 1410ef90db9STheodore Ts'o #define EXT4_MB_HINT_GROUP_ALLOC 0x0080 1423dcf5451SChristoph Hellwig /* allocate goal blocks or none */ 1430ef90db9STheodore Ts'o #define EXT4_MB_HINT_GOAL_ONLY 0x0100 1443dcf5451SChristoph Hellwig /* goal is meaningful */ 1450ef90db9STheodore Ts'o #define EXT4_MB_HINT_TRY_GOAL 0x0200 146d2a17637SMingming Cao /* blocks already pre-reserved by delayed allocation */ 1470ef90db9STheodore Ts'o #define EXT4_MB_DELALLOC_RESERVED 0x0400 1484ba74d00STheodore Ts'o /* We are doing stream allocation */ 1494ba74d00STheodore Ts'o #define EXT4_MB_STREAM_ALLOC 0x0800 15055f020dbSAllison Henderson /* Use reserved root blocks if needed */ 15155f020dbSAllison Henderson #define EXT4_MB_USE_ROOT_BLOCKS 0x1000 15227dd4385SLukas Czerner /* Use blocks from reserved pool */ 15327dd4385SLukas Czerner #define EXT4_MB_USE_RESERVED 0x2000 15499377830SRitesh Harjani /* Do strict check for free blocks while retrying block allocation */ 15599377830SRitesh Harjani #define EXT4_MB_STRICT_CHECK 0x4000 1563dcf5451SChristoph Hellwig 1573dcf5451SChristoph Hellwig struct ext4_allocation_request { 1583dcf5451SChristoph Hellwig /* target inode for block we're allocating */ 1593dcf5451SChristoph Hellwig struct inode *inode; 1603dcf5451SChristoph Hellwig /* how many blocks we want to allocate */ 161498e5f24STheodore Ts'o unsigned int len; 162726447d8SEric Sandeen /* logical block in target inode */ 163726447d8SEric Sandeen ext4_lblk_t logical; 164726447d8SEric Sandeen /* the closest logical allocated block to the left */ 165726447d8SEric Sandeen ext4_lblk_t lleft; 166726447d8SEric Sandeen /* the closest logical allocated block to the right */ 167726447d8SEric Sandeen ext4_lblk_t lright; 168726447d8SEric Sandeen /* phys. target (a hint) */ 169726447d8SEric Sandeen ext4_fsblk_t goal; 170726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the left */ 171726447d8SEric Sandeen ext4_fsblk_t pleft; 172726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the right */ 173726447d8SEric Sandeen ext4_fsblk_t pright; 1743dcf5451SChristoph Hellwig /* flags. see above EXT4_MB_HINT_* */ 175498e5f24STheodore Ts'o unsigned int flags; 1763dcf5451SChristoph Hellwig }; 1773dcf5451SChristoph Hellwig 1783dcf5451SChristoph Hellwig /* 179e35fd660STheodore Ts'o * Logical to physical block mapping, used by ext4_map_blocks() 180e35fd660STheodore Ts'o * 181e35fd660STheodore Ts'o * This structure is used to pass requests into ext4_map_blocks() as 182e35fd660STheodore Ts'o * well as to store the information returned by ext4_map_blocks(). It 183e35fd660STheodore Ts'o * takes less room on the stack than a struct buffer_head. 184e35fd660STheodore Ts'o */ 1856db07461SRitesh Harjani #define EXT4_MAP_NEW BIT(BH_New) 1866db07461SRitesh Harjani #define EXT4_MAP_MAPPED BIT(BH_Mapped) 1876db07461SRitesh Harjani #define EXT4_MAP_UNWRITTEN BIT(BH_Unwritten) 1886db07461SRitesh Harjani #define EXT4_MAP_BOUNDARY BIT(BH_Boundary) 189e35fd660STheodore Ts'o #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ 190cbd7584eSJan Kara EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY) 191e35fd660STheodore Ts'o 192e35fd660STheodore Ts'o struct ext4_map_blocks { 193e35fd660STheodore Ts'o ext4_fsblk_t m_pblk; 194e35fd660STheodore Ts'o ext4_lblk_t m_lblk; 195e35fd660STheodore Ts'o unsigned int m_len; 196e35fd660STheodore Ts'o unsigned int m_flags; 197e35fd660STheodore Ts'o }; 198e35fd660STheodore Ts'o 199e35fd660STheodore Ts'o /* 2007727ae52Szhangyi (F) * Block validity checking, system zone rbtree. 2017727ae52Szhangyi (F) */ 2027727ae52Szhangyi (F) struct ext4_system_blocks { 2037727ae52Szhangyi (F) struct rb_root root; 2047727ae52Szhangyi (F) struct rcu_head rcu; 2057727ae52Szhangyi (F) }; 2067727ae52Szhangyi (F) 2077727ae52Szhangyi (F) /* 208bd2d0210STheodore Ts'o * Flags for ext4_io_end->flags 209bd2d0210STheodore Ts'o */ 210bd2d0210STheodore Ts'o #define EXT4_IO_END_UNWRITTEN 0x0001 211bd2d0210STheodore Ts'o 212c8cc8816SRitesh Harjani struct ext4_io_end_vec { 213c8cc8816SRitesh Harjani struct list_head list; /* list of io_end_vec */ 214c8cc8816SRitesh Harjani loff_t offset; /* offset in the file */ 215c8cc8816SRitesh Harjani ssize_t size; /* size of the extent */ 216c8cc8816SRitesh Harjani }; 217c8cc8816SRitesh Harjani 2184188188bSCurt Wohlgemuth /* 219556615dcSLukas Czerner * For converting unwritten extents on a work queue. 'handle' is used for 2206b523df4SJan Kara * buffered writeback. 2214188188bSCurt Wohlgemuth */ 2220031462bSMingming Cao typedef struct ext4_io_end { 2235b3ff237Sjiayingz@google.com (Jiaying Zhang) struct list_head list; /* per-file finished IO list */ 2246b523df4SJan Kara handle_t *handle; /* handle reserved for extent 2256b523df4SJan Kara * conversion */ 2260031462bSMingming Cao struct inode *inode; /* file being written to */ 227b0857d30SJan Kara struct bio *bio; /* Linked list of completed 228b0857d30SJan Kara * bios covering the extent */ 2298d5d02e6SMingming Cao unsigned int flag; /* unwritten or not */ 2303bd6ad7bSJan Kara atomic_t count; /* reference counter */ 231c8cc8816SRitesh Harjani struct list_head list_vec; /* list of ext4_io_end_vec */ 2320031462bSMingming Cao } ext4_io_end_t; 2330031462bSMingming Cao 234bd2d0210STheodore Ts'o struct ext4_io_submit { 2355a33911fSTejun Heo struct writeback_control *io_wbc; 236bd2d0210STheodore Ts'o struct bio *io_bio; 237bd2d0210STheodore Ts'o ext4_io_end_t *io_end; 238bd2d0210STheodore Ts'o sector_t io_next_block; 239bd2d0210STheodore Ts'o }; 240bd2d0210STheodore Ts'o 241b3a3ca8cSTheodore Ts'o /* 2423dcf5451SChristoph Hellwig * Special inodes numbers 2433dcf5451SChristoph Hellwig */ 2443dcf5451SChristoph Hellwig #define EXT4_BAD_INO 1 /* Bad blocks inode */ 2453dcf5451SChristoph Hellwig #define EXT4_ROOT_INO 2 /* Root inode */ 246ae812306SAditya Kali #define EXT4_USR_QUOTA_INO 3 /* User quota inode */ 247ae812306SAditya Kali #define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */ 2483dcf5451SChristoph Hellwig #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */ 2493dcf5451SChristoph Hellwig #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */ 2503dcf5451SChristoph Hellwig #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */ 2513dcf5451SChristoph Hellwig #define EXT4_JOURNAL_INO 8 /* Journal inode */ 2523dcf5451SChristoph Hellwig 2533dcf5451SChristoph Hellwig /* First non-reserved inode for old ext4 filesystems */ 2543dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_FIRST_INO 11 2553dcf5451SChristoph Hellwig 2563dcf5451SChristoph Hellwig /* 2573dcf5451SChristoph Hellwig * Maximal count of links to a file 2583dcf5451SChristoph Hellwig */ 2593dcf5451SChristoph Hellwig #define EXT4_LINK_MAX 65000 2603dcf5451SChristoph Hellwig 2613dcf5451SChristoph Hellwig /* 2623dcf5451SChristoph Hellwig * Macro-instructions used to manage several block sizes 2633dcf5451SChristoph Hellwig */ 2643dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_SIZE 1024 2653dcf5451SChristoph Hellwig #define EXT4_MAX_BLOCK_SIZE 65536 2663dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_LOG_SIZE 10 267fb1813f4SCurt Wohlgemuth #define EXT4_MAX_BLOCK_LOG_SIZE 16 2689e47a4c9STheodore Ts'o #define EXT4_MAX_CLUSTER_LOG_SIZE 30 2693dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2703dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize) 2713dcf5451SChristoph Hellwig #else 2723dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size) 2733dcf5451SChristoph Hellwig #endif 2743dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32)) 275281b5995STheodore Ts'o #define EXT4_CLUSTER_SIZE(s) (EXT4_BLOCK_SIZE(s) << \ 276281b5995STheodore Ts'o EXT4_SB(s)->s_cluster_bits) 2773dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2783dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 279281b5995STheodore Ts'o # define EXT4_CLUSTER_BITS(s) (EXT4_SB(s)->s_cluster_bits) 2803dcf5451SChristoph Hellwig #else 2813dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 2823dcf5451SChristoph Hellwig #endif 2833dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2843dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits) 2853dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size) 2863dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino) 2873dcf5451SChristoph Hellwig #else 2883dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 2893dcf5451SChristoph Hellwig EXT4_GOOD_OLD_INODE_SIZE : \ 2903dcf5451SChristoph Hellwig (s)->s_inode_size) 2913dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 2923dcf5451SChristoph Hellwig EXT4_GOOD_OLD_FIRST_INO : \ 2933dcf5451SChristoph Hellwig (s)->s_first_ino) 2943dcf5451SChristoph Hellwig #endif 2953dcf5451SChristoph Hellwig #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 296518eaa63SFabian Frederick #define EXT4_MAX_BLOCKS(size, offset, blkbits) \ 297518eaa63SFabian Frederick ((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \ 298518eaa63SFabian Frederick blkbits)) 2993dcf5451SChristoph Hellwig 300d5b8f310STheodore Ts'o /* Translate a block number to a cluster number */ 301d5b8f310STheodore Ts'o #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) 302d5b8f310STheodore Ts'o /* Translate a cluster number to a block number */ 303d5b8f310STheodore Ts'o #define EXT4_C2B(sbi, cluster) ((cluster) << (sbi)->s_cluster_bits) 304d5b8f310STheodore Ts'o /* Translate # of blks to # of clusters */ 305d5b8f310STheodore Ts'o #define EXT4_NUM_B2C(sbi, blks) (((blks) + (sbi)->s_cluster_ratio - 1) >> \ 306d5b8f310STheodore Ts'o (sbi)->s_cluster_bits) 307f5a44db5STheodore Ts'o /* Mask out the low bits to get the starting block of the cluster */ 308f5a44db5STheodore Ts'o #define EXT4_PBLK_CMASK(s, pblk) ((pblk) & \ 309f5a44db5STheodore Ts'o ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 310f5a44db5STheodore Ts'o #define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \ 311f5a44db5STheodore Ts'o ~((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 3128fcc3a58SEric Whitney /* Fill in the low bits to get the last block of the cluster */ 3138fcc3a58SEric Whitney #define EXT4_LBLK_CFILL(sbi, lblk) ((lblk) | \ 3148fcc3a58SEric Whitney ((ext4_lblk_t) (sbi)->s_cluster_ratio - 1)) 315f5a44db5STheodore Ts'o /* Get the cluster offset */ 316f5a44db5STheodore Ts'o #define EXT4_PBLK_COFF(s, pblk) ((pblk) & \ 317f5a44db5STheodore Ts'o ((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 318f5a44db5STheodore Ts'o #define EXT4_LBLK_COFF(s, lblk) ((lblk) & \ 319f5a44db5STheodore Ts'o ((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 320d5b8f310STheodore Ts'o 3213dcf5451SChristoph Hellwig /* 3223dcf5451SChristoph Hellwig * Structure of a blocks group descriptor 3233dcf5451SChristoph Hellwig */ 3243dcf5451SChristoph Hellwig struct ext4_group_desc 3253dcf5451SChristoph Hellwig { 3263dcf5451SChristoph Hellwig __le32 bg_block_bitmap_lo; /* Blocks bitmap block */ 3273dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */ 3283dcf5451SChristoph Hellwig __le32 bg_inode_table_lo; /* Inodes table block */ 329560671a0SAneesh Kumar K.V __le16 bg_free_blocks_count_lo;/* Free blocks count */ 330560671a0SAneesh Kumar K.V __le16 bg_free_inodes_count_lo;/* Free inodes count */ 331560671a0SAneesh Kumar K.V __le16 bg_used_dirs_count_lo; /* Directories count */ 3323dcf5451SChristoph Hellwig __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 333e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ 334e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */ 335e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */ 336560671a0SAneesh Kumar K.V __le16 bg_itable_unused_lo; /* Unused inodes count */ 3373dcf5451SChristoph Hellwig __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 3383dcf5451SChristoph Hellwig __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 3393dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ 3403dcf5451SChristoph Hellwig __le32 bg_inode_table_hi; /* Inodes table block MSB */ 3413dcf5451SChristoph Hellwig __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ 3423dcf5451SChristoph Hellwig __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 3433dcf5451SChristoph Hellwig __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 3443dcf5451SChristoph Hellwig __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 345e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ 346e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */ 347e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */ 348e6153918SDarrick J. Wong __u32 bg_reserved; 3493dcf5451SChristoph Hellwig }; 3503dcf5451SChristoph Hellwig 35141a246d1SDarrick J. Wong #define EXT4_BG_INODE_BITMAP_CSUM_HI_END \ 35241a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \ 35341a246d1SDarrick J. Wong sizeof(__le16)) 35441a246d1SDarrick J. Wong #define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \ 35541a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \ 35641a246d1SDarrick J. Wong sizeof(__le16)) 35741a246d1SDarrick J. Wong 358772cb7c8SJose R. Santos /* 359772cb7c8SJose R. Santos * Structure of a flex block group info 360772cb7c8SJose R. Santos */ 361772cb7c8SJose R. Santos 362772cb7c8SJose R. Santos struct flex_groups { 36390ba983fSTheodore Ts'o atomic64_t free_clusters; 3649f24e420STheodore Ts'o atomic_t free_inodes; 3657d39db14STheodore Ts'o atomic_t used_dirs; 366772cb7c8SJose R. Santos }; 367772cb7c8SJose R. Santos 3683dcf5451SChristoph Hellwig #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 3693dcf5451SChristoph Hellwig #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 3703dcf5451SChristoph Hellwig #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 3713dcf5451SChristoph Hellwig 3723dcf5451SChristoph Hellwig /* 3733dcf5451SChristoph Hellwig * Macro-instructions used to manage group descriptors 3743dcf5451SChristoph Hellwig */ 3753dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE 32 3763dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE_64BIT 64 3773dcf5451SChristoph Hellwig #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE 3783dcf5451SChristoph Hellwig #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size) 3793dcf5451SChristoph Hellwig #ifdef __KERNEL__ 3803dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group) 381281b5995STheodore Ts'o # define EXT4_CLUSTERS_PER_GROUP(s) (EXT4_SB(s)->s_clusters_per_group) 3823dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block) 3833dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group) 3843dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits) 3853dcf5451SChristoph Hellwig #else 3863dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 3873dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s)) 3883dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 3893dcf5451SChristoph Hellwig #endif 3903dcf5451SChristoph Hellwig 3913dcf5451SChristoph Hellwig /* 3923dcf5451SChristoph Hellwig * Constants relative to the data blocks 3933dcf5451SChristoph Hellwig */ 3943dcf5451SChristoph Hellwig #define EXT4_NDIR_BLOCKS 12 3953dcf5451SChristoph Hellwig #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS 3963dcf5451SChristoph Hellwig #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) 3973dcf5451SChristoph Hellwig #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) 3983dcf5451SChristoph Hellwig #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) 3993dcf5451SChristoph Hellwig 4003dcf5451SChristoph Hellwig /* 4013dcf5451SChristoph Hellwig * Inode flags 4023dcf5451SChristoph Hellwig */ 4033dcf5451SChristoph Hellwig #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */ 4043dcf5451SChristoph Hellwig #define EXT4_UNRM_FL 0x00000002 /* Undelete */ 4053dcf5451SChristoph Hellwig #define EXT4_COMPR_FL 0x00000004 /* Compress file */ 4063dcf5451SChristoph Hellwig #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */ 4073dcf5451SChristoph Hellwig #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */ 4083dcf5451SChristoph Hellwig #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */ 4093dcf5451SChristoph Hellwig #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */ 4103dcf5451SChristoph Hellwig #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */ 4113dcf5451SChristoph Hellwig /* Reserved for compression usage... */ 4123dcf5451SChristoph Hellwig #define EXT4_DIRTY_FL 0x00000100 4133dcf5451SChristoph Hellwig #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 4143dcf5451SChristoph Hellwig #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */ 4153edc18d8STheodore Ts'o /* nb: was previously EXT2_ECOMPR_FL */ 4163edc18d8STheodore Ts'o #define EXT4_ENCRYPT_FL 0x00000800 /* encrypted file */ 4173dcf5451SChristoph Hellwig /* End compression flags --- maybe not all used */ 4183dcf5451SChristoph Hellwig #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */ 4193dcf5451SChristoph Hellwig #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */ 4203dcf5451SChristoph Hellwig #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 4213dcf5451SChristoph Hellwig #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 4223dcf5451SChristoph Hellwig #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 4233dcf5451SChristoph Hellwig #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 4243dcf5451SChristoph Hellwig #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 4253dcf5451SChristoph Hellwig #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 426c93d8f88SEric Biggers #define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */ 427f710b4b9STheodore Ts'o #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 4284337ecd1SEric Whitney /* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */ 429b383a73fSIra Weiny 430b383a73fSIra Weiny #define EXT4_DAX_FL 0x02000000 /* Inode is DAX */ 431b383a73fSIra Weiny 43267cf5b09STao Ma #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ 4338b4953e1STheodore Ts'o #define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 434de8ff14cSEric Biggers #define EXT4_CASEFOLD_FL 0x40000000 /* Casefolded directory */ 4353dcf5451SChristoph Hellwig #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 4363dcf5451SChristoph Hellwig 4372a12e147SEric Biggers /* User modifiable flags */ 4382a12e147SEric Biggers #define EXT4_FL_USER_MODIFIABLE (EXT4_SECRM_FL | \ 4392a12e147SEric Biggers EXT4_UNRM_FL | \ 4402a12e147SEric Biggers EXT4_COMPR_FL | \ 4412a12e147SEric Biggers EXT4_SYNC_FL | \ 4422a12e147SEric Biggers EXT4_IMMUTABLE_FL | \ 4432a12e147SEric Biggers EXT4_APPEND_FL | \ 4442a12e147SEric Biggers EXT4_NODUMP_FL | \ 4452a12e147SEric Biggers EXT4_NOATIME_FL | \ 4462a12e147SEric Biggers EXT4_JOURNAL_DATA_FL | \ 4472a12e147SEric Biggers EXT4_NOTAIL_FL | \ 4482a12e147SEric Biggers EXT4_DIRSYNC_FL | \ 4492a12e147SEric Biggers EXT4_TOPDIR_FL | \ 4502a12e147SEric Biggers EXT4_EXTENTS_FL | \ 4512a12e147SEric Biggers 0x00400000 /* EXT4_EOFBLOCKS_FL */ | \ 4522a12e147SEric Biggers EXT4_DAX_FL | \ 4532a12e147SEric Biggers EXT4_PROJINHERIT_FL | \ 4542a12e147SEric Biggers EXT4_CASEFOLD_FL) 4552a12e147SEric Biggers 4562a12e147SEric Biggers /* User visible flags */ 4572a12e147SEric Biggers #define EXT4_FL_USER_VISIBLE (EXT4_FL_USER_MODIFIABLE | \ 4582a12e147SEric Biggers EXT4_DIRTY_FL | \ 4592a12e147SEric Biggers EXT4_COMPRBLK_FL | \ 4602a12e147SEric Biggers EXT4_NOCOMPR_FL | \ 4612a12e147SEric Biggers EXT4_ENCRYPT_FL | \ 4622a12e147SEric Biggers EXT4_INDEX_FL | \ 4632a12e147SEric Biggers EXT4_VERITY_FL | \ 4642a12e147SEric Biggers EXT4_INLINE_DATA_FL) 4653dcf5451SChristoph Hellwig 466cb29a02dSEric Biggers /* Flags we can manipulate with through FS_IOC_FSSETXATTR */ 4679b7365fcSLi Xi #define EXT4_FL_XFLAG_VISIBLE (EXT4_SYNC_FL | \ 4689b7365fcSLi Xi EXT4_IMMUTABLE_FL | \ 4699b7365fcSLi Xi EXT4_APPEND_FL | \ 4709b7365fcSLi Xi EXT4_NODUMP_FL | \ 4719b7365fcSLi Xi EXT4_NOATIME_FL | \ 472b383a73fSIra Weiny EXT4_PROJINHERIT_FL | \ 473b383a73fSIra Weiny EXT4_DAX_FL) 4749b7365fcSLi Xi 4758fa43a81SDuane Griffin /* Flags that should be inherited by new inodes from their parent. */ 4768fa43a81SDuane Griffin #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ 4771cd9f097STheodore Ts'o EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ 4788fa43a81SDuane Griffin EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ 479040cb378SLi Xi EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\ 480b383a73fSIra Weiny EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\ 481b383a73fSIra Weiny EXT4_DAX_FL) 4828fa43a81SDuane Griffin 4832dc6b0d4SDuane Griffin /* Flags that are appropriate for regular files (all but dir-specific ones). */ 4847ddf79a1SWang Shilong #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL |\ 4857ddf79a1SWang Shilong EXT4_PROJINHERIT_FL)) 4862dc6b0d4SDuane Griffin 4872dc6b0d4SDuane Griffin /* Flags that are appropriate for non-directories/regular files. */ 4882dc6b0d4SDuane Griffin #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) 4892dc6b0d4SDuane Griffin 490abdc644eSyangerkun /* The only flags that should be swapped */ 491abdc644eSyangerkun #define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL) 492abdc644eSyangerkun 493b383a73fSIra Weiny /* Flags which are mutually exclusive to DAX */ 494b383a73fSIra Weiny #define EXT4_DAX_MUT_EXCL (EXT4_VERITY_FL | EXT4_ENCRYPT_FL |\ 495b383a73fSIra Weiny EXT4_JOURNAL_DATA_FL) 496b383a73fSIra Weiny 4972dc6b0d4SDuane Griffin /* Mask out flags that are inappropriate for the given type of inode. */ 4982dc6b0d4SDuane Griffin static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) 4992dc6b0d4SDuane Griffin { 5002dc6b0d4SDuane Griffin if (S_ISDIR(mode)) 5012dc6b0d4SDuane Griffin return flags; 5022dc6b0d4SDuane Griffin else if (S_ISREG(mode)) 5032dc6b0d4SDuane Griffin return flags & EXT4_REG_FLMASK; 5042dc6b0d4SDuane Griffin else 5052dc6b0d4SDuane Griffin return flags & EXT4_OTHER_FLMASK; 5062dc6b0d4SDuane Griffin } 5072dc6b0d4SDuane Griffin 50812e9b892SDmitry Monakhov /* 50912e9b892SDmitry Monakhov * Inode flags used for atomic set/get 51012e9b892SDmitry Monakhov */ 51112e9b892SDmitry Monakhov enum { 51212e9b892SDmitry Monakhov EXT4_INODE_SECRM = 0, /* Secure deletion */ 51312e9b892SDmitry Monakhov EXT4_INODE_UNRM = 1, /* Undelete */ 51412e9b892SDmitry Monakhov EXT4_INODE_COMPR = 2, /* Compress file */ 51512e9b892SDmitry Monakhov EXT4_INODE_SYNC = 3, /* Synchronous updates */ 51612e9b892SDmitry Monakhov EXT4_INODE_IMMUTABLE = 4, /* Immutable file */ 51712e9b892SDmitry Monakhov EXT4_INODE_APPEND = 5, /* writes to file may only append */ 51812e9b892SDmitry Monakhov EXT4_INODE_NODUMP = 6, /* do not dump file */ 51912e9b892SDmitry Monakhov EXT4_INODE_NOATIME = 7, /* do not update atime */ 52012e9b892SDmitry Monakhov /* Reserved for compression usage... */ 52112e9b892SDmitry Monakhov EXT4_INODE_DIRTY = 8, 52212e9b892SDmitry Monakhov EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */ 52312e9b892SDmitry Monakhov EXT4_INODE_NOCOMPR = 10, /* Don't compress */ 524f542fbe8STheodore Ts'o EXT4_INODE_ENCRYPT = 11, /* Encrypted file */ 52512e9b892SDmitry Monakhov /* End compression flags --- maybe not all used */ 52612e9b892SDmitry Monakhov EXT4_INODE_INDEX = 12, /* hash-indexed directory */ 52712e9b892SDmitry Monakhov EXT4_INODE_IMAGIC = 13, /* AFS directory */ 52812e9b892SDmitry Monakhov EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */ 52912e9b892SDmitry Monakhov EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */ 53012e9b892SDmitry Monakhov EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */ 53112e9b892SDmitry Monakhov EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/ 53212e9b892SDmitry Monakhov EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */ 53312e9b892SDmitry Monakhov EXT4_INODE_EXTENTS = 19, /* Inode uses extents */ 534c93d8f88SEric Biggers EXT4_INODE_VERITY = 20, /* Verity protected inode */ 53512e9b892SDmitry Monakhov EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */ 5364337ecd1SEric Whitney /* 22 was formerly EXT4_INODE_EOFBLOCKS */ 537b383a73fSIra Weiny EXT4_INODE_DAX = 25, /* Inode is DAX */ 53867cf5b09STao Ma EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */ 5398b4953e1STheodore Ts'o EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */ 540de8ff14cSEric Biggers EXT4_INODE_CASEFOLD = 30, /* Casefolded directory */ 54112e9b892SDmitry Monakhov EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ 54212e9b892SDmitry Monakhov }; 54312e9b892SDmitry Monakhov 54412e9b892SDmitry Monakhov /* 5459a4c8019SCarlos Maiolino * Since it's pretty easy to mix up bit numbers and hex values, we use a 5469a4c8019SCarlos Maiolino * build-time check to make sure that EXT4_XXX_FL is consistent with respect to 5479a4c8019SCarlos Maiolino * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost 5489a4c8019SCarlos Maiolino * any extra space in the compiled kernel image, otherwise, the build will fail. 5499a4c8019SCarlos Maiolino * It's important that these values are the same, since we are using 5509a4c8019SCarlos Maiolino * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent 5519a4c8019SCarlos Maiolino * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk 5529a4c8019SCarlos Maiolino * values found in ext2, ext3 and ext4 filesystems, and of course the values 5539a4c8019SCarlos Maiolino * defined in e2fsprogs. 55412e9b892SDmitry Monakhov * 55512e9b892SDmitry Monakhov * It's not paranoia if the Murphy's Law really *is* out to get you. :-) 55612e9b892SDmitry Monakhov */ 5579a4c8019SCarlos Maiolino #define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) 5589a4c8019SCarlos Maiolino #define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) 5599a4c8019SCarlos Maiolino 56012e9b892SDmitry Monakhov static inline void ext4_check_flag_values(void) 56112e9b892SDmitry Monakhov { 56212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SECRM); 56312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(UNRM); 56412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPR); 56512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SYNC); 56612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMMUTABLE); 56712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(APPEND); 56812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NODUMP); 56912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOATIME); 57012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRTY); 57112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPRBLK); 57212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOCOMPR); 5733edc18d8STheodore Ts'o CHECK_FLAG_VALUE(ENCRYPT); 57412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(INDEX); 57512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMAGIC); 57612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(JOURNAL_DATA); 57712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOTAIL); 57812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRSYNC); 57912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(TOPDIR); 58012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(HUGE_FILE); 58112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EXTENTS); 582c93d8f88SEric Biggers CHECK_FLAG_VALUE(VERITY); 58312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EA_INODE); 58467cf5b09STao Ma CHECK_FLAG_VALUE(INLINE_DATA); 5858b4953e1STheodore Ts'o CHECK_FLAG_VALUE(PROJINHERIT); 586de8ff14cSEric Biggers CHECK_FLAG_VALUE(CASEFOLD); 58712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(RESERVED); 58812e9b892SDmitry Monakhov } 58912e9b892SDmitry Monakhov 5903dcf5451SChristoph Hellwig /* Used to pass group descriptor data when online resize is done */ 5913dcf5451SChristoph Hellwig struct ext4_new_group_input { 5923dcf5451SChristoph Hellwig __u32 group; /* Group number for this data */ 5933dcf5451SChristoph Hellwig __u64 block_bitmap; /* Absolute block number of block bitmap */ 5943dcf5451SChristoph Hellwig __u64 inode_bitmap; /* Absolute block number of inode bitmap */ 5953dcf5451SChristoph Hellwig __u64 inode_table; /* Absolute block number of inode table start */ 5963dcf5451SChristoph Hellwig __u32 blocks_count; /* Total number of blocks in this group */ 5973dcf5451SChristoph Hellwig __u16 reserved_blocks; /* Number of reserved blocks in this group */ 5983dcf5451SChristoph Hellwig __u16 unused; 5993dcf5451SChristoph Hellwig }; 6003dcf5451SChristoph Hellwig 6014d92dc0fSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 6024d92dc0fSBen Hutchings struct compat_ext4_new_group_input { 6034d92dc0fSBen Hutchings u32 group; 6044d92dc0fSBen Hutchings compat_u64 block_bitmap; 6054d92dc0fSBen Hutchings compat_u64 inode_bitmap; 6064d92dc0fSBen Hutchings compat_u64 inode_table; 6074d92dc0fSBen Hutchings u32 blocks_count; 6084d92dc0fSBen Hutchings u16 reserved_blocks; 6094d92dc0fSBen Hutchings u16 unused; 6104d92dc0fSBen Hutchings }; 6114d92dc0fSBen Hutchings #endif 6124d92dc0fSBen Hutchings 6133dcf5451SChristoph Hellwig /* The struct ext4_new_group_input in kernel space, with free_blocks_count */ 6143dcf5451SChristoph Hellwig struct ext4_new_group_data { 6153dcf5451SChristoph Hellwig __u32 group; 6163dcf5451SChristoph Hellwig __u64 block_bitmap; 6173dcf5451SChristoph Hellwig __u64 inode_bitmap; 6183dcf5451SChristoph Hellwig __u64 inode_table; 6193dcf5451SChristoph Hellwig __u32 blocks_count; 6203dcf5451SChristoph Hellwig __u16 reserved_blocks; 621d77147ffSharshads __u16 mdata_blocks; 622d77147ffSharshads __u32 free_clusters_count; 6233dcf5451SChristoph Hellwig }; 6243dcf5451SChristoph Hellwig 62533afdcc5SYongqiang Yang /* Indexes used to index group tables in ext4_new_group_data */ 62633afdcc5SYongqiang Yang enum { 62733afdcc5SYongqiang Yang BLOCK_BITMAP = 0, /* block bitmap */ 62833afdcc5SYongqiang Yang INODE_BITMAP, /* inode bitmap */ 62933afdcc5SYongqiang Yang INODE_TABLE, /* inode tables */ 63033afdcc5SYongqiang Yang GROUP_TABLE_COUNT, 63133afdcc5SYongqiang Yang }; 63233afdcc5SYongqiang Yang 6333dcf5451SChristoph Hellwig /* 63479e83036SEric Sandeen * Flags used by ext4_map_blocks() 6353dcf5451SChristoph Hellwig */ 636556615dcSLukas Czerner /* Allocate any needed blocks and/or convert an unwritten 637c2177057STheodore Ts'o extent to be an initialized ext4 */ 6382ac3b6e0STheodore Ts'o #define EXT4_GET_BLOCKS_CREATE 0x0001 639556615dcSLukas Czerner /* Request the creation of an unwritten extent */ 640556615dcSLukas Czerner #define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002 641556615dcSLukas Czerner #define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\ 642c2177057STheodore Ts'o EXT4_GET_BLOCKS_CREATE) 64327dd4385SLukas Czerner /* Caller is from the delayed allocation writeout path 64427dd4385SLukas Czerner * finally doing the actual allocation of delayed blocks */ 64503f5d8bcSJan Kara #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004 6460031462bSMingming Cao /* caller is from the direct IO path, request to creation of an 647556615dcSLukas Czerner unwritten extents if not allocated, split the unwritten 6480031462bSMingming Cao extent if blocks has been preallocated already*/ 649c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_PRE_IO 0x0008 6501296cc85SAneesh Kumar K.V #define EXT4_GET_BLOCKS_CONVERT 0x0010 651c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\ 652556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 653c7064ef1SJiaying Zhang /* Convert extent to initialized after IO complete */ 654c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\ 655556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 65627dd4385SLukas Czerner /* Eventual metadata allocation (due to growing extent tree) 65727dd4385SLukas Czerner * should not fail, so try to use reserved blocks for that.*/ 65827dd4385SLukas Czerner #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020 659556b27abSVivek Haldar /* Don't normalize allocation size (used for fallocate) */ 660556b27abSVivek Haldar #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040 661b8a86845SLukas Czerner /* Convert written extents to unwritten */ 6622dcba478SJan Kara #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100 663c86d8db3SJan Kara /* Write zeros to newly created written extents */ 664c86d8db3SJan Kara #define EXT4_GET_BLOCKS_ZERO 0x0200 665c86d8db3SJan Kara #define EXT4_GET_BLOCKS_CREATE_ZERO (EXT4_GET_BLOCKS_CREATE |\ 666c86d8db3SJan Kara EXT4_GET_BLOCKS_ZERO) 667ee0876bcSJan Kara /* Caller will submit data before dropping transaction handle. This 668ee0876bcSJan Kara * allows jbd2 to avoid submitting data before commit. */ 669ee0876bcSJan Kara #define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400 6703dcf5451SChristoph Hellwig 6713dcf5451SChristoph Hellwig /* 6727869a4a6STheodore Ts'o * The bit position of these flags must not overlap with any of the 673ed8a1a76STheodore Ts'o * EXT4_GET_BLOCKS_*. They are used by ext4_find_extent(), 674107a7bd3STheodore Ts'o * read_extent_tree_block(), ext4_split_extent_at(), 6757869a4a6STheodore Ts'o * ext4_ext_insert_extent(), and ext4_ext_create_new_leaf(). 6767869a4a6STheodore Ts'o * EXT4_EX_NOCACHE is used to indicate that the we shouldn't be 6777869a4a6STheodore Ts'o * caching the extents when reading from the extent tree while a 6787869a4a6STheodore Ts'o * truncate or punch hole operation is in progress. 679107a7bd3STheodore Ts'o */ 680d26e2c4dSTheodore Ts'o #define EXT4_EX_NOCACHE 0x40000000 681d26e2c4dSTheodore Ts'o #define EXT4_EX_FORCE_CACHE 0x20000000 68273c384c0STheodore Ts'o #define EXT4_EX_NOFAIL 0x10000000 683107a7bd3STheodore Ts'o 684107a7bd3STheodore Ts'o /* 685e6362609STheodore Ts'o * Flags used by ext4_free_blocks 686e6362609STheodore Ts'o */ 687e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_METADATA 0x0001 688e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_FORGET 0x0002 6891f2acb60STheodore Ts'o #define EXT4_FREE_BLOCKS_VALIDATED 0x0004 6907132de74SMaxim Patlasov #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008 69184130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010 69284130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020 6939fe67149SEric Whitney #define EXT4_FREE_BLOCKS_RERESERVE_CLUSTER 0x0040 694e6362609STheodore Ts'o 695e6362609STheodore Ts'o /* 6963dcf5451SChristoph Hellwig * ioctl commands 6973dcf5451SChristoph Hellwig */ 6983dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION _IOR('f', 3, long) 6993dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION _IOW('f', 4, long) 7003dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION 7013dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION 7023dcf5451SChristoph Hellwig #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long) 7033dcf5451SChristoph Hellwig #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) 7048eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) 7058eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input) 7068eea80d5STheodore Ts'o #define EXT4_IOC_MIGRATE _IO('f', 9) 707ccd2506bSTheodore Ts'o /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */ 7088eea80d5STheodore Ts'o /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ 709ccd2506bSTheodore Ts'o #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) 710748de673SAkira Fujita #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) 71119c5246dSYongqiang Yang #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) 712393d1d1dSDr. Tilmann Bubeck #define EXT4_IOC_SWAP_BOOT _IO('f', 17) 7137869a4a6STheodore Ts'o #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18) 714b0c013e2STheodore Ts'o /* ioctl codes 19--39 are reserved for fscrypt */ 715b0c013e2STheodore Ts'o #define EXT4_IOC_CLEAR_ES_CACHE _IO('f', 40) 7161ad3ea6eSTheodore Ts'o #define EXT4_IOC_GETSTATE _IOW('f', 41, __u32) 717bb5835edSTheodore Ts'o #define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap) 7183dcf5451SChristoph Hellwig 719e9be2ac7STheodore Ts'o #define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32) 720783d9485STheodore Ts'o 721783d9485STheodore Ts'o /* 722783d9485STheodore Ts'o * Flags for going down operation 723783d9485STheodore Ts'o */ 724783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_DEFAULT 0x0 /* going down */ 725783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */ 726783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */ 727783d9485STheodore Ts'o 7281ad3ea6eSTheodore Ts'o /* 7291ad3ea6eSTheodore Ts'o * Flags returned by EXT4_IOC_GETSTATE 7301ad3ea6eSTheodore Ts'o * 7311ad3ea6eSTheodore Ts'o * We only expose to userspace a subset of the state flags in 7321ad3ea6eSTheodore Ts'o * i_state_flags 7331ad3ea6eSTheodore Ts'o */ 7341ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_EXT_PRECACHED 0x00000001 7351ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_NEW 0x00000002 7361ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_NEWENTRY 0x00000004 7371ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_DA_ALLOC_CLOSE 0x00000008 738783d9485STheodore Ts'o 739899ad0ceSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 7403dcf5451SChristoph Hellwig /* 7413dcf5451SChristoph Hellwig * ioctl commands in 32 bit emulation 7423dcf5451SChristoph Hellwig */ 7433dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION _IOR('f', 3, int) 7443dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION _IOW('f', 4, int) 7453dcf5451SChristoph Hellwig #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int) 7463dcf5451SChristoph Hellwig #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int) 7473dcf5451SChristoph Hellwig #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 7484d92dc0fSBen Hutchings #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input) 7493dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 7503dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 751899ad0ceSBen Hutchings #endif 7523dcf5451SChristoph Hellwig 753bb5835edSTheodore Ts'o /* 754bb5835edSTheodore Ts'o * Returned by EXT4_IOC_GET_ES_CACHE as an additional possible flag. 755bb5835edSTheodore Ts'o * It indicates that the entry in extent status cache is for a hole. 756bb5835edSTheodore Ts'o */ 757bb5835edSTheodore Ts'o #define EXT4_FIEMAP_EXTENT_HOLE 0x08000000 758bb5835edSTheodore Ts'o 759b595076aSUwe Kleine-König /* Max physical block we can address w/o extents */ 760fb0a387dSEric Sandeen #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF 761fb0a387dSEric Sandeen 762bcd8e91fSTheodore Ts'o /* Max logical block we can support */ 7639f44eda1SRitesh Harjani #define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFE 764bcd8e91fSTheodore Ts'o 7653dcf5451SChristoph Hellwig /* 7663dcf5451SChristoph Hellwig * Structure of an inode on the disk 7673dcf5451SChristoph Hellwig */ 7683dcf5451SChristoph Hellwig struct ext4_inode { 7693dcf5451SChristoph Hellwig __le16 i_mode; /* File mode */ 7703dcf5451SChristoph Hellwig __le16 i_uid; /* Low 16 bits of Owner Uid */ 7713dcf5451SChristoph Hellwig __le32 i_size_lo; /* Size in bytes */ 7723dcf5451SChristoph Hellwig __le32 i_atime; /* Access time */ 7733dcf5451SChristoph Hellwig __le32 i_ctime; /* Inode Change time */ 7743dcf5451SChristoph Hellwig __le32 i_mtime; /* Modification time */ 7753dcf5451SChristoph Hellwig __le32 i_dtime; /* Deletion Time */ 7763dcf5451SChristoph Hellwig __le16 i_gid; /* Low 16 bits of Group Id */ 7773dcf5451SChristoph Hellwig __le16 i_links_count; /* Links count */ 7783dcf5451SChristoph Hellwig __le32 i_blocks_lo; /* Blocks count */ 7793dcf5451SChristoph Hellwig __le32 i_flags; /* File flags */ 7803dcf5451SChristoph Hellwig union { 7813dcf5451SChristoph Hellwig struct { 7823dcf5451SChristoph Hellwig __le32 l_i_version; 7833dcf5451SChristoph Hellwig } linux1; 7843dcf5451SChristoph Hellwig struct { 7853dcf5451SChristoph Hellwig __u32 h_i_translator; 7863dcf5451SChristoph Hellwig } hurd1; 7873dcf5451SChristoph Hellwig struct { 7883dcf5451SChristoph Hellwig __u32 m_i_reserved1; 7893dcf5451SChristoph Hellwig } masix1; 7903dcf5451SChristoph Hellwig } osd1; /* OS dependent 1 */ 7913dcf5451SChristoph Hellwig __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ 7923dcf5451SChristoph Hellwig __le32 i_generation; /* File version (for NFS) */ 7933dcf5451SChristoph Hellwig __le32 i_file_acl_lo; /* File ACL */ 7943dcf5451SChristoph Hellwig __le32 i_size_high; 7953dcf5451SChristoph Hellwig __le32 i_obso_faddr; /* Obsoleted fragment address */ 7963dcf5451SChristoph Hellwig union { 7973dcf5451SChristoph Hellwig struct { 7983dcf5451SChristoph Hellwig __le16 l_i_blocks_high; /* were l_i_reserved1 */ 7993dcf5451SChristoph Hellwig __le16 l_i_file_acl_high; 8003dcf5451SChristoph Hellwig __le16 l_i_uid_high; /* these 2 fields */ 8013dcf5451SChristoph Hellwig __le16 l_i_gid_high; /* were reserved2[0] */ 802e6153918SDarrick J. Wong __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */ 803e6153918SDarrick J. Wong __le16 l_i_reserved; 8043dcf5451SChristoph Hellwig } linux2; 8053dcf5451SChristoph Hellwig struct { 8063dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 8073dcf5451SChristoph Hellwig __u16 h_i_mode_high; 8083dcf5451SChristoph Hellwig __u16 h_i_uid_high; 8093dcf5451SChristoph Hellwig __u16 h_i_gid_high; 8103dcf5451SChristoph Hellwig __u32 h_i_author; 8113dcf5451SChristoph Hellwig } hurd2; 8123dcf5451SChristoph Hellwig struct { 8133dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 8143dcf5451SChristoph Hellwig __le16 m_i_file_acl_high; 8153dcf5451SChristoph Hellwig __u32 m_i_reserved2[2]; 8163dcf5451SChristoph Hellwig } masix2; 8173dcf5451SChristoph Hellwig } osd2; /* OS dependent 2 */ 8183dcf5451SChristoph Hellwig __le16 i_extra_isize; 819e6153918SDarrick J. Wong __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ 8203dcf5451SChristoph Hellwig __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 8213dcf5451SChristoph Hellwig __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 8223dcf5451SChristoph Hellwig __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 8233dcf5451SChristoph Hellwig __le32 i_crtime; /* File Creation time */ 8243dcf5451SChristoph Hellwig __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 8253dcf5451SChristoph Hellwig __le32 i_version_hi; /* high 32 bits for 64-bit version */ 8268b4953e1STheodore Ts'o __le32 i_projid; /* Project ID */ 8273dcf5451SChristoph Hellwig }; 8283dcf5451SChristoph Hellwig 829748de673SAkira Fujita struct move_extent { 830748de673SAkira Fujita __u32 reserved; /* should be zero */ 831748de673SAkira Fujita __u32 donor_fd; /* donor file descriptor */ 832748de673SAkira Fujita __u64 orig_start; /* logical start offset in block for orig */ 833748de673SAkira Fujita __u64 donor_start; /* logical start offset in block for donor */ 834748de673SAkira Fujita __u64 len; /* block length to be moved */ 835748de673SAkira Fujita __u64 moved_len; /* moved block length */ 836748de673SAkira Fujita }; 8373dcf5451SChristoph Hellwig 8383dcf5451SChristoph Hellwig #define EXT4_EPOCH_BITS 2 8393dcf5451SChristoph Hellwig #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) 8403dcf5451SChristoph Hellwig #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) 8413dcf5451SChristoph Hellwig 8423dcf5451SChristoph Hellwig /* 8433dcf5451SChristoph Hellwig * Extended fields will fit into an inode if the filesystem was formatted 8443dcf5451SChristoph Hellwig * with large inodes (-I 256 or larger) and there are not currently any EAs 8453dcf5451SChristoph Hellwig * consuming all of the available space. For new inodes we always reserve 8463dcf5451SChristoph Hellwig * enough space for the kernel's known extended fields, but for inodes 8473dcf5451SChristoph Hellwig * created with an old kernel this might not have been the case. None of 8483dcf5451SChristoph Hellwig * the extended inode fields is critical for correct filesystem operation. 8493dcf5451SChristoph Hellwig * This macro checks if a certain field fits in the inode. Note that 8503dcf5451SChristoph Hellwig * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize 8513dcf5451SChristoph Hellwig */ 8523dcf5451SChristoph Hellwig #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \ 8533dcf5451SChristoph Hellwig ((offsetof(typeof(*ext4_inode), field) + \ 8543dcf5451SChristoph Hellwig sizeof((ext4_inode)->field)) \ 8553dcf5451SChristoph Hellwig <= (EXT4_GOOD_OLD_INODE_SIZE + \ 8563dcf5451SChristoph Hellwig (einode)->i_extra_isize)) \ 8573dcf5451SChristoph Hellwig 858a4dad1aeSDavid Turner /* 859a4dad1aeSDavid Turner * We use an encoding that preserves the times for extra epoch "00": 860a4dad1aeSDavid Turner * 861a4dad1aeSDavid Turner * extra msb of adjust for signed 862a4dad1aeSDavid Turner * epoch 32-bit 32-bit tv_sec to 863a4dad1aeSDavid Turner * bits time decoded 64-bit tv_sec 64-bit tv_sec valid time range 864a4dad1aeSDavid Turner * 0 0 1 -0x80000000..-0x00000001 0x000000000 1901-12-13..1969-12-31 865a4dad1aeSDavid Turner * 0 0 0 0x000000000..0x07fffffff 0x000000000 1970-01-01..2038-01-19 866a4dad1aeSDavid Turner * 0 1 1 0x080000000..0x0ffffffff 0x100000000 2038-01-19..2106-02-07 867a4dad1aeSDavid Turner * 0 1 0 0x100000000..0x17fffffff 0x100000000 2106-02-07..2174-02-25 868a4dad1aeSDavid Turner * 1 0 1 0x180000000..0x1ffffffff 0x200000000 2174-02-25..2242-03-16 869a4dad1aeSDavid Turner * 1 0 0 0x200000000..0x27fffffff 0x200000000 2242-03-16..2310-04-04 870a4dad1aeSDavid Turner * 1 1 1 0x280000000..0x2ffffffff 0x300000000 2310-04-04..2378-04-22 871a4dad1aeSDavid Turner * 1 1 0 0x300000000..0x37fffffff 0x300000000 2378-04-22..2446-05-10 872a4dad1aeSDavid Turner * 873a4dad1aeSDavid Turner * Note that previous versions of the kernel on 64-bit systems would 874a4dad1aeSDavid Turner * incorrectly use extra epoch bits 1,1 for dates between 1901 and 875a4dad1aeSDavid Turner * 1970. e2fsck will correct this, assuming that it is run on the 876a4dad1aeSDavid Turner * affected filesystem before 2242. 877a4dad1aeSDavid Turner */ 878a4dad1aeSDavid Turner 8797b62b293SArnd Bergmann static inline __le32 ext4_encode_extra_time(struct timespec64 *time) 8803dcf5451SChristoph Hellwig { 8817b62b293SArnd Bergmann u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK; 882a4dad1aeSDavid Turner return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); 8833dcf5451SChristoph Hellwig } 8843dcf5451SChristoph Hellwig 8857b62b293SArnd Bergmann static inline void ext4_decode_extra_time(struct timespec64 *time, 8867b62b293SArnd Bergmann __le32 extra) 8873dcf5451SChristoph Hellwig { 888cd2d9922STheodore Ts'o if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) 889a4dad1aeSDavid Turner time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 890c1fccc06STheodore Ts'o time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 8913dcf5451SChristoph Hellwig } 8923dcf5451SChristoph Hellwig 8933dcf5451SChristoph Hellwig #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 8943dcf5451SChristoph Hellwig do { \ 89595582b00SDeepa Dinamani if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\ 8964881c497SDeepa Dinamani (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ 8973dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 8987b62b293SArnd Bergmann ext4_encode_extra_time(&(inode)->xtime); \ 89995582b00SDeepa Dinamani } \ 900cba465b4SDeepa Dinamani else \ 9014881c497SDeepa Dinamani (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (inode)->xtime.tv_sec, S32_MIN, S32_MAX)); \ 9023dcf5451SChristoph Hellwig } while (0) 9033dcf5451SChristoph Hellwig 9043dcf5451SChristoph Hellwig #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 9053dcf5451SChristoph Hellwig do { \ 9063dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 9073dcf5451SChristoph Hellwig (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \ 9083dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 9093dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 9103dcf5451SChristoph Hellwig ext4_encode_extra_time(&(einode)->xtime); \ 9113dcf5451SChristoph Hellwig } while (0) 9123dcf5451SChristoph Hellwig 9133dcf5451SChristoph Hellwig #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 9143dcf5451SChristoph Hellwig do { \ 9153dcf5451SChristoph Hellwig (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ 91695582b00SDeepa Dinamani if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ 9177b62b293SArnd Bergmann ext4_decode_extra_time(&(inode)->xtime, \ 9183dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 91995582b00SDeepa Dinamani } \ 920af0b44a1SEric Sandeen else \ 921af0b44a1SEric Sandeen (inode)->xtime.tv_nsec = 0; \ 9223dcf5451SChristoph Hellwig } while (0) 9233dcf5451SChristoph Hellwig 92495582b00SDeepa Dinamani 9253dcf5451SChristoph Hellwig #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 9263dcf5451SChristoph Hellwig do { \ 9273dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 9283dcf5451SChristoph Hellwig (einode)->xtime.tv_sec = \ 9293dcf5451SChristoph Hellwig (signed)le32_to_cpu((raw_inode)->xtime); \ 93019ea8060STheodore Ts'o else \ 93119ea8060STheodore Ts'o (einode)->xtime.tv_sec = 0; \ 9323dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 9333dcf5451SChristoph Hellwig ext4_decode_extra_time(&(einode)->xtime, \ 9343dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 935af0b44a1SEric Sandeen else \ 936af0b44a1SEric Sandeen (einode)->xtime.tv_nsec = 0; \ 9373dcf5451SChristoph Hellwig } while (0) 9383dcf5451SChristoph Hellwig 9393dcf5451SChristoph Hellwig #define i_disk_version osd1.linux1.l_i_version 9403dcf5451SChristoph Hellwig 9413dcf5451SChristoph Hellwig #if defined(__KERNEL__) || defined(__linux__) 9423dcf5451SChristoph Hellwig #define i_reserved1 osd1.linux1.l_i_reserved1 9433dcf5451SChristoph Hellwig #define i_file_acl_high osd2.linux2.l_i_file_acl_high 9443dcf5451SChristoph Hellwig #define i_blocks_high osd2.linux2.l_i_blocks_high 9453dcf5451SChristoph Hellwig #define i_uid_low i_uid 9463dcf5451SChristoph Hellwig #define i_gid_low i_gid 9473dcf5451SChristoph Hellwig #define i_uid_high osd2.linux2.l_i_uid_high 9483dcf5451SChristoph Hellwig #define i_gid_high osd2.linux2.l_i_gid_high 949e6153918SDarrick J. Wong #define i_checksum_lo osd2.linux2.l_i_checksum_lo 9503dcf5451SChristoph Hellwig 9513dcf5451SChristoph Hellwig #elif defined(__GNU__) 9523dcf5451SChristoph Hellwig 9533dcf5451SChristoph Hellwig #define i_translator osd1.hurd1.h_i_translator 9543dcf5451SChristoph Hellwig #define i_uid_high osd2.hurd2.h_i_uid_high 9553dcf5451SChristoph Hellwig #define i_gid_high osd2.hurd2.h_i_gid_high 9563dcf5451SChristoph Hellwig #define i_author osd2.hurd2.h_i_author 9573dcf5451SChristoph Hellwig 9583dcf5451SChristoph Hellwig #elif defined(__masix__) 9593dcf5451SChristoph Hellwig 9603dcf5451SChristoph Hellwig #define i_reserved1 osd1.masix1.m_i_reserved1 9613dcf5451SChristoph Hellwig #define i_file_acl_high osd2.masix2.m_i_file_acl_high 9623dcf5451SChristoph Hellwig #define i_reserved2 osd2.masix2.m_i_reserved2 9633dcf5451SChristoph Hellwig 9643dcf5451SChristoph Hellwig #endif /* defined(__KERNEL__) || defined(__linux__) */ 9653dcf5451SChristoph Hellwig 966c0677e6dSZheng Liu #include "extents_status.h" 967c0677e6dSZheng Liu 968d444c3c3STheodore Ts'o /* 969daf647d2STheodore Ts'o * Lock subclasses for i_data_sem in the ext4_inode_info structure. 970daf647d2STheodore Ts'o * 971daf647d2STheodore Ts'o * These are needed to avoid lockdep false positives when we need to 972daf647d2STheodore Ts'o * allocate blocks to the quota inode during ext4_map_blocks(), while 973daf647d2STheodore Ts'o * holding i_data_sem for a normal (non-quota) inode. Since we don't 974daf647d2STheodore Ts'o * do quota tracking for the quota inode, this avoids deadlock (as 975daf647d2STheodore Ts'o * well as infinite recursion, since it isn't turtles all the way 976daf647d2STheodore Ts'o * down...) 977daf647d2STheodore Ts'o * 978daf647d2STheodore Ts'o * I_DATA_SEM_NORMAL - Used for most inodes 979daf647d2STheodore Ts'o * I_DATA_SEM_OTHER - Used by move_inode.c for the second normal inode 980daf647d2STheodore Ts'o * where the second inode has larger inode number 981daf647d2STheodore Ts'o * than the first 982daf647d2STheodore Ts'o * I_DATA_SEM_QUOTA - Used for quota inodes only 983daf647d2STheodore Ts'o */ 984daf647d2STheodore Ts'o enum { 985daf647d2STheodore Ts'o I_DATA_SEM_NORMAL = 0, 986daf647d2STheodore Ts'o I_DATA_SEM_OTHER, 987daf647d2STheodore Ts'o I_DATA_SEM_QUOTA, 988daf647d2STheodore Ts'o }; 989daf647d2STheodore Ts'o 990daf647d2STheodore Ts'o 991daf647d2STheodore Ts'o /* 992d444c3c3STheodore Ts'o * fourth extended file system inode data in memory 993d444c3c3STheodore Ts'o */ 994d444c3c3STheodore Ts'o struct ext4_inode_info { 995d444c3c3STheodore Ts'o __le32 i_data[15]; /* unconverted */ 996d444c3c3STheodore Ts'o __u32 i_dtime; 99712e9b892SDmitry Monakhov ext4_fsblk_t i_file_acl; 998d444c3c3STheodore Ts'o 999d444c3c3STheodore Ts'o /* 1000d444c3c3STheodore Ts'o * i_block_group is the number of the block group which contains 1001d444c3c3STheodore Ts'o * this file's inode. Constant across the lifetime of the inode, 1002a627b0a7SEric Whitney * it is used for making block allocation decisions - we try to 1003d444c3c3STheodore Ts'o * place a file's data blocks near its inode block, and new inodes 1004d444c3c3STheodore Ts'o * near to their parent directory's inode. 1005d444c3c3STheodore Ts'o */ 1006d444c3c3STheodore Ts'o ext4_group_t i_block_group; 10078a2005d3STheodore Ts'o ext4_lblk_t i_dir_start_lookup; 1008353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 100919f5fb7aSTheodore Ts'o unsigned long i_state_flags; /* Dynamic state flags */ 1010353eb83cSTheodore Ts'o #endif 101112e9b892SDmitry Monakhov unsigned long i_flags; 1012d444c3c3STheodore Ts'o 1013d444c3c3STheodore Ts'o /* 1014d444c3c3STheodore Ts'o * Extended attributes can be read independently of the main file 1015d444c3c3STheodore Ts'o * data. Taking i_mutex even when reading would cause contention 1016d444c3c3STheodore Ts'o * between readers of EAs and writers of regular file data, so 1017d444c3c3STheodore Ts'o * instead we synchronize on xattr_sem when reading or changing 1018d444c3c3STheodore Ts'o * EAs. 1019d444c3c3STheodore Ts'o */ 1020d444c3c3STheodore Ts'o struct rw_semaphore xattr_sem; 1021d444c3c3STheodore Ts'o 1022d444c3c3STheodore Ts'o struct list_head i_orphan; /* unlinked but open inodes */ 1023d444c3c3STheodore Ts'o 1024d444c3c3STheodore Ts'o /* 1025d444c3c3STheodore Ts'o * i_disksize keeps track of what the inode size is ON DISK, not 1026d444c3c3STheodore Ts'o * in memory. During truncate, i_size is set to the new size by 1027d444c3c3STheodore Ts'o * the VFS prior to calling ext4_truncate(), but the filesystem won't 1028d444c3c3STheodore Ts'o * set i_disksize to 0 until the truncate is actually under way. 1029d444c3c3STheodore Ts'o * 1030d444c3c3STheodore Ts'o * The intent is that i_disksize always represents the blocks which 1031d444c3c3STheodore Ts'o * are used by this file. This allows recovery to restart truncate 1032d444c3c3STheodore Ts'o * on orphans if we crash during truncate. We actually write i_disksize 1033d444c3c3STheodore Ts'o * into the on-disk inode when writing inodes out, instead of i_size. 1034d444c3c3STheodore Ts'o * 1035d444c3c3STheodore Ts'o * The only time when i_disksize and i_size may be different is when 1036d444c3c3STheodore Ts'o * a truncate is in progress. The only things which change i_disksize 1037d444c3c3STheodore Ts'o * are ext4_get_block (growth) and ext4_truncate (shrinkth). 1038d444c3c3STheodore Ts'o */ 1039d444c3c3STheodore Ts'o loff_t i_disksize; 1040d444c3c3STheodore Ts'o 1041d444c3c3STheodore Ts'o /* 1042d444c3c3STheodore Ts'o * i_data_sem is for serialising ext4_truncate() against 1043d444c3c3STheodore Ts'o * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's 1044d444c3c3STheodore Ts'o * data tree are chopped off during truncate. We can't do that in 1045d444c3c3STheodore Ts'o * ext4 because whenever we perform intermediate commits during 1046d444c3c3STheodore Ts'o * truncate, the inode and all the metadata blocks *must* be in a 1047d444c3c3STheodore Ts'o * consistent state which allows truncation of the orphans to restart 1048d444c3c3STheodore Ts'o * during recovery. Hence we must fix the get_block-vs-truncate race 1049d444c3c3STheodore Ts'o * by other means, so we have i_data_sem. 1050d444c3c3STheodore Ts'o */ 1051d444c3c3STheodore Ts'o struct rw_semaphore i_data_sem; 1052ea3d7209SJan Kara /* 1053ea3d7209SJan Kara * i_mmap_sem is for serializing page faults with truncate / punch hole 1054ea3d7209SJan Kara * operations. We have to make sure that new page cannot be faulted in 1055ea3d7209SJan Kara * a section of the inode that is being punched. We cannot easily use 1056ea3d7209SJan Kara * i_data_sem for this since we need protection for the whole punch 1057ea3d7209SJan Kara * operation and i_data_sem ranks below transaction start so we have 1058ea3d7209SJan Kara * to occasionally drop it. 1059ea3d7209SJan Kara */ 1060ea3d7209SJan Kara struct rw_semaphore i_mmap_sem; 1061d444c3c3STheodore Ts'o struct inode vfs_inode; 10628aefcd55STheodore Ts'o struct jbd2_inode *jinode; 1063d444c3c3STheodore Ts'o 1064202ee5dfSTheodore Ts'o spinlock_t i_raw_lock; /* protects updates to the raw inode */ 1065202ee5dfSTheodore Ts'o 1066d444c3c3STheodore Ts'o /* 1067d444c3c3STheodore Ts'o * File creation time. Its function is same as that of 10687b62b293SArnd Bergmann * struct timespec64 i_{a,c,m}time in the generic inode. 1069d444c3c3STheodore Ts'o */ 10707b62b293SArnd Bergmann struct timespec64 i_crtime; 1071d444c3c3STheodore Ts'o 1072d444c3c3STheodore Ts'o /* mballoc */ 1073d444c3c3STheodore Ts'o struct list_head i_prealloc_list; 1074d444c3c3STheodore Ts'o spinlock_t i_prealloc_lock; 1075d444c3c3STheodore Ts'o 1076c0677e6dSZheng Liu /* extents status tree */ 1077c0677e6dSZheng Liu struct ext4_es_tree i_es_tree; 1078c0677e6dSZheng Liu rwlock_t i_es_lock; 1079edaa53caSZheng Liu struct list_head i_es_list; 1080eb68d0e2SZheng Liu unsigned int i_es_all_nr; /* protected by i_es_lock */ 1081edaa53caSZheng Liu unsigned int i_es_shk_nr; /* protected by i_es_lock */ 1082dd475925SJan Kara ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for 1083dd475925SJan Kara extents to shrink. Protected by 1084dd475925SJan Kara i_es_lock */ 1085c0677e6dSZheng Liu 1086d444c3c3STheodore Ts'o /* ialloc */ 1087d444c3c3STheodore Ts'o ext4_group_t i_last_alloc_group; 1088d444c3c3STheodore Ts'o 1089d444c3c3STheodore Ts'o /* allocation reservation info for delalloc */ 1090a627b0a7SEric Whitney /* In case of bigalloc, this refer to clusters rather than blocks */ 1091d444c3c3STheodore Ts'o unsigned int i_reserved_data_blocks; 1092d444c3c3STheodore Ts'o 10931dc0aa46SEric Whitney /* pending cluster reservations for bigalloc file systems */ 10941dc0aa46SEric Whitney struct ext4_pending_tree i_pending_tree; 10951dc0aa46SEric Whitney 1096d444c3c3STheodore Ts'o /* on-disk additional length */ 1097d444c3c3STheodore Ts'o __u16 i_extra_isize; 1098d444c3c3STheodore Ts'o 109967cf5b09STao Ma /* Indicate the inline data space. */ 110067cf5b09STao Ma u16 i_inline_off; 110167cf5b09STao Ma u16 i_inline_size; 110267cf5b09STao Ma 1103a9e7f447SDmitry Monakhov #ifdef CONFIG_QUOTA 1104a9e7f447SDmitry Monakhov /* quota space reservation, managed internally by quota code */ 1105a9e7f447SDmitry Monakhov qsize_t i_reserved_quota; 1106a9e7f447SDmitry Monakhov #endif 11078d5d02e6SMingming Cao 11082e8fa54eSJan Kara /* Lock protecting lists below */ 1109744692dcSJiaying Zhang spinlock_t i_completed_io_lock; 11102e8fa54eSJan Kara /* 11112e8fa54eSJan Kara * Completed IOs that need unwritten extents handling and have 11122e8fa54eSJan Kara * transaction reserved 11132e8fa54eSJan Kara */ 11142e8fa54eSJan Kara struct list_head i_rsv_conversion_list; 11152e8fa54eSJan Kara struct work_struct i_rsv_conversion_work; 1116600be30aSJan Kara atomic_t i_unwritten; /* Nr. of inflight conversions pending */ 11178a2005d3STheodore Ts'o 11188a2005d3STheodore Ts'o spinlock_t i_block_reservation_lock; 1119b436b9beSJan Kara 1120b436b9beSJan Kara /* 1121b436b9beSJan Kara * Transactions that contain inode's metadata needed to complete 1122b436b9beSJan Kara * fsync and fdatasync, respectively. 1123b436b9beSJan Kara */ 1124b436b9beSJan Kara tid_t i_sync_tid; 1125b436b9beSJan Kara tid_t i_datasync_tid; 1126814525f4SDarrick J. Wong 112796c7e0d9SJan Kara #ifdef CONFIG_QUOTA 112896c7e0d9SJan Kara struct dquot *i_dquot[MAXQUOTAS]; 112996c7e0d9SJan Kara #endif 113096c7e0d9SJan Kara 1131814525f4SDarrick J. Wong /* Precomputed uuid+inum+igen checksum for seeding inode checksums */ 1132814525f4SDarrick J. Wong __u32 i_csum_seed; 1133b30ab0e0SMichael Halcrow 1134040cb378SLi Xi kprojid_t i_projid; 1135d444c3c3STheodore Ts'o }; 1136d444c3c3STheodore Ts'o 1137d444c3c3STheodore Ts'o /* 11383dcf5451SChristoph Hellwig * File system states 11393dcf5451SChristoph Hellwig */ 11403dcf5451SChristoph Hellwig #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 11413dcf5451SChristoph Hellwig #define EXT4_ERROR_FS 0x0002 /* Errors detected */ 11423dcf5451SChristoph Hellwig #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ 11433dcf5451SChristoph Hellwig 11443dcf5451SChristoph Hellwig /* 11453dcf5451SChristoph Hellwig * Misc. filesystem flags 11463dcf5451SChristoph Hellwig */ 11473dcf5451SChristoph Hellwig #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ 11483dcf5451SChristoph Hellwig #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ 11493dcf5451SChristoph Hellwig #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ 11503dcf5451SChristoph Hellwig 11513dcf5451SChristoph Hellwig /* 115268911009SLukas Czerner * Mount flags set via mount options or defaults 11533dcf5451SChristoph Hellwig */ 1154cdb7ee4cSTahsin Erdogan #define EXT4_MOUNT_NO_MBCACHE 0x00001 /* Do not use mbcache */ 11553dcf5451SChristoph Hellwig #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 11563dcf5451SChristoph Hellwig #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 11573dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 11583dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 11593dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 116039ef17f1STheodore Ts'o #define EXT4_MOUNT_ERRORS_MASK 0x00070 11613dcf5451SChristoph Hellwig #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 11623dcf5451SChristoph Hellwig #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 1163923ae0ffSRoss Zwisler #ifdef CONFIG_FS_DAX 1164fc626fe3SIra Weiny #define EXT4_MOUNT_DAX_ALWAYS 0x00200 /* Direct Access */ 1165923ae0ffSRoss Zwisler #else 1166fc626fe3SIra Weiny #define EXT4_MOUNT_DAX_ALWAYS 0 1167923ae0ffSRoss Zwisler #endif 11683dcf5451SChristoph Hellwig #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 11693dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 11703dcf5451SChristoph Hellwig #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 11713dcf5451SChristoph Hellwig #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 11723dcf5451SChristoph Hellwig #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 11733dcf5451SChristoph Hellwig #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 11743dcf5451SChristoph Hellwig #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 11753dcf5451SChristoph Hellwig #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 1176afd4672dSTheodore Ts'o #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 11773dcf5451SChristoph Hellwig #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 117849da9392SJan Kara #define EXT4_MOUNT_QUOTA 0x40000 /* Some quota option set */ 117949da9392SJan Kara #define EXT4_MOUNT_USRQUOTA 0x80000 /* "old" user quota, 118049da9392SJan Kara * enable enforcement for hidden 118149da9392SJan Kara * quota files */ 118249da9392SJan Kara #define EXT4_MOUNT_GRPQUOTA 0x100000 /* "old" group quota, enable 118349da9392SJan Kara * enforcement for hidden quota 118449da9392SJan Kara * files */ 118549da9392SJan Kara #define EXT4_MOUNT_PRJQUOTA 0x200000 /* Enable project quota 118649da9392SJan Kara * enforcement */ 1187744692dcSJiaying Zhang #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */ 1188d4da6c9cSLinus Torvalds #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 11893dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 1190327eaf73STheodore Ts'o #define EXT4_MOUNT_WARN_ON_ERROR 0x2000000 /* Trigger WARN_ON on error */ 11913d392b26STheodore Ts'o #define EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS 0x4000000 119264769240SAlex Tomas #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 11935bf5683aSHidehiro Kawai #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 11946fd058f7STheodore Ts'o #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */ 11955328e635SEric Sandeen #define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */ 1196bfff6873SLukas Czerner #define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */ 11975bf5683aSHidehiro Kawai 119868911009SLukas Czerner /* 119968911009SLukas Czerner * Mount flags set either automatically (could not be set by mount option) 120068911009SLukas Czerner * based on per file system feature or property or in special cases such as 120168911009SLukas Czerner * distinguishing between explicit mount option definition and default. 120268911009SLukas Czerner */ 120356889787STheodore Ts'o #define EXT4_MOUNT2_EXPLICIT_DELALLOC 0x00000001 /* User explicitly 120456889787STheodore Ts'o specified delalloc */ 120568911009SLukas Czerner #define EXT4_MOUNT2_STD_GROUP_SIZE 0x00000002 /* We have standard group 120668911009SLukas Czerner size of blocksize * 8 120768911009SLukas Czerner blocks */ 1208ed3654ebSTheodore Ts'o #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated 1209ed3654ebSTheodore Ts'o file systems */ 12109cb20f94SIra Weiny #define EXT4_MOUNT2_DAX_NEVER 0x00000008 /* Do not allow Direct Access */ 12119cb20f94SIra Weiny #define EXT4_MOUNT2_DAX_INODE 0x00000010 /* For printing options only */ 121256889787STheodore Ts'o 12131e381f60SDmitry Monakhov #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly 12141e381f60SDmitry Monakhov specified journal checksum */ 12151e381f60SDmitry Monakhov 1216fd8c37ecSTheodore Ts'o #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ 1217fd8c37ecSTheodore Ts'o ~EXT4_MOUNT_##opt 1218fd8c37ecSTheodore Ts'o #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \ 1219fd8c37ecSTheodore Ts'o EXT4_MOUNT_##opt 12203dcf5451SChristoph Hellwig #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \ 12213dcf5451SChristoph Hellwig EXT4_MOUNT_##opt) 12223dcf5451SChristoph Hellwig 1223a2595b8aSTheodore Ts'o #define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \ 1224a2595b8aSTheodore Ts'o ~EXT4_MOUNT2_##opt 1225a2595b8aSTheodore Ts'o #define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \ 1226a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt 1227a2595b8aSTheodore Ts'o #define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \ 1228a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt) 1229a2595b8aSTheodore Ts'o 1230597d508cSAkinobu Mita #define ext4_test_and_set_bit __test_and_set_bit_le 1231597d508cSAkinobu Mita #define ext4_set_bit __set_bit_le 12323dcf5451SChristoph Hellwig #define ext4_set_bit_atomic ext2_set_bit_atomic 1233597d508cSAkinobu Mita #define ext4_test_and_clear_bit __test_and_clear_bit_le 1234597d508cSAkinobu Mita #define ext4_clear_bit __clear_bit_le 12353dcf5451SChristoph Hellwig #define ext4_clear_bit_atomic ext2_clear_bit_atomic 123650e0168cSAkinobu Mita #define ext4_test_bit test_bit_le 123750e0168cSAkinobu Mita #define ext4_find_next_zero_bit find_next_zero_bit_le 123850e0168cSAkinobu Mita #define ext4_find_next_bit find_next_bit_le 12393dcf5451SChristoph Hellwig 1240c3e94d1dSYongqiang Yang extern void ext4_set_bits(void *bm, int cur, int len); 1241c3e94d1dSYongqiang Yang 12423dcf5451SChristoph Hellwig /* 12433dcf5451SChristoph Hellwig * Maximal mount counts between two filesystem checks 12443dcf5451SChristoph Hellwig */ 12453dcf5451SChristoph Hellwig #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 12463dcf5451SChristoph Hellwig #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 12473dcf5451SChristoph Hellwig 12483dcf5451SChristoph Hellwig /* 12493dcf5451SChristoph Hellwig * Behaviour when detecting errors 12503dcf5451SChristoph Hellwig */ 12513dcf5451SChristoph Hellwig #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */ 12523dcf5451SChristoph Hellwig #define EXT4_ERRORS_RO 2 /* Remount fs read-only */ 12533dcf5451SChristoph Hellwig #define EXT4_ERRORS_PANIC 3 /* Panic */ 12543dcf5451SChristoph Hellwig #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 12553dcf5451SChristoph Hellwig 1256e6153918SDarrick J. Wong /* Metadata checksum algorithm codes */ 1257e6153918SDarrick J. Wong #define EXT4_CRC32C_CHKSUM 1 1258e6153918SDarrick J. Wong 12593dcf5451SChristoph Hellwig /* 12603dcf5451SChristoph Hellwig * Structure of the super block 12613dcf5451SChristoph Hellwig */ 12623dcf5451SChristoph Hellwig struct ext4_super_block { 12633dcf5451SChristoph Hellwig /*00*/ __le32 s_inodes_count; /* Inodes count */ 12643dcf5451SChristoph Hellwig __le32 s_blocks_count_lo; /* Blocks count */ 12653dcf5451SChristoph Hellwig __le32 s_r_blocks_count_lo; /* Reserved blocks count */ 12663dcf5451SChristoph Hellwig __le32 s_free_blocks_count_lo; /* Free blocks count */ 12673dcf5451SChristoph Hellwig /*10*/ __le32 s_free_inodes_count; /* Free inodes count */ 12683dcf5451SChristoph Hellwig __le32 s_first_data_block; /* First Data Block */ 12693dcf5451SChristoph Hellwig __le32 s_log_block_size; /* Block size */ 1270281b5995STheodore Ts'o __le32 s_log_cluster_size; /* Allocation cluster size */ 12713dcf5451SChristoph Hellwig /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ 1272281b5995STheodore Ts'o __le32 s_clusters_per_group; /* # Clusters per group */ 12733dcf5451SChristoph Hellwig __le32 s_inodes_per_group; /* # Inodes per group */ 12743dcf5451SChristoph Hellwig __le32 s_mtime; /* Mount time */ 12753dcf5451SChristoph Hellwig /*30*/ __le32 s_wtime; /* Write time */ 12763dcf5451SChristoph Hellwig __le16 s_mnt_count; /* Mount count */ 12773dcf5451SChristoph Hellwig __le16 s_max_mnt_count; /* Maximal mount count */ 12783dcf5451SChristoph Hellwig __le16 s_magic; /* Magic signature */ 12793dcf5451SChristoph Hellwig __le16 s_state; /* File system state */ 12803dcf5451SChristoph Hellwig __le16 s_errors; /* Behaviour when detecting errors */ 12813dcf5451SChristoph Hellwig __le16 s_minor_rev_level; /* minor revision level */ 12823dcf5451SChristoph Hellwig /*40*/ __le32 s_lastcheck; /* time of last check */ 12833dcf5451SChristoph Hellwig __le32 s_checkinterval; /* max. time between checks */ 12843dcf5451SChristoph Hellwig __le32 s_creator_os; /* OS */ 12853dcf5451SChristoph Hellwig __le32 s_rev_level; /* Revision level */ 12863dcf5451SChristoph Hellwig /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 12873dcf5451SChristoph Hellwig __le16 s_def_resgid; /* Default gid for reserved blocks */ 12883dcf5451SChristoph Hellwig /* 12893dcf5451SChristoph Hellwig * These fields are for EXT4_DYNAMIC_REV superblocks only. 12903dcf5451SChristoph Hellwig * 12913dcf5451SChristoph Hellwig * Note: the difference between the compatible feature set and 12923dcf5451SChristoph Hellwig * the incompatible feature set is that if there is a bit set 12933dcf5451SChristoph Hellwig * in the incompatible feature set that the kernel doesn't 12943dcf5451SChristoph Hellwig * know about, it should refuse to mount the filesystem. 12953dcf5451SChristoph Hellwig * 12963dcf5451SChristoph Hellwig * e2fsck's requirements are more strict; if it doesn't know 12973dcf5451SChristoph Hellwig * about a feature in either the compatible or incompatible 12983dcf5451SChristoph Hellwig * feature set, it must abort and not try to meddle with 12993dcf5451SChristoph Hellwig * things it doesn't understand... 13003dcf5451SChristoph Hellwig */ 13013dcf5451SChristoph Hellwig __le32 s_first_ino; /* First non-reserved inode */ 13023dcf5451SChristoph Hellwig __le16 s_inode_size; /* size of inode structure */ 13033dcf5451SChristoph Hellwig __le16 s_block_group_nr; /* block group # of this superblock */ 13043dcf5451SChristoph Hellwig __le32 s_feature_compat; /* compatible feature set */ 13053dcf5451SChristoph Hellwig /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 13063dcf5451SChristoph Hellwig __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 13073dcf5451SChristoph Hellwig /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 13083dcf5451SChristoph Hellwig /*78*/ char s_volume_name[16]; /* volume name */ 1309072ebb3bSTheodore Ts'o /*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */ 13103dcf5451SChristoph Hellwig /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 13113dcf5451SChristoph Hellwig /* 13123dcf5451SChristoph Hellwig * Performance hints. Directory preallocation should only 13133dcf5451SChristoph Hellwig * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. 13143dcf5451SChristoph Hellwig */ 13153dcf5451SChristoph Hellwig __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 13163dcf5451SChristoph Hellwig __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 13173dcf5451SChristoph Hellwig __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 13183dcf5451SChristoph Hellwig /* 13193dcf5451SChristoph Hellwig * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. 13203dcf5451SChristoph Hellwig */ 13213dcf5451SChristoph Hellwig /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 13223dcf5451SChristoph Hellwig /*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 13233dcf5451SChristoph Hellwig __le32 s_journal_dev; /* device number of journal file */ 13243dcf5451SChristoph Hellwig __le32 s_last_orphan; /* start of list of inodes to delete */ 13253dcf5451SChristoph Hellwig __le32 s_hash_seed[4]; /* HTREE hash seed */ 13263dcf5451SChristoph Hellwig __u8 s_def_hash_version; /* Default hash version to use */ 132789eeddf0STheodore Ts'o __u8 s_jnl_backup_type; 13283dcf5451SChristoph Hellwig __le16 s_desc_size; /* size of group descriptor */ 13293dcf5451SChristoph Hellwig /*100*/ __le32 s_default_mount_opts; 13303dcf5451SChristoph Hellwig __le32 s_first_meta_bg; /* First metablock block group */ 13313dcf5451SChristoph Hellwig __le32 s_mkfs_time; /* When the filesystem was created */ 13323dcf5451SChristoph Hellwig __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ 13333dcf5451SChristoph Hellwig /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ 13343dcf5451SChristoph Hellwig /*150*/ __le32 s_blocks_count_hi; /* Blocks count */ 13353dcf5451SChristoph Hellwig __le32 s_r_blocks_count_hi; /* Reserved blocks count */ 13363dcf5451SChristoph Hellwig __le32 s_free_blocks_count_hi; /* Free blocks count */ 13373dcf5451SChristoph Hellwig __le16 s_min_extra_isize; /* All inodes have at least # bytes */ 13383dcf5451SChristoph Hellwig __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ 13393dcf5451SChristoph Hellwig __le32 s_flags; /* Miscellaneous flags */ 13403dcf5451SChristoph Hellwig __le16 s_raid_stride; /* RAID stride */ 1341c5e06d10SJohann Lombardi __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ 13423dcf5451SChristoph Hellwig __le64 s_mmp_block; /* Block for multi-mount protection */ 13433dcf5451SChristoph Hellwig __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 1344772cb7c8SJose R. Santos __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 1345e6153918SDarrick J. Wong __u8 s_checksum_type; /* metadata checksum algorithm used */ 1346f542fbe8STheodore Ts'o __u8 s_encryption_level; /* versioning level for encryption */ 1347f542fbe8STheodore Ts'o __u8 s_reserved_pad; /* Padding to next 32bits */ 1348afc32f7eSTheodore Ts'o __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 13494a9cdec7STheodore Ts'o __le32 s_snapshot_inum; /* Inode number of active snapshot */ 13504a9cdec7STheodore Ts'o __le32 s_snapshot_id; /* sequential ID of active snapshot */ 13514a9cdec7STheodore Ts'o __le64 s_snapshot_r_blocks_count; /* reserved blocks for active 13524a9cdec7STheodore Ts'o snapshot's future use */ 13534a9cdec7STheodore Ts'o __le32 s_snapshot_list; /* inode number of the head of the 13544a9cdec7STheodore Ts'o on-disk snapshot list */ 13551c13d5c0STheodore Ts'o #define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count) 13561c13d5c0STheodore Ts'o __le32 s_error_count; /* number of fs errors */ 13571c13d5c0STheodore Ts'o __le32 s_first_error_time; /* first time an error happened */ 13581c13d5c0STheodore Ts'o __le32 s_first_error_ino; /* inode involved in first error */ 13591c13d5c0STheodore Ts'o __le64 s_first_error_block; /* block involved of first error */ 1360072ebb3bSTheodore Ts'o __u8 s_first_error_func[32] __nonstring; /* function where the error happened */ 13611c13d5c0STheodore Ts'o __le32 s_first_error_line; /* line number where error happened */ 13621c13d5c0STheodore Ts'o __le32 s_last_error_time; /* most recent time of an error */ 13631c13d5c0STheodore Ts'o __le32 s_last_error_ino; /* inode involved in last error */ 13641c13d5c0STheodore Ts'o __le32 s_last_error_line; /* line number where error happened */ 13651c13d5c0STheodore Ts'o __le64 s_last_error_block; /* block involved of last error */ 1366072ebb3bSTheodore Ts'o __u8 s_last_error_func[32] __nonstring; /* function where the error happened */ 13678b67f04aSTheodore Ts'o #define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts) 13688b67f04aSTheodore Ts'o __u8 s_mount_opts[64]; 1369281b5995STheodore Ts'o __le32 s_usr_quota_inum; /* inode for tracking user quota */ 1370281b5995STheodore Ts'o __le32 s_grp_quota_inum; /* inode for tracking group quota */ 1371281b5995STheodore Ts'o __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ 13721beeef1bSDarrick J. Wong __le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */ 13733edc18d8STheodore Ts'o __u8 s_encrypt_algos[4]; /* Encryption algorithms in use */ 1374f542fbe8STheodore Ts'o __u8 s_encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ 1375f542fbe8STheodore Ts'o __le32 s_lpf_ino; /* Location of the lost+found inode */ 13768b4953e1STheodore Ts'o __le32 s_prj_quota_inum; /* inode for tracking project quota */ 13778c81bd8fSDarrick J. Wong __le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */ 13786a0678a7SArnd Bergmann __u8 s_wtime_hi; 13796a0678a7SArnd Bergmann __u8 s_mtime_hi; 13806a0678a7SArnd Bergmann __u8 s_mkfs_time_hi; 13816a0678a7SArnd Bergmann __u8 s_lastcheck_hi; 13826a0678a7SArnd Bergmann __u8 s_first_error_time_hi; 13836a0678a7SArnd Bergmann __u8 s_last_error_time_hi; 1384878520acSTheodore Ts'o __u8 s_first_error_errcode; 1385878520acSTheodore Ts'o __u8 s_last_error_errcode; 1386c83ad55eSGabriel Krisman Bertazi __le16 s_encoding; /* Filename charset encoding */ 1387c83ad55eSGabriel Krisman Bertazi __le16 s_encoding_flags; /* Filename charset encoding flags */ 1388c83ad55eSGabriel Krisman Bertazi __le32 s_reserved[95]; /* Padding to the end of the block */ 1389e6153918SDarrick J. Wong __le32 s_checksum; /* crc32c(superblock) */ 13903dcf5451SChristoph Hellwig }; 13913dcf5451SChristoph Hellwig 13921c13d5c0STheodore Ts'o #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) 13931c13d5c0STheodore Ts'o 13943dcf5451SChristoph Hellwig #ifdef __KERNEL__ 1395bc0b0d6dSTheodore Ts'o 1396bc0b0d6dSTheodore Ts'o /* 13974ab2f15bSTheodore Ts'o * run-time mount flags 1398bc0b0d6dSTheodore Ts'o */ 1399bc0b0d6dSTheodore Ts'o #define EXT4_MF_MNTDIR_SAMPLED 0x0001 14004ab2f15bSTheodore Ts'o #define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */ 14016ddb2447STheodore Ts'o 1402643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 1403ed318a6cSEric Biggers #define DUMMY_ENCRYPTION_ENABLED(sbi) ((sbi)->s_dummy_enc_ctx.ctx != NULL) 14046ddb2447STheodore Ts'o #else 14056ddb2447STheodore Ts'o #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) 14066ddb2447STheodore Ts'o #endif 1407bc0b0d6dSTheodore Ts'o 1408a2d4a646SJan Kara /* Number of quota types we support */ 1409689c958cSLi Xi #define EXT4_MAXQUOTAS 3 1410a2d4a646SJan Kara 1411c83ad55eSGabriel Krisman Bertazi #define EXT4_ENC_UTF8_12_1 1 1412c83ad55eSGabriel Krisman Bertazi 1413c83ad55eSGabriel Krisman Bertazi /* 1414c83ad55eSGabriel Krisman Bertazi * Flags for ext4_sb_info.s_encoding_flags. 1415c83ad55eSGabriel Krisman Bertazi */ 1416c83ad55eSGabriel Krisman Bertazi #define EXT4_ENC_STRICT_MODE_FL (1 << 0) 1417c83ad55eSGabriel Krisman Bertazi 1418c83ad55eSGabriel Krisman Bertazi #define ext4_has_strict_mode(sbi) \ 1419c83ad55eSGabriel Krisman Bertazi (sbi->s_encoding_flags & EXT4_ENC_STRICT_MODE_FL) 1420c83ad55eSGabriel Krisman Bertazi 1421ca0faba0STheodore Ts'o /* 1422ca0faba0STheodore Ts'o * fourth extended-fs super-block data in memory 1423ca0faba0STheodore Ts'o */ 1424ca0faba0STheodore Ts'o struct ext4_sb_info { 1425ca0faba0STheodore Ts'o unsigned long s_desc_size; /* Size of a group descriptor in bytes */ 1426ca0faba0STheodore Ts'o unsigned long s_inodes_per_block;/* Number of inodes per block */ 1427ca0faba0STheodore Ts'o unsigned long s_blocks_per_group;/* Number of blocks in a group */ 1428281b5995STheodore Ts'o unsigned long s_clusters_per_group; /* Number of clusters in a group */ 1429ca0faba0STheodore Ts'o unsigned long s_inodes_per_group;/* Number of inodes in a group */ 1430ca0faba0STheodore Ts'o unsigned long s_itb_per_group; /* Number of inode table blocks per group */ 1431ca0faba0STheodore Ts'o unsigned long s_gdb_count; /* Number of group descriptor blocks */ 1432ca0faba0STheodore Ts'o unsigned long s_desc_per_block; /* Number of group descriptors per block */ 1433ca0faba0STheodore Ts'o ext4_group_t s_groups_count; /* Number of groups in the fs */ 1434fb0a387dSEric Sandeen ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */ 1435952fc18eSTheodore Ts'o unsigned long s_overhead; /* # of fs overhead clusters */ 1436281b5995STheodore Ts'o unsigned int s_cluster_ratio; /* Number of blocks per cluster */ 1437281b5995STheodore Ts'o unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */ 1438ca0faba0STheodore Ts'o loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */ 1439ca0faba0STheodore Ts'o struct buffer_head * s_sbh; /* Buffer containing the super block */ 1440ca0faba0STheodore Ts'o struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */ 14411d0c3924STheodore Ts'o struct buffer_head * __rcu *s_group_desc; 14427f4520ccSTheodore Ts'o unsigned int s_mount_opt; 1443a2595b8aSTheodore Ts'o unsigned int s_mount_opt2; 1444bc0b0d6dSTheodore Ts'o unsigned int s_mount_flags; 14455a916be1STheodore Ts'o unsigned int s_def_mount_opt; 1446ca0faba0STheodore Ts'o ext4_fsblk_t s_sb_block; 144727dd4385SLukas Czerner atomic64_t s_resv_clusters; 144808cefc7aSEric W. Biederman kuid_t s_resuid; 144908cefc7aSEric W. Biederman kgid_t s_resgid; 1450ca0faba0STheodore Ts'o unsigned short s_mount_state; 1451ca0faba0STheodore Ts'o unsigned short s_pad; 1452ca0faba0STheodore Ts'o int s_addr_per_block_bits; 1453ca0faba0STheodore Ts'o int s_desc_per_block_bits; 1454ca0faba0STheodore Ts'o int s_inode_size; 1455ca0faba0STheodore Ts'o int s_first_ino; 1456ca0faba0STheodore Ts'o unsigned int s_inode_readahead_blks; 145711013911SAndreas Dilger unsigned int s_inode_goal; 1458ca0faba0STheodore Ts'o u32 s_hash_seed[4]; 1459ca0faba0STheodore Ts'o int s_def_hash_version; 1460ca0faba0STheodore Ts'o int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */ 146157042651STheodore Ts'o struct percpu_counter s_freeclusters_counter; 1462ca0faba0STheodore Ts'o struct percpu_counter s_freeinodes_counter; 1463ca0faba0STheodore Ts'o struct percpu_counter s_dirs_counter; 146457042651STheodore Ts'o struct percpu_counter s_dirtyclusters_counter; 1465ca0faba0STheodore Ts'o struct blockgroup_lock *s_blockgroup_lock; 1466ca0faba0STheodore Ts'o struct proc_dir_entry *s_proc; 1467ca0faba0STheodore Ts'o struct kobject s_kobj; 1468ca0faba0STheodore Ts'o struct completion s_kobj_unregister; 14692c0544b2STheodore Ts'o struct super_block *s_sb; 1470c83ad55eSGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 1471c83ad55eSGabriel Krisman Bertazi struct unicode_map *s_encoding; 1472c83ad55eSGabriel Krisman Bertazi __u16 s_encoding_flags; 1473c83ad55eSGabriel Krisman Bertazi #endif 1474ca0faba0STheodore Ts'o 1475ca0faba0STheodore Ts'o /* Journaling */ 1476ca0faba0STheodore Ts'o struct journal_s *s_journal; 1477ca0faba0STheodore Ts'o struct list_head s_orphan; 1478ca0faba0STheodore Ts'o struct mutex s_orphan_lock; 14799549a168STheodore Ts'o unsigned long s_ext4_flags; /* Ext4 superblock flags */ 1480ca0faba0STheodore Ts'o unsigned long s_commit_interval; 1481ca0faba0STheodore Ts'o u32 s_max_batch_time; 1482ca0faba0STheodore Ts'o u32 s_min_batch_time; 1483ca0faba0STheodore Ts'o struct block_device *journal_bdev; 1484ca0faba0STheodore Ts'o #ifdef CONFIG_QUOTA 148533458eabSTheodore Ts'o /* Names of quota files with journalled quota */ 148633458eabSTheodore Ts'o char __rcu *s_qf_names[EXT4_MAXQUOTAS]; 1487ca0faba0STheodore Ts'o int s_jquota_fmt; /* Format of quota to use */ 1488ca0faba0STheodore Ts'o #endif 1489ca0faba0STheodore Ts'o unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */ 14907727ae52Szhangyi (F) struct ext4_system_blocks __rcu *system_blks; 1491ca0faba0STheodore Ts'o 1492ca0faba0STheodore Ts'o #ifdef EXTENTS_STATS 1493ca0faba0STheodore Ts'o /* ext4 extents stats */ 1494ca0faba0STheodore Ts'o unsigned long s_ext_min; 1495ca0faba0STheodore Ts'o unsigned long s_ext_max; 1496ca0faba0STheodore Ts'o unsigned long s_depth_max; 1497ca0faba0STheodore Ts'o spinlock_t s_ext_stats_lock; 1498ca0faba0STheodore Ts'o unsigned long s_ext_blocks; 1499ca0faba0STheodore Ts'o unsigned long s_ext_extents; 1500ca0faba0STheodore Ts'o #endif 1501ca0faba0STheodore Ts'o 1502ca0faba0STheodore Ts'o /* for buddy allocator */ 1503df3da4eaSSuraj Jitindar Singh struct ext4_group_info ** __rcu *s_group_info; 1504ca0faba0STheodore Ts'o struct inode *s_buddy_cache; 1505ca0faba0STheodore Ts'o spinlock_t s_md_lock; 1506ca0faba0STheodore Ts'o unsigned short *s_mb_offsets; 1507ca0faba0STheodore Ts'o unsigned int *s_mb_maxs; 150828623c2fSTheodore Ts'o unsigned int s_group_info_size; 1509d08854f5STheodore Ts'o unsigned int s_mb_free_pending; 1510a0154344SDaeho Jeong struct list_head s_freed_data_list; /* List of blocks to be freed 1511a0154344SDaeho Jeong after commit completed */ 1512ca0faba0STheodore Ts'o 1513ca0faba0STheodore Ts'o /* tunables */ 1514ca0faba0STheodore Ts'o unsigned long s_stripe; 1515ca0faba0STheodore Ts'o unsigned int s_mb_stream_request; 1516ca0faba0STheodore Ts'o unsigned int s_mb_max_to_scan; 1517ca0faba0STheodore Ts'o unsigned int s_mb_min_to_scan; 1518ca0faba0STheodore Ts'o unsigned int s_mb_stats; 1519ca0faba0STheodore Ts'o unsigned int s_mb_order2_reqs; 1520ca0faba0STheodore Ts'o unsigned int s_mb_group_prealloc; 1521df981d03STheodore Ts'o unsigned int s_max_dir_size_kb; 1522ca0faba0STheodore Ts'o /* where last allocation was done - for stream allocation */ 1523ca0faba0STheodore Ts'o unsigned long s_mb_last_group; 1524ca0faba0STheodore Ts'o unsigned long s_mb_last_start; 1525cfd73237SAlex Zhuravlev unsigned int s_mb_prefetch; 1526cfd73237SAlex Zhuravlev unsigned int s_mb_prefetch_limit; 1527ca0faba0STheodore Ts'o 1528ca0faba0STheodore Ts'o /* stats for buddy allocator */ 1529ca0faba0STheodore Ts'o atomic_t s_bal_reqs; /* number of reqs with len > 1 */ 1530ca0faba0STheodore Ts'o atomic_t s_bal_success; /* we found long enough chunks */ 1531ca0faba0STheodore Ts'o atomic_t s_bal_allocated; /* in blocks */ 1532ca0faba0STheodore Ts'o atomic_t s_bal_ex_scanned; /* total extents scanned */ 1533ca0faba0STheodore Ts'o atomic_t s_bal_goals; /* goal hits */ 1534ca0faba0STheodore Ts'o atomic_t s_bal_breaks; /* too long searches */ 1535ca0faba0STheodore Ts'o atomic_t s_bal_2orders; /* 2^order hits */ 1536ca0faba0STheodore Ts'o spinlock_t s_bal_lock; 1537ca0faba0STheodore Ts'o unsigned long s_mb_buddies_generated; 1538ca0faba0STheodore Ts'o unsigned long long s_mb_generation_time; 1539ca0faba0STheodore Ts'o atomic_t s_mb_lost_chunks; 1540ca0faba0STheodore Ts'o atomic_t s_mb_preallocated; 1541ca0faba0STheodore Ts'o atomic_t s_mb_discarded; 154250797481STheodore Ts'o atomic_t s_lock_busy; 1543ca0faba0STheodore Ts'o 1544ca0faba0STheodore Ts'o /* locality groups */ 1545003cb608STejun Heo struct ext4_locality_group __percpu *s_locality_groups; 1546ca0faba0STheodore Ts'o 1547ca0faba0STheodore Ts'o /* for write statistics */ 1548ca0faba0STheodore Ts'o unsigned long s_sectors_written_start; 1549ca0faba0STheodore Ts'o u64 s_kbytes_written; 1550ca0faba0STheodore Ts'o 155167a5da56SZheng Liu /* the size of zero-out chunk */ 155267a5da56SZheng Liu unsigned int s_extent_max_zeroout_kb; 155367a5da56SZheng Liu 1554ca0faba0STheodore Ts'o unsigned int s_log_groups_per_flex; 15557c990728SSuraj Jitindar Singh struct flex_groups * __rcu *s_flex_groups; 1556117fff10STheodore Ts'o ext4_group_t s_flex_groups_allocated; 15574c0425ffSMingming Cao 15582e8fa54eSJan Kara /* workqueue for reserved extent conversions (buffered io) */ 15592e8fa54eSJan Kara struct workqueue_struct *rsv_conversion_wq; 156066e61a9eSTheodore Ts'o 156166e61a9eSTheodore Ts'o /* timer for periodic error stats printing */ 156266e61a9eSTheodore Ts'o struct timer_list s_err_report; 1563bfff6873SLukas Czerner 1564bfff6873SLukas Czerner /* Lazy inode table initialization info */ 1565bfff6873SLukas Czerner struct ext4_li_request *s_li_request; 1566bfff6873SLukas Czerner /* Wait multiplier for lazy initialization thread */ 1567bfff6873SLukas Czerner unsigned int s_li_wait_mult; 1568c5e06d10SJohann Lombardi 1569c5e06d10SJohann Lombardi /* Kernel thread for multiple mount protection */ 1570c5e06d10SJohann Lombardi struct task_struct *s_mmp_tsk; 15713d56b8d2STao Ma 15723d56b8d2STao Ma /* record the last minlen when FITRIM is called. */ 15733d56b8d2STao Ma atomic_t s_last_trim_minblks; 15740441984aSDarrick J. Wong 15750441984aSDarrick J. Wong /* Reference to checksum algorithm driver via cryptoapi */ 15760441984aSDarrick J. Wong struct crypto_shash *s_chksum_driver; 1577a9c47317SDarrick J. Wong 1578a9c47317SDarrick J. Wong /* Precomputed FS UUID checksum for seeding other checksums */ 1579a9c47317SDarrick J. Wong __u32 s_csum_seed; 158074cd15cdSZheng Liu 158174cd15cdSZheng Liu /* Reclaim extents from extent status tree */ 158274cd15cdSZheng Liu struct shrinker s_es_shrinker; 1583dd475925SJan Kara struct list_head s_es_list; /* List of inodes with reclaimable extents */ 1584edaa53caSZheng Liu long s_es_nr_inode; 1585eb68d0e2SZheng Liu struct ext4_es_stats s_es_stats; 158647387409STahsin Erdogan struct mb_cache *s_ea_block_cache; 1587dec214d0STahsin Erdogan struct mb_cache *s_ea_inode_cache; 1588edaa53caSZheng Liu spinlock_t s_es_lock ____cacheline_aligned_in_smp; 1589efbed4dcSTheodore Ts'o 1590efbed4dcSTheodore Ts'o /* Ratelimit ext4 messages. */ 1591efbed4dcSTheodore Ts'o struct ratelimit_state s_err_ratelimit_state; 1592efbed4dcSTheodore Ts'o struct ratelimit_state s_warning_ratelimit_state; 1593efbed4dcSTheodore Ts'o struct ratelimit_state s_msg_ratelimit_state; 15941cf006edSDmitry Monakhov atomic_t s_warning_count; 15951cf006edSDmitry Monakhov atomic_t s_msg_count; 1596c8585c6fSDaeho Jeong 1597ed318a6cSEric Biggers /* Encryption context for '-o test_dummy_encryption' */ 1598ed318a6cSEric Biggers struct fscrypt_dummy_context s_dummy_enc_ctx; 1599ed318a6cSEric Biggers 1600cb85f4d2SEric Biggers /* 1601cb85f4d2SEric Biggers * Barrier between writepages ops and changing any inode's JOURNAL_DATA 1602cb85f4d2SEric Biggers * or EXTENTS flag. 1603cb85f4d2SEric Biggers */ 1604bbd55937SEric Biggers struct percpu_rw_semaphore s_writepages_rwsem; 16055e405595SDan Williams struct dax_device *s_daxdev; 160646f870d6STheodore Ts'o #ifdef CONFIG_EXT4_DEBUG 160746f870d6STheodore Ts'o unsigned long s_simulate_fail; 160846f870d6STheodore Ts'o #endif 1609bc71726cSzhangyi (F) /* Record the errseq of the backing block device */ 1610bc71726cSzhangyi (F) errseq_t s_bdev_wb_err; 1611bc71726cSzhangyi (F) spinlock_t s_bdev_wb_lock; 1612ca0faba0STheodore Ts'o }; 1613ca0faba0STheodore Ts'o 16143dcf5451SChristoph Hellwig static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 16153dcf5451SChristoph Hellwig { 16163dcf5451SChristoph Hellwig return sb->s_fs_info; 16173dcf5451SChristoph Hellwig } 16183dcf5451SChristoph Hellwig static inline struct ext4_inode_info *EXT4_I(struct inode *inode) 16193dcf5451SChristoph Hellwig { 16203dcf5451SChristoph Hellwig return container_of(inode, struct ext4_inode_info, vfs_inode); 16213dcf5451SChristoph Hellwig } 16223dcf5451SChristoph Hellwig 16233dcf5451SChristoph Hellwig static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 16243dcf5451SChristoph Hellwig { 16253dcf5451SChristoph Hellwig return ino == EXT4_ROOT_INO || 16263dcf5451SChristoph Hellwig (ino >= EXT4_FIRST_INO(sb) && 16273dcf5451SChristoph Hellwig ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 16283dcf5451SChristoph Hellwig } 162919f5fb7aSTheodore Ts'o 163019f5fb7aSTheodore Ts'o /* 16311d0c3924STheodore Ts'o * Returns: sbi->field[index] 16321d0c3924STheodore Ts'o * Used to access an array element from the following sbi fields which require 16331d0c3924STheodore Ts'o * rcu protection to avoid dereferencing an invalid pointer due to reassignment 16341d0c3924STheodore Ts'o * - s_group_desc 16351d0c3924STheodore Ts'o * - s_group_info 16361d0c3924STheodore Ts'o * - s_flex_group 16371d0c3924STheodore Ts'o */ 16381d0c3924STheodore Ts'o #define sbi_array_rcu_deref(sbi, field, index) \ 16391d0c3924STheodore Ts'o ({ \ 16401d0c3924STheodore Ts'o typeof(*((sbi)->field)) _v; \ 16411d0c3924STheodore Ts'o rcu_read_lock(); \ 16421d0c3924STheodore Ts'o _v = ((typeof(_v)*)rcu_dereference((sbi)->field))[index]; \ 16431d0c3924STheodore Ts'o rcu_read_unlock(); \ 16441d0c3924STheodore Ts'o _v; \ 16451d0c3924STheodore Ts'o }) 16461d0c3924STheodore Ts'o 16471d0c3924STheodore Ts'o /* 164846f870d6STheodore Ts'o * Simulate_fail codes 164946f870d6STheodore Ts'o */ 165046f870d6STheodore Ts'o #define EXT4_SIM_BBITMAP_EIO 1 165146f870d6STheodore Ts'o #define EXT4_SIM_BBITMAP_CRC 2 165246f870d6STheodore Ts'o #define EXT4_SIM_IBITMAP_EIO 3 165346f870d6STheodore Ts'o #define EXT4_SIM_IBITMAP_CRC 4 165446f870d6STheodore Ts'o #define EXT4_SIM_INODE_EIO 5 165546f870d6STheodore Ts'o #define EXT4_SIM_INODE_CRC 6 165646f870d6STheodore Ts'o #define EXT4_SIM_DIRBLOCK_EIO 7 165746f870d6STheodore Ts'o #define EXT4_SIM_DIRBLOCK_CRC 8 165846f870d6STheodore Ts'o 165946f870d6STheodore Ts'o static inline bool ext4_simulate_fail(struct super_block *sb, 166046f870d6STheodore Ts'o unsigned long code) 166146f870d6STheodore Ts'o { 166246f870d6STheodore Ts'o #ifdef CONFIG_EXT4_DEBUG 166346f870d6STheodore Ts'o struct ext4_sb_info *sbi = EXT4_SB(sb); 166446f870d6STheodore Ts'o 166546f870d6STheodore Ts'o if (unlikely(sbi->s_simulate_fail == code)) { 166646f870d6STheodore Ts'o sbi->s_simulate_fail = 0; 166746f870d6STheodore Ts'o return true; 166846f870d6STheodore Ts'o } 166946f870d6STheodore Ts'o #endif 167046f870d6STheodore Ts'o return false; 167146f870d6STheodore Ts'o } 167246f870d6STheodore Ts'o 167346f870d6STheodore Ts'o static inline void ext4_simulate_fail_bh(struct super_block *sb, 167446f870d6STheodore Ts'o struct buffer_head *bh, 167546f870d6STheodore Ts'o unsigned long code) 167646f870d6STheodore Ts'o { 167746f870d6STheodore Ts'o if (!IS_ERR(bh) && ext4_simulate_fail(sb, code)) 167846f870d6STheodore Ts'o clear_buffer_uptodate(bh); 167946f870d6STheodore Ts'o } 168046f870d6STheodore Ts'o 168146f870d6STheodore Ts'o /* 1682878520acSTheodore Ts'o * Error number codes for s_{first,last}_error_errno 1683878520acSTheodore Ts'o * 1684878520acSTheodore Ts'o * Linux errno numbers are architecture specific, so we need to translate 1685878520acSTheodore Ts'o * them into something which is architecture independent. We don't define 1686878520acSTheodore Ts'o * codes for all errno's; just the ones which are most likely to be the cause 1687878520acSTheodore Ts'o * of an ext4_error() call. 1688878520acSTheodore Ts'o */ 1689878520acSTheodore Ts'o #define EXT4_ERR_UNKNOWN 1 1690878520acSTheodore Ts'o #define EXT4_ERR_EIO 2 1691878520acSTheodore Ts'o #define EXT4_ERR_ENOMEM 3 1692878520acSTheodore Ts'o #define EXT4_ERR_EFSBADCRC 4 1693878520acSTheodore Ts'o #define EXT4_ERR_EFSCORRUPTED 5 1694878520acSTheodore Ts'o #define EXT4_ERR_ENOSPC 6 1695878520acSTheodore Ts'o #define EXT4_ERR_ENOKEY 7 1696878520acSTheodore Ts'o #define EXT4_ERR_EROFS 8 1697878520acSTheodore Ts'o #define EXT4_ERR_EFBIG 9 1698878520acSTheodore Ts'o #define EXT4_ERR_EEXIST 10 1699878520acSTheodore Ts'o #define EXT4_ERR_ERANGE 11 1700878520acSTheodore Ts'o #define EXT4_ERR_EOVERFLOW 12 1701878520acSTheodore Ts'o #define EXT4_ERR_EBUSY 13 1702878520acSTheodore Ts'o #define EXT4_ERR_ENOTDIR 14 1703878520acSTheodore Ts'o #define EXT4_ERR_ENOTEMPTY 15 1704878520acSTheodore Ts'o #define EXT4_ERR_ESHUTDOWN 16 1705878520acSTheodore Ts'o #define EXT4_ERR_EFAULT 17 1706878520acSTheodore Ts'o 1707878520acSTheodore Ts'o /* 170819f5fb7aSTheodore Ts'o * Inode dynamic state flags 170919f5fb7aSTheodore Ts'o */ 171019f5fb7aSTheodore Ts'o enum { 171119f5fb7aSTheodore Ts'o EXT4_STATE_JDATA, /* journaled data exists */ 171219f5fb7aSTheodore Ts'o EXT4_STATE_NEW, /* inode is newly created */ 171319f5fb7aSTheodore Ts'o EXT4_STATE_XATTR, /* has in-inode xattrs */ 171419f5fb7aSTheodore Ts'o EXT4_STATE_NO_EXPAND, /* No space for expansion */ 171519f5fb7aSTheodore Ts'o EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */ 171619f5fb7aSTheodore Ts'o EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */ 171714ece102SFrank Mayhar EXT4_STATE_NEWENTRY, /* File just added to dir */ 171867cf5b09STao Ma EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ 17197869a4a6STheodore Ts'o EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ 1720a6d05676STahsin Erdogan EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ 1721c93d8f88SEric Biggers EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 172219f5fb7aSTheodore Ts'o }; 172319f5fb7aSTheodore Ts'o 1724353eb83cSTheodore Ts'o #define EXT4_INODE_BIT_FNS(name, field, offset) \ 172512e9b892SDmitry Monakhov static inline int ext4_test_inode_##name(struct inode *inode, int bit) \ 172612e9b892SDmitry Monakhov { \ 1727353eb83cSTheodore Ts'o return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 172812e9b892SDmitry Monakhov } \ 172912e9b892SDmitry Monakhov static inline void ext4_set_inode_##name(struct inode *inode, int bit) \ 173012e9b892SDmitry Monakhov { \ 1731353eb83cSTheodore Ts'o set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 173212e9b892SDmitry Monakhov } \ 173312e9b892SDmitry Monakhov static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ 173412e9b892SDmitry Monakhov { \ 1735353eb83cSTheodore Ts'o clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 173619f5fb7aSTheodore Ts'o } 173719f5fb7aSTheodore Ts'o 17383f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 17393f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 17403f61c0ccSAndreas Dilger static inline int ext4_test_inode_flag(struct inode *inode, int bit); 17413f61c0ccSAndreas Dilger static inline void ext4_set_inode_flag(struct inode *inode, int bit); 17423f61c0ccSAndreas Dilger static inline void ext4_clear_inode_flag(struct inode *inode, int bit); 1743353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(flag, flags, 0) 17443f61c0ccSAndreas Dilger 17453f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 17463f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 17473f61c0ccSAndreas Dilger static inline int ext4_test_inode_state(struct inode *inode, int bit); 17483f61c0ccSAndreas Dilger static inline void ext4_set_inode_state(struct inode *inode, int bit); 17493f61c0ccSAndreas Dilger static inline void ext4_clear_inode_state(struct inode *inode, int bit); 1750353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 1751353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, state_flags, 0) 1752353eb83cSTheodore Ts'o 1753353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1754353eb83cSTheodore Ts'o { 1755353eb83cSTheodore Ts'o (ei)->i_state_flags = 0; 1756353eb83cSTheodore Ts'o } 1757353eb83cSTheodore Ts'o #else 1758353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, flags, 32) 1759353eb83cSTheodore Ts'o 1760353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1761353eb83cSTheodore Ts'o { 1762353eb83cSTheodore Ts'o /* We depend on the fact that callers will set i_flags */ 1763353eb83cSTheodore Ts'o } 1764353eb83cSTheodore Ts'o #endif 17653dcf5451SChristoph Hellwig #else 17663dcf5451SChristoph Hellwig /* Assume that user mode programs are passing in an ext4fs superblock, not 17673dcf5451SChristoph Hellwig * a kernel struct super_block. This will allow us to call the feature-test 17683dcf5451SChristoph Hellwig * macros from user land. */ 17693dcf5451SChristoph Hellwig #define EXT4_SB(sb) (sb) 17703dcf5451SChristoph Hellwig #endif 17713dcf5451SChristoph Hellwig 1772c93d8f88SEric Biggers static inline bool ext4_verity_in_progress(struct inode *inode) 1773c93d8f88SEric Biggers { 1774c93d8f88SEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 1775c93d8f88SEric Biggers ext4_test_inode_state(inode, EXT4_STATE_VERITY_IN_PROGRESS); 1776c93d8f88SEric Biggers } 1777c93d8f88SEric Biggers 17783dcf5451SChristoph Hellwig #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime 17793dcf5451SChristoph Hellwig 17803dcf5451SChristoph Hellwig /* 17813dcf5451SChristoph Hellwig * Codes for operating systems 17823dcf5451SChristoph Hellwig */ 17833dcf5451SChristoph Hellwig #define EXT4_OS_LINUX 0 17843dcf5451SChristoph Hellwig #define EXT4_OS_HURD 1 17853dcf5451SChristoph Hellwig #define EXT4_OS_MASIX 2 17863dcf5451SChristoph Hellwig #define EXT4_OS_FREEBSD 3 17873dcf5451SChristoph Hellwig #define EXT4_OS_LITES 4 17883dcf5451SChristoph Hellwig 17893dcf5451SChristoph Hellwig /* 17903dcf5451SChristoph Hellwig * Revision levels 17913dcf5451SChristoph Hellwig */ 17923dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */ 17933dcf5451SChristoph Hellwig #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 17943dcf5451SChristoph Hellwig 17953dcf5451SChristoph Hellwig #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV 17963dcf5451SChristoph Hellwig #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV 17973dcf5451SChristoph Hellwig 17983dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_INODE_SIZE 128 17993dcf5451SChristoph Hellwig 18004881c497SDeepa Dinamani #define EXT4_EXTRA_TIMESTAMP_MAX (((s64)1 << 34) - 1 + S32_MIN) 18014881c497SDeepa Dinamani #define EXT4_NON_EXTRA_TIMESTAMP_MAX S32_MAX 18024881c497SDeepa Dinamani #define EXT4_TIMESTAMP_MIN S32_MIN 18034881c497SDeepa Dinamani 18043dcf5451SChristoph Hellwig /* 18053dcf5451SChristoph Hellwig * Feature set definitions 18063dcf5451SChristoph Hellwig */ 18073dcf5451SChristoph Hellwig 18083dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 18093dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002 18103dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 18113dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008 18123dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010 18133dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 18141beeef1bSDarrick J. Wong #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 1815b925acb8SEric Biggers #define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800 18163dcf5451SChristoph Hellwig 18173dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 18183dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 18193dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 18203dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 18213dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 18223dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 18233dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 1824ae812306SAditya Kali #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 1825281b5995STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 1826e6153918SDarrick J. Wong /* 1827e6153918SDarrick J. Wong * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When 1828e6153918SDarrick J. Wong * METADATA_CSUM is set, group descriptor checksums use the same algorithm as 1829e6153918SDarrick J. Wong * all other data structures' checksums. However, the METADATA_CSUM and 1830e6153918SDarrick J. Wong * GDT_CSUM bits are mutually exclusive. 1831e6153918SDarrick J. Wong */ 18329b90e5e0STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 18332cb5cc8bSDarrick J. Wong #define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000 18348b4953e1STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_PROJECT 0x2000 1835c93d8f88SEric Biggers #define EXT4_FEATURE_RO_COMPAT_VERITY 0x8000 18363dcf5451SChristoph Hellwig 18373dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 18383dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 18393dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 18403dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 18413dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010 18423dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ 18433dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 18443dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 18453dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 1846f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */ 1847f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */ 18488c81bd8fSDarrick J. Wong #define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 18499b90e5e0STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ 185067cf5b09STao Ma #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */ 18513edc18d8STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 1852c83ad55eSGabriel Krisman Bertazi #define EXT4_FEATURE_INCOMPAT_CASEFOLD 0x20000 18533dcf5451SChristoph Hellwig 1854c9e716ebSAndreas Dilger extern void ext4_update_dynamic_rev(struct super_block *sb); 1855c9e716ebSAndreas Dilger 1856e2b911c5SDarrick J. Wong #define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \ 1857e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 1858e2b911c5SDarrick J. Wong { \ 1859e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 1860e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname)) != 0); \ 1861e2b911c5SDarrick J. Wong } \ 1862e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 1863e2b911c5SDarrick J. Wong { \ 1864c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 1865e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_compat |= \ 1866e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 1867e2b911c5SDarrick J. Wong } \ 1868e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 1869e2b911c5SDarrick J. Wong { \ 1870e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_compat &= \ 1871e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 1872e2b911c5SDarrick J. Wong } 1873e2b911c5SDarrick J. Wong 1874e2b911c5SDarrick J. Wong #define EXT4_FEATURE_RO_COMPAT_FUNCS(name, flagname) \ 1875e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 1876e2b911c5SDarrick J. Wong { \ 1877e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 1878e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname)) != 0); \ 1879e2b911c5SDarrick J. Wong } \ 1880e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 1881e2b911c5SDarrick J. Wong { \ 1882c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 1883e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_ro_compat |= \ 1884e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 1885e2b911c5SDarrick J. Wong } \ 1886e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 1887e2b911c5SDarrick J. Wong { \ 1888e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_ro_compat &= \ 1889e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 1890e2b911c5SDarrick J. Wong } 1891e2b911c5SDarrick J. Wong 1892e2b911c5SDarrick J. Wong #define EXT4_FEATURE_INCOMPAT_FUNCS(name, flagname) \ 1893e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 1894e2b911c5SDarrick J. Wong { \ 1895e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 1896e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname)) != 0); \ 1897e2b911c5SDarrick J. Wong } \ 1898e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 1899e2b911c5SDarrick J. Wong { \ 1900c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 1901e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_incompat |= \ 1902e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 1903e2b911c5SDarrick J. Wong } \ 1904e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 1905e2b911c5SDarrick J. Wong { \ 1906e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_incompat &= \ 1907e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 1908e2b911c5SDarrick J. Wong } 1909e2b911c5SDarrick J. Wong 1910e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(dir_prealloc, DIR_PREALLOC) 1911e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(imagic_inodes, IMAGIC_INODES) 1912e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(journal, HAS_JOURNAL) 1913e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(xattr, EXT_ATTR) 1914e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE) 1915e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX) 1916e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2) 1917b925acb8SEric Biggers EXT4_FEATURE_COMPAT_FUNCS(stable_inodes, STABLE_INODES) 1918e2b911c5SDarrick J. Wong 1919e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super, SPARSE_SUPER) 1920e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(large_file, LARGE_FILE) 1921e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(btree_dir, BTREE_DIR) 1922e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(huge_file, HUGE_FILE) 1923e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(gdt_csum, GDT_CSUM) 1924e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(dir_nlink, DIR_NLINK) 1925e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(extra_isize, EXTRA_ISIZE) 1926e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(quota, QUOTA) 1927e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(bigalloc, BIGALLOC) 1928e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(metadata_csum, METADATA_CSUM) 1929e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(readonly, READONLY) 1930e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(project, PROJECT) 1931c93d8f88SEric Biggers EXT4_FEATURE_RO_COMPAT_FUNCS(verity, VERITY) 1932e2b911c5SDarrick J. Wong 1933e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(compression, COMPRESSION) 1934e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(filetype, FILETYPE) 1935e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(journal_needs_recovery, RECOVER) 1936e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(journal_dev, JOURNAL_DEV) 1937e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(meta_bg, META_BG) 1938e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(extents, EXTENTS) 1939e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT) 1940e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(mmp, MMP) 1941e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(flex_bg, FLEX_BG) 1942e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(ea_inode, EA_INODE) 1943e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(dirdata, DIRDATA) 1944e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(csum_seed, CSUM_SEED) 1945e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(largedir, LARGEDIR) 1946e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(inline_data, INLINE_DATA) 1947e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, ENCRYPT) 1948c83ad55eSGabriel Krisman Bertazi EXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD) 1949e2b911c5SDarrick J. Wong 19502035e776STheodore Ts'o #define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 19512035e776STheodore Ts'o #define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 19522035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 19532035e776STheodore Ts'o #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 19542035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 19552035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 19562035e776STheodore Ts'o 19572035e776STheodore Ts'o #define EXT3_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 19582035e776STheodore Ts'o #define EXT3_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 19592035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_RECOVER| \ 19602035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 19612035e776STheodore Ts'o #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 19622035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 19632035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 19642035e776STheodore Ts'o 1965e2b911c5SDarrick J. Wong #define EXT4_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 19663dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 19673dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_RECOVER| \ 19683dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_META_BG| \ 19693dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_EXTENTS| \ 19703dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_64BIT| \ 1971c5e06d10SJohann Lombardi EXT4_FEATURE_INCOMPAT_FLEX_BG| \ 1972e50e5129SAndreas Dilger EXT4_FEATURE_INCOMPAT_EA_INODE| \ 1973f08225d1STao Ma EXT4_FEATURE_INCOMPAT_MMP | \ 19746ddb2447STheodore Ts'o EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ 19758c81bd8fSDarrick J. Wong EXT4_FEATURE_INCOMPAT_ENCRYPT | \ 1976c83ad55eSGabriel Krisman Bertazi EXT4_FEATURE_INCOMPAT_CASEFOLD | \ 1977e08ac99fSArtem Blagodarenko EXT4_FEATURE_INCOMPAT_CSUM_SEED | \ 1978e08ac99fSArtem Blagodarenko EXT4_FEATURE_INCOMPAT_LARGEDIR) 19793dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 19803dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 19813dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ 19823dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ 19833dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 19843dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 19856f16b606STheodore Ts'o EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\ 1986e93376c2SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_BIGALLOC |\ 19877c319d32SAditya Kali EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\ 1988040cb378SLi Xi EXT4_FEATURE_RO_COMPAT_QUOTA |\ 1989c93d8f88SEric Biggers EXT4_FEATURE_RO_COMPAT_PROJECT |\ 1990c93d8f88SEric Biggers EXT4_FEATURE_RO_COMPAT_VERITY) 19913dcf5451SChristoph Hellwig 1992e2b911c5SDarrick J. Wong #define EXTN_FEATURE_FUNCS(ver) \ 1993e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_compat_features(struct super_block *sb) \ 1994e2b911c5SDarrick J. Wong { \ 1995e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 1996e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_COMPAT_SUPP)) != 0); \ 1997e2b911c5SDarrick J. Wong } \ 1998e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_ro_compat_features(struct super_block *sb) \ 1999e2b911c5SDarrick J. Wong { \ 2000e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 2001e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_RO_COMPAT_SUPP)) != 0); \ 2002e2b911c5SDarrick J. Wong } \ 2003e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_incompat_features(struct super_block *sb) \ 2004e2b911c5SDarrick J. Wong { \ 2005e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 2006e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_INCOMPAT_SUPP)) != 0); \ 2007e2b911c5SDarrick J. Wong } 2008e2b911c5SDarrick J. Wong 2009e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(2) 2010e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(3) 2011e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(4) 2012e2b911c5SDarrick J. Wong 2013e2b911c5SDarrick J. Wong static inline bool ext4_has_compat_features(struct super_block *sb) 2014e2b911c5SDarrick J. Wong { 2015e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_compat != 0); 2016e2b911c5SDarrick J. Wong } 2017e2b911c5SDarrick J. Wong static inline bool ext4_has_ro_compat_features(struct super_block *sb) 2018e2b911c5SDarrick J. Wong { 2019e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_ro_compat != 0); 2020e2b911c5SDarrick J. Wong } 2021e2b911c5SDarrick J. Wong static inline bool ext4_has_incompat_features(struct super_block *sb) 2022e2b911c5SDarrick J. Wong { 2023e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_incompat != 0); 2024e2b911c5SDarrick J. Wong } 2025e2b911c5SDarrick J. Wong 20263dcf5451SChristoph Hellwig /* 20279549a168STheodore Ts'o * Superblock flags 20289549a168STheodore Ts'o */ 20299549a168STheodore Ts'o #define EXT4_FLAGS_RESIZING 0 20300db1ff22STheodore Ts'o #define EXT4_FLAGS_SHUTDOWN 1 2031a8ab6d38SIra Weiny #define EXT4_FLAGS_BDEV_IS_DAX 2 20320db1ff22STheodore Ts'o 20330db1ff22STheodore Ts'o static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi) 20340db1ff22STheodore Ts'o { 20350db1ff22STheodore Ts'o return test_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); 20360db1ff22STheodore Ts'o } 20379549a168STheodore Ts'o 20389549a168STheodore Ts'o 20399549a168STheodore Ts'o /* 20403dcf5451SChristoph Hellwig * Default values for user and/or group using reserved blocks 20413dcf5451SChristoph Hellwig */ 20423dcf5451SChristoph Hellwig #define EXT4_DEF_RESUID 0 20433dcf5451SChristoph Hellwig #define EXT4_DEF_RESGID 0 20443dcf5451SChristoph Hellwig 2045040cb378SLi Xi /* 2046040cb378SLi Xi * Default project ID 2047040cb378SLi Xi */ 2048040cb378SLi Xi #define EXT4_DEF_PROJID 0 2049040cb378SLi Xi 2050240799cdSTheodore Ts'o #define EXT4_DEF_INODE_READAHEAD_BLKS 32 2051240799cdSTheodore Ts'o 20523dcf5451SChristoph Hellwig /* 20533dcf5451SChristoph Hellwig * Default mount options 20543dcf5451SChristoph Hellwig */ 20553dcf5451SChristoph Hellwig #define EXT4_DEFM_DEBUG 0x0001 20563dcf5451SChristoph Hellwig #define EXT4_DEFM_BSDGROUPS 0x0002 20573dcf5451SChristoph Hellwig #define EXT4_DEFM_XATTR_USER 0x0004 20583dcf5451SChristoph Hellwig #define EXT4_DEFM_ACL 0x0008 20593dcf5451SChristoph Hellwig #define EXT4_DEFM_UID16 0x0010 20603dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE 0x0060 20613dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_DATA 0x0020 20623dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_ORDERED 0x0040 20633dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_WBACK 0x0060 20648b67f04aSTheodore Ts'o #define EXT4_DEFM_NOBARRIER 0x0100 20658b67f04aSTheodore Ts'o #define EXT4_DEFM_BLOCK_VALIDITY 0x0200 20668b67f04aSTheodore Ts'o #define EXT4_DEFM_DISCARD 0x0400 20678b67f04aSTheodore Ts'o #define EXT4_DEFM_NODELALLOC 0x0800 20683dcf5451SChristoph Hellwig 20693dcf5451SChristoph Hellwig /* 207030773840STheodore Ts'o * Default journal batch times 207130773840STheodore Ts'o */ 207230773840STheodore Ts'o #define EXT4_DEF_MIN_BATCH_TIME 0 207330773840STheodore Ts'o #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ 207430773840STheodore Ts'o 207530773840STheodore Ts'o /* 2076a4912123STheodore Ts'o * Minimum number of groups in a flexgroup before we separate out 2077a4912123STheodore Ts'o * directories into the first block group of a flexgroup 2078a4912123STheodore Ts'o */ 2079a4912123STheodore Ts'o #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4 2080a4912123STheodore Ts'o 2081a4912123STheodore Ts'o /* 20823dcf5451SChristoph Hellwig * Structure of a directory entry 20833dcf5451SChristoph Hellwig */ 20843dcf5451SChristoph Hellwig #define EXT4_NAME_LEN 255 20853dcf5451SChristoph Hellwig 20863dcf5451SChristoph Hellwig struct ext4_dir_entry { 20873dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 20883dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 20893dcf5451SChristoph Hellwig __le16 name_len; /* Name length */ 20903dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 20913dcf5451SChristoph Hellwig }; 20923dcf5451SChristoph Hellwig 20933dcf5451SChristoph Hellwig /* 20943dcf5451SChristoph Hellwig * The new version of the directory entry. Since EXT4 structures are 20953dcf5451SChristoph Hellwig * stored in intel byte order, and the name_len field could never be 20963dcf5451SChristoph Hellwig * bigger than 255 chars, it's safe to reclaim the extra byte for the 20973dcf5451SChristoph Hellwig * file_type field. 20983dcf5451SChristoph Hellwig */ 20993dcf5451SChristoph Hellwig struct ext4_dir_entry_2 { 21003dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 21013dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 21023dcf5451SChristoph Hellwig __u8 name_len; /* Name length */ 21039f364e1dSJonathan Grant __u8 file_type; /* See file type macros EXT4_FT_* below */ 21043dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 21053dcf5451SChristoph Hellwig }; 21063dcf5451SChristoph Hellwig 21073dcf5451SChristoph Hellwig /* 2108e6153918SDarrick J. Wong * This is a bogus directory entry at the end of each leaf block that 2109e6153918SDarrick J. Wong * records checksums. 2110e6153918SDarrick J. Wong */ 2111e6153918SDarrick J. Wong struct ext4_dir_entry_tail { 2112e6153918SDarrick J. Wong __le32 det_reserved_zero1; /* Pretend to be unused */ 2113e6153918SDarrick J. Wong __le16 det_rec_len; /* 12 */ 2114e6153918SDarrick J. Wong __u8 det_reserved_zero2; /* Zero name length */ 2115e6153918SDarrick J. Wong __u8 det_reserved_ft; /* 0xDE, fake file type */ 2116e6153918SDarrick J. Wong __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */ 2117e6153918SDarrick J. Wong }; 2118e6153918SDarrick J. Wong 21193c47d541STao Ma #define EXT4_DIRENT_TAIL(block, blocksize) \ 21203c47d541STao Ma ((struct ext4_dir_entry_tail *)(((void *)(block)) + \ 21213c47d541STao Ma ((blocksize) - \ 21223c47d541STao Ma sizeof(struct ext4_dir_entry_tail)))) 21233c47d541STao Ma 2124e6153918SDarrick J. Wong /* 21253dcf5451SChristoph Hellwig * Ext4 directory file types. Only the low 3 bits are used. The 21263dcf5451SChristoph Hellwig * other bits are reserved for now. 21273dcf5451SChristoph Hellwig */ 21283dcf5451SChristoph Hellwig #define EXT4_FT_UNKNOWN 0 21293dcf5451SChristoph Hellwig #define EXT4_FT_REG_FILE 1 21303dcf5451SChristoph Hellwig #define EXT4_FT_DIR 2 21313dcf5451SChristoph Hellwig #define EXT4_FT_CHRDEV 3 21323dcf5451SChristoph Hellwig #define EXT4_FT_BLKDEV 4 21333dcf5451SChristoph Hellwig #define EXT4_FT_FIFO 5 21343dcf5451SChristoph Hellwig #define EXT4_FT_SOCK 6 21353dcf5451SChristoph Hellwig #define EXT4_FT_SYMLINK 7 21363dcf5451SChristoph Hellwig 21373dcf5451SChristoph Hellwig #define EXT4_FT_MAX 8 21383dcf5451SChristoph Hellwig 2139e6153918SDarrick J. Wong #define EXT4_FT_DIR_CSUM 0xDE 2140e6153918SDarrick J. Wong 21413dcf5451SChristoph Hellwig /* 21423dcf5451SChristoph Hellwig * EXT4_DIR_PAD defines the directory entries boundaries 21433dcf5451SChristoph Hellwig * 21443dcf5451SChristoph Hellwig * NOTE: It must be a multiple of 4 21453dcf5451SChristoph Hellwig */ 21463dcf5451SChristoph Hellwig #define EXT4_DIR_PAD 4 21473dcf5451SChristoph Hellwig #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1) 21483dcf5451SChristoph Hellwig #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \ 21493dcf5451SChristoph Hellwig ~EXT4_DIR_ROUND) 21503dcf5451SChristoph Hellwig #define EXT4_MAX_REC_LEN ((1<<16)-1) 21513dcf5451SChristoph Hellwig 21523dcf5451SChristoph Hellwig /* 21530cfc9255SEric Sandeen * If we ever get support for fs block sizes > page_size, we'll need 21540cfc9255SEric Sandeen * to remove the #if statements in the next two functions... 21550cfc9255SEric Sandeen */ 21560cfc9255SEric Sandeen static inline unsigned int 21570cfc9255SEric Sandeen ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) 21580cfc9255SEric Sandeen { 21590cfc9255SEric Sandeen unsigned len = le16_to_cpu(dlen); 21600cfc9255SEric Sandeen 2161ea1754a0SKirill A. Shutemov #if (PAGE_SIZE >= 65536) 21620cfc9255SEric Sandeen if (len == EXT4_MAX_REC_LEN || len == 0) 21630cfc9255SEric Sandeen return blocksize; 21640cfc9255SEric Sandeen return (len & 65532) | ((len & 3) << 16); 21650cfc9255SEric Sandeen #else 21660cfc9255SEric Sandeen return len; 21670cfc9255SEric Sandeen #endif 21680cfc9255SEric Sandeen } 21690cfc9255SEric Sandeen 21700cfc9255SEric Sandeen static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) 21710cfc9255SEric Sandeen { 21720cfc9255SEric Sandeen if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)) 21730cfc9255SEric Sandeen BUG(); 2174ea1754a0SKirill A. Shutemov #if (PAGE_SIZE >= 65536) 21750cfc9255SEric Sandeen if (len < 65536) 21760cfc9255SEric Sandeen return cpu_to_le16(len); 21770cfc9255SEric Sandeen if (len == blocksize) { 21780cfc9255SEric Sandeen if (blocksize == 65536) 21790cfc9255SEric Sandeen return cpu_to_le16(EXT4_MAX_REC_LEN); 21800cfc9255SEric Sandeen else 21810cfc9255SEric Sandeen return cpu_to_le16(0); 21820cfc9255SEric Sandeen } 21830cfc9255SEric Sandeen return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); 21840cfc9255SEric Sandeen #else 21850cfc9255SEric Sandeen return cpu_to_le16(len); 21860cfc9255SEric Sandeen #endif 21870cfc9255SEric Sandeen } 21880cfc9255SEric Sandeen 21890cfc9255SEric Sandeen /* 21903dcf5451SChristoph Hellwig * Hash Tree Directory indexing 21913dcf5451SChristoph Hellwig * (c) Daniel Phillips, 2001 21923dcf5451SChristoph Hellwig */ 21933dcf5451SChristoph Hellwig 2194e2b911c5SDarrick J. Wong #define is_dx(dir) (ext4_has_feature_dir_index((dir)->i_sb) && \ 219512e9b892SDmitry Monakhov ext4_test_inode_flag((dir), EXT4_INODE_INDEX)) 2196c7414892SAndreas Dilger #define EXT4_DIR_LINK_MAX(dir) unlikely((dir)->i_nlink >= EXT4_LINK_MAX && \ 2197c7414892SAndreas Dilger !(ext4_has_feature_dir_nlink((dir)->i_sb) && is_dx(dir))) 21983dcf5451SChristoph Hellwig #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 21993dcf5451SChristoph Hellwig 22003dcf5451SChristoph Hellwig /* Legal values for the dx_root hash_version field: */ 22013dcf5451SChristoph Hellwig 22023dcf5451SChristoph Hellwig #define DX_HASH_LEGACY 0 22033dcf5451SChristoph Hellwig #define DX_HASH_HALF_MD4 1 22043dcf5451SChristoph Hellwig #define DX_HASH_TEA 2 2205f99b2589STheodore Ts'o #define DX_HASH_LEGACY_UNSIGNED 3 2206f99b2589STheodore Ts'o #define DX_HASH_HALF_MD4_UNSIGNED 4 2207f99b2589STheodore Ts'o #define DX_HASH_TEA_UNSIGNED 5 22083dcf5451SChristoph Hellwig 22090441984aSDarrick J. Wong static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc, 22100441984aSDarrick J. Wong const void *address, unsigned int length) 22110441984aSDarrick J. Wong { 22120441984aSDarrick J. Wong struct { 22130441984aSDarrick J. Wong struct shash_desc shash; 22143108b54bSTheodore Ts'o char ctx[4]; 22150441984aSDarrick J. Wong } desc; 22160441984aSDarrick J. Wong 22173108b54bSTheodore Ts'o BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx)); 22183108b54bSTheodore Ts'o 22190441984aSDarrick J. Wong desc.shash.tfm = sbi->s_chksum_driver; 22200441984aSDarrick J. Wong *(u32 *)desc.ctx = crc; 22210441984aSDarrick J. Wong 2222e7093f0dSPetros Koutoupis BUG_ON(crypto_shash_update(&desc.shash, address, length)); 22230441984aSDarrick J. Wong 22240441984aSDarrick J. Wong return *(u32 *)desc.ctx; 22250441984aSDarrick J. Wong } 22260441984aSDarrick J. Wong 22273dcf5451SChristoph Hellwig #ifdef __KERNEL__ 22283dcf5451SChristoph Hellwig 22293dcf5451SChristoph Hellwig /* hash info structure used by the directory hash */ 22303dcf5451SChristoph Hellwig struct dx_hash_info 22313dcf5451SChristoph Hellwig { 22323dcf5451SChristoph Hellwig u32 hash; 22333dcf5451SChristoph Hellwig u32 minor_hash; 22343dcf5451SChristoph Hellwig int hash_version; 22353dcf5451SChristoph Hellwig u32 *seed; 22363dcf5451SChristoph Hellwig }; 22373dcf5451SChristoph Hellwig 2238d1f5273eSFan Yong 2239d1f5273eSFan Yong /* 32 and 64 bit signed EOF for dx directories */ 2240d1f5273eSFan Yong #define EXT4_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1) 2241d1f5273eSFan Yong #define EXT4_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1) 2242d1f5273eSFan Yong 22433dcf5451SChristoph Hellwig 22443dcf5451SChristoph Hellwig /* 22453dcf5451SChristoph Hellwig * Control parameters used by ext4_htree_next_block 22463dcf5451SChristoph Hellwig */ 22473dcf5451SChristoph Hellwig #define HASH_NB_ALWAYS 1 22483dcf5451SChristoph Hellwig 22495b643f9cSTheodore Ts'o struct ext4_filename { 22505b643f9cSTheodore Ts'o const struct qstr *usr_fname; 2251a7550b30SJaegeuk Kim struct fscrypt_str disk_name; 22525b643f9cSTheodore Ts'o struct dx_hash_info hinfo; 2253643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 2254a7550b30SJaegeuk Kim struct fscrypt_str crypto_buf; 22555b643f9cSTheodore Ts'o #endif 22563ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 22573ae72562SGabriel Krisman Bertazi struct fscrypt_str cf_name; 22583ae72562SGabriel Krisman Bertazi #endif 22595b643f9cSTheodore Ts'o }; 22605b643f9cSTheodore Ts'o 22615b643f9cSTheodore Ts'o #define fname_name(p) ((p)->disk_name.name) 22625b643f9cSTheodore Ts'o #define fname_len(p) ((p)->disk_name.len) 22633dcf5451SChristoph Hellwig 22643dcf5451SChristoph Hellwig /* 22653dcf5451SChristoph Hellwig * Describe an inode's exact location on disk and in memory 22663dcf5451SChristoph Hellwig */ 22673dcf5451SChristoph Hellwig struct ext4_iloc 22683dcf5451SChristoph Hellwig { 22693dcf5451SChristoph Hellwig struct buffer_head *bh; 22703dcf5451SChristoph Hellwig unsigned long offset; 22713dcf5451SChristoph Hellwig ext4_group_t block_group; 22723dcf5451SChristoph Hellwig }; 22733dcf5451SChristoph Hellwig 22743dcf5451SChristoph Hellwig static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc) 22753dcf5451SChristoph Hellwig { 22763dcf5451SChristoph Hellwig return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); 22773dcf5451SChristoph Hellwig } 22783dcf5451SChristoph Hellwig 2279dec214d0STahsin Erdogan static inline bool ext4_is_quota_file(struct inode *inode) 2280dec214d0STahsin Erdogan { 2281dec214d0STahsin Erdogan return IS_NOQUOTA(inode) && 2282dec214d0STahsin Erdogan !(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL); 2283dec214d0STahsin Erdogan } 228402749a4cSTahsin Erdogan 22853dcf5451SChristoph Hellwig /* 22863dcf5451SChristoph Hellwig * This structure is stuffed into the struct file's private_data field 22873dcf5451SChristoph Hellwig * for directories. It is where we put information so that we can do 22883dcf5451SChristoph Hellwig * readdir operations in hash tree order. 22893dcf5451SChristoph Hellwig */ 22903dcf5451SChristoph Hellwig struct dir_private_info { 22913dcf5451SChristoph Hellwig struct rb_root root; 22923dcf5451SChristoph Hellwig struct rb_node *curr_node; 22933dcf5451SChristoph Hellwig struct fname *extra_fname; 22943dcf5451SChristoph Hellwig loff_t last_pos; 22953dcf5451SChristoph Hellwig __u32 curr_hash; 22963dcf5451SChristoph Hellwig __u32 curr_minor_hash; 22973dcf5451SChristoph Hellwig __u32 next_hash; 22983dcf5451SChristoph Hellwig }; 22993dcf5451SChristoph Hellwig 23003dcf5451SChristoph Hellwig /* calculate the first block number of the group */ 23013dcf5451SChristoph Hellwig static inline ext4_fsblk_t 23023dcf5451SChristoph Hellwig ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no) 23033dcf5451SChristoph Hellwig { 23043dcf5451SChristoph Hellwig return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + 23053dcf5451SChristoph Hellwig le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 23063dcf5451SChristoph Hellwig } 23073dcf5451SChristoph Hellwig 23083dcf5451SChristoph Hellwig /* 23093dcf5451SChristoph Hellwig * Special error return code only used by dx_probe() and its callers. 23103dcf5451SChristoph Hellwig */ 231136de9286STheodore Ts'o #define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1)) 23123dcf5451SChristoph Hellwig 2313e08ac99fSArtem Blagodarenko /* htree levels for ext4 */ 2314e08ac99fSArtem Blagodarenko #define EXT4_HTREE_LEVEL_COMPAT 2 2315e08ac99fSArtem Blagodarenko #define EXT4_HTREE_LEVEL 3 2316e08ac99fSArtem Blagodarenko 2317e08ac99fSArtem Blagodarenko static inline int ext4_dir_htree_level(struct super_block *sb) 2318e08ac99fSArtem Blagodarenko { 2319e08ac99fSArtem Blagodarenko return ext4_has_feature_largedir(sb) ? 2320e08ac99fSArtem Blagodarenko EXT4_HTREE_LEVEL : EXT4_HTREE_LEVEL_COMPAT; 2321e08ac99fSArtem Blagodarenko } 2322e08ac99fSArtem Blagodarenko 23233dcf5451SChristoph Hellwig /* 2324bfff6873SLukas Czerner * Timeout and state flag for lazy initialization inode thread. 2325bfff6873SLukas Czerner */ 2326bfff6873SLukas Czerner #define EXT4_DEF_LI_WAIT_MULT 10 2327bfff6873SLukas Czerner #define EXT4_DEF_LI_MAX_START_DELAY 5 2328bfff6873SLukas Czerner #define EXT4_LAZYINIT_QUIT 0x0001 2329bfff6873SLukas Czerner #define EXT4_LAZYINIT_RUNNING 0x0002 2330bfff6873SLukas Czerner 2331bfff6873SLukas Czerner /* 2332bfff6873SLukas Czerner * Lazy inode table initialization info 2333bfff6873SLukas Czerner */ 2334bfff6873SLukas Czerner struct ext4_lazy_init { 2335bfff6873SLukas Czerner unsigned long li_state; 2336bfff6873SLukas Czerner struct list_head li_request_list; 2337bfff6873SLukas Czerner struct mutex li_list_mtx; 2338bfff6873SLukas Czerner }; 2339bfff6873SLukas Czerner 23403d392b26STheodore Ts'o enum ext4_li_mode { 23413d392b26STheodore Ts'o EXT4_LI_MODE_PREFETCH_BBITMAP, 23423d392b26STheodore Ts'o EXT4_LI_MODE_ITABLE, 23433d392b26STheodore Ts'o }; 23443d392b26STheodore Ts'o 2345bfff6873SLukas Czerner struct ext4_li_request { 2346bfff6873SLukas Czerner struct super_block *lr_super; 23473d392b26STheodore Ts'o enum ext4_li_mode lr_mode; 23483d392b26STheodore Ts'o ext4_group_t lr_first_not_zeroed; 2349bfff6873SLukas Czerner ext4_group_t lr_next_group; 2350bfff6873SLukas Czerner struct list_head lr_request; 2351bfff6873SLukas Czerner unsigned long lr_next_sched; 2352bfff6873SLukas Czerner unsigned long lr_timeout; 2353bfff6873SLukas Czerner }; 2354bfff6873SLukas Czerner 2355857ac889SLukas Czerner struct ext4_features { 2356857ac889SLukas Czerner struct kobject f_kobj; 2357857ac889SLukas Czerner struct completion f_kobj_unregister; 2358857ac889SLukas Czerner }; 2359857ac889SLukas Czerner 2360bfff6873SLukas Czerner /* 2361c5e06d10SJohann Lombardi * This structure will be used for multiple mount protection. It will be 2362c5e06d10SJohann Lombardi * written into the block number saved in the s_mmp_block field in the 2363c5e06d10SJohann Lombardi * superblock. Programs that check MMP should assume that if 2364c5e06d10SJohann Lombardi * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe 2365c5e06d10SJohann Lombardi * to use the filesystem, regardless of how old the timestamp is. 2366c5e06d10SJohann Lombardi */ 2367c5e06d10SJohann Lombardi #define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ 2368c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ 2369c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ 2370c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ 2371c5e06d10SJohann Lombardi 2372c5e06d10SJohann Lombardi struct mmp_struct { 2373c5e06d10SJohann Lombardi __le32 mmp_magic; /* Magic number for MMP */ 2374c5e06d10SJohann Lombardi __le32 mmp_seq; /* Sequence no. updated periodically */ 2375c5e06d10SJohann Lombardi 2376c5e06d10SJohann Lombardi /* 2377c5e06d10SJohann Lombardi * mmp_time, mmp_nodename & mmp_bdevname are only used for information 2378c5e06d10SJohann Lombardi * purposes and do not affect the correctness of the algorithm 2379c5e06d10SJohann Lombardi */ 2380c5e06d10SJohann Lombardi __le64 mmp_time; /* Time last updated */ 2381c5e06d10SJohann Lombardi char mmp_nodename[64]; /* Node which last updated MMP block */ 2382c5e06d10SJohann Lombardi char mmp_bdevname[32]; /* Bdev which last updated MMP block */ 2383c5e06d10SJohann Lombardi 2384c5e06d10SJohann Lombardi /* 2385c5e06d10SJohann Lombardi * mmp_check_interval is used to verify if the MMP block has been 2386c5e06d10SJohann Lombardi * updated on the block device. The value is updated based on the 2387c5e06d10SJohann Lombardi * maximum time to write the MMP block during an update cycle. 2388c5e06d10SJohann Lombardi */ 2389c5e06d10SJohann Lombardi __le16 mmp_check_interval; 2390c5e06d10SJohann Lombardi 2391c5e06d10SJohann Lombardi __le16 mmp_pad1; 2392e6153918SDarrick J. Wong __le32 mmp_pad2[226]; 2393e6153918SDarrick J. Wong __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */ 2394c5e06d10SJohann Lombardi }; 2395c5e06d10SJohann Lombardi 2396c5e06d10SJohann Lombardi /* arguments passed to the mmp thread */ 2397c5e06d10SJohann Lombardi struct mmpd_data { 2398c5e06d10SJohann Lombardi struct buffer_head *bh; /* bh from initial read_mmp_block() */ 2399c5e06d10SJohann Lombardi struct super_block *sb; /* super block of the fs */ 2400c5e06d10SJohann Lombardi }; 2401c5e06d10SJohann Lombardi 2402c5e06d10SJohann Lombardi /* 2403c5e06d10SJohann Lombardi * Check interval multiplier 2404c5e06d10SJohann Lombardi * The MMP block is written every update interval and initially checked every 2405c5e06d10SJohann Lombardi * update interval x the multiplier (the value is then adapted based on the 2406c5e06d10SJohann Lombardi * write latency). The reason is that writes can be delayed under load and we 2407c5e06d10SJohann Lombardi * don't want readers to incorrectly assume that the filesystem is no longer 2408c5e06d10SJohann Lombardi * in use. 2409c5e06d10SJohann Lombardi */ 2410c5e06d10SJohann Lombardi #define EXT4_MMP_CHECK_MULT 2UL 2411c5e06d10SJohann Lombardi 2412c5e06d10SJohann Lombardi /* 2413c5e06d10SJohann Lombardi * Minimum interval for MMP checking in seconds. 2414c5e06d10SJohann Lombardi */ 2415c5e06d10SJohann Lombardi #define EXT4_MMP_MIN_CHECK_INTERVAL 5UL 2416c5e06d10SJohann Lombardi 2417c5e06d10SJohann Lombardi /* 2418c5e06d10SJohann Lombardi * Maximum interval for MMP checking in seconds. 2419c5e06d10SJohann Lombardi */ 2420c5e06d10SJohann Lombardi #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL 2421c5e06d10SJohann Lombardi 2422c5e06d10SJohann Lombardi /* 24233dcf5451SChristoph Hellwig * Function prototypes 24243dcf5451SChristoph Hellwig */ 24253dcf5451SChristoph Hellwig 24263dcf5451SChristoph Hellwig /* 24273dcf5451SChristoph Hellwig * Ok, these declarations are also in <linux/kernel.h> but none of the 24283dcf5451SChristoph Hellwig * ext4 source programs needs to include it so they are duplicated here. 24293dcf5451SChristoph Hellwig */ 24303dcf5451SChristoph Hellwig # define NORET_TYPE /**/ 24313dcf5451SChristoph Hellwig # define ATTRIB_NORET __attribute__((noreturn)) 24323dcf5451SChristoph Hellwig # define NORET_AND noreturn, 24333dcf5451SChristoph Hellwig 2434498e5f24STheodore Ts'o /* bitmap.c */ 2435f6fb99caSTheodore Ts'o extern unsigned int ext4_count_free(char *bitmap, unsigned numchars); 243641a246d1SDarrick J. Wong void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 243741a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 243841a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 243941a246d1SDarrick J. Wong int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 244041a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 244141a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 2442fa77dcfaSDarrick J. Wong void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 2443fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 244479f1ba49STao Ma struct buffer_head *bh); 2445fa77dcfaSDarrick J. Wong int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 2446fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 244779f1ba49STao Ma struct buffer_head *bh); 2448498e5f24STheodore Ts'o 24493dcf5451SChristoph Hellwig /* balloc.c */ 2450bd86298eSLukas Czerner extern void ext4_get_group_no_and_offset(struct super_block *sb, 2451bd86298eSLukas Czerner ext4_fsblk_t blocknr, 2452bd86298eSLukas Czerner ext4_group_t *blockgrpp, 2453bd86298eSLukas Czerner ext4_grpblk_t *offsetp); 2454bd86298eSLukas Czerner extern ext4_group_t ext4_get_group_number(struct super_block *sb, 2455bd86298eSLukas Czerner ext4_fsblk_t block); 2456bd86298eSLukas Czerner 24573dcf5451SChristoph Hellwig extern unsigned int ext4_block_group(struct super_block *sb, 24583dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 24593dcf5451SChristoph Hellwig extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb, 24603dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 24613dcf5451SChristoph Hellwig extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group); 24623dcf5451SChristoph Hellwig extern unsigned long ext4_bg_num_gdb(struct super_block *sb, 24633dcf5451SChristoph Hellwig ext4_group_t group); 24647061eba7SAneesh Kumar K.V extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 246555f020dbSAllison Henderson ext4_fsblk_t goal, 246655f020dbSAllison Henderson unsigned int flags, 246755f020dbSAllison Henderson unsigned long *count, 246855f020dbSAllison Henderson int *errp); 2469e7d5f315STheodore Ts'o extern int ext4_claim_free_clusters(struct ext4_sb_info *sbi, 2470e7d5f315STheodore Ts'o s64 nclusters, unsigned int flags); 24715dee5437STheodore Ts'o extern ext4_fsblk_t ext4_count_free_clusters(struct super_block *); 24723dcf5451SChristoph Hellwig extern void ext4_check_blocks_bitmap(struct super_block *); 24733dcf5451SChristoph Hellwig extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 24743dcf5451SChristoph Hellwig ext4_group_t block_group, 24753dcf5451SChristoph Hellwig struct buffer_head ** bh); 24763dcf5451SChristoph Hellwig extern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 2477813e5727STheodore Ts'o 2478813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb, 2479cfd73237SAlex Zhuravlev ext4_group_t block_group, 2480cfd73237SAlex Zhuravlev bool ignore_locked); 2481813e5727STheodore Ts'o extern int ext4_wait_block_bitmap(struct super_block *sb, 2482813e5727STheodore Ts'o ext4_group_t block_group, 2483813e5727STheodore Ts'o struct buffer_head *bh); 2484813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb, 2485bb23c20aSTheodore Ts'o ext4_group_t block_group); 2486cff1dfd7STheodore Ts'o extern unsigned ext4_free_clusters_after_init(struct super_block *sb, 2487fd034a84STheodore Ts'o ext4_group_t block_group, 2488fd034a84STheodore Ts'o struct ext4_group_desc *gdp); 2489f86186b4SEric Sandeen ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); 24903dcf5451SChristoph Hellwig 24913ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 24923ae72562SGabriel Krisman Bertazi extern void ext4_fname_setup_ci_filename(struct inode *dir, 24933ae72562SGabriel Krisman Bertazi const struct qstr *iname, 24943ae72562SGabriel Krisman Bertazi struct fscrypt_str *fname); 24953ae72562SGabriel Krisman Bertazi #endif 24963ae72562SGabriel Krisman Bertazi 2497643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 2498b01531dbSEric Biggers static inline void ext4_fname_from_fscrypt_name(struct ext4_filename *dst, 2499b01531dbSEric Biggers const struct fscrypt_name *src) 2500b01531dbSEric Biggers { 2501b01531dbSEric Biggers memset(dst, 0, sizeof(*dst)); 2502b01531dbSEric Biggers 2503b01531dbSEric Biggers dst->usr_fname = src->usr_fname; 2504b01531dbSEric Biggers dst->disk_name = src->disk_name; 2505b01531dbSEric Biggers dst->hinfo.hash = src->hash; 2506b01531dbSEric Biggers dst->hinfo.minor_hash = src->minor_hash; 2507b01531dbSEric Biggers dst->crypto_buf = src->crypto_buf; 2508b01531dbSEric Biggers } 2509b01531dbSEric Biggers 2510a7550b30SJaegeuk Kim static inline int ext4_fname_setup_filename(struct inode *dir, 2511a7550b30SJaegeuk Kim const struct qstr *iname, 2512b01531dbSEric Biggers int lookup, 2513b01531dbSEric Biggers struct ext4_filename *fname) 2514a7550b30SJaegeuk Kim { 2515a7550b30SJaegeuk Kim struct fscrypt_name name; 2516a7550b30SJaegeuk Kim int err; 2517a7550b30SJaegeuk Kim 2518a7550b30SJaegeuk Kim err = fscrypt_setup_filename(dir, iname, lookup, &name); 2519b01531dbSEric Biggers if (err) 2520a7550b30SJaegeuk Kim return err; 2521b01531dbSEric Biggers 2522b01531dbSEric Biggers ext4_fname_from_fscrypt_name(fname, &name); 25233ae72562SGabriel Krisman Bertazi 25243ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 25253ae72562SGabriel Krisman Bertazi ext4_fname_setup_ci_filename(dir, iname, &fname->cf_name); 25263ae72562SGabriel Krisman Bertazi #endif 2527b01531dbSEric Biggers return 0; 2528b01531dbSEric Biggers } 2529b01531dbSEric Biggers 2530b01531dbSEric Biggers static inline int ext4_fname_prepare_lookup(struct inode *dir, 2531b01531dbSEric Biggers struct dentry *dentry, 2532b01531dbSEric Biggers struct ext4_filename *fname) 2533b01531dbSEric Biggers { 2534b01531dbSEric Biggers struct fscrypt_name name; 2535b01531dbSEric Biggers int err; 2536b01531dbSEric Biggers 2537b01531dbSEric Biggers err = fscrypt_prepare_lookup(dir, dentry, &name); 2538b01531dbSEric Biggers if (err) 2539b01531dbSEric Biggers return err; 2540b01531dbSEric Biggers 2541b01531dbSEric Biggers ext4_fname_from_fscrypt_name(fname, &name); 25423ae72562SGabriel Krisman Bertazi 25433ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 25443ae72562SGabriel Krisman Bertazi ext4_fname_setup_ci_filename(dir, &dentry->d_name, &fname->cf_name); 25453ae72562SGabriel Krisman Bertazi #endif 2546b01531dbSEric Biggers return 0; 2547a7550b30SJaegeuk Kim } 2548a7550b30SJaegeuk Kim 2549a7550b30SJaegeuk Kim static inline void ext4_fname_free_filename(struct ext4_filename *fname) 2550a7550b30SJaegeuk Kim { 2551a7550b30SJaegeuk Kim struct fscrypt_name name; 2552a7550b30SJaegeuk Kim 2553a7550b30SJaegeuk Kim name.crypto_buf = fname->crypto_buf; 2554a7550b30SJaegeuk Kim fscrypt_free_filename(&name); 2555a7550b30SJaegeuk Kim 2556a7550b30SJaegeuk Kim fname->crypto_buf.name = NULL; 2557a7550b30SJaegeuk Kim fname->usr_fname = NULL; 2558a7550b30SJaegeuk Kim fname->disk_name.name = NULL; 25593ae72562SGabriel Krisman Bertazi 25603ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 25613ae72562SGabriel Krisman Bertazi kfree(fname->cf_name.name); 25623ae72562SGabriel Krisman Bertazi fname->cf_name.name = NULL; 25633ae72562SGabriel Krisman Bertazi #endif 2564a7550b30SJaegeuk Kim } 2565b01531dbSEric Biggers #else /* !CONFIG_FS_ENCRYPTION */ 25665b643f9cSTheodore Ts'o static inline int ext4_fname_setup_filename(struct inode *dir, 25675b643f9cSTheodore Ts'o const struct qstr *iname, 2568b01531dbSEric Biggers int lookup, 2569b01531dbSEric Biggers struct ext4_filename *fname) 25705b643f9cSTheodore Ts'o { 25715b643f9cSTheodore Ts'o fname->usr_fname = iname; 25725b643f9cSTheodore Ts'o fname->disk_name.name = (unsigned char *) iname->name; 25735b643f9cSTheodore Ts'o fname->disk_name.len = iname->len; 25743ae72562SGabriel Krisman Bertazi 25753ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 25763ae72562SGabriel Krisman Bertazi ext4_fname_setup_ci_filename(dir, iname, &fname->cf_name); 25773ae72562SGabriel Krisman Bertazi #endif 25783ae72562SGabriel Krisman Bertazi 25795b643f9cSTheodore Ts'o return 0; 25805b643f9cSTheodore Ts'o } 2581a7550b30SJaegeuk Kim 2582b01531dbSEric Biggers static inline int ext4_fname_prepare_lookup(struct inode *dir, 2583b01531dbSEric Biggers struct dentry *dentry, 2584b01531dbSEric Biggers struct ext4_filename *fname) 2585b01531dbSEric Biggers { 2586b01531dbSEric Biggers return ext4_fname_setup_filename(dir, &dentry->d_name, 1, fname); 2587b01531dbSEric Biggers } 2588b01531dbSEric Biggers 25893ae72562SGabriel Krisman Bertazi static inline void ext4_fname_free_filename(struct ext4_filename *fname) 25903ae72562SGabriel Krisman Bertazi { 25913ae72562SGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 25923ae72562SGabriel Krisman Bertazi kfree(fname->cf_name.name); 25933ae72562SGabriel Krisman Bertazi fname->cf_name.name = NULL; 25943ae72562SGabriel Krisman Bertazi #endif 25953ae72562SGabriel Krisman Bertazi } 2596b01531dbSEric Biggers #endif /* !CONFIG_FS_ENCRYPTION */ 2597d5d0e8c7SMichael Halcrow 25983dcf5451SChristoph Hellwig /* dir.c */ 259960fd4da3STheodore Ts'o extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *, 2600f7c21177STheodore Ts'o struct file *, 26013dcf5451SChristoph Hellwig struct ext4_dir_entry_2 *, 2602226ba972STao Ma struct buffer_head *, char *, int, 2603226ba972STao Ma unsigned int); 2604226ba972STao Ma #define ext4_check_dir_entry(dir, filp, de, bh, buf, size, offset) \ 2605f7c21177STheodore Ts'o unlikely(__ext4_check_dir_entry(__func__, __LINE__, (dir), (filp), \ 2606226ba972STao Ma (de), (bh), (buf), (size), (offset))) 26073dcf5451SChristoph Hellwig extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 26083dcf5451SChristoph Hellwig __u32 minor_hash, 26092f61830aSTheodore Ts'o struct ext4_dir_entry_2 *dirent, 2610a7550b30SJaegeuk Kim struct fscrypt_str *ent_name); 26113dcf5451SChristoph Hellwig extern void ext4_htree_free_dir_info(struct dir_private_info *p); 2612978fef91STao Ma extern int ext4_find_dest_de(struct inode *dir, struct inode *inode, 2613978fef91STao Ma struct buffer_head *bh, 2614978fef91STao Ma void *buf, int buf_size, 26155b643f9cSTheodore Ts'o struct ext4_filename *fname, 2616978fef91STao Ma struct ext4_dir_entry_2 **dest_de); 26171bc0af60SEric Biggers void ext4_insert_dentry(struct inode *inode, 2618978fef91STao Ma struct ext4_dir_entry_2 *de, 2619978fef91STao Ma int buf_size, 26205b643f9cSTheodore Ts'o struct ext4_filename *fname); 2621978fef91STao Ma static inline void ext4_update_dx_flag(struct inode *inode) 2622978fef91STao Ma { 262348a34311SJan Kara if (!ext4_has_feature_dir_index(inode->i_sb)) { 262448a34311SJan Kara /* ext4_iget() should have caught this... */ 262548a34311SJan Kara WARN_ON_ONCE(ext4_has_feature_metadata_csum(inode->i_sb)); 2626978fef91STao Ma ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); 2627978fef91STao Ma } 262848a34311SJan Kara } 2629d6006186SEric Biggers static const unsigned char ext4_filetype_table[] = { 263065d165d9STao Ma DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 263165d165d9STao Ma }; 263265d165d9STao Ma 263365d165d9STao Ma static inline unsigned char get_dtype(struct super_block *sb, int filetype) 263465d165d9STao Ma { 2635e2b911c5SDarrick J. Wong if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) 263665d165d9STao Ma return DT_UNKNOWN; 263765d165d9STao Ma 263865d165d9STao Ma return ext4_filetype_table[filetype]; 263965d165d9STao Ma } 264040b163f1SDarrick J. Wong extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, 264140b163f1SDarrick J. Wong void *buf, int buf_size); 26423dcf5451SChristoph Hellwig 26433dcf5451SChristoph Hellwig /* fsync.c */ 264402c24a82SJosef Bacik extern int ext4_sync_file(struct file *, loff_t, loff_t, int); 26453dcf5451SChristoph Hellwig 26463dcf5451SChristoph Hellwig /* hash.c */ 2647b886ee3eSGabriel Krisman Bertazi extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len, 2648b886ee3eSGabriel Krisman Bertazi struct dx_hash_info *hinfo); 26493dcf5451SChristoph Hellwig 26503dcf5451SChristoph Hellwig /* ialloc.c */ 26511139575aSTheodore Ts'o extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t, 26525cb81dabSDmitry Monakhov const struct qstr *qstr, __u32 goal, 26531b917ed8STahsin Erdogan uid_t *owner, __u32 i_flags, 26541b917ed8STahsin Erdogan int handle_type, unsigned int line_no, 26551b917ed8STahsin Erdogan int nblocks); 26561139575aSTheodore Ts'o 26571b917ed8STahsin Erdogan #define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \ 26581139575aSTheodore Ts'o __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \ 26591b917ed8STahsin Erdogan i_flags, 0, 0, 0) 26601139575aSTheodore Ts'o #define ext4_new_inode_start_handle(dir, mode, qstr, goal, owner, \ 26611139575aSTheodore Ts'o type, nblocks) \ 26621139575aSTheodore Ts'o __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \ 26631b917ed8STahsin Erdogan 0, (type), __LINE__, (nblocks)) 26641139575aSTheodore Ts'o 26651139575aSTheodore Ts'o 26663dcf5451SChristoph Hellwig extern void ext4_free_inode(handle_t *, struct inode *); 26673dcf5451SChristoph Hellwig extern struct inode * ext4_orphan_get(struct super_block *, unsigned long); 26683dcf5451SChristoph Hellwig extern unsigned long ext4_count_free_inodes(struct super_block *); 26693dcf5451SChristoph Hellwig extern unsigned long ext4_count_dirs(struct super_block *); 26703dcf5451SChristoph Hellwig extern void ext4_check_inodes_bitmap(struct super_block *); 267161d08673STheodore Ts'o extern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap); 2672bfff6873SLukas Czerner extern int ext4_init_inode_table(struct super_block *sb, 2673bfff6873SLukas Czerner ext4_group_t group, int barrier); 2674813e5727STheodore Ts'o extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 26753dcf5451SChristoph Hellwig 26763dcf5451SChristoph Hellwig /* mballoc.c */ 2677247dbed8SChristoph Hellwig extern const struct seq_operations ext4_mb_seq_groups_ops; 26783dcf5451SChristoph Hellwig extern long ext4_mb_stats; 26793dcf5451SChristoph Hellwig extern long ext4_mb_max_to_scan; 26809d99012fSAkira Fujita extern int ext4_mb_init(struct super_block *); 26813dcf5451SChristoph Hellwig extern int ext4_mb_release(struct super_block *); 26823dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 26833dcf5451SChristoph Hellwig struct ext4_allocation_request *, int *); 26843dcf5451SChristoph Hellwig extern int ext4_mb_reserve_blocks(struct super_block *, int); 2685c2ea3fdeSTheodore Ts'o extern void ext4_discard_preallocations(struct inode *); 26865dabfc78STheodore Ts'o extern int __init ext4_init_mballoc(void); 26875dabfc78STheodore Ts'o extern void ext4_exit_mballoc(void); 26883d392b26STheodore Ts'o extern ext4_group_t ext4_mb_prefetch(struct super_block *sb, 26893d392b26STheodore Ts'o ext4_group_t group, 26903d392b26STheodore Ts'o unsigned int nr, int *cnt); 26913d392b26STheodore Ts'o extern void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group, 26923d392b26STheodore Ts'o unsigned int nr); 26933d392b26STheodore Ts'o 269444338711STheodore Ts'o extern void ext4_free_blocks(handle_t *handle, struct inode *inode, 2695e6362609STheodore Ts'o struct buffer_head *bh, ext4_fsblk_t block, 2696e6362609STheodore Ts'o unsigned long count, int flags); 269728623c2fSTheodore Ts'o extern int ext4_mb_alloc_groupinfo(struct super_block *sb, 269828623c2fSTheodore Ts'o ext4_group_t ngroups); 2699920313a7SAneesh Kumar K.V extern int ext4_mb_add_groupinfo(struct super_block *sb, 27005f21b0e6SFrederic Bohe ext4_group_t i, struct ext4_group_desc *desc); 2701cc7365dfSYongqiang Yang extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, 27022846e820SAmir Goldstein ext4_fsblk_t block, unsigned long count); 27037360d173SLukas Czerner extern int ext4_trim_fs(struct super_block *, struct fstrim_range *); 2704a0154344SDaeho Jeong extern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid); 27057360d173SLukas Czerner 27063dcf5451SChristoph Hellwig /* inode.c */ 2707f348c252STheodore Ts'o int ext4_inode_is_fast_symlink(struct inode *inode); 270810560082STheodore Ts'o struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); 27091c215028STheodore Ts'o struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); 27109699d4f9STahsin Erdogan int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, 27119699d4f9STahsin Erdogan bool wait, struct buffer_head **bhs); 2712705965bdSJan Kara int ext4_get_block_unwritten(struct inode *inode, sector_t iblock, 2713f19d5870STao Ma struct buffer_head *bh_result, int create); 27146873fa0dSEric Sandeen int ext4_get_block(struct inode *inode, sector_t iblock, 27156873fa0dSEric Sandeen struct buffer_head *bh_result, int create); 27169c3569b5STao Ma int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, 27179c3569b5STao Ma struct buffer_head *bh, int create); 2718f19d5870STao Ma int ext4_walk_page_buffers(handle_t *handle, 2719f19d5870STao Ma struct buffer_head *head, 2720f19d5870STao Ma unsigned from, 2721f19d5870STao Ma unsigned to, 2722f19d5870STao Ma int *partial, 2723f19d5870STao Ma int (*fn)(handle_t *handle, 2724f19d5870STao Ma struct buffer_head *bh)); 2725f19d5870STao Ma int do_journal_get_write_access(handle_t *handle, 2726f19d5870STao Ma struct buffer_head *bh); 27279c3569b5STao Ma #define FALL_BACK_TO_NONDELALLOC 1 27289c3569b5STao Ma #define CONVERT_INLINE_DATA 2 27293dcf5451SChristoph Hellwig 27308a363970STheodore Ts'o typedef enum { 27318a363970STheodore Ts'o EXT4_IGET_NORMAL = 0, 27328a363970STheodore Ts'o EXT4_IGET_SPECIAL = 0x0001, /* OK to iget a system inode */ 27338a363970STheodore Ts'o EXT4_IGET_HANDLE = 0x0002 /* Inode # is from a handle */ 27348a363970STheodore Ts'o } ext4_iget_flags; 27358a363970STheodore Ts'o 27368a363970STheodore Ts'o extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, 27378a363970STheodore Ts'o ext4_iget_flags flags, const char *function, 27388a363970STheodore Ts'o unsigned int line); 27398a363970STheodore Ts'o 27408a363970STheodore Ts'o #define ext4_iget(sb, ino, flags) \ 27418a363970STheodore Ts'o __ext4_iget((sb), (ino), (flags), __func__, __LINE__) 27428a363970STheodore Ts'o 2743a9185b41SChristoph Hellwig extern int ext4_write_inode(struct inode *, struct writeback_control *); 27443dcf5451SChristoph Hellwig extern int ext4_setattr(struct dentry *, struct iattr *); 2745a528d35eSDavid Howells extern int ext4_getattr(const struct path *, struct kstat *, u32, unsigned int); 27460930fcc1SAl Viro extern void ext4_evict_inode(struct inode *); 27470930fcc1SAl Viro extern void ext4_clear_inode(struct inode *); 274899652ea5SDavid Howells extern int ext4_file_getattr(const struct path *, struct kstat *, u32, unsigned int); 27493dcf5451SChristoph Hellwig extern int ext4_sync_inode(handle_t *, struct inode *); 2750aa385729SChristoph Hellwig extern void ext4_dirty_inode(struct inode *, int); 27513dcf5451SChristoph Hellwig extern int ext4_change_inode_journal_flag(struct inode *, int); 27523dcf5451SChristoph Hellwig extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *); 2753a361293fSJan Kara extern int ext4_inode_attach_jinode(struct inode *inode); 275491ef4cafSDuane Griffin extern int ext4_can_truncate(struct inode *inode); 27552c98eb5eSTheodore Ts'o extern int ext4_truncate(struct inode *); 2756430657b6SRoss Zwisler extern int ext4_break_layouts(struct inode *); 2757aeb2817aSAshish Sangwan extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length); 2758043546e4SIra Weiny extern void ext4_set_inode_flags(struct inode *, bool init); 2759ccd2506bSTheodore Ts'o extern int ext4_alloc_da_blocks(struct inode *inode); 27603dcf5451SChristoph Hellwig extern void ext4_set_aops(struct inode *inode); 27613dcf5451SChristoph Hellwig extern int ext4_writepage_trans_blocks(struct inode *); 2762f3bd1f3fSMingming Cao extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); 2763a87dd18cSLukas Czerner extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 2764a87dd18cSLukas Czerner loff_t lstart, loff_t lend); 2765401b25aaSSouptick Joarder extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); 2766401b25aaSSouptick Joarder extern vm_fault_t ext4_filemap_fault(struct vm_fault *vmf); 2767a9e7f447SDmitry Monakhov extern qsize_t *ext4_get_reserved_space(struct inode *inode); 2768040cb378SLi Xi extern int ext4_get_projid(struct inode *inode, kprojid_t *projid); 2769f456767dSEric Whitney extern void ext4_da_release_space(struct inode *inode, int to_free); 27705f634d06SAneesh Kumar K.V extern void ext4_da_update_reserve_space(struct inode *inode, 27715f634d06SAneesh Kumar K.V int used, int quota_claim); 277253085facSJan Kara extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, 277353085facSJan Kara ext4_fsblk_t pblk, ext4_lblk_t len); 2774dae1e52cSAmir Goldstein 2775dae1e52cSAmir Goldstein /* indirect.c */ 2776dae1e52cSAmir Goldstein extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 2777dae1e52cSAmir Goldstein struct ext4_map_blocks *map, int flags); 2778fa55a0edSJan Kara extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 2779819c4920STheodore Ts'o extern void ext4_ind_truncate(handle_t *, struct inode *inode); 27804f579ae7SLukas Czerner extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode, 27814f579ae7SLukas Czerner ext4_lblk_t start, ext4_lblk_t end); 2782ff9893dcSAmir Goldstein 27833dcf5451SChristoph Hellwig /* ioctl.c */ 27843dcf5451SChristoph Hellwig extern long ext4_ioctl(struct file *, unsigned int, unsigned long); 27853dcf5451SChristoph Hellwig extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long); 27863dcf5451SChristoph Hellwig 27873dcf5451SChristoph Hellwig /* migrate.c */ 27882a43a878SAneesh Kumar K.V extern int ext4_ext_migrate(struct inode *); 27890d14b098SLukas Czerner extern int ext4_ind_migrate(struct inode *inode); 27903d0518f4SWei Yongjun 27913dcf5451SChristoph Hellwig /* namei.c */ 2792f036adb3STheodore Ts'o extern int ext4_dirblock_csum_verify(struct inode *inode, 2793f036adb3STheodore Ts'o struct buffer_head *bh); 27943dcf5451SChristoph Hellwig extern int ext4_orphan_add(handle_t *, struct inode *); 27953dcf5451SChristoph Hellwig extern int ext4_orphan_del(handle_t *, struct inode *); 27963dcf5451SChristoph Hellwig extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 27973dcf5451SChristoph Hellwig __u32 start_minor_hash, __u32 *next_hash); 27985b643f9cSTheodore Ts'o extern int ext4_search_dir(struct buffer_head *bh, 27997335cd3bSTao Ma char *search_buf, 28007335cd3bSTao Ma int buf_size, 28017335cd3bSTao Ma struct inode *dir, 28025b643f9cSTheodore Ts'o struct ext4_filename *fname, 28037335cd3bSTao Ma unsigned int offset, 28047335cd3bSTao Ma struct ext4_dir_entry_2 **res_dir); 280505019a9eSTao Ma extern int ext4_generic_delete_entry(handle_t *handle, 280605019a9eSTao Ma struct inode *dir, 280705019a9eSTao Ma struct ext4_dir_entry_2 *de_del, 280805019a9eSTao Ma struct buffer_head *bh, 280905019a9eSTao Ma void *entry_buf, 281005019a9eSTao Ma int buf_size, 281105019a9eSTao Ma int csum_size); 2812a7550b30SJaegeuk Kim extern bool ext4_empty_dir(struct inode *inode); 28133dcf5451SChristoph Hellwig 28143dcf5451SChristoph Hellwig /* resize.c */ 28151d0c3924STheodore Ts'o extern void ext4_kvfree_array_rcu(void *to_free); 28163dcf5451SChristoph Hellwig extern int ext4_group_add(struct super_block *sb, 28173dcf5451SChristoph Hellwig struct ext4_new_group_data *input); 28183dcf5451SChristoph Hellwig extern int ext4_group_extend(struct super_block *sb, 28193dcf5451SChristoph Hellwig struct ext4_super_block *es, 28203dcf5451SChristoph Hellwig ext4_fsblk_t n_blocks_count); 282119c5246dSYongqiang Yang extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 28223dcf5451SChristoph Hellwig 28233dcf5451SChristoph Hellwig /* super.c */ 2824fb265c9cSTheodore Ts'o extern struct buffer_head *ext4_sb_bread(struct super_block *sb, 2825fb265c9cSTheodore Ts'o sector_t block, int op_flags); 2826ebd173beSTheodore Ts'o extern int ext4_seq_options_show(struct seq_file *seq, void *offset); 2827952fc18eSTheodore Ts'o extern int ext4_calculate_overhead(struct super_block *sb); 282806db49e6STheodore Ts'o extern void ext4_superblock_csum_set(struct super_block *sb); 2829117fff10STheodore Ts'o extern int ext4_alloc_flex_bg_array(struct super_block *sb, 2830117fff10STheodore Ts'o ext4_group_t ngroup); 2831722887ddSTheodore Ts'o extern const char *ext4_decode_error(struct super_block *sb, int errno, 2832722887ddSTheodore Ts'o char nbuf[16]); 2833db79e6d1SWang Shilong extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb, 2834db79e6d1SWang Shilong ext4_group_t block_group, 2835db79e6d1SWang Shilong unsigned int flags); 2836e7c96e8eSJoe Perches 283754d3adbcSTheodore Ts'o extern __printf(6, 7) 283854d3adbcSTheodore Ts'o void __ext4_error(struct super_block *, const char *, unsigned int, int, __u64, 2839b9075fa9SJoe Perches const char *, ...); 284054d3adbcSTheodore Ts'o extern __printf(6, 7) 284154d3adbcSTheodore Ts'o void __ext4_error_inode(struct inode *, const char *, unsigned int, 284254d3adbcSTheodore Ts'o ext4_fsblk_t, int, const char *, ...); 2843b9075fa9SJoe Perches extern __printf(5, 6) 2844e7c96e8eSJoe Perches void __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t, 2845b9075fa9SJoe Perches const char *, ...); 2846c398eda0STheodore Ts'o extern void __ext4_std_error(struct super_block *, const char *, 2847c398eda0STheodore Ts'o unsigned int, int); 284854d3adbcSTheodore Ts'o extern __printf(5, 6) 284954d3adbcSTheodore Ts'o void __ext4_abort(struct super_block *, const char *, unsigned int, int, 2850b9075fa9SJoe Perches const char *, ...); 2851b9075fa9SJoe Perches extern __printf(4, 5) 2852b9075fa9SJoe Perches void __ext4_warning(struct super_block *, const char *, unsigned int, 2853b9075fa9SJoe Perches const char *, ...); 2854b03a2f7eSAndreas Dilger extern __printf(4, 5) 2855b03a2f7eSAndreas Dilger void __ext4_warning_inode(const struct inode *inode, const char *function, 2856b03a2f7eSAndreas Dilger unsigned int line, const char *fmt, ...); 2857b9075fa9SJoe Perches extern __printf(3, 4) 2858e7c96e8eSJoe Perches void __ext4_msg(struct super_block *, const char *, const char *, ...); 2859c5e06d10SJohann Lombardi extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp, 2860c5e06d10SJohann Lombardi const char *, unsigned int, const char *); 2861b9075fa9SJoe Perches extern __printf(7, 8) 2862b9075fa9SJoe Perches void __ext4_grp_locked_error(const char *, unsigned int, 2863b9075fa9SJoe Perches struct super_block *, ext4_group_t, 2864b9075fa9SJoe Perches unsigned long, ext4_fsblk_t, 2865b9075fa9SJoe Perches const char *, ...); 2866e7c96e8eSJoe Perches 2867b03a2f7eSAndreas Dilger #define EXT4_ERROR_INODE(inode, fmt, a...) \ 2868b03a2f7eSAndreas Dilger ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a) 2869b03a2f7eSAndreas Dilger 287054d3adbcSTheodore Ts'o #define EXT4_ERROR_INODE_ERR(inode, err, fmt, a...) \ 287154d3adbcSTheodore Ts'o __ext4_error_inode((inode), __func__, __LINE__, 0, (err), (fmt), ## a) 287254d3adbcSTheodore Ts'o 287354d3adbcSTheodore Ts'o #define ext4_error_inode_block(inode, block, err, fmt, a...) \ 287454d3adbcSTheodore Ts'o __ext4_error_inode((inode), __func__, __LINE__, (block), (err), \ 287554d3adbcSTheodore Ts'o (fmt), ## a) 2876b03a2f7eSAndreas Dilger 2877b03a2f7eSAndreas Dilger #define EXT4_ERROR_FILE(file, block, fmt, a...) \ 2878b03a2f7eSAndreas Dilger ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a) 2879b03a2f7eSAndreas Dilger 2880e7c96e8eSJoe Perches #ifdef CONFIG_PRINTK 2881e7c96e8eSJoe Perches 2882e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 288354d3adbcSTheodore Ts'o __ext4_error_inode(inode, func, line, block, 0, fmt, ##__VA_ARGS__) 288454d3adbcSTheodore Ts'o #define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 288554d3adbcSTheodore Ts'o __ext4_error_inode((inode), (func), (line), (block), \ 288654d3adbcSTheodore Ts'o (err), (fmt), ##__VA_ARGS__) 2887e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 2888e7c96e8eSJoe Perches __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__) 2889e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 289054d3adbcSTheodore Ts'o __ext4_error((sb), __func__, __LINE__, 0, 0, (fmt), ##__VA_ARGS__) 289154d3adbcSTheodore Ts'o #define ext4_error_err(sb, err, fmt, ...) \ 289254d3adbcSTheodore Ts'o __ext4_error((sb), __func__, __LINE__, (err), 0, (fmt), ##__VA_ARGS__) 289354d3adbcSTheodore Ts'o #define ext4_abort(sb, err, fmt, ...) \ 289454d3adbcSTheodore Ts'o __ext4_abort((sb), __func__, __LINE__, (err), (fmt), ##__VA_ARGS__) 2895e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 2896e7c96e8eSJoe Perches __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 2897b03a2f7eSAndreas Dilger #define ext4_warning_inode(inode, fmt, ...) \ 2898b03a2f7eSAndreas Dilger __ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__) 2899e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 2900e7c96e8eSJoe Perches __ext4_msg(sb, level, fmt, ##__VA_ARGS__) 2901e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 2902e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg) 2903e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 2904e7c96e8eSJoe Perches __ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino, block, \ 2905e7c96e8eSJoe Perches fmt, ##__VA_ARGS__) 2906e7c96e8eSJoe Perches 2907e7c96e8eSJoe Perches #else 2908e7c96e8eSJoe Perches 2909e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 2910e7c96e8eSJoe Perches do { \ 2911e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 291254d3adbcSTheodore Ts'o __ext4_error_inode(inode, "", 0, block, 0, " "); \ 291354d3adbcSTheodore Ts'o } while (0) 291454d3adbcSTheodore Ts'o #define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 291554d3adbcSTheodore Ts'o do { \ 291654d3adbcSTheodore Ts'o no_printk(fmt, ##__VA_ARGS__); \ 291754d3adbcSTheodore Ts'o __ext4_error_inode(inode, "", 0, block, err, " "); \ 2918e7c96e8eSJoe Perches } while (0) 2919e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 2920e7c96e8eSJoe Perches do { \ 2921e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2922e7c96e8eSJoe Perches __ext4_error_file(file, "", 0, block, " "); \ 2923e7c96e8eSJoe Perches } while (0) 2924e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 2925e7c96e8eSJoe Perches do { \ 2926e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 292754d3adbcSTheodore Ts'o __ext4_error(sb, "", 0, 0, 0, " "); \ 2928e7c96e8eSJoe Perches } while (0) 292954d3adbcSTheodore Ts'o #define ext4_error_err(sb, err, fmt, ...) \ 2930e7c96e8eSJoe Perches do { \ 2931e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 293254d3adbcSTheodore Ts'o __ext4_error(sb, "", 0, err, 0, " "); \ 293354d3adbcSTheodore Ts'o } while (0) 293454d3adbcSTheodore Ts'o #define ext4_abort(sb, err, fmt, ...) \ 293554d3adbcSTheodore Ts'o do { \ 293654d3adbcSTheodore Ts'o no_printk(fmt, ##__VA_ARGS__); \ 293754d3adbcSTheodore Ts'o __ext4_abort(sb, "", 0, err, " "); \ 2938e7c96e8eSJoe Perches } while (0) 2939e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 2940e7c96e8eSJoe Perches do { \ 2941e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2942e7c96e8eSJoe Perches __ext4_warning(sb, "", 0, " "); \ 2943e7c96e8eSJoe Perches } while (0) 2944b03a2f7eSAndreas Dilger #define ext4_warning_inode(inode, fmt, ...) \ 2945b03a2f7eSAndreas Dilger do { \ 2946b03a2f7eSAndreas Dilger no_printk(fmt, ##__VA_ARGS__); \ 2947b03a2f7eSAndreas Dilger __ext4_warning_inode(inode, "", 0, " "); \ 2948b03a2f7eSAndreas Dilger } while (0) 2949e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 2950e7c96e8eSJoe Perches do { \ 2951e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2952e7c96e8eSJoe Perches __ext4_msg(sb, "", " "); \ 2953e7c96e8eSJoe Perches } while (0) 2954e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 2955e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, "", 0, "") 2956e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 2957e7c96e8eSJoe Perches do { \ 2958e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2959e7c96e8eSJoe Perches __ext4_grp_locked_error("", 0, sb, grp, ino, block, " "); \ 2960e7c96e8eSJoe Perches } while (0) 2961e7c96e8eSJoe Perches 2962e7c96e8eSJoe Perches #endif 2963e7c96e8eSJoe Perches 29643dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 29653dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 29663dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 29673dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 29683dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_table(struct super_block *sb, 29693dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 2970021b65bbSTheodore Ts'o extern __u32 ext4_free_group_clusters(struct super_block *sb, 2971560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2972560671a0SAneesh Kumar K.V extern __u32 ext4_free_inodes_count(struct super_block *sb, 2973560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2974560671a0SAneesh Kumar K.V extern __u32 ext4_used_dirs_count(struct super_block *sb, 2975560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2976560671a0SAneesh Kumar K.V extern __u32 ext4_itable_unused_count(struct super_block *sb, 2977560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 29783dcf5451SChristoph Hellwig extern void ext4_block_bitmap_set(struct super_block *sb, 29793dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 29803dcf5451SChristoph Hellwig extern void ext4_inode_bitmap_set(struct super_block *sb, 29813dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 29823dcf5451SChristoph Hellwig extern void ext4_inode_table_set(struct super_block *sb, 29833dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 2984021b65bbSTheodore Ts'o extern void ext4_free_group_clusters_set(struct super_block *sb, 2985021b65bbSTheodore Ts'o struct ext4_group_desc *bg, 2986021b65bbSTheodore Ts'o __u32 count); 2987560671a0SAneesh Kumar K.V extern void ext4_free_inodes_set(struct super_block *sb, 2988560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2989560671a0SAneesh Kumar K.V extern void ext4_used_dirs_set(struct super_block *sb, 2990560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2991560671a0SAneesh Kumar K.V extern void ext4_itable_unused_set(struct super_block *sb, 2992560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2993feb0ab32SDarrick J. Wong extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group, 2994bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 2995feb0ab32SDarrick J. Wong extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group, 2996bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 29977f511862STheodore Ts'o extern int ext4_register_li_request(struct super_block *sb, 29987f511862STheodore Ts'o ext4_group_t first_not_zeroed); 29993dcf5451SChristoph Hellwig 30009aa5d32bSDmitry Monakhov static inline int ext4_has_metadata_csum(struct super_block *sb) 30019aa5d32bSDmitry Monakhov { 3002e2b911c5SDarrick J. Wong WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) && 30039aa5d32bSDmitry Monakhov !EXT4_SB(sb)->s_chksum_driver); 30049aa5d32bSDmitry Monakhov 3005dec214d0STahsin Erdogan return ext4_has_feature_metadata_csum(sb) && 3006dec214d0STahsin Erdogan (EXT4_SB(sb)->s_chksum_driver != NULL); 30079aa5d32bSDmitry Monakhov } 3008dec214d0STahsin Erdogan 3009dec214d0STahsin Erdogan static inline int ext4_has_group_desc_csum(struct super_block *sb) 3010dec214d0STahsin Erdogan { 3011dec214d0STahsin Erdogan return ext4_has_feature_gdt_csum(sb) || ext4_has_metadata_csum(sb); 3012dec214d0STahsin Erdogan } 3013dec214d0STahsin Erdogan 30143dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 30153dcf5451SChristoph Hellwig { 30163dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | 30173dcf5451SChristoph Hellwig le32_to_cpu(es->s_blocks_count_lo); 30183dcf5451SChristoph Hellwig } 30193dcf5451SChristoph Hellwig 30203dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) 30213dcf5451SChristoph Hellwig { 30223dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) | 30233dcf5451SChristoph Hellwig le32_to_cpu(es->s_r_blocks_count_lo); 30243dcf5451SChristoph Hellwig } 30253dcf5451SChristoph Hellwig 30263dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es) 30273dcf5451SChristoph Hellwig { 30283dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) | 30293dcf5451SChristoph Hellwig le32_to_cpu(es->s_free_blocks_count_lo); 30303dcf5451SChristoph Hellwig } 30313dcf5451SChristoph Hellwig 30323dcf5451SChristoph Hellwig static inline void ext4_blocks_count_set(struct ext4_super_block *es, 30333dcf5451SChristoph Hellwig ext4_fsblk_t blk) 30343dcf5451SChristoph Hellwig { 30353dcf5451SChristoph Hellwig es->s_blocks_count_lo = cpu_to_le32((u32)blk); 30363dcf5451SChristoph Hellwig es->s_blocks_count_hi = cpu_to_le32(blk >> 32); 30373dcf5451SChristoph Hellwig } 30383dcf5451SChristoph Hellwig 30393dcf5451SChristoph Hellwig static inline void ext4_free_blocks_count_set(struct ext4_super_block *es, 30403dcf5451SChristoph Hellwig ext4_fsblk_t blk) 30413dcf5451SChristoph Hellwig { 30423dcf5451SChristoph Hellwig es->s_free_blocks_count_lo = cpu_to_le32((u32)blk); 30433dcf5451SChristoph Hellwig es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32); 30443dcf5451SChristoph Hellwig } 30453dcf5451SChristoph Hellwig 30463dcf5451SChristoph Hellwig static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, 30473dcf5451SChristoph Hellwig ext4_fsblk_t blk) 30483dcf5451SChristoph Hellwig { 30493dcf5451SChristoph Hellwig es->s_r_blocks_count_lo = cpu_to_le32((u32)blk); 30503dcf5451SChristoph Hellwig es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32); 30513dcf5451SChristoph Hellwig } 30523dcf5451SChristoph Hellwig 3053e08ac99fSArtem Blagodarenko static inline loff_t ext4_isize(struct super_block *sb, 3054e08ac99fSArtem Blagodarenko struct ext4_inode *raw_inode) 30553dcf5451SChristoph Hellwig { 3056e08ac99fSArtem Blagodarenko if (ext4_has_feature_largedir(sb) || 3057e08ac99fSArtem Blagodarenko S_ISREG(le16_to_cpu(raw_inode->i_mode))) 30583dcf5451SChristoph Hellwig return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | 30593dcf5451SChristoph Hellwig le32_to_cpu(raw_inode->i_size_lo); 3060e08ac99fSArtem Blagodarenko 306106a279d6STheodore Ts'o return (loff_t) le32_to_cpu(raw_inode->i_size_lo); 30623dcf5451SChristoph Hellwig } 30633dcf5451SChristoph Hellwig 30643dcf5451SChristoph Hellwig static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) 30653dcf5451SChristoph Hellwig { 30663dcf5451SChristoph Hellwig raw_inode->i_size_lo = cpu_to_le32(i_size); 30673dcf5451SChristoph Hellwig raw_inode->i_size_high = cpu_to_le32(i_size >> 32); 30683dcf5451SChristoph Hellwig } 30693dcf5451SChristoph Hellwig 30703dcf5451SChristoph Hellwig static inline 30713dcf5451SChristoph Hellwig struct ext4_group_info *ext4_get_group_info(struct super_block *sb, 30723dcf5451SChristoph Hellwig ext4_group_t group) 30733dcf5451SChristoph Hellwig { 3074df3da4eaSSuraj Jitindar Singh struct ext4_group_info **grp_info; 30753dcf5451SChristoph Hellwig long indexv, indexh; 30762f2e09ebSTheodore Ts'o BUG_ON(group >= EXT4_SB(sb)->s_groups_count); 30773dcf5451SChristoph Hellwig indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb)); 30783dcf5451SChristoph Hellwig indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1); 3079df3da4eaSSuraj Jitindar Singh grp_info = sbi_array_rcu_deref(EXT4_SB(sb), s_group_info, indexv); 3080df3da4eaSSuraj Jitindar Singh return grp_info[indexh]; 30813dcf5451SChristoph Hellwig } 30823dcf5451SChristoph Hellwig 30838df9675fSTheodore Ts'o /* 30848df9675fSTheodore Ts'o * Reading s_groups_count requires using smp_rmb() afterwards. See 30858df9675fSTheodore Ts'o * the locking protocol documented in the comments of ext4_group_add() 30868df9675fSTheodore Ts'o * in resize.c 30878df9675fSTheodore Ts'o */ 30888df9675fSTheodore Ts'o static inline ext4_group_t ext4_get_groups_count(struct super_block *sb) 30898df9675fSTheodore Ts'o { 30908df9675fSTheodore Ts'o ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 30918df9675fSTheodore Ts'o 30928df9675fSTheodore Ts'o smp_rmb(); 30938df9675fSTheodore Ts'o return ngroups; 30948df9675fSTheodore Ts'o } 30953dcf5451SChristoph Hellwig 3096772cb7c8SJose R. Santos static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 3097772cb7c8SJose R. Santos ext4_group_t block_group) 3098772cb7c8SJose R. Santos { 3099772cb7c8SJose R. Santos return block_group >> sbi->s_log_groups_per_flex; 3100772cb7c8SJose R. Santos } 3101772cb7c8SJose R. Santos 3102772cb7c8SJose R. Santos static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) 3103772cb7c8SJose R. Santos { 3104772cb7c8SJose R. Santos return 1 << sbi->s_log_groups_per_flex; 3105772cb7c8SJose R. Santos } 3106772cb7c8SJose R. Santos 31073dcf5451SChristoph Hellwig #define ext4_std_error(sb, errno) \ 31083dcf5451SChristoph Hellwig do { \ 31093dcf5451SChristoph Hellwig if ((errno)) \ 3110c398eda0STheodore Ts'o __ext4_std_error((sb), __func__, __LINE__, (errno)); \ 31113dcf5451SChristoph Hellwig } while (0) 31123dcf5451SChristoph Hellwig 3113a30d542aSAneesh Kumar K.V #ifdef CONFIG_SMP 3114df55c99dSTheodore Ts'o /* Each CPU can accumulate percpu_counter_batch clusters in their local 3115df55c99dSTheodore Ts'o * counters. So we need to make sure we have free clusters more 3116179f7ebfSEric Dumazet * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. 3117a30d542aSAneesh Kumar K.V */ 3118df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) 3119a30d542aSAneesh Kumar K.V #else 3120df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK 0 3121a30d542aSAneesh Kumar K.V #endif 3122a30d542aSAneesh Kumar K.V 312390e775b7SJan Kara /* Update i_disksize. Requires i_mutex to avoid races with truncate */ 3124cf17fea6SAneesh Kumar K.V static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) 3125cf17fea6SAneesh Kumar K.V { 312690e775b7SJan Kara WARN_ON_ONCE(S_ISREG(inode->i_mode) && 31275955102cSAl Viro !inode_is_locked(inode)); 3128cf17fea6SAneesh Kumar K.V down_write(&EXT4_I(inode)->i_data_sem); 3129cf17fea6SAneesh Kumar K.V if (newsize > EXT4_I(inode)->i_disksize) 313035df4299SQian Cai WRITE_ONCE(EXT4_I(inode)->i_disksize, newsize); 3131cf17fea6SAneesh Kumar K.V up_write(&EXT4_I(inode)->i_data_sem); 313290e775b7SJan Kara } 313390e775b7SJan Kara 31344631dbf6SDmitry Monakhov /* Update i_size, i_disksize. Requires i_mutex to avoid races with truncate */ 31354631dbf6SDmitry Monakhov static inline int ext4_update_inode_size(struct inode *inode, loff_t newsize) 31364631dbf6SDmitry Monakhov { 31374631dbf6SDmitry Monakhov int changed = 0; 31384631dbf6SDmitry Monakhov 31394631dbf6SDmitry Monakhov if (newsize > inode->i_size) { 31404631dbf6SDmitry Monakhov i_size_write(inode, newsize); 31414631dbf6SDmitry Monakhov changed = 1; 31424631dbf6SDmitry Monakhov } 31434631dbf6SDmitry Monakhov if (newsize > EXT4_I(inode)->i_disksize) { 31444631dbf6SDmitry Monakhov ext4_update_i_disksize(inode, newsize); 31454631dbf6SDmitry Monakhov changed |= 2; 31464631dbf6SDmitry Monakhov } 31474631dbf6SDmitry Monakhov return changed; 31484631dbf6SDmitry Monakhov } 31494631dbf6SDmitry Monakhov 315001127848SJan Kara int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset, 315101127848SJan Kara loff_t len); 315201127848SJan Kara 31535d1b1b3fSAneesh Kumar K.V struct ext4_group_info { 31545d1b1b3fSAneesh Kumar K.V unsigned long bb_state; 31555d1b1b3fSAneesh Kumar K.V struct rb_root bb_free_root; 3156a36b4498SEric Sandeen ext4_grpblk_t bb_first_free; /* first free block */ 3157a36b4498SEric Sandeen ext4_grpblk_t bb_free; /* total free blocks */ 3158a36b4498SEric Sandeen ext4_grpblk_t bb_fragments; /* nr of freespace fragments */ 31598a57d9d6SCurt Wohlgemuth ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */ 31605d1b1b3fSAneesh Kumar K.V struct list_head bb_prealloc_list; 31615d1b1b3fSAneesh Kumar K.V #ifdef DOUBLE_CHECK 31625d1b1b3fSAneesh Kumar K.V void *bb_bitmap; 31635d1b1b3fSAneesh Kumar K.V #endif 31645d1b1b3fSAneesh Kumar K.V struct rw_semaphore alloc_sem; 3165a36b4498SEric Sandeen ext4_grpblk_t bb_counters[]; /* Nr of free power-of-two-block 3166a36b4498SEric Sandeen * regions, index is order. 3167a36b4498SEric Sandeen * bb_counters[3] = 5 means 3168a36b4498SEric Sandeen * 5 free 8-block regions. */ 31695d1b1b3fSAneesh Kumar K.V }; 31705d1b1b3fSAneesh Kumar K.V 31715d1b1b3fSAneesh Kumar K.V #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 31723d56b8d2STao Ma #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 3173163a203dSDarrick J. Wong #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2 317487a39389SDarrick J. Wong #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3 3175db79e6d1SWang Shilong #define EXT4_GROUP_INFO_BBITMAP_CORRUPT \ 3176db79e6d1SWang Shilong (1 << EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT) 3177db79e6d1SWang Shilong #define EXT4_GROUP_INFO_IBITMAP_CORRUPT \ 3178db79e6d1SWang Shilong (1 << EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT) 3179cfd73237SAlex Zhuravlev #define EXT4_GROUP_INFO_BBITMAP_READ_BIT 4 31805d1b1b3fSAneesh Kumar K.V 31815d1b1b3fSAneesh Kumar K.V #define EXT4_MB_GRP_NEED_INIT(grp) \ 31825d1b1b3fSAneesh Kumar K.V (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 3183163a203dSDarrick J. Wong #define EXT4_MB_GRP_BBITMAP_CORRUPT(grp) \ 3184163a203dSDarrick J. Wong (test_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 318587a39389SDarrick J. Wong #define EXT4_MB_GRP_IBITMAP_CORRUPT(grp) \ 318687a39389SDarrick J. Wong (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 31875d1b1b3fSAneesh Kumar K.V 31883d56b8d2STao Ma #define EXT4_MB_GRP_WAS_TRIMMED(grp) \ 31893d56b8d2STao Ma (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 31903d56b8d2STao Ma #define EXT4_MB_GRP_SET_TRIMMED(grp) \ 31913d56b8d2STao Ma (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 31923d56b8d2STao Ma #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \ 31933d56b8d2STao Ma (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 3194cfd73237SAlex Zhuravlev #define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \ 3195cfd73237SAlex Zhuravlev (test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state))) 31963d56b8d2STao Ma 319750797481STheodore Ts'o #define EXT4_MAX_CONTENTION 8 319850797481STheodore Ts'o #define EXT4_CONTENTION_THRESHOLD 2 319950797481STheodore Ts'o 3200955ce5f5SAneesh Kumar K.V static inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb, 3201955ce5f5SAneesh Kumar K.V ext4_group_t group) 3202955ce5f5SAneesh Kumar K.V { 3203955ce5f5SAneesh Kumar K.V return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group); 3204955ce5f5SAneesh Kumar K.V } 3205955ce5f5SAneesh Kumar K.V 320650797481STheodore Ts'o /* 320750797481STheodore Ts'o * Returns true if the filesystem is busy enough that attempts to 320850797481STheodore Ts'o * access the block group locks has run into contention. 320950797481STheodore Ts'o */ 321050797481STheodore Ts'o static inline int ext4_fs_is_busy(struct ext4_sb_info *sbi) 321150797481STheodore Ts'o { 321250797481STheodore Ts'o return (atomic_read(&sbi->s_lock_busy) > EXT4_CONTENTION_THRESHOLD); 321350797481STheodore Ts'o } 321450797481STheodore Ts'o 32155d1b1b3fSAneesh Kumar K.V static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 32165d1b1b3fSAneesh Kumar K.V { 321750797481STheodore Ts'o spinlock_t *lock = ext4_group_lock_ptr(sb, group); 321850797481STheodore Ts'o if (spin_trylock(lock)) 321950797481STheodore Ts'o /* 322050797481STheodore Ts'o * We're able to grab the lock right away, so drop the 322150797481STheodore Ts'o * lock contention counter. 322250797481STheodore Ts'o */ 322350797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, -1, 0); 322450797481STheodore Ts'o else { 322550797481STheodore Ts'o /* 322650797481STheodore Ts'o * The lock is busy, so bump the contention counter, 322750797481STheodore Ts'o * and then wait on the spin lock. 322850797481STheodore Ts'o */ 322950797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, 1, 323050797481STheodore Ts'o EXT4_MAX_CONTENTION); 323150797481STheodore Ts'o spin_lock(lock); 323250797481STheodore Ts'o } 32335d1b1b3fSAneesh Kumar K.V } 32345d1b1b3fSAneesh Kumar K.V 32355d1b1b3fSAneesh Kumar K.V static inline void ext4_unlock_group(struct super_block *sb, 32365d1b1b3fSAneesh Kumar K.V ext4_group_t group) 32375d1b1b3fSAneesh Kumar K.V { 3238955ce5f5SAneesh Kumar K.V spin_unlock(ext4_group_lock_ptr(sb, group)); 32395d1b1b3fSAneesh Kumar K.V } 32405d1b1b3fSAneesh Kumar K.V 32413dcf5451SChristoph Hellwig /* 32421f7d1e77STheodore Ts'o * Block validity checking 32431f7d1e77STheodore Ts'o */ 32441f7d1e77STheodore Ts'o #define ext4_check_indirect_blockref(inode, bh) \ 32451f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 32461f7d1e77STheodore Ts'o (__le32 *)(bh)->b_data, \ 32471f7d1e77STheodore Ts'o EXT4_ADDR_PER_BLOCK((inode)->i_sb)) 32481f7d1e77STheodore Ts'o 32491f7d1e77STheodore Ts'o #define ext4_ind_check_inode(inode) \ 32501f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 32511f7d1e77STheodore Ts'o EXT4_I(inode)->i_data, \ 32521f7d1e77STheodore Ts'o EXT4_NDIR_BLOCKS) 32531f7d1e77STheodore Ts'o 32541f7d1e77STheodore Ts'o /* 32553dcf5451SChristoph Hellwig * Inodes and files operations 32563dcf5451SChristoph Hellwig */ 32573dcf5451SChristoph Hellwig 32583dcf5451SChristoph Hellwig /* dir.c */ 32593dcf5451SChristoph Hellwig extern const struct file_operations ext4_dir_operations; 32603dcf5451SChristoph Hellwig 3261b886ee3eSGabriel Krisman Bertazi #ifdef CONFIG_UNICODE 3262b886ee3eSGabriel Krisman Bertazi extern const struct dentry_operations ext4_dentry_ops; 3263b886ee3eSGabriel Krisman Bertazi #endif 3264b886ee3eSGabriel Krisman Bertazi 32653dcf5451SChristoph Hellwig /* file.c */ 32663dcf5451SChristoph Hellwig extern const struct inode_operations ext4_file_inode_operations; 32673dcf5451SChristoph Hellwig extern const struct file_operations ext4_file_operations; 3268e0d10bfaSToshiyuki Okajima extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin); 32693dcf5451SChristoph Hellwig 327095eaefbdSTheodore Ts'o /* inline.c */ 327195eaefbdSTheodore Ts'o extern int ext4_get_max_inline_size(struct inode *inode); 327295eaefbdSTheodore Ts'o extern int ext4_find_inline_data_nolock(struct inode *inode); 327395eaefbdSTheodore Ts'o extern int ext4_init_inline_data(handle_t *handle, struct inode *inode, 327495eaefbdSTheodore Ts'o unsigned int len); 327595eaefbdSTheodore Ts'o extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode); 327695eaefbdSTheodore Ts'o 327795eaefbdSTheodore Ts'o extern int ext4_readpage_inline(struct inode *inode, struct page *page); 327895eaefbdSTheodore Ts'o extern int ext4_try_to_write_inline_data(struct address_space *mapping, 327995eaefbdSTheodore Ts'o struct inode *inode, 328095eaefbdSTheodore Ts'o loff_t pos, unsigned len, 328195eaefbdSTheodore Ts'o unsigned flags, 328295eaefbdSTheodore Ts'o struct page **pagep); 328395eaefbdSTheodore Ts'o extern int ext4_write_inline_data_end(struct inode *inode, 328495eaefbdSTheodore Ts'o loff_t pos, unsigned len, 328595eaefbdSTheodore Ts'o unsigned copied, 328695eaefbdSTheodore Ts'o struct page *page); 328795eaefbdSTheodore Ts'o extern struct buffer_head * 328895eaefbdSTheodore Ts'o ext4_journalled_write_inline_data(struct inode *inode, 328995eaefbdSTheodore Ts'o unsigned len, 329095eaefbdSTheodore Ts'o struct page *page); 329195eaefbdSTheodore Ts'o extern int ext4_da_write_inline_data_begin(struct address_space *mapping, 329295eaefbdSTheodore Ts'o struct inode *inode, 329395eaefbdSTheodore Ts'o loff_t pos, unsigned len, 329495eaefbdSTheodore Ts'o unsigned flags, 329595eaefbdSTheodore Ts'o struct page **pagep, 329695eaefbdSTheodore Ts'o void **fsdata); 329795eaefbdSTheodore Ts'o extern int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, 329895eaefbdSTheodore Ts'o unsigned len, unsigned copied, 329995eaefbdSTheodore Ts'o struct page *page); 33005b643f9cSTheodore Ts'o extern int ext4_try_add_inline_entry(handle_t *handle, 33015b643f9cSTheodore Ts'o struct ext4_filename *fname, 330256a04915STheodore Ts'o struct inode *dir, struct inode *inode); 330395eaefbdSTheodore Ts'o extern int ext4_try_create_inline_dir(handle_t *handle, 330495eaefbdSTheodore Ts'o struct inode *parent, 330595eaefbdSTheodore Ts'o struct inode *inode); 330695eaefbdSTheodore Ts'o extern int ext4_read_inline_dir(struct file *filp, 3307725bebb2SAl Viro struct dir_context *ctx, 330895eaefbdSTheodore Ts'o int *has_inline_data); 33097633b08bSTheodore Ts'o extern int ext4_inlinedir_to_tree(struct file *dir_file, 33108af0f082STao Ma struct inode *dir, ext4_lblk_t block, 33118af0f082STao Ma struct dx_hash_info *hinfo, 33128af0f082STao Ma __u32 start_hash, __u32 start_minor_hash, 33138af0f082STao Ma int *has_inline_data); 331495eaefbdSTheodore Ts'o extern struct buffer_head *ext4_find_inline_entry(struct inode *dir, 33155b643f9cSTheodore Ts'o struct ext4_filename *fname, 331695eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **res_dir, 331795eaefbdSTheodore Ts'o int *has_inline_data); 331895eaefbdSTheodore Ts'o extern int ext4_delete_inline_entry(handle_t *handle, 331995eaefbdSTheodore Ts'o struct inode *dir, 332095eaefbdSTheodore Ts'o struct ext4_dir_entry_2 *de_del, 332195eaefbdSTheodore Ts'o struct buffer_head *bh, 332295eaefbdSTheodore Ts'o int *has_inline_data); 3323a7550b30SJaegeuk Kim extern bool empty_inline_dir(struct inode *dir, int *has_inline_data); 332495eaefbdSTheodore Ts'o extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode, 332595eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **parent_de, 332695eaefbdSTheodore Ts'o int *retval); 332795eaefbdSTheodore Ts'o extern int ext4_inline_data_fiemap(struct inode *inode, 332895eaefbdSTheodore Ts'o struct fiemap_extent_info *fieinfo, 3329d952d69eSDmitry Monakhov int *has_inline, __u64 start, __u64 len); 33307046ae35SAndreas Gruenbacher 33317046ae35SAndreas Gruenbacher struct iomap; 33327046ae35SAndreas Gruenbacher extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap); 33337046ae35SAndreas Gruenbacher 333401daf945STheodore Ts'o extern int ext4_inline_data_truncate(struct inode *inode, int *has_inline); 333595eaefbdSTheodore Ts'o 333695eaefbdSTheodore Ts'o extern int ext4_convert_inline_data(struct inode *inode); 333795eaefbdSTheodore Ts'o 333883447ccbSZheng Liu static inline int ext4_has_inline_data(struct inode *inode) 333983447ccbSZheng Liu { 334083447ccbSZheng Liu return ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA) && 334183447ccbSZheng Liu EXT4_I(inode)->i_inline_off; 334283447ccbSZheng Liu } 334383447ccbSZheng Liu 33443dcf5451SChristoph Hellwig /* namei.c */ 33453dcf5451SChristoph Hellwig extern const struct inode_operations ext4_dir_inode_operations; 33463dcf5451SChristoph Hellwig extern const struct inode_operations ext4_special_inode_operations; 3347596397b7STheodore Ts'o extern struct dentry *ext4_get_parent(struct dentry *child); 3348a774f9c2STao Ma extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode, 3349a774f9c2STao Ma struct ext4_dir_entry_2 *de, 3350a774f9c2STao Ma int blocksize, int csum_size, 3351a774f9c2STao Ma unsigned int parent_ino, int dotdot_real_len); 3352ddce3b94STheodore Ts'o extern void ext4_initialize_dirent_tail(struct buffer_head *bh, 33533c47d541STao Ma unsigned int blocksize); 3354f036adb3STheodore Ts'o extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode, 33553c47d541STao Ma struct buffer_head *bh); 3356b886ee3eSGabriel Krisman Bertazi extern int ext4_ci_compare(const struct inode *parent, 33573ae72562SGabriel Krisman Bertazi const struct qstr *fname, 33583ae72562SGabriel Krisman Bertazi const struct qstr *entry, bool quick); 3359b886ee3eSGabriel Krisman Bertazi 33608af0f082STao Ma #define S_SHIFT 12 3361381cebfeSDan Carpenter static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { 33628af0f082STao Ma [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, 33638af0f082STao Ma [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, 33648af0f082STao Ma [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, 33658af0f082STao Ma [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, 33668af0f082STao Ma [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, 33678af0f082STao Ma [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, 33688af0f082STao Ma [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, 33698af0f082STao Ma }; 33708af0f082STao Ma 33718af0f082STao Ma static inline void ext4_set_de_type(struct super_block *sb, 33728af0f082STao Ma struct ext4_dir_entry_2 *de, 33738af0f082STao Ma umode_t mode) { 3374e2b911c5SDarrick J. Wong if (ext4_has_feature_filetype(sb)) 33758af0f082STao Ma de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 33768af0f082STao Ma } 33778af0f082STao Ma 3378f64e02feSTheodore Ts'o /* readpages.c */ 3379a07f624bSMatthew Wilcox (Oracle) extern int ext4_mpage_readpages(struct inode *inode, 33806311f91fSMatthew Wilcox (Oracle) struct readahead_control *rac, struct page *page); 338122cfe4b4SEric Biggers extern int __init ext4_init_post_read_processing(void); 338222cfe4b4SEric Biggers extern void ext4_exit_post_read_processing(void); 33833dcf5451SChristoph Hellwig 33843dcf5451SChristoph Hellwig /* symlink.c */ 3385a7a67e8aSAl Viro extern const struct inode_operations ext4_encrypted_symlink_inode_operations; 33863dcf5451SChristoph Hellwig extern const struct inode_operations ext4_symlink_inode_operations; 33873dcf5451SChristoph Hellwig extern const struct inode_operations ext4_fast_symlink_inode_operations; 33883dcf5451SChristoph Hellwig 3389b5799018STheodore Ts'o /* sysfs.c */ 3390b5799018STheodore Ts'o extern int ext4_register_sysfs(struct super_block *sb); 3391ebd173beSTheodore Ts'o extern void ext4_unregister_sysfs(struct super_block *sb); 3392b5799018STheodore Ts'o extern int __init ext4_init_sysfs(void); 3393b5799018STheodore Ts'o extern void ext4_exit_sysfs(void); 3394b5799018STheodore Ts'o 33956fd058f7STheodore Ts'o /* block_validity */ 33966fd058f7STheodore Ts'o extern void ext4_release_system_zone(struct super_block *sb); 33976fd058f7STheodore Ts'o extern int ext4_setup_system_zone(struct super_block *sb); 33985dabfc78STheodore Ts'o extern int __init ext4_init_system_zone(void); 33995dabfc78STheodore Ts'o extern void ext4_exit_system_zone(void); 3400ce9f24ccSJan Kara extern int ext4_inode_block_valid(struct inode *inode, 34016fd058f7STheodore Ts'o ext4_fsblk_t start_blk, 34026fd058f7STheodore Ts'o unsigned int count); 34031f7d1e77STheodore Ts'o extern int ext4_check_blockref(const char *, unsigned int, 34041f7d1e77STheodore Ts'o struct inode *, __le32 *, unsigned int); 34056fd058f7STheodore Ts'o 34063dcf5451SChristoph Hellwig /* extents.c */ 34074a092d73STheodore Ts'o struct ext4_ext_path; 34084a092d73STheodore Ts'o struct ext4_extent; 34094a092d73STheodore Ts'o 3410d7b2a00cSZheng Liu /* 3411d7b2a00cSZheng Liu * Maximum number of logical blocks in a file; ext4_extent's ee_block is 3412d7b2a00cSZheng Liu * __le32. 3413d7b2a00cSZheng Liu */ 3414d7b2a00cSZheng Liu #define EXT_MAX_BLOCKS 0xffffffff 3415d7b2a00cSZheng Liu 34164209ae12SHarshad Shirwadkar extern void ext4_ext_tree_init(handle_t *handle, struct inode *inode); 3417fffb2739SJan Kara extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents); 3418e35fd660STheodore Ts'o extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, 3419e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 3420d0abb36dSTheodore Ts'o extern int ext4_ext_truncate(handle_t *, struct inode *); 342126a4c0c6STheodore Ts'o extern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, 342226a4c0c6STheodore Ts'o ext4_lblk_t end); 34233dcf5451SChristoph Hellwig extern void ext4_ext_init(struct super_block *); 34243dcf5451SChristoph Hellwig extern void ext4_ext_release(struct super_block *); 34252fe17c10SChristoph Hellwig extern long ext4_fallocate(struct file *file, int mode, loff_t offset, 34263dcf5451SChristoph Hellwig loff_t len); 34276b523df4SJan Kara extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode, 34286b523df4SJan Kara loff_t offset, ssize_t len); 3429a00713eaSRitesh Harjani extern int ext4_convert_unwritten_io_end_vec(handle_t *handle, 3430a00713eaSRitesh Harjani ext4_io_end_t *io_end); 3431e35fd660STheodore Ts'o extern int ext4_map_blocks(handle_t *handle, struct inode *inode, 3432e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 34334a092d73STheodore Ts'o extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, 34344a092d73STheodore Ts'o int num, 34354a092d73STheodore Ts'o struct ext4_ext_path *path); 34364a092d73STheodore Ts'o extern int ext4_ext_insert_extent(handle_t *, struct inode *, 3437dfe50809STheodore Ts'o struct ext4_ext_path **, 34384a092d73STheodore Ts'o struct ext4_extent *, int); 3439ed8a1a76STheodore Ts'o extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, 3440705912caSTheodore Ts'o struct ext4_ext_path **, 3441107a7bd3STheodore Ts'o int flags); 34424a092d73STheodore Ts'o extern void ext4_ext_drop_refs(struct ext4_ext_path *); 34434a092d73STheodore Ts'o extern int ext4_ext_check_inode(struct inode *inode); 3444fcf6b1b7SDmitry Monakhov extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path); 34453a06d778SAneesh Kumar K.V extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 34463a06d778SAneesh Kumar K.V __u64 start, __u64 len); 3447bb5835edSTheodore Ts'o extern int ext4_get_es_cache(struct inode *inode, 3448bb5835edSTheodore Ts'o struct fiemap_extent_info *fieinfo, 3449bb5835edSTheodore Ts'o __u64 start, __u64 len); 34507869a4a6STheodore Ts'o extern int ext4_ext_precache(struct inode *inode); 3451fcf6b1b7SDmitry Monakhov extern int ext4_swap_extents(handle_t *handle, struct inode *inode1, 3452fcf6b1b7SDmitry Monakhov struct inode *inode2, ext4_lblk_t lblk1, 3453fcf6b1b7SDmitry Monakhov ext4_lblk_t lblk2, ext4_lblk_t count, 3454fcf6b1b7SDmitry Monakhov int mark_unwritten,int *err); 34550b02f4c0SEric Whitney extern int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu); 3456a4130367SJan Kara extern int ext4_datasem_ensure_credits(handle_t *handle, struct inode *inode, 345783448bdfSJan Kara int check_cred, int restart_cred, 345883448bdfSJan Kara int revoke_cred); 3459a4130367SJan Kara 34604a092d73STheodore Ts'o 3461748de673SAkira Fujita /* move_extent.c */ 3462393d1d1dSDr. Tilmann Bubeck extern void ext4_double_down_write_data_sem(struct inode *first, 3463393d1d1dSDr. Tilmann Bubeck struct inode *second); 3464393d1d1dSDr. Tilmann Bubeck extern void ext4_double_up_write_data_sem(struct inode *orig_inode, 3465393d1d1dSDr. Tilmann Bubeck struct inode *donor_inode); 3466748de673SAkira Fujita extern int ext4_move_extents(struct file *o_filp, struct file *d_filp, 3467748de673SAkira Fujita __u64 start_orig, __u64 start_donor, 3468748de673SAkira Fujita __u64 len, __u64 *moved_len); 3469748de673SAkira Fujita 3470bd2d0210STheodore Ts'o /* page-io.c */ 34715dabfc78STheodore Ts'o extern int __init ext4_init_pageio(void); 34725dabfc78STheodore Ts'o extern void ext4_exit_pageio(void); 3473bd2d0210STheodore Ts'o extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags); 347497a851edSJan Kara extern ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end); 347597a851edSJan Kara extern int ext4_put_io_end(ext4_io_end_t *io_end); 347697a851edSJan Kara extern void ext4_put_io_end_defer(ext4_io_end_t *io_end); 347797a851edSJan Kara extern void ext4_io_submit_init(struct ext4_io_submit *io, 347897a851edSJan Kara struct writeback_control *wbc); 34792e8fa54eSJan Kara extern void ext4_end_io_rsv_work(struct work_struct *work); 3480bd2d0210STheodore Ts'o extern void ext4_io_submit(struct ext4_io_submit *io); 3481bd2d0210STheodore Ts'o extern int ext4_bio_write_page(struct ext4_io_submit *io, 3482bd2d0210STheodore Ts'o struct page *page, 3483bd2d0210STheodore Ts'o int len, 34841c8349a1SNamjae Jeon struct writeback_control *wbc, 34851c8349a1SNamjae Jeon bool keep_towrite); 3486c8cc8816SRitesh Harjani extern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end); 3487c8cc8816SRitesh Harjani extern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end); 34883a06d778SAneesh Kumar K.V 3489c5e06d10SJohann Lombardi /* mmp.c */ 3490c5e06d10SJohann Lombardi extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); 3491c5e06d10SJohann Lombardi 3492c93d8f88SEric Biggers /* verity.c */ 3493c93d8f88SEric Biggers extern const struct fsverity_operations ext4_verityops; 3494c93d8f88SEric Biggers 34953613d228SJan Kara /* 349648fc7f7eSAdam Buchbinder * Add new method to test whether block and inode bitmaps are properly 34972ccb5fb9SAneesh Kumar K.V * initialized. With uninit_bg reading the block from disk is not enough 34982ccb5fb9SAneesh Kumar K.V * to mark the bitmap uptodate. We need to also zero-out the bitmap 34992ccb5fb9SAneesh Kumar K.V */ 35002ccb5fb9SAneesh Kumar K.V #define BH_BITMAP_UPTODATE BH_JBDPrivateStart 35012ccb5fb9SAneesh Kumar K.V 35022ccb5fb9SAneesh Kumar K.V static inline int bitmap_uptodate(struct buffer_head *bh) 35032ccb5fb9SAneesh Kumar K.V { 35042ccb5fb9SAneesh Kumar K.V return (buffer_uptodate(bh) && 35052ccb5fb9SAneesh Kumar K.V test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state)); 35062ccb5fb9SAneesh Kumar K.V } 35072ccb5fb9SAneesh Kumar K.V static inline void set_bitmap_uptodate(struct buffer_head *bh) 35082ccb5fb9SAneesh Kumar K.V { 35092ccb5fb9SAneesh Kumar K.V set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); 35102ccb5fb9SAneesh Kumar K.V } 35112ccb5fb9SAneesh Kumar K.V 3512731eb1a0SAkinobu Mita #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) 3513731eb1a0SAkinobu Mita 3514e9e3bcecSEric Sandeen /* For ioend & aio unwritten conversion wait queues */ 3515e9e3bcecSEric Sandeen #define EXT4_WQ_HASH_SZ 37 3516e9e3bcecSEric Sandeen #define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\ 3517e9e3bcecSEric Sandeen EXT4_WQ_HASH_SZ]) 3518e9e3bcecSEric Sandeen extern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; 3519e9e3bcecSEric Sandeen 35208f82f840SYongqiang Yang extern int ext4_resize_begin(struct super_block *sb); 35218f82f840SYongqiang Yang extern void ext4_resize_end(struct super_block *sb); 35228f82f840SYongqiang Yang 352374c66bcbSJan Kara static inline void ext4_set_io_unwritten_flag(struct inode *inode, 352474c66bcbSJan Kara struct ext4_io_end *io_end) 352574c66bcbSJan Kara { 352674c66bcbSJan Kara if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 352774c66bcbSJan Kara io_end->flag |= EXT4_IO_END_UNWRITTEN; 352874c66bcbSJan Kara atomic_inc(&EXT4_I(inode)->i_unwritten); 352974c66bcbSJan Kara } 353074c66bcbSJan Kara } 353174c66bcbSJan Kara 353274c66bcbSJan Kara static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) 353374c66bcbSJan Kara { 353474c66bcbSJan Kara struct inode *inode = io_end->inode; 353574c66bcbSJan Kara 353674c66bcbSJan Kara if (io_end->flag & EXT4_IO_END_UNWRITTEN) { 353774c66bcbSJan Kara io_end->flag &= ~EXT4_IO_END_UNWRITTEN; 353874c66bcbSJan Kara /* Wake up anyone waiting on unwritten extent conversion */ 353974c66bcbSJan Kara if (atomic_dec_and_test(&EXT4_I(inode)->i_unwritten)) 354074c66bcbSJan Kara wake_up_all(ext4_ioend_wq(inode)); 354174c66bcbSJan Kara } 354274c66bcbSJan Kara } 354374c66bcbSJan Kara 35448ff6daa1SChristoph Hellwig extern const struct iomap_ops ext4_iomap_ops; 35458cd115bdSJan Kara extern const struct iomap_ops ext4_iomap_overwrite_ops; 354609edf4d3SMatthew Bobrowski extern const struct iomap_ops ext4_iomap_report_ops; 3547364443cbSJan Kara 35487963e5acSZhangXiaoxu static inline int ext4_buffer_uptodate(struct buffer_head *bh) 35497963e5acSZhangXiaoxu { 35507963e5acSZhangXiaoxu /* 35517963e5acSZhangXiaoxu * If the buffer has the write error flag, we have failed 35527963e5acSZhangXiaoxu * to write out data in the block. In this case, we don't 35537963e5acSZhangXiaoxu * have to read the block because we may read the old data 35547963e5acSZhangXiaoxu * successfully. 35557963e5acSZhangXiaoxu */ 35567963e5acSZhangXiaoxu if (!buffer_uptodate(bh) && buffer_write_io_error(bh)) 35577963e5acSZhangXiaoxu set_buffer_uptodate(bh); 35587963e5acSZhangXiaoxu return buffer_uptodate(bh); 35597963e5acSZhangXiaoxu } 35607963e5acSZhangXiaoxu 35613dcf5451SChristoph Hellwig #endif /* __KERNEL__ */ 35623dcf5451SChristoph Hellwig 35636a797d27SDarrick J. Wong #define EFSBADCRC EBADMSG /* Bad CRC detected */ 35646a797d27SDarrick J. Wong #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 35656a797d27SDarrick J. Wong 35663dcf5451SChristoph Hellwig #endif /* _EXT4_H */ 3567