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