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