1 .\" Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 .Dd $Mdocdate: July 30 2021 $
20 .Nd Simple Distributed File System
23 is a protocol that implements a distributed file systems.
24 It provides primitives to manage
25 .Pq create, read, write and delete
26 sets of files remotely.
27 These files don't necessarily need to be actually stored on a disk,
28 they may be, for example, synthesise on demand from external sources.
30 A client transmits requests
32 to a server, which returns replies
35 The combined acts of transmitting a request of a particular type and
36 receiving a reply is called a transaction of that type.
38 Each message consists of a sequence of bytes mostly grouped in one,
39 two or four integer fields transmitted in little-endian order
40 .Pq least significant byte first .
41 Data items of larger or variable lengths are represented by a two-byte
42 field specifying the length followed by the actual data.
43 The only exception to this rule are QIDs, thirteen byte long
44 objects, that are sent as-is.
46 Text strings are represented with a two-byte count and the sequence of
47 UNICODE codepoints encoded in UTF-8.
48 Text strings in 9p are not NUL-terminated.
49 The NUL-terminator is illegal in all text strings and thus excluded
50 from paths, user names and so on.
52 Fields are hereafter denoted as
53 .Bd -literal -offset indent
57 to indicate that type is one byte long, tag two and fid four.
58 Strings are denoted as name[s] and are sent on the wire as
59 .Bd -literal -offset indent
60 length[2] string[length]
63 A qid, described later, is a 13-byte value that is sent on the wire as
64 .Bd -literal -offset indent
65 type[1] version[4] path[8]
68 Every message has a header with the following fields:
69 .Bd -literal -offset indent
73 where len indicates the overall length of the message, including
74 itself; type is one byte indicating the type of the message and the
75 tag is a number choosen by the client that indicate uniquely the
77 Then follows an optional body whose structure depends on the type of
80 The message types are as follows:
81 .Pq the header is omitted for brevity
82 .Bl -tag -width versionxx
84 Negotiate the version and maximum message size.
92 request must be the first message sent, and the client cannot issue
93 further requests until receiving the Rversion reply.
100 .Pq the maximum size for packets
101 and the protocol version used, the server replies with a
103 smaller or equal to the one proposed by the client.
104 The version string must always begin with the two character
106 If the server don't understand the client required version, should
107 reply with a Rversion using the version string
109 and not use a Rerror.
111 Populate the namespace
113 fid[4] afid[4] uname[s] aname[s]
119 message binds the given
121 to the root of the file tree identified by
124 identifies the user and
126 specifies a fid previously established by an auth message, or the
130 .Pq defined as (u32int)~0
131 if the authentication is not required.
139 Once a fid has been clunked
143 and the same value can be used for subsequential
149 The actual file on the disk is not remove unless it was opened with the
153 Return an error string.
158 The Rerror message is used to return an error string describing the
159 failure of a request.
162 indicates the failed request.
164 Note that there isn't a
166 request for obvious reason and it's not possible for a server to reply to
174 Abort an ongoing operation.
180 Given the asynchronous nature of the protocol, the server may respond to
181 the pending request before responding to the
183 and is possible for a client to send multiple
185 for the same operation.
186 The client must wait to receive a corresponding
190 for subsequent messages.
194 is received before the
196 reply, the client must assume that the operation was completed with success
197 .Pq fid allocated, files created, ...
198 If no response is received before the
200 then the transaction is considered to have been successfully cancelled.
202 Note that the tag of this request and the corresponding reply is NOT
206 Traverse a file tree.
208 fid[4] newfid[4] nwname[2] nwname*(wname[s])
209 nwqid[2] nwqid*(qid[13])
214 components are walked in order starting from
216 .Pq which must point to a directory
219 is associated to the reached file.
225 to be equal, in this case the fid is
230 As a special case, a walk of zero components duplicates the fid.
232 If the first element cannot be walked for any reason an
237 is returned with a number of qids equal to the file viside by the walk.
238 A client can thus detect a walk when that the replied
240 number is not equal to the
242 field in the request.
243 Only when walk return successfully
247 A maximum of 16 component can be used per walk request.
249 Prepare a fid for I/O.
256 determines the type of I/O:
257 .Bl -tag -width Ds -offset indent -compact
266 is the optimal blocksize for I/O.
268 Read data at offset from file
270 fid[4] offset[8] count[4]
275 must have been prepared for I/O with a previous
280 is zero when reaching end-of-file and may be lesser than what requested.
282 Directories are a stream of stat structures, as described in
284 and for them the read request message must have offset equal to zero or
287 in the previous read on the directory plus the number of bytes returned
288 in the previous read.
296 The stat structure is made by the following fields:
297 .Bl -tag -width twelveletters -compact
299 total byte count of the following data
305 server unique identifier of the file
307 permissions and flags
311 last modification time
313 length of file in bytes
318 if the file is the root directory of the server)
324 name of the user who last modified the file.
327 .Sh 9P2000.L EXTENSIONS
329 supports also a subset of the
332 The supported messages are
333 .Bl -tag -width readdir
335 Read directory entries
337 fid[4] offset[8] count[4]
341 Each directory entry is described by a variable-length record:
342 .Ql qid[13] offset[8] type[1] name[s] .
343 Offset is zero upon the first call.
348 response is not zero then more data is available.
351 is allowed to be zero in the request.