1.\" $NetBSD: fs.5,v 1.9 1999/03/17 20:19:45 garbled Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)fs.5 8.2 (Berkeley) 4/19/94 35.\" 36.Dd April 19, 1994 37.Dt FS 5 38.Os 39.Sh NAME 40.Nm fs , 41.Nm inode 42.Nd format of file system volume 43.Sh SYNOPSIS 44.Fd #include <sys/types.h> 45.Fd #include <ufs/ffs/fs.h> 46.Fd #include <ufs/ufs/inode.h> 47.Sh DESCRIPTION 48The files 49.Aq Pa fs.h 50and 51.Aq Pa inode.h 52declare several structures, defined variables and macros 53which are used to create and manage the underlying format of 54file system objects on random access devices (disks). 55.Pp 56The block size and number of blocks which 57comprise a file system are parameters of the file system. 58Sectors beginning at 59.Dv BBLOCK 60and continuing for 61.Dv BBSIZE 62are used 63for a disklabel and for some hardware primary 64and secondary bootstrapping programs. 65.Pp 66The actual file system begins at sector 67.Dv SBLOCK 68with the 69.Em super-block 70that is of size 71.Dv SBSIZE . 72The following structure described the super-block and is 73from the file 74.Aq Pa ufs/ffs/fs.h : 75.Bd -literal 76#define FS_MAGIC 0x011954 77struct fs { 78 struct fs *fs_link; /* linked list of file systems */ 79 struct fs *fs_rlink; /* used for incore super blocks */ 80 daddr_t fs_sblkno; /* addr of super-block in filesys */ 81 daddr_t fs_cblkno; /* offset of cyl-block in filesys */ 82 daddr_t fs_iblkno; /* offset of inode-blocks in filesys */ 83 daddr_t fs_dblkno; /* offset of first data after cg */ 84 long fs_cgoffset; /* cylinder group offset in cylinder */ 85 long fs_cgmask; /* used to calc mod fs_ntrak */ 86 time_t fs_time; /* last time written */ 87 long fs_size; /* number of blocks in fs */ 88 long fs_dsize; /* number of data blocks in fs */ 89 long fs_ncg; /* number of cylinder groups */ 90 long fs_bsize; /* size of basic blocks in fs */ 91 long fs_fsize; /* size of frag blocks in fs */ 92 long fs_frag; /* number of frags in a block in fs */ 93/* these are configuration parameters */ 94 long fs_minfree; /* minimum percentage of free blocks */ 95 long fs_rotdelay; /* num of ms for optimal next block */ 96 long fs_rps; /* disk revolutions per second */ 97/* these fields can be computed from the others */ 98 long fs_bmask; /* ``blkoff'' calc of blk offsets */ 99 long fs_fmask; /* ``fragoff'' calc of frag offsets */ 100 long fs_bshift; /* ``lblkno'' calc of logical blkno */ 101 long fs_fshift; /* ``numfrags'' calc number of frags */ 102/* these are configuration parameters */ 103 long fs_maxcontig; /* max number of contiguous blks */ 104 long fs_maxbpg; /* max number of blks per cyl group */ 105/* these fields can be computed from the others */ 106 long fs_fragshift; /* block to frag shift */ 107 long fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 108 long fs_sbsize; /* actual size of super block */ 109 long fs_csmask; /* csum block offset */ 110 long fs_csshift; /* csum block number */ 111 long fs_nindir; /* value of NINDIR */ 112 long fs_inopb; /* value of INOPB */ 113 long fs_nspf; /* value of NSPF */ 114/* yet another configuration parameter */ 115 long fs_optim; /* optimization preference, see below */ 116/* these fields are derived from the hardware */ 117 long fs_npsect; /* # sectors/track including spares */ 118 long fs_interleave; /* hardware sector interleave */ 119 long fs_trackskew; /* sector 0 skew, per track */ 120 long fs_headswitch; /* head switch time, usec */ 121 long fs_trkseek; /* track-to-track seek, usec */ 122/* sizes determined by number of cylinder groups and their sizes */ 123 daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ 124 long fs_cssize; /* size of cyl grp summary area */ 125 long fs_cgsize; /* cylinder group size */ 126/* these fields are derived from the hardware */ 127 long fs_ntrak; /* tracks per cylinder */ 128 long fs_nsect; /* sectors per track */ 129 long fs_spc; /* sectors per cylinder */ 130/* this comes from the disk driver partitioning */ 131 long fs_ncyl; /* cylinders in file system */ 132/* these fields can be computed from the others */ 133 long fs_cpg; /* cylinders per group */ 134 long fs_ipg; /* inodes per group */ 135 long fs_fpg; /* blocks per group * fs_frag */ 136/* this data must be re-computed after crashes */ 137 struct csum fs_cstotal; /* cylinder summary information */ 138/* these fields are cleared at mount time */ 139 char fs_fmod; /* super block modified flag */ 140 char fs_clean; /* file system is clean flag */ 141 char fs_ronly; /* mounted read-only flag */ 142 char fs_flags; /* currently unused flag */ 143 char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ 144/* these fields retain the current block allocation info */ 145 long fs_cgrotor; /* last cg searched */ 146 struct csum *fs_csp[MAXCSBUFS]; /* list of fs_cs info buffers */ 147 long fs_cpc; /* cyl per cycle in postbl */ 148 short fs_opostbl[16][8]; /* old rotation block list head */ 149 long fs_sparecon[56]; /* reserved for future constants */ 150 quad fs_qbmask; /* ~fs_bmask - for use with quad size */ 151 quad fs_qfmask; /* ~fs_fmask - for use with quad size */ 152 long fs_postblformat; /* format of positional layout tables */ 153 long fs_nrpos; /* number of rotational positions */ 154 long fs_postbloff; /* (short) rotation block list head */ 155 long fs_rotbloff; /* (u_char) blocks for each rotation */ 156 long fs_magic; /* magic number */ 157 u_char fs_space[1]; /* list of blocks for each rotation */ 158/* actually longer */ 159}; 160.Ed 161.Pp 162Each disk drive contains some number of file systems. 163A file system consists of a number of cylinder groups. 164Each cylinder group has inodes and data. 165.Pp 166A file system is described by its super-block, which in turn 167describes the cylinder groups. 168The super-block is critical data and is replicated in each cylinder 169group to protect against catastrophic loss. 170This is done at file system creation time and the critical super-block 171data does not change, so the copies need not be referenced further 172unless disaster strikes. 173.Pp 174Addresses stored in inodes are capable of addressing fragments 175of `blocks'. 176File system blocks of at most size 177.Dv MAXBSIZE 178can 179be optionally broken into 2, 4, or 8 pieces, each of which is 180addressable; these pieces may be 181.Dv DEV_BSIZE , 182or some multiple of 183a 184.Dv DEV_BSIZE 185unit. 186.Pp 187Large files consist of exclusively large data blocks. 188To avoid undue wasted disk space, the last data block of a small 189file is allocated as only as many fragments of a large block as 190are necessary. 191The file system format retains only a single pointer to such a 192fragment, which is a piece of a single large block that has been divided. 193The size of such a fragment is determinable from 194information in the inode, using the 195.Fn blksize fs ip lbn 196macro. 197.Pp 198The file system records space availability at the fragment level; 199to determine block availability, aligned fragments are examined. 200.Pp 201The root inode is the root of the file system. 202Inode 0 can't be used for normal purposes and 203historically bad blocks were linked to inode 1, 204thus the root inode is 2 (inode 1 is no longer used for 205this purpose, however numerous dump tapes make this 206assumption, so we are stuck with it). 207.Pp 208The 209.Fa fs_minfree 210element gives the minimum acceptable percentage of file system 211blocks that may be free. 212If the freelist drops below this level 213only the super-user may continue to allocate blocks. 214The 215.Fa fs_minfree 216element 217may be set to 0 if no reserve of free blocks is deemed necessary, 218however severe performance degradations will be observed if the 219file system is run at greater than 90% full; thus the default 220value of 221.Fa fs_minfree 222is 10%. 223.Pp 224Empirically the best trade-off between block fragmentation and 225overall disk utilization at a loading of 90% comes with a 226fragmentation of 8, thus the default fragment size is an eighth 227of the block size. 228.Pp 229The element 230.Fa fs_optim 231specifies whether the file system should try to minimize the time spent 232allocating blocks, or if it should attempt to minimize the space 233fragmentation on the disk. 234If the value of fs_minfree (see above) is less than 10%, 235then the file system defaults to optimizing for space to avoid 236running out of full sized blocks. 237If the value of minfree is greater than or equal to 10%, 238fragmentation is unlikely to be problematical, and 239the file system defaults to optimizing for time. 240.Pp 241.Em Cylinder group related limits : 242Each cylinder keeps track of the availability of blocks at different 243rotational positions, so that sequential blocks can be laid out 244with minimum rotational latency. 245With the default of 8 distinguished 246rotational positions, the resolution of the 247summary information is 2ms for a typical 3600 rpm drive. 248.Pp 249The element 250.Fa fs_rotdelay 251gives the minimum number of milliseconds to initiate 252another disk transfer on the same cylinder. 253It is used in determining the rotationally optimal 254layout for disk blocks within a file; 255the default value for 256.Fa fs_rotdelay 257is 2ms. 258.Pp 259Each file system has a statically allocated number of inodes, 260determined by its size and the desired number of file data bytes per 261inode at the time it was created. See 262.Xr newfs 8 263for details on how to set this (and other) filesystem parameters. 264By default, the inode allocation strategy is extremely conservative. 265.Pp 266.Dv MINBSIZE 267is the smallest allowable block size. 268With a 269.Dv MINBSIZE 270of 4096 271it is possible to create files of size 2722^32 with only two levels of indirection. 273.Dv MINBSIZE 274must be big enough to hold a cylinder group block, 275thus changes to 276.Pq Fa struct cg 277must keep its size within 278.Dv MINBSIZE . 279Note that super-blocks are never more than size 280.Dv SBSIZE . 281.Pp 282The path name on which the file system is mounted is maintained in 283.Fa fs_fsmnt . 284.Dv MAXMNTLEN 285defines the amount of space allocated in 286the super-block for this name. 287The limit on the amount of summary information per file system 288is defined by 289.Dv MAXCSBUFS. 290For a 4096 byte block size, it is currently parameterized for a 291maximum of two million cylinders. 292.Pp 293Per cylinder group information is summarized in blocks allocated 294from the first cylinder group's data blocks. 295These blocks are read in from 296.Fa fs_csaddr 297(size 298.Fa fs_cssize ) 299in addition to the super-block. 300.Pp 301.Sy N.B.: 302.Fn sizeof "struct csum" 303must be a power of two in order for 304the 305.Fn fs_cs 306macro to work. 307.Pp 308The 309.Em "Super-block for a file system" : 310The size of the rotational layout tables 311is limited by the fact that the super-block is of size 312.Dv SBSIZE . 313The size of these tables is 314.Em inversely 315proportional to the block size of the file system. 316The size of the tables is increased when sector sizes are not powers 317of two, as this increases the number of cylinders included before 318the rotational pattern repeats 319.Pq Fa fs_cpc . 320The size of the rotational layout 321tables is derived from the number of bytes remaining in 322.Pq Fa struct fs . 323.Pp 324The number of blocks of data per cylinder group 325is limited because cylinder groups are at most one block. 326The inode and free block tables 327must fit into a single block after deducting space for 328the cylinder group structure 329.Pq Fa struct cg . 330.Pp 331The 332.Em Inode : 333The inode is the focus of all file activity in the 334.Ux 335file system. 336There is a unique inode allocated 337for each active file, 338each current directory, each mounted-on file, 339text file, and the root. 340An inode is `named' by its device/i-number pair. 341For further information, see the include file 342.Aq Pa ufs/ufs/inode.h . 343.Sh SEE ALSO 344.Xr newfs 8 345.Sh HISTORY 346A super-block structure named filsys appeared in 347.At v6 . 348The file system described in this manual appeared 349in 350.Bx 4.2 . 351