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