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