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