1
0

p2 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. .SH
  2. The server processes
  3. .PP
  4. The main file system algorithm is a set
  5. of identical processes
  6. named
  7. .CW srv
  8. that honor the
  9. 9P protocol.
  10. Each file system process waits on
  11. a message queue for an incoming request.
  12. The request contains a 9P message and
  13. the address of a reply queue.
  14. A
  15. .CW srv
  16. process parses the message,
  17. performs pseudo-disk I/O
  18. to the corresponding file system block device,
  19. formulates a response,
  20. and sends the
  21. response back to the reply queue.
  22. .PP
  23. The unit of storage is a
  24. logical block
  25. (not physical sector) of data on a device:
  26. .Ex
  27. .TA 0.5i 1i 1.5i 2i 2.5i 3i 3.5i 4i 4.5i 5i 5.5i
  28. enum
  29. {
  30. RBUFSIZE = 8*1024
  31. };
  32. typedef vlong Off;
  33. typedef
  34. struct
  35. {
  36. short pad;
  37. short tag;
  38. Off path;
  39. } Tag;
  40. enum
  41. {
  42. BUFSIZE = RBUFSIZE - sizeof(Tag)
  43. };
  44. typedef
  45. struct
  46. {
  47. uchar data[BUFSIZE];
  48. Tag tag;
  49. } Block;
  50. .Ee
  51. All devices are idealized as a perfect disk
  52. of contiguously numbered blocks each of size
  53. .CW RBUFSIZE .
  54. Each block has a tag that identifies what type
  55. of block it is and a unique id of the file or directory
  56. where this block resides.
  57. The remaining data in the block depends on
  58. what type of block it is.
  59. .PP
  60. The
  61. .CW srv
  62. process's main data structure is the directory entry.
  63. This is the equivalent of a UNIX i-node and
  64. defines the set of block addresses that comprise a file or directory.
  65. Unlike the i-node,
  66. the directory entry also has the name of the
  67. file or directory in it:
  68. .Ex
  69. enum
  70. {
  71. NAMELEN = 56,
  72. NDBLOCK = 6,
  73. NIBLOCK = 4,
  74. };
  75. .Ee
  76. .Ex
  77. typedef
  78. struct
  79. {
  80. char name[NAMELEN];
  81. short uid;
  82. short gid;
  83. ushort mode;
  84. short wuid;
  85. Qid qid;
  86. Off size;
  87. Off dblock[NDBLOCK];
  88. Off iblocks[NIBLOCK];
  89. long atime;
  90. long mtime;
  91. } Dentry;
  92. .Ee
  93. Each directory entry holds the file or directory
  94. name, protection mode, access times, user-id, group-id, and addressing
  95. information.
  96. The entry
  97. .CW wuid
  98. is the user-id of the last writer of the file
  99. and
  100. .CW size
  101. is the size of the file in bytes.
  102. The addresses of the first 6
  103. blocks of the file are held in the
  104. .CW dblock
  105. array.
  106. If the file is larger than that,
  107. an indirect block is allocated that holds
  108. the next
  109. .CW BUFSIZE/sizeof(Off)
  110. block addresses of the file.
  111. The indirect block address is held in
  112. .CW iblocks[0] .
  113. If the file is larger yet,
  114. then there is a double indirect block that points
  115. at indirect blocks.
  116. The double indirect address is held in
  117. .CW iblocks[1]
  118. and can point at another
  119. .CW (BUFSIZE/sizeof(Off))\u\s-2\&2\s+2\d
  120. blocks of data.
  121. This is extended through a quadruple indirect block at
  122. .CW iblocks[3]
  123. but the code is now parameterised to permit easily changing the
  124. number of direct blocks and the depth of indirect blocks,
  125. and also the maximum size of a file name component.
  126. The maximum addressable size of a file is
  127. therefore 7.93 petabytes at a block size of 8k,
  128. but 7.98 exabytes (just under $2 sup 63$ bytes) at a block size of 32k.
  129. File size is restricted to $2 sup 63 - 1$ bytes in any case
  130. because the length of a file is maintained in a
  131. (signed)
  132. .I vlong .
  133. These numbers are based on
  134. .I fs64
  135. which has a block size of 8k and
  136. .CW sizeof(Off)
  137. is 8.
  138. .PP
  139. The declarations of the indirect and double indirect blocks
  140. are as follows.
  141. .Ex
  142. enum
  143. {
  144. INDPERBUF = BUFSIZE/sizeof(Off),
  145. };
  146. .Ee
  147. .Ex
  148. typedef
  149. {
  150. Off dblock[INDPERBUF];
  151. Tag ibtag;
  152. } Iblock;
  153. .Ee
  154. .Ex
  155. typedef
  156. {
  157. Off iblock[INDPERBUF];
  158. Tag dibtag;
  159. } Diblock;
  160. .Ee
  161. .PP
  162. The root of a file system is a single directory entry
  163. at a known block address.
  164. A directory is a file that consists of a list of
  165. directory entries.
  166. To make access easier,
  167. a directory entry cannot cross blocks.
  168. In
  169. .I fs64
  170. there are 47 directory entries per block.
  171. .PP
  172. The device on which the blocks reside is implicit
  173. and ultimately comes from the 9P
  174. .CW attach
  175. message that specifies the name of the
  176. device containing the root.