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 version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
27 #include <linux/module.h>
28 #include <linux/errno.h>
30 #include <linux/idr.h>
39 * v9fs_t_version - negotiate protocol parameters with sever
40 * @v9ses: 9P2000 session information
41 * @msize: requested max size packet
42 * @version: requested version.extension string
43 * @fcall: pointer to response fcall pointer
48 v9fs_t_version(struct v9fs_session_info
*v9ses
, u32 msize
,
49 char *version
, struct v9fs_fcall
**rcp
)
52 struct v9fs_fcall
*tc
;
54 dprintk(DEBUG_9P
, "msize: %d version: %s\n", msize
, version
);
55 tc
= v9fs_create_tversion(msize
, version
);
58 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
67 * v9fs_t_attach - mount the server
68 * @v9ses: 9P2000 session information
69 * @uname: user name doing the attach
70 * @aname: remote name being attached to
71 * @fid: mount fid to attatch to root node
72 * @afid: authentication fid (in this case result key)
73 * @fcall: pointer to response fcall pointer
78 v9fs_t_attach(struct v9fs_session_info
*v9ses
, char *uname
, char *aname
,
79 u32 fid
, u32 afid
, struct v9fs_fcall
**rcp
)
82 struct v9fs_fcall
* tc
;
84 dprintk(DEBUG_9P
, "uname '%s' aname '%s' fid %d afid %d\n", uname
,
87 tc
= v9fs_create_tattach(fid
, afid
, uname
, aname
);
89 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
97 static void v9fs_t_clunk_cb(void *a
, struct v9fs_fcall
*tc
,
98 struct v9fs_fcall
*rc
, int err
)
101 struct v9fs_session_info
*v9ses
;
104 fid
= tc
->params
.tclunk
.fid
;
112 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
117 * v9fs_t_clunk - release a fid (finish a transaction)
118 * @v9ses: 9P2000 session information
119 * @fid: fid to release
120 * @fcall: pointer to response fcall pointer
125 v9fs_t_clunk(struct v9fs_session_info
*v9ses
, u32 fid
)
128 struct v9fs_fcall
*tc
, *rc
;
130 dprintk(DEBUG_9P
, "fid %d\n", fid
);
133 tc
= v9fs_create_tclunk(fid
);
135 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
140 dprintk(DEBUG_ERROR
, "failed fid %d err %d\n", fid
, ret
);
142 v9fs_t_clunk_cb(v9ses
, tc
, rc
, ret
);
148 * v9fs_v9fs_t_flush - flush a pending transaction
149 * @v9ses: 9P2000 session information
150 * @tag: tag to release
153 int v9fs_t_flush(struct v9fs_session_info
*v9ses
, u16 oldtag
)
156 struct v9fs_fcall
*tc
;
158 dprintk(DEBUG_9P
, "oldtag %d\n", oldtag
);
160 tc
= v9fs_create_tflush(oldtag
);
162 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, NULL
);
172 * v9fs_t_stat - read a file's meta-data
173 * @v9ses: 9P2000 session information
174 * @fid: fid pointing to file or directory to get info about
175 * @fcall: pointer to response fcall
180 v9fs_t_stat(struct v9fs_session_info
*v9ses
, u32 fid
, struct v9fs_fcall
**rcp
)
183 struct v9fs_fcall
*tc
;
185 dprintk(DEBUG_9P
, "fid %d\n", fid
);
188 tc
= v9fs_create_tstat(fid
);
190 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
199 * v9fs_t_wstat - write a file's meta-data
200 * @v9ses: 9P2000 session information
201 * @fid: fid pointing to file or directory to write info about
203 * @fcall: pointer to response fcall
208 v9fs_t_wstat(struct v9fs_session_info
*v9ses
, u32 fid
,
209 struct v9fs_wstat
*wstat
, struct v9fs_fcall
**rcp
)
212 struct v9fs_fcall
*tc
;
214 dprintk(DEBUG_9P
, "fid %d\n", fid
);
216 tc
= v9fs_create_twstat(fid
, wstat
, v9ses
->extended
);
218 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
227 * v9fs_t_walk - walk a fid to a new file or directory
228 * @v9ses: 9P2000 session information
230 * @newfid: new fid (for clone operations)
231 * @name: path to walk fid to
232 * @fcall: pointer to response fcall
236 /* TODO: support multiple walk */
239 v9fs_t_walk(struct v9fs_session_info
*v9ses
, u32 fid
, u32 newfid
,
240 char *name
, struct v9fs_fcall
**rcp
)
243 struct v9fs_fcall
*tc
;
246 dprintk(DEBUG_9P
, "fid %d newfid %d wname '%s'\n", fid
, newfid
, name
);
253 tc
= v9fs_create_twalk(fid
, newfid
, nwname
, &name
);
255 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
264 * v9fs_t_open - open a file
266 * @v9ses - 9P2000 session information
268 * @mode - mode to open file (R, RW, etc)
269 * @fcall - pointer to response fcall
274 v9fs_t_open(struct v9fs_session_info
*v9ses
, u32 fid
, u8 mode
,
275 struct v9fs_fcall
**rcp
)
278 struct v9fs_fcall
*tc
;
280 dprintk(DEBUG_9P
, "fid %d mode %d\n", fid
, mode
);
282 tc
= v9fs_create_topen(fid
, mode
);
284 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
293 * v9fs_t_remove - remove a file or directory
294 * @v9ses: 9P2000 session information
295 * @fid: fid to remove
296 * @fcall: pointer to response fcall
301 v9fs_t_remove(struct v9fs_session_info
*v9ses
, u32 fid
,
302 struct v9fs_fcall
**rcp
)
305 struct v9fs_fcall
*tc
;
307 dprintk(DEBUG_9P
, "fid %d\n", fid
);
309 tc
= v9fs_create_tremove(fid
);
311 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
320 * v9fs_t_create - create a file or directory
321 * @v9ses: 9P2000 session information
322 * @fid: fid to create
323 * @name: name of the file or directory to create
324 * @perm: permissions to create with
325 * @mode: mode to open file (R, RW, etc)
326 * @fcall: pointer to response fcall
331 v9fs_t_create(struct v9fs_session_info
*v9ses
, u32 fid
, char *name
, u32 perm
,
332 u8 mode
, char *extension
, struct v9fs_fcall
**rcp
)
335 struct v9fs_fcall
*tc
;
337 dprintk(DEBUG_9P
, "fid %d name '%s' perm %x mode %d\n",
338 fid
, name
, perm
, mode
);
340 tc
= v9fs_create_tcreate(fid
, name
, perm
, mode
, extension
,
344 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
353 * v9fs_t_read - read data
354 * @v9ses: 9P2000 session information
355 * @fid: fid to read from
356 * @offset: offset to start read at
357 * @count: how many bytes to read
358 * @fcall: pointer to response fcall (with data)
363 v9fs_t_read(struct v9fs_session_info
*v9ses
, u32 fid
, u64 offset
,
364 u32 count
, struct v9fs_fcall
**rcp
)
367 struct v9fs_fcall
*tc
, *rc
;
369 dprintk(DEBUG_9P
, "fid %d offset 0x%llux count 0x%x\n", fid
,
370 (long long unsigned) offset
, count
);
372 tc
= v9fs_create_tread(fid
, offset
, count
);
374 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
376 ret
= rc
->params
.rread
.count
;
390 * v9fs_t_write - write data
391 * @v9ses: 9P2000 session information
392 * @fid: fid to write to
393 * @offset: offset to start write at
394 * @count: how many bytes to write
395 * @fcall: pointer to response fcall
400 v9fs_t_write(struct v9fs_session_info
*v9ses
, u32 fid
, u64 offset
, u32 count
,
401 const char __user
*data
, struct v9fs_fcall
**rcp
)
404 struct v9fs_fcall
*tc
, *rc
;
406 dprintk(DEBUG_9P
, "fid %d offset 0x%llux count 0x%x\n", fid
,
407 (long long unsigned) offset
, count
);
409 tc
= v9fs_create_twrite(fid
, offset
, count
, data
);
411 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
414 ret
= rc
->params
.rwrite
.count
;