Annotation of kernel/bsd/ufs/ffs/fs.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
                     26: /*
                     27:  * Copyright (c) 1982, 1986, 1993
                     28:  *     The Regents of the University of California.  All rights reserved.
                     29:  *
                     30:  * Redistribution and use in source and binary forms, with or without
                     31:  * modification, are permitted provided that the following conditions
                     32:  * are met:
                     33:  * 1. Redistributions of source code must retain the above copyright
                     34:  *    notice, this list of conditions and the following disclaimer.
                     35:  * 2. Redistributions in binary form must reproduce the above copyright
                     36:  *    notice, this list of conditions and the following disclaimer in the
                     37:  *    documentation and/or other materials provided with the distribution.
                     38:  * 3. All advertising materials mentioning features or use of this software
                     39:  *    must display the following acknowledgement:
                     40:  *     This product includes software developed by the University of
                     41:  *     California, Berkeley and its contributors.
                     42:  * 4. Neither the name of the University nor the names of its contributors
                     43:  *    may be used to endorse or promote products derived from this software
                     44:  *    without specific prior written permission.
                     45:  *
                     46:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     47:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     48:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     49:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     50:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     51:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     52:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     53:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     54:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     55:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     56:  * SUCH DAMAGE.
                     57:  *
                     58:  *     @(#)fs.h        8.13 (Berkeley) 3/21/95
                     59:  */
                     60: 
                     61: /*
                     62:  * Each disk drive contains some number of file systems.
                     63:  * A file system consists of a number of cylinder groups.
                     64:  * Each cylinder group has inodes and data.
                     65:  *
                     66:  * A file system is described by its super-block, which in turn
                     67:  * describes the cylinder groups.  The super-block is critical
                     68:  * data and is replicated in each cylinder group to protect against
                     69:  * catastrophic loss.  This is done at `newfs' time and the critical
                     70:  * super-block data does not change, so the copies need not be
                     71:  * referenced further unless disaster strikes.
                     72:  *
                     73:  * For file system fs, the offsets of the various blocks of interest
                     74:  * are given in the super block as:
                     75:  *     [fs->fs_sblkno]         Super-block
                     76:  *     [fs->fs_cblkno]         Cylinder group block
                     77:  *     [fs->fs_iblkno]         Inode blocks
                     78:  *     [fs->fs_dblkno]         Data blocks
                     79:  * The beginning of cylinder group cg in fs, is given by
                     80:  * the ``cgbase(fs, cg)'' macro.
                     81:  *
                     82:  * The first boot and super blocks are given in absolute disk addresses.
                     83:  * The byte-offset forms are preferred, as they don't imply a sector size.
                     84:  */
                     85: #define BBSIZE         8192
                     86: #define SBSIZE         8192
                     87: #define        BBOFF           ((off_t)(0))
                     88: #define        SBOFF           ((off_t)(BBOFF + BBSIZE))
                     89: #define        BBLOCK          ((ufs_daddr_t)(0))
                     90: #define        SBLOCK          ((ufs_daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
                     91: 
                     92: /*
                     93:  * Addresses stored in inodes are capable of addressing fragments
                     94:  * of `blocks'. File system blocks of at most size MAXBSIZE can 
                     95:  * be optionally broken into 2, 4, or 8 pieces, each of which is
                     96:  * addressible; these pieces may be DEV_BSIZE, or some multiple of
                     97:  * a DEV_BSIZE unit.
                     98:  *
                     99:  * Large files consist of exclusively large data blocks.  To avoid
                    100:  * undue wasted disk space, the last data block of a small file may be
                    101:  * allocated as only as many fragments of a large block as are
                    102:  * necessary.  The file system format retains only a single pointer
                    103:  * to such a fragment, which is a piece of a single large block that
                    104:  * has been divided.  The size of such a fragment is determinable from
                    105:  * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
                    106:  *
                    107:  * The file system records space availability at the fragment level;
                    108:  * to determine block availability, aligned fragments are examined.
                    109:  */
                    110: 
                    111: /*
                    112:  * MINBSIZE is the smallest allowable block size.
                    113:  * In order to insure that it is possible to create files of size
                    114:  * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
                    115:  * MINBSIZE must be big enough to hold a cylinder group block,
                    116:  * thus changes to (struct cg) must keep its size within MINBSIZE.
                    117:  * Note that super blocks are always of size SBSIZE,
                    118:  * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
                    119:  */
                    120: #define MINBSIZE       4096
                    121: 
                    122: /*
                    123:  * The path name on which the file system is mounted is maintained
                    124:  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 
                    125:  * the super block for this name.
                    126:  */
                    127: #define MAXMNTLEN      512
                    128: 
                    129: /*
                    130:  * The limit on the amount of summary information per file system
                    131:  * is defined by MAXCSBUFS. It is currently parameterized for a
                    132:  * size of 128 bytes (2 million cylinder groups on machines with
                    133:  * 32-bit pointers, and 1 million on 64-bit machines). One pointer
                    134:  * is taken away to point to an array of cluster sizes that is
                    135:  * computed as cylinder groups are inspected.
                    136:  */
                    137: #define        MAXCSBUFS       ((128 / sizeof(void *)) - 1)
                    138: 
                    139: /*
                    140:  * A summary of contiguous blocks of various sizes is maintained
                    141:  * in each cylinder group. Normally this is set by the initial
                    142:  * value of fs_maxcontig. To conserve space, a maximum summary size
                    143:  * is set by FS_MAXCONTIG.
                    144:  */
                    145: #define FS_MAXCONTIG   16
                    146: 
                    147: /*
                    148:  * MINFREE gives the minimum acceptable percentage of file system
                    149:  * blocks which may be free. If the freelist drops below this level
                    150:  * only the superuser may continue to allocate blocks. This may
                    151:  * be set to 0 if no reserve of free blocks is deemed necessary,
                    152:  * however throughput drops by fifty percent if the file system
                    153:  * is run at between 95% and 100% full; thus the minimum default
                    154:  * value of fs_minfree is 5%. However, to get good clustering
                    155:  * performance, 10% is a better choice. hence we use 10% as our
                    156:  * default value. With 10% free space, fragmentation is not a
                    157:  * problem, so we choose to optimize for time.
                    158:  */
                    159: #define MINFREE                5
                    160: #define DEFAULTOPT     FS_OPTTIME
                    161: 
                    162: /*
                    163:  * Per cylinder group information; summarized in blocks allocated
                    164:  * from first cylinder group data blocks.  These blocks have to be
                    165:  * read in from fs_csaddr (size fs_cssize) in addition to the
                    166:  * super block.
                    167:  *
                    168:  * N.B. sizeof(struct csum) must be a power of two in order for
                    169:  * the ``fs_cs'' macro to work (see below).
                    170:  */
                    171: struct csum {
                    172:        int32_t cs_ndir;                /* number of directories */
                    173:        int32_t cs_nbfree;              /* number of free blocks */
                    174:        int32_t cs_nifree;              /* number of free inodes */
                    175:        int32_t cs_nffree;              /* number of free frags */
                    176: };
                    177: 
                    178: /*
                    179:  * Super block for an FFS file system.
                    180:  */
                    181: struct fs {
                    182:        int32_t  fs_firstfield;         /* historic file system linked list, */
                    183:        int32_t  fs_unused_1;           /*     used for incore super blocks */
                    184:        ufs_daddr_t fs_sblkno;          /* addr of super-block in filesys */
                    185:        ufs_daddr_t fs_cblkno;          /* offset of cyl-block in filesys */
                    186:        ufs_daddr_t fs_iblkno;          /* offset of inode-blocks in filesys */
                    187:        ufs_daddr_t fs_dblkno;          /* offset of first data after cg */
                    188:        int32_t  fs_cgoffset;           /* cylinder group offset in cylinder */
                    189:        int32_t  fs_cgmask;             /* used to calc mod fs_ntrak */
                    190:        time_t   fs_time;               /* last time written */
                    191:        int32_t  fs_size;               /* number of blocks in fs */
                    192:        int32_t  fs_dsize;              /* number of data blocks in fs */
                    193:        int32_t  fs_ncg;                /* number of cylinder groups */
                    194:        int32_t  fs_bsize;              /* size of basic blocks in fs */
                    195:        int32_t  fs_fsize;              /* size of frag blocks in fs */
                    196:        int32_t  fs_frag;               /* number of frags in a block in fs */
                    197: /* these are configuration parameters */
                    198:        int32_t  fs_minfree;            /* minimum percentage of free blocks */
                    199:        int32_t  fs_rotdelay;           /* num of ms for optimal next block */
                    200:        int32_t  fs_rps;                /* disk revolutions per second */
                    201: /* these fields can be computed from the others */
                    202:        int32_t  fs_bmask;              /* ``blkoff'' calc of blk offsets */
                    203:        int32_t  fs_fmask;              /* ``fragoff'' calc of frag offsets */
                    204:        int32_t  fs_bshift;             /* ``lblkno'' calc of logical blkno */
                    205:        int32_t  fs_fshift;             /* ``numfrags'' calc number of frags */
                    206: /* these are configuration parameters */
                    207:        int32_t  fs_maxcontig;          /* max number of contiguous blks */
                    208:        int32_t  fs_maxbpg;             /* max number of blks per cyl group */
                    209: /* these fields can be computed from the others */
                    210:        int32_t  fs_fragshift;          /* block to frag shift */
                    211:        int32_t  fs_fsbtodb;            /* fsbtodb and dbtofsb shift constant */
                    212:        int32_t  fs_sbsize;             /* actual size of super block */
                    213:        int32_t  fs_csmask;             /* csum block offset */
                    214:        int32_t  fs_csshift;            /* csum block number */
                    215:        int32_t  fs_nindir;             /* value of NINDIR */
                    216:        int32_t  fs_inopb;              /* value of INOPB */
                    217:        int32_t  fs_nspf;               /* value of NSPF */
                    218: /* yet another configuration parameter */
                    219:        int32_t  fs_optim;              /* optimization preference, see below */
                    220: /* these fields are derived from the hardware */
                    221:        int32_t  fs_npsect;             /* # sectors/track including spares */
                    222:        int32_t  fs_interleave;         /* hardware sector interleave */
                    223:        int32_t  fs_trackskew;          /* sector 0 skew, per track */
                    224:        int32_t  fs_headswitch;         /* head switch time, usec */
                    225:        int32_t  fs_trkseek;            /* track-to-track seek, usec */
                    226: /* sizes determined by number of cylinder groups and their sizes */
                    227:        ufs_daddr_t fs_csaddr;          /* blk addr of cyl grp summary area */
                    228:        int32_t  fs_cssize;             /* size of cyl grp summary area */
                    229:        int32_t  fs_cgsize;             /* cylinder group size */
                    230: /* these fields are derived from the hardware */
                    231:        int32_t  fs_ntrak;              /* tracks per cylinder */
                    232:        int32_t  fs_nsect;              /* sectors per track */
                    233:        int32_t  fs_spc;                        /* sectors per cylinder */
                    234: /* this comes from the disk driver partitioning */
                    235:        int32_t  fs_ncyl;               /* cylinders in file system */
                    236: /* these fields can be computed from the others */
                    237:        int32_t  fs_cpg;                        /* cylinders per group */
                    238:        int32_t  fs_ipg;                        /* inodes per group */
                    239:        int32_t  fs_fpg;                        /* blocks per group * fs_frag */
                    240: /* this data must be re-computed after crashes */
                    241:        struct  csum fs_cstotal;        /* cylinder summary information */
                    242: /* these fields are cleared at mount time */
                    243:        int8_t   fs_fmod;               /* super block modified flag */
                    244:        int8_t   fs_clean;              /* file system is clean flag */
                    245:        int8_t   fs_ronly;              /* mounted read-only flag */
                    246:        int8_t   fs_flags;              /* currently unused flag */
                    247:        u_char   fs_fsmnt[MAXMNTLEN];   /* name mounted on */
                    248: /* these fields retain the current block allocation info */
                    249:        int32_t  fs_cgrotor;            /* last cg searched */
                    250:        struct  csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
                    251:        int32_t  *fs_maxcluster;        /* max cluster in each cyl group */
                    252:        int32_t  fs_cpc;                /* cyl per cycle in postbl */
                    253:        int16_t  fs_opostbl[16][8];     /* old rotation block list head */
                    254:        int32_t  fs_sparecon[50];       /* reserved for future constants */
                    255:        int32_t  fs_contigsumsize;      /* size of cluster summary array */ 
                    256:        int32_t  fs_maxsymlinklen;      /* max length of an internal symlink */
                    257:        int32_t  fs_inodefmt;           /* format of on-disk inodes */
                    258:        u_int64_t fs_maxfilesize;       /* maximum representable file size */
                    259:        int64_t  fs_qbmask;             /* ~fs_bmask for use with 64-bit size */
                    260:        int64_t  fs_qfmask;             /* ~fs_fmask for use with 64-bit size */
                    261:        int32_t  fs_state;              /* validate fs_clean field */
                    262:        int32_t  fs_postblformat;       /* format of positional layout tables */
                    263:        int32_t  fs_nrpos;              /* number of rotational positions */
                    264:        int32_t  fs_postbloff;          /* (u_int16) rotation block list head */
                    265:        int32_t  fs_rotbloff;           /* (u_int8) blocks for each rotation */
                    266:        int32_t  fs_magic;              /* magic number */
                    267:        u_int8_t fs_space[1];           /* list of blocks for each rotation */
                    268: /* actually longer */
                    269: };
                    270: 
                    271: /*
                    272:  * Filesystem identification
                    273:  */
                    274: #define        FS_MAGIC        0x011954        /* the fast filesystem magic number */
                    275: #define        FS_OKAY         0x7c269d38      /* superblock checksum */
                    276: #define FS_42INODEFMT  -1              /* 4.2BSD inode format */
                    277: #define FS_44INODEFMT  2               /* 4.4BSD inode format */
                    278: /*
                    279:  * Preference for optimization.
                    280:  */
                    281: #define FS_OPTTIME     0       /* minimize allocation time */
                    282: #define FS_OPTSPACE    1       /* minimize disk fragmentation */
                    283: 
                    284: /*
                    285:  * Rotational layout table format types
                    286:  */
                    287: #define FS_42POSTBLFMT         -1      /* 4.2BSD rotational table format */
                    288: #define FS_DYNAMICPOSTBLFMT    1       /* dynamic rotational table format */
                    289: /*
                    290:  * Macros for access to superblock array structures
                    291:  */
                    292: #define fs_postbl(fs, cylno) \
                    293:     (((fs)->fs_postblformat == FS_42POSTBLFMT) \
                    294:     ? ((fs)->fs_opostbl[cylno]) \
                    295:     : ((int16_t *)((u_int8_t *)(fs) + \
                    296:        (fs)->fs_postbloff) + (cylno) * (fs)->fs_nrpos))
                    297: #define fs_rotbl(fs) \
                    298:     (((fs)->fs_postblformat == FS_42POSTBLFMT) \
                    299:     ? ((fs)->fs_space) \
                    300:     : ((u_int8_t *)((u_int8_t *)(fs) + (fs)->fs_rotbloff)))
                    301: 
                    302: /*
                    303:  * The size of a cylinder group is calculated by CGSIZE. The maximum size
                    304:  * is limited by the fact that cylinder groups are at most one block.
                    305:  * Its size is derived from the size of the maps maintained in the 
                    306:  * cylinder group and the (struct cg) size.
                    307:  */
                    308: #define CGSIZE(fs) \
                    309:     /* base cg */      (sizeof(struct cg) + sizeof(int32_t) + \
                    310:     /* blktot size */  (fs)->fs_cpg * sizeof(int32_t) + \
                    311:     /* blks size */    (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(int16_t) + \
                    312:     /* inode map */    howmany((fs)->fs_ipg, NBBY) + \
                    313:     /* block map */    howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY) +\
                    314:     /* if present */   ((fs)->fs_contigsumsize <= 0 ? 0 : \
                    315:     /* cluster sum */  (fs)->fs_contigsumsize * sizeof(int32_t) + \
                    316:     /* cluster map */  howmany((fs)->fs_cpg * (fs)->fs_spc / NSPB(fs), NBBY)))
                    317: 
                    318: /*
                    319:  * Convert cylinder group to base address of its global summary info.
                    320:  *
                    321:  * N.B. This macro assumes that sizeof(struct csum) is a power of two.
                    322:  */
                    323: #define fs_cs(fs, indx) \
                    324:        fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
                    325: 
                    326: /*
                    327:  * Cylinder group block for a file system.
                    328:  */
                    329: #define        CG_MAGIC        0x090255
                    330: struct cg {
                    331:        int32_t  cg_firstfield;         /* historic cyl groups linked list */
                    332:        int32_t  cg_magic;              /* magic number */
                    333:        time_t   cg_time;               /* time last written */
                    334:        int32_t  cg_cgx;                /* we are the cgx'th cylinder group */
                    335:        int16_t  cg_ncyl;               /* number of cyl's this cg */
                    336:        int16_t  cg_niblk;              /* number of inode blocks this cg */
                    337:        int32_t  cg_ndblk;              /* number of data blocks this cg */
                    338:        struct  csum cg_cs;             /* cylinder summary information */
                    339:        int32_t  cg_rotor;              /* position of last used block */
                    340:        int32_t  cg_frotor;             /* position of last used frag */
                    341:        int32_t  cg_irotor;             /* position of last used inode */
                    342:        int32_t  cg_frsum[MAXFRAG];     /* counts of available frags */
                    343:        int32_t  cg_btotoff;            /* (int32) block totals per cylinder */
                    344:        int32_t  cg_boff;               /* (u_int16) free block positions */
                    345:        int32_t  cg_iusedoff;           /* (u_int8) used inode map */
                    346:        int32_t  cg_freeoff;            /* (u_int8) free block map */
                    347:        int32_t  cg_nextfreeoff;        /* (u_int8) next available space */
                    348:        int32_t  cg_clustersumoff;      /* (u_int32) counts of avail clusters */
                    349:        int32_t  cg_clusteroff;         /* (u_int8) free cluster map */
                    350:        int32_t  cg_nclusterblks;       /* number of clusters this cg */
                    351:        int32_t  cg_sparecon[13];       /* reserved for future use */
                    352:        u_int8_t cg_space[1];           /* space for cylinder group maps */
                    353: /* actually longer */
                    354: };
                    355: 
                    356: /*
                    357:  * Macros for access to cylinder group array structures
                    358:  */
                    359: #define cg_blktot(cgp) \
                    360:     (((cgp)->cg_magic != CG_MAGIC) \
                    361:     ? (((struct ocg *)(cgp))->cg_btot) \
                    362:     : ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_btotoff)))
                    363: #define cg_blks(fs, cgp, cylno) \
                    364:     (((cgp)->cg_magic != CG_MAGIC) \
                    365:     ? (((struct ocg *)(cgp))->cg_b[cylno]) \
                    366:     : ((int16_t *)((u_int8_t *)(cgp) + \
                    367:        (cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos))
                    368: #define cg_inosused(cgp) \
                    369:     (((cgp)->cg_magic != CG_MAGIC) \
                    370:     ? (((struct ocg *)(cgp))->cg_iused) \
                    371:     : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_iusedoff)))
                    372: #define cg_blksfree(cgp) \
                    373:     (((cgp)->cg_magic != CG_MAGIC) \
                    374:     ? (((struct ocg *)(cgp))->cg_free) \
                    375:     : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_freeoff)))
                    376: #define cg_chkmagic(cgp) \
                    377:     ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
                    378: #define cg_clustersfree(cgp) \
                    379:     ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_clusteroff))
                    380: #define cg_clustersum(cgp) \
                    381:     ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_clustersumoff))
                    382: 
                    383: /*
                    384:  * The following structure is defined
                    385:  * for compatibility with old file systems.
                    386:  */
                    387: struct ocg {
                    388:        int32_t  cg_firstfield;         /* historic linked list of cyl groups */
                    389:        int32_t  cg_unused_1;           /*     used for incore cyl groups */
                    390:        time_t   cg_time;               /* time last written */
                    391:        int32_t  cg_cgx;                /* we are the cgx'th cylinder group */
                    392:        int16_t  cg_ncyl;               /* number of cyl's this cg */
                    393:        int16_t  cg_niblk;              /* number of inode blocks this cg */
                    394:        int32_t  cg_ndblk;              /* number of data blocks this cg */
                    395:        struct  csum cg_cs;             /* cylinder summary information */
                    396:        int32_t  cg_rotor;              /* position of last used block */
                    397:        int32_t  cg_frotor;             /* position of last used frag */
                    398:        int32_t  cg_irotor;             /* position of last used inode */
                    399:        int32_t  cg_frsum[8];           /* counts of available frags */
                    400:        int32_t  cg_btot[32];           /* block totals per cylinder */
                    401:        int16_t  cg_b[32][8];           /* positions of free blocks */
                    402:        u_int8_t cg_iused[256];         /* used inode map */
                    403:        int32_t  cg_magic;              /* magic number */
                    404:        u_int8_t cg_free[1];            /* free block map */
                    405: /* actually longer */
                    406: };
                    407: 
                    408: /*
                    409:  * Turn file system block numbers into disk block addresses.
                    410:  * This maps file system blocks to device size blocks.
                    411:  */
                    412: #define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb)
                    413: #define        dbtofsb(fs, b)  ((b) >> (fs)->fs_fsbtodb)
                    414: 
                    415: /*
                    416:  * Cylinder group macros to locate things in cylinder groups.
                    417:  * They calc file system addresses of cylinder group data structures.
                    418:  */
                    419: #define        cgbase(fs, c)   ((ufs_daddr_t)((fs)->fs_fpg * (c)))
                    420: #define        cgdmin(fs, c)   (cgstart(fs, c) + (fs)->fs_dblkno)      /* 1st data */
                    421: #define        cgimin(fs, c)   (cgstart(fs, c) + (fs)->fs_iblkno)      /* inode blk */
                    422: #define        cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno)      /* super blk */
                    423: #define        cgtod(fs, c)    (cgstart(fs, c) + (fs)->fs_cblkno)      /* cg block */
                    424: #define cgstart(fs, c)                                                 \
                    425:        (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
                    426: 
                    427: /*
                    428:  * Macros for handling inode numbers:
                    429:  *     inode number to file system block offset.
                    430:  *     inode number to cylinder group number.
                    431:  *     inode number to file system block address.
                    432:  */
                    433: #define        ino_to_cg(fs, x)        ((x) / (fs)->fs_ipg)
                    434: #define        ino_to_fsba(fs, x)                                              \
                    435:        ((ufs_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +                   \
                    436:            (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
                    437: #define        ino_to_fsbo(fs, x)      ((x) % INOPB(fs))
                    438: 
                    439: /*
                    440:  * Give cylinder group number for a file system block.
                    441:  * Give cylinder group block number for a file system block.
                    442:  */
                    443: #define        dtog(fs, d)     ((d) / (fs)->fs_fpg)
                    444: #define        dtogd(fs, d)    ((d) % (fs)->fs_fpg)
                    445: 
                    446: /*
                    447:  * Extract the bits for a block from a map.
                    448:  * Compute the cylinder and rotational position of a cyl block addr.
                    449:  */
                    450: #define blkmap(fs, map, loc) \
                    451:     (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
                    452: #define cbtocylno(fs, bno) \
                    453:     ((bno) * NSPF(fs) / (fs)->fs_spc)
                    454: #define cbtorpos(fs, bno) \
                    455:     (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \
                    456:      (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \
                    457:      (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect)
                    458: 
                    459: /*
                    460:  * The following macros optimize certain frequently calculated
                    461:  * quantities by using shifts and masks in place of divisions
                    462:  * modulos and multiplications.
                    463:  */
                    464: #define blkoff(fs, loc)                /* calculates (loc % fs->fs_bsize) */ \
                    465:        ((loc) & (fs)->fs_qbmask)
                    466: #define fragoff(fs, loc)       /* calculates (loc % fs->fs_fsize) */ \
                    467:        ((loc) & (fs)->fs_qfmask)
                    468: #define lblktosize(fs, blk)    /* calculates (blk * fs->fs_bsize) */ \
                    469:        ((blk) << (fs)->fs_bshift)
                    470: #define lblkno(fs, loc)                /* calculates (loc / fs->fs_bsize) */ \
                    471:        ((loc) >> (fs)->fs_bshift)
                    472: #define numfrags(fs, loc)      /* calculates (loc / fs->fs_fsize) */ \
                    473:        ((loc) >> (fs)->fs_fshift)
                    474: #define blkroundup(fs, size)   /* calculates roundup(size, fs->fs_bsize) */ \
                    475:        (((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
                    476: #define fragroundup(fs, size)  /* calculates roundup(size, fs->fs_fsize) */ \
                    477:        (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
                    478: #define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \
                    479:        ((frags) >> (fs)->fs_fragshift)
                    480: #define blkstofrags(fs, blks)  /* calculates (blks * fs->fs_frag) */ \
                    481:        ((blks) << (fs)->fs_fragshift)
                    482: #define fragnum(fs, fsb)       /* calculates (fsb % fs->fs_frag) */ \
                    483:        ((fsb) & ((fs)->fs_frag - 1))
                    484: #define blknum(fs, fsb)                /* calculates rounddown(fsb, fs->fs_frag) */ \
                    485:        ((fsb) &~ ((fs)->fs_frag - 1))
                    486: 
                    487: /*
                    488:  * Determine the number of available frags given a
                    489:  * percentage to hold in reserve.
                    490:  */
                    491: #define freespace(fs, percentreserved) \
                    492:        (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
                    493:        (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100))
                    494: 
                    495: /*
                    496:  * Determining the size of a file block in the file system.
                    497:  */
                    498: #define blksize(fs, ip, lbn) \
                    499:        (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \
                    500:            ? (fs)->fs_bsize \
                    501:            : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
                    502: #define dblksize(fs, dip, lbn) \
                    503:        (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
                    504:            ? (fs)->fs_bsize \
                    505:            : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
                    506: 
                    507: /*
                    508:  * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte
                    509:  * sector size.
                    510:  */
                    511: #define        NSPB(fs)        ((fs)->fs_nspf << (fs)->fs_fragshift)
                    512: #define        NSPF(fs)        ((fs)->fs_nspf)
                    513: 
                    514: /*
                    515:  * Number of inodes in a secondary storage block/fragment.
                    516:  */
                    517: #define        INOPB(fs)       ((fs)->fs_inopb)
                    518: #define        INOPF(fs)       ((fs)->fs_inopb >> (fs)->fs_fragshift)
                    519: 
                    520: /*
                    521:  * Number of indirects in a file system block.
                    522:  */
                    523: #define        NINDIR(fs)      ((fs)->fs_nindir)
                    524: 
                    525: /*
                    526:  * This macro controls whether the file system format is byte swapped or not.
                    527:  * At NeXT, all little endian machines read and write big endian file systems.
                    528:  */
                    529: #define        BIG_ENDIAN_FS   (__LITTLE_ENDIAN__)
                    530: 
                    531: extern int inside[], around[];
                    532: extern u_char *fragtbl[];

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.