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