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 2031d21d21SXiyu Yang #include <linux/refcount.h> 213dcf5451SChristoph Hellwig #include <linux/types.h> 223dcf5451SChristoph Hellwig #include <linux/blkdev.h> 233dcf5451SChristoph Hellwig #include <linux/magic.h> 242ccb5fb9SAneesh Kumar K.V #include <linux/jbd2.h> 2560e58e0fSMingming Cao #include <linux/quota.h> 26d444c3c3STheodore Ts'o #include <linux/rwsem.h> 27d444c3c3STheodore Ts'o #include <linux/rbtree.h> 28d444c3c3STheodore Ts'o #include <linux/seqlock.h> 29d444c3c3STheodore Ts'o #include <linux/mutex.h> 30ca0faba0STheodore Ts'o #include <linux/timer.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 102837c23fbSChunguang Xu #define ASSERT(assert) \ 103837c23fbSChunguang Xu do { \ 104837c23fbSChunguang Xu if (unlikely(!(assert))) { \ 105837c23fbSChunguang Xu printk(KERN_EMERG \ 106837c23fbSChunguang Xu "Assertion failure in %s() at %s:%d: '%s'\n", \ 107837c23fbSChunguang Xu __func__, __FILE__, __LINE__, #assert); \ 108837c23fbSChunguang Xu BUG(); \ 109837c23fbSChunguang Xu } \ 110837c23fbSChunguang Xu } while (0) 111837c23fbSChunguang Xu 112d444c3c3STheodore Ts'o /* data type for block offset of block group */ 113d444c3c3STheodore Ts'o typedef int ext4_grpblk_t; 114d444c3c3STheodore Ts'o 115d444c3c3STheodore Ts'o /* data type for filesystem-wide blocks number */ 116d444c3c3STheodore Ts'o typedef unsigned long long ext4_fsblk_t; 117d444c3c3STheodore Ts'o 118d444c3c3STheodore Ts'o /* data type for file logical block number */ 119d444c3c3STheodore Ts'o typedef __u32 ext4_lblk_t; 120d444c3c3STheodore Ts'o 121d444c3c3STheodore Ts'o /* data type for block group number */ 122d444c3c3STheodore Ts'o typedef unsigned int ext4_group_t; 123d444c3c3STheodore Ts'o 124331573feSNamjae Jeon enum SHIFT_DIRECTION { 125331573feSNamjae Jeon SHIFT_LEFT = 0, 126331573feSNamjae Jeon SHIFT_RIGHT, 127331573feSNamjae Jeon }; 128331573feSNamjae Jeon 129296c355cSTheodore Ts'o /* 130296c355cSTheodore Ts'o * Flags used in mballoc's allocation_context flags field. 131296c355cSTheodore Ts'o * 132296c355cSTheodore Ts'o * Also used to show what's going on for debugging purposes when the 133296c355cSTheodore Ts'o * flag field is exported via the traceport interface 134296c355cSTheodore Ts'o */ 135d444c3c3STheodore Ts'o 1363dcf5451SChristoph Hellwig /* prefer goal again. length */ 1370ef90db9STheodore Ts'o #define EXT4_MB_HINT_MERGE 0x0001 1383dcf5451SChristoph Hellwig /* blocks already reserved */ 1390ef90db9STheodore Ts'o #define EXT4_MB_HINT_RESERVED 0x0002 1403dcf5451SChristoph Hellwig /* metadata is being allocated */ 1410ef90db9STheodore Ts'o #define EXT4_MB_HINT_METADATA 0x0004 1423dcf5451SChristoph Hellwig /* first blocks in the file */ 1430ef90db9STheodore Ts'o #define EXT4_MB_HINT_FIRST 0x0008 1443dcf5451SChristoph Hellwig /* search for the best chunk */ 1450ef90db9STheodore Ts'o #define EXT4_MB_HINT_BEST 0x0010 1463dcf5451SChristoph Hellwig /* data is being allocated */ 1470ef90db9STheodore Ts'o #define EXT4_MB_HINT_DATA 0x0020 1483dcf5451SChristoph Hellwig /* don't preallocate (for tails) */ 1490ef90db9STheodore Ts'o #define EXT4_MB_HINT_NOPREALLOC 0x0040 1503dcf5451SChristoph Hellwig /* allocate for locality group */ 1510ef90db9STheodore Ts'o #define EXT4_MB_HINT_GROUP_ALLOC 0x0080 1523dcf5451SChristoph Hellwig /* allocate goal blocks or none */ 1530ef90db9STheodore Ts'o #define EXT4_MB_HINT_GOAL_ONLY 0x0100 1543dcf5451SChristoph Hellwig /* goal is meaningful */ 1550ef90db9STheodore Ts'o #define EXT4_MB_HINT_TRY_GOAL 0x0200 156d2a17637SMingming Cao /* blocks already pre-reserved by delayed allocation */ 1570ef90db9STheodore Ts'o #define EXT4_MB_DELALLOC_RESERVED 0x0400 1584ba74d00STheodore Ts'o /* We are doing stream allocation */ 1594ba74d00STheodore Ts'o #define EXT4_MB_STREAM_ALLOC 0x0800 16055f020dbSAllison Henderson /* Use reserved root blocks if needed */ 16155f020dbSAllison Henderson #define EXT4_MB_USE_ROOT_BLOCKS 0x1000 16227dd4385SLukas Czerner /* Use blocks from reserved pool */ 16327dd4385SLukas Czerner #define EXT4_MB_USE_RESERVED 0x2000 16499377830SRitesh Harjani /* Do strict check for free blocks while retrying block allocation */ 16599377830SRitesh Harjani #define EXT4_MB_STRICT_CHECK 0x4000 166196e402aSHarshad Shirwadkar /* Large fragment size list lookup succeeded at least once for cr = 0 */ 167196e402aSHarshad Shirwadkar #define EXT4_MB_CR0_OPTIMIZED 0x8000 168196e402aSHarshad Shirwadkar /* Avg fragment size rb tree lookup succeeded at least once for cr = 1 */ 169196e402aSHarshad Shirwadkar #define EXT4_MB_CR1_OPTIMIZED 0x00010000 170196e402aSHarshad Shirwadkar /* Perform linear traversal for one group */ 171196e402aSHarshad Shirwadkar #define EXT4_MB_SEARCH_NEXT_LINEAR 0x00020000 1723dcf5451SChristoph Hellwig struct ext4_allocation_request { 1733dcf5451SChristoph Hellwig /* target inode for block we're allocating */ 1743dcf5451SChristoph Hellwig struct inode *inode; 1753dcf5451SChristoph Hellwig /* how many blocks we want to allocate */ 176498e5f24STheodore Ts'o unsigned int len; 177726447d8SEric Sandeen /* logical block in target inode */ 178726447d8SEric Sandeen ext4_lblk_t logical; 179726447d8SEric Sandeen /* the closest logical allocated block to the left */ 180726447d8SEric Sandeen ext4_lblk_t lleft; 181726447d8SEric Sandeen /* the closest logical allocated block to the right */ 182726447d8SEric Sandeen ext4_lblk_t lright; 183726447d8SEric Sandeen /* phys. target (a hint) */ 184726447d8SEric Sandeen ext4_fsblk_t goal; 185726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the left */ 186726447d8SEric Sandeen ext4_fsblk_t pleft; 187726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the right */ 188726447d8SEric Sandeen ext4_fsblk_t pright; 1893dcf5451SChristoph Hellwig /* flags. see above EXT4_MB_HINT_* */ 190498e5f24STheodore Ts'o unsigned int flags; 1913dcf5451SChristoph Hellwig }; 1923dcf5451SChristoph Hellwig 1933dcf5451SChristoph Hellwig /* 194e35fd660STheodore Ts'o * Logical to physical block mapping, used by ext4_map_blocks() 195e35fd660STheodore Ts'o * 196e35fd660STheodore Ts'o * This structure is used to pass requests into ext4_map_blocks() as 197e35fd660STheodore Ts'o * well as to store the information returned by ext4_map_blocks(). It 198e35fd660STheodore Ts'o * takes less room on the stack than a struct buffer_head. 199e35fd660STheodore Ts'o */ 2006db07461SRitesh Harjani #define EXT4_MAP_NEW BIT(BH_New) 2016db07461SRitesh Harjani #define EXT4_MAP_MAPPED BIT(BH_Mapped) 2026db07461SRitesh Harjani #define EXT4_MAP_UNWRITTEN BIT(BH_Unwritten) 2036db07461SRitesh Harjani #define EXT4_MAP_BOUNDARY BIT(BH_Boundary) 204e35fd660STheodore Ts'o #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ 205cbd7584eSJan Kara EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY) 206e35fd660STheodore Ts'o 207e35fd660STheodore Ts'o struct ext4_map_blocks { 208e35fd660STheodore Ts'o ext4_fsblk_t m_pblk; 209e35fd660STheodore Ts'o ext4_lblk_t m_lblk; 210e35fd660STheodore Ts'o unsigned int m_len; 211e35fd660STheodore Ts'o unsigned int m_flags; 212e35fd660STheodore Ts'o }; 213e35fd660STheodore Ts'o 214e35fd660STheodore Ts'o /* 2157727ae52Szhangyi (F) * Block validity checking, system zone rbtree. 2167727ae52Szhangyi (F) */ 2177727ae52Szhangyi (F) struct ext4_system_blocks { 2187727ae52Szhangyi (F) struct rb_root root; 2197727ae52Szhangyi (F) struct rcu_head rcu; 2207727ae52Szhangyi (F) }; 2217727ae52Szhangyi (F) 2227727ae52Szhangyi (F) /* 223bd2d0210STheodore Ts'o * Flags for ext4_io_end->flags 224bd2d0210STheodore Ts'o */ 225bd2d0210STheodore Ts'o #define EXT4_IO_END_UNWRITTEN 0x0001 226bd2d0210STheodore Ts'o 227c8cc8816SRitesh Harjani struct ext4_io_end_vec { 228c8cc8816SRitesh Harjani struct list_head list; /* list of io_end_vec */ 229c8cc8816SRitesh Harjani loff_t offset; /* offset in the file */ 230c8cc8816SRitesh Harjani ssize_t size; /* size of the extent */ 231c8cc8816SRitesh Harjani }; 232c8cc8816SRitesh Harjani 2334188188bSCurt Wohlgemuth /* 234556615dcSLukas Czerner * For converting unwritten extents on a work queue. 'handle' is used for 2356b523df4SJan Kara * buffered writeback. 2364188188bSCurt Wohlgemuth */ 2370031462bSMingming Cao typedef struct ext4_io_end { 2385b3ff237Sjiayingz@google.com (Jiaying Zhang) struct list_head list; /* per-file finished IO list */ 2396b523df4SJan Kara handle_t *handle; /* handle reserved for extent 2406b523df4SJan Kara * conversion */ 2410031462bSMingming Cao struct inode *inode; /* file being written to */ 242b0857d30SJan Kara struct bio *bio; /* Linked list of completed 243b0857d30SJan Kara * bios covering the extent */ 2448d5d02e6SMingming Cao unsigned int flag; /* unwritten or not */ 24531d21d21SXiyu Yang refcount_t count; /* reference counter */ 246c8cc8816SRitesh Harjani struct list_head list_vec; /* list of ext4_io_end_vec */ 2470031462bSMingming Cao } ext4_io_end_t; 2480031462bSMingming Cao 249bd2d0210STheodore Ts'o struct ext4_io_submit { 2505a33911fSTejun Heo struct writeback_control *io_wbc; 251bd2d0210STheodore Ts'o struct bio *io_bio; 252bd2d0210STheodore Ts'o ext4_io_end_t *io_end; 253bd2d0210STheodore Ts'o sector_t io_next_block; 254bd2d0210STheodore Ts'o }; 255bd2d0210STheodore Ts'o 256b3a3ca8cSTheodore Ts'o /* 2573dcf5451SChristoph Hellwig * Special inodes numbers 2583dcf5451SChristoph Hellwig */ 2593dcf5451SChristoph Hellwig #define EXT4_BAD_INO 1 /* Bad blocks inode */ 2603dcf5451SChristoph Hellwig #define EXT4_ROOT_INO 2 /* Root inode */ 261ae812306SAditya Kali #define EXT4_USR_QUOTA_INO 3 /* User quota inode */ 262ae812306SAditya Kali #define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */ 2633dcf5451SChristoph Hellwig #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */ 2643dcf5451SChristoph Hellwig #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */ 2653dcf5451SChristoph Hellwig #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */ 2663dcf5451SChristoph Hellwig #define EXT4_JOURNAL_INO 8 /* Journal inode */ 2673dcf5451SChristoph Hellwig 2683dcf5451SChristoph Hellwig /* First non-reserved inode for old ext4 filesystems */ 2693dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_FIRST_INO 11 2703dcf5451SChristoph Hellwig 2713dcf5451SChristoph Hellwig /* 2723dcf5451SChristoph Hellwig * Maximal count of links to a file 2733dcf5451SChristoph Hellwig */ 2743dcf5451SChristoph Hellwig #define EXT4_LINK_MAX 65000 2753dcf5451SChristoph Hellwig 2763dcf5451SChristoph Hellwig /* 2773dcf5451SChristoph Hellwig * Macro-instructions used to manage several block sizes 2783dcf5451SChristoph Hellwig */ 2793dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_SIZE 1024 2803dcf5451SChristoph Hellwig #define EXT4_MAX_BLOCK_SIZE 65536 2813dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_LOG_SIZE 10 282fb1813f4SCurt Wohlgemuth #define EXT4_MAX_BLOCK_LOG_SIZE 16 2839e47a4c9STheodore Ts'o #define EXT4_MAX_CLUSTER_LOG_SIZE 30 2843dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2853dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize) 2863dcf5451SChristoph Hellwig #else 2873dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size) 2883dcf5451SChristoph Hellwig #endif 2893dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32)) 290281b5995STheodore Ts'o #define EXT4_CLUSTER_SIZE(s) (EXT4_BLOCK_SIZE(s) << \ 291281b5995STheodore Ts'o EXT4_SB(s)->s_cluster_bits) 2923dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2933dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 294281b5995STheodore Ts'o # define EXT4_CLUSTER_BITS(s) (EXT4_SB(s)->s_cluster_bits) 2953dcf5451SChristoph Hellwig #else 2963dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 2973dcf5451SChristoph Hellwig #endif 2983dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2993dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits) 3003dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size) 3013dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino) 3023dcf5451SChristoph Hellwig #else 3033dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 3043dcf5451SChristoph Hellwig EXT4_GOOD_OLD_INODE_SIZE : \ 3053dcf5451SChristoph Hellwig (s)->s_inode_size) 3063dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 3073dcf5451SChristoph Hellwig EXT4_GOOD_OLD_FIRST_INO : \ 3083dcf5451SChristoph Hellwig (s)->s_first_ino) 3093dcf5451SChristoph Hellwig #endif 3103dcf5451SChristoph Hellwig #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 311518eaa63SFabian Frederick #define EXT4_MAX_BLOCKS(size, offset, blkbits) \ 312518eaa63SFabian Frederick ((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \ 313518eaa63SFabian Frederick blkbits)) 3143dcf5451SChristoph Hellwig 315d5b8f310STheodore Ts'o /* Translate a block number to a cluster number */ 316d5b8f310STheodore Ts'o #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) 317d5b8f310STheodore Ts'o /* Translate a cluster number to a block number */ 318d5b8f310STheodore Ts'o #define EXT4_C2B(sbi, cluster) ((cluster) << (sbi)->s_cluster_bits) 319d5b8f310STheodore Ts'o /* Translate # of blks to # of clusters */ 320d5b8f310STheodore Ts'o #define EXT4_NUM_B2C(sbi, blks) (((blks) + (sbi)->s_cluster_ratio - 1) >> \ 321d5b8f310STheodore Ts'o (sbi)->s_cluster_bits) 322f5a44db5STheodore Ts'o /* Mask out the low bits to get the starting block of the cluster */ 323f5a44db5STheodore Ts'o #define EXT4_PBLK_CMASK(s, pblk) ((pblk) & \ 324f5a44db5STheodore Ts'o ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 325f5a44db5STheodore Ts'o #define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \ 326f5a44db5STheodore Ts'o ~((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 3278fcc3a58SEric Whitney /* Fill in the low bits to get the last block of the cluster */ 3288fcc3a58SEric Whitney #define EXT4_LBLK_CFILL(sbi, lblk) ((lblk) | \ 3298fcc3a58SEric Whitney ((ext4_lblk_t) (sbi)->s_cluster_ratio - 1)) 330f5a44db5STheodore Ts'o /* Get the cluster offset */ 331f5a44db5STheodore Ts'o #define EXT4_PBLK_COFF(s, pblk) ((pblk) & \ 332f5a44db5STheodore Ts'o ((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 333f5a44db5STheodore Ts'o #define EXT4_LBLK_COFF(s, lblk) ((lblk) & \ 334f5a44db5STheodore Ts'o ((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 335d5b8f310STheodore Ts'o 3363dcf5451SChristoph Hellwig /* 3373dcf5451SChristoph Hellwig * Structure of a blocks group descriptor 3383dcf5451SChristoph Hellwig */ 3393dcf5451SChristoph Hellwig struct ext4_group_desc 3403dcf5451SChristoph Hellwig { 3413dcf5451SChristoph Hellwig __le32 bg_block_bitmap_lo; /* Blocks bitmap block */ 3423dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */ 3433dcf5451SChristoph Hellwig __le32 bg_inode_table_lo; /* Inodes table block */ 344560671a0SAneesh Kumar K.V __le16 bg_free_blocks_count_lo;/* Free blocks count */ 345560671a0SAneesh Kumar K.V __le16 bg_free_inodes_count_lo;/* Free inodes count */ 346560671a0SAneesh Kumar K.V __le16 bg_used_dirs_count_lo; /* Directories count */ 3473dcf5451SChristoph Hellwig __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 348e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ 349e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */ 350e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */ 351560671a0SAneesh Kumar K.V __le16 bg_itable_unused_lo; /* Unused inodes count */ 3523dcf5451SChristoph Hellwig __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 3533dcf5451SChristoph Hellwig __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 3543dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ 3553dcf5451SChristoph Hellwig __le32 bg_inode_table_hi; /* Inodes table block MSB */ 3563dcf5451SChristoph Hellwig __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ 3573dcf5451SChristoph Hellwig __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 3583dcf5451SChristoph Hellwig __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 3593dcf5451SChristoph Hellwig __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 360e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ 361e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */ 362e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */ 363e6153918SDarrick J. Wong __u32 bg_reserved; 3643dcf5451SChristoph Hellwig }; 3653dcf5451SChristoph Hellwig 36641a246d1SDarrick J. Wong #define EXT4_BG_INODE_BITMAP_CSUM_HI_END \ 36741a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \ 36841a246d1SDarrick J. Wong sizeof(__le16)) 36941a246d1SDarrick J. Wong #define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \ 37041a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \ 37141a246d1SDarrick J. Wong sizeof(__le16)) 37241a246d1SDarrick J. Wong 373772cb7c8SJose R. Santos /* 374772cb7c8SJose R. Santos * Structure of a flex block group info 375772cb7c8SJose R. Santos */ 376772cb7c8SJose R. Santos 377772cb7c8SJose R. Santos struct flex_groups { 37890ba983fSTheodore Ts'o atomic64_t free_clusters; 3799f24e420STheodore Ts'o atomic_t free_inodes; 3807d39db14STheodore Ts'o atomic_t used_dirs; 381772cb7c8SJose R. Santos }; 382772cb7c8SJose R. Santos 3833dcf5451SChristoph Hellwig #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 3843dcf5451SChristoph Hellwig #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 3853dcf5451SChristoph Hellwig #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 3863dcf5451SChristoph Hellwig 3873dcf5451SChristoph Hellwig /* 3883dcf5451SChristoph Hellwig * Macro-instructions used to manage group descriptors 3893dcf5451SChristoph Hellwig */ 3903dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE 32 3913dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE_64BIT 64 3923dcf5451SChristoph Hellwig #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE 3933dcf5451SChristoph Hellwig #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size) 3943dcf5451SChristoph Hellwig #ifdef __KERNEL__ 3953dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group) 396281b5995STheodore Ts'o # define EXT4_CLUSTERS_PER_GROUP(s) (EXT4_SB(s)->s_clusters_per_group) 3973dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block) 3983dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group) 3993dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits) 4003dcf5451SChristoph Hellwig #else 4013dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 4023dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s)) 4033dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 4043dcf5451SChristoph Hellwig #endif 4053dcf5451SChristoph Hellwig 4063dcf5451SChristoph Hellwig /* 4073dcf5451SChristoph Hellwig * Constants relative to the data blocks 4083dcf5451SChristoph Hellwig */ 4093dcf5451SChristoph Hellwig #define EXT4_NDIR_BLOCKS 12 4103dcf5451SChristoph Hellwig #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS 4113dcf5451SChristoph Hellwig #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) 4123dcf5451SChristoph Hellwig #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) 4133dcf5451SChristoph Hellwig #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) 4143dcf5451SChristoph Hellwig 4153dcf5451SChristoph Hellwig /* 4163dcf5451SChristoph Hellwig * Inode flags 4173dcf5451SChristoph Hellwig */ 4183dcf5451SChristoph Hellwig #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */ 4193dcf5451SChristoph Hellwig #define EXT4_UNRM_FL 0x00000002 /* Undelete */ 4203dcf5451SChristoph Hellwig #define EXT4_COMPR_FL 0x00000004 /* Compress file */ 4213dcf5451SChristoph Hellwig #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */ 4223dcf5451SChristoph Hellwig #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */ 4233dcf5451SChristoph Hellwig #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */ 4243dcf5451SChristoph Hellwig #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */ 4253dcf5451SChristoph Hellwig #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */ 4263dcf5451SChristoph Hellwig /* Reserved for compression usage... */ 4273dcf5451SChristoph Hellwig #define EXT4_DIRTY_FL 0x00000100 4283dcf5451SChristoph Hellwig #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 4293dcf5451SChristoph Hellwig #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */ 4303edc18d8STheodore Ts'o /* nb: was previously EXT2_ECOMPR_FL */ 4313edc18d8STheodore Ts'o #define EXT4_ENCRYPT_FL 0x00000800 /* encrypted file */ 4323dcf5451SChristoph Hellwig /* End compression flags --- maybe not all used */ 4333dcf5451SChristoph Hellwig #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */ 4343dcf5451SChristoph Hellwig #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */ 4353dcf5451SChristoph Hellwig #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 4363dcf5451SChristoph Hellwig #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 4373dcf5451SChristoph Hellwig #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 4383dcf5451SChristoph Hellwig #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 4393dcf5451SChristoph Hellwig #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 4403dcf5451SChristoph Hellwig #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 441c93d8f88SEric Biggers #define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */ 442f710b4b9STheodore Ts'o #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 4434337ecd1SEric Whitney /* 0x00400000 was formerly EXT4_EOFBLOCKS_FL */ 444b383a73fSIra Weiny 445b383a73fSIra Weiny #define EXT4_DAX_FL 0x02000000 /* Inode is DAX */ 446b383a73fSIra Weiny 44767cf5b09STao Ma #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ 4488b4953e1STheodore Ts'o #define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 449de8ff14cSEric Biggers #define EXT4_CASEFOLD_FL 0x40000000 /* Casefolded directory */ 4503dcf5451SChristoph Hellwig #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 4513dcf5451SChristoph Hellwig 4522a12e147SEric Biggers /* User modifiable flags */ 4532a12e147SEric Biggers #define EXT4_FL_USER_MODIFIABLE (EXT4_SECRM_FL | \ 4542a12e147SEric Biggers EXT4_UNRM_FL | \ 4552a12e147SEric Biggers EXT4_COMPR_FL | \ 4562a12e147SEric Biggers EXT4_SYNC_FL | \ 4572a12e147SEric Biggers EXT4_IMMUTABLE_FL | \ 4582a12e147SEric Biggers EXT4_APPEND_FL | \ 4592a12e147SEric Biggers EXT4_NODUMP_FL | \ 4602a12e147SEric Biggers EXT4_NOATIME_FL | \ 4612a12e147SEric Biggers EXT4_JOURNAL_DATA_FL | \ 4622a12e147SEric Biggers EXT4_NOTAIL_FL | \ 4632a12e147SEric Biggers EXT4_DIRSYNC_FL | \ 4642a12e147SEric Biggers EXT4_TOPDIR_FL | \ 4652a12e147SEric Biggers EXT4_EXTENTS_FL | \ 4662a12e147SEric Biggers 0x00400000 /* EXT4_EOFBLOCKS_FL */ | \ 4672a12e147SEric Biggers EXT4_DAX_FL | \ 4682a12e147SEric Biggers EXT4_PROJINHERIT_FL | \ 4692a12e147SEric Biggers EXT4_CASEFOLD_FL) 4702a12e147SEric Biggers 4712a12e147SEric Biggers /* User visible flags */ 4722a12e147SEric Biggers #define EXT4_FL_USER_VISIBLE (EXT4_FL_USER_MODIFIABLE | \ 4732a12e147SEric Biggers EXT4_DIRTY_FL | \ 4742a12e147SEric Biggers EXT4_COMPRBLK_FL | \ 4752a12e147SEric Biggers EXT4_NOCOMPR_FL | \ 4762a12e147SEric Biggers EXT4_ENCRYPT_FL | \ 4772a12e147SEric Biggers EXT4_INDEX_FL | \ 4782a12e147SEric Biggers EXT4_VERITY_FL | \ 4792a12e147SEric Biggers EXT4_INLINE_DATA_FL) 4803dcf5451SChristoph Hellwig 4818fa43a81SDuane Griffin /* Flags that should be inherited by new inodes from their parent. */ 4828fa43a81SDuane Griffin #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ 4831cd9f097STheodore Ts'o EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ 4848fa43a81SDuane Griffin EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ 485040cb378SLi Xi EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL |\ 486b383a73fSIra Weiny EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL |\ 487b383a73fSIra Weiny EXT4_DAX_FL) 4888fa43a81SDuane Griffin 4892dc6b0d4SDuane Griffin /* Flags that are appropriate for regular files (all but dir-specific ones). */ 4907ddf79a1SWang Shilong #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL | EXT4_CASEFOLD_FL |\ 4917ddf79a1SWang Shilong EXT4_PROJINHERIT_FL)) 4922dc6b0d4SDuane Griffin 4932dc6b0d4SDuane Griffin /* Flags that are appropriate for non-directories/regular files. */ 4942dc6b0d4SDuane Griffin #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) 4952dc6b0d4SDuane Griffin 496abdc644eSyangerkun /* The only flags that should be swapped */ 497abdc644eSyangerkun #define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL) 498abdc644eSyangerkun 499b383a73fSIra Weiny /* Flags which are mutually exclusive to DAX */ 500b383a73fSIra Weiny #define EXT4_DAX_MUT_EXCL (EXT4_VERITY_FL | EXT4_ENCRYPT_FL |\ 501aa2f7792SXiao Yang EXT4_JOURNAL_DATA_FL | EXT4_INLINE_DATA_FL) 502b383a73fSIra Weiny 5032dc6b0d4SDuane Griffin /* Mask out flags that are inappropriate for the given type of inode. */ 5042dc6b0d4SDuane Griffin static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) 5052dc6b0d4SDuane Griffin { 5062dc6b0d4SDuane Griffin if (S_ISDIR(mode)) 5072dc6b0d4SDuane Griffin return flags; 5082dc6b0d4SDuane Griffin else if (S_ISREG(mode)) 5092dc6b0d4SDuane Griffin return flags & EXT4_REG_FLMASK; 5102dc6b0d4SDuane Griffin else 5112dc6b0d4SDuane Griffin return flags & EXT4_OTHER_FLMASK; 5122dc6b0d4SDuane Griffin } 5132dc6b0d4SDuane Griffin 51412e9b892SDmitry Monakhov /* 51512e9b892SDmitry Monakhov * Inode flags used for atomic set/get 51612e9b892SDmitry Monakhov */ 51712e9b892SDmitry Monakhov enum { 51812e9b892SDmitry Monakhov EXT4_INODE_SECRM = 0, /* Secure deletion */ 51912e9b892SDmitry Monakhov EXT4_INODE_UNRM = 1, /* Undelete */ 52012e9b892SDmitry Monakhov EXT4_INODE_COMPR = 2, /* Compress file */ 52112e9b892SDmitry Monakhov EXT4_INODE_SYNC = 3, /* Synchronous updates */ 52212e9b892SDmitry Monakhov EXT4_INODE_IMMUTABLE = 4, /* Immutable file */ 52312e9b892SDmitry Monakhov EXT4_INODE_APPEND = 5, /* writes to file may only append */ 52412e9b892SDmitry Monakhov EXT4_INODE_NODUMP = 6, /* do not dump file */ 52512e9b892SDmitry Monakhov EXT4_INODE_NOATIME = 7, /* do not update atime */ 52612e9b892SDmitry Monakhov /* Reserved for compression usage... */ 52712e9b892SDmitry Monakhov EXT4_INODE_DIRTY = 8, 52812e9b892SDmitry Monakhov EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */ 52912e9b892SDmitry Monakhov EXT4_INODE_NOCOMPR = 10, /* Don't compress */ 530f542fbe8STheodore Ts'o EXT4_INODE_ENCRYPT = 11, /* Encrypted file */ 53112e9b892SDmitry Monakhov /* End compression flags --- maybe not all used */ 53212e9b892SDmitry Monakhov EXT4_INODE_INDEX = 12, /* hash-indexed directory */ 53312e9b892SDmitry Monakhov EXT4_INODE_IMAGIC = 13, /* AFS directory */ 53412e9b892SDmitry Monakhov EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */ 53512e9b892SDmitry Monakhov EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */ 53612e9b892SDmitry Monakhov EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */ 53712e9b892SDmitry Monakhov EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/ 53812e9b892SDmitry Monakhov EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */ 53912e9b892SDmitry Monakhov EXT4_INODE_EXTENTS = 19, /* Inode uses extents */ 540c93d8f88SEric Biggers EXT4_INODE_VERITY = 20, /* Verity protected inode */ 54112e9b892SDmitry Monakhov EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */ 5424337ecd1SEric Whitney /* 22 was formerly EXT4_INODE_EOFBLOCKS */ 543b383a73fSIra Weiny EXT4_INODE_DAX = 25, /* Inode is DAX */ 54467cf5b09STao Ma EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */ 5458b4953e1STheodore Ts'o EXT4_INODE_PROJINHERIT = 29, /* Create with parents projid */ 546de8ff14cSEric Biggers EXT4_INODE_CASEFOLD = 30, /* Casefolded directory */ 54712e9b892SDmitry Monakhov EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ 54812e9b892SDmitry Monakhov }; 54912e9b892SDmitry Monakhov 55012e9b892SDmitry Monakhov /* 5519a4c8019SCarlos Maiolino * Since it's pretty easy to mix up bit numbers and hex values, we use a 5529a4c8019SCarlos Maiolino * build-time check to make sure that EXT4_XXX_FL is consistent with respect to 5539a4c8019SCarlos Maiolino * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost 5549a4c8019SCarlos Maiolino * any extra space in the compiled kernel image, otherwise, the build will fail. 5559a4c8019SCarlos Maiolino * It's important that these values are the same, since we are using 5569a4c8019SCarlos Maiolino * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent 5579a4c8019SCarlos Maiolino * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk 5589a4c8019SCarlos Maiolino * values found in ext2, ext3 and ext4 filesystems, and of course the values 5599a4c8019SCarlos Maiolino * defined in e2fsprogs. 56012e9b892SDmitry Monakhov * 56112e9b892SDmitry Monakhov * It's not paranoia if the Murphy's Law really *is* out to get you. :-) 56212e9b892SDmitry Monakhov */ 5639a4c8019SCarlos Maiolino #define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) 5649a4c8019SCarlos Maiolino #define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) 5659a4c8019SCarlos Maiolino 56612e9b892SDmitry Monakhov static inline void ext4_check_flag_values(void) 56712e9b892SDmitry Monakhov { 56812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SECRM); 56912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(UNRM); 57012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPR); 57112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SYNC); 57212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMMUTABLE); 57312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(APPEND); 57412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NODUMP); 57512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOATIME); 57612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRTY); 57712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPRBLK); 57812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOCOMPR); 5793edc18d8STheodore Ts'o CHECK_FLAG_VALUE(ENCRYPT); 58012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(INDEX); 58112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMAGIC); 58212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(JOURNAL_DATA); 58312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOTAIL); 58412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRSYNC); 58512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(TOPDIR); 58612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(HUGE_FILE); 58712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EXTENTS); 588c93d8f88SEric Biggers CHECK_FLAG_VALUE(VERITY); 58912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EA_INODE); 59067cf5b09STao Ma CHECK_FLAG_VALUE(INLINE_DATA); 5918b4953e1STheodore Ts'o CHECK_FLAG_VALUE(PROJINHERIT); 592de8ff14cSEric Biggers CHECK_FLAG_VALUE(CASEFOLD); 59312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(RESERVED); 59412e9b892SDmitry Monakhov } 59512e9b892SDmitry Monakhov 5963dcf5451SChristoph Hellwig /* Used to pass group descriptor data when online resize is done */ 5973dcf5451SChristoph Hellwig struct ext4_new_group_input { 5983dcf5451SChristoph Hellwig __u32 group; /* Group number for this data */ 5993dcf5451SChristoph Hellwig __u64 block_bitmap; /* Absolute block number of block bitmap */ 6003dcf5451SChristoph Hellwig __u64 inode_bitmap; /* Absolute block number of inode bitmap */ 6013dcf5451SChristoph Hellwig __u64 inode_table; /* Absolute block number of inode table start */ 6023dcf5451SChristoph Hellwig __u32 blocks_count; /* Total number of blocks in this group */ 6033dcf5451SChristoph Hellwig __u16 reserved_blocks; /* Number of reserved blocks in this group */ 6043dcf5451SChristoph Hellwig __u16 unused; 6053dcf5451SChristoph Hellwig }; 6063dcf5451SChristoph Hellwig 6074d92dc0fSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 6084d92dc0fSBen Hutchings struct compat_ext4_new_group_input { 6094d92dc0fSBen Hutchings u32 group; 6104d92dc0fSBen Hutchings compat_u64 block_bitmap; 6114d92dc0fSBen Hutchings compat_u64 inode_bitmap; 6124d92dc0fSBen Hutchings compat_u64 inode_table; 6134d92dc0fSBen Hutchings u32 blocks_count; 6144d92dc0fSBen Hutchings u16 reserved_blocks; 6154d92dc0fSBen Hutchings u16 unused; 6164d92dc0fSBen Hutchings }; 6174d92dc0fSBen Hutchings #endif 6184d92dc0fSBen Hutchings 6193dcf5451SChristoph Hellwig /* The struct ext4_new_group_input in kernel space, with free_blocks_count */ 6203dcf5451SChristoph Hellwig struct ext4_new_group_data { 6213dcf5451SChristoph Hellwig __u32 group; 6223dcf5451SChristoph Hellwig __u64 block_bitmap; 6233dcf5451SChristoph Hellwig __u64 inode_bitmap; 6243dcf5451SChristoph Hellwig __u64 inode_table; 6253dcf5451SChristoph Hellwig __u32 blocks_count; 6263dcf5451SChristoph Hellwig __u16 reserved_blocks; 627d77147ffSharshads __u16 mdata_blocks; 628d77147ffSharshads __u32 free_clusters_count; 6293dcf5451SChristoph Hellwig }; 6303dcf5451SChristoph Hellwig 63133afdcc5SYongqiang Yang /* Indexes used to index group tables in ext4_new_group_data */ 63233afdcc5SYongqiang Yang enum { 63333afdcc5SYongqiang Yang BLOCK_BITMAP = 0, /* block bitmap */ 63433afdcc5SYongqiang Yang INODE_BITMAP, /* inode bitmap */ 63533afdcc5SYongqiang Yang INODE_TABLE, /* inode tables */ 63633afdcc5SYongqiang Yang GROUP_TABLE_COUNT, 63733afdcc5SYongqiang Yang }; 63833afdcc5SYongqiang Yang 6393dcf5451SChristoph Hellwig /* 64079e83036SEric Sandeen * Flags used by ext4_map_blocks() 6413dcf5451SChristoph Hellwig */ 642556615dcSLukas Czerner /* Allocate any needed blocks and/or convert an unwritten 643c2177057STheodore Ts'o extent to be an initialized ext4 */ 6442ac3b6e0STheodore Ts'o #define EXT4_GET_BLOCKS_CREATE 0x0001 645556615dcSLukas Czerner /* Request the creation of an unwritten extent */ 646556615dcSLukas Czerner #define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002 647556615dcSLukas Czerner #define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\ 648c2177057STheodore Ts'o EXT4_GET_BLOCKS_CREATE) 64927dd4385SLukas Czerner /* Caller is from the delayed allocation writeout path 65027dd4385SLukas Czerner * finally doing the actual allocation of delayed blocks */ 65103f5d8bcSJan Kara #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004 6520031462bSMingming Cao /* caller is from the direct IO path, request to creation of an 653556615dcSLukas Czerner unwritten extents if not allocated, split the unwritten 6540031462bSMingming Cao extent if blocks has been preallocated already*/ 655c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_PRE_IO 0x0008 6561296cc85SAneesh Kumar K.V #define EXT4_GET_BLOCKS_CONVERT 0x0010 657c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\ 658556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 659c7064ef1SJiaying Zhang /* Convert extent to initialized after IO complete */ 660c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\ 661556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 66227dd4385SLukas Czerner /* Eventual metadata allocation (due to growing extent tree) 66327dd4385SLukas Czerner * should not fail, so try to use reserved blocks for that.*/ 66427dd4385SLukas Czerner #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020 665556b27abSVivek Haldar /* Don't normalize allocation size (used for fallocate) */ 666556b27abSVivek Haldar #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040 667b8a86845SLukas Czerner /* Convert written extents to unwritten */ 6682dcba478SJan Kara #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0100 669c86d8db3SJan Kara /* Write zeros to newly created written extents */ 670c86d8db3SJan Kara #define EXT4_GET_BLOCKS_ZERO 0x0200 671c86d8db3SJan Kara #define EXT4_GET_BLOCKS_CREATE_ZERO (EXT4_GET_BLOCKS_CREATE |\ 672c86d8db3SJan Kara EXT4_GET_BLOCKS_ZERO) 673ee0876bcSJan Kara /* Caller will submit data before dropping transaction handle. This 674ee0876bcSJan Kara * allows jbd2 to avoid submitting data before commit. */ 675ee0876bcSJan Kara #define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400 6769558cf14SZhang Yi /* Caller is in the atomic contex, find extent if it has been cached */ 6779558cf14SZhang Yi #define EXT4_GET_BLOCKS_CACHED_NOWAIT 0x0800 6783dcf5451SChristoph Hellwig 6793dcf5451SChristoph Hellwig /* 6807869a4a6STheodore Ts'o * The bit position of these flags must not overlap with any of the 681ed8a1a76STheodore Ts'o * EXT4_GET_BLOCKS_*. They are used by ext4_find_extent(), 682107a7bd3STheodore Ts'o * read_extent_tree_block(), ext4_split_extent_at(), 6837869a4a6STheodore Ts'o * ext4_ext_insert_extent(), and ext4_ext_create_new_leaf(). 6847869a4a6STheodore Ts'o * EXT4_EX_NOCACHE is used to indicate that the we shouldn't be 6857869a4a6STheodore Ts'o * caching the extents when reading from the extent tree while a 6867869a4a6STheodore Ts'o * truncate or punch hole operation is in progress. 687107a7bd3STheodore Ts'o */ 688d26e2c4dSTheodore Ts'o #define EXT4_EX_NOCACHE 0x40000000 689d26e2c4dSTheodore Ts'o #define EXT4_EX_FORCE_CACHE 0x20000000 69073c384c0STheodore Ts'o #define EXT4_EX_NOFAIL 0x10000000 691107a7bd3STheodore Ts'o 692107a7bd3STheodore Ts'o /* 693e6362609STheodore Ts'o * Flags used by ext4_free_blocks 694e6362609STheodore Ts'o */ 695e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_METADATA 0x0001 696e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_FORGET 0x0002 6971f2acb60STheodore Ts'o #define EXT4_FREE_BLOCKS_VALIDATED 0x0004 6987132de74SMaxim Patlasov #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008 69984130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010 70084130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020 7019fe67149SEric Whitney #define EXT4_FREE_BLOCKS_RERESERVE_CLUSTER 0x0040 702e6362609STheodore Ts'o 703e6362609STheodore Ts'o /* 7043dcf5451SChristoph Hellwig * ioctl commands 7053dcf5451SChristoph Hellwig */ 7063dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION _IOR('f', 3, long) 7073dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION _IOW('f', 4, long) 7083dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION 7093dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION 7103dcf5451SChristoph Hellwig #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long) 7113dcf5451SChristoph Hellwig #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) 7128eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) 7138eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input) 7148eea80d5STheodore Ts'o #define EXT4_IOC_MIGRATE _IO('f', 9) 715ccd2506bSTheodore Ts'o /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */ 7168eea80d5STheodore Ts'o /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ 717ccd2506bSTheodore Ts'o #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) 718748de673SAkira Fujita #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) 71919c5246dSYongqiang Yang #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) 720393d1d1dSDr. Tilmann Bubeck #define EXT4_IOC_SWAP_BOOT _IO('f', 17) 7217869a4a6STheodore Ts'o #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18) 722b0c013e2STheodore Ts'o /* ioctl codes 19--39 are reserved for fscrypt */ 723b0c013e2STheodore Ts'o #define EXT4_IOC_CLEAR_ES_CACHE _IO('f', 40) 7241ad3ea6eSTheodore Ts'o #define EXT4_IOC_GETSTATE _IOW('f', 41, __u32) 725bb5835edSTheodore Ts'o #define EXT4_IOC_GET_ES_CACHE _IOWR('f', 42, struct fiemap) 726351a0a3fSLeah Rumancik #define EXT4_IOC_CHECKPOINT _IOW('f', 43, __u32) 7273dcf5451SChristoph Hellwig 728e9be2ac7STheodore Ts'o #define EXT4_IOC_SHUTDOWN _IOR ('X', 125, __u32) 729783d9485STheodore Ts'o 730783d9485STheodore Ts'o /* 731783d9485STheodore Ts'o * Flags for going down operation 732783d9485STheodore Ts'o */ 733783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_DEFAULT 0x0 /* going down */ 734783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */ 735783d9485STheodore Ts'o #define EXT4_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */ 736783d9485STheodore Ts'o 7371ad3ea6eSTheodore Ts'o /* 7381ad3ea6eSTheodore Ts'o * Flags returned by EXT4_IOC_GETSTATE 7391ad3ea6eSTheodore Ts'o * 7401ad3ea6eSTheodore Ts'o * We only expose to userspace a subset of the state flags in 7411ad3ea6eSTheodore Ts'o * i_state_flags 7421ad3ea6eSTheodore Ts'o */ 7431ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_EXT_PRECACHED 0x00000001 7441ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_NEW 0x00000002 7451ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_NEWENTRY 0x00000004 7461ad3ea6eSTheodore Ts'o #define EXT4_STATE_FLAG_DA_ALLOC_CLOSE 0x00000008 747783d9485STheodore Ts'o 748351a0a3fSLeah Rumancik /* flags for ioctl EXT4_IOC_CHECKPOINT */ 749351a0a3fSLeah Rumancik #define EXT4_IOC_CHECKPOINT_FLAG_DISCARD 0x1 750351a0a3fSLeah Rumancik #define EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT 0x2 751351a0a3fSLeah Rumancik #define EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN 0x4 752351a0a3fSLeah Rumancik #define EXT4_IOC_CHECKPOINT_FLAG_VALID (EXT4_IOC_CHECKPOINT_FLAG_DISCARD | \ 753351a0a3fSLeah Rumancik EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT | \ 754351a0a3fSLeah Rumancik EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) 755351a0a3fSLeah Rumancik 756899ad0ceSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 7573dcf5451SChristoph Hellwig /* 7583dcf5451SChristoph Hellwig * ioctl commands in 32 bit emulation 7593dcf5451SChristoph Hellwig */ 7603dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION _IOR('f', 3, int) 7613dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION _IOW('f', 4, int) 7623dcf5451SChristoph Hellwig #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int) 7633dcf5451SChristoph Hellwig #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int) 7643dcf5451SChristoph Hellwig #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 7654d92dc0fSBen Hutchings #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input) 7663dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 7673dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 768899ad0ceSBen Hutchings #endif 7693dcf5451SChristoph Hellwig 770bb5835edSTheodore Ts'o /* 771bb5835edSTheodore Ts'o * Returned by EXT4_IOC_GET_ES_CACHE as an additional possible flag. 772bb5835edSTheodore Ts'o * It indicates that the entry in extent status cache is for a hole. 773bb5835edSTheodore Ts'o */ 774bb5835edSTheodore Ts'o #define EXT4_FIEMAP_EXTENT_HOLE 0x08000000 775bb5835edSTheodore Ts'o 776b595076aSUwe Kleine-König /* Max physical block we can address w/o extents */ 777fb0a387dSEric Sandeen #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF 778fb0a387dSEric Sandeen 779bcd8e91fSTheodore Ts'o /* Max logical block we can support */ 7809f44eda1SRitesh Harjani #define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFE 781bcd8e91fSTheodore Ts'o 7823dcf5451SChristoph Hellwig /* 7833dcf5451SChristoph Hellwig * Structure of an inode on the disk 7843dcf5451SChristoph Hellwig */ 7853dcf5451SChristoph Hellwig struct ext4_inode { 7863dcf5451SChristoph Hellwig __le16 i_mode; /* File mode */ 7873dcf5451SChristoph Hellwig __le16 i_uid; /* Low 16 bits of Owner Uid */ 7883dcf5451SChristoph Hellwig __le32 i_size_lo; /* Size in bytes */ 7893dcf5451SChristoph Hellwig __le32 i_atime; /* Access time */ 7903dcf5451SChristoph Hellwig __le32 i_ctime; /* Inode Change time */ 7913dcf5451SChristoph Hellwig __le32 i_mtime; /* Modification time */ 7923dcf5451SChristoph Hellwig __le32 i_dtime; /* Deletion Time */ 7933dcf5451SChristoph Hellwig __le16 i_gid; /* Low 16 bits of Group Id */ 7943dcf5451SChristoph Hellwig __le16 i_links_count; /* Links count */ 7953dcf5451SChristoph Hellwig __le32 i_blocks_lo; /* Blocks count */ 7963dcf5451SChristoph Hellwig __le32 i_flags; /* File flags */ 7973dcf5451SChristoph Hellwig union { 7983dcf5451SChristoph Hellwig struct { 7993dcf5451SChristoph Hellwig __le32 l_i_version; 8003dcf5451SChristoph Hellwig } linux1; 8013dcf5451SChristoph Hellwig struct { 8023dcf5451SChristoph Hellwig __u32 h_i_translator; 8033dcf5451SChristoph Hellwig } hurd1; 8043dcf5451SChristoph Hellwig struct { 8053dcf5451SChristoph Hellwig __u32 m_i_reserved1; 8063dcf5451SChristoph Hellwig } masix1; 8073dcf5451SChristoph Hellwig } osd1; /* OS dependent 1 */ 8083dcf5451SChristoph Hellwig __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ 8093dcf5451SChristoph Hellwig __le32 i_generation; /* File version (for NFS) */ 8103dcf5451SChristoph Hellwig __le32 i_file_acl_lo; /* File ACL */ 8113dcf5451SChristoph Hellwig __le32 i_size_high; 8123dcf5451SChristoph Hellwig __le32 i_obso_faddr; /* Obsoleted fragment address */ 8133dcf5451SChristoph Hellwig union { 8143dcf5451SChristoph Hellwig struct { 8153dcf5451SChristoph Hellwig __le16 l_i_blocks_high; /* were l_i_reserved1 */ 8163dcf5451SChristoph Hellwig __le16 l_i_file_acl_high; 8173dcf5451SChristoph Hellwig __le16 l_i_uid_high; /* these 2 fields */ 8183dcf5451SChristoph Hellwig __le16 l_i_gid_high; /* were reserved2[0] */ 819e6153918SDarrick J. Wong __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */ 820e6153918SDarrick J. Wong __le16 l_i_reserved; 8213dcf5451SChristoph Hellwig } linux2; 8223dcf5451SChristoph Hellwig struct { 8233dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 8243dcf5451SChristoph Hellwig __u16 h_i_mode_high; 8253dcf5451SChristoph Hellwig __u16 h_i_uid_high; 8263dcf5451SChristoph Hellwig __u16 h_i_gid_high; 8273dcf5451SChristoph Hellwig __u32 h_i_author; 8283dcf5451SChristoph Hellwig } hurd2; 8293dcf5451SChristoph Hellwig struct { 8303dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 8313dcf5451SChristoph Hellwig __le16 m_i_file_acl_high; 8323dcf5451SChristoph Hellwig __u32 m_i_reserved2[2]; 8333dcf5451SChristoph Hellwig } masix2; 8343dcf5451SChristoph Hellwig } osd2; /* OS dependent 2 */ 8353dcf5451SChristoph Hellwig __le16 i_extra_isize; 836e6153918SDarrick J. Wong __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ 8373dcf5451SChristoph Hellwig __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 8383dcf5451SChristoph Hellwig __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 8393dcf5451SChristoph Hellwig __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 8403dcf5451SChristoph Hellwig __le32 i_crtime; /* File Creation time */ 8413dcf5451SChristoph Hellwig __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 8423dcf5451SChristoph Hellwig __le32 i_version_hi; /* high 32 bits for 64-bit version */ 8438b4953e1STheodore Ts'o __le32 i_projid; /* Project ID */ 8443dcf5451SChristoph Hellwig }; 8453dcf5451SChristoph Hellwig 846748de673SAkira Fujita struct move_extent { 847748de673SAkira Fujita __u32 reserved; /* should be zero */ 848748de673SAkira Fujita __u32 donor_fd; /* donor file descriptor */ 849748de673SAkira Fujita __u64 orig_start; /* logical start offset in block for orig */ 850748de673SAkira Fujita __u64 donor_start; /* logical start offset in block for donor */ 851748de673SAkira Fujita __u64 len; /* block length to be moved */ 852748de673SAkira Fujita __u64 moved_len; /* moved block length */ 853748de673SAkira Fujita }; 8543dcf5451SChristoph Hellwig 8553dcf5451SChristoph Hellwig #define EXT4_EPOCH_BITS 2 8563dcf5451SChristoph Hellwig #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) 8573dcf5451SChristoph Hellwig #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) 8583dcf5451SChristoph Hellwig 8593dcf5451SChristoph Hellwig /* 8603dcf5451SChristoph Hellwig * Extended fields will fit into an inode if the filesystem was formatted 8613dcf5451SChristoph Hellwig * with large inodes (-I 256 or larger) and there are not currently any EAs 8623dcf5451SChristoph Hellwig * consuming all of the available space. For new inodes we always reserve 8633dcf5451SChristoph Hellwig * enough space for the kernel's known extended fields, but for inodes 8643dcf5451SChristoph Hellwig * created with an old kernel this might not have been the case. None of 8653dcf5451SChristoph Hellwig * the extended inode fields is critical for correct filesystem operation. 8663dcf5451SChristoph Hellwig * This macro checks if a certain field fits in the inode. Note that 8673dcf5451SChristoph Hellwig * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize 8683dcf5451SChristoph Hellwig */ 8693dcf5451SChristoph Hellwig #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \ 8703dcf5451SChristoph Hellwig ((offsetof(typeof(*ext4_inode), field) + \ 8713dcf5451SChristoph Hellwig sizeof((ext4_inode)->field)) \ 8723dcf5451SChristoph Hellwig <= (EXT4_GOOD_OLD_INODE_SIZE + \ 8733dcf5451SChristoph Hellwig (einode)->i_extra_isize)) \ 8743dcf5451SChristoph Hellwig 875a4dad1aeSDavid Turner /* 876a4dad1aeSDavid Turner * We use an encoding that preserves the times for extra epoch "00": 877a4dad1aeSDavid Turner * 878a4dad1aeSDavid Turner * extra msb of adjust for signed 879a4dad1aeSDavid Turner * epoch 32-bit 32-bit tv_sec to 880a4dad1aeSDavid Turner * bits time decoded 64-bit tv_sec 64-bit tv_sec valid time range 881a4dad1aeSDavid Turner * 0 0 1 -0x80000000..-0x00000001 0x000000000 1901-12-13..1969-12-31 882a4dad1aeSDavid Turner * 0 0 0 0x000000000..0x07fffffff 0x000000000 1970-01-01..2038-01-19 883a4dad1aeSDavid Turner * 0 1 1 0x080000000..0x0ffffffff 0x100000000 2038-01-19..2106-02-07 884a4dad1aeSDavid Turner * 0 1 0 0x100000000..0x17fffffff 0x100000000 2106-02-07..2174-02-25 885a4dad1aeSDavid Turner * 1 0 1 0x180000000..0x1ffffffff 0x200000000 2174-02-25..2242-03-16 886a4dad1aeSDavid Turner * 1 0 0 0x200000000..0x27fffffff 0x200000000 2242-03-16..2310-04-04 887a4dad1aeSDavid Turner * 1 1 1 0x280000000..0x2ffffffff 0x300000000 2310-04-04..2378-04-22 888a4dad1aeSDavid Turner * 1 1 0 0x300000000..0x37fffffff 0x300000000 2378-04-22..2446-05-10 889a4dad1aeSDavid Turner * 890a4dad1aeSDavid Turner * Note that previous versions of the kernel on 64-bit systems would 891a4dad1aeSDavid Turner * incorrectly use extra epoch bits 1,1 for dates between 1901 and 892a4dad1aeSDavid Turner * 1970. e2fsck will correct this, assuming that it is run on the 893a4dad1aeSDavid Turner * affected filesystem before 2242. 894a4dad1aeSDavid Turner */ 895a4dad1aeSDavid Turner 8967b62b293SArnd Bergmann static inline __le32 ext4_encode_extra_time(struct timespec64 *time) 8973dcf5451SChristoph Hellwig { 8987b62b293SArnd Bergmann u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK; 899a4dad1aeSDavid Turner return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); 9003dcf5451SChristoph Hellwig } 9013dcf5451SChristoph Hellwig 9027b62b293SArnd Bergmann static inline void ext4_decode_extra_time(struct timespec64 *time, 9037b62b293SArnd Bergmann __le32 extra) 9043dcf5451SChristoph Hellwig { 905cd2d9922STheodore Ts'o if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) 906a4dad1aeSDavid Turner time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; 907c1fccc06STheodore Ts'o time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 9083dcf5451SChristoph Hellwig } 9093dcf5451SChristoph Hellwig 9103dcf5451SChristoph Hellwig #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 9113dcf5451SChristoph Hellwig do { \ 91295582b00SDeepa Dinamani if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\ 9134881c497SDeepa Dinamani (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ 9143dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 9157b62b293SArnd Bergmann ext4_encode_extra_time(&(inode)->xtime); \ 91695582b00SDeepa Dinamani } \ 917cba465b4SDeepa Dinamani else \ 9184881c497SDeepa Dinamani (raw_inode)->xtime = cpu_to_le32(clamp_t(int32_t, (inode)->xtime.tv_sec, S32_MIN, S32_MAX)); \ 9193dcf5451SChristoph Hellwig } while (0) 9203dcf5451SChristoph Hellwig 9213dcf5451SChristoph Hellwig #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 9223dcf5451SChristoph Hellwig do { \ 9233dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 9243dcf5451SChristoph Hellwig (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \ 9253dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 9263dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 9273dcf5451SChristoph Hellwig ext4_encode_extra_time(&(einode)->xtime); \ 9283dcf5451SChristoph Hellwig } while (0) 9293dcf5451SChristoph Hellwig 9303dcf5451SChristoph Hellwig #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 9313dcf5451SChristoph Hellwig do { \ 9323dcf5451SChristoph Hellwig (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ 93395582b00SDeepa Dinamani if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ 9347b62b293SArnd Bergmann ext4_decode_extra_time(&(inode)->xtime, \ 9353dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 93695582b00SDeepa Dinamani } \ 937af0b44a1SEric Sandeen else \ 938af0b44a1SEric Sandeen (inode)->xtime.tv_nsec = 0; \ 9393dcf5451SChristoph Hellwig } while (0) 9403dcf5451SChristoph Hellwig 94195582b00SDeepa Dinamani 9423dcf5451SChristoph Hellwig #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 9433dcf5451SChristoph Hellwig do { \ 9443dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 9453dcf5451SChristoph Hellwig (einode)->xtime.tv_sec = \ 9463dcf5451SChristoph Hellwig (signed)le32_to_cpu((raw_inode)->xtime); \ 94719ea8060STheodore Ts'o else \ 94819ea8060STheodore Ts'o (einode)->xtime.tv_sec = 0; \ 9493dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 9503dcf5451SChristoph Hellwig ext4_decode_extra_time(&(einode)->xtime, \ 9513dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 952af0b44a1SEric Sandeen else \ 953af0b44a1SEric Sandeen (einode)->xtime.tv_nsec = 0; \ 9543dcf5451SChristoph Hellwig } while (0) 9553dcf5451SChristoph Hellwig 9563dcf5451SChristoph Hellwig #define i_disk_version osd1.linux1.l_i_version 9573dcf5451SChristoph Hellwig 9583dcf5451SChristoph Hellwig #if defined(__KERNEL__) || defined(__linux__) 9593dcf5451SChristoph Hellwig #define i_reserved1 osd1.linux1.l_i_reserved1 9603dcf5451SChristoph Hellwig #define i_file_acl_high osd2.linux2.l_i_file_acl_high 9613dcf5451SChristoph Hellwig #define i_blocks_high osd2.linux2.l_i_blocks_high 9623dcf5451SChristoph Hellwig #define i_uid_low i_uid 9633dcf5451SChristoph Hellwig #define i_gid_low i_gid 9643dcf5451SChristoph Hellwig #define i_uid_high osd2.linux2.l_i_uid_high 9653dcf5451SChristoph Hellwig #define i_gid_high osd2.linux2.l_i_gid_high 966e6153918SDarrick J. Wong #define i_checksum_lo osd2.linux2.l_i_checksum_lo 9673dcf5451SChristoph Hellwig 9683dcf5451SChristoph Hellwig #elif defined(__GNU__) 9693dcf5451SChristoph Hellwig 9703dcf5451SChristoph Hellwig #define i_translator osd1.hurd1.h_i_translator 9713dcf5451SChristoph Hellwig #define i_uid_high osd2.hurd2.h_i_uid_high 9723dcf5451SChristoph Hellwig #define i_gid_high osd2.hurd2.h_i_gid_high 9733dcf5451SChristoph Hellwig #define i_author osd2.hurd2.h_i_author 9743dcf5451SChristoph Hellwig 9753dcf5451SChristoph Hellwig #elif defined(__masix__) 9763dcf5451SChristoph Hellwig 9773dcf5451SChristoph Hellwig #define i_reserved1 osd1.masix1.m_i_reserved1 9783dcf5451SChristoph Hellwig #define i_file_acl_high osd2.masix2.m_i_file_acl_high 9793dcf5451SChristoph Hellwig #define i_reserved2 osd2.masix2.m_i_reserved2 9803dcf5451SChristoph Hellwig 9813dcf5451SChristoph Hellwig #endif /* defined(__KERNEL__) || defined(__linux__) */ 9823dcf5451SChristoph Hellwig 983c0677e6dSZheng Liu #include "extents_status.h" 9846866d7b3SHarshad Shirwadkar #include "fast_commit.h" 985c0677e6dSZheng Liu 986d444c3c3STheodore Ts'o /* 987daf647d2STheodore Ts'o * Lock subclasses for i_data_sem in the ext4_inode_info structure. 988daf647d2STheodore Ts'o * 989daf647d2STheodore Ts'o * These are needed to avoid lockdep false positives when we need to 990daf647d2STheodore Ts'o * allocate blocks to the quota inode during ext4_map_blocks(), while 991daf647d2STheodore Ts'o * holding i_data_sem for a normal (non-quota) inode. Since we don't 992daf647d2STheodore Ts'o * do quota tracking for the quota inode, this avoids deadlock (as 993daf647d2STheodore Ts'o * well as infinite recursion, since it isn't turtles all the way 994daf647d2STheodore Ts'o * down...) 995daf647d2STheodore Ts'o * 996daf647d2STheodore Ts'o * I_DATA_SEM_NORMAL - Used for most inodes 997daf647d2STheodore Ts'o * I_DATA_SEM_OTHER - Used by move_inode.c for the second normal inode 998daf647d2STheodore Ts'o * where the second inode has larger inode number 999daf647d2STheodore Ts'o * than the first 1000daf647d2STheodore Ts'o * I_DATA_SEM_QUOTA - Used for quota inodes only 1001daf647d2STheodore Ts'o */ 1002daf647d2STheodore Ts'o enum { 1003daf647d2STheodore Ts'o I_DATA_SEM_NORMAL = 0, 1004daf647d2STheodore Ts'o I_DATA_SEM_OTHER, 1005daf647d2STheodore Ts'o I_DATA_SEM_QUOTA, 1006daf647d2STheodore Ts'o }; 1007daf647d2STheodore Ts'o 1008daf647d2STheodore Ts'o 1009daf647d2STheodore Ts'o /* 1010d444c3c3STheodore Ts'o * fourth extended file system inode data in memory 1011d444c3c3STheodore Ts'o */ 1012d444c3c3STheodore Ts'o struct ext4_inode_info { 1013d444c3c3STheodore Ts'o __le32 i_data[15]; /* unconverted */ 1014d444c3c3STheodore Ts'o __u32 i_dtime; 101512e9b892SDmitry Monakhov ext4_fsblk_t i_file_acl; 1016d444c3c3STheodore Ts'o 1017d444c3c3STheodore Ts'o /* 1018d444c3c3STheodore Ts'o * i_block_group is the number of the block group which contains 1019d444c3c3STheodore Ts'o * this file's inode. Constant across the lifetime of the inode, 1020a627b0a7SEric Whitney * it is used for making block allocation decisions - we try to 1021d444c3c3STheodore Ts'o * place a file's data blocks near its inode block, and new inodes 1022d444c3c3STheodore Ts'o * near to their parent directory's inode. 1023d444c3c3STheodore Ts'o */ 1024d444c3c3STheodore Ts'o ext4_group_t i_block_group; 10258a2005d3STheodore Ts'o ext4_lblk_t i_dir_start_lookup; 1026353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 102719f5fb7aSTheodore Ts'o unsigned long i_state_flags; /* Dynamic state flags */ 1028353eb83cSTheodore Ts'o #endif 102912e9b892SDmitry Monakhov unsigned long i_flags; 1030d444c3c3STheodore Ts'o 1031d444c3c3STheodore Ts'o /* 1032d444c3c3STheodore Ts'o * Extended attributes can be read independently of the main file 1033f340b3d9Shongnanli * data. Taking i_rwsem even when reading would cause contention 1034d444c3c3STheodore Ts'o * between readers of EAs and writers of regular file data, so 1035d444c3c3STheodore Ts'o * instead we synchronize on xattr_sem when reading or changing 1036d444c3c3STheodore Ts'o * EAs. 1037d444c3c3STheodore Ts'o */ 1038d444c3c3STheodore Ts'o struct rw_semaphore xattr_sem; 1039d444c3c3STheodore Ts'o 104002f310fcSJan Kara /* 104102f310fcSJan Kara * Inodes with EXT4_STATE_ORPHAN_FILE use i_orphan_idx. Otherwise 104202f310fcSJan Kara * i_orphan is used. 104302f310fcSJan Kara */ 104402f310fcSJan Kara union { 1045d444c3c3STheodore Ts'o struct list_head i_orphan; /* unlinked but open inodes */ 104602f310fcSJan Kara unsigned int i_orphan_idx; /* Index in orphan file */ 104702f310fcSJan Kara }; 1048d444c3c3STheodore Ts'o 1049aa75f4d3SHarshad Shirwadkar /* Fast commit related info */ 1050aa75f4d3SHarshad Shirwadkar 1051b3998b3bSRitesh Harjani /* For tracking dentry create updates */ 1052b3998b3bSRitesh Harjani struct list_head i_fc_dilist; 1053aa75f4d3SHarshad Shirwadkar struct list_head i_fc_list; /* 1054aa75f4d3SHarshad Shirwadkar * inodes that need fast commit 1055aa75f4d3SHarshad Shirwadkar * protected by sbi->s_fc_lock. 1056aa75f4d3SHarshad Shirwadkar */ 1057aa75f4d3SHarshad Shirwadkar 1058aa75f4d3SHarshad Shirwadkar /* Start of lblk range that needs to be committed in this fast commit */ 1059aa75f4d3SHarshad Shirwadkar ext4_lblk_t i_fc_lblk_start; 1060aa75f4d3SHarshad Shirwadkar 1061aa75f4d3SHarshad Shirwadkar /* End of lblk range that needs to be committed in this fast commit */ 1062aa75f4d3SHarshad Shirwadkar ext4_lblk_t i_fc_lblk_len; 1063aa75f4d3SHarshad Shirwadkar 1064aa75f4d3SHarshad Shirwadkar /* Number of ongoing updates on this inode */ 1065aa75f4d3SHarshad Shirwadkar atomic_t i_fc_updates; 1066aa75f4d3SHarshad Shirwadkar 1067aa75f4d3SHarshad Shirwadkar /* Fast commit wait queue for this inode */ 1068aa75f4d3SHarshad Shirwadkar wait_queue_head_t i_fc_wait; 1069aa75f4d3SHarshad Shirwadkar 1070aa75f4d3SHarshad Shirwadkar /* Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len */ 1071aa75f4d3SHarshad Shirwadkar struct mutex i_fc_lock; 1072aa75f4d3SHarshad Shirwadkar 1073d444c3c3STheodore Ts'o /* 1074d444c3c3STheodore Ts'o * i_disksize keeps track of what the inode size is ON DISK, not 1075d444c3c3STheodore Ts'o * in memory. During truncate, i_size is set to the new size by 1076d444c3c3STheodore Ts'o * the VFS prior to calling ext4_truncate(), but the filesystem won't 1077d444c3c3STheodore Ts'o * set i_disksize to 0 until the truncate is actually under way. 1078d444c3c3STheodore Ts'o * 1079d444c3c3STheodore Ts'o * The intent is that i_disksize always represents the blocks which 1080d444c3c3STheodore Ts'o * are used by this file. This allows recovery to restart truncate 1081d444c3c3STheodore Ts'o * on orphans if we crash during truncate. We actually write i_disksize 1082d444c3c3STheodore Ts'o * into the on-disk inode when writing inodes out, instead of i_size. 1083d444c3c3STheodore Ts'o * 1084d444c3c3STheodore Ts'o * The only time when i_disksize and i_size may be different is when 1085d444c3c3STheodore Ts'o * a truncate is in progress. The only things which change i_disksize 1086d444c3c3STheodore Ts'o * are ext4_get_block (growth) and ext4_truncate (shrinkth). 1087d444c3c3STheodore Ts'o */ 1088d444c3c3STheodore Ts'o loff_t i_disksize; 1089d444c3c3STheodore Ts'o 1090d444c3c3STheodore Ts'o /* 1091d444c3c3STheodore Ts'o * i_data_sem is for serialising ext4_truncate() against 1092d444c3c3STheodore Ts'o * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's 1093d444c3c3STheodore Ts'o * data tree are chopped off during truncate. We can't do that in 1094d444c3c3STheodore Ts'o * ext4 because whenever we perform intermediate commits during 1095d444c3c3STheodore Ts'o * truncate, the inode and all the metadata blocks *must* be in a 1096d444c3c3STheodore Ts'o * consistent state which allows truncation of the orphans to restart 1097d444c3c3STheodore Ts'o * during recovery. Hence we must fix the get_block-vs-truncate race 1098d444c3c3STheodore Ts'o * by other means, so we have i_data_sem. 1099d444c3c3STheodore Ts'o */ 1100d444c3c3STheodore Ts'o struct rw_semaphore i_data_sem; 1101d444c3c3STheodore Ts'o struct inode vfs_inode; 11028aefcd55STheodore Ts'o struct jbd2_inode *jinode; 1103d444c3c3STheodore Ts'o 1104202ee5dfSTheodore Ts'o spinlock_t i_raw_lock; /* protects updates to the raw inode */ 1105202ee5dfSTheodore Ts'o 1106d444c3c3STheodore Ts'o /* 1107d444c3c3STheodore Ts'o * File creation time. Its function is same as that of 11087b62b293SArnd Bergmann * struct timespec64 i_{a,c,m}time in the generic inode. 1109d444c3c3STheodore Ts'o */ 11107b62b293SArnd Bergmann struct timespec64 i_crtime; 1111d444c3c3STheodore Ts'o 1112d444c3c3STheodore Ts'o /* mballoc */ 111327bc446eSbrookxu atomic_t i_prealloc_active; 1114d444c3c3STheodore Ts'o struct list_head i_prealloc_list; 1115d444c3c3STheodore Ts'o spinlock_t i_prealloc_lock; 1116d444c3c3STheodore Ts'o 1117c0677e6dSZheng Liu /* extents status tree */ 1118c0677e6dSZheng Liu struct ext4_es_tree i_es_tree; 1119c0677e6dSZheng Liu rwlock_t i_es_lock; 1120edaa53caSZheng Liu struct list_head i_es_list; 1121eb68d0e2SZheng Liu unsigned int i_es_all_nr; /* protected by i_es_lock */ 1122edaa53caSZheng Liu unsigned int i_es_shk_nr; /* protected by i_es_lock */ 1123dd475925SJan Kara ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for 1124dd475925SJan Kara extents to shrink. Protected by 1125dd475925SJan Kara i_es_lock */ 1126c0677e6dSZheng Liu 1127d444c3c3STheodore Ts'o /* ialloc */ 1128d444c3c3STheodore Ts'o ext4_group_t i_last_alloc_group; 1129d444c3c3STheodore Ts'o 1130d444c3c3STheodore Ts'o /* allocation reservation info for delalloc */ 1131a627b0a7SEric Whitney /* In case of bigalloc, this refer to clusters rather than blocks */ 1132d444c3c3STheodore Ts'o unsigned int i_reserved_data_blocks; 1133d444c3c3STheodore Ts'o 11341dc0aa46SEric Whitney /* pending cluster reservations for bigalloc file systems */ 11351dc0aa46SEric Whitney struct ext4_pending_tree i_pending_tree; 11361dc0aa46SEric Whitney 1137d444c3c3STheodore Ts'o /* on-disk additional length */ 1138d444c3c3STheodore Ts'o __u16 i_extra_isize; 1139d444c3c3STheodore Ts'o 114067cf5b09STao Ma /* Indicate the inline data space. */ 114167cf5b09STao Ma u16 i_inline_off; 114267cf5b09STao Ma u16 i_inline_size; 114367cf5b09STao Ma 1144a9e7f447SDmitry Monakhov #ifdef CONFIG_QUOTA 1145a9e7f447SDmitry Monakhov /* quota space reservation, managed internally by quota code */ 1146a9e7f447SDmitry Monakhov qsize_t i_reserved_quota; 1147a9e7f447SDmitry Monakhov #endif 11488d5d02e6SMingming Cao 11492e8fa54eSJan Kara /* Lock protecting lists below */ 1150744692dcSJiaying Zhang spinlock_t i_completed_io_lock; 11512e8fa54eSJan Kara /* 11522e8fa54eSJan Kara * Completed IOs that need unwritten extents handling and have 11532e8fa54eSJan Kara * transaction reserved 11542e8fa54eSJan Kara */ 11552e8fa54eSJan Kara struct list_head i_rsv_conversion_list; 11562e8fa54eSJan Kara struct work_struct i_rsv_conversion_work; 1157600be30aSJan Kara atomic_t i_unwritten; /* Nr. of inflight conversions pending */ 11588a2005d3STheodore Ts'o 11598a2005d3STheodore Ts'o spinlock_t i_block_reservation_lock; 1160b436b9beSJan Kara 1161b436b9beSJan Kara /* 1162b436b9beSJan Kara * Transactions that contain inode's metadata needed to complete 1163b436b9beSJan Kara * fsync and fdatasync, respectively. 1164b436b9beSJan Kara */ 1165b436b9beSJan Kara tid_t i_sync_tid; 1166b436b9beSJan Kara tid_t i_datasync_tid; 1167814525f4SDarrick J. Wong 116896c7e0d9SJan Kara #ifdef CONFIG_QUOTA 116996c7e0d9SJan Kara struct dquot *i_dquot[MAXQUOTAS]; 117096c7e0d9SJan Kara #endif 117196c7e0d9SJan Kara 1172814525f4SDarrick J. Wong /* Precomputed uuid+inum+igen checksum for seeding inode checksums */ 1173814525f4SDarrick J. Wong __u32 i_csum_seed; 1174b30ab0e0SMichael Halcrow 1175040cb378SLi Xi kprojid_t i_projid; 1176d444c3c3STheodore Ts'o }; 1177d444c3c3STheodore Ts'o 1178d444c3c3STheodore Ts'o /* 11793dcf5451SChristoph Hellwig * File system states 11803dcf5451SChristoph Hellwig */ 11813dcf5451SChristoph Hellwig #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 11823dcf5451SChristoph Hellwig #define EXT4_ERROR_FS 0x0002 /* Errors detected */ 11833dcf5451SChristoph Hellwig #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ 11848016e29fSHarshad Shirwadkar #define EXT4_FC_REPLAY 0x0020 /* Fast commit replay ongoing */ 11853dcf5451SChristoph Hellwig 11863dcf5451SChristoph Hellwig /* 11873dcf5451SChristoph Hellwig * Misc. filesystem flags 11883dcf5451SChristoph Hellwig */ 11893dcf5451SChristoph Hellwig #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ 11903dcf5451SChristoph Hellwig #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ 11913dcf5451SChristoph Hellwig #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ 11923dcf5451SChristoph Hellwig 11933dcf5451SChristoph Hellwig /* 119468911009SLukas Czerner * Mount flags set via mount options or defaults 11953dcf5451SChristoph Hellwig */ 1196cdb7ee4cSTahsin Erdogan #define EXT4_MOUNT_NO_MBCACHE 0x00001 /* Do not use mbcache */ 11973dcf5451SChristoph Hellwig #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 11983dcf5451SChristoph Hellwig #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 11993dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 12003dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 12013dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 120239ef17f1STheodore Ts'o #define EXT4_MOUNT_ERRORS_MASK 0x00070 12033dcf5451SChristoph Hellwig #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 12043dcf5451SChristoph Hellwig #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 1205923ae0ffSRoss Zwisler #ifdef CONFIG_FS_DAX 1206fc626fe3SIra Weiny #define EXT4_MOUNT_DAX_ALWAYS 0x00200 /* Direct Access */ 1207923ae0ffSRoss Zwisler #else 1208fc626fe3SIra Weiny #define EXT4_MOUNT_DAX_ALWAYS 0 1209923ae0ffSRoss Zwisler #endif 12103dcf5451SChristoph Hellwig #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 12113dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 12123dcf5451SChristoph Hellwig #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 12133dcf5451SChristoph Hellwig #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 12143dcf5451SChristoph Hellwig #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 12153dcf5451SChristoph Hellwig #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 12163dcf5451SChristoph Hellwig #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 12173dcf5451SChristoph Hellwig #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 1218afd4672dSTheodore Ts'o #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 12193dcf5451SChristoph Hellwig #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 122049da9392SJan Kara #define EXT4_MOUNT_QUOTA 0x40000 /* Some quota option set */ 122149da9392SJan Kara #define EXT4_MOUNT_USRQUOTA 0x80000 /* "old" user quota, 122249da9392SJan Kara * enable enforcement for hidden 122349da9392SJan Kara * quota files */ 122449da9392SJan Kara #define EXT4_MOUNT_GRPQUOTA 0x100000 /* "old" group quota, enable 122549da9392SJan Kara * enforcement for hidden quota 122649da9392SJan Kara * files */ 122749da9392SJan Kara #define EXT4_MOUNT_PRJQUOTA 0x200000 /* Enable project quota 122849da9392SJan Kara * enforcement */ 1229744692dcSJiaying Zhang #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */ 1230d4da6c9cSLinus Torvalds #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 12313dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 1232327eaf73STheodore Ts'o #define EXT4_MOUNT_WARN_ON_ERROR 0x2000000 /* Trigger WARN_ON on error */ 123321175ca4SHarshad Shirwadkar #define EXT4_MOUNT_NO_PREFETCH_BLOCK_BITMAPS 0x4000000 123464769240SAlex Tomas #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 12355bf5683aSHidehiro Kawai #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 12366fd058f7STheodore Ts'o #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */ 12375328e635SEric Sandeen #define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */ 1238bfff6873SLukas Czerner #define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */ 12395bf5683aSHidehiro Kawai 124068911009SLukas Czerner /* 124168911009SLukas Czerner * Mount flags set either automatically (could not be set by mount option) 124268911009SLukas Czerner * based on per file system feature or property or in special cases such as 124368911009SLukas Czerner * distinguishing between explicit mount option definition and default. 124468911009SLukas Czerner */ 124556889787STheodore Ts'o #define EXT4_MOUNT2_EXPLICIT_DELALLOC 0x00000001 /* User explicitly 124656889787STheodore Ts'o specified delalloc */ 124768911009SLukas Czerner #define EXT4_MOUNT2_STD_GROUP_SIZE 0x00000002 /* We have standard group 124868911009SLukas Czerner size of blocksize * 8 124968911009SLukas Czerner blocks */ 1250ed3654ebSTheodore Ts'o #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated 1251ed3654ebSTheodore Ts'o file systems */ 12521e381f60SDmitry Monakhov #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly 12531e381f60SDmitry Monakhov specified journal checksum */ 12541e381f60SDmitry Monakhov 1255995a3ed6SHarshad Shirwadkar #define EXT4_MOUNT2_JOURNAL_FAST_COMMIT 0x00000010 /* Journal fast commit */ 1256a72b38eeSHarshad Shirwadkar #define EXT4_MOUNT2_DAX_NEVER 0x00000020 /* Do not allow Direct Access */ 1257a72b38eeSHarshad Shirwadkar #define EXT4_MOUNT2_DAX_INODE 0x00000040 /* For printing options only */ 1258196e402aSHarshad Shirwadkar #define EXT4_MOUNT2_MB_OPTIMIZE_SCAN 0x00000080 /* Optimize group 1259196e402aSHarshad Shirwadkar * scanning in mballoc 1260196e402aSHarshad Shirwadkar */ 1261995a3ed6SHarshad Shirwadkar 1262fd8c37ecSTheodore Ts'o #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ 1263fd8c37ecSTheodore Ts'o ~EXT4_MOUNT_##opt 1264fd8c37ecSTheodore Ts'o #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \ 1265fd8c37ecSTheodore Ts'o EXT4_MOUNT_##opt 12663dcf5451SChristoph Hellwig #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \ 12673dcf5451SChristoph Hellwig EXT4_MOUNT_##opt) 12683dcf5451SChristoph Hellwig 1269a2595b8aSTheodore Ts'o #define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \ 1270a2595b8aSTheodore Ts'o ~EXT4_MOUNT2_##opt 1271a2595b8aSTheodore Ts'o #define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \ 1272a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt 1273a2595b8aSTheodore Ts'o #define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \ 1274a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt) 1275a2595b8aSTheodore Ts'o 1276597d508cSAkinobu Mita #define ext4_test_and_set_bit __test_and_set_bit_le 1277597d508cSAkinobu Mita #define ext4_set_bit __set_bit_le 12783dcf5451SChristoph Hellwig #define ext4_set_bit_atomic ext2_set_bit_atomic 1279597d508cSAkinobu Mita #define ext4_test_and_clear_bit __test_and_clear_bit_le 1280597d508cSAkinobu Mita #define ext4_clear_bit __clear_bit_le 12813dcf5451SChristoph Hellwig #define ext4_clear_bit_atomic ext2_clear_bit_atomic 128250e0168cSAkinobu Mita #define ext4_test_bit test_bit_le 128350e0168cSAkinobu Mita #define ext4_find_next_zero_bit find_next_zero_bit_le 128450e0168cSAkinobu Mita #define ext4_find_next_bit find_next_bit_le 12853dcf5451SChristoph Hellwig 1286123e3016SRitesh Harjani extern void mb_set_bits(void *bm, int cur, int len); 1287c3e94d1dSYongqiang Yang 12883dcf5451SChristoph Hellwig /* 12893dcf5451SChristoph Hellwig * Maximal mount counts between two filesystem checks 12903dcf5451SChristoph Hellwig */ 12913dcf5451SChristoph Hellwig #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 12923dcf5451SChristoph Hellwig #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 12933dcf5451SChristoph Hellwig 12943dcf5451SChristoph Hellwig /* 12953dcf5451SChristoph Hellwig * Behaviour when detecting errors 12963dcf5451SChristoph Hellwig */ 12973dcf5451SChristoph Hellwig #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */ 12983dcf5451SChristoph Hellwig #define EXT4_ERRORS_RO 2 /* Remount fs read-only */ 12993dcf5451SChristoph Hellwig #define EXT4_ERRORS_PANIC 3 /* Panic */ 13003dcf5451SChristoph Hellwig #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 13013dcf5451SChristoph Hellwig 1302e6153918SDarrick J. Wong /* Metadata checksum algorithm codes */ 1303e6153918SDarrick J. Wong #define EXT4_CRC32C_CHKSUM 1 1304e6153918SDarrick J. Wong 1305bbc605cdSLukas Czerner #define EXT4_LABEL_MAX 16 1306bbc605cdSLukas Czerner 13073dcf5451SChristoph Hellwig /* 13083dcf5451SChristoph Hellwig * Structure of the super block 13093dcf5451SChristoph Hellwig */ 13103dcf5451SChristoph Hellwig struct ext4_super_block { 13113dcf5451SChristoph Hellwig /*00*/ __le32 s_inodes_count; /* Inodes count */ 13123dcf5451SChristoph Hellwig __le32 s_blocks_count_lo; /* Blocks count */ 13133dcf5451SChristoph Hellwig __le32 s_r_blocks_count_lo; /* Reserved blocks count */ 13143dcf5451SChristoph Hellwig __le32 s_free_blocks_count_lo; /* Free blocks count */ 13153dcf5451SChristoph Hellwig /*10*/ __le32 s_free_inodes_count; /* Free inodes count */ 13163dcf5451SChristoph Hellwig __le32 s_first_data_block; /* First Data Block */ 13173dcf5451SChristoph Hellwig __le32 s_log_block_size; /* Block size */ 1318281b5995STheodore Ts'o __le32 s_log_cluster_size; /* Allocation cluster size */ 13193dcf5451SChristoph Hellwig /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ 1320281b5995STheodore Ts'o __le32 s_clusters_per_group; /* # Clusters per group */ 13213dcf5451SChristoph Hellwig __le32 s_inodes_per_group; /* # Inodes per group */ 13223dcf5451SChristoph Hellwig __le32 s_mtime; /* Mount time */ 13233dcf5451SChristoph Hellwig /*30*/ __le32 s_wtime; /* Write time */ 13243dcf5451SChristoph Hellwig __le16 s_mnt_count; /* Mount count */ 13253dcf5451SChristoph Hellwig __le16 s_max_mnt_count; /* Maximal mount count */ 13263dcf5451SChristoph Hellwig __le16 s_magic; /* Magic signature */ 13273dcf5451SChristoph Hellwig __le16 s_state; /* File system state */ 13283dcf5451SChristoph Hellwig __le16 s_errors; /* Behaviour when detecting errors */ 13293dcf5451SChristoph Hellwig __le16 s_minor_rev_level; /* minor revision level */ 13303dcf5451SChristoph Hellwig /*40*/ __le32 s_lastcheck; /* time of last check */ 13313dcf5451SChristoph Hellwig __le32 s_checkinterval; /* max. time between checks */ 13323dcf5451SChristoph Hellwig __le32 s_creator_os; /* OS */ 13333dcf5451SChristoph Hellwig __le32 s_rev_level; /* Revision level */ 13343dcf5451SChristoph Hellwig /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 13353dcf5451SChristoph Hellwig __le16 s_def_resgid; /* Default gid for reserved blocks */ 13363dcf5451SChristoph Hellwig /* 13373dcf5451SChristoph Hellwig * These fields are for EXT4_DYNAMIC_REV superblocks only. 13383dcf5451SChristoph Hellwig * 13393dcf5451SChristoph Hellwig * Note: the difference between the compatible feature set and 13403dcf5451SChristoph Hellwig * the incompatible feature set is that if there is a bit set 13413dcf5451SChristoph Hellwig * in the incompatible feature set that the kernel doesn't 13423dcf5451SChristoph Hellwig * know about, it should refuse to mount the filesystem. 13433dcf5451SChristoph Hellwig * 13443dcf5451SChristoph Hellwig * e2fsck's requirements are more strict; if it doesn't know 13453dcf5451SChristoph Hellwig * about a feature in either the compatible or incompatible 13463dcf5451SChristoph Hellwig * feature set, it must abort and not try to meddle with 13473dcf5451SChristoph Hellwig * things it doesn't understand... 13483dcf5451SChristoph Hellwig */ 13493dcf5451SChristoph Hellwig __le32 s_first_ino; /* First non-reserved inode */ 13503dcf5451SChristoph Hellwig __le16 s_inode_size; /* size of inode structure */ 13513dcf5451SChristoph Hellwig __le16 s_block_group_nr; /* block group # of this superblock */ 13523dcf5451SChristoph Hellwig __le32 s_feature_compat; /* compatible feature set */ 13533dcf5451SChristoph Hellwig /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 13543dcf5451SChristoph Hellwig __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 13553dcf5451SChristoph Hellwig /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 1356bbc605cdSLukas Czerner /*78*/ char s_volume_name[EXT4_LABEL_MAX]; /* volume name */ 1357072ebb3bSTheodore Ts'o /*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */ 13583dcf5451SChristoph Hellwig /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 13593dcf5451SChristoph Hellwig /* 13603dcf5451SChristoph Hellwig * Performance hints. Directory preallocation should only 13613dcf5451SChristoph Hellwig * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. 13623dcf5451SChristoph Hellwig */ 13633dcf5451SChristoph Hellwig __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 13643dcf5451SChristoph Hellwig __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 13653dcf5451SChristoph Hellwig __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 13663dcf5451SChristoph Hellwig /* 13673dcf5451SChristoph Hellwig * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. 13683dcf5451SChristoph Hellwig */ 13693dcf5451SChristoph Hellwig /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 13703dcf5451SChristoph Hellwig /*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 13713dcf5451SChristoph Hellwig __le32 s_journal_dev; /* device number of journal file */ 13723dcf5451SChristoph Hellwig __le32 s_last_orphan; /* start of list of inodes to delete */ 13733dcf5451SChristoph Hellwig __le32 s_hash_seed[4]; /* HTREE hash seed */ 13743dcf5451SChristoph Hellwig __u8 s_def_hash_version; /* Default hash version to use */ 137589eeddf0STheodore Ts'o __u8 s_jnl_backup_type; 13763dcf5451SChristoph Hellwig __le16 s_desc_size; /* size of group descriptor */ 13773dcf5451SChristoph Hellwig /*100*/ __le32 s_default_mount_opts; 13783dcf5451SChristoph Hellwig __le32 s_first_meta_bg; /* First metablock block group */ 13793dcf5451SChristoph Hellwig __le32 s_mkfs_time; /* When the filesystem was created */ 13803dcf5451SChristoph Hellwig __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ 13813dcf5451SChristoph Hellwig /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ 13823dcf5451SChristoph Hellwig /*150*/ __le32 s_blocks_count_hi; /* Blocks count */ 13833dcf5451SChristoph Hellwig __le32 s_r_blocks_count_hi; /* Reserved blocks count */ 13843dcf5451SChristoph Hellwig __le32 s_free_blocks_count_hi; /* Free blocks count */ 13853dcf5451SChristoph Hellwig __le16 s_min_extra_isize; /* All inodes have at least # bytes */ 13863dcf5451SChristoph Hellwig __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ 13873dcf5451SChristoph Hellwig __le32 s_flags; /* Miscellaneous flags */ 13883dcf5451SChristoph Hellwig __le16 s_raid_stride; /* RAID stride */ 1389c5e06d10SJohann Lombardi __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ 13903dcf5451SChristoph Hellwig __le64 s_mmp_block; /* Block for multi-mount protection */ 13913dcf5451SChristoph Hellwig __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 1392772cb7c8SJose R. Santos __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 1393e6153918SDarrick J. Wong __u8 s_checksum_type; /* metadata checksum algorithm used */ 1394f542fbe8STheodore Ts'o __u8 s_encryption_level; /* versioning level for encryption */ 1395f542fbe8STheodore Ts'o __u8 s_reserved_pad; /* Padding to next 32bits */ 1396afc32f7eSTheodore Ts'o __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 13974a9cdec7STheodore Ts'o __le32 s_snapshot_inum; /* Inode number of active snapshot */ 13984a9cdec7STheodore Ts'o __le32 s_snapshot_id; /* sequential ID of active snapshot */ 13994a9cdec7STheodore Ts'o __le64 s_snapshot_r_blocks_count; /* reserved blocks for active 14004a9cdec7STheodore Ts'o snapshot's future use */ 14014a9cdec7STheodore Ts'o __le32 s_snapshot_list; /* inode number of the head of the 14024a9cdec7STheodore Ts'o on-disk snapshot list */ 14031c13d5c0STheodore Ts'o #define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count) 14041c13d5c0STheodore Ts'o __le32 s_error_count; /* number of fs errors */ 14051c13d5c0STheodore Ts'o __le32 s_first_error_time; /* first time an error happened */ 14061c13d5c0STheodore Ts'o __le32 s_first_error_ino; /* inode involved in first error */ 14071c13d5c0STheodore Ts'o __le64 s_first_error_block; /* block involved of first error */ 1408072ebb3bSTheodore Ts'o __u8 s_first_error_func[32] __nonstring; /* function where the error happened */ 14091c13d5c0STheodore Ts'o __le32 s_first_error_line; /* line number where error happened */ 14101c13d5c0STheodore Ts'o __le32 s_last_error_time; /* most recent time of an error */ 14111c13d5c0STheodore Ts'o __le32 s_last_error_ino; /* inode involved in last error */ 14121c13d5c0STheodore Ts'o __le32 s_last_error_line; /* line number where error happened */ 14131c13d5c0STheodore Ts'o __le64 s_last_error_block; /* block involved of last error */ 1414072ebb3bSTheodore Ts'o __u8 s_last_error_func[32] __nonstring; /* function where the error happened */ 14158b67f04aSTheodore Ts'o #define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts) 14168b67f04aSTheodore Ts'o __u8 s_mount_opts[64]; 1417281b5995STheodore Ts'o __le32 s_usr_quota_inum; /* inode for tracking user quota */ 1418281b5995STheodore Ts'o __le32 s_grp_quota_inum; /* inode for tracking group quota */ 1419281b5995STheodore Ts'o __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ 14201beeef1bSDarrick J. Wong __le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */ 14213edc18d8STheodore Ts'o __u8 s_encrypt_algos[4]; /* Encryption algorithms in use */ 1422f542fbe8STheodore Ts'o __u8 s_encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ 1423f542fbe8STheodore Ts'o __le32 s_lpf_ino; /* Location of the lost+found inode */ 14248b4953e1STheodore Ts'o __le32 s_prj_quota_inum; /* inode for tracking project quota */ 14258c81bd8fSDarrick J. Wong __le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */ 14266a0678a7SArnd Bergmann __u8 s_wtime_hi; 14276a0678a7SArnd Bergmann __u8 s_mtime_hi; 14286a0678a7SArnd Bergmann __u8 s_mkfs_time_hi; 14296a0678a7SArnd Bergmann __u8 s_lastcheck_hi; 14306a0678a7SArnd Bergmann __u8 s_first_error_time_hi; 14316a0678a7SArnd Bergmann __u8 s_last_error_time_hi; 1432878520acSTheodore Ts'o __u8 s_first_error_errcode; 1433878520acSTheodore Ts'o __u8 s_last_error_errcode; 1434c83ad55eSGabriel Krisman Bertazi __le16 s_encoding; /* Filename charset encoding */ 1435c83ad55eSGabriel Krisman Bertazi __le16 s_encoding_flags; /* Filename charset encoding flags */ 143602f310fcSJan Kara __le32 s_orphan_file_inum; /* Inode for tracking orphan inodes */ 143702f310fcSJan Kara __le32 s_reserved[94]; /* Padding to the end of the block */ 1438e6153918SDarrick J. Wong __le32 s_checksum; /* crc32c(superblock) */ 14393dcf5451SChristoph Hellwig }; 14403dcf5451SChristoph Hellwig 14411c13d5c0STheodore Ts'o #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) 14421c13d5c0STheodore Ts'o 14433dcf5451SChristoph Hellwig #ifdef __KERNEL__ 1444bc0b0d6dSTheodore Ts'o 1445a2d4a646SJan Kara /* Number of quota types we support */ 1446689c958cSLi Xi #define EXT4_MAXQUOTAS 3 1447a2d4a646SJan Kara 1448c83ad55eSGabriel Krisman Bertazi #define EXT4_ENC_UTF8_12_1 1 1449c83ad55eSGabriel Krisman Bertazi 1450188c299eSJan Kara /* Types of ext4 journal triggers */ 1451188c299eSJan Kara enum ext4_journal_trigger_type { 145202f310fcSJan Kara EXT4_JTR_ORPHAN_FILE, 1453188c299eSJan Kara EXT4_JTR_NONE /* This must be the last entry for indexing to work! */ 1454188c299eSJan Kara }; 1455188c299eSJan Kara 1456188c299eSJan Kara #define EXT4_JOURNAL_TRIGGER_COUNT EXT4_JTR_NONE 1457188c299eSJan Kara 1458188c299eSJan Kara struct ext4_journal_trigger { 1459188c299eSJan Kara struct jbd2_buffer_trigger_type tr_triggers; 1460188c299eSJan Kara struct super_block *sb; 1461188c299eSJan Kara }; 1462188c299eSJan Kara 1463188c299eSJan Kara static inline struct ext4_journal_trigger *EXT4_TRIGGER( 1464188c299eSJan Kara struct jbd2_buffer_trigger_type *trigger) 1465188c299eSJan Kara { 1466188c299eSJan Kara return container_of(trigger, struct ext4_journal_trigger, tr_triggers); 1467188c299eSJan Kara } 1468188c299eSJan Kara 146902f310fcSJan Kara #define EXT4_ORPHAN_BLOCK_MAGIC 0x0b10ca04 147002f310fcSJan Kara 147102f310fcSJan Kara /* Structure at the tail of orphan block */ 147202f310fcSJan Kara struct ext4_orphan_block_tail { 147302f310fcSJan Kara __le32 ob_magic; 147402f310fcSJan Kara __le32 ob_checksum; 147502f310fcSJan Kara }; 147602f310fcSJan Kara 147702f310fcSJan Kara static inline int ext4_inodes_per_orphan_block(struct super_block *sb) 147802f310fcSJan Kara { 147902f310fcSJan Kara return (sb->s_blocksize - sizeof(struct ext4_orphan_block_tail)) / 148002f310fcSJan Kara sizeof(u32); 148102f310fcSJan Kara } 148202f310fcSJan Kara 148302f310fcSJan Kara struct ext4_orphan_block { 14844a79a98cSJan Kara atomic_t ob_free_entries; /* Number of free orphan entries in block */ 148502f310fcSJan Kara struct buffer_head *ob_bh; /* Buffer for orphan block */ 148602f310fcSJan Kara }; 148702f310fcSJan Kara 148802f310fcSJan Kara /* 148902f310fcSJan Kara * Info about orphan file. 149002f310fcSJan Kara */ 149102f310fcSJan Kara struct ext4_orphan_info { 149202f310fcSJan Kara int of_blocks; /* Number of orphan blocks in a file */ 149302f310fcSJan Kara __u32 of_csum_seed; /* Checksum seed for orphan file */ 149402f310fcSJan Kara struct ext4_orphan_block *of_binfo; /* Array with info about orphan 149502f310fcSJan Kara * file blocks */ 149602f310fcSJan Kara }; 149702f310fcSJan Kara 1498c83ad55eSGabriel Krisman Bertazi /* 1499ca0faba0STheodore Ts'o * fourth extended-fs super-block data in memory 1500ca0faba0STheodore Ts'o */ 1501ca0faba0STheodore Ts'o struct ext4_sb_info { 1502ca0faba0STheodore Ts'o unsigned long s_desc_size; /* Size of a group descriptor in bytes */ 1503ca0faba0STheodore Ts'o unsigned long s_inodes_per_block;/* Number of inodes per block */ 1504ca0faba0STheodore Ts'o unsigned long s_blocks_per_group;/* Number of blocks in a group */ 1505281b5995STheodore Ts'o unsigned long s_clusters_per_group; /* Number of clusters in a group */ 1506ca0faba0STheodore Ts'o unsigned long s_inodes_per_group;/* Number of inodes in a group */ 1507ca0faba0STheodore Ts'o unsigned long s_itb_per_group; /* Number of inode table blocks per group */ 1508ca0faba0STheodore Ts'o unsigned long s_gdb_count; /* Number of group descriptor blocks */ 1509ca0faba0STheodore Ts'o unsigned long s_desc_per_block; /* Number of group descriptors per block */ 1510ca0faba0STheodore Ts'o ext4_group_t s_groups_count; /* Number of groups in the fs */ 1511fb0a387dSEric Sandeen ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */ 1512952fc18eSTheodore Ts'o unsigned long s_overhead; /* # of fs overhead clusters */ 1513281b5995STheodore Ts'o unsigned int s_cluster_ratio; /* Number of blocks per cluster */ 1514281b5995STheodore Ts'o unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */ 1515ca0faba0STheodore Ts'o loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */ 1516ca0faba0STheodore Ts'o struct buffer_head * s_sbh; /* Buffer containing the super block */ 1517ca0faba0STheodore Ts'o struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */ 15181d0c3924STheodore Ts'o struct buffer_head * __rcu *s_group_desc; 15197f4520ccSTheodore Ts'o unsigned int s_mount_opt; 1520a2595b8aSTheodore Ts'o unsigned int s_mount_opt2; 15219b5f6c9bSHarshad Shirwadkar unsigned long s_mount_flags; 15225a916be1STheodore Ts'o unsigned int s_def_mount_opt; 1523ca0faba0STheodore Ts'o ext4_fsblk_t s_sb_block; 152427dd4385SLukas Czerner atomic64_t s_resv_clusters; 152508cefc7aSEric W. Biederman kuid_t s_resuid; 152608cefc7aSEric W. Biederman kgid_t s_resgid; 1527ca0faba0STheodore Ts'o unsigned short s_mount_state; 1528ca0faba0STheodore Ts'o unsigned short s_pad; 1529ca0faba0STheodore Ts'o int s_addr_per_block_bits; 1530ca0faba0STheodore Ts'o int s_desc_per_block_bits; 1531ca0faba0STheodore Ts'o int s_inode_size; 1532ca0faba0STheodore Ts'o int s_first_ino; 1533ca0faba0STheodore Ts'o unsigned int s_inode_readahead_blks; 153411013911SAndreas Dilger unsigned int s_inode_goal; 1535ca0faba0STheodore Ts'o u32 s_hash_seed[4]; 1536ca0faba0STheodore Ts'o int s_def_hash_version; 15376d2424a8SEric Biggers int s_hash_unsigned; /* 3 if hash should be unsigned, 0 if not */ 153857042651STheodore Ts'o struct percpu_counter s_freeclusters_counter; 1539ca0faba0STheodore Ts'o struct percpu_counter s_freeinodes_counter; 1540ca0faba0STheodore Ts'o struct percpu_counter s_dirs_counter; 154157042651STheodore Ts'o struct percpu_counter s_dirtyclusters_counter; 1542efc61345SEric Whitney struct percpu_counter s_sra_exceeded_retry_limit; 1543ca0faba0STheodore Ts'o struct blockgroup_lock *s_blockgroup_lock; 1544ca0faba0STheodore Ts'o struct proc_dir_entry *s_proc; 1545ca0faba0STheodore Ts'o struct kobject s_kobj; 1546ca0faba0STheodore Ts'o struct completion s_kobj_unregister; 15472c0544b2STheodore Ts'o struct super_block *s_sb; 1548618f0031SPavel Skripkin struct buffer_head *s_mmp_bh; 1549ca0faba0STheodore Ts'o 1550ca0faba0STheodore Ts'o /* Journaling */ 1551ca0faba0STheodore Ts'o struct journal_s *s_journal; 15529549a168STheodore Ts'o unsigned long s_ext4_flags; /* Ext4 superblock flags */ 155302f310fcSJan Kara struct mutex s_orphan_lock; /* Protects on disk list changes */ 155402f310fcSJan Kara struct list_head s_orphan; /* List of orphaned inodes in on disk 155502f310fcSJan Kara list */ 155602f310fcSJan Kara struct ext4_orphan_info s_orphan_info; 1557ca0faba0STheodore Ts'o unsigned long s_commit_interval; 1558ca0faba0STheodore Ts'o u32 s_max_batch_time; 1559ca0faba0STheodore Ts'o u32 s_min_batch_time; 1560ee7ed3aaSChunguang Xu struct block_device *s_journal_bdev; 1561ca0faba0STheodore Ts'o #ifdef CONFIG_QUOTA 156233458eabSTheodore Ts'o /* Names of quota files with journalled quota */ 156333458eabSTheodore Ts'o char __rcu *s_qf_names[EXT4_MAXQUOTAS]; 1564ca0faba0STheodore Ts'o int s_jquota_fmt; /* Format of quota to use */ 1565ca0faba0STheodore Ts'o #endif 1566ca0faba0STheodore Ts'o unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */ 1567dd0db94fSChunguang Xu struct ext4_system_blocks __rcu *s_system_blks; 1568ca0faba0STheodore Ts'o 1569ca0faba0STheodore Ts'o #ifdef EXTENTS_STATS 1570ca0faba0STheodore Ts'o /* ext4 extents stats */ 1571ca0faba0STheodore Ts'o unsigned long s_ext_min; 1572ca0faba0STheodore Ts'o unsigned long s_ext_max; 1573ca0faba0STheodore Ts'o unsigned long s_depth_max; 1574ca0faba0STheodore Ts'o spinlock_t s_ext_stats_lock; 1575ca0faba0STheodore Ts'o unsigned long s_ext_blocks; 1576ca0faba0STheodore Ts'o unsigned long s_ext_extents; 1577ca0faba0STheodore Ts'o #endif 1578ca0faba0STheodore Ts'o 1579ca0faba0STheodore Ts'o /* for buddy allocator */ 1580df3da4eaSSuraj Jitindar Singh struct ext4_group_info ** __rcu *s_group_info; 1581ca0faba0STheodore Ts'o struct inode *s_buddy_cache; 1582ca0faba0STheodore Ts'o spinlock_t s_md_lock; 1583ca0faba0STheodore Ts'o unsigned short *s_mb_offsets; 1584ca0faba0STheodore Ts'o unsigned int *s_mb_maxs; 158528623c2fSTheodore Ts'o unsigned int s_group_info_size; 1586d08854f5STheodore Ts'o unsigned int s_mb_free_pending; 1587a0154344SDaeho Jeong struct list_head s_freed_data_list; /* List of blocks to be freed 1588a0154344SDaeho Jeong after commit completed */ 158955cdd0afSWang Jianchao struct list_head s_discard_list; 159055cdd0afSWang Jianchao struct work_struct s_discard_work; 15915036ab8dSWang Jianchao atomic_t s_retry_alloc_pending; 1592196e402aSHarshad Shirwadkar struct rb_root s_mb_avg_fragment_size_root; 1593196e402aSHarshad Shirwadkar rwlock_t s_mb_rb_lock; 1594196e402aSHarshad Shirwadkar struct list_head *s_mb_largest_free_orders; 1595196e402aSHarshad Shirwadkar rwlock_t *s_mb_largest_free_orders_locks; 1596ca0faba0STheodore Ts'o 1597ca0faba0STheodore Ts'o /* tunables */ 1598ca0faba0STheodore Ts'o unsigned long s_stripe; 1599196e402aSHarshad Shirwadkar unsigned int s_mb_max_linear_groups; 1600ca0faba0STheodore Ts'o unsigned int s_mb_stream_request; 1601ca0faba0STheodore Ts'o unsigned int s_mb_max_to_scan; 1602ca0faba0STheodore Ts'o unsigned int s_mb_min_to_scan; 1603ca0faba0STheodore Ts'o unsigned int s_mb_stats; 1604ca0faba0STheodore Ts'o unsigned int s_mb_order2_reqs; 1605ca0faba0STheodore Ts'o unsigned int s_mb_group_prealloc; 160627bc446eSbrookxu unsigned int s_mb_max_inode_prealloc; 1607df981d03STheodore Ts'o unsigned int s_max_dir_size_kb; 1608ca0faba0STheodore Ts'o /* where last allocation was done - for stream allocation */ 1609ca0faba0STheodore Ts'o unsigned long s_mb_last_group; 1610ca0faba0STheodore Ts'o unsigned long s_mb_last_start; 1611cfd73237SAlex Zhuravlev unsigned int s_mb_prefetch; 1612cfd73237SAlex Zhuravlev unsigned int s_mb_prefetch_limit; 1613ca0faba0STheodore Ts'o 1614ca0faba0STheodore Ts'o /* stats for buddy allocator */ 1615ca0faba0STheodore Ts'o atomic_t s_bal_reqs; /* number of reqs with len > 1 */ 1616ca0faba0STheodore Ts'o atomic_t s_bal_success; /* we found long enough chunks */ 1617ca0faba0STheodore Ts'o atomic_t s_bal_allocated; /* in blocks */ 1618ca0faba0STheodore Ts'o atomic_t s_bal_ex_scanned; /* total extents scanned */ 1619a6c75eafSHarshad Shirwadkar atomic_t s_bal_groups_scanned; /* number of groups scanned */ 1620ca0faba0STheodore Ts'o atomic_t s_bal_goals; /* goal hits */ 1621ca0faba0STheodore Ts'o atomic_t s_bal_breaks; /* too long searches */ 1622ca0faba0STheodore Ts'o atomic_t s_bal_2orders; /* 2^order hits */ 1623196e402aSHarshad Shirwadkar atomic_t s_bal_cr0_bad_suggestions; 1624196e402aSHarshad Shirwadkar atomic_t s_bal_cr1_bad_suggestions; 1625a6c75eafSHarshad Shirwadkar atomic64_t s_bal_cX_groups_considered[4]; 1626a6c75eafSHarshad Shirwadkar atomic64_t s_bal_cX_hits[4]; 1627a6c75eafSHarshad Shirwadkar atomic64_t s_bal_cX_failed[4]; /* cX loop didn't find blocks */ 162867d25186SHarshad Shirwadkar atomic_t s_mb_buddies_generated; /* number of buddies generated */ 162967d25186SHarshad Shirwadkar atomic64_t s_mb_generation_time; 1630ca0faba0STheodore Ts'o atomic_t s_mb_lost_chunks; 1631ca0faba0STheodore Ts'o atomic_t s_mb_preallocated; 1632ca0faba0STheodore Ts'o atomic_t s_mb_discarded; 163350797481STheodore Ts'o atomic_t s_lock_busy; 1634ca0faba0STheodore Ts'o 1635ca0faba0STheodore Ts'o /* locality groups */ 1636003cb608STejun Heo struct ext4_locality_group __percpu *s_locality_groups; 1637ca0faba0STheodore Ts'o 1638ca0faba0STheodore Ts'o /* for write statistics */ 1639ca0faba0STheodore Ts'o unsigned long s_sectors_written_start; 1640ca0faba0STheodore Ts'o u64 s_kbytes_written; 1641ca0faba0STheodore Ts'o 164267a5da56SZheng Liu /* the size of zero-out chunk */ 164367a5da56SZheng Liu unsigned int s_extent_max_zeroout_kb; 164467a5da56SZheng Liu 1645ca0faba0STheodore Ts'o unsigned int s_log_groups_per_flex; 16467c990728SSuraj Jitindar Singh struct flex_groups * __rcu *s_flex_groups; 1647117fff10STheodore Ts'o ext4_group_t s_flex_groups_allocated; 16484c0425ffSMingming Cao 16492e8fa54eSJan Kara /* workqueue for reserved extent conversions (buffered io) */ 16502e8fa54eSJan Kara struct workqueue_struct *rsv_conversion_wq; 165166e61a9eSTheodore Ts'o 165266e61a9eSTheodore Ts'o /* timer for periodic error stats printing */ 165366e61a9eSTheodore Ts'o struct timer_list s_err_report; 1654bfff6873SLukas Czerner 1655bfff6873SLukas Czerner /* Lazy inode table initialization info */ 1656bfff6873SLukas Czerner struct ext4_li_request *s_li_request; 1657bfff6873SLukas Czerner /* Wait multiplier for lazy initialization thread */ 1658bfff6873SLukas Czerner unsigned int s_li_wait_mult; 1659c5e06d10SJohann Lombardi 1660c5e06d10SJohann Lombardi /* Kernel thread for multiple mount protection */ 1661c5e06d10SJohann Lombardi struct task_struct *s_mmp_tsk; 16623d56b8d2STao Ma 16633d56b8d2STao Ma /* record the last minlen when FITRIM is called. */ 16642327fb2eSLukas Czerner unsigned long s_last_trim_minblks; 16650441984aSDarrick J. Wong 16660441984aSDarrick J. Wong /* Reference to checksum algorithm driver via cryptoapi */ 16670441984aSDarrick J. Wong struct crypto_shash *s_chksum_driver; 1668a9c47317SDarrick J. Wong 1669a9c47317SDarrick J. Wong /* Precomputed FS UUID checksum for seeding other checksums */ 1670a9c47317SDarrick J. Wong __u32 s_csum_seed; 167174cd15cdSZheng Liu 167274cd15cdSZheng Liu /* Reclaim extents from extent status tree */ 167374cd15cdSZheng Liu struct shrinker s_es_shrinker; 1674dd475925SJan Kara struct list_head s_es_list; /* List of inodes with reclaimable extents */ 1675edaa53caSZheng Liu long s_es_nr_inode; 1676eb68d0e2SZheng Liu struct ext4_es_stats s_es_stats; 167747387409STahsin Erdogan struct mb_cache *s_ea_block_cache; 1678dec214d0STahsin Erdogan struct mb_cache *s_ea_inode_cache; 1679edaa53caSZheng Liu spinlock_t s_es_lock ____cacheline_aligned_in_smp; 1680efbed4dcSTheodore Ts'o 1681188c299eSJan Kara /* Journal triggers for checksum computation */ 1682188c299eSJan Kara struct ext4_journal_trigger s_journal_triggers[EXT4_JOURNAL_TRIGGER_COUNT]; 1683188c299eSJan Kara 1684efbed4dcSTheodore Ts'o /* Ratelimit ext4 messages. */ 1685efbed4dcSTheodore Ts'o struct ratelimit_state s_err_ratelimit_state; 1686efbed4dcSTheodore Ts'o struct ratelimit_state s_warning_ratelimit_state; 1687efbed4dcSTheodore Ts'o struct ratelimit_state s_msg_ratelimit_state; 16881cf006edSDmitry Monakhov atomic_t s_warning_count; 16891cf006edSDmitry Monakhov atomic_t s_msg_count; 1690c8585c6fSDaeho Jeong 1691ac4acb1fSEric Biggers /* Encryption policy for '-o test_dummy_encryption' */ 1692ac4acb1fSEric Biggers struct fscrypt_dummy_policy s_dummy_enc_policy; 1693ed318a6cSEric Biggers 1694cb85f4d2SEric Biggers /* 1695cb85f4d2SEric Biggers * Barrier between writepages ops and changing any inode's JOURNAL_DATA 1696cb85f4d2SEric Biggers * or EXTENTS flag. 1697cb85f4d2SEric Biggers */ 1698bbd55937SEric Biggers struct percpu_rw_semaphore s_writepages_rwsem; 16995e405595SDan Williams struct dax_device *s_daxdev; 1700cd913c76SChristoph Hellwig u64 s_dax_part_off; 170146f870d6STheodore Ts'o #ifdef CONFIG_EXT4_DEBUG 170246f870d6STheodore Ts'o unsigned long s_simulate_fail; 170346f870d6STheodore Ts'o #endif 1704bc71726cSzhangyi (F) /* Record the errseq of the backing block device */ 1705bc71726cSzhangyi (F) errseq_t s_bdev_wb_err; 1706bc71726cSzhangyi (F) spinlock_t s_bdev_wb_lock; 1707aa75f4d3SHarshad Shirwadkar 1708c92dc856SJan Kara /* Information about errors that happened during this mount */ 1709c92dc856SJan Kara spinlock_t s_error_lock; 1710c92dc856SJan Kara int s_add_error_count; 1711c92dc856SJan Kara int s_first_error_code; 1712c92dc856SJan Kara __u32 s_first_error_line; 1713c92dc856SJan Kara __u32 s_first_error_ino; 1714c92dc856SJan Kara __u64 s_first_error_block; 1715c92dc856SJan Kara const char *s_first_error_func; 1716c92dc856SJan Kara time64_t s_first_error_time; 1717c92dc856SJan Kara int s_last_error_code; 1718c92dc856SJan Kara __u32 s_last_error_line; 1719c92dc856SJan Kara __u32 s_last_error_ino; 1720c92dc856SJan Kara __u64 s_last_error_block; 1721c92dc856SJan Kara const char *s_last_error_func; 1722c92dc856SJan Kara time64_t s_last_error_time; 1723c92dc856SJan Kara /* 1724c92dc856SJan Kara * If we are in a context where we cannot update error information in 1725c92dc856SJan Kara * the on-disk superblock, we queue this work to do it. 1726c92dc856SJan Kara */ 1727c92dc856SJan Kara struct work_struct s_error_work; 1728c92dc856SJan Kara 17297bbbe241SHarshad Shirwadkar /* Ext4 fast commit sub transaction ID */ 1730aa75f4d3SHarshad Shirwadkar atomic_t s_fc_subtid; 17317bbbe241SHarshad Shirwadkar 1732aa75f4d3SHarshad Shirwadkar /* 1733aa75f4d3SHarshad Shirwadkar * After commit starts, the main queue gets locked, and the further 1734aa75f4d3SHarshad Shirwadkar * updates get added in the staging queue. 1735aa75f4d3SHarshad Shirwadkar */ 1736aa75f4d3SHarshad Shirwadkar #define FC_Q_MAIN 0 1737aa75f4d3SHarshad Shirwadkar #define FC_Q_STAGING 1 1738aa75f4d3SHarshad Shirwadkar struct list_head s_fc_q[2]; /* Inodes staged for fast commit 1739aa75f4d3SHarshad Shirwadkar * that have data changes in them. 1740aa75f4d3SHarshad Shirwadkar */ 1741aa75f4d3SHarshad Shirwadkar struct list_head s_fc_dentry_q[2]; /* directory entry updates */ 1742aa75f4d3SHarshad Shirwadkar unsigned int s_fc_bytes; 1743aa75f4d3SHarshad Shirwadkar /* 1744aa75f4d3SHarshad Shirwadkar * Main fast commit lock. This lock protects accesses to the 1745aa75f4d3SHarshad Shirwadkar * following fields: 1746aa75f4d3SHarshad Shirwadkar * ei->i_fc_list, s_fc_dentry_q, s_fc_q, s_fc_bytes, s_fc_bh. 1747aa75f4d3SHarshad Shirwadkar */ 1748aa75f4d3SHarshad Shirwadkar spinlock_t s_fc_lock; 1749aa75f4d3SHarshad Shirwadkar struct buffer_head *s_fc_bh; 1750aa75f4d3SHarshad Shirwadkar struct ext4_fc_stats s_fc_stats; 1751e85c81baSXin Yin tid_t s_fc_ineligible_tid; 17528016e29fSHarshad Shirwadkar #ifdef CONFIG_EXT4_DEBUG 17538016e29fSHarshad Shirwadkar int s_fc_debug_max_replay; 17548016e29fSHarshad Shirwadkar #endif 17558016e29fSHarshad Shirwadkar struct ext4_fc_replay_state s_fc_replay_state; 1756ca0faba0STheodore Ts'o }; 1757ca0faba0STheodore Ts'o 17583dcf5451SChristoph Hellwig static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 17593dcf5451SChristoph Hellwig { 17603dcf5451SChristoph Hellwig return sb->s_fs_info; 17613dcf5451SChristoph Hellwig } 17623dcf5451SChristoph Hellwig static inline struct ext4_inode_info *EXT4_I(struct inode *inode) 17633dcf5451SChristoph Hellwig { 17643dcf5451SChristoph Hellwig return container_of(inode, struct ext4_inode_info, vfs_inode); 17653dcf5451SChristoph Hellwig } 17663dcf5451SChristoph Hellwig 17673dcf5451SChristoph Hellwig static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 17683dcf5451SChristoph Hellwig { 17693dcf5451SChristoph Hellwig return ino == EXT4_ROOT_INO || 17703dcf5451SChristoph Hellwig (ino >= EXT4_FIRST_INO(sb) && 17713dcf5451SChristoph Hellwig ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 17723dcf5451SChristoph Hellwig } 177319f5fb7aSTheodore Ts'o 177419f5fb7aSTheodore Ts'o /* 17751d0c3924STheodore Ts'o * Returns: sbi->field[index] 17761d0c3924STheodore Ts'o * Used to access an array element from the following sbi fields which require 17771d0c3924STheodore Ts'o * rcu protection to avoid dereferencing an invalid pointer due to reassignment 17781d0c3924STheodore Ts'o * - s_group_desc 17791d0c3924STheodore Ts'o * - s_group_info 17801d0c3924STheodore Ts'o * - s_flex_group 17811d0c3924STheodore Ts'o */ 17821d0c3924STheodore Ts'o #define sbi_array_rcu_deref(sbi, field, index) \ 17831d0c3924STheodore Ts'o ({ \ 17841d0c3924STheodore Ts'o typeof(*((sbi)->field)) _v; \ 17851d0c3924STheodore Ts'o rcu_read_lock(); \ 17861d0c3924STheodore Ts'o _v = ((typeof(_v)*)rcu_dereference((sbi)->field))[index]; \ 17871d0c3924STheodore Ts'o rcu_read_unlock(); \ 17881d0c3924STheodore Ts'o _v; \ 17891d0c3924STheodore Ts'o }) 17901d0c3924STheodore Ts'o 17911d0c3924STheodore Ts'o /* 17929b5f6c9bSHarshad Shirwadkar * run-time mount flags 17939b5f6c9bSHarshad Shirwadkar */ 17949b5f6c9bSHarshad Shirwadkar enum { 17959b5f6c9bSHarshad Shirwadkar EXT4_MF_MNTDIR_SAMPLED, 17969b5f6c9bSHarshad Shirwadkar EXT4_MF_FS_ABORTED, /* Fatal error detected */ 1797bdc8a53aSXin Yin EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */ 17989b5f6c9bSHarshad Shirwadkar }; 17999b5f6c9bSHarshad Shirwadkar 18009b5f6c9bSHarshad Shirwadkar static inline void ext4_set_mount_flag(struct super_block *sb, int bit) 18019b5f6c9bSHarshad Shirwadkar { 18029b5f6c9bSHarshad Shirwadkar set_bit(bit, &EXT4_SB(sb)->s_mount_flags); 18039b5f6c9bSHarshad Shirwadkar } 18049b5f6c9bSHarshad Shirwadkar 18059b5f6c9bSHarshad Shirwadkar static inline void ext4_clear_mount_flag(struct super_block *sb, int bit) 18069b5f6c9bSHarshad Shirwadkar { 18079b5f6c9bSHarshad Shirwadkar clear_bit(bit, &EXT4_SB(sb)->s_mount_flags); 18089b5f6c9bSHarshad Shirwadkar } 18099b5f6c9bSHarshad Shirwadkar 18109b5f6c9bSHarshad Shirwadkar static inline int ext4_test_mount_flag(struct super_block *sb, int bit) 18119b5f6c9bSHarshad Shirwadkar { 18129b5f6c9bSHarshad Shirwadkar return test_bit(bit, &EXT4_SB(sb)->s_mount_flags); 18139b5f6c9bSHarshad Shirwadkar } 18149b5f6c9bSHarshad Shirwadkar 18159b5f6c9bSHarshad Shirwadkar 18169b5f6c9bSHarshad Shirwadkar /* 181746f870d6STheodore Ts'o * Simulate_fail codes 181846f870d6STheodore Ts'o */ 181946f870d6STheodore Ts'o #define EXT4_SIM_BBITMAP_EIO 1 182046f870d6STheodore Ts'o #define EXT4_SIM_BBITMAP_CRC 2 182146f870d6STheodore Ts'o #define EXT4_SIM_IBITMAP_EIO 3 182246f870d6STheodore Ts'o #define EXT4_SIM_IBITMAP_CRC 4 182346f870d6STheodore Ts'o #define EXT4_SIM_INODE_EIO 5 182446f870d6STheodore Ts'o #define EXT4_SIM_INODE_CRC 6 182546f870d6STheodore Ts'o #define EXT4_SIM_DIRBLOCK_EIO 7 182646f870d6STheodore Ts'o #define EXT4_SIM_DIRBLOCK_CRC 8 182746f870d6STheodore Ts'o 182846f870d6STheodore Ts'o static inline bool ext4_simulate_fail(struct super_block *sb, 182946f870d6STheodore Ts'o unsigned long code) 183046f870d6STheodore Ts'o { 183146f870d6STheodore Ts'o #ifdef CONFIG_EXT4_DEBUG 183246f870d6STheodore Ts'o struct ext4_sb_info *sbi = EXT4_SB(sb); 183346f870d6STheodore Ts'o 183446f870d6STheodore Ts'o if (unlikely(sbi->s_simulate_fail == code)) { 183546f870d6STheodore Ts'o sbi->s_simulate_fail = 0; 183646f870d6STheodore Ts'o return true; 183746f870d6STheodore Ts'o } 183846f870d6STheodore Ts'o #endif 183946f870d6STheodore Ts'o return false; 184046f870d6STheodore Ts'o } 184146f870d6STheodore Ts'o 184246f870d6STheodore Ts'o static inline void ext4_simulate_fail_bh(struct super_block *sb, 184346f870d6STheodore Ts'o struct buffer_head *bh, 184446f870d6STheodore Ts'o unsigned long code) 184546f870d6STheodore Ts'o { 184646f870d6STheodore Ts'o if (!IS_ERR(bh) && ext4_simulate_fail(sb, code)) 184746f870d6STheodore Ts'o clear_buffer_uptodate(bh); 184846f870d6STheodore Ts'o } 184946f870d6STheodore Ts'o 185046f870d6STheodore Ts'o /* 1851878520acSTheodore Ts'o * Error number codes for s_{first,last}_error_errno 1852878520acSTheodore Ts'o * 1853878520acSTheodore Ts'o * Linux errno numbers are architecture specific, so we need to translate 1854878520acSTheodore Ts'o * them into something which is architecture independent. We don't define 1855878520acSTheodore Ts'o * codes for all errno's; just the ones which are most likely to be the cause 1856878520acSTheodore Ts'o * of an ext4_error() call. 1857878520acSTheodore Ts'o */ 1858878520acSTheodore Ts'o #define EXT4_ERR_UNKNOWN 1 1859878520acSTheodore Ts'o #define EXT4_ERR_EIO 2 1860878520acSTheodore Ts'o #define EXT4_ERR_ENOMEM 3 1861878520acSTheodore Ts'o #define EXT4_ERR_EFSBADCRC 4 1862878520acSTheodore Ts'o #define EXT4_ERR_EFSCORRUPTED 5 1863878520acSTheodore Ts'o #define EXT4_ERR_ENOSPC 6 1864878520acSTheodore Ts'o #define EXT4_ERR_ENOKEY 7 1865878520acSTheodore Ts'o #define EXT4_ERR_EROFS 8 1866878520acSTheodore Ts'o #define EXT4_ERR_EFBIG 9 1867878520acSTheodore Ts'o #define EXT4_ERR_EEXIST 10 1868878520acSTheodore Ts'o #define EXT4_ERR_ERANGE 11 1869878520acSTheodore Ts'o #define EXT4_ERR_EOVERFLOW 12 1870878520acSTheodore Ts'o #define EXT4_ERR_EBUSY 13 1871878520acSTheodore Ts'o #define EXT4_ERR_ENOTDIR 14 1872878520acSTheodore Ts'o #define EXT4_ERR_ENOTEMPTY 15 1873878520acSTheodore Ts'o #define EXT4_ERR_ESHUTDOWN 16 1874878520acSTheodore Ts'o #define EXT4_ERR_EFAULT 17 1875878520acSTheodore Ts'o 1876878520acSTheodore Ts'o /* 187719f5fb7aSTheodore Ts'o * Inode dynamic state flags 187819f5fb7aSTheodore Ts'o */ 187919f5fb7aSTheodore Ts'o enum { 188019f5fb7aSTheodore Ts'o EXT4_STATE_JDATA, /* journaled data exists */ 188119f5fb7aSTheodore Ts'o EXT4_STATE_NEW, /* inode is newly created */ 188219f5fb7aSTheodore Ts'o EXT4_STATE_XATTR, /* has in-inode xattrs */ 188319f5fb7aSTheodore Ts'o EXT4_STATE_NO_EXPAND, /* No space for expansion */ 188419f5fb7aSTheodore Ts'o EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */ 188519f5fb7aSTheodore Ts'o EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */ 188614ece102SFrank Mayhar EXT4_STATE_NEWENTRY, /* File just added to dir */ 188767cf5b09STao Ma EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ 18887869a4a6STheodore Ts'o EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ 1889a6d05676STahsin Erdogan EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ 1890c93d8f88SEric Biggers EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 1891aa75f4d3SHarshad Shirwadkar EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */ 189202f310fcSJan Kara EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */ 189319f5fb7aSTheodore Ts'o }; 189419f5fb7aSTheodore Ts'o 1895353eb83cSTheodore Ts'o #define EXT4_INODE_BIT_FNS(name, field, offset) \ 189612e9b892SDmitry Monakhov static inline int ext4_test_inode_##name(struct inode *inode, int bit) \ 189712e9b892SDmitry Monakhov { \ 1898353eb83cSTheodore Ts'o return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 189912e9b892SDmitry Monakhov } \ 190012e9b892SDmitry Monakhov static inline void ext4_set_inode_##name(struct inode *inode, int bit) \ 190112e9b892SDmitry Monakhov { \ 1902353eb83cSTheodore Ts'o set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 190312e9b892SDmitry Monakhov } \ 190412e9b892SDmitry Monakhov static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ 190512e9b892SDmitry Monakhov { \ 1906353eb83cSTheodore Ts'o clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 190719f5fb7aSTheodore Ts'o } 190819f5fb7aSTheodore Ts'o 19093f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 19103f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 19113f61c0ccSAndreas Dilger static inline int ext4_test_inode_flag(struct inode *inode, int bit); 19123f61c0ccSAndreas Dilger static inline void ext4_set_inode_flag(struct inode *inode, int bit); 19133f61c0ccSAndreas Dilger static inline void ext4_clear_inode_flag(struct inode *inode, int bit); 1914353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(flag, flags, 0) 19153f61c0ccSAndreas Dilger 19163f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 19173f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 19183f61c0ccSAndreas Dilger static inline int ext4_test_inode_state(struct inode *inode, int bit); 19193f61c0ccSAndreas Dilger static inline void ext4_set_inode_state(struct inode *inode, int bit); 19203f61c0ccSAndreas Dilger static inline void ext4_clear_inode_state(struct inode *inode, int bit); 1921353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 1922353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, state_flags, 0) 1923353eb83cSTheodore Ts'o 1924353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1925353eb83cSTheodore Ts'o { 1926353eb83cSTheodore Ts'o (ei)->i_state_flags = 0; 1927353eb83cSTheodore Ts'o } 1928353eb83cSTheodore Ts'o #else 1929353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, flags, 32) 1930353eb83cSTheodore Ts'o 1931353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1932353eb83cSTheodore Ts'o { 1933353eb83cSTheodore Ts'o /* We depend on the fact that callers will set i_flags */ 1934353eb83cSTheodore Ts'o } 1935353eb83cSTheodore Ts'o #endif 19363dcf5451SChristoph Hellwig #else 19373dcf5451SChristoph Hellwig /* Assume that user mode programs are passing in an ext4fs superblock, not 19383dcf5451SChristoph Hellwig * a kernel struct super_block. This will allow us to call the feature-test 19393dcf5451SChristoph Hellwig * macros from user land. */ 19403dcf5451SChristoph Hellwig #define EXT4_SB(sb) (sb) 19413dcf5451SChristoph Hellwig #endif 19423dcf5451SChristoph Hellwig 1943c93d8f88SEric Biggers static inline bool ext4_verity_in_progress(struct inode *inode) 1944c93d8f88SEric Biggers { 1945c93d8f88SEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 1946c93d8f88SEric Biggers ext4_test_inode_state(inode, EXT4_STATE_VERITY_IN_PROGRESS); 1947c93d8f88SEric Biggers } 1948c93d8f88SEric Biggers 19493dcf5451SChristoph Hellwig #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime 19503dcf5451SChristoph Hellwig 19513dcf5451SChristoph Hellwig /* 19523dcf5451SChristoph Hellwig * Codes for operating systems 19533dcf5451SChristoph Hellwig */ 19543dcf5451SChristoph Hellwig #define EXT4_OS_LINUX 0 19553dcf5451SChristoph Hellwig #define EXT4_OS_HURD 1 19563dcf5451SChristoph Hellwig #define EXT4_OS_MASIX 2 19573dcf5451SChristoph Hellwig #define EXT4_OS_FREEBSD 3 19583dcf5451SChristoph Hellwig #define EXT4_OS_LITES 4 19593dcf5451SChristoph Hellwig 19603dcf5451SChristoph Hellwig /* 19613dcf5451SChristoph Hellwig * Revision levels 19623dcf5451SChristoph Hellwig */ 19633dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */ 19643dcf5451SChristoph Hellwig #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 19653dcf5451SChristoph Hellwig 19663dcf5451SChristoph Hellwig #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV 19673dcf5451SChristoph Hellwig 19683dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_INODE_SIZE 128 19693dcf5451SChristoph Hellwig 19704881c497SDeepa Dinamani #define EXT4_EXTRA_TIMESTAMP_MAX (((s64)1 << 34) - 1 + S32_MIN) 19714881c497SDeepa Dinamani #define EXT4_NON_EXTRA_TIMESTAMP_MAX S32_MAX 19724881c497SDeepa Dinamani #define EXT4_TIMESTAMP_MIN S32_MIN 19734881c497SDeepa Dinamani 19743dcf5451SChristoph Hellwig /* 19753dcf5451SChristoph Hellwig * Feature set definitions 19763dcf5451SChristoph Hellwig */ 19773dcf5451SChristoph Hellwig 19783dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 19793dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002 19803dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 19813dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008 19823dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010 19833dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 19841beeef1bSDarrick J. Wong #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 1985a44ad683SHarshad Shirwadkar /* 1986a44ad683SHarshad Shirwadkar * The reason why "FAST_COMMIT" is a compat feature is that, FS becomes 1987a44ad683SHarshad Shirwadkar * incompatible only if fast commit blocks are present in the FS. Since we 1988a44ad683SHarshad Shirwadkar * clear the journal (and thus the fast commit blocks), we don't mark FS as 1989a44ad683SHarshad Shirwadkar * incompatible. We also have a JBD2 incompat feature, which gets set when 1990a44ad683SHarshad Shirwadkar * there are fast commit blocks present in the journal. 1991a44ad683SHarshad Shirwadkar */ 1992995a3ed6SHarshad Shirwadkar #define EXT4_FEATURE_COMPAT_FAST_COMMIT 0x0400 1993b925acb8SEric Biggers #define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800 199402f310fcSJan Kara #define EXT4_FEATURE_COMPAT_ORPHAN_FILE 0x1000 /* Orphan file exists */ 19953dcf5451SChristoph Hellwig 19963dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 19973dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 19983dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 19993dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 20003dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 20013dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 20023dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 2003ae812306SAditya Kali #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 2004281b5995STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 2005e6153918SDarrick J. Wong /* 2006e6153918SDarrick J. Wong * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When 2007e6153918SDarrick J. Wong * METADATA_CSUM is set, group descriptor checksums use the same algorithm as 2008e6153918SDarrick J. Wong * all other data structures' checksums. However, the METADATA_CSUM and 2009e6153918SDarrick J. Wong * GDT_CSUM bits are mutually exclusive. 2010e6153918SDarrick J. Wong */ 20119b90e5e0STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 20122cb5cc8bSDarrick J. Wong #define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000 20138b4953e1STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_PROJECT 0x2000 2014c93d8f88SEric Biggers #define EXT4_FEATURE_RO_COMPAT_VERITY 0x8000 201502f310fcSJan Kara #define EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT 0x10000 /* Orphan file may be 201602f310fcSJan Kara non-empty */ 20173dcf5451SChristoph Hellwig 20183dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 20193dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 20203dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 20213dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 20223dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010 20233dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ 20243dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 20253dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 20263dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 2027f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */ 2028f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */ 20298c81bd8fSDarrick J. Wong #define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 20309b90e5e0STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ 203167cf5b09STao Ma #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */ 20323edc18d8STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 2033c83ad55eSGabriel Krisman Bertazi #define EXT4_FEATURE_INCOMPAT_CASEFOLD 0x20000 20343dcf5451SChristoph Hellwig 2035c9e716ebSAndreas Dilger extern void ext4_update_dynamic_rev(struct super_block *sb); 2036c9e716ebSAndreas Dilger 2037e2b911c5SDarrick J. Wong #define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \ 2038e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 2039e2b911c5SDarrick J. Wong { \ 2040e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 2041e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname)) != 0); \ 2042e2b911c5SDarrick J. Wong } \ 2043e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 2044e2b911c5SDarrick J. Wong { \ 2045c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 2046e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_compat |= \ 2047e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 2048e2b911c5SDarrick J. Wong } \ 2049e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 2050e2b911c5SDarrick J. Wong { \ 2051e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_compat &= \ 2052e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \ 2053e2b911c5SDarrick J. Wong } 2054e2b911c5SDarrick J. Wong 2055e2b911c5SDarrick J. Wong #define EXT4_FEATURE_RO_COMPAT_FUNCS(name, flagname) \ 2056e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 2057e2b911c5SDarrick J. Wong { \ 2058e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 2059e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname)) != 0); \ 2060e2b911c5SDarrick J. Wong } \ 2061e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 2062e2b911c5SDarrick J. Wong { \ 2063c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 2064e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_ro_compat |= \ 2065e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 2066e2b911c5SDarrick J. Wong } \ 2067e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 2068e2b911c5SDarrick J. Wong { \ 2069e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_ro_compat &= \ 2070e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \ 2071e2b911c5SDarrick J. Wong } 2072e2b911c5SDarrick J. Wong 2073e2b911c5SDarrick J. Wong #define EXT4_FEATURE_INCOMPAT_FUNCS(name, flagname) \ 2074e2b911c5SDarrick J. Wong static inline bool ext4_has_feature_##name(struct super_block *sb) \ 2075e2b911c5SDarrick J. Wong { \ 2076e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 2077e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname)) != 0); \ 2078e2b911c5SDarrick J. Wong } \ 2079e2b911c5SDarrick J. Wong static inline void ext4_set_feature_##name(struct super_block *sb) \ 2080e2b911c5SDarrick J. Wong { \ 2081c9e716ebSAndreas Dilger ext4_update_dynamic_rev(sb); \ 2082e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_incompat |= \ 2083e2b911c5SDarrick J. Wong cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 2084e2b911c5SDarrick J. Wong } \ 2085e2b911c5SDarrick J. Wong static inline void ext4_clear_feature_##name(struct super_block *sb) \ 2086e2b911c5SDarrick J. Wong { \ 2087e2b911c5SDarrick J. Wong EXT4_SB(sb)->s_es->s_feature_incompat &= \ 2088e2b911c5SDarrick J. Wong ~cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \ 2089e2b911c5SDarrick J. Wong } 2090e2b911c5SDarrick J. Wong 2091e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(dir_prealloc, DIR_PREALLOC) 2092e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(imagic_inodes, IMAGIC_INODES) 2093e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(journal, HAS_JOURNAL) 2094e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(xattr, EXT_ATTR) 2095e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE) 2096e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX) 2097e2b911c5SDarrick J. Wong EXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2) 2098995a3ed6SHarshad Shirwadkar EXT4_FEATURE_COMPAT_FUNCS(fast_commit, FAST_COMMIT) 2099b925acb8SEric Biggers EXT4_FEATURE_COMPAT_FUNCS(stable_inodes, STABLE_INODES) 210002f310fcSJan Kara EXT4_FEATURE_COMPAT_FUNCS(orphan_file, ORPHAN_FILE) 2101e2b911c5SDarrick J. Wong 2102e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(sparse_super, SPARSE_SUPER) 2103e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(large_file, LARGE_FILE) 2104e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(btree_dir, BTREE_DIR) 2105e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(huge_file, HUGE_FILE) 2106e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(gdt_csum, GDT_CSUM) 2107e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(dir_nlink, DIR_NLINK) 2108e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(extra_isize, EXTRA_ISIZE) 2109e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(quota, QUOTA) 2110e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(bigalloc, BIGALLOC) 2111e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(metadata_csum, METADATA_CSUM) 2112e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(readonly, READONLY) 2113e2b911c5SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_FUNCS(project, PROJECT) 2114c93d8f88SEric Biggers EXT4_FEATURE_RO_COMPAT_FUNCS(verity, VERITY) 211502f310fcSJan Kara EXT4_FEATURE_RO_COMPAT_FUNCS(orphan_present, ORPHAN_PRESENT) 2116e2b911c5SDarrick J. Wong 2117e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(compression, COMPRESSION) 2118e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(filetype, FILETYPE) 2119e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(journal_needs_recovery, RECOVER) 2120e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(journal_dev, JOURNAL_DEV) 2121e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(meta_bg, META_BG) 2122e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(extents, EXTENTS) 2123e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT) 2124e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(mmp, MMP) 2125e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(flex_bg, FLEX_BG) 2126e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(ea_inode, EA_INODE) 2127e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(dirdata, DIRDATA) 2128e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(csum_seed, CSUM_SEED) 2129e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(largedir, LARGEDIR) 2130e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(inline_data, INLINE_DATA) 2131e2b911c5SDarrick J. Wong EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, ENCRYPT) 2132c83ad55eSGabriel Krisman Bertazi EXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD) 2133e2b911c5SDarrick J. Wong 21342035e776STheodore Ts'o #define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 21352035e776STheodore Ts'o #define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 21362035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 21372035e776STheodore Ts'o #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 21382035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 21392035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 21402035e776STheodore Ts'o 21412035e776STheodore Ts'o #define EXT3_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 21422035e776STheodore Ts'o #define EXT3_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 21432035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_RECOVER| \ 21442035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 21452035e776STheodore Ts'o #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 21462035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 21472035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 21482035e776STheodore Ts'o 214902f310fcSJan Kara #define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_EXT_ATTR| \ 215002f310fcSJan Kara EXT4_FEATURE_COMPAT_ORPHAN_FILE) 21513dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 21523dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_RECOVER| \ 21533dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_META_BG| \ 21543dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_EXTENTS| \ 21553dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_64BIT| \ 2156c5e06d10SJohann Lombardi EXT4_FEATURE_INCOMPAT_FLEX_BG| \ 2157e50e5129SAndreas Dilger EXT4_FEATURE_INCOMPAT_EA_INODE| \ 2158f08225d1STao Ma EXT4_FEATURE_INCOMPAT_MMP | \ 21596ddb2447STheodore Ts'o EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ 21608c81bd8fSDarrick J. Wong EXT4_FEATURE_INCOMPAT_ENCRYPT | \ 2161c83ad55eSGabriel Krisman Bertazi EXT4_FEATURE_INCOMPAT_CASEFOLD | \ 2162e08ac99fSArtem Blagodarenko EXT4_FEATURE_INCOMPAT_CSUM_SEED | \ 2163e08ac99fSArtem Blagodarenko EXT4_FEATURE_INCOMPAT_LARGEDIR) 21643dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 21653dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 21663dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ 21673dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ 21683dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 21693dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 21706f16b606STheodore Ts'o EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\ 2171e93376c2SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_BIGALLOC |\ 21727c319d32SAditya Kali EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\ 2173040cb378SLi Xi EXT4_FEATURE_RO_COMPAT_QUOTA |\ 2174c93d8f88SEric Biggers EXT4_FEATURE_RO_COMPAT_PROJECT |\ 217502f310fcSJan Kara EXT4_FEATURE_RO_COMPAT_VERITY |\ 217602f310fcSJan Kara EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT) 21773dcf5451SChristoph Hellwig 2178e2b911c5SDarrick J. Wong #define EXTN_FEATURE_FUNCS(ver) \ 2179e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_compat_features(struct super_block *sb) \ 2180e2b911c5SDarrick J. Wong { \ 2181e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_compat & \ 2182e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_COMPAT_SUPP)) != 0); \ 2183e2b911c5SDarrick J. Wong } \ 2184e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_ro_compat_features(struct super_block *sb) \ 2185e2b911c5SDarrick J. Wong { \ 2186e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_ro_compat & \ 2187e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_RO_COMPAT_SUPP)) != 0); \ 2188e2b911c5SDarrick J. Wong } \ 2189e2b911c5SDarrick J. Wong static inline bool ext4_has_unknown_ext##ver##_incompat_features(struct super_block *sb) \ 2190e2b911c5SDarrick J. Wong { \ 2191e2b911c5SDarrick J. Wong return ((EXT4_SB(sb)->s_es->s_feature_incompat & \ 2192e2b911c5SDarrick J. Wong cpu_to_le32(~EXT##ver##_FEATURE_INCOMPAT_SUPP)) != 0); \ 2193e2b911c5SDarrick J. Wong } 2194e2b911c5SDarrick J. Wong 2195e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(2) 2196e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(3) 2197e2b911c5SDarrick J. Wong EXTN_FEATURE_FUNCS(4) 2198e2b911c5SDarrick J. Wong 2199e2b911c5SDarrick J. Wong static inline bool ext4_has_compat_features(struct super_block *sb) 2200e2b911c5SDarrick J. Wong { 2201e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_compat != 0); 2202e2b911c5SDarrick J. Wong } 2203e2b911c5SDarrick J. Wong static inline bool ext4_has_ro_compat_features(struct super_block *sb) 2204e2b911c5SDarrick J. Wong { 2205e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_ro_compat != 0); 2206e2b911c5SDarrick J. Wong } 2207e2b911c5SDarrick J. Wong static inline bool ext4_has_incompat_features(struct super_block *sb) 2208e2b911c5SDarrick J. Wong { 2209e2b911c5SDarrick J. Wong return (EXT4_SB(sb)->s_es->s_feature_incompat != 0); 2210e2b911c5SDarrick J. Wong } 2211e2b911c5SDarrick J. Wong 221225c6d98fSJan Kara extern int ext4_feature_set_ok(struct super_block *sb, int readonly); 221325c6d98fSJan Kara 22143dcf5451SChristoph Hellwig /* 22159549a168STheodore Ts'o * Superblock flags 22169549a168STheodore Ts'o */ 22179549a168STheodore Ts'o #define EXT4_FLAGS_RESIZING 0 22180db1ff22STheodore Ts'o #define EXT4_FLAGS_SHUTDOWN 1 2219a8ab6d38SIra Weiny #define EXT4_FLAGS_BDEV_IS_DAX 2 22200db1ff22STheodore Ts'o 22210db1ff22STheodore Ts'o static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi) 22220db1ff22STheodore Ts'o { 22230db1ff22STheodore Ts'o return test_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); 22240db1ff22STheodore Ts'o } 22259549a168STheodore Ts'o 22269549a168STheodore Ts'o /* 22273dcf5451SChristoph Hellwig * Default values for user and/or group using reserved blocks 22283dcf5451SChristoph Hellwig */ 22293dcf5451SChristoph Hellwig #define EXT4_DEF_RESUID 0 22303dcf5451SChristoph Hellwig #define EXT4_DEF_RESGID 0 22313dcf5451SChristoph Hellwig 2232040cb378SLi Xi /* 2233040cb378SLi Xi * Default project ID 2234040cb378SLi Xi */ 2235040cb378SLi Xi #define EXT4_DEF_PROJID 0 2236040cb378SLi Xi 2237240799cdSTheodore Ts'o #define EXT4_DEF_INODE_READAHEAD_BLKS 32 2238240799cdSTheodore Ts'o 22393dcf5451SChristoph Hellwig /* 22403dcf5451SChristoph Hellwig * Default mount options 22413dcf5451SChristoph Hellwig */ 22423dcf5451SChristoph Hellwig #define EXT4_DEFM_DEBUG 0x0001 22433dcf5451SChristoph Hellwig #define EXT4_DEFM_BSDGROUPS 0x0002 22443dcf5451SChristoph Hellwig #define EXT4_DEFM_XATTR_USER 0x0004 22453dcf5451SChristoph Hellwig #define EXT4_DEFM_ACL 0x0008 22463dcf5451SChristoph Hellwig #define EXT4_DEFM_UID16 0x0010 22473dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE 0x0060 22483dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_DATA 0x0020 22493dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_ORDERED 0x0040 22503dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_WBACK 0x0060 22518b67f04aSTheodore Ts'o #define EXT4_DEFM_NOBARRIER 0x0100 22528b67f04aSTheodore Ts'o #define EXT4_DEFM_BLOCK_VALIDITY 0x0200 22538b67f04aSTheodore Ts'o #define EXT4_DEFM_DISCARD 0x0400 22548b67f04aSTheodore Ts'o #define EXT4_DEFM_NODELALLOC 0x0800 22553dcf5451SChristoph Hellwig 22563dcf5451SChristoph Hellwig /* 225730773840STheodore Ts'o * Default journal batch times 225830773840STheodore Ts'o */ 225930773840STheodore Ts'o #define EXT4_DEF_MIN_BATCH_TIME 0 226030773840STheodore Ts'o #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ 226130773840STheodore Ts'o 226230773840STheodore Ts'o /* 2263a4912123STheodore Ts'o * Minimum number of groups in a flexgroup before we separate out 2264a4912123STheodore Ts'o * directories into the first block group of a flexgroup 2265a4912123STheodore Ts'o */ 2266a4912123STheodore Ts'o #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4 2267a4912123STheodore Ts'o 2268a4912123STheodore Ts'o /* 22693dcf5451SChristoph Hellwig * Structure of a directory entry 22703dcf5451SChristoph Hellwig */ 22713dcf5451SChristoph Hellwig #define EXT4_NAME_LEN 255 2272c186f088SYe Bin /* 2273c186f088SYe Bin * Base length of the ext4 directory entry excluding the name length 2274c186f088SYe Bin */ 2275c186f088SYe Bin #define EXT4_BASE_DIR_LEN (sizeof(struct ext4_dir_entry_2) - EXT4_NAME_LEN) 22763dcf5451SChristoph Hellwig 22773dcf5451SChristoph Hellwig struct ext4_dir_entry { 22783dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 22793dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 22803dcf5451SChristoph Hellwig __le16 name_len; /* Name length */ 22813dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 22823dcf5451SChristoph Hellwig }; 22833dcf5451SChristoph Hellwig 2284471fbbeaSDaniel Rosenberg 2285471fbbeaSDaniel Rosenberg /* 2286471fbbeaSDaniel Rosenberg * Encrypted Casefolded entries require saving the hash on disk. This structure 2287471fbbeaSDaniel Rosenberg * followed ext4_dir_entry_2's name[name_len] at the next 4 byte aligned 2288471fbbeaSDaniel Rosenberg * boundary. 2289471fbbeaSDaniel Rosenberg */ 2290471fbbeaSDaniel Rosenberg struct ext4_dir_entry_hash { 2291471fbbeaSDaniel Rosenberg __le32 hash; 2292471fbbeaSDaniel Rosenberg __le32 minor_hash; 2293471fbbeaSDaniel Rosenberg }; 2294471fbbeaSDaniel Rosenberg 22953dcf5451SChristoph Hellwig /* 22963dcf5451SChristoph Hellwig * The new version of the directory entry. Since EXT4 structures are 22973dcf5451SChristoph Hellwig * stored in intel byte order, and the name_len field could never be 22983dcf5451SChristoph Hellwig * bigger than 255 chars, it's safe to reclaim the extra byte for the 22993dcf5451SChristoph Hellwig * file_type field. 23003dcf5451SChristoph Hellwig */ 23013dcf5451SChristoph Hellwig struct ext4_dir_entry_2 { 23023dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 23033dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 23043dcf5451SChristoph Hellwig __u8 name_len; /* Name length */ 23059f364e1dSJonathan Grant __u8 file_type; /* See file type macros EXT4_FT_* below */ 23063dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 23073dcf5451SChristoph Hellwig }; 23083dcf5451SChristoph Hellwig 23093dcf5451SChristoph Hellwig /* 2310471fbbeaSDaniel Rosenberg * Access the hashes at the end of ext4_dir_entry_2 2311471fbbeaSDaniel Rosenberg */ 2312471fbbeaSDaniel Rosenberg #define EXT4_DIRENT_HASHES(entry) \ 2313471fbbeaSDaniel Rosenberg ((struct ext4_dir_entry_hash *) \ 2314471fbbeaSDaniel Rosenberg (((void *)(entry)) + \ 2315471fbbeaSDaniel Rosenberg ((8 + (entry)->name_len + EXT4_DIR_ROUND) & ~EXT4_DIR_ROUND))) 2316471fbbeaSDaniel Rosenberg #define EXT4_DIRENT_HASH(entry) le32_to_cpu(EXT4_DIRENT_HASHES(de)->hash) 2317471fbbeaSDaniel Rosenberg #define EXT4_DIRENT_MINOR_HASH(entry) \ 2318471fbbeaSDaniel Rosenberg le32_to_cpu(EXT4_DIRENT_HASHES(de)->minor_hash) 2319471fbbeaSDaniel Rosenberg 2320471fbbeaSDaniel Rosenberg static inline bool ext4_hash_in_dirent(const struct inode *inode) 2321471fbbeaSDaniel Rosenberg { 2322471fbbeaSDaniel Rosenberg return IS_CASEFOLDED(inode) && IS_ENCRYPTED(inode); 2323471fbbeaSDaniel Rosenberg } 2324471fbbeaSDaniel Rosenberg 2325471fbbeaSDaniel Rosenberg /* 2326e6153918SDarrick J. Wong * This is a bogus directory entry at the end of each leaf block that 2327e6153918SDarrick J. Wong * records checksums. 2328e6153918SDarrick J. Wong */ 2329e6153918SDarrick J. Wong struct ext4_dir_entry_tail { 2330e6153918SDarrick J. Wong __le32 det_reserved_zero1; /* Pretend to be unused */ 2331e6153918SDarrick J. Wong __le16 det_rec_len; /* 12 */ 2332e6153918SDarrick J. Wong __u8 det_reserved_zero2; /* Zero name length */ 2333e6153918SDarrick J. Wong __u8 det_reserved_ft; /* 0xDE, fake file type */ 2334e6153918SDarrick J. Wong __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */ 2335e6153918SDarrick J. Wong }; 2336e6153918SDarrick J. Wong 23373c47d541STao Ma #define EXT4_DIRENT_TAIL(block, blocksize) \ 23383c47d541STao Ma ((struct ext4_dir_entry_tail *)(((void *)(block)) + \ 23393c47d541STao Ma ((blocksize) - \ 23403c47d541STao Ma sizeof(struct ext4_dir_entry_tail)))) 23413c47d541STao Ma 2342e6153918SDarrick J. Wong /* 23433dcf5451SChristoph Hellwig * Ext4 directory file types. Only the low 3 bits are used. The 23443dcf5451SChristoph Hellwig * other bits are reserved for now. 23453dcf5451SChristoph Hellwig */ 23463dcf5451SChristoph Hellwig #define EXT4_FT_UNKNOWN 0 23473dcf5451SChristoph Hellwig #define EXT4_FT_REG_FILE 1 23483dcf5451SChristoph Hellwig #define EXT4_FT_DIR 2 23493dcf5451SChristoph Hellwig #define EXT4_FT_CHRDEV 3 23503dcf5451SChristoph Hellwig #define EXT4_FT_BLKDEV 4 23513dcf5451SChristoph Hellwig #define EXT4_FT_FIFO 5 23523dcf5451SChristoph Hellwig #define EXT4_FT_SOCK 6 23533dcf5451SChristoph Hellwig #define EXT4_FT_SYMLINK 7 23543dcf5451SChristoph Hellwig 23553dcf5451SChristoph Hellwig #define EXT4_FT_MAX 8 23563dcf5451SChristoph Hellwig 2357e6153918SDarrick J. Wong #define EXT4_FT_DIR_CSUM 0xDE 2358e6153918SDarrick J. Wong 23593dcf5451SChristoph Hellwig /* 23603dcf5451SChristoph Hellwig * EXT4_DIR_PAD defines the directory entries boundaries 23613dcf5451SChristoph Hellwig * 23623dcf5451SChristoph Hellwig * NOTE: It must be a multiple of 4 23633dcf5451SChristoph Hellwig */ 23643dcf5451SChristoph Hellwig #define EXT4_DIR_PAD 4 23653dcf5451SChristoph Hellwig #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1) 23663dcf5451SChristoph Hellwig #define EXT4_MAX_REC_LEN ((1<<16)-1) 23673dcf5451SChristoph Hellwig 23683dcf5451SChristoph Hellwig /* 2369471fbbeaSDaniel Rosenberg * The rec_len is dependent on the type of directory. Directories that are 2370471fbbeaSDaniel Rosenberg * casefolded and encrypted need to store the hash as well, so we add room for 2371471fbbeaSDaniel Rosenberg * ext4_extended_dir_entry_2. For all entries related to '.' or '..' you should 2372471fbbeaSDaniel Rosenberg * pass NULL for dir, as those entries do not use the extra fields. 2373471fbbeaSDaniel Rosenberg */ 2374471fbbeaSDaniel Rosenberg static inline unsigned int ext4_dir_rec_len(__u8 name_len, 2375471fbbeaSDaniel Rosenberg const struct inode *dir) 2376471fbbeaSDaniel Rosenberg { 2377471fbbeaSDaniel Rosenberg int rec_len = (name_len + 8 + EXT4_DIR_ROUND); 2378471fbbeaSDaniel Rosenberg 2379471fbbeaSDaniel Rosenberg if (dir && ext4_hash_in_dirent(dir)) 2380471fbbeaSDaniel Rosenberg rec_len += sizeof(struct ext4_dir_entry_hash); 2381471fbbeaSDaniel Rosenberg return (rec_len & ~EXT4_DIR_ROUND); 2382471fbbeaSDaniel Rosenberg } 2383471fbbeaSDaniel Rosenberg 2384471fbbeaSDaniel Rosenberg /* 23850cfc9255SEric Sandeen * If we ever get support for fs block sizes > page_size, we'll need 23860cfc9255SEric Sandeen * to remove the #if statements in the next two functions... 23870cfc9255SEric Sandeen */ 23880cfc9255SEric Sandeen static inline unsigned int 23890cfc9255SEric Sandeen ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) 23900cfc9255SEric Sandeen { 23910cfc9255SEric Sandeen unsigned len = le16_to_cpu(dlen); 23920cfc9255SEric Sandeen 2393ea1754a0SKirill A. Shutemov #if (PAGE_SIZE >= 65536) 23940cfc9255SEric Sandeen if (len == EXT4_MAX_REC_LEN || len == 0) 23950cfc9255SEric Sandeen return blocksize; 23960cfc9255SEric Sandeen return (len & 65532) | ((len & 3) << 16); 23970cfc9255SEric Sandeen #else 23980cfc9255SEric Sandeen return len; 23990cfc9255SEric Sandeen #endif 24000cfc9255SEric Sandeen } 24010cfc9255SEric Sandeen 24020cfc9255SEric Sandeen static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) 24030cfc9255SEric Sandeen { 2404a2e3965dSxu xin BUG_ON((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)); 2405ea1754a0SKirill A. Shutemov #if (PAGE_SIZE >= 65536) 24060cfc9255SEric Sandeen if (len < 65536) 24070cfc9255SEric Sandeen return cpu_to_le16(len); 24080cfc9255SEric Sandeen if (len == blocksize) { 24090cfc9255SEric Sandeen if (blocksize == 65536) 24100cfc9255SEric Sandeen return cpu_to_le16(EXT4_MAX_REC_LEN); 24110cfc9255SEric Sandeen else 24120cfc9255SEric Sandeen return cpu_to_le16(0); 24130cfc9255SEric Sandeen } 24140cfc9255SEric Sandeen return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); 24150cfc9255SEric Sandeen #else 24160cfc9255SEric Sandeen return cpu_to_le16(len); 24170cfc9255SEric Sandeen #endif 24180cfc9255SEric Sandeen } 24190cfc9255SEric Sandeen 24200cfc9255SEric Sandeen /* 24213dcf5451SChristoph Hellwig * Hash Tree Directory indexing 24223dcf5451SChristoph Hellwig * (c) Daniel Phillips, 2001 24233dcf5451SChristoph Hellwig */ 24243dcf5451SChristoph Hellwig 2425e2b911c5SDarrick J. Wong #define is_dx(dir) (ext4_has_feature_dir_index((dir)->i_sb) && \ 242612e9b892SDmitry Monakhov ext4_test_inode_flag((dir), EXT4_INODE_INDEX)) 2427c7414892SAndreas Dilger #define EXT4_DIR_LINK_MAX(dir) unlikely((dir)->i_nlink >= EXT4_LINK_MAX && \ 2428c7414892SAndreas Dilger !(ext4_has_feature_dir_nlink((dir)->i_sb) && is_dx(dir))) 24293dcf5451SChristoph Hellwig #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 24303dcf5451SChristoph Hellwig 24313dcf5451SChristoph Hellwig /* Legal values for the dx_root hash_version field: */ 24323dcf5451SChristoph Hellwig 24333dcf5451SChristoph Hellwig #define DX_HASH_LEGACY 0 24343dcf5451SChristoph Hellwig #define DX_HASH_HALF_MD4 1 24353dcf5451SChristoph Hellwig #define DX_HASH_TEA 2 2436f99b2589STheodore Ts'o #define DX_HASH_LEGACY_UNSIGNED 3 2437f99b2589STheodore Ts'o #define DX_HASH_HALF_MD4_UNSIGNED 4 2438f99b2589STheodore Ts'o #define DX_HASH_TEA_UNSIGNED 5 2439471fbbeaSDaniel Rosenberg #define DX_HASH_SIPHASH 6 24403dcf5451SChristoph Hellwig 24410441984aSDarrick J. Wong static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc, 24420441984aSDarrick J. Wong const void *address, unsigned int length) 24430441984aSDarrick J. Wong { 24440441984aSDarrick J. Wong struct { 24450441984aSDarrick J. Wong struct shash_desc shash; 24463108b54bSTheodore Ts'o char ctx[4]; 24470441984aSDarrick J. Wong } desc; 24480441984aSDarrick J. Wong 24493108b54bSTheodore Ts'o BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx)); 24503108b54bSTheodore Ts'o 24510441984aSDarrick J. Wong desc.shash.tfm = sbi->s_chksum_driver; 24520441984aSDarrick J. Wong *(u32 *)desc.ctx = crc; 24530441984aSDarrick J. Wong 2454e7093f0dSPetros Koutoupis BUG_ON(crypto_shash_update(&desc.shash, address, length)); 24550441984aSDarrick J. Wong 24560441984aSDarrick J. Wong return *(u32 *)desc.ctx; 24570441984aSDarrick J. Wong } 24580441984aSDarrick J. Wong 24593dcf5451SChristoph Hellwig #ifdef __KERNEL__ 24603dcf5451SChristoph Hellwig 24613dcf5451SChristoph Hellwig /* hash info structure used by the directory hash */ 24623dcf5451SChristoph Hellwig struct dx_hash_info 24633dcf5451SChristoph Hellwig { 24643dcf5451SChristoph Hellwig u32 hash; 24653dcf5451SChristoph Hellwig u32 minor_hash; 24663dcf5451SChristoph Hellwig int hash_version; 24673dcf5451SChristoph Hellwig u32 *seed; 24683dcf5451SChristoph Hellwig }; 24693dcf5451SChristoph Hellwig 2470d1f5273eSFan Yong 2471d1f5273eSFan Yong /* 32 and 64 bit signed EOF for dx directories */ 2472d1f5273eSFan Yong #define EXT4_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1) 2473d1f5273eSFan Yong #define EXT4_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1) 2474d1f5273eSFan Yong 24753dcf5451SChristoph Hellwig 24763dcf5451SChristoph Hellwig /* 24773dcf5451SChristoph Hellwig * Control parameters used by ext4_htree_next_block 24783dcf5451SChristoph Hellwig */ 24793dcf5451SChristoph Hellwig #define HASH_NB_ALWAYS 1 24803dcf5451SChristoph Hellwig 24815b643f9cSTheodore Ts'o struct ext4_filename { 24825b643f9cSTheodore Ts'o const struct qstr *usr_fname; 2483a7550b30SJaegeuk Kim struct fscrypt_str disk_name; 24845b643f9cSTheodore Ts'o struct dx_hash_info hinfo; 2485643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 2486a7550b30SJaegeuk Kim struct fscrypt_str crypto_buf; 24875b643f9cSTheodore Ts'o #endif 24885298d4bfSChristoph Hellwig #if IS_ENABLED(CONFIG_UNICODE) 24893ae72562SGabriel Krisman Bertazi struct fscrypt_str cf_name; 24903ae72562SGabriel Krisman Bertazi #endif 24915b643f9cSTheodore Ts'o }; 24925b643f9cSTheodore Ts'o 24935b643f9cSTheodore Ts'o #define fname_name(p) ((p)->disk_name.name) 2494471fbbeaSDaniel Rosenberg #define fname_usr_name(p) ((p)->usr_fname->name) 24955b643f9cSTheodore Ts'o #define fname_len(p) ((p)->disk_name.len) 24963dcf5451SChristoph Hellwig 24973dcf5451SChristoph Hellwig /* 24983dcf5451SChristoph Hellwig * Describe an inode's exact location on disk and in memory 24993dcf5451SChristoph Hellwig */ 25003dcf5451SChristoph Hellwig struct ext4_iloc 25013dcf5451SChristoph Hellwig { 25023dcf5451SChristoph Hellwig struct buffer_head *bh; 25033dcf5451SChristoph Hellwig unsigned long offset; 25043dcf5451SChristoph Hellwig ext4_group_t block_group; 25053dcf5451SChristoph Hellwig }; 25063dcf5451SChristoph Hellwig 25073dcf5451SChristoph Hellwig static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc) 25083dcf5451SChristoph Hellwig { 25093dcf5451SChristoph Hellwig return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); 25103dcf5451SChristoph Hellwig } 25113dcf5451SChristoph Hellwig 2512dec214d0STahsin Erdogan static inline bool ext4_is_quota_file(struct inode *inode) 2513dec214d0STahsin Erdogan { 2514dec214d0STahsin Erdogan return IS_NOQUOTA(inode) && 2515dec214d0STahsin Erdogan !(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL); 2516dec214d0STahsin Erdogan } 251702749a4cSTahsin Erdogan 25183dcf5451SChristoph Hellwig /* 25193dcf5451SChristoph Hellwig * This structure is stuffed into the struct file's private_data field 25203dcf5451SChristoph Hellwig * for directories. It is where we put information so that we can do 25213dcf5451SChristoph Hellwig * readdir operations in hash tree order. 25223dcf5451SChristoph Hellwig */ 25233dcf5451SChristoph Hellwig struct dir_private_info { 25243dcf5451SChristoph Hellwig struct rb_root root; 25253dcf5451SChristoph Hellwig struct rb_node *curr_node; 25263dcf5451SChristoph Hellwig struct fname *extra_fname; 25273dcf5451SChristoph Hellwig loff_t last_pos; 25283dcf5451SChristoph Hellwig __u32 curr_hash; 25293dcf5451SChristoph Hellwig __u32 curr_minor_hash; 25303dcf5451SChristoph Hellwig __u32 next_hash; 25313dcf5451SChristoph Hellwig }; 25323dcf5451SChristoph Hellwig 25333dcf5451SChristoph Hellwig /* calculate the first block number of the group */ 25343dcf5451SChristoph Hellwig static inline ext4_fsblk_t 25353dcf5451SChristoph Hellwig ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no) 25363dcf5451SChristoph Hellwig { 25373dcf5451SChristoph Hellwig return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + 25383dcf5451SChristoph Hellwig le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 25393dcf5451SChristoph Hellwig } 25403dcf5451SChristoph Hellwig 25413dcf5451SChristoph Hellwig /* 25423dcf5451SChristoph Hellwig * Special error return code only used by dx_probe() and its callers. 25433dcf5451SChristoph Hellwig */ 254436de9286STheodore Ts'o #define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1)) 25453dcf5451SChristoph Hellwig 2546e08ac99fSArtem Blagodarenko /* htree levels for ext4 */ 2547e08ac99fSArtem Blagodarenko #define EXT4_HTREE_LEVEL_COMPAT 2 2548e08ac99fSArtem Blagodarenko #define EXT4_HTREE_LEVEL 3 2549e08ac99fSArtem Blagodarenko 2550e08ac99fSArtem Blagodarenko static inline int ext4_dir_htree_level(struct super_block *sb) 2551e08ac99fSArtem Blagodarenko { 2552e08ac99fSArtem Blagodarenko return ext4_has_feature_largedir(sb) ? 2553e08ac99fSArtem Blagodarenko EXT4_HTREE_LEVEL : EXT4_HTREE_LEVEL_COMPAT; 2554e08ac99fSArtem Blagodarenko } 2555e08ac99fSArtem Blagodarenko 25563dcf5451SChristoph Hellwig /* 2557bfff6873SLukas Czerner * Timeout and state flag for lazy initialization inode thread. 2558bfff6873SLukas Czerner */ 2559bfff6873SLukas Czerner #define EXT4_DEF_LI_WAIT_MULT 10 2560bfff6873SLukas Czerner #define EXT4_DEF_LI_MAX_START_DELAY 5 2561bfff6873SLukas Czerner #define EXT4_LAZYINIT_QUIT 0x0001 2562bfff6873SLukas Czerner #define EXT4_LAZYINIT_RUNNING 0x0002 2563bfff6873SLukas Czerner 2564bfff6873SLukas Czerner /* 2565bfff6873SLukas Czerner * Lazy inode table initialization info 2566bfff6873SLukas Czerner */ 2567bfff6873SLukas Czerner struct ext4_lazy_init { 2568bfff6873SLukas Czerner unsigned long li_state; 2569bfff6873SLukas Czerner struct list_head li_request_list; 2570bfff6873SLukas Czerner struct mutex li_list_mtx; 2571bfff6873SLukas Czerner }; 2572bfff6873SLukas Czerner 25733d392b26STheodore Ts'o enum ext4_li_mode { 25743d392b26STheodore Ts'o EXT4_LI_MODE_PREFETCH_BBITMAP, 25753d392b26STheodore Ts'o EXT4_LI_MODE_ITABLE, 25763d392b26STheodore Ts'o }; 25773d392b26STheodore Ts'o 2578bfff6873SLukas Czerner struct ext4_li_request { 2579bfff6873SLukas Czerner struct super_block *lr_super; 25803d392b26STheodore Ts'o enum ext4_li_mode lr_mode; 25813d392b26STheodore Ts'o ext4_group_t lr_first_not_zeroed; 2582bfff6873SLukas Czerner ext4_group_t lr_next_group; 2583bfff6873SLukas Czerner struct list_head lr_request; 2584bfff6873SLukas Czerner unsigned long lr_next_sched; 2585bfff6873SLukas Czerner unsigned long lr_timeout; 2586bfff6873SLukas Czerner }; 2587bfff6873SLukas Czerner 2588857ac889SLukas Czerner struct ext4_features { 2589857ac889SLukas Czerner struct kobject f_kobj; 2590857ac889SLukas Czerner struct completion f_kobj_unregister; 2591857ac889SLukas Czerner }; 2592857ac889SLukas Czerner 2593bfff6873SLukas Czerner /* 2594c5e06d10SJohann Lombardi * This structure will be used for multiple mount protection. It will be 2595c5e06d10SJohann Lombardi * written into the block number saved in the s_mmp_block field in the 2596c5e06d10SJohann Lombardi * superblock. Programs that check MMP should assume that if 2597c5e06d10SJohann Lombardi * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe 2598c5e06d10SJohann Lombardi * to use the filesystem, regardless of how old the timestamp is. 2599c5e06d10SJohann Lombardi */ 2600c5e06d10SJohann Lombardi #define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ 2601c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ 2602c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ 2603c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ 2604c5e06d10SJohann Lombardi 2605c5e06d10SJohann Lombardi struct mmp_struct { 2606c5e06d10SJohann Lombardi __le32 mmp_magic; /* Magic number for MMP */ 2607c5e06d10SJohann Lombardi __le32 mmp_seq; /* Sequence no. updated periodically */ 2608c5e06d10SJohann Lombardi 2609c5e06d10SJohann Lombardi /* 2610c5e06d10SJohann Lombardi * mmp_time, mmp_nodename & mmp_bdevname are only used for information 2611c5e06d10SJohann Lombardi * purposes and do not affect the correctness of the algorithm 2612c5e06d10SJohann Lombardi */ 2613c5e06d10SJohann Lombardi __le64 mmp_time; /* Time last updated */ 2614c5e06d10SJohann Lombardi char mmp_nodename[64]; /* Node which last updated MMP block */ 2615c5e06d10SJohann Lombardi char mmp_bdevname[32]; /* Bdev which last updated MMP block */ 2616c5e06d10SJohann Lombardi 2617c5e06d10SJohann Lombardi /* 2618c5e06d10SJohann Lombardi * mmp_check_interval is used to verify if the MMP block has been 2619c5e06d10SJohann Lombardi * updated on the block device. The value is updated based on the 2620c5e06d10SJohann Lombardi * maximum time to write the MMP block during an update cycle. 2621c5e06d10SJohann Lombardi */ 2622c5e06d10SJohann Lombardi __le16 mmp_check_interval; 2623c5e06d10SJohann Lombardi 2624c5e06d10SJohann Lombardi __le16 mmp_pad1; 2625e6153918SDarrick J. Wong __le32 mmp_pad2[226]; 2626e6153918SDarrick J. Wong __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */ 2627c5e06d10SJohann Lombardi }; 2628c5e06d10SJohann Lombardi 2629c5e06d10SJohann Lombardi /* arguments passed to the mmp thread */ 2630c5e06d10SJohann Lombardi struct mmpd_data { 2631c5e06d10SJohann Lombardi struct buffer_head *bh; /* bh from initial read_mmp_block() */ 2632c5e06d10SJohann Lombardi struct super_block *sb; /* super block of the fs */ 2633c5e06d10SJohann Lombardi }; 2634c5e06d10SJohann Lombardi 2635c5e06d10SJohann Lombardi /* 2636c5e06d10SJohann Lombardi * Check interval multiplier 2637c5e06d10SJohann Lombardi * The MMP block is written every update interval and initially checked every 2638c5e06d10SJohann Lombardi * update interval x the multiplier (the value is then adapted based on the 2639c5e06d10SJohann Lombardi * write latency). The reason is that writes can be delayed under load and we 2640c5e06d10SJohann Lombardi * don't want readers to incorrectly assume that the filesystem is no longer 2641c5e06d10SJohann Lombardi * in use. 2642c5e06d10SJohann Lombardi */ 2643c5e06d10SJohann Lombardi #define EXT4_MMP_CHECK_MULT 2UL 2644c5e06d10SJohann Lombardi 2645c5e06d10SJohann Lombardi /* 2646c5e06d10SJohann Lombardi * Minimum interval for MMP checking in seconds. 2647c5e06d10SJohann Lombardi */ 2648c5e06d10SJohann Lombardi #define EXT4_MMP_MIN_CHECK_INTERVAL 5UL 2649c5e06d10SJohann Lombardi 2650c5e06d10SJohann Lombardi /* 2651c5e06d10SJohann Lombardi * Maximum interval for MMP checking in seconds. 2652c5e06d10SJohann Lombardi */ 2653c5e06d10SJohann Lombardi #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL 2654c5e06d10SJohann Lombardi 2655c5e06d10SJohann Lombardi /* 26563dcf5451SChristoph Hellwig * Function prototypes 26573dcf5451SChristoph Hellwig */ 26583dcf5451SChristoph Hellwig 26593dcf5451SChristoph Hellwig /* 26603dcf5451SChristoph Hellwig * Ok, these declarations are also in <linux/kernel.h> but none of the 26613dcf5451SChristoph Hellwig * ext4 source programs needs to include it so they are duplicated here. 26623dcf5451SChristoph Hellwig */ 26633dcf5451SChristoph Hellwig # define NORET_TYPE /**/ 26643dcf5451SChristoph Hellwig # define ATTRIB_NORET __attribute__((noreturn)) 26653dcf5451SChristoph Hellwig # define NORET_AND noreturn, 26663dcf5451SChristoph Hellwig 2667498e5f24STheodore Ts'o /* bitmap.c */ 2668f6fb99caSTheodore Ts'o extern unsigned int ext4_count_free(char *bitmap, unsigned numchars); 266941a246d1SDarrick J. Wong void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 267041a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 267141a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 267241a246d1SDarrick J. Wong int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 267341a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 267441a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 2675fa77dcfaSDarrick J. Wong void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 2676fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 267779f1ba49STao Ma struct buffer_head *bh); 2678fa77dcfaSDarrick J. Wong int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 2679fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 268079f1ba49STao Ma struct buffer_head *bh); 2681498e5f24STheodore Ts'o 26823dcf5451SChristoph Hellwig /* balloc.c */ 2683bd86298eSLukas Czerner extern void ext4_get_group_no_and_offset(struct super_block *sb, 2684bd86298eSLukas Czerner ext4_fsblk_t blocknr, 2685bd86298eSLukas Czerner ext4_group_t *blockgrpp, 2686bd86298eSLukas Czerner ext4_grpblk_t *offsetp); 2687bd86298eSLukas Czerner extern ext4_group_t ext4_get_group_number(struct super_block *sb, 2688bd86298eSLukas Czerner ext4_fsblk_t block); 2689bd86298eSLukas Czerner 26903dcf5451SChristoph Hellwig extern unsigned int ext4_block_group(struct super_block *sb, 26913dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 26923dcf5451SChristoph Hellwig extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb, 26933dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 26943dcf5451SChristoph Hellwig extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group); 26953dcf5451SChristoph Hellwig extern unsigned long ext4_bg_num_gdb(struct super_block *sb, 26963dcf5451SChristoph Hellwig ext4_group_t group); 26977061eba7SAneesh Kumar K.V extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 269855f020dbSAllison Henderson ext4_fsblk_t goal, 269955f020dbSAllison Henderson unsigned int flags, 270055f020dbSAllison Henderson unsigned long *count, 270155f020dbSAllison Henderson int *errp); 2702e7d5f315STheodore Ts'o extern int ext4_claim_free_clusters(struct ext4_sb_info *sbi, 2703e7d5f315STheodore Ts'o s64 nclusters, unsigned int flags); 27045dee5437STheodore Ts'o extern ext4_fsblk_t ext4_count_free_clusters(struct super_block *); 27053dcf5451SChristoph Hellwig extern void ext4_check_blocks_bitmap(struct super_block *); 27063dcf5451SChristoph Hellwig extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 27073dcf5451SChristoph Hellwig ext4_group_t block_group, 27083dcf5451SChristoph Hellwig struct buffer_head ** bh); 27093dcf5451SChristoph Hellwig extern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 2710813e5727STheodore Ts'o 2711813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb, 2712cfd73237SAlex Zhuravlev ext4_group_t block_group, 2713cfd73237SAlex Zhuravlev bool ignore_locked); 2714813e5727STheodore Ts'o extern int ext4_wait_block_bitmap(struct super_block *sb, 2715813e5727STheodore Ts'o ext4_group_t block_group, 2716813e5727STheodore Ts'o struct buffer_head *bh); 2717813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb, 2718bb23c20aSTheodore Ts'o ext4_group_t block_group); 2719cff1dfd7STheodore Ts'o extern unsigned ext4_free_clusters_after_init(struct super_block *sb, 2720fd034a84STheodore Ts'o ext4_group_t block_group, 2721fd034a84STheodore Ts'o struct ext4_group_desc *gdp); 2722f86186b4SEric Sandeen ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); 27233dcf5451SChristoph Hellwig 27245298d4bfSChristoph Hellwig #if IS_ENABLED(CONFIG_UNICODE) 27251ae98e29SDaniel Rosenberg extern int ext4_fname_setup_ci_filename(struct inode *dir, 27263ae72562SGabriel Krisman Bertazi const struct qstr *iname, 27271ae98e29SDaniel Rosenberg struct ext4_filename *fname); 27283ae72562SGabriel Krisman Bertazi #endif 27293ae72562SGabriel Krisman Bertazi 2730b1241c8eSRitesh Harjani /* ext4 encryption related stuff goes here crypto.c */ 2731643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 2732b1241c8eSRitesh Harjani extern const struct fscrypt_operations ext4_cryptops; 2733b1241c8eSRitesh Harjani 27343030b59cSRitesh Harjani int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, 27353030b59cSRitesh Harjani int lookup, struct ext4_filename *fname); 2736b01531dbSEric Biggers 27373030b59cSRitesh Harjani int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, 27383030b59cSRitesh Harjani struct ext4_filename *fname); 2739b01531dbSEric Biggers 27403030b59cSRitesh Harjani void ext4_fname_free_filename(struct ext4_filename *fname); 2741a7550b30SJaegeuk Kim 274272f63f4aSRitesh Harjani int ext4_ioctl_get_encryption_pwsalt(struct file *filp, void __user *arg); 274372f63f4aSRitesh Harjani 2744b01531dbSEric Biggers #else /* !CONFIG_FS_ENCRYPTION */ 27455b643f9cSTheodore Ts'o static inline int ext4_fname_setup_filename(struct inode *dir, 27465b643f9cSTheodore Ts'o const struct qstr *iname, 2747b01531dbSEric Biggers int lookup, 2748b01531dbSEric Biggers struct ext4_filename *fname) 27495b643f9cSTheodore Ts'o { 27501ae98e29SDaniel Rosenberg int err = 0; 27515b643f9cSTheodore Ts'o fname->usr_fname = iname; 27525b643f9cSTheodore Ts'o fname->disk_name.name = (unsigned char *) iname->name; 27535b643f9cSTheodore Ts'o fname->disk_name.len = iname->len; 27543ae72562SGabriel Krisman Bertazi 27555298d4bfSChristoph Hellwig #if IS_ENABLED(CONFIG_UNICODE) 27561ae98e29SDaniel Rosenberg err = ext4_fname_setup_ci_filename(dir, iname, fname); 27573ae72562SGabriel Krisman Bertazi #endif 27583ae72562SGabriel Krisman Bertazi 27591ae98e29SDaniel Rosenberg return err; 27605b643f9cSTheodore Ts'o } 2761a7550b30SJaegeuk Kim 2762b01531dbSEric Biggers static inline int ext4_fname_prepare_lookup(struct inode *dir, 2763b01531dbSEric Biggers struct dentry *dentry, 2764b01531dbSEric Biggers struct ext4_filename *fname) 2765b01531dbSEric Biggers { 2766b01531dbSEric Biggers return ext4_fname_setup_filename(dir, &dentry->d_name, 1, fname); 2767b01531dbSEric Biggers } 2768b01531dbSEric Biggers 27693ae72562SGabriel Krisman Bertazi static inline void ext4_fname_free_filename(struct ext4_filename *fname) 27703ae72562SGabriel Krisman Bertazi { 27715298d4bfSChristoph Hellwig #if IS_ENABLED(CONFIG_UNICODE) 27723ae72562SGabriel Krisman Bertazi kfree(fname->cf_name.name); 27733ae72562SGabriel Krisman Bertazi fname->cf_name.name = NULL; 27743ae72562SGabriel Krisman Bertazi #endif 27753ae72562SGabriel Krisman Bertazi } 277672f63f4aSRitesh Harjani 277772f63f4aSRitesh Harjani static inline int ext4_ioctl_get_encryption_pwsalt(struct file *filp, 277872f63f4aSRitesh Harjani void __user *arg) 277972f63f4aSRitesh Harjani { 278072f63f4aSRitesh Harjani return -EOPNOTSUPP; 278172f63f4aSRitesh Harjani } 2782b01531dbSEric Biggers #endif /* !CONFIG_FS_ENCRYPTION */ 2783d5d0e8c7SMichael Halcrow 27843dcf5451SChristoph Hellwig /* dir.c */ 278560fd4da3STheodore Ts'o extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *, 2786f7c21177STheodore Ts'o struct file *, 27873dcf5451SChristoph Hellwig struct ext4_dir_entry_2 *, 2788226ba972STao Ma struct buffer_head *, char *, int, 2789226ba972STao Ma unsigned int); 2790226ba972STao Ma #define ext4_check_dir_entry(dir, filp, de, bh, buf, size, offset) \ 2791f7c21177STheodore Ts'o unlikely(__ext4_check_dir_entry(__func__, __LINE__, (dir), (filp), \ 2792226ba972STao Ma (de), (bh), (buf), (size), (offset))) 27933dcf5451SChristoph Hellwig extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 27943dcf5451SChristoph Hellwig __u32 minor_hash, 27952f61830aSTheodore Ts'o struct ext4_dir_entry_2 *dirent, 2796a7550b30SJaegeuk Kim struct fscrypt_str *ent_name); 27973dcf5451SChristoph Hellwig extern void ext4_htree_free_dir_info(struct dir_private_info *p); 2798978fef91STao Ma extern int ext4_find_dest_de(struct inode *dir, struct inode *inode, 2799978fef91STao Ma struct buffer_head *bh, 2800978fef91STao Ma void *buf, int buf_size, 28015b643f9cSTheodore Ts'o struct ext4_filename *fname, 2802978fef91STao Ma struct ext4_dir_entry_2 **dest_de); 2803471fbbeaSDaniel Rosenberg void ext4_insert_dentry(struct inode *dir, struct inode *inode, 2804978fef91STao Ma struct ext4_dir_entry_2 *de, 2805978fef91STao Ma int buf_size, 28065b643f9cSTheodore Ts'o struct ext4_filename *fname); 2807978fef91STao Ma static inline void ext4_update_dx_flag(struct inode *inode) 2808978fef91STao Ma { 2809f902b216SJan Kara if (!ext4_has_feature_dir_index(inode->i_sb) && 2810f902b216SJan Kara ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) { 281148a34311SJan Kara /* ext4_iget() should have caught this... */ 281248a34311SJan Kara WARN_ON_ONCE(ext4_has_feature_metadata_csum(inode->i_sb)); 2813978fef91STao Ma ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); 2814978fef91STao Ma } 281548a34311SJan Kara } 2816d6006186SEric Biggers static const unsigned char ext4_filetype_table[] = { 281765d165d9STao Ma DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 281865d165d9STao Ma }; 281965d165d9STao Ma 282065d165d9STao Ma static inline unsigned char get_dtype(struct super_block *sb, int filetype) 282165d165d9STao Ma { 2822e2b911c5SDarrick J. Wong if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) 282365d165d9STao Ma return DT_UNKNOWN; 282465d165d9STao Ma 282565d165d9STao Ma return ext4_filetype_table[filetype]; 282665d165d9STao Ma } 282740b163f1SDarrick J. Wong extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, 282840b163f1SDarrick J. Wong void *buf, int buf_size); 28293dcf5451SChristoph Hellwig 28303dcf5451SChristoph Hellwig /* fsync.c */ 283102c24a82SJosef Bacik extern int ext4_sync_file(struct file *, loff_t, loff_t, int); 28323dcf5451SChristoph Hellwig 28333dcf5451SChristoph Hellwig /* hash.c */ 2834b886ee3eSGabriel Krisman Bertazi extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len, 2835b886ee3eSGabriel Krisman Bertazi struct dx_hash_info *hinfo); 28363dcf5451SChristoph Hellwig 28373dcf5451SChristoph Hellwig /* ialloc.c */ 28388016e29fSHarshad Shirwadkar extern int ext4_mark_inode_used(struct super_block *sb, int ino); 283914f3db55SChristian Brauner extern struct inode *__ext4_new_inode(struct user_namespace *, handle_t *, 284014f3db55SChristian Brauner struct inode *, umode_t, 28415cb81dabSDmitry Monakhov const struct qstr *qstr, __u32 goal, 28421b917ed8STahsin Erdogan uid_t *owner, __u32 i_flags, 28431b917ed8STahsin Erdogan int handle_type, unsigned int line_no, 28441b917ed8STahsin Erdogan int nblocks); 28451139575aSTheodore Ts'o 28461b917ed8STahsin Erdogan #define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \ 284714f3db55SChristian Brauner __ext4_new_inode(&init_user_ns, (handle), (dir), (mode), (qstr), \ 284814f3db55SChristian Brauner (goal), (owner), i_flags, 0, 0, 0) 284914f3db55SChristian Brauner #define ext4_new_inode_start_handle(mnt_userns, dir, mode, qstr, goal, owner, \ 28501139575aSTheodore Ts'o type, nblocks) \ 285114f3db55SChristian Brauner __ext4_new_inode((mnt_userns), NULL, (dir), (mode), (qstr), (goal), (owner), \ 28521b917ed8STahsin Erdogan 0, (type), __LINE__, (nblocks)) 28531139575aSTheodore Ts'o 28541139575aSTheodore Ts'o 28553dcf5451SChristoph Hellwig extern void ext4_free_inode(handle_t *, struct inode *); 28563dcf5451SChristoph Hellwig extern struct inode * ext4_orphan_get(struct super_block *, unsigned long); 28573dcf5451SChristoph Hellwig extern unsigned long ext4_count_free_inodes(struct super_block *); 28583dcf5451SChristoph Hellwig extern unsigned long ext4_count_dirs(struct super_block *); 28593dcf5451SChristoph Hellwig extern void ext4_check_inodes_bitmap(struct super_block *); 286061d08673STheodore Ts'o extern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap); 2861bfff6873SLukas Czerner extern int ext4_init_inode_table(struct super_block *sb, 2862bfff6873SLukas Czerner ext4_group_t group, int barrier); 2863813e5727STheodore Ts'o extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 28643dcf5451SChristoph Hellwig 28656866d7b3SHarshad Shirwadkar /* fast_commit.c */ 2866ce8c59d1SHarshad Shirwadkar int ext4_fc_info_show(struct seq_file *seq, void *v); 28676866d7b3SHarshad Shirwadkar void ext4_fc_init(struct super_block *sb, journal_t *journal); 2868aa75f4d3SHarshad Shirwadkar void ext4_fc_init_inode(struct inode *inode); 2869a80f7fcfSHarshad Shirwadkar void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start, 2870aa75f4d3SHarshad Shirwadkar ext4_lblk_t end); 2871a80f7fcfSHarshad Shirwadkar void __ext4_fc_track_unlink(handle_t *handle, struct inode *inode, 2872a80f7fcfSHarshad Shirwadkar struct dentry *dentry); 2873a80f7fcfSHarshad Shirwadkar void __ext4_fc_track_link(handle_t *handle, struct inode *inode, 2874a80f7fcfSHarshad Shirwadkar struct dentry *dentry); 2875a80f7fcfSHarshad Shirwadkar void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry); 2876a80f7fcfSHarshad Shirwadkar void ext4_fc_track_link(handle_t *handle, struct dentry *dentry); 28778210bb29SHarshad Shirwadkar void __ext4_fc_track_create(handle_t *handle, struct inode *inode, 28788210bb29SHarshad Shirwadkar struct dentry *dentry); 2879a80f7fcfSHarshad Shirwadkar void ext4_fc_track_create(handle_t *handle, struct dentry *dentry); 2880a80f7fcfSHarshad Shirwadkar void ext4_fc_track_inode(handle_t *handle, struct inode *inode); 2881e85c81baSXin Yin void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handle); 2882aa75f4d3SHarshad Shirwadkar void ext4_fc_start_update(struct inode *inode); 2883aa75f4d3SHarshad Shirwadkar void ext4_fc_stop_update(struct inode *inode); 2884aa75f4d3SHarshad Shirwadkar void ext4_fc_del(struct inode *inode); 28858016e29fSHarshad Shirwadkar bool ext4_fc_replay_check_excluded(struct super_block *sb, ext4_fsblk_t block); 28868016e29fSHarshad Shirwadkar void ext4_fc_replay_cleanup(struct super_block *sb); 2887aa75f4d3SHarshad Shirwadkar int ext4_fc_commit(journal_t *journal, tid_t commit_tid); 2888aa75f4d3SHarshad Shirwadkar int __init ext4_fc_init_dentry_cache(void); 2889ab047d51SSebastian Andrzej Siewior void ext4_fc_destroy_dentry_cache(void); 2890599ea31dSXin Yin int ext4_fc_record_regions(struct super_block *sb, int ino, 2891599ea31dSXin Yin ext4_lblk_t lblk, ext4_fsblk_t pblk, 2892599ea31dSXin Yin int len, int replay); 2893aa75f4d3SHarshad Shirwadkar 28943dcf5451SChristoph Hellwig /* mballoc.c */ 2895247dbed8SChristoph Hellwig extern const struct seq_operations ext4_mb_seq_groups_ops; 2896f68f4063SHarshad Shirwadkar extern const struct seq_operations ext4_mb_seq_structs_summary_ops; 28973dcf5451SChristoph Hellwig extern long ext4_mb_stats; 28983dcf5451SChristoph Hellwig extern long ext4_mb_max_to_scan; 2899a6c75eafSHarshad Shirwadkar extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset); 29009d99012fSAkira Fujita extern int ext4_mb_init(struct super_block *); 29013dcf5451SChristoph Hellwig extern int ext4_mb_release(struct super_block *); 29023dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 29033dcf5451SChristoph Hellwig struct ext4_allocation_request *, int *); 29043dcf5451SChristoph Hellwig extern int ext4_mb_reserve_blocks(struct super_block *, int); 290527bc446eSbrookxu extern void ext4_discard_preallocations(struct inode *, unsigned int); 29065dabfc78STheodore Ts'o extern int __init ext4_init_mballoc(void); 29075dabfc78STheodore Ts'o extern void ext4_exit_mballoc(void); 29083d392b26STheodore Ts'o extern ext4_group_t ext4_mb_prefetch(struct super_block *sb, 29093d392b26STheodore Ts'o ext4_group_t group, 29103d392b26STheodore Ts'o unsigned int nr, int *cnt); 29113d392b26STheodore Ts'o extern void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group, 29123d392b26STheodore Ts'o unsigned int nr); 29133d392b26STheodore Ts'o 291444338711STheodore Ts'o extern void ext4_free_blocks(handle_t *handle, struct inode *inode, 2915e6362609STheodore Ts'o struct buffer_head *bh, ext4_fsblk_t block, 2916e6362609STheodore Ts'o unsigned long count, int flags); 291728623c2fSTheodore Ts'o extern int ext4_mb_alloc_groupinfo(struct super_block *sb, 291828623c2fSTheodore Ts'o ext4_group_t ngroups); 2919920313a7SAneesh Kumar K.V extern int ext4_mb_add_groupinfo(struct super_block *sb, 29205f21b0e6SFrederic Bohe ext4_group_t i, struct ext4_group_desc *desc); 2921cc7365dfSYongqiang Yang extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, 29222846e820SAmir Goldstein ext4_fsblk_t block, unsigned long count); 29237360d173SLukas Czerner extern int ext4_trim_fs(struct super_block *, struct fstrim_range *); 2924a0154344SDaeho Jeong extern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid); 29258016e29fSHarshad Shirwadkar extern void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, 29268016e29fSHarshad Shirwadkar int len, int state); 29277360d173SLukas Czerner 29283dcf5451SChristoph Hellwig /* inode.c */ 29298016e29fSHarshad Shirwadkar void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, 29308016e29fSHarshad Shirwadkar struct ext4_inode_info *ei); 2931f348c252STheodore Ts'o int ext4_inode_is_fast_symlink(struct inode *inode); 293210560082STheodore Ts'o struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); 29331c215028STheodore Ts'o struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); 29349699d4f9STahsin Erdogan int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, 29359699d4f9STahsin Erdogan bool wait, struct buffer_head **bhs); 2936705965bdSJan Kara int ext4_get_block_unwritten(struct inode *inode, sector_t iblock, 2937f19d5870STao Ma struct buffer_head *bh_result, int create); 29386873fa0dSEric Sandeen int ext4_get_block(struct inode *inode, sector_t iblock, 29396873fa0dSEric Sandeen struct buffer_head *bh_result, int create); 29409c3569b5STao Ma int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, 29419c3569b5STao Ma struct buffer_head *bh, int create); 2942f19d5870STao Ma int ext4_walk_page_buffers(handle_t *handle, 2943188c299eSJan Kara struct inode *inode, 2944f19d5870STao Ma struct buffer_head *head, 2945f19d5870STao Ma unsigned from, 2946f19d5870STao Ma unsigned to, 2947f19d5870STao Ma int *partial, 2948188c299eSJan Kara int (*fn)(handle_t *handle, struct inode *inode, 2949f19d5870STao Ma struct buffer_head *bh)); 2950188c299eSJan Kara int do_journal_get_write_access(handle_t *handle, struct inode *inode, 2951f19d5870STao Ma struct buffer_head *bh); 29529c3569b5STao Ma #define FALL_BACK_TO_NONDELALLOC 1 29539c3569b5STao Ma #define CONVERT_INLINE_DATA 2 29543dcf5451SChristoph Hellwig 29558a363970STheodore Ts'o typedef enum { 29568a363970STheodore Ts'o EXT4_IGET_NORMAL = 0, 29578a363970STheodore Ts'o EXT4_IGET_SPECIAL = 0x0001, /* OK to iget a system inode */ 29588a363970STheodore Ts'o EXT4_IGET_HANDLE = 0x0002 /* Inode # is from a handle */ 29598a363970STheodore Ts'o } ext4_iget_flags; 29608a363970STheodore Ts'o 29618a363970STheodore Ts'o extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, 29628a363970STheodore Ts'o ext4_iget_flags flags, const char *function, 29638a363970STheodore Ts'o unsigned int line); 29648a363970STheodore Ts'o 29658a363970STheodore Ts'o #define ext4_iget(sb, ino, flags) \ 29668a363970STheodore Ts'o __ext4_iget((sb), (ino), (flags), __func__, __LINE__) 29678a363970STheodore Ts'o 2968a9185b41SChristoph Hellwig extern int ext4_write_inode(struct inode *, struct writeback_control *); 2969549c7297SChristian Brauner extern int ext4_setattr(struct user_namespace *, struct dentry *, 2970549c7297SChristian Brauner struct iattr *); 2971549c7297SChristian Brauner extern int ext4_getattr(struct user_namespace *, const struct path *, 2972549c7297SChristian Brauner struct kstat *, u32, unsigned int); 29730930fcc1SAl Viro extern void ext4_evict_inode(struct inode *); 29740930fcc1SAl Viro extern void ext4_clear_inode(struct inode *); 2975549c7297SChristian Brauner extern int ext4_file_getattr(struct user_namespace *, const struct path *, 2976549c7297SChristian Brauner struct kstat *, u32, unsigned int); 29773dcf5451SChristoph Hellwig extern int ext4_sync_inode(handle_t *, struct inode *); 2978aa385729SChristoph Hellwig extern void ext4_dirty_inode(struct inode *, int); 29793dcf5451SChristoph Hellwig extern int ext4_change_inode_journal_flag(struct inode *, int); 29803dcf5451SChristoph Hellwig extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *); 29818016e29fSHarshad Shirwadkar extern int ext4_get_fc_inode_loc(struct super_block *sb, unsigned long ino, 29828016e29fSHarshad Shirwadkar struct ext4_iloc *iloc); 2983a361293fSJan Kara extern int ext4_inode_attach_jinode(struct inode *inode); 298491ef4cafSDuane Griffin extern int ext4_can_truncate(struct inode *inode); 29852c98eb5eSTheodore Ts'o extern int ext4_truncate(struct inode *); 2986430657b6SRoss Zwisler extern int ext4_break_layouts(struct inode *); 2987ad5cd4f4SDarrick J. Wong extern int ext4_punch_hole(struct file *file, loff_t offset, loff_t length); 2988043546e4SIra Weiny extern void ext4_set_inode_flags(struct inode *, bool init); 2989ccd2506bSTheodore Ts'o extern int ext4_alloc_da_blocks(struct inode *inode); 29903dcf5451SChristoph Hellwig extern void ext4_set_aops(struct inode *inode); 29913dcf5451SChristoph Hellwig extern int ext4_writepage_trans_blocks(struct inode *); 2992f3bd1f3fSMingming Cao extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); 2993a87dd18cSLukas Czerner extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 2994a87dd18cSLukas Czerner loff_t lstart, loff_t lend); 2995401b25aaSSouptick Joarder extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); 2996a9e7f447SDmitry Monakhov extern qsize_t *ext4_get_reserved_space(struct inode *inode); 2997040cb378SLi Xi extern int ext4_get_projid(struct inode *inode, kprojid_t *projid); 2998f456767dSEric Whitney extern void ext4_da_release_space(struct inode *inode, int to_free); 29995f634d06SAneesh Kumar K.V extern void ext4_da_update_reserve_space(struct inode *inode, 30005f634d06SAneesh Kumar K.V int used, int quota_claim); 300153085facSJan Kara extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, 300253085facSJan Kara ext4_fsblk_t pblk, ext4_lblk_t len); 3003dae1e52cSAmir Goldstein 3004dae1e52cSAmir Goldstein /* indirect.c */ 3005dae1e52cSAmir Goldstein extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 3006dae1e52cSAmir Goldstein struct ext4_map_blocks *map, int flags); 3007fa55a0edSJan Kara extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 3008819c4920STheodore Ts'o extern void ext4_ind_truncate(handle_t *, struct inode *inode); 30094f579ae7SLukas Czerner extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode, 30104f579ae7SLukas Czerner ext4_lblk_t start, ext4_lblk_t end); 3011ff9893dcSAmir Goldstein 30123dcf5451SChristoph Hellwig /* ioctl.c */ 30133dcf5451SChristoph Hellwig extern long ext4_ioctl(struct file *, unsigned int, unsigned long); 30143dcf5451SChristoph Hellwig extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long); 30154db5c2e6SMiklos Szeredi int ext4_fileattr_set(struct user_namespace *mnt_userns, 30164db5c2e6SMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 30174db5c2e6SMiklos Szeredi int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa); 30188016e29fSHarshad Shirwadkar extern void ext4_reset_inode_seed(struct inode *inode); 3019eb705421STheodore Ts'o int ext4_update_overhead(struct super_block *sb); 30203dcf5451SChristoph Hellwig 30213dcf5451SChristoph Hellwig /* migrate.c */ 30222a43a878SAneesh Kumar K.V extern int ext4_ext_migrate(struct inode *); 30230d14b098SLukas Czerner extern int ext4_ind_migrate(struct inode *inode); 30243d0518f4SWei Yongjun 30253dcf5451SChristoph Hellwig /* namei.c */ 30268016e29fSHarshad Shirwadkar extern int ext4_init_new_dir(handle_t *handle, struct inode *dir, 30278016e29fSHarshad Shirwadkar struct inode *inode); 3028f036adb3STheodore Ts'o extern int ext4_dirblock_csum_verify(struct inode *inode, 3029f036adb3STheodore Ts'o struct buffer_head *bh); 30303dcf5451SChristoph Hellwig extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 30313dcf5451SChristoph Hellwig __u32 start_minor_hash, __u32 *next_hash); 30325b643f9cSTheodore Ts'o extern int ext4_search_dir(struct buffer_head *bh, 30337335cd3bSTao Ma char *search_buf, 30347335cd3bSTao Ma int buf_size, 30357335cd3bSTao Ma struct inode *dir, 30365b643f9cSTheodore Ts'o struct ext4_filename *fname, 30377335cd3bSTao Ma unsigned int offset, 30387335cd3bSTao Ma struct ext4_dir_entry_2 **res_dir); 30392fe34d29SKyoungho Koo extern int ext4_generic_delete_entry(struct inode *dir, 304005019a9eSTao Ma struct ext4_dir_entry_2 *de_del, 304105019a9eSTao Ma struct buffer_head *bh, 304205019a9eSTao Ma void *entry_buf, 304305019a9eSTao Ma int buf_size, 304405019a9eSTao Ma int csum_size); 3045a7550b30SJaegeuk Kim extern bool ext4_empty_dir(struct inode *inode); 30463dcf5451SChristoph Hellwig 30473dcf5451SChristoph Hellwig /* resize.c */ 30481d0c3924STheodore Ts'o extern void ext4_kvfree_array_rcu(void *to_free); 30493dcf5451SChristoph Hellwig extern int ext4_group_add(struct super_block *sb, 30503dcf5451SChristoph Hellwig struct ext4_new_group_data *input); 30513dcf5451SChristoph Hellwig extern int ext4_group_extend(struct super_block *sb, 30523dcf5451SChristoph Hellwig struct ext4_super_block *es, 30533dcf5451SChristoph Hellwig ext4_fsblk_t n_blocks_count); 305419c5246dSYongqiang Yang extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 3055bbc605cdSLukas Czerner extern unsigned int ext4_list_backups(struct super_block *sb, 3056bbc605cdSLukas Czerner unsigned int *three, unsigned int *five, 3057bbc605cdSLukas Czerner unsigned int *seven); 30583dcf5451SChristoph Hellwig 30593dcf5451SChristoph Hellwig /* super.c */ 3060fb265c9cSTheodore Ts'o extern struct buffer_head *ext4_sb_bread(struct super_block *sb, 3061fb265c9cSTheodore Ts'o sector_t block, int op_flags); 30628394a6abSzhangyi (F) extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, 30638394a6abSzhangyi (F) sector_t block); 3064fa491b14Szhangyi (F) extern void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags, 3065fa491b14Szhangyi (F) bh_end_io_t *end_io); 3066fa491b14Szhangyi (F) extern int ext4_read_bh(struct buffer_head *bh, int op_flags, 3067fa491b14Szhangyi (F) bh_end_io_t *end_io); 3068fa491b14Szhangyi (F) extern int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait); 30695df1d412Szhangyi (F) extern void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block); 3070ebd173beSTheodore Ts'o extern int ext4_seq_options_show(struct seq_file *seq, void *offset); 3071952fc18eSTheodore Ts'o extern int ext4_calculate_overhead(struct super_block *sb); 3072bbc605cdSLukas Czerner extern __le32 ext4_superblock_csum(struct super_block *sb, 3073bbc605cdSLukas Czerner struct ext4_super_block *es); 307406db49e6STheodore Ts'o extern void ext4_superblock_csum_set(struct super_block *sb); 3075117fff10STheodore Ts'o extern int ext4_alloc_flex_bg_array(struct super_block *sb, 3076117fff10STheodore Ts'o ext4_group_t ngroup); 3077722887ddSTheodore Ts'o extern const char *ext4_decode_error(struct super_block *sb, int errno, 3078722887ddSTheodore Ts'o char nbuf[16]); 3079db79e6d1SWang Shilong extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb, 3080db79e6d1SWang Shilong ext4_group_t block_group, 3081db79e6d1SWang Shilong unsigned int flags); 3082e7c96e8eSJoe Perches 3083014c9caaSJan Kara extern __printf(7, 8) 3084014c9caaSJan Kara void __ext4_error(struct super_block *, const char *, unsigned int, bool, 3085014c9caaSJan Kara int, __u64, const char *, ...); 308654d3adbcSTheodore Ts'o extern __printf(6, 7) 308754d3adbcSTheodore Ts'o void __ext4_error_inode(struct inode *, const char *, unsigned int, 308854d3adbcSTheodore Ts'o ext4_fsblk_t, int, const char *, ...); 3089b9075fa9SJoe Perches extern __printf(5, 6) 3090e7c96e8eSJoe Perches void __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t, 3091b9075fa9SJoe Perches const char *, ...); 3092c398eda0STheodore Ts'o extern void __ext4_std_error(struct super_block *, const char *, 3093c398eda0STheodore Ts'o unsigned int, int); 3094b9075fa9SJoe Perches extern __printf(4, 5) 3095b9075fa9SJoe Perches void __ext4_warning(struct super_block *, const char *, unsigned int, 3096b9075fa9SJoe Perches const char *, ...); 3097b03a2f7eSAndreas Dilger extern __printf(4, 5) 3098b03a2f7eSAndreas Dilger void __ext4_warning_inode(const struct inode *inode, const char *function, 3099b03a2f7eSAndreas Dilger unsigned int line, const char *fmt, ...); 3100b9075fa9SJoe Perches extern __printf(3, 4) 3101e7c96e8eSJoe Perches void __ext4_msg(struct super_block *, const char *, const char *, ...); 3102c5e06d10SJohann Lombardi extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp, 3103c5e06d10SJohann Lombardi const char *, unsigned int, const char *); 3104b9075fa9SJoe Perches extern __printf(7, 8) 3105b9075fa9SJoe Perches void __ext4_grp_locked_error(const char *, unsigned int, 3106b9075fa9SJoe Perches struct super_block *, ext4_group_t, 3107b9075fa9SJoe Perches unsigned long, ext4_fsblk_t, 3108b9075fa9SJoe Perches const char *, ...); 3109e7c96e8eSJoe Perches 3110b03a2f7eSAndreas Dilger #define EXT4_ERROR_INODE(inode, fmt, a...) \ 3111b03a2f7eSAndreas Dilger ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a) 3112b03a2f7eSAndreas Dilger 311354d3adbcSTheodore Ts'o #define EXT4_ERROR_INODE_ERR(inode, err, fmt, a...) \ 311454d3adbcSTheodore Ts'o __ext4_error_inode((inode), __func__, __LINE__, 0, (err), (fmt), ## a) 311554d3adbcSTheodore Ts'o 311654d3adbcSTheodore Ts'o #define ext4_error_inode_block(inode, block, err, fmt, a...) \ 311754d3adbcSTheodore Ts'o __ext4_error_inode((inode), __func__, __LINE__, (block), (err), \ 311854d3adbcSTheodore Ts'o (fmt), ## a) 3119b03a2f7eSAndreas Dilger 3120b03a2f7eSAndreas Dilger #define EXT4_ERROR_FILE(file, block, fmt, a...) \ 3121b03a2f7eSAndreas Dilger ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a) 3122b03a2f7eSAndreas Dilger 3123014c9caaSJan Kara #define ext4_abort(sb, err, fmt, a...) \ 3124014c9caaSJan Kara __ext4_error((sb), __func__, __LINE__, true, (err), 0, (fmt), ## a) 3125014c9caaSJan Kara 3126e7c96e8eSJoe Perches #ifdef CONFIG_PRINTK 3127e7c96e8eSJoe Perches 3128e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 312954d3adbcSTheodore Ts'o __ext4_error_inode(inode, func, line, block, 0, fmt, ##__VA_ARGS__) 313054d3adbcSTheodore Ts'o #define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 313154d3adbcSTheodore Ts'o __ext4_error_inode((inode), (func), (line), (block), \ 313254d3adbcSTheodore Ts'o (err), (fmt), ##__VA_ARGS__) 3133e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 3134e7c96e8eSJoe Perches __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__) 3135e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 3136014c9caaSJan Kara __ext4_error((sb), __func__, __LINE__, false, 0, 0, (fmt), \ 3137014c9caaSJan Kara ##__VA_ARGS__) 313854d3adbcSTheodore Ts'o #define ext4_error_err(sb, err, fmt, ...) \ 3139014c9caaSJan Kara __ext4_error((sb), __func__, __LINE__, false, (err), 0, (fmt), \ 3140014c9caaSJan Kara ##__VA_ARGS__) 3141e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 3142e7c96e8eSJoe Perches __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 3143b03a2f7eSAndreas Dilger #define ext4_warning_inode(inode, fmt, ...) \ 3144b03a2f7eSAndreas Dilger __ext4_warning_inode(inode, __func__, __LINE__, fmt, ##__VA_ARGS__) 3145e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 3146e7c96e8eSJoe Perches __ext4_msg(sb, level, fmt, ##__VA_ARGS__) 3147e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 3148e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg) 3149e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 3150e7c96e8eSJoe Perches __ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino, block, \ 3151e7c96e8eSJoe Perches fmt, ##__VA_ARGS__) 3152e7c96e8eSJoe Perches 3153e7c96e8eSJoe Perches #else 3154e7c96e8eSJoe Perches 3155e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 3156e7c96e8eSJoe Perches do { \ 3157e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 315854d3adbcSTheodore Ts'o __ext4_error_inode(inode, "", 0, block, 0, " "); \ 315954d3adbcSTheodore Ts'o } while (0) 316054d3adbcSTheodore Ts'o #define ext4_error_inode_err(inode, func, line, block, err, fmt, ...) \ 316154d3adbcSTheodore Ts'o do { \ 316254d3adbcSTheodore Ts'o no_printk(fmt, ##__VA_ARGS__); \ 316354d3adbcSTheodore Ts'o __ext4_error_inode(inode, "", 0, block, err, " "); \ 3164e7c96e8eSJoe Perches } while (0) 3165e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 3166e7c96e8eSJoe Perches do { \ 3167e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3168e7c96e8eSJoe Perches __ext4_error_file(file, "", 0, block, " "); \ 3169e7c96e8eSJoe Perches } while (0) 3170e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 3171e7c96e8eSJoe Perches do { \ 3172e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3173014c9caaSJan Kara __ext4_error(sb, "", 0, false, 0, 0, " "); \ 3174e7c96e8eSJoe Perches } while (0) 317554d3adbcSTheodore Ts'o #define ext4_error_err(sb, err, fmt, ...) \ 3176e7c96e8eSJoe Perches do { \ 3177e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3178014c9caaSJan Kara __ext4_error(sb, "", 0, false, err, 0, " "); \ 3179e7c96e8eSJoe Perches } while (0) 3180e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 3181e7c96e8eSJoe Perches do { \ 3182e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3183e7c96e8eSJoe Perches __ext4_warning(sb, "", 0, " "); \ 3184e7c96e8eSJoe Perches } while (0) 3185b03a2f7eSAndreas Dilger #define ext4_warning_inode(inode, fmt, ...) \ 3186b03a2f7eSAndreas Dilger do { \ 3187b03a2f7eSAndreas Dilger no_printk(fmt, ##__VA_ARGS__); \ 3188b03a2f7eSAndreas Dilger __ext4_warning_inode(inode, "", 0, " "); \ 3189b03a2f7eSAndreas Dilger } while (0) 3190e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 3191e7c96e8eSJoe Perches do { \ 3192e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3193e7c96e8eSJoe Perches __ext4_msg(sb, "", " "); \ 3194e7c96e8eSJoe Perches } while (0) 3195e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 3196e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, "", 0, "") 3197e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 3198e7c96e8eSJoe Perches do { \ 3199e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 3200e7c96e8eSJoe Perches __ext4_grp_locked_error("", 0, sb, grp, ino, block, " "); \ 3201e7c96e8eSJoe Perches } while (0) 3202e7c96e8eSJoe Perches 3203e7c96e8eSJoe Perches #endif 3204e7c96e8eSJoe Perches 32053dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 32063dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 32073dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 32083dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 32093dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_table(struct super_block *sb, 32103dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 3211021b65bbSTheodore Ts'o extern __u32 ext4_free_group_clusters(struct super_block *sb, 3212560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 3213560671a0SAneesh Kumar K.V extern __u32 ext4_free_inodes_count(struct super_block *sb, 3214560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 3215560671a0SAneesh Kumar K.V extern __u32 ext4_used_dirs_count(struct super_block *sb, 3216560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 3217560671a0SAneesh Kumar K.V extern __u32 ext4_itable_unused_count(struct super_block *sb, 3218560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 32193dcf5451SChristoph Hellwig extern void ext4_block_bitmap_set(struct super_block *sb, 32203dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 32213dcf5451SChristoph Hellwig extern void ext4_inode_bitmap_set(struct super_block *sb, 32223dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 32233dcf5451SChristoph Hellwig extern void ext4_inode_table_set(struct super_block *sb, 32243dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 3225021b65bbSTheodore Ts'o extern void ext4_free_group_clusters_set(struct super_block *sb, 3226021b65bbSTheodore Ts'o struct ext4_group_desc *bg, 3227021b65bbSTheodore Ts'o __u32 count); 3228560671a0SAneesh Kumar K.V extern void ext4_free_inodes_set(struct super_block *sb, 3229560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 3230560671a0SAneesh Kumar K.V extern void ext4_used_dirs_set(struct super_block *sb, 3231560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 3232560671a0SAneesh Kumar K.V extern void ext4_itable_unused_set(struct super_block *sb, 3233560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 3234feb0ab32SDarrick J. Wong extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group, 3235bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 3236feb0ab32SDarrick J. Wong extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group, 3237bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 32387f511862STheodore Ts'o extern int ext4_register_li_request(struct super_block *sb, 32397f511862STheodore Ts'o ext4_group_t first_not_zeroed); 32403dcf5451SChristoph Hellwig 32419aa5d32bSDmitry Monakhov static inline int ext4_has_metadata_csum(struct super_block *sb) 32429aa5d32bSDmitry Monakhov { 3243e2b911c5SDarrick J. Wong WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) && 32449aa5d32bSDmitry Monakhov !EXT4_SB(sb)->s_chksum_driver); 32459aa5d32bSDmitry Monakhov 3246dec214d0STahsin Erdogan return ext4_has_feature_metadata_csum(sb) && 3247dec214d0STahsin Erdogan (EXT4_SB(sb)->s_chksum_driver != NULL); 32489aa5d32bSDmitry Monakhov } 3249dec214d0STahsin Erdogan 3250dec214d0STahsin Erdogan static inline int ext4_has_group_desc_csum(struct super_block *sb) 3251dec214d0STahsin Erdogan { 3252dec214d0STahsin Erdogan return ext4_has_feature_gdt_csum(sb) || ext4_has_metadata_csum(sb); 3253dec214d0STahsin Erdogan } 3254dec214d0STahsin Erdogan 325581e8c3c5SPetr Malat #define ext4_read_incompat_64bit_val(es, name) \ 325681e8c3c5SPetr Malat (((es)->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT) \ 325781e8c3c5SPetr Malat ? (ext4_fsblk_t)le32_to_cpu(es->name##_hi) << 32 : 0) | \ 325881e8c3c5SPetr Malat le32_to_cpu(es->name##_lo)) 325981e8c3c5SPetr Malat 32603dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 32613dcf5451SChristoph Hellwig { 326281e8c3c5SPetr Malat return ext4_read_incompat_64bit_val(es, s_blocks_count); 32633dcf5451SChristoph Hellwig } 32643dcf5451SChristoph Hellwig 32653dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) 32663dcf5451SChristoph Hellwig { 326781e8c3c5SPetr Malat return ext4_read_incompat_64bit_val(es, s_r_blocks_count); 32683dcf5451SChristoph Hellwig } 32693dcf5451SChristoph Hellwig 32703dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es) 32713dcf5451SChristoph Hellwig { 327281e8c3c5SPetr Malat return ext4_read_incompat_64bit_val(es, s_free_blocks_count); 32733dcf5451SChristoph Hellwig } 32743dcf5451SChristoph Hellwig 32753dcf5451SChristoph Hellwig static inline void ext4_blocks_count_set(struct ext4_super_block *es, 32763dcf5451SChristoph Hellwig ext4_fsblk_t blk) 32773dcf5451SChristoph Hellwig { 32783dcf5451SChristoph Hellwig es->s_blocks_count_lo = cpu_to_le32((u32)blk); 32793dcf5451SChristoph Hellwig es->s_blocks_count_hi = cpu_to_le32(blk >> 32); 32803dcf5451SChristoph Hellwig } 32813dcf5451SChristoph Hellwig 32823dcf5451SChristoph Hellwig static inline void ext4_free_blocks_count_set(struct ext4_super_block *es, 32833dcf5451SChristoph Hellwig ext4_fsblk_t blk) 32843dcf5451SChristoph Hellwig { 32853dcf5451SChristoph Hellwig es->s_free_blocks_count_lo = cpu_to_le32((u32)blk); 32863dcf5451SChristoph Hellwig es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32); 32873dcf5451SChristoph Hellwig } 32883dcf5451SChristoph Hellwig 32893dcf5451SChristoph Hellwig static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, 32903dcf5451SChristoph Hellwig ext4_fsblk_t blk) 32913dcf5451SChristoph Hellwig { 32923dcf5451SChristoph Hellwig es->s_r_blocks_count_lo = cpu_to_le32((u32)blk); 32933dcf5451SChristoph Hellwig es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32); 32943dcf5451SChristoph Hellwig } 32953dcf5451SChristoph Hellwig 3296e08ac99fSArtem Blagodarenko static inline loff_t ext4_isize(struct super_block *sb, 3297e08ac99fSArtem Blagodarenko struct ext4_inode *raw_inode) 32983dcf5451SChristoph Hellwig { 3299e08ac99fSArtem Blagodarenko if (ext4_has_feature_largedir(sb) || 3300e08ac99fSArtem Blagodarenko S_ISREG(le16_to_cpu(raw_inode->i_mode))) 33013dcf5451SChristoph Hellwig return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | 33023dcf5451SChristoph Hellwig le32_to_cpu(raw_inode->i_size_lo); 3303e08ac99fSArtem Blagodarenko 330406a279d6STheodore Ts'o return (loff_t) le32_to_cpu(raw_inode->i_size_lo); 33053dcf5451SChristoph Hellwig } 33063dcf5451SChristoph Hellwig 33073dcf5451SChristoph Hellwig static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) 33083dcf5451SChristoph Hellwig { 33093dcf5451SChristoph Hellwig raw_inode->i_size_lo = cpu_to_le32(i_size); 33103dcf5451SChristoph Hellwig raw_inode->i_size_high = cpu_to_le32(i_size >> 32); 33113dcf5451SChristoph Hellwig } 33123dcf5451SChristoph Hellwig 33133dcf5451SChristoph Hellwig static inline 33143dcf5451SChristoph Hellwig struct ext4_group_info *ext4_get_group_info(struct super_block *sb, 33153dcf5451SChristoph Hellwig ext4_group_t group) 33163dcf5451SChristoph Hellwig { 3317df3da4eaSSuraj Jitindar Singh struct ext4_group_info **grp_info; 33183dcf5451SChristoph Hellwig long indexv, indexh; 33192f2e09ebSTheodore Ts'o BUG_ON(group >= EXT4_SB(sb)->s_groups_count); 33203dcf5451SChristoph Hellwig indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb)); 33213dcf5451SChristoph Hellwig indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1); 3322df3da4eaSSuraj Jitindar Singh grp_info = sbi_array_rcu_deref(EXT4_SB(sb), s_group_info, indexv); 3323df3da4eaSSuraj Jitindar Singh return grp_info[indexh]; 33243dcf5451SChristoph Hellwig } 33253dcf5451SChristoph Hellwig 33268df9675fSTheodore Ts'o /* 33278df9675fSTheodore Ts'o * Reading s_groups_count requires using smp_rmb() afterwards. See 33288df9675fSTheodore Ts'o * the locking protocol documented in the comments of ext4_group_add() 33298df9675fSTheodore Ts'o * in resize.c 33308df9675fSTheodore Ts'o */ 33318df9675fSTheodore Ts'o static inline ext4_group_t ext4_get_groups_count(struct super_block *sb) 33328df9675fSTheodore Ts'o { 33338df9675fSTheodore Ts'o ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 33348df9675fSTheodore Ts'o 33358df9675fSTheodore Ts'o smp_rmb(); 33368df9675fSTheodore Ts'o return ngroups; 33378df9675fSTheodore Ts'o } 33383dcf5451SChristoph Hellwig 3339772cb7c8SJose R. Santos static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 3340772cb7c8SJose R. Santos ext4_group_t block_group) 3341772cb7c8SJose R. Santos { 3342772cb7c8SJose R. Santos return block_group >> sbi->s_log_groups_per_flex; 3343772cb7c8SJose R. Santos } 3344772cb7c8SJose R. Santos 3345772cb7c8SJose R. Santos static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) 3346772cb7c8SJose R. Santos { 3347772cb7c8SJose R. Santos return 1 << sbi->s_log_groups_per_flex; 3348772cb7c8SJose R. Santos } 3349772cb7c8SJose R. Santos 33503dcf5451SChristoph Hellwig #define ext4_std_error(sb, errno) \ 33513dcf5451SChristoph Hellwig do { \ 33523dcf5451SChristoph Hellwig if ((errno)) \ 3353c398eda0STheodore Ts'o __ext4_std_error((sb), __func__, __LINE__, (errno)); \ 33543dcf5451SChristoph Hellwig } while (0) 33553dcf5451SChristoph Hellwig 3356a30d542aSAneesh Kumar K.V #ifdef CONFIG_SMP 3357df55c99dSTheodore Ts'o /* Each CPU can accumulate percpu_counter_batch clusters in their local 3358df55c99dSTheodore Ts'o * counters. So we need to make sure we have free clusters more 3359179f7ebfSEric Dumazet * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. 3360a30d542aSAneesh Kumar K.V */ 3361df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) 3362a30d542aSAneesh Kumar K.V #else 3363df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK 0 3364a30d542aSAneesh Kumar K.V #endif 3365a30d542aSAneesh Kumar K.V 3366f340b3d9Shongnanli /* Update i_disksize. Requires i_rwsem to avoid races with truncate */ 3367cf17fea6SAneesh Kumar K.V static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) 3368cf17fea6SAneesh Kumar K.V { 336990e775b7SJan Kara WARN_ON_ONCE(S_ISREG(inode->i_mode) && 33705955102cSAl Viro !inode_is_locked(inode)); 3371cf17fea6SAneesh Kumar K.V down_write(&EXT4_I(inode)->i_data_sem); 3372cf17fea6SAneesh Kumar K.V if (newsize > EXT4_I(inode)->i_disksize) 337335df4299SQian Cai WRITE_ONCE(EXT4_I(inode)->i_disksize, newsize); 3374cf17fea6SAneesh Kumar K.V up_write(&EXT4_I(inode)->i_data_sem); 337590e775b7SJan Kara } 337690e775b7SJan Kara 3377f340b3d9Shongnanli /* Update i_size, i_disksize. Requires i_rwsem to avoid races with truncate */ 33784631dbf6SDmitry Monakhov static inline int ext4_update_inode_size(struct inode *inode, loff_t newsize) 33794631dbf6SDmitry Monakhov { 33804631dbf6SDmitry Monakhov int changed = 0; 33814631dbf6SDmitry Monakhov 33824631dbf6SDmitry Monakhov if (newsize > inode->i_size) { 33834631dbf6SDmitry Monakhov i_size_write(inode, newsize); 33844631dbf6SDmitry Monakhov changed = 1; 33854631dbf6SDmitry Monakhov } 33864631dbf6SDmitry Monakhov if (newsize > EXT4_I(inode)->i_disksize) { 33874631dbf6SDmitry Monakhov ext4_update_i_disksize(inode, newsize); 33884631dbf6SDmitry Monakhov changed |= 2; 33894631dbf6SDmitry Monakhov } 33904631dbf6SDmitry Monakhov return changed; 33914631dbf6SDmitry Monakhov } 33924631dbf6SDmitry Monakhov 339301127848SJan Kara int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset, 339401127848SJan Kara loff_t len); 339501127848SJan Kara 33965d1b1b3fSAneesh Kumar K.V struct ext4_group_info { 33975d1b1b3fSAneesh Kumar K.V unsigned long bb_state; 3398addd752cSChunguang Xu #ifdef AGGRESSIVE_CHECK 3399addd752cSChunguang Xu unsigned long bb_check_counter; 3400addd752cSChunguang Xu #endif 34015d1b1b3fSAneesh Kumar K.V struct rb_root bb_free_root; 3402a36b4498SEric Sandeen ext4_grpblk_t bb_first_free; /* first free block */ 3403a36b4498SEric Sandeen ext4_grpblk_t bb_free; /* total free blocks */ 3404a36b4498SEric Sandeen ext4_grpblk_t bb_fragments; /* nr of freespace fragments */ 34058a57d9d6SCurt Wohlgemuth ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */ 3406196e402aSHarshad Shirwadkar ext4_group_t bb_group; /* Group number */ 34075d1b1b3fSAneesh Kumar K.V struct list_head bb_prealloc_list; 34085d1b1b3fSAneesh Kumar K.V #ifdef DOUBLE_CHECK 34095d1b1b3fSAneesh Kumar K.V void *bb_bitmap; 34105d1b1b3fSAneesh Kumar K.V #endif 34115d1b1b3fSAneesh Kumar K.V struct rw_semaphore alloc_sem; 3412196e402aSHarshad Shirwadkar struct rb_node bb_avg_fragment_size_rb; 3413196e402aSHarshad Shirwadkar struct list_head bb_largest_free_order_node; 3414a36b4498SEric Sandeen ext4_grpblk_t bb_counters[]; /* Nr of free power-of-two-block 3415a36b4498SEric Sandeen * regions, index is order. 3416a36b4498SEric Sandeen * bb_counters[3] = 5 means 3417a36b4498SEric Sandeen * 5 free 8-block regions. */ 34185d1b1b3fSAneesh Kumar K.V }; 34195d1b1b3fSAneesh Kumar K.V 34205d1b1b3fSAneesh Kumar K.V #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 34213d56b8d2STao Ma #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 3422163a203dSDarrick J. Wong #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2 342387a39389SDarrick J. Wong #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3 3424db79e6d1SWang Shilong #define EXT4_GROUP_INFO_BBITMAP_CORRUPT \ 3425db79e6d1SWang Shilong (1 << EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT) 3426db79e6d1SWang Shilong #define EXT4_GROUP_INFO_IBITMAP_CORRUPT \ 3427db79e6d1SWang Shilong (1 << EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT) 3428cfd73237SAlex Zhuravlev #define EXT4_GROUP_INFO_BBITMAP_READ_BIT 4 34295d1b1b3fSAneesh Kumar K.V 34305d1b1b3fSAneesh Kumar K.V #define EXT4_MB_GRP_NEED_INIT(grp) \ 34315d1b1b3fSAneesh Kumar K.V (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 3432163a203dSDarrick J. Wong #define EXT4_MB_GRP_BBITMAP_CORRUPT(grp) \ 3433163a203dSDarrick J. Wong (test_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 343487a39389SDarrick J. Wong #define EXT4_MB_GRP_IBITMAP_CORRUPT(grp) \ 343587a39389SDarrick J. Wong (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 34365d1b1b3fSAneesh Kumar K.V 34373d56b8d2STao Ma #define EXT4_MB_GRP_WAS_TRIMMED(grp) \ 34383d56b8d2STao Ma (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 34393d56b8d2STao Ma #define EXT4_MB_GRP_SET_TRIMMED(grp) \ 34403d56b8d2STao Ma (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 34413d56b8d2STao Ma #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \ 34423d56b8d2STao Ma (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 3443cfd73237SAlex Zhuravlev #define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \ 3444cfd73237SAlex Zhuravlev (test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state))) 34453d56b8d2STao Ma 344650797481STheodore Ts'o #define EXT4_MAX_CONTENTION 8 344750797481STheodore Ts'o #define EXT4_CONTENTION_THRESHOLD 2 344850797481STheodore Ts'o 3449955ce5f5SAneesh Kumar K.V static inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb, 3450955ce5f5SAneesh Kumar K.V ext4_group_t group) 3451955ce5f5SAneesh Kumar K.V { 3452955ce5f5SAneesh Kumar K.V return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group); 3453955ce5f5SAneesh Kumar K.V } 3454955ce5f5SAneesh Kumar K.V 345550797481STheodore Ts'o /* 345650797481STheodore Ts'o * Returns true if the filesystem is busy enough that attempts to 345750797481STheodore Ts'o * access the block group locks has run into contention. 345850797481STheodore Ts'o */ 345950797481STheodore Ts'o static inline int ext4_fs_is_busy(struct ext4_sb_info *sbi) 346050797481STheodore Ts'o { 346150797481STheodore Ts'o return (atomic_read(&sbi->s_lock_busy) > EXT4_CONTENTION_THRESHOLD); 346250797481STheodore Ts'o } 346350797481STheodore Ts'o 34645d1b1b3fSAneesh Kumar K.V static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 34655d1b1b3fSAneesh Kumar K.V { 346650797481STheodore Ts'o spinlock_t *lock = ext4_group_lock_ptr(sb, group); 346750797481STheodore Ts'o if (spin_trylock(lock)) 346850797481STheodore Ts'o /* 346950797481STheodore Ts'o * We're able to grab the lock right away, so drop the 347050797481STheodore Ts'o * lock contention counter. 347150797481STheodore Ts'o */ 347250797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, -1, 0); 347350797481STheodore Ts'o else { 347450797481STheodore Ts'o /* 347550797481STheodore Ts'o * The lock is busy, so bump the contention counter, 347650797481STheodore Ts'o * and then wait on the spin lock. 347750797481STheodore Ts'o */ 347850797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, 1, 347950797481STheodore Ts'o EXT4_MAX_CONTENTION); 348050797481STheodore Ts'o spin_lock(lock); 348150797481STheodore Ts'o } 34825d1b1b3fSAneesh Kumar K.V } 34835d1b1b3fSAneesh Kumar K.V 34845d1b1b3fSAneesh Kumar K.V static inline void ext4_unlock_group(struct super_block *sb, 34855d1b1b3fSAneesh Kumar K.V ext4_group_t group) 34865d1b1b3fSAneesh Kumar K.V { 3487955ce5f5SAneesh Kumar K.V spin_unlock(ext4_group_lock_ptr(sb, group)); 34885d1b1b3fSAneesh Kumar K.V } 34895d1b1b3fSAneesh Kumar K.V 3490f177ee08SRoman Anufriev #ifdef CONFIG_QUOTA 3491f177ee08SRoman Anufriev static inline bool ext4_quota_capable(struct super_block *sb) 3492f177ee08SRoman Anufriev { 3493f177ee08SRoman Anufriev return (test_opt(sb, QUOTA) || ext4_has_feature_quota(sb)); 3494f177ee08SRoman Anufriev } 3495f177ee08SRoman Anufriev 3496f177ee08SRoman Anufriev static inline bool ext4_is_quota_journalled(struct super_block *sb) 3497f177ee08SRoman Anufriev { 3498f177ee08SRoman Anufriev struct ext4_sb_info *sbi = EXT4_SB(sb); 3499f177ee08SRoman Anufriev 3500f177ee08SRoman Anufriev return (ext4_has_feature_quota(sb) || 3501f177ee08SRoman Anufriev sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]); 3502f177ee08SRoman Anufriev } 350325c6d98fSJan Kara int ext4_enable_quotas(struct super_block *sb); 3504f177ee08SRoman Anufriev #endif 3505f177ee08SRoman Anufriev 35063dcf5451SChristoph Hellwig /* 35071f7d1e77STheodore Ts'o * Block validity checking 35081f7d1e77STheodore Ts'o */ 35091f7d1e77STheodore Ts'o #define ext4_check_indirect_blockref(inode, bh) \ 35101f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 35111f7d1e77STheodore Ts'o (__le32 *)(bh)->b_data, \ 35121f7d1e77STheodore Ts'o EXT4_ADDR_PER_BLOCK((inode)->i_sb)) 35131f7d1e77STheodore Ts'o 35141f7d1e77STheodore Ts'o #define ext4_ind_check_inode(inode) \ 35151f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 35161f7d1e77STheodore Ts'o EXT4_I(inode)->i_data, \ 35171f7d1e77STheodore Ts'o EXT4_NDIR_BLOCKS) 35181f7d1e77STheodore Ts'o 35191f7d1e77STheodore Ts'o /* 35203dcf5451SChristoph Hellwig * Inodes and files operations 35213dcf5451SChristoph Hellwig */ 35223dcf5451SChristoph Hellwig 35233dcf5451SChristoph Hellwig /* dir.c */ 35243dcf5451SChristoph Hellwig extern const struct file_operations ext4_dir_operations; 35253dcf5451SChristoph Hellwig 35263dcf5451SChristoph Hellwig /* file.c */ 35273dcf5451SChristoph Hellwig extern const struct inode_operations ext4_file_inode_operations; 35283dcf5451SChristoph Hellwig extern const struct file_operations ext4_file_operations; 3529e0d10bfaSToshiyuki Okajima extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin); 35303dcf5451SChristoph Hellwig 353195eaefbdSTheodore Ts'o /* inline.c */ 353295eaefbdSTheodore Ts'o extern int ext4_get_max_inline_size(struct inode *inode); 353395eaefbdSTheodore Ts'o extern int ext4_find_inline_data_nolock(struct inode *inode); 353495eaefbdSTheodore Ts'o extern int ext4_init_inline_data(handle_t *handle, struct inode *inode, 353595eaefbdSTheodore Ts'o unsigned int len); 353695eaefbdSTheodore Ts'o extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode); 353795eaefbdSTheodore Ts'o 353895eaefbdSTheodore Ts'o extern int ext4_readpage_inline(struct inode *inode, struct page *page); 353995eaefbdSTheodore Ts'o extern int ext4_try_to_write_inline_data(struct address_space *mapping, 354095eaefbdSTheodore Ts'o struct inode *inode, 354195eaefbdSTheodore Ts'o loff_t pos, unsigned len, 354295eaefbdSTheodore Ts'o struct page **pagep); 354395eaefbdSTheodore Ts'o extern int ext4_write_inline_data_end(struct inode *inode, 354495eaefbdSTheodore Ts'o loff_t pos, unsigned len, 354595eaefbdSTheodore Ts'o unsigned copied, 354695eaefbdSTheodore Ts'o struct page *page); 354795eaefbdSTheodore Ts'o extern struct buffer_head * 354895eaefbdSTheodore Ts'o ext4_journalled_write_inline_data(struct inode *inode, 354995eaefbdSTheodore Ts'o unsigned len, 355095eaefbdSTheodore Ts'o struct page *page); 355195eaefbdSTheodore Ts'o extern int ext4_da_write_inline_data_begin(struct address_space *mapping, 355295eaefbdSTheodore Ts'o struct inode *inode, 355395eaefbdSTheodore Ts'o loff_t pos, unsigned len, 355495eaefbdSTheodore Ts'o struct page **pagep, 355595eaefbdSTheodore Ts'o void **fsdata); 35565b643f9cSTheodore Ts'o extern int ext4_try_add_inline_entry(handle_t *handle, 35575b643f9cSTheodore Ts'o struct ext4_filename *fname, 355856a04915STheodore Ts'o struct inode *dir, struct inode *inode); 355995eaefbdSTheodore Ts'o extern int ext4_try_create_inline_dir(handle_t *handle, 356095eaefbdSTheodore Ts'o struct inode *parent, 356195eaefbdSTheodore Ts'o struct inode *inode); 356295eaefbdSTheodore Ts'o extern int ext4_read_inline_dir(struct file *filp, 3563725bebb2SAl Viro struct dir_context *ctx, 356495eaefbdSTheodore Ts'o int *has_inline_data); 35657633b08bSTheodore Ts'o extern int ext4_inlinedir_to_tree(struct file *dir_file, 35668af0f082STao Ma struct inode *dir, ext4_lblk_t block, 35678af0f082STao Ma struct dx_hash_info *hinfo, 35688af0f082STao Ma __u32 start_hash, __u32 start_minor_hash, 35698af0f082STao Ma int *has_inline_data); 357095eaefbdSTheodore Ts'o extern struct buffer_head *ext4_find_inline_entry(struct inode *dir, 35715b643f9cSTheodore Ts'o struct ext4_filename *fname, 357295eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **res_dir, 357395eaefbdSTheodore Ts'o int *has_inline_data); 357495eaefbdSTheodore Ts'o extern int ext4_delete_inline_entry(handle_t *handle, 357595eaefbdSTheodore Ts'o struct inode *dir, 357695eaefbdSTheodore Ts'o struct ext4_dir_entry_2 *de_del, 357795eaefbdSTheodore Ts'o struct buffer_head *bh, 357895eaefbdSTheodore Ts'o int *has_inline_data); 3579a7550b30SJaegeuk Kim extern bool empty_inline_dir(struct inode *dir, int *has_inline_data); 358095eaefbdSTheodore Ts'o extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode, 358195eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **parent_de, 358295eaefbdSTheodore Ts'o int *retval); 358395eaefbdSTheodore Ts'o extern int ext4_inline_data_fiemap(struct inode *inode, 358495eaefbdSTheodore Ts'o struct fiemap_extent_info *fieinfo, 3585d952d69eSDmitry Monakhov int *has_inline, __u64 start, __u64 len); 3586*5a57bca9SZhang Yi extern void *ext4_read_inline_link(struct inode *inode); 35877046ae35SAndreas Gruenbacher 35887046ae35SAndreas Gruenbacher struct iomap; 35897046ae35SAndreas Gruenbacher extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap); 35907046ae35SAndreas Gruenbacher 359101daf945STheodore Ts'o extern int ext4_inline_data_truncate(struct inode *inode, int *has_inline); 359295eaefbdSTheodore Ts'o 359395eaefbdSTheodore Ts'o extern int ext4_convert_inline_data(struct inode *inode); 359495eaefbdSTheodore Ts'o 359583447ccbSZheng Liu static inline int ext4_has_inline_data(struct inode *inode) 359683447ccbSZheng Liu { 359783447ccbSZheng Liu return ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA) && 359883447ccbSZheng Liu EXT4_I(inode)->i_inline_off; 359983447ccbSZheng Liu } 360083447ccbSZheng Liu 36013dcf5451SChristoph Hellwig /* namei.c */ 36023dcf5451SChristoph Hellwig extern const struct inode_operations ext4_dir_inode_operations; 36033dcf5451SChristoph Hellwig extern const struct inode_operations ext4_special_inode_operations; 3604596397b7STheodore Ts'o extern struct dentry *ext4_get_parent(struct dentry *child); 3605a774f9c2STao Ma extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode, 3606a774f9c2STao Ma struct ext4_dir_entry_2 *de, 3607a774f9c2STao Ma int blocksize, int csum_size, 3608a774f9c2STao Ma unsigned int parent_ino, int dotdot_real_len); 3609ddce3b94STheodore Ts'o extern void ext4_initialize_dirent_tail(struct buffer_head *bh, 36103c47d541STao Ma unsigned int blocksize); 3611f036adb3STheodore Ts'o extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode, 36123c47d541STao Ma struct buffer_head *bh); 3613a80f7fcfSHarshad Shirwadkar extern int __ext4_unlink(handle_t *handle, struct inode *dir, const struct qstr *d_name, 36148016e29fSHarshad Shirwadkar struct inode *inode); 36158016e29fSHarshad Shirwadkar extern int __ext4_link(struct inode *dir, struct inode *inode, 36168016e29fSHarshad Shirwadkar struct dentry *dentry); 3617b886ee3eSGabriel Krisman Bertazi 36188af0f082STao Ma #define S_SHIFT 12 3619381cebfeSDan Carpenter static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { 36208af0f082STao Ma [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, 36218af0f082STao Ma [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, 36228af0f082STao Ma [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, 36238af0f082STao Ma [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, 36248af0f082STao Ma [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, 36258af0f082STao Ma [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, 36268af0f082STao Ma [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, 36278af0f082STao Ma }; 36288af0f082STao Ma 36298af0f082STao Ma static inline void ext4_set_de_type(struct super_block *sb, 36308af0f082STao Ma struct ext4_dir_entry_2 *de, 36318af0f082STao Ma umode_t mode) { 3632e2b911c5SDarrick J. Wong if (ext4_has_feature_filetype(sb)) 36338af0f082STao Ma de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 36348af0f082STao Ma } 36358af0f082STao Ma 3636f64e02feSTheodore Ts'o /* readpages.c */ 3637a07f624bSMatthew Wilcox (Oracle) extern int ext4_mpage_readpages(struct inode *inode, 36386311f91fSMatthew Wilcox (Oracle) struct readahead_control *rac, struct page *page); 363922cfe4b4SEric Biggers extern int __init ext4_init_post_read_processing(void); 364022cfe4b4SEric Biggers extern void ext4_exit_post_read_processing(void); 36413dcf5451SChristoph Hellwig 36423dcf5451SChristoph Hellwig /* symlink.c */ 3643a7a67e8aSAl Viro extern const struct inode_operations ext4_encrypted_symlink_inode_operations; 36443dcf5451SChristoph Hellwig extern const struct inode_operations ext4_symlink_inode_operations; 36453dcf5451SChristoph Hellwig extern const struct inode_operations ext4_fast_symlink_inode_operations; 36463dcf5451SChristoph Hellwig 3647b5799018STheodore Ts'o /* sysfs.c */ 3648d578b994SJonathan Davies extern void ext4_notify_error_sysfs(struct ext4_sb_info *sbi); 3649b5799018STheodore Ts'o extern int ext4_register_sysfs(struct super_block *sb); 3650ebd173beSTheodore Ts'o extern void ext4_unregister_sysfs(struct super_block *sb); 3651b5799018STheodore Ts'o extern int __init ext4_init_sysfs(void); 3652b5799018STheodore Ts'o extern void ext4_exit_sysfs(void); 3653b5799018STheodore Ts'o 36546fd058f7STheodore Ts'o /* block_validity */ 36556fd058f7STheodore Ts'o extern void ext4_release_system_zone(struct super_block *sb); 36566fd058f7STheodore Ts'o extern int ext4_setup_system_zone(struct super_block *sb); 36575dabfc78STheodore Ts'o extern int __init ext4_init_system_zone(void); 36585dabfc78STheodore Ts'o extern void ext4_exit_system_zone(void); 3659ce9f24ccSJan Kara extern int ext4_inode_block_valid(struct inode *inode, 36606fd058f7STheodore Ts'o ext4_fsblk_t start_blk, 36616fd058f7STheodore Ts'o unsigned int count); 36621f7d1e77STheodore Ts'o extern int ext4_check_blockref(const char *, unsigned int, 36631f7d1e77STheodore Ts'o struct inode *, __le32 *, unsigned int); 36646bc6c2bdSRitesh Harjani extern int ext4_sb_block_valid(struct super_block *sb, struct inode *inode, 36656bc6c2bdSRitesh Harjani ext4_fsblk_t start_blk, unsigned int count); 36666bc6c2bdSRitesh Harjani 36676fd058f7STheodore Ts'o 36683dcf5451SChristoph Hellwig /* extents.c */ 36694a092d73STheodore Ts'o struct ext4_ext_path; 36704a092d73STheodore Ts'o struct ext4_extent; 36714a092d73STheodore Ts'o 3672d7b2a00cSZheng Liu /* 3673d7b2a00cSZheng Liu * Maximum number of logical blocks in a file; ext4_extent's ee_block is 3674d7b2a00cSZheng Liu * __le32. 3675d7b2a00cSZheng Liu */ 3676d7b2a00cSZheng Liu #define EXT_MAX_BLOCKS 0xffffffff 3677d7b2a00cSZheng Liu 36784209ae12SHarshad Shirwadkar extern void ext4_ext_tree_init(handle_t *handle, struct inode *inode); 3679fffb2739SJan Kara extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents); 3680e35fd660STheodore Ts'o extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, 3681e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 3682d0abb36dSTheodore Ts'o extern int ext4_ext_truncate(handle_t *, struct inode *); 368326a4c0c6STheodore Ts'o extern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, 368426a4c0c6STheodore Ts'o ext4_lblk_t end); 36853dcf5451SChristoph Hellwig extern void ext4_ext_init(struct super_block *); 36863dcf5451SChristoph Hellwig extern void ext4_ext_release(struct super_block *); 36872fe17c10SChristoph Hellwig extern long ext4_fallocate(struct file *file, int mode, loff_t offset, 36883dcf5451SChristoph Hellwig loff_t len); 36896b523df4SJan Kara extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode, 36906b523df4SJan Kara loff_t offset, ssize_t len); 3691a00713eaSRitesh Harjani extern int ext4_convert_unwritten_io_end_vec(handle_t *handle, 3692a00713eaSRitesh Harjani ext4_io_end_t *io_end); 3693e35fd660STheodore Ts'o extern int ext4_map_blocks(handle_t *handle, struct inode *inode, 3694e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 36954a092d73STheodore Ts'o extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, 36964a092d73STheodore Ts'o int num, 36974a092d73STheodore Ts'o struct ext4_ext_path *path); 36984a092d73STheodore Ts'o extern int ext4_ext_insert_extent(handle_t *, struct inode *, 3699dfe50809STheodore Ts'o struct ext4_ext_path **, 37004a092d73STheodore Ts'o struct ext4_extent *, int); 3701ed8a1a76STheodore Ts'o extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, 3702705912caSTheodore Ts'o struct ext4_ext_path **, 3703107a7bd3STheodore Ts'o int flags); 37044a092d73STheodore Ts'o extern void ext4_ext_drop_refs(struct ext4_ext_path *); 37054a092d73STheodore Ts'o extern int ext4_ext_check_inode(struct inode *inode); 3706fcf6b1b7SDmitry Monakhov extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path); 37073a06d778SAneesh Kumar K.V extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 37083a06d778SAneesh Kumar K.V __u64 start, __u64 len); 3709bb5835edSTheodore Ts'o extern int ext4_get_es_cache(struct inode *inode, 3710bb5835edSTheodore Ts'o struct fiemap_extent_info *fieinfo, 3711bb5835edSTheodore Ts'o __u64 start, __u64 len); 37127869a4a6STheodore Ts'o extern int ext4_ext_precache(struct inode *inode); 3713fcf6b1b7SDmitry Monakhov extern int ext4_swap_extents(handle_t *handle, struct inode *inode1, 3714fcf6b1b7SDmitry Monakhov struct inode *inode2, ext4_lblk_t lblk1, 3715fcf6b1b7SDmitry Monakhov ext4_lblk_t lblk2, ext4_lblk_t count, 3716fcf6b1b7SDmitry Monakhov int mark_unwritten,int *err); 37170b02f4c0SEric Whitney extern int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu); 3718a4130367SJan Kara extern int ext4_datasem_ensure_credits(handle_t *handle, struct inode *inode, 371983448bdfSJan Kara int check_cred, int restart_cred, 372083448bdfSJan Kara int revoke_cred); 37218016e29fSHarshad Shirwadkar extern void ext4_ext_replay_shrink_inode(struct inode *inode, ext4_lblk_t end); 37228016e29fSHarshad Shirwadkar extern int ext4_ext_replay_set_iblocks(struct inode *inode); 37238016e29fSHarshad Shirwadkar extern int ext4_ext_replay_update_ex(struct inode *inode, ext4_lblk_t start, 37248016e29fSHarshad Shirwadkar int len, int unwritten, ext4_fsblk_t pblk); 37258016e29fSHarshad Shirwadkar extern int ext4_ext_clear_bb(struct inode *inode); 3726a4130367SJan Kara 37274a092d73STheodore Ts'o 3728748de673SAkira Fujita /* move_extent.c */ 3729393d1d1dSDr. Tilmann Bubeck extern void ext4_double_down_write_data_sem(struct inode *first, 3730393d1d1dSDr. Tilmann Bubeck struct inode *second); 3731393d1d1dSDr. Tilmann Bubeck extern void ext4_double_up_write_data_sem(struct inode *orig_inode, 3732393d1d1dSDr. Tilmann Bubeck struct inode *donor_inode); 3733748de673SAkira Fujita extern int ext4_move_extents(struct file *o_filp, struct file *d_filp, 3734748de673SAkira Fujita __u64 start_orig, __u64 start_donor, 3735748de673SAkira Fujita __u64 len, __u64 *moved_len); 3736748de673SAkira Fujita 3737bd2d0210STheodore Ts'o /* page-io.c */ 37385dabfc78STheodore Ts'o extern int __init ext4_init_pageio(void); 37395dabfc78STheodore Ts'o extern void ext4_exit_pageio(void); 3740bd2d0210STheodore Ts'o extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags); 374197a851edSJan Kara extern ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end); 374297a851edSJan Kara extern int ext4_put_io_end(ext4_io_end_t *io_end); 374397a851edSJan Kara extern void ext4_put_io_end_defer(ext4_io_end_t *io_end); 374497a851edSJan Kara extern void ext4_io_submit_init(struct ext4_io_submit *io, 374597a851edSJan Kara struct writeback_control *wbc); 37462e8fa54eSJan Kara extern void ext4_end_io_rsv_work(struct work_struct *work); 3747bd2d0210STheodore Ts'o extern void ext4_io_submit(struct ext4_io_submit *io); 3748bd2d0210STheodore Ts'o extern int ext4_bio_write_page(struct ext4_io_submit *io, 3749bd2d0210STheodore Ts'o struct page *page, 3750bd2d0210STheodore Ts'o int len, 37511c8349a1SNamjae Jeon bool keep_towrite); 3752c8cc8816SRitesh Harjani extern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end); 3753c8cc8816SRitesh Harjani extern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end); 37543a06d778SAneesh Kumar K.V 3755c5e06d10SJohann Lombardi /* mmp.c */ 3756c5e06d10SJohann Lombardi extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); 3757c5e06d10SJohann Lombardi 3758618f0031SPavel Skripkin /* mmp.c */ 3759618f0031SPavel Skripkin extern void ext4_stop_mmpd(struct ext4_sb_info *sbi); 3760618f0031SPavel Skripkin 3761c93d8f88SEric Biggers /* verity.c */ 3762c93d8f88SEric Biggers extern const struct fsverity_operations ext4_verityops; 3763c93d8f88SEric Biggers 376425c6d98fSJan Kara /* orphan.c */ 376525c6d98fSJan Kara extern int ext4_orphan_add(handle_t *, struct inode *); 376625c6d98fSJan Kara extern int ext4_orphan_del(handle_t *, struct inode *); 376725c6d98fSJan Kara extern void ext4_orphan_cleanup(struct super_block *sb, 376825c6d98fSJan Kara struct ext4_super_block *es); 376902f310fcSJan Kara extern void ext4_release_orphan_info(struct super_block *sb); 377002f310fcSJan Kara extern int ext4_init_orphan_info(struct super_block *sb); 377102f310fcSJan Kara extern int ext4_orphan_file_empty(struct super_block *sb); 377202f310fcSJan Kara extern void ext4_orphan_file_block_trigger( 377302f310fcSJan Kara struct jbd2_buffer_trigger_type *triggers, 377402f310fcSJan Kara struct buffer_head *bh, 377502f310fcSJan Kara void *data, size_t size); 377625c6d98fSJan Kara 37773613d228SJan Kara /* 377848fc7f7eSAdam Buchbinder * Add new method to test whether block and inode bitmaps are properly 37792ccb5fb9SAneesh Kumar K.V * initialized. With uninit_bg reading the block from disk is not enough 37802ccb5fb9SAneesh Kumar K.V * to mark the bitmap uptodate. We need to also zero-out the bitmap 37812ccb5fb9SAneesh Kumar K.V */ 37822ccb5fb9SAneesh Kumar K.V #define BH_BITMAP_UPTODATE BH_JBDPrivateStart 37832ccb5fb9SAneesh Kumar K.V 37842ccb5fb9SAneesh Kumar K.V static inline int bitmap_uptodate(struct buffer_head *bh) 37852ccb5fb9SAneesh Kumar K.V { 37862ccb5fb9SAneesh Kumar K.V return (buffer_uptodate(bh) && 37872ccb5fb9SAneesh Kumar K.V test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state)); 37882ccb5fb9SAneesh Kumar K.V } 37892ccb5fb9SAneesh Kumar K.V static inline void set_bitmap_uptodate(struct buffer_head *bh) 37902ccb5fb9SAneesh Kumar K.V { 37912ccb5fb9SAneesh Kumar K.V set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); 37922ccb5fb9SAneesh Kumar K.V } 37932ccb5fb9SAneesh Kumar K.V 3794731eb1a0SAkinobu Mita #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) 3795731eb1a0SAkinobu Mita 3796e9e3bcecSEric Sandeen /* For ioend & aio unwritten conversion wait queues */ 3797e9e3bcecSEric Sandeen #define EXT4_WQ_HASH_SZ 37 3798e9e3bcecSEric Sandeen #define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\ 3799e9e3bcecSEric Sandeen EXT4_WQ_HASH_SZ]) 3800e9e3bcecSEric Sandeen extern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; 3801e9e3bcecSEric Sandeen 38028f82f840SYongqiang Yang extern int ext4_resize_begin(struct super_block *sb); 38038f82f840SYongqiang Yang extern void ext4_resize_end(struct super_block *sb); 38048f82f840SYongqiang Yang 380574c66bcbSJan Kara static inline void ext4_set_io_unwritten_flag(struct inode *inode, 380674c66bcbSJan Kara struct ext4_io_end *io_end) 380774c66bcbSJan Kara { 380874c66bcbSJan Kara if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 380974c66bcbSJan Kara io_end->flag |= EXT4_IO_END_UNWRITTEN; 381074c66bcbSJan Kara atomic_inc(&EXT4_I(inode)->i_unwritten); 381174c66bcbSJan Kara } 381274c66bcbSJan Kara } 381374c66bcbSJan Kara 381474c66bcbSJan Kara static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) 381574c66bcbSJan Kara { 381674c66bcbSJan Kara struct inode *inode = io_end->inode; 381774c66bcbSJan Kara 381874c66bcbSJan Kara if (io_end->flag & EXT4_IO_END_UNWRITTEN) { 381974c66bcbSJan Kara io_end->flag &= ~EXT4_IO_END_UNWRITTEN; 382074c66bcbSJan Kara /* Wake up anyone waiting on unwritten extent conversion */ 382174c66bcbSJan Kara if (atomic_dec_and_test(&EXT4_I(inode)->i_unwritten)) 382274c66bcbSJan Kara wake_up_all(ext4_ioend_wq(inode)); 382374c66bcbSJan Kara } 382474c66bcbSJan Kara } 382574c66bcbSJan Kara 38268ff6daa1SChristoph Hellwig extern const struct iomap_ops ext4_iomap_ops; 38278cd115bdSJan Kara extern const struct iomap_ops ext4_iomap_overwrite_ops; 382809edf4d3SMatthew Bobrowski extern const struct iomap_ops ext4_iomap_report_ops; 3829364443cbSJan Kara 38307963e5acSZhangXiaoxu static inline int ext4_buffer_uptodate(struct buffer_head *bh) 38317963e5acSZhangXiaoxu { 38327963e5acSZhangXiaoxu /* 38337963e5acSZhangXiaoxu * If the buffer has the write error flag, we have failed 38347963e5acSZhangXiaoxu * to write out data in the block. In this case, we don't 38357963e5acSZhangXiaoxu * have to read the block because we may read the old data 38367963e5acSZhangXiaoxu * successfully. 38377963e5acSZhangXiaoxu */ 38385c680150SJoseph Qi if (buffer_write_io_error(bh)) 38397963e5acSZhangXiaoxu set_buffer_uptodate(bh); 38407963e5acSZhangXiaoxu return buffer_uptodate(bh); 38417963e5acSZhangXiaoxu } 38427963e5acSZhangXiaoxu 38433dcf5451SChristoph Hellwig #endif /* __KERNEL__ */ 38443dcf5451SChristoph Hellwig 38456a797d27SDarrick J. Wong #define EFSBADCRC EBADMSG /* Bad CRC detected */ 38466a797d27SDarrick J. Wong #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 38476a797d27SDarrick J. Wong 38483dcf5451SChristoph Hellwig #endif /* _EXT4_H */ 3849