home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / man / man5 / fs.5 < prev    next >
Encoding:
Text File  |  1975-06-26  |  6.9 KB  |  298 lines

  1. .th "FILE SYSTEM" V 2/9/75
  2. .sh NAME
  3. fs \*- format of file system volume
  4. .sh DESCRIPTION
  5. Every
  6. file system storage volume
  7. (e.g. RF disk, RK disk, RP disk, DECtape reel)
  8. has a common format for certain vital information.
  9. Every such volume is divided into a certain number
  10. of 256 word (512 byte) blocks.
  11. Block 0 is unused and is available to contain
  12. a bootstrap program, pack label, or other information.
  13. .s3
  14. Block 1 is the
  15. .it "super block."
  16. Starting from its first word, the format of a super-block is
  17. .s3
  18. .nf
  19. struct {
  20.     int    isize;
  21.     int    fsize;
  22.     int    nfree;
  23.     int    free[100];
  24.     int    ninode;
  25.     int    inode[100];
  26.     char    flock;
  27.     char    ilock;
  28.     char    fmod;
  29.     int    time[2];
  30. };
  31. .s3
  32. .fi
  33. .it Isize
  34. is the number of blocks devoted to the i-list,
  35. which starts just after the super-block, in block 2.
  36. .it Fsize
  37. is the first block not potentially available for allocation
  38. to a file.
  39. These numbers are used by the system to
  40. check for bad block numbers;
  41. if an ``impossible'' block number is allocated from the free list
  42. or is freed,
  43. a diagnostic is written on the on-line console.
  44. Moreover, the free array is cleared, so as to prevent further
  45. allocation from a presumably corrupted free list.
  46. .s3
  47. The free list for each volume is maintained as
  48. follows.
  49. The
  50. .it free
  51. array contains, in
  52. .it "free[1], ... , free[nfree\*-1],"
  53. up to 99 numbers of free blocks.
  54. .it Free[0]
  55. is the block number of the head
  56. of a chain of blocks constituting the free list.
  57. The first word in each free-chain block is the number
  58. (up to 100) of free-block numbers listed in the
  59. next 100 words of this chain member.
  60. The first of these 100 blocks is the link to the
  61. next member of the chain.
  62. To allocate a block:
  63. decrement
  64. .it nfree,
  65. and the new block is
  66. .it free[nfree].
  67. If the new block number is 0,
  68. there are no blocks left, so give an error.
  69. If
  70. .it nfree
  71. became 0,
  72. read in the block named by the new block number,
  73. replace
  74. .it nfree
  75. by its first word,
  76. and copy the block numbers in the next 100 words into the
  77. .it free
  78. array.
  79. To free a block, check if
  80. .it nfree
  81. is 100; if so,
  82. copy
  83. .it nfree
  84. and the
  85. .it free
  86. array into it,
  87. write it out, and set
  88. .it nfree
  89. to 0.
  90. In any event set
  91. .it free[nfree]
  92. to the freed block's number and
  93. increment
  94. .it nfree.
  95. .s3
  96. .it Ninode
  97. is the number of free i-numbers in the
  98. .it inode
  99. array.
  100. To allocate an i-node:
  101. if
  102. .it ninode
  103. is greater than 0,
  104. decrement it and return
  105. .it inode[ninode].
  106. If it was 0, read the i-list
  107. and place the numbers of all free inodes
  108. (up to 100) into the
  109. .it inode
  110. array,
  111. then try again.
  112. To free an i-node,
  113. provided
  114. .it ninode
  115. is less than 100,
  116. place its number into
  117. .it inode[ninode]
  118. and increment
  119. .it ninode.
  120. If
  121. .it ninode
  122. is already 100, don't bother to enter the freed i-node into any table.
  123. This list of i-nodes is only to speed
  124. up the allocation process; the information
  125. as to whether the inode is really free
  126. or not is maintained in the inode itself.
  127. .s3
  128. .it Flock
  129. and
  130. .it ilock
  131. are flags maintained in the core
  132. copy of the file system
  133. while it is mounted
  134. and their values on disk are immaterial.
  135. The value of
  136. .it fmod
  137. on disk is likewise immaterial;
  138. it is used as a flag to indicate that the super-block has
  139. changed and should be copied to
  140. the disk during the next periodic update of file
  141. system information.
  142. .s3
  143. .it Time
  144. is the last time the super-block of the file system was changed,
  145. and is a double-precision representation
  146. of the number of seconds that have elapsed
  147. since
  148. 0000 Jan. 1 1970 (GMT).
  149. During a reboot, the
  150. .it time
  151. of the super-block for the root file system
  152. is used to set the system's idea of the time.
  153. .s3
  154. I-numbers begin at 1, and the storage for i-nodes
  155. begins in block 2.
  156. .tr |
  157. Also, i-nodes are 32 bytes long, so 16 of them fit into a block.
  158. Therefore, i-node
  159. .it i
  160. is located in block (\fIi\fR|+|31)|/|16, and begins
  161. 32\u\fB.\fR\d((\fIi\fR|+|31)|(mod 16) bytes from its start.
  162. I-node 1 is reserved for the root directory of the file
  163. system, but no other i-number has a built-in
  164. meaning.
  165. Each i-node represents one file.
  166. The format of an i-node is as follows.
  167. .s3
  168. .nf
  169. .if t .ta .5i 1.i 2.5i
  170. struct {
  171.     int    flags;    /* +0: see below */
  172.     char    nlinks;    /* +2: number of links to file */
  173.     char    uid;    /* +3: user ID of owner */
  174.     char    gid;    /* +4: group ID of owner */
  175.     char    size0;    /* +5: high byte of 24-bit size */
  176.     int    size1;    /* +6: low word of 24-bit size */
  177.     int    addr[8];    /* +8: block numbers or device number */
  178.     int    actime[2];    /* +24: time of last access */
  179.     int    modtime[2];    /* +28: time of last modification */
  180. };
  181. .dt
  182. .fi
  183. .s3
  184. The flags are as follows:
  185. .s3
  186. .lp +10 9
  187. 100000    i-node is allocated
  188. .lp +10 9
  189. 060000    2-bit file type:
  190. .lp +15 9
  191. 000000    plain file
  192. .lp +15 9
  193. 040000    directory
  194. .lp +15 9
  195. 020000    character-type special file
  196. .lp +15 9
  197. 060000    block-type special file.
  198. .lp +10 9
  199. 010000    large file
  200. .lp +10 9
  201. 004000    set user-ID on execution
  202. .lp +10 9
  203. 002000    set group-ID on execution
  204. .lp +10 9
  205. 000400    read (owner)
  206. .lp +10 9
  207. 000200    write (owner)
  208. .lp +10 9
  209. 000100    execute (owner)
  210. .lp +10 9
  211. 000070    read, write, execute (group)
  212. .lp +10 9
  213. 000007    read, write, execute (others)
  214. .s3
  215. .i0
  216. Special files are recognized by their flags
  217. and not by i-number.
  218. A block-type special file is basically one which
  219. can potentially be mounted as a file system;
  220. a character-type special file cannot, though it is
  221. not necessarily character-oriented.
  222. For special files the high byte of the first address word
  223. specifies the type of device; the low byte specifies
  224. one of several devices of
  225. that type.
  226. The device type numbers
  227. of block and character special files overlap.
  228. .s3
  229. The address words of ordinary files and directories
  230. contain the numbers of the blocks in the
  231. file (if it is small)
  232. or the numbers of indirect blocks (if the file
  233. is large).
  234. Byte number
  235. .it n
  236. of a file is accessed as follows.
  237. .it N
  238. is divided by 512 to find its logical block number
  239. (say
  240. .it b
  241. )
  242. in the file.
  243. If the file is small (flag 010000 is 0),
  244. then
  245. .it b
  246. must be less than 8, and the physical
  247. block number is
  248. .it addr[b].
  249. .s3
  250. If the file is large,
  251. .it b
  252. is divided by 256 to yield
  253. .it i.
  254. If
  255. .it i
  256. is less than 7, then
  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. If
  266. .it i
  267. is equal to 7,
  268. then the file has become extra-large (huge),
  269. and
  270. .it addr[7]
  271. is the address of a first indirect block.
  272. Each word in this block
  273. is the number of a second-level indirect block;
  274. each word in the second-level indirect blocks points to a data block.
  275. Notice that extra-large files are not marked by any mode
  276. bit, but only by having
  277. .it addr[7]
  278. non-zero;
  279. and that although this scheme allows for more than
  280. 256\*X256\*X512 = 33,554,432 bytes per file,
  281. the length of files is stored in 24 bits
  282. so in practice a file can be at most
  283. 16,777,216 bytes long.
  284. .s3
  285. For block
  286. .it b
  287. in a file to exist,
  288. it
  289. is not necessary that all blocks less than
  290. .it b
  291. exist.
  292. A zero block number either in the address words of
  293. the i-node or in an indirect block indicates that the
  294. corresponding block has never been allocated.
  295. Such a missing block reads as if it contained all zero words.
  296. .sh "SEE ALSO"
  297. icheck, dcheck (VIII)
  298.