2005-01-06 18:27:30 +00:00
|
|
|
/*-
|
1995-11-05 23:25:12 +00:00
|
|
|
* modified for EXT2FS support in Lites 1.1
|
|
|
|
*
|
|
|
|
* Aug 1995, Godmar Back (gback@cs.utah.edu)
|
|
|
|
* University of Utah, Department of Computer Science
|
|
|
|
*/
|
2005-01-06 18:27:30 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1995-11-05 23:25:12 +00:00
|
|
|
* Copyright (c) 1982, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2016-12-02 19:47:23 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-11-05 23:25:12 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)fs.h 8.7 (Berkeley) 4/19/94
|
2000-11-10 14:54:15 +00:00
|
|
|
* $FreeBSD$
|
1995-11-05 23:25:12 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-16 15:47:43 +00:00
|
|
|
#ifndef _FS_EXT2FS_FS_H_
|
2014-02-28 21:25:32 +00:00
|
|
|
#define _FS_EXT2FS_FS_H_
|
2011-12-16 15:47:43 +00:00
|
|
|
|
1995-11-05 23:25:12 +00:00
|
|
|
/*
|
|
|
|
* Each disk drive contains some number of file systems.
|
|
|
|
* A file system consists of a number of cylinder groups.
|
|
|
|
* Each cylinder group has inodes and data.
|
|
|
|
*
|
|
|
|
* A file system is described by its super-block, which in turn
|
|
|
|
* describes the cylinder groups. The super-block is critical
|
|
|
|
* data and is replicated in each cylinder group to protect against
|
|
|
|
* catastrophic loss. This is done at `newfs' time and the critical
|
|
|
|
* super-block data does not change, so the copies need not be
|
|
|
|
* referenced further unless disaster strikes.
|
|
|
|
*
|
|
|
|
* The first boot and super blocks are given in absolute disk addresses.
|
|
|
|
* The byte-offset forms are preferred, as they don't imply a sector size.
|
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define SBSIZE 1024
|
|
|
|
#define SBLOCK 2
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The path name on which the file system is mounted is maintained
|
2016-12-28 15:43:17 +00:00
|
|
|
* in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
|
|
|
|
* the super block for this name.
|
1995-11-05 23:25:12 +00:00
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define MAXMNTLEN 512
|
1995-11-05 23:25:12 +00:00
|
|
|
|
2013-06-16 16:10:45 +00:00
|
|
|
/*
|
|
|
|
* A summary of contiguous blocks of various sizes is maintained
|
|
|
|
* in each cylinder group. Normally this is set by the initial
|
|
|
|
* value of fs_maxcontig.
|
|
|
|
*
|
|
|
|
* XXX:FS_MAXCONTIG is set to 16 to conserve space. Here we set
|
|
|
|
* EXT2_MAXCONTIG to 32 for better performance.
|
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define EXT2_MAXCONTIG 32
|
2013-06-16 16:10:45 +00:00
|
|
|
|
1995-11-05 23:25:12 +00:00
|
|
|
/*
|
2010-01-14 14:30:54 +00:00
|
|
|
* Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine
|
|
|
|
* tune the layout preferences for directories within a filesystem.
|
|
|
|
* His algorithm can be tuned by adjusting the following parameters
|
|
|
|
* which tell the system the average file size and the average number
|
|
|
|
* of files per directory. These defaults are well selected for typical
|
|
|
|
* filesystems, but may need to be tuned for odd cases like filesystems
|
|
|
|
* being used for squid caches or news spools.
|
2016-12-28 15:43:17 +00:00
|
|
|
* AVFPDIR is the expected number of files per directory. AVGDIRSIZE is
|
|
|
|
* obtained by multiplying AVFPDIR and AVFILESIZ which is assumed to be
|
2010-01-14 14:30:54 +00:00
|
|
|
* 16384.
|
1995-11-05 23:25:12 +00:00
|
|
|
*/
|
|
|
|
|
2014-02-28 21:25:32 +00:00
|
|
|
#define AFPDIR 64
|
|
|
|
#define AVGDIRSIZE 1048576
|
2010-01-14 14:30:54 +00:00
|
|
|
|
1995-11-05 23:25:12 +00:00
|
|
|
/*
|
2010-01-14 14:30:54 +00:00
|
|
|
* Macros for access to superblock array structures
|
1995-11-05 23:25:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn file system block numbers into disk block addresses.
|
|
|
|
* This maps file system blocks to device size blocks.
|
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->e2fs_fsbtodb)
|
2013-06-23 02:44:42 +00:00
|
|
|
#define dbtofsb(fs, b) ((b) >> (fs)->e2fs_fsbtodb)
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/* get group containing inode */
|
2014-02-28 21:25:32 +00:00
|
|
|
#define ino_to_cg(fs, x) (((x) - 1) / (fs->e2fs_ipg))
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/* get block containing inode from its number x */
|
2014-02-28 21:25:32 +00:00
|
|
|
#define ino_to_fsba(fs, x) \
|
2018-01-05 10:04:01 +00:00
|
|
|
(e2fs_gd_get_i_tables(&(fs)->e2fs_gd[ino_to_cg((fs), (x))]) + \
|
2010-01-14 14:30:54 +00:00
|
|
|
(((x) - 1) % (fs)->e2fs->e2fs_ipg) / (fs)->e2fs_ipb)
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/* get offset for inode in block */
|
2010-01-14 14:30:54 +00:00
|
|
|
#define ino_to_fsbo(fs, x) ((x-1) % (fs->e2fs_ipb))
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Give cylinder group number for a file system block.
|
|
|
|
* Give cylinder group block number for a file system block.
|
|
|
|
*/
|
2010-01-14 14:30:54 +00:00
|
|
|
#define dtog(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) / \
|
1995-11-05 23:25:12 +00:00
|
|
|
EXT2_BLOCKS_PER_GROUP(fs))
|
2010-01-14 14:30:54 +00:00
|
|
|
#define dtogd(fs, d) (((d) - fs->e2fs->e2fs_first_dblock) % \
|
1995-11-05 23:25:12 +00:00
|
|
|
EXT2_BLOCKS_PER_GROUP(fs))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following macros optimize certain frequently calculated
|
|
|
|
* quantities by using shifts and masks in place of divisions
|
|
|
|
* modulos and multiplications.
|
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
|
2010-01-14 14:30:54 +00:00
|
|
|
((loc) & (fs)->e2fs_qbmask)
|
1995-11-05 23:25:12 +00:00
|
|
|
|
2014-02-28 21:25:32 +00:00
|
|
|
#define lblktosize(fs, blk) /* calculates (blk * fs->fs_bsize) */ \
|
2010-01-14 14:30:54 +00:00
|
|
|
((blk) << (fs->e2fs_bshift))
|
1995-11-05 23:25:12 +00:00
|
|
|
|
2014-02-28 21:25:32 +00:00
|
|
|
#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
|
2010-01-14 14:30:54 +00:00
|
|
|
((loc) >> (fs->e2fs_bshift))
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/* no fragments -> logical block number equal # of frags */
|
2014-02-28 21:25:32 +00:00
|
|
|
#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
|
2010-01-14 14:30:54 +00:00
|
|
|
((loc) >> (fs->e2fs_bshift))
|
1995-11-05 23:25:12 +00:00
|
|
|
|
2014-02-28 21:25:32 +00:00
|
|
|
#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
|
2010-01-14 14:30:54 +00:00
|
|
|
roundup(size, fs->e2fs_fsize)
|
1995-11-05 23:25:12 +00:00
|
|
|
/* was (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determining the size of a file block in the file system.
|
|
|
|
* easy w/o fragments
|
|
|
|
*/
|
2014-02-28 21:25:32 +00:00
|
|
|
#define blksize(fs, ip, lbn) ((fs)->e2fs_fsize)
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* INOPB is the number of inodes in a secondary storage block.
|
|
|
|
*/
|
2010-01-14 14:30:54 +00:00
|
|
|
#define INOPB(fs) (fs->e2fs_ipb)
|
1995-11-05 23:25:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NINDIR is the number of indirects in a file system block.
|
|
|
|
*/
|
|
|
|
#define NINDIR(fs) (EXT2_ADDR_PER_BLOCK(fs))
|
|
|
|
|
2018-05-13 19:19:10 +00:00
|
|
|
/*
|
|
|
|
* Use if additional debug logging is required.
|
|
|
|
*/
|
2019-04-16 11:20:10 +00:00
|
|
|
/* #define EXT2FS_PRINT_EXTENTS */
|
2018-05-13 19:19:10 +00:00
|
|
|
|
2016-12-28 15:43:17 +00:00
|
|
|
#endif /* !_FS_EXT2FS_FS_H_ */
|