2929#include <linux/wait.h>
3030#include <linux/blockgroup_lock.h>
3131#include <linux/percpu_counter.h>
32+ #ifdef __KERNEL__
33+ #include <linux/compat.h>
34+ #endif
3235
3336/*
3437 * The fourth extended filesystem constants/structures
5457#endif
5558
5659#define EXT4_ERROR_INODE (inode , fmt , a ...) \
57- ext4_error_inode(__func__, (inode), (fmt), ## a);
60+ ext4_error_inode(__func__, (inode), (fmt), ## a)
5861
5962#define EXT4_ERROR_FILE (file , fmt , a ...) \
60- ext4_error_file(__func__, (file), (fmt), ## a);
63+ ext4_error_file(__func__, (file), (fmt), ## a)
6164
6265/* data type for block offset of block group */
6366typedef int ext4_grpblk_t ;
@@ -72,7 +75,7 @@ typedef __u32 ext4_lblk_t;
7275typedef unsigned int ext4_group_t ;
7376
7477/*
75- * Flags used in mballoc's allocation_context flags field.
78+ * Flags used in mballoc's allocation_context flags field.
7679 *
7780 * Also used to show what's going on for debugging purposes when the
7881 * flag field is exported via the traceport interface
@@ -125,6 +128,29 @@ struct ext4_allocation_request {
125128 unsigned int flags ;
126129};
127130
131+ /*
132+ * Logical to physical block mapping, used by ext4_map_blocks()
133+ *
134+ * This structure is used to pass requests into ext4_map_blocks() as
135+ * well as to store the information returned by ext4_map_blocks(). It
136+ * takes less room on the stack than a struct buffer_head.
137+ */
138+ #define EXT4_MAP_NEW (1 << BH_New)
139+ #define EXT4_MAP_MAPPED (1 << BH_Mapped)
140+ #define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
141+ #define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
142+ #define EXT4_MAP_UNINIT (1 << BH_Uninit)
143+ #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
144+ EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
145+ EXT4_MAP_UNINIT)
146+
147+ struct ext4_map_blocks {
148+ ext4_fsblk_t m_pblk ;
149+ ext4_lblk_t m_lblk ;
150+ unsigned int m_len ;
151+ unsigned int m_flags ;
152+ };
153+
128154/*
129155 * For delayed allocation tracking
130156 */
@@ -321,6 +347,83 @@ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
321347 return flags & EXT4_OTHER_FLMASK ;
322348}
323349
350+ /*
351+ * Inode flags used for atomic set/get
352+ */
353+ enum {
354+ EXT4_INODE_SECRM = 0 , /* Secure deletion */
355+ EXT4_INODE_UNRM = 1 , /* Undelete */
356+ EXT4_INODE_COMPR = 2 , /* Compress file */
357+ EXT4_INODE_SYNC = 3 , /* Synchronous updates */
358+ EXT4_INODE_IMMUTABLE = 4 , /* Immutable file */
359+ EXT4_INODE_APPEND = 5 , /* writes to file may only append */
360+ EXT4_INODE_NODUMP = 6 , /* do not dump file */
361+ EXT4_INODE_NOATIME = 7 , /* do not update atime */
362+ /* Reserved for compression usage... */
363+ EXT4_INODE_DIRTY = 8 ,
364+ EXT4_INODE_COMPRBLK = 9 , /* One or more compressed clusters */
365+ EXT4_INODE_NOCOMPR = 10 , /* Don't compress */
366+ EXT4_INODE_ECOMPR = 11 , /* Compression error */
367+ /* End compression flags --- maybe not all used */
368+ EXT4_INODE_INDEX = 12 , /* hash-indexed directory */
369+ EXT4_INODE_IMAGIC = 13 , /* AFS directory */
370+ EXT4_INODE_JOURNAL_DATA = 14 , /* file data should be journaled */
371+ EXT4_INODE_NOTAIL = 15 , /* file tail should not be merged */
372+ EXT4_INODE_DIRSYNC = 16 , /* dirsync behaviour (directories only) */
373+ EXT4_INODE_TOPDIR = 17 , /* Top of directory hierarchies*/
374+ EXT4_INODE_HUGE_FILE = 18 , /* Set to each huge file */
375+ EXT4_INODE_EXTENTS = 19 , /* Inode uses extents */
376+ EXT4_INODE_EA_INODE = 21 , /* Inode used for large EA */
377+ EXT4_INODE_EOFBLOCKS = 22 , /* Blocks allocated beyond EOF */
378+ EXT4_INODE_RESERVED = 31 , /* reserved for ext4 lib */
379+ };
380+
381+ #define TEST_FLAG_VALUE (FLAG ) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG))
382+ #define CHECK_FLAG_VALUE (FLAG ) if (!TEST_FLAG_VALUE(FLAG)) { \
383+ printk(KERN_EMERG "EXT4 flag fail: " #FLAG ": %d %d\n", \
384+ EXT4_##FLAG##_FL, EXT4_INODE_##FLAG); BUG_ON(1); }
385+
386+ /*
387+ * Since it's pretty easy to mix up bit numbers and hex values, and we
388+ * can't do a compile-time test for ENUM values, we use a run-time
389+ * test to make sure that EXT4_XXX_FL is consistent with respect to
390+ * EXT4_INODE_XXX. If all is well the printk and BUG_ON will all drop
391+ * out so it won't cost any extra space in the compiled kernel image.
392+ * But it's important that these values are the same, since we are
393+ * using EXT4_INODE_XXX to test for the flag values, but EXT4_XX_FL
394+ * must be consistent with the values of FS_XXX_FL defined in
395+ * include/linux/fs.h and the on-disk values found in ext2, ext3, and
396+ * ext4 filesystems, and of course the values defined in e2fsprogs.
397+ *
398+ * It's not paranoia if the Murphy's Law really *is* out to get you. :-)
399+ */
400+ static inline void ext4_check_flag_values (void )
401+ {
402+ CHECK_FLAG_VALUE (SECRM );
403+ CHECK_FLAG_VALUE (UNRM );
404+ CHECK_FLAG_VALUE (COMPR );
405+ CHECK_FLAG_VALUE (SYNC );
406+ CHECK_FLAG_VALUE (IMMUTABLE );
407+ CHECK_FLAG_VALUE (APPEND );
408+ CHECK_FLAG_VALUE (NODUMP );
409+ CHECK_FLAG_VALUE (NOATIME );
410+ CHECK_FLAG_VALUE (DIRTY );
411+ CHECK_FLAG_VALUE (COMPRBLK );
412+ CHECK_FLAG_VALUE (NOCOMPR );
413+ CHECK_FLAG_VALUE (ECOMPR );
414+ CHECK_FLAG_VALUE (INDEX );
415+ CHECK_FLAG_VALUE (IMAGIC );
416+ CHECK_FLAG_VALUE (JOURNAL_DATA );
417+ CHECK_FLAG_VALUE (NOTAIL );
418+ CHECK_FLAG_VALUE (DIRSYNC );
419+ CHECK_FLAG_VALUE (TOPDIR );
420+ CHECK_FLAG_VALUE (HUGE_FILE );
421+ CHECK_FLAG_VALUE (EXTENTS );
422+ CHECK_FLAG_VALUE (EA_INODE );
423+ CHECK_FLAG_VALUE (EOFBLOCKS );
424+ CHECK_FLAG_VALUE (RESERVED );
425+ }
426+
324427/* Used to pass group descriptor data when online resize is done */
325428struct ext4_new_group_input {
326429 __u32 group ; /* Group number for this data */
@@ -332,6 +435,18 @@ struct ext4_new_group_input {
332435 __u16 unused ;
333436};
334437
438+ #if defined(__KERNEL__ ) && defined(CONFIG_COMPAT )
439+ struct compat_ext4_new_group_input {
440+ u32 group ;
441+ compat_u64 block_bitmap ;
442+ compat_u64 inode_bitmap ;
443+ compat_u64 inode_table ;
444+ u32 blocks_count ;
445+ u16 reserved_blocks ;
446+ u16 unused ;
447+ };
448+ #endif
449+
335450/* The struct ext4_new_group_input in kernel space, with free_blocks_count */
336451struct ext4_new_group_data {
337452 __u32 group ;
@@ -355,7 +470,7 @@ struct ext4_new_group_data {
355470#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
356471 EXT4_GET_BLOCKS_CREATE)
357472 /* Caller is from the delayed allocation writeout path,
358- so set the magic i_delalloc_reserve_flag after taking the
473+ so set the magic i_delalloc_reserve_flag after taking the
359474 inode allocation semaphore for */
360475#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
361476 /* caller is from the direct IO path, request to creation of an
@@ -398,6 +513,7 @@ struct ext4_new_group_data {
398513#define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
399514#define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent)
400515
516+ #if defined(__KERNEL__ ) && defined(CONFIG_COMPAT )
401517/*
402518 * ioctl commands in 32 bit emulation
403519 */
@@ -408,11 +524,13 @@ struct ext4_new_group_data {
408524#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
409525#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
410526#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
527+ #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)
411528#ifdef CONFIG_JBD2_DEBUG
412529#define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
413530#endif
414531#define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
415532#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
533+ #endif
416534
417535
418536/*
@@ -616,9 +734,8 @@ struct ext4_ext_cache {
616734 */
617735struct ext4_inode_info {
618736 __le32 i_data [15 ]; /* unconverted */
619- __u32 i_flags ;
620- ext4_fsblk_t i_file_acl ;
621737 __u32 i_dtime ;
738+ ext4_fsblk_t i_file_acl ;
622739
623740 /*
624741 * i_block_group is the number of the block group which contains
@@ -629,6 +746,7 @@ struct ext4_inode_info {
629746 */
630747 ext4_group_t i_block_group ;
631748 unsigned long i_state_flags ; /* Dynamic state flags */
749+ unsigned long i_flags ;
632750
633751 ext4_lblk_t i_dir_start_lookup ;
634752#ifdef CONFIG_EXT4_FS_XATTR
@@ -1062,22 +1180,25 @@ enum {
10621180 EXT4_STATE_DA_ALLOC_CLOSE , /* Alloc DA blks on close */
10631181 EXT4_STATE_EXT_MIGRATE , /* Inode is migrating */
10641182 EXT4_STATE_DIO_UNWRITTEN , /* need convert on dio done*/
1183+ EXT4_STATE_NEWENTRY , /* File just added to dir */
10651184};
10661185
1067- static inline int ext4_test_inode_state (struct inode * inode , int bit )
1068- {
1069- return test_bit (bit , & EXT4_I (inode )-> i_state_flags );
1070- }
1071-
1072- static inline void ext4_set_inode_state (struct inode * inode , int bit )
1073- {
1074- set_bit (bit , & EXT4_I (inode )-> i_state_flags );
1186+ #define EXT4_INODE_BIT_FNS (name , field ) \
1187+ static inline int ext4_test_inode_##name(struct inode *inode, int bit) \
1188+ { \
1189+ return test_bit(bit, &EXT4_I(inode)->i_##field); \
1190+ } \
1191+ static inline void ext4_set_inode_##name(struct inode *inode, int bit) \
1192+ { \
1193+ set_bit(bit, &EXT4_I(inode)->i_##field); \
1194+ } \
1195+ static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
1196+ { \
1197+ clear_bit(bit, &EXT4_I(inode)->i_##field); \
10751198}
10761199
1077- static inline void ext4_clear_inode_state (struct inode * inode , int bit )
1078- {
1079- clear_bit (bit , & EXT4_I (inode )-> i_state_flags );
1080- }
1200+ EXT4_INODE_BIT_FNS (flag , flags )
1201+ EXT4_INODE_BIT_FNS (state , state_flags )
10811202#else
10821203/* Assume that user mode programs are passing in an ext4fs superblock, not
10831204 * a kernel struct super_block. This will allow us to call the feature-test
@@ -1264,7 +1385,7 @@ struct ext4_dir_entry_2 {
12641385
12651386#define is_dx (dir ) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
12661387 EXT4_FEATURE_COMPAT_DIR_INDEX) && \
1267- (EXT4_I (dir)->i_flags & EXT4_INDEX_FL ))
1388+ ext4_test_inode_flag( (dir), EXT4_INODE_INDEX ))
12681389#define EXT4_DIR_LINK_MAX (dir ) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
12691390#define EXT4_DIR_LINK_EMPTY (dir ) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
12701391
@@ -1678,6 +1799,7 @@ struct ext4_group_info {
16781799 ext4_grpblk_t bb_first_free ; /* first free block */
16791800 ext4_grpblk_t bb_free ; /* total free blocks */
16801801 ext4_grpblk_t bb_fragments ; /* nr of freespace fragments */
1802+ ext4_grpblk_t bb_largest_free_order ;/* order of largest frag in BG */
16811803 struct list_head bb_prealloc_list ;
16821804#ifdef DOUBLE_CHECK
16831805 void * bb_bitmap ;
@@ -1772,16 +1894,17 @@ extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
17721894extern int ext4_ext_writepage_trans_blocks (struct inode * , int );
17731895extern int ext4_ext_index_trans_blocks (struct inode * inode , int nrblocks ,
17741896 int chunk );
1775- extern int ext4_ext_get_blocks (handle_t * handle , struct inode * inode ,
1776- ext4_lblk_t iblock , unsigned int max_blocks ,
1777- struct buffer_head * bh_result , int flags );
1897+ extern int ext4_ext_map_blocks (handle_t * handle , struct inode * inode ,
1898+ struct ext4_map_blocks * map , int flags );
17781899extern void ext4_ext_truncate (struct inode * );
17791900extern void ext4_ext_init (struct super_block * );
17801901extern void ext4_ext_release (struct super_block * );
17811902extern long ext4_fallocate (struct inode * inode , int mode , loff_t offset ,
17821903 loff_t len );
17831904extern int ext4_convert_unwritten_extents (struct inode * inode , loff_t offset ,
17841905 ssize_t len );
1906+ extern int ext4_map_blocks (handle_t * handle , struct inode * inode ,
1907+ struct ext4_map_blocks * map , int flags );
17851908extern int ext4_get_blocks (handle_t * handle , struct inode * inode ,
17861909 sector_t block , unsigned int max_blocks ,
17871910 struct buffer_head * bh , int flags );
0 commit comments