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