Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/9p/9p.c |
| 3 | * |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 4 | * This file contains functions to perform synchronous 9P calls |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 5 | * |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 6 | * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net> |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 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" |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 37 | #include "conv.h" |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 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, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 51 | char *version, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 52 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 53 | int ret; |
| 54 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 55 | |
| 56 | dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 57 | tc = v9fs_create_tversion(msize, version); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 58 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 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; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 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, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 81 | u32 fid, u32 afid, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 82 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 83 | int ret; |
| 84 | struct v9fs_fcall* tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 85 | |
| 86 | dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname, |
| 87 | aname, fid, afid); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 88 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 89 | ret = -ENOMEM; |
| 90 | tc = v9fs_create_tattach(fid, afid, uname, aname); |
| 91 | if (!IS_ERR(tc)) { |
| 92 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 93 | kfree(tc); |
| 94 | } else |
| 95 | ret = PTR_ERR(tc); |
| 96 | |
| 97 | return ret; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc, |
| 101 | struct v9fs_fcall *rc, int err) |
| 102 | { |
| 103 | int fid; |
| 104 | struct v9fs_session_info *v9ses; |
| 105 | |
| 106 | if (err) |
| 107 | return; |
| 108 | |
| 109 | fid = tc->params.tclunk.fid; |
| 110 | kfree(tc); |
| 111 | |
| 112 | if (!rc) |
| 113 | return; |
| 114 | |
| 115 | dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id); |
| 116 | v9ses = a; |
| 117 | if (rc->id == RCLUNK) |
| 118 | v9fs_put_idpool(fid, &v9ses->fidpool); |
| 119 | |
| 120 | kfree(rc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * v9fs_t_clunk - release a fid (finish a transaction) |
| 125 | * @v9ses: 9P2000 session information |
| 126 | * @fid: fid to release |
| 127 | * @fcall: pointer to response fcall pointer |
| 128 | * |
| 129 | */ |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 130 | |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 131 | int |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 132 | v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 133 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 134 | int ret; |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 135 | struct v9fs_fcall *tc, *rc; |
| 136 | |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 137 | dprintk(DEBUG_9P, "fid %d\n", fid); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 138 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 139 | ret = -ENOMEM; |
| 140 | rc = NULL; |
| 141 | tc = v9fs_create_tclunk(fid); |
| 142 | if (!IS_ERR(tc)) |
| 143 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); |
| 144 | else |
| 145 | ret = PTR_ERR(tc); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 146 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 147 | if (ret) |
| 148 | dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret); |
| 149 | |
| 150 | v9fs_t_clunk_cb(v9ses, tc, rc, ret); |
| 151 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * v9fs_v9fs_t_flush - flush a pending transaction |
| 156 | * @v9ses: 9P2000 session information |
| 157 | * @tag: tid to release |
| 158 | * |
| 159 | */ |
| 160 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 161 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 162 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 163 | int ret; |
| 164 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 165 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 166 | dprintk(DEBUG_9P, "oldtag %d\n", oldtag); |
| 167 | |
| 168 | ret = -ENOMEM; |
| 169 | tc = v9fs_create_tflush(oldtag); |
| 170 | if (!IS_ERR(tc)) { |
| 171 | ret = v9fs_mux_rpc(v9ses->mux, tc, NULL); |
| 172 | kfree(tc); |
| 173 | } else |
| 174 | ret = PTR_ERR(tc); |
| 175 | |
| 176 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
| 180 | * v9fs_t_stat - read a file's meta-data |
| 181 | * @v9ses: 9P2000 session information |
| 182 | * @fid: fid pointing to file or directory to get info about |
| 183 | * @fcall: pointer to response fcall |
| 184 | * |
| 185 | */ |
| 186 | |
| 187 | int |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 188 | v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 189 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 190 | int ret; |
| 191 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 192 | |
| 193 | dprintk(DEBUG_9P, "fid %d\n", fid); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 194 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 195 | ret = -ENOMEM; |
| 196 | tc = v9fs_create_tstat(fid); |
| 197 | if (!IS_ERR(tc)) { |
| 198 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 199 | kfree(tc); |
| 200 | } else |
| 201 | ret = PTR_ERR(tc); |
| 202 | |
| 203 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /** |
| 207 | * v9fs_t_wstat - write a file's meta-data |
| 208 | * @v9ses: 9P2000 session information |
| 209 | * @fid: fid pointing to file or directory to write info about |
| 210 | * @stat: metadata |
| 211 | * @fcall: pointer to response fcall |
| 212 | * |
| 213 | */ |
| 214 | |
| 215 | int |
| 216 | v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 217 | struct v9fs_wstat *wstat, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 218 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 219 | int ret; |
| 220 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 221 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 222 | dprintk(DEBUG_9P, "fid %d\n", fid); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 223 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 224 | ret = -ENOMEM; |
| 225 | tc = v9fs_create_twstat(fid, wstat, v9ses->extended); |
| 226 | if (!IS_ERR(tc)) { |
| 227 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 228 | kfree(tc); |
| 229 | } else |
| 230 | ret = PTR_ERR(tc); |
| 231 | |
| 232 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
| 236 | * v9fs_t_walk - walk a fid to a new file or directory |
| 237 | * @v9ses: 9P2000 session information |
| 238 | * @fid: fid to walk |
| 239 | * @newfid: new fid (for clone operations) |
| 240 | * @name: path to walk fid to |
| 241 | * @fcall: pointer to response fcall |
| 242 | * |
| 243 | */ |
| 244 | |
| 245 | /* TODO: support multiple walk */ |
| 246 | |
| 247 | int |
| 248 | v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 249 | char *name, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 250 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 251 | int ret; |
| 252 | struct v9fs_fcall *tc; |
| 253 | int nwname; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 254 | |
| 255 | dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 256 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 257 | if (name) |
| 258 | nwname = 1; |
| 259 | else |
| 260 | nwname = 0; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 261 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 262 | ret = -ENOMEM; |
| 263 | tc = v9fs_create_twalk(fid, newfid, nwname, &name); |
| 264 | if (!IS_ERR(tc)) { |
| 265 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 266 | kfree(tc); |
| 267 | } else |
| 268 | ret = PTR_ERR(tc); |
| 269 | |
| 270 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * v9fs_t_open - open a file |
| 275 | * |
| 276 | * @v9ses - 9P2000 session information |
| 277 | * @fid - fid to open |
| 278 | * @mode - mode to open file (R, RW, etc) |
| 279 | * @fcall - pointer to response fcall |
| 280 | * |
| 281 | */ |
| 282 | |
| 283 | int |
| 284 | v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 285 | struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 286 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 287 | int ret; |
| 288 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 289 | |
| 290 | dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 291 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 292 | ret = -ENOMEM; |
| 293 | tc = v9fs_create_topen(fid, mode); |
| 294 | if (!IS_ERR(tc)) { |
| 295 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 296 | kfree(tc); |
| 297 | } else |
| 298 | ret = PTR_ERR(tc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 299 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 300 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /** |
| 304 | * v9fs_t_remove - remove a file or directory |
| 305 | * @v9ses: 9P2000 session information |
| 306 | * @fid: fid to remove |
| 307 | * @fcall: pointer to response fcall |
| 308 | * |
| 309 | */ |
| 310 | |
| 311 | int |
| 312 | v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 313 | struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 314 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 315 | int ret; |
| 316 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 317 | |
| 318 | dprintk(DEBUG_9P, "fid %d\n", fid); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 319 | |
| 320 | ret = -ENOMEM; |
| 321 | tc = v9fs_create_tremove(fid); |
| 322 | if (!IS_ERR(tc)) { |
| 323 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 324 | kfree(tc); |
| 325 | } else |
| 326 | ret = PTR_ERR(tc); |
| 327 | |
| 328 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /** |
| 332 | * v9fs_t_create - create a file or directory |
| 333 | * @v9ses: 9P2000 session information |
| 334 | * @fid: fid to create |
| 335 | * @name: name of the file or directory to create |
| 336 | * @perm: permissions to create with |
| 337 | * @mode: mode to open file (R, RW, etc) |
| 338 | * @fcall: pointer to response fcall |
| 339 | * |
| 340 | */ |
| 341 | |
| 342 | int |
| 343 | v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 344 | u32 perm, u8 mode, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 345 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 346 | int ret; |
| 347 | struct v9fs_fcall *tc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 348 | |
| 349 | dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n", |
| 350 | fid, name, perm, mode); |
| 351 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 352 | ret = -ENOMEM; |
| 353 | tc = v9fs_create_tcreate(fid, name, perm, mode); |
| 354 | if (!IS_ERR(tc)) { |
| 355 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
| 356 | kfree(tc); |
| 357 | } else |
| 358 | ret = PTR_ERR(tc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 359 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 360 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
| 364 | * v9fs_t_read - read data |
| 365 | * @v9ses: 9P2000 session information |
| 366 | * @fid: fid to read from |
| 367 | * @offset: offset to start read at |
| 368 | * @count: how many bytes to read |
| 369 | * @fcall: pointer to response fcall (with data) |
| 370 | * |
| 371 | */ |
| 372 | |
| 373 | int |
| 374 | v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 375 | u32 count, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 376 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 377 | int ret; |
| 378 | struct v9fs_fcall *tc, *rc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 379 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 380 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, |
| 381 | (long long unsigned) offset, count); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 382 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 383 | ret = -ENOMEM; |
| 384 | tc = v9fs_create_tread(fid, offset, count); |
| 385 | if (!IS_ERR(tc)) { |
| 386 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); |
| 387 | if (!ret) |
| 388 | ret = rc->params.rread.count; |
| 389 | if (rcp) |
| 390 | *rcp = rc; |
| 391 | else |
| 392 | kfree(rc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 393 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 394 | kfree(tc); |
| 395 | } else |
| 396 | ret = PTR_ERR(tc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 397 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 398 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
| 402 | * v9fs_t_write - write data |
| 403 | * @v9ses: 9P2000 session information |
| 404 | * @fid: fid to write to |
| 405 | * @offset: offset to start write at |
| 406 | * @count: how many bytes to write |
| 407 | * @fcall: pointer to response fcall |
| 408 | * |
| 409 | */ |
| 410 | |
| 411 | int |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 412 | v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count, |
| 413 | const char __user *data, struct v9fs_fcall **rcp) |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 414 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 415 | int ret; |
| 416 | struct v9fs_fcall *tc, *rc; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 417 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 418 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, |
| 419 | (long long unsigned) offset, count); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 420 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 421 | ret = -ENOMEM; |
| 422 | tc = v9fs_create_twrite(fid, offset, count, data); |
| 423 | if (!IS_ERR(tc)) { |
| 424 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 425 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 426 | if (!ret) |
| 427 | ret = rc->params.rwrite.count; |
| 428 | if (rcp) |
| 429 | *rcp = rc; |
| 430 | else |
| 431 | kfree(rc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 432 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 433 | kfree(tc); |
| 434 | } else |
| 435 | ret = PTR_ERR(tc); |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 436 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 437 | return ret; |
Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame] | 438 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame^] | 439 | |