9p.h 6.8 KB
Newer Older
1 2 3 4 5
/*
 * linux/fs/9p/9p.h
 *
 * 9P protocol definitions.
 *
6
 *  Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 8 9 10
 *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
 *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
 *
 *  This program is free software; you can redistribute it and/or modify
11 12
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to:
 *  Free Software Foundation
 *  51 Franklin Street, Fifth Floor
 *  Boston, MA  02111-1301  USA
 *
 */

/* Message Types */
enum {
	TVERSION = 100,
	RVERSION,
	TAUTH = 102,
	RAUTH,
	TATTACH = 104,
	RATTACH,
	TERROR = 106,
	RERROR,
	TFLUSH = 108,
	RFLUSH,
	TWALK = 110,
	RWALK,
	TOPEN = 112,
	ROPEN,
	TCREATE = 114,
	RCREATE,
	TREAD = 116,
	RREAD,
	TWRITE = 118,
	RWRITE,
	TCLUNK = 120,
	RCLUNK,
	TREMOVE = 122,
	RREMOVE,
	TSTAT = 124,
	RSTAT,
	TWSTAT = 126,
	RWSTAT,
};

/* modes */
enum {
	V9FS_OREAD = 0x00,
	V9FS_OWRITE = 0x01,
	V9FS_ORDWR = 0x02,
	V9FS_OEXEC = 0x03,
	V9FS_OEXCL = 0x04,
	V9FS_OTRUNC = 0x10,
	V9FS_OREXEC = 0x20,
	V9FS_ORCLOSE = 0x40,
	V9FS_OAPPEND = 0x80,
};

/* permissions */
enum {
	V9FS_DMDIR = 0x80000000,
	V9FS_DMAPPEND = 0x40000000,
	V9FS_DMEXCL = 0x20000000,
	V9FS_DMMOUNT = 0x10000000,
	V9FS_DMAUTH = 0x08000000,
	V9FS_DMTMP = 0x04000000,
	V9FS_DMSYMLINK = 0x02000000,
	V9FS_DMLINK = 0x01000000,
	/* 9P2000.u extensions */
	V9FS_DMDEVICE = 0x00800000,
	V9FS_DMNAMEDPIPE = 0x00200000,
	V9FS_DMSOCKET = 0x00100000,
	V9FS_DMSETUID = 0x00080000,
	V9FS_DMSETGID = 0x00040000,
};

/* qid.types */
enum {
	V9FS_QTDIR = 0x80,
	V9FS_QTAPPEND = 0x40,
	V9FS_QTEXCL = 0x20,
	V9FS_QTMOUNT = 0x10,
	V9FS_QTAUTH = 0x08,
	V9FS_QTTMP = 0x04,
	V9FS_QTSYMLINK = 0x02,
	V9FS_QTLINK = 0x01,
	V9FS_QTFILE = 0x00,
};

103 104
#define V9FS_NOTAG	(u16)(~0)
#define V9FS_NOFID	(u32)(~0)
105
#define V9FS_MAXWELEM	16
106

107 108 109
/* ample room for Twrite/Rread header (iounit) */
#define V9FS_IOHDRSZ	24

110 111 112 113 114
struct v9fs_str {
	u16 len;
	char *str;
};

115 116 117 118 119 120 121 122 123
/* qids are the unique ID for a file (like an inode */
struct v9fs_qid {
	u8 type;
	u32 version;
	u64 path;
};

/* Plan 9 file metadata (stat) structure */
struct v9fs_stat {
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
	u16 size;
	u16 type;
	u32 dev;
	struct v9fs_qid qid;
	u32 mode;
	u32 atime;
	u32 mtime;
	u64 length;
	struct v9fs_str name;
	struct v9fs_str uid;
	struct v9fs_str gid;
	struct v9fs_str muid;
	struct v9fs_str extension;	/* 9p2000.u extensions */
	u32 n_uid;		/* 9p2000.u extensions */
	u32 n_gid;		/* 9p2000.u extensions */
	u32 n_muid;		/* 9p2000.u extensions */
};

/* file metadata (stat) structure used to create Twstat message
   The is similar to v9fs_stat, but the strings don't point to
   the same memory block and should be freed separately
*/
struct v9fs_wstat {
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
	u16 size;
	u16 type;
	u32 dev;
	struct v9fs_qid qid;
	u32 mode;
	u32 atime;
	u32 mtime;
	u64 length;
	char *name;
	char *uid;
	char *gid;
	char *muid;
	char *extension;	/* 9p2000.u extensions */
	u32 n_uid;		/* 9p2000.u extensions */
	u32 n_gid;		/* 9p2000.u extensions */
	u32 n_muid;		/* 9p2000.u extensions */
};

