xref: /dragonfly/sys/vfs/ext2fs/ext2fs.h (revision cfe60390)
1*cfe60390STomohiro Kusumi /*-
2*cfe60390STomohiro Kusumi  *  modified for EXT2FS support in Lites 1.1
3*cfe60390STomohiro Kusumi  *
4*cfe60390STomohiro Kusumi  *  Aug 1995, Godmar Back (gback@cs.utah.edu)
5*cfe60390STomohiro Kusumi  *  University of Utah, Department of Computer Science
6*cfe60390STomohiro Kusumi  *
7*cfe60390STomohiro Kusumi  * $FreeBSD$
8*cfe60390STomohiro Kusumi  */
9*cfe60390STomohiro Kusumi /*-
10*cfe60390STomohiro Kusumi  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
11*cfe60390STomohiro Kusumi  *
12*cfe60390STomohiro Kusumi  * Copyright (c) 2009 Aditya Sarawgi
13*cfe60390STomohiro Kusumi  * All rights reserved.
14*cfe60390STomohiro Kusumi  *
15*cfe60390STomohiro Kusumi  * Redistribution and use in source and binary forms, with or without
16*cfe60390STomohiro Kusumi  * modification, are permitted provided that the following conditions
17*cfe60390STomohiro Kusumi  * are met:
18*cfe60390STomohiro Kusumi  * 1. Redistributions of source code must retain the above copyright
19*cfe60390STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer.
20*cfe60390STomohiro Kusumi  * 2. Redistributions in binary form must reproduce the above copyright
21*cfe60390STomohiro Kusumi  *    notice, this list of conditions and the following disclaimer in the
22*cfe60390STomohiro Kusumi  *    documentation and/or other materials provided with the distribution.
23*cfe60390STomohiro Kusumi  *
24*cfe60390STomohiro Kusumi  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25*cfe60390STomohiro Kusumi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*cfe60390STomohiro Kusumi  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*cfe60390STomohiro Kusumi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28*cfe60390STomohiro Kusumi  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*cfe60390STomohiro Kusumi  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*cfe60390STomohiro Kusumi  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*cfe60390STomohiro Kusumi  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*cfe60390STomohiro Kusumi  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*cfe60390STomohiro Kusumi  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*cfe60390STomohiro Kusumi  * SUCH DAMAGE.
35*cfe60390STomohiro Kusumi  *
36*cfe60390STomohiro Kusumi  *
37*cfe60390STomohiro Kusumi  */
38*cfe60390STomohiro Kusumi 
39*cfe60390STomohiro Kusumi #ifndef _FS_EXT2FS_EXT2FS_H_
40*cfe60390STomohiro Kusumi #define	_FS_EXT2FS_EXT2FS_H_
41*cfe60390STomohiro Kusumi 
42*cfe60390STomohiro Kusumi #include <sys/types.h>
43*cfe60390STomohiro Kusumi 
44*cfe60390STomohiro Kusumi /*
45*cfe60390STomohiro Kusumi  * Super block for an ext2fs file system.
46*cfe60390STomohiro Kusumi  */
47*cfe60390STomohiro Kusumi struct ext2fs {
48*cfe60390STomohiro Kusumi 	uint32_t  e2fs_icount;		/* Inode count */
49*cfe60390STomohiro Kusumi 	uint32_t  e2fs_bcount;		/* blocks count */
50*cfe60390STomohiro Kusumi 	uint32_t  e2fs_rbcount;		/* reserved blocks count */
51*cfe60390STomohiro Kusumi 	uint32_t  e2fs_fbcount;		/* free blocks count */
52*cfe60390STomohiro Kusumi 	uint32_t  e2fs_ficount;		/* free inodes count */
53*cfe60390STomohiro Kusumi 	uint32_t  e2fs_first_dblock;	/* first data block */
54*cfe60390STomohiro Kusumi 	uint32_t  e2fs_log_bsize;	/* block size = 1024*(2^e2fs_log_bsize) */
55*cfe60390STomohiro Kusumi 	uint32_t  e2fs_log_fsize;	/* fragment size */
56*cfe60390STomohiro Kusumi 	uint32_t  e2fs_bpg;		/* blocks per group */
57*cfe60390STomohiro Kusumi 	uint32_t  e2fs_fpg;		/* frags per group */
58*cfe60390STomohiro Kusumi 	uint32_t  e2fs_ipg;		/* inodes per group */
59*cfe60390STomohiro Kusumi 	uint32_t  e2fs_mtime;		/* mount time */
60*cfe60390STomohiro Kusumi 	uint32_t  e2fs_wtime;		/* write time */
61*cfe60390STomohiro Kusumi 	uint16_t  e2fs_mnt_count;	/* mount count */
62*cfe60390STomohiro Kusumi 	uint16_t  e2fs_max_mnt_count;	/* max mount count */
63*cfe60390STomohiro Kusumi 	uint16_t  e2fs_magic;		/* magic number */
64*cfe60390STomohiro Kusumi 	uint16_t  e2fs_state;		/* file system state */
65*cfe60390STomohiro Kusumi 	uint16_t  e2fs_beh;		/* behavior on errors */
66*cfe60390STomohiro Kusumi 	uint16_t  e2fs_minrev;		/* minor revision level */
67*cfe60390STomohiro Kusumi 	uint32_t  e2fs_lastfsck;	/* time of last fsck */
68*cfe60390STomohiro Kusumi 	uint32_t  e2fs_fsckintv;	/* max time between fscks */
69*cfe60390STomohiro Kusumi 	uint32_t  e2fs_creator;		/* creator OS */
70*cfe60390STomohiro Kusumi 	uint32_t  e2fs_rev;		/* revision level */
71*cfe60390STomohiro Kusumi 	uint16_t  e2fs_ruid;		/* default uid for reserved blocks */
72*cfe60390STomohiro Kusumi 	uint16_t  e2fs_rgid;		/* default gid for reserved blocks */
73*cfe60390STomohiro Kusumi 	/* EXT2_DYNAMIC_REV superblocks */
74*cfe60390STomohiro Kusumi 	uint32_t  e2fs_first_ino;	/* first non-reserved inode */
75*cfe60390STomohiro Kusumi 	uint16_t  e2fs_inode_size;	/* size of inode structure */
76*cfe60390STomohiro Kusumi 	uint16_t  e2fs_block_group_nr;	/* block grp number of this sblk*/
77*cfe60390STomohiro Kusumi 	uint32_t  e2fs_features_compat;	/* compatible feature set */
78*cfe60390STomohiro Kusumi 	uint32_t  e2fs_features_incompat; /* incompatible feature set */
79*cfe60390STomohiro Kusumi 	uint32_t  e2fs_features_rocompat; /* RO-compatible feature set */
80*cfe60390STomohiro Kusumi 	uint8_t	  e2fs_uuid[16];	/* 128-bit uuid for volume */
81*cfe60390STomohiro Kusumi 	char      e2fs_vname[16];	/* volume name */
82*cfe60390STomohiro Kusumi 	char      e2fs_fsmnt[64];	/* name mounted on */
83*cfe60390STomohiro Kusumi 	uint32_t  e2fs_algo;		/* For compression */
84*cfe60390STomohiro Kusumi 	uint8_t   e2fs_prealloc;	/* # of blocks for old prealloc */
85*cfe60390STomohiro Kusumi 	uint8_t   e2fs_dir_prealloc;	/* # of blocks for old prealloc dirs */
86*cfe60390STomohiro Kusumi 	uint16_t  e2fs_reserved_ngdb;	/* # of reserved gd blocks for resize */
87*cfe60390STomohiro Kusumi 	char      e3fs_journal_uuid[16]; /* uuid of journal superblock */
88*cfe60390STomohiro Kusumi 	uint32_t  e3fs_journal_inum;	/* inode number of journal file */
89*cfe60390STomohiro Kusumi 	uint32_t  e3fs_journal_dev;	/* device number of journal file */
90*cfe60390STomohiro Kusumi 	uint32_t  e3fs_last_orphan;	/* start of list of inodes to delete */
91*cfe60390STomohiro Kusumi 	uint32_t  e3fs_hash_seed[4];	/* HTREE hash seed */
92*cfe60390STomohiro Kusumi 	char      e3fs_def_hash_version;/* Default hash version to use */
93*cfe60390STomohiro Kusumi 	char      e3fs_jnl_backup_type;
94*cfe60390STomohiro Kusumi 	uint16_t  e3fs_desc_size;	/* size of group descriptor */
95*cfe60390STomohiro Kusumi 	uint32_t  e3fs_default_mount_opts;
96*cfe60390STomohiro Kusumi 	uint32_t  e3fs_first_meta_bg;	/* First metablock block group */
97*cfe60390STomohiro Kusumi 	uint32_t  e3fs_mkfs_time;	/* when the fs was created */
98*cfe60390STomohiro Kusumi 	uint32_t  e3fs_jnl_blks[17];	/* backup of the journal inode */
99*cfe60390STomohiro Kusumi 	uint32_t  e4fs_bcount_hi;	/* high bits of blocks count */
100*cfe60390STomohiro Kusumi 	uint32_t  e4fs_rbcount_hi;	/* high bits of reserved blocks count */
101*cfe60390STomohiro Kusumi 	uint32_t  e4fs_fbcount_hi;	/* high bits of free blocks count */
102*cfe60390STomohiro Kusumi 	uint16_t  e4fs_min_extra_isize; /* all inodes have some bytes */
103*cfe60390STomohiro Kusumi 	uint16_t  e4fs_want_extra_isize;/* inodes must reserve some bytes */
104*cfe60390STomohiro Kusumi 	uint32_t  e4fs_flags;		/* miscellaneous flags */
105*cfe60390STomohiro Kusumi 	uint16_t  e4fs_raid_stride;	/* RAID stride */
106*cfe60390STomohiro Kusumi 	uint16_t  e4fs_mmpintv;		/* seconds to wait in MMP checking */
107*cfe60390STomohiro Kusumi 	uint64_t  e4fs_mmpblk;		/* block for multi-mount protection */
108*cfe60390STomohiro Kusumi 	uint32_t  e4fs_raid_stripe_wid; /* blocks on data disks (N * stride) */
109*cfe60390STomohiro Kusumi 	uint8_t   e4fs_log_gpf;		/* FLEX_BG group size */
110*cfe60390STomohiro Kusumi 	uint8_t   e4fs_chksum_type;	/* metadata checksum algorithm used */
111*cfe60390STomohiro Kusumi 	uint8_t   e4fs_encrypt;		/* versioning level for encryption */
112*cfe60390STomohiro Kusumi 	uint8_t   e4fs_reserved_pad;
113*cfe60390STomohiro Kusumi 	uint64_t  e4fs_kbytes_written;	/* number of lifetime kilobytes */
114*cfe60390STomohiro Kusumi 	uint32_t  e4fs_snapinum;	/* inode number of active snapshot */
115*cfe60390STomohiro Kusumi 	uint32_t  e4fs_snapid;		/* sequential ID of active snapshot */
116*cfe60390STomohiro Kusumi 	uint64_t  e4fs_snaprbcount;	/* reserved blocks for active snapshot */
117*cfe60390STomohiro Kusumi 	uint32_t  e4fs_snaplist;	/* inode number for on-disk snapshot */
118*cfe60390STomohiro Kusumi 	uint32_t  e4fs_errcount;	/* number of file system errors */
119*cfe60390STomohiro Kusumi 	uint32_t  e4fs_first_errtime;	/* first time an error happened */
120*cfe60390STomohiro Kusumi 	uint32_t  e4fs_first_errino;	/* inode involved in first error */
121*cfe60390STomohiro Kusumi 	uint64_t  e4fs_first_errblk;	/* block involved of first error */
122*cfe60390STomohiro Kusumi 	uint8_t   e4fs_first_errfunc[32];/* function where error happened */
123*cfe60390STomohiro Kusumi 	uint32_t  e4fs_first_errline;	/* line number where error happened */
124*cfe60390STomohiro Kusumi 	uint32_t  e4fs_last_errtime;	/* most recent time of an error */
125*cfe60390STomohiro Kusumi 	uint32_t  e4fs_last_errino;	/* inode involved in last error */
126*cfe60390STomohiro Kusumi 	uint32_t  e4fs_last_errline;	/* line number where error happened */
127*cfe60390STomohiro Kusumi 	uint64_t  e4fs_last_errblk;	/* block involved of last error */
128*cfe60390STomohiro Kusumi 	uint8_t   e4fs_last_errfunc[32]; /* function where error happened */
129*cfe60390STomohiro Kusumi 	uint8_t   e4fs_mount_opts[64];
130*cfe60390STomohiro Kusumi 	uint32_t  e4fs_usrquota_inum;	/* inode for tracking user quota */
131*cfe60390STomohiro Kusumi 	uint32_t  e4fs_grpquota_inum;	/* inode for tracking group quota */
132*cfe60390STomohiro Kusumi 	uint32_t  e4fs_overhead_clusters;/* overhead blocks/clusters */
133*cfe60390STomohiro Kusumi 	uint32_t  e4fs_backup_bgs[2];	/* groups with sparse_super2 SBs */
134*cfe60390STomohiro Kusumi 	uint8_t   e4fs_encrypt_algos[4];/* encryption algorithms in use */
135*cfe60390STomohiro Kusumi 	uint8_t   e4fs_encrypt_pw_salt[16];/* salt used for string2key */
136*cfe60390STomohiro Kusumi 	uint32_t  e4fs_lpf_ino;		/* location of the lost+found inode */
137*cfe60390STomohiro Kusumi 	uint32_t  e4fs_proj_quota_inum;	/* inode for tracking project quota */
138*cfe60390STomohiro Kusumi 	uint32_t  e4fs_chksum_seed;	/* checksum seed */
139*cfe60390STomohiro Kusumi 	uint32_t  e4fs_reserved[98];	/* padding to the end of the block */
140*cfe60390STomohiro Kusumi 	uint32_t  e4fs_sbchksum;	/* superblock checksum */
141*cfe60390STomohiro Kusumi };
142*cfe60390STomohiro Kusumi 
143*cfe60390STomohiro Kusumi /*
144*cfe60390STomohiro Kusumi  * The path name on which the file system is mounted is maintained
145*cfe60390STomohiro Kusumi  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
146*cfe60390STomohiro Kusumi  * the super block for this name.
147*cfe60390STomohiro Kusumi  */
148*cfe60390STomohiro Kusumi #define	MAXMNTLEN 512
149*cfe60390STomohiro Kusumi 
150*cfe60390STomohiro Kusumi /*
151*cfe60390STomohiro Kusumi  * In-Memory Superblock
152*cfe60390STomohiro Kusumi  */
153*cfe60390STomohiro Kusumi 
154*cfe60390STomohiro Kusumi struct m_ext2fs {
155*cfe60390STomohiro Kusumi 	struct ext2fs * e2fs;
156*cfe60390STomohiro Kusumi 	char     e2fs_fsmnt[MAXMNTLEN];/* name mounted on */
157*cfe60390STomohiro Kusumi 	char     e2fs_ronly;	  /* mounted read-only flag */
158*cfe60390STomohiro Kusumi 	char     e2fs_fmod;	  /* super block modified flag */
159*cfe60390STomohiro Kusumi 	uint64_t e2fs_bcount;	  /* blocks count */
160*cfe60390STomohiro Kusumi 	uint64_t e2fs_rbcount;	  /* reserved blocks count */
161*cfe60390STomohiro Kusumi 	uint64_t e2fs_fbcount;	  /* free blocks count */
162*cfe60390STomohiro Kusumi 	uint32_t e2fs_ficount;	  /* free inodes count */
163*cfe60390STomohiro Kusumi 	uint32_t e2fs_bsize;	  /* Block size */
164*cfe60390STomohiro Kusumi 	uint32_t e2fs_bshift;	  /* calc of logical block no */
165*cfe60390STomohiro Kusumi 	uint32_t e2fs_bpg;	  /* Number of blocks per group */
166*cfe60390STomohiro Kusumi 	int64_t  e2fs_qbmask;	  /* = s_blocksize -1 */
167*cfe60390STomohiro Kusumi 	uint32_t e2fs_fsbtodb;	  /* Shift to get disk block */
168*cfe60390STomohiro Kusumi 	uint32_t e2fs_ipg;	  /* Number of inodes per group */
169*cfe60390STomohiro Kusumi 	uint32_t e2fs_ipb;	  /* Number of inodes per block */
170*cfe60390STomohiro Kusumi 	uint32_t e2fs_itpg;	  /* Number of inode table per group */
171*cfe60390STomohiro Kusumi 	uint32_t e2fs_fsize;	  /* Size of fragments per block */
172*cfe60390STomohiro Kusumi 	uint32_t e2fs_fpb;	  /* Number of fragments per block */
173*cfe60390STomohiro Kusumi 	uint32_t e2fs_fpg;	  /* Number of fragments per group */
174*cfe60390STomohiro Kusumi 	uint32_t e2fs_gdbcount;	  /* Number of group descriptors */
175*cfe60390STomohiro Kusumi 	uint32_t e2fs_gcount;	  /* Number of groups */
176*cfe60390STomohiro Kusumi 	uint32_t e2fs_isize;	  /* Size of inode */
177*cfe60390STomohiro Kusumi 	uint32_t e2fs_total_dir;  /* Total number of directories */
178*cfe60390STomohiro Kusumi 	uint8_t	*e2fs_contigdirs; /* (u) # of contig. allocated dirs */
179*cfe60390STomohiro Kusumi 	char     e2fs_wasvalid;	  /* valid at mount time */
180*cfe60390STomohiro Kusumi 	off_t    e2fs_maxfilesize;
181*cfe60390STomohiro Kusumi 	struct   ext2_gd *e2fs_gd; /* Group Descriptors */
182*cfe60390STomohiro Kusumi 	int32_t  e2fs_contigsumsize;    /* size of cluster summary array */
183*cfe60390STomohiro Kusumi 	int32_t *e2fs_maxcluster;       /* max cluster in each cyl group */
184*cfe60390STomohiro Kusumi 	struct   csum *e2fs_clustersum; /* cluster summary in each cyl group */
185*cfe60390STomohiro Kusumi 	int32_t  e2fs_uhash;	  /* 3 if hash should be signed, 0 if not */
186*cfe60390STomohiro Kusumi 	uint32_t e2fs_csum_seed;  /* sb checksum seed */
187*cfe60390STomohiro Kusumi };
188*cfe60390STomohiro Kusumi 
189*cfe60390STomohiro Kusumi /* cluster summary information */
190*cfe60390STomohiro Kusumi 
191*cfe60390STomohiro Kusumi struct csum {
192*cfe60390STomohiro Kusumi 	int8_t   cs_init; /* cluster summary has been initialized */
193*cfe60390STomohiro Kusumi 	int32_t *cs_sum;  /* cluster summary array */
194*cfe60390STomohiro Kusumi };
195*cfe60390STomohiro Kusumi 
196*cfe60390STomohiro Kusumi /*
197*cfe60390STomohiro Kusumi  * The second extended file system magic number
198*cfe60390STomohiro Kusumi  */
199*cfe60390STomohiro Kusumi #define	E2FS_MAGIC		0xEF53
200*cfe60390STomohiro Kusumi 
201*cfe60390STomohiro Kusumi /*
202*cfe60390STomohiro Kusumi  * Revision levels
203*cfe60390STomohiro Kusumi  */
204*cfe60390STomohiro Kusumi #define	E2FS_REV0		0	/* The good old (original) format */
205*cfe60390STomohiro Kusumi #define	E2FS_REV1		1	/* V2 format w/ dynamic inode sizes */
206*cfe60390STomohiro Kusumi 
207*cfe60390STomohiro Kusumi #define	E2FS_REV0_INODE_SIZE 128
208*cfe60390STomohiro Kusumi 
209*cfe60390STomohiro Kusumi /*
210*cfe60390STomohiro Kusumi  * Metadata checksum algorithm codes
211*cfe60390STomohiro Kusumi  */
212*cfe60390STomohiro Kusumi #define EXT4_CRC32C_CHKSUM		1
213*cfe60390STomohiro Kusumi 
214*cfe60390STomohiro Kusumi /*
215*cfe60390STomohiro Kusumi  * compatible/incompatible features
216*cfe60390STomohiro Kusumi  */
217*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_PREALLOC		0x0001
218*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_IMAGIC_INODES	0x0002
219*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_HASJOURNAL		0x0004
220*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_EXT_ATTR		0x0008
221*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_RESIZE		0x0010
222*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_DIRHASHINDEX	0x0020
223*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_LAZY_BG		0x0040
224*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_EXCLUDE_BITMAP	0x0100
225*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_SPARSESUPER2	0x0200
226*cfe60390STomohiro Kusumi 
227*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_SPARSESUPER	0x0001
228*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_LARGEFILE	0x0002
229*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_BTREE_DIR	0x0004
230*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_HUGE_FILE	0x0008
231*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_GDT_CSUM		0x0010
232*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_DIR_NLINK	0x0020
233*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_EXTRA_ISIZE	0x0040
234*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_HAS_SNAPSHOT	0x0080
235*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_QUOTA		0x0100
236*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_BIGALLOC		0x0200
237*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_METADATA_CKSUM	0x0400
238*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_REPLICA		0x0800
239*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_READONLY		0x1000
240*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_PROJECT		0x2000
241*cfe60390STomohiro Kusumi 
242*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_COMP		0x0001
243*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_FTYPE		0x0002
244*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_RECOVER		0x0004
245*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_JOURNAL_DEV	0x0008
246*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_META_BG		0x0010
247*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_EXTENTS		0x0040
248*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_64BIT		0x0080
249*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_MMP		0x0100
250*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_FLEX_BG		0x0200
251*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_EA_INODE		0x0400
252*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_DIRDATA		0x1000
253*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_CSUM_SEED	0x2000
254*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_LARGEDIR		0x4000
255*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_INLINE_DATA	0x8000
256*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_ENCRYPT		0x10000
257*cfe60390STomohiro Kusumi 
258*cfe60390STomohiro Kusumi struct ext2_feature
259*cfe60390STomohiro Kusumi {
260*cfe60390STomohiro Kusumi 	int mask;
261*cfe60390STomohiro Kusumi 	const char *name;
262*cfe60390STomohiro Kusumi };
263*cfe60390STomohiro Kusumi 
264*cfe60390STomohiro Kusumi static const struct ext2_feature compat[] = {
265*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_PREALLOC,       "dir_prealloc"    },
266*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_IMAGIC_INODES,  "imagic_inodes"   },
267*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_HASJOURNAL,     "has_journal"     },
268*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_EXT_ATTR,       "ext_attr"        },
269*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_RESIZE,         "resize_inode"    },
270*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_DIRHASHINDEX,   "dir_index"       },
271*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_EXCLUDE_BITMAP, "snapshot_bitmap" },
272*cfe60390STomohiro Kusumi 	{ EXT2F_COMPAT_SPARSESUPER2,   "sparse_super2"   }
273*cfe60390STomohiro Kusumi };
274*cfe60390STomohiro Kusumi 
275*cfe60390STomohiro Kusumi static const struct ext2_feature ro_compat[] = {
276*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_SPARSESUPER,    "sparse_super"  },
277*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_LARGEFILE,      "large_file"    },
278*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_BTREE_DIR,      "btree_dir"     },
279*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_HUGE_FILE,      "huge_file"     },
280*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_GDT_CSUM,       "uninit_groups" },
281*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_DIR_NLINK,      "dir_nlink"     },
282*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_EXTRA_ISIZE,    "extra_isize"   },
283*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_HAS_SNAPSHOT,   "snapshot"      },
284*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_QUOTA,          "quota"         },
285*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_BIGALLOC,       "bigalloc"      },
286*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_METADATA_CKSUM, "metadata_csum" },
287*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_REPLICA,        "replica"       },
288*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_READONLY,       "ro"            },
289*cfe60390STomohiro Kusumi 	{ EXT2F_ROCOMPAT_PROJECT,        "project"       }
290*cfe60390STomohiro Kusumi };
291*cfe60390STomohiro Kusumi 
292*cfe60390STomohiro Kusumi static const struct ext2_feature incompat[] = {
293*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_COMP,        "compression"        },
294*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_FTYPE,       "filetype"           },
295*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_RECOVER,     "needs_recovery"     },
296*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_JOURNAL_DEV, "journal_dev"        },
297*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_META_BG,     "meta_bg"            },
298*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_EXTENTS,     "extents"            },
299*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_64BIT,       "64bit"              },
300*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_MMP,         "mmp"                },
301*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_FLEX_BG,     "flex_bg"            },
302*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_EA_INODE,    "ea_inode"           },
303*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_DIRDATA,     "dirdata"            },
304*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_CSUM_SEED,   "metadata_csum_seed" },
305*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_LARGEDIR,    "large_dir"          },
306*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_INLINE_DATA, "inline_data"        },
307*cfe60390STomohiro Kusumi 	{ EXT2F_INCOMPAT_ENCRYPT,     "encrypt"            }
308*cfe60390STomohiro Kusumi };
309*cfe60390STomohiro Kusumi 
310*cfe60390STomohiro Kusumi /*
311*cfe60390STomohiro Kusumi  * Features supported in this implementation
312*cfe60390STomohiro Kusumi  *
313*cfe60390STomohiro Kusumi  * We support the following REV1 features:
314*cfe60390STomohiro Kusumi  * - EXT2F_ROCOMPAT_SPARSESUPER
315*cfe60390STomohiro Kusumi  * - EXT2F_ROCOMPAT_LARGEFILE
316*cfe60390STomohiro Kusumi  * - EXT2F_ROCOMPAT_EXTRA_ISIZE
317*cfe60390STomohiro Kusumi  * - EXT2F_INCOMPAT_FTYPE
318*cfe60390STomohiro Kusumi  *
319*cfe60390STomohiro Kusumi  * We partially (read-only) support the following EXT4 features:
320*cfe60390STomohiro Kusumi  * - EXT2F_ROCOMPAT_HUGE_FILE
321*cfe60390STomohiro Kusumi  * - EXT2F_INCOMPAT_EXTENTS
322*cfe60390STomohiro Kusumi  *
323*cfe60390STomohiro Kusumi  */
324*cfe60390STomohiro Kusumi #define	EXT2F_COMPAT_SUPP		EXT2F_COMPAT_DIRHASHINDEX
325*cfe60390STomohiro Kusumi #define	EXT2F_ROCOMPAT_SUPP		(EXT2F_ROCOMPAT_SPARSESUPER | \
326*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_LARGEFILE | \
327*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_GDT_CSUM | \
328*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_METADATA_CKSUM | \
329*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_DIR_NLINK | \
330*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_HUGE_FILE | \
331*cfe60390STomohiro Kusumi 					 EXT2F_ROCOMPAT_EXTRA_ISIZE)
332*cfe60390STomohiro Kusumi #define	EXT2F_INCOMPAT_SUPP		(EXT2F_INCOMPAT_FTYPE | \
333*cfe60390STomohiro Kusumi 					 EXT2F_INCOMPAT_META_BG | \
334*cfe60390STomohiro Kusumi 					 EXT2F_INCOMPAT_EXTENTS | \
335*cfe60390STomohiro Kusumi 					 EXT2F_INCOMPAT_64BIT | \
336*cfe60390STomohiro Kusumi 					 EXT2F_INCOMPAT_FLEX_BG | \
337*cfe60390STomohiro Kusumi 					 EXT2F_INCOMPAT_CSUM_SEED)
338*cfe60390STomohiro Kusumi 
339*cfe60390STomohiro Kusumi /* Assume that user mode programs are passing in an ext2fs superblock, not
340*cfe60390STomohiro Kusumi  * a kernel struct super_block.  This will allow us to call the feature-test
341*cfe60390STomohiro Kusumi  * macros from user land. */
342*cfe60390STomohiro Kusumi #define	EXT2_SB(sb)	(sb)
343*cfe60390STomohiro Kusumi 
344*cfe60390STomohiro Kusumi /*
345*cfe60390STomohiro Kusumi  * Feature set definitions
346*cfe60390STomohiro Kusumi  */
347*cfe60390STomohiro Kusumi #define	EXT2_HAS_COMPAT_FEATURE(sb,mask)			\
348*cfe60390STomohiro Kusumi 	( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_compat) & mask)
349*cfe60390STomohiro Kusumi #define	EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)			\
350*cfe60390STomohiro Kusumi 	( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_rocompat) & mask)
351*cfe60390STomohiro Kusumi #define	EXT2_HAS_INCOMPAT_FEATURE(sb,mask)			\
352*cfe60390STomohiro Kusumi 	( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_incompat) & mask)
353*cfe60390STomohiro Kusumi 
354*cfe60390STomohiro Kusumi /*
355*cfe60390STomohiro Kusumi  * File clean flags
356*cfe60390STomohiro Kusumi  */
357*cfe60390STomohiro Kusumi #define	E2FS_ISCLEAN			0x0001	/* Unmounted cleanly */
358*cfe60390STomohiro Kusumi #define	E2FS_ERRORS			0x0002	/* Errors detected */
359*cfe60390STomohiro Kusumi 
360*cfe60390STomohiro Kusumi /*
361*cfe60390STomohiro Kusumi  * Filesystem miscellaneous flags
362*cfe60390STomohiro Kusumi  */
363*cfe60390STomohiro Kusumi #define	E2FS_SIGNED_HASH	0x0001
364*cfe60390STomohiro Kusumi #define	E2FS_UNSIGNED_HASH	0x0002
365*cfe60390STomohiro Kusumi 
366*cfe60390STomohiro Kusumi #define	EXT2_BG_INODE_UNINIT	0x0001	/* Inode table/bitmap not in use */
367*cfe60390STomohiro Kusumi #define	EXT2_BG_BLOCK_UNINIT	0x0002	/* Block bitmap not in use */
368*cfe60390STomohiro Kusumi #define	EXT2_BG_INODE_ZEROED	0x0004	/* On-disk itable initialized to zero */
369*cfe60390STomohiro Kusumi 
370*cfe60390STomohiro Kusumi /* ext2 file system block group descriptor */
371*cfe60390STomohiro Kusumi 
372*cfe60390STomohiro Kusumi struct ext2_gd {
373*cfe60390STomohiro Kusumi 	uint32_t ext2bgd_b_bitmap;	/* blocks bitmap block */
374*cfe60390STomohiro Kusumi 	uint32_t ext2bgd_i_bitmap;	/* inodes bitmap block */
375*cfe60390STomohiro Kusumi 	uint32_t ext2bgd_i_tables;	/* inodes table block  */
376*cfe60390STomohiro Kusumi 	uint16_t ext2bgd_nbfree;	/* number of free blocks */
377*cfe60390STomohiro Kusumi 	uint16_t ext2bgd_nifree;	/* number of free inodes */
378*cfe60390STomohiro Kusumi 	uint16_t ext2bgd_ndirs;		/* number of directories */
379*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_flags;		/* block group flags */
380*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_x_bitmap;	/* snapshot exclusion bitmap loc. */
381*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_b_bmap_csum;	/* block bitmap checksum */
382*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_i_bmap_csum;	/* inode bitmap checksum */
383*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_i_unused;	/* unused inode count */
384*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_csum;		/* group descriptor checksum */
385*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_b_bitmap_hi;	/* high bits of blocks bitmap block */
386*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_i_bitmap_hi;	/* high bits of inodes bitmap block */
387*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_i_tables_hi;	/* high bits of inodes table block */
388*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_nbfree_hi;	/* high bits of number of free blocks */
389*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_nifree_hi;	/* high bits of number of free inodes */
390*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_ndirs_hi;	/* high bits of number of directories */
391*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_i_unused_hi;	/* high bits of unused inode count */
392*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_x_bitmap_hi;   /* high bits of snapshot exclusion */
393*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_b_bmap_csum_hi;/* high bits of block bitmap checksum */
394*cfe60390STomohiro Kusumi 	uint16_t ext4bgd_i_bmap_csum_hi;/* high bits of inode bitmap checksum */
395*cfe60390STomohiro Kusumi 	uint32_t ext4bgd_reserved;
396*cfe60390STomohiro Kusumi };
397*cfe60390STomohiro Kusumi 
398*cfe60390STomohiro Kusumi #define	E2FS_REV0_GD_SIZE (sizeof(struct ext2_gd) / 2)
399*cfe60390STomohiro Kusumi #define	E2FS_64BIT_GD_SIZE (sizeof(struct ext2_gd))
400*cfe60390STomohiro Kusumi 
401*cfe60390STomohiro Kusumi /*
402*cfe60390STomohiro Kusumi  * Macro-instructions used to manage several block sizes
403*cfe60390STomohiro Kusumi  */
404*cfe60390STomohiro Kusumi #define	EXT2_MIN_BLOCK_LOG_SIZE		  10
405*cfe60390STomohiro Kusumi #define	EXT2_BLOCK_SIZE(s)		((s)->e2fs_bsize)
406*cfe60390STomohiro Kusumi #define	EXT2_ADDR_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof(uint32_t))
407*cfe60390STomohiro Kusumi #define	EXT2_INODE_SIZE(s)		(EXT2_SB(s)->e2fs_isize)
408*cfe60390STomohiro Kusumi 
409*cfe60390STomohiro Kusumi /*
410*cfe60390STomohiro Kusumi  * Macro-instructions used to manage fragments
411*cfe60390STomohiro Kusumi  */
412*cfe60390STomohiro Kusumi #define	EXT2_MIN_FRAG_SIZE		1024
413*cfe60390STomohiro Kusumi #define	EXT2_MIN_FRAG_LOG_SIZE		10
414*cfe60390STomohiro Kusumi #define	EXT2_MAX_FRAG_LOG_SIZE		30
415*cfe60390STomohiro Kusumi #define	EXT2_FRAG_SIZE(s)		(EXT2_SB(s)->e2fs_fsize)
416*cfe60390STomohiro Kusumi #define	EXT2_FRAGS_PER_BLOCK(s)		(EXT2_SB(s)->e2fs_fpb)
417*cfe60390STomohiro Kusumi 
418*cfe60390STomohiro Kusumi /*
419*cfe60390STomohiro Kusumi  * Macro-instructions used to manage group descriptors
420*cfe60390STomohiro Kusumi  */
421*cfe60390STomohiro Kusumi #define	EXT2_BLOCKS_PER_GROUP(s)	(EXT2_SB(s)->e2fs_bpg)
422*cfe60390STomohiro Kusumi #define	EXT2_DESCS_PER_BLOCK(s)		(EXT2_HAS_INCOMPAT_FEATURE((s),  \
423*cfe60390STomohiro Kusumi     EXT2F_INCOMPAT_64BIT) ? ((s)->e2fs_bsize / sizeof(struct ext2_gd)) : \
424*cfe60390STomohiro Kusumi     ((s)->e2fs_bsize / E2FS_REV0_GD_SIZE))
425*cfe60390STomohiro Kusumi 
426*cfe60390STomohiro Kusumi /*
427*cfe60390STomohiro Kusumi  * Macro-instructions used to manage inodes
428*cfe60390STomohiro Kusumi  */
429*cfe60390STomohiro Kusumi #define	EXT2_FIRST_INO(s)	(le32toh((EXT2_SB(s)->e2fs->e2fs_rev) == \
430*cfe60390STomohiro Kusumi     E2FS_REV0) ? EXT2_FIRSTINO : le32toh(EXT2_SB(s)->e2fs->e2fs_first_ino))
431*cfe60390STomohiro Kusumi 
432*cfe60390STomohiro Kusumi /*
433*cfe60390STomohiro Kusumi  * FreeBSD compat macros
434*cfe60390STomohiro Kusumi  */
435*cfe60390STomohiro Kusumi #define SDT_PROVIDER_DEFINE(a)
436*cfe60390STomohiro Kusumi #define SDT_PROVIDER_DECLARE(a)
437*cfe60390STomohiro Kusumi #define SDT_PROBE_DEFINE1(a, b, c, d, e)
438*cfe60390STomohiro Kusumi #define SDT_PROBE_DEFINE2(a, b, c, d, e, f)
439*cfe60390STomohiro Kusumi #define SDT_PROBE_DEFINE3(a, b, c, d, e, f, g)
440*cfe60390STomohiro Kusumi #define SDT_PROBE_DEFINE4(a, b, c, d, e, f, g, h)
441*cfe60390STomohiro Kusumi #define SDT_PROBE_DEFINE5(a, b, c, d, e, f, g, h, i)
442*cfe60390STomohiro Kusumi #define SDT_PROBE1(a, b, c, d, e)
443*cfe60390STomohiro Kusumi #define SDT_PROBE2(a, b, c, d, e, f)
444*cfe60390STomohiro Kusumi #define SDT_PROBE3(a, b, c, d, e, f, g)
445*cfe60390STomohiro Kusumi #define SDT_PROBE4(a, b, c, d, e, f, g, h)
446*cfe60390STomohiro Kusumi #define SDT_PROBE5(a, b, c, d, e, f, g, h, i)
447*cfe60390STomohiro Kusumi 
448*cfe60390STomohiro Kusumi #define printf				kprintf
449*cfe60390STomohiro Kusumi #define malloc				kmalloc
450*cfe60390STomohiro Kusumi #define free(addr, type)		ext2_free(addr, type, __func__)
451*cfe60390STomohiro Kusumi 
452*cfe60390STomohiro Kusumi #define ASSERT_VOP_ELOCKED(vp, str)	KASSERT(vn_islocked(vp), (str))
453*cfe60390STomohiro Kusumi #define ASSERT_VOP_LOCKED(vp, str)	KASSERT(vn_islocked(vp), (str))
454*cfe60390STomohiro Kusumi #define mtx_assert(mtx, x)		KKASSERT(mtx_islocked(mtx))
455*cfe60390STomohiro Kusumi 
456*cfe60390STomohiro Kusumi #define DOINGASYNC(vp)			((vp)->v_mount->mnt_flag & MNT_ASYNC)
457*cfe60390STomohiro Kusumi 
458*cfe60390STomohiro Kusumi #endif	/* !_FS_EXT2FS_EXT2FS_H_ */
459