Blob


1 .\" Copyright (c) 2021 Omar Polo <op@omarpolo.com>
2 .\"
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.
6 .\"
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.
14 .\"
15 .Dd $Mdocdate: July 30 2021 $
16 .Dt 9P 7
17 .Os
18 .Sh NAME
19 .Nm 9P
20 .Nd Simple Distributed File System
21 .Sh DESCRIPTION
22 .Nm
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.
29 .Pp
30 A client transmits requests
31 .Pq T-messages
32 to a server, which returns replies
33 .Pq R-messages
34 to the client.
35 The combined acts of transmitting a request of a particular type and
36 receiving a reply is called a transaction of that type.
37 .Pp
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.
45 .Pp
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.
51 .Pp
52 Fields are hereafter denoted as
53 .Bd -literal -offset indent
54 type[1] tag[2] fid[4]
55 .Ed
56 .Pp
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]
61 .Ed
62 .Pp
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]
66 .Ed
67 .Sh MESSAGE STRUCTURE
68 Every message has a header with the following fields:
69 .Bd -literal -offset indent
70 len[4] type[1] tag[2]
71 .Ed
72 .Pp
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
76 request.
77 Then follows an optional body whose structure depends on the type of
78 the message.
79 .Pp
80 The message types are as follows:
81 .Bl -tag -width versionxx
82 .It Ic version
83 Negotiate the version and maximum message size.
84 .Bd -literal
85 len[4] Tversion tag[2] msize[4] version[s]
86 len[4] Rversion tag[2] msize[4] version[s]
87 .Ed
88 .Pp
89 The
90 .Ic version
91 request must be the first message sent, and the client cannot issue
92 further requests until it has received the Rversion reply.
93 .Cm tag
94 should be
95 .Dv NOTAG
96 .Pq \-1 or 255 .
97 The client suggest a
98 .Cm msize
99 .Pq the maximum size for packets
100 and the protocol version used, the server replies with a
101 .Cm msize
102 smaller or equal to the one proposed by the client.
103 The version string must always begin with the two character
104 .Dq 9P .
105 If the server don't understand the client required version, should
106 reply with a Rversion using the version string
107 .Dq unknown
108 and not use a Rerror.
109 .It Ic attach
110 Populate the namespace
111 .Bd -literal
112 len[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s]
113 len[4] Rattach tag[2] qid[13]
114 .Ed
115 .It Ic clunk
116 Close fids.
117 .Bd -literal
118 len[4] Tclunk tag[2] fid[4]
119 len[4] Rclunk tag[2]
120 .Ed
121 .It Ic error
122 Return an error string
123 .Bd -literal
124 len[4] Rerror tag[2] ename[s]
125 .Ed
126 .Pp
127 The Rerror message is used to return an error string describing the
128 failure of a request.
129 .Cm tag
130 indicates the failed request.
131 Note that there isn't a Terror, and it's not possible for a server to
132 reply to a
133 .Ic Tversion
134 using Rerror.
135 .It Ic flush
136 Abort an ongoing operation.
137 .Bd -literal
138 len[4] Tflush tag[2] oldtag[2]
139 len[4] Rflush tag[2]
140 .Ed
141 .El
142 .Sh SEE ALSO
143 .Xr utf8 7 ,
144 .Xr kamid 8