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