1139778Simp/*-
212115Sdyson *  modified for EXT2FS support in Lites 1.1
312115Sdyson *
412115Sdyson *  Aug 1995, Godmar Back (gback@cs.utah.edu)
512115Sdyson *  University of Utah, Department of Computer Science
612115Sdyson */
7139778Simp/*-
812115Sdyson * Copyright (c) 1982, 1986, 1993
912115Sdyson *	The Regents of the University of California.  All rights reserved.
1012115Sdyson *
1112115Sdyson * Redistribution and use in source and binary forms, with or without
1212115Sdyson * modification, are permitted provided that the following conditions
1312115Sdyson * are met:
1412115Sdyson * 1. Redistributions of source code must retain the above copyright
1512115Sdyson *    notice, this list of conditions and the following disclaimer.
1612115Sdyson * 2. Redistributions in binary form must reproduce the above copyright
1712115Sdyson *    notice, this list of conditions and the following disclaimer in the
1812115Sdyson *    documentation and/or other materials provided with the distribution.
1912115Sdyson * 4. Neither the name of the University nor the names of its contributors
2012115Sdyson *    may be used to endorse or promote products derived from this software
2112115Sdyson *    without specific prior written permission.
2212115Sdyson *
2312115Sdyson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2412115Sdyson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2512115Sdyson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2612115Sdyson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2712115Sdyson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2812115Sdyson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2912115Sdyson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3012115Sdyson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3112115Sdyson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3212115Sdyson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3312115Sdyson * SUCH DAMAGE.
3412115Sdyson *
3512115Sdyson *	@(#)fs.h	8.7 (Berkeley) 4/19/94
3668568Sbde * $FreeBSD$
3712115Sdyson */
3812115Sdyson
39228583Spfg#ifndef _FS_EXT2FS_FS_H_
40262723Spfg#define	_FS_EXT2FS_FS_H_
41228583Spfg
4212115Sdyson/*
4312115Sdyson * Each disk drive contains some number of file systems.
4412115Sdyson * A file system consists of a number of cylinder groups.
4512115Sdyson * Each cylinder group has inodes and data.
4612115Sdyson *
4712115Sdyson * A file system is described by its super-block, which in turn
4812115Sdyson * describes the cylinder groups.  The super-block is critical
4912115Sdyson * data and is replicated in each cylinder group to protect against
5012115Sdyson * catastrophic loss.  This is done at `newfs' time and the critical
5112115Sdyson * super-block data does not change, so the copies need not be
5212115Sdyson * referenced further unless disaster strikes.
5312115Sdyson *
5412115Sdyson * The first boot and super blocks are given in absolute disk addresses.
5512115Sdyson * The byte-offset forms are preferred, as they don't imply a sector size.
5612115Sdyson */
57262723Spfg#define	SBSIZE		1024
58262723Spfg#define	SBLOCK		2
5912115Sdyson
6012115Sdyson/*
6112115Sdyson * The path name on which the file system is mounted is maintained
6212115Sdyson * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
63202283Slulf * the super block for this name.
6412115Sdyson */
65262723Spfg#define	MAXMNTLEN	512
6612115Sdyson
6712115Sdyson/*
68251809Spfg * A summary of contiguous blocks of various sizes is maintained
69251809Spfg * in each cylinder group. Normally this is set by the initial
70251809Spfg * value of fs_maxcontig.
71251809Spfg *
72251809Spfg * XXX:FS_MAXCONTIG is set to 16 to conserve space. Here we set
73251809Spfg * EXT2_MAXCONTIG to 32 for better performance.
74251809Spfg */
75262723Spfg#define	EXT2_MAXCONTIG	32
76251809Spfg
77251809Spfg/*
78202283Slulf * Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine
79202283Slulf * tune the layout preferences for directories within a filesystem.
80202283Slulf * His algorithm can be tuned by adjusting the following parameters
81202283Slulf * which tell the system the average file size and the average number
82202283Slulf * of files per directory. These defaults are well selected for typical
83202283Slulf * filesystems, but may need to be tuned for odd cases like filesystems
84202283Slulf * being used for squid caches or news spools.
85202283Slulf * AVFPDIR is the expected number of files per directory. AVGDIRSIZE is
86202283Slulf * obtained by multiplying AVFPDIR and AVFILESIZ which is assumed to be
87202283Slulf * 16384.
8812115Sdyson */
8912115Sdyson
90262723Spfg#define	AFPDIR		64
91262723Spfg#define	AVGDIRSIZE	1048576
92202283Slulf
9312115Sdyson/*
94202283Slulf * Macros for access to superblock array structures
9512115Sdyson */
9612115Sdyson
9712115Sdyson/*
9812115Sdyson * Turn file system block numbers into disk block addresses.
9912115Sdyson * This maps file system blocks to device size blocks.
10012115Sdyson */
101262723Spfg#define	fsbtodb(fs, b)	((daddr_t)(b) << (fs)->e2fs_fsbtodb)
102252103Spfg#define	dbtofsb(fs, b)	((b) >> (fs)->e2fs_fsbtodb)
10312115Sdyson
10412115Sdyson/* get group containing inode */
105262723Spfg#define	ino_to_cg(fs, x)	(((x) - 1) / (fs->e2fs_ipg))
10612115Sdyson
10712115Sdyson/* get block containing inode from its number x */
108262723Spfg#define	ino_to_fsba(fs, x)                                              \
109202283Slulf        ((fs)->e2fs_gd[ino_to_cg((fs), (x))].ext2bgd_i_tables +         \
110202283Slulf        (((x) - 1) % (fs)->e2fs->e2fs_ipg) / (fs)->e2fs_ipb)
11112115Sdyson
11212115Sdyson/* get offset for inode in block */
113202283Slulf#define	ino_to_fsbo(fs, x)	((x-1) % (fs->e2fs_ipb))
11412115Sdyson
11512115Sdyson/*
11612115Sdyson * Give cylinder group number for a file system block.
11712115Sdyson * Give cylinder group block number for a file system block.
11812115Sdyson */
119202283Slulf#define	dtog(fs, d)	(((d) - fs->e2fs->e2fs_first_dblock) / \
12012115Sdyson			EXT2_BLOCKS_PER_GROUP(fs))
121202283Slulf#define	dtogd(fs, d)	(((d) - fs->e2fs->e2fs_first_dblock) % \
12212115Sdyson			EXT2_BLOCKS_PER_GROUP(fs))
12312115Sdyson
12412115Sdyson/*
12512115Sdyson * The following macros optimize certain frequently calculated
12612115Sdyson * quantities by using shifts and masks in place of divisions
12712115Sdyson * modulos and multiplications.
12812115Sdyson */
129262723Spfg#define	blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
130202283Slulf	((loc) & (fs)->e2fs_qbmask)
13112115Sdyson
132262723Spfg#define	lblktosize(fs, blk)	/* calculates (blk * fs->fs_bsize) */ \
133202283Slulf	((blk) << (fs->e2fs_bshift))
13412115Sdyson
135262723Spfg#define	lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
136202283Slulf	((loc) >> (fs->e2fs_bshift))
13712115Sdyson
13812115Sdyson/* no fragments -> logical block number equal # of frags */
139262723Spfg#define	numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
140202283Slulf	((loc) >> (fs->e2fs_bshift))
14112115Sdyson
142262723Spfg#define	fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \
143202283Slulf	roundup(size, fs->e2fs_fsize)
14412115Sdyson	/* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */
14512115Sdyson
14612115Sdyson/*
14712115Sdyson * Determining the size of a file block in the file system.
14812115Sdyson * easy w/o fragments
14912115Sdyson */
150262723Spfg#define	blksize(fs, ip, lbn) ((fs)->e2fs_fsize)
15112115Sdyson
15212115Sdyson/*
15312115Sdyson * INOPB is the number of inodes in a secondary storage block.
15412115Sdyson */
155202283Slulf#define	INOPB(fs)	(fs->e2fs_ipb)
15612115Sdyson
15712115Sdyson/*
15812115Sdyson * NINDIR is the number of indirects in a file system block.
15912115Sdyson */
16012115Sdyson#define	NINDIR(fs)	(EXT2_ADDR_PER_BLOCK(fs))
16112115Sdyson
162228583Spfg#endif /* !_FS_EXT2FS_FS_H_ */
163