/* Structures for Protocol Operations */

struct Tversion {
	u32 msize;
169
	struct v9fs_str version;
170 171 172 173
};

struct Rversion {
	u32 msize;
174
	struct v9fs_str version;
175 176 177 178
};

struct Tauth {
	u32 afid;
179 180
	struct v9fs_str uname;
	struct v9fs_str aname;
181 182 183 184 185 186 187
};

struct Rauth {
	struct v9fs_qid qid;
};

struct Rerror {
188
	struct v9fs_str error;
189 190 191 192
	u32 errno;		/* 9p2000.u extension */
};

struct Tflush {
193
	u16 oldtag;
194 195 196 197 198 199 200 201
};

struct Rflush {
};

struct Tattach {
	u32 fid;
	u32 afid;
202 203
	struct v9fs_str uname;
	struct v9fs_str aname;
204 205 206 207 208 209 210 211 212
};

struct Rattach {
	struct v9fs_qid qid;
};

struct Twalk {
	u32 fid;
	u32 newfid;
213 214
	u16 nwname;
	struct v9fs_str wnames[16];
215 216 217
};

struct Rwalk {
218 219
	u16 nwqid;
	struct v9fs_qid wqids[16];
220 221 222 223 224 225 226 227 228 229 230 231 232 233
};

struct Topen {
	u32 fid;
	u8 mode;
};

struct Ropen {
	struct v9fs_qid qid;
	u32 iounit;
};

struct Tcreate {
	u32 fid;
234
	struct v9fs_str name;
235 236
	u32 perm;
	u8 mode;
237
	struct v9fs_str extension;
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
};

struct Rcreate {
	struct v9fs_qid qid;
	u32 iounit;
};

struct Tread {
	u32 fid;
	u64 offset;
	u32 count;
};

struct Rread {
	u32 count;
	u8 *data;
};

struct Twrite {
	u32 fid;
	u64 offset;
	u32 count;
	u8 *data;
};

struct Rwrite {
	u32 count;
};

struct Tclunk {
	u32 fid;
};

struct Rclunk {
};

struct Tremove {
	u32 fid;
};

struct Rremove {
};

struct Tstat {
	u32 fid;
};

struct Rstat {
286
	struct v9fs_stat stat;
287 288 289 290
};

struct Twstat {
	u32 fid;
291
	struct v9fs_stat stat;
292 293 294 295 296 297 298 299 300 301 302 303 304 305
};

struct Rwstat {
};

/*
  * fcall is the primary packet structure
  *
  */

struct v9fs_fcall {
	u32 size;
	u8 id;
	u16 tag;
306
	void *sdata;
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

	union {
		struct Tversion tversion;
		struct Rversion rversion;
		struct Tauth tauth;
		struct Rauth rauth;
		struct Rerror rerror;
		struct Tflush tflush;
		struct Rflush rflush;
		struct Tattach tattach;
		struct Rattach rattach;
		struct Twalk twalk;
		struct Rwalk rwalk;
		struct Topen topen;
		struct Ropen ropen;
		struct Tcreate tcreate;
		struct Rcreate rcreate;
		struct Tread tread;
		struct Rread rread;
		struct Twrite twrite;
		struct Rwrite rwrite;
		struct Tclunk tclunk;
		struct Rclunk rclunk;
		struct Tremove tremove;
		struct Rremove rremove;
		struct Tstat tstat;
		struct Rstat rstat;
		struct Twstat twstat;
		struct Rwstat rwstat;
	} params;
};

339 340 341
#define PRINT_FCALL_ERROR(s, fcall) dprintk(DEBUG_ERROR, "%s: %.*s\n", s, \
	fcall?fcall->params.rerror.error.len:0, \
	fcall?fcall->params.rerror.error.str:"");
342

343 344 345 346 347 348
int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
		   char *version, struct v9fs_fcall **rcall);

int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
		  u32 fid, u32 afid, struct v9fs_fcall **rcall);

349
int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
350 351 352 353 354

int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
		struct v9fs_fcall **rcall);

int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
355
		 struct v9fs_wstat *wstat, struct v9fs_fcall **rcall);
356 357 358 359 360 361 362 363 364 365 366

int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
		char *name, struct v9fs_fcall **rcall);

int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
		struct v9fs_fcall **rcall);

int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
		  struct v9fs_fcall **rcall);

int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
367
	u32 perm, u8 mode, char *extension, struct v9fs_fcall **rcall);
368 369 370 371 372

int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
		u64 offset, u32 count, struct v9fs_fcall **rcall);

int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
373 374
		 u32 count, const char __user * data,
		 struct v9fs_fcall **rcall);
375
int v9fs_printfcall(char *, int, struct v9fs_fcall *, int);