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,
89 tc = v9fs_create_tattach(fid, afid, uname, aname);
91 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
99 static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
100 struct v9fs_fcall *rc, int err)
103 struct v9fs_session_info *v9ses;
108 fid = tc->params.tclunk.fid;
115 if (rc->id == RCLUNK)
116 v9fs_put_idpool(fid, &v9ses->fidpool);
122 * v9fs_t_clunk - release a fid (finish a transaction)
123 * @v9ses: 9P2000 session information
124 * @fid: fid to release
125 * @fcall: pointer to response fcall pointer
130 v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
133 struct v9fs_fcall *tc, *rc;
135 dprintk(DEBUG_9P, "fid %d\n", fid);
138 tc = v9fs_create_tclunk(fid);
140 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
145 dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret);
147 v9fs_t_clunk_cb(v9ses, tc, rc, ret);
153 * v9fs_v9fs_t_flush - flush a pending transaction
154 * @v9ses: 9P2000 session information
155 * @tag: tag to release
159 int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag)
162 struct v9fs_fcall *tc;
164 dprintk(DEBUG_9P, "oldtag %d\n", oldtag);
166 tc = v9fs_create_tflush(oldtag);
168 ret = v9fs_mux_rpc(v9ses->mux, tc, NULL);
178 * v9fs_t_stat - read a file's meta-data
179 * @v9ses: 9P2000 session information
180 * @fid: fid pointing to file or directory to get info about
181 * @fcall: pointer to response fcall
186 v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp)
189 struct v9fs_fcall *tc;
191 dprintk(DEBUG_9P, "fid %d\n", fid);
194 tc = v9fs_create_tstat(fid);
196 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
205 * v9fs_t_wstat - write a file's meta-data
206 * @v9ses: 9P2000 session information
207 * @fid: fid pointing to file or directory to write info about
209 * @fcall: pointer to response fcall
214 v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
215 struct v9fs_wstat *wstat, struct v9fs_fcall **rcp)
218 struct v9fs_fcall *tc;
220 dprintk(DEBUG_9P, "fid %d\n", fid);
222 tc = v9fs_create_twstat(fid, wstat, v9ses->extended);
224 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
233 * v9fs_t_walk - walk a fid to a new file or directory
234 * @v9ses: 9P2000 session information
236 * @newfid: new fid (for clone operations)
237 * @name: path to walk fid to
238 * @fcall: pointer to response fcall
242 /* TODO: support multiple walk */
245 v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
246 char *name, struct v9fs_fcall **rcp)
249 struct v9fs_fcall *tc;
252 dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name);
259 tc = v9fs_create_twalk(fid, newfid, nwname, &name);
261 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
270 * v9fs_t_open - open a file
272 * @v9ses - 9P2000 session information
274 * @mode - mode to open file (R, RW, etc)
275 * @fcall - pointer to response fcall
280 v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
281 struct v9fs_fcall **rcp)
284 struct v9fs_fcall *tc;
286 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
288 tc = v9fs_create_topen(fid, mode);
290 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
299 * v9fs_t_remove - remove a file or directory
300 * @v9ses: 9P2000 session information
301 * @fid: fid to remove
302 * @fcall: pointer to response fcall
307 v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
308 struct v9fs_fcall **rcp)
311 struct v9fs_fcall *tc;
313 dprintk(DEBUG_9P, "fid %d\n", fid);
315 tc = v9fs_create_tremove(fid);
317 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
326 * v9fs_t_create - create a file or directory
327 * @v9ses: 9P2000 session information
328 * @fid: fid to create
329 * @name: name of the file or directory to create
330 * @perm: permissions to create with
331 * @mode: mode to open file (R, RW, etc)
332 * @fcall: pointer to response fcall
337 v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
338 u32 perm, u8 mode, struct v9fs_fcall **rcp)
341 struct v9fs_fcall *tc;
343 dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
344 fid, name, perm, mode);
346 tc = v9fs_create_tcreate(fid, name, perm, mode);
348 ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
357 * v9fs_t_read - read data
358 * @v9ses: 9P2000 session information
359 * @fid: fid to read from
360 * @offset: offset to start read at
361 * @count: how many bytes to read
362 * @fcall: pointer to response fcall (with data)
367 v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
368 u32 count, struct v9fs_fcall **rcp)
371 struct v9fs_fcall *tc, *rc;
373 dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
374 (long long unsigned) offset, count);
376 tc = v9fs_create_tread(fid, offset, count);
378 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
380 ret = rc->params.rread.count;
394 * v9fs_t_write - write data
395 * @v9ses: 9P2000 session information
396 * @fid: fid to write to
397 * @offset: offset to start write at
398 * @count: how many bytes to write
399 * @fcall: pointer to response fcall
404 v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count,
405 const char __user *data, struct v9fs_fcall **rcp)
408 struct v9fs_fcall *tc, *rc;
410 dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
411 (long long unsigned) offset, count);
413 tc = v9fs_create_twrite(fid, offset, count, data);
415 ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
418 ret = rc->params.rwrite.count;