11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
24613ad180d19082f99551477dcb13cb23d23661bAl Viro * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
34613ad180d19082f99551477dcb13cb23d23661bAl Viro *
44613ad180d19082f99551477dcb13cb23d23661bAl Viro * Copyright 1998--1999 Red Hat corp --- All Rights Reserved
54613ad180d19082f99551477dcb13cb23d23661bAl Viro *
64613ad180d19082f99551477dcb13cb23d23661bAl Viro * This file is part of the Linux kernel and is made available under
74613ad180d19082f99551477dcb13cb23d23661bAl Viro * the terms of the GNU General Public License, version 2, or at your
84613ad180d19082f99551477dcb13cb23d23661bAl Viro * option, any later version, incorporated herein by reference.
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1992, 1993, 1994, 1995
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Remy Card (card@masi.ibp.fr)
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Laboratoire MASI - Institut Blaise Pascal
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Universite Pierre et Marie Curie (Paris VI)
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  from
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  linux/include/linux/minix_fs.h
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  Copyright (C) 1991, 1992  Linus Torvalds
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
224613ad180d19082f99551477dcb13cb23d23661bAl Viro#include <linux/fs.h>
234613ad180d19082f99551477dcb13cb23d23661bAl Viro#include <linux/jbd.h>
24e18fa700c9a31360bc8f193aa543b7ef7b39a06bJeff Garzik#include <linux/magic.h>
25187f1882b5b0748b3c4c22274663fdb372ac0452Paul Gortmaker#include <linux/bug.h>
264613ad180d19082f99551477dcb13cb23d23661bAl Viro#include <linux/blockgroup_lock.h>
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The second extended filesystem constants/structures
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Define EXT3FS_DEBUG to produce debug messages
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#undef EXT3FS_DEBUG
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Define EXT3_RESERVATION to reserve data blocks for expanding files
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFAULT_RESERVE_BLOCKS     8
41b54e41ec17ae91dce174eb5a3515e7af4a440d42Mingming Cao/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
42b54e41ec17ae91dce174eb5a3515e7af4a440d42Mingming Cao#define EXT3_MAX_RESERVE_BLOCKS         1027
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Debug code
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef EXT3FS_DEBUG
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ext3_debug(f, a...)						\
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	do {								\
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:",	\
52d5c003b4d1690e666dbab02bc8e705947baa848cHarvey Harrison			__FILE__, __LINE__, __func__);		\
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		printk (KERN_DEBUG f, ## a);				\
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} while (0)
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ext3_debug(f, a...)	do {} while (0)
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Special inodes numbers
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_BAD_INO		 1	/* Bad blocks inode */
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ROOT_INO		 2	/* Root inode */
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_BOOT_LOADER_INO	 5	/* Boot loader inode */
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_UNDEL_DIR_INO	 6	/* Undelete directory inode */
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_RESIZE_INO		 7	/* Reserved group descriptors inode */
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_JOURNAL_INO	 8	/* Journal inode */
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* First non-reserved inode for old ext3 filesystems */
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_GOOD_OLD_FIRST_INO	11
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Maximal count of links to a file
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_LINK_MAX		32000
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Macro-instructions used to manage several block sizes
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MIN_BLOCK_SIZE		1024
810f0a89ebe1ccf7c280534f69577cdd182941eb6aTakashi Sato#define	EXT3_MAX_BLOCK_SIZE		65536
820f0a89ebe1ccf7c280534f69577cdd182941eb6aTakashi Sato#define EXT3_MIN_BLOCK_LOG_SIZE		10
834613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_BLOCK_SIZE(s)		((s)->s_blocksize)
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_ADDR_PER_BLOCK(s)		(EXT3_BLOCK_SIZE(s) / sizeof (__u32))
854613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_BLOCK_SIZE_BITS(s)	((s)->s_blocksize_bits)
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_ADDR_PER_BLOCK_BITS(s)	(EXT3_SB(s)->s_addr_per_block_bits)
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_INODE_SIZE(s)		(EXT3_SB(s)->s_inode_size)
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FIRST_INO(s)		(EXT3_SB(s)->s_first_ino)
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Macro-instructions used to manage fragments
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MIN_FRAG_SIZE		1024
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_MAX_FRAG_SIZE		4096
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MIN_FRAG_LOG_SIZE		  10
964613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_FRAG_SIZE(s)		(EXT3_SB(s)->s_frag_size)
974613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_FRAGS_PER_BLOCK(s)		(EXT3_SB(s)->s_frags_per_block)
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Structure of a blocks group descriptor
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_group_desc
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	bg_block_bitmap;		/* Blocks bitmap block */
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	bg_inode_bitmap;		/* Inodes bitmap block */
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	bg_inode_table;		/* Inodes table block */
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	bg_free_blocks_count;	/* Free blocks count */
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	bg_free_inodes_count;	/* Free inodes count */
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	bg_used_dirs_count;	/* Directories count */
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16	bg_pad;
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	bg_reserved[3];
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Macro-instructions used to manage group descriptors
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1174613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_BLOCKS_PER_GROUP(s)	(EXT3_SB(s)->s_blocks_per_group)
1184613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_DESC_PER_BLOCK(s)		(EXT3_SB(s)->s_desc_per_block)
1194613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_INODES_PER_GROUP(s)	(EXT3_SB(s)->s_inodes_per_group)
1204613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_DESC_PER_BLOCK_BITS(s)	(EXT3_SB(s)->s_desc_per_block_bits)
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Constants relative to the data blocks
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_NDIR_BLOCKS		12
1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_IND_BLOCK			EXT3_NDIR_BLOCKS
1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_DIND_BLOCK			(EXT3_IND_BLOCK + 1)
1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_TIND_BLOCK			(EXT3_DIND_BLOCK + 1)
1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_N_BLOCKS			(EXT3_TIND_BLOCK + 1)
1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Inode flags
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_SECRM_FL			0x00000001 /* Secure deletion */
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_UNRM_FL			0x00000002 /* Undelete */
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_COMPR_FL			0x00000004 /* Compress file */
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_SYNC_FL			0x00000008 /* Synchronous updates */
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IMMUTABLE_FL		0x00000010 /* Immutable file */
1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_APPEND_FL			0x00000020 /* writes to file may only append */
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_NODUMP_FL			0x00000040 /* do not dump file */
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_NOATIME_FL			0x00000080 /* do not update atime */
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Reserved for compression usage... */
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIRTY_FL			0x00000100
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_COMPRBLK_FL		0x00000200 /* One or more compressed clusters */
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_NOCOMPR_FL			0x00000400 /* Don't compress */
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ECOMPR_FL			0x00000800 /* Compression error */
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* End compression flags --- maybe not all used */
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_INDEX_FL			0x00001000 /* hash-indexed directory */
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IMAGIC_FL			0x00002000 /* AFS directory */
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_JOURNAL_DATA_FL		0x00004000 /* file data should be journaled */
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_NOTAIL_FL			0x00008000 /* file tail should not be merged */
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_TOPDIR_FL			0x00020000 /* Top of directory hierarchies*/
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_RESERVED_FL		0x80000000 /* reserved for ext3 lib */
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FL_USER_VISIBLE		0x0003DFFF /* User visible flags */
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FL_USER_MODIFIABLE		0x000380FF /* User modifiable flags */
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1592e8671cb566da993425d324fc355af31edc6e7f1Duane Griffin/* Flags that should be inherited by new inodes from their parent. */
1602e8671cb566da993425d324fc355af31edc6e7f1Duane Griffin#define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
1611cd9f0976aa4606db8d6e3dc3edd0aca8019372aTheodore Ts'o			   EXT3_SYNC_FL | EXT3_NODUMP_FL |\
1621cd9f0976aa4606db8d6e3dc3edd0aca8019372aTheodore Ts'o			   EXT3_NOATIME_FL | EXT3_COMPRBLK_FL |\
1632e8671cb566da993425d324fc355af31edc6e7f1Duane Griffin			   EXT3_NOCOMPR_FL | EXT3_JOURNAL_DATA_FL |\
1642e8671cb566da993425d324fc355af31edc6e7f1Duane Griffin			   EXT3_NOTAIL_FL | EXT3_DIRSYNC_FL)
1652e8671cb566da993425d324fc355af31edc6e7f1Duane Griffin
16604143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin/* Flags that are appropriate for regular files (all but dir-specific ones). */
16704143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin#define EXT3_REG_FLMASK (~(EXT3_DIRSYNC_FL | EXT3_TOPDIR_FL))
16804143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin
16904143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin/* Flags that are appropriate for non-directories/regular files. */
17004143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin#define EXT3_OTHER_FLMASK (EXT3_NODUMP_FL | EXT3_NOATIME_FL)
17104143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin
17204143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin/* Mask out flags that are inappropriate for the given type of inode. */
17304143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffinstatic inline __u32 ext3_mask_flags(umode_t mode, __u32 flags)
17404143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin{
17504143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin	if (S_ISDIR(mode))
17604143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin		return flags;
17704143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin	else if (S_ISREG(mode))
17804143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin		return flags & EXT3_REG_FLMASK;
17904143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin	else
18004143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin		return flags & EXT3_OTHER_FLMASK;
18104143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin}
18204143e2fb9d512c21e1dcfb561dbb0445dcfdc8cDuane Griffin
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Used to pass group descriptor data when online resize is done */
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_new_group_input {
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 group;            /* Group number for this data */
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 block_bitmap;     /* Absolute block number of block bitmap */
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 inode_bitmap;     /* Absolute block number of inode bitmap */
1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 inode_table;      /* Absolute block number of inode table start */
1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 blocks_count;     /* Total number of blocks in this group */
1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16 reserved_blocks;  /* Number of reserved blocks in this group */
1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16 unused;
1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* The struct ext3_new_group_input in kernel space, with free_blocks_count */
1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_new_group_data {
1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 group;
1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 block_bitmap;
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 inode_bitmap;
1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 inode_table;
2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 blocks_count;
2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16 reserved_blocks;
2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16 unused;
2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 free_blocks_count;
2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ioctl commands
2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
21036695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define	EXT3_IOC_GETFLAGS		FS_IOC_GETFLAGS
21136695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define	EXT3_IOC_SETFLAGS		FS_IOC_SETFLAGS
2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_IOC_GETVERSION		_IOR('f', 3, long)
2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_IOC_SETVERSION		_IOW('f', 4, long)
2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IOC_GROUP_EXTEND		_IOW('f', 7, unsigned long)
2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IOC_GROUP_ADD		_IOW('f', 8,struct ext3_new_group_input)
21636695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define	EXT3_IOC_GETVERSION_OLD		FS_IOC_GETVERSION
21736695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define	EXT3_IOC_SETVERSION_OLD		FS_IOC_SETVERSION
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef CONFIG_JBD_DEBUG
2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IOC_WAIT_FOR_READONLY	_IOR('f', 99, long)
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IOC_GETRSVSZ		_IOR('f', 5, long)
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_IOC_SETRSVSZ		_IOW('f', 6, long)
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
22536695673b012096228ebdc1b39a6a5850daa474eDavid Howells * ioctl commands in 32 bit emulation
22636695673b012096228ebdc1b39a6a5850daa474eDavid Howells */
22752a700c5675f399c07e6e57328291e57f13ef3bbDavid Howells#define EXT3_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
22852a700c5675f399c07e6e57328291e57f13ef3bbDavid Howells#define EXT3_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
22936695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_GETVERSION		_IOR('f', 3, int)
23036695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_SETVERSION		_IOW('f', 4, int)
23136695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_GETRSVSZ		_IOR('f', 5, int)
23236695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_SETRSVSZ		_IOW('f', 6, int)
23336695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_GROUP_EXTEND		_IOW('f', 7, unsigned int)
23436695673b012096228ebdc1b39a6a5850daa474eDavid Howells#ifdef CONFIG_JBD_DEBUG
23536695673b012096228ebdc1b39a6a5850daa474eDavid Howells#define EXT3_IOC32_WAIT_FOR_READONLY	_IOR('f', 99, int)
23636695673b012096228ebdc1b39a6a5850daa474eDavid Howells#endif
23752a700c5675f399c07e6e57328291e57f13ef3bbDavid Howells#define EXT3_IOC32_GETVERSION_OLD	FS_IOC32_GETVERSION
23852a700c5675f399c07e6e57328291e57f13ef3bbDavid Howells#define EXT3_IOC32_SETVERSION_OLD	FS_IOC32_SETVERSION
23952a700c5675f399c07e6e57328291e57f13ef3bbDavid Howells
240a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara/* Number of supported quota types */
241a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara#define EXT3_MAXQUOTAS 2
24236695673b012096228ebdc1b39a6a5850daa474eDavid Howells
24336695673b012096228ebdc1b39a6a5850daa474eDavid Howells/*
24408c6a96fd77836856c090ebb39beadc81cb8484dJan Kara *  Mount options
24508c6a96fd77836856c090ebb39beadc81cb8484dJan Kara */
24608c6a96fd77836856c090ebb39beadc81cb8484dJan Karastruct ext3_mount_options {
24708c6a96fd77836856c090ebb39beadc81cb8484dJan Kara	unsigned long s_mount_opt;
2481523299d5817773e344d135d4b1c485f269400bcEric W. Biederman	kuid_t s_resuid;
2491523299d5817773e344d135d4b1c485f269400bcEric W. Biederman	kgid_t s_resgid;
25008c6a96fd77836856c090ebb39beadc81cb8484dJan Kara	unsigned long s_commit_interval;
25108c6a96fd77836856c090ebb39beadc81cb8484dJan Kara#ifdef CONFIG_QUOTA
25208c6a96fd77836856c090ebb39beadc81cb8484dJan Kara	int s_jquota_fmt;
253a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara	char *s_qf_names[EXT3_MAXQUOTAS];
25408c6a96fd77836856c090ebb39beadc81cb8484dJan Kara#endif
25508c6a96fd77836856c090ebb39beadc81cb8484dJan Kara};
25608c6a96fd77836856c090ebb39beadc81cb8484dJan Kara
25708c6a96fd77836856c090ebb39beadc81cb8484dJan Kara/*
2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Structure of an inode on the disk
2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_inode {
2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_mode;		/* File mode */
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_uid;		/* Low 16 bits of Owner Uid */
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_size;		/* Size in bytes */
2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_atime;	/* Access time */
2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_ctime;	/* Creation time */
2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_mtime;	/* Modification time */
2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_dtime;	/* Deletion Time */
2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_gid;		/* Low 16 bits of Group Id */
2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_links_count;	/* Links count */
2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_blocks;	/* Blocks count */
2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_flags;	/* File flags */
2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	union {
2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32  l_i_reserved1;
2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} linux1;
2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32  h_i_translator;
2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} hurd1;
2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32  m_i_reserved1;
2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} masix1;
2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} osd1;				/* OS dependent 1 */
2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_block[EXT3_N_BLOCKS];/* Pointers to blocks */
2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_generation;	/* File version (for NFS) */
2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_file_acl;	/* File ACL */
2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_dir_acl;	/* Directory ACL */
2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	i_faddr;	/* Fragment address */
2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	union {
2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	l_i_frag;	/* Fragment number */
2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	l_i_fsize;	/* Fragment size */
2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u16	i_pad1;
2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__le16	l_i_uid_high;	/* these 2 fields    */
2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__le16	l_i_gid_high;	/* were reserved2[0] */
2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32	l_i_reserved2;
2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} linux2;
2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	h_i_frag;	/* Fragment number */
2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	h_i_fsize;	/* Fragment size */
3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u16	h_i_mode_high;
3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u16	h_i_uid_high;
3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u16	h_i_gid_high;
3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32	h_i_author;
3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} hurd2;
3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		struct {
3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	m_i_frag;	/* Fragment number */
3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u8	m_i_fsize;	/* Fragment size */
3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u16	m_pad1;
3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__u32	m_i_reserved2[2];
3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		} masix2;
3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	} osd2;				/* OS dependent 2 */
3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_extra_isize;
3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	i_pad1;
3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_size_high	i_dir_acl
3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_reserved1	osd1.linux1.l_i_reserved1
3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_frag		osd2.linux2.l_i_frag
3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_fsize		osd2.linux2.l_i_fsize
3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_uid_low	i_uid
3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_gid_low	i_gid
3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_uid_high	osd2.linux2.l_i_uid_high
3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_gid_high	osd2.linux2.l_i_gid_high
3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define i_reserved2	osd2.linux2.l_i_reserved2
3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * File system states
3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_VALID_FS			0x0001	/* Unmounted cleanly */
3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_ERROR_FS			0x0002	/* Errors detected */
3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_ORPHAN_FS			0x0004	/* Orphans being recovered */
3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
3355e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o * Misc. filesystem flags
3365e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o */
3375e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define EXT2_FLAGS_SIGNED_HASH		0x0001  /* Signed dirhash in use */
3385e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define EXT2_FLAGS_UNSIGNED_HASH	0x0002  /* Unsigned dirhash in use */
3395e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define EXT2_FLAGS_TEST_FILESYS		0x0004	/* to test development code */
3405e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o
3415e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o/*
3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Mount flags
3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_CHECK		0x00001	/* Do mount-time checks */
345fbc854027c91fa2813ae7f9de43cc0b5c1119f41Lukas Czerner/* EXT3_MOUNT_OLDALLOC was there */
3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_GRPID		0x00004	/* Create files with directory's group */
3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_DEBUG		0x00008	/* Some debugging messages */
3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_ERRORS_CONT		0x00010	/* Continue on errors */
3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_ERRORS_RO		0x00020	/* Remount fs ro on errors */
3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_ERRORS_PANIC		0x00040	/* Panic on errors */
3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_MINIX_DF		0x00080	/* Mimics the Minix statfs */
3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_NOLOAD		0x00100	/* Don't use existing journal*/
3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_ABORT		0x00200	/* Fatal error detected */
3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_DATA_FLAGS		0x00C00	/* Mode for data writes: */
3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_JOURNAL_DATA		0x00400	/* Write data to journal */
3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_ORDERED_DATA		0x00800	/* Flush data before commit */
3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_WRITEBACK_DATA	0x00C00	/* No data ordering */
3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_UPDATE_JOURNAL	0x01000	/* Update the journal format */
3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_NO_UID32		0x02000  /* Disable 32-bit UIDs */
3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_XATTR_USER		0x04000	/* Extended user attributes */
3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_POSIX_ACL		0x08000	/* POSIX Access Control Lists */
3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_RESERVATION		0x10000	/* Preallocation */
3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MOUNT_BARRIER		0x20000 /* Use block barriers */
3641f54587bea84a35125c95e19b98c2f464c50871bJan Kara#define EXT3_MOUNT_QUOTA		0x80000 /* Some quota option set */
3658fc2751beb0941966d3a97b26544e8585e428c08Mark Bellon#define EXT3_MOUNT_USRQUOTA		0x100000 /* "old" user quota */
3668fc2751beb0941966d3a97b26544e8585e428c08Mark Bellon#define EXT3_MOUNT_GRPQUOTA		0x200000 /* "old" group quota */
3670e4fb5e283870757024294bc4567a7c59d936f0bHidehiro Kawai#define EXT3_MOUNT_DATA_ERR_ABORT	0x400000 /* Abort on file data write
3680e4fb5e283870757024294bc4567a7c59d936f0bHidehiro Kawai						  * error in ordered mode */
3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _LINUX_EXT2_FS_H
3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define clear_opt(o, opt)		o &= ~EXT3_MOUNT_##opt
3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define set_opt(o, opt)			o |= EXT3_MOUNT_##opt
3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define test_opt(sb, opt)		(EXT3_SB(sb)->s_mount_opt & \
3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 EXT3_MOUNT_##opt)
3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT2_MOUNT_NOLOAD		EXT3_MOUNT_NOLOAD
3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT2_MOUNT_ABORT		EXT3_MOUNT_ABORT
3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT2_MOUNT_DATA_FLAGS		EXT3_MOUNT_DATA_FLAGS
3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3829008593017069ad513cc7dc78a6c94e8dfddba31Akinobu Mita#define ext3_set_bit			__set_bit_le
3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ext3_set_bit_atomic		ext2_set_bit_atomic
3849008593017069ad513cc7dc78a6c94e8dfddba31Akinobu Mita#define ext3_clear_bit			__clear_bit_le
3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ext3_clear_bit_atomic		ext2_clear_bit_atomic
3860795ccea24714c790187e3d4f23c8e5be515f42dAkinobu Mita#define ext3_test_bit			test_bit_le
3870795ccea24714c790187e3d4f23c8e5be515f42dAkinobu Mita#define ext3_find_next_zero_bit		find_next_zero_bit_le
3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Maximal mount counts between two filesystem checks
3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DFL_MAX_MNT_COUNT		20	/* Allow 20 mounts */
3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DFL_CHECKINTERVAL		0	/* Don't use interval check */
3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Behaviour when detecting errors
3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ERRORS_CONTINUE		1	/* Continue execution */
3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ERRORS_RO			2	/* Remount fs read-only */
4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ERRORS_PANIC		3	/* Panic */
4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_ERRORS_DEFAULT		EXT3_ERRORS_CONTINUE
4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Structure of the super block
4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_super_block {
4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*00*/	__le32	s_inodes_count;		/* Inodes count */
4081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_blocks_count;		/* Blocks count */
4091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_r_blocks_count;	/* Reserved blocks count */
4101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_free_blocks_count;	/* Free blocks count */
4111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*10*/	__le32	s_free_inodes_count;	/* Free inodes count */
4121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_first_data_block;	/* First Data Block */
4131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_log_block_size;	/* Block size */
4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_log_frag_size;	/* Fragment size */
4151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*20*/	__le32	s_blocks_per_group;	/* # Blocks per group */
4161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_frags_per_group;	/* # Fragments per group */
4171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_inodes_per_group;	/* # Inodes per group */
4181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_mtime;		/* Mount time */
4191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*30*/	__le32	s_wtime;		/* Write time */
4201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_mnt_count;		/* Mount count */
4211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_max_mnt_count;	/* Maximal mount count */
4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_magic;		/* Magic signature */
4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_state;		/* File system state */
4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_errors;		/* Behaviour when detecting errors */
4251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_minor_rev_level;	/* minor revision level */
4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*40*/	__le32	s_lastcheck;		/* time of last check */
4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_checkinterval;	/* max. time between checks */
4281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_creator_os;		/* OS */
4291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_rev_level;		/* Revision level */
4301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*50*/	__le16	s_def_resuid;		/* Default uid for reserved blocks */
4311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_def_resgid;		/* Default gid for reserved blocks */
4321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
4331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * These fields are for EXT3_DYNAMIC_REV superblocks only.
4341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 *
4351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Note: the difference between the compatible feature set and
4361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * the incompatible feature set is that if there is a bit set
4371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * in the incompatible feature set that the kernel doesn't
4381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * know about, it should refuse to mount the filesystem.
4391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 *
4401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * e2fsck's requirements are more strict; if it doesn't know
4411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * about a feature in either the compatible or incompatible
4421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * feature set, it must abort and not try to meddle with
4431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * things it doesn't understand...
4441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
4451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_first_ino;		/* First non-reserved inode */
4461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16   s_inode_size;		/* size of inode structure */
4471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	s_block_group_nr;	/* block group # of this superblock */
4481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_feature_compat;	/* compatible feature set */
4491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*60*/	__le32	s_feature_incompat;	/* incompatible feature set */
4501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_feature_ro_compat;	/* readonly-compatible feature set */
4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*68*/	__u8	s_uuid[16];		/* 128-bit uuid for volume */
4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*78*/	char	s_volume_name[16];	/* volume name */
4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*88*/	char	s_last_mounted[64];	/* directory where last mounted */
4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*C8*/	__le32	s_algorithm_usage_bitmap; /* For compression */
4551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Performance hints.  Directory preallocation should only
4571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on.
4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
461a4e4de36dc446b2193bdc8ebb96a96e44b69dd94Dave Kleikamp	__le16	s_reserved_gdt_blocks;	/* Per group desc for online growth */
4621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*D0*/	__u8	s_journal_uuid[16];	/* uuid of journal superblock */
4661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*E0*/	__le32	s_journal_inum;		/* inode number of journal file */
4671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_journal_dev;		/* device number of journal file */
4681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_last_orphan;		/* start of list of inodes to delete */
4691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_hash_seed[4];		/* HTREE hash seed */
4701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	s_def_hash_version;	/* Default hash version to use */
4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	s_reserved_char_pad;
4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u16	s_reserved_word_pad;
4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	s_default_mount_opts;
474e9ad5620bfb901df8a7a2603c88689ededeecaf1Dave Kleikamp	__le32	s_first_meta_bg;	/* First metablock block group */
4755e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32	s_mkfs_time;		/* When the filesystem was created */
4765e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32	s_jnl_blocks[17];	/* Backup of the journal inode */
4775e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
4785e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o/*150*/	__le32	s_blocks_count_hi;	/* Blocks count */
4795e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32	s_r_blocks_count_hi;	/* Reserved blocks count */
4805e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32	s_free_blocks_count_hi;	/* Free blocks count */
4815e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le16	s_min_extra_isize;	/* All inodes have at least # bytes */
4825e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le16	s_want_extra_isize; 	/* New inodes should reserve # bytes */
4835e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32	s_flags;		/* Miscellaneous flags */
4845e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le16  s_raid_stride;		/* RAID stride */
4855e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le16  s_mmp_interval;         /* # seconds to wait in MMP checking */
4865e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le64  s_mmp_block;            /* Block for multi-mount protection */
4875e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le32  s_raid_stripe_width;    /* blocks on all data disks (N*stride)*/
4885e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__u8	s_log_groups_per_flex;  /* FLEX_BG group size */
4895e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__u8	s_reserved_char_pad2;
4905e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__le16  s_reserved_pad;
4915e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o	__u32   s_reserved[162];        /* Padding to the end of the block */
4921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
4931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4944613ad180d19082f99551477dcb13cb23d23661bAl Viro/* data type for block offset of block group */
4954613ad180d19082f99551477dcb13cb23d23661bAl Virotypedef int ext3_grpblk_t;
4964613ad180d19082f99551477dcb13cb23d23661bAl Viro
4974613ad180d19082f99551477dcb13cb23d23661bAl Viro/* data type for filesystem-wide blocks number */
4984613ad180d19082f99551477dcb13cb23d23661bAl Virotypedef unsigned long ext3_fsblk_t;
4994613ad180d19082f99551477dcb13cb23d23661bAl Viro
5004613ad180d19082f99551477dcb13cb23d23661bAl Viro#define E3FSBLK "%lu"
5014613ad180d19082f99551477dcb13cb23d23661bAl Viro
5024613ad180d19082f99551477dcb13cb23d23661bAl Virostruct ext3_reserve_window {
5034613ad180d19082f99551477dcb13cb23d23661bAl Viro	ext3_fsblk_t	_rsv_start;	/* First byte reserved */
5044613ad180d19082f99551477dcb13cb23d23661bAl Viro	ext3_fsblk_t	_rsv_end;	/* Last byte reserved or 0 */
5054613ad180d19082f99551477dcb13cb23d23661bAl Viro};
5064613ad180d19082f99551477dcb13cb23d23661bAl Viro
5074613ad180d19082f99551477dcb13cb23d23661bAl Virostruct ext3_reserve_window_node {
5084613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct rb_node		rsv_node;
5094613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32			rsv_goal_size;
5104613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32			rsv_alloc_hit;
5114613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct ext3_reserve_window	rsv_window;
5124613ad180d19082f99551477dcb13cb23d23661bAl Viro};
5134613ad180d19082f99551477dcb13cb23d23661bAl Viro
5144613ad180d19082f99551477dcb13cb23d23661bAl Virostruct ext3_block_alloc_info {
5154613ad180d19082f99551477dcb13cb23d23661bAl Viro	/* information about reservation window */
5164613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct ext3_reserve_window_node	rsv_window_node;
5174613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
5184613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * was i_next_alloc_block in ext3_inode_info
5194613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * is the logical (file-relative) number of the
5204613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * most-recently-allocated block in this file.
5214613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * We use this for detecting linearly ascending allocation requests.
5224613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
5234613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32                   last_alloc_logical_block;
5244613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
5254613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * Was i_next_alloc_goal in ext3_inode_info
5264613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * is the *physical* companion to i_next_alloc_block.
5274613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * it the physical block number of the block which was most-recentl
5284613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * allocated to this file.  This give us the goal (target) for the next
5294613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * allocation when we detect linearly ascending requests.
5304613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
5314613ad180d19082f99551477dcb13cb23d23661bAl Viro	ext3_fsblk_t		last_alloc_physical_block;
5324613ad180d19082f99551477dcb13cb23d23661bAl Viro};
5334613ad180d19082f99551477dcb13cb23d23661bAl Viro
5344613ad180d19082f99551477dcb13cb23d23661bAl Viro#define rsv_start rsv_window._rsv_start
5354613ad180d19082f99551477dcb13cb23d23661bAl Viro#define rsv_end rsv_window._rsv_end
5364613ad180d19082f99551477dcb13cb23d23661bAl Viro
5374613ad180d19082f99551477dcb13cb23d23661bAl Viro/*
5384613ad180d19082f99551477dcb13cb23d23661bAl Viro * third extended file system inode data in memory
5394613ad180d19082f99551477dcb13cb23d23661bAl Viro */
5404613ad180d19082f99551477dcb13cb23d23661bAl Virostruct ext3_inode_info {
5414613ad180d19082f99551477dcb13cb23d23661bAl Viro	__le32	i_data[15];	/* unconverted */
5424613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_flags;
5434613ad180d19082f99551477dcb13cb23d23661bAl Viro#ifdef EXT3_FRAGMENTS
5444613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_faddr;
5454613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u8	i_frag_no;
5464613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u8	i_frag_size;
5474613ad180d19082f99551477dcb13cb23d23661bAl Viro#endif
5484613ad180d19082f99551477dcb13cb23d23661bAl Viro	ext3_fsblk_t	i_file_acl;
5494613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_dir_acl;
5504613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_dtime;
5514613ad180d19082f99551477dcb13cb23d23661bAl Viro
5524613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
5534613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * i_block_group is the number of the block group which contains
5544613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * this file's inode.  Constant across the lifetime of the inode,
5554613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * it is ued for making block allocation decisions - we try to
5564613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * place a file's data blocks near its inode block, and new inodes
5574613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * near to their parent directory's inode.
5584613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
5594613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_block_group;
5604613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long	i_state_flags;	/* Dynamic state flags for ext3 */
5614613ad180d19082f99551477dcb13cb23d23661bAl Viro
5624613ad180d19082f99551477dcb13cb23d23661bAl Viro	/* block reservation info */
5634613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct ext3_block_alloc_info *i_block_alloc_info;
5644613ad180d19082f99551477dcb13cb23d23661bAl Viro
5654613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u32	i_dir_start_lookup;
5664613ad180d19082f99551477dcb13cb23d23661bAl Viro#ifdef CONFIG_EXT3_FS_XATTR
5674613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
5684613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * Extended attributes can be read independently of the main file
5694613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * data. Taking i_mutex even when reading would cause contention
5704613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * between readers of EAs and writers of regular file data, so
5714613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * instead we synchronize on xattr_sem when reading or changing
5724613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * EAs.
5734613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
5744613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct rw_semaphore xattr_sem;
5754613ad180d19082f99551477dcb13cb23d23661bAl Viro#endif
5764613ad180d19082f99551477dcb13cb23d23661bAl Viro
5774613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct list_head i_orphan;	/* unlinked but open inodes */
5784613ad180d19082f99551477dcb13cb23d23661bAl Viro
5794613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
5804613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * i_disksize keeps track of what the inode size is ON DISK, not
5814613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * in memory.  During truncate, i_size is set to the new size by
5824613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * the VFS prior to calling ext3_truncate(), but the filesystem won't
5834613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * set i_disksize to 0 until the truncate is actually under way.
5844613ad180d19082f99551477dcb13cb23d23661bAl Viro	 *
5854613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * The intent is that i_disksize always represents the blocks which
5864613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * are used by this file.  This allows recovery to restart truncate
5874613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * on orphans if we crash during truncate.  We actually write i_disksize
5884613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * into the on-disk inode when writing inodes out, instead of i_size.
5894613ad180d19082f99551477dcb13cb23d23661bAl Viro	 *
5904613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * The only time when i_disksize and i_size may be different is when
5914613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * a truncate is in progress.  The only things which change i_disksize
5924613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * are ext3_get_block (growth) and ext3_truncate (shrinkth).
5934613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
5944613ad180d19082f99551477dcb13cb23d23661bAl Viro	loff_t	i_disksize;
5954613ad180d19082f99551477dcb13cb23d23661bAl Viro
5964613ad180d19082f99551477dcb13cb23d23661bAl Viro	/* on-disk additional length */
5974613ad180d19082f99551477dcb13cb23d23661bAl Viro	__u16 i_extra_isize;
5984613ad180d19082f99551477dcb13cb23d23661bAl Viro
5994613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
6004613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * truncate_mutex is for serialising ext3_truncate() against
6014613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * ext3_getblock().  In the 2.4 ext2 design, great chunks of inode's
6024613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * data tree are chopped off during truncate. We can't do that in
6034613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * ext3 because whenever we perform intermediate commits during
6044613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * truncate, the inode and all the metadata blocks *must* be in a
6054613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * consistent state which allows truncation of the orphans to restart
6064613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * during recovery.  Hence we must fix the get_block-vs-truncate race
6074613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * by other means, so we have truncate_mutex.
6084613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
6094613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct mutex truncate_mutex;
6104613ad180d19082f99551477dcb13cb23d23661bAl Viro
6114613ad180d19082f99551477dcb13cb23d23661bAl Viro	/*
6124613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * Transactions that contain inode's metadata needed to complete
6134613ad180d19082f99551477dcb13cb23d23661bAl Viro	 * fsync and fdatasync, respectively.
6144613ad180d19082f99551477dcb13cb23d23661bAl Viro	 */
6154613ad180d19082f99551477dcb13cb23d23661bAl Viro	atomic_t i_sync_tid;
6164613ad180d19082f99551477dcb13cb23d23661bAl Viro	atomic_t i_datasync_tid;
6174613ad180d19082f99551477dcb13cb23d23661bAl Viro
6184613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct inode vfs_inode;
6194613ad180d19082f99551477dcb13cb23d23661bAl Viro};
6204613ad180d19082f99551477dcb13cb23d23661bAl Viro
6214613ad180d19082f99551477dcb13cb23d23661bAl Viro/*
6224613ad180d19082f99551477dcb13cb23d23661bAl Viro * third extended-fs super-block data in memory
6234613ad180d19082f99551477dcb13cb23d23661bAl Viro */
6244613ad180d19082f99551477dcb13cb23d23661bAl Virostruct ext3_sb_info {
6254613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_frag_size;	/* Size of a fragment in bytes */
6264613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_frags_per_block;/* Number of fragments per block */
6274613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_inodes_per_block;/* Number of inodes per block */
6284613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_frags_per_group;/* Number of fragments in a group */
6294613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_blocks_per_group;/* Number of blocks in a group */
6304613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_inodes_per_group;/* Number of inodes in a group */
6314613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
6324613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_gdb_count;	/* Number of group descriptor blocks */
6334613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_desc_per_block;	/* Number of group descriptors per block */
6344613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_groups_count;	/* Number of groups in the fs */
6354613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_overhead_last;  /* Last calculated overhead */
6364613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_blocks_last;    /* Last seen block count */
6374613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct buffer_head * s_sbh;	/* Buffer containing the super block */
6384613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct ext3_super_block * s_es;	/* Pointer to the super block in the buffer */
6394613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct buffer_head ** s_group_desc;
6404613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long  s_mount_opt;
6414613ad180d19082f99551477dcb13cb23d23661bAl Viro	ext3_fsblk_t s_sb_block;
6421523299d5817773e344d135d4b1c485f269400bcEric W. Biederman	kuid_t s_resuid;
6431523299d5817773e344d135d4b1c485f269400bcEric W. Biederman	kgid_t s_resgid;
6444613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned short s_mount_state;
6454613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned short s_pad;
6464613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_addr_per_block_bits;
6474613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_desc_per_block_bits;
6484613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_inode_size;
6494613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_first_ino;
6504613ad180d19082f99551477dcb13cb23d23661bAl Viro	spinlock_t s_next_gen_lock;
6514613ad180d19082f99551477dcb13cb23d23661bAl Viro	u32 s_next_generation;
6524613ad180d19082f99551477dcb13cb23d23661bAl Viro	u32 s_hash_seed[4];
6534613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_def_hash_version;
6544613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_hash_unsigned;	/* 3 if hash should be signed, 0 if not */
6554613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct percpu_counter s_freeblocks_counter;
6564613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct percpu_counter s_freeinodes_counter;
6574613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct percpu_counter s_dirs_counter;
6584613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct blockgroup_lock *s_blockgroup_lock;
6594613ad180d19082f99551477dcb13cb23d23661bAl Viro
6604613ad180d19082f99551477dcb13cb23d23661bAl Viro	/* root of the per fs reservation window tree */
6614613ad180d19082f99551477dcb13cb23d23661bAl Viro	spinlock_t s_rsv_window_lock;
6624613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct rb_root s_rsv_window_root;
6634613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct ext3_reserve_window_node s_rsv_window_head;
6644613ad180d19082f99551477dcb13cb23d23661bAl Viro
6654613ad180d19082f99551477dcb13cb23d23661bAl Viro	/* Journaling */
6664613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct inode * s_journal_inode;
6674613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct journal_s * s_journal;
6684613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct list_head s_orphan;
6694613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct mutex s_orphan_lock;
6704613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct mutex s_resize_lock;
6714613ad180d19082f99551477dcb13cb23d23661bAl Viro	unsigned long s_commit_interval;
6724613ad180d19082f99551477dcb13cb23d23661bAl Viro	struct block_device *journal_bdev;
6734613ad180d19082f99551477dcb13cb23d23661bAl Viro#ifdef CONFIG_QUOTA
674a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara	char *s_qf_names[EXT3_MAXQUOTAS];	/* Names of quota files with journalled quota */
6754613ad180d19082f99551477dcb13cb23d23661bAl Viro	int s_jquota_fmt;			/* Format of quota to use */
6764613ad180d19082f99551477dcb13cb23d23661bAl Viro#endif
6774613ad180d19082f99551477dcb13cb23d23661bAl Viro};
6784613ad180d19082f99551477dcb13cb23d23661bAl Viro
6794613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline spinlock_t *
6804613ad180d19082f99551477dcb13cb23d23661bAl Virosb_bgl_lock(struct ext3_sb_info *sbi, unsigned int block_group)
6814613ad180d19082f99551477dcb13cb23d23661bAl Viro{
6824613ad180d19082f99551477dcb13cb23d23661bAl Viro	return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
6834613ad180d19082f99551477dcb13cb23d23661bAl Viro}
6844613ad180d19082f99551477dcb13cb23d23661bAl Viro
6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct ext3_sb_info * EXT3_SB(struct super_block *sb)
6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return sb->s_fs_info;
6881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct ext3_inode_info *EXT3_I(struct inode *inode)
6901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
6911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return container_of(inode, struct ext3_inode_info, vfs_inode);
6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
6932ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown
6942ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brownstatic inline int ext3_valid_inum(struct super_block *sb, unsigned long ino)
6952ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown{
6962ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown	return ino == EXT3_ROOT_INO ||
6972ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown		ino == EXT3_JOURNAL_INO ||
6982ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown		ino == EXT3_RESIZE_INO ||
6992ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown		(ino >= EXT3_FIRST_INO(sb) &&
7002ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown		 ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count));
7012ccb48ebb4de139eef4fcefd5f2bb823cb0d81b9Neil Brown}
7029df93939b735dd273e49cbee290b9f4738500ef4Jan Kara
7039df93939b735dd273e49cbee290b9f4738500ef4Jan Kara/*
7049df93939b735dd273e49cbee290b9f4738500ef4Jan Kara * Inode dynamic state flags
7059df93939b735dd273e49cbee290b9f4738500ef4Jan Kara */
7069df93939b735dd273e49cbee290b9f4738500ef4Jan Karaenum {
7079df93939b735dd273e49cbee290b9f4738500ef4Jan Kara	EXT3_STATE_JDATA,		/* journaled data exists */
7089df93939b735dd273e49cbee290b9f4738500ef4Jan Kara	EXT3_STATE_NEW,			/* inode is newly created */
7099df93939b735dd273e49cbee290b9f4738500ef4Jan Kara	EXT3_STATE_XATTR,		/* has in-inode xattrs */
7109df93939b735dd273e49cbee290b9f4738500ef4Jan Kara	EXT3_STATE_FLUSH_ON_CLOSE,	/* flush dirty pages on close */
7119df93939b735dd273e49cbee290b9f4738500ef4Jan Kara};
7129df93939b735dd273e49cbee290b9f4738500ef4Jan Kara
7139df93939b735dd273e49cbee290b9f4738500ef4Jan Karastatic inline int ext3_test_inode_state(struct inode *inode, int bit)
7149df93939b735dd273e49cbee290b9f4738500ef4Jan Kara{
715de329820e920cd9cfbc2127cad26a37026260cceLinus Torvalds	return test_bit(bit, &EXT3_I(inode)->i_state_flags);
7169df93939b735dd273e49cbee290b9f4738500ef4Jan Kara}
7179df93939b735dd273e49cbee290b9f4738500ef4Jan Kara
7189df93939b735dd273e49cbee290b9f4738500ef4Jan Karastatic inline void ext3_set_inode_state(struct inode *inode, int bit)
7199df93939b735dd273e49cbee290b9f4738500ef4Jan Kara{
720de329820e920cd9cfbc2127cad26a37026260cceLinus Torvalds	set_bit(bit, &EXT3_I(inode)->i_state_flags);
7219df93939b735dd273e49cbee290b9f4738500ef4Jan Kara}
7229df93939b735dd273e49cbee290b9f4738500ef4Jan Kara
7239df93939b735dd273e49cbee290b9f4738500ef4Jan Karastatic inline void ext3_clear_inode_state(struct inode *inode, int bit)
7249df93939b735dd273e49cbee290b9f4738500ef4Jan Kara{
725de329820e920cd9cfbc2127cad26a37026260cceLinus Torvalds	clear_bit(bit, &EXT3_I(inode)->i_state_flags);
7269df93939b735dd273e49cbee290b9f4738500ef4Jan Kara}
7271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime
7291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
7311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Codes for operating systems
7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
7331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_OS_LINUX		0
7341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_OS_HURD		1
7351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_OS_MASIX		2
7361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_OS_FREEBSD		3
7371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_OS_LITES		4
7381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Revision levels
7411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_GOOD_OLD_REV	0	/* The good old (original) format */
7431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DYNAMIC_REV	1	/* V2 format w/ dynamic inode sizes */
7441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_CURRENT_REV	EXT3_GOOD_OLD_REV
7461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_MAX_SUPP_REV	EXT3_DYNAMIC_REV
7471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_GOOD_OLD_INODE_SIZE 128
7491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Feature set definitions
7521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
7531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_HAS_COMPAT_FEATURE(sb,mask)			\
7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask)			\
7571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_HAS_INCOMPAT_FEATURE(sb,mask)			\
7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_SET_COMPAT_FEATURE(sb,mask)			\
7611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
7621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_SET_RO_COMPAT_FEATURE(sb,mask)			\
7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_SET_INCOMPAT_FEATURE(sb,mask)			\
7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
7661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_CLEAR_COMPAT_FEATURE(sb,mask)			\
7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
7691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
7701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
7721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_DIR_PREALLOC	0x0001
7741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_IMAGIC_INODES	0x0002
7751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x0004
7761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_EXT_ATTR		0x0008
7771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_RESIZE_INODE	0x0010
7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_DIR_INDEX		0x0020
7791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
7811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
7821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_RO_COMPAT_BTREE_DIR	0x0004
7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_COMPRESSION	0x0001
7851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_FILETYPE		0x0002
7861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004 /* Needs recovery */
7871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008 /* Journal device */
7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_META_BG		0x0010
7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
7911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_INCOMPAT_SUPP	(EXT3_FEATURE_INCOMPAT_FILETYPE| \
7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 EXT3_FEATURE_INCOMPAT_RECOVER| \
7931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 EXT3_FEATURE_INCOMPAT_META_BG)
7941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FEATURE_RO_COMPAT_SUPP	(EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Default values for user and/or group using reserved blocks
8001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_DEF_RESUID		0
8021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define	EXT3_DEF_RESGID		0
8031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Default mount options
8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_DEBUG		0x0001
8081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_BSDGROUPS	0x0002
8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_XATTR_USER	0x0004
8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_ACL		0x0008
8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_UID16		0x0010
8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_JMODE		0x0060
8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_JMODE_DATA	0x0020
8141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_JMODE_ORDERED	0x0040
8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DEFM_JMODE_WBACK	0x0060
8161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Structure of a directory entry
8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_NAME_LEN 255
8211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_dir_entry {
8231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	inode;			/* Inode number */
8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	rec_len;		/* Directory entry length */
8251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	name_len;		/* Name length */
8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char	name[EXT3_NAME_LEN];	/* File name */
8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
8281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The new version of the directory entry.  Since EXT3 structures are
8311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * stored in intel byte order, and the name_len field could never be
8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * bigger than 255 chars, it's safe to reclaim the extra byte for the
8331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * file_type field.
8341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_dir_entry_2 {
8361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le32	inode;			/* Inode number */
8371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__le16	rec_len;		/* Directory entry length */
8381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	name_len;		/* Name length */
8391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8	file_type;
8401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	char	name[EXT3_NAME_LEN];	/* File name */
8411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
8421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Ext3 directory file types.  Only the low 3 bits are used.  The
8451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * other bits are reserved for now.
8461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_UNKNOWN		0
8481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_REG_FILE	1
8491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_DIR		2
8501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_CHRDEV		3
8511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_BLKDEV		4
8521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_FIFO		5
8531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_SOCK		6
8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_SYMLINK		7
8551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_FT_MAX		8
8571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * EXT3_DIR_PAD defines the directory entries boundaries
8601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
8611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NOTE: It must be a multiple of 4
8621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIR_PAD			4
8641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIR_ROUND			(EXT3_DIR_PAD - 1)
8651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT3_DIR_ROUND) & \
8661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds					 ~EXT3_DIR_ROUND)
8677c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara#define EXT3_MAX_REC_LEN		((1<<16)-1)
8687c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara
869a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen/*
870a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen * Tests against MAX_REC_LEN etc were put in place for 64k block
871a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen * sizes; if that is not possible on this arch, we can skip
872a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen * those tests and speed things up.
873a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen */
8747c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Karastatic inline unsigned ext3_rec_len_from_disk(__le16 dlen)
8757c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara{
8767c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	unsigned len = le16_to_cpu(dlen);
8777c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara
878a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen#if (PAGE_CACHE_SIZE >= 65536)
8797c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	if (len == EXT3_MAX_REC_LEN)
8807c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara		return 1 << 16;
881a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen#endif
8827c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	return len;
8837c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara}
8847c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara
8857c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Karastatic inline __le16 ext3_rec_len_to_disk(unsigned len)
8867c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara{
887a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen#if (PAGE_CACHE_SIZE >= 65536)
8887c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	if (len == (1 << 16))
8897c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara		return cpu_to_le16(EXT3_MAX_REC_LEN);
8907c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	else if (len > (1 << 16))
8917c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara		BUG();
892a4ae3094869f18e26ece25ad175bbe4cd740e60bEric Sandeen#endif
8937c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara	return cpu_to_le16(len);
8947c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara}
8957c06a8dc64a2d1884bd19b4c6353d9267ae4e3e1Jan Kara
8961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
8971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Hash Tree Directory indexing
8981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (c) Daniel Phillips, 2001
8991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
901059590f495f9c6e89cb018b9e612c3eec2336109Eric Sandeen#define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
902059590f495f9c6e89cb018b9e612c3eec2336109Eric Sandeen				      EXT3_FEATURE_COMPAT_DIR_INDEX) && \
9031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		      (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
9041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
9051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
9061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Legal values for the dx_root hash_version field: */
9081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DX_HASH_LEGACY		0
9101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DX_HASH_HALF_MD4	1
9111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DX_HASH_TEA		2
9125e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define DX_HASH_LEGACY_UNSIGNED	3
9135e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define DX_HASH_HALF_MD4_UNSIGNED	4
9145e1f8c9e20a92743eefc9a82c2db835213905e26Theodore Ts'o#define DX_HASH_TEA_UNSIGNED		5
9151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* hash info structure used by the directory hash */
9171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct dx_hash_info
9181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
9191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32		hash;
9201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32		minor_hash;
9211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int		hash_version;
9221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32		*seed;
9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
925d7dab39b6e16d5eea78ed3c705d2a2d0772b4f06Eric Sandeen
926d7dab39b6e16d5eea78ed3c705d2a2d0772b4f06Eric Sandeen/* 32 and 64 bit signed EOF for dx directories */
927d7dab39b6e16d5eea78ed3c705d2a2d0772b4f06Eric Sandeen#define EXT3_HTREE_EOF_32BIT   ((1UL  << (32 - 1)) - 1)
928d7dab39b6e16d5eea78ed3c705d2a2d0772b4f06Eric Sandeen#define EXT3_HTREE_EOF_64BIT   ((1ULL << (64 - 1)) - 1)
929d7dab39b6e16d5eea78ed3c705d2a2d0772b4f06Eric Sandeen
9301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Control parameters used by ext3_htree_next_block
9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define HASH_NB_ALWAYS		1
9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Describe an inode's exact location on disk and in memory
9391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct ext3_iloc
9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
9421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct buffer_head *bh;
9431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long offset;
9441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long block_group;
9451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
9461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline struct ext3_inode *ext3_raw_inode(struct ext3_iloc *iloc)
9481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
9491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset);
9501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
9511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This structure is stuffed into the struct file's private_data field
9541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * for directories.  It is where we put information so that we can do
9551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * readdir operations in hash tree order.
9561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct dir_private_info {
9581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct rb_root	root;
9591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct rb_node	*curr_node;
9601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct fname	*extra_fname;
9611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	loff_t		last_pos;
9621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32		curr_hash;
9631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32		curr_minor_hash;
9641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32		next_hash;
9651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
9661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
96743d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao/* calculate the first block number of the group */
96843d23f9039fc810ecd621f1e4f9d578eadce058aMingming Caostatic inline ext3_fsblk_t
96943d23f9039fc810ecd621f1e4f9d578eadce058aMingming Caoext3_group_first_block_no(struct super_block *sb, unsigned long group_no)
97043d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao{
97143d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao	return group_no * (ext3_fsblk_t)EXT3_BLOCKS_PER_GROUP(sb) +
97243d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao		le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block);
97343d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao}
97443d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao
9751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Special error return code only used by dx_probe() and its callers.
9771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ERR_BAD_DX_DIR	-75000
9791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Function prototypes
9821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
9851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Ok, these declarations are also in <linux/kernel.h> but none of the
9861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ext3 source programs needs to include it so they are duplicated here.
9871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
9881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define NORET_TYPE    /**/
9891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define ATTRIB_NORET  __attribute__((noreturn))
9901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds# define NORET_AND     noreturn,
9911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* balloc.c */
9931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_bg_has_super(struct super_block *sb, int group);
9941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
9951c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Caoextern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode,
9961c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao			ext3_fsblk_t goal, int *errp);
9971c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Caoextern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode,
9981c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao			ext3_fsblk_t goal, unsigned long *count, int *errp);
9991c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Caoextern void ext3_free_blocks (handle_t *handle, struct inode *inode,
10001c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao			ext3_fsblk_t block, unsigned long count);
10011c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Caoextern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb,
10021c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao				 ext3_fsblk_t block, unsigned long count,
10031c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao				unsigned long *pdquot_freed_blocks);
100443d23f9039fc810ecd621f1e4f9d578eadce058aMingming Caoextern ext3_fsblk_t ext3_count_free_blocks (struct super_block *);
10051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_check_blocks_bitmap (struct super_block *);
10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
10071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds						    unsigned int block_group,
10081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds						    struct buffer_head ** bh);
10091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_should_retry_alloc(struct super_block *sb, int *retries);
10101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_init_block_alloc_info(struct inode *);
10111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_rsv_window_add(struct super_block *sb, struct ext3_reserve_window_node *rsv);
1012b853b96b1dbdc05fc8eae141a595366d8172962bLukas Czernerextern int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range);
10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* dir.c */
10151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_check_dir_entry(const char *, struct inode *,
10161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				struct ext3_dir_entry_2 *,
10171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				struct buffer_head *, unsigned long);
10181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				    __u32 minor_hash,
10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				    struct ext3_dir_entry_2 *dirent);
10211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_htree_free_dir_info(struct dir_private_info *p);
10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* fsync.c */
102402c24a82187d5a628c68edfe71ae60dc135cd178Josef Bacikextern int ext3_sync_file(struct file *, loff_t, loff_t, int);
10251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* hash.c */
10271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3fs_dirhash(const char *name, int len, struct
10281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			  dx_hash_info *hinfo);
10291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ialloc.c */
10312a7dba391e5628ad665ce84ef9a6648da541ebabEric Parisextern struct inode * ext3_new_inode (handle_t *, struct inode *,
103269b34f3ab30836bb736b5108f40bf76de9f656f3Al Viro				      const struct qstr *, umode_t);
10331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_free_inode (handle_t *, struct inode *);
10341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct inode * ext3_orphan_get (struct super_block *, unsigned long);
10351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned long ext3_count_free_inodes (struct super_block *);
10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned long ext3_count_dirs (struct super_block *);
10371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_check_inodes_bitmap (struct super_block *);
10381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern unsigned long ext3_count_free (struct buffer_head *, unsigned);
10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* inode.c */
10421c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Caoint ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
10431c2bf374a4b8c2e1a3e6ff3a64fb67272a8cd2e2Mingming Cao		struct buffer_head *bh, ext3_fsblk_t blocknr);
1044d8733c2956968a01394a4d2a9e97a8b431a78776Andrew Mortonstruct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
1045d8733c2956968a01394a4d2a9e97a8b431a78776Andrew Mortonstruct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
104689747d369d34e333b9b60f10f333a0b727b4e4e2Mingming Caoint ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
104789747d369d34e333b9b60f10f333a0b727b4e4e2Mingming Cao	sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
104843237b5490e8f2f4679decd660064ff35ce490ccJan Kara	int create);
10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1050473043dcee1874aab99f66b0362b344618eb3790David Howellsextern struct inode *ext3_iget(struct super_block *, unsigned long);
1051a9185b41a4f84971b930c519f0c63bd450c4810dChristoph Hellwigextern int  ext3_write_inode (struct inode *, struct writeback_control *);
10521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int  ext3_setattr (struct dentry *, struct iattr *);
1053ac14a95b5239d37b6082c3791b88d7ab4e8e444cAl Viroextern void ext3_evict_inode (struct inode *);
10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int  ext3_sync_inode (handle_t *, struct inode *);
10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_discard_reservation (struct inode *);
1056aa38572954ade525817fe88c54faebf85e5a61c0Christoph Hellwigextern void ext3_dirty_inode(struct inode *, int);
10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_change_inode_journal_flag(struct inode *, int);
10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);
1059ae76dd9a6b5bbe5315fb7028e03f68f75b8538f3Duane Griffinextern int ext3_can_truncate(struct inode *inode);
106040680f2fa4670ab35ee554822a69dda1a118f966Jan Karaextern void ext3_truncate(struct inode *inode);
10611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_set_inode_flags(struct inode *);
106228be5abb400e5e082f5225105fdc69337ec0c0b4Jan Karaextern void ext3_get_inode_flags(struct ext3_inode_info *);
10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_set_aops(struct inode *inode);
106468c9d702bb72f367f3b148963ec6cf5e07ff7f65Josef Bacikextern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
106568c9d702bb72f367f3b148963ec6cf5e07ff7f65Josef Bacik		       u64 start, u64 len);
10661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ioctl.c */
1068039fd8ce6258e01ec29f1637f9bf1868dd877c55Cyrus Massoumiextern long ext3_ioctl(struct file *, unsigned int, unsigned long);
1069039fd8ce6258e01ec29f1637f9bf1868dd877c55Cyrus Massoumiextern long ext3_compat_ioctl(struct file *, unsigned int, unsigned long);
10701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* namei.c */
10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_orphan_add(handle_t *, struct inode *);
10731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_orphan_del(handle_t *, struct inode *);
10741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
10751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				__u32 start_minor_hash, __u32 *next_hash);
10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* resize.c */
10781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_group_add(struct super_block *sb,
10791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				struct ext3_new_group_data *input);
10801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int ext3_group_extend(struct super_block *sb,
10811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				struct ext3_super_block *es,
108243d23f9039fc810ecd621f1e4f9d578eadce058aMingming Cao				ext3_fsblk_t n_blocks_count);
10831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* super.c */
1085b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesextern __printf(3, 4)
1086b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesvoid ext3_error(struct super_block *, const char *, const char *, ...);
10871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void __ext3_std_error (struct super_block *, const char *, int);
1088b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesextern __printf(3, 4)
1089b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesvoid ext3_abort(struct super_block *, const char *, const char *, ...);
1090b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesextern __printf(3, 4)
1091b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesvoid ext3_warning(struct super_block *, const char *, const char *, ...);
1092b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesextern __printf(3, 4)
1093b9075fa968a0a4347aef35e235e2995c0e57ddddJoe Perchesvoid ext3_msg(struct super_block *, const char *, const char *, ...);
10941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void ext3_update_dynamic_rev (struct super_block *sb);
10951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
10961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ext3_std_error(sb, errno)				\
10971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo {								\
10981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if ((errno))						\
1099d5c003b4d1690e666dbab02bc8e705947baa848cHarvey Harrison		__ext3_std_error((sb), __func__, (errno));	\
11001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0)
11011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
11031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Inodes and files operations
11041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
11051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* dir.c */
11074b6f5d20b04dcbc3d888555522b90ba6d36c4106Arjan van de Venextern const struct file_operations ext3_dir_operations;
11081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* file.c */
1110c5ef1c42c51b1b5b4a401a6517bdda30933ddbafArjan van de Venextern const struct inode_operations ext3_file_inode_operations;
11114b6f5d20b04dcbc3d888555522b90ba6d36c4106Arjan van de Venextern const struct file_operations ext3_file_operations;
11121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* namei.c */
1114c5ef1c42c51b1b5b4a401a6517bdda30933ddbafArjan van de Venextern const struct inode_operations ext3_dir_inode_operations;
1115c5ef1c42c51b1b5b4a401a6517bdda30933ddbafArjan van de Venextern const struct inode_operations ext3_special_inode_operations;
11161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* symlink.c */
1118c5ef1c42c51b1b5b4a401a6517bdda30933ddbafArjan van de Venextern const struct inode_operations ext3_symlink_inode_operations;
1119c5ef1c42c51b1b5b4a401a6517bdda30933ddbafArjan van de Venextern const struct inode_operations ext3_fast_symlink_inode_operations;
11201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
11214613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_JOURNAL(inode)	(EXT3_SB((inode)->i_sb)->s_journal)
11224613ad180d19082f99551477dcb13cb23d23661bAl Viro
11234613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Define the number of blocks we need to account to a transaction to
11244613ad180d19082f99551477dcb13cb23d23661bAl Viro * modify one block of data.
11254613ad180d19082f99551477dcb13cb23d23661bAl Viro *
11264613ad180d19082f99551477dcb13cb23d23661bAl Viro * We may have to touch one inode, one bitmap buffer, up to three
11274613ad180d19082f99551477dcb13cb23d23661bAl Viro * indirection blocks, the group and superblock summaries, and the data
11284613ad180d19082f99551477dcb13cb23d23661bAl Viro * block to complete the transaction.  */
11294613ad180d19082f99551477dcb13cb23d23661bAl Viro
11304613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_SINGLEDATA_TRANS_BLOCKS	8U
11314613ad180d19082f99551477dcb13cb23d23661bAl Viro
11324613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Extended attribute operations touch at most two data buffers,
11334613ad180d19082f99551477dcb13cb23d23661bAl Viro * two bitmap buffers, and two group summaries, in addition to the inode
11344613ad180d19082f99551477dcb13cb23d23661bAl Viro * and the superblock, which are already accounted for. */
11354613ad180d19082f99551477dcb13cb23d23661bAl Viro
11364613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_XATTR_TRANS_BLOCKS		6U
11374613ad180d19082f99551477dcb13cb23d23661bAl Viro
11384613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Define the minimum size for a transaction which modifies data.  This
11394613ad180d19082f99551477dcb13cb23d23661bAl Viro * needs to take into account the fact that we may end up modifying two
11404613ad180d19082f99551477dcb13cb23d23661bAl Viro * quota files too (one for the group, one for the user quota).  The
11414613ad180d19082f99551477dcb13cb23d23661bAl Viro * superblock only gets updated once, of course, so don't bother
11424613ad180d19082f99551477dcb13cb23d23661bAl Viro * counting that again for the quota updates. */
11434613ad180d19082f99551477dcb13cb23d23661bAl Viro
11444613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_DATA_TRANS_BLOCKS(sb)	(EXT3_SINGLEDATA_TRANS_BLOCKS + \
11454613ad180d19082f99551477dcb13cb23d23661bAl Viro					 EXT3_XATTR_TRANS_BLOCKS - 2 + \
11464613ad180d19082f99551477dcb13cb23d23661bAl Viro					 EXT3_MAXQUOTAS_TRANS_BLOCKS(sb))
11474613ad180d19082f99551477dcb13cb23d23661bAl Viro
11484613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Delete operations potentially hit one directory's namespace plus an
11494613ad180d19082f99551477dcb13cb23d23661bAl Viro * entire inode, plus arbitrary amounts of bitmap/indirection data.  Be
11504613ad180d19082f99551477dcb13cb23d23661bAl Viro * generous.  We can grow the delete transaction later if necessary. */
11514613ad180d19082f99551477dcb13cb23d23661bAl Viro
11524613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_DELETE_TRANS_BLOCKS(sb)   (EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) + 64)
11534613ad180d19082f99551477dcb13cb23d23661bAl Viro
11544613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Define an arbitrary limit for the amount of data we will anticipate
11554613ad180d19082f99551477dcb13cb23d23661bAl Viro * writing to any given transaction.  For unbounded transactions such as
11564613ad180d19082f99551477dcb13cb23d23661bAl Viro * write(2) and truncate(2) we can write more than this, but we always
11574613ad180d19082f99551477dcb13cb23d23661bAl Viro * start off at the maximum transaction size and grow the transaction
11584613ad180d19082f99551477dcb13cb23d23661bAl Viro * optimistically as we go. */
11594613ad180d19082f99551477dcb13cb23d23661bAl Viro
11604613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_MAX_TRANS_DATA		64U
11614613ad180d19082f99551477dcb13cb23d23661bAl Viro
11624613ad180d19082f99551477dcb13cb23d23661bAl Viro/* We break up a large truncate or write transaction once the handle's
11634613ad180d19082f99551477dcb13cb23d23661bAl Viro * buffer credits gets this low, we need either to extend the
11644613ad180d19082f99551477dcb13cb23d23661bAl Viro * transaction or to start a new one.  Reserve enough space here for
11654613ad180d19082f99551477dcb13cb23d23661bAl Viro * inode, bitmap, superblock, group and indirection updates for at least
11664613ad180d19082f99551477dcb13cb23d23661bAl Viro * one block, plus two quota updates.  Quota allocations are not
11674613ad180d19082f99551477dcb13cb23d23661bAl Viro * needed. */
11684613ad180d19082f99551477dcb13cb23d23661bAl Viro
11694613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_RESERVE_TRANS_BLOCKS	12U
11704613ad180d19082f99551477dcb13cb23d23661bAl Viro
11714613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_INDEX_EXTRA_TRANS_BLOCKS	8
11724613ad180d19082f99551477dcb13cb23d23661bAl Viro
11734613ad180d19082f99551477dcb13cb23d23661bAl Viro#ifdef CONFIG_QUOTA
11744613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Amount of blocks needed for quota update - we know that the structure was
11754613ad180d19082f99551477dcb13cb23d23661bAl Viro * allocated so we need to update only inode+data */
11764613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
11774613ad180d19082f99551477dcb13cb23d23661bAl Viro/* Amount of blocks needed for quota insert/delete - we do some block writes
11784613ad180d19082f99551477dcb13cb23d23661bAl Viro * but inode, sb and group updates are done only once */
11794613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
11804613ad180d19082f99551477dcb13cb23d23661bAl Viro		(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
11814613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
11824613ad180d19082f99551477dcb13cb23d23661bAl Viro		(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
11834613ad180d19082f99551477dcb13cb23d23661bAl Viro#else
11844613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_TRANS_BLOCKS(sb) 0
11854613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_INIT_BLOCKS(sb) 0
11864613ad180d19082f99551477dcb13cb23d23661bAl Viro#define EXT3_QUOTA_DEL_BLOCKS(sb) 0
11874613ad180d19082f99551477dcb13cb23d23661bAl Viro#endif
1188a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara#define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (EXT3_MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb))
1189a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara#define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (EXT3_MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb))
1190a93114e4688f8ff7aba3a1012f17cfadc054d08bJan Kara#define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (EXT3_MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb))
11914613ad180d19082f99551477dcb13cb23d23661bAl Viro
11924613ad180d19082f99551477dcb13cb23d23661bAl Viroint
11934613ad180d19082f99551477dcb13cb23d23661bAl Viroext3_mark_iloc_dirty(handle_t *handle,
11944613ad180d19082f99551477dcb13cb23d23661bAl Viro		     struct inode *inode,
11954613ad180d19082f99551477dcb13cb23d23661bAl Viro		     struct ext3_iloc *iloc);
11964613ad180d19082f99551477dcb13cb23d23661bAl Viro
11974613ad180d19082f99551477dcb13cb23d23661bAl Viro/*
11984613ad180d19082f99551477dcb13cb23d23661bAl Viro * On success, We end up with an outstanding reference count against
11994613ad180d19082f99551477dcb13cb23d23661bAl Viro * iloc->bh.  This _must_ be cleaned up later.
12004613ad180d19082f99551477dcb13cb23d23661bAl Viro */
12014613ad180d19082f99551477dcb13cb23d23661bAl Viro
12024613ad180d19082f99551477dcb13cb23d23661bAl Viroint ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
12034613ad180d19082f99551477dcb13cb23d23661bAl Viro			struct ext3_iloc *iloc);
12044613ad180d19082f99551477dcb13cb23d23661bAl Viro
12054613ad180d19082f99551477dcb13cb23d23661bAl Viroint ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
12064613ad180d19082f99551477dcb13cb23d23661bAl Viro
12074613ad180d19082f99551477dcb13cb23d23661bAl Viro/*
12084613ad180d19082f99551477dcb13cb23d23661bAl Viro * Wrapper functions with which ext3 calls into JBD.  The intent here is
12094613ad180d19082f99551477dcb13cb23d23661bAl Viro * to allow these to be turned into appropriate stubs so ext3 can control
12104613ad180d19082f99551477dcb13cb23d23661bAl Viro * ext2 filesystems, so ext2+ext3 systems only nee one fs.  This work hasn't
12114613ad180d19082f99551477dcb13cb23d23661bAl Viro * been done yet.
12124613ad180d19082f99551477dcb13cb23d23661bAl Viro */
12134613ad180d19082f99551477dcb13cb23d23661bAl Viro
12144613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline void ext3_journal_release_buffer(handle_t *handle,
12154613ad180d19082f99551477dcb13cb23d23661bAl Viro						struct buffer_head *bh)
12164613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12174613ad180d19082f99551477dcb13cb23d23661bAl Viro	journal_release_buffer(handle, bh);
12184613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12194613ad180d19082f99551477dcb13cb23d23661bAl Viro
12204613ad180d19082f99551477dcb13cb23d23661bAl Virovoid ext3_journal_abort_handle(const char *caller, const char *err_fn,
12214613ad180d19082f99551477dcb13cb23d23661bAl Viro		struct buffer_head *bh, handle_t *handle, int err);
12224613ad180d19082f99551477dcb13cb23d23661bAl Viro
12234613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_get_undo_access(const char *where, handle_t *handle,
12244613ad180d19082f99551477dcb13cb23d23661bAl Viro				struct buffer_head *bh);
12254613ad180d19082f99551477dcb13cb23d23661bAl Viro
12264613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_get_write_access(const char *where, handle_t *handle,
12274613ad180d19082f99551477dcb13cb23d23661bAl Viro				struct buffer_head *bh);
12284613ad180d19082f99551477dcb13cb23d23661bAl Viro
12294613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_forget(const char *where, handle_t *handle,
12304613ad180d19082f99551477dcb13cb23d23661bAl Viro				struct buffer_head *bh);
12311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12324613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_revoke(const char *where, handle_t *handle,
12334613ad180d19082f99551477dcb13cb23d23661bAl Viro				unsigned long blocknr, struct buffer_head *bh);
12344613ad180d19082f99551477dcb13cb23d23661bAl Viro
12354613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_get_create_access(const char *where,
12364613ad180d19082f99551477dcb13cb23d23661bAl Viro				handle_t *handle, struct buffer_head *bh);
12374613ad180d19082f99551477dcb13cb23d23661bAl Viro
12384613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_dirty_metadata(const char *where,
12394613ad180d19082f99551477dcb13cb23d23661bAl Viro				handle_t *handle, struct buffer_head *bh);
12404613ad180d19082f99551477dcb13cb23d23661bAl Viro
12414613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_get_undo_access(handle, bh) \
12424613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_get_undo_access(__func__, (handle), (bh))
12434613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_get_write_access(handle, bh) \
12444613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_get_write_access(__func__, (handle), (bh))
12454613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_revoke(handle, blocknr, bh) \
12464613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_revoke(__func__, (handle), (blocknr), (bh))
12474613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_get_create_access(handle, bh) \
12484613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_get_create_access(__func__, (handle), (bh))
12494613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_dirty_metadata(handle, bh) \
12504613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_dirty_metadata(__func__, (handle), (bh))
12514613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_forget(handle, bh) \
12524613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_forget(__func__, (handle), (bh))
12534613ad180d19082f99551477dcb13cb23d23661bAl Viro
12544613ad180d19082f99551477dcb13cb23d23661bAl Viroint ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
12554613ad180d19082f99551477dcb13cb23d23661bAl Viro
12564613ad180d19082f99551477dcb13cb23d23661bAl Virohandle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
12574613ad180d19082f99551477dcb13cb23d23661bAl Viroint __ext3_journal_stop(const char *where, handle_t *handle);
12584613ad180d19082f99551477dcb13cb23d23661bAl Viro
12594613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
12604613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12614613ad180d19082f99551477dcb13cb23d23661bAl Viro	return ext3_journal_start_sb(inode->i_sb, nblocks);
12624613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12634613ad180d19082f99551477dcb13cb23d23661bAl Viro
12644613ad180d19082f99551477dcb13cb23d23661bAl Viro#define ext3_journal_stop(handle) \
12654613ad180d19082f99551477dcb13cb23d23661bAl Viro	__ext3_journal_stop(__func__, (handle))
12664613ad180d19082f99551477dcb13cb23d23661bAl Viro
12674613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline handle_t *ext3_journal_current_handle(void)
12684613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12694613ad180d19082f99551477dcb13cb23d23661bAl Viro	return journal_current_handle();
12704613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12714613ad180d19082f99551477dcb13cb23d23661bAl Viro
12724613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_journal_extend(handle_t *handle, int nblocks)
12734613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12744613ad180d19082f99551477dcb13cb23d23661bAl Viro	return journal_extend(handle, nblocks);
12754613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12764613ad180d19082f99551477dcb13cb23d23661bAl Viro
12774613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_journal_restart(handle_t *handle, int nblocks)
12784613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12794613ad180d19082f99551477dcb13cb23d23661bAl Viro	return journal_restart(handle, nblocks);
12804613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12814613ad180d19082f99551477dcb13cb23d23661bAl Viro
12824613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_journal_blocks_per_page(struct inode *inode)
12834613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12844613ad180d19082f99551477dcb13cb23d23661bAl Viro	return journal_blocks_per_page(inode);
12854613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12864613ad180d19082f99551477dcb13cb23d23661bAl Viro
12874613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_journal_force_commit(journal_t *journal)
12884613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12894613ad180d19082f99551477dcb13cb23d23661bAl Viro	return journal_force_commit(journal);
12904613ad180d19082f99551477dcb13cb23d23661bAl Viro}
12914613ad180d19082f99551477dcb13cb23d23661bAl Viro
12924613ad180d19082f99551477dcb13cb23d23661bAl Viro/* super.c */
12934613ad180d19082f99551477dcb13cb23d23661bAl Viroint ext3_force_commit(struct super_block *sb);
12944613ad180d19082f99551477dcb13cb23d23661bAl Viro
12954613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_should_journal_data(struct inode *inode)
12964613ad180d19082f99551477dcb13cb23d23661bAl Viro{
12974613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (!S_ISREG(inode->i_mode))
12984613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 1;
12994613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
13004613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 1;
13014613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
13024613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 1;
13034613ad180d19082f99551477dcb13cb23d23661bAl Viro	return 0;
13044613ad180d19082f99551477dcb13cb23d23661bAl Viro}
13054613ad180d19082f99551477dcb13cb23d23661bAl Viro
13064613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_should_order_data(struct inode *inode)
13074613ad180d19082f99551477dcb13cb23d23661bAl Viro{
13084613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (!S_ISREG(inode->i_mode))
13094613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 0;
13104613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
13114613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 0;
13124613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
13134613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 1;
13144613ad180d19082f99551477dcb13cb23d23661bAl Viro	return 0;
13154613ad180d19082f99551477dcb13cb23d23661bAl Viro}
13164613ad180d19082f99551477dcb13cb23d23661bAl Viro
13174613ad180d19082f99551477dcb13cb23d23661bAl Virostatic inline int ext3_should_writeback_data(struct inode *inode)
13184613ad180d19082f99551477dcb13cb23d23661bAl Viro{
13194613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (!S_ISREG(inode->i_mode))
13204613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 0;
13214613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
13224613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 0;
13234613ad180d19082f99551477dcb13cb23d23661bAl Viro	if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
13244613ad180d19082f99551477dcb13cb23d23661bAl Viro		return 1;
13254613ad180d19082f99551477dcb13cb23d23661bAl Viro	return 0;
13264613ad180d19082f99551477dcb13cb23d23661bAl Viro}
13271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13284613ad180d19082f99551477dcb13cb23d23661bAl Viro#include <trace/events/ext3.h>
1329