ext2fs.h revision 1.53 1 1.53 rillig /* $NetBSD: ext2fs.h,v 1.53 2025/05/04 20:26:56 rillig Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 1982, 1986, 1993
5 1.1 bouyer * The Regents of the University of California. All rights reserved.
6 1.13 agc *
7 1.13 agc * Redistribution and use in source and binary forms, with or without
8 1.13 agc * modification, are permitted provided that the following conditions
9 1.13 agc * are met:
10 1.13 agc * 1. Redistributions of source code must retain the above copyright
11 1.13 agc * notice, this list of conditions and the following disclaimer.
12 1.13 agc * 2. Redistributions in binary form must reproduce the above copyright
13 1.13 agc * notice, this list of conditions and the following disclaimer in the
14 1.13 agc * documentation and/or other materials provided with the distribution.
15 1.13 agc * 3. Neither the name of the University nor the names of its contributors
16 1.13 agc * may be used to endorse or promote products derived from this software
17 1.13 agc * without specific prior written permission.
18 1.13 agc *
19 1.13 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.13 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.13 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.13 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.13 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.13 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.13 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.13 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.13 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.13 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.13 agc * SUCH DAMAGE.
30 1.13 agc *
31 1.13 agc * @(#)fs.h 8.10 (Berkeley) 10/27/94
32 1.13 agc * Modified for ext2fs by Manuel Bouyer.
33 1.13 agc */
34 1.13 agc
35 1.13 agc /*
36 1.13 agc * Copyright (c) 1997 Manuel Bouyer.
37 1.1 bouyer *
38 1.1 bouyer * Redistribution and use in source and binary forms, with or without
39 1.1 bouyer * modification, are permitted provided that the following conditions
40 1.1 bouyer * are met:
41 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
42 1.1 bouyer * notice, this list of conditions and the following disclaimer.
43 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
45 1.1 bouyer * documentation and/or other materials provided with the distribution.
46 1.1 bouyer *
47 1.15 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.15 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.15 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.15 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.15 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.15 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.15 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.15 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.15 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.15 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.1 bouyer *
58 1.1 bouyer * @(#)fs.h 8.10 (Berkeley) 10/27/94
59 1.1 bouyer * Modified for ext2fs by Manuel Bouyer.
60 1.1 bouyer */
61 1.5 bouyer
62 1.11 matt #ifndef _UFS_EXT2FS_EXT2FS_H_
63 1.11 matt #define _UFS_EXT2FS_EXT2FS_H_
64 1.11 matt
65 1.21 dsl #include <sys/bswap.h>
66 1.1 bouyer
67 1.1 bouyer /*
68 1.1 bouyer * Each disk drive contains some number of file systems.
69 1.1 bouyer * A file system consists of a number of cylinder groups.
70 1.1 bouyer * Each cylinder group has inodes and data.
71 1.1 bouyer *
72 1.1 bouyer * A file system is described by its super-block, which in turn
73 1.1 bouyer * describes the cylinder groups. The super-block is critical
74 1.1 bouyer * data and is replicated in each cylinder group to protect against
75 1.1 bouyer * catastrophic loss. This is done at `newfs' time and the critical
76 1.1 bouyer * super-block data does not change, so the copies need not be
77 1.1 bouyer * referenced further unless disaster strikes.
78 1.1 bouyer *
79 1.1 bouyer * The first boot and super blocks are given in absolute disk addresses.
80 1.1 bouyer * The byte-offset forms are preferred, as they don't imply a sector size.
81 1.1 bouyer */
82 1.1 bouyer #define BBSIZE 1024
83 1.1 bouyer #define SBSIZE 1024
84 1.1 bouyer #define BBOFF ((off_t)(0))
85 1.1 bouyer #define SBOFF ((off_t)(BBOFF + BBSIZE))
86 1.12 fvdl #define BBLOCK ((daddr_t)(0))
87 1.12 fvdl #define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
88 1.1 bouyer
89 1.37 christos #define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->e2fs_fsbtodb)
90 1.37 christos /* calculates (loc / fs->fs_bsize) */
91 1.37 christos #define lblkno(fs, loc) ((loc) >> (fs->e2fs_bshift))
92 1.37 christos #define blksize(fs, ip, lbn) ((fs)->e2fs_bsize)
93 1.37 christos
94 1.1 bouyer /*
95 1.1 bouyer * Addresses stored in inodes are capable of addressing blocks
96 1.1 bouyer * XXX
97 1.1 bouyer */
98 1.1 bouyer
99 1.1 bouyer /*
100 1.1 bouyer * MINBSIZE is the smallest allowable block size.
101 1.1 bouyer * MINBSIZE must be big enough to hold a cylinder group block,
102 1.1 bouyer * thus changes to (struct cg) must keep its size within MINBSIZE.
103 1.1 bouyer * Note that super blocks are always of size SBSIZE,
104 1.1 bouyer * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
105 1.1 bouyer */
106 1.25 tsutsui #define LOG_MINBSIZE 10
107 1.1 bouyer #define MINBSIZE (1 << LOG_MINBSIZE)
108 1.1 bouyer
109 1.1 bouyer /*
110 1.1 bouyer * The path name on which the file system is mounted is maintained
111 1.1 bouyer * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
112 1.1 bouyer * the super block for this name.
113 1.1 bouyer */
114 1.1 bouyer #define MAXMNTLEN 512
115 1.1 bouyer
116 1.1 bouyer /*
117 1.1 bouyer * MINFREE gives the minimum acceptable percentage of file system
118 1.1 bouyer * blocks which may be free. If the freelist drops below this level
119 1.1 bouyer * only the superuser may continue to allocate blocks. This may
120 1.1 bouyer * be set to 0 if no reserve of free blocks is deemed necessary,
121 1.1 bouyer * however throughput drops by fifty percent if the file system
122 1.1 bouyer * is run at between 95% and 100% full; thus the minimum default
123 1.1 bouyer * value of fs_minfree is 5%. However, to get good clustering
124 1.1 bouyer * performance, 10% is a better choice. hence we use 10% as our
125 1.1 bouyer * default value. With 10% free space, fragmentation is not a
126 1.1 bouyer * problem, so we choose to optimize for time.
127 1.1 bouyer */
128 1.1 bouyer #define MINFREE 5
129 1.1 bouyer
130 1.1 bouyer /*
131 1.46 jdolecek * This is maximum amount of links allowed for files. For directories,
132 1.46 jdolecek * going over this means setting DIR_NLINK feature.
133 1.46 jdolecek */
134 1.46 jdolecek #define EXT2FS_LINK_MAX 65000
135 1.46 jdolecek #define EXT2FS_LINK_INF 1 /* link count unknown */
136 1.46 jdolecek
137 1.46 jdolecek /*
138 1.1 bouyer * Super block for an ext2fs file system.
139 1.1 bouyer */
140 1.1 bouyer struct ext2fs {
141 1.27 tsutsui uint32_t e2fs_icount; /* Inode count */
142 1.27 tsutsui uint32_t e2fs_bcount; /* blocks count */
143 1.27 tsutsui uint32_t e2fs_rbcount; /* reserved blocks count */
144 1.27 tsutsui uint32_t e2fs_fbcount; /* free blocks count */
145 1.27 tsutsui uint32_t e2fs_ficount; /* free inodes count */
146 1.27 tsutsui uint32_t e2fs_first_dblock; /* first data block */
147 1.37 christos uint32_t e2fs_log_bsize; /* bsize = 1024*(2^e2fs_log_bsize) */
148 1.27 tsutsui uint32_t e2fs_fsize; /* fragment size */
149 1.27 tsutsui uint32_t e2fs_bpg; /* blocks per group */
150 1.27 tsutsui uint32_t e2fs_fpg; /* frags per group */
151 1.27 tsutsui uint32_t e2fs_ipg; /* inodes per group */
152 1.27 tsutsui uint32_t e2fs_mtime; /* mount time */
153 1.27 tsutsui uint32_t e2fs_wtime; /* write time */
154 1.27 tsutsui uint16_t e2fs_mnt_count; /* mount count */
155 1.27 tsutsui uint16_t e2fs_max_mnt_count; /* max mount count */
156 1.27 tsutsui uint16_t e2fs_magic; /* magic number */
157 1.27 tsutsui uint16_t e2fs_state; /* file system state */
158 1.27 tsutsui uint16_t e2fs_beh; /* behavior on errors */
159 1.27 tsutsui uint16_t e2fs_minrev; /* minor revision level */
160 1.27 tsutsui uint32_t e2fs_lastfsck; /* time of last fsck */
161 1.27 tsutsui uint32_t e2fs_fsckintv; /* max time between fscks */
162 1.27 tsutsui uint32_t e2fs_creator; /* creator OS */
163 1.27 tsutsui uint32_t e2fs_rev; /* revision level */
164 1.27 tsutsui uint16_t e2fs_ruid; /* default uid for reserved blocks */
165 1.27 tsutsui uint16_t e2fs_rgid; /* default gid for reserved blocks */
166 1.8 bouyer /* EXT2_DYNAMIC_REV superblocks */
167 1.27 tsutsui uint32_t e2fs_first_ino; /* first non-reserved inode */
168 1.27 tsutsui uint16_t e2fs_inode_size; /* size of inode structure */
169 1.27 tsutsui uint16_t e2fs_block_group_nr; /* block grp number of this sblk*/
170 1.27 tsutsui uint32_t e2fs_features_compat; /* compatible feature set */
171 1.27 tsutsui uint32_t e2fs_features_incompat; /* incompatible feature set */
172 1.27 tsutsui uint32_t e2fs_features_rocompat; /* RO-compatible feature set */
173 1.27 tsutsui uint8_t e2fs_uuid[16]; /* 128-bit uuid for volume */
174 1.27 tsutsui char e2fs_vname[16]; /* volume name */
175 1.27 tsutsui char e2fs_fsmnt[64]; /* name mounted on */
176 1.27 tsutsui uint32_t e2fs_algo; /* For compression */
177 1.27 tsutsui uint8_t e2fs_prealloc; /* # of blocks to preallocate */
178 1.27 tsutsui uint8_t e2fs_dir_prealloc; /* # of blocks to preallocate for dir */
179 1.27 tsutsui uint16_t e2fs_reserved_ngdb; /* # of reserved gd blocks for resize */
180 1.51 riastrad
181 1.37 christos /* Additional fields */
182 1.37 christos char e3fs_journal_uuid[16];/* uuid of journal superblock */
183 1.37 christos uint32_t e3fs_journal_inum; /* inode number of journal file */
184 1.37 christos uint32_t e3fs_journal_dev; /* device number of journal file */
185 1.37 christos uint32_t e3fs_last_orphan; /* start of list of inodes to delete */
186 1.37 christos uint32_t e3fs_hash_seed[4]; /* HTREE hash seed */
187 1.37 christos char e3fs_def_hash_version;/* Default hash version to use */
188 1.37 christos char e3fs_jnl_backup_type;
189 1.37 christos uint16_t e3fs_desc_size; /* size of group descriptor */
190 1.37 christos uint32_t e3fs_default_mount_opts;
191 1.37 christos uint32_t e3fs_first_meta_bg; /* First metablock block group */
192 1.37 christos uint32_t e3fs_mkfs_time; /* when the fs was created */
193 1.37 christos uint32_t e3fs_jnl_blks[17]; /* backup of the journal inode */
194 1.37 christos uint32_t e4fs_bcount_hi; /* high bits of blocks count */
195 1.37 christos uint32_t e4fs_rbcount_hi; /* high bits of reserved blocks count */
196 1.37 christos uint32_t e4fs_fbcount_hi; /* high bits of free blocks count */
197 1.37 christos uint16_t e4fs_min_extra_isize; /* all inodes have some bytes */
198 1.37 christos uint16_t e4fs_want_extra_isize;/* inodes must reserve some bytes */
199 1.37 christos uint32_t e4fs_flags; /* miscellaneous flags */
200 1.37 christos uint16_t e4fs_raid_stride; /* RAID stride */
201 1.37 christos uint16_t e4fs_mmpintv; /* seconds to wait in MMP checking */
202 1.37 christos uint64_t e4fs_mmpblk; /* block for multi-mount protection */
203 1.37 christos uint32_t e4fs_raid_stripe_wid; /* blocks on data disks (N * stride) */
204 1.37 christos uint8_t e4fs_log_gpf; /* FLEX_BG group size */
205 1.37 christos uint8_t e4fs_chksum_type; /* metadata checksum algorithm used */
206 1.37 christos uint8_t e4fs_encrypt; /* versioning level for encryption */
207 1.37 christos uint8_t e4fs_reserved_pad;
208 1.37 christos uint64_t e4fs_kbytes_written; /* number of lifetime kilobytes */
209 1.37 christos uint32_t e4fs_snapinum; /* inode number of active snapshot */
210 1.37 christos uint32_t e4fs_snapid; /* sequential ID of active snapshot */
211 1.37 christos uint64_t e4fs_snaprbcount; /* rsvd blocks for active snapshot */
212 1.37 christos uint32_t e4fs_snaplist; /* inode number for on-disk snapshot */
213 1.37 christos uint32_t e4fs_errcount; /* number of file system errors */
214 1.37 christos uint32_t e4fs_first_errtime; /* first time an error happened */
215 1.37 christos uint32_t e4fs_first_errino; /* inode involved in first error */
216 1.37 christos uint64_t e4fs_first_errblk; /* block involved of first error */
217 1.37 christos uint8_t e4fs_first_errfunc[32];/* function where error happened */
218 1.37 christos uint32_t e4fs_first_errline; /* line number where error happened */
219 1.37 christos uint32_t e4fs_last_errtime; /* most recent time of an error */
220 1.37 christos uint32_t e4fs_last_errino; /* inode involved in last error */
221 1.37 christos uint32_t e4fs_last_errline; /* line number where error happened */
222 1.37 christos uint64_t e4fs_last_errblk; /* block involved of last error */
223 1.37 christos uint8_t e4fs_last_errfunc[32];/* function where error happened */
224 1.37 christos uint8_t e4fs_mount_opts[64];
225 1.37 christos uint32_t e4fs_usrquota_inum; /* inode for tracking user quota */
226 1.37 christos uint32_t e4fs_grpquota_inum; /* inode for tracking group quota */
227 1.37 christos uint32_t e4fs_overhead_clusters;/* overhead blocks/clusters */
228 1.37 christos uint32_t e4fs_backup_bgs[2]; /* groups with sparse_super2 SBs */
229 1.37 christos uint8_t e4fs_encrypt_algos[4];/* encryption algorithms in use */
230 1.37 christos uint8_t e4fs_encrypt_pw_salt[16];/* salt used for string2key */
231 1.37 christos uint32_t e4fs_lpf_ino; /* location of the lost+found inode */
232 1.37 christos uint32_t e4fs_proj_quota_inum; /* inode for tracking project quota */
233 1.37 christos uint32_t e4fs_chksum_seed; /* checksum seed */
234 1.37 christos uint32_t e4fs_reserved[98]; /* padding to the end of the block */
235 1.37 christos uint32_t e4fs_sbchksum; /* superblock checksum */
236 1.1 bouyer };
237 1.1 bouyer
238 1.1 bouyer
239 1.1 bouyer /* in-memory data for ext2fs */
240 1.1 bouyer struct m_ext2fs {
241 1.1 bouyer struct ext2fs e2fs;
242 1.1 bouyer u_char e2fs_fsmnt[MAXMNTLEN]; /* name mounted on */
243 1.8 bouyer int8_t e2fs_ronly; /* mounted read-only flag */
244 1.8 bouyer int8_t e2fs_fmod; /* super block modified flag */
245 1.38 christos int8_t e2fs_uhash; /* 3 if hash should be signed, 0 if not */
246 1.8 bouyer int32_t e2fs_bsize; /* block size */
247 1.8 bouyer int32_t e2fs_bshift; /* ``lblkno'' calc of logical blkno */
248 1.8 bouyer int32_t e2fs_bmask; /* ``blkoff'' calc of blk offsets */
249 1.8 bouyer int64_t e2fs_qbmask; /* ~fs_bmask - for use with quad size */
250 1.8 bouyer int32_t e2fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
251 1.8 bouyer int32_t e2fs_ncg; /* number of cylinder groups */
252 1.48 jdolecek int32_t e2fs_ngdb; /* number of group descriptor blocks */
253 1.8 bouyer int32_t e2fs_ipb; /* number of inodes per block */
254 1.48 jdolecek int32_t e2fs_itpg; /* number of inode table blocks per group */
255 1.49 christos uint8_t e2fs_group_desc_shift; /* binary log group desc size */
256 1.48 jdolecek struct ext2_gd *e2fs_gd; /* group descriptors (data not byteswapped) */
257 1.1 bouyer };
258 1.1 bouyer
259 1.1 bouyer
260 1.1 bouyer
261 1.1 bouyer /*
262 1.1 bouyer * Filesystem identification
263 1.1 bouyer */
264 1.1 bouyer #define E2FS_MAGIC 0xef53 /* the ext2fs magic number */
265 1.23 tsutsui #define E2FS_REV0 0 /* GOOD_OLD revision */
266 1.23 tsutsui #define E2FS_REV1 1 /* Support compat/incompat features */
267 1.9 bouyer
268 1.23 tsutsui /* compatible/incompatible features */
269 1.9 bouyer #define EXT2F_COMPAT_PREALLOC 0x0001
270 1.30 christos #define EXT2F_COMPAT_AFS 0x0002
271 1.29 tsutsui #define EXT2F_COMPAT_HASJOURNAL 0x0004
272 1.30 christos #define EXT2F_COMPAT_EXTATTR 0x0008
273 1.24 tsutsui #define EXT2F_COMPAT_RESIZE 0x0010
274 1.30 christos #define EXT2F_COMPAT_DIRHASHINDEX 0x0020
275 1.41 jdolecek #define EXT2F_COMPAT_SPARSESUPER2 0x0200
276 1.30 christos #define EXT2F_COMPAT_BITS \
277 1.30 christos "\20" \
278 1.41 jdolecek "\12COMPAT_SPARSESUPER2" \
279 1.41 jdolecek "\11" \
280 1.41 jdolecek "\10" \
281 1.41 jdolecek "\07" \
282 1.32 jakllsch "\06COMPAT_DIRHASHINDEX" \
283 1.30 christos "\05COMPAT_RESIZE" \
284 1.30 christos "\04COMPAT_EXTATTR" \
285 1.30 christos "\03COMPAT_HASJOURNAL" \
286 1.30 christos "\02COMPAT_AFS" \
287 1.30 christos "\01COMPAT_PREALLOC"
288 1.9 bouyer
289 1.9 bouyer #define EXT2F_ROCOMPAT_SPARSESUPER 0x0001
290 1.9 bouyer #define EXT2F_ROCOMPAT_LARGEFILE 0x0002
291 1.9 bouyer #define EXT2F_ROCOMPAT_BTREE_DIR 0x0004
292 1.32 jakllsch #define EXT2F_ROCOMPAT_HUGE_FILE 0x0008
293 1.32 jakllsch #define EXT2F_ROCOMPAT_GDT_CSUM 0x0010
294 1.32 jakllsch #define EXT2F_ROCOMPAT_DIR_NLINK 0x0020
295 1.32 jakllsch #define EXT2F_ROCOMPAT_EXTRA_ISIZE 0x0040
296 1.41 jdolecek #define EXT2F_ROCOMPAT_QUOTA 0x0100
297 1.41 jdolecek #define EXT2F_ROCOMPAT_BIGALLOC 0x0200
298 1.41 jdolecek #define EXT2F_ROCOMPAT_METADATA_CKSUM 0x0400
299 1.41 jdolecek #define EXT2F_ROCOMPAT_READONLY 0x1000
300 1.41 jdolecek #define EXT2F_ROCOMPAT_PROJECT 0x2000
301 1.30 christos #define EXT2F_ROCOMPAT_BITS \
302 1.30 christos "\20" \
303 1.41 jdolecek "\16ROCOMPAT_PROJECT" \
304 1.41 jdolecek "\15ROCOMPAT_READONLY" \
305 1.53 rillig "\14?" \
306 1.41 jdolecek "\13ROCOMPAT_METADATA_CKSUM" \
307 1.41 jdolecek "\12ROCOMPAT_BIGALLOC" \
308 1.41 jdolecek "\11ROCOMPAT_QUOTA" \
309 1.53 rillig "\10?" \
310 1.32 jakllsch "\07ROCOMPAT_EXTRA_ISIZE" \
311 1.32 jakllsch "\06ROCOMPAT_DIR_NLINK" \
312 1.32 jakllsch "\05ROCOMPAT_GDT_CSUM" \
313 1.32 jakllsch "\04ROCOMPAT_HUGE_FILE" \
314 1.30 christos "\03ROCOMPAT_BTREE_DIR" \
315 1.30 christos "\02ROCOMPAT_LARGEFILE" \
316 1.31 jakllsch "\01ROCOMPAT_SPARSESUPER"
317 1.9 bouyer
318 1.9 bouyer #define EXT2F_INCOMPAT_COMP 0x0001
319 1.9 bouyer #define EXT2F_INCOMPAT_FTYPE 0x0002
320 1.30 christos #define EXT2F_INCOMPAT_REPLAY_JOURNAL 0x0004
321 1.30 christos #define EXT2F_INCOMPAT_USES_JOURNAL 0x0008
322 1.32 jakllsch #define EXT2F_INCOMPAT_META_BG 0x0010
323 1.32 jakllsch #define EXT2F_INCOMPAT_EXTENTS 0x0040
324 1.32 jakllsch #define EXT2F_INCOMPAT_64BIT 0x0080
325 1.32 jakllsch #define EXT2F_INCOMPAT_MMP 0x0100
326 1.32 jakllsch #define EXT2F_INCOMPAT_FLEX_BG 0x0200
327 1.41 jdolecek #define EXT2F_INCOMPAT_EA_INODE 0x0400
328 1.41 jdolecek #define EXT2F_INCOMPAT_DIRDATA 0x1000
329 1.41 jdolecek #define EXT2F_INCOMPAT_CSUM_SEED 0x2000
330 1.41 jdolecek #define EXT2F_INCOMPAT_LARGEDIR 0x4000
331 1.41 jdolecek #define EXT2F_INCOMPAT_INLINE_DATA 0x8000
332 1.41 jdolecek #define EXT2F_INCOMPAT_ENCRYPT 0x10000
333 1.30 christos #define EXT2F_INCOMPAT_BITS \
334 1.30 christos "\20" \
335 1.41 jdolecek "\021INCOMPAT_ENCRYPT" \
336 1.41 jdolecek "\020INCOMPAT_INLINE_DATA" \
337 1.41 jdolecek "\017INCOMPAT_LARGEDIR" \
338 1.41 jdolecek "\016INCOMPAT_CSUM_SEED" \
339 1.41 jdolecek "\015INCOMPAT_DIRDATA" \
340 1.53 rillig "\014?" \
341 1.41 jdolecek "\013INCOMPAT_EA_INODE" \
342 1.32 jakllsch "\012INCOMPAT_FLEX_BG" \
343 1.32 jakllsch "\011INCOMPAT_MMP" \
344 1.32 jakllsch "\010INCOMPAT_64BIT" \
345 1.32 jakllsch "\07INCOMPAT_EXTENTS" \
346 1.32 jakllsch "\05INCOMPAT_META_BG" \
347 1.30 christos "\04INCOMPAT_USES_JOURNAL" \
348 1.30 christos "\03INCOMPAT_REPLAY_JOURNAL" \
349 1.30 christos "\02INCOMPAT_FTYPE" \
350 1.30 christos "\01INCOMPAT_COMP"
351 1.9 bouyer
352 1.23 tsutsui /*
353 1.23 tsutsui * Features supported in this implementation
354 1.23 tsutsui *
355 1.23 tsutsui * We support the following REV1 features:
356 1.23 tsutsui * - EXT2F_ROCOMPAT_SPARSESUPER
357 1.23 tsutsui * superblock backups stored only in cg_has_sb(bno) groups
358 1.23 tsutsui * - EXT2F_ROCOMPAT_LARGEFILE
359 1.51 riastrad * use e2di_size_high in struct ext2fs_dinode to store
360 1.23 tsutsui * upper 32bit of size for >2GB files
361 1.23 tsutsui * - EXT2F_INCOMPAT_FTYPE
362 1.23 tsutsui * store file type to e2d_type in struct ext2fs_direct
363 1.23 tsutsui * (on REV0 e2d_namlen is uint16_t and no e2d_type, like ffs)
364 1.23 tsutsui */
365 1.9 bouyer #define EXT2F_COMPAT_SUPP 0x0000
366 1.16 ws #define EXT2F_ROCOMPAT_SUPP (EXT2F_ROCOMPAT_SPARSESUPER \
367 1.33 jakllsch | EXT2F_ROCOMPAT_LARGEFILE \
368 1.39 jdolecek | EXT2F_ROCOMPAT_HUGE_FILE \
369 1.46 jdolecek | EXT2F_ROCOMPAT_EXTRA_ISIZE \
370 1.48 jdolecek | EXT2F_ROCOMPAT_DIR_NLINK \
371 1.48 jdolecek | EXT2F_ROCOMPAT_GDT_CSUM)
372 1.37 christos #define EXT2F_INCOMPAT_SUPP (EXT2F_INCOMPAT_FTYPE \
373 1.47 jdolecek | EXT2F_INCOMPAT_EXTENTS \
374 1.49 christos | EXT2F_INCOMPAT_FLEX_BG \
375 1.49 christos | EXT2F_INCOMPAT_64BIT)
376 1.1 bouyer
377 1.1 bouyer /*
378 1.38 christos * Feature set definitions
379 1.38 christos */
380 1.44 jdolecek #define EXT2F_HAS_COMPAT_FEATURE(fs, feature) \
381 1.44 jdolecek ((fs)->e2fs.e2fs_rev >= E2FS_REV1 && \
382 1.44 jdolecek ((fs)->e2fs.e2fs_features_compat & (feature)) != 0)
383 1.44 jdolecek
384 1.44 jdolecek #define EXT2F_HAS_ROCOMPAT_FEATURE(fs, feature) \
385 1.44 jdolecek ((fs)->e2fs.e2fs_rev >= E2FS_REV1 && \
386 1.44 jdolecek ((fs)->e2fs.e2fs_features_rocompat & (feature)) != 0)
387 1.44 jdolecek
388 1.44 jdolecek #define EXT2F_HAS_INCOMPAT_FEATURE(fs, feature) \
389 1.44 jdolecek ((fs)->e2fs.e2fs_rev >= E2FS_REV1 && \
390 1.44 jdolecek ((fs)->e2fs.e2fs_features_incompat & (feature)) != 0)
391 1.44 jdolecek
392 1.38 christos
393 1.38 christos /*
394 1.23 tsutsui * Definitions of behavior on errors
395 1.23 tsutsui */
396 1.23 tsutsui #define E2FS_BEH_CONTINUE 1 /* continue operation */
397 1.23 tsutsui #define E2FS_BEH_READONLY 2 /* remount fs read only */
398 1.23 tsutsui #define E2FS_BEH_PANIC 3 /* cause panic */
399 1.23 tsutsui #define E2FS_BEH_DEFAULT E2FS_BEH_CONTINUE
400 1.23 tsutsui
401 1.23 tsutsui /*
402 1.1 bouyer * OS identification
403 1.1 bouyer */
404 1.23 tsutsui #define E2FS_OS_LINUX 0
405 1.23 tsutsui #define E2FS_OS_HURD 1
406 1.23 tsutsui #define E2FS_OS_MASIX 2
407 1.23 tsutsui #define E2FS_OS_FREEBSD 3
408 1.23 tsutsui #define E2FS_OS_LITES 4
409 1.1 bouyer
410 1.1 bouyer /*
411 1.1 bouyer * Filesystem clean flags
412 1.1 bouyer */
413 1.1 bouyer #define E2FS_ISCLEAN 0x01
414 1.9 bouyer #define E2FS_ERRORS 0x02
415 1.1 bouyer
416 1.1 bouyer /* ext2 file system block group descriptor */
417 1.1 bouyer
418 1.1 bouyer struct ext2_gd {
419 1.27 tsutsui uint32_t ext2bgd_b_bitmap; /* blocks bitmap block */
420 1.27 tsutsui uint32_t ext2bgd_i_bitmap; /* inodes bitmap block */
421 1.48 jdolecek uint32_t ext2bgd_i_tables; /* first inodes table block */
422 1.27 tsutsui uint16_t ext2bgd_nbfree; /* number of free blocks */
423 1.27 tsutsui uint16_t ext2bgd_nifree; /* number of free inodes */
424 1.27 tsutsui uint16_t ext2bgd_ndirs; /* number of directories */
425 1.48 jdolecek
426 1.48 jdolecek /*
427 1.51 riastrad * Following only valid when either GDT_CSUM (AKA uninit_bg)
428 1.48 jdolecek * or METADATA_CKSUM feature is on
429 1.48 jdolecek */
430 1.48 jdolecek uint16_t ext2bgd_flags; /* ext4 bg flags (INODE_UNINIT, ...)*/
431 1.48 jdolecek uint32_t ext2bgd_exclude_bitmap_lo; /* snapshot exclude bitmap */
432 1.48 jdolecek uint16_t ext2bgd_block_bitmap_csum_lo; /* Low block bitmap checksum */
433 1.48 jdolecek uint16_t ext2bgd_inode_bitmap_csum_lo; /* Low inode bitmap checksum */
434 1.48 jdolecek uint16_t ext2bgd_itable_unused_lo; /* Low unused inode offset */
435 1.48 jdolecek uint16_t ext2bgd_checksum; /* Group desc checksum */
436 1.48 jdolecek
437 1.49 christos uint32_t ext2bgd_b_bitmap_hi; /* blocks bitmap block (high bits) */
438 1.49 christos uint32_t ext2bgd_i_bitmap_hi; /* inodes bitmap block (high bits) */
439 1.49 christos uint32_t ext2bgd_i_tables_hi; /* inodes table block (high bits) */
440 1.49 christos uint16_t ext2bgd_nbfree_hi; /* number of free blocks (high bits) */
441 1.49 christos uint16_t ext2bgd_nifree_hi; /* number of free inodes (high bits) */
442 1.49 christos uint16_t ext2bgd_ndirs_hi; /* number of directories (high bits) */
443 1.49 christos uint16_t reserved_hi;
444 1.49 christos uint32_t reserved2_hi[3];
445 1.1 bouyer };
446 1.10 bouyer
447 1.52 christos #define E2FS_REV0_GD_SIZE (sizeof(struct ext2_gd) / 2) /* 32 */
448 1.48 jdolecek #define E2FS_BG_INODE_UNINIT 0x0001 /* Inode bitmap not used/initialized */
449 1.48 jdolecek #define E2FS_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not used/initialized */
450 1.48 jdolecek #define E2FS_BG_INODE_ZEROED 0x0004 /* On-disk inode table initialized */
451 1.10 bouyer
452 1.48 jdolecek #define E2FS_HAS_GD_CSUM(fs) \
453 1.48 jdolecek EXT2F_HAS_ROCOMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM|EXT2F_ROCOMPAT_METADATA_CKSUM) != 0
454 1.51 riastrad
455 1.10 bouyer /*
456 1.10 bouyer * If the EXT2F_ROCOMPAT_SPARSESUPER flag is set, the cylinder group has a
457 1.10 bouyer * copy of the super and cylinder group descriptors blocks only if it's
458 1.23 tsutsui * 1, a power of 3, 5 or 7
459 1.10 bouyer */
460 1.10 bouyer
461 1.26 perry static __inline int cg_has_sb(int) __unused;
462 1.22 perry static __inline int
463 1.25 tsutsui cg_has_sb(int i)
464 1.10 bouyer {
465 1.25 tsutsui int a3, a5, a7;
466 1.10 bouyer
467 1.10 bouyer if (i == 0 || i == 1)
468 1.10 bouyer return 1;
469 1.10 bouyer for (a3 = 3, a5 = 5, a7 = 7;
470 1.10 bouyer a3 <= i || a5 <= i || a7 <= i;
471 1.10 bouyer a3 *= 3, a5 *= 5, a7 *= 7)
472 1.10 bouyer if (i == a3 || i == a5 || i == a7)
473 1.10 bouyer return 1;
474 1.10 bouyer return 0;
475 1.10 bouyer }
476 1.2 bouyer
477 1.2 bouyer /* EXT2FS metadatas are stored in little-endian byte order. These macros
478 1.2 bouyer * helps reading theses metadatas
479 1.2 bouyer */
480 1.2 bouyer
481 1.2 bouyer #if BYTE_ORDER == LITTLE_ENDIAN
482 1.2 bouyer # define h2fs16(x) (x)
483 1.2 bouyer # define h2fs32(x) (x)
484 1.12 fvdl # define h2fs64(x) (x)
485 1.2 bouyer # define fs2h16(x) (x)
486 1.2 bouyer # define fs2h32(x) (x)
487 1.12 fvdl # define fs2h64(x) (x)
488 1.48 jdolecek # define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE)
489 1.48 jdolecek # define e2fs_sbsave(old, new) memcpy((new), (old), SBSIZE)
490 1.2 bouyer #else
491 1.18 xtraeme void e2fs_sb_bswap(struct ext2fs *, struct ext2fs *);
492 1.2 bouyer # define h2fs16(x) bswap16(x)
493 1.2 bouyer # define h2fs32(x) bswap32(x)
494 1.12 fvdl # define h2fs64(x) bswap64(x)
495 1.2 bouyer # define fs2h16(x) bswap16(x)
496 1.2 bouyer # define fs2h32(x) bswap32(x)
497 1.12 fvdl # define fs2h64(x) bswap64(x)
498 1.2 bouyer # define e2fs_sbload(old, new) e2fs_sb_bswap((old), (new))
499 1.2 bouyer # define e2fs_sbsave(old, new) e2fs_sb_bswap((old), (new))
500 1.2 bouyer #endif
501 1.1 bouyer
502 1.50 riastrad #ifndef _KERNEL /* XXX */
503 1.50 riastrad /* Group descriptors are not byte swapped */
504 1.50 riastrad #define e2fs_cgload(old, new, size) memcpy((new), (old), (size))
505 1.50 riastrad #define e2fs_cgsave(old, new, size) memcpy((new), (old), (size))
506 1.50 riastrad #endif
507 1.50 riastrad
508 1.1 bouyer /*
509 1.1 bouyer * Turn file system block numbers into disk block addresses.
510 1.1 bouyer * This maps file system blocks to device size blocks.
511 1.1 bouyer */
512 1.35 dholland #define EXT2_FSBTODB(fs, b) ((b) << (fs)->e2fs_fsbtodb)
513 1.49 christos #define EXT2_FSBTODB64(fs, b, b_hi) \
514 1.49 christos (((((uint64_t)(b_hi)) << 32) | (b)) << (fs)->e2fs_fsbtodb)
515 1.49 christos #define EXT2_FSBTODB64OFF(fs, b, b_hi, off) \
516 1.49 christos ((((((uint64_t)(b_hi)) << 32) | (b)) + (off)) << (fs)->e2fs_fsbtodb)
517 1.35 dholland #define EXT2_DBTOFSB(fs, b) ((b) >> (fs)->e2fs_fsbtodb)
518 1.1 bouyer
519 1.1 bouyer /*
520 1.1 bouyer * Macros for handling inode numbers:
521 1.1 bouyer * inode number to file system block offset.
522 1.1 bouyer * inode number to cylinder group number.
523 1.1 bouyer * inode number to file system block address.
524 1.1 bouyer */
525 1.1 bouyer #define ino_to_cg(fs, x) (((x) - 1) / (fs)->e2fs.e2fs_ipg)
526 1.49 christos #define _e2fs_gd(fs, x) (fs)->e2fs_gd[ino_to_cg((fs), (x))]
527 1.49 christos #define ino_to_fsba(fs, x) \
528 1.49 christos (fs2h32(_e2fs_gd(fs, x).ext2bgd_i_tables) + \
529 1.49 christos (((uint64_t)fs2h32(_e2fs_gd(fs, x).ext2bgd_i_tables_hi)) << 32) + \
530 1.49 christos (((x) - 1) % (fs)->e2fs.e2fs_ipg) / (fs)->e2fs_ipb)
531 1.25 tsutsui #define ino_to_fsbo(fs, x) (((x) - 1) % (fs)->e2fs_ipb)
532 1.1 bouyer
533 1.1 bouyer /*
534 1.1 bouyer * Give cylinder group number for a file system block.
535 1.1 bouyer * Give cylinder group block number for a file system block.
536 1.1 bouyer */
537 1.1 bouyer #define dtog(fs, d) (((d) - (fs)->e2fs.e2fs_first_dblock) / (fs)->e2fs.e2fs_fpg)
538 1.1 bouyer #define dtogd(fs, d) \
539 1.1 bouyer (((d) - (fs)->e2fs.e2fs_first_dblock) % (fs)->e2fs.e2fs_fpg)
540 1.1 bouyer
541 1.1 bouyer /*
542 1.1 bouyer * The following macros optimize certain frequently calculated
543 1.1 bouyer * quantities by using shifts and masks in place of divisions
544 1.1 bouyer * modulos and multiplications.
545 1.1 bouyer */
546 1.34 dholland #define ext2_blkoff(fs, loc) /* calculates (loc % fs->e2fs_bsize) */ \
547 1.1 bouyer ((loc) & (fs)->e2fs_qbmask)
548 1.36 dholland #define ext2_lblktosize(fs, blk) /* calculates (blk * fs->e2fs_bsize) */ \
549 1.1 bouyer ((blk) << (fs)->e2fs_bshift)
550 1.36 dholland #define ext2_lblkno(fs, loc) /* calculates (loc / fs->e2fs_bsize) */ \
551 1.1 bouyer ((loc) >> (fs)->e2fs_bshift)
552 1.36 dholland #define ext2_blkroundup(fs, size) /* calculates roundup(size, fs->e2fs_bsize) */ \
553 1.1 bouyer (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
554 1.36 dholland #define ext2_fragroundup(fs, size) /* calculates roundup(size, fs->e2fs_bsize) */ \
555 1.1 bouyer (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
556 1.17 perry /*
557 1.1 bouyer * Determine the number of available frags given a
558 1.1 bouyer * percentage to hold in reserve.
559 1.17 perry */
560 1.1 bouyer #define freespace(fs) \
561 1.17 perry ((fs)->e2fs.e2fs_fbcount - (fs)->e2fs.e2fs_rbcount)
562 1.1 bouyer
563 1.1 bouyer /*
564 1.1 bouyer * Number of indirects in a file system block.
565 1.1 bouyer */
566 1.34 dholland #define EXT2_NINDIR(fs) ((fs)->e2fs_bsize / sizeof(uint32_t))
567 1.11 matt
568 1.11 matt #endif /* !_UFS_EXT2FS_EXT2FS_H_ */
569