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/sched.h>
31 #include <linux/idr.h>
40 * v9fs_t_version - negotiate protocol parameters with sever
41 * @v9ses: 9P2000 session information
42 * @msize: requested max size packet
43 * @version: requested version.extension string
44 * @fcall: pointer to response fcall pointer
49 v9fs_t_version(struct v9fs_session_info
*v9ses
, u32 msize
,
50 char *version
, struct v9fs_fcall
**rcp
)
53 struct v9fs_fcall
*tc
;
55 dprintk(DEBUG_9P
, "msize: %d version: %s\n", msize
, version
);
56 tc
= v9fs_create_tversion(msize
, version
);
59 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
68 * v9fs_t_attach - mount the server
69 * @v9ses: 9P2000 session information
70 * @uname: user name doing the attach
71 * @aname: remote name being attached to
72 * @fid: mount fid to attatch to root node
73 * @afid: authentication fid (in this case result key)
74 * @fcall: pointer to response fcall pointer
79 v9fs_t_attach(struct v9fs_session_info
*v9ses
, char *uname
, char *aname
,
80 u32 fid
, u32 afid
, struct v9fs_fcall
**rcp
)
83 struct v9fs_fcall
* tc
;
85 dprintk(DEBUG_9P
, "uname '%s' aname '%s' fid %d afid %d\n", uname
,
88 tc
= v9fs_create_tattach(fid
, afid
, uname
, aname
);
90 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
98 static void v9fs_t_clunk_cb(void *a
, struct v9fs_fcall
*tc
,
99 struct v9fs_fcall
*rc
, int err
)
102 struct v9fs_session_info
*v9ses
;
105 fid
= tc
->params
.tclunk
.fid
;
113 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
118 * v9fs_t_clunk - release a fid (finish a transaction)
119 * @v9ses: 9P2000 session information
120 * @fid: fid to release
121 * @fcall: pointer to response fcall pointer
126 v9fs_t_clunk(struct v9fs_session_info
*v9ses
, u32 fid
)
129 struct v9fs_fcall
*tc
, *rc
;
131 dprintk(DEBUG_9P
, "fid %d\n", fid
);
134 tc
= v9fs_create_tclunk(fid
);
136 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
141 dprintk(DEBUG_ERROR
, "failed fid %d err %d\n", fid
, ret
);
143 v9fs_t_clunk_cb(v9ses
, tc
, rc
, ret
);
149 * v9fs_v9fs_t_flush - flush a pending transaction
150 * @v9ses: 9P2000 session information
151 * @tag: tag to release
154 int v9fs_t_flush(struct v9fs_session_info
*v9ses
, u16 oldtag
)
157 struct v9fs_fcall
*tc
;
159 dprintk(DEBUG_9P
, "oldtag %d\n", oldtag
);
161 tc
= v9fs_create_tflush(oldtag
);
163 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, NULL
);
173 * v9fs_t_stat - read a file's meta-data
174 * @v9ses: 9P2000 session information
175 * @fid: fid pointing to file or directory to get info about
176 * @fcall: pointer to response fcall
181 v9fs_t_stat(struct v9fs_session_info
*v9ses
, u32 fid
, struct v9fs_fcall
**rcp
)
184 struct v9fs_fcall
*tc
;
186 dprintk(DEBUG_9P
, "fid %d\n", fid
);
189 tc
= v9fs_create_tstat(fid
);
191 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
200 * v9fs_t_wstat - write a file's meta-data
201 * @v9ses: 9P2000 session information
202 * @fid: fid pointing to file or directory to write info about
204 * @fcall: pointer to response fcall
209 v9fs_t_wstat(struct v9fs_session_info
*v9ses
, u32 fid
,
210 struct v9fs_wstat
*wstat
, struct v9fs_fcall
**rcp
)
213 struct v9fs_fcall
*tc
;
215 dprintk(DEBUG_9P
, "fid %d\n", fid
);
217 tc
= v9fs_create_twstat(fid
, wstat
, v9ses
->extended
);
219 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
228 * v9fs_t_walk - walk a fid to a new file or directory
229 * @v9ses: 9P2000 session information
231 * @newfid: new fid (for clone operations)
232 * @name: path to walk fid to
233 * @fcall: pointer to response fcall
237 /* TODO: support multiple walk */
240 v9fs_t_walk(struct v9fs_session_info
*v9ses
, u32 fid
, u32 newfid
,
241 char *name
, struct v9fs_fcall
**rcp
)
244 struct v9fs_fcall
*tc
;
247 dprintk(DEBUG_9P
, "fid %d newfid %d wname '%s'\n", fid
, newfid
, name
);
254 tc
= v9fs_create_twalk(fid
, newfid
, nwname
, &name
);
256 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
265 * v9fs_t_open - open a file
267 * @v9ses - 9P2000 session information
269 * @mode - mode to open file (R, RW, etc)
270 * @fcall - pointer to response fcall
275 v9fs_t_open(struct v9fs_session_info
*v9ses
, u32 fid
, u8 mode
,
276 struct v9fs_fcall
**rcp
)
279 struct v9fs_fcall
*tc
;
281 dprintk(DEBUG_9P
, "fid %d mode %d\n", fid
, mode
);
283 tc
= v9fs_create_topen(fid
, mode
);
285 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
294 * v9fs_t_remove - remove a file or directory
295 * @v9ses: 9P2000 session information
296 * @fid: fid to remove
297 * @fcall: pointer to response fcall
302 v9fs_t_remove(struct v9fs_session_info
*v9ses
, u32 fid
,
303 struct v9fs_fcall
**rcp
)
306 struct v9fs_fcall
*tc
;
308 dprintk(DEBUG_9P
, "fid %d\n", fid
);
310 tc
= v9fs_create_tremove(fid
);
312 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
321 * v9fs_t_create - create a file or directory
322 * @v9ses: 9P2000 session information
323 * @fid: fid to create
324 * @name: name of the file or directory to create
325 * @perm: permissions to create with
326 * @mode: mode to open file (R, RW, etc)
327 * @fcall: pointer to response fcall
332 v9fs_t_create(struct v9fs_session_info
*v9ses
, u32 fid
, char *name
, u32 perm
,
333 u8 mode
, char *extension
, struct v9fs_fcall
**rcp
)
336 struct v9fs_fcall
*tc
;
338 dprintk(DEBUG_9P
, "fid %d name '%s' perm %x mode %d\n",
339 fid
, name
, perm
, mode
);
341 tc
= v9fs_create_tcreate(fid
, name
, perm
, mode
, extension
,
345 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, rcp
);
354 * v9fs_t_read - read data
355 * @v9ses: 9P2000 session information
356 * @fid: fid to read from
357 * @offset: offset to start read at
358 * @count: how many bytes to read
359 * @fcall: pointer to response fcall (with data)
364 v9fs_t_read(struct v9fs_session_info
*v9ses
, u32 fid
, u64 offset
,
365 u32 count
, struct v9fs_fcall
**rcp
)
368 struct v9fs_fcall
*tc
, *rc
;
370 dprintk(DEBUG_9P
, "fid %d offset 0x%llux count 0x%x\n", fid
,
371 (long long unsigned) offset
, count
);
373 tc
= v9fs_create_tread(fid
, offset
, count
);
375 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
377 ret
= rc
->params
.rread
.count
;
391 * v9fs_t_write - write data
392 * @v9ses: 9P2000 session information
393 * @fid: fid to write to
394 * @offset: offset to start write at
395 * @count: how many bytes to write
396 * @fcall: pointer to response fcall
401 v9fs_t_write(struct v9fs_session_info
*v9ses
, u32 fid
, u64 offset
, u32 count
,
402 const char __user
*data
, struct v9fs_fcall
**rcp
)
405 struct v9fs_fcall
*tc
, *rc
;
407 dprintk(DEBUG_9P
, "fid %d offset 0x%llux count 0x%x\n", fid
,
408 (long long unsigned) offset
, count
);
410 tc
= v9fs_create_twrite(fid
, offset
, count
, data
);
412 ret
= v9fs_mux_rpc(v9ses
->mux
, tc
, &rc
);
415 ret
= rc
->params
.rwrite
.count
;