]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man5/fs.5
BSD 4.4 Lite Share Sources
[FreeBSD/FreeBSD.git] / share / man / man5 / fs.5
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/fs.h>
44 .Fd #include <ufs/inode.h>
45 .Sh DESCRIPTION
46 The files
47 .Aq Pa fs.h
48 and
49 .Aq Pa inode.h
50 declare several structures, defined variables and macros
51 which are used to create and manage the underlying format of
52 file system objects on random access devices (disks).
53 .Pp
54 The block size and number of blocks which
55 comprise a file system are parameters of the file system.
56 Sectors beginning at
57 .Dv BBLOCK
58 and continuing for
59 .Dv BBSIZE
60 are used
61 for a disklabel and for some hardware primary
62 and secondary bootstrapping programs.
63 .Pp
64 The actual file system begins at sector
65 .Dv SBLOCK
66 with the
67 .Em super-block
68 that is of size
69 .Dv SBSIZE .
70 The following structure described the super-block and is
71 from the file
72 .Aq Pa ufs/fs.h :
73 .Bd -literal
74 #define FS_MAGIC 0x011954
75 struct 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 rotational 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
160 Each disk drive contains some number of file systems.
161 A file system consists of a number of cylinder groups.
162 Each cylinder group has inodes and data.
163 .Pp
164 A file system is described by its super-block, which in turn
165 describes the cylinder groups.  The super-block is critical
166 data and is replicated in each cylinder group to protect against
167 catastrophic loss.  This is done at file system creation
168 time and the critical
169 super-block data does not change, so the copies need not be
170 referenced further unless disaster strikes.
171 .Pp
172 Addresses stored in inodes are capable of addressing fragments
173 of `blocks'. File system blocks of at most size
174 .Dv MAXBSIZE
175 can 
176 be optionally broken into 2, 4, or 8 pieces, each of which is
177 addressable; these pieces may be
178 .Dv DEV_BSIZE ,
179 or some multiple of
180 a
181 .Dv DEV_BSIZE
182 unit.
183 .Pp
184 Large files consist of exclusively large data blocks.  To avoid
185 undue wasted disk space, the last data block of a small file is
186 allocated as only as many fragments of a large block as are
187 necessary.  The file system format retains only a single pointer
188 to such a fragment, which is a piece of a single large block that
189 has been divided.  The size of such a fragment is determinable from
190 information in the inode, using the
191 .Fn blksize fs ip lbn
192 macro.
193 .Pp
194 The file system records space availability at the fragment level;
195 to determine block availability, aligned fragments are examined.
196 .Pp
197 The root inode is the root of the file system.
198 Inode 0 can't be used for normal purposes and
199 historically bad blocks were linked to inode 1,
200 thus the root inode is 2 (inode 1 is no longer used for
201 this purpose, however numerous dump tapes make this
202 assumption, so we are stuck with it).
203 .Pp
204 The
205 .Fa fs_minfree
206 element gives the minimum acceptable percentage of file system
207 blocks that may be free. If the freelist drops below this level
208 only the super-user may continue to allocate blocks.
209 The
210 .Fa fs_minfree
211 element
212 may be set to 0 if no reserve of free blocks is deemed necessary,
213 however severe performance degradations will be observed if the
214 file system is run at greater than 90% full; thus the default
215 value of
216 .Fa fs_minfree
217 is 10%.
218 .Pp
219 Empirically the best trade-off between block fragmentation and
220 overall disk utilization at a loading of 90% comes with a
221 fragmentation of 8, thus the default fragment size is an eighth
222 of the block size.
223 .Pp
224 The element
225 .Fa fs_optim
226 specifies whether the file system should try to minimize the time spent
227 allocating blocks, or if it should attempt to minimize the space
228 fragmentation on the disk.
229 If the value of fs_minfree (see above) is less than 10%,
230 then the file system defaults to optimizing for space to avoid
231 running out of full sized blocks.
232 If the value of minfree is greater than or equal to 10%,
233 fragmentation is unlikely to be problematical, and
234 the file system defaults to optimizing for time.
235 .Pp
236 .Em Cylinder group related limits :
237 Each cylinder keeps track of the availability of blocks at different
238 rotational positions, so that sequential blocks can be laid out
239 with minimum rotational latency. With the default of 8 distinguished
240 rotational positions, the resolution of the
241 summary information is 2ms for a typical 3600 rpm drive.
242 .Pp
243 The element
244 .Fa fs_rotdelay
245 gives the minimum number of milliseconds to initiate
246 another disk transfer on the same cylinder.
247 It is used in determining the rotationally optimal
248 layout for disk blocks within a file;
249 the default value for
250 .Fa fs_rotdelay
251 is 2ms.
252 .Pp
253 Each file system has a statically allocated number of inodes.
254 An inode is allocated for each
255 .Dv NBPI
256 bytes of disk space.
257 The inode allocation strategy is extremely conservative.
258 .Pp
259 .Dv MINBSIZE
260 is the smallest allowable block size.
261 With a
262 .Dv MINBSIZE
263 of 4096
264 it is possible to create files of size
265 2^32 with only two levels of indirection.
266 .Dv MINBSIZE
267 must be big enough to hold a cylinder group block,
268 thus changes to
269 .Pq Fa struct cg
270 must keep its size within
271 .Dv MINBSIZE .
272 Note that super-blocks are never more than size
273 .Dv SBSIZE .
274 .Pp
275 The path name on which the file system is mounted is maintained in
276 .Fa fs_fsmnt .
277 .Dv MAXMNTLEN
278 defines the amount of space allocated in 
279 the super-block for this name.
280 The limit on the amount of summary information per file system
281 is defined by
282 .Dv MAXCSBUFS.
283 For a 4096 byte block size, it is currently parameterized for a
284 maximum of two million cylinders.
285 .Pp
286 Per cylinder group information is summarized in blocks allocated
287 from the first cylinder group's data blocks. 
288 These blocks are read in from
289 .Fa fs_csaddr
290 (size
291 .Fa fs_cssize )
292 in addition to the super-block.
293 .Pp
294 .Sy N.B.:
295 .Xr sizeof Pq Fa struct csum
296 must be a power of two in order for
297 the
298 .Fn fs_cs
299 macro to work.
300 .Pp
301 The
302 .Em "Super-block for a file system" :
303 The size of the rotational layout tables
304 is limited by the fact that the super-block is of size
305 .Dv SBSIZE .
306 The size of these tables is
307 .Em inversely
308 proportional to the block
309 size of the file system. The size of the tables is
310 increased when sector sizes are not powers of two,
311 as this increases the number of cylinders
312 included before the rotational pattern repeats
313 .Pq Fa fs_cpc .
314 The size of the rotational layout
315 tables is derived from the number of bytes remaining in
316 .Pq Fa struct fs .
317 .Pp
318 The number of blocks of data per cylinder group
319 is limited because cylinder groups are at most one block.
320 The inode and free block tables
321 must fit into a single block after deducting space for
322 the cylinder group structure
323 .Pq Fa struct cg .
324 .Pp
325 The
326 .Em Inode :
327 The inode is the focus of all file activity in the
328 .Tn UNIX
329 file system.
330 There is a unique inode allocated
331 for each active file,
332 each current directory, each mounted-on file,
333 text file, and the root.
334 An inode is `named' by its device/i-number pair.
335 For further information, see the include file
336 .Aq Pa sys/inode.h .
337 .Sh HISTORY
338 A super-block structure named filsys appeared in
339 .At v6 .
340 The file system described in this manual appeared
341 in
342 .Bx 4.2 .