Blob


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