1 /* 2 * include/net/9p/9p.h 3 * 4 * 9P protocol definitions. 5 * 6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> 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 version 2 12 * as published by the Free Software Foundation. 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 #ifndef NET_9P_H 28 #define NET_9P_H 29 30 #ifdef CONFIG_NET_9P_DEBUG 31 32 #define P9_DEBUG_ERROR (1<<0) 33 #define P9_DEBUG_9P (1<<2) 34 #define P9_DEBUG_VFS (1<<3) 35 #define P9_DEBUG_CONV (1<<4) 36 #define P9_DEBUG_MUX (1<<5) 37 #define P9_DEBUG_TRANS (1<<6) 38 #define P9_DEBUG_SLABS (1<<7) 39 #define P9_DEBUG_FCALL (1<<8) 40 41 extern unsigned int p9_debug_level; 42 43 #define P9_DPRINTK(level, format, arg...) \ 44 do { \ 45 if ((p9_debug_level & level) == level) \ 46 printk(KERN_NOTICE "-- %s (%d): " \ 47 format , __FUNCTION__, task_pid_nr(current) , ## arg); \ 48 } while (0) 49 50 #define PRINT_FCALL_ERROR(s, fcall) P9_DPRINTK(P9_DEBUG_ERROR, \ 51 "%s: %.*s\n", s, fcall?fcall->params.rerror.error.len:0, \ 52 fcall?fcall->params.rerror.error.str:""); 53 54 #else 55 #define P9_DPRINTK(level, format, arg...) do { } while (0) 56 #define PRINT_FCALL_ERROR(s, fcall) do { } while (0) 57 #endif 58 59 #define P9_EPRINTK(level, format, arg...) \ 60 do { \ 61 printk(level "9p: %s (%d): " \ 62 format , __FUNCTION__, task_pid_nr(current), ## arg); \ 63 } while (0) 64 65 66 /* Message Types */ 67 enum { 68 P9_TVERSION = 100, 69 P9_RVERSION, 70 P9_TAUTH = 102, 71 P9_RAUTH, 72 P9_TATTACH = 104, 73 P9_RATTACH, 74 P9_TERROR = 106, 75 P9_RERROR, 76 P9_TFLUSH = 108, 77 P9_RFLUSH, 78 P9_TWALK = 110, 79 P9_RWALK, 80 P9_TOPEN = 112, 81 P9_ROPEN, 82 P9_TCREATE = 114, 83 P9_RCREATE, 84 P9_TREAD = 116, 85 P9_RREAD, 86 P9_TWRITE = 118, 87 P9_RWRITE, 88 P9_TCLUNK = 120, 89 P9_RCLUNK, 90 P9_TREMOVE = 122, 91 P9_RREMOVE, 92 P9_TSTAT = 124, 93 P9_RSTAT, 94 P9_TWSTAT = 126, 95 P9_RWSTAT, 96 }; 97 98 /* open modes */ 99 enum { 100 P9_OREAD = 0x00, 101 P9_OWRITE = 0x01, 102 P9_ORDWR = 0x02, 103 P9_OEXEC = 0x03, 104 P9_OEXCL = 0x04, 105 P9_OTRUNC = 0x10, 106 P9_OREXEC = 0x20, 107 P9_ORCLOSE = 0x40, 108 P9_OAPPEND = 0x80, 109 }; 110 111 /* permissions */ 112 enum { 113 P9_DMDIR = 0x80000000, 114 P9_DMAPPEND = 0x40000000, 115 P9_DMEXCL = 0x20000000, 116 P9_DMMOUNT = 0x10000000, 117 P9_DMAUTH = 0x08000000, 118 P9_DMTMP = 0x04000000, 119 P9_DMSYMLINK = 0x02000000, 120 P9_DMLINK = 0x01000000, 121 /* 9P2000.u extensions */ 122 P9_DMDEVICE = 0x00800000, 123 P9_DMNAMEDPIPE = 0x00200000, 124 P9_DMSOCKET = 0x00100000, 125 P9_DMSETUID = 0x00080000, 126 P9_DMSETGID = 0x00040000, 127 P9_DMSETVTX = 0x00010000, 128 }; 129 130 /* qid.types */ 131 enum { 132 P9_QTDIR = 0x80, 133 P9_QTAPPEND = 0x40, 134 P9_QTEXCL = 0x20, 135 P9_QTMOUNT = 0x10, 136 P9_QTAUTH = 0x08, 137 P9_QTTMP = 0x04, 138 P9_QTSYMLINK = 0x02, 139 P9_QTLINK = 0x01, 140 P9_QTFILE = 0x00, 141 }; 142 143 #define P9_NOTAG (u16)(~0) 144 #define P9_NOFID (u32)(~0) 145 #define P9_MAXWELEM 16 146 147 /* ample room for Twrite/Rread header */ 148 #define P9_IOHDRSZ 24 149 150 struct p9_str { 151 u16 len; 152 char *str; 153 }; 154 155 /* qids are the unique ID for a file (like an inode */ 156 struct p9_qid { 157 u8 type; 158 u32 version; 159 u64 path; 160 }; 161 162 /* Plan 9 file metadata (stat) structure */ 163 struct p9_stat { 164 u16 size; 165 u16 type; 166 u32 dev; 167 struct p9_qid qid; 168 u32 mode; 169 u32 atime; 170 u32 mtime; 171 u64 length; 172 struct p9_str name; 173 struct p9_str uid; 174 struct p9_str gid; 175 struct p9_str muid; 176 struct p9_str extension; /* 9p2000.u extensions */ 177 u32 n_uid; /* 9p2000.u extensions */ 178 u32 n_gid; /* 9p2000.u extensions */ 179 u32 n_muid; /* 9p2000.u extensions */ 180 }; 181 182 /* file metadata (stat) structure used to create Twstat message 183 The is similar to p9_stat, but the strings don't point to 184 the same memory block and should be freed separately 185 */ 186 struct p9_wstat { 187 u16 size; 188 u16 type; 189 u32 dev; 190 struct p9_qid qid; 191 u32 mode; 192 u32 atime; 193 u32 mtime; 194 u64 length; 195 char *name; 196 char *uid; 197 char *gid; 198 char *muid; 199 char *extension; /* 9p2000.u extensions */ 200 u32 n_uid; /* 9p2000.u extensions */ 201 u32 n_gid; /* 9p2000.u extensions */ 202 u32 n_muid; /* 9p2000.u extensions */ 203 }; 204 205 /* Structures for Protocol Operations */ 206 struct p9_tversion { 207 u32 msize; 208 struct p9_str version; 209 }; 210 211 struct p9_rversion { 212 u32 msize; 213 struct p9_str version; 214 }; 215 216 struct p9_tauth { 217 u32 afid; 218 struct p9_str uname; 219 struct p9_str aname; 220 u32 n_uname; /* 9P2000.u extensions */ 221 }; 222 223 struct p9_rauth { 224 struct p9_qid qid; 225 }; 226 227 struct p9_rerror { 228 struct p9_str error; 229 u32 errno; /* 9p2000.u extension */ 230 }; 231 232 struct p9_tflush { 233 u16 oldtag; 234 }; 235 236 struct p9_rflush { 237 }; 238 239 struct p9_tattach { 240 u32 fid; 241 u32 afid; 242 struct p9_str uname; 243 struct p9_str aname; 244 u32 n_uname; /* 9P2000.u extensions */ 245 }; 246 247 struct p9_rattach { 248 struct p9_qid qid; 249 }; 250 251 struct p9_twalk { 252 u32 fid; 253 u32 newfid; 254 u16 nwname; 255 struct p9_str wnames[16]; 256 }; 257 258 struct p9_rwalk { 259 u16 nwqid; 260 struct p9_qid wqids[16]; 261 }; 262 263 struct p9_topen { 264 u32 fid; 265 u8 mode; 266 }; 267 268 struct p9_ropen { 269 struct p9_qid qid; 270 u32 iounit; 271 }; 272 273 struct p9_tcreate { 274 u32 fid; 275 struct p9_str name; 276 u32 perm; 277 u8 mode; 278 struct p9_str extension; 279 }; 280 281 struct p9_rcreate { 282 struct p9_qid qid; 283 u32 iounit; 284 }; 285 286 struct p9_tread { 287 u32 fid; 288 u64 offset; 289 u32 count; 290 }; 291 292 struct p9_rread { 293 u32 count; 294 u8 *data; 295 }; 296 297 struct p9_twrite { 298 u32 fid; 299 u64 offset; 300 u32 count; 301 u8 *data; 302 }; 303 304 struct p9_rwrite { 305 u32 count; 306 }; 307 308 struct p9_tclunk { 309 u32 fid; 310 }; 311 312 struct p9_rclunk { 313 }; 314 315 struct p9_tremove { 316 u32 fid; 317 }; 318 319 struct p9_rremove { 320 }; 321 322 struct p9_tstat { 323 u32 fid; 324 }; 325 326 struct p9_rstat { 327 struct p9_stat stat; 328 }; 329 330 struct p9_twstat { 331 u32 fid; 332 struct p9_stat stat; 333 }; 334 335 struct p9_rwstat { 336 }; 337 338 /* 339 * fcall is the primary packet structure 340 * 341 */ 342 343 struct p9_fcall { 344 u32 size; 345 u8 id; 346 u16 tag; 347 void *sdata; 348 349 union { 350 struct p9_tversion tversion; 351 struct p9_rversion rversion; 352 struct p9_tauth tauth; 353 struct p9_rauth rauth; 354 struct p9_rerror rerror; 355 struct p9_tflush tflush; 356 struct p9_rflush rflush; 357 struct p9_tattach tattach; 358 struct p9_rattach rattach; 359 struct p9_twalk twalk; 360 struct p9_rwalk rwalk; 361 struct p9_topen topen; 362 struct p9_ropen ropen; 363 struct p9_tcreate tcreate; 364 struct p9_rcreate rcreate; 365 struct p9_tread tread; 366 struct p9_rread rread; 367 struct p9_twrite twrite; 368 struct p9_rwrite rwrite; 369 struct p9_tclunk tclunk; 370 struct p9_rclunk rclunk; 371 struct p9_tremove tremove; 372 struct p9_rremove rremove; 373 struct p9_tstat tstat; 374 struct p9_rstat rstat; 375 struct p9_twstat twstat; 376 struct p9_rwstat rwstat; 377 } params; 378 }; 379 380 struct p9_idpool; 381 382 int p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat, 383 int dotu); 384 int p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *fc, int dotu); 385 void p9_set_tag(struct p9_fcall *fc, u16 tag); 386 struct p9_fcall *p9_create_tversion(u32 msize, char *version); 387 struct p9_fcall *p9_create_tattach(u32 fid, u32 afid, char *uname, 388 char *aname, u32 n_uname, int dotu); 389 struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname, 390 u32 n_uname, int dotu); 391 struct p9_fcall *p9_create_tflush(u16 oldtag); 392 struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname, 393 char **wnames); 394 struct p9_fcall *p9_create_topen(u32 fid, u8 mode); 395 struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode, 396 char *extension, int dotu); 397 struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count); 398 struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count, 399 const char *data); 400 struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count, 401 const char __user *data); 402 struct p9_fcall *p9_create_tclunk(u32 fid); 403 struct p9_fcall *p9_create_tremove(u32 fid); 404 struct p9_fcall *p9_create_tstat(u32 fid); 405 struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat, 406 int dotu); 407 408 int p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int dotu); 409 int p9_errstr2errno(char *errstr, int len); 410 411 struct p9_idpool *p9_idpool_create(void); 412 void p9_idpool_destroy(struct p9_idpool *); 413 int p9_idpool_get(struct p9_idpool *p); 414 void p9_idpool_put(int id, struct p9_idpool *p); 415 int p9_idpool_check(int id, struct p9_idpool *p); 416 417 int p9_error_init(void); 418 int p9_errstr2errno(char *, int); 419 #endif /* NET_9P_H */ 420