fix to reeves fix of dgo handling (reset b_active to 1)
[unix-history] / .ref-BSD-3 / usr / man / man5 / filsys.5
CommitLineData
91cbef75
BJ
1.TH FILSYS 5
2.SH NAME
3filsys, flblk, ino \- format of file system volume
4.SH SYNOPSIS
5.B #include <sys/types.h>
6.br
7.B #include <sys/flbk.h>
8.br
9.B #include <sys/filsys.h>
10.br
11.B #include <sys/ino.h>
12.SH DESCRIPTION
13Every
14file system storage volume
15(e.g. RF disk, RK disk, RP disk, DECtape reel)
16has a common format for certain vital information.
17Every such volume is divided into a certain number
18of 1024-byte blocks.
19Block 0 is unused and is available to contain
20a bootstrap program, pack label, or other information.
21.PP
22Block 1 is the
23.I "super block."
24The layout of the super block as defined by the include file
25.I <sys/filsys.h>
26is:
27.PP
28.nf
29.ta \w'struct 'u +\w'daddr_t 'u +\w's_inode[NICINOD]; 'u
30.so /usr/include/sys/filsys.h
31.fi
32.PP
33.I S_isize
34is the address of the first block after the i-list,
35which starts just after the super-block, in block 2.
36Thus the i-list is
37.IR s_isize \-2
38blocks long.
39.I S_fsize
40is the address of the first block not potentially
41available for allocation
42to a file.
43These numbers are used by the system to
44check for bad block addresses;
45if an `impossible' block address is allocated from the free list
46or is freed,
47a diagnostic is written on the on-line console.
48Moreover, the free array is cleared, so as to prevent further
49allocation from a presumably corrupted free list.
50.PP
51The free list for each volume is maintained as
52follows.
53The
54.I s_free
55array contains, in
56.I "s_free[1], ... , s_free[s_nfree\-1],"
57up to NICFREE free block numbers.
58NICFREE is a configuration constant.
59.I S_free[0]
60is the block address of the head
61of a chain of blocks constituting the free list.
62The layout of each block of the free chain as defined
63in the include file
64.I <sys/fblk.h>
65is:
66.PP
67.nf
68.so /usr/include/sys/fblk.h
69.fi
70.PP
71The fields
72.I df_nfree
73and
74.I df_free
75in a free block are used exactly like
76.I s_nfree
77and
78.I s_free
79in the super block.
80To allocate a block:
81decrement
82.I s_nfree,
83and the new block number is
84.I s_free[s_nfree].
85If the new block address is 0,
86there are no blocks left, so give an error.
87If
88.I s_nfree
89became 0,
90read the new block into
91.I s_nfree
92and
93.I s_free.
94To free a block, check if
95.I s_nfree
96is NICFREE; if so,
97copy
98.I s_nfree
99and the
100.I s_free
101array into it,
102write it out, and set
103.I s_nfree
104to 0.
105In any event set
106.I s_free[s_nfree]
107to the freed block's address and
108increment
109.I s_nfree.
110.PP
111.I S_ninode
112is the number of free i-numbers in the
113.I s_inode
114array.
115To allocate an i-node:
116if
117.I s_ninode
118is greater than 0,
119decrement it and return
120.I s_inode[s_ninode].
121If it was 0, read the i-list
122and place the numbers of all free inodes
123(up to NICINOD) into the
124.I s_inode
125array,
126then try again.
127To free an i-node,
128provided
129.I s_ninode
130is less than NICINODE,
131place its number into
132.I s_inode[s_ninode]
133and increment
134.I s_ninode.
135If
136.I s_ninode
137is already NICINODE, don't bother to enter the freed i-node into any table.
138This list of i-nodes is only to speed
139up the allocation process; the information
140as to whether the inode is really free
141or not is maintained in the inode itself.
142.PP
143The fields
144.I s_lasti
145and
146.I s_nbehind
147are used to avoid searching the inode list from the beginning
148each time the system runs out of inodes.
149.I S_lasti
150gives the base of the block of inodes last searched on the filesystem
151when inodes ran out, and
152.I s_nbehind
153gives the number of inodes, whose numbers were less than
154.I s_lasti
155when they were freed with
156.I s_ninode
157already
158NICINODE.
159Thus
160.I s_ninode
161is the number of free inodes before
162.I s_lasti.
163The system will search forward for free inodes from
164.I s_lasti
165for more inodes unless
166.I s_nbehind
167is sufficiently large, in which case it will search the file system
168inode list from the beginning.
169This mechanism serves to avoid n**2 behavior in allocating inodes.
170.PP
171.I S_flock
172and
173.I s_ilock
174are flags maintained in the core
175copy of the file system
176while it is mounted
177and their values on disk are immaterial.
178The value of
179.I s_fmod
180on disk is likewise immaterial;
181it is used as a flag to indicate that the super-block has
182changed and should be copied to
183the disk during the next periodic update of file
184system information.
185.I S_ronly
186is a write-protection indicator; its disk value is also immaterial.
187.PP
188.I S_time
189is the last time the super-block of the file system was changed.
190During a reboot,
191.I s_time
192of the super-block for the root file system
193is used to set the system's idea of the time.
194.PP
195The fields
196.I s_tfree, s_tinode, s_fname
197and
198.I s_fpack
199are not currently maintained.
200.PP
201I-numbers begin at 1, and the storage for i-nodes
202begins in block 2.
203.tr |
204I-nodes are 64 bytes long, so 16 of them fit into a block.
205I-node 2 is reserved for the root directory of the file
206system, but no other i-number has a built-in
207meaning.
208Each i-node represents one file.
209The format of an i-node as given in the include file
210.I <sys/ino.h>
211is:
212.PP
213.nf
214.ta \w'#define 'u +\w'time_t 'u +\w'di_addr[40]; 'u
215.so /usr/include/sys/ino.h
216.fi
217.PP
218.I Di_mode
219tells the kind of file; it
220is encoded identically to the
221.I st_mode field of
222.IR stat (2).
223.I Di_nlink
224is the number of directory entries
225(links) that refer to this i-node.
226.I Di_uid
227and
228.I di_gid
229are the owner's user and group IDs.
230.I Size
231is the number of bytes in the file.
232.I Di_atime
233and
234.I di_mtime
235are the times of last access and modification
236of the file contents (read, write or create)
237(see
238.IR times (2));
239.I Di_ctime
240records the time of last modification
241to the inode or to the file, and is used
242to determine whether it should be dumped.
243.PP
244Special files are recognized by their modes
245and not by i-number.
246A block-type special file is one which
247can potentially be mounted as a file system;
248a character-type special file cannot, though it is
249not necessarily character-oriented.
250For special files, the
251.I di_addr
252field is occupied by the device code
253(see
254.IR types (5)).
255The device codes
256of block and character special files overlap.
257.PP
258Disk addresses of plain files and directories
259are kept in the array
260.I di_addr
261packed into 3 bytes each.
262The first 10 addresses specify device blocks directly.
263The last 3 addresses are singly, doubly, and triply
264indirect and point to blocks of 256 block pointers.
265Pointers in indirect blocks have the type
266.I daddr_t
267(see
268.IR types (5)).
269.PP
270For block
271.I b
272in a file to exist,
273it
274is not necessary that all blocks less than
275.I b
276exist.
277A zero block number either in the address words of
278the i-node or in an indirect block indicates that the
279corresponding block has never been allocated.
280Such a missing block reads as if it contained all zero words.
281.SH "SEE ALSO"
282icheck(1), dcheck(1), dir(5), mount(1), stat(2), types(5)