4 * This file contains functions 9P2000 functions
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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/config.h>
28 #include <linux/module.h>
29 #include <linux/errno.h>
31 #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 **fcall)
51 struct v9fs_fcall msg;
53 dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
56 msg.params.tversion.msize = msize;
57 msg.params.tversion.version = version;
59 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
63 * v9fs_t_attach - mount the server
64 * @v9ses: 9P2000 session information
65 * @uname: user name doing the attach
66 * @aname: remote name being attached to
67 * @fid: mount fid to attatch to root node
68 * @afid: authentication fid (in this case result key)
69 * @fcall: pointer to response fcall pointer
74 v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
75 u32 fid, u32 afid, struct v9fs_fcall **fcall)
77 struct v9fs_fcall msg;
79 dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname,
82 msg.params.tattach.fid = fid;
83 msg.params.tattach.afid = afid;
84 msg.params.tattach.uname = uname;
85 msg.params.tattach.aname = aname;
87 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
90 static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
91 struct v9fs_fcall *rc, int err)
94 struct v9fs_session_info *v9ses;
99 fid = tc->params.tclunk.fid;
105 dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id);
107 if (rc->id == RCLUNK)
108 v9fs_put_idpool(fid, &v9ses->fidpool);
114 * v9fs_t_clunk - release a fid (finish a transaction)
115 * @v9ses: 9P2000 session information
116 * @fid: fid to release
117 * @fcall: pointer to response fcall pointer
121 v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
124 struct v9fs_fcall *tc, *rc;
126 tc = kmalloc(sizeof(struct v9fs_fcall), GFP_KERNEL);
128 dprintk(DEBUG_9P, "fid %d\n", fid);
130 tc->params.tclunk.fid = fid;
132 err = v9fs_mux_rpc(v9ses->mux, tc, &rc);
134 v9fs_t_clunk_cb(v9ses, tc, rc, 0);
141 * v9fs_v9fs_t_flush - flush a pending transaction
142 * @v9ses: 9P2000 session information
143 * @tag: tid to release
147 int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag)
149 struct v9fs_fcall msg;
151 dprintk(DEBUG_9P, "oldtag %d\n", tag);
153 msg.params.tflush.oldtag = tag;
154 return v9fs_mux_rpc(v9ses->mux, &msg, NULL);
158 * v9fs_t_stat - read a file's meta-data
159 * @v9ses: 9P2000 session information
160 * @fid: fid pointing to file or directory to get info about
161 * @fcall: pointer to response fcall
166 v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall)
168 struct v9fs_fcall msg;
170 dprintk(DEBUG_9P, "fid %d\n", fid);
175 msg.params.tstat.fid = fid;
176 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
180 * v9fs_t_wstat - write a file's meta-data
181 * @v9ses: 9P2000 session information
182 * @fid: fid pointing to file or directory to write info about
184 * @fcall: pointer to response fcall
189 v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
190 struct v9fs_stat *stat, struct v9fs_fcall **fcall)
192 struct v9fs_fcall msg;
194 dprintk(DEBUG_9P, "fid %d length %d\n", fid, (int)stat->length);
196 msg.params.twstat.fid = fid;
197 msg.params.twstat.stat = stat;
199 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
203 * v9fs_t_walk - walk a fid to a new file or directory
204 * @v9ses: 9P2000 session information
206 * @newfid: new fid (for clone operations)
207 * @name: path to walk fid to
208 * @fcall: pointer to response fcall
212 /* TODO: support multiple walk */
215 v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
216 char *name, struct v9fs_fcall **fcall)
218 struct v9fs_fcall msg;
220 dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name);
222 msg.params.twalk.fid = fid;
223 msg.params.twalk.newfid = newfid;
226 msg.params.twalk.nwname = 1;
227 msg.params.twalk.wnames = &name;
229 msg.params.twalk.nwname = 0;
232 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
236 * v9fs_t_open - open a file
238 * @v9ses - 9P2000 session information
240 * @mode - mode to open file (R, RW, etc)
241 * @fcall - pointer to response fcall
246 v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
247 struct v9fs_fcall **fcall)
249 struct v9fs_fcall msg;
252 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
254 msg.params.topen.fid = fid;
255 msg.params.topen.mode = mode;
257 errorno = v9fs_mux_rpc(v9ses->mux, &msg, fcall);
263 * v9fs_t_remove - remove a file or directory
264 * @v9ses: 9P2000 session information
265 * @fid: fid to remove
266 * @fcall: pointer to response fcall
271 v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
272 struct v9fs_fcall **fcall)
274 struct v9fs_fcall msg;
276 dprintk(DEBUG_9P, "fid %d\n", fid);
278 msg.params.tremove.fid = fid;
279 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
283 * v9fs_t_create - create a file or directory
284 * @v9ses: 9P2000 session information
285 * @fid: fid to create
286 * @name: name of the file or directory to create
287 * @perm: permissions to create with
288 * @mode: mode to open file (R, RW, etc)
289 * @fcall: pointer to response fcall
294 v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
295 u32 perm, u8 mode, struct v9fs_fcall **fcall)
297 struct v9fs_fcall msg;
299 dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
300 fid, name, perm, mode);
303 msg.params.tcreate.fid = fid;
304 msg.params.tcreate.name = name;
305 msg.params.tcreate.perm = perm;
306 msg.params.tcreate.mode = mode;
308 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
312 * v9fs_t_read - read data
313 * @v9ses: 9P2000 session information
314 * @fid: fid to read from
315 * @offset: offset to start read at
316 * @count: how many bytes to read
317 * @fcall: pointer to response fcall (with data)
322 v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
323 u32 count, struct v9fs_fcall **fcall)
325 struct v9fs_fcall msg;
326 struct v9fs_fcall *rc = NULL;
329 dprintk(DEBUG_9P, "fid %d offset 0x%lx count 0x%x\n", fid,
330 (long unsigned int)offset, count);
332 msg.params.tread.fid = fid;
333 msg.params.tread.offset = offset;
334 msg.params.tread.count = count;
335 errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);
338 errorno = rc->params.rread.count;
339 dump_data(rc->params.rread.data, rc->params.rread.count);
351 * v9fs_t_write - write data
352 * @v9ses: 9P2000 session information
353 * @fid: fid to write to
354 * @offset: offset to start write at
355 * @count: how many bytes to write
356 * @fcall: pointer to response fcall
361 v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid,
362 u64 offset, u32 count, void *data, struct v9fs_fcall **fcall)
364 struct v9fs_fcall msg;
365 struct v9fs_fcall *rc = NULL;
368 dprintk(DEBUG_9P, "fid %d offset 0x%llx count 0x%x\n", fid,
369 (unsigned long long)offset, count);
370 dump_data(data, count);
373 msg.params.twrite.fid = fid;
374 msg.params.twrite.offset = offset;
375 msg.params.twrite.count = count;
376 msg.params.twrite.data = data;
378 errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);
381 errorno = rc->params.rwrite.count;