/*-1* modified for EXT2FS support in Lites 1.12*3* Aug 1995, Godmar Back ([email protected])4* University of Utah, Department of Computer Science5*/6/*-7* SPDX-License-Identifier: BSD-3-Clause8*9* Copyright (c) 1982, 1986, 199310* The Regents of the University of California. All rights reserved.11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15* 1. Redistributions of source code must retain the above copyright16* notice, this list of conditions and the following disclaimer.17* 2. Redistributions in binary form must reproduce the above copyright18* notice, this list of conditions and the following disclaimer in the19* documentation and/or other materials provided with the distribution.20* 3. Neither the name of the University nor the names of its contributors21* may be used to endorse or promote products derived from this software22* without specific prior written permission.23*24* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND25* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE26* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE27* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE28* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL29* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS30* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)31* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT32* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY33* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF34* SUCH DAMAGE.35*/3637#ifndef _FS_EXT2FS_FS_H_38#define _FS_EXT2FS_FS_H_3940/*41* Each disk drive contains some number of file systems.42* A file system consists of a number of cylinder groups.43* Each cylinder group has inodes and data.44*45* A file system is described by its super-block, which in turn46* describes the cylinder groups. The super-block is critical47* data and is replicated in each cylinder group to protect against48* catastrophic loss. This is done at `newfs' time and the critical49* super-block data does not change, so the copies need not be50* referenced further unless disaster strikes.51*52* The first boot and super blocks are given in absolute disk addresses.53* The byte-offset forms are preferred, as they don't imply a sector size.54*/55#define SBLOCK 056#define SBLOCKSIZE 102457#define SBLOCKOFFSET 102458#define SBLOCKBLKSIZE 40965960/*61* The path name on which the file system is mounted is maintained62* in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in63* the super block for this name.64*/65#define MAXMNTLEN 5126667/*68* A summary of contiguous blocks of various sizes is maintained69* in each cylinder group. Normally this is set by the initial70* value of fs_maxcontig.71*72* XXX:FS_MAXCONTIG is set to 16 to conserve space. Here we set73* EXT2_MAXCONTIG to 32 for better performance.74*/75#define EXT2_MAXCONTIG 327677/*78* Grigoriy Orlov <[email protected]> has done some extensive work to fine79* tune the layout preferences for directories within a filesystem.80* His algorithm can be tuned by adjusting the following parameters81* which tell the system the average file size and the average number82* of files per directory. These defaults are well selected for typical83* filesystems, but may need to be tuned for odd cases like filesystems84* being used for squid caches or news spools.85* AVFPDIR is the expected number of files per directory. AVGDIRSIZE is86* obtained by multiplying AVFPDIR and AVFILESIZ which is assumed to be87* 16384.88*/8990#define AFPDIR 6491#define AVGDIRSIZE 10485769293/*94* Macros for access to superblock array structures95*/9697/*98* Turn file system block numbers into disk block addresses.99* This maps file system blocks to device size blocks.100*/101#define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->e2fs_fsbtodb)102#define dbtofsb(fs, b) ((b) >> (fs)->e2fs_fsbtodb)103104/* get group containing inode */105#define ino_to_cg(fs, x) (((x) - 1) / (fs->e2fs_ipg))106107/* get block containing inode from its number x */108#define ino_to_fsba(fs, x) \109(e2fs_gd_get_i_tables(&(fs)->e2fs_gd[ino_to_cg((fs), (x))]) + \110(((x) - 1) % (fs)->e2fs_ipg) / (fs)->e2fs_ipb)111112/* get offset for inode in block */113#define ino_to_fsbo(fs, x) ((x-1) % (fs->e2fs_ipb))114115/*116* Give cylinder group number for a file system block.117* Give cylinder group block number for a file system block.118*/119#define dtog(fs, d) (((d) - le32toh(fs->e2fs->e2fs_first_dblock)) / \120EXT2_BLOCKS_PER_GROUP(fs))121#define dtogd(fs, d) (((d) - le32toh(fs->e2fs->e2fs_first_dblock)) % \122EXT2_BLOCKS_PER_GROUP(fs))123124/*125* The following macros optimize certain frequently calculated126* quantities by using shifts and masks in place of divisions127* modulos and multiplications.128*/129#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \130((loc) & (fs)->e2fs_qbmask)131132#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \133((blk) << (fs->e2fs_bshift))134135#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \136((loc) >> (fs->e2fs_bshift))137138/* no fragments -> logical block number equal # of frags */139#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \140((loc) >> (fs->e2fs_bshift))141142#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \143roundup(size, fs->e2fs_fsize)144/* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */145146/*147* Determining the size of a file block in the file system.148* easy w/o fragments149*/150#define blksize(fs, ip, lbn) ((fs)->e2fs_fsize)151152/*153* INOPB is the number of inodes in a secondary storage block.154*/155#define INOPB(fs) (fs->e2fs_ipb)156157/*158* NINDIR is the number of indirects in a file system block.159*/160#define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs))161162/*163* Use if additional debug logging is required.164*/165/* #define EXT2FS_PRINT_EXTENTS */166167#endif /* !_FS_EXT2FS_FS_H_ */168169170