4 * This file contains functions to perform synchronous 9P calls
6 * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net>
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to:
22 * Free Software Foundation
23 * 51 Franklin Street, Fifth Floor
24 * Boston, MA 02111-1301 USA
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/errno.h>
32 #include <linux/idr.h>
41 * v9fs_t_version - negotiate protocol parameters with sever
42 * @v9ses: 9P2000 session information
43 * @msize: requested max size packet
44 * @version: requested version.extension string
45 * @fcall: pointer to response fcall pointer
50 v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
51 char *version, struct v9fs_fcall **rcp)
54 struct v9fs_fcall *tc;
56 dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
57 tc = v9fs_create_tversion(msize, version);
60 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
69 * v9fs_t_attach - mount the server
70 * @v9ses: 9P2000 session information
71 * @uname: user name doing the attach
72 * @aname: remote name being attached to
73 * @fid: mount fid to attatch to root node
74 * @afid: authentication fid (in this case result key)
75 * @fcall: pointer to response fcall pointer
80 v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
81 u32 fid, u32 afid, struct v9fs_fcall **rcp)
84 struct v9fs_fcall* tc;
86 dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname,
90 tc = v9fs_create_tattach(fid, afid, uname, aname);
92 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
100 static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
101 struct v9fs_fcall *rc, int err)
104 struct v9fs_session_info *v9ses;
109 fid = tc->params.tclunk.fid;
115 dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id);
117 if (rc->id == RCLUNK)
118 v9fs_put_idpool(fid, &v9ses->fidpool);
124 * v9fs_t_clunk - release a fid (finish a transaction)
125 * @v9ses: 9P2000 session information
126 * @fid: fid to release
127 * @fcall: pointer to response fcall pointer
132 v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
135 struct v9fs_fcall *tc, *rc;
137 dprintk(DEBUG_9P, "fid %d\n", fid);
141 tc = v9fs_create_tclunk(fid);
143 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
148 dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret);
150 v9fs_t_clunk_cb(v9ses, tc, rc, ret);
155 * v9fs_v9fs_t_flush - flush a pending transaction
156 * @v9ses: 9P2000 session information
157 * @tag: tid to release
161 int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag)
164 struct v9fs_fcall *tc;
166 dprintk(DEBUG_9P, "oldtag %d\n", oldtag);
169 tc = v9fs_create_tflush(oldtag);
171 ret = v9fs_mux_rpc(v9ses->mux, tc, NULL);
180 * v9fs_t_stat - read a file's meta-data
181 * @v9ses: 9P2000 session information
182 * @fid: fid pointing to file or directory to get info about
183 * @fcall: pointer to response fcall
188 v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp)
191 struct v9fs_fcall *tc;
193 dprintk(DEBUG_9P, "fid %d\n", fid);
196 tc = v9fs_create_tstat(fid);
198 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
207 * v9fs_t_wstat - write a file's meta-data
208 * @v9ses: 9P2000 session information
209 * @fid: fid pointing to file or directory to write info about
211 * @fcall: pointer to response fcall
216 v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
217 struct v9fs_wstat *wstat, struct v9fs_fcall **rcp)
220 struct v9fs_fcall *tc;
222 dprintk(DEBUG_9P, "fid %d\n", fid);
225 tc = v9fs_create_twstat(fid, wstat, v9ses->extended);
227 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
236 * v9fs_t_walk - walk a fid to a new file or directory
237 * @v9ses: 9P2000 session information
239 * @newfid: new fid (for clone operations)
240 * @name: path to walk fid to
241 * @fcall: pointer to response fcall
245 /* TODO: support multiple walk */
248 v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
249 char *name, struct v9fs_fcall **rcp)
252 struct v9fs_fcall *tc;
255 dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name);
263 tc = v9fs_create_twalk(fid, newfid, nwname, &name);
265 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
274 * v9fs_t_open - open a file
276 * @v9ses - 9P2000 session information
278 * @mode - mode to open file (R, RW, etc)
279 * @fcall - pointer to response fcall
284 v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
285 struct v9fs_fcall **rcp)
288 struct v9fs_fcall *tc;
290 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
293 tc = v9fs_create_topen(fid, mode);
295 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
304 * v9fs_t_remove - remove a file or directory
305 * @v9ses: 9P2000 session information
306 * @fid: fid to remove
307 * @fcall: pointer to response fcall
312 v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
313 struct v9fs_fcall **rcp)
316 struct v9fs_fcall *tc;
318 dprintk(DEBUG_9P, "fid %d\n", fid);
321 tc = v9fs_create_tremove(fid);
323 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
332 * v9fs_t_create - create a file or directory
333 * @v9ses: 9P2000 session information
334 * @fid: fid to create
335 * @name: name of the file or directory to create
336 * @perm: permissions to create with
337 * @mode: mode to open file (R, RW, etc)
338 * @fcall: pointer to response fcall
343 v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
344 u32 perm, u8 mode, struct v9fs_fcall **rcp)
347 struct v9fs_fcall *tc;
349 dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
350 fid, name, perm, mode);
353 tc = v9fs_create_tcreate(fid, name, perm, mode);
355 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
364 * v9fs_t_read - read data
365 * @v9ses: 9P2000 session information
366 * @fid: fid to read from
367 * @offset: offset to start read at
368 * @count: how many bytes to read
369 * @fcall: pointer to response fcall (with data)
374 v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
375 u32 count, struct v9fs_fcall **rcp)
378 struct v9fs_fcall *tc, *rc;
380 dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
381 (long long unsigned) offset, count);
384 tc = v9fs_create_tread(fid, offset, count);
386 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
388 ret = rc->params.rread.count;
402 * v9fs_t_write - write data
403 * @v9ses: 9P2000 session information
404 * @fid: fid to write to
405 * @offset: offset to start write at
406 * @count: how many bytes to write
407 * @fcall: pointer to response fcall
412 v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count,
413 const char __user *data, struct v9fs_fcall **rcp)
416 struct v9fs_fcall *tc, *rc;
418 dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
419 (long long unsigned) offset, count);
422 tc = v9fs_create_twrite(fid, offset, count, data);
424 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
427 ret = rc->params.rwrite.count;