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