Blob


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