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