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