/*1* include/net/9p/9p.h2*3* 9P protocol definitions.4*5* Copyright (C) 2005 by Latchesar Ionkov <[email protected]>6* Copyright (C) 2004 by Eric Van Hensbergen <[email protected]>7* Copyright (C) 2002 by Ron Minnich <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License version 211* as published by the Free Software Foundation.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to:20* Free Software Foundation21* 51 Franklin Street, Fifth Floor22* Boston, MA 02111-1301 USA23*24*/2526#ifndef NET_9P_H27#define NET_9P_H2829/**30* enum p9_debug_flags - bits for mount time debug parameter31* @P9_DEBUG_ERROR: more verbose error messages including original error string32* @P9_DEBUG_9P: 9P protocol tracing33* @P9_DEBUG_VFS: VFS API tracing34* @P9_DEBUG_CONV: protocol conversion tracing35* @P9_DEBUG_MUX: trace management of concurrent transactions36* @P9_DEBUG_TRANS: transport tracing37* @P9_DEBUG_SLABS: memory management tracing38* @P9_DEBUG_FCALL: verbose dump of protocol messages39* @P9_DEBUG_FID: fid allocation/deallocation tracking40* @P9_DEBUG_PKT: packet marshalling/unmarshalling41* @P9_DEBUG_FSC: FS-cache tracing42*43* These flags are passed at mount time to turn on various levels of44* verbosity and tracing which will be output to the system logs.45*/4647enum p9_debug_flags {48P9_DEBUG_ERROR = (1<<0),49P9_DEBUG_9P = (1<<2),50P9_DEBUG_VFS = (1<<3),51P9_DEBUG_CONV = (1<<4),52P9_DEBUG_MUX = (1<<5),53P9_DEBUG_TRANS = (1<<6),54P9_DEBUG_SLABS = (1<<7),55P9_DEBUG_FCALL = (1<<8),56P9_DEBUG_FID = (1<<9),57P9_DEBUG_PKT = (1<<10),58P9_DEBUG_FSC = (1<<11),59};6061#ifdef CONFIG_NET_9P_DEBUG62extern unsigned int p9_debug_level;6364#define P9_DPRINTK(level, format, arg...) \65do { \66if ((p9_debug_level & level) == level) {\67if (level == P9_DEBUG_9P) \68printk(KERN_NOTICE "(%8.8d) " \69format , task_pid_nr(current) , ## arg); \70else \71printk(KERN_NOTICE "-- %s (%d): " \72format , __func__, task_pid_nr(current) , ## arg); \73} \74} while (0)7576#else77#define P9_DPRINTK(level, format, arg...) do { } while (0)78#endif7980#define P9_EPRINTK(level, format, arg...) \81do { \82printk(level "9p: %s (%d): " \83format , __func__, task_pid_nr(current), ## arg); \84} while (0)8586/**87* enum p9_msg_t - 9P message types88* @P9_TLERROR: not used89* @P9_RLERROR: response for any failed request for 9P2000.L90* @P9_TSTATFS: file system status request91* @P9_RSTATFS: file system status response92* @P9_TSYMLINK: make symlink request93* @P9_RSYMLINK: make symlink response94* @P9_TMKNOD: create a special file object request95* @P9_RMKNOD: create a special file object response96* @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L97* @P9_RLCREATE: response with file access information for 9P2000.L98* @P9_TRENAME: rename request99* @P9_RRENAME: rename response100* @P9_TMKDIR: create a directory request101* @P9_RMKDIR: create a directory response102* @P9_TVERSION: version handshake request103* @P9_RVERSION: version handshake response104* @P9_TAUTH: request to establish authentication channel105* @P9_RAUTH: response with authentication information106* @P9_TATTACH: establish user access to file service107* @P9_RATTACH: response with top level handle to file hierarchy108* @P9_TERROR: not used109* @P9_RERROR: response for any failed request110* @P9_TFLUSH: request to abort a previous request111* @P9_RFLUSH: response when previous request has been cancelled112* @P9_TWALK: descend a directory hierarchy113* @P9_RWALK: response with new handle for position within hierarchy114* @P9_TOPEN: prepare a handle for I/O on an existing file115* @P9_ROPEN: response with file access information116* @P9_TCREATE: prepare a handle for I/O on a new file117* @P9_RCREATE: response with file access information118* @P9_TREAD: request to transfer data from a file or directory119* @P9_RREAD: response with data requested120* @P9_TWRITE: reuqest to transfer data to a file121* @P9_RWRITE: response with out much data was transferred to file122* @P9_TCLUNK: forget about a handle to an entity within the file system123* @P9_RCLUNK: response when server has forgotten about the handle124* @P9_TREMOVE: request to remove an entity from the hierarchy125* @P9_RREMOVE: response when server has removed the entity126* @P9_TSTAT: request file entity attributes127* @P9_RSTAT: response with file entity attributes128* @P9_TWSTAT: request to update file entity attributes129* @P9_RWSTAT: response when file entity attributes are updated130*131* There are 14 basic operations in 9P2000, paired as132* requests and responses. The one special case is ERROR133* as there is no @P9_TERROR request for clients to transmit to134* the server, but the server may respond to any other request135* with an @P9_RERROR.136*137* See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html138*/139140enum p9_msg_t {141P9_TLERROR = 6,142P9_RLERROR,143P9_TSTATFS = 8,144P9_RSTATFS,145P9_TLOPEN = 12,146P9_RLOPEN,147P9_TLCREATE = 14,148P9_RLCREATE,149P9_TSYMLINK = 16,150P9_RSYMLINK,151P9_TMKNOD = 18,152P9_RMKNOD,153P9_TRENAME = 20,154P9_RRENAME,155P9_TREADLINK = 22,156P9_RREADLINK,157P9_TGETATTR = 24,158P9_RGETATTR,159P9_TSETATTR = 26,160P9_RSETATTR,161P9_TXATTRWALK = 30,162P9_RXATTRWALK,163P9_TXATTRCREATE = 32,164P9_RXATTRCREATE,165P9_TREADDIR = 40,166P9_RREADDIR,167P9_TFSYNC = 50,168P9_RFSYNC,169P9_TLOCK = 52,170P9_RLOCK,171P9_TGETLOCK = 54,172P9_RGETLOCK,173P9_TLINK = 70,174P9_RLINK,175P9_TMKDIR = 72,176P9_RMKDIR,177P9_TVERSION = 100,178P9_RVERSION,179P9_TAUTH = 102,180P9_RAUTH,181P9_TATTACH = 104,182P9_RATTACH,183P9_TERROR = 106,184P9_RERROR,185P9_TFLUSH = 108,186P9_RFLUSH,187P9_TWALK = 110,188P9_RWALK,189P9_TOPEN = 112,190P9_ROPEN,191P9_TCREATE = 114,192P9_RCREATE,193P9_TREAD = 116,194P9_RREAD,195P9_TWRITE = 118,196P9_RWRITE,197P9_TCLUNK = 120,198P9_RCLUNK,199P9_TREMOVE = 122,200P9_RREMOVE,201P9_TSTAT = 124,202P9_RSTAT,203P9_TWSTAT = 126,204P9_RWSTAT,205};206207/**208* enum p9_open_mode_t - 9P open modes209* @P9_OREAD: open file for reading only210* @P9_OWRITE: open file for writing only211* @P9_ORDWR: open file for reading or writing212* @P9_OEXEC: open file for execution213* @P9_OTRUNC: truncate file to zero-length before opening it214* @P9_OREXEC: close the file when an exec(2) system call is made215* @P9_ORCLOSE: remove the file when the file is closed216* @P9_OAPPEND: open the file and seek to the end217* @P9_OEXCL: only create a file, do not open it218*219* 9P open modes differ slightly from Posix standard modes.220* In particular, there are extra modes which specify different221* semantic behaviors than may be available on standard Posix222* systems. For example, @P9_OREXEC and @P9_ORCLOSE are modes that223* most likely will not be issued from the Linux VFS client, but may224* be supported by servers.225*226* See Also: http://plan9.bell-labs.com/magic/man2html/2/open227*/228229enum p9_open_mode_t {230P9_OREAD = 0x00,231P9_OWRITE = 0x01,232P9_ORDWR = 0x02,233P9_OEXEC = 0x03,234P9_OTRUNC = 0x10,235P9_OREXEC = 0x20,236P9_ORCLOSE = 0x40,237P9_OAPPEND = 0x80,238P9_OEXCL = 0x1000,239};240241/**242* enum p9_perm_t - 9P permissions243* @P9_DMDIR: mode bit for directories244* @P9_DMAPPEND: mode bit for is append-only245* @P9_DMEXCL: mode bit for excluse use (only one open handle allowed)246* @P9_DMMOUNT: mode bit for mount points247* @P9_DMAUTH: mode bit for authentication file248* @P9_DMTMP: mode bit for non-backed-up files249* @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u)250* @P9_DMLINK: mode bit for hard-link (9P2000.u)251* @P9_DMDEVICE: mode bit for device files (9P2000.u)252* @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u)253* @P9_DMSOCKET: mode bit for socket (9P2000.u)254* @P9_DMSETUID: mode bit for setuid (9P2000.u)255* @P9_DMSETGID: mode bit for setgid (9P2000.u)256* @P9_DMSETVTX: mode bit for sticky bit (9P2000.u)257*258* 9P permissions differ slightly from Posix standard modes.259*260* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat261*/262enum p9_perm_t {263P9_DMDIR = 0x80000000,264P9_DMAPPEND = 0x40000000,265P9_DMEXCL = 0x20000000,266P9_DMMOUNT = 0x10000000,267P9_DMAUTH = 0x08000000,268P9_DMTMP = 0x04000000,269/* 9P2000.u extensions */270P9_DMSYMLINK = 0x02000000,271P9_DMLINK = 0x01000000,272P9_DMDEVICE = 0x00800000,273P9_DMNAMEDPIPE = 0x00200000,274P9_DMSOCKET = 0x00100000,275P9_DMSETUID = 0x00080000,276P9_DMSETGID = 0x00040000,277P9_DMSETVTX = 0x00010000,278};279280/**281* enum p9_qid_t - QID types282* @P9_QTDIR: directory283* @P9_QTAPPEND: append-only284* @P9_QTEXCL: excluse use (only one open handle allowed)285* @P9_QTMOUNT: mount points286* @P9_QTAUTH: authentication file287* @P9_QTTMP: non-backed-up files288* @P9_QTSYMLINK: symbolic links (9P2000.u)289* @P9_QTLINK: hard-link (9P2000.u)290* @P9_QTFILE: normal files291*292* QID types are a subset of permissions - they are primarily293* used to differentiate semantics for a file system entity via294* a jump-table. Their value is also the most significant 16 bits295* of the permission_t296*297* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat298*/299enum p9_qid_t {300P9_QTDIR = 0x80,301P9_QTAPPEND = 0x40,302P9_QTEXCL = 0x20,303P9_QTMOUNT = 0x10,304P9_QTAUTH = 0x08,305P9_QTTMP = 0x04,306P9_QTSYMLINK = 0x02,307P9_QTLINK = 0x01,308P9_QTFILE = 0x00,309};310311/* 9P Magic Numbers */312#define P9_NOTAG (u16)(~0)313#define P9_NOFID (u32)(~0)314#define P9_MAXWELEM 16315316/* ample room for Twrite/Rread header */317#define P9_IOHDRSZ 24318319/* Room for readdir header */320#define P9_READDIRHDRSZ 24321322/**323* struct p9_str - length prefixed string type324* @len: length of the string325* @str: the string326*327* The protocol uses length prefixed strings for all328* string data, so we replicate that for our internal329* string members.330*/331332struct p9_str {333u16 len;334char *str;335};336337/**338* struct p9_qid - file system entity information339* @type: 8-bit type &p9_qid_t340* @version: 16-bit monotonically incrementing version number341* @path: 64-bit per-server-unique ID for a file system element342*343* qids are identifiers used by 9P servers to track file system344* entities. The type is used to differentiate semantics for operations345* on the entity (ie. read means something different on a directory than346* on a file). The path provides a server unique index for an entity347* (roughly analogous to an inode number), while the version is updated348* every time a file is modified and can be used to maintain cache349* coherency between clients and serves.350* Servers will often differentiate purely synthetic entities by setting351* their version to 0, signaling that they should never be cached and352* should be accessed synchronously.353*354* See Also://plan9.bell-labs.com/magic/man2html/2/stat355*/356357struct p9_qid {358u8 type;359u32 version;360u64 path;361};362363/**364* struct p9_wstat - file system metadata information365* @size: length prefix for this stat structure instance366* @type: the type of the server (equivalent to a major number)367* @dev: the sub-type of the server (equivalent to a minor number)368* @qid: unique id from the server of type &p9_qid369* @mode: Plan 9 format permissions of type &p9_perm_t370* @atime: Last access/read time371* @mtime: Last modify/write time372* @length: file length373* @name: last element of path (aka filename) in type &p9_str374* @uid: owner name in type &p9_str375* @gid: group owner in type &p9_str376* @muid: last modifier in type &p9_str377* @extension: area used to encode extended UNIX support in type &p9_str378* @n_uid: numeric user id of owner (part of 9p2000.u extension)379* @n_gid: numeric group id (part of 9p2000.u extension)380* @n_muid: numeric user id of laster modifier (part of 9p2000.u extension)381*382* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat383*/384385struct p9_wstat {386u16 size;387u16 type;388u32 dev;389struct p9_qid qid;390u32 mode;391u32 atime;392u32 mtime;393u64 length;394char *name;395char *uid;396char *gid;397char *muid;398char *extension; /* 9p2000.u extensions */399u32 n_uid; /* 9p2000.u extensions */400u32 n_gid; /* 9p2000.u extensions */401u32 n_muid; /* 9p2000.u extensions */402};403404struct p9_stat_dotl {405u64 st_result_mask;406struct p9_qid qid;407u32 st_mode;408u32 st_uid;409u32 st_gid;410u64 st_nlink;411u64 st_rdev;412u64 st_size;413u64 st_blksize;414u64 st_blocks;415u64 st_atime_sec;416u64 st_atime_nsec;417u64 st_mtime_sec;418u64 st_mtime_nsec;419u64 st_ctime_sec;420u64 st_ctime_nsec;421u64 st_btime_sec;422u64 st_btime_nsec;423u64 st_gen;424u64 st_data_version;425};426427#define P9_STATS_MODE 0x00000001ULL428#define P9_STATS_NLINK 0x00000002ULL429#define P9_STATS_UID 0x00000004ULL430#define P9_STATS_GID 0x00000008ULL431#define P9_STATS_RDEV 0x00000010ULL432#define P9_STATS_ATIME 0x00000020ULL433#define P9_STATS_MTIME 0x00000040ULL434#define P9_STATS_CTIME 0x00000080ULL435#define P9_STATS_INO 0x00000100ULL436#define P9_STATS_SIZE 0x00000200ULL437#define P9_STATS_BLOCKS 0x00000400ULL438439#define P9_STATS_BTIME 0x00000800ULL440#define P9_STATS_GEN 0x00001000ULL441#define P9_STATS_DATA_VERSION 0x00002000ULL442443#define P9_STATS_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */444#define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */445446/**447* struct p9_iattr_dotl - P9 inode attribute for setattr448* @valid: bitfield specifying which fields are valid449* same as in struct iattr450* @mode: File permission bits451* @uid: user id of owner452* @gid: group id453* @size: File size454* @atime_sec: Last access time, seconds455* @atime_nsec: Last access time, nanoseconds456* @mtime_sec: Last modification time, seconds457* @mtime_nsec: Last modification time, nanoseconds458*/459460struct p9_iattr_dotl {461u32 valid;462u32 mode;463u32 uid;464u32 gid;465u64 size;466u64 atime_sec;467u64 atime_nsec;468u64 mtime_sec;469u64 mtime_nsec;470};471472#define P9_LOCK_SUCCESS 0473#define P9_LOCK_BLOCKED 1474#define P9_LOCK_ERROR 2475#define P9_LOCK_GRACE 3476477#define P9_LOCK_FLAGS_BLOCK 1478#define P9_LOCK_FLAGS_RECLAIM 2479480/* struct p9_flock: POSIX lock structure481* @type - type of lock482* @flags - lock flags483* @start - starting offset of the lock484* @length - number of bytes485* @proc_id - process id which wants to take lock486* @client_id - client id487*/488489struct p9_flock {490u8 type;491u32 flags;492u64 start;493u64 length;494u32 proc_id;495char *client_id;496};497498/* struct p9_getlock: getlock structure499* @type - type of lock500* @start - starting offset of the lock501* @length - number of bytes502* @proc_id - process id which wants to take lock503* @client_id - client id504*/505506struct p9_getlock {507u8 type;508u64 start;509u64 length;510u32 proc_id;511char *client_id;512};513514/* Structures for Protocol Operations */515struct p9_tstatfs {516u32 fid;517};518519struct p9_rstatfs {520u32 type;521u32 bsize;522u64 blocks;523u64 bfree;524u64 bavail;525u64 files;526u64 ffree;527u64 fsid;528u32 namelen;529};530531struct p9_trename {532u32 fid;533u32 newdirfid;534struct p9_str name;535};536537struct p9_rrename {538};539540struct p9_tversion {541u32 msize;542struct p9_str version;543};544545struct p9_rversion {546u32 msize;547struct p9_str version;548};549550struct p9_tauth {551u32 afid;552struct p9_str uname;553struct p9_str aname;554u32 n_uname; /* 9P2000.u extensions */555};556557struct p9_rauth {558struct p9_qid qid;559};560561struct p9_rerror {562struct p9_str error;563u32 errno; /* 9p2000.u extension */564};565566struct p9_tflush {567u16 oldtag;568};569570struct p9_rflush {571};572573struct p9_tattach {574u32 fid;575u32 afid;576struct p9_str uname;577struct p9_str aname;578u32 n_uname; /* 9P2000.u extensions */579};580581struct p9_rattach {582struct p9_qid qid;583};584585struct p9_twalk {586u32 fid;587u32 newfid;588u16 nwname;589struct p9_str wnames[16];590};591592struct p9_rwalk {593u16 nwqid;594struct p9_qid wqids[16];595};596597struct p9_topen {598u32 fid;599u8 mode;600};601602struct p9_ropen {603struct p9_qid qid;604u32 iounit;605};606607struct p9_tcreate {608u32 fid;609struct p9_str name;610u32 perm;611u8 mode;612struct p9_str extension;613};614615struct p9_rcreate {616struct p9_qid qid;617u32 iounit;618};619620struct p9_tread {621u32 fid;622u64 offset;623u32 count;624};625626struct p9_rread {627u32 count;628u8 *data;629};630631struct p9_twrite {632u32 fid;633u64 offset;634u32 count;635u8 *data;636};637638struct p9_rwrite {639u32 count;640};641642struct p9_treaddir {643u32 fid;644u64 offset;645u32 count;646};647648struct p9_rreaddir {649u32 count;650u8 *data;651};652653654struct p9_tclunk {655u32 fid;656};657658struct p9_rclunk {659};660661struct p9_tremove {662u32 fid;663};664665struct p9_rremove {666};667668struct p9_tstat {669u32 fid;670};671672struct p9_rstat {673struct p9_wstat stat;674};675676struct p9_twstat {677u32 fid;678struct p9_wstat stat;679};680681struct p9_rwstat {682};683684/**685* struct p9_fcall - primary packet structure686* @size: prefixed length of the structure687* @id: protocol operating identifier of type &p9_msg_t688* @tag: transaction id of the request689* @offset: used by marshalling routines to track current position in buffer690* @capacity: used by marshalling routines to track total malloc'd capacity691* @pubuf: Payload user buffer given by the caller692* @pkbuf: Payload kernel buffer given by the caller693* @pbuf_size: pubuf/pkbuf(only one will be !NULL) size to be read/write.694* @private: For transport layer's use.695* @sdata: payload696*697* &p9_fcall represents the structure for all 9P RPC698* transactions. Requests are packaged into fcalls, and reponses699* must be extracted from them.700*701* See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall702*/703704struct p9_fcall {705u32 size;706u8 id;707u16 tag;708709size_t offset;710size_t capacity;711char __user *pubuf;712char *pkbuf;713size_t pbuf_size;714void *private;715716u8 *sdata;717};718719struct p9_idpool;720721int p9_errstr2errno(char *errstr, int len);722723struct p9_idpool *p9_idpool_create(void);724void p9_idpool_destroy(struct p9_idpool *);725int p9_idpool_get(struct p9_idpool *p);726void p9_idpool_put(int id, struct p9_idpool *p);727int p9_idpool_check(int id, struct p9_idpool *p);728729int p9_error_init(void);730int p9_trans_fd_init(void);731void p9_trans_fd_exit(void);732#endif /* NET_9P_H */733734735