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