Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs.h revision 1.29.12.1
      1  1.29.12.1     yamt /*	$NetBSD: ext2fs.h,v 1.29.12.1 2012/10/30 17:22:59 yamt Exp $	*/
      2        1.1   bouyer 
      3        1.1   bouyer /*
      4        1.1   bouyer  * Copyright (c) 1982, 1986, 1993
      5        1.1   bouyer  *	The Regents of the University of California.  All rights reserved.
      6       1.13      agc  *
      7       1.13      agc  * Redistribution and use in source and binary forms, with or without
      8       1.13      agc  * modification, are permitted provided that the following conditions
      9       1.13      agc  * are met:
     10       1.13      agc  * 1. Redistributions of source code must retain the above copyright
     11       1.13      agc  *    notice, this list of conditions and the following disclaimer.
     12       1.13      agc  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.13      agc  *    notice, this list of conditions and the following disclaimer in the
     14       1.13      agc  *    documentation and/or other materials provided with the distribution.
     15       1.13      agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.13      agc  *    may be used to endorse or promote products derived from this software
     17       1.13      agc  *    without specific prior written permission.
     18       1.13      agc  *
     19       1.13      agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.13      agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.13      agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.13      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.13      agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.13      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.13      agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.13      agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.13      agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.13      agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.13      agc  * SUCH DAMAGE.
     30       1.13      agc  *
     31       1.13      agc  *	@(#)fs.h	8.10 (Berkeley) 10/27/94
     32       1.13      agc  *  Modified for ext2fs by Manuel Bouyer.
     33       1.13      agc  */
     34       1.13      agc 
     35       1.13      agc /*
     36       1.13      agc  * Copyright (c) 1997 Manuel Bouyer.
     37        1.1   bouyer  *
     38        1.1   bouyer  * Redistribution and use in source and binary forms, with or without
     39        1.1   bouyer  * modification, are permitted provided that the following conditions
     40        1.1   bouyer  * are met:
     41        1.1   bouyer  * 1. Redistributions of source code must retain the above copyright
     42        1.1   bouyer  *    notice, this list of conditions and the following disclaimer.
     43        1.1   bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     44        1.1   bouyer  *    notice, this list of conditions and the following disclaimer in the
     45        1.1   bouyer  *    documentation and/or other materials provided with the distribution.
     46        1.1   bouyer  *
     47       1.15   bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48       1.15   bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49       1.15   bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50       1.15   bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51       1.15   bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52       1.15   bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53       1.15   bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54       1.15   bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55       1.15   bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56       1.15   bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57        1.1   bouyer  *
     58        1.1   bouyer  *	@(#)fs.h	8.10 (Berkeley) 10/27/94
     59        1.1   bouyer  *  Modified for ext2fs by Manuel Bouyer.
     60        1.1   bouyer  */
     61        1.5   bouyer 
     62       1.11     matt #ifndef _UFS_EXT2FS_EXT2FS_H_
     63       1.11     matt #define _UFS_EXT2FS_EXT2FS_H_
     64       1.11     matt 
     65       1.21      dsl #include <sys/bswap.h>
     66        1.1   bouyer 
     67        1.1   bouyer /*
     68        1.1   bouyer  * Each disk drive contains some number of file systems.
     69        1.1   bouyer  * A file system consists of a number of cylinder groups.
     70        1.1   bouyer  * Each cylinder group has inodes and data.
     71        1.1   bouyer  *
     72        1.1   bouyer  * A file system is described by its super-block, which in turn
     73        1.1   bouyer  * describes the cylinder groups.  The super-block is critical
     74        1.1   bouyer  * data and is replicated in each cylinder group to protect against
     75        1.1   bouyer  * catastrophic loss.  This is done at `newfs' time and the critical
     76        1.1   bouyer  * super-block data does not change, so the copies need not be
     77        1.1   bouyer  * referenced further unless disaster strikes.
     78        1.1   bouyer  *
     79        1.1   bouyer  * The first boot and super blocks are given in absolute disk addresses.
     80        1.1   bouyer  * The byte-offset forms are preferred, as they don't imply a sector size.
     81        1.1   bouyer  */
     82        1.1   bouyer #define BBSIZE		1024
     83        1.1   bouyer #define SBSIZE		1024
     84        1.1   bouyer #define	BBOFF		((off_t)(0))
     85        1.1   bouyer #define	SBOFF		((off_t)(BBOFF + BBSIZE))
     86       1.12     fvdl #define	BBLOCK		((daddr_t)(0))
     87       1.12     fvdl #define	SBLOCK		((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
     88        1.1   bouyer 
     89        1.1   bouyer /*
     90        1.1   bouyer  * Addresses stored in inodes are capable of addressing blocks
     91        1.1   bouyer  * XXX
     92        1.1   bouyer  */
     93        1.1   bouyer 
     94        1.1   bouyer /*
     95        1.1   bouyer  * MINBSIZE is the smallest allowable block size.
     96        1.1   bouyer  * MINBSIZE must be big enough to hold a cylinder group block,
     97        1.1   bouyer  * thus changes to (struct cg) must keep its size within MINBSIZE.
     98        1.1   bouyer  * Note that super blocks are always of size SBSIZE,
     99        1.1   bouyer  * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
    100        1.1   bouyer  */
    101       1.25  tsutsui #define LOG_MINBSIZE	10
    102        1.1   bouyer #define MINBSIZE	(1 << LOG_MINBSIZE)
    103        1.1   bouyer 
    104        1.1   bouyer /*
    105        1.1   bouyer  * The path name on which the file system is mounted is maintained
    106        1.1   bouyer  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
    107        1.1   bouyer  * the super block for this name.
    108        1.1   bouyer  */
    109        1.1   bouyer #define MAXMNTLEN	512
    110        1.1   bouyer 
    111        1.1   bouyer /*
    112        1.1   bouyer  * MINFREE gives the minimum acceptable percentage of file system
    113        1.1   bouyer  * blocks which may be free. If the freelist drops below this level
    114        1.1   bouyer  * only the superuser may continue to allocate blocks. This may
    115        1.1   bouyer  * be set to 0 if no reserve of free blocks is deemed necessary,
    116        1.1   bouyer  * however throughput drops by fifty percent if the file system
    117        1.1   bouyer  * is run at between 95% and 100% full; thus the minimum default
    118        1.1   bouyer  * value of fs_minfree is 5%. However, to get good clustering
    119        1.1   bouyer  * performance, 10% is a better choice. hence we use 10% as our
    120        1.1   bouyer  * default value. With 10% free space, fragmentation is not a
    121        1.1   bouyer  * problem, so we choose to optimize for time.
    122        1.1   bouyer  */
    123        1.1   bouyer #define MINFREE		5
    124        1.1   bouyer 
    125        1.1   bouyer /*
    126        1.1   bouyer  * Super block for an ext2fs file system.
    127        1.1   bouyer  */
    128        1.1   bouyer struct ext2fs {
    129       1.27  tsutsui 	uint32_t  e2fs_icount;		/* Inode count */
    130       1.27  tsutsui 	uint32_t  e2fs_bcount;		/* blocks count */
    131       1.27  tsutsui 	uint32_t  e2fs_rbcount;		/* reserved blocks count */
    132       1.27  tsutsui 	uint32_t  e2fs_fbcount;		/* free blocks count */
    133       1.27  tsutsui 	uint32_t  e2fs_ficount;		/* free inodes count */
    134       1.27  tsutsui 	uint32_t  e2fs_first_dblock;	/* first data block */
    135       1.27  tsutsui 	uint32_t  e2fs_log_bsize;	/* block size = 1024*(2^e2fs_log_bsize) */
    136       1.27  tsutsui 	uint32_t  e2fs_fsize;		/* fragment size */
    137       1.27  tsutsui 	uint32_t  e2fs_bpg;		/* blocks per group */
    138       1.27  tsutsui 	uint32_t  e2fs_fpg;		/* frags per group */
    139       1.27  tsutsui 	uint32_t  e2fs_ipg;		/* inodes per group */
    140       1.27  tsutsui 	uint32_t  e2fs_mtime;		/* mount time */
    141       1.27  tsutsui 	uint32_t  e2fs_wtime;		/* write time */
    142       1.27  tsutsui 	uint16_t  e2fs_mnt_count;	/* mount count */
    143       1.27  tsutsui 	uint16_t  e2fs_max_mnt_count;	/* max mount count */
    144       1.27  tsutsui 	uint16_t  e2fs_magic;		/* magic number */
    145       1.27  tsutsui 	uint16_t  e2fs_state;		/* file system state */
    146       1.27  tsutsui 	uint16_t  e2fs_beh;		/* behavior on errors */
    147       1.27  tsutsui 	uint16_t  e2fs_minrev;		/* minor revision level */
    148       1.27  tsutsui 	uint32_t  e2fs_lastfsck;	/* time of last fsck */
    149       1.27  tsutsui 	uint32_t  e2fs_fsckintv;	/* max time between fscks */
    150       1.27  tsutsui 	uint32_t  e2fs_creator;		/* creator OS */
    151       1.27  tsutsui 	uint32_t  e2fs_rev;		/* revision level */
    152       1.27  tsutsui 	uint16_t  e2fs_ruid;		/* default uid for reserved blocks */
    153       1.27  tsutsui 	uint16_t  e2fs_rgid;		/* default gid for reserved blocks */
    154        1.8   bouyer 	/* EXT2_DYNAMIC_REV superblocks */
    155       1.27  tsutsui 	uint32_t  e2fs_first_ino;	/* first non-reserved inode */
    156       1.27  tsutsui 	uint16_t  e2fs_inode_size;	/* size of inode structure */
    157       1.27  tsutsui 	uint16_t  e2fs_block_group_nr;	/* block grp number of this sblk*/
    158       1.27  tsutsui 	uint32_t  e2fs_features_compat;	/*  compatible feature set */
    159       1.27  tsutsui 	uint32_t  e2fs_features_incompat; /* incompatible feature set */
    160       1.27  tsutsui 	uint32_t  e2fs_features_rocompat; /* RO-compatible feature set */
    161       1.27  tsutsui 	uint8_t   e2fs_uuid[16];	/* 128-bit uuid for volume */
    162       1.27  tsutsui 	char      e2fs_vname[16];	/* volume name */
    163       1.27  tsutsui 	char      e2fs_fsmnt[64];	/* name mounted on */
    164       1.27  tsutsui 	uint32_t  e2fs_algo;		/* For compression */
    165       1.27  tsutsui 	uint8_t   e2fs_prealloc;	/* # of blocks to preallocate */
    166       1.27  tsutsui 	uint8_t   e2fs_dir_prealloc;	/* # of blocks to preallocate for dir */
    167       1.27  tsutsui 	uint16_t  e2fs_reserved_ngdb;	/* # of reserved gd blocks for resize */
    168       1.27  tsutsui 	uint32_t  reserved2[204];
    169        1.1   bouyer };
    170        1.1   bouyer 
    171        1.1   bouyer 
    172        1.1   bouyer /* in-memory data for ext2fs */
    173        1.1   bouyer struct m_ext2fs {
    174        1.1   bouyer 	struct ext2fs e2fs;
    175        1.1   bouyer 	u_char	e2fs_fsmnt[MAXMNTLEN];	/* name mounted on */
    176        1.8   bouyer 	int8_t	e2fs_ronly;	/* mounted read-only flag */
    177        1.8   bouyer 	int8_t	e2fs_fmod;	/* super block modified flag */
    178        1.8   bouyer 	int32_t	e2fs_bsize;	/* block size */
    179        1.8   bouyer 	int32_t e2fs_bshift;	/* ``lblkno'' calc of logical blkno */
    180        1.8   bouyer 	int32_t e2fs_bmask;	/* ``blkoff'' calc of blk offsets */
    181        1.8   bouyer 	int64_t e2fs_qbmask;	/* ~fs_bmask - for use with quad size */
    182        1.8   bouyer 	int32_t	e2fs_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
    183        1.8   bouyer 	int32_t	e2fs_ncg;	/* number of cylinder groups */
    184        1.8   bouyer 	int32_t	e2fs_ngdb;	/* number of group descriptor block */
    185        1.8   bouyer 	int32_t	e2fs_ipb;	/* number of inodes per block */
    186        1.8   bouyer 	int32_t	e2fs_itpg;	/* number of inode table per group */
    187        1.8   bouyer 	struct	ext2_gd *e2fs_gd; /* group descripors */
    188        1.1   bouyer };
    189        1.1   bouyer 
    190        1.1   bouyer 
    191        1.1   bouyer 
    192        1.1   bouyer /*
    193        1.1   bouyer  * Filesystem identification
    194        1.1   bouyer  */
    195        1.1   bouyer #define	E2FS_MAGIC	0xef53	/* the ext2fs magic number */
    196       1.23  tsutsui #define E2FS_REV0	0	/* GOOD_OLD revision */
    197       1.23  tsutsui #define E2FS_REV1	1	/* Support compat/incompat features */
    198        1.9   bouyer 
    199       1.23  tsutsui /* compatible/incompatible features */
    200        1.9   bouyer #define EXT2F_COMPAT_PREALLOC		0x0001
    201  1.29.12.1     yamt #define EXT2F_COMPAT_AFS		0x0002
    202       1.29  tsutsui #define EXT2F_COMPAT_HASJOURNAL		0x0004
    203  1.29.12.1     yamt #define EXT2F_COMPAT_EXTATTR		0x0008
    204       1.24  tsutsui #define EXT2F_COMPAT_RESIZE		0x0010
    205  1.29.12.1     yamt #define EXT2F_COMPAT_DIRHASHINDEX	0x0020
    206  1.29.12.1     yamt #define	EXT2F_COMPAT_BITS \
    207  1.29.12.1     yamt 	"\20" \
    208  1.29.12.1     yamt         "\06COMPAT_DIRHASHINDEX" \
    209  1.29.12.1     yamt 	"\05COMPAT_RESIZE" \
    210  1.29.12.1     yamt 	"\04COMPAT_EXTATTR" \
    211  1.29.12.1     yamt 	"\03COMPAT_HASJOURNAL" \
    212  1.29.12.1     yamt 	"\02COMPAT_AFS" \
    213  1.29.12.1     yamt 	"\01COMPAT_PREALLOC"
    214        1.9   bouyer 
    215        1.9   bouyer #define EXT2F_ROCOMPAT_SPARSESUPER	0x0001
    216        1.9   bouyer #define EXT2F_ROCOMPAT_LARGEFILE	0x0002
    217        1.9   bouyer #define EXT2F_ROCOMPAT_BTREE_DIR	0x0004
    218  1.29.12.1     yamt #define	EXT2F_ROCOMPAT_BITS \
    219  1.29.12.1     yamt 	"\20" \
    220  1.29.12.1     yamt 	"\03ROCOMPAT_BTREE_DIR" \
    221  1.29.12.1     yamt 	"\02ROCOMPAT_LARGEFILE" \
    222  1.29.12.1     yamt 	"\01ROCOMPAT_SPARSEBUFFER"
    223        1.9   bouyer 
    224        1.9   bouyer #define EXT2F_INCOMPAT_COMP		0x0001
    225        1.9   bouyer #define EXT2F_INCOMPAT_FTYPE		0x0002
    226  1.29.12.1     yamt #define	EXT2F_INCOMPAT_REPLAY_JOURNAL	0x0004
    227  1.29.12.1     yamt #define	EXT2F_INCOMPAT_USES_JOURNAL	0x0008
    228  1.29.12.1     yamt #define	EXT2F_INCOMPAT_BITS \
    229  1.29.12.1     yamt 	"\20" \
    230  1.29.12.1     yamt 	"\04INCOMPAT_USES_JOURNAL" \
    231  1.29.12.1     yamt 	"\03INCOMPAT_REPLAY_JOURNAL" \
    232  1.29.12.1     yamt 	"\02INCOMPAT_FTYPE" \
    233  1.29.12.1     yamt 	"\01INCOMPAT_COMP"
    234        1.9   bouyer 
    235       1.23  tsutsui /*
    236       1.23  tsutsui  * Features supported in this implementation
    237       1.23  tsutsui  *
    238       1.23  tsutsui  * We support the following REV1 features:
    239       1.23  tsutsui  * - EXT2F_ROCOMPAT_SPARSESUPER
    240       1.23  tsutsui  *    superblock backups stored only in cg_has_sb(bno) groups
    241       1.23  tsutsui  * - EXT2F_ROCOMPAT_LARGEFILE
    242       1.23  tsutsui  *    use e2di_dacl in struct ext2fs_dinode to store
    243       1.23  tsutsui  *    upper 32bit of size for >2GB files
    244       1.23  tsutsui  * - EXT2F_INCOMPAT_FTYPE
    245       1.23  tsutsui  *    store file type to e2d_type in struct ext2fs_direct
    246       1.23  tsutsui  *    (on REV0 e2d_namlen is uint16_t and no e2d_type, like ffs)
    247       1.23  tsutsui  */
    248        1.9   bouyer #define EXT2F_COMPAT_SUPP		0x0000
    249       1.16       ws #define EXT2F_ROCOMPAT_SUPP		(EXT2F_ROCOMPAT_SPARSESUPER \
    250       1.16       ws 					 | EXT2F_ROCOMPAT_LARGEFILE)
    251        1.9   bouyer #define EXT2F_INCOMPAT_SUPP		EXT2F_INCOMPAT_FTYPE
    252        1.1   bouyer 
    253        1.1   bouyer /*
    254       1.23  tsutsui  * Definitions of behavior on errors
    255       1.23  tsutsui  */
    256       1.23  tsutsui #define E2FS_BEH_CONTINUE	1	/* continue operation */
    257       1.23  tsutsui #define E2FS_BEH_READONLY	2	/* remount fs read only */
    258       1.23  tsutsui #define E2FS_BEH_PANIC		3	/* cause panic */
    259       1.23  tsutsui #define E2FS_BEH_DEFAULT	E2FS_BEH_CONTINUE
    260       1.23  tsutsui 
    261       1.23  tsutsui /*
    262        1.1   bouyer  * OS identification
    263        1.1   bouyer  */
    264       1.23  tsutsui #define E2FS_OS_LINUX	0
    265       1.23  tsutsui #define E2FS_OS_HURD	1
    266       1.23  tsutsui #define E2FS_OS_MASIX	2
    267       1.23  tsutsui #define E2FS_OS_FREEBSD	3
    268       1.23  tsutsui #define E2FS_OS_LITES	4
    269        1.1   bouyer 
    270        1.1   bouyer /*
    271        1.1   bouyer  * Filesystem clean flags
    272        1.1   bouyer  */
    273        1.1   bouyer #define	E2FS_ISCLEAN	0x01
    274        1.9   bouyer #define	E2FS_ERRORS	0x02
    275        1.1   bouyer 
    276        1.1   bouyer /* ext2 file system block group descriptor */
    277        1.1   bouyer 
    278        1.1   bouyer struct ext2_gd {
    279       1.27  tsutsui 	uint32_t ext2bgd_b_bitmap;	/* blocks bitmap block */
    280       1.27  tsutsui 	uint32_t ext2bgd_i_bitmap;	/* inodes bitmap block */
    281       1.27  tsutsui 	uint32_t ext2bgd_i_tables;	/* inodes table block  */
    282       1.27  tsutsui 	uint16_t ext2bgd_nbfree;	/* number of free blocks */
    283       1.27  tsutsui 	uint16_t ext2bgd_nifree;	/* number of free inodes */
    284       1.27  tsutsui 	uint16_t ext2bgd_ndirs;		/* number of directories */
    285       1.27  tsutsui 	uint16_t reserved;
    286       1.27  tsutsui 	uint32_t reserved2[3];
    287        1.1   bouyer };
    288       1.10   bouyer 
    289       1.10   bouyer 
    290       1.10   bouyer /*
    291       1.10   bouyer  * If the EXT2F_ROCOMPAT_SPARSESUPER flag is set, the cylinder group has a
    292       1.10   bouyer  * copy of the super and cylinder group descriptors blocks only if it's
    293       1.23  tsutsui  * 1, a power of 3, 5 or 7
    294       1.10   bouyer  */
    295       1.10   bouyer 
    296       1.26    perry static __inline int cg_has_sb(int) __unused;
    297       1.22    perry static __inline int
    298       1.25  tsutsui cg_has_sb(int i)
    299       1.10   bouyer {
    300       1.25  tsutsui 	int a3, a5, a7;
    301       1.10   bouyer 
    302       1.10   bouyer 	if (i == 0 || i == 1)
    303       1.10   bouyer 		return 1;
    304       1.10   bouyer 	for (a3 = 3, a5 = 5, a7 = 7;
    305       1.10   bouyer 	    a3 <= i || a5 <= i || a7 <= i;
    306       1.10   bouyer 	    a3 *= 3, a5 *= 5, a7 *= 7)
    307       1.10   bouyer 		if (i == a3 || i == a5 || i == a7)
    308       1.10   bouyer 			return 1;
    309       1.10   bouyer 	return 0;
    310       1.10   bouyer }
    311        1.2   bouyer 
    312        1.2   bouyer /* EXT2FS metadatas are stored in little-endian byte order. These macros
    313        1.2   bouyer  * helps reading theses metadatas
    314        1.2   bouyer  */
    315        1.2   bouyer 
    316        1.2   bouyer #if BYTE_ORDER == LITTLE_ENDIAN
    317        1.2   bouyer #	define h2fs16(x) (x)
    318        1.2   bouyer #	define h2fs32(x) (x)
    319       1.12     fvdl #	define h2fs64(x) (x)
    320        1.2   bouyer #	define fs2h16(x) (x)
    321        1.2   bouyer #	define fs2h32(x) (x)
    322       1.12     fvdl #	define fs2h64(x) (x)
    323        1.4    perry #	define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE);
    324        1.4    perry #	define e2fs_cgload(old, new, size) memcpy((new), (old), (size));
    325        1.4    perry #	define e2fs_sbsave(old, new) memcpy((new), (old), SBSIZE);
    326        1.4    perry #	define e2fs_cgsave(old, new, size) memcpy((new), (old), (size));
    327        1.2   bouyer #else
    328       1.18  xtraeme void e2fs_sb_bswap(struct ext2fs *, struct ext2fs *);
    329       1.18  xtraeme void e2fs_cg_bswap(struct ext2_gd *, struct ext2_gd *, int);
    330        1.2   bouyer #	define h2fs16(x) bswap16(x)
    331        1.2   bouyer #	define h2fs32(x) bswap32(x)
    332       1.12     fvdl #	define h2fs64(x) bswap64(x)
    333        1.2   bouyer #	define fs2h16(x) bswap16(x)
    334        1.2   bouyer #	define fs2h32(x) bswap32(x)
    335       1.12     fvdl #	define fs2h64(x) bswap64(x)
    336        1.2   bouyer #	define e2fs_sbload(old, new) e2fs_sb_bswap((old), (new))
    337        1.2   bouyer #	define e2fs_cgload(old, new, size) e2fs_cg_bswap((old), (new), (size));
    338        1.2   bouyer #	define e2fs_sbsave(old, new) e2fs_sb_bswap((old), (new))
    339        1.2   bouyer #	define e2fs_cgsave(old, new, size) e2fs_cg_bswap((old), (new), (size));
    340        1.2   bouyer #endif
    341        1.1   bouyer 
    342        1.1   bouyer /*
    343        1.1   bouyer  * Turn file system block numbers into disk block addresses.
    344        1.1   bouyer  * This maps file system blocks to device size blocks.
    345        1.1   bouyer  */
    346        1.1   bouyer #define fsbtodb(fs, b)	((b) << (fs)->e2fs_fsbtodb)
    347        1.1   bouyer #define dbtofsb(fs, b)	((b) >> (fs)->e2fs_fsbtodb)
    348        1.1   bouyer 
    349        1.1   bouyer /*
    350        1.1   bouyer  * Macros for handling inode numbers:
    351        1.1   bouyer  *	 inode number to file system block offset.
    352        1.1   bouyer  *	 inode number to cylinder group number.
    353        1.1   bouyer  *	 inode number to file system block address.
    354        1.1   bouyer  */
    355        1.1   bouyer #define	ino_to_cg(fs, x)	(((x) - 1) / (fs)->e2fs.e2fs_ipg)
    356        1.1   bouyer #define	ino_to_fsba(fs, x)						\
    357       1.25  tsutsui 	((fs)->e2fs_gd[ino_to_cg((fs), (x))].ext2bgd_i_tables +		\
    358       1.25  tsutsui 	(((x) - 1) % (fs)->e2fs.e2fs_ipg) / (fs)->e2fs_ipb)
    359       1.25  tsutsui #define	ino_to_fsbo(fs, x)	(((x) - 1) % (fs)->e2fs_ipb)
    360        1.1   bouyer 
    361        1.1   bouyer /*
    362        1.1   bouyer  * Give cylinder group number for a file system block.
    363        1.1   bouyer  * Give cylinder group block number for a file system block.
    364        1.1   bouyer  */
    365        1.1   bouyer #define	dtog(fs, d) (((d) - (fs)->e2fs.e2fs_first_dblock) / (fs)->e2fs.e2fs_fpg)
    366        1.1   bouyer #define	dtogd(fs, d) \
    367        1.1   bouyer 	(((d) - (fs)->e2fs.e2fs_first_dblock) % (fs)->e2fs.e2fs_fpg)
    368        1.1   bouyer 
    369        1.1   bouyer /*
    370        1.1   bouyer  * The following macros optimize certain frequently calculated
    371        1.1   bouyer  * quantities by using shifts and masks in place of divisions
    372        1.1   bouyer  * modulos and multiplications.
    373        1.1   bouyer  */
    374        1.1   bouyer #define blkoff(fs, loc)		/* calculates (loc % fs->e2fs_bsize) */ \
    375        1.1   bouyer 	((loc) & (fs)->e2fs_qbmask)
    376        1.1   bouyer #define lblktosize(fs, blk)	/* calculates (blk * fs->e2fs_bsize) */ \
    377        1.1   bouyer 	((blk) << (fs)->e2fs_bshift)
    378        1.1   bouyer #define lblkno(fs, loc)		/* calculates (loc / fs->e2fs_bsize) */ \
    379        1.1   bouyer 	((loc) >> (fs)->e2fs_bshift)
    380        1.1   bouyer #define blkroundup(fs, size)	/* calculates roundup(size, fs->e2fs_bsize) */ \
    381        1.1   bouyer 	(((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
    382        1.1   bouyer #define fragroundup(fs, size)	/* calculates roundup(size, fs->e2fs_bsize) */ \
    383        1.1   bouyer 	(((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask)
    384       1.17    perry /*
    385        1.1   bouyer  * Determine the number of available frags given a
    386        1.1   bouyer  * percentage to hold in reserve.
    387       1.17    perry  */
    388        1.1   bouyer #define freespace(fs) \
    389       1.17    perry    ((fs)->e2fs.e2fs_fbcount - (fs)->e2fs.e2fs_rbcount)
    390        1.1   bouyer 
    391        1.1   bouyer /*
    392        1.1   bouyer  * Number of indirects in a file system block.
    393        1.1   bouyer  */
    394       1.27  tsutsui #define	NINDIR(fs)	((fs)->e2fs_bsize / sizeof(uint32_t))
    395       1.11     matt 
    396       1.11     matt #endif /* !_UFS_EXT2FS_EXT2FS_H_ */
    397