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