13dcf5451SChristoph Hellwig /* 23dcf5451SChristoph Hellwig * ext4.h 33dcf5451SChristoph Hellwig * 43dcf5451SChristoph Hellwig * Copyright (C) 1992, 1993, 1994, 1995 53dcf5451SChristoph Hellwig * Remy Card (card@masi.ibp.fr) 63dcf5451SChristoph Hellwig * Laboratoire MASI - Institut Blaise Pascal 73dcf5451SChristoph Hellwig * Universite Pierre et Marie Curie (Paris VI) 83dcf5451SChristoph Hellwig * 93dcf5451SChristoph Hellwig * from 103dcf5451SChristoph Hellwig * 113dcf5451SChristoph Hellwig * linux/include/linux/minix_fs.h 123dcf5451SChristoph Hellwig * 133dcf5451SChristoph Hellwig * Copyright (C) 1991, 1992 Linus Torvalds 143dcf5451SChristoph Hellwig */ 153dcf5451SChristoph Hellwig 163dcf5451SChristoph Hellwig #ifndef _EXT4_H 173dcf5451SChristoph Hellwig #define _EXT4_H 183dcf5451SChristoph Hellwig 193dcf5451SChristoph Hellwig #include <linux/types.h> 203dcf5451SChristoph Hellwig #include <linux/blkdev.h> 213dcf5451SChristoph Hellwig #include <linux/magic.h> 222ccb5fb9SAneesh Kumar K.V #include <linux/jbd2.h> 2360e58e0fSMingming Cao #include <linux/quota.h> 24d444c3c3STheodore Ts'o #include <linux/rwsem.h> 25d444c3c3STheodore Ts'o #include <linux/rbtree.h> 26d444c3c3STheodore Ts'o #include <linux/seqlock.h> 27d444c3c3STheodore Ts'o #include <linux/mutex.h> 28ca0faba0STheodore Ts'o #include <linux/timer.h> 29ca0faba0STheodore Ts'o #include <linux/wait.h> 30ca0faba0STheodore Ts'o #include <linux/blockgroup_lock.h> 31ca0faba0STheodore Ts'o #include <linux/percpu_counter.h> 32efbed4dcSTheodore Ts'o #include <linux/ratelimit.h> 330441984aSDarrick J. Wong #include <crypto/hash.h> 34a633f5a3SLukas Czerner #include <linux/falloc.h> 354d92dc0fSBen Hutchings #ifdef __KERNEL__ 364d92dc0fSBen Hutchings #include <linux/compat.h> 374d92dc0fSBen Hutchings #endif 383dcf5451SChristoph Hellwig 393dcf5451SChristoph Hellwig /* 408a35694eSShen Feng * The fourth extended filesystem constants/structures 413dcf5451SChristoph Hellwig */ 423dcf5451SChristoph Hellwig 433dcf5451SChristoph Hellwig /* 443dcf5451SChristoph Hellwig * Define EXT4FS_DEBUG to produce debug messages 453dcf5451SChristoph Hellwig */ 463dcf5451SChristoph Hellwig #undef EXT4FS_DEBUG 473dcf5451SChristoph Hellwig 483dcf5451SChristoph Hellwig /* 493dcf5451SChristoph Hellwig * Debug code 503dcf5451SChristoph Hellwig */ 513dcf5451SChristoph Hellwig #ifdef EXT4FS_DEBUG 523dcf5451SChristoph Hellwig #define ext4_debug(f, a...) \ 533dcf5451SChristoph Hellwig do { \ 543dcf5451SChristoph Hellwig printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \ 554db9c54aSStoyan Gaydarov __FILE__, __LINE__, __func__); \ 563dcf5451SChristoph Hellwig printk(KERN_DEBUG f, ## a); \ 573dcf5451SChristoph Hellwig } while (0) 583dcf5451SChristoph Hellwig #else 59ace36ad4SJoe Perches #define ext4_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 603dcf5451SChristoph Hellwig #endif 613dcf5451SChristoph Hellwig 624a092d73STheodore Ts'o /* 634a092d73STheodore Ts'o * Turn on EXT_DEBUG to get lots of info about extents operations. 644a092d73STheodore Ts'o */ 654a092d73STheodore Ts'o #define EXT_DEBUG__ 664a092d73STheodore Ts'o #ifdef EXT_DEBUG 674a092d73STheodore Ts'o #define ext_debug(fmt, ...) printk(fmt, ##__VA_ARGS__) 684a092d73STheodore Ts'o #else 694a092d73STheodore Ts'o #define ext_debug(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 704a092d73STheodore Ts'o #endif 714a092d73STheodore Ts'o 72273df556SFrank Mayhar #define EXT4_ERROR_INODE(inode, fmt, a...) \ 73c398eda0STheodore Ts'o ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a) 74c398eda0STheodore Ts'o 75c398eda0STheodore Ts'o #define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \ 76c398eda0STheodore Ts'o ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a) 77273df556SFrank Mayhar 78f7c21177STheodore Ts'o #define EXT4_ERROR_FILE(file, block, fmt, a...) \ 79f7c21177STheodore Ts'o ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a) 80273df556SFrank Mayhar 81d444c3c3STheodore Ts'o /* data type for block offset of block group */ 82d444c3c3STheodore Ts'o typedef int ext4_grpblk_t; 83d444c3c3STheodore Ts'o 84d444c3c3STheodore Ts'o /* data type for filesystem-wide blocks number */ 85d444c3c3STheodore Ts'o typedef unsigned long long ext4_fsblk_t; 86d444c3c3STheodore Ts'o 87d444c3c3STheodore Ts'o /* data type for file logical block number */ 88d444c3c3STheodore Ts'o typedef __u32 ext4_lblk_t; 89d444c3c3STheodore Ts'o 90d444c3c3STheodore Ts'o /* data type for block group number */ 91d444c3c3STheodore Ts'o typedef unsigned int ext4_group_t; 92d444c3c3STheodore Ts'o 93296c355cSTheodore Ts'o /* 94296c355cSTheodore Ts'o * Flags used in mballoc's allocation_context flags field. 95296c355cSTheodore Ts'o * 96296c355cSTheodore Ts'o * Also used to show what's going on for debugging purposes when the 97296c355cSTheodore Ts'o * flag field is exported via the traceport interface 98296c355cSTheodore Ts'o */ 99d444c3c3STheodore Ts'o 1003dcf5451SChristoph Hellwig /* prefer goal again. length */ 1010ef90db9STheodore Ts'o #define EXT4_MB_HINT_MERGE 0x0001 1023dcf5451SChristoph Hellwig /* blocks already reserved */ 1030ef90db9STheodore Ts'o #define EXT4_MB_HINT_RESERVED 0x0002 1043dcf5451SChristoph Hellwig /* metadata is being allocated */ 1050ef90db9STheodore Ts'o #define EXT4_MB_HINT_METADATA 0x0004 1063dcf5451SChristoph Hellwig /* first blocks in the file */ 1070ef90db9STheodore Ts'o #define EXT4_MB_HINT_FIRST 0x0008 1083dcf5451SChristoph Hellwig /* search for the best chunk */ 1090ef90db9STheodore Ts'o #define EXT4_MB_HINT_BEST 0x0010 1103dcf5451SChristoph Hellwig /* data is being allocated */ 1110ef90db9STheodore Ts'o #define EXT4_MB_HINT_DATA 0x0020 1123dcf5451SChristoph Hellwig /* don't preallocate (for tails) */ 1130ef90db9STheodore Ts'o #define EXT4_MB_HINT_NOPREALLOC 0x0040 1143dcf5451SChristoph Hellwig /* allocate for locality group */ 1150ef90db9STheodore Ts'o #define EXT4_MB_HINT_GROUP_ALLOC 0x0080 1163dcf5451SChristoph Hellwig /* allocate goal blocks or none */ 1170ef90db9STheodore Ts'o #define EXT4_MB_HINT_GOAL_ONLY 0x0100 1183dcf5451SChristoph Hellwig /* goal is meaningful */ 1190ef90db9STheodore Ts'o #define EXT4_MB_HINT_TRY_GOAL 0x0200 120d2a17637SMingming Cao /* blocks already pre-reserved by delayed allocation */ 1210ef90db9STheodore Ts'o #define EXT4_MB_DELALLOC_RESERVED 0x0400 1224ba74d00STheodore Ts'o /* We are doing stream allocation */ 1234ba74d00STheodore Ts'o #define EXT4_MB_STREAM_ALLOC 0x0800 12455f020dbSAllison Henderson /* Use reserved root blocks if needed */ 12555f020dbSAllison Henderson #define EXT4_MB_USE_ROOT_BLOCKS 0x1000 12627dd4385SLukas Czerner /* Use blocks from reserved pool */ 12727dd4385SLukas Czerner #define EXT4_MB_USE_RESERVED 0x2000 1283dcf5451SChristoph Hellwig 1293dcf5451SChristoph Hellwig struct ext4_allocation_request { 1303dcf5451SChristoph Hellwig /* target inode for block we're allocating */ 1313dcf5451SChristoph Hellwig struct inode *inode; 1323dcf5451SChristoph Hellwig /* how many blocks we want to allocate */ 133498e5f24STheodore Ts'o unsigned int len; 134726447d8SEric Sandeen /* logical block in target inode */ 135726447d8SEric Sandeen ext4_lblk_t logical; 136726447d8SEric Sandeen /* the closest logical allocated block to the left */ 137726447d8SEric Sandeen ext4_lblk_t lleft; 138726447d8SEric Sandeen /* the closest logical allocated block to the right */ 139726447d8SEric Sandeen ext4_lblk_t lright; 140726447d8SEric Sandeen /* phys. target (a hint) */ 141726447d8SEric Sandeen ext4_fsblk_t goal; 142726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the left */ 143726447d8SEric Sandeen ext4_fsblk_t pleft; 144726447d8SEric Sandeen /* phys. block for the closest logical allocated block to the right */ 145726447d8SEric Sandeen ext4_fsblk_t pright; 1463dcf5451SChristoph Hellwig /* flags. see above EXT4_MB_HINT_* */ 147498e5f24STheodore Ts'o unsigned int flags; 1483dcf5451SChristoph Hellwig }; 1493dcf5451SChristoph Hellwig 1503dcf5451SChristoph Hellwig /* 151e35fd660STheodore Ts'o * Logical to physical block mapping, used by ext4_map_blocks() 152e35fd660STheodore Ts'o * 153e35fd660STheodore Ts'o * This structure is used to pass requests into ext4_map_blocks() as 154e35fd660STheodore Ts'o * well as to store the information returned by ext4_map_blocks(). It 155e35fd660STheodore Ts'o * takes less room on the stack than a struct buffer_head. 156e35fd660STheodore Ts'o */ 157e35fd660STheodore Ts'o #define EXT4_MAP_NEW (1 << BH_New) 158e35fd660STheodore Ts'o #define EXT4_MAP_MAPPED (1 << BH_Mapped) 159e35fd660STheodore Ts'o #define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten) 160e35fd660STheodore Ts'o #define EXT4_MAP_BOUNDARY (1 << BH_Boundary) 161e35fd660STheodore Ts'o #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\ 162cbd7584eSJan Kara EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY) 163e35fd660STheodore Ts'o 164e35fd660STheodore Ts'o struct ext4_map_blocks { 165e35fd660STheodore Ts'o ext4_fsblk_t m_pblk; 166e35fd660STheodore Ts'o ext4_lblk_t m_lblk; 167e35fd660STheodore Ts'o unsigned int m_len; 168e35fd660STheodore Ts'o unsigned int m_flags; 169e35fd660STheodore Ts'o }; 170e35fd660STheodore Ts'o 171e35fd660STheodore Ts'o /* 172bd2d0210STheodore Ts'o * Flags for ext4_io_end->flags 173bd2d0210STheodore Ts'o */ 174bd2d0210STheodore Ts'o #define EXT4_IO_END_UNWRITTEN 0x0001 175bd2d0210STheodore Ts'o 1764188188bSCurt Wohlgemuth /* 177556615dcSLukas Czerner * For converting unwritten extents on a work queue. 'handle' is used for 1786b523df4SJan Kara * buffered writeback. 1794188188bSCurt Wohlgemuth */ 1800031462bSMingming Cao typedef struct ext4_io_end { 1815b3ff237Sjiayingz@google.com (Jiaying Zhang) struct list_head list; /* per-file finished IO list */ 1826b523df4SJan Kara handle_t *handle; /* handle reserved for extent 1836b523df4SJan Kara * conversion */ 1840031462bSMingming Cao struct inode *inode; /* file being written to */ 185b0857d30SJan Kara struct bio *bio; /* Linked list of completed 186b0857d30SJan Kara * bios covering the extent */ 1878d5d02e6SMingming Cao unsigned int flag; /* unwritten or not */ 188a1de02dcSEric Sandeen loff_t offset; /* offset in the file */ 189a1de02dcSEric Sandeen ssize_t size; /* size of the extent */ 19097a851edSJan Kara atomic_t count; /* reference counter */ 1910031462bSMingming Cao } ext4_io_end_t; 1920031462bSMingming Cao 193bd2d0210STheodore Ts'o struct ext4_io_submit { 194bd2d0210STheodore Ts'o int io_op; 195bd2d0210STheodore Ts'o struct bio *io_bio; 196bd2d0210STheodore Ts'o ext4_io_end_t *io_end; 197bd2d0210STheodore Ts'o sector_t io_next_block; 198bd2d0210STheodore Ts'o }; 199bd2d0210STheodore Ts'o 200b3a3ca8cSTheodore Ts'o /* 2013dcf5451SChristoph Hellwig * Special inodes numbers 2023dcf5451SChristoph Hellwig */ 2033dcf5451SChristoph Hellwig #define EXT4_BAD_INO 1 /* Bad blocks inode */ 2043dcf5451SChristoph Hellwig #define EXT4_ROOT_INO 2 /* Root inode */ 205ae812306SAditya Kali #define EXT4_USR_QUOTA_INO 3 /* User quota inode */ 206ae812306SAditya Kali #define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */ 2073dcf5451SChristoph Hellwig #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */ 2083dcf5451SChristoph Hellwig #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */ 2093dcf5451SChristoph Hellwig #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */ 2103dcf5451SChristoph Hellwig #define EXT4_JOURNAL_INO 8 /* Journal inode */ 2113dcf5451SChristoph Hellwig 2123dcf5451SChristoph Hellwig /* First non-reserved inode for old ext4 filesystems */ 2133dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_FIRST_INO 11 2143dcf5451SChristoph Hellwig 2153dcf5451SChristoph Hellwig /* 2163dcf5451SChristoph Hellwig * Maximal count of links to a file 2173dcf5451SChristoph Hellwig */ 2183dcf5451SChristoph Hellwig #define EXT4_LINK_MAX 65000 2193dcf5451SChristoph Hellwig 2203dcf5451SChristoph Hellwig /* 2213dcf5451SChristoph Hellwig * Macro-instructions used to manage several block sizes 2223dcf5451SChristoph Hellwig */ 2233dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_SIZE 1024 2243dcf5451SChristoph Hellwig #define EXT4_MAX_BLOCK_SIZE 65536 2253dcf5451SChristoph Hellwig #define EXT4_MIN_BLOCK_LOG_SIZE 10 226fb1813f4SCurt Wohlgemuth #define EXT4_MAX_BLOCK_LOG_SIZE 16 2273dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2283dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize) 2293dcf5451SChristoph Hellwig #else 2303dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size) 2313dcf5451SChristoph Hellwig #endif 2323dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32)) 233281b5995STheodore Ts'o #define EXT4_CLUSTER_SIZE(s) (EXT4_BLOCK_SIZE(s) << \ 234281b5995STheodore Ts'o EXT4_SB(s)->s_cluster_bits) 2353dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2363dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 237281b5995STheodore Ts'o # define EXT4_CLUSTER_BITS(s) (EXT4_SB(s)->s_cluster_bits) 2383dcf5451SChristoph Hellwig #else 2393dcf5451SChristoph Hellwig # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 2403dcf5451SChristoph Hellwig #endif 2413dcf5451SChristoph Hellwig #ifdef __KERNEL__ 2423dcf5451SChristoph Hellwig #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits) 2433dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size) 2443dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino) 2453dcf5451SChristoph Hellwig #else 2463dcf5451SChristoph Hellwig #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 2473dcf5451SChristoph Hellwig EXT4_GOOD_OLD_INODE_SIZE : \ 2483dcf5451SChristoph Hellwig (s)->s_inode_size) 2493dcf5451SChristoph Hellwig #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \ 2503dcf5451SChristoph Hellwig EXT4_GOOD_OLD_FIRST_INO : \ 2513dcf5451SChristoph Hellwig (s)->s_first_ino) 2523dcf5451SChristoph Hellwig #endif 2533dcf5451SChristoph Hellwig #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 2543dcf5451SChristoph Hellwig 255d5b8f310STheodore Ts'o /* Translate a block number to a cluster number */ 256d5b8f310STheodore Ts'o #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) 257d5b8f310STheodore Ts'o /* Translate a cluster number to a block number */ 258d5b8f310STheodore Ts'o #define EXT4_C2B(sbi, cluster) ((cluster) << (sbi)->s_cluster_bits) 259d5b8f310STheodore Ts'o /* Translate # of blks to # of clusters */ 260d5b8f310STheodore Ts'o #define EXT4_NUM_B2C(sbi, blks) (((blks) + (sbi)->s_cluster_ratio - 1) >> \ 261d5b8f310STheodore Ts'o (sbi)->s_cluster_bits) 262f5a44db5STheodore Ts'o /* Mask out the low bits to get the starting block of the cluster */ 263f5a44db5STheodore Ts'o #define EXT4_PBLK_CMASK(s, pblk) ((pblk) & \ 264f5a44db5STheodore Ts'o ~((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 265f5a44db5STheodore Ts'o #define EXT4_LBLK_CMASK(s, lblk) ((lblk) & \ 266f5a44db5STheodore Ts'o ~((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 267f5a44db5STheodore Ts'o /* Get the cluster offset */ 268f5a44db5STheodore Ts'o #define EXT4_PBLK_COFF(s, pblk) ((pblk) & \ 269f5a44db5STheodore Ts'o ((ext4_fsblk_t) (s)->s_cluster_ratio - 1)) 270f5a44db5STheodore Ts'o #define EXT4_LBLK_COFF(s, lblk) ((lblk) & \ 271f5a44db5STheodore Ts'o ((ext4_lblk_t) (s)->s_cluster_ratio - 1)) 272d5b8f310STheodore Ts'o 2733dcf5451SChristoph Hellwig /* 2743dcf5451SChristoph Hellwig * Structure of a blocks group descriptor 2753dcf5451SChristoph Hellwig */ 2763dcf5451SChristoph Hellwig struct ext4_group_desc 2773dcf5451SChristoph Hellwig { 2783dcf5451SChristoph Hellwig __le32 bg_block_bitmap_lo; /* Blocks bitmap block */ 2793dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */ 2803dcf5451SChristoph Hellwig __le32 bg_inode_table_lo; /* Inodes table block */ 281560671a0SAneesh Kumar K.V __le16 bg_free_blocks_count_lo;/* Free blocks count */ 282560671a0SAneesh Kumar K.V __le16 bg_free_inodes_count_lo;/* Free inodes count */ 283560671a0SAneesh Kumar K.V __le16 bg_used_dirs_count_lo; /* Directories count */ 2843dcf5451SChristoph Hellwig __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 285e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ 286e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */ 287e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */ 288560671a0SAneesh Kumar K.V __le16 bg_itable_unused_lo; /* Unused inodes count */ 2893dcf5451SChristoph Hellwig __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 2903dcf5451SChristoph Hellwig __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 2913dcf5451SChristoph Hellwig __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ 2923dcf5451SChristoph Hellwig __le32 bg_inode_table_hi; /* Inodes table block MSB */ 2933dcf5451SChristoph Hellwig __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ 2943dcf5451SChristoph Hellwig __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 2953dcf5451SChristoph Hellwig __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 2963dcf5451SChristoph Hellwig __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 297e6153918SDarrick J. Wong __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ 298e6153918SDarrick J. Wong __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */ 299e6153918SDarrick J. Wong __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */ 300e6153918SDarrick J. Wong __u32 bg_reserved; 3013dcf5451SChristoph Hellwig }; 3023dcf5451SChristoph Hellwig 30341a246d1SDarrick J. Wong #define EXT4_BG_INODE_BITMAP_CSUM_HI_END \ 30441a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \ 30541a246d1SDarrick J. Wong sizeof(__le16)) 30641a246d1SDarrick J. Wong #define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \ 30741a246d1SDarrick J. Wong (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \ 30841a246d1SDarrick J. Wong sizeof(__le16)) 30941a246d1SDarrick J. Wong 310772cb7c8SJose R. Santos /* 311772cb7c8SJose R. Santos * Structure of a flex block group info 312772cb7c8SJose R. Santos */ 313772cb7c8SJose R. Santos 314772cb7c8SJose R. Santos struct flex_groups { 31590ba983fSTheodore Ts'o atomic64_t free_clusters; 3169f24e420STheodore Ts'o atomic_t free_inodes; 3177d39db14STheodore Ts'o atomic_t used_dirs; 318772cb7c8SJose R. Santos }; 319772cb7c8SJose R. Santos 3203dcf5451SChristoph Hellwig #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 3213dcf5451SChristoph Hellwig #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 3223dcf5451SChristoph Hellwig #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 3233dcf5451SChristoph Hellwig 3243dcf5451SChristoph Hellwig /* 3253dcf5451SChristoph Hellwig * Macro-instructions used to manage group descriptors 3263dcf5451SChristoph Hellwig */ 3273dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE 32 3283dcf5451SChristoph Hellwig #define EXT4_MIN_DESC_SIZE_64BIT 64 3293dcf5451SChristoph Hellwig #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE 3303dcf5451SChristoph Hellwig #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size) 3313dcf5451SChristoph Hellwig #ifdef __KERNEL__ 3323dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group) 333281b5995STheodore Ts'o # define EXT4_CLUSTERS_PER_GROUP(s) (EXT4_SB(s)->s_clusters_per_group) 3343dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block) 3353dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group) 3363dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits) 3373dcf5451SChristoph Hellwig #else 3383dcf5451SChristoph Hellwig # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 3393dcf5451SChristoph Hellwig # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s)) 3403dcf5451SChristoph Hellwig # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 3413dcf5451SChristoph Hellwig #endif 3423dcf5451SChristoph Hellwig 3433dcf5451SChristoph Hellwig /* 3443dcf5451SChristoph Hellwig * Constants relative to the data blocks 3453dcf5451SChristoph Hellwig */ 3463dcf5451SChristoph Hellwig #define EXT4_NDIR_BLOCKS 12 3473dcf5451SChristoph Hellwig #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS 3483dcf5451SChristoph Hellwig #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) 3493dcf5451SChristoph Hellwig #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) 3503dcf5451SChristoph Hellwig #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) 3513dcf5451SChristoph Hellwig 3523dcf5451SChristoph Hellwig /* 3533dcf5451SChristoph Hellwig * Inode flags 3543dcf5451SChristoph Hellwig */ 3553dcf5451SChristoph Hellwig #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */ 3563dcf5451SChristoph Hellwig #define EXT4_UNRM_FL 0x00000002 /* Undelete */ 3573dcf5451SChristoph Hellwig #define EXT4_COMPR_FL 0x00000004 /* Compress file */ 3583dcf5451SChristoph Hellwig #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */ 3593dcf5451SChristoph Hellwig #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */ 3603dcf5451SChristoph Hellwig #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */ 3613dcf5451SChristoph Hellwig #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */ 3623dcf5451SChristoph Hellwig #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */ 3633dcf5451SChristoph Hellwig /* Reserved for compression usage... */ 3643dcf5451SChristoph Hellwig #define EXT4_DIRTY_FL 0x00000100 3653dcf5451SChristoph Hellwig #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 3663dcf5451SChristoph Hellwig #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */ 3673edc18d8STheodore Ts'o /* nb: was previously EXT2_ECOMPR_FL */ 3683edc18d8STheodore Ts'o #define EXT4_ENCRYPT_FL 0x00000800 /* encrypted file */ 3693dcf5451SChristoph Hellwig /* End compression flags --- maybe not all used */ 3703dcf5451SChristoph Hellwig #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */ 3713dcf5451SChristoph Hellwig #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */ 3723dcf5451SChristoph Hellwig #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 3733dcf5451SChristoph Hellwig #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 3743dcf5451SChristoph Hellwig #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 3753dcf5451SChristoph Hellwig #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 3763dcf5451SChristoph Hellwig #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 3773dcf5451SChristoph Hellwig #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 378f710b4b9STheodore Ts'o #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 379c8d46e41SJiaying Zhang #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */ 38067cf5b09STao Ma #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ 3813dcf5451SChristoph Hellwig #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 3823dcf5451SChristoph Hellwig 383c8d46e41SJiaying Zhang #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */ 384996bb9fdSTheodore Ts'o #define EXT4_FL_USER_MODIFIABLE 0x004380FF /* User modifiable flags */ 3853dcf5451SChristoph Hellwig 3868fa43a81SDuane Griffin /* Flags that should be inherited by new inodes from their parent. */ 3878fa43a81SDuane Griffin #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\ 3881cd9f097STheodore Ts'o EXT4_SYNC_FL | EXT4_NODUMP_FL | EXT4_NOATIME_FL |\ 3898fa43a81SDuane Griffin EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\ 3908fa43a81SDuane Griffin EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL) 3918fa43a81SDuane Griffin 3922dc6b0d4SDuane Griffin /* Flags that are appropriate for regular files (all but dir-specific ones). */ 3932dc6b0d4SDuane Griffin #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL)) 3942dc6b0d4SDuane Griffin 3952dc6b0d4SDuane Griffin /* Flags that are appropriate for non-directories/regular files. */ 3962dc6b0d4SDuane Griffin #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) 3972dc6b0d4SDuane Griffin 3982dc6b0d4SDuane Griffin /* Mask out flags that are inappropriate for the given type of inode. */ 3992dc6b0d4SDuane Griffin static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) 4002dc6b0d4SDuane Griffin { 4012dc6b0d4SDuane Griffin if (S_ISDIR(mode)) 4022dc6b0d4SDuane Griffin return flags; 4032dc6b0d4SDuane Griffin else if (S_ISREG(mode)) 4042dc6b0d4SDuane Griffin return flags & EXT4_REG_FLMASK; 4052dc6b0d4SDuane Griffin else 4062dc6b0d4SDuane Griffin return flags & EXT4_OTHER_FLMASK; 4072dc6b0d4SDuane Griffin } 4082dc6b0d4SDuane Griffin 40912e9b892SDmitry Monakhov /* 41012e9b892SDmitry Monakhov * Inode flags used for atomic set/get 41112e9b892SDmitry Monakhov */ 41212e9b892SDmitry Monakhov enum { 41312e9b892SDmitry Monakhov EXT4_INODE_SECRM = 0, /* Secure deletion */ 41412e9b892SDmitry Monakhov EXT4_INODE_UNRM = 1, /* Undelete */ 41512e9b892SDmitry Monakhov EXT4_INODE_COMPR = 2, /* Compress file */ 41612e9b892SDmitry Monakhov EXT4_INODE_SYNC = 3, /* Synchronous updates */ 41712e9b892SDmitry Monakhov EXT4_INODE_IMMUTABLE = 4, /* Immutable file */ 41812e9b892SDmitry Monakhov EXT4_INODE_APPEND = 5, /* writes to file may only append */ 41912e9b892SDmitry Monakhov EXT4_INODE_NODUMP = 6, /* do not dump file */ 42012e9b892SDmitry Monakhov EXT4_INODE_NOATIME = 7, /* do not update atime */ 42112e9b892SDmitry Monakhov /* Reserved for compression usage... */ 42212e9b892SDmitry Monakhov EXT4_INODE_DIRTY = 8, 42312e9b892SDmitry Monakhov EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */ 42412e9b892SDmitry Monakhov EXT4_INODE_NOCOMPR = 10, /* Don't compress */ 425f542fbe8STheodore Ts'o EXT4_INODE_ENCRYPT = 11, /* Encrypted file */ 42612e9b892SDmitry Monakhov /* End compression flags --- maybe not all used */ 42712e9b892SDmitry Monakhov EXT4_INODE_INDEX = 12, /* hash-indexed directory */ 42812e9b892SDmitry Monakhov EXT4_INODE_IMAGIC = 13, /* AFS directory */ 42912e9b892SDmitry Monakhov EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */ 43012e9b892SDmitry Monakhov EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */ 43112e9b892SDmitry Monakhov EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */ 43212e9b892SDmitry Monakhov EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/ 43312e9b892SDmitry Monakhov EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */ 43412e9b892SDmitry Monakhov EXT4_INODE_EXTENTS = 19, /* Inode uses extents */ 43512e9b892SDmitry Monakhov EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */ 43612e9b892SDmitry Monakhov EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */ 43767cf5b09STao Ma EXT4_INODE_INLINE_DATA = 28, /* Data in inode. */ 43812e9b892SDmitry Monakhov EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ 43912e9b892SDmitry Monakhov }; 44012e9b892SDmitry Monakhov 44112e9b892SDmitry Monakhov /* 4429a4c8019SCarlos Maiolino * Since it's pretty easy to mix up bit numbers and hex values, we use a 4439a4c8019SCarlos Maiolino * build-time check to make sure that EXT4_XXX_FL is consistent with respect to 4449a4c8019SCarlos Maiolino * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost 4459a4c8019SCarlos Maiolino * any extra space in the compiled kernel image, otherwise, the build will fail. 4469a4c8019SCarlos Maiolino * It's important that these values are the same, since we are using 4479a4c8019SCarlos Maiolino * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent 4489a4c8019SCarlos Maiolino * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk 4499a4c8019SCarlos Maiolino * values found in ext2, ext3 and ext4 filesystems, and of course the values 4509a4c8019SCarlos Maiolino * defined in e2fsprogs. 45112e9b892SDmitry Monakhov * 45212e9b892SDmitry Monakhov * It's not paranoia if the Murphy's Law really *is* out to get you. :-) 45312e9b892SDmitry Monakhov */ 4549a4c8019SCarlos Maiolino #define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) 4559a4c8019SCarlos Maiolino #define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) 4569a4c8019SCarlos Maiolino 45712e9b892SDmitry Monakhov static inline void ext4_check_flag_values(void) 45812e9b892SDmitry Monakhov { 45912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SECRM); 46012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(UNRM); 46112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPR); 46212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(SYNC); 46312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMMUTABLE); 46412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(APPEND); 46512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NODUMP); 46612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOATIME); 46712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRTY); 46812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(COMPRBLK); 46912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOCOMPR); 4703edc18d8STheodore Ts'o CHECK_FLAG_VALUE(ENCRYPT); 47112e9b892SDmitry Monakhov CHECK_FLAG_VALUE(INDEX); 47212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(IMAGIC); 47312e9b892SDmitry Monakhov CHECK_FLAG_VALUE(JOURNAL_DATA); 47412e9b892SDmitry Monakhov CHECK_FLAG_VALUE(NOTAIL); 47512e9b892SDmitry Monakhov CHECK_FLAG_VALUE(DIRSYNC); 47612e9b892SDmitry Monakhov CHECK_FLAG_VALUE(TOPDIR); 47712e9b892SDmitry Monakhov CHECK_FLAG_VALUE(HUGE_FILE); 47812e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EXTENTS); 47912e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EA_INODE); 48012e9b892SDmitry Monakhov CHECK_FLAG_VALUE(EOFBLOCKS); 48167cf5b09STao Ma CHECK_FLAG_VALUE(INLINE_DATA); 48212e9b892SDmitry Monakhov CHECK_FLAG_VALUE(RESERVED); 48312e9b892SDmitry Monakhov } 48412e9b892SDmitry Monakhov 4853dcf5451SChristoph Hellwig /* Used to pass group descriptor data when online resize is done */ 4863dcf5451SChristoph Hellwig struct ext4_new_group_input { 4873dcf5451SChristoph Hellwig __u32 group; /* Group number for this data */ 4883dcf5451SChristoph Hellwig __u64 block_bitmap; /* Absolute block number of block bitmap */ 4893dcf5451SChristoph Hellwig __u64 inode_bitmap; /* Absolute block number of inode bitmap */ 4903dcf5451SChristoph Hellwig __u64 inode_table; /* Absolute block number of inode table start */ 4913dcf5451SChristoph Hellwig __u32 blocks_count; /* Total number of blocks in this group */ 4923dcf5451SChristoph Hellwig __u16 reserved_blocks; /* Number of reserved blocks in this group */ 4933dcf5451SChristoph Hellwig __u16 unused; 4943dcf5451SChristoph Hellwig }; 4953dcf5451SChristoph Hellwig 4964d92dc0fSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 4974d92dc0fSBen Hutchings struct compat_ext4_new_group_input { 4984d92dc0fSBen Hutchings u32 group; 4994d92dc0fSBen Hutchings compat_u64 block_bitmap; 5004d92dc0fSBen Hutchings compat_u64 inode_bitmap; 5014d92dc0fSBen Hutchings compat_u64 inode_table; 5024d92dc0fSBen Hutchings u32 blocks_count; 5034d92dc0fSBen Hutchings u16 reserved_blocks; 5044d92dc0fSBen Hutchings u16 unused; 5054d92dc0fSBen Hutchings }; 5064d92dc0fSBen Hutchings #endif 5074d92dc0fSBen Hutchings 5083dcf5451SChristoph Hellwig /* The struct ext4_new_group_input in kernel space, with free_blocks_count */ 5093dcf5451SChristoph Hellwig struct ext4_new_group_data { 5103dcf5451SChristoph Hellwig __u32 group; 5113dcf5451SChristoph Hellwig __u64 block_bitmap; 5123dcf5451SChristoph Hellwig __u64 inode_bitmap; 5133dcf5451SChristoph Hellwig __u64 inode_table; 5143dcf5451SChristoph Hellwig __u32 blocks_count; 5153dcf5451SChristoph Hellwig __u16 reserved_blocks; 5163dcf5451SChristoph Hellwig __u16 unused; 5173dcf5451SChristoph Hellwig __u32 free_blocks_count; 5183dcf5451SChristoph Hellwig }; 5193dcf5451SChristoph Hellwig 52033afdcc5SYongqiang Yang /* Indexes used to index group tables in ext4_new_group_data */ 52133afdcc5SYongqiang Yang enum { 52233afdcc5SYongqiang Yang BLOCK_BITMAP = 0, /* block bitmap */ 52333afdcc5SYongqiang Yang INODE_BITMAP, /* inode bitmap */ 52433afdcc5SYongqiang Yang INODE_TABLE, /* inode tables */ 52533afdcc5SYongqiang Yang GROUP_TABLE_COUNT, 52633afdcc5SYongqiang Yang }; 52733afdcc5SYongqiang Yang 5283dcf5451SChristoph Hellwig /* 52979e83036SEric Sandeen * Flags used by ext4_map_blocks() 5303dcf5451SChristoph Hellwig */ 531556615dcSLukas Czerner /* Allocate any needed blocks and/or convert an unwritten 532c2177057STheodore Ts'o extent to be an initialized ext4 */ 5332ac3b6e0STheodore Ts'o #define EXT4_GET_BLOCKS_CREATE 0x0001 534556615dcSLukas Czerner /* Request the creation of an unwritten extent */ 535556615dcSLukas Czerner #define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002 536556615dcSLukas Czerner #define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\ 537c2177057STheodore Ts'o EXT4_GET_BLOCKS_CREATE) 53827dd4385SLukas Czerner /* Caller is from the delayed allocation writeout path 53927dd4385SLukas Czerner * finally doing the actual allocation of delayed blocks */ 54003f5d8bcSJan Kara #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004 5410031462bSMingming Cao /* caller is from the direct IO path, request to creation of an 542556615dcSLukas Czerner unwritten extents if not allocated, split the unwritten 5430031462bSMingming Cao extent if blocks has been preallocated already*/ 544c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_PRE_IO 0x0008 5451296cc85SAneesh Kumar K.V #define EXT4_GET_BLOCKS_CONVERT 0x0010 546c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\ 547556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 548c7064ef1SJiaying Zhang /* Convert extent to initialized after IO complete */ 549c7064ef1SJiaying Zhang #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\ 550556615dcSLukas Czerner EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) 55127dd4385SLukas Czerner /* Eventual metadata allocation (due to growing extent tree) 55227dd4385SLukas Czerner * should not fail, so try to use reserved blocks for that.*/ 55327dd4385SLukas Czerner #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020 554556b27abSVivek Haldar /* Don't normalize allocation size (used for fallocate) */ 555556b27abSVivek Haldar #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040 556a4e5d88bSDmitry Monakhov /* Request will not result in inode size update (user for fallocate) */ 557a4e5d88bSDmitry Monakhov #define EXT4_GET_BLOCKS_KEEP_SIZE 0x0080 558729f52c6SZheng Liu /* Do not take i_data_sem locking in ext4_map_blocks */ 559729f52c6SZheng Liu #define EXT4_GET_BLOCKS_NO_LOCK 0x0100 560b8a86845SLukas Czerner /* Convert written extents to unwritten */ 5612f8e0a7cSZheng Liu #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0200 5623dcf5451SChristoph Hellwig 5633dcf5451SChristoph Hellwig /* 5647869a4a6STheodore Ts'o * The bit position of these flags must not overlap with any of the 565ed8a1a76STheodore Ts'o * EXT4_GET_BLOCKS_*. They are used by ext4_find_extent(), 566107a7bd3STheodore Ts'o * read_extent_tree_block(), ext4_split_extent_at(), 5677869a4a6STheodore Ts'o * ext4_ext_insert_extent(), and ext4_ext_create_new_leaf(). 5687869a4a6STheodore Ts'o * EXT4_EX_NOCACHE is used to indicate that the we shouldn't be 5697869a4a6STheodore Ts'o * caching the extents when reading from the extent tree while a 5707869a4a6STheodore Ts'o * truncate or punch hole operation is in progress. 571107a7bd3STheodore Ts'o */ 572d26e2c4dSTheodore Ts'o #define EXT4_EX_NOCACHE 0x40000000 573d26e2c4dSTheodore Ts'o #define EXT4_EX_FORCE_CACHE 0x20000000 574107a7bd3STheodore Ts'o 575107a7bd3STheodore Ts'o /* 576e6362609STheodore Ts'o * Flags used by ext4_free_blocks 577e6362609STheodore Ts'o */ 578e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_METADATA 0x0001 579e6362609STheodore Ts'o #define EXT4_FREE_BLOCKS_FORGET 0x0002 5801f2acb60STheodore Ts'o #define EXT4_FREE_BLOCKS_VALIDATED 0x0004 5817132de74SMaxim Patlasov #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008 58284130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010 58384130193STheodore Ts'o #define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020 584e6362609STheodore Ts'o 585f542fbe8STheodore Ts'o /* Encryption algorithms */ 586f542fbe8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_INVALID 0 587f542fbe8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_XTS 1 588f542fbe8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_GCM 2 589f542fbe8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_CBC 3 590f542fbe8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_CTS 4 591f542fbe8STheodore Ts'o 5929bd8212fSMichael Halcrow #include "ext4_crypto.h" 5939bd8212fSMichael Halcrow 594e6362609STheodore Ts'o /* 5953dcf5451SChristoph Hellwig * ioctl commands 5963dcf5451SChristoph Hellwig */ 5973dcf5451SChristoph Hellwig #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS 5983dcf5451SChristoph Hellwig #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS 5993dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION _IOR('f', 3, long) 6003dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION _IOW('f', 4, long) 6013dcf5451SChristoph Hellwig #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION 6023dcf5451SChristoph Hellwig #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION 6033dcf5451SChristoph Hellwig #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long) 6043dcf5451SChristoph Hellwig #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) 6058eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) 6068eea80d5STheodore Ts'o #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input) 6078eea80d5STheodore Ts'o #define EXT4_IOC_MIGRATE _IO('f', 9) 608ccd2506bSTheodore Ts'o /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */ 6098eea80d5STheodore Ts'o /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ 610ccd2506bSTheodore Ts'o #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) 611748de673SAkira Fujita #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) 61219c5246dSYongqiang Yang #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) 613393d1d1dSDr. Tilmann Bubeck #define EXT4_IOC_SWAP_BOOT _IO('f', 17) 6147869a4a6STheodore Ts'o #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18) 6159bd8212fSMichael Halcrow #define EXT4_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct ext4_encryption_policy) 6169bd8212fSMichael Halcrow #define EXT4_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16]) 6179bd8212fSMichael Halcrow #define EXT4_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct ext4_encryption_policy) 6183dcf5451SChristoph Hellwig 619899ad0ceSBen Hutchings #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 6203dcf5451SChristoph Hellwig /* 6213dcf5451SChristoph Hellwig * ioctl commands in 32 bit emulation 6223dcf5451SChristoph Hellwig */ 6233dcf5451SChristoph Hellwig #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS 6243dcf5451SChristoph Hellwig #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS 6253dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION _IOR('f', 3, int) 6263dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION _IOW('f', 4, int) 6273dcf5451SChristoph Hellwig #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int) 6283dcf5451SChristoph Hellwig #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int) 6293dcf5451SChristoph Hellwig #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 6304d92dc0fSBen Hutchings #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input) 6313dcf5451SChristoph Hellwig #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 6323dcf5451SChristoph Hellwig #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 633899ad0ceSBen Hutchings #endif 6343dcf5451SChristoph Hellwig 635b595076aSUwe Kleine-König /* Max physical block we can address w/o extents */ 636fb0a387dSEric Sandeen #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF 637fb0a387dSEric Sandeen 6383dcf5451SChristoph Hellwig /* 6393dcf5451SChristoph Hellwig * Structure of an inode on the disk 6403dcf5451SChristoph Hellwig */ 6413dcf5451SChristoph Hellwig struct ext4_inode { 6423dcf5451SChristoph Hellwig __le16 i_mode; /* File mode */ 6433dcf5451SChristoph Hellwig __le16 i_uid; /* Low 16 bits of Owner Uid */ 6443dcf5451SChristoph Hellwig __le32 i_size_lo; /* Size in bytes */ 6453dcf5451SChristoph Hellwig __le32 i_atime; /* Access time */ 6463dcf5451SChristoph Hellwig __le32 i_ctime; /* Inode Change time */ 6473dcf5451SChristoph Hellwig __le32 i_mtime; /* Modification time */ 6483dcf5451SChristoph Hellwig __le32 i_dtime; /* Deletion Time */ 6493dcf5451SChristoph Hellwig __le16 i_gid; /* Low 16 bits of Group Id */ 6503dcf5451SChristoph Hellwig __le16 i_links_count; /* Links count */ 6513dcf5451SChristoph Hellwig __le32 i_blocks_lo; /* Blocks count */ 6523dcf5451SChristoph Hellwig __le32 i_flags; /* File flags */ 6533dcf5451SChristoph Hellwig union { 6543dcf5451SChristoph Hellwig struct { 6553dcf5451SChristoph Hellwig __le32 l_i_version; 6563dcf5451SChristoph Hellwig } linux1; 6573dcf5451SChristoph Hellwig struct { 6583dcf5451SChristoph Hellwig __u32 h_i_translator; 6593dcf5451SChristoph Hellwig } hurd1; 6603dcf5451SChristoph Hellwig struct { 6613dcf5451SChristoph Hellwig __u32 m_i_reserved1; 6623dcf5451SChristoph Hellwig } masix1; 6633dcf5451SChristoph Hellwig } osd1; /* OS dependent 1 */ 6643dcf5451SChristoph Hellwig __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */ 6653dcf5451SChristoph Hellwig __le32 i_generation; /* File version (for NFS) */ 6663dcf5451SChristoph Hellwig __le32 i_file_acl_lo; /* File ACL */ 6673dcf5451SChristoph Hellwig __le32 i_size_high; 6683dcf5451SChristoph Hellwig __le32 i_obso_faddr; /* Obsoleted fragment address */ 6693dcf5451SChristoph Hellwig union { 6703dcf5451SChristoph Hellwig struct { 6713dcf5451SChristoph Hellwig __le16 l_i_blocks_high; /* were l_i_reserved1 */ 6723dcf5451SChristoph Hellwig __le16 l_i_file_acl_high; 6733dcf5451SChristoph Hellwig __le16 l_i_uid_high; /* these 2 fields */ 6743dcf5451SChristoph Hellwig __le16 l_i_gid_high; /* were reserved2[0] */ 675e6153918SDarrick J. Wong __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */ 676e6153918SDarrick J. Wong __le16 l_i_reserved; 6773dcf5451SChristoph Hellwig } linux2; 6783dcf5451SChristoph Hellwig struct { 6793dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 6803dcf5451SChristoph Hellwig __u16 h_i_mode_high; 6813dcf5451SChristoph Hellwig __u16 h_i_uid_high; 6823dcf5451SChristoph Hellwig __u16 h_i_gid_high; 6833dcf5451SChristoph Hellwig __u32 h_i_author; 6843dcf5451SChristoph Hellwig } hurd2; 6853dcf5451SChristoph Hellwig struct { 6863dcf5451SChristoph Hellwig __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 6873dcf5451SChristoph Hellwig __le16 m_i_file_acl_high; 6883dcf5451SChristoph Hellwig __u32 m_i_reserved2[2]; 6893dcf5451SChristoph Hellwig } masix2; 6903dcf5451SChristoph Hellwig } osd2; /* OS dependent 2 */ 6913dcf5451SChristoph Hellwig __le16 i_extra_isize; 692e6153918SDarrick J. Wong __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ 6933dcf5451SChristoph Hellwig __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 6943dcf5451SChristoph Hellwig __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 6953dcf5451SChristoph Hellwig __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 6963dcf5451SChristoph Hellwig __le32 i_crtime; /* File Creation time */ 6973dcf5451SChristoph Hellwig __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 6983dcf5451SChristoph Hellwig __le32 i_version_hi; /* high 32 bits for 64-bit version */ 6993dcf5451SChristoph Hellwig }; 7003dcf5451SChristoph Hellwig 701748de673SAkira Fujita struct move_extent { 702748de673SAkira Fujita __u32 reserved; /* should be zero */ 703748de673SAkira Fujita __u32 donor_fd; /* donor file descriptor */ 704748de673SAkira Fujita __u64 orig_start; /* logical start offset in block for orig */ 705748de673SAkira Fujita __u64 donor_start; /* logical start offset in block for donor */ 706748de673SAkira Fujita __u64 len; /* block length to be moved */ 707748de673SAkira Fujita __u64 moved_len; /* moved block length */ 708748de673SAkira Fujita }; 7093dcf5451SChristoph Hellwig 7103dcf5451SChristoph Hellwig #define EXT4_EPOCH_BITS 2 7113dcf5451SChristoph Hellwig #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) 7123dcf5451SChristoph Hellwig #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) 7133dcf5451SChristoph Hellwig 7143dcf5451SChristoph Hellwig /* 7153dcf5451SChristoph Hellwig * Extended fields will fit into an inode if the filesystem was formatted 7163dcf5451SChristoph Hellwig * with large inodes (-I 256 or larger) and there are not currently any EAs 7173dcf5451SChristoph Hellwig * consuming all of the available space. For new inodes we always reserve 7183dcf5451SChristoph Hellwig * enough space for the kernel's known extended fields, but for inodes 7193dcf5451SChristoph Hellwig * created with an old kernel this might not have been the case. None of 7203dcf5451SChristoph Hellwig * the extended inode fields is critical for correct filesystem operation. 7213dcf5451SChristoph Hellwig * This macro checks if a certain field fits in the inode. Note that 7223dcf5451SChristoph Hellwig * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize 7233dcf5451SChristoph Hellwig */ 7243dcf5451SChristoph Hellwig #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \ 7253dcf5451SChristoph Hellwig ((offsetof(typeof(*ext4_inode), field) + \ 7263dcf5451SChristoph Hellwig sizeof((ext4_inode)->field)) \ 7273dcf5451SChristoph Hellwig <= (EXT4_GOOD_OLD_INODE_SIZE + \ 7283dcf5451SChristoph Hellwig (einode)->i_extra_isize)) \ 7293dcf5451SChristoph Hellwig 7303dcf5451SChristoph Hellwig static inline __le32 ext4_encode_extra_time(struct timespec *time) 7313dcf5451SChristoph Hellwig { 7323dcf5451SChristoph Hellwig return cpu_to_le32((sizeof(time->tv_sec) > 4 ? 733c1fccc06STheodore Ts'o (time->tv_sec >> 32) & EXT4_EPOCH_MASK : 0) | 734c1fccc06STheodore Ts'o ((time->tv_nsec << EXT4_EPOCH_BITS) & EXT4_NSEC_MASK)); 7353dcf5451SChristoph Hellwig } 7363dcf5451SChristoph Hellwig 7373dcf5451SChristoph Hellwig static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) 7383dcf5451SChristoph Hellwig { 7393dcf5451SChristoph Hellwig if (sizeof(time->tv_sec) > 4) 7403dcf5451SChristoph Hellwig time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) 7413dcf5451SChristoph Hellwig << 32; 742c1fccc06STheodore Ts'o time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; 7433dcf5451SChristoph Hellwig } 7443dcf5451SChristoph Hellwig 7453dcf5451SChristoph Hellwig #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \ 7463dcf5451SChristoph Hellwig do { \ 7473dcf5451SChristoph Hellwig (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ 7483dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \ 7493dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 7503dcf5451SChristoph Hellwig ext4_encode_extra_time(&(inode)->xtime); \ 7513dcf5451SChristoph Hellwig } while (0) 7523dcf5451SChristoph Hellwig 7533dcf5451SChristoph Hellwig #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \ 7543dcf5451SChristoph Hellwig do { \ 7553dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 7563dcf5451SChristoph Hellwig (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \ 7573dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 7583dcf5451SChristoph Hellwig (raw_inode)->xtime ## _extra = \ 7593dcf5451SChristoph Hellwig ext4_encode_extra_time(&(einode)->xtime); \ 7603dcf5451SChristoph Hellwig } while (0) 7613dcf5451SChristoph Hellwig 7623dcf5451SChristoph Hellwig #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \ 7633dcf5451SChristoph Hellwig do { \ 7643dcf5451SChristoph Hellwig (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ 7653dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \ 7663dcf5451SChristoph Hellwig ext4_decode_extra_time(&(inode)->xtime, \ 7673dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 768af0b44a1SEric Sandeen else \ 769af0b44a1SEric Sandeen (inode)->xtime.tv_nsec = 0; \ 7703dcf5451SChristoph Hellwig } while (0) 7713dcf5451SChristoph Hellwig 7723dcf5451SChristoph Hellwig #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \ 7733dcf5451SChristoph Hellwig do { \ 7743dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \ 7753dcf5451SChristoph Hellwig (einode)->xtime.tv_sec = \ 7763dcf5451SChristoph Hellwig (signed)le32_to_cpu((raw_inode)->xtime); \ 77719ea8060STheodore Ts'o else \ 77819ea8060STheodore Ts'o (einode)->xtime.tv_sec = 0; \ 7793dcf5451SChristoph Hellwig if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \ 7803dcf5451SChristoph Hellwig ext4_decode_extra_time(&(einode)->xtime, \ 7813dcf5451SChristoph Hellwig raw_inode->xtime ## _extra); \ 782af0b44a1SEric Sandeen else \ 783af0b44a1SEric Sandeen (einode)->xtime.tv_nsec = 0; \ 7843dcf5451SChristoph Hellwig } while (0) 7853dcf5451SChristoph Hellwig 7863dcf5451SChristoph Hellwig #define i_disk_version osd1.linux1.l_i_version 7873dcf5451SChristoph Hellwig 7883dcf5451SChristoph Hellwig #if defined(__KERNEL__) || defined(__linux__) 7893dcf5451SChristoph Hellwig #define i_reserved1 osd1.linux1.l_i_reserved1 7903dcf5451SChristoph Hellwig #define i_file_acl_high osd2.linux2.l_i_file_acl_high 7913dcf5451SChristoph Hellwig #define i_blocks_high osd2.linux2.l_i_blocks_high 7923dcf5451SChristoph Hellwig #define i_uid_low i_uid 7933dcf5451SChristoph Hellwig #define i_gid_low i_gid 7943dcf5451SChristoph Hellwig #define i_uid_high osd2.linux2.l_i_uid_high 7953dcf5451SChristoph Hellwig #define i_gid_high osd2.linux2.l_i_gid_high 796e6153918SDarrick J. Wong #define i_checksum_lo osd2.linux2.l_i_checksum_lo 7973dcf5451SChristoph Hellwig 7983dcf5451SChristoph Hellwig #elif defined(__GNU__) 7993dcf5451SChristoph Hellwig 8003dcf5451SChristoph Hellwig #define i_translator osd1.hurd1.h_i_translator 8013dcf5451SChristoph Hellwig #define i_uid_high osd2.hurd2.h_i_uid_high 8023dcf5451SChristoph Hellwig #define i_gid_high osd2.hurd2.h_i_gid_high 8033dcf5451SChristoph Hellwig #define i_author osd2.hurd2.h_i_author 8043dcf5451SChristoph Hellwig 8053dcf5451SChristoph Hellwig #elif defined(__masix__) 8063dcf5451SChristoph Hellwig 8073dcf5451SChristoph Hellwig #define i_reserved1 osd1.masix1.m_i_reserved1 8083dcf5451SChristoph Hellwig #define i_file_acl_high osd2.masix2.m_i_file_acl_high 8093dcf5451SChristoph Hellwig #define i_reserved2 osd2.masix2.m_i_reserved2 8103dcf5451SChristoph Hellwig 8113dcf5451SChristoph Hellwig #endif /* defined(__KERNEL__) || defined(__linux__) */ 8123dcf5451SChristoph Hellwig 813c0677e6dSZheng Liu #include "extents_status.h" 814c0677e6dSZheng Liu 815d444c3c3STheodore Ts'o /* 816d444c3c3STheodore Ts'o * fourth extended file system inode data in memory 817d444c3c3STheodore Ts'o */ 818d444c3c3STheodore Ts'o struct ext4_inode_info { 819d444c3c3STheodore Ts'o __le32 i_data[15]; /* unconverted */ 820d444c3c3STheodore Ts'o __u32 i_dtime; 82112e9b892SDmitry Monakhov ext4_fsblk_t i_file_acl; 822d444c3c3STheodore Ts'o 823d444c3c3STheodore Ts'o /* 824d444c3c3STheodore Ts'o * i_block_group is the number of the block group which contains 825d444c3c3STheodore Ts'o * this file's inode. Constant across the lifetime of the inode, 826d444c3c3STheodore Ts'o * it is ued for making block allocation decisions - we try to 827d444c3c3STheodore Ts'o * place a file's data blocks near its inode block, and new inodes 828d444c3c3STheodore Ts'o * near to their parent directory's inode. 829d444c3c3STheodore Ts'o */ 830d444c3c3STheodore Ts'o ext4_group_t i_block_group; 8318a2005d3STheodore Ts'o ext4_lblk_t i_dir_start_lookup; 832353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 83319f5fb7aSTheodore Ts'o unsigned long i_state_flags; /* Dynamic state flags */ 834353eb83cSTheodore Ts'o #endif 83512e9b892SDmitry Monakhov unsigned long i_flags; 836d444c3c3STheodore Ts'o 837d444c3c3STheodore Ts'o /* 838d444c3c3STheodore Ts'o * Extended attributes can be read independently of the main file 839d444c3c3STheodore Ts'o * data. Taking i_mutex even when reading would cause contention 840d444c3c3STheodore Ts'o * between readers of EAs and writers of regular file data, so 841d444c3c3STheodore Ts'o * instead we synchronize on xattr_sem when reading or changing 842d444c3c3STheodore Ts'o * EAs. 843d444c3c3STheodore Ts'o */ 844d444c3c3STheodore Ts'o struct rw_semaphore xattr_sem; 845d444c3c3STheodore Ts'o 846d444c3c3STheodore Ts'o struct list_head i_orphan; /* unlinked but open inodes */ 847d444c3c3STheodore Ts'o 848d444c3c3STheodore Ts'o /* 849d444c3c3STheodore Ts'o * i_disksize keeps track of what the inode size is ON DISK, not 850d444c3c3STheodore Ts'o * in memory. During truncate, i_size is set to the new size by 851d444c3c3STheodore Ts'o * the VFS prior to calling ext4_truncate(), but the filesystem won't 852d444c3c3STheodore Ts'o * set i_disksize to 0 until the truncate is actually under way. 853d444c3c3STheodore Ts'o * 854d444c3c3STheodore Ts'o * The intent is that i_disksize always represents the blocks which 855d444c3c3STheodore Ts'o * are used by this file. This allows recovery to restart truncate 856d444c3c3STheodore Ts'o * on orphans if we crash during truncate. We actually write i_disksize 857d444c3c3STheodore Ts'o * into the on-disk inode when writing inodes out, instead of i_size. 858d444c3c3STheodore Ts'o * 859d444c3c3STheodore Ts'o * The only time when i_disksize and i_size may be different is when 860d444c3c3STheodore Ts'o * a truncate is in progress. The only things which change i_disksize 861d444c3c3STheodore Ts'o * are ext4_get_block (growth) and ext4_truncate (shrinkth). 862d444c3c3STheodore Ts'o */ 863d444c3c3STheodore Ts'o loff_t i_disksize; 864d444c3c3STheodore Ts'o 865d444c3c3STheodore Ts'o /* 866d444c3c3STheodore Ts'o * i_data_sem is for serialising ext4_truncate() against 867d444c3c3STheodore Ts'o * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's 868d444c3c3STheodore Ts'o * data tree are chopped off during truncate. We can't do that in 869d444c3c3STheodore Ts'o * ext4 because whenever we perform intermediate commits during 870d444c3c3STheodore Ts'o * truncate, the inode and all the metadata blocks *must* be in a 871d444c3c3STheodore Ts'o * consistent state which allows truncation of the orphans to restart 872d444c3c3STheodore Ts'o * during recovery. Hence we must fix the get_block-vs-truncate race 873d444c3c3STheodore Ts'o * by other means, so we have i_data_sem. 874d444c3c3STheodore Ts'o */ 875d444c3c3STheodore Ts'o struct rw_semaphore i_data_sem; 876d444c3c3STheodore Ts'o struct inode vfs_inode; 8778aefcd55STheodore Ts'o struct jbd2_inode *jinode; 878d444c3c3STheodore Ts'o 879202ee5dfSTheodore Ts'o spinlock_t i_raw_lock; /* protects updates to the raw inode */ 880202ee5dfSTheodore Ts'o 881d444c3c3STheodore Ts'o /* 882d444c3c3STheodore Ts'o * File creation time. Its function is same as that of 883d444c3c3STheodore Ts'o * struct timespec i_{a,c,m}time in the generic inode. 884d444c3c3STheodore Ts'o */ 885d444c3c3STheodore Ts'o struct timespec i_crtime; 886d444c3c3STheodore Ts'o 887d444c3c3STheodore Ts'o /* mballoc */ 888d444c3c3STheodore Ts'o struct list_head i_prealloc_list; 889d444c3c3STheodore Ts'o spinlock_t i_prealloc_lock; 890d444c3c3STheodore Ts'o 891c0677e6dSZheng Liu /* extents status tree */ 892c0677e6dSZheng Liu struct ext4_es_tree i_es_tree; 893c0677e6dSZheng Liu rwlock_t i_es_lock; 894edaa53caSZheng Liu struct list_head i_es_list; 895eb68d0e2SZheng Liu unsigned int i_es_all_nr; /* protected by i_es_lock */ 896edaa53caSZheng Liu unsigned int i_es_shk_nr; /* protected by i_es_lock */ 897dd475925SJan Kara ext4_lblk_t i_es_shrink_lblk; /* Offset where we start searching for 898dd475925SJan Kara extents to shrink. Protected by 899dd475925SJan Kara i_es_lock */ 900c0677e6dSZheng Liu 901d444c3c3STheodore Ts'o /* ialloc */ 902d444c3c3STheodore Ts'o ext4_group_t i_last_alloc_group; 903d444c3c3STheodore Ts'o 904d444c3c3STheodore Ts'o /* allocation reservation info for delalloc */ 90557042651STheodore Ts'o /* In case of bigalloc, these refer to clusters rather than blocks */ 906d444c3c3STheodore Ts'o unsigned int i_reserved_data_blocks; 907d444c3c3STheodore Ts'o unsigned int i_reserved_meta_blocks; 908d444c3c3STheodore Ts'o unsigned int i_allocated_meta_blocks; 90901f49d0bSTheodore Ts'o ext4_lblk_t i_da_metadata_calc_last_lblock; 9109d0be502STheodore Ts'o int i_da_metadata_calc_len; 911d444c3c3STheodore Ts'o 912d444c3c3STheodore Ts'o /* on-disk additional length */ 913d444c3c3STheodore Ts'o __u16 i_extra_isize; 914d444c3c3STheodore Ts'o 91567cf5b09STao Ma /* Indicate the inline data space. */ 91667cf5b09STao Ma u16 i_inline_off; 91767cf5b09STao Ma u16 i_inline_size; 91867cf5b09STao Ma 919a9e7f447SDmitry Monakhov #ifdef CONFIG_QUOTA 920a9e7f447SDmitry Monakhov /* quota space reservation, managed internally by quota code */ 921a9e7f447SDmitry Monakhov qsize_t i_reserved_quota; 922a9e7f447SDmitry Monakhov #endif 9238d5d02e6SMingming Cao 9242e8fa54eSJan Kara /* Lock protecting lists below */ 925744692dcSJiaying Zhang spinlock_t i_completed_io_lock; 9262e8fa54eSJan Kara /* 9272e8fa54eSJan Kara * Completed IOs that need unwritten extents handling and have 9282e8fa54eSJan Kara * transaction reserved 9292e8fa54eSJan Kara */ 9302e8fa54eSJan Kara struct list_head i_rsv_conversion_list; 9312e8fa54eSJan Kara /* 9322e8fa54eSJan Kara * Completed IOs that need unwritten extents handling and don't have 9332e8fa54eSJan Kara * transaction reserved 9342e8fa54eSJan Kara */ 9358a2005d3STheodore Ts'o atomic_t i_ioend_count; /* Number of outstanding io_end structs */ 936e27f41e1SDmitry Monakhov atomic_t i_unwritten; /* Nr. of inflight conversions pending */ 9372e8fa54eSJan Kara struct work_struct i_rsv_conversion_work; 9388a2005d3STheodore Ts'o 9398a2005d3STheodore Ts'o spinlock_t i_block_reservation_lock; 940b436b9beSJan Kara 941b436b9beSJan Kara /* 942b436b9beSJan Kara * Transactions that contain inode's metadata needed to complete 943b436b9beSJan Kara * fsync and fdatasync, respectively. 944b436b9beSJan Kara */ 945b436b9beSJan Kara tid_t i_sync_tid; 946b436b9beSJan Kara tid_t i_datasync_tid; 947814525f4SDarrick J. Wong 94896c7e0d9SJan Kara #ifdef CONFIG_QUOTA 94996c7e0d9SJan Kara struct dquot *i_dquot[MAXQUOTAS]; 95096c7e0d9SJan Kara #endif 95196c7e0d9SJan Kara 952814525f4SDarrick J. Wong /* Precomputed uuid+inum+igen checksum for seeding inode checksums */ 953814525f4SDarrick J. Wong __u32 i_csum_seed; 954b30ab0e0SMichael Halcrow 955b30ab0e0SMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 956b30ab0e0SMichael Halcrow /* Encryption params */ 957b30ab0e0SMichael Halcrow struct ext4_encryption_key i_encryption_key; 958b30ab0e0SMichael Halcrow #endif 959d444c3c3STheodore Ts'o }; 960d444c3c3STheodore Ts'o 961d444c3c3STheodore Ts'o /* 9623dcf5451SChristoph Hellwig * File system states 9633dcf5451SChristoph Hellwig */ 9643dcf5451SChristoph Hellwig #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 9653dcf5451SChristoph Hellwig #define EXT4_ERROR_FS 0x0002 /* Errors detected */ 9663dcf5451SChristoph Hellwig #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ 9673dcf5451SChristoph Hellwig 9683dcf5451SChristoph Hellwig /* 9693dcf5451SChristoph Hellwig * Misc. filesystem flags 9703dcf5451SChristoph Hellwig */ 9713dcf5451SChristoph Hellwig #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ 9723dcf5451SChristoph Hellwig #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ 9733dcf5451SChristoph Hellwig #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ 9743dcf5451SChristoph Hellwig 9753dcf5451SChristoph Hellwig /* 97668911009SLukas Czerner * Mount flags set via mount options or defaults 9773dcf5451SChristoph Hellwig */ 9783dcf5451SChristoph Hellwig #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 9793dcf5451SChristoph Hellwig #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 9803dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 9813dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 9823dcf5451SChristoph Hellwig #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 98339ef17f1STheodore Ts'o #define EXT4_MOUNT_ERRORS_MASK 0x00070 9843dcf5451SChristoph Hellwig #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 9853dcf5451SChristoph Hellwig #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 986923ae0ffSRoss Zwisler #ifdef CONFIG_FS_DAX 987923ae0ffSRoss Zwisler #define EXT4_MOUNT_DAX 0x00200 /* Direct Access */ 988923ae0ffSRoss Zwisler #else 989923ae0ffSRoss Zwisler #define EXT4_MOUNT_DAX 0 990923ae0ffSRoss Zwisler #endif 9913dcf5451SChristoph Hellwig #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 9923dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 9933dcf5451SChristoph Hellwig #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 9943dcf5451SChristoph Hellwig #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 9953dcf5451SChristoph Hellwig #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 9963dcf5451SChristoph Hellwig #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 9973dcf5451SChristoph Hellwig #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 9983dcf5451SChristoph Hellwig #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 999afd4672dSTheodore Ts'o #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 10003dcf5451SChristoph Hellwig #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 10013dcf5451SChristoph Hellwig #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ 10023dcf5451SChristoph Hellwig #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ 10033dcf5451SChristoph Hellwig #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ 1004744692dcSJiaying Zhang #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */ 1005d4da6c9cSLinus Torvalds #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 10063dcf5451SChristoph Hellwig #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 100764769240SAlex Tomas #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 10085bf5683aSHidehiro Kawai #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 10096fd058f7STheodore Ts'o #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */ 10105328e635SEric Sandeen #define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */ 1011bfff6873SLukas Czerner #define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */ 10125bf5683aSHidehiro Kawai 101368911009SLukas Czerner /* 101468911009SLukas Czerner * Mount flags set either automatically (could not be set by mount option) 101568911009SLukas Czerner * based on per file system feature or property or in special cases such as 101668911009SLukas Czerner * distinguishing between explicit mount option definition and default. 101768911009SLukas Czerner */ 101856889787STheodore Ts'o #define EXT4_MOUNT2_EXPLICIT_DELALLOC 0x00000001 /* User explicitly 101956889787STheodore Ts'o specified delalloc */ 102068911009SLukas Czerner #define EXT4_MOUNT2_STD_GROUP_SIZE 0x00000002 /* We have standard group 102168911009SLukas Czerner size of blocksize * 8 102268911009SLukas Czerner blocks */ 1023ed3654ebSTheodore Ts'o #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated 1024ed3654ebSTheodore Ts'o file systems */ 102556889787STheodore Ts'o 1026fd8c37ecSTheodore Ts'o #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ 1027fd8c37ecSTheodore Ts'o ~EXT4_MOUNT_##opt 1028fd8c37ecSTheodore Ts'o #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \ 1029fd8c37ecSTheodore Ts'o EXT4_MOUNT_##opt 10303dcf5451SChristoph Hellwig #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \ 10313dcf5451SChristoph Hellwig EXT4_MOUNT_##opt) 10323dcf5451SChristoph Hellwig 1033a2595b8aSTheodore Ts'o #define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \ 1034a2595b8aSTheodore Ts'o ~EXT4_MOUNT2_##opt 1035a2595b8aSTheodore Ts'o #define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \ 1036a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt 1037a2595b8aSTheodore Ts'o #define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \ 1038a2595b8aSTheodore Ts'o EXT4_MOUNT2_##opt) 1039a2595b8aSTheodore Ts'o 1040597d508cSAkinobu Mita #define ext4_test_and_set_bit __test_and_set_bit_le 1041597d508cSAkinobu Mita #define ext4_set_bit __set_bit_le 10423dcf5451SChristoph Hellwig #define ext4_set_bit_atomic ext2_set_bit_atomic 1043597d508cSAkinobu Mita #define ext4_test_and_clear_bit __test_and_clear_bit_le 1044597d508cSAkinobu Mita #define ext4_clear_bit __clear_bit_le 10453dcf5451SChristoph Hellwig #define ext4_clear_bit_atomic ext2_clear_bit_atomic 104650e0168cSAkinobu Mita #define ext4_test_bit test_bit_le 104750e0168cSAkinobu Mita #define ext4_find_next_zero_bit find_next_zero_bit_le 104850e0168cSAkinobu Mita #define ext4_find_next_bit find_next_bit_le 10493dcf5451SChristoph Hellwig 1050c3e94d1dSYongqiang Yang extern void ext4_set_bits(void *bm, int cur, int len); 1051c3e94d1dSYongqiang Yang 10523dcf5451SChristoph Hellwig /* 10533dcf5451SChristoph Hellwig * Maximal mount counts between two filesystem checks 10543dcf5451SChristoph Hellwig */ 10553dcf5451SChristoph Hellwig #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 10563dcf5451SChristoph Hellwig #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 10573dcf5451SChristoph Hellwig 10583dcf5451SChristoph Hellwig /* 10593dcf5451SChristoph Hellwig * Behaviour when detecting errors 10603dcf5451SChristoph Hellwig */ 10613dcf5451SChristoph Hellwig #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */ 10623dcf5451SChristoph Hellwig #define EXT4_ERRORS_RO 2 /* Remount fs read-only */ 10633dcf5451SChristoph Hellwig #define EXT4_ERRORS_PANIC 3 /* Panic */ 10643dcf5451SChristoph Hellwig #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 10653dcf5451SChristoph Hellwig 1066e6153918SDarrick J. Wong /* Metadata checksum algorithm codes */ 1067e6153918SDarrick J. Wong #define EXT4_CRC32C_CHKSUM 1 1068e6153918SDarrick J. Wong 10693edc18d8STheodore Ts'o /* Encryption algorithms */ 10703edc18d8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_INVALID 0 10713edc18d8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_XTS 1 10723edc18d8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_GCM 2 10733edc18d8STheodore Ts'o #define EXT4_ENCRYPTION_MODE_AES_256_CBC 3 10743edc18d8STheodore Ts'o 10753dcf5451SChristoph Hellwig /* 10763dcf5451SChristoph Hellwig * Structure of the super block 10773dcf5451SChristoph Hellwig */ 10783dcf5451SChristoph Hellwig struct ext4_super_block { 10793dcf5451SChristoph Hellwig /*00*/ __le32 s_inodes_count; /* Inodes count */ 10803dcf5451SChristoph Hellwig __le32 s_blocks_count_lo; /* Blocks count */ 10813dcf5451SChristoph Hellwig __le32 s_r_blocks_count_lo; /* Reserved blocks count */ 10823dcf5451SChristoph Hellwig __le32 s_free_blocks_count_lo; /* Free blocks count */ 10833dcf5451SChristoph Hellwig /*10*/ __le32 s_free_inodes_count; /* Free inodes count */ 10843dcf5451SChristoph Hellwig __le32 s_first_data_block; /* First Data Block */ 10853dcf5451SChristoph Hellwig __le32 s_log_block_size; /* Block size */ 1086281b5995STheodore Ts'o __le32 s_log_cluster_size; /* Allocation cluster size */ 10873dcf5451SChristoph Hellwig /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ 1088281b5995STheodore Ts'o __le32 s_clusters_per_group; /* # Clusters per group */ 10893dcf5451SChristoph Hellwig __le32 s_inodes_per_group; /* # Inodes per group */ 10903dcf5451SChristoph Hellwig __le32 s_mtime; /* Mount time */ 10913dcf5451SChristoph Hellwig /*30*/ __le32 s_wtime; /* Write time */ 10923dcf5451SChristoph Hellwig __le16 s_mnt_count; /* Mount count */ 10933dcf5451SChristoph Hellwig __le16 s_max_mnt_count; /* Maximal mount count */ 10943dcf5451SChristoph Hellwig __le16 s_magic; /* Magic signature */ 10953dcf5451SChristoph Hellwig __le16 s_state; /* File system state */ 10963dcf5451SChristoph Hellwig __le16 s_errors; /* Behaviour when detecting errors */ 10973dcf5451SChristoph Hellwig __le16 s_minor_rev_level; /* minor revision level */ 10983dcf5451SChristoph Hellwig /*40*/ __le32 s_lastcheck; /* time of last check */ 10993dcf5451SChristoph Hellwig __le32 s_checkinterval; /* max. time between checks */ 11003dcf5451SChristoph Hellwig __le32 s_creator_os; /* OS */ 11013dcf5451SChristoph Hellwig __le32 s_rev_level; /* Revision level */ 11023dcf5451SChristoph Hellwig /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 11033dcf5451SChristoph Hellwig __le16 s_def_resgid; /* Default gid for reserved blocks */ 11043dcf5451SChristoph Hellwig /* 11053dcf5451SChristoph Hellwig * These fields are for EXT4_DYNAMIC_REV superblocks only. 11063dcf5451SChristoph Hellwig * 11073dcf5451SChristoph Hellwig * Note: the difference between the compatible feature set and 11083dcf5451SChristoph Hellwig * the incompatible feature set is that if there is a bit set 11093dcf5451SChristoph Hellwig * in the incompatible feature set that the kernel doesn't 11103dcf5451SChristoph Hellwig * know about, it should refuse to mount the filesystem. 11113dcf5451SChristoph Hellwig * 11123dcf5451SChristoph Hellwig * e2fsck's requirements are more strict; if it doesn't know 11133dcf5451SChristoph Hellwig * about a feature in either the compatible or incompatible 11143dcf5451SChristoph Hellwig * feature set, it must abort and not try to meddle with 11153dcf5451SChristoph Hellwig * things it doesn't understand... 11163dcf5451SChristoph Hellwig */ 11173dcf5451SChristoph Hellwig __le32 s_first_ino; /* First non-reserved inode */ 11183dcf5451SChristoph Hellwig __le16 s_inode_size; /* size of inode structure */ 11193dcf5451SChristoph Hellwig __le16 s_block_group_nr; /* block group # of this superblock */ 11203dcf5451SChristoph Hellwig __le32 s_feature_compat; /* compatible feature set */ 11213dcf5451SChristoph Hellwig /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 11223dcf5451SChristoph Hellwig __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 11233dcf5451SChristoph Hellwig /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 11243dcf5451SChristoph Hellwig /*78*/ char s_volume_name[16]; /* volume name */ 11253dcf5451SChristoph Hellwig /*88*/ char s_last_mounted[64]; /* directory where last mounted */ 11263dcf5451SChristoph Hellwig /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 11273dcf5451SChristoph Hellwig /* 11283dcf5451SChristoph Hellwig * Performance hints. Directory preallocation should only 11293dcf5451SChristoph Hellwig * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. 11303dcf5451SChristoph Hellwig */ 11313dcf5451SChristoph Hellwig __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 11323dcf5451SChristoph Hellwig __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 11333dcf5451SChristoph Hellwig __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 11343dcf5451SChristoph Hellwig /* 11353dcf5451SChristoph Hellwig * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. 11363dcf5451SChristoph Hellwig */ 11373dcf5451SChristoph Hellwig /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 11383dcf5451SChristoph Hellwig /*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 11393dcf5451SChristoph Hellwig __le32 s_journal_dev; /* device number of journal file */ 11403dcf5451SChristoph Hellwig __le32 s_last_orphan; /* start of list of inodes to delete */ 11413dcf5451SChristoph Hellwig __le32 s_hash_seed[4]; /* HTREE hash seed */ 11423dcf5451SChristoph Hellwig __u8 s_def_hash_version; /* Default hash version to use */ 114389eeddf0STheodore Ts'o __u8 s_jnl_backup_type; 11443dcf5451SChristoph Hellwig __le16 s_desc_size; /* size of group descriptor */ 11453dcf5451SChristoph Hellwig /*100*/ __le32 s_default_mount_opts; 11463dcf5451SChristoph Hellwig __le32 s_first_meta_bg; /* First metablock block group */ 11473dcf5451SChristoph Hellwig __le32 s_mkfs_time; /* When the filesystem was created */ 11483dcf5451SChristoph Hellwig __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ 11493dcf5451SChristoph Hellwig /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ 11503dcf5451SChristoph Hellwig /*150*/ __le32 s_blocks_count_hi; /* Blocks count */ 11513dcf5451SChristoph Hellwig __le32 s_r_blocks_count_hi; /* Reserved blocks count */ 11523dcf5451SChristoph Hellwig __le32 s_free_blocks_count_hi; /* Free blocks count */ 11533dcf5451SChristoph Hellwig __le16 s_min_extra_isize; /* All inodes have at least # bytes */ 11543dcf5451SChristoph Hellwig __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ 11553dcf5451SChristoph Hellwig __le32 s_flags; /* Miscellaneous flags */ 11563dcf5451SChristoph Hellwig __le16 s_raid_stride; /* RAID stride */ 1157c5e06d10SJohann Lombardi __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ 11583dcf5451SChristoph Hellwig __le64 s_mmp_block; /* Block for multi-mount protection */ 11593dcf5451SChristoph Hellwig __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 1160772cb7c8SJose R. Santos __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 1161e6153918SDarrick J. Wong __u8 s_checksum_type; /* metadata checksum algorithm used */ 1162f542fbe8STheodore Ts'o __u8 s_encryption_level; /* versioning level for encryption */ 1163f542fbe8STheodore Ts'o __u8 s_reserved_pad; /* Padding to next 32bits */ 1164afc32f7eSTheodore Ts'o __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 11654a9cdec7STheodore Ts'o __le32 s_snapshot_inum; /* Inode number of active snapshot */ 11664a9cdec7STheodore Ts'o __le32 s_snapshot_id; /* sequential ID of active snapshot */ 11674a9cdec7STheodore Ts'o __le64 s_snapshot_r_blocks_count; /* reserved blocks for active 11684a9cdec7STheodore Ts'o snapshot's future use */ 11694a9cdec7STheodore Ts'o __le32 s_snapshot_list; /* inode number of the head of the 11704a9cdec7STheodore Ts'o on-disk snapshot list */ 11711c13d5c0STheodore Ts'o #define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count) 11721c13d5c0STheodore Ts'o __le32 s_error_count; /* number of fs errors */ 11731c13d5c0STheodore Ts'o __le32 s_first_error_time; /* first time an error happened */ 11741c13d5c0STheodore Ts'o __le32 s_first_error_ino; /* inode involved in first error */ 11751c13d5c0STheodore Ts'o __le64 s_first_error_block; /* block involved of first error */ 11761c13d5c0STheodore Ts'o __u8 s_first_error_func[32]; /* function where the error happened */ 11771c13d5c0STheodore Ts'o __le32 s_first_error_line; /* line number where error happened */ 11781c13d5c0STheodore Ts'o __le32 s_last_error_time; /* most recent time of an error */ 11791c13d5c0STheodore Ts'o __le32 s_last_error_ino; /* inode involved in last error */ 11801c13d5c0STheodore Ts'o __le32 s_last_error_line; /* line number where error happened */ 11811c13d5c0STheodore Ts'o __le64 s_last_error_block; /* block involved of last error */ 11821c13d5c0STheodore Ts'o __u8 s_last_error_func[32]; /* function where the error happened */ 11838b67f04aSTheodore Ts'o #define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts) 11848b67f04aSTheodore Ts'o __u8 s_mount_opts[64]; 1185281b5995STheodore Ts'o __le32 s_usr_quota_inum; /* inode for tracking user quota */ 1186281b5995STheodore Ts'o __le32 s_grp_quota_inum; /* inode for tracking group quota */ 1187281b5995STheodore Ts'o __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ 11881beeef1bSDarrick J. Wong __le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */ 11893edc18d8STheodore Ts'o __u8 s_encrypt_algos[4]; /* Encryption algorithms in use */ 1190f542fbe8STheodore Ts'o __u8 s_encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ 1191f542fbe8STheodore Ts'o __le32 s_lpf_ino; /* Location of the lost+found inode */ 1192f542fbe8STheodore Ts'o __le32 s_reserved[100]; /* Padding to the end of the block */ 1193e6153918SDarrick J. Wong __le32 s_checksum; /* crc32c(superblock) */ 11943dcf5451SChristoph Hellwig }; 11953dcf5451SChristoph Hellwig 11961c13d5c0STheodore Ts'o #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) 11971c13d5c0STheodore Ts'o 11983dcf5451SChristoph Hellwig #ifdef __KERNEL__ 1199bc0b0d6dSTheodore Ts'o 1200bc0b0d6dSTheodore Ts'o /* 12014ab2f15bSTheodore Ts'o * run-time mount flags 1202bc0b0d6dSTheodore Ts'o */ 1203bc0b0d6dSTheodore Ts'o #define EXT4_MF_MNTDIR_SAMPLED 0x0001 12044ab2f15bSTheodore Ts'o #define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */ 12056ddb2447STheodore Ts'o #define EXT4_MF_TEST_DUMMY_ENCRYPTION 0x0004 12066ddb2447STheodore Ts'o 12076ddb2447STheodore Ts'o #ifdef CONFIG_EXT4_FS_ENCRYPTION 12086ddb2447STheodore Ts'o #define DUMMY_ENCRYPTION_ENABLED(sbi) (unlikely((sbi)->s_mount_flags & \ 12096ddb2447STheodore Ts'o EXT4_MF_TEST_DUMMY_ENCRYPTION)) 12106ddb2447STheodore Ts'o #else 12116ddb2447STheodore Ts'o #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) 12126ddb2447STheodore Ts'o #endif 1213bc0b0d6dSTheodore Ts'o 1214a2d4a646SJan Kara /* Number of quota types we support */ 1215a2d4a646SJan Kara #define EXT4_MAXQUOTAS 2 1216a2d4a646SJan Kara 1217ca0faba0STheodore Ts'o /* 1218ca0faba0STheodore Ts'o * fourth extended-fs super-block data in memory 1219ca0faba0STheodore Ts'o */ 1220ca0faba0STheodore Ts'o struct ext4_sb_info { 1221ca0faba0STheodore Ts'o unsigned long s_desc_size; /* Size of a group descriptor in bytes */ 1222ca0faba0STheodore Ts'o unsigned long s_inodes_per_block;/* Number of inodes per block */ 1223ca0faba0STheodore Ts'o unsigned long s_blocks_per_group;/* Number of blocks in a group */ 1224281b5995STheodore Ts'o unsigned long s_clusters_per_group; /* Number of clusters in a group */ 1225ca0faba0STheodore Ts'o unsigned long s_inodes_per_group;/* Number of inodes in a group */ 1226ca0faba0STheodore Ts'o unsigned long s_itb_per_group; /* Number of inode table blocks per group */ 1227ca0faba0STheodore Ts'o unsigned long s_gdb_count; /* Number of group descriptor blocks */ 1228ca0faba0STheodore Ts'o unsigned long s_desc_per_block; /* Number of group descriptors per block */ 1229ca0faba0STheodore Ts'o ext4_group_t s_groups_count; /* Number of groups in the fs */ 1230fb0a387dSEric Sandeen ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */ 1231952fc18eSTheodore Ts'o unsigned long s_overhead; /* # of fs overhead clusters */ 1232281b5995STheodore Ts'o unsigned int s_cluster_ratio; /* Number of blocks per cluster */ 1233281b5995STheodore Ts'o unsigned int s_cluster_bits; /* log2 of s_cluster_ratio */ 1234ca0faba0STheodore Ts'o loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */ 1235ca0faba0STheodore Ts'o struct buffer_head * s_sbh; /* Buffer containing the super block */ 1236ca0faba0STheodore Ts'o struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */ 1237ca0faba0STheodore Ts'o struct buffer_head **s_group_desc; 12387f4520ccSTheodore Ts'o unsigned int s_mount_opt; 1239a2595b8aSTheodore Ts'o unsigned int s_mount_opt2; 1240bc0b0d6dSTheodore Ts'o unsigned int s_mount_flags; 12415a916be1STheodore Ts'o unsigned int s_def_mount_opt; 1242ca0faba0STheodore Ts'o ext4_fsblk_t s_sb_block; 124327dd4385SLukas Czerner atomic64_t s_resv_clusters; 124408cefc7aSEric W. Biederman kuid_t s_resuid; 124508cefc7aSEric W. Biederman kgid_t s_resgid; 1246ca0faba0STheodore Ts'o unsigned short s_mount_state; 1247ca0faba0STheodore Ts'o unsigned short s_pad; 1248ca0faba0STheodore Ts'o int s_addr_per_block_bits; 1249ca0faba0STheodore Ts'o int s_desc_per_block_bits; 1250ca0faba0STheodore Ts'o int s_inode_size; 1251ca0faba0STheodore Ts'o int s_first_ino; 1252ca0faba0STheodore Ts'o unsigned int s_inode_readahead_blks; 125311013911SAndreas Dilger unsigned int s_inode_goal; 1254ca0faba0STheodore Ts'o spinlock_t s_next_gen_lock; 1255ca0faba0STheodore Ts'o u32 s_next_generation; 1256ca0faba0STheodore Ts'o u32 s_hash_seed[4]; 1257ca0faba0STheodore Ts'o int s_def_hash_version; 1258ca0faba0STheodore Ts'o int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */ 125957042651STheodore Ts'o struct percpu_counter s_freeclusters_counter; 1260ca0faba0STheodore Ts'o struct percpu_counter s_freeinodes_counter; 1261ca0faba0STheodore Ts'o struct percpu_counter s_dirs_counter; 126257042651STheodore Ts'o struct percpu_counter s_dirtyclusters_counter; 1263ca0faba0STheodore Ts'o struct blockgroup_lock *s_blockgroup_lock; 1264ca0faba0STheodore Ts'o struct proc_dir_entry *s_proc; 1265ca0faba0STheodore Ts'o struct kobject s_kobj; 1266ca0faba0STheodore Ts'o struct completion s_kobj_unregister; 12672c0544b2STheodore Ts'o struct super_block *s_sb; 1268ca0faba0STheodore Ts'o 1269ca0faba0STheodore Ts'o /* Journaling */ 1270ca0faba0STheodore Ts'o struct journal_s *s_journal; 1271ca0faba0STheodore Ts'o struct list_head s_orphan; 1272ca0faba0STheodore Ts'o struct mutex s_orphan_lock; 12738f82f840SYongqiang Yang unsigned long s_resize_flags; /* Flags indicating if there 12748f82f840SYongqiang Yang is a resizer */ 1275ca0faba0STheodore Ts'o unsigned long s_commit_interval; 1276ca0faba0STheodore Ts'o u32 s_max_batch_time; 1277ca0faba0STheodore Ts'o u32 s_min_batch_time; 1278ca0faba0STheodore Ts'o struct block_device *journal_bdev; 1279ca0faba0STheodore Ts'o #ifdef CONFIG_QUOTA 1280a2d4a646SJan Kara char *s_qf_names[EXT4_MAXQUOTAS]; /* Names of quota files with journalled quota */ 1281ca0faba0STheodore Ts'o int s_jquota_fmt; /* Format of quota to use */ 1282ca0faba0STheodore Ts'o #endif 1283ca0faba0STheodore Ts'o unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */ 12846fd058f7STheodore Ts'o struct rb_root system_blks; 1285ca0faba0STheodore Ts'o 1286ca0faba0STheodore Ts'o #ifdef EXTENTS_STATS 1287ca0faba0STheodore Ts'o /* ext4 extents stats */ 1288ca0faba0STheodore Ts'o unsigned long s_ext_min; 1289ca0faba0STheodore Ts'o unsigned long s_ext_max; 1290ca0faba0STheodore Ts'o unsigned long s_depth_max; 1291ca0faba0STheodore Ts'o spinlock_t s_ext_stats_lock; 1292ca0faba0STheodore Ts'o unsigned long s_ext_blocks; 1293ca0faba0STheodore Ts'o unsigned long s_ext_extents; 1294ca0faba0STheodore Ts'o #endif 1295ca0faba0STheodore Ts'o 1296ca0faba0STheodore Ts'o /* for buddy allocator */ 1297ca0faba0STheodore Ts'o struct ext4_group_info ***s_group_info; 1298ca0faba0STheodore Ts'o struct inode *s_buddy_cache; 1299ca0faba0STheodore Ts'o spinlock_t s_md_lock; 1300ca0faba0STheodore Ts'o unsigned short *s_mb_offsets; 1301ca0faba0STheodore Ts'o unsigned int *s_mb_maxs; 130228623c2fSTheodore Ts'o unsigned int s_group_info_size; 1303ca0faba0STheodore Ts'o 1304ca0faba0STheodore Ts'o /* tunables */ 1305ca0faba0STheodore Ts'o unsigned long s_stripe; 1306ca0faba0STheodore Ts'o unsigned int s_mb_stream_request; 1307ca0faba0STheodore Ts'o unsigned int s_mb_max_to_scan; 1308ca0faba0STheodore Ts'o unsigned int s_mb_min_to_scan; 1309ca0faba0STheodore Ts'o unsigned int s_mb_stats; 1310ca0faba0STheodore Ts'o unsigned int s_mb_order2_reqs; 1311ca0faba0STheodore Ts'o unsigned int s_mb_group_prealloc; 1312df981d03STheodore Ts'o unsigned int s_max_dir_size_kb; 1313ca0faba0STheodore Ts'o /* where last allocation was done - for stream allocation */ 1314ca0faba0STheodore Ts'o unsigned long s_mb_last_group; 1315ca0faba0STheodore Ts'o unsigned long s_mb_last_start; 1316ca0faba0STheodore Ts'o 1317ca0faba0STheodore Ts'o /* stats for buddy allocator */ 1318ca0faba0STheodore Ts'o atomic_t s_bal_reqs; /* number of reqs with len > 1 */ 1319ca0faba0STheodore Ts'o atomic_t s_bal_success; /* we found long enough chunks */ 1320ca0faba0STheodore Ts'o atomic_t s_bal_allocated; /* in blocks */ 1321ca0faba0STheodore Ts'o atomic_t s_bal_ex_scanned; /* total extents scanned */ 1322ca0faba0STheodore Ts'o atomic_t s_bal_goals; /* goal hits */ 1323ca0faba0STheodore Ts'o atomic_t s_bal_breaks; /* too long searches */ 1324ca0faba0STheodore Ts'o atomic_t s_bal_2orders; /* 2^order hits */ 1325ca0faba0STheodore Ts'o spinlock_t s_bal_lock; 1326ca0faba0STheodore Ts'o unsigned long s_mb_buddies_generated; 1327ca0faba0STheodore Ts'o unsigned long long s_mb_generation_time; 1328ca0faba0STheodore Ts'o atomic_t s_mb_lost_chunks; 1329ca0faba0STheodore Ts'o atomic_t s_mb_preallocated; 1330ca0faba0STheodore Ts'o atomic_t s_mb_discarded; 133150797481STheodore Ts'o atomic_t s_lock_busy; 1332ca0faba0STheodore Ts'o 1333ca0faba0STheodore Ts'o /* locality groups */ 1334003cb608STejun Heo struct ext4_locality_group __percpu *s_locality_groups; 1335ca0faba0STheodore Ts'o 1336ca0faba0STheodore Ts'o /* for write statistics */ 1337ca0faba0STheodore Ts'o unsigned long s_sectors_written_start; 1338ca0faba0STheodore Ts'o u64 s_kbytes_written; 1339ca0faba0STheodore Ts'o 134067a5da56SZheng Liu /* the size of zero-out chunk */ 134167a5da56SZheng Liu unsigned int s_extent_max_zeroout_kb; 134267a5da56SZheng Liu 1343ca0faba0STheodore Ts'o unsigned int s_log_groups_per_flex; 1344ca0faba0STheodore Ts'o struct flex_groups *s_flex_groups; 1345117fff10STheodore Ts'o ext4_group_t s_flex_groups_allocated; 13464c0425ffSMingming Cao 13472e8fa54eSJan Kara /* workqueue for reserved extent conversions (buffered io) */ 13482e8fa54eSJan Kara struct workqueue_struct *rsv_conversion_wq; 134966e61a9eSTheodore Ts'o 135066e61a9eSTheodore Ts'o /* timer for periodic error stats printing */ 135166e61a9eSTheodore Ts'o struct timer_list s_err_report; 1352bfff6873SLukas Czerner 1353bfff6873SLukas Czerner /* Lazy inode table initialization info */ 1354bfff6873SLukas Czerner struct ext4_li_request *s_li_request; 1355bfff6873SLukas Czerner /* Wait multiplier for lazy initialization thread */ 1356bfff6873SLukas Czerner unsigned int s_li_wait_mult; 1357c5e06d10SJohann Lombardi 1358c5e06d10SJohann Lombardi /* Kernel thread for multiple mount protection */ 1359c5e06d10SJohann Lombardi struct task_struct *s_mmp_tsk; 13603d56b8d2STao Ma 13613d56b8d2STao Ma /* record the last minlen when FITRIM is called. */ 13623d56b8d2STao Ma atomic_t s_last_trim_minblks; 13630441984aSDarrick J. Wong 13640441984aSDarrick J. Wong /* Reference to checksum algorithm driver via cryptoapi */ 13650441984aSDarrick J. Wong struct crypto_shash *s_chksum_driver; 1366a9c47317SDarrick J. Wong 1367a9c47317SDarrick J. Wong /* Precomputed FS UUID checksum for seeding other checksums */ 1368a9c47317SDarrick J. Wong __u32 s_csum_seed; 136974cd15cdSZheng Liu 137074cd15cdSZheng Liu /* Reclaim extents from extent status tree */ 137174cd15cdSZheng Liu struct shrinker s_es_shrinker; 1372dd475925SJan Kara struct list_head s_es_list; /* List of inodes with reclaimable extents */ 1373edaa53caSZheng Liu long s_es_nr_inode; 1374eb68d0e2SZheng Liu struct ext4_es_stats s_es_stats; 13759c191f70ST Makphaibulchoke struct mb_cache *s_mb_cache; 1376edaa53caSZheng Liu spinlock_t s_es_lock ____cacheline_aligned_in_smp; 1377efbed4dcSTheodore Ts'o 1378efbed4dcSTheodore Ts'o /* Ratelimit ext4 messages. */ 1379efbed4dcSTheodore Ts'o struct ratelimit_state s_err_ratelimit_state; 1380efbed4dcSTheodore Ts'o struct ratelimit_state s_warning_ratelimit_state; 1381efbed4dcSTheodore Ts'o struct ratelimit_state s_msg_ratelimit_state; 1382b30ab0e0SMichael Halcrow 1383b30ab0e0SMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 1384b30ab0e0SMichael Halcrow /* Encryption */ 1385b30ab0e0SMichael Halcrow uint32_t s_file_encryption_mode; 1386b30ab0e0SMichael Halcrow uint32_t s_dir_encryption_mode; 1387b30ab0e0SMichael Halcrow #endif 1388ca0faba0STheodore Ts'o }; 1389ca0faba0STheodore Ts'o 13903dcf5451SChristoph Hellwig static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 13913dcf5451SChristoph Hellwig { 13923dcf5451SChristoph Hellwig return sb->s_fs_info; 13933dcf5451SChristoph Hellwig } 13943dcf5451SChristoph Hellwig static inline struct ext4_inode_info *EXT4_I(struct inode *inode) 13953dcf5451SChristoph Hellwig { 13963dcf5451SChristoph Hellwig return container_of(inode, struct ext4_inode_info, vfs_inode); 13973dcf5451SChristoph Hellwig } 13983dcf5451SChristoph Hellwig 13993dcf5451SChristoph Hellwig static inline struct timespec ext4_current_time(struct inode *inode) 14003dcf5451SChristoph Hellwig { 14013dcf5451SChristoph Hellwig return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ? 14023dcf5451SChristoph Hellwig current_fs_time(inode->i_sb) : CURRENT_TIME_SEC; 14033dcf5451SChristoph Hellwig } 14043dcf5451SChristoph Hellwig 14053dcf5451SChristoph Hellwig static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 14063dcf5451SChristoph Hellwig { 14073dcf5451SChristoph Hellwig return ino == EXT4_ROOT_INO || 14087c319d32SAditya Kali ino == EXT4_USR_QUOTA_INO || 14097c319d32SAditya Kali ino == EXT4_GRP_QUOTA_INO || 1410393d1d1dSDr. Tilmann Bubeck ino == EXT4_BOOT_LOADER_INO || 14113dcf5451SChristoph Hellwig ino == EXT4_JOURNAL_INO || 14123dcf5451SChristoph Hellwig ino == EXT4_RESIZE_INO || 14133dcf5451SChristoph Hellwig (ino >= EXT4_FIRST_INO(sb) && 14143dcf5451SChristoph Hellwig ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 14153dcf5451SChristoph Hellwig } 141619f5fb7aSTheodore Ts'o 14170edeb71dSTao Ma static inline void ext4_set_io_unwritten_flag(struct inode *inode, 14180edeb71dSTao Ma struct ext4_io_end *io_end) 14190edeb71dSTao Ma { 14200edeb71dSTao Ma if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 14210edeb71dSTao Ma io_end->flag |= EXT4_IO_END_UNWRITTEN; 1422e27f41e1SDmitry Monakhov atomic_inc(&EXT4_I(inode)->i_unwritten); 14230edeb71dSTao Ma } 14240edeb71dSTao Ma } 14250edeb71dSTao Ma 1426f45ee3a1SDmitry Monakhov static inline ext4_io_end_t *ext4_inode_aio(struct inode *inode) 1427f45ee3a1SDmitry Monakhov { 1428f45ee3a1SDmitry Monakhov return inode->i_private; 1429f45ee3a1SDmitry Monakhov } 1430f45ee3a1SDmitry Monakhov 1431f45ee3a1SDmitry Monakhov static inline void ext4_inode_aio_set(struct inode *inode, ext4_io_end_t *io) 1432f45ee3a1SDmitry Monakhov { 1433f45ee3a1SDmitry Monakhov inode->i_private = io; 1434f45ee3a1SDmitry Monakhov } 1435f45ee3a1SDmitry Monakhov 143619f5fb7aSTheodore Ts'o /* 143719f5fb7aSTheodore Ts'o * Inode dynamic state flags 143819f5fb7aSTheodore Ts'o */ 143919f5fb7aSTheodore Ts'o enum { 144019f5fb7aSTheodore Ts'o EXT4_STATE_JDATA, /* journaled data exists */ 144119f5fb7aSTheodore Ts'o EXT4_STATE_NEW, /* inode is newly created */ 144219f5fb7aSTheodore Ts'o EXT4_STATE_XATTR, /* has in-inode xattrs */ 144319f5fb7aSTheodore Ts'o EXT4_STATE_NO_EXPAND, /* No space for expansion */ 144419f5fb7aSTheodore Ts'o EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */ 144519f5fb7aSTheodore Ts'o EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */ 144619f5fb7aSTheodore Ts'o EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/ 144714ece102SFrank Mayhar EXT4_STATE_NEWENTRY, /* File just added to dir */ 144817335dccSDmitry Monakhov EXT4_STATE_DIOREAD_LOCK, /* Disable support for dio read 144917335dccSDmitry Monakhov nolocking */ 145067cf5b09STao Ma EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ 145174d553aaSTheodore Ts'o EXT4_STATE_ORDERED_MODE, /* data=ordered mode */ 14527869a4a6STheodore Ts'o EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ 145319f5fb7aSTheodore Ts'o }; 145419f5fb7aSTheodore Ts'o 1455353eb83cSTheodore Ts'o #define EXT4_INODE_BIT_FNS(name, field, offset) \ 145612e9b892SDmitry Monakhov static inline int ext4_test_inode_##name(struct inode *inode, int bit) \ 145712e9b892SDmitry Monakhov { \ 1458353eb83cSTheodore Ts'o return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 145912e9b892SDmitry Monakhov } \ 146012e9b892SDmitry Monakhov static inline void ext4_set_inode_##name(struct inode *inode, int bit) \ 146112e9b892SDmitry Monakhov { \ 1462353eb83cSTheodore Ts'o set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 146312e9b892SDmitry Monakhov } \ 146412e9b892SDmitry Monakhov static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ 146512e9b892SDmitry Monakhov { \ 1466353eb83cSTheodore Ts'o clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ 146719f5fb7aSTheodore Ts'o } 146819f5fb7aSTheodore Ts'o 14693f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 14703f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 14713f61c0ccSAndreas Dilger static inline int ext4_test_inode_flag(struct inode *inode, int bit); 14723f61c0ccSAndreas Dilger static inline void ext4_set_inode_flag(struct inode *inode, int bit); 14733f61c0ccSAndreas Dilger static inline void ext4_clear_inode_flag(struct inode *inode, int bit); 1474353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(flag, flags, 0) 14753f61c0ccSAndreas Dilger 14763f61c0ccSAndreas Dilger /* Add these declarations here only so that these functions can be 14773f61c0ccSAndreas Dilger * found by name. Otherwise, they are very hard to locate. */ 14783f61c0ccSAndreas Dilger static inline int ext4_test_inode_state(struct inode *inode, int bit); 14793f61c0ccSAndreas Dilger static inline void ext4_set_inode_state(struct inode *inode, int bit); 14803f61c0ccSAndreas Dilger static inline void ext4_clear_inode_state(struct inode *inode, int bit); 1481353eb83cSTheodore Ts'o #if (BITS_PER_LONG < 64) 1482353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, state_flags, 0) 1483353eb83cSTheodore Ts'o 1484353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1485353eb83cSTheodore Ts'o { 1486353eb83cSTheodore Ts'o (ei)->i_state_flags = 0; 1487353eb83cSTheodore Ts'o } 1488353eb83cSTheodore Ts'o #else 1489353eb83cSTheodore Ts'o EXT4_INODE_BIT_FNS(state, flags, 32) 1490353eb83cSTheodore Ts'o 1491353eb83cSTheodore Ts'o static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) 1492353eb83cSTheodore Ts'o { 1493353eb83cSTheodore Ts'o /* We depend on the fact that callers will set i_flags */ 1494353eb83cSTheodore Ts'o } 1495353eb83cSTheodore Ts'o #endif 14963dcf5451SChristoph Hellwig #else 14973dcf5451SChristoph Hellwig /* Assume that user mode programs are passing in an ext4fs superblock, not 14983dcf5451SChristoph Hellwig * a kernel struct super_block. This will allow us to call the feature-test 14993dcf5451SChristoph Hellwig * macros from user land. */ 15003dcf5451SChristoph Hellwig #define EXT4_SB(sb) (sb) 15013dcf5451SChristoph Hellwig #endif 15023dcf5451SChristoph Hellwig 1503b30ab0e0SMichael Halcrow /* 1504b30ab0e0SMichael Halcrow * Returns true if the inode is inode is encrypted 1505b30ab0e0SMichael Halcrow */ 1506b30ab0e0SMichael Halcrow static inline int ext4_encrypted_inode(struct inode *inode) 1507b30ab0e0SMichael Halcrow { 1508b30ab0e0SMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 1509b30ab0e0SMichael Halcrow return ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT); 1510b30ab0e0SMichael Halcrow #else 1511b30ab0e0SMichael Halcrow return 0; 1512b30ab0e0SMichael Halcrow #endif 1513b30ab0e0SMichael Halcrow } 1514b30ab0e0SMichael Halcrow 15153dcf5451SChristoph Hellwig #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime 15163dcf5451SChristoph Hellwig 15173dcf5451SChristoph Hellwig /* 15183dcf5451SChristoph Hellwig * Codes for operating systems 15193dcf5451SChristoph Hellwig */ 15203dcf5451SChristoph Hellwig #define EXT4_OS_LINUX 0 15213dcf5451SChristoph Hellwig #define EXT4_OS_HURD 1 15223dcf5451SChristoph Hellwig #define EXT4_OS_MASIX 2 15233dcf5451SChristoph Hellwig #define EXT4_OS_FREEBSD 3 15243dcf5451SChristoph Hellwig #define EXT4_OS_LITES 4 15253dcf5451SChristoph Hellwig 15263dcf5451SChristoph Hellwig /* 15273dcf5451SChristoph Hellwig * Revision levels 15283dcf5451SChristoph Hellwig */ 15293dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */ 15303dcf5451SChristoph Hellwig #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 15313dcf5451SChristoph Hellwig 15323dcf5451SChristoph Hellwig #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV 15333dcf5451SChristoph Hellwig #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV 15343dcf5451SChristoph Hellwig 15353dcf5451SChristoph Hellwig #define EXT4_GOOD_OLD_INODE_SIZE 128 15363dcf5451SChristoph Hellwig 15373dcf5451SChristoph Hellwig /* 15383dcf5451SChristoph Hellwig * Feature set definitions 15393dcf5451SChristoph Hellwig */ 15403dcf5451SChristoph Hellwig 15413dcf5451SChristoph Hellwig #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \ 15423a06d778SAneesh Kumar K.V ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0) 15433dcf5451SChristoph Hellwig #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \ 15443a06d778SAneesh Kumar K.V ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0) 15453dcf5451SChristoph Hellwig #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \ 15463a06d778SAneesh Kumar K.V ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0) 15473dcf5451SChristoph Hellwig #define EXT4_SET_COMPAT_FEATURE(sb,mask) \ 15483dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask) 15493dcf5451SChristoph Hellwig #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \ 15503dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask) 15513dcf5451SChristoph Hellwig #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \ 15523dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask) 15533dcf5451SChristoph Hellwig #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \ 15543dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask) 15553dcf5451SChristoph Hellwig #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ 15563dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask) 15573dcf5451SChristoph Hellwig #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \ 15583dcf5451SChristoph Hellwig EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask) 15593dcf5451SChristoph Hellwig 15603dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 15613dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002 15623dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 15633dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008 15643dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010 15653dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020 15661beeef1bSDarrick J. Wong #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 15673dcf5451SChristoph Hellwig 15683dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 15693dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 15703dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 15713dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 15723dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 15733dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 15743dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 1575ae812306SAditya Kali #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 1576281b5995STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 1577e6153918SDarrick J. Wong /* 1578e6153918SDarrick J. Wong * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When 1579e6153918SDarrick J. Wong * METADATA_CSUM is set, group descriptor checksums use the same algorithm as 1580e6153918SDarrick J. Wong * all other data structures' checksums. However, the METADATA_CSUM and 1581e6153918SDarrick J. Wong * GDT_CSUM bits are mutually exclusive. 1582e6153918SDarrick J. Wong */ 15839b90e5e0STheodore Ts'o #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 15842cb5cc8bSDarrick J. Wong #define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000 15853dcf5451SChristoph Hellwig 15863dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 15873dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 15883dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 15893dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 15903dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010 15913dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ 15923dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 15933dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_MMP 0x0100 15943dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 1595f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */ 1596f710b4b9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */ 1597856cbcf9STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */ 15989b90e5e0STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ 159967cf5b09STao Ma #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */ 16003edc18d8STheodore Ts'o #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 16013dcf5451SChristoph Hellwig 16022035e776STheodore Ts'o #define EXT2_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 16032035e776STheodore Ts'o #define EXT2_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 16042035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 16052035e776STheodore Ts'o #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 16062035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 16072035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 16082035e776STheodore Ts'o 16092035e776STheodore Ts'o #define EXT3_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR 16102035e776STheodore Ts'o #define EXT3_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 16112035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_RECOVER| \ 16122035e776STheodore Ts'o EXT4_FEATURE_INCOMPAT_META_BG) 16132035e776STheodore Ts'o #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 16142035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 16152035e776STheodore Ts'o EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 16162035e776STheodore Ts'o 16173dcf5451SChristoph Hellwig #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR 16183dcf5451SChristoph Hellwig #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \ 16193dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_RECOVER| \ 16203dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_META_BG| \ 16213dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_EXTENTS| \ 16223dcf5451SChristoph Hellwig EXT4_FEATURE_INCOMPAT_64BIT| \ 1623c5e06d10SJohann Lombardi EXT4_FEATURE_INCOMPAT_FLEX_BG| \ 1624f08225d1STao Ma EXT4_FEATURE_INCOMPAT_MMP | \ 16256ddb2447STheodore Ts'o EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ 16266ddb2447STheodore Ts'o EXT4_FEATURE_INCOMPAT_ENCRYPT) 16273dcf5451SChristoph Hellwig #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 16283dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 16293dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \ 16303dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ 16313dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 16323dcf5451SChristoph Hellwig EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 16336f16b606STheodore Ts'o EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\ 1634e93376c2SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_BIGALLOC |\ 16357c319d32SAditya Kali EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\ 16367c319d32SAditya Kali EXT4_FEATURE_RO_COMPAT_QUOTA) 16373dcf5451SChristoph Hellwig 16383dcf5451SChristoph Hellwig /* 16393dcf5451SChristoph Hellwig * Default values for user and/or group using reserved blocks 16403dcf5451SChristoph Hellwig */ 16413dcf5451SChristoph Hellwig #define EXT4_DEF_RESUID 0 16423dcf5451SChristoph Hellwig #define EXT4_DEF_RESGID 0 16433dcf5451SChristoph Hellwig 1644240799cdSTheodore Ts'o #define EXT4_DEF_INODE_READAHEAD_BLKS 32 1645240799cdSTheodore Ts'o 16463dcf5451SChristoph Hellwig /* 16473dcf5451SChristoph Hellwig * Default mount options 16483dcf5451SChristoph Hellwig */ 16493dcf5451SChristoph Hellwig #define EXT4_DEFM_DEBUG 0x0001 16503dcf5451SChristoph Hellwig #define EXT4_DEFM_BSDGROUPS 0x0002 16513dcf5451SChristoph Hellwig #define EXT4_DEFM_XATTR_USER 0x0004 16523dcf5451SChristoph Hellwig #define EXT4_DEFM_ACL 0x0008 16533dcf5451SChristoph Hellwig #define EXT4_DEFM_UID16 0x0010 16543dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE 0x0060 16553dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_DATA 0x0020 16563dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_ORDERED 0x0040 16573dcf5451SChristoph Hellwig #define EXT4_DEFM_JMODE_WBACK 0x0060 16588b67f04aSTheodore Ts'o #define EXT4_DEFM_NOBARRIER 0x0100 16598b67f04aSTheodore Ts'o #define EXT4_DEFM_BLOCK_VALIDITY 0x0200 16608b67f04aSTheodore Ts'o #define EXT4_DEFM_DISCARD 0x0400 16618b67f04aSTheodore Ts'o #define EXT4_DEFM_NODELALLOC 0x0800 16623dcf5451SChristoph Hellwig 16633dcf5451SChristoph Hellwig /* 166430773840STheodore Ts'o * Default journal batch times 166530773840STheodore Ts'o */ 166630773840STheodore Ts'o #define EXT4_DEF_MIN_BATCH_TIME 0 166730773840STheodore Ts'o #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ 166830773840STheodore Ts'o 166930773840STheodore Ts'o /* 1670a4912123STheodore Ts'o * Minimum number of groups in a flexgroup before we separate out 1671a4912123STheodore Ts'o * directories into the first block group of a flexgroup 1672a4912123STheodore Ts'o */ 1673a4912123STheodore Ts'o #define EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME 4 1674a4912123STheodore Ts'o 1675a4912123STheodore Ts'o /* 16763dcf5451SChristoph Hellwig * Structure of a directory entry 16773dcf5451SChristoph Hellwig */ 16783dcf5451SChristoph Hellwig #define EXT4_NAME_LEN 255 16793dcf5451SChristoph Hellwig 16803dcf5451SChristoph Hellwig struct ext4_dir_entry { 16813dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 16823dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 16833dcf5451SChristoph Hellwig __le16 name_len; /* Name length */ 16843dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 16853dcf5451SChristoph Hellwig }; 16863dcf5451SChristoph Hellwig 16873dcf5451SChristoph Hellwig /* 16883dcf5451SChristoph Hellwig * The new version of the directory entry. Since EXT4 structures are 16893dcf5451SChristoph Hellwig * stored in intel byte order, and the name_len field could never be 16903dcf5451SChristoph Hellwig * bigger than 255 chars, it's safe to reclaim the extra byte for the 16913dcf5451SChristoph Hellwig * file_type field. 16923dcf5451SChristoph Hellwig */ 16933dcf5451SChristoph Hellwig struct ext4_dir_entry_2 { 16943dcf5451SChristoph Hellwig __le32 inode; /* Inode number */ 16953dcf5451SChristoph Hellwig __le16 rec_len; /* Directory entry length */ 16963dcf5451SChristoph Hellwig __u8 name_len; /* Name length */ 16973dcf5451SChristoph Hellwig __u8 file_type; 16983dcf5451SChristoph Hellwig char name[EXT4_NAME_LEN]; /* File name */ 16993dcf5451SChristoph Hellwig }; 17003dcf5451SChristoph Hellwig 17013dcf5451SChristoph Hellwig /* 1702e6153918SDarrick J. Wong * This is a bogus directory entry at the end of each leaf block that 1703e6153918SDarrick J. Wong * records checksums. 1704e6153918SDarrick J. Wong */ 1705e6153918SDarrick J. Wong struct ext4_dir_entry_tail { 1706e6153918SDarrick J. Wong __le32 det_reserved_zero1; /* Pretend to be unused */ 1707e6153918SDarrick J. Wong __le16 det_rec_len; /* 12 */ 1708e6153918SDarrick J. Wong __u8 det_reserved_zero2; /* Zero name length */ 1709e6153918SDarrick J. Wong __u8 det_reserved_ft; /* 0xDE, fake file type */ 1710e6153918SDarrick J. Wong __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */ 1711e6153918SDarrick J. Wong }; 1712e6153918SDarrick J. Wong 17133c47d541STao Ma #define EXT4_DIRENT_TAIL(block, blocksize) \ 17143c47d541STao Ma ((struct ext4_dir_entry_tail *)(((void *)(block)) + \ 17153c47d541STao Ma ((blocksize) - \ 17163c47d541STao Ma sizeof(struct ext4_dir_entry_tail)))) 17173c47d541STao Ma 1718e6153918SDarrick J. Wong /* 17193dcf5451SChristoph Hellwig * Ext4 directory file types. Only the low 3 bits are used. The 17203dcf5451SChristoph Hellwig * other bits are reserved for now. 17213dcf5451SChristoph Hellwig */ 17223dcf5451SChristoph Hellwig #define EXT4_FT_UNKNOWN 0 17233dcf5451SChristoph Hellwig #define EXT4_FT_REG_FILE 1 17243dcf5451SChristoph Hellwig #define EXT4_FT_DIR 2 17253dcf5451SChristoph Hellwig #define EXT4_FT_CHRDEV 3 17263dcf5451SChristoph Hellwig #define EXT4_FT_BLKDEV 4 17273dcf5451SChristoph Hellwig #define EXT4_FT_FIFO 5 17283dcf5451SChristoph Hellwig #define EXT4_FT_SOCK 6 17293dcf5451SChristoph Hellwig #define EXT4_FT_SYMLINK 7 17303dcf5451SChristoph Hellwig 17313dcf5451SChristoph Hellwig #define EXT4_FT_MAX 8 17323dcf5451SChristoph Hellwig 1733e6153918SDarrick J. Wong #define EXT4_FT_DIR_CSUM 0xDE 1734e6153918SDarrick J. Wong 17353dcf5451SChristoph Hellwig /* 17363dcf5451SChristoph Hellwig * EXT4_DIR_PAD defines the directory entries boundaries 17373dcf5451SChristoph Hellwig * 17383dcf5451SChristoph Hellwig * NOTE: It must be a multiple of 4 17393dcf5451SChristoph Hellwig */ 17403dcf5451SChristoph Hellwig #define EXT4_DIR_PAD 4 17413dcf5451SChristoph Hellwig #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1) 17423dcf5451SChristoph Hellwig #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \ 17433dcf5451SChristoph Hellwig ~EXT4_DIR_ROUND) 17443dcf5451SChristoph Hellwig #define EXT4_MAX_REC_LEN ((1<<16)-1) 17453dcf5451SChristoph Hellwig 17463dcf5451SChristoph Hellwig /* 17470cfc9255SEric Sandeen * If we ever get support for fs block sizes > page_size, we'll need 17480cfc9255SEric Sandeen * to remove the #if statements in the next two functions... 17490cfc9255SEric Sandeen */ 17500cfc9255SEric Sandeen static inline unsigned int 17510cfc9255SEric Sandeen ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize) 17520cfc9255SEric Sandeen { 17530cfc9255SEric Sandeen unsigned len = le16_to_cpu(dlen); 17540cfc9255SEric Sandeen 17550cfc9255SEric Sandeen #if (PAGE_CACHE_SIZE >= 65536) 17560cfc9255SEric Sandeen if (len == EXT4_MAX_REC_LEN || len == 0) 17570cfc9255SEric Sandeen return blocksize; 17580cfc9255SEric Sandeen return (len & 65532) | ((len & 3) << 16); 17590cfc9255SEric Sandeen #else 17600cfc9255SEric Sandeen return len; 17610cfc9255SEric Sandeen #endif 17620cfc9255SEric Sandeen } 17630cfc9255SEric Sandeen 17640cfc9255SEric Sandeen static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) 17650cfc9255SEric Sandeen { 17660cfc9255SEric Sandeen if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)) 17670cfc9255SEric Sandeen BUG(); 17680cfc9255SEric Sandeen #if (PAGE_CACHE_SIZE >= 65536) 17690cfc9255SEric Sandeen if (len < 65536) 17700cfc9255SEric Sandeen return cpu_to_le16(len); 17710cfc9255SEric Sandeen if (len == blocksize) { 17720cfc9255SEric Sandeen if (blocksize == 65536) 17730cfc9255SEric Sandeen return cpu_to_le16(EXT4_MAX_REC_LEN); 17740cfc9255SEric Sandeen else 17750cfc9255SEric Sandeen return cpu_to_le16(0); 17760cfc9255SEric Sandeen } 17770cfc9255SEric Sandeen return cpu_to_le16((len & 65532) | ((len >> 16) & 3)); 17780cfc9255SEric Sandeen #else 17790cfc9255SEric Sandeen return cpu_to_le16(len); 17800cfc9255SEric Sandeen #endif 17810cfc9255SEric Sandeen } 17820cfc9255SEric Sandeen 17830cfc9255SEric Sandeen /* 17843dcf5451SChristoph Hellwig * Hash Tree Directory indexing 17853dcf5451SChristoph Hellwig * (c) Daniel Phillips, 2001 17863dcf5451SChristoph Hellwig */ 17873dcf5451SChristoph Hellwig 17883dcf5451SChristoph Hellwig #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \ 17893dcf5451SChristoph Hellwig EXT4_FEATURE_COMPAT_DIR_INDEX) && \ 179012e9b892SDmitry Monakhov ext4_test_inode_flag((dir), EXT4_INODE_INDEX)) 17913dcf5451SChristoph Hellwig #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX) 17923dcf5451SChristoph Hellwig #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 17933dcf5451SChristoph Hellwig 17943dcf5451SChristoph Hellwig /* Legal values for the dx_root hash_version field: */ 17953dcf5451SChristoph Hellwig 17963dcf5451SChristoph Hellwig #define DX_HASH_LEGACY 0 17973dcf5451SChristoph Hellwig #define DX_HASH_HALF_MD4 1 17983dcf5451SChristoph Hellwig #define DX_HASH_TEA 2 1799f99b2589STheodore Ts'o #define DX_HASH_LEGACY_UNSIGNED 3 1800f99b2589STheodore Ts'o #define DX_HASH_HALF_MD4_UNSIGNED 4 1801f99b2589STheodore Ts'o #define DX_HASH_TEA_UNSIGNED 5 18023dcf5451SChristoph Hellwig 18030441984aSDarrick J. Wong static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc, 18040441984aSDarrick J. Wong const void *address, unsigned int length) 18050441984aSDarrick J. Wong { 18060441984aSDarrick J. Wong struct { 18070441984aSDarrick J. Wong struct shash_desc shash; 18083108b54bSTheodore Ts'o char ctx[4]; 18090441984aSDarrick J. Wong } desc; 18100441984aSDarrick J. Wong int err; 18110441984aSDarrick J. Wong 18123108b54bSTheodore Ts'o BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx)); 18133108b54bSTheodore Ts'o 18140441984aSDarrick J. Wong desc.shash.tfm = sbi->s_chksum_driver; 18150441984aSDarrick J. Wong desc.shash.flags = 0; 18160441984aSDarrick J. Wong *(u32 *)desc.ctx = crc; 18170441984aSDarrick J. Wong 18180441984aSDarrick J. Wong err = crypto_shash_update(&desc.shash, address, length); 18190441984aSDarrick J. Wong BUG_ON(err); 18200441984aSDarrick J. Wong 18210441984aSDarrick J. Wong return *(u32 *)desc.ctx; 18220441984aSDarrick J. Wong } 18230441984aSDarrick J. Wong 18243dcf5451SChristoph Hellwig #ifdef __KERNEL__ 18253dcf5451SChristoph Hellwig 18263dcf5451SChristoph Hellwig /* hash info structure used by the directory hash */ 18273dcf5451SChristoph Hellwig struct dx_hash_info 18283dcf5451SChristoph Hellwig { 18293dcf5451SChristoph Hellwig u32 hash; 18303dcf5451SChristoph Hellwig u32 minor_hash; 18313dcf5451SChristoph Hellwig int hash_version; 18323dcf5451SChristoph Hellwig u32 *seed; 18333dcf5451SChristoph Hellwig }; 18343dcf5451SChristoph Hellwig 1835d1f5273eSFan Yong 1836d1f5273eSFan Yong /* 32 and 64 bit signed EOF for dx directories */ 1837d1f5273eSFan Yong #define EXT4_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1) 1838d1f5273eSFan Yong #define EXT4_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1) 1839d1f5273eSFan Yong 18403dcf5451SChristoph Hellwig 18413dcf5451SChristoph Hellwig /* 18423dcf5451SChristoph Hellwig * Control parameters used by ext4_htree_next_block 18433dcf5451SChristoph Hellwig */ 18443dcf5451SChristoph Hellwig #define HASH_NB_ALWAYS 1 18453dcf5451SChristoph Hellwig 18463dcf5451SChristoph Hellwig 18473dcf5451SChristoph Hellwig /* 18483dcf5451SChristoph Hellwig * Describe an inode's exact location on disk and in memory 18493dcf5451SChristoph Hellwig */ 18503dcf5451SChristoph Hellwig struct ext4_iloc 18513dcf5451SChristoph Hellwig { 18523dcf5451SChristoph Hellwig struct buffer_head *bh; 18533dcf5451SChristoph Hellwig unsigned long offset; 18543dcf5451SChristoph Hellwig ext4_group_t block_group; 18553dcf5451SChristoph Hellwig }; 18563dcf5451SChristoph Hellwig 18573dcf5451SChristoph Hellwig static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc) 18583dcf5451SChristoph Hellwig { 18593dcf5451SChristoph Hellwig return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset); 18603dcf5451SChristoph Hellwig } 18613dcf5451SChristoph Hellwig 18623dcf5451SChristoph Hellwig /* 18633dcf5451SChristoph Hellwig * This structure is stuffed into the struct file's private_data field 18643dcf5451SChristoph Hellwig * for directories. It is where we put information so that we can do 18653dcf5451SChristoph Hellwig * readdir operations in hash tree order. 18663dcf5451SChristoph Hellwig */ 18673dcf5451SChristoph Hellwig struct dir_private_info { 18683dcf5451SChristoph Hellwig struct rb_root root; 18693dcf5451SChristoph Hellwig struct rb_node *curr_node; 18703dcf5451SChristoph Hellwig struct fname *extra_fname; 18713dcf5451SChristoph Hellwig loff_t last_pos; 18723dcf5451SChristoph Hellwig __u32 curr_hash; 18733dcf5451SChristoph Hellwig __u32 curr_minor_hash; 18743dcf5451SChristoph Hellwig __u32 next_hash; 18753dcf5451SChristoph Hellwig }; 18763dcf5451SChristoph Hellwig 18773dcf5451SChristoph Hellwig /* calculate the first block number of the group */ 18783dcf5451SChristoph Hellwig static inline ext4_fsblk_t 18793dcf5451SChristoph Hellwig ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no) 18803dcf5451SChristoph Hellwig { 18813dcf5451SChristoph Hellwig return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + 18823dcf5451SChristoph Hellwig le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 18833dcf5451SChristoph Hellwig } 18843dcf5451SChristoph Hellwig 18853dcf5451SChristoph Hellwig /* 18863dcf5451SChristoph Hellwig * Special error return code only used by dx_probe() and its callers. 18873dcf5451SChristoph Hellwig */ 188836de9286STheodore Ts'o #define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1)) 18893dcf5451SChristoph Hellwig 18903dcf5451SChristoph Hellwig /* 1891bfff6873SLukas Czerner * Timeout and state flag for lazy initialization inode thread. 1892bfff6873SLukas Czerner */ 1893bfff6873SLukas Czerner #define EXT4_DEF_LI_WAIT_MULT 10 1894bfff6873SLukas Czerner #define EXT4_DEF_LI_MAX_START_DELAY 5 1895bfff6873SLukas Czerner #define EXT4_LAZYINIT_QUIT 0x0001 1896bfff6873SLukas Czerner #define EXT4_LAZYINIT_RUNNING 0x0002 1897bfff6873SLukas Czerner 1898bfff6873SLukas Czerner /* 1899bfff6873SLukas Czerner * Lazy inode table initialization info 1900bfff6873SLukas Czerner */ 1901bfff6873SLukas Czerner struct ext4_lazy_init { 1902bfff6873SLukas Czerner unsigned long li_state; 1903bfff6873SLukas Czerner struct list_head li_request_list; 1904bfff6873SLukas Czerner struct mutex li_list_mtx; 1905bfff6873SLukas Czerner }; 1906bfff6873SLukas Czerner 1907bfff6873SLukas Czerner struct ext4_li_request { 1908bfff6873SLukas Czerner struct super_block *lr_super; 1909bfff6873SLukas Czerner struct ext4_sb_info *lr_sbi; 1910bfff6873SLukas Czerner ext4_group_t lr_next_group; 1911bfff6873SLukas Czerner struct list_head lr_request; 1912bfff6873SLukas Czerner unsigned long lr_next_sched; 1913bfff6873SLukas Czerner unsigned long lr_timeout; 1914bfff6873SLukas Czerner }; 1915bfff6873SLukas Czerner 1916857ac889SLukas Czerner struct ext4_features { 1917857ac889SLukas Czerner struct kobject f_kobj; 1918857ac889SLukas Czerner struct completion f_kobj_unregister; 1919857ac889SLukas Czerner }; 1920857ac889SLukas Czerner 1921bfff6873SLukas Czerner /* 1922c5e06d10SJohann Lombardi * This structure will be used for multiple mount protection. It will be 1923c5e06d10SJohann Lombardi * written into the block number saved in the s_mmp_block field in the 1924c5e06d10SJohann Lombardi * superblock. Programs that check MMP should assume that if 1925c5e06d10SJohann Lombardi * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe 1926c5e06d10SJohann Lombardi * to use the filesystem, regardless of how old the timestamp is. 1927c5e06d10SJohann Lombardi */ 1928c5e06d10SJohann Lombardi #define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ 1929c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ 1930c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ 1931c5e06d10SJohann Lombardi #define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ 1932c5e06d10SJohann Lombardi 1933c5e06d10SJohann Lombardi struct mmp_struct { 1934c5e06d10SJohann Lombardi __le32 mmp_magic; /* Magic number for MMP */ 1935c5e06d10SJohann Lombardi __le32 mmp_seq; /* Sequence no. updated periodically */ 1936c5e06d10SJohann Lombardi 1937c5e06d10SJohann Lombardi /* 1938c5e06d10SJohann Lombardi * mmp_time, mmp_nodename & mmp_bdevname are only used for information 1939c5e06d10SJohann Lombardi * purposes and do not affect the correctness of the algorithm 1940c5e06d10SJohann Lombardi */ 1941c5e06d10SJohann Lombardi __le64 mmp_time; /* Time last updated */ 1942c5e06d10SJohann Lombardi char mmp_nodename[64]; /* Node which last updated MMP block */ 1943c5e06d10SJohann Lombardi char mmp_bdevname[32]; /* Bdev which last updated MMP block */ 1944c5e06d10SJohann Lombardi 1945c5e06d10SJohann Lombardi /* 1946c5e06d10SJohann Lombardi * mmp_check_interval is used to verify if the MMP block has been 1947c5e06d10SJohann Lombardi * updated on the block device. The value is updated based on the 1948c5e06d10SJohann Lombardi * maximum time to write the MMP block during an update cycle. 1949c5e06d10SJohann Lombardi */ 1950c5e06d10SJohann Lombardi __le16 mmp_check_interval; 1951c5e06d10SJohann Lombardi 1952c5e06d10SJohann Lombardi __le16 mmp_pad1; 1953e6153918SDarrick J. Wong __le32 mmp_pad2[226]; 1954e6153918SDarrick J. Wong __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */ 1955c5e06d10SJohann Lombardi }; 1956c5e06d10SJohann Lombardi 1957c5e06d10SJohann Lombardi /* arguments passed to the mmp thread */ 1958c5e06d10SJohann Lombardi struct mmpd_data { 1959c5e06d10SJohann Lombardi struct buffer_head *bh; /* bh from initial read_mmp_block() */ 1960c5e06d10SJohann Lombardi struct super_block *sb; /* super block of the fs */ 1961c5e06d10SJohann Lombardi }; 1962c5e06d10SJohann Lombardi 1963c5e06d10SJohann Lombardi /* 1964c5e06d10SJohann Lombardi * Check interval multiplier 1965c5e06d10SJohann Lombardi * The MMP block is written every update interval and initially checked every 1966c5e06d10SJohann Lombardi * update interval x the multiplier (the value is then adapted based on the 1967c5e06d10SJohann Lombardi * write latency). The reason is that writes can be delayed under load and we 1968c5e06d10SJohann Lombardi * don't want readers to incorrectly assume that the filesystem is no longer 1969c5e06d10SJohann Lombardi * in use. 1970c5e06d10SJohann Lombardi */ 1971c5e06d10SJohann Lombardi #define EXT4_MMP_CHECK_MULT 2UL 1972c5e06d10SJohann Lombardi 1973c5e06d10SJohann Lombardi /* 1974c5e06d10SJohann Lombardi * Minimum interval for MMP checking in seconds. 1975c5e06d10SJohann Lombardi */ 1976c5e06d10SJohann Lombardi #define EXT4_MMP_MIN_CHECK_INTERVAL 5UL 1977c5e06d10SJohann Lombardi 1978c5e06d10SJohann Lombardi /* 1979c5e06d10SJohann Lombardi * Maximum interval for MMP checking in seconds. 1980c5e06d10SJohann Lombardi */ 1981c5e06d10SJohann Lombardi #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL 1982c5e06d10SJohann Lombardi 1983c5e06d10SJohann Lombardi /* 19843dcf5451SChristoph Hellwig * Function prototypes 19853dcf5451SChristoph Hellwig */ 19863dcf5451SChristoph Hellwig 19873dcf5451SChristoph Hellwig /* 19883dcf5451SChristoph Hellwig * Ok, these declarations are also in <linux/kernel.h> but none of the 19893dcf5451SChristoph Hellwig * ext4 source programs needs to include it so they are duplicated here. 19903dcf5451SChristoph Hellwig */ 19913dcf5451SChristoph Hellwig # define NORET_TYPE /**/ 19923dcf5451SChristoph Hellwig # define ATTRIB_NORET __attribute__((noreturn)) 19933dcf5451SChristoph Hellwig # define NORET_AND noreturn, 19943dcf5451SChristoph Hellwig 1995498e5f24STheodore Ts'o /* bitmap.c */ 1996f6fb99caSTheodore Ts'o extern unsigned int ext4_count_free(char *bitmap, unsigned numchars); 199741a246d1SDarrick J. Wong void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 199841a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 199941a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 200041a246d1SDarrick J. Wong int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 200141a246d1SDarrick J. Wong struct ext4_group_desc *gdp, 200241a246d1SDarrick J. Wong struct buffer_head *bh, int sz); 2003fa77dcfaSDarrick J. Wong void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group, 2004fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 200579f1ba49STao Ma struct buffer_head *bh); 2006fa77dcfaSDarrick J. Wong int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, 2007fa77dcfaSDarrick J. Wong struct ext4_group_desc *gdp, 200879f1ba49STao Ma struct buffer_head *bh); 2009498e5f24STheodore Ts'o 20103dcf5451SChristoph Hellwig /* balloc.c */ 2011bd86298eSLukas Czerner extern void ext4_get_group_no_and_offset(struct super_block *sb, 2012bd86298eSLukas Czerner ext4_fsblk_t blocknr, 2013bd86298eSLukas Czerner ext4_group_t *blockgrpp, 2014bd86298eSLukas Czerner ext4_grpblk_t *offsetp); 2015bd86298eSLukas Czerner extern ext4_group_t ext4_get_group_number(struct super_block *sb, 2016bd86298eSLukas Czerner ext4_fsblk_t block); 2017bd86298eSLukas Czerner 20183dcf5451SChristoph Hellwig extern unsigned int ext4_block_group(struct super_block *sb, 20193dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 20203dcf5451SChristoph Hellwig extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb, 20213dcf5451SChristoph Hellwig ext4_fsblk_t blocknr); 20223dcf5451SChristoph Hellwig extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group); 20233dcf5451SChristoph Hellwig extern unsigned long ext4_bg_num_gdb(struct super_block *sb, 20243dcf5451SChristoph Hellwig ext4_group_t group); 20257061eba7SAneesh Kumar K.V extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 202655f020dbSAllison Henderson ext4_fsblk_t goal, 202755f020dbSAllison Henderson unsigned int flags, 202855f020dbSAllison Henderson unsigned long *count, 202955f020dbSAllison Henderson int *errp); 2030e7d5f315STheodore Ts'o extern int ext4_claim_free_clusters(struct ext4_sb_info *sbi, 2031e7d5f315STheodore Ts'o s64 nclusters, unsigned int flags); 20325dee5437STheodore Ts'o extern ext4_fsblk_t ext4_count_free_clusters(struct super_block *); 20333dcf5451SChristoph Hellwig extern void ext4_check_blocks_bitmap(struct super_block *); 20343dcf5451SChristoph Hellwig extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 20353dcf5451SChristoph Hellwig ext4_group_t block_group, 20363dcf5451SChristoph Hellwig struct buffer_head ** bh); 20373dcf5451SChristoph Hellwig extern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 2038813e5727STheodore Ts'o 2039813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap_nowait(struct super_block *sb, 2040813e5727STheodore Ts'o ext4_group_t block_group); 2041813e5727STheodore Ts'o extern int ext4_wait_block_bitmap(struct super_block *sb, 2042813e5727STheodore Ts'o ext4_group_t block_group, 2043813e5727STheodore Ts'o struct buffer_head *bh); 2044813e5727STheodore Ts'o extern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb, 2045bb23c20aSTheodore Ts'o ext4_group_t block_group); 2046cff1dfd7STheodore Ts'o extern unsigned ext4_free_clusters_after_init(struct super_block *sb, 2047fd034a84STheodore Ts'o ext4_group_t block_group, 2048fd034a84STheodore Ts'o struct ext4_group_desc *gdp); 2049f86186b4SEric Sandeen ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); 20503dcf5451SChristoph Hellwig 20519bd8212fSMichael Halcrow /* crypto_policy.c */ 20529bd8212fSMichael Halcrow int ext4_is_child_context_consistent_with_parent(struct inode *parent, 20539bd8212fSMichael Halcrow struct inode *child); 20549bd8212fSMichael Halcrow int ext4_inherit_context(struct inode *parent, struct inode *child); 20559bd8212fSMichael Halcrow void ext4_to_hex(char *dst, char *src, size_t src_size); 20569bd8212fSMichael Halcrow int ext4_process_policy(const struct ext4_encryption_policy *policy, 20579bd8212fSMichael Halcrow struct inode *inode); 20589bd8212fSMichael Halcrow int ext4_get_policy(struct inode *inode, 20599bd8212fSMichael Halcrow struct ext4_encryption_policy *policy); 20609bd8212fSMichael Halcrow 2061b30ab0e0SMichael Halcrow /* crypto.c */ 2062b30ab0e0SMichael Halcrow bool ext4_valid_contents_enc_mode(uint32_t mode); 2063b30ab0e0SMichael Halcrow uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size); 2064b30ab0e0SMichael Halcrow extern struct workqueue_struct *ext4_read_workqueue; 2065b30ab0e0SMichael Halcrow struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode); 2066b30ab0e0SMichael Halcrow void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); 2067b30ab0e0SMichael Halcrow void ext4_restore_control_page(struct page *data_page); 2068b30ab0e0SMichael Halcrow struct page *ext4_encrypt(struct inode *inode, 2069b30ab0e0SMichael Halcrow struct page *plaintext_page); 2070b30ab0e0SMichael Halcrow int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page); 2071b30ab0e0SMichael Halcrow int ext4_decrypt_one(struct inode *inode, struct page *page); 2072b30ab0e0SMichael Halcrow int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex); 2073b30ab0e0SMichael Halcrow 2074b30ab0e0SMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 2075b30ab0e0SMichael Halcrow int ext4_init_crypto(void); 2076b30ab0e0SMichael Halcrow void ext4_exit_crypto(void); 2077b30ab0e0SMichael Halcrow static inline int ext4_sb_has_crypto(struct super_block *sb) 2078b30ab0e0SMichael Halcrow { 2079b30ab0e0SMichael Halcrow return EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT); 2080b30ab0e0SMichael Halcrow } 2081b30ab0e0SMichael Halcrow #else 2082b30ab0e0SMichael Halcrow static inline int ext4_init_crypto(void) { return 0; } 2083b30ab0e0SMichael Halcrow static inline void ext4_exit_crypto(void) { } 2084b30ab0e0SMichael Halcrow static inline int ext4_sb_has_crypto(struct super_block *sb) 2085b30ab0e0SMichael Halcrow { 2086b30ab0e0SMichael Halcrow return 0; 2087b30ab0e0SMichael Halcrow } 2088b30ab0e0SMichael Halcrow #endif 2089b30ab0e0SMichael Halcrow 2090d5d0e8c7SMichael Halcrow /* crypto_fname.c */ 2091d5d0e8c7SMichael Halcrow bool ext4_valid_filenames_enc_mode(uint32_t mode); 2092d5d0e8c7SMichael Halcrow u32 ext4_fname_crypto_round_up(u32 size, u32 blksize); 2093d5d0e8c7SMichael Halcrow int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx, 2094d5d0e8c7SMichael Halcrow u32 ilen, struct ext4_str *crypto_str); 2095d5d0e8c7SMichael Halcrow int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 20965de0b4d0STheodore Ts'o struct dx_hash_info *hinfo, 2097d5d0e8c7SMichael Halcrow const struct ext4_str *iname, 2098d5d0e8c7SMichael Halcrow struct ext4_str *oname); 2099d5d0e8c7SMichael Halcrow int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 21005de0b4d0STheodore Ts'o struct dx_hash_info *hinfo, 2101d5d0e8c7SMichael Halcrow const struct ext4_dir_entry_2 *de, 2102d5d0e8c7SMichael Halcrow struct ext4_str *oname); 2103d5d0e8c7SMichael Halcrow int ext4_fname_usr_to_disk(struct ext4_fname_crypto_ctx *ctx, 2104d5d0e8c7SMichael Halcrow const struct qstr *iname, 2105d5d0e8c7SMichael Halcrow struct ext4_str *oname); 2106d5d0e8c7SMichael Halcrow int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx, 2107d5d0e8c7SMichael Halcrow const struct qstr *iname, 2108d5d0e8c7SMichael Halcrow struct dx_hash_info *hinfo); 2109d5d0e8c7SMichael Halcrow int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx, 2110d5d0e8c7SMichael Halcrow u32 namelen); 21115de0b4d0STheodore Ts'o int ext4_fname_match(struct ext4_fname_crypto_ctx *ctx, struct ext4_str *cstr, 21125de0b4d0STheodore Ts'o int len, const char * const name, 21135de0b4d0STheodore Ts'o struct ext4_dir_entry_2 *de); 21145de0b4d0STheodore Ts'o 2115d5d0e8c7SMichael Halcrow 2116d5d0e8c7SMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 2117d5d0e8c7SMichael Halcrow void ext4_put_fname_crypto_ctx(struct ext4_fname_crypto_ctx **ctx); 2118d5d0e8c7SMichael Halcrow struct ext4_fname_crypto_ctx *ext4_get_fname_crypto_ctx(struct inode *inode, 2119d5d0e8c7SMichael Halcrow u32 max_len); 2120d5d0e8c7SMichael Halcrow void ext4_fname_crypto_free_buffer(struct ext4_str *crypto_str); 2121d5d0e8c7SMichael Halcrow #else 2122d5d0e8c7SMichael Halcrow static inline 2123d5d0e8c7SMichael Halcrow void ext4_put_fname_crypto_ctx(struct ext4_fname_crypto_ctx **ctx) { } 2124d5d0e8c7SMichael Halcrow static inline 2125d5d0e8c7SMichael Halcrow struct ext4_fname_crypto_ctx *ext4_get_fname_crypto_ctx(struct inode *inode, 2126d5d0e8c7SMichael Halcrow u32 max_len) 2127d5d0e8c7SMichael Halcrow { 2128d5d0e8c7SMichael Halcrow return NULL; 2129d5d0e8c7SMichael Halcrow } 2130d5d0e8c7SMichael Halcrow static inline void ext4_fname_crypto_free_buffer(struct ext4_str *p) { } 2131d5d0e8c7SMichael Halcrow #endif 2132d5d0e8c7SMichael Halcrow 2133d5d0e8c7SMichael Halcrow 213488bd6ccdSMichael Halcrow /* crypto_key.c */ 213588bd6ccdSMichael Halcrow int ext4_generate_encryption_key(struct inode *inode); 213688bd6ccdSMichael Halcrow 213788bd6ccdSMichael Halcrow #ifdef CONFIG_EXT4_FS_ENCRYPTION 213888bd6ccdSMichael Halcrow int ext4_has_encryption_key(struct inode *inode); 213988bd6ccdSMichael Halcrow #else 214088bd6ccdSMichael Halcrow static inline int ext4_has_encryption_key(struct inode *inode) 214188bd6ccdSMichael Halcrow { 214288bd6ccdSMichael Halcrow return 0; 214388bd6ccdSMichael Halcrow } 214488bd6ccdSMichael Halcrow #endif 214588bd6ccdSMichael Halcrow 214688bd6ccdSMichael Halcrow 21473dcf5451SChristoph Hellwig /* dir.c */ 214860fd4da3STheodore Ts'o extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *, 2149f7c21177STheodore Ts'o struct file *, 21503dcf5451SChristoph Hellwig struct ext4_dir_entry_2 *, 2151226ba972STao Ma struct buffer_head *, char *, int, 2152226ba972STao Ma unsigned int); 2153226ba972STao Ma #define ext4_check_dir_entry(dir, filp, de, bh, buf, size, offset) \ 2154f7c21177STheodore Ts'o unlikely(__ext4_check_dir_entry(__func__, __LINE__, (dir), (filp), \ 2155226ba972STao Ma (de), (bh), (buf), (size), (offset))) 21563dcf5451SChristoph Hellwig extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 21573dcf5451SChristoph Hellwig __u32 minor_hash, 21582f61830aSTheodore Ts'o struct ext4_dir_entry_2 *dirent, 21592f61830aSTheodore Ts'o struct ext4_str *ent_name); 21603dcf5451SChristoph Hellwig extern void ext4_htree_free_dir_info(struct dir_private_info *p); 2161978fef91STao Ma extern int ext4_find_dest_de(struct inode *dir, struct inode *inode, 2162978fef91STao Ma struct buffer_head *bh, 2163978fef91STao Ma void *buf, int buf_size, 2164978fef91STao Ma const char *name, int namelen, 2165978fef91STao Ma struct ext4_dir_entry_2 **dest_de); 21664bdfc873SMichael Halcrow int ext4_insert_dentry(struct inode *dir, 21674bdfc873SMichael Halcrow struct inode *inode, 2168978fef91STao Ma struct ext4_dir_entry_2 *de, 2169978fef91STao Ma int buf_size, 21704bdfc873SMichael Halcrow const struct qstr *iname, 2171978fef91STao Ma const char *name, int namelen); 2172978fef91STao Ma static inline void ext4_update_dx_flag(struct inode *inode) 2173978fef91STao Ma { 2174978fef91STao Ma if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb, 2175978fef91STao Ma EXT4_FEATURE_COMPAT_DIR_INDEX)) 2176978fef91STao Ma ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); 2177978fef91STao Ma } 217865d165d9STao Ma static unsigned char ext4_filetype_table[] = { 217965d165d9STao Ma DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 218065d165d9STao Ma }; 218165d165d9STao Ma 218265d165d9STao Ma static inline unsigned char get_dtype(struct super_block *sb, int filetype) 218365d165d9STao Ma { 218465d165d9STao Ma if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) || 218565d165d9STao Ma (filetype >= EXT4_FT_MAX)) 218665d165d9STao Ma return DT_UNKNOWN; 218765d165d9STao Ma 218865d165d9STao Ma return ext4_filetype_table[filetype]; 218965d165d9STao Ma } 219040b163f1SDarrick J. Wong extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, 219140b163f1SDarrick J. Wong void *buf, int buf_size); 21923dcf5451SChristoph Hellwig 21933dcf5451SChristoph Hellwig /* fsync.c */ 219402c24a82SJosef Bacik extern int ext4_sync_file(struct file *, loff_t, loff_t, int); 21953dcf5451SChristoph Hellwig 21963dcf5451SChristoph Hellwig /* hash.c */ 21973dcf5451SChristoph Hellwig extern int ext4fs_dirhash(const char *name, int len, struct 21983dcf5451SChristoph Hellwig dx_hash_info *hinfo); 21993dcf5451SChristoph Hellwig 22003dcf5451SChristoph Hellwig /* ialloc.c */ 22011139575aSTheodore Ts'o extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t, 22025cb81dabSDmitry Monakhov const struct qstr *qstr, __u32 goal, 22031139575aSTheodore Ts'o uid_t *owner, int handle_type, 22041139575aSTheodore Ts'o unsigned int line_no, int nblocks); 22051139575aSTheodore Ts'o 22061139575aSTheodore Ts'o #define ext4_new_inode(handle, dir, mode, qstr, goal, owner) \ 22071139575aSTheodore Ts'o __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \ 22081139575aSTheodore Ts'o 0, 0, 0) 22091139575aSTheodore Ts'o #define ext4_new_inode_start_handle(dir, mode, qstr, goal, owner, \ 22101139575aSTheodore Ts'o type, nblocks) \ 22111139575aSTheodore Ts'o __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \ 22121139575aSTheodore Ts'o (type), __LINE__, (nblocks)) 22131139575aSTheodore Ts'o 22141139575aSTheodore Ts'o 22153dcf5451SChristoph Hellwig extern void ext4_free_inode(handle_t *, struct inode *); 22163dcf5451SChristoph Hellwig extern struct inode * ext4_orphan_get(struct super_block *, unsigned long); 22173dcf5451SChristoph Hellwig extern unsigned long ext4_count_free_inodes(struct super_block *); 22183dcf5451SChristoph Hellwig extern unsigned long ext4_count_dirs(struct super_block *); 22193dcf5451SChristoph Hellwig extern void ext4_check_inodes_bitmap(struct super_block *); 222061d08673STheodore Ts'o extern void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap); 2221bfff6873SLukas Czerner extern int ext4_init_inode_table(struct super_block *sb, 2222bfff6873SLukas Czerner ext4_group_t group, int barrier); 2223813e5727STheodore Ts'o extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 22243dcf5451SChristoph Hellwig 22253dcf5451SChristoph Hellwig /* mballoc.c */ 22263dcf5451SChristoph Hellwig extern long ext4_mb_stats; 22273dcf5451SChristoph Hellwig extern long ext4_mb_max_to_scan; 22289d99012fSAkira Fujita extern int ext4_mb_init(struct super_block *); 22293dcf5451SChristoph Hellwig extern int ext4_mb_release(struct super_block *); 22303dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 22313dcf5451SChristoph Hellwig struct ext4_allocation_request *, int *); 22323dcf5451SChristoph Hellwig extern int ext4_mb_reserve_blocks(struct super_block *, int); 2233c2ea3fdeSTheodore Ts'o extern void ext4_discard_preallocations(struct inode *); 22345dabfc78STheodore Ts'o extern int __init ext4_init_mballoc(void); 22355dabfc78STheodore Ts'o extern void ext4_exit_mballoc(void); 223644338711STheodore Ts'o extern void ext4_free_blocks(handle_t *handle, struct inode *inode, 2237e6362609STheodore Ts'o struct buffer_head *bh, ext4_fsblk_t block, 2238e6362609STheodore Ts'o unsigned long count, int flags); 223928623c2fSTheodore Ts'o extern int ext4_mb_alloc_groupinfo(struct super_block *sb, 224028623c2fSTheodore Ts'o ext4_group_t ngroups); 2241920313a7SAneesh Kumar K.V extern int ext4_mb_add_groupinfo(struct super_block *sb, 22425f21b0e6SFrederic Bohe ext4_group_t i, struct ext4_group_desc *desc); 2243cc7365dfSYongqiang Yang extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, 22442846e820SAmir Goldstein ext4_fsblk_t block, unsigned long count); 22457360d173SLukas Czerner extern int ext4_trim_fs(struct super_block *, struct fstrim_range *); 22467360d173SLukas Czerner 22473dcf5451SChristoph Hellwig /* inode.c */ 2248f348c252STheodore Ts'o int ext4_inode_is_fast_symlink(struct inode *inode); 224910560082STheodore Ts'o struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); 22501c215028STheodore Ts'o struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); 2251f19d5870STao Ma int ext4_get_block_write(struct inode *inode, sector_t iblock, 2252f19d5870STao Ma struct buffer_head *bh_result, int create); 22536873fa0dSEric Sandeen int ext4_get_block(struct inode *inode, sector_t iblock, 22546873fa0dSEric Sandeen struct buffer_head *bh_result, int create); 22559c3569b5STao Ma int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, 22569c3569b5STao Ma struct buffer_head *bh, int create); 2257f19d5870STao Ma int ext4_walk_page_buffers(handle_t *handle, 2258f19d5870STao Ma struct buffer_head *head, 2259f19d5870STao Ma unsigned from, 2260f19d5870STao Ma unsigned to, 2261f19d5870STao Ma int *partial, 2262f19d5870STao Ma int (*fn)(handle_t *handle, 2263f19d5870STao Ma struct buffer_head *bh)); 2264f19d5870STao Ma int do_journal_get_write_access(handle_t *handle, 2265f19d5870STao Ma struct buffer_head *bh); 22669c3569b5STao Ma #define FALL_BACK_TO_NONDELALLOC 1 22679c3569b5STao Ma #define CONVERT_INLINE_DATA 2 22683dcf5451SChristoph Hellwig 22693dcf5451SChristoph Hellwig extern struct inode *ext4_iget(struct super_block *, unsigned long); 2270f4bb2981STheodore Ts'o extern struct inode *ext4_iget_normal(struct super_block *, unsigned long); 2271a9185b41SChristoph Hellwig extern int ext4_write_inode(struct inode *, struct writeback_control *); 22723dcf5451SChristoph Hellwig extern int ext4_setattr(struct dentry *, struct iattr *); 22733e3398a0SMingming Cao extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, 22743e3398a0SMingming Cao struct kstat *stat); 22750930fcc1SAl Viro extern void ext4_evict_inode(struct inode *); 22760930fcc1SAl Viro extern void ext4_clear_inode(struct inode *); 22773dcf5451SChristoph Hellwig extern int ext4_sync_inode(handle_t *, struct inode *); 2278aa385729SChristoph Hellwig extern void ext4_dirty_inode(struct inode *, int); 22793dcf5451SChristoph Hellwig extern int ext4_change_inode_journal_flag(struct inode *, int); 22803dcf5451SChristoph Hellwig extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *); 2281a361293fSJan Kara extern int ext4_inode_attach_jinode(struct inode *inode); 228291ef4cafSDuane Griffin extern int ext4_can_truncate(struct inode *inode); 22833dcf5451SChristoph Hellwig extern void ext4_truncate(struct inode *); 2284aeb2817aSAshish Sangwan extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length); 2285487caeefSJan Kara extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks); 22863dcf5451SChristoph Hellwig extern void ext4_set_inode_flags(struct inode *); 22873dcf5451SChristoph Hellwig extern void ext4_get_inode_flags(struct ext4_inode_info *); 2288ccd2506bSTheodore Ts'o extern int ext4_alloc_da_blocks(struct inode *inode); 22893dcf5451SChristoph Hellwig extern void ext4_set_aops(struct inode *inode); 22903dcf5451SChristoph Hellwig extern int ext4_writepage_trans_blocks(struct inode *); 2291f3bd1f3fSMingming Cao extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); 2292a87dd18cSLukas Czerner extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 2293a87dd18cSLukas Czerner loff_t lstart, loff_t lend); 2294c2ec175cSNick Piggin extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); 2295a9e7f447SDmitry Monakhov extern qsize_t *ext4_get_reserved_space(struct inode *inode); 22965f634d06SAneesh Kumar K.V extern void ext4_da_update_reserve_space(struct inode *inode, 22975f634d06SAneesh Kumar K.V int used, int quota_claim); 2298dae1e52cSAmir Goldstein 2299dae1e52cSAmir Goldstein /* indirect.c */ 2300dae1e52cSAmir Goldstein extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 2301dae1e52cSAmir Goldstein struct ext4_map_blocks *map, int flags); 2302dae1e52cSAmir Goldstein extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, 230316b1f05dSAl Viro struct iov_iter *iter, loff_t offset); 2304dae1e52cSAmir Goldstein extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock); 2305fa55a0edSJan Kara extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 2306819c4920STheodore Ts'o extern void ext4_ind_truncate(handle_t *, struct inode *inode); 23074f579ae7SLukas Czerner extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode, 23084f579ae7SLukas Czerner ext4_lblk_t start, ext4_lblk_t end); 2309ff9893dcSAmir Goldstein 23103dcf5451SChristoph Hellwig /* ioctl.c */ 23113dcf5451SChristoph Hellwig extern long ext4_ioctl(struct file *, unsigned int, unsigned long); 23123dcf5451SChristoph Hellwig extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long); 23133dcf5451SChristoph Hellwig 23143dcf5451SChristoph Hellwig /* migrate.c */ 23152a43a878SAneesh Kumar K.V extern int ext4_ext_migrate(struct inode *); 23160d14b098SLukas Czerner extern int ext4_ind_migrate(struct inode *inode); 23173d0518f4SWei Yongjun 23183dcf5451SChristoph Hellwig /* namei.c */ 2319b0336e8dSDarrick J. Wong extern int ext4_dirent_csum_verify(struct inode *inode, 2320b0336e8dSDarrick J. Wong struct ext4_dir_entry *dirent); 23213dcf5451SChristoph Hellwig extern int ext4_orphan_add(handle_t *, struct inode *); 23223dcf5451SChristoph Hellwig extern int ext4_orphan_del(handle_t *, struct inode *); 23233dcf5451SChristoph Hellwig extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 23243dcf5451SChristoph Hellwig __u32 start_minor_hash, __u32 *next_hash); 23257335cd3bSTao Ma extern int search_dir(struct buffer_head *bh, 23267335cd3bSTao Ma char *search_buf, 23277335cd3bSTao Ma int buf_size, 23287335cd3bSTao Ma struct inode *dir, 23297335cd3bSTao Ma const struct qstr *d_name, 23307335cd3bSTao Ma unsigned int offset, 23317335cd3bSTao Ma struct ext4_dir_entry_2 **res_dir); 233205019a9eSTao Ma extern int ext4_generic_delete_entry(handle_t *handle, 233305019a9eSTao Ma struct inode *dir, 233405019a9eSTao Ma struct ext4_dir_entry_2 *de_del, 233505019a9eSTao Ma struct buffer_head *bh, 233605019a9eSTao Ma void *entry_buf, 233705019a9eSTao Ma int buf_size, 233805019a9eSTao Ma int csum_size); 2339e875a2ddSMichael Halcrow extern int ext4_empty_dir(struct inode *inode); 23403dcf5451SChristoph Hellwig 23413dcf5451SChristoph Hellwig /* resize.c */ 23423dcf5451SChristoph Hellwig extern int ext4_group_add(struct super_block *sb, 23433dcf5451SChristoph Hellwig struct ext4_new_group_data *input); 23443dcf5451SChristoph Hellwig extern int ext4_group_extend(struct super_block *sb, 23453dcf5451SChristoph Hellwig struct ext4_super_block *es, 23463dcf5451SChristoph Hellwig ext4_fsblk_t n_blocks_count); 234719c5246dSYongqiang Yang extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 23483dcf5451SChristoph Hellwig 23493dcf5451SChristoph Hellwig /* super.c */ 2350952fc18eSTheodore Ts'o extern int ext4_calculate_overhead(struct super_block *sb); 235106db49e6STheodore Ts'o extern void ext4_superblock_csum_set(struct super_block *sb); 23529933fc0aSTheodore Ts'o extern void *ext4_kvmalloc(size_t size, gfp_t flags); 23539933fc0aSTheodore Ts'o extern void *ext4_kvzalloc(size_t size, gfp_t flags); 2354117fff10STheodore Ts'o extern int ext4_alloc_flex_bg_array(struct super_block *sb, 2355117fff10STheodore Ts'o ext4_group_t ngroup); 2356722887ddSTheodore Ts'o extern const char *ext4_decode_error(struct super_block *sb, int errno, 2357722887ddSTheodore Ts'o char nbuf[16]); 2358e7c96e8eSJoe Perches 2359b9075fa9SJoe Perches extern __printf(4, 5) 2360b9075fa9SJoe Perches void __ext4_error(struct super_block *, const char *, unsigned int, 2361b9075fa9SJoe Perches const char *, ...); 2362b9075fa9SJoe Perches extern __printf(5, 6) 2363e7c96e8eSJoe Perches void __ext4_error_inode(struct inode *, const char *, unsigned int, ext4_fsblk_t, 2364b9075fa9SJoe Perches const char *, ...); 2365b9075fa9SJoe Perches extern __printf(5, 6) 2366e7c96e8eSJoe Perches void __ext4_error_file(struct file *, const char *, unsigned int, ext4_fsblk_t, 2367b9075fa9SJoe Perches const char *, ...); 2368c398eda0STheodore Ts'o extern void __ext4_std_error(struct super_block *, const char *, 2369c398eda0STheodore Ts'o unsigned int, int); 2370b9075fa9SJoe Perches extern __printf(4, 5) 2371b9075fa9SJoe Perches void __ext4_abort(struct super_block *, const char *, unsigned int, 2372b9075fa9SJoe Perches const char *, ...); 2373b9075fa9SJoe Perches extern __printf(4, 5) 2374b9075fa9SJoe Perches void __ext4_warning(struct super_block *, const char *, unsigned int, 2375b9075fa9SJoe Perches const char *, ...); 2376b9075fa9SJoe Perches extern __printf(3, 4) 2377e7c96e8eSJoe Perches void __ext4_msg(struct super_block *, const char *, const char *, ...); 2378c5e06d10SJohann Lombardi extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp, 2379c5e06d10SJohann Lombardi const char *, unsigned int, const char *); 2380b9075fa9SJoe Perches extern __printf(7, 8) 2381b9075fa9SJoe Perches void __ext4_grp_locked_error(const char *, unsigned int, 2382b9075fa9SJoe Perches struct super_block *, ext4_group_t, 2383b9075fa9SJoe Perches unsigned long, ext4_fsblk_t, 2384b9075fa9SJoe Perches const char *, ...); 2385e7c96e8eSJoe Perches 2386e7c96e8eSJoe Perches #ifdef CONFIG_PRINTK 2387e7c96e8eSJoe Perches 2388e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 2389e7c96e8eSJoe Perches __ext4_error_inode(inode, func, line, block, fmt, ##__VA_ARGS__) 2390e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 2391e7c96e8eSJoe Perches __ext4_error_file(file, func, line, block, fmt, ##__VA_ARGS__) 2392e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 2393e7c96e8eSJoe Perches __ext4_error(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 2394e7c96e8eSJoe Perches #define ext4_abort(sb, fmt, ...) \ 2395e7c96e8eSJoe Perches __ext4_abort(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 2396e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 2397e7c96e8eSJoe Perches __ext4_warning(sb, __func__, __LINE__, fmt, ##__VA_ARGS__) 2398e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 2399e7c96e8eSJoe Perches __ext4_msg(sb, level, fmt, ##__VA_ARGS__) 2400e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 2401e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, __func__, __LINE__, msg) 2402e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 2403e7c96e8eSJoe Perches __ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino, block, \ 2404e7c96e8eSJoe Perches fmt, ##__VA_ARGS__) 2405e7c96e8eSJoe Perches 2406e7c96e8eSJoe Perches #else 2407e7c96e8eSJoe Perches 2408e7c96e8eSJoe Perches #define ext4_error_inode(inode, func, line, block, fmt, ...) \ 2409e7c96e8eSJoe Perches do { \ 2410e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2411e7c96e8eSJoe Perches __ext4_error_inode(inode, "", 0, block, " "); \ 2412e7c96e8eSJoe Perches } while (0) 2413e7c96e8eSJoe Perches #define ext4_error_file(file, func, line, block, fmt, ...) \ 2414e7c96e8eSJoe Perches do { \ 2415e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2416e7c96e8eSJoe Perches __ext4_error_file(file, "", 0, block, " "); \ 2417e7c96e8eSJoe Perches } while (0) 2418e7c96e8eSJoe Perches #define ext4_error(sb, fmt, ...) \ 2419e7c96e8eSJoe Perches do { \ 2420e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2421e7c96e8eSJoe Perches __ext4_error(sb, "", 0, " "); \ 2422e7c96e8eSJoe Perches } while (0) 2423e7c96e8eSJoe Perches #define ext4_abort(sb, fmt, ...) \ 2424e7c96e8eSJoe Perches do { \ 2425e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2426e7c96e8eSJoe Perches __ext4_abort(sb, "", 0, " "); \ 2427e7c96e8eSJoe Perches } while (0) 2428e7c96e8eSJoe Perches #define ext4_warning(sb, fmt, ...) \ 2429e7c96e8eSJoe Perches do { \ 2430e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2431e7c96e8eSJoe Perches __ext4_warning(sb, "", 0, " "); \ 2432e7c96e8eSJoe Perches } while (0) 2433e7c96e8eSJoe Perches #define ext4_msg(sb, level, fmt, ...) \ 2434e7c96e8eSJoe Perches do { \ 2435e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2436e7c96e8eSJoe Perches __ext4_msg(sb, "", " "); \ 2437e7c96e8eSJoe Perches } while (0) 2438e7c96e8eSJoe Perches #define dump_mmp_msg(sb, mmp, msg) \ 2439e7c96e8eSJoe Perches __dump_mmp_msg(sb, mmp, "", 0, "") 2440e7c96e8eSJoe Perches #define ext4_grp_locked_error(sb, grp, ino, block, fmt, ...) \ 2441e7c96e8eSJoe Perches do { \ 2442e7c96e8eSJoe Perches no_printk(fmt, ##__VA_ARGS__); \ 2443e7c96e8eSJoe Perches __ext4_grp_locked_error("", 0, sb, grp, ino, block, " "); \ 2444e7c96e8eSJoe Perches } while (0) 2445e7c96e8eSJoe Perches 2446e7c96e8eSJoe Perches #endif 2447e7c96e8eSJoe Perches 24483dcf5451SChristoph Hellwig extern void ext4_update_dynamic_rev(struct super_block *sb); 24493dcf5451SChristoph Hellwig extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb, 24503dcf5451SChristoph Hellwig __u32 compat); 24513dcf5451SChristoph Hellwig extern int ext4_update_rocompat_feature(handle_t *handle, 24523dcf5451SChristoph Hellwig struct super_block *sb, __u32 rocompat); 24533dcf5451SChristoph Hellwig extern int ext4_update_incompat_feature(handle_t *handle, 24543dcf5451SChristoph Hellwig struct super_block *sb, __u32 incompat); 24553dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, 24563dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 24573dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 24583dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 24593dcf5451SChristoph Hellwig extern ext4_fsblk_t ext4_inode_table(struct super_block *sb, 24603dcf5451SChristoph Hellwig struct ext4_group_desc *bg); 2461021b65bbSTheodore Ts'o extern __u32 ext4_free_group_clusters(struct super_block *sb, 2462560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2463560671a0SAneesh Kumar K.V extern __u32 ext4_free_inodes_count(struct super_block *sb, 2464560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2465560671a0SAneesh Kumar K.V extern __u32 ext4_used_dirs_count(struct super_block *sb, 2466560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 2467560671a0SAneesh Kumar K.V extern __u32 ext4_itable_unused_count(struct super_block *sb, 2468560671a0SAneesh Kumar K.V struct ext4_group_desc *bg); 24693dcf5451SChristoph Hellwig extern void ext4_block_bitmap_set(struct super_block *sb, 24703dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 24713dcf5451SChristoph Hellwig extern void ext4_inode_bitmap_set(struct super_block *sb, 24723dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 24733dcf5451SChristoph Hellwig extern void ext4_inode_table_set(struct super_block *sb, 24743dcf5451SChristoph Hellwig struct ext4_group_desc *bg, ext4_fsblk_t blk); 2475021b65bbSTheodore Ts'o extern void ext4_free_group_clusters_set(struct super_block *sb, 2476021b65bbSTheodore Ts'o struct ext4_group_desc *bg, 2477021b65bbSTheodore Ts'o __u32 count); 2478560671a0SAneesh Kumar K.V extern void ext4_free_inodes_set(struct super_block *sb, 2479560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2480560671a0SAneesh Kumar K.V extern void ext4_used_dirs_set(struct super_block *sb, 2481560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2482560671a0SAneesh Kumar K.V extern void ext4_itable_unused_set(struct super_block *sb, 2483560671a0SAneesh Kumar K.V struct ext4_group_desc *bg, __u32 count); 2484feb0ab32SDarrick J. Wong extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group, 2485bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 2486feb0ab32SDarrick J. Wong extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group, 2487bb23c20aSTheodore Ts'o struct ext4_group_desc *gdp); 24887f511862STheodore Ts'o extern int ext4_register_li_request(struct super_block *sb, 24897f511862STheodore Ts'o ext4_group_t first_not_zeroed); 24903dcf5451SChristoph Hellwig 249141a246d1SDarrick J. Wong static inline int ext4_has_group_desc_csum(struct super_block *sb) 249241a246d1SDarrick J. Wong { 249341a246d1SDarrick J. Wong return EXT4_HAS_RO_COMPAT_FEATURE(sb, 2494813d32f9SDarrick J. Wong EXT4_FEATURE_RO_COMPAT_GDT_CSUM) || 2495813d32f9SDarrick J. Wong (EXT4_SB(sb)->s_chksum_driver != NULL); 249641a246d1SDarrick J. Wong } 249741a246d1SDarrick J. Wong 24989aa5d32bSDmitry Monakhov static inline int ext4_has_metadata_csum(struct super_block *sb) 24999aa5d32bSDmitry Monakhov { 25009aa5d32bSDmitry Monakhov WARN_ON_ONCE(EXT4_HAS_RO_COMPAT_FEATURE(sb, 25019aa5d32bSDmitry Monakhov EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) && 25029aa5d32bSDmitry Monakhov !EXT4_SB(sb)->s_chksum_driver); 25039aa5d32bSDmitry Monakhov 25049aa5d32bSDmitry Monakhov return (EXT4_SB(sb)->s_chksum_driver != NULL); 25059aa5d32bSDmitry Monakhov } 25063dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 25073dcf5451SChristoph Hellwig { 25083dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | 25093dcf5451SChristoph Hellwig le32_to_cpu(es->s_blocks_count_lo); 25103dcf5451SChristoph Hellwig } 25113dcf5451SChristoph Hellwig 25123dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) 25133dcf5451SChristoph Hellwig { 25143dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) | 25153dcf5451SChristoph Hellwig le32_to_cpu(es->s_r_blocks_count_lo); 25163dcf5451SChristoph Hellwig } 25173dcf5451SChristoph Hellwig 25183dcf5451SChristoph Hellwig static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es) 25193dcf5451SChristoph Hellwig { 25203dcf5451SChristoph Hellwig return ((ext4_fsblk_t)le32_to_cpu(es->s_free_blocks_count_hi) << 32) | 25213dcf5451SChristoph Hellwig le32_to_cpu(es->s_free_blocks_count_lo); 25223dcf5451SChristoph Hellwig } 25233dcf5451SChristoph Hellwig 25243dcf5451SChristoph Hellwig static inline void ext4_blocks_count_set(struct ext4_super_block *es, 25253dcf5451SChristoph Hellwig ext4_fsblk_t blk) 25263dcf5451SChristoph Hellwig { 25273dcf5451SChristoph Hellwig es->s_blocks_count_lo = cpu_to_le32((u32)blk); 25283dcf5451SChristoph Hellwig es->s_blocks_count_hi = cpu_to_le32(blk >> 32); 25293dcf5451SChristoph Hellwig } 25303dcf5451SChristoph Hellwig 25313dcf5451SChristoph Hellwig static inline void ext4_free_blocks_count_set(struct ext4_super_block *es, 25323dcf5451SChristoph Hellwig ext4_fsblk_t blk) 25333dcf5451SChristoph Hellwig { 25343dcf5451SChristoph Hellwig es->s_free_blocks_count_lo = cpu_to_le32((u32)blk); 25353dcf5451SChristoph Hellwig es->s_free_blocks_count_hi = cpu_to_le32(blk >> 32); 25363dcf5451SChristoph Hellwig } 25373dcf5451SChristoph Hellwig 25383dcf5451SChristoph Hellwig static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, 25393dcf5451SChristoph Hellwig ext4_fsblk_t blk) 25403dcf5451SChristoph Hellwig { 25413dcf5451SChristoph Hellwig es->s_r_blocks_count_lo = cpu_to_le32((u32)blk); 25423dcf5451SChristoph Hellwig es->s_r_blocks_count_hi = cpu_to_le32(blk >> 32); 25433dcf5451SChristoph Hellwig } 25443dcf5451SChristoph Hellwig 25453dcf5451SChristoph Hellwig static inline loff_t ext4_isize(struct ext4_inode *raw_inode) 25463dcf5451SChristoph Hellwig { 254706a279d6STheodore Ts'o if (S_ISREG(le16_to_cpu(raw_inode->i_mode))) 25483dcf5451SChristoph Hellwig return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | 25493dcf5451SChristoph Hellwig le32_to_cpu(raw_inode->i_size_lo); 255006a279d6STheodore Ts'o else 255106a279d6STheodore Ts'o return (loff_t) le32_to_cpu(raw_inode->i_size_lo); 25523dcf5451SChristoph Hellwig } 25533dcf5451SChristoph Hellwig 25543dcf5451SChristoph Hellwig static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) 25553dcf5451SChristoph Hellwig { 25563dcf5451SChristoph Hellwig raw_inode->i_size_lo = cpu_to_le32(i_size); 25573dcf5451SChristoph Hellwig raw_inode->i_size_high = cpu_to_le32(i_size >> 32); 25583dcf5451SChristoph Hellwig } 25593dcf5451SChristoph Hellwig 25603dcf5451SChristoph Hellwig static inline 25613dcf5451SChristoph Hellwig struct ext4_group_info *ext4_get_group_info(struct super_block *sb, 25623dcf5451SChristoph Hellwig ext4_group_t group) 25633dcf5451SChristoph Hellwig { 25643dcf5451SChristoph Hellwig struct ext4_group_info ***grp_info; 25653dcf5451SChristoph Hellwig long indexv, indexh; 25662f2e09ebSTheodore Ts'o BUG_ON(group >= EXT4_SB(sb)->s_groups_count); 25673dcf5451SChristoph Hellwig grp_info = EXT4_SB(sb)->s_group_info; 25683dcf5451SChristoph Hellwig indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb)); 25693dcf5451SChristoph Hellwig indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1); 25703dcf5451SChristoph Hellwig return grp_info[indexv][indexh]; 25713dcf5451SChristoph Hellwig } 25723dcf5451SChristoph Hellwig 25738df9675fSTheodore Ts'o /* 25748df9675fSTheodore Ts'o * Reading s_groups_count requires using smp_rmb() afterwards. See 25758df9675fSTheodore Ts'o * the locking protocol documented in the comments of ext4_group_add() 25768df9675fSTheodore Ts'o * in resize.c 25778df9675fSTheodore Ts'o */ 25788df9675fSTheodore Ts'o static inline ext4_group_t ext4_get_groups_count(struct super_block *sb) 25798df9675fSTheodore Ts'o { 25808df9675fSTheodore Ts'o ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 25818df9675fSTheodore Ts'o 25828df9675fSTheodore Ts'o smp_rmb(); 25838df9675fSTheodore Ts'o return ngroups; 25848df9675fSTheodore Ts'o } 25853dcf5451SChristoph Hellwig 2586772cb7c8SJose R. Santos static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 2587772cb7c8SJose R. Santos ext4_group_t block_group) 2588772cb7c8SJose R. Santos { 2589772cb7c8SJose R. Santos return block_group >> sbi->s_log_groups_per_flex; 2590772cb7c8SJose R. Santos } 2591772cb7c8SJose R. Santos 2592772cb7c8SJose R. Santos static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) 2593772cb7c8SJose R. Santos { 2594772cb7c8SJose R. Santos return 1 << sbi->s_log_groups_per_flex; 2595772cb7c8SJose R. Santos } 2596772cb7c8SJose R. Santos 25973dcf5451SChristoph Hellwig #define ext4_std_error(sb, errno) \ 25983dcf5451SChristoph Hellwig do { \ 25993dcf5451SChristoph Hellwig if ((errno)) \ 2600c398eda0STheodore Ts'o __ext4_std_error((sb), __func__, __LINE__, (errno)); \ 26013dcf5451SChristoph Hellwig } while (0) 26023dcf5451SChristoph Hellwig 2603a30d542aSAneesh Kumar K.V #ifdef CONFIG_SMP 2604df55c99dSTheodore Ts'o /* Each CPU can accumulate percpu_counter_batch clusters in their local 2605df55c99dSTheodore Ts'o * counters. So we need to make sure we have free clusters more 2606179f7ebfSEric Dumazet * than percpu_counter_batch * nr_cpu_ids. Also add a window of 4 times. 2607a30d542aSAneesh Kumar K.V */ 2608df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK (4 * (percpu_counter_batch * nr_cpu_ids)) 2609a30d542aSAneesh Kumar K.V #else 2610df55c99dSTheodore Ts'o #define EXT4_FREECLUSTERS_WATERMARK 0 2611a30d542aSAneesh Kumar K.V #endif 2612a30d542aSAneesh Kumar K.V 261390e775b7SJan Kara /* Update i_disksize. Requires i_mutex to avoid races with truncate */ 2614cf17fea6SAneesh Kumar K.V static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize) 2615cf17fea6SAneesh Kumar K.V { 261690e775b7SJan Kara WARN_ON_ONCE(S_ISREG(inode->i_mode) && 261790e775b7SJan Kara !mutex_is_locked(&inode->i_mutex)); 2618cf17fea6SAneesh Kumar K.V down_write(&EXT4_I(inode)->i_data_sem); 2619cf17fea6SAneesh Kumar K.V if (newsize > EXT4_I(inode)->i_disksize) 2620cf17fea6SAneesh Kumar K.V EXT4_I(inode)->i_disksize = newsize; 2621cf17fea6SAneesh Kumar K.V up_write(&EXT4_I(inode)->i_data_sem); 262290e775b7SJan Kara } 262390e775b7SJan Kara 26244631dbf6SDmitry Monakhov /* Update i_size, i_disksize. Requires i_mutex to avoid races with truncate */ 26254631dbf6SDmitry Monakhov static inline int ext4_update_inode_size(struct inode *inode, loff_t newsize) 26264631dbf6SDmitry Monakhov { 26274631dbf6SDmitry Monakhov int changed = 0; 26284631dbf6SDmitry Monakhov 26294631dbf6SDmitry Monakhov if (newsize > inode->i_size) { 26304631dbf6SDmitry Monakhov i_size_write(inode, newsize); 26314631dbf6SDmitry Monakhov changed = 1; 26324631dbf6SDmitry Monakhov } 26334631dbf6SDmitry Monakhov if (newsize > EXT4_I(inode)->i_disksize) { 26344631dbf6SDmitry Monakhov ext4_update_i_disksize(inode, newsize); 26354631dbf6SDmitry Monakhov changed |= 2; 26364631dbf6SDmitry Monakhov } 26374631dbf6SDmitry Monakhov return changed; 26384631dbf6SDmitry Monakhov } 26394631dbf6SDmitry Monakhov 26405d1b1b3fSAneesh Kumar K.V struct ext4_group_info { 26415d1b1b3fSAneesh Kumar K.V unsigned long bb_state; 26425d1b1b3fSAneesh Kumar K.V struct rb_root bb_free_root; 2643a36b4498SEric Sandeen ext4_grpblk_t bb_first_free; /* first free block */ 2644a36b4498SEric Sandeen ext4_grpblk_t bb_free; /* total free blocks */ 2645a36b4498SEric Sandeen ext4_grpblk_t bb_fragments; /* nr of freespace fragments */ 26468a57d9d6SCurt Wohlgemuth ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */ 26475d1b1b3fSAneesh Kumar K.V struct list_head bb_prealloc_list; 26485d1b1b3fSAneesh Kumar K.V #ifdef DOUBLE_CHECK 26495d1b1b3fSAneesh Kumar K.V void *bb_bitmap; 26505d1b1b3fSAneesh Kumar K.V #endif 26515d1b1b3fSAneesh Kumar K.V struct rw_semaphore alloc_sem; 2652a36b4498SEric Sandeen ext4_grpblk_t bb_counters[]; /* Nr of free power-of-two-block 2653a36b4498SEric Sandeen * regions, index is order. 2654a36b4498SEric Sandeen * bb_counters[3] = 5 means 2655a36b4498SEric Sandeen * 5 free 8-block regions. */ 26565d1b1b3fSAneesh Kumar K.V }; 26575d1b1b3fSAneesh Kumar K.V 26585d1b1b3fSAneesh Kumar K.V #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 26593d56b8d2STao Ma #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 2660163a203dSDarrick J. Wong #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2 266187a39389SDarrick J. Wong #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3 26625d1b1b3fSAneesh Kumar K.V 26635d1b1b3fSAneesh Kumar K.V #define EXT4_MB_GRP_NEED_INIT(grp) \ 26645d1b1b3fSAneesh Kumar K.V (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 2665163a203dSDarrick J. Wong #define EXT4_MB_GRP_BBITMAP_CORRUPT(grp) \ 2666163a203dSDarrick J. Wong (test_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 266787a39389SDarrick J. Wong #define EXT4_MB_GRP_IBITMAP_CORRUPT(grp) \ 266887a39389SDarrick J. Wong (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state))) 26695d1b1b3fSAneesh Kumar K.V 26703d56b8d2STao Ma #define EXT4_MB_GRP_WAS_TRIMMED(grp) \ 26713d56b8d2STao Ma (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 26723d56b8d2STao Ma #define EXT4_MB_GRP_SET_TRIMMED(grp) \ 26733d56b8d2STao Ma (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 26743d56b8d2STao Ma #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \ 26753d56b8d2STao Ma (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) 26763d56b8d2STao Ma 267750797481STheodore Ts'o #define EXT4_MAX_CONTENTION 8 267850797481STheodore Ts'o #define EXT4_CONTENTION_THRESHOLD 2 267950797481STheodore Ts'o 2680955ce5f5SAneesh Kumar K.V static inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb, 2681955ce5f5SAneesh Kumar K.V ext4_group_t group) 2682955ce5f5SAneesh Kumar K.V { 2683955ce5f5SAneesh Kumar K.V return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group); 2684955ce5f5SAneesh Kumar K.V } 2685955ce5f5SAneesh Kumar K.V 268650797481STheodore Ts'o /* 268750797481STheodore Ts'o * Returns true if the filesystem is busy enough that attempts to 268850797481STheodore Ts'o * access the block group locks has run into contention. 268950797481STheodore Ts'o */ 269050797481STheodore Ts'o static inline int ext4_fs_is_busy(struct ext4_sb_info *sbi) 269150797481STheodore Ts'o { 269250797481STheodore Ts'o return (atomic_read(&sbi->s_lock_busy) > EXT4_CONTENTION_THRESHOLD); 269350797481STheodore Ts'o } 269450797481STheodore Ts'o 26955d1b1b3fSAneesh Kumar K.V static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 26965d1b1b3fSAneesh Kumar K.V { 269750797481STheodore Ts'o spinlock_t *lock = ext4_group_lock_ptr(sb, group); 269850797481STheodore Ts'o if (spin_trylock(lock)) 269950797481STheodore Ts'o /* 270050797481STheodore Ts'o * We're able to grab the lock right away, so drop the 270150797481STheodore Ts'o * lock contention counter. 270250797481STheodore Ts'o */ 270350797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, -1, 0); 270450797481STheodore Ts'o else { 270550797481STheodore Ts'o /* 270650797481STheodore Ts'o * The lock is busy, so bump the contention counter, 270750797481STheodore Ts'o * and then wait on the spin lock. 270850797481STheodore Ts'o */ 270950797481STheodore Ts'o atomic_add_unless(&EXT4_SB(sb)->s_lock_busy, 1, 271050797481STheodore Ts'o EXT4_MAX_CONTENTION); 271150797481STheodore Ts'o spin_lock(lock); 271250797481STheodore Ts'o } 27135d1b1b3fSAneesh Kumar K.V } 27145d1b1b3fSAneesh Kumar K.V 27155d1b1b3fSAneesh Kumar K.V static inline void ext4_unlock_group(struct super_block *sb, 27165d1b1b3fSAneesh Kumar K.V ext4_group_t group) 27175d1b1b3fSAneesh Kumar K.V { 2718955ce5f5SAneesh Kumar K.V spin_unlock(ext4_group_lock_ptr(sb, group)); 27195d1b1b3fSAneesh Kumar K.V } 27205d1b1b3fSAneesh Kumar K.V 27213dcf5451SChristoph Hellwig /* 27221f7d1e77STheodore Ts'o * Block validity checking 27231f7d1e77STheodore Ts'o */ 27241f7d1e77STheodore Ts'o #define ext4_check_indirect_blockref(inode, bh) \ 27251f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 27261f7d1e77STheodore Ts'o (__le32 *)(bh)->b_data, \ 27271f7d1e77STheodore Ts'o EXT4_ADDR_PER_BLOCK((inode)->i_sb)) 27281f7d1e77STheodore Ts'o 27291f7d1e77STheodore Ts'o #define ext4_ind_check_inode(inode) \ 27301f7d1e77STheodore Ts'o ext4_check_blockref(__func__, __LINE__, inode, \ 27311f7d1e77STheodore Ts'o EXT4_I(inode)->i_data, \ 27321f7d1e77STheodore Ts'o EXT4_NDIR_BLOCKS) 27331f7d1e77STheodore Ts'o 27341f7d1e77STheodore Ts'o /* 27353dcf5451SChristoph Hellwig * Inodes and files operations 27363dcf5451SChristoph Hellwig */ 27373dcf5451SChristoph Hellwig 27383dcf5451SChristoph Hellwig /* dir.c */ 27393dcf5451SChristoph Hellwig extern const struct file_operations ext4_dir_operations; 27403dcf5451SChristoph Hellwig 27413dcf5451SChristoph Hellwig /* file.c */ 27423dcf5451SChristoph Hellwig extern const struct inode_operations ext4_file_inode_operations; 27433dcf5451SChristoph Hellwig extern const struct file_operations ext4_file_operations; 2744923ae0ffSRoss Zwisler extern const struct file_operations ext4_dax_file_operations; 2745e0d10bfaSToshiyuki Okajima extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin); 27463dcf5451SChristoph Hellwig 274795eaefbdSTheodore Ts'o /* inline.c */ 274895eaefbdSTheodore Ts'o extern int ext4_get_max_inline_size(struct inode *inode); 274995eaefbdSTheodore Ts'o extern int ext4_find_inline_data_nolock(struct inode *inode); 275095eaefbdSTheodore Ts'o extern int ext4_init_inline_data(handle_t *handle, struct inode *inode, 275195eaefbdSTheodore Ts'o unsigned int len); 275295eaefbdSTheodore Ts'o extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode); 275395eaefbdSTheodore Ts'o 275495eaefbdSTheodore Ts'o extern int ext4_readpage_inline(struct inode *inode, struct page *page); 275595eaefbdSTheodore Ts'o extern int ext4_try_to_write_inline_data(struct address_space *mapping, 275695eaefbdSTheodore Ts'o struct inode *inode, 275795eaefbdSTheodore Ts'o loff_t pos, unsigned len, 275895eaefbdSTheodore Ts'o unsigned flags, 275995eaefbdSTheodore Ts'o struct page **pagep); 276095eaefbdSTheodore Ts'o extern int ext4_write_inline_data_end(struct inode *inode, 276195eaefbdSTheodore Ts'o loff_t pos, unsigned len, 276295eaefbdSTheodore Ts'o unsigned copied, 276395eaefbdSTheodore Ts'o struct page *page); 276495eaefbdSTheodore Ts'o extern struct buffer_head * 276595eaefbdSTheodore Ts'o ext4_journalled_write_inline_data(struct inode *inode, 276695eaefbdSTheodore Ts'o unsigned len, 276795eaefbdSTheodore Ts'o struct page *page); 276895eaefbdSTheodore Ts'o extern int ext4_da_write_inline_data_begin(struct address_space *mapping, 276995eaefbdSTheodore Ts'o struct inode *inode, 277095eaefbdSTheodore Ts'o loff_t pos, unsigned len, 277195eaefbdSTheodore Ts'o unsigned flags, 277295eaefbdSTheodore Ts'o struct page **pagep, 277395eaefbdSTheodore Ts'o void **fsdata); 277495eaefbdSTheodore Ts'o extern int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, 277595eaefbdSTheodore Ts'o unsigned len, unsigned copied, 277695eaefbdSTheodore Ts'o struct page *page); 277795eaefbdSTheodore Ts'o extern int ext4_try_add_inline_entry(handle_t *handle, struct dentry *dentry, 277895eaefbdSTheodore Ts'o struct inode *inode); 277995eaefbdSTheodore Ts'o extern int ext4_try_create_inline_dir(handle_t *handle, 278095eaefbdSTheodore Ts'o struct inode *parent, 278195eaefbdSTheodore Ts'o struct inode *inode); 278295eaefbdSTheodore Ts'o extern int ext4_read_inline_dir(struct file *filp, 2783725bebb2SAl Viro struct dir_context *ctx, 278495eaefbdSTheodore Ts'o int *has_inline_data); 27858af0f082STao Ma extern int htree_inlinedir_to_tree(struct file *dir_file, 27868af0f082STao Ma struct inode *dir, ext4_lblk_t block, 27878af0f082STao Ma struct dx_hash_info *hinfo, 27888af0f082STao Ma __u32 start_hash, __u32 start_minor_hash, 27898af0f082STao Ma int *has_inline_data); 279095eaefbdSTheodore Ts'o extern struct buffer_head *ext4_find_inline_entry(struct inode *dir, 279195eaefbdSTheodore Ts'o const struct qstr *d_name, 279295eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **res_dir, 279395eaefbdSTheodore Ts'o int *has_inline_data); 279495eaefbdSTheodore Ts'o extern int ext4_delete_inline_entry(handle_t *handle, 279595eaefbdSTheodore Ts'o struct inode *dir, 279695eaefbdSTheodore Ts'o struct ext4_dir_entry_2 *de_del, 279795eaefbdSTheodore Ts'o struct buffer_head *bh, 279895eaefbdSTheodore Ts'o int *has_inline_data); 279995eaefbdSTheodore Ts'o extern int empty_inline_dir(struct inode *dir, int *has_inline_data); 280095eaefbdSTheodore Ts'o extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode, 280195eaefbdSTheodore Ts'o struct ext4_dir_entry_2 **parent_de, 280295eaefbdSTheodore Ts'o int *retval); 280395eaefbdSTheodore Ts'o extern int ext4_inline_data_fiemap(struct inode *inode, 280495eaefbdSTheodore Ts'o struct fiemap_extent_info *fieinfo, 2805d952d69eSDmitry Monakhov int *has_inline, __u64 start, __u64 len); 280695eaefbdSTheodore Ts'o extern int ext4_try_to_evict_inline_data(handle_t *handle, 280795eaefbdSTheodore Ts'o struct inode *inode, 280895eaefbdSTheodore Ts'o int needed); 280995eaefbdSTheodore Ts'o extern void ext4_inline_data_truncate(struct inode *inode, int *has_inline); 281095eaefbdSTheodore Ts'o 281195eaefbdSTheodore Ts'o extern int ext4_convert_inline_data(struct inode *inode); 281295eaefbdSTheodore Ts'o 281383447ccbSZheng Liu static inline int ext4_has_inline_data(struct inode *inode) 281483447ccbSZheng Liu { 281583447ccbSZheng Liu return ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA) && 281683447ccbSZheng Liu EXT4_I(inode)->i_inline_off; 281783447ccbSZheng Liu } 281883447ccbSZheng Liu 28193dcf5451SChristoph Hellwig /* namei.c */ 28203dcf5451SChristoph Hellwig extern const struct inode_operations ext4_dir_inode_operations; 28213dcf5451SChristoph Hellwig extern const struct inode_operations ext4_special_inode_operations; 2822596397b7STheodore Ts'o extern struct dentry *ext4_get_parent(struct dentry *child); 2823a774f9c2STao Ma extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode, 2824a774f9c2STao Ma struct ext4_dir_entry_2 *de, 2825a774f9c2STao Ma int blocksize, int csum_size, 2826a774f9c2STao Ma unsigned int parent_ino, int dotdot_real_len); 28273c47d541STao Ma extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t, 28283c47d541STao Ma unsigned int blocksize); 28293c47d541STao Ma extern int ext4_handle_dirty_dirent_node(handle_t *handle, 28303c47d541STao Ma struct inode *inode, 28313c47d541STao Ma struct buffer_head *bh); 28328af0f082STao Ma #define S_SHIFT 12 28338af0f082STao Ma static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = { 28348af0f082STao Ma [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, 28358af0f082STao Ma [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, 28368af0f082STao Ma [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, 28378af0f082STao Ma [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, 28388af0f082STao Ma [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, 28398af0f082STao Ma [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, 28408af0f082STao Ma [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, 28418af0f082STao Ma }; 28428af0f082STao Ma 28438af0f082STao Ma static inline void ext4_set_de_type(struct super_block *sb, 28448af0f082STao Ma struct ext4_dir_entry_2 *de, 28458af0f082STao Ma umode_t mode) { 28468af0f082STao Ma if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE)) 28478af0f082STao Ma de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 28488af0f082STao Ma } 28498af0f082STao Ma 2850f64e02feSTheodore Ts'o /* readpages.c */ 2851f64e02feSTheodore Ts'o extern int ext4_mpage_readpages(struct address_space *mapping, 2852f64e02feSTheodore Ts'o struct list_head *pages, struct page *page, 2853f64e02feSTheodore Ts'o unsigned nr_pages); 28543dcf5451SChristoph Hellwig 28553dcf5451SChristoph Hellwig /* symlink.c */ 28563dcf5451SChristoph Hellwig extern const struct inode_operations ext4_symlink_inode_operations; 28573dcf5451SChristoph Hellwig extern const struct inode_operations ext4_fast_symlink_inode_operations; 28583dcf5451SChristoph Hellwig 28596fd058f7STheodore Ts'o /* block_validity */ 28606fd058f7STheodore Ts'o extern void ext4_release_system_zone(struct super_block *sb); 28616fd058f7STheodore Ts'o extern int ext4_setup_system_zone(struct super_block *sb); 28625dabfc78STheodore Ts'o extern int __init ext4_init_system_zone(void); 28635dabfc78STheodore Ts'o extern void ext4_exit_system_zone(void); 28646fd058f7STheodore Ts'o extern int ext4_data_block_valid(struct ext4_sb_info *sbi, 28656fd058f7STheodore Ts'o ext4_fsblk_t start_blk, 28666fd058f7STheodore Ts'o unsigned int count); 28671f7d1e77STheodore Ts'o extern int ext4_check_blockref(const char *, unsigned int, 28681f7d1e77STheodore Ts'o struct inode *, __le32 *, unsigned int); 28696fd058f7STheodore Ts'o 28703dcf5451SChristoph Hellwig /* extents.c */ 28714a092d73STheodore Ts'o struct ext4_ext_path; 28724a092d73STheodore Ts'o struct ext4_extent; 28734a092d73STheodore Ts'o 2874d7b2a00cSZheng Liu /* 2875d7b2a00cSZheng Liu * Maximum number of logical blocks in a file; ext4_extent's ee_block is 2876d7b2a00cSZheng Liu * __le32. 2877d7b2a00cSZheng Liu */ 2878d7b2a00cSZheng Liu #define EXT_MAX_BLOCKS 0xffffffff 2879d7b2a00cSZheng Liu 28803dcf5451SChristoph Hellwig extern int ext4_ext_tree_init(handle_t *handle, struct inode *); 28813dcf5451SChristoph Hellwig extern int ext4_ext_writepage_trans_blocks(struct inode *, int); 2882fffb2739SJan Kara extern int ext4_ext_index_trans_blocks(struct inode *inode, int extents); 2883e35fd660STheodore Ts'o extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, 2884e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 2885819c4920STheodore Ts'o extern void ext4_ext_truncate(handle_t *, struct inode *); 288626a4c0c6STheodore Ts'o extern int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, 288726a4c0c6STheodore Ts'o ext4_lblk_t end); 28883dcf5451SChristoph Hellwig extern void ext4_ext_init(struct super_block *); 28893dcf5451SChristoph Hellwig extern void ext4_ext_release(struct super_block *); 28902fe17c10SChristoph Hellwig extern long ext4_fallocate(struct file *file, int mode, loff_t offset, 28913dcf5451SChristoph Hellwig loff_t len); 28926b523df4SJan Kara extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode, 28936b523df4SJan Kara loff_t offset, ssize_t len); 2894e35fd660STheodore Ts'o extern int ext4_map_blocks(handle_t *handle, struct inode *inode, 2895e35fd660STheodore Ts'o struct ext4_map_blocks *map, int flags); 28964a092d73STheodore Ts'o extern int ext4_ext_calc_metadata_amount(struct inode *inode, 28974a092d73STheodore Ts'o ext4_lblk_t lblocks); 28984a092d73STheodore Ts'o extern int ext4_extent_tree_init(handle_t *, struct inode *); 28994a092d73STheodore Ts'o extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, 29004a092d73STheodore Ts'o int num, 29014a092d73STheodore Ts'o struct ext4_ext_path *path); 29024a092d73STheodore Ts'o extern int ext4_can_extents_be_merged(struct inode *inode, 29034a092d73STheodore Ts'o struct ext4_extent *ex1, 29044a092d73STheodore Ts'o struct ext4_extent *ex2); 29054a092d73STheodore Ts'o extern int ext4_ext_insert_extent(handle_t *, struct inode *, 2906dfe50809STheodore Ts'o struct ext4_ext_path **, 29074a092d73STheodore Ts'o struct ext4_extent *, int); 2908ed8a1a76STheodore Ts'o extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, 2909705912caSTheodore Ts'o struct ext4_ext_path **, 2910107a7bd3STheodore Ts'o int flags); 29114a092d73STheodore Ts'o extern void ext4_ext_drop_refs(struct ext4_ext_path *); 29124a092d73STheodore Ts'o extern int ext4_ext_check_inode(struct inode *inode); 2913f7fec032SZheng Liu extern int ext4_find_delalloc_range(struct inode *inode, 2914f7fec032SZheng Liu ext4_lblk_t lblk_start, 2915f7fec032SZheng Liu ext4_lblk_t lblk_end); 29164a092d73STheodore Ts'o extern int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk); 2917fcf6b1b7SDmitry Monakhov extern ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path); 29183a06d778SAneesh Kumar K.V extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 29193a06d778SAneesh Kumar K.V __u64 start, __u64 len); 29207869a4a6STheodore Ts'o extern int ext4_ext_precache(struct inode *inode); 29219eb79482SNamjae Jeon extern int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len); 2922fcf6b1b7SDmitry Monakhov extern int ext4_swap_extents(handle_t *handle, struct inode *inode1, 2923fcf6b1b7SDmitry Monakhov struct inode *inode2, ext4_lblk_t lblk1, 2924fcf6b1b7SDmitry Monakhov ext4_lblk_t lblk2, ext4_lblk_t count, 2925fcf6b1b7SDmitry Monakhov int mark_unwritten,int *err); 29264a092d73STheodore Ts'o 2927748de673SAkira Fujita /* move_extent.c */ 2928393d1d1dSDr. Tilmann Bubeck extern void ext4_double_down_write_data_sem(struct inode *first, 2929393d1d1dSDr. Tilmann Bubeck struct inode *second); 2930393d1d1dSDr. Tilmann Bubeck extern void ext4_double_up_write_data_sem(struct inode *orig_inode, 2931393d1d1dSDr. Tilmann Bubeck struct inode *donor_inode); 2932748de673SAkira Fujita extern int ext4_move_extents(struct file *o_filp, struct file *d_filp, 2933748de673SAkira Fujita __u64 start_orig, __u64 start_donor, 2934748de673SAkira Fujita __u64 len, __u64 *moved_len); 2935748de673SAkira Fujita 2936bd2d0210STheodore Ts'o /* page-io.c */ 29375dabfc78STheodore Ts'o extern int __init ext4_init_pageio(void); 29385dabfc78STheodore Ts'o extern void ext4_exit_pageio(void); 2939bd2d0210STheodore Ts'o extern ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags); 294097a851edSJan Kara extern ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end); 294197a851edSJan Kara extern int ext4_put_io_end(ext4_io_end_t *io_end); 294297a851edSJan Kara extern void ext4_put_io_end_defer(ext4_io_end_t *io_end); 294397a851edSJan Kara extern void ext4_io_submit_init(struct ext4_io_submit *io, 294497a851edSJan Kara struct writeback_control *wbc); 29452e8fa54eSJan Kara extern void ext4_end_io_rsv_work(struct work_struct *work); 2946bd2d0210STheodore Ts'o extern void ext4_io_submit(struct ext4_io_submit *io); 2947bd2d0210STheodore Ts'o extern int ext4_bio_write_page(struct ext4_io_submit *io, 2948bd2d0210STheodore Ts'o struct page *page, 2949bd2d0210STheodore Ts'o int len, 29501c8349a1SNamjae Jeon struct writeback_control *wbc, 29511c8349a1SNamjae Jeon bool keep_towrite); 29523a06d778SAneesh Kumar K.V 2953c5e06d10SJohann Lombardi /* mmp.c */ 2954c5e06d10SJohann Lombardi extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); 2955c5e06d10SJohann Lombardi 29563613d228SJan Kara /* 295748fc7f7eSAdam Buchbinder * Add new method to test whether block and inode bitmaps are properly 29582ccb5fb9SAneesh Kumar K.V * initialized. With uninit_bg reading the block from disk is not enough 29592ccb5fb9SAneesh Kumar K.V * to mark the bitmap uptodate. We need to also zero-out the bitmap 29602ccb5fb9SAneesh Kumar K.V */ 29612ccb5fb9SAneesh Kumar K.V #define BH_BITMAP_UPTODATE BH_JBDPrivateStart 29622ccb5fb9SAneesh Kumar K.V 29632ccb5fb9SAneesh Kumar K.V static inline int bitmap_uptodate(struct buffer_head *bh) 29642ccb5fb9SAneesh Kumar K.V { 29652ccb5fb9SAneesh Kumar K.V return (buffer_uptodate(bh) && 29662ccb5fb9SAneesh Kumar K.V test_bit(BH_BITMAP_UPTODATE, &(bh)->b_state)); 29672ccb5fb9SAneesh Kumar K.V } 29682ccb5fb9SAneesh Kumar K.V static inline void set_bitmap_uptodate(struct buffer_head *bh) 29692ccb5fb9SAneesh Kumar K.V { 29702ccb5fb9SAneesh Kumar K.V set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); 29712ccb5fb9SAneesh Kumar K.V } 29722ccb5fb9SAneesh Kumar K.V 297317335dccSDmitry Monakhov /* 297417335dccSDmitry Monakhov * Disable DIO read nolock optimization, so new dioreaders will be forced 297517335dccSDmitry Monakhov * to grab i_mutex 297617335dccSDmitry Monakhov */ 297717335dccSDmitry Monakhov static inline void ext4_inode_block_unlocked_dio(struct inode *inode) 297817335dccSDmitry Monakhov { 297917335dccSDmitry Monakhov ext4_set_inode_state(inode, EXT4_STATE_DIOREAD_LOCK); 298017335dccSDmitry Monakhov smp_mb(); 298117335dccSDmitry Monakhov } 298217335dccSDmitry Monakhov static inline void ext4_inode_resume_unlocked_dio(struct inode *inode) 298317335dccSDmitry Monakhov { 298417335dccSDmitry Monakhov smp_mb(); 298517335dccSDmitry Monakhov ext4_clear_inode_state(inode, EXT4_STATE_DIOREAD_LOCK); 298617335dccSDmitry Monakhov } 298717335dccSDmitry Monakhov 2988731eb1a0SAkinobu Mita #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) 2989731eb1a0SAkinobu Mita 2990e9e3bcecSEric Sandeen /* For ioend & aio unwritten conversion wait queues */ 2991e9e3bcecSEric Sandeen #define EXT4_WQ_HASH_SZ 37 2992e9e3bcecSEric Sandeen #define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\ 2993e9e3bcecSEric Sandeen EXT4_WQ_HASH_SZ]) 2994e9e3bcecSEric Sandeen #define ext4_aio_mutex(v) (&ext4__aio_mutex[((unsigned long)(v)) %\ 2995e9e3bcecSEric Sandeen EXT4_WQ_HASH_SZ]) 2996e9e3bcecSEric Sandeen extern wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ]; 2997e9e3bcecSEric Sandeen extern struct mutex ext4__aio_mutex[EXT4_WQ_HASH_SZ]; 2998e9e3bcecSEric Sandeen 29998f82f840SYongqiang Yang #define EXT4_RESIZING 0 30008f82f840SYongqiang Yang extern int ext4_resize_begin(struct super_block *sb); 30018f82f840SYongqiang Yang extern void ext4_resize_end(struct super_block *sb); 30028f82f840SYongqiang Yang 30033dcf5451SChristoph Hellwig #endif /* __KERNEL__ */ 30043dcf5451SChristoph Hellwig 30053dcf5451SChristoph Hellwig #endif /* _EXT4_H */ 3006