p2 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. block of data on a device:
  25. .P1
  26. enum
  27. {
  28. RBUFSIZE = 16*1024
  29. };
  30. typedef
  31. struct
  32. {
  33. short pad;
  34. short tag;
  35. long path;
  36. } Tag;
  37. enum
  38. {
  39. BUFSIZE = RBUFSIZE - sizeof(Tag)
  40. };
  41. typedef
  42. struct
  43. {
  44. uchar data[BUFSIZE];
  45. Tag tag;
  46. } Block;
  47. .P2
  48. All devices are idealized as a perfect disk
  49. of contiguously numbered blocks each of size
  50. .CW RBUFSIZE .
  51. Each block has a tag that identifies what type
  52. of block it is and a unique id of the file or directory
  53. where this block resides.
  54. The remaining data in the block depends on
  55. what type of block it is.
  56. .PP
  57. The
  58. .CW srv
  59. process's main data structure is the directory entry.
  60. This is the equivalent of a UNIX i-node and
  61. defines the set of block addresses that comprise a file or directory.
  62. Unlike the i-node,
  63. the directory entry also has the name of the
  64. file or directory in it:
  65. .P1
  66. enum
  67. {
  68. NAMELEN = 28,
  69. NDBLOCK = 6
  70. };
  71. .P2
  72. .P1
  73. typedef
  74. struct
  75. {
  76. char name[NAMELEN];
  77. short uid;
  78. short gid;
  79. ushort mode;
  80. short wuid;
  81. Qid qid;
  82. long size;
  83. long dblock[NDBLOCK];
  84. long iblock;
  85. long diblock;
  86. long atime;
  87. long mtime;
  88. } Dentry;
  89. .P2
  90. Each directory entry holds the file or directory
  91. name, protection mode, access times, user-id, group-id, and addressing
  92. information.
  93. The entry
  94. .CW wuid
  95. is the user-id of the last writer of the file
  96. and
  97. .CW size
  98. is the size of the file in bytes.
  99. The first 6
  100. blocks of the file are held in the
  101. .CW dblock
  102. array.
  103. If the file is larger than that,
  104. an indirect block is allocated that holds
  105. the next
  106. .CW BUFSIZE/sizeof(long)
  107. blocks of the file.
  108. The indirect block address is held in the structure member
  109. .CW iblock .
  110. If the file is larger yet,
  111. then there is a double indirect block that points
  112. at indirect blocks.
  113. The double indirect address is held in
  114. .CW diblock
  115. and can point at another
  116. .CW (BUFSIZE/sizeof(long))\u\s-2\&2\s+2\d
  117. blocks of data.
  118. The maximum addressable size of a file is
  119. therefore 275 Gbytes.
  120. There is a tighter restriction of
  121. 2\u\s-2\&32\s+2\d
  122. bytes because the length of a file is maintained in
  123. a long.
  124. Even so,
  125. sloppy use of long arithmetic restricts the length to
  126. 2\u\s-2\&31\s+2\d
  127. bytes.
  128. These numbers are based on Emelie
  129. which has a block size of 16K and
  130. .CW sizeof(long)
  131. is 4.
  132. It would be different if the size of a block
  133. changed.
  134. .PP
  135. The declarations of the indirect and double indirect blocks
  136. are as follows.
  137. .P1
  138. enum
  139. {
  140. INDPERBUF = BUFSIZE/sizeof(long),
  141. };
  142. .P2
  143. .P1
  144. typedef
  145. {
  146. long dblock[INDPERBUF];
  147. Tag ibtag;
  148. } Iblock;
  149. .P2
  150. .P1
  151. typedef
  152. {
  153. long iblock[INDPERBUF];
  154. Tag dibtag;
  155. } Diblock;
  156. .P2
  157. .PP
  158. The root of a file system is a single directory entry
  159. at a known block address.
  160. A directory is a file that consists of a list of
  161. directory entries.
  162. To make access easier,
  163. a directory entry cannot cross blocks.
  164. In Emelie there are 233 directory entries per block.
  165. .PP
  166. The device on which the blocks reside is implicit
  167. and ultimately comes from the 9P
  168. .CW attach
  169. message that specifies the name of the
  170. device containing the root.