2 * modified for EXT2FS support in Lites 1.1
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
8 * Copyright (c) 1982, 1986, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)fs.h 8.7 (Berkeley) 4/19/94
40 * Each disk drive contains some number of file systems.
41 * A file system consists of a number of cylinder groups.
42 * Each cylinder group has inodes and data.
44 * A file system is described by its super-block, which in turn
45 * describes the cylinder groups. The super-block is critical
46 * data and is replicated in each cylinder group to protect against
47 * catastrophic loss. This is done at `newfs' time and the critical
48 * super-block data does not change, so the copies need not be
49 * referenced further unless disaster strikes.
51 * The first boot and super blocks are given in absolute disk addresses.
52 * The byte-offset forms are preferred, as they don't imply a sector size.
58 * The path name on which the file system is mounted is maintained
59 * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
60 * the super block for this name.
65 * Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine
66 * tune the layout preferences for directories within a filesystem.
67 * His algorithm can be tuned by adjusting the following parameters
68 * which tell the system the average file size and the average number
69 * of files per directory. These defaults are well selected for typical
70 * filesystems, but may need to be tuned for odd cases like filesystems
71 * being used for squid caches or news spools.
72 * AVFPDIR is the expected number of files per directory. AVGDIRSIZE is
73 * obtained by multiplying AVFPDIR and AVFILESIZ which is assumed to be
78 #define AVGDIRSIZE 1048576
81 * Macros for access to superblock array structures
85 * Turn file system block numbers into disk block addresses.
86 * This maps file system blocks to device size blocks.
88 #define fsbtodb(fs, b) ((b) << ((fs)->e2fs_fsbtodb))
89 #define dbtofsb(fs, b) ((b) >> ((fs)->e2fs_fsbtodb))
91 /* get group containing inode */
92 #define ino_to_cg(fs, x) (((x) - 1) / (fs->e2fs_ipg))
94 /* get block containing inode from its number x */
95 #define ino_to_fsba(fs, x) \
96 ((fs)->e2fs_gd[ino_to_cg((fs), (x))].ext2bgd_i_tables + \
97 (((x) - 1) % (fs)->e2fs->e2fs_ipg) / (fs)->e2fs_ipb)
99 /* get offset for inode in block */
100 #define ino_to_fsbo(fs, x) ((x-1) % (fs->e2fs_ipb))
103 * Give cylinder group number for a file system block.
104 * Give cylinder group block number for a file system block.
106 #define dtog(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) / \
107 EXT2_BLOCKS_PER_GROUP(fs))
108 #define dtogd(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) % \
109 EXT2_BLOCKS_PER_GROUP(fs))
112 * The following macros optimize certain frequently calculated
113 * quantities by using shifts and masks in place of divisions
114 * modulos and multiplications.
116 #define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
117 ((loc) & (fs)->e2fs_qbmask)
119 #define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \
120 ((blk) << (fs->e2fs_bshift))
122 #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
123 ((loc) >> (fs->e2fs_bshift))
125 /* no fragments -> logical block number equal # of frags */
126 #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
127 ((loc) >> (fs->e2fs_bshift))
129 #define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
130 roundup(size, fs->e2fs_fsize)
131 /* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */
134 * Determining the size of a file block in the file system.
137 #define blksize(fs, ip, lbn) ((fs)->e2fs_fsize)
140 * INOPB is the number of inodes in a secondary storage block.
142 #define INOPB(fs) (fs->e2fs_ipb)
145 * NINDIR is the number of indirects in a file system block.
147 #define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs))
149 extern int inside[], around[];
150 extern u_char *fragtbl[];