Blob


1 .TH 9PCLIENT 3
2 .SH NAME
3 CFid, CFsys, fsinit, fsmount, fsroot, fssetroot, fsunmount, nsmount, fsversion, fsauth, fsattach, fsclose, fscreate, fsdirread, fsdirreadall, fsdirstat, fsdirfstat, fsdirwstat, fsdirfwstat, fsopen, fsopenfd, fspread, fspwrite, fsread, fsreadn, fswrite \- 9P client library
4 .SH SYNOPSIS
5 .B #include <u.h>
6 .PP
7 .B #include <libc.h>
8 .PP
9 .B #include <fcall.h>
10 .PP
11 .B #include <9pclient.h>
12 .ta +\w'\fLCFsys* 'u
13 .PP
14 .B
15 CFsys* fsmount(int fd, char *aname)
16 .PP
17 .B
18 CFsys* nsmount(char *name, char *aname)
19 .PP
20 .B
21 CFid* fsroot(CFsys *fsys)
22 .PP
23 .B
24 void fsunmount(CFsys *fsys)
25 .PP
26 .B
27 CFsys* fsinit(int fd)
28 .PP
29 .B
30 int fsversion(CFsys *fsys, int msize, char *version, int nversion)
31 .PP
32 .B
33 CFid* fsauth(CFsys *fsys, char *uname, char *aname)
34 .PP
35 .B
36 CFid* fsattach(CFsys *fsys, CFid *afid, char *uname, char *aname)
37 .PP
38 .B
39 void fssetroot(CFsys *fsys, CFid *fid)
40 .PP
41 .B
42 void fsclose(CFid *fid)
43 .PP
44 .B
45 CFid* fscreate(CFsys *fs, char *path, int mode, ulong perm)
46 .PP
47 .B
48 CFid* fsopen(CFsys *fs, char *path, int mode)
49 .PP
50 .B
51 long fspread(CFid *fid, void *buf, long n, vlong offset)
52 .PP
53 .B
54 long fspwrite(CFid *fid, void *buf, long n, vlong offset)
55 .PP
56 .B
57 long fsread(CFid *fid, void *buf, long n)
58 .PP
59 .B
60 long fsreadn(CFid *fid, void *buf, long n)
61 .PP
62 .B
63 long fswrite(CFid *fid, void *buf, long n)
64 .PP
65 .B
66 vlong fsseek(CFid *Fid, vlong n, int type)
67 .PP
68 .B
69 long fsdirread(CFid *fid, Dir **d)
70 .PP
71 .B
72 long fsdirreadall(CFid *fid, Dir **d)
73 .PP
74 .B
75 Dir* fsdirstat(CFsys *fs, char *path)
76 .PP
77 .B
78 Dir* fsdirfstat(CFid *fid)
79 .PP
80 .B
81 int fsdirwstat(CFsys *fs, char *path, Dir *d)
82 .PP
83 .B
84 int fsdirfwstat(CFid *fid, Dir *d)
85 .PP
86 .B
87 int fsopenfd(CFsys *fs, char *path, int mode)
88 .SH DESCRIPTION
89 The
90 .I 9pclient
91 library helps client programs interact with 9P servers.
92 .PP
93 A
94 .B CFsys*
95 represents a connection to a 9P server.
96 A
97 .B CFid*
98 represents an active fid on some connection;
99 see
100 .IR intro (9p).
101 .PP
102 A new connection to a 9P server is typically established by
103 .I fsmount
104 or
105 .IR nsmount .
106 .I Fsmount
107 initializes a new 9P conversation on the open file descriptor
108 .IR fd ;
109 .I nsmount
110 connects to a service named
111 .I name
112 in the current name space directory
113 (see
114 .IR intro (4)).
115 Both attach to the root of the file system
116 using the attach name
117 .IR aname .
118 .I Fsroot
119 returns the
120 .B CFid*
121 corresponding to this root.
122 .PP
123 .IR Fsinit ,
124 .IR fsversion ,
125 .IR fsauth ,
126 .IR fsattach ,
127 and
128 .I fssetroot
129 provide more detailed control over the file system connection
130 than
131 .I fsmount
132 and
133 .IR nsmount .
134 .I Fsinit
135 allocates a new
136 .B CFsys*
137 corresponding to a 9P conversation on the file descriptor
138 .IR fd .
139 .I Fsversion
140 executes a
141 .IR version (9p)
142 transaction to establish
143 maximum message size and 9P version.
144 .I Fsauth
145 executes an
146 .IR auth (9p)
147 transaction, returning the new auth fid.
148 .RI ( Fsread
149 and
150 .I fswrite
151 can then be used to run the authentication protocol over the fid.)
152 .I Fsattach
153 executes an
154 .IR attach (9p)
155 transaction to connect to the root of a file tree served by the server.
156 It presents
157 .I afid
158 (which may be nil)
159 to establish identity.
160 .I Fssetroot
161 sets the root fid used by
162 .IR fsopen ,
163 .IR fsopenfd ,
164 .IR fsdirstat ,
165 and
166 .IR fsdirwstat ,
167 which evaluate rooted path names.
168 .PP
169 When a fid
170 is no longer needed, it should be clunked by calling
171 .I fsclose
172 and then considered freed.
173 Similarly, when the connection to the server is no longer needed,
174 it should be closed by calling
175 .IR fsunmount ,
176 which will take care of calling
177 .I fsclose
178 on the current root fid.
179 Once all fids have been clunked
180 .I and
181 the connection has been closed
182 (the order is not important),
183 the allocated structures will be freed and the
184 file descriptor corresponding to the connection
185 will be closed
186 (see
187 .IR close (2)).
188 Fids are not reference counted: when
189 .I fsclose
190 is called, the clunk transaction and freeing of storage
191 happen immediately.
192 .PP
193 .I Fscreate
194 and
195 .I fsopen
196 establish new fids using the
197 .IR walk ,
198 .I create
199 and
200 .I open
201 transactions
202 (see
203 .IR walk (9p)
204 and
205 .IR open (9p)).
206 The
207 .I path
208 argument is evaluated relative to the
209 .B CFsys
210 root
211 (see
212 .I fsroot
213 and
214 .I fssetroot
215 above).
216 The path is parsed as a slash-separated sequence of path elements,
217 as on Unix and Plan 9.
218 Elements that are empty or
219 dot
220 .RB ( . )
221 are ignored.
222 .PP
223 Once opened, these fids can be read and written using
224 .I fspread
225 and
226 .IR fspwrite ,
227 which execute
228 .I read
229 and
230 .I write
231 transactions
232 (see
233 .IR read (9p)).
234 The library maintains an offset for each fid,
235 analagous to the offset maintained by the kernel for each open file descriptor.
236 .I Fsread
237 and
238 .I fswrite
239 read and write from this offset, and update it after successful calls.
240 .I Fsseek
241 sets the offset; the
242 .I n
243 and
244 .I type
245 arguments are used as in
246 .IR seek (3).
247 Calling
248 .I fspread
249 or
250 .I fspwrite
251 with an
252 .I offset
253 of \-1
254 is identical to calling
255 .I fsread
256 or
257 .IR fswrite .
258 .I Fsreadn
259 calls
260 .I fsread
261 repeatedly to obtain exactly
262 .I n
263 bytes of data, unless it encounters end-of-file or an error.
264 .PP
265 Reading an open a directory returns directory entries encoded as described in
266 .IR stat (9p).
267 .I Fsdirread
268 calls
269 .I fsread
270 and then parses the encoded entries into an array of
271 .B Dir*
272 data structures,
273 storing a pointer to the array in
274 .BI *d
275 and returning the number of entries.
276 .I Fsdirreadall
277 is similar but reads the entire directory.
278 The returned pointer should be freed with
279 .I free
280 (see
281 .IR malloc (3))
282 when no longer needed.
283 .PP
284 .I Fsdirfstat
285 and
286 .I fsdirfwstat
287 execute
288 .I stat
289 and
290 .I wstat
291 (see
292 .IR stat (9p))
293 transactions.
294 The
295 .B Dir
296 structure returned by
297 .I fsdirfstat
298 should be freed with
299 .I free
300 (see
301 .IR malloc (3))
302 when no longer needed.
303 .PP
304 .I Fsdirstat
305 and
306 .I fsdirwstat
307 are similar to
308 .I fsdirfstat
309 and
310 .I fsdirfwstat
311 but operate on paths relative to the file system root
312 (see
313 .I fsopen
314 and
315 .I fscreate
316 above).
317 .PP
318 .I Fsopenfd
319 opens a file on the 9P server
320 for reading or writing but returns a Unix file descriptor
321 instead of a fid structure.
322 The file descriptor is actually one end of a
323 .IR pipe (2).
324 A proxy process on the other end is ferrying data
325 between the pipe and the 9P fid.
326 Because of the implementation as a pipe,
327 the only signal of a read or write error is the closing of the pipe.
328 The file descriptor remains valid even after the
329 .B CFsys
330 is unmounted.
331 .SH SOURCE
332 .B \*9/src/lib9pclient
333 .SH SEE ALSO
334 .IR intro (4),
335 .IR intro (9p)
336 .SH BUGS
337 The implementation
338 should use a special version string to distinguish between
339 servers that support
340 .IR openfd (9p)
341 and servers that do not.
342 .PP
343 The interface does not provide access to the
344 .IR walk (9p)
345 transaction, or to
346 .I open
347 and
348 .I create
349 on already-established fids.