xref: /freebsd/share/man/man5/fs.5 (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
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$
34.\"
35.Dd April 19, 1994
36.Dt FS 5
37.Os BSD 4.2
38.Sh NAME
39.Nm fs ,
40.Nm inode
41.Nd format of file system volume
42.Sh SYNOPSIS
43.Fd #include <sys/param.h>
44.Fd #include <ufs/ffs/fs.h>
45.Pp
46.Fd #include <sys/types.h>
47.Fd #include <sys/lock.h>
48.Fd #include <ufs/ufs/quota.h>
49.Fd #include <ufs/ufs/inode.h>
50.Sh DESCRIPTION
51The files
52.Aq Pa fs.h
53and
54.Aq Pa inode.h
55declare several structures, defined variables and macros
56which are used to create and manage the underlying format of
57file system objects on random access devices (disks).
58.Pp
59The block size and number of blocks which
60comprise a file system are parameters of the file system.
61Sectors beginning at
62.Dv BBLOCK
63and continuing for
64.Dv BBSIZE
65are used
66for a disklabel and for some hardware primary
67and secondary bootstrapping programs.
68.Pp
69The actual file system begins at sector
70.Dv SBLOCK
71with the
72.Em super-block
73that is of size
74.Dv SBSIZE .
75The following structure describes the super-block and is
76from the file
77.Aq Pa ufs/ffs/fs.h :
78.Bd -literal
79/*
80 * Super block for an FFS file system.
81 */
82struct fs {
83	int32_t	 fs_firstfield;	/* historic file system linked list, */
84	int32_t	 fs_unused_1;	/*     used for incore super blocks */
85	ufs_daddr_t fs_sblkno;	/* addr of super-block in filesys */
86	ufs_daddr_t fs_cblkno;	/* offset of cyl-block in filesys */
87	ufs_daddr_t fs_iblkno;	/* offset of inode-blocks in filesys */
88	ufs_daddr_t fs_dblkno;	/* offset of first data after cg */
89	int32_t	 fs_cgoffset;	/* cylinder group offset in cylinder */
90	int32_t	 fs_cgmask;	/* used to calc mod fs_ntrak */
91	time_t 	 fs_time;	/* last time written */
92	int32_t	 fs_size;	/* number of blocks in fs */
93	int32_t	 fs_dsize;	/* number of data blocks in fs */
94	int32_t	 fs_ncg;	/* number of cylinder groups */
95	int32_t	 fs_bsize;	/* size of basic blocks in fs */
96	int32_t	 fs_fsize;	/* size of frag blocks in fs */
97	int32_t	 fs_frag;	/* number of frags in a block in fs */
98/* these are configuration parameters */
99	int32_t	 fs_minfree;	/* minimum percentage of free blocks */
100	int32_t	 fs_rotdelay;	/* num of ms for optimal next block */
101	int32_t	 fs_rps;	/* disk revolutions per second */
102/* these fields can be computed from the others */
103	int32_t	 fs_bmask;	/* ``blkoff'' calc of blk offsets */
104	int32_t	 fs_fmask;	/* ``fragoff'' calc of frag offsets */
105	int32_t	 fs_bshift;	/* ``lblkno'' calc of logical blkno */
106	int32_t	 fs_fshift;	/* ``numfrags'' calc number of frags */
107/* these are configuration parameters */
108	int32_t	 fs_maxcontig;	/* max number of contiguous blks */
109	int32_t	 fs_maxbpg;	/* max number of blks per cyl group */
110/* these fields can be computed from the others */
111	int32_t	 fs_fragshift;	/* block to frag shift */
112	int32_t	 fs_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
113	int32_t	 fs_sbsize;	/* actual size of super block */
114	int32_t	 fs_csmask;	/* csum block offset */
115	int32_t	 fs_csshift;	/* csum block number */
116	int32_t	 fs_nindir;	/* value of NINDIR */
117	int32_t	 fs_inopb;	/* value of INOPB */
118	int32_t	 fs_nspf;	/* value of NSPF */
119/* yet another configuration parameter */
120	int32_t	 fs_optim;	/* optimization preference, see below */
121/* these fields are derived from the hardware */
122	int32_t	 fs_npsect;	/* # sectors/track including spares */
123	int32_t	 fs_interleave;	/* hardware sector interleave */
124	int32_t	 fs_trackskew;	/* sector 0 skew, per track */
125/* fs_id takes the space of the unused fs_headswitch and fs_trkseek fields */
126	int32_t	fs_id[2];	/* unique filesystem id*/
127/* sizes determined by number of cylinder groups and their sizes */
128	ufs_daddr_t fs_csaddr;	/* blk addr of cyl grp summary area */
129	int32_t	 fs_cssize;	/* size of cyl grp summary area */
130	int32_t	 fs_cgsize;	/* cylinder group size */
131/* these fields are derived from the hardware */
132	int32_t	 fs_ntrak;	/* tracks per cylinder */
133	int32_t	 fs_nsect;	/* sectors per track */
134	int32_t  fs_spc;	/* sectors per cylinder */
135/* this comes from the disk driver partitioning */
136	int32_t	 fs_ncyl;	/* cylinders in file system */
137/* these fields can be computed from the others */
138	int32_t	 fs_cpg;	/* cylinders per group */
139	int32_t	 fs_ipg;	/* inodes per group */
140	int32_t	 fs_fpg;	/* blocks per group * fs_frag */
141/* this data must be re-computed after crashes */
142	struct	csum fs_cstotal;/* cylinder summary information */
143/* these fields are cleared at mount time */
144	int8_t   fs_fmod;	/* super block modified flag */
145	int8_t   fs_clean;	/* file system is clean flag */
146	int8_t 	 fs_ronly;	/* mounted read-only flag */
147	int8_t   fs_flags;	/* currently unused flag */
148	u_char	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
149/* these fields retain the current block allocation info */
150	int32_t	 fs_cgrotor;	/* last cg searched */
151	struct	csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
152	int32_t	 *fs_maxcluster;/* max cluster in each cyl group */
153	int32_t	 fs_cpc;	/* cyl per cycle in postbl */
154	int16_t	 fs_opostbl[16][8];	/* old rotation block list head */
155	int32_t	 fs_sparecon[50];	/* reserved for future constants */
156	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
157	int32_t	 fs_maxsymlinklen;/* max length of an internal symlink */
158	int32_t	 fs_inodefmt;	/* format of on-disk inodes */
159	u_int64_t fs_maxfilesize;/* maximum representable file size */
160	int64_t	 fs_qbmask;	/* ~fs_bmask for use with 64-bit size */
161	int64_t	 fs_qfmask;	/* ~fs_fmask for use with 64-bit size */
162	int32_t	 fs_state;	/* validate fs_clean field */
163	int32_t	 fs_postblformat;/* format of positional layout tables */
164	int32_t	 fs_nrpos;	/* number of rotational positions */
165	int32_t	 fs_postbloff;	/* (u_int16) rotation block list head */
166	int32_t	 fs_rotbloff;	/* (u_int8) blocks for each rotation */
167	int32_t	 fs_magic;	/* magic number */
168	u_int8_t fs_space[1];	/* list of blocks for each rotation */
169/* actually longer */
170};
171
172/*
173 * Filesystem identification
174 */
175#define	FS_MAGIC	0x011954   /* the fast filesystem magic number */
176#define	FS_OKAY		0x7c269d38 /* superblock checksum */
177#define FS_42INODEFMT	-1	   /* 4.2BSD inode format */
178#define FS_44INODEFMT	2	   /* 4.4BSD inode format */
179/*
180 * Preference for optimization.
181 */
182#define FS_OPTTIME	0	/* minimize allocation time */
183#define FS_OPTSPACE	1	/* minimize disk fragmentation */
184
185/*
186 * Rotational layout table format types
187 */
188#define FS_42POSTBLFMT		-1  /* 4.2BSD rotational table format */
189#define FS_DYNAMICPOSTBLFMT	1   /* dynamic rotational table format */
190.Ed
191.Pp
192Each disk drive contains some number of file systems.
193A file system consists of a number of cylinder groups.
194Each cylinder group has inodes and data.
195.Pp
196A file system is described by its super-block, which in turn
197describes the cylinder groups.  The super-block is critical
198data and is replicated in each cylinder group to protect against
199catastrophic loss.  This is done at file system creation
200time and the critical
201super-block data does not change, so the copies need not be
202referenced further unless disaster strikes.
203.Pp
204Addresses stored in inodes are capable of addressing fragments
205of `blocks'. File system blocks of at most size
206.Dv MAXBSIZE
207can
208be optionally broken into 2, 4, or 8 pieces, each of which is
209addressable; these pieces may be
210.Dv DEV_BSIZE ,
211or some multiple of
212a
213.Dv DEV_BSIZE
214unit.
215.Pp
216Large files consist of exclusively large data blocks.  To avoid
217undue wasted disk space, the last data block of a small file is
218allocated as only as many fragments of a large block as are
219necessary.  The file system format retains only a single pointer
220to such a fragment, which is a piece of a single large block that
221has been divided.  The size of such a fragment is determinable from
222information in the inode, using the
223.Fn blksize fs ip lbn
224macro.
225.Pp
226The file system records space availability at the fragment level;
227to determine block availability, aligned fragments are examined.
228.Pp
229The root inode is the root of the file system.
230Inode 0 can't be used for normal purposes and
231historically bad blocks were linked to inode 1,
232thus the root inode is 2 (inode 1 is no longer used for
233this purpose, however numerous dump tapes make this
234assumption, so we are stuck with it).
235.Pp
236The
237.Fa fs_minfree
238element gives the minimum acceptable percentage of file system
239blocks that may be free. If the freelist drops below this level
240only the super-user may continue to allocate blocks.
241The
242.Fa fs_minfree
243element
244may be set to 0 if no reserve of free blocks is deemed necessary,
245however severe performance degradations will be observed if the
246file system is run at greater than 90% full; thus the default
247value of
248.Fa fs_minfree
249is 10%.
250.Pp
251Empirically the best trade-off between block fragmentation and
252overall disk utilization at a loading of 90% comes with a
253fragmentation of 8, thus the default fragment size is an eighth
254of the block size.
255.Pp
256The element
257.Fa fs_optim
258specifies whether the file system should try to minimize the time spent
259allocating blocks, or if it should attempt to minimize the space
260fragmentation on the disk.
261If the value of fs_minfree (see above) is less than 10%,
262then the file system defaults to optimizing for space to avoid
263running out of full sized blocks.
264If the value of minfree is greater than or equal to 10%,
265fragmentation is unlikely to be problematical, and
266the file system defaults to optimizing for time.
267.Pp
268.Em Cylinder group related limits :
269Each cylinder keeps track of the availability of blocks at different
270rotational positions, so that sequential blocks can be laid out
271with minimum rotational latency. With the default of 8 distinguished
272rotational positions, the resolution of the
273summary information is 2ms for a typical 3600 rpm drive.
274.Pp
275The element
276.Fa fs_rotdelay
277gives the minimum number of milliseconds to initiate
278another disk transfer on the same cylinder.
279It is used in determining the rotationally optimal
280layout for disk blocks within a file;
281the default value for
282.Fa fs_rotdelay
283is 2ms.
284.Pp
285Each file system has a statically allocated number of inodes.
286An inode is allocated for each
287.Dv NBPI
288bytes of disk space.
289The inode allocation strategy is extremely conservative.
290.Pp
291.Dv MINBSIZE
292is the smallest allowable block size.
293With a
294.Dv MINBSIZE
295of 4096
296it is possible to create files of size
2972^32 with only two levels of indirection.
298.Dv MINBSIZE
299must be big enough to hold a cylinder group block,
300thus changes to
301.Pq Fa struct cg
302must keep its size within
303.Dv MINBSIZE .
304Note that super-blocks are never more than size
305.Dv SBSIZE .
306.Pp
307The path name on which the file system is mounted is maintained in
308.Fa fs_fsmnt .
309.Dv MAXMNTLEN
310defines the amount of space allocated in
311the super-block for this name.
312The limit on the amount of summary information per file system
313is defined by
314.Dv MAXCSBUFS.
315For a 4096 byte block size, it is currently parameterized for a
316maximum of two million cylinders.
317.Pp
318Per cylinder group information is summarized in blocks allocated
319from the first cylinder group's data blocks.
320These blocks are read in from
321.Fa fs_csaddr
322(size
323.Fa fs_cssize )
324in addition to the super-block.
325.Pp
326.Sy N.B.:
327.Fn sizeof "struct csum"
328must be a power of two in order for
329the
330.Fn fs_cs
331macro to work.
332.Pp
333The
334.Em "Super-block for a file system" :
335The size of the rotational layout tables
336is limited by the fact that the super-block is of size
337.Dv SBSIZE .
338The size of these tables is
339.Em inversely
340proportional to the block
341size of the file system. The 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.Tn UNIX
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.Aq Pa ufs/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