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