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