Blame


1 17ab44fc 2021-07-31 op .\" Copyright (c) 2021 Omar Polo <op@omarpolo.com>
2 17ab44fc 2021-07-31 op .\"
3 17ab44fc 2021-07-31 op .\" Permission to use, copy, modify, and distribute this software for any
4 17ab44fc 2021-07-31 op .\" purpose with or without fee is hereby granted, provided that the above
5 17ab44fc 2021-07-31 op .\" copyright notice and this permission notice appear in all copies.
6 17ab44fc 2021-07-31 op .\"
7 17ab44fc 2021-07-31 op .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 17ab44fc 2021-07-31 op .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 17ab44fc 2021-07-31 op .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 17ab44fc 2021-07-31 op .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 17ab44fc 2021-07-31 op .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 17ab44fc 2021-07-31 op .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 17ab44fc 2021-07-31 op .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 17ab44fc 2021-07-31 op .\"
15 17ab44fc 2021-07-31 op .Dd $Mdocdate: July 30 2021 $
16 17ab44fc 2021-07-31 op .Dt 9P 7
17 17ab44fc 2021-07-31 op .Os
18 17ab44fc 2021-07-31 op .Sh NAME
19 17ab44fc 2021-07-31 op .Nm 9P
20 17ab44fc 2021-07-31 op .Nd Simple Distributed File System
21 17ab44fc 2021-07-31 op .Sh DESCRIPTION
22 17ab44fc 2021-07-31 op .Nm
23 3d1d2398 2021-08-04 op is a protocol that implements a distributed file systems.
24 17ab44fc 2021-07-31 op It provides primitives to manage
25 17ab44fc 2021-07-31 op .Pq create, read, write and delete
26 17ab44fc 2021-07-31 op sets of files remotely.
27 17ab44fc 2021-07-31 op These files don't necessarily need to be actually stored on a disk,
28 17ab44fc 2021-07-31 op they may be, for example, synthesise on demand from external sources.
29 17ab44fc 2021-07-31 op .Pp
30 17ab44fc 2021-07-31 op A client transmits requests
31 17ab44fc 2021-07-31 op .Pq T-messages
32 17ab44fc 2021-07-31 op to a server, which returns replies
33 17ab44fc 2021-07-31 op .Pq R-messages
34 17ab44fc 2021-07-31 op to the client.
35 17ab44fc 2021-07-31 op The combined acts of transmitting a request of a particular type and
36 17ab44fc 2021-07-31 op receiving a reply is called a transaction of that type.
37 17ab44fc 2021-07-31 op .Pp
38 3d1d2398 2021-08-04 op Each message consists of a sequence of bytes mostly grouped in one,
39 3d1d2398 2021-08-04 op two or four integer fields transmitted in little-endian order
40 17ab44fc 2021-07-31 op .Pq least significant byte first .
41 17ab44fc 2021-07-31 op Data items of larger or variable lengths are represented by a two-byte
42 17ab44fc 2021-07-31 op field specifying the length followed by the actual data.
43 3d1d2398 2021-08-04 op The only exception to this rule are QIDs, thirteen byte long
44 3d1d2398 2021-08-04 op objects, that are sent as-is.
45 3d1d2398 2021-08-04 op .Pp
46 3d1d2398 2021-08-04 op Text strings are represented with a two-byte count and the sequence of
47 3d1d2398 2021-08-04 op UNICODE codepoints encoded in UTF-8.
48 3d1d2398 2021-08-04 op Text strings in 9p are not NUL-terminated.
49 17ab44fc 2021-07-31 op The NUL-terminator is illegal in all text strings and thus excluded
50 17ab44fc 2021-07-31 op from paths, user names and so on.
51 17ab44fc 2021-07-31 op .Pp
52 17ab44fc 2021-07-31 op Fields are hereafter denoted as
53 17ab44fc 2021-07-31 op .Bd -literal -offset indent
54 17ab44fc 2021-07-31 op type[1] tag[2] fid[4]
55 17ab44fc 2021-07-31 op .Ed
56 17ab44fc 2021-07-31 op .Pp
57 17ab44fc 2021-07-31 op to indicate that type is one byte long, tag two and fid four.
58 17ab44fc 2021-07-31 op Strings are denoted as name[s] and are sent on the wire as
59 17ab44fc 2021-07-31 op .Bd -literal -offset indent
60 17ab44fc 2021-07-31 op length[2] string[length]
61 17ab44fc 2021-07-31 op .Ed
62 17ab44fc 2021-07-31 op .Pp
63 17ab44fc 2021-07-31 op A qid, described later, is a 13-byte value that is sent on the wire as
64 17ab44fc 2021-07-31 op .Bd -literal -offset indent
65 17ab44fc 2021-07-31 op type[1] version[4] path[8]
66 17ab44fc 2021-07-31 op .Ed
67 3d1d2398 2021-08-04 op .Sh MESSAGE STRUCTURE
68 17ab44fc 2021-07-31 op Every message has a header with the following fields:
69 17ab44fc 2021-07-31 op .Bd -literal -offset indent
70 17ab44fc 2021-07-31 op len[4] type[1] tag[2]
71 17ab44fc 2021-07-31 op .Ed
72 17ab44fc 2021-07-31 op .Pp
73 17ab44fc 2021-07-31 op where len indicates the overall length of the message, including
74 17ab44fc 2021-07-31 op itself; type is one byte indicating the type of the message and the
75 3d1d2398 2021-08-04 op tag is a number choosen by the client that indicate uniquely the
76 17ab44fc 2021-07-31 op request.
77 3d1d2398 2021-08-04 op Then follows an optional body whose structure depends on the type of
78 3d1d2398 2021-08-04 op the message.
79 17ab44fc 2021-07-31 op .Pp
80 17ab44fc 2021-07-31 op The message types are as follows:
81 d3d4880e 2021-12-02 op .Pq the header is omitted for brevity
82 17ab44fc 2021-07-31 op .Bl -tag -width versionxx
83 17ab44fc 2021-07-31 op .It Ic version
84 17ab44fc 2021-07-31 op Negotiate the version and maximum message size.
85 17ab44fc 2021-07-31 op .Bd -literal
86 3756a3df 2021-08-08 op msize[4] version[s]
87 3756a3df 2021-08-08 op msize[4] version[s]
88 17ab44fc 2021-07-31 op .Ed
89 17ab44fc 2021-07-31 op .Pp
90 17ab44fc 2021-07-31 op The
91 17ab44fc 2021-07-31 op .Ic version
92 17ab44fc 2021-07-31 op request must be the first message sent, and the client cannot issue
93 d3d4880e 2021-12-02 op further requests until receiving the Rversion reply.
94 17ab44fc 2021-07-31 op .Cm tag
95 17ab44fc 2021-07-31 op should be
96 17ab44fc 2021-07-31 op .Dv NOTAG
97 3d1d2398 2021-08-04 op .Pq \-1 or 255 .
98 17ab44fc 2021-07-31 op The client suggest a
99 17ab44fc 2021-07-31 op .Cm msize
100 17ab44fc 2021-07-31 op .Pq the maximum size for packets
101 3d1d2398 2021-08-04 op and the protocol version used, the server replies with a
102 17ab44fc 2021-07-31 op .Cm msize
103 17ab44fc 2021-07-31 op smaller or equal to the one proposed by the client.
104 17ab44fc 2021-07-31 op The version string must always begin with the two character
105 17ab44fc 2021-07-31 op .Dq 9P .
106 17ab44fc 2021-07-31 op If the server don't understand the client required version, should
107 17ab44fc 2021-07-31 op reply with a Rversion using the version string
108 17ab44fc 2021-07-31 op .Dq unknown
109 17ab44fc 2021-07-31 op and not use a Rerror.
110 17ab44fc 2021-07-31 op .It Ic attach
111 17ab44fc 2021-07-31 op Populate the namespace
112 17ab44fc 2021-07-31 op .Bd -literal
113 3756a3df 2021-08-08 op fid[4] afid[4] uname[s] aname[s]
114 3756a3df 2021-08-08 op qid[13]
115 17ab44fc 2021-07-31 op .Ed
116 30d22cc7 2021-12-14 op .Pp
117 30d22cc7 2021-12-14 op The
118 30d22cc7 2021-12-14 op .Ic attach
119 30d22cc7 2021-12-14 op message binds the given
120 30d22cc7 2021-12-14 op .Ar fid
121 30d22cc7 2021-12-14 op to the root of the file tree identified by
122 30d22cc7 2021-12-14 op .Ar aname .
123 30d22cc7 2021-12-14 op .Ar uname
124 30d22cc7 2021-12-14 op identifies the user and
125 30d22cc7 2021-12-14 op .Ar afid
126 30d22cc7 2021-12-14 op specifies a fid previously established by an auth message, or the
127 30d22cc7 2021-12-14 op special
128 30d22cc7 2021-12-14 op .Dv NOFID
129 30d22cc7 2021-12-14 op value
130 30d22cc7 2021-12-14 op .Pq defined as (u32int)~0
131 30d22cc7 2021-12-14 op if the authentication is not required.
132 17ab44fc 2021-07-31 op .It Ic clunk
133 17ab44fc 2021-07-31 op Close fids.
134 17ab44fc 2021-07-31 op .Bd -literal
135 3756a3df 2021-08-08 op fid[4]
136 3756a3df 2021-08-08 op .Aq empty response
137 17ab44fc 2021-07-31 op .Ed
138 30d22cc7 2021-12-14 op .Pp
139 30d22cc7 2021-12-14 op Once a fid has been clunked
140 30d22cc7 2021-12-14 op .Pq closed
141 30d22cc7 2021-12-14 op it becomes
142 30d22cc7 2021-12-14 op .Dq free
143 30d22cc7 2021-12-14 op and the same value can be used for subsequential
144 30d22cc7 2021-12-14 op .Ic walk
145 30d22cc7 2021-12-14 op or
146 30d22cc7 2021-12-14 op .Ic attach
147 30d22cc7 2021-12-14 op requests.
148 30d22cc7 2021-12-14 op .Pp
149 30d22cc7 2021-12-14 op The actual file on the disk is not remove unless it was opened with the
150 30d22cc7 2021-12-14 op .Dv ORCLOSE
151 30d22cc7 2021-12-14 op flag.
152 17ab44fc 2021-07-31 op .It Ic error
153 30d22cc7 2021-12-14 op Return an error string.
154 17ab44fc 2021-07-31 op .Bd -literal
155 3756a3df 2021-08-08 op ename[s]
156 17ab44fc 2021-07-31 op .Ed
157 17ab44fc 2021-07-31 op .Pp
158 17ab44fc 2021-07-31 op The Rerror message is used to return an error string describing the
159 17ab44fc 2021-07-31 op failure of a request.
160 3756a3df 2021-08-08 op The
161 17ab44fc 2021-07-31 op .Cm tag
162 17ab44fc 2021-07-31 op indicates the failed request.
163 30d22cc7 2021-12-14 op .Pp
164 3756a3df 2021-08-08 op Note that there isn't a
165 3756a3df 2021-08-08 op .Ic Terror
166 30d22cc7 2021-12-14 op request for obvious reason and it's not possible for a server to reply to
167 30d22cc7 2021-12-14 op a
168 17ab44fc 2021-07-31 op .Ic Tversion
169 30d22cc7 2021-12-14 op or
170 30d22cc7 2021-12-14 op .Ic Tflush
171 3756a3df 2021-08-08 op using
172 3756a3df 2021-08-08 op .Ic Rerror .
173 17ab44fc 2021-07-31 op .It Ic flush
174 17ab44fc 2021-07-31 op Abort an ongoing operation.
175 17ab44fc 2021-07-31 op .Bd -literal
176 3756a3df 2021-08-08 op oldtag[2]
177 3756a3df 2021-08-08 op .Aq empty response
178 17ab44fc 2021-07-31 op .Ed
179 30d22cc7 2021-12-14 op .Pp
180 30d22cc7 2021-12-14 op Given the asynchronous nature of the protocol, the server may respond to
181 30d22cc7 2021-12-14 op the pending request before responding to the
182 30d22cc7 2021-12-14 op .Ic Tflush
183 30d22cc7 2021-12-14 op and is possible for a client to send multiple
184 30d22cc7 2021-12-14 op .Ic Tflush
185 30d22cc7 2021-12-14 op for the same operation.
186 30d22cc7 2021-12-14 op The client must wait to receive a corresponding
187 30d22cc7 2021-12-14 op .Ic Rflush
188 30d22cc7 2021-12-14 op before reusing
189 30d22cc7 2021-12-14 op .Ar oldtag
190 30d22cc7 2021-12-14 op for subsequent messages.
191 30d22cc7 2021-12-14 op .Pp
192 30d22cc7 2021-12-14 op If a response for
193 30d22cc7 2021-12-14 op .Ar oldtag
194 30d22cc7 2021-12-14 op is received before the
195 30d22cc7 2021-12-14 op .Ic Rflush
196 30d22cc7 2021-12-14 op reply, the client must assume that the operation was completed with success
197 30d22cc7 2021-12-14 op .Pq fid allocated, files created, ...
198 30d22cc7 2021-12-14 op If no response is received before the
199 30d22cc7 2021-12-14 op .Ic Rflush
200 30d22cc7 2021-12-14 op then the transaction is considered to have been successfully cancelled.
201 30d22cc7 2021-12-14 op .Pp
202 30d22cc7 2021-12-14 op Note that the tag of this request and the corresponding reply is NOT
203 30d22cc7 2021-12-14 op .Ar oldtag
204 30d22cc7 2021-12-14 op but a new tag value.
205 5ab50685 2021-08-08 op .It Ic walk
206 5ab50685 2021-08-08 op Traverse a file tree.
207 5ab50685 2021-08-08 op .Bd -literal
208 3756a3df 2021-08-08 op fid[4] newfid[4] nwname[2] nwname*(wname[s])
209 3756a3df 2021-08-08 op nwqid[2] nwqid*(qid[13])
210 5ab50685 2021-08-08 op .Ed
211 30d22cc7 2021-12-14 op .Pp
212 30d22cc7 2021-12-14 op The
213 30d22cc7 2021-12-14 op .Ar nwname
214 30d22cc7 2021-12-14 op components are walked in order starting from
215 30d22cc7 2021-12-14 op .Ar fid
216 30d22cc7 2021-12-14 op .Pq which must point to a directory
217 30d22cc7 2021-12-14 op and, if successful,
218 30d22cc7 2021-12-14 op .Ar newfid
219 30d22cc7 2021-12-14 op is associated to the reached file.
220 30d22cc7 2021-12-14 op .Pp
221 30d22cc7 2021-12-14 op It is possible for
222 30d22cc7 2021-12-14 op .Ar fid
223 30d22cc7 2021-12-14 op and
224 30d22cc7 2021-12-14 op .Ar newfid
225 30d22cc7 2021-12-14 op to be equal, in this case the fid is
226 30d22cc7 2021-12-14 op .Dq mutated ,
227 30d22cc7 2021-12-14 op otherwise
228 30d22cc7 2021-12-14 op .Ar newfid
229 30d22cc7 2021-12-14 op must be unused.
230 30d22cc7 2021-12-14 op As a special case, a walk of zero components duplicates the fid.
231 30d22cc7 2021-12-14 op .Pp
232 30d22cc7 2021-12-14 op If the first element cannot be walked for any reason an
233 30d22cc7 2021-12-14 op .Ic Rerror
234 30d22cc7 2021-12-14 op is returned.
235 30d22cc7 2021-12-14 op Otherwise,
236 30d22cc7 2021-12-14 op .Ic Rwalk
237 30d22cc7 2021-12-14 op is returned with a number of qids equal to the file viside by the walk.
238 30d22cc7 2021-12-14 op A client can thus detect a walk when that the replied
239 30d22cc7 2021-12-14 op .Ar nwqid
240 30d22cc7 2021-12-14 op number is not equal to the
241 30d22cc7 2021-12-14 op .Ar nwname
242 30d22cc7 2021-12-14 op field in the request.
243 30d22cc7 2021-12-14 op Only when walk return successfully
244 30d22cc7 2021-12-14 op .Ar newfid
245 30d22cc7 2021-12-14 op will be affected.
246 30d22cc7 2021-12-14 op .Pp
247 30d22cc7 2021-12-14 op A maximum of 16 component can be used per walk request.
248 021481ca 2021-12-13 op .It Ic open
249 30d22cc7 2021-12-14 op Prepare a fid for I/O.
250 021481ca 2021-12-13 op .Bd -literal
251 021481ca 2021-12-13 op fid[4] mode[1]
252 021481ca 2021-12-13 op qid[13] iounit[4]
253 021481ca 2021-12-13 op .Ed
254 30d22cc7 2021-12-14 op .Pp
255 30d22cc7 2021-12-14 op .Ar mode
256 30d22cc7 2021-12-14 op determines the type of I/O:
257 30d22cc7 2021-12-14 op .Bl -tag -width Ds -offset indent -compact
258 30d22cc7 2021-12-14 op .It 0 Dt OREAD
259 30d22cc7 2021-12-14 op .It 1 Dt OWRITE
260 30d22cc7 2021-12-14 op .It 2 Dt ORDWD
261 30d22cc7 2021-12-14 op .It 3 Dt OEXEC
262 17ab44fc 2021-07-31 op .El
263 30d22cc7 2021-12-14 op .Pp
264 30d22cc7 2021-12-14 op The returned
265 30d22cc7 2021-12-14 op .Ar iounit
266 30d22cc7 2021-12-14 op is the optimal blocksize for I/O.
267 30d22cc7 2021-12-14 op .El
268 17ab44fc 2021-07-31 op .Sh SEE ALSO
269 17ab44fc 2021-07-31 op .Xr utf8 7 ,
270 17ab44fc 2021-07-31 op .Xr kamid 8