Eric Van Hensbergen | b8cf945 | 2005-09-09 13:04:21 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * linux/fs/9p/9p.h |
| 3 | * |
| 4 | * 9P protocol definitions. |
| 5 | * |
| 6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
| 7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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 |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /* Message Types */ |
| 28 | enum { |
| 29 | TVERSION = 100, |
| 30 | RVERSION, |
| 31 | TAUTH = 102, |
| 32 | RAUTH, |
| 33 | TATTACH = 104, |
| 34 | RATTACH, |
| 35 | TERROR = 106, |
| 36 | RERROR, |
| 37 | TFLUSH = 108, |
| 38 | RFLUSH, |
| 39 | TWALK = 110, |
| 40 | RWALK, |
| 41 | TOPEN = 112, |
| 42 | ROPEN, |
| 43 | TCREATE = 114, |
| 44 | RCREATE, |
| 45 | TREAD = 116, |
| 46 | RREAD, |
| 47 | TWRITE = 118, |
| 48 | RWRITE, |
| 49 | TCLUNK = 120, |
| 50 | RCLUNK, |
| 51 | TREMOVE = 122, |
| 52 | RREMOVE, |
| 53 | TSTAT = 124, |
| 54 | RSTAT, |
| 55 | TWSTAT = 126, |
| 56 | RWSTAT, |
| 57 | }; |
| 58 | |
| 59 | /* modes */ |
| 60 | enum { |
| 61 | V9FS_OREAD = 0x00, |
| 62 | V9FS_OWRITE = 0x01, |
| 63 | V9FS_ORDWR = 0x02, |
| 64 | V9FS_OEXEC = 0x03, |
| 65 | V9FS_OEXCL = 0x04, |
| 66 | V9FS_OTRUNC = 0x10, |
| 67 | V9FS_OREXEC = 0x20, |
| 68 | V9FS_ORCLOSE = 0x40, |
| 69 | V9FS_OAPPEND = 0x80, |
| 70 | }; |
| 71 | |
| 72 | /* permissions */ |
| 73 | enum { |
| 74 | V9FS_DMDIR = 0x80000000, |
| 75 | V9FS_DMAPPEND = 0x40000000, |
| 76 | V9FS_DMEXCL = 0x20000000, |
| 77 | V9FS_DMMOUNT = 0x10000000, |
| 78 | V9FS_DMAUTH = 0x08000000, |
| 79 | V9FS_DMTMP = 0x04000000, |
| 80 | V9FS_DMSYMLINK = 0x02000000, |
| 81 | V9FS_DMLINK = 0x01000000, |
| 82 | /* 9P2000.u extensions */ |
| 83 | V9FS_DMDEVICE = 0x00800000, |
| 84 | V9FS_DMNAMEDPIPE = 0x00200000, |
| 85 | V9FS_DMSOCKET = 0x00100000, |
| 86 | V9FS_DMSETUID = 0x00080000, |
| 87 | V9FS_DMSETGID = 0x00040000, |
| 88 | }; |
| 89 | |
| 90 | /* qid.types */ |
| 91 | enum { |
| 92 | V9FS_QTDIR = 0x80, |
| 93 | V9FS_QTAPPEND = 0x40, |
| 94 | V9FS_QTEXCL = 0x20, |
| 95 | V9FS_QTMOUNT = 0x10, |
| 96 | V9FS_QTAUTH = 0x08, |
| 97 | V9FS_QTTMP = 0x04, |
| 98 | V9FS_QTSYMLINK = 0x02, |
| 99 | V9FS_QTLINK = 0x01, |
| 100 | V9FS_QTFILE = 0x00, |
| 101 | }; |
| 102 | |
| 103 | /* ample room for Twrite/Rread header (iounit) */ |
| 104 | #define V9FS_IOHDRSZ 24 |
| 105 | |
| 106 | /* qids are the unique ID for a file (like an inode */ |
| 107 | struct v9fs_qid { |
| 108 | u8 type; |
| 109 | u32 version; |
| 110 | u64 path; |
| 111 | }; |
| 112 | |
| 113 | /* Plan 9 file metadata (stat) structure */ |
| 114 | struct v9fs_stat { |
| 115 | u16 size; |
| 116 | u16 type; |
| 117 | u32 dev; |
| 118 | struct v9fs_qid qid; |
| 119 | u32 mode; |
| 120 | u32 atime; |
| 121 | u32 mtime; |
| 122 | u64 length; |
| 123 | char *name; |
| 124 | char *uid; |
| 125 | char *gid; |
| 126 | char *muid; |
| 127 | char *extension; /* 9p2000.u extensions */ |
| 128 | u32 n_uid; /* 9p2000.u extensions */ |
| 129 | u32 n_gid; /* 9p2000.u extensions */ |
| 130 | u32 n_muid; /* 9p2000.u extensions */ |
| 131 | char data[0]; |
| 132 | }; |
| 133 | |
| 134 | /* Structures for Protocol Operations */ |
| 135 | |
| 136 | struct Tversion { |
| 137 | u32 msize; |
| 138 | char *version; |
| 139 | }; |
| 140 | |
| 141 | struct Rversion { |
| 142 | u32 msize; |
| 143 | char *version; |
| 144 | }; |
| 145 | |
| 146 | struct Tauth { |
| 147 | u32 afid; |
| 148 | char *uname; |
| 149 | char *aname; |
| 150 | }; |
| 151 | |
| 152 | struct Rauth { |
| 153 | struct v9fs_qid qid; |
| 154 | }; |
| 155 | |
| 156 | struct Rerror { |
| 157 | char *error; |
| 158 | u32 errno; /* 9p2000.u extension */ |
| 159 | }; |
| 160 | |
| 161 | struct Tflush { |
| 162 | u32 oldtag; |
| 163 | }; |
| 164 | |
| 165 | struct Rflush { |
| 166 | }; |
| 167 | |
| 168 | struct Tattach { |
| 169 | u32 fid; |
| 170 | u32 afid; |
| 171 | char *uname; |
| 172 | char *aname; |
| 173 | }; |
| 174 | |
| 175 | struct Rattach { |
| 176 | struct v9fs_qid qid; |
| 177 | }; |
| 178 | |
| 179 | struct Twalk { |
| 180 | u32 fid; |
| 181 | u32 newfid; |
| 182 | u32 nwname; |
| 183 | char **wnames; |
| 184 | }; |
| 185 | |
| 186 | struct Rwalk { |
| 187 | u32 nwqid; |
| 188 | struct v9fs_qid *wqids; |
| 189 | }; |
| 190 | |
| 191 | struct Topen { |
| 192 | u32 fid; |
| 193 | u8 mode; |
| 194 | }; |
| 195 | |
| 196 | struct Ropen { |
| 197 | struct v9fs_qid qid; |
| 198 | u32 iounit; |
| 199 | }; |
| 200 | |
| 201 | struct Tcreate { |
| 202 | u32 fid; |
| 203 | char *name; |
| 204 | u32 perm; |
| 205 | u8 mode; |
| 206 | }; |
| 207 | |
| 208 | struct Rcreate { |
| 209 | struct v9fs_qid qid; |
| 210 | u32 iounit; |
| 211 | }; |
| 212 | |
| 213 | struct Tread { |
| 214 | u32 fid; |
| 215 | u64 offset; |
| 216 | u32 count; |
| 217 | }; |
| 218 | |
| 219 | struct Rread { |
| 220 | u32 count; |
| 221 | u8 *data; |
| 222 | }; |
| 223 | |
| 224 | struct Twrite { |
| 225 | u32 fid; |
| 226 | u64 offset; |
| 227 | u32 count; |
| 228 | u8 *data; |
| 229 | }; |
| 230 | |
| 231 | struct Rwrite { |
| 232 | u32 count; |
| 233 | }; |
| 234 | |
| 235 | struct Tclunk { |
| 236 | u32 fid; |
| 237 | }; |
| 238 | |
| 239 | struct Rclunk { |
| 240 | }; |
| 241 | |
| 242 | struct Tremove { |
| 243 | u32 fid; |
| 244 | }; |
| 245 | |
| 246 | struct Rremove { |
| 247 | }; |
| 248 | |
| 249 | struct Tstat { |
| 250 | u32 fid; |
| 251 | }; |
| 252 | |
| 253 | struct Rstat { |
| 254 | struct v9fs_stat *stat; |
| 255 | }; |
| 256 | |
| 257 | struct Twstat { |
| 258 | u32 fid; |
| 259 | struct v9fs_stat *stat; |
| 260 | }; |
| 261 | |
| 262 | struct Rwstat { |
| 263 | }; |
| 264 | |
| 265 | /* |
| 266 | * fcall is the primary packet structure |
| 267 | * |
| 268 | */ |
| 269 | |
| 270 | struct v9fs_fcall { |
| 271 | u32 size; |
| 272 | u8 id; |
| 273 | u16 tag; |
| 274 | |
| 275 | union { |
| 276 | struct Tversion tversion; |
| 277 | struct Rversion rversion; |
| 278 | struct Tauth tauth; |
| 279 | struct Rauth rauth; |
| 280 | struct Rerror rerror; |
| 281 | struct Tflush tflush; |
| 282 | struct Rflush rflush; |
| 283 | struct Tattach tattach; |
| 284 | struct Rattach rattach; |
| 285 | struct Twalk twalk; |
| 286 | struct Rwalk rwalk; |
| 287 | struct Topen topen; |
| 288 | struct Ropen ropen; |
| 289 | struct Tcreate tcreate; |
| 290 | struct Rcreate rcreate; |
| 291 | struct Tread tread; |
| 292 | struct Rread rread; |
| 293 | struct Twrite twrite; |
| 294 | struct Rwrite rwrite; |
| 295 | struct Tclunk tclunk; |
| 296 | struct Rclunk rclunk; |
| 297 | struct Tremove tremove; |
| 298 | struct Rremove rremove; |
| 299 | struct Tstat tstat; |
| 300 | struct Rstat rstat; |
| 301 | struct Twstat twstat; |
| 302 | struct Rwstat rwstat; |
| 303 | } params; |
| 304 | }; |
| 305 | |
| 306 | #define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "") |
| 307 | |
| 308 | int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, |
| 309 | char *version, struct v9fs_fcall **rcall); |
| 310 | |
| 311 | int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, |
| 312 | u32 fid, u32 afid, struct v9fs_fcall **rcall); |
| 313 | |
| 314 | int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, |
| 315 | struct v9fs_fcall **rcall); |
| 316 | |
| 317 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag); |
| 318 | |
| 319 | int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, |
| 320 | struct v9fs_fcall **rcall); |
| 321 | |
| 322 | int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, |
| 323 | struct v9fs_stat *stat, struct v9fs_fcall **rcall); |
| 324 | |
| 325 | int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, |
| 326 | char *name, struct v9fs_fcall **rcall); |
| 327 | |
| 328 | int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, |
| 329 | struct v9fs_fcall **rcall); |
| 330 | |
| 331 | int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, |
| 332 | struct v9fs_fcall **rcall); |
| 333 | |
| 334 | int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, |
| 335 | u32 perm, u8 mode, struct v9fs_fcall **rcall); |
| 336 | |
| 337 | int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, |
| 338 | u64 offset, u32 count, struct v9fs_fcall **rcall); |
| 339 | |
| 340 | int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, |
| 341 | u32 count, void *data, struct v9fs_fcall **rcall); |