Research V4 development
[unix-history] / man / man5 / fs.5
CommitLineData
6f5c3593
KT
1.th "FILE SYSTEM" V 9/7/73
2.sh NAME
3fs \*- format of file system volume
4.sh DESCRIPTION
5.ft I
6Caution: this information applies only to
7the latest versions of the UNIX system.
8.s3
9.ft R
10Every
11file system storage volume
12(e.g. RF disk, RK disk, RP disk, DECtape reel)
13has a common format for certain vital information.
14Every such volume is divided into a certain number
15of 256 word (512 byte) blocks.
16Block 0 is unused and is available to contain
17a bootstrap program, pack label, or other information.
18.s3
19Block 1 is the
20.it "super block."
21Starting from its first word, the format of a super-block is
22.s3
23.nf
24struct {
25 int isize;
26 int fsize;
27 int nfree;
28 int free[100];
29 int ninode;
30 int inode[100];
31 char flock;
32 char ilock;
33 char fmod;
34 int time[2];
35};
36.s3
37.fi
38.it Isize
39is the number of blocks devoted to the i-list,
40which starts just after the super-block, in block 2.
41.it Fsize
42is the first block not potentially available for allocation
43to a file.
44This number is unused by the system, but is used by
45programs like
46.it "check (I)"
47to test for bad block numbers.
48The free list for each volume is maintained as
49follows.
50The
51.it free
52array contains, in
53.it "free[1], ... , free[nfree\*-1],"
54up to 99 numbers of free blocks.
55.it Free[0]
56is the block number of the head
57of a chain of blocks constituting the free list.
58The first word in each free-chain block is the number
59(up to 100) of free-block numbers listed in the
60next 100 words of this chain member.
61The first of these 100 blocks is the link to the
62next member of the chain.
63To allocate a block:
64decrement
65.it nfree,
66and the new block is
67.it free[nfree].
68If the new block number is 0,
69there are no blocks left, so give an error.
70If
71.it nfree
72became 0,
73read in the block named by the new block number,
74replace
75.it nfree
76by its first word,
77and copy the block numbers in the next 100 words into the
78.it free
79array.
80To free a block, check if
81.it nfree
82is 100; if so,
83copy
84.it nfree
85and the
86.it free
87array into it,
88write it out, and set
89.it nfree
90to 0.
91In any event set
92.it free[nfree]
93to the freed block's number and
94increment
95.it nfree.
96.s3
97.it Ninode
98is the number of free i-numbers in the
99.it inode
100array.
101To allocate an i-node:
102if
103.it ninode
104is greater than 0,
105decrement it and return
106.it inode[ninode].
107If it was 0, read the i-list
108and place the numbers of all free inodes
109(up to 100) into the
110.it inode
111array,
112then try again.
113To free an i-node,
114provided
115.it ninode
116is less than 100,
117place its number into
118.it inode[ninode]
119and increment
120.it ninode.
121If
122.it ninode
123is already 100, don't bother to enter the freed i-node into any table.
124This list of i-nodes is only to speed
125up the allocation process; the information
126as to whether the inode is really free
127or not is maintained in the inode itself.
128.s3
129.it Flock
130and
131.it ilock
132are flags maintained in the core
133copy of the file system
134while it is mounted
135and their values on disk are immaterial.
136The value of
137.it fmod
138on disk is likewise immaterial;
139it is used as a flag to indicate that the super-block has
140changed and should be copied to
141the disk during the next periodic update of file
142system information.
143.s3
144.it Time
145is the last time the super-block of the file system was changed,
146and is a double-precision representation
147of the number of seconds that have elapsed
148since
1490000 Jan. 1 1970 (GMT).
150During a reboot, the
151.it time
152of the super-block for the root file system
153is used to set the system's idea of the time.
154.s3
155I-numbers begin at 1, and the storage for i-nodes
156begins in block 2.
157.tr |
158Also, i-nodes are 32 bytes long, so 16 of them fit into a block.
159Therefore, i-node
160.it i
161is located in block (\fIi\fR|+|31)|/|16, and begins
16232\u\fB.\fR\d((\fIi\fR|+|31)|(mod 16) bytes from its start.
163I-node 1 is reserved for the root directory of the file
164system, but no other i-number has a built-in
165meaning.
166Each i-node represents one file.
167The format of an i-node is as follows.
168.s3
169.nf
170.if t .ta .5i 1.i 2.5i
171struct {
172 int flags; /* +0: see below */
173 char nlinks; /* +2: number of links to file */
174 char uid; /* +3: user ID of owner */
175 char gid; /* +4: group ID of owner */
176 char size0; /* +5: high byte of 24-bit size */
177 int size1; /* +6: low word of 24-bit size */
178 int addr[8]; /* +8: block numbers or device number */
179 int actime[2]; /* +24: time of last access */
180 int modtime[2]; /* +28: time of last modification */
181};
182.dt
183.fi
184.s3
185The flags are as follows:
186.s3
187.lp +10 9
188100000 i-node is allocated
189.lp +10 9
190060000 2-bit file type:
191.lp +15 9
192000000 plain file
193.lp +15 9
194040000 directory
195.lp +15 9
196020000 character-type special file
197.lp +15 9
198060000 block-type special file.
199.lp +10 9
200010000 large file
201.lp +10 9
202004000 set user-ID on execution
203.lp +10 9
204002000 set group-ID on execution
205.lp +10 9
206000400 read (owner)
207.lp +10 9
208000200 write (owner)
209.lp +10 9
210000100 execute (owner)
211.lp +10 9
212000070 read, write, execute (group)
213.lp +10 9
214000007 read, write, execute (others)
215.s3
216.i0
217Special files are recognized by their flags
218and not by i-number.
219A block-type special file is basically one which
220can potentially be mounted as a file system;
221a character-type special file cannot, though it is
222not necessarily character-oriented.
223For special files the high byte of the first address word
224specifies the type of device; the low byte specifies
225one of several devices of
226that type.
227The device type numbers
228of block and character special files overlap.
229.s3
230The address words of ordinary files and directories
231contain the numbers of the blocks in the
232file (if it is small)
233or the numbers of indirect blocks (if the file
234is large).
235.s3
236Byte number
237.it n
238of a file is accessed as follows.
239.it N
240is divided by 512 to find its logical block number
241(say
242.it b
243)
244in the file.
245If the file is small (flag 010000 is 0),
246then
247.it b
248must be less than 8, and the physical
249block number is
250.it addr[b].
251.s3
252If the file is large,
253.it b
254is divided by 256 to yield
255.it i,
256and
257.it addr[i]
258is the physical block number of
259the indirect block.
260The remainder from the division
261yields the word in the indirect block
262which contains the number of the block for
263the sought-for byte.
264.s3
265For block
266.it b
267in a file to exist,
268it
269is not necessary that all blocks less than
270.it b
271exist.
272A zero block number either in the address words of
273the i-node or in an indirect block indicates that the
274corresponding block has never been allocated.
275Such a missing block reads as if it contained all zero words.
276.sh "SEE ALSO"
277check (VIII)