1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifndef _SYS_FS_UFS_FS_H 41*7c478bd9Sstevel@tonic-gate #define _SYS_FS_UFS_FS_H 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/types32.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> /* for kmutex_t */ 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 50*7c478bd9Sstevel@tonic-gate extern "C" { 51*7c478bd9Sstevel@tonic-gate #endif 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* 54*7c478bd9Sstevel@tonic-gate * The following values are minor release values for UFS. 55*7c478bd9Sstevel@tonic-gate * The fs_version field in the superblock will equal one of them 56*7c478bd9Sstevel@tonic-gate * if the file system's magic number is MTB_UFS_MAGIC. 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #define MTB_UFS_VERSION_MIN 1 60*7c478bd9Sstevel@tonic-gate #define MTB_UFS_VERSION_1 1 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * Each disk drive contains some number of file systems. 64*7c478bd9Sstevel@tonic-gate * A file system consists of a number of cylinder groups. 65*7c478bd9Sstevel@tonic-gate * Each cylinder group has inodes and data. 66*7c478bd9Sstevel@tonic-gate * 67*7c478bd9Sstevel@tonic-gate * A file system is described by its super-block, which in turn 68*7c478bd9Sstevel@tonic-gate * describes the cylinder groups. The super-block is critical 69*7c478bd9Sstevel@tonic-gate * data and is replicated in the first 10 cylinder groups and the 70*7c478bd9Sstevel@tonic-gate * the last 10 cylinder groups to protect against 71*7c478bd9Sstevel@tonic-gate * catastrophic loss. This is done at mkfs time and the critical 72*7c478bd9Sstevel@tonic-gate * super-block data does not change, so the copies need not be 73*7c478bd9Sstevel@tonic-gate * referenced further unless disaster strikes. 74*7c478bd9Sstevel@tonic-gate * 75*7c478bd9Sstevel@tonic-gate * For file system fs, the offsets of the various blocks of interest 76*7c478bd9Sstevel@tonic-gate * are given in the super block as: 77*7c478bd9Sstevel@tonic-gate * [fs->fs_sblkno] Super-block 78*7c478bd9Sstevel@tonic-gate * [fs->fs_cblkno] Cylinder group block 79*7c478bd9Sstevel@tonic-gate * [fs->fs_iblkno] Inode blocks 80*7c478bd9Sstevel@tonic-gate * [fs->fs_dblkno] Data blocks 81*7c478bd9Sstevel@tonic-gate * The beginning of cylinder group cg in fs, is given by 82*7c478bd9Sstevel@tonic-gate * the ``cgbase(fs, cg)'' macro. 83*7c478bd9Sstevel@tonic-gate * 84*7c478bd9Sstevel@tonic-gate * The first boot and super blocks are given in absolute disk addresses. 85*7c478bd9Sstevel@tonic-gate * The byte-offset forms are preferred, as they don't imply a sector size. 86*7c478bd9Sstevel@tonic-gate */ 87*7c478bd9Sstevel@tonic-gate #define BBSIZE 8192 88*7c478bd9Sstevel@tonic-gate #define SBSIZE 8192 89*7c478bd9Sstevel@tonic-gate #define BBOFF ((off_t)(0)) 90*7c478bd9Sstevel@tonic-gate #define SBOFF ((off_t)(BBOFF + BBSIZE)) 91*7c478bd9Sstevel@tonic-gate #define BBLOCK ((daddr32_t)(0)) 92*7c478bd9Sstevel@tonic-gate #define SBLOCK ((daddr32_t)(BBLOCK + BBSIZE / DEV_BSIZE)) 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * Addresses stored in inodes are capable of addressing fragments 96*7c478bd9Sstevel@tonic-gate * of `blocks'. File system blocks of at most size MAXBSIZE can 97*7c478bd9Sstevel@tonic-gate * be optionally broken into 2, 4, or 8 pieces, each of which is 98*7c478bd9Sstevel@tonic-gate * addressible; these pieces may be DEV_BSIZE, or some multiple of 99*7c478bd9Sstevel@tonic-gate * a DEV_BSIZE unit. 100*7c478bd9Sstevel@tonic-gate * 101*7c478bd9Sstevel@tonic-gate * Large files consist of exclusively large data blocks. To avoid 102*7c478bd9Sstevel@tonic-gate * undue wasted disk space, the last data block of a small file may be 103*7c478bd9Sstevel@tonic-gate * allocated as only as many fragments of a large block as are 104*7c478bd9Sstevel@tonic-gate * necessary. The file system format retains only a single pointer 105*7c478bd9Sstevel@tonic-gate * to such a fragment, which is a piece of a single large block that 106*7c478bd9Sstevel@tonic-gate * has been divided. The size of such a fragment is determinable from 107*7c478bd9Sstevel@tonic-gate * information in the inode, using the ``blksize(fs, ip, lbn)'' macro. 108*7c478bd9Sstevel@tonic-gate * 109*7c478bd9Sstevel@tonic-gate * The file system records space availability at the fragment level; 110*7c478bd9Sstevel@tonic-gate * to determine block availability, aligned fragments are examined. 111*7c478bd9Sstevel@tonic-gate * 112*7c478bd9Sstevel@tonic-gate * The root inode is the root of the file system. 113*7c478bd9Sstevel@tonic-gate * Inode 0 can't be used for normal purposes and 114*7c478bd9Sstevel@tonic-gate * historically bad blocks were linked to inode 1, 115*7c478bd9Sstevel@tonic-gate * thus the root inode is 2. (inode 1 is no longer used for 116*7c478bd9Sstevel@tonic-gate * this purpose, however numerous dump tapes make this 117*7c478bd9Sstevel@tonic-gate * assumption, so we are stuck with it) 118*7c478bd9Sstevel@tonic-gate * The lost+found directory is given the next available 119*7c478bd9Sstevel@tonic-gate * inode when it is created by ``mkfs''. 120*7c478bd9Sstevel@tonic-gate */ 121*7c478bd9Sstevel@tonic-gate #define UFSROOTINO ((ino_t)2) /* i number of all roots */ 122*7c478bd9Sstevel@tonic-gate #define LOSTFOUNDINO (UFSROOTINO + 1) 123*7c478bd9Sstevel@tonic-gate #ifndef _LONGLONG_TYPE 124*7c478bd9Sstevel@tonic-gate #define UFS_MAXOFFSET_T MAXOFF_T 125*7c478bd9Sstevel@tonic-gate #define UFS_FILESIZE_BITS 32 126*7c478bd9Sstevel@tonic-gate #else 127*7c478bd9Sstevel@tonic-gate #define UFS_MAXOFFSET_T ((1LL << NBBY * sizeof (daddr32_t) + DEV_BSHIFT - 1) \ 128*7c478bd9Sstevel@tonic-gate - 1) 129*7c478bd9Sstevel@tonic-gate #define UFS_FILESIZE_BITS 41 130*7c478bd9Sstevel@tonic-gate #endif /* _LONGLONG_TYPE */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * MINBSIZE is the smallest allowable block size. 134*7c478bd9Sstevel@tonic-gate * In order to insure that it is possible to create files of size 135*7c478bd9Sstevel@tonic-gate * 2^32 with only two levels of indirection, MINBSIZE is set to 4096. 136*7c478bd9Sstevel@tonic-gate * MINBSIZE must be big enough to hold a cylinder group block, 137*7c478bd9Sstevel@tonic-gate * thus changes to (struct cg) must keep its size within MINBSIZE. 138*7c478bd9Sstevel@tonic-gate * Note that super blocks are always of size SBSIZE, 139*7c478bd9Sstevel@tonic-gate * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. 140*7c478bd9Sstevel@tonic-gate */ 141*7c478bd9Sstevel@tonic-gate #define MINBSIZE 4096 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate /* 144*7c478bd9Sstevel@tonic-gate * The path name on which the file system is mounted is maintained 145*7c478bd9Sstevel@tonic-gate * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 146*7c478bd9Sstevel@tonic-gate * the super block for this name. 147*7c478bd9Sstevel@tonic-gate * The limit on the amount of summary information per file system 148*7c478bd9Sstevel@tonic-gate * is defined by MAXCSBUFS. It is currently parameterized for a 149*7c478bd9Sstevel@tonic-gate * maximum of two million cylinders. 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate #define MAXMNTLEN 512 152*7c478bd9Sstevel@tonic-gate #define MAXCSBUFS 32 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * Per cylinder group information; summarized in blocks allocated 156*7c478bd9Sstevel@tonic-gate * from first cylinder group data blocks. These blocks have to be 157*7c478bd9Sstevel@tonic-gate * read in from fs_csaddr (size fs_cssize) in addition to the 158*7c478bd9Sstevel@tonic-gate * super block. 159*7c478bd9Sstevel@tonic-gate * 160*7c478bd9Sstevel@tonic-gate * N.B. sizeof (struct csum) must be a power of two in order for 161*7c478bd9Sstevel@tonic-gate * the ``fs_cs'' macro to work (see below). 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate struct csum { 164*7c478bd9Sstevel@tonic-gate int32_t cs_ndir; /* number of directories */ 165*7c478bd9Sstevel@tonic-gate int32_t cs_nbfree; /* number of free blocks */ 166*7c478bd9Sstevel@tonic-gate int32_t cs_nifree; /* number of free inodes */ 167*7c478bd9Sstevel@tonic-gate int32_t cs_nffree; /* number of free frags */ 168*7c478bd9Sstevel@tonic-gate }; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * In the 5.0 release, the file system state flag in the superblock (fs_clean) 172*7c478bd9Sstevel@tonic-gate * is now used. The value of fs_clean can be: 173*7c478bd9Sstevel@tonic-gate * FSACTIVE file system may have fsck inconsistencies 174*7c478bd9Sstevel@tonic-gate * FSCLEAN file system has successfully unmounted (implies 175*7c478bd9Sstevel@tonic-gate * everything is ok) 176*7c478bd9Sstevel@tonic-gate * FSSTABLE No fsck inconsistencies, no guarantee on user data 177*7c478bd9Sstevel@tonic-gate * FSBAD file system is mounted from a partition that is 178*7c478bd9Sstevel@tonic-gate * neither FSCLEAN or FSSTABLE 179*7c478bd9Sstevel@tonic-gate * FSSUSPEND Clean flag processing is temporarily disabled 180*7c478bd9Sstevel@tonic-gate * FSLOG Logging file system 181*7c478bd9Sstevel@tonic-gate * Under this scheme, fsck can safely skip file systems that 182*7c478bd9Sstevel@tonic-gate * are FSCLEAN or FSSTABLE. To provide additional safeguard, 183*7c478bd9Sstevel@tonic-gate * fs_clean information could be trusted only if 184*7c478bd9Sstevel@tonic-gate * fs_state == FSOKAY - fs_time, where FSOKAY is a constant 185*7c478bd9Sstevel@tonic-gate * 186*7c478bd9Sstevel@tonic-gate * Note: mount(2) will now return ENOSPC if fs_clean is neither FSCLEAN nor 187*7c478bd9Sstevel@tonic-gate * FSSTABLE, or fs_state is not valid. The exceptions are the root or 188*7c478bd9Sstevel@tonic-gate * the read-only partitions 189*7c478bd9Sstevel@tonic-gate */ 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate /* 192*7c478bd9Sstevel@tonic-gate * Super block for a file system. 193*7c478bd9Sstevel@tonic-gate * 194*7c478bd9Sstevel@tonic-gate * Most of the data in the super block is read-only data and needs 195*7c478bd9Sstevel@tonic-gate * no explicit locking to protect it. Exceptions are: 196*7c478bd9Sstevel@tonic-gate * fs_time 197*7c478bd9Sstevel@tonic-gate * fs_optim 198*7c478bd9Sstevel@tonic-gate * fs_cstotal 199*7c478bd9Sstevel@tonic-gate * fs_fmod 200*7c478bd9Sstevel@tonic-gate * fs_cgrotor 201*7c478bd9Sstevel@tonic-gate * fs_flags (largefiles flag - set when a file grows large) 202*7c478bd9Sstevel@tonic-gate * These fields require the use of fs->fs_lock. 203*7c478bd9Sstevel@tonic-gate */ 204*7c478bd9Sstevel@tonic-gate #define FS_MAGIC 0x011954 205*7c478bd9Sstevel@tonic-gate #define MTB_UFS_MAGIC 0xdecade 206*7c478bd9Sstevel@tonic-gate #define FSOKAY (0x7c269d38) 207*7c478bd9Sstevel@tonic-gate /* #define FSOKAY (0x7c269d38 + 3) */ 208*7c478bd9Sstevel@tonic-gate /* 209*7c478bd9Sstevel@tonic-gate * fs_clean values 210*7c478bd9Sstevel@tonic-gate */ 211*7c478bd9Sstevel@tonic-gate #define FSACTIVE ((char)0) 212*7c478bd9Sstevel@tonic-gate #define FSCLEAN ((char)0x1) 213*7c478bd9Sstevel@tonic-gate #define FSSTABLE ((char)0x2) 214*7c478bd9Sstevel@tonic-gate #define FSBAD ((char)0xff) /* mounted !FSCLEAN and !FSSTABLE */ 215*7c478bd9Sstevel@tonic-gate #define FSSUSPEND ((char)0xfe) /* temporarily suspended */ 216*7c478bd9Sstevel@tonic-gate #define FSLOG ((char)0xfd) /* logging fs */ 217*7c478bd9Sstevel@tonic-gate #define FSFIX ((char)0xfc) /* being repaired while mounted */ 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate /* 220*7c478bd9Sstevel@tonic-gate * fs_flags values 221*7c478bd9Sstevel@tonic-gate */ 222*7c478bd9Sstevel@tonic-gate #define FSLARGEFILES ((char)0x1) /* largefiles exist on filesystem */ 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate struct fs { 225*7c478bd9Sstevel@tonic-gate uint32_t fs_link; /* linked list of file systems */ 226*7c478bd9Sstevel@tonic-gate uint32_t fs_rolled; /* logging only: fs fully rolled */ 227*7c478bd9Sstevel@tonic-gate daddr32_t fs_sblkno; /* addr of super-block in filesys */ 228*7c478bd9Sstevel@tonic-gate daddr32_t fs_cblkno; /* offset of cyl-block in filesys */ 229*7c478bd9Sstevel@tonic-gate daddr32_t fs_iblkno; /* offset of inode-blocks in filesys */ 230*7c478bd9Sstevel@tonic-gate daddr32_t fs_dblkno; /* offset of first data after cg */ 231*7c478bd9Sstevel@tonic-gate int32_t fs_cgoffset; /* cylinder group offset in cylinder */ 232*7c478bd9Sstevel@tonic-gate int32_t fs_cgmask; /* used to calc mod fs_ntrak */ 233*7c478bd9Sstevel@tonic-gate time32_t fs_time; /* last time written */ 234*7c478bd9Sstevel@tonic-gate int32_t fs_size; /* number of blocks in fs */ 235*7c478bd9Sstevel@tonic-gate int32_t fs_dsize; /* number of data blocks in fs */ 236*7c478bd9Sstevel@tonic-gate int32_t fs_ncg; /* number of cylinder groups */ 237*7c478bd9Sstevel@tonic-gate int32_t fs_bsize; /* size of basic blocks in fs */ 238*7c478bd9Sstevel@tonic-gate int32_t fs_fsize; /* size of frag blocks in fs */ 239*7c478bd9Sstevel@tonic-gate int32_t fs_frag; /* number of frags in a block in fs */ 240*7c478bd9Sstevel@tonic-gate /* these are configuration parameters */ 241*7c478bd9Sstevel@tonic-gate int32_t fs_minfree; /* minimum percentage of free blocks */ 242*7c478bd9Sstevel@tonic-gate int32_t fs_rotdelay; /* num of ms for optimal next block */ 243*7c478bd9Sstevel@tonic-gate int32_t fs_rps; /* disk revolutions per second */ 244*7c478bd9Sstevel@tonic-gate /* these fields can be computed from the others */ 245*7c478bd9Sstevel@tonic-gate int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */ 246*7c478bd9Sstevel@tonic-gate int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */ 247*7c478bd9Sstevel@tonic-gate int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */ 248*7c478bd9Sstevel@tonic-gate int32_t fs_fshift; /* ``numfrags'' calc number of frags */ 249*7c478bd9Sstevel@tonic-gate /* these are configuration parameters */ 250*7c478bd9Sstevel@tonic-gate int32_t fs_maxcontig; /* max number of contiguous blks */ 251*7c478bd9Sstevel@tonic-gate int32_t fs_maxbpg; /* max number of blks per cyl group */ 252*7c478bd9Sstevel@tonic-gate /* these fields can be computed from the others */ 253*7c478bd9Sstevel@tonic-gate int32_t fs_fragshift; /* block to frag shift */ 254*7c478bd9Sstevel@tonic-gate int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 255*7c478bd9Sstevel@tonic-gate int32_t fs_sbsize; /* actual size of super block */ 256*7c478bd9Sstevel@tonic-gate int32_t fs_csmask; /* csum block offset */ 257*7c478bd9Sstevel@tonic-gate int32_t fs_csshift; /* csum block number */ 258*7c478bd9Sstevel@tonic-gate int32_t fs_nindir; /* value of NINDIR */ 259*7c478bd9Sstevel@tonic-gate int32_t fs_inopb; /* value of INOPB */ 260*7c478bd9Sstevel@tonic-gate int32_t fs_nspf; /* value of NSPF */ 261*7c478bd9Sstevel@tonic-gate /* yet another configuration parameter */ 262*7c478bd9Sstevel@tonic-gate int32_t fs_optim; /* optimization preference, see below */ 263*7c478bd9Sstevel@tonic-gate /* these fields are derived from the hardware */ 264*7c478bd9Sstevel@tonic-gate /* USL SVR4 compatibility */ 265*7c478bd9Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN 266*7c478bd9Sstevel@tonic-gate /* 267*7c478bd9Sstevel@tonic-gate * USL SVR4 compatibility 268*7c478bd9Sstevel@tonic-gate * 269*7c478bd9Sstevel@tonic-gate * There was a significant divergence here between Solaris and 270*7c478bd9Sstevel@tonic-gate * SVR4 for x86. By swapping these two members in the superblock, 271*7c478bd9Sstevel@tonic-gate * we get read-only compatibility of SVR4 filesystems. Otherwise 272*7c478bd9Sstevel@tonic-gate * there would be no compatibility. This change was introduced 273*7c478bd9Sstevel@tonic-gate * during bootstrapping of Solaris on x86. By making this ifdef'ed 274*7c478bd9Sstevel@tonic-gate * on byte order, we provide ongoing compatibility across all 275*7c478bd9Sstevel@tonic-gate * platforms with the same byte order, the highest compatibility 276*7c478bd9Sstevel@tonic-gate * that can be achieved. 277*7c478bd9Sstevel@tonic-gate */ 278*7c478bd9Sstevel@tonic-gate int32_t fs_state; /* file system state time stamp */ 279*7c478bd9Sstevel@tonic-gate #else 280*7c478bd9Sstevel@tonic-gate int32_t fs_npsect; /* # sectors/track including spares */ 281*7c478bd9Sstevel@tonic-gate #endif 282*7c478bd9Sstevel@tonic-gate int32_t fs_si; /* summary info state - lufs only */ 283*7c478bd9Sstevel@tonic-gate int32_t fs_trackskew; /* sector 0 skew, per track */ 284*7c478bd9Sstevel@tonic-gate /* a unique id for this filesystem (currently unused and unmaintained) */ 285*7c478bd9Sstevel@tonic-gate /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */ 286*7c478bd9Sstevel@tonic-gate /* Neither of those fields is used in the Tahoe code right now but */ 287*7c478bd9Sstevel@tonic-gate /* there could be problems if they are. */ 288*7c478bd9Sstevel@tonic-gate int32_t fs_id[2]; /* file system id */ 289*7c478bd9Sstevel@tonic-gate /* sizes determined by number of cylinder groups and their sizes */ 290*7c478bd9Sstevel@tonic-gate daddr32_t fs_csaddr; /* blk addr of cyl grp summary area */ 291*7c478bd9Sstevel@tonic-gate int32_t fs_cssize; /* size of cyl grp summary area */ 292*7c478bd9Sstevel@tonic-gate int32_t fs_cgsize; /* cylinder group size */ 293*7c478bd9Sstevel@tonic-gate /* these fields are derived from the hardware */ 294*7c478bd9Sstevel@tonic-gate int32_t fs_ntrak; /* tracks per cylinder */ 295*7c478bd9Sstevel@tonic-gate int32_t fs_nsect; /* sectors per track */ 296*7c478bd9Sstevel@tonic-gate int32_t fs_spc; /* sectors per cylinder */ 297*7c478bd9Sstevel@tonic-gate /* this comes from the disk driver partitioning */ 298*7c478bd9Sstevel@tonic-gate int32_t fs_ncyl; /* cylinders in file system */ 299*7c478bd9Sstevel@tonic-gate /* these fields can be computed from the others */ 300*7c478bd9Sstevel@tonic-gate int32_t fs_cpg; /* cylinders per group */ 301*7c478bd9Sstevel@tonic-gate int32_t fs_ipg; /* inodes per group */ 302*7c478bd9Sstevel@tonic-gate int32_t fs_fpg; /* blocks per group * fs_frag */ 303*7c478bd9Sstevel@tonic-gate /* this data must be re-computed after crashes */ 304*7c478bd9Sstevel@tonic-gate struct csum fs_cstotal; /* cylinder summary information */ 305*7c478bd9Sstevel@tonic-gate /* these fields are cleared at mount time */ 306*7c478bd9Sstevel@tonic-gate char fs_fmod; /* super block modified flag */ 307*7c478bd9Sstevel@tonic-gate char fs_clean; /* file system state flag */ 308*7c478bd9Sstevel@tonic-gate char fs_ronly; /* mounted read-only flag */ 309*7c478bd9Sstevel@tonic-gate char fs_flags; /* largefiles flag, etc. */ 310*7c478bd9Sstevel@tonic-gate char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ 311*7c478bd9Sstevel@tonic-gate /* these fields retain the current block allocation info */ 312*7c478bd9Sstevel@tonic-gate int32_t fs_cgrotor; /* last cg searched */ 313*7c478bd9Sstevel@tonic-gate /* 314*7c478bd9Sstevel@tonic-gate * The following used to be fs_csp[MAXCSBUFS]. It was not 315*7c478bd9Sstevel@tonic-gate * used anywhere except in old utilities. We removed this 316*7c478bd9Sstevel@tonic-gate * in 5.6 and expect fs_u.fs_csp to be used instead. 317*7c478bd9Sstevel@tonic-gate * We no longer limit fs_cssize based on MAXCSBUFS. 318*7c478bd9Sstevel@tonic-gate */ 319*7c478bd9Sstevel@tonic-gate union { /* fs_cs (csum) info */ 320*7c478bd9Sstevel@tonic-gate uint32_t fs_csp_pad[MAXCSBUFS]; 321*7c478bd9Sstevel@tonic-gate struct csum *fs_csp; 322*7c478bd9Sstevel@tonic-gate } fs_u; 323*7c478bd9Sstevel@tonic-gate int32_t fs_cpc; /* cyl per cycle in postbl */ 324*7c478bd9Sstevel@tonic-gate short fs_opostbl[16][8]; /* old rotation block list head */ 325*7c478bd9Sstevel@tonic-gate int32_t fs_sparecon[51]; /* reserved for future constants */ 326*7c478bd9Sstevel@tonic-gate int32_t fs_version; /* minor version of MTB ufs */ 327*7c478bd9Sstevel@tonic-gate int32_t fs_logbno; /* block # of embedded log */ 328*7c478bd9Sstevel@tonic-gate int32_t fs_reclaim; /* reclaim open, deleted files */ 329*7c478bd9Sstevel@tonic-gate int32_t fs_sparecon2; /* reserved for future constant */ 330*7c478bd9Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN 331*7c478bd9Sstevel@tonic-gate /* USL SVR4 compatibility */ 332*7c478bd9Sstevel@tonic-gate int32_t fs_npsect; /* # sectors/track including spares */ 333*7c478bd9Sstevel@tonic-gate #else 334*7c478bd9Sstevel@tonic-gate int32_t fs_state; /* file system state time stamp */ 335*7c478bd9Sstevel@tonic-gate #endif 336*7c478bd9Sstevel@tonic-gate quad_t fs_qbmask; /* ~fs_bmask - for use with quad size */ 337*7c478bd9Sstevel@tonic-gate quad_t fs_qfmask; /* ~fs_fmask - for use with quad size */ 338*7c478bd9Sstevel@tonic-gate int32_t fs_postblformat; /* format of positional layout tables */ 339*7c478bd9Sstevel@tonic-gate int32_t fs_nrpos; /* number of rotaional positions */ 340*7c478bd9Sstevel@tonic-gate int32_t fs_postbloff; /* (short) rotation block list head */ 341*7c478bd9Sstevel@tonic-gate int32_t fs_rotbloff; /* (uchar_t) blocks for each rotation */ 342*7c478bd9Sstevel@tonic-gate int32_t fs_magic; /* magic number */ 343*7c478bd9Sstevel@tonic-gate uchar_t fs_space[1]; /* list of blocks for each rotation */ 344*7c478bd9Sstevel@tonic-gate /* actually longer */ 345*7c478bd9Sstevel@tonic-gate }; 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate /* 348*7c478bd9Sstevel@tonic-gate * values for fs_reclaim 349*7c478bd9Sstevel@tonic-gate */ 350*7c478bd9Sstevel@tonic-gate #define FS_RECLAIM (0x00000001) /* run the reclaim-files thread */ 351*7c478bd9Sstevel@tonic-gate #define FS_RECLAIMING (0x00000002) /* running the reclaim-files thread */ 352*7c478bd9Sstevel@tonic-gate #define FS_CHECKCLEAN (0x00000004) /* checking for a clean file system */ 353*7c478bd9Sstevel@tonic-gate #define FS_CHECKRECLAIM (0x00000008) /* checking for a reclaimable file */ 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate /* 356*7c478bd9Sstevel@tonic-gate * values for fs_rolled 357*7c478bd9Sstevel@tonic-gate */ 358*7c478bd9Sstevel@tonic-gate #define FS_PRE_FLAG 0 /* old system, prior to fs_rolled flag */ 359*7c478bd9Sstevel@tonic-gate #define FS_ALL_ROLLED 1 360*7c478bd9Sstevel@tonic-gate #define FS_NEED_ROLL 2 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate /* 363*7c478bd9Sstevel@tonic-gate * values for fs_si, logging only 364*7c478bd9Sstevel@tonic-gate * si is the summary of the summary - a copy of the cylinder group summary 365*7c478bd9Sstevel@tonic-gate * info held in an array for perf. On a mount if this is out of date 366*7c478bd9Sstevel@tonic-gate * (FS_SI_BAD) it can be re-constructed by re-reading the cgs. 367*7c478bd9Sstevel@tonic-gate */ 368*7c478bd9Sstevel@tonic-gate #define FS_SI_OK 0 /* on-disk summary info ok */ 369*7c478bd9Sstevel@tonic-gate #define FS_SI_BAD 1 /* out of date on-disk si */ 370*7c478bd9Sstevel@tonic-gate 371*7c478bd9Sstevel@tonic-gate /* 372*7c478bd9Sstevel@tonic-gate * Preference for optimization. 373*7c478bd9Sstevel@tonic-gate */ 374*7c478bd9Sstevel@tonic-gate #define FS_OPTTIME 0 /* minimize allocation time */ 375*7c478bd9Sstevel@tonic-gate #define FS_OPTSPACE 1 /* minimize disk fragmentation */ 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate /* 378*7c478bd9Sstevel@tonic-gate * Rotational layout table format types 379*7c478bd9Sstevel@tonic-gate */ 380*7c478bd9Sstevel@tonic-gate #define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */ 381*7c478bd9Sstevel@tonic-gate #define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */ 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate /* 384*7c478bd9Sstevel@tonic-gate * Macros for access to superblock array structures 385*7c478bd9Sstevel@tonic-gate */ 386*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 387*7c478bd9Sstevel@tonic-gate #define fs_postbl(ufsvfsp, cylno) \ 388*7c478bd9Sstevel@tonic-gate (((ufsvfsp)->vfs_fs->fs_postblformat != FS_DYNAMICPOSTBLFMT) \ 389*7c478bd9Sstevel@tonic-gate ? ((ufsvfsp)->vfs_fs->fs_opostbl[cylno]) \ 390*7c478bd9Sstevel@tonic-gate : ((short *)((char *)(ufsvfsp)->vfs_fs + \ 391*7c478bd9Sstevel@tonic-gate (ufsvfsp)->vfs_fs->fs_postbloff) \ 392*7c478bd9Sstevel@tonic-gate + (cylno) * (ufsvfsp)->vfs_nrpos)) 393*7c478bd9Sstevel@tonic-gate #else 394*7c478bd9Sstevel@tonic-gate #define fs_postbl(fs, cylno) \ 395*7c478bd9Sstevel@tonic-gate (((fs)->fs_postblformat != FS_DYNAMICPOSTBLFMT) \ 396*7c478bd9Sstevel@tonic-gate ? ((fs)->fs_opostbl[cylno]) \ 397*7c478bd9Sstevel@tonic-gate : ((short *)((char *)(fs) + \ 398*7c478bd9Sstevel@tonic-gate (fs)->fs_postbloff) \ 399*7c478bd9Sstevel@tonic-gate + (cylno) * (fs)->fs_nrpos)) 400*7c478bd9Sstevel@tonic-gate #endif 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate #define fs_rotbl(fs) \ 403*7c478bd9Sstevel@tonic-gate (((fs)->fs_postblformat != FS_DYNAMICPOSTBLFMT) \ 404*7c478bd9Sstevel@tonic-gate ? ((fs)->fs_space) \ 405*7c478bd9Sstevel@tonic-gate : ((uchar_t *)((char *)(fs) + (fs)->fs_rotbloff))) 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate /* 408*7c478bd9Sstevel@tonic-gate * Convert cylinder group to base address of its global summary info. 409*7c478bd9Sstevel@tonic-gate * 410*7c478bd9Sstevel@tonic-gate * N.B. This macro assumes that sizeof (struct csum) is a power of two. 411*7c478bd9Sstevel@tonic-gate * We just index off the first entry into one big array 412*7c478bd9Sstevel@tonic-gate */ 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate #define fs_cs(fs, indx) fs_u.fs_csp[(indx)] 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate /* 417*7c478bd9Sstevel@tonic-gate * Cylinder group block for a file system. 418*7c478bd9Sstevel@tonic-gate * 419*7c478bd9Sstevel@tonic-gate * Writable fields in the cylinder group are protected by the associated 420*7c478bd9Sstevel@tonic-gate * super block lock fs->fs_lock. 421*7c478bd9Sstevel@tonic-gate */ 422*7c478bd9Sstevel@tonic-gate #define CG_MAGIC 0x090255 423*7c478bd9Sstevel@tonic-gate struct cg { 424*7c478bd9Sstevel@tonic-gate uint32_t cg_link; /* NOT USED linked list of cyl groups */ 425*7c478bd9Sstevel@tonic-gate int32_t cg_magic; /* magic number */ 426*7c478bd9Sstevel@tonic-gate time32_t cg_time; /* time last written */ 427*7c478bd9Sstevel@tonic-gate int32_t cg_cgx; /* we are the cgx'th cylinder group */ 428*7c478bd9Sstevel@tonic-gate short cg_ncyl; /* number of cyl's this cg */ 429*7c478bd9Sstevel@tonic-gate short cg_niblk; /* number of inode blocks this cg */ 430*7c478bd9Sstevel@tonic-gate int32_t cg_ndblk; /* number of data blocks this cg */ 431*7c478bd9Sstevel@tonic-gate struct csum cg_cs; /* cylinder summary information */ 432*7c478bd9Sstevel@tonic-gate int32_t cg_rotor; /* position of last used block */ 433*7c478bd9Sstevel@tonic-gate int32_t cg_frotor; /* position of last used frag */ 434*7c478bd9Sstevel@tonic-gate int32_t cg_irotor; /* position of last used inode */ 435*7c478bd9Sstevel@tonic-gate int32_t cg_frsum[MAXFRAG]; /* counts of available frags */ 436*7c478bd9Sstevel@tonic-gate int32_t cg_btotoff; /* (int32_t)block totals per cylinder */ 437*7c478bd9Sstevel@tonic-gate int32_t cg_boff; /* (short) free block positions */ 438*7c478bd9Sstevel@tonic-gate int32_t cg_iusedoff; /* (char) used inode map */ 439*7c478bd9Sstevel@tonic-gate int32_t cg_freeoff; /* (uchar_t) free block map */ 440*7c478bd9Sstevel@tonic-gate int32_t cg_nextfreeoff; /* (uchar_t) next available space */ 441*7c478bd9Sstevel@tonic-gate int32_t cg_sparecon[16]; /* reserved for future use */ 442*7c478bd9Sstevel@tonic-gate uchar_t cg_space[1]; /* space for cylinder group maps */ 443*7c478bd9Sstevel@tonic-gate /* actually longer */ 444*7c478bd9Sstevel@tonic-gate }; 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate /* 447*7c478bd9Sstevel@tonic-gate * Macros for access to cylinder group array structures 448*7c478bd9Sstevel@tonic-gate */ 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate #define cg_blktot(cgp) \ 451*7c478bd9Sstevel@tonic-gate (((cgp)->cg_magic != CG_MAGIC) \ 452*7c478bd9Sstevel@tonic-gate ? (((struct ocg *)(cgp))->cg_btot) \ 453*7c478bd9Sstevel@tonic-gate : ((int32_t *)((char *)(cgp) + (cgp)->cg_btotoff))) 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 456*7c478bd9Sstevel@tonic-gate #define cg_blks(ufsvfsp, cgp, cylno) \ 457*7c478bd9Sstevel@tonic-gate (((cgp)->cg_magic != CG_MAGIC) \ 458*7c478bd9Sstevel@tonic-gate ? (((struct ocg *)(cgp))->cg_b[cylno]) \ 459*7c478bd9Sstevel@tonic-gate : ((short *)((char *)(cgp) + (cgp)->cg_boff) + \ 460*7c478bd9Sstevel@tonic-gate (cylno) * (ufsvfsp)->vfs_nrpos)) 461*7c478bd9Sstevel@tonic-gate #else 462*7c478bd9Sstevel@tonic-gate #define cg_blks(fs, cgp, cylno) \ 463*7c478bd9Sstevel@tonic-gate (((cgp)->cg_magic != CG_MAGIC) \ 464*7c478bd9Sstevel@tonic-gate ? (((struct ocg *)(cgp))->cg_b[cylno]) \ 465*7c478bd9Sstevel@tonic-gate : ((short *)((char *)(cgp) + (cgp)->cg_boff) + \ 466*7c478bd9Sstevel@tonic-gate (cylno) * (fs)->fs_nrpos)) 467*7c478bd9Sstevel@tonic-gate #endif 468*7c478bd9Sstevel@tonic-gate 469*7c478bd9Sstevel@tonic-gate #define cg_inosused(cgp) \ 470*7c478bd9Sstevel@tonic-gate (((cgp)->cg_magic != CG_MAGIC) \ 471*7c478bd9Sstevel@tonic-gate ? (((struct ocg *)(cgp))->cg_iused) \ 472*7c478bd9Sstevel@tonic-gate : ((char *)((char *)(cgp) + (cgp)->cg_iusedoff))) 473*7c478bd9Sstevel@tonic-gate 474*7c478bd9Sstevel@tonic-gate #define cg_blksfree(cgp) \ 475*7c478bd9Sstevel@tonic-gate (((cgp)->cg_magic != CG_MAGIC) \ 476*7c478bd9Sstevel@tonic-gate ? (((struct ocg *)(cgp))->cg_free) \ 477*7c478bd9Sstevel@tonic-gate : ((uchar_t *)((char *)(cgp) + (cgp)->cg_freeoff))) 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate #define cg_chkmagic(cgp) \ 480*7c478bd9Sstevel@tonic-gate ((cgp)->cg_magic == CG_MAGIC || \ 481*7c478bd9Sstevel@tonic-gate ((struct ocg *)(cgp))->cg_magic == CG_MAGIC) 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate /* 484*7c478bd9Sstevel@tonic-gate * The following structure is defined 485*7c478bd9Sstevel@tonic-gate * for compatibility with old file systems. 486*7c478bd9Sstevel@tonic-gate */ 487*7c478bd9Sstevel@tonic-gate struct ocg { 488*7c478bd9Sstevel@tonic-gate uint32_t cg_link; /* NOT USED linked list of cyl groups */ 489*7c478bd9Sstevel@tonic-gate uint32_t cg_rlink; /* NOT USED incore cyl groups */ 490*7c478bd9Sstevel@tonic-gate time32_t cg_time; /* time last written */ 491*7c478bd9Sstevel@tonic-gate int32_t cg_cgx; /* we are the cgx'th cylinder group */ 492*7c478bd9Sstevel@tonic-gate short cg_ncyl; /* number of cyl's this cg */ 493*7c478bd9Sstevel@tonic-gate short cg_niblk; /* number of inode blocks this cg */ 494*7c478bd9Sstevel@tonic-gate int32_t cg_ndblk; /* number of data blocks this cg */ 495*7c478bd9Sstevel@tonic-gate struct csum cg_cs; /* cylinder summary information */ 496*7c478bd9Sstevel@tonic-gate int32_t cg_rotor; /* position of last used block */ 497*7c478bd9Sstevel@tonic-gate int32_t cg_frotor; /* position of last used frag */ 498*7c478bd9Sstevel@tonic-gate int32_t cg_irotor; /* position of last used inode */ 499*7c478bd9Sstevel@tonic-gate int32_t cg_frsum[8]; /* counts of available frags */ 500*7c478bd9Sstevel@tonic-gate int32_t cg_btot[32]; /* block totals per cylinder */ 501*7c478bd9Sstevel@tonic-gate short cg_b[32][8]; /* positions of free blocks */ 502*7c478bd9Sstevel@tonic-gate char cg_iused[256]; /* used inode map */ 503*7c478bd9Sstevel@tonic-gate int32_t cg_magic; /* magic number */ 504*7c478bd9Sstevel@tonic-gate uchar_t cg_free[1]; /* free block map */ 505*7c478bd9Sstevel@tonic-gate /* actually longer */ 506*7c478bd9Sstevel@tonic-gate }; 507*7c478bd9Sstevel@tonic-gate 508*7c478bd9Sstevel@tonic-gate /* 509*7c478bd9Sstevel@tonic-gate * Turn frag offsets into disk block addresses. 510*7c478bd9Sstevel@tonic-gate * This maps frags to device size blocks. 511*7c478bd9Sstevel@tonic-gate * (In the names of these macros, "fsb" refers to "frags", not 512*7c478bd9Sstevel@tonic-gate * file system blocks.) 513*7c478bd9Sstevel@tonic-gate */ 514*7c478bd9Sstevel@tonic-gate #ifdef KERNEL 515*7c478bd9Sstevel@tonic-gate #define fsbtodb(fs, b) (((daddr_t)(b)) << (fs)->fs_fsbtodb) 516*7c478bd9Sstevel@tonic-gate #else /* KERNEL */ 517*7c478bd9Sstevel@tonic-gate #define fsbtodb(fs, b) (((diskaddr_t)(b)) << (fs)->fs_fsbtodb) 518*7c478bd9Sstevel@tonic-gate #endif /* KERNEL */ 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate #define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb) 521*7c478bd9Sstevel@tonic-gate 522*7c478bd9Sstevel@tonic-gate /* 523*7c478bd9Sstevel@tonic-gate * Get the offset of the log, in either sectors, frags, or file system 524*7c478bd9Sstevel@tonic-gate * blocks. The interpretation of the fs_logbno field depends on whether 525*7c478bd9Sstevel@tonic-gate * this is UFS or MTB UFS. (UFS stores the value as sectors. MTBUFS 526*7c478bd9Sstevel@tonic-gate * stores the value as frags.) 527*7c478bd9Sstevel@tonic-gate */ 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate #ifdef KERNEL 530*7c478bd9Sstevel@tonic-gate #define logbtodb(fs, b) ((fs)->fs_magic == FS_MAGIC ? \ 531*7c478bd9Sstevel@tonic-gate (daddr_t)(b) : ((daddr_t)(b) << (fs)->fs_fsbtodb)) 532*7c478bd9Sstevel@tonic-gate #else /* KERNEL */ 533*7c478bd9Sstevel@tonic-gate #define logbtodb(fs, b) ((fs)->fs_magic == FS_MAGIC ? \ 534*7c478bd9Sstevel@tonic-gate (diskaddr_t)(b) : ((diskaddr_t)(b) << (fs)->fs_fsbtodb)) 535*7c478bd9Sstevel@tonic-gate #endif /* KERNEL */ 536*7c478bd9Sstevel@tonic-gate #define logbtofrag(fs, b) ((fs)->fs_magic == FS_MAGIC ? \ 537*7c478bd9Sstevel@tonic-gate (b) >> (fs)->fs_fsbtodb : (b)) 538*7c478bd9Sstevel@tonic-gate #define logbtofsblk(fs, b) ((fs)->fs_magic == FS_MAGIC ? \ 539*7c478bd9Sstevel@tonic-gate (b) >> ((fs)->fs_fsbtodb + (fs)->fs_fragshift) : \ 540*7c478bd9Sstevel@tonic-gate (b) >> (fs)->fs_fragshift) 541*7c478bd9Sstevel@tonic-gate 542*7c478bd9Sstevel@tonic-gate /* 543*7c478bd9Sstevel@tonic-gate * Cylinder group macros to locate things in cylinder groups. 544*7c478bd9Sstevel@tonic-gate * They calc file system addresses of cylinder group data structures. 545*7c478bd9Sstevel@tonic-gate */ 546*7c478bd9Sstevel@tonic-gate #define cgbase(fs, c) ((daddr32_t)((fs)->fs_fpg * (c))) 547*7c478bd9Sstevel@tonic-gate 548*7c478bd9Sstevel@tonic-gate #define cgstart(fs, c) \ 549*7c478bd9Sstevel@tonic-gate (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask))) 550*7c478bd9Sstevel@tonic-gate 551*7c478bd9Sstevel@tonic-gate #define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */ 552*7c478bd9Sstevel@tonic-gate 553*7c478bd9Sstevel@tonic-gate #define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */ 554*7c478bd9Sstevel@tonic-gate 555*7c478bd9Sstevel@tonic-gate #define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ 556*7c478bd9Sstevel@tonic-gate 557*7c478bd9Sstevel@tonic-gate #define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */ 558*7c478bd9Sstevel@tonic-gate 559*7c478bd9Sstevel@tonic-gate /* 560*7c478bd9Sstevel@tonic-gate * Macros for handling inode numbers: 561*7c478bd9Sstevel@tonic-gate * inode number to file system block offset. 562*7c478bd9Sstevel@tonic-gate * inode number to cylinder group number. 563*7c478bd9Sstevel@tonic-gate * inode number to file system block address. 564*7c478bd9Sstevel@tonic-gate */ 565*7c478bd9Sstevel@tonic-gate #define itoo(fs, x) ((x) % (uint32_t)INOPB(fs)) 566*7c478bd9Sstevel@tonic-gate 567*7c478bd9Sstevel@tonic-gate #define itog(fs, x) ((x) / (uint32_t)(fs)->fs_ipg) 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate #define itod(fs, x) \ 570*7c478bd9Sstevel@tonic-gate ((daddr32_t)(cgimin(fs, itog(fs, x)) + \ 571*7c478bd9Sstevel@tonic-gate (blkstofrags((fs), (((x)%(ulong_t)(fs)->fs_ipg)/(ulong_t)INOPB(fs)))))) 572*7c478bd9Sstevel@tonic-gate 573*7c478bd9Sstevel@tonic-gate /* 574*7c478bd9Sstevel@tonic-gate * Give cylinder group number for a file system block. 575*7c478bd9Sstevel@tonic-gate * Give cylinder group block number for a file system block. 576*7c478bd9Sstevel@tonic-gate */ 577*7c478bd9Sstevel@tonic-gate #define dtog(fs, d) ((d) / (fs)->fs_fpg) 578*7c478bd9Sstevel@tonic-gate #define dtogd(fs, d) ((d) % (fs)->fs_fpg) 579*7c478bd9Sstevel@tonic-gate 580*7c478bd9Sstevel@tonic-gate /* 581*7c478bd9Sstevel@tonic-gate * Extract the bits for a block from a map. 582*7c478bd9Sstevel@tonic-gate * Compute the cylinder and rotational position of a cyl block addr. 583*7c478bd9Sstevel@tonic-gate */ 584*7c478bd9Sstevel@tonic-gate #define blkmap(fs, map, loc) \ 585*7c478bd9Sstevel@tonic-gate (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & \ 586*7c478bd9Sstevel@tonic-gate (0xff >> (NBBY - (fs)->fs_frag))) 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate #define cbtocylno(fs, bno) \ 589*7c478bd9Sstevel@tonic-gate ((bno) * NSPF(fs) / (fs)->fs_spc) 590*7c478bd9Sstevel@tonic-gate 591*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 592*7c478bd9Sstevel@tonic-gate #define cbtorpos(ufsvfsp, bno) \ 593*7c478bd9Sstevel@tonic-gate ((((bno) * NSPF((ufsvfsp)->vfs_fs) % (ufsvfsp)->vfs_fs->fs_spc) % \ 594*7c478bd9Sstevel@tonic-gate (ufsvfsp)->vfs_fs->fs_nsect) * \ 595*7c478bd9Sstevel@tonic-gate (ufsvfsp)->vfs_nrpos) / (ufsvfsp)->vfs_fs->fs_nsect 596*7c478bd9Sstevel@tonic-gate #else 597*7c478bd9Sstevel@tonic-gate #define cbtorpos(fs, bno) \ 598*7c478bd9Sstevel@tonic-gate ((((bno) * NSPF(fs) % (fs)->fs_spc) % \ 599*7c478bd9Sstevel@tonic-gate (fs)->fs_nsect) * \ 600*7c478bd9Sstevel@tonic-gate (fs)->fs_nrpos) / (fs)->fs_nsect 601*7c478bd9Sstevel@tonic-gate #endif 602*7c478bd9Sstevel@tonic-gate 603*7c478bd9Sstevel@tonic-gate /* 604*7c478bd9Sstevel@tonic-gate * The following macros optimize certain frequently calculated 605*7c478bd9Sstevel@tonic-gate * quantities by using shifts and masks in place of divisions 606*7c478bd9Sstevel@tonic-gate * modulos and multiplications. 607*7c478bd9Sstevel@tonic-gate */ 608*7c478bd9Sstevel@tonic-gate 609*7c478bd9Sstevel@tonic-gate /* 610*7c478bd9Sstevel@tonic-gate * This macro works for 40 bit offset support in ufs because 611*7c478bd9Sstevel@tonic-gate * this calculates offset in the block and therefore no loss of 612*7c478bd9Sstevel@tonic-gate * information while casting to int. 613*7c478bd9Sstevel@tonic-gate */ 614*7c478bd9Sstevel@tonic-gate 615*7c478bd9Sstevel@tonic-gate #define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ 616*7c478bd9Sstevel@tonic-gate ((int)((loc) & ~(fs)->fs_bmask)) 617*7c478bd9Sstevel@tonic-gate 618*7c478bd9Sstevel@tonic-gate /* 619*7c478bd9Sstevel@tonic-gate * This macro works for 40 bit offset support similar to blkoff 620*7c478bd9Sstevel@tonic-gate */ 621*7c478bd9Sstevel@tonic-gate 622*7c478bd9Sstevel@tonic-gate #define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \ 623*7c478bd9Sstevel@tonic-gate ((int)((loc) & ~(fs)->fs_fmask)) 624*7c478bd9Sstevel@tonic-gate 625*7c478bd9Sstevel@tonic-gate /* 626*7c478bd9Sstevel@tonic-gate * The cast to int32_t does not result in any loss of information because 627*7c478bd9Sstevel@tonic-gate * the number of logical blocks in the file system is limited to 628*7c478bd9Sstevel@tonic-gate * what fits in an int32_t anyway. 629*7c478bd9Sstevel@tonic-gate */ 630*7c478bd9Sstevel@tonic-gate 631*7c478bd9Sstevel@tonic-gate #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ 632*7c478bd9Sstevel@tonic-gate ((int32_t)((loc) >> (fs)->fs_bshift)) 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate /* 635*7c478bd9Sstevel@tonic-gate * The same argument as above applies here. 636*7c478bd9Sstevel@tonic-gate */ 637*7c478bd9Sstevel@tonic-gate 638*7c478bd9Sstevel@tonic-gate #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 639*7c478bd9Sstevel@tonic-gate ((int32_t)((loc) >> (fs)->fs_fshift)) 640*7c478bd9Sstevel@tonic-gate 641*7c478bd9Sstevel@tonic-gate /* 642*7c478bd9Sstevel@tonic-gate * Size can be a 64-bit value and therefore we sign extend fs_bmask 643*7c478bd9Sstevel@tonic-gate * to a 64-bit value too so that the higher 32 bits are masked 644*7c478bd9Sstevel@tonic-gate * properly. Note that the type of fs_bmask has to be signed. Otherwise 645*7c478bd9Sstevel@tonic-gate * compiler will set the higher 32 bits as zero and we don't want 646*7c478bd9Sstevel@tonic-gate * this to happen. 647*7c478bd9Sstevel@tonic-gate */ 648*7c478bd9Sstevel@tonic-gate 649*7c478bd9Sstevel@tonic-gate #define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \ 650*7c478bd9Sstevel@tonic-gate (((size) + (fs)->fs_bsize - 1) & (offset_t)(fs)->fs_bmask) 651*7c478bd9Sstevel@tonic-gate 652*7c478bd9Sstevel@tonic-gate /* 653*7c478bd9Sstevel@tonic-gate * Same argument as above. 654*7c478bd9Sstevel@tonic-gate */ 655*7c478bd9Sstevel@tonic-gate 656*7c478bd9Sstevel@tonic-gate #define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ 657*7c478bd9Sstevel@tonic-gate (((size) + (fs)->fs_fsize - 1) & (offset_t)(fs)->fs_fmask) 658*7c478bd9Sstevel@tonic-gate 659*7c478bd9Sstevel@tonic-gate /* 660*7c478bd9Sstevel@tonic-gate * frags cannot exceed 32-bit value since we only support 40bit sizes. 661*7c478bd9Sstevel@tonic-gate */ 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate #define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \ 664*7c478bd9Sstevel@tonic-gate ((frags) >> (fs)->fs_fragshift) 665*7c478bd9Sstevel@tonic-gate 666*7c478bd9Sstevel@tonic-gate #define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \ 667*7c478bd9Sstevel@tonic-gate ((blks) << (fs)->fs_fragshift) 668*7c478bd9Sstevel@tonic-gate 669*7c478bd9Sstevel@tonic-gate #define fragnum(fs, fsb) /* calculates (fsb % fs->fs_frag) */ \ 670*7c478bd9Sstevel@tonic-gate ((fsb) & ((fs)->fs_frag - 1)) 671*7c478bd9Sstevel@tonic-gate 672*7c478bd9Sstevel@tonic-gate #define blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \ 673*7c478bd9Sstevel@tonic-gate ((fsb) &~ ((fs)->fs_frag - 1)) 674*7c478bd9Sstevel@tonic-gate 675*7c478bd9Sstevel@tonic-gate /* 676*7c478bd9Sstevel@tonic-gate * Determine the number of available frags given a 677*7c478bd9Sstevel@tonic-gate * percentage to hold in reserve 678*7c478bd9Sstevel@tonic-gate */ 679*7c478bd9Sstevel@tonic-gate #define freespace(fs, ufsvfsp) \ 680*7c478bd9Sstevel@tonic-gate ((blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \ 681*7c478bd9Sstevel@tonic-gate (fs)->fs_cstotal.cs_nffree) - (ufsvfsp)->vfs_minfrags) 682*7c478bd9Sstevel@tonic-gate 683*7c478bd9Sstevel@tonic-gate /* 684*7c478bd9Sstevel@tonic-gate * Determining the size of a file block in the file system. 685*7c478bd9Sstevel@tonic-gate */ 686*7c478bd9Sstevel@tonic-gate 687*7c478bd9Sstevel@tonic-gate #define blksize(fs, ip, lbn) \ 688*7c478bd9Sstevel@tonic-gate (((lbn) >= NDADDR || \ 689*7c478bd9Sstevel@tonic-gate (ip)->i_size >= (offset_t)((lbn) + 1) << (fs)->fs_bshift) \ 690*7c478bd9Sstevel@tonic-gate ? (fs)->fs_bsize \ 691*7c478bd9Sstevel@tonic-gate : (fragroundup(fs, blkoff(fs, (ip)->i_size)))) 692*7c478bd9Sstevel@tonic-gate 693*7c478bd9Sstevel@tonic-gate #define dblksize(fs, dip, lbn) \ 694*7c478bd9Sstevel@tonic-gate (((lbn) >= NDADDR || \ 695*7c478bd9Sstevel@tonic-gate (dip)->di_size >= (offset_t)((lbn) + 1) << (fs)->fs_bshift) \ 696*7c478bd9Sstevel@tonic-gate ? (fs)->fs_bsize \ 697*7c478bd9Sstevel@tonic-gate : (fragroundup(fs, blkoff(fs, (dip)->di_size)))) 698*7c478bd9Sstevel@tonic-gate 699*7c478bd9Sstevel@tonic-gate /* 700*7c478bd9Sstevel@tonic-gate * Number of disk sectors per block; assumes DEV_BSIZE byte sector size. 701*7c478bd9Sstevel@tonic-gate */ 702*7c478bd9Sstevel@tonic-gate #define NSPB(fs) ((fs)->fs_nspf << (fs)->fs_fragshift) 703*7c478bd9Sstevel@tonic-gate #define NSPF(fs) ((fs)->fs_nspf) 704*7c478bd9Sstevel@tonic-gate 705*7c478bd9Sstevel@tonic-gate /* 706*7c478bd9Sstevel@tonic-gate * INOPB is the number of inodes in a secondary storage block. 707*7c478bd9Sstevel@tonic-gate */ 708*7c478bd9Sstevel@tonic-gate #define INOPB(fs) ((fs)->fs_inopb) 709*7c478bd9Sstevel@tonic-gate #define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift) 710*7c478bd9Sstevel@tonic-gate 711*7c478bd9Sstevel@tonic-gate /* 712*7c478bd9Sstevel@tonic-gate * NINDIR is the number of indirects in a file system block. 713*7c478bd9Sstevel@tonic-gate */ 714*7c478bd9Sstevel@tonic-gate #define NINDIR(fs) ((fs)->fs_nindir) 715*7c478bd9Sstevel@tonic-gate 716*7c478bd9Sstevel@tonic-gate /* 717*7c478bd9Sstevel@tonic-gate * bit map related macros 718*7c478bd9Sstevel@tonic-gate */ 719*7c478bd9Sstevel@tonic-gate #define bitloc(a, i) ((a)[(i)/NBBY]) 720*7c478bd9Sstevel@tonic-gate #define setbit(a, i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 721*7c478bd9Sstevel@tonic-gate #define clrbit(a, i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 722*7c478bd9Sstevel@tonic-gate #define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 723*7c478bd9Sstevel@tonic-gate #define isclr(a, i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate #define getfs(vfsp) \ 726*7c478bd9Sstevel@tonic-gate ((struct fs *)((struct ufsvfs *)vfsp->vfs_data)->vfs_bufp->b_un.b_addr) 727*7c478bd9Sstevel@tonic-gate 728*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 729*7c478bd9Sstevel@tonic-gate } 730*7c478bd9Sstevel@tonic-gate #endif 731*7c478bd9Sstevel@tonic-gate 732*7c478bd9Sstevel@tonic-gate #endif /* _SYS_FS_UFS_FS_H */ 733