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