1e09c00caSUlf Lilleengen /*- 2e09c00caSUlf Lilleengen * modified for EXT2FS support in Lites 1.1 3e09c00caSUlf Lilleengen * 4e09c00caSUlf Lilleengen * Aug 1995, Godmar Back (gback@cs.utah.edu) 5e09c00caSUlf Lilleengen * University of Utah, Department of Computer Science 6e09c00caSUlf Lilleengen */ 7e09c00caSUlf Lilleengen /*- 851369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 951369649SPedro F. Giffuni * 10e09c00caSUlf Lilleengen * Copyright (c) 1982, 1986, 1993 11e09c00caSUlf Lilleengen * The Regents of the University of California. All rights reserved. 12e09c00caSUlf Lilleengen * 13e09c00caSUlf Lilleengen * Redistribution and use in source and binary forms, with or without 14e09c00caSUlf Lilleengen * modification, are permitted provided that the following conditions 15e09c00caSUlf Lilleengen * are met: 16e09c00caSUlf Lilleengen * 1. Redistributions of source code must retain the above copyright 17e09c00caSUlf Lilleengen * notice, this list of conditions and the following disclaimer. 18e09c00caSUlf Lilleengen * 2. Redistributions in binary form must reproduce the above copyright 19e09c00caSUlf Lilleengen * notice, this list of conditions and the following disclaimer in the 20e09c00caSUlf Lilleengen * documentation and/or other materials provided with the distribution. 21fca15474SPedro F. Giffuni * 3. Neither the name of the University nor the names of its contributors 22e09c00caSUlf Lilleengen * may be used to endorse or promote products derived from this software 23e09c00caSUlf Lilleengen * without specific prior written permission. 24e09c00caSUlf Lilleengen * 25e09c00caSUlf Lilleengen * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26e09c00caSUlf Lilleengen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27e09c00caSUlf Lilleengen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28e09c00caSUlf Lilleengen * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29e09c00caSUlf Lilleengen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30e09c00caSUlf Lilleengen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31e09c00caSUlf Lilleengen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32e09c00caSUlf Lilleengen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33e09c00caSUlf Lilleengen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34e09c00caSUlf Lilleengen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35e09c00caSUlf Lilleengen * SUCH DAMAGE. 36e09c00caSUlf Lilleengen */ 37e09c00caSUlf Lilleengen 385ed5554fSPedro F. Giffuni #ifndef _FS_EXT2FS_FS_H_ 395ed5554fSPedro F. Giffuni #define _FS_EXT2FS_FS_H_ 405ed5554fSPedro F. Giffuni 41e09c00caSUlf Lilleengen /* 42e09c00caSUlf Lilleengen * Each disk drive contains some number of file systems. 43e09c00caSUlf Lilleengen * A file system consists of a number of cylinder groups. 44e09c00caSUlf Lilleengen * Each cylinder group has inodes and data. 45e09c00caSUlf Lilleengen * 46e09c00caSUlf Lilleengen * A file system is described by its super-block, which in turn 47e09c00caSUlf Lilleengen * describes the cylinder groups. The super-block is critical 48e09c00caSUlf Lilleengen * data and is replicated in each cylinder group to protect against 49e09c00caSUlf Lilleengen * catastrophic loss. This is done at `newfs' time and the critical 50e09c00caSUlf Lilleengen * super-block data does not change, so the copies need not be 51e09c00caSUlf Lilleengen * referenced further unless disaster strikes. 52e09c00caSUlf Lilleengen * 53e09c00caSUlf Lilleengen * The first boot and super blocks are given in absolute disk addresses. 54e09c00caSUlf Lilleengen * The byte-offset forms are preferred, as they don't imply a sector size. 55e09c00caSUlf Lilleengen */ 56*50be18ccSFedor Uporov #define SBLOCK 0 57*50be18ccSFedor Uporov #define SBLOCKSIZE 1024 58*50be18ccSFedor Uporov #define SBLOCKOFFSET 1024 59*50be18ccSFedor Uporov #define SBLOCKBLKSIZE 4096 60e09c00caSUlf Lilleengen 61e09c00caSUlf Lilleengen /* 62e09c00caSUlf Lilleengen * The path name on which the file system is mounted is maintained 63e09c00caSUlf Lilleengen * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 64e09c00caSUlf Lilleengen * the super block for this name. 65e09c00caSUlf Lilleengen */ 66e09c00caSUlf Lilleengen #define MAXMNTLEN 512 67e09c00caSUlf Lilleengen 68e09c00caSUlf Lilleengen /* 69b6113fb3SPedro F. Giffuni * A summary of contiguous blocks of various sizes is maintained 70b6113fb3SPedro F. Giffuni * in each cylinder group. Normally this is set by the initial 71b6113fb3SPedro F. Giffuni * value of fs_maxcontig. 72b6113fb3SPedro F. Giffuni * 73b6113fb3SPedro F. Giffuni * XXX:FS_MAXCONTIG is set to 16 to conserve space. Here we set 74b6113fb3SPedro F. Giffuni * EXT2_MAXCONTIG to 32 for better performance. 75b6113fb3SPedro F. Giffuni */ 76b6113fb3SPedro F. Giffuni #define EXT2_MAXCONTIG 32 77b6113fb3SPedro F. Giffuni 78b6113fb3SPedro F. Giffuni /* 79e09c00caSUlf Lilleengen * Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine 80e09c00caSUlf Lilleengen * tune the layout preferences for directories within a filesystem. 81e09c00caSUlf Lilleengen * His algorithm can be tuned by adjusting the following parameters 82e09c00caSUlf Lilleengen * which tell the system the average file size and the average number 83e09c00caSUlf Lilleengen * of files per directory. These defaults are well selected for typical 84e09c00caSUlf Lilleengen * filesystems, but may need to be tuned for odd cases like filesystems 85e09c00caSUlf Lilleengen * being used for squid caches or news spools. 86e09c00caSUlf Lilleengen * AVFPDIR is the expected number of files per directory. AVGDIRSIZE is 87e09c00caSUlf Lilleengen * obtained by multiplying AVFPDIR and AVFILESIZ which is assumed to be 88e09c00caSUlf Lilleengen * 16384. 89e09c00caSUlf Lilleengen */ 90e09c00caSUlf Lilleengen 91e09c00caSUlf Lilleengen #define AFPDIR 64 92e09c00caSUlf Lilleengen #define AVGDIRSIZE 1048576 93e09c00caSUlf Lilleengen 94e09c00caSUlf Lilleengen /* 95e09c00caSUlf Lilleengen * Macros for access to superblock array structures 96e09c00caSUlf Lilleengen */ 97e09c00caSUlf Lilleengen 98e09c00caSUlf Lilleengen /* 99e09c00caSUlf Lilleengen * Turn file system block numbers into disk block addresses. 100e09c00caSUlf Lilleengen * This maps file system blocks to device size blocks. 101e09c00caSUlf Lilleengen */ 102da057ed2SPedro F. Giffuni #define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->e2fs_fsbtodb) 103da057ed2SPedro F. Giffuni #define dbtofsb(fs, b) ((b) >> (fs)->e2fs_fsbtodb) 104e09c00caSUlf Lilleengen 105e09c00caSUlf Lilleengen /* get group containing inode */ 106e09c00caSUlf Lilleengen #define ino_to_cg(fs, x) (((x) - 1) / (fs->e2fs_ipg)) 107e09c00caSUlf Lilleengen 108e09c00caSUlf Lilleengen /* get block containing inode from its number x */ 109e09c00caSUlf Lilleengen #define ino_to_fsba(fs, x) \ 1103acd9182SFedor Uporov (e2fs_gd_get_i_tables(&(fs)->e2fs_gd[ino_to_cg((fs), (x))]) + \ 111cd3acfe7SFedor Uporov (((x) - 1) % (fs)->e2fs_ipg) / (fs)->e2fs_ipb) 112e09c00caSUlf Lilleengen 113e09c00caSUlf Lilleengen /* get offset for inode in block */ 114e09c00caSUlf Lilleengen #define ino_to_fsbo(fs, x) ((x-1) % (fs->e2fs_ipb)) 115e09c00caSUlf Lilleengen 116e09c00caSUlf Lilleengen /* 117e09c00caSUlf Lilleengen * Give cylinder group number for a file system block. 118e09c00caSUlf Lilleengen * Give cylinder group block number for a file system block. 119e09c00caSUlf Lilleengen */ 120cd3acfe7SFedor Uporov #define dtog(fs, d) (((d) - le32toh(fs->e2fs->e2fs_first_dblock)) / \ 121e09c00caSUlf Lilleengen EXT2_BLOCKS_PER_GROUP(fs)) 122cd3acfe7SFedor Uporov #define dtogd(fs, d) (((d) - le32toh(fs->e2fs->e2fs_first_dblock)) % \ 123e09c00caSUlf Lilleengen EXT2_BLOCKS_PER_GROUP(fs)) 124e09c00caSUlf Lilleengen 125e09c00caSUlf Lilleengen /* 126e09c00caSUlf Lilleengen * The following macros optimize certain frequently calculated 127e09c00caSUlf Lilleengen * quantities by using shifts and masks in place of divisions 128e09c00caSUlf Lilleengen * modulos and multiplications. 129e09c00caSUlf Lilleengen */ 130e09c00caSUlf Lilleengen #define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ 131e09c00caSUlf Lilleengen ((loc) & (fs)->e2fs_qbmask) 132e09c00caSUlf Lilleengen 133e09c00caSUlf Lilleengen #define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \ 134e09c00caSUlf Lilleengen ((blk) << (fs->e2fs_bshift)) 135e09c00caSUlf Lilleengen 136e09c00caSUlf Lilleengen #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ 137e09c00caSUlf Lilleengen ((loc) >> (fs->e2fs_bshift)) 138e09c00caSUlf Lilleengen 139e09c00caSUlf Lilleengen /* no fragments -> logical block number equal # of frags */ 140e09c00caSUlf Lilleengen #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 141e09c00caSUlf Lilleengen ((loc) >> (fs->e2fs_bshift)) 142e09c00caSUlf Lilleengen 143e09c00caSUlf Lilleengen #define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ 144e09c00caSUlf Lilleengen roundup(size, fs->e2fs_fsize) 145e09c00caSUlf Lilleengen /* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */ 146e09c00caSUlf Lilleengen 147e09c00caSUlf Lilleengen /* 148e09c00caSUlf Lilleengen * Determining the size of a file block in the file system. 149e09c00caSUlf Lilleengen * easy w/o fragments 150e09c00caSUlf Lilleengen */ 151e09c00caSUlf Lilleengen #define blksize(fs, ip, lbn) ((fs)->e2fs_fsize) 152e09c00caSUlf Lilleengen 153e09c00caSUlf Lilleengen /* 154e09c00caSUlf Lilleengen * INOPB is the number of inodes in a secondary storage block. 155e09c00caSUlf Lilleengen */ 156e09c00caSUlf Lilleengen #define INOPB(fs) (fs->e2fs_ipb) 157e09c00caSUlf Lilleengen 158e09c00caSUlf Lilleengen /* 159e09c00caSUlf Lilleengen * NINDIR is the number of indirects in a file system block. 160e09c00caSUlf Lilleengen */ 161e09c00caSUlf Lilleengen #define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs)) 162e09c00caSUlf Lilleengen 163e06e5241SFedor Uporov /* 164e06e5241SFedor Uporov * Use if additional debug logging is required. 165e06e5241SFedor Uporov */ 166ebc94b66SFedor Uporov /* #define EXT2FS_PRINT_EXTENTS */ 167e06e5241SFedor Uporov 1685ed5554fSPedro F. Giffuni #endif /* !_FS_EXT2FS_FS_H_ */ 169