24 #include <linux/magic.h>
40 #define EXT3_DEFAULT_RESERVE_BLOCKS 8
42 #define EXT3_MAX_RESERVE_BLOCKS 1027
43 #define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0
49 #define ext3_debug(f, a...) \
51 printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:", \
52 __FILE__, __LINE__, __func__); \
53 printk (KERN_DEBUG f, ## a); \
56 #define ext3_debug(f, a...) do {} while (0)
62 #define EXT3_BAD_INO 1
63 #define EXT3_ROOT_INO 2
64 #define EXT3_BOOT_LOADER_INO 5
65 #define EXT3_UNDEL_DIR_INO 6
66 #define EXT3_RESIZE_INO 7
67 #define EXT3_JOURNAL_INO 8
70 #define EXT3_GOOD_OLD_FIRST_INO 11
75 #define EXT3_LINK_MAX 32000
80 #define EXT3_MIN_BLOCK_SIZE 1024
81 #define EXT3_MAX_BLOCK_SIZE 65536
82 #define EXT3_MIN_BLOCK_LOG_SIZE 10
83 #define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize)
84 #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
85 #define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
86 #define EXT3_ADDR_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_addr_per_block_bits)
87 #define EXT3_INODE_SIZE(s) (EXT3_SB(s)->s_inode_size)
88 #define EXT3_FIRST_INO(s) (EXT3_SB(s)->s_first_ino)
93 #define EXT3_MIN_FRAG_SIZE 1024
94 #define EXT3_MAX_FRAG_SIZE 4096
95 #define EXT3_MIN_FRAG_LOG_SIZE 10
96 #define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size)
97 #define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block)
117 #define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group)
118 #define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block)
119 #define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group)
120 #define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits)
125 #define EXT3_NDIR_BLOCKS 12
126 #define EXT3_IND_BLOCK EXT3_NDIR_BLOCKS
127 #define EXT3_DIND_BLOCK (EXT3_IND_BLOCK + 1)
128 #define EXT3_TIND_BLOCK (EXT3_DIND_BLOCK + 1)
129 #define EXT3_N_BLOCKS (EXT3_TIND_BLOCK + 1)
134 #define EXT3_SECRM_FL 0x00000001
135 #define EXT3_UNRM_FL 0x00000002
136 #define EXT3_COMPR_FL 0x00000004
137 #define EXT3_SYNC_FL 0x00000008
138 #define EXT3_IMMUTABLE_FL 0x00000010
139 #define EXT3_APPEND_FL 0x00000020
140 #define EXT3_NODUMP_FL 0x00000040
141 #define EXT3_NOATIME_FL 0x00000080
143 #define EXT3_DIRTY_FL 0x00000100
144 #define EXT3_COMPRBLK_FL 0x00000200
145 #define EXT3_NOCOMPR_FL 0x00000400
146 #define EXT3_ECOMPR_FL 0x00000800
148 #define EXT3_INDEX_FL 0x00001000
149 #define EXT3_IMAGIC_FL 0x00002000
150 #define EXT3_JOURNAL_DATA_FL 0x00004000
151 #define EXT3_NOTAIL_FL 0x00008000
152 #define EXT3_DIRSYNC_FL 0x00010000
153 #define EXT3_TOPDIR_FL 0x00020000
154 #define EXT3_RESERVED_FL 0x80000000
156 #define EXT3_FL_USER_VISIBLE 0x0003DFFF
157 #define EXT3_FL_USER_MODIFIABLE 0x000380FF
160 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
161 EXT3_SYNC_FL | EXT3_NODUMP_FL |\
162 EXT3_NOATIME_FL | EXT3_COMPRBLK_FL |\
163 EXT3_NOCOMPR_FL | EXT3_JOURNAL_DATA_FL |\
164 EXT3_NOTAIL_FL | EXT3_DIRSYNC_FL)
167 #define EXT3_REG_FLMASK (~(EXT3_DIRSYNC_FL | EXT3_TOPDIR_FL))
170 #define EXT3_OTHER_FLMASK (EXT3_NODUMP_FL | EXT3_NOATIME_FL)
210 #define EXT3_IOC_GETFLAGS FS_IOC_GETFLAGS
211 #define EXT3_IOC_SETFLAGS FS_IOC_SETFLAGS
212 #define EXT3_IOC_GETVERSION _IOR('f', 3, long)
213 #define EXT3_IOC_SETVERSION _IOW('f', 4, long)
214 #define EXT3_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
215 #define EXT3_IOC_GROUP_ADD _IOW('f', 8,struct ext3_new_group_input)
216 #define EXT3_IOC_GETVERSION_OLD FS_IOC_GETVERSION
217 #define EXT3_IOC_SETVERSION_OLD FS_IOC_SETVERSION
218 #ifdef CONFIG_JBD_DEBUG
219 #define EXT3_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
221 #define EXT3_IOC_GETRSVSZ _IOR('f', 5, long)
222 #define EXT3_IOC_SETRSVSZ _IOW('f', 6, long)
227 #define EXT3_IOC32_GETFLAGS FS_IOC32_GETFLAGS
228 #define EXT3_IOC32_SETFLAGS FS_IOC32_SETFLAGS
229 #define EXT3_IOC32_GETVERSION _IOR('f', 3, int)
230 #define EXT3_IOC32_SETVERSION _IOW('f', 4, int)
231 #define EXT3_IOC32_GETRSVSZ _IOR('f', 5, int)
232 #define EXT3_IOC32_SETRSVSZ _IOW('f', 6, int)
233 #define EXT3_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
234 #ifdef CONFIG_JBD_DEBUG
235 #define EXT3_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
237 #define EXT3_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
238 #define EXT3_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
314 #define i_size_high i_dir_acl
316 #define i_reserved1 osd1.linux1.l_i_reserved1
317 #define i_frag osd2.linux2.l_i_frag
318 #define i_fsize osd2.linux2.l_i_fsize
319 #define i_uid_low i_uid
320 #define i_gid_low i_gid
321 #define i_uid_high osd2.linux2.l_i_uid_high
322 #define i_gid_high osd2.linux2.l_i_gid_high
323 #define i_reserved2 osd2.linux2.l_i_reserved2
328 #define EXT3_VALID_FS 0x0001
329 #define EXT3_ERROR_FS 0x0002
330 #define EXT3_ORPHAN_FS 0x0004
335 #define EXT2_FLAGS_SIGNED_HASH 0x0001
336 #define EXT2_FLAGS_UNSIGNED_HASH 0x0002
337 #define EXT2_FLAGS_TEST_FILESYS 0x0004
342 #define EXT3_MOUNT_CHECK 0x00001
344 #define EXT3_MOUNT_GRPID 0x00004
345 #define EXT3_MOUNT_DEBUG 0x00008
346 #define EXT3_MOUNT_ERRORS_CONT 0x00010
347 #define EXT3_MOUNT_ERRORS_RO 0x00020
348 #define EXT3_MOUNT_ERRORS_PANIC 0x00040
349 #define EXT3_MOUNT_MINIX_DF 0x00080
350 #define EXT3_MOUNT_NOLOAD 0x00100
351 #define EXT3_MOUNT_ABORT 0x00200
352 #define EXT3_MOUNT_DATA_FLAGS 0x00C00
353 #define EXT3_MOUNT_JOURNAL_DATA 0x00400
354 #define EXT3_MOUNT_ORDERED_DATA 0x00800
355 #define EXT3_MOUNT_WRITEBACK_DATA 0x00C00
356 #define EXT3_MOUNT_UPDATE_JOURNAL 0x01000
357 #define EXT3_MOUNT_NO_UID32 0x02000
358 #define EXT3_MOUNT_XATTR_USER 0x04000
359 #define EXT3_MOUNT_POSIX_ACL 0x08000
360 #define EXT3_MOUNT_RESERVATION 0x10000
361 #define EXT3_MOUNT_BARRIER 0x20000
362 #define EXT3_MOUNT_QUOTA 0x80000
363 #define EXT3_MOUNT_USRQUOTA 0x100000
364 #define EXT3_MOUNT_GRPQUOTA 0x200000
365 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000
369 #ifndef _LINUX_EXT2_FS_H
370 #define clear_opt(o, opt) o &= ~EXT3_MOUNT_##opt
371 #define set_opt(o, opt) o |= EXT3_MOUNT_##opt
372 #define test_opt(sb, opt) (EXT3_SB(sb)->s_mount_opt & \
375 #define EXT2_MOUNT_NOLOAD EXT3_MOUNT_NOLOAD
376 #define EXT2_MOUNT_ABORT EXT3_MOUNT_ABORT
377 #define EXT2_MOUNT_DATA_FLAGS EXT3_MOUNT_DATA_FLAGS
380 #define ext3_set_bit __set_bit_le
381 #define ext3_set_bit_atomic ext2_set_bit_atomic
382 #define ext3_clear_bit __clear_bit_le
383 #define ext3_clear_bit_atomic ext2_clear_bit_atomic
384 #define ext3_test_bit test_bit_le
385 #define ext3_find_next_zero_bit find_next_zero_bit_le
390 #define EXT3_DFL_MAX_MNT_COUNT 20
391 #define EXT3_DFL_CHECKINTERVAL 0
396 #define EXT3_ERRORS_CONTINUE 1
397 #define EXT3_ERRORS_RO 2
398 #define EXT3_ERRORS_PANIC 3
399 #define EXT3_ERRORS_DEFAULT EXT3_ERRORS_CONTINUE
498 #define E3FSBLK "%lu"
532 #define rsv_start rsv_window._rsv_start
533 #define rsv_end rsv_window._rsv_end
541 #ifdef EXT3_FRAGMENTS
564 #ifdef CONFIG_EXT3_FS_XATTR
692 static inline int ext3_valid_inum(
struct super_block *
sb,
unsigned long ino)
698 ino <=
le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count));
711 static inline int ext3_test_inode_state(
struct inode *
inode,
int bit)
716 static inline void ext3_set_inode_state(
struct inode *
inode,
int bit)
721 static inline void ext3_clear_inode_state(
struct inode *inode,
int bit)
726 #define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime
731 #define EXT3_OS_LINUX 0
732 #define EXT3_OS_HURD 1
733 #define EXT3_OS_MASIX 2
734 #define EXT3_OS_FREEBSD 3
735 #define EXT3_OS_LITES 4
740 #define EXT3_GOOD_OLD_REV 0
741 #define EXT3_DYNAMIC_REV 1
743 #define EXT3_CURRENT_REV EXT3_GOOD_OLD_REV
744 #define EXT3_MAX_SUPP_REV EXT3_DYNAMIC_REV
746 #define EXT3_GOOD_OLD_INODE_SIZE 128
752 #define EXT3_HAS_COMPAT_FEATURE(sb,mask) \
753 ( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
754 #define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask) \
755 ( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
756 #define EXT3_HAS_INCOMPAT_FEATURE(sb,mask) \
757 ( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
758 #define EXT3_SET_COMPAT_FEATURE(sb,mask) \
759 EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
760 #define EXT3_SET_RO_COMPAT_FEATURE(sb,mask) \
761 EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
762 #define EXT3_SET_INCOMPAT_FEATURE(sb,mask) \
763 EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
764 #define EXT3_CLEAR_COMPAT_FEATURE(sb,mask) \
765 EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
766 #define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
767 EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
768 #define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask) \
769 EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
771 #define EXT3_FEATURE_COMPAT_DIR_PREALLOC 0x0001
772 #define EXT3_FEATURE_COMPAT_IMAGIC_INODES 0x0002
773 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
774 #define EXT3_FEATURE_COMPAT_EXT_ATTR 0x0008
775 #define EXT3_FEATURE_COMPAT_RESIZE_INODE 0x0010
776 #define EXT3_FEATURE_COMPAT_DIR_INDEX 0x0020
778 #define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
779 #define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
780 #define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
782 #define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001
783 #define EXT3_FEATURE_INCOMPAT_FILETYPE 0x0002
784 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
785 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
786 #define EXT3_FEATURE_INCOMPAT_META_BG 0x0010
788 #define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
789 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
790 EXT3_FEATURE_INCOMPAT_RECOVER| \
791 EXT3_FEATURE_INCOMPAT_META_BG)
792 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
793 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
794 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
799 #define EXT3_DEF_RESUID 0
800 #define EXT3_DEF_RESGID 0
805 #define EXT3_DEFM_DEBUG 0x0001
806 #define EXT3_DEFM_BSDGROUPS 0x0002
807 #define EXT3_DEFM_XATTR_USER 0x0004
808 #define EXT3_DEFM_ACL 0x0008
809 #define EXT3_DEFM_UID16 0x0010
810 #define EXT3_DEFM_JMODE 0x0060
811 #define EXT3_DEFM_JMODE_DATA 0x0020
812 #define EXT3_DEFM_JMODE_ORDERED 0x0040
813 #define EXT3_DEFM_JMODE_WBACK 0x0060
818 #define EXT3_NAME_LEN 255
845 #define EXT3_FT_UNKNOWN 0
846 #define EXT3_FT_REG_FILE 1
847 #define EXT3_FT_DIR 2
848 #define EXT3_FT_CHRDEV 3
849 #define EXT3_FT_BLKDEV 4
850 #define EXT3_FT_FIFO 5
851 #define EXT3_FT_SOCK 6
852 #define EXT3_FT_SYMLINK 7
854 #define EXT3_FT_MAX 8
861 #define EXT3_DIR_PAD 4
862 #define EXT3_DIR_ROUND (EXT3_DIR_PAD - 1)
863 #define EXT3_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT3_DIR_ROUND) & \
865 #define EXT3_MAX_REC_LEN ((1<<16)-1)
872 static inline unsigned ext3_rec_len_from_disk(
__le16 dlen)
876 #if (PAGE_CACHE_SIZE >= 65536)
883 static inline __le16 ext3_rec_len_to_disk(
unsigned len)
885 #if (PAGE_CACHE_SIZE >= 65536)
886 if (len == (1 << 16))
888 else if (len > (1 << 16))
899 #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
900 EXT3_FEATURE_COMPAT_DIR_INDEX) && \
901 (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
902 #define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
903 #define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
907 #define DX_HASH_LEGACY 0
908 #define DX_HASH_HALF_MD4 1
909 #define DX_HASH_TEA 2
910 #define DX_HASH_LEGACY_UNSIGNED 3
911 #define DX_HASH_HALF_MD4_UNSIGNED 4
912 #define DX_HASH_TEA_UNSIGNED 5
925 #define EXT3_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1)
926 #define EXT3_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1)
932 #define HASH_NB_ALWAYS 1
940 struct buffer_head *
bh;
967 ext3_group_first_block_no(
struct super_block *sb,
unsigned long group_no)
970 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block);
976 #define ERR_BAD_DX_DIR -75000
987 # define ATTRIB_NORET __attribute__((noreturn))
988 # define NORET_AND noreturn,
1001 unsigned long *pdquot_freed_blocks);
1006 struct buffer_head ** bh);
1015 struct buffer_head *,
unsigned long);
1029 extern struct inode *
ext3_new_inode (handle_t *,
struct inode *,
1036 extern unsigned long ext3_count_free (
struct buffer_head *,
unsigned);
1042 struct buffer_head *
ext3_getblk (handle_t *,
struct inode *,
long,
int,
int *);
1043 struct buffer_head *
ext3_bread (handle_t *,
struct inode *,
int,
int,
int *);
1045 sector_t iblock,
unsigned long maxblocks,
struct buffer_head *bh_result,
1066 extern long ext3_ioctl(
struct file *,
unsigned int,
unsigned long);
1088 extern __printf(3, 4)
1090 extern __printf(3, 4)
1094 #define ext3_std_error(sb, errno) \
1097 __ext3_std_error((sb), __func__, (errno)); \
1119 #define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal)
1128 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
1134 #define EXT3_XATTR_TRANS_BLOCKS 6U
1142 #define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \
1143 EXT3_XATTR_TRANS_BLOCKS - 2 + \
1144 EXT3_MAXQUOTAS_TRANS_BLOCKS(sb))
1150 #define EXT3_DELETE_TRANS_BLOCKS(sb) (EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) + 64)
1158 #define EXT3_MAX_TRANS_DATA 64U
1167 #define EXT3_RESERVE_TRANS_BLOCKS 12U
1169 #define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8
1174 #define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
1177 #define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
1178 (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
1179 #define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
1180 (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
1182 #define EXT3_QUOTA_TRANS_BLOCKS(sb) 0
1183 #define EXT3_QUOTA_INIT_BLOCKS(sb) 0
1184 #define EXT3_QUOTA_DEL_BLOCKS(sb) 0
1186 #define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb))
1187 #define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb))
1188 #define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb))
1192 struct inode *inode,
1212 static inline void ext3_journal_release_buffer(handle_t *
handle,
1213 struct buffer_head *bh)
1219 struct buffer_head *bh, handle_t *
handle,
int err);
1222 struct buffer_head *bh);
1225 struct buffer_head *bh);
1228 struct buffer_head *bh);
1231 unsigned long blocknr,
struct buffer_head *bh);
1234 handle_t *
handle,
struct buffer_head *bh);
1237 handle_t *
handle,
struct buffer_head *bh);
1239 #define ext3_journal_get_undo_access(handle, bh) \
1240 __ext3_journal_get_undo_access(__func__, (handle), (bh))
1241 #define ext3_journal_get_write_access(handle, bh) \
1242 __ext3_journal_get_write_access(__func__, (handle), (bh))
1243 #define ext3_journal_revoke(handle, blocknr, bh) \
1244 __ext3_journal_revoke(__func__, (handle), (blocknr), (bh))
1245 #define ext3_journal_get_create_access(handle, bh) \
1246 __ext3_journal_get_create_access(__func__, (handle), (bh))
1247 #define ext3_journal_dirty_metadata(handle, bh) \
1248 __ext3_journal_dirty_metadata(__func__, (handle), (bh))
1249 #define ext3_journal_forget(handle, bh) \
1250 __ext3_journal_forget(__func__, (handle), (bh))
1257 static inline handle_t *ext3_journal_start(
struct inode *inode,
int nblocks)
1262 #define ext3_journal_stop(handle) \
1263 __ext3_journal_stop(__func__, (handle))
1265 static inline handle_t *ext3_journal_current_handle(
void)
1267 return journal_current_handle();
1270 static inline int ext3_journal_extend(handle_t *
handle,
int nblocks)
1275 static inline int ext3_journal_restart(handle_t *
handle,
int nblocks)
1280 static inline int ext3_journal_blocks_per_page(
struct inode *inode)
1285 static inline int ext3_journal_force_commit(journal_t *journal)
1293 static inline int ext3_should_journal_data(
struct inode *inode)
1304 static inline int ext3_should_order_data(
struct inode *inode)
1315 static inline int ext3_should_writeback_data(
struct inode *inode)
1319 if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)