Annotation of 43BSDTahoe/etc/onewfs/sys/fs.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  *
                      6:  *     @(#)fs.h        7.3 (Berkeley) 4/2/87
                      7:  */
                      8: 
                      9: /*
                     10:  * Each disk drive contains some number of file systems.
                     11:  * A file system consists of a number of cylinder groups.
                     12:  * Each cylinder group has inodes and data.
                     13:  *
                     14:  * A file system is described by its super-block, which in turn
                     15:  * describes the cylinder groups.  The super-block is critical
                     16:  * data and is replicated in each cylinder group to protect against
                     17:  * catastrophic loss.  This is done at mkfs time and the critical
                     18:  * super-block data does not change, so the copies need not be
                     19:  * referenced further unless disaster strikes.
                     20:  *
                     21:  * For file system fs, the offsets of the various blocks of interest
                     22:  * are given in the super block as:
                     23:  *     [fs->fs_sblkno]         Super-block
                     24:  *     [fs->fs_cblkno]         Cylinder group block
                     25:  *     [fs->fs_iblkno]         Inode blocks
                     26:  *     [fs->fs_dblkno]         Data blocks
                     27:  * The beginning of cylinder group cg in fs, is given by
                     28:  * the ``cgbase(fs, cg)'' macro.
                     29:  *
                     30:  * The first boot and super blocks are given in absolute disk addresses.
                     31:  * The byte-offset forms are preferred, as they don't imply a sector size.
                     32:  */
                     33: #define BBSIZE         8192
                     34: #define SBSIZE         8192
                     35: #define        BBOFF           ((off_t)(0))
                     36: #define        SBOFF           ((off_t)(BBOFF + BBSIZE))
                     37: #define        BBLOCK          ((daddr_t)(0))
                     38: #define        SBLOCK          ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
                     39: 
                     40: /*
                     41:  * Addresses stored in inodes are capable of addressing fragments
                     42:  * of `blocks'. File system blocks of at most size MAXBSIZE can 
                     43:  * be optionally broken into 2, 4, or 8 pieces, each of which is
                     44:  * addressible; these pieces may be DEV_BSIZE, or some multiple of
                     45:  * a DEV_BSIZE unit.
                     46:  *
                     47:  * Large files consist of exclusively large data blocks.  To avoid
                     48:  * undue wasted disk space, the last data block of a small file may be
                     49:  * allocated as only as many fragments of a large block as are
                     50:  * necessary.  The file system format retains only a single pointer
                     51:  * to such a fragment, which is a piece of a single large block that
                     52:  * has been divided.  The size of such a fragment is determinable from
                     53:  * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
                     54:  *
                     55:  * The file system records space availability at the fragment level;
                     56:  * to determine block availability, aligned fragments are examined.
                     57:  *
                     58:  * The root inode is the root of the file system.
                     59:  * Inode 0 can't be used for normal purposes and
                     60:  * historically bad blocks were linked to inode 1,
                     61:  * thus the root inode is 2. (inode 1 is no longer used for
                     62:  * this purpose, however numerous dump tapes make this
                     63:  * assumption, so we are stuck with it)
                     64:  * The lost+found directory is given the next available
                     65:  * inode when it is created by ``mkfs''.
                     66:  */
                     67: #define        ROOTINO         ((ino_t)2)      /* i number of all roots */
                     68: #define LOSTFOUNDINO   (ROOTINO + 1)
                     69: 
                     70: /*
                     71:  * Cylinder group related limits.
                     72:  *
                     73:  * For each cylinder we keep track of the availability of blocks at different
                     74:  * rotational positions, so that we can lay out the data to be picked
                     75:  * up with minimum rotational latency.  NRPOS is the number of rotational
                     76:  * positions which we distinguish.  With NRPOS 8 the resolution of our
                     77:  * summary information is 2ms for a typical 3600 rpm drive.
                     78:  */
                     79: #define        NRPOS           8       /* number distinct rotational positions */
                     80: 
                     81: /*
                     82:  * MAXIPG bounds the number of inodes per cylinder group, and
                     83:  * is needed only to keep the structure simpler by having the
                     84:  * only a single variable size element (the free bit map).
                     85:  *
                     86:  * N.B.: MAXIPG must be a multiple of INOPB(fs).
                     87:  */
                     88: #define        MAXIPG          2048    /* max number inodes/cyl group */
                     89: 
                     90: /*
                     91:  * MINBSIZE is the smallest allowable block size.
                     92:  * In order to insure that it is possible to create files of size
                     93:  * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
                     94:  * MINBSIZE must be big enough to hold a cylinder group block,
                     95:  * thus changes to (struct cg) must keep its size within MINBSIZE.
                     96:  * MAXCPG is limited only to dimension an array in (struct cg);
                     97:  * it can be made larger as long as that structures size remains
                     98:  * within the bounds dictated by MINBSIZE.
                     99:  * Note that super blocks are always of size SBSIZE,
                    100:  * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
                    101:  */
                    102: #define MINBSIZE       4096
                    103: #define        MAXCPG          32      /* maximum fs_cpg */
                    104: 
                    105: /*
                    106:  * The path name on which the file system is mounted is maintained
                    107:  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 
                    108:  * the super block for this name.
                    109:  * The limit on the amount of summary information per file system
                    110:  * is defined by MAXCSBUFS. It is currently parameterized for a
                    111:  * maximum of two million cylinders.
                    112:  */
                    113: #define MAXMNTLEN 384
                    114: #define MAXCSBUFS 32
                    115: 
                    116: /*
                    117:  * Per cylinder group information; summarized in blocks allocated
                    118:  * from first cylinder group data blocks.  These blocks have to be
                    119:  * read in from fs_csaddr (size fs_cssize) in addition to the
                    120:  * super block.
                    121:  *
                    122:  * N.B. sizeof(struct csum) must be a power of two in order for
                    123:  * the ``fs_cs'' macro to work (see below).
                    124:  */
                    125: struct csum {
                    126:        long    cs_ndir;        /* number of directories */
                    127:        long    cs_nbfree;      /* number of free blocks */
                    128:        long    cs_nifree;      /* number of free inodes */
                    129:        long    cs_nffree;      /* number of free frags */
                    130: };
                    131: 
                    132: /*
                    133:  * Super block for a file system.
                    134:  */
                    135: #define        FS_MAGIC        0x011954
                    136: struct fs
                    137: {
                    138:        struct  fs *fs_link;            /* linked list of file systems */
                    139:        struct  fs *fs_rlink;           /*     used for incore super blocks */
                    140:        daddr_t fs_sblkno;              /* addr of super-block in filesys */
                    141:        daddr_t fs_cblkno;              /* offset of cyl-block in filesys */
                    142:        daddr_t fs_iblkno;              /* offset of inode-blocks in filesys */
                    143:        daddr_t fs_dblkno;              /* offset of first data after cg */
                    144:        long    fs_cgoffset;            /* cylinder group offset in cylinder */
                    145:        long    fs_cgmask;              /* used to calc mod fs_ntrak */
                    146:        time_t  fs_time;                /* last time written */
                    147:        long    fs_size;                /* number of blocks in fs */
                    148:        long    fs_dsize;               /* number of data blocks in fs */
                    149:        long    fs_ncg;                 /* number of cylinder groups */
                    150:        long    fs_bsize;               /* size of basic blocks in fs */
                    151:        long    fs_fsize;               /* size of frag blocks in fs */
                    152:        long    fs_frag;                /* number of frags in a block in fs */
                    153: /* these are configuration parameters */
                    154:        long    fs_minfree;             /* minimum percentage of free blocks */
                    155:        long    fs_rotdelay;            /* num of ms for optimal next block */
                    156:        long    fs_rps;                 /* disk revolutions per second */
                    157: /* these fields can be computed from the others */
                    158:        long    fs_bmask;               /* ``blkoff'' calc of blk offsets */
                    159:        long    fs_fmask;               /* ``fragoff'' calc of frag offsets */
                    160:        long    fs_bshift;              /* ``lblkno'' calc of logical blkno */
                    161:        long    fs_fshift;              /* ``numfrags'' calc number of frags */
                    162: /* these are configuration parameters */
                    163:        long    fs_maxcontig;           /* max number of contiguous blks */
                    164:        long    fs_maxbpg;              /* max number of blks per cyl group */
                    165: /* these fields can be computed from the others */
                    166:        long    fs_fragshift;           /* block to frag shift */
                    167:        long    fs_fsbtodb;             /* fsbtodb and dbtofsb shift constant */
                    168:        long    fs_sbsize;              /* actual size of super block */
                    169:        long    fs_csmask;              /* csum block offset */
                    170:        long    fs_csshift;             /* csum block number */
                    171:        long    fs_nindir;              /* value of NINDIR */
                    172:        long    fs_inopb;               /* value of INOPB */
                    173:        long    fs_nspf;                /* value of NSPF */
                    174: /* yet another configuration parameter */
                    175:        long    fs_optim;               /* optimization preference, see below */
                    176: /* these fields are derived from the hardware */
                    177:        long    fs_npsect;              /* # sectors/track including spares */
                    178:        long    fs_interleave;          /* hardware sector interleave */
                    179:        long    fs_trackskew;           /* sector 0 skew, per track */
                    180:        long    fs_headswitch;          /* head switch time, usec */
                    181:        long    fs_trkseek;             /* track-to-track seek, usec */
                    182: /* sizes determined by number of cylinder groups and their sizes */
                    183:        daddr_t fs_csaddr;              /* blk addr of cyl grp summary area */
                    184:        long    fs_cssize;              /* size of cyl grp summary area */
                    185:        long    fs_cgsize;              /* cylinder group size */
                    186: /* these fields are derived from the hardware */
                    187:        long    fs_ntrak;               /* tracks per cylinder */
                    188:        long    fs_nsect;               /* sectors per track */
                    189:        long    fs_spc;                 /* sectors per cylinder */
                    190: /* this comes from the disk driver partitioning */
                    191:        long    fs_ncyl;                /* cylinders in file system */
                    192: /* these fields can be computed from the others */
                    193:        long    fs_cpg;                 /* cylinders per group */
                    194:        long    fs_ipg;                 /* inodes per group */
                    195:        long    fs_fpg;                 /* blocks per group * fs_frag */
                    196: /* this data must be re-computed after crashes */
                    197:        struct  csum fs_cstotal;        /* cylinder summary information */
                    198: /* these fields are cleared at mount time */
                    199:        char    fs_fmod;                /* super block modified flag */
                    200:        char    fs_clean;               /* file system is clean flag */
                    201:        char    fs_ronly;               /* mounted read-only flag */
                    202:        char    fs_flags;               /* currently unused flag */
                    203:        char    fs_fsmnt[MAXMNTLEN];    /* name mounted on */
                    204:        long    fs_dbsize;              /* hardware sector size */
                    205:        long    fs_sparecon[31];        /* reserved for future constants */
                    206: /* these fields retain the current block allocation info */
                    207:        long    fs_cgrotor;             /* last cg searched */
                    208:        struct  csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
                    209:        long    fs_cpc;                 /* cyl per cycle in postbl */
                    210:        short   fs_postbl[MAXCPG][NRPOS];/* head of blocks for each rotation */
                    211:        long    fs_magic;               /* magic number */
                    212:        u_char  fs_rotbl[1];            /* list of blocks for each rotation */
                    213: /* actually longer */
                    214: };
                    215: /*
                    216:  * Preference for optimization.
                    217:  */
                    218: #define FS_OPTTIME     0       /* minimize allocation time */
                    219: #define FS_OPTSPACE    1       /* minimize disk fragmentation */
                    220: 
                    221: /*
                    222:  * Convert cylinder group to base address of its global summary info.
                    223:  *
                    224:  * N.B. This macro assumes that sizeof(struct csum) is a power of two.
                    225:  */
                    226: #define fs_cs(fs, indx) \
                    227:        fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
                    228: 
                    229: /*
                    230:  * MAXBPC bounds the size of the rotational layout tables and
                    231:  * is limited by the fact that the super block is of size SBSIZE.
                    232:  * The size of these tables is INVERSELY proportional to the block
                    233:  * size of the file system. It is aggravated by sector sizes that
                    234:  * are not powers of two, as this increases the number of cylinders
                    235:  * included before the rotational pattern repeats (fs_cpc).
                    236:  * Its size is derived from the number of bytes remaining in (struct fs)
                    237:  */
                    238: #define        MAXBPC  (SBSIZE - sizeof (struct fs))
                    239: 
                    240: /*
                    241:  * Cylinder group block for a file system.
                    242:  */
                    243: #define        CG_MAGIC        0x090255
                    244: struct cg {
                    245:        struct  cg *cg_link;            /* linked list of cyl groups */
                    246:        struct  cg *cg_rlink;           /*     used for incore cyl groups */
                    247:        time_t  cg_time;                /* time last written */
                    248:        long    cg_cgx;                 /* we are the cgx'th cylinder group */
                    249:        short   cg_ncyl;                /* number of cyl's this cg */
                    250:        short   cg_niblk;               /* number of inode blocks this cg */
                    251:        long    cg_ndblk;               /* number of data blocks this cg */
                    252:        struct  csum cg_cs;             /* cylinder summary information */
                    253:        long    cg_rotor;               /* position of last used block */
                    254:        long    cg_frotor;              /* position of last used frag */
                    255:        long    cg_irotor;              /* position of last used inode */
                    256:        long    cg_frsum[MAXFRAG];      /* counts of available frags */
                    257:        long    cg_btot[MAXCPG];        /* block totals per cylinder */
                    258:        short   cg_b[MAXCPG][NRPOS];    /* positions of free blocks */
                    259:        char    cg_iused[MAXIPG/NBBY];  /* used inode map */
                    260:        long    cg_magic;               /* magic number */
                    261:        u_char  cg_free[1];             /* free block map */
                    262: /* actually longer */
                    263: };
                    264: 
                    265: /*
                    266:  * MAXBPG bounds the number of blocks of data per cylinder group,
                    267:  * and is limited by the fact that cylinder groups are at most one block.
                    268:  * Its size is derived from the size of blocks and the (struct cg) size,
                    269:  * by the number of remaining bits.
                    270:  */
                    271: #define        MAXBPG(fs) \
                    272:        (fragstoblks((fs), (NBBY * ((fs)->fs_bsize - (sizeof (struct cg))))))
                    273: 
                    274: /*
                    275:  * Turn file system block numbers into disk block addresses.
                    276:  * This maps file system blocks to device size blocks.
                    277:  */
                    278: #define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb)
                    279: #define        dbtofsb(fs, b)  ((b) >> (fs)->fs_fsbtodb)
                    280: 
                    281: /*
                    282:  * Cylinder group macros to locate things in cylinder groups.
                    283:  * They calc file system addresses of cylinder group data structures.
                    284:  */
                    285: #define        cgbase(fs, c)   ((daddr_t)((fs)->fs_fpg * (c)))
                    286: #define cgstart(fs, c) \
                    287:        (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
                    288: #define        cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno)      /* super blk */
                    289: #define        cgtod(fs, c)    (cgstart(fs, c) + (fs)->fs_cblkno)      /* cg block */
                    290: #define        cgimin(fs, c)   (cgstart(fs, c) + (fs)->fs_iblkno)      /* inode blk */
                    291: #define        cgdmin(fs, c)   (cgstart(fs, c) + (fs)->fs_dblkno)      /* 1st data */
                    292: 
                    293: /*
                    294:  * Macros for handling inode numbers:
                    295:  *     inode number to file system block offset.
                    296:  *     inode number to cylinder group number.
                    297:  *     inode number to file system block address.
                    298:  */
                    299: #define        itoo(fs, x)     ((x) % INOPB(fs))
                    300: #define        itog(fs, x)     ((x) / (fs)->fs_ipg)
                    301: #define        itod(fs, x) \
                    302:        ((daddr_t)(cgimin(fs, itog(fs, x)) + \
                    303:        (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
                    304: 
                    305: /*
                    306:  * Give cylinder group number for a file system block.
                    307:  * Give cylinder group block number for a file system block.
                    308:  */
                    309: #define        dtog(fs, d)     ((d) / (fs)->fs_fpg)
                    310: #define        dtogd(fs, d)    ((d) % (fs)->fs_fpg)
                    311: 
                    312: /*
                    313:  * Extract the bits for a block from a map.
                    314:  * Compute the cylinder and rotational position of a cyl block addr.
                    315:  */
                    316: #define blkmap(fs, map, loc) \
                    317:     (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
                    318: #define cbtocylno(fs, bno) \
                    319:     ((bno) * NSPF(fs) / (fs)->fs_spc)
                    320: #define cbtorpos(fs, bno) \
                    321:     (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \
                    322:      (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \
                    323:      (fs)->fs_nsect * NRPOS / (fs)->fs_npsect)
                    324: 
                    325: /*
                    326:  * The following macros optimize certain frequently calculated
                    327:  * quantities by using shifts and masks in place of divisions
                    328:  * modulos and multiplications.
                    329:  */
                    330: #define blkoff(fs, loc)                /* calculates (loc % fs->fs_bsize) */ \
                    331:        ((loc) & ~(fs)->fs_bmask)
                    332: #define fragoff(fs, loc)       /* calculates (loc % fs->fs_fsize) */ \
                    333:        ((loc) & ~(fs)->fs_fmask)
                    334: #define lblkno(fs, loc)                /* calculates (loc / fs->fs_bsize) */ \
                    335:        ((loc) >> (fs)->fs_bshift)
                    336: #define numfrags(fs, loc)      /* calculates (loc / fs->fs_fsize) */ \
                    337:        ((loc) >> (fs)->fs_fshift)
                    338: #define blkroundup(fs, size)   /* calculates roundup(size, fs->fs_bsize) */ \
                    339:        (((size) + (fs)->fs_bsize - 1) & (fs)->fs_bmask)
                    340: #define fragroundup(fs, size)  /* calculates roundup(size, fs->fs_fsize) */ \
                    341:        (((size) + (fs)->fs_fsize - 1) & (fs)->fs_fmask)
                    342: #define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \
                    343:        ((frags) >> (fs)->fs_fragshift)
                    344: #define blkstofrags(fs, blks)  /* calculates (blks * fs->fs_frag) */ \
                    345:        ((blks) << (fs)->fs_fragshift)
                    346: #define fragnum(fs, fsb)       /* calculates (fsb % fs->fs_frag) */ \
                    347:        ((fsb) & ((fs)->fs_frag - 1))
                    348: #define blknum(fs, fsb)                /* calculates rounddown(fsb, fs->fs_frag) */ \
                    349:        ((fsb) &~ ((fs)->fs_frag - 1))
                    350: 
                    351: /*
                    352:  * Determine the number of available frags given a
                    353:  * percentage to hold in reserve
                    354:  */
                    355: #define freespace(fs, percentreserved) \
                    356:        (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
                    357:        (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100))
                    358: 
                    359: /*
                    360:  * Determining the size of a file block in the file system.
                    361:  */
                    362: #define blksize(fs, ip, lbn) \
                    363:        (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \
                    364:            ? (fs)->fs_bsize \
                    365:            : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
                    366: #define dblksize(fs, dip, lbn) \
                    367:        (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
                    368:            ? (fs)->fs_bsize \
                    369:            : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
                    370: 
                    371: /*
                    372:  * Number of disk sectors per block; assumes DEV_BSIZE byte sector size.
                    373:  */
                    374: #define        NSPB(fs)        ((fs)->fs_nspf << (fs)->fs_fragshift)
                    375: #define        NSPF(fs)        ((fs)->fs_nspf)
                    376: 
                    377: /*
                    378:  * INOPB is the number of inodes in a secondary storage block.
                    379:  */
                    380: #define        INOPB(fs)       ((fs)->fs_inopb)
                    381: #define        INOPF(fs)       ((fs)->fs_inopb >> (fs)->fs_fragshift)
                    382: 
                    383: /*
                    384:  * NINDIR is the number of indirects in a file system block.
                    385:  */
                    386: #define        NINDIR(fs)      ((fs)->fs_nindir)
                    387: 
                    388: #ifdef KERNEL
                    389: struct fs *getfs();
                    390: struct fs *mountfs();
                    391: #endif

unix.superglobalmegacorp.com

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