]>
Commit | Line | Data |
---|---|---|
b8cf945b EVH |
1 | /* |
2 | * linux/fs/9p/9p.c | |
3 | * | |
531b1094 | 4 | * This file contains functions to perform synchronous 9P calls |
b8cf945b | 5 | * |
531b1094 | 6 | * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net> |
b8cf945b EVH |
7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
8 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | |
9 | * | |
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. | |
14 | * | |
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. | |
19 | * | |
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 | |
25 | * | |
26 | */ | |
27 | ||
28 | #include <linux/config.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/errno.h> | |
31 | #include <linux/fs.h> | |
32 | #include <linux/idr.h> | |
33 | ||
34 | #include "debug.h" | |
35 | #include "v9fs.h" | |
36 | #include "9p.h" | |
531b1094 | 37 | #include "conv.h" |
b8cf945b EVH |
38 | #include "mux.h" |
39 | ||
40 | /** | |
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 | |
46 | * | |
47 | */ | |
48 | ||
49 | int | |
50 | v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, | |
531b1094 | 51 | char *version, struct v9fs_fcall **rcp) |
b8cf945b | 52 | { |
531b1094 LI |
53 | int ret; |
54 | struct v9fs_fcall *tc; | |
b8cf945b EVH |
55 | |
56 | dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version); | |
531b1094 | 57 | tc = v9fs_create_tversion(msize, version); |
b8cf945b | 58 | |
531b1094 LI |
59 | if (!IS_ERR(tc)) { |
60 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
61 | kfree(tc); | |
62 | } else | |
63 | ret = PTR_ERR(tc); | |
64 | ||
65 | return ret; | |
b8cf945b EVH |
66 | } |
67 | ||
68 | /** | |
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 | |
76 | * | |
77 | */ | |
78 | ||
79 | int | |
80 | v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, | |
531b1094 | 81 | u32 fid, u32 afid, struct v9fs_fcall **rcp) |
b8cf945b | 82 | { |
531b1094 LI |
83 | int ret; |
84 | struct v9fs_fcall* tc; | |
b8cf945b EVH |
85 | |
86 | dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname, | |
87 | aname, fid, afid); | |
b8cf945b | 88 | |
531b1094 LI |
89 | tc = v9fs_create_tattach(fid, afid, uname, aname); |
90 | if (!IS_ERR(tc)) { | |
91 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
92 | kfree(tc); | |
93 | } else | |
94 | ret = PTR_ERR(tc); | |
95 | ||
96 | return ret; | |
3cf6429a LI |
97 | } |
98 | ||
99 | static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc, | |
100 | struct v9fs_fcall *rc, int err) | |
101 | { | |
102 | int fid; | |
103 | struct v9fs_session_info *v9ses; | |
104 | ||
105 | if (err) | |
106 | return; | |
107 | ||
108 | fid = tc->params.tclunk.fid; | |
109 | kfree(tc); | |
110 | ||
111 | if (!rc) | |
112 | return; | |
113 | ||
3cf6429a LI |
114 | v9ses = a; |
115 | if (rc->id == RCLUNK) | |
116 | v9fs_put_idpool(fid, &v9ses->fidpool); | |
117 | ||
118 | kfree(rc); | |
b8cf945b EVH |
119 | } |
120 | ||
121 | /** | |
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 | |
126 | * | |
127 | */ | |
531b1094 | 128 | |
b8cf945b | 129 | int |
3cf6429a | 130 | v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid) |
b8cf945b | 131 | { |
531b1094 | 132 | int ret; |
3cf6429a LI |
133 | struct v9fs_fcall *tc, *rc; |
134 | ||
b8cf945b | 135 | dprintk(DEBUG_9P, "fid %d\n", fid); |
b8cf945b | 136 | |
531b1094 LI |
137 | rc = NULL; |
138 | tc = v9fs_create_tclunk(fid); | |
139 | if (!IS_ERR(tc)) | |
140 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); | |
141 | else | |
142 | ret = PTR_ERR(tc); | |
143 | ||
144 | if (ret) | |
145 | dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret); | |
3cf6429a | 146 | |
531b1094 LI |
147 | v9fs_t_clunk_cb(v9ses, tc, rc, ret); |
148 | return ret; | |
b8cf945b EVH |
149 | } |
150 | ||
29c6e486 | 151 | #if 0 |
b8cf945b EVH |
152 | /** |
153 | * v9fs_v9fs_t_flush - flush a pending transaction | |
154 | * @v9ses: 9P2000 session information | |
155 | * @tag: tid to release | |
156 | * | |
157 | */ | |
158 | ||
531b1094 | 159 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag) |
b8cf945b | 160 | { |
531b1094 LI |
161 | int ret; |
162 | struct v9fs_fcall *tc; | |
b8cf945b | 163 | |
531b1094 LI |
164 | dprintk(DEBUG_9P, "oldtag %d\n", oldtag); |
165 | ||
531b1094 LI |
166 | tc = v9fs_create_tflush(oldtag); |
167 | if (!IS_ERR(tc)) { | |
168 | ret = v9fs_mux_rpc(v9ses->mux, tc, NULL); | |
169 | kfree(tc); | |
170 | } else | |
171 | ret = PTR_ERR(tc); | |
172 | ||
173 | return ret; | |
b8cf945b | 174 | } |
29c6e486 | 175 | #endif /* 0 */ |
b8cf945b EVH |
176 | |
177 | /** | |
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 | |
182 | * | |
183 | */ | |
184 | ||
185 | int | |
531b1094 | 186 | v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp) |
b8cf945b | 187 | { |
531b1094 LI |
188 | int ret; |
189 | struct v9fs_fcall *tc; | |
b8cf945b EVH |
190 | |
191 | dprintk(DEBUG_9P, "fid %d\n", fid); | |
b8cf945b | 192 | |
531b1094 LI |
193 | ret = -ENOMEM; |
194 | tc = v9fs_create_tstat(fid); | |
195 | if (!IS_ERR(tc)) { | |
196 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
197 | kfree(tc); | |
198 | } else | |
199 | ret = PTR_ERR(tc); | |
200 | ||
201 | return ret; | |
b8cf945b EVH |
202 | } |
203 | ||
204 | /** | |
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 | |
208 | * @stat: metadata | |
209 | * @fcall: pointer to response fcall | |
210 | * | |
211 | */ | |
212 | ||
213 | int | |
214 | v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, | |
531b1094 | 215 | struct v9fs_wstat *wstat, struct v9fs_fcall **rcp) |
b8cf945b | 216 | { |
531b1094 LI |
217 | int ret; |
218 | struct v9fs_fcall *tc; | |
b8cf945b | 219 | |
531b1094 LI |
220 | dprintk(DEBUG_9P, "fid %d\n", fid); |
221 | ||
531b1094 LI |
222 | tc = v9fs_create_twstat(fid, wstat, v9ses->extended); |
223 | if (!IS_ERR(tc)) { | |
224 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
225 | kfree(tc); | |
226 | } else | |
227 | ret = PTR_ERR(tc); | |
b8cf945b | 228 | |
531b1094 | 229 | return ret; |
b8cf945b EVH |
230 | } |
231 | ||
232 | /** | |
233 | * v9fs_t_walk - walk a fid to a new file or directory | |
234 | * @v9ses: 9P2000 session information | |
235 | * @fid: fid to walk | |
236 | * @newfid: new fid (for clone operations) | |
237 | * @name: path to walk fid to | |
238 | * @fcall: pointer to response fcall | |
239 | * | |
240 | */ | |
241 | ||
242 | /* TODO: support multiple walk */ | |
243 | ||
244 | int | |
245 | v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, | |
531b1094 | 246 | char *name, struct v9fs_fcall **rcp) |
b8cf945b | 247 | { |
531b1094 LI |
248 | int ret; |
249 | struct v9fs_fcall *tc; | |
250 | int nwname; | |
b8cf945b EVH |
251 | |
252 | dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name); | |
531b1094 LI |
253 | |
254 | if (name) | |
255 | nwname = 1; | |
256 | else | |
257 | nwname = 0; | |
258 | ||
531b1094 LI |
259 | tc = v9fs_create_twalk(fid, newfid, nwname, &name); |
260 | if (!IS_ERR(tc)) { | |
261 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
262 | kfree(tc); | |
263 | } else | |
264 | ret = PTR_ERR(tc); | |
265 | ||
266 | return ret; | |
b8cf945b EVH |
267 | } |
268 | ||
269 | /** | |
270 | * v9fs_t_open - open a file | |
271 | * | |
272 | * @v9ses - 9P2000 session information | |
273 | * @fid - fid to open | |
274 | * @mode - mode to open file (R, RW, etc) | |
275 | * @fcall - pointer to response fcall | |
276 | * | |
277 | */ | |
278 | ||
279 | int | |
280 | v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, | |
531b1094 | 281 | struct v9fs_fcall **rcp) |
b8cf945b | 282 | { |
531b1094 LI |
283 | int ret; |
284 | struct v9fs_fcall *tc; | |
b8cf945b EVH |
285 | |
286 | dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode); | |
b8cf945b | 287 | |
531b1094 LI |
288 | tc = v9fs_create_topen(fid, mode); |
289 | if (!IS_ERR(tc)) { | |
290 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
291 | kfree(tc); | |
292 | } else | |
293 | ret = PTR_ERR(tc); | |
b8cf945b | 294 | |
531b1094 | 295 | return ret; |
b8cf945b EVH |
296 | } |
297 | ||
298 | /** | |
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 | |
303 | * | |
304 | */ | |
305 | ||
306 | int | |
307 | v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, | |
531b1094 | 308 | struct v9fs_fcall **rcp) |
b8cf945b | 309 | { |
531b1094 LI |
310 | int ret; |
311 | struct v9fs_fcall *tc; | |
b8cf945b EVH |
312 | |
313 | dprintk(DEBUG_9P, "fid %d\n", fid); | |
531b1094 | 314 | |
531b1094 LI |
315 | tc = v9fs_create_tremove(fid); |
316 | if (!IS_ERR(tc)) { | |
317 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
318 | kfree(tc); | |
319 | } else | |
320 | ret = PTR_ERR(tc); | |
321 | ||
322 | return ret; | |
b8cf945b EVH |
323 | } |
324 | ||
325 | /** | |
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 | |
333 | * | |
334 | */ | |
335 | ||
336 | int | |
337 | v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, | |
531b1094 | 338 | u32 perm, u8 mode, struct v9fs_fcall **rcp) |
b8cf945b | 339 | { |
531b1094 LI |
340 | int ret; |
341 | struct v9fs_fcall *tc; | |
b8cf945b EVH |
342 | |
343 | dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n", | |
344 | fid, name, perm, mode); | |
345 | ||
531b1094 LI |
346 | tc = v9fs_create_tcreate(fid, name, perm, mode); |
347 | if (!IS_ERR(tc)) { | |
348 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | |
349 | kfree(tc); | |
350 | } else | |
351 | ret = PTR_ERR(tc); | |
b8cf945b | 352 | |
531b1094 | 353 | return ret; |
b8cf945b EVH |
354 | } |
355 | ||
356 | /** | |
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) | |
363 | * | |
364 | */ | |
365 | ||
366 | int | |
367 | v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset, | |
531b1094 | 368 | u32 count, struct v9fs_fcall **rcp) |
b8cf945b | 369 | { |
531b1094 LI |
370 | int ret; |
371 | struct v9fs_fcall *tc, *rc; | |
b8cf945b | 372 | |
531b1094 LI |
373 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, |
374 | (long long unsigned) offset, count); | |
375 | ||
531b1094 LI |
376 | tc = v9fs_create_tread(fid, offset, count); |
377 | if (!IS_ERR(tc)) { | |
378 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); | |
379 | if (!ret) | |
380 | ret = rc->params.rread.count; | |
381 | if (rcp) | |
382 | *rcp = rc; | |
383 | else | |
384 | kfree(rc); | |
385 | ||
386 | kfree(tc); | |
387 | } else | |
388 | ret = PTR_ERR(tc); | |
389 | ||
390 | return ret; | |
b8cf945b EVH |
391 | } |
392 | ||
393 | /** | |
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 | |
400 | * | |
401 | */ | |
402 | ||
403 | int | |
531b1094 LI |
404 | v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count, |
405 | const char __user *data, struct v9fs_fcall **rcp) | |
b8cf945b | 406 | { |
531b1094 LI |
407 | int ret; |
408 | struct v9fs_fcall *tc, *rc; | |
b8cf945b | 409 | |
531b1094 LI |
410 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, |
411 | (long long unsigned) offset, count); | |
b8cf945b | 412 | |
531b1094 LI |
413 | tc = v9fs_create_twrite(fid, offset, count, data); |
414 | if (!IS_ERR(tc)) { | |
415 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); | |
b8cf945b | 416 | |
531b1094 LI |
417 | if (!ret) |
418 | ret = rc->params.rwrite.count; | |
419 | if (rcp) | |
420 | *rcp = rc; | |
421 | else | |
422 | kfree(rc); | |
b8cf945b | 423 | |
531b1094 LI |
424 | kfree(tc); |
425 | } else | |
426 | ret = PTR_ERR(tc); | |
b8cf945b | 427 | |
531b1094 | 428 | return ret; |
b8cf945b | 429 | } |
531b1094 | 430 |