fs.h (175294) | fs.h (202283) |
---|---|
1/*- 2 * modified for EXT2FS support in Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/*- 8 * Copyright (c) 1982, 1986, 1993 --- 19 unchanged lines hidden (view full) --- 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 33 * SUCH DAMAGE. 34 * 35 * @(#)fs.h 8.7 (Berkeley) 4/19/94 | 1/*- 2 * modified for EXT2FS support in Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/*- 8 * Copyright (c) 1982, 1986, 1993 --- 19 unchanged lines hidden (view full) --- 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 33 * SUCH DAMAGE. 34 * 35 * @(#)fs.h 8.7 (Berkeley) 4/19/94 |
36 * $FreeBSD: head/sys/gnu/fs/ext2fs/fs.h 175294 2008-01-13 14:44:15Z attilio $ | 36 * $FreeBSD: head/sys/fs/ext2fs/fs.h 202283 2010-01-14 14:30:54Z lulf $ |
37 */ 38 39/* 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. 43 * 44 * A file system is described by its super-block, which in turn --- 7 unchanged lines hidden (view full) --- 52 * The byte-offset forms are preferred, as they don't imply a sector size. 53 */ 54#define SBSIZE 1024 55#define SBLOCK 2 56 57/* 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 | 37 */ 38 39/* 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. 43 * 44 * A file system is described by its super-block, which in turn --- 7 unchanged lines hidden (view full) --- 52 * The byte-offset forms are preferred, as they don't imply a sector size. 53 */ 54#define SBSIZE 1024 55#define SBLOCK 2 56 57/* 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. | 60 * the super block for this name. |
61 */ | 61 */ |
62#define MAXMNTLEN 512 | 62#define MAXMNTLEN 512 |
63 64/* | 63 64/* |
65 * Macros for access to superblock array structures | 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 74 * 16384. |
66 */ 67 | 75 */ 76 |
77#define AFPDIR 64 78#define AVGDIRSIZE 1048576 79 |
|
68/* | 80/* |
69 * Convert cylinder group to base address of its global summary info. | 81 * Macros for access to superblock array structures |
70 */ | 82 */ |
71#define fs_cs(fs, cgindx) (((struct ext2_group_desc *) \ 72 (fs->s_group_desc[cgindx / EXT2_DESC_PER_BLOCK(fs)]->b_data)) \ 73 [cgindx % EXT2_DESC_PER_BLOCK(fs)]) | |
74 75/* 76 * Turn file system block numbers into disk block addresses. 77 * This maps file system blocks to device size blocks. 78 */ | 83 84/* 85 * Turn file system block numbers into disk block addresses. 86 * This maps file system blocks to device size blocks. 87 */ |
79#define fsbtodb(fs, b) ((b) << ((fs)->s_fsbtodb)) 80#define dbtofsb(fs, b) ((b) >> ((fs)->s_fsbtodb)) | 88#define fsbtodb(fs, b) ((b) << ((fs)->e2fs_fsbtodb)) 89#define dbtofsb(fs, b) ((b) >> ((fs)->e2fs_fsbtodb)) |
81 82/* get group containing inode */ | 90 91/* get group containing inode */ |
83#define ino_to_cg(fs, x) (((x) - 1) / EXT2_INODES_PER_GROUP(fs)) | 92#define ino_to_cg(fs, x) (((x) - 1) / (fs->e2fs_ipg)) |
84 85/* get block containing inode from its number x */ | 93 94/* get block containing inode from its number x */ |
86#define ino_to_fsba(fs, x) fs_cs(fs, ino_to_cg(fs, x)).bg_inode_table + \ 87 (((x)-1) % EXT2_INODES_PER_GROUP(fs))/EXT2_INODES_PER_BLOCK(fs) | 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) |
88 89/* get offset for inode in block */ | 98 99/* get offset for inode in block */ |
90#define ino_to_fsbo(fs, x) ((x-1) % EXT2_INODES_PER_BLOCK(fs)) | 100#define ino_to_fsbo(fs, x) ((x-1) % (fs->e2fs_ipb)) |
91 92/* 93 * Give cylinder group number for a file system block. 94 * Give cylinder group block number for a file system block. 95 */ | 101 102/* 103 * Give cylinder group number for a file system block. 104 * Give cylinder group block number for a file system block. 105 */ |
96#define dtog(fs, d) (((d) - fs->s_es->s_first_data_block) / \ | 106#define dtog(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) / \ |
97 EXT2_BLOCKS_PER_GROUP(fs)) | 107 EXT2_BLOCKS_PER_GROUP(fs)) |
98#define dtogd(fs, d) (((d) - fs->s_es->s_first_data_block) % \ | 108#define dtogd(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) % \ |
99 EXT2_BLOCKS_PER_GROUP(fs)) 100 101/* 102 * The following macros optimize certain frequently calculated 103 * quantities by using shifts and masks in place of divisions 104 * modulos and multiplications. 105 */ 106#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ | 109 EXT2_BLOCKS_PER_GROUP(fs)) 110 111/* 112 * The following macros optimize certain frequently calculated 113 * quantities by using shifts and masks in place of divisions 114 * modulos and multiplications. 115 */ 116#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ |
107 ((loc) & (fs)->s_qbmask) | 117 ((loc) & (fs)->e2fs_qbmask) |
108 109#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \ | 118 119#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \ |
110 ((blk) << (fs->s_bshift)) | 120 ((blk) << (fs->e2fs_bshift)) |
111 112#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ | 121 122#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ |
113 ((loc) >> (fs->s_bshift)) | 123 ((loc) >> (fs->e2fs_bshift)) |
114 115/* no fragments -> logical block number equal # of frags */ 116#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ | 124 125/* no fragments -> logical block number equal # of frags */ 126#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ |
117 ((loc) >> (fs->s_bshift)) | 127 ((loc) >> (fs->e2fs_bshift)) |
118 119#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ | 128 129#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ |
120 roundup(size, fs->s_frag_size) | 130 roundup(size, fs->e2fs_fsize) |
121 /* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */ 122 123/* 124 * Determining the size of a file block in the file system. 125 * easy w/o fragments 126 */ | 131 /* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */ 132 133/* 134 * Determining the size of a file block in the file system. 135 * easy w/o fragments 136 */ |
127#define blksize(fs, ip, lbn) ((fs)->s_frag_size) | 137#define blksize(fs, ip, lbn) ((fs)->e2fs_fsize) |
128 129/* 130 * INOPB is the number of inodes in a secondary storage block. 131 */ | 138 139/* 140 * INOPB is the number of inodes in a secondary storage block. 141 */ |
132#define INOPB(fs) EXT2_INODES_PER_BLOCK(fs) | 142#define INOPB(fs) (fs->e2fs_ipb) |
133 134/* 135 * NINDIR is the number of indirects in a file system block. 136 */ 137#define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs)) 138 139extern int inside[], around[]; 140extern u_char *fragtbl[]; 141 | 143 144/* 145 * NINDIR is the number of indirects in a file system block. 146 */ 147#define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs)) 148 149extern int inside[], around[]; 150extern u_char *fragtbl[]; 151 |
142/* a few remarks about superblock locking/unlocking 143 * Linux provides special routines for doing so 144 * I haven't figured out yet what BSD does 145 * I think I'll try a VOP_LOCK/VOP_UNLOCK on the device vnode 146 */ 147#define DEVVP(inode) (VFSTOEXT2(ITOV(inode)->v_mount)->um_devvp) 148#define lock_super(devvp) vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY) 149#define unlock_super(devvp) VOP_UNLOCK(devvp, 0) | |
150 | 152 |
151/* 152 * Historically, ext2fs kept it's metadata buffers on the LOCKED queue. Now, 153 * we change the lock owner to kern so that we may use it from contexts other 154 * than the one that originally locked it. When we are finished with the 155 * buffer, we release it, writing it first if it was dirty. 156 */ 157#define LCK_BUF(bp) { \ 158 (bp)->b_flags |= B_PERSISTENT; \ 159 BUF_KERNPROC(bp); \ 160} 161 162#define ULCK_BUF(bp) { \ 163 long flags; \ 164 flags = (bp)->b_flags; \ 165 (bp)->b_flags &= ~(B_DIRTY | B_PERSISTENT); \ 166 if (flags & B_DIRTY) \ 167 bwrite(bp); \ 168 else \ 169 brelse(bp); \ 170} | |