/* SPDX-License-Identifier: GPL-2.0-only */1/*2* 9P protocol definitions.3*4* Copyright (C) 2005 by Latchesar Ionkov <[email protected]>5* Copyright (C) 2004 by Eric Van Hensbergen <[email protected]>6* Copyright (C) 2002 by Ron Minnich <[email protected]>7*/89#ifndef NET_9P_H10#define NET_9P_H1112/**13* enum p9_debug_flags - bits for mount time debug parameter14* @P9_DEBUG_ERROR: more verbose error messages including original error string15* @P9_DEBUG_9P: 9P protocol tracing16* @P9_DEBUG_VFS: VFS API tracing17* @P9_DEBUG_CONV: protocol conversion tracing18* @P9_DEBUG_MUX: trace management of concurrent transactions19* @P9_DEBUG_TRANS: transport tracing20* @P9_DEBUG_SLABS: memory management tracing21* @P9_DEBUG_FCALL: verbose dump of protocol messages22* @P9_DEBUG_FID: fid allocation/deallocation tracking23* @P9_DEBUG_PKT: packet marshalling/unmarshalling24* @P9_DEBUG_FSC: FS-cache tracing25* @P9_DEBUG_VPKT: Verbose packet debugging (full packet dump)26*27* These flags are passed at mount time to turn on various levels of28* verbosity and tracing which will be output to the system logs.29*/3031enum p9_debug_flags {32P9_DEBUG_ERROR = (1<<0),33P9_DEBUG_9P = (1<<2),34P9_DEBUG_VFS = (1<<3),35P9_DEBUG_CONV = (1<<4),36P9_DEBUG_MUX = (1<<5),37P9_DEBUG_TRANS = (1<<6),38P9_DEBUG_SLABS = (1<<7),39P9_DEBUG_FCALL = (1<<8),40P9_DEBUG_FID = (1<<9),41P9_DEBUG_PKT = (1<<10),42P9_DEBUG_FSC = (1<<11),43P9_DEBUG_VPKT = (1<<12),44P9_DEBUG_CACHE = (1<<13),45P9_DEBUG_MMAP = (1<<14),46};4748#ifdef CONFIG_NET_9P_DEBUG49extern unsigned int p9_debug_level;50__printf(3, 4)51void _p9_debug(enum p9_debug_flags level, const char *func,52const char *fmt, ...);53#define p9_debug(level, fmt, ...) \54_p9_debug(level, __func__, fmt, ##__VA_ARGS__)55#else56#define p9_debug(level, fmt, ...) \57no_printk(fmt, ##__VA_ARGS__)58#endif5960/**61* enum p9_msg_t - 9P message types62* @P9_TLERROR: not used63* @P9_RLERROR: response for any failed request for 9P2000.L64* @P9_TSTATFS: file system status request65* @P9_RSTATFS: file system status response66* @P9_TSYMLINK: make symlink request67* @P9_RSYMLINK: make symlink response68* @P9_TMKNOD: create a special file object request69* @P9_RMKNOD: create a special file object response70* @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L71* @P9_RLCREATE: response with file access information for 9P2000.L72* @P9_TRENAME: rename request73* @P9_RRENAME: rename response74* @P9_TMKDIR: create a directory request75* @P9_RMKDIR: create a directory response76* @P9_TVERSION: version handshake request77* @P9_RVERSION: version handshake response78* @P9_TAUTH: request to establish authentication channel79* @P9_RAUTH: response with authentication information80* @P9_TATTACH: establish user access to file service81* @P9_RATTACH: response with top level handle to file hierarchy82* @P9_TERROR: not used83* @P9_RERROR: response for any failed request84* @P9_TFLUSH: request to abort a previous request85* @P9_RFLUSH: response when previous request has been cancelled86* @P9_TWALK: descend a directory hierarchy87* @P9_RWALK: response with new handle for position within hierarchy88* @P9_TOPEN: prepare a handle for I/O on an existing file89* @P9_ROPEN: response with file access information90* @P9_TCREATE: prepare a handle for I/O on a new file91* @P9_RCREATE: response with file access information92* @P9_TREAD: request to transfer data from a file or directory93* @P9_RREAD: response with data requested94* @P9_TWRITE: reuqest to transfer data to a file95* @P9_RWRITE: response with out much data was transferred to file96* @P9_TCLUNK: forget about a handle to an entity within the file system97* @P9_RCLUNK: response when server has forgotten about the handle98* @P9_TREMOVE: request to remove an entity from the hierarchy99* @P9_RREMOVE: response when server has removed the entity100* @P9_TSTAT: request file entity attributes101* @P9_RSTAT: response with file entity attributes102* @P9_TWSTAT: request to update file entity attributes103* @P9_RWSTAT: response when file entity attributes are updated104*105* There are 14 basic operations in 9P2000, paired as106* requests and responses. The one special case is ERROR107* as there is no @P9_TERROR request for clients to transmit to108* the server, but the server may respond to any other request109* with an @P9_RERROR.110*111* See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html112*/113114enum p9_msg_t {115P9_TLERROR = 6,116P9_RLERROR,117P9_TSTATFS = 8,118P9_RSTATFS,119P9_TLOPEN = 12,120P9_RLOPEN,121P9_TLCREATE = 14,122P9_RLCREATE,123P9_TSYMLINK = 16,124P9_RSYMLINK,125P9_TMKNOD = 18,126P9_RMKNOD,127P9_TRENAME = 20,128P9_RRENAME,129P9_TREADLINK = 22,130P9_RREADLINK,131P9_TGETATTR = 24,132P9_RGETATTR,133P9_TSETATTR = 26,134P9_RSETATTR,135P9_TXATTRWALK = 30,136P9_RXATTRWALK,137P9_TXATTRCREATE = 32,138P9_RXATTRCREATE,139P9_TREADDIR = 40,140P9_RREADDIR,141P9_TFSYNC = 50,142P9_RFSYNC,143P9_TLOCK = 52,144P9_RLOCK,145P9_TGETLOCK = 54,146P9_RGETLOCK,147P9_TLINK = 70,148P9_RLINK,149P9_TMKDIR = 72,150P9_RMKDIR,151P9_TRENAMEAT = 74,152P9_RRENAMEAT,153P9_TUNLINKAT = 76,154P9_RUNLINKAT,155P9_TVERSION = 100,156P9_RVERSION,157P9_TAUTH = 102,158P9_RAUTH,159P9_TATTACH = 104,160P9_RATTACH,161P9_TERROR = 106,162P9_RERROR,163P9_TFLUSH = 108,164P9_RFLUSH,165P9_TWALK = 110,166P9_RWALK,167P9_TOPEN = 112,168P9_ROPEN,169P9_TCREATE = 114,170P9_RCREATE,171P9_TREAD = 116,172P9_RREAD,173P9_TWRITE = 118,174P9_RWRITE,175P9_TCLUNK = 120,176P9_RCLUNK,177P9_TREMOVE = 122,178P9_RREMOVE,179P9_TSTAT = 124,180P9_RSTAT,181P9_TWSTAT = 126,182P9_RWSTAT,183};184185/**186* enum p9_open_mode_t - 9P open modes187* @P9_OREAD: open file for reading only188* @P9_OWRITE: open file for writing only189* @P9_ORDWR: open file for reading or writing190* @P9_OEXEC: open file for execution191* @P9_OTRUNC: truncate file to zero-length before opening it192* @P9_OREXEC: close the file when an exec(2) system call is made193* @P9_ORCLOSE: remove the file when the file is closed194* @P9_OAPPEND: open the file and seek to the end195* @P9_OEXCL: only create a file, do not open it196*197* 9P open modes differ slightly from Posix standard modes.198* In particular, there are extra modes which specify different199* semantic behaviors than may be available on standard Posix200* systems. For example, @P9_OREXEC and @P9_ORCLOSE are modes that201* most likely will not be issued from the Linux VFS client, but may202* be supported by servers.203*204* See Also: http://plan9.bell-labs.com/magic/man2html/2/open205*/206207enum p9_open_mode_t {208P9_OREAD = 0x00,209P9_OWRITE = 0x01,210P9_ORDWR = 0x02,211P9_OEXEC = 0x03,212P9_OTRUNC = 0x10,213P9_OREXEC = 0x20,214P9_ORCLOSE = 0x40,215P9_OAPPEND = 0x80,216P9_OEXCL = 0x1000,217P9L_MODE_MASK = 0x1FFF, /* don't send anything under this to server */218P9L_DIRECT = 0x2000, /* cache disabled */219P9L_NOWRITECACHE = 0x4000, /* no write caching */220P9L_LOOSE = 0x8000, /* loose cache */221};222223/**224* enum p9_perm_t - 9P permissions225* @P9_DMDIR: mode bit for directories226* @P9_DMAPPEND: mode bit for is append-only227* @P9_DMEXCL: mode bit for excluse use (only one open handle allowed)228* @P9_DMMOUNT: mode bit for mount points229* @P9_DMAUTH: mode bit for authentication file230* @P9_DMTMP: mode bit for non-backed-up files231* @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u)232* @P9_DMLINK: mode bit for hard-link (9P2000.u)233* @P9_DMDEVICE: mode bit for device files (9P2000.u)234* @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u)235* @P9_DMSOCKET: mode bit for socket (9P2000.u)236* @P9_DMSETUID: mode bit for setuid (9P2000.u)237* @P9_DMSETGID: mode bit for setgid (9P2000.u)238* @P9_DMSETVTX: mode bit for sticky bit (9P2000.u)239*240* 9P permissions differ slightly from Posix standard modes.241*242* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat243*/244enum p9_perm_t {245P9_DMDIR = 0x80000000,246P9_DMAPPEND = 0x40000000,247P9_DMEXCL = 0x20000000,248P9_DMMOUNT = 0x10000000,249P9_DMAUTH = 0x08000000,250P9_DMTMP = 0x04000000,251/* 9P2000.u extensions */252P9_DMSYMLINK = 0x02000000,253P9_DMLINK = 0x01000000,254P9_DMDEVICE = 0x00800000,255P9_DMNAMEDPIPE = 0x00200000,256P9_DMSOCKET = 0x00100000,257P9_DMSETUID = 0x00080000,258P9_DMSETGID = 0x00040000,259P9_DMSETVTX = 0x00010000,260};261262/* 9p2000.L open flags */263#define P9_DOTL_RDONLY 00000000264#define P9_DOTL_WRONLY 00000001265#define P9_DOTL_RDWR 00000002266#define P9_DOTL_NOACCESS 00000003267#define P9_DOTL_CREATE 00000100268#define P9_DOTL_EXCL 00000200269#define P9_DOTL_NOCTTY 00000400270#define P9_DOTL_TRUNC 00001000271#define P9_DOTL_APPEND 00002000272#define P9_DOTL_NONBLOCK 00004000273#define P9_DOTL_DSYNC 00010000274#define P9_DOTL_FASYNC 00020000275#define P9_DOTL_DIRECT 00040000276#define P9_DOTL_LARGEFILE 00100000277#define P9_DOTL_DIRECTORY 00200000278#define P9_DOTL_NOFOLLOW 00400000279#define P9_DOTL_NOATIME 01000000280#define P9_DOTL_CLOEXEC 02000000281#define P9_DOTL_SYNC 04000000282283/* 9p2000.L at flags */284#define P9_DOTL_AT_REMOVEDIR 0x200285286/* 9p2000.L lock type */287#define P9_LOCK_TYPE_RDLCK 0288#define P9_LOCK_TYPE_WRLCK 1289#define P9_LOCK_TYPE_UNLCK 2290291/**292* enum p9_qid_t - QID types293* @P9_QTDIR: directory294* @P9_QTAPPEND: append-only295* @P9_QTEXCL: excluse use (only one open handle allowed)296* @P9_QTMOUNT: mount points297* @P9_QTAUTH: authentication file298* @P9_QTTMP: non-backed-up files299* @P9_QTSYMLINK: symbolic links (9P2000.u)300* @P9_QTLINK: hard-link (9P2000.u)301* @P9_QTFILE: normal files302*303* QID types are a subset of permissions - they are primarily304* used to differentiate semantics for a file system entity via305* a jump-table. Their value is also the most significant 16 bits306* of the permission_t307*308* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat309*/310enum p9_qid_t {311P9_QTDIR = 0x80,312P9_QTAPPEND = 0x40,313P9_QTEXCL = 0x20,314P9_QTMOUNT = 0x10,315P9_QTAUTH = 0x08,316P9_QTTMP = 0x04,317P9_QTSYMLINK = 0x02,318P9_QTLINK = 0x01,319P9_QTFILE = 0x00,320};321322/* 9P Magic Numbers */323#define P9_NOTAG ((u16)(~0))324#define P9_NOFID ((u32)(~0))325#define P9_MAXWELEM 16326327/* Minimal header size: size[4] type[1] tag[2] */328#define P9_HDRSZ 7329330/* ample room for Twrite/Rread header */331#define P9_IOHDRSZ 24332333/* Room for readdir header */334#define P9_READDIRHDRSZ 24335336/* size of header for zero copy read/write */337#define P9_ZC_HDR_SZ 4096338339/* maximum length of an error string */340#define P9_ERRMAX 128341342/**343* struct p9_qid - file system entity information344* @type: 8-bit type &p9_qid_t345* @version: 16-bit monotonically incrementing version number346* @path: 64-bit per-server-unique ID for a file system element347*348* qids are identifiers used by 9P servers to track file system349* entities. The type is used to differentiate semantics for operations350* on the entity (ie. read means something different on a directory than351* on a file). The path provides a server unique index for an entity352* (roughly analogous to an inode number), while the version is updated353* every time a file is modified and can be used to maintain cache354* coherency between clients and serves.355* Servers will often differentiate purely synthetic entities by setting356* their version to 0, signaling that they should never be cached and357* should be accessed synchronously.358*359* See Also://plan9.bell-labs.com/magic/man2html/2/stat360*/361362struct p9_qid {363u8 type;364u32 version;365u64 path;366};367368/**369* struct p9_wstat - file system metadata information370* @size: length prefix for this stat structure instance371* @type: the type of the server (equivalent to a major number)372* @dev: the sub-type of the server (equivalent to a minor number)373* @qid: unique id from the server of type &p9_qid374* @mode: Plan 9 format permissions of type &p9_perm_t375* @atime: Last access/read time376* @mtime: Last modify/write time377* @length: file length378* @name: last element of path (aka filename)379* @uid: owner name380* @gid: group owner381* @muid: last modifier382* @extension: area used to encode extended UNIX support383* @n_uid: numeric user id of owner (part of 9p2000.u extension)384* @n_gid: numeric group id (part of 9p2000.u extension)385* @n_muid: numeric user id of laster modifier (part of 9p2000.u extension)386*387* See Also: http://plan9.bell-labs.com/magic/man2html/2/stat388*/389390struct p9_wstat {391u16 size;392u16 type;393u32 dev;394struct p9_qid qid;395u32 mode;396u32 atime;397u32 mtime;398u64 length;399const char *name;400const char *uid;401const char *gid;402const char *muid;403char *extension; /* 9p2000.u extensions */404kuid_t n_uid; /* 9p2000.u extensions */405kgid_t n_gid; /* 9p2000.u extensions */406kuid_t n_muid; /* 9p2000.u extensions */407};408409struct p9_stat_dotl {410u64 st_result_mask;411struct p9_qid qid;412u32 st_mode;413kuid_t st_uid;414kgid_t st_gid;415u64 st_nlink;416u64 st_rdev;417u64 st_size;418u64 st_blksize;419u64 st_blocks;420u64 st_atime_sec;421u64 st_atime_nsec;422u64 st_mtime_sec;423u64 st_mtime_nsec;424u64 st_ctime_sec;425u64 st_ctime_nsec;426u64 st_btime_sec;427u64 st_btime_nsec;428u64 st_gen;429u64 st_data_version;430};431432#define P9_STATS_MODE 0x00000001ULL433#define P9_STATS_NLINK 0x00000002ULL434#define P9_STATS_UID 0x00000004ULL435#define P9_STATS_GID 0x00000008ULL436#define P9_STATS_RDEV 0x00000010ULL437#define P9_STATS_ATIME 0x00000020ULL438#define P9_STATS_MTIME 0x00000040ULL439#define P9_STATS_CTIME 0x00000080ULL440#define P9_STATS_INO 0x00000100ULL441#define P9_STATS_SIZE 0x00000200ULL442#define P9_STATS_BLOCKS 0x00000400ULL443444#define P9_STATS_BTIME 0x00000800ULL445#define P9_STATS_GEN 0x00001000ULL446#define P9_STATS_DATA_VERSION 0x00002000ULL447448#define P9_STATS_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */449#define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */450451/**452* struct p9_iattr_dotl - P9 inode attribute for setattr453* @valid: bitfield specifying which fields are valid454* same as in struct iattr455* @mode: File permission bits456* @uid: user id of owner457* @gid: group id458* @size: File size459* @atime_sec: Last access time, seconds460* @atime_nsec: Last access time, nanoseconds461* @mtime_sec: Last modification time, seconds462* @mtime_nsec: Last modification time, nanoseconds463*/464465struct p9_iattr_dotl {466u32 valid;467u32 mode;468kuid_t uid;469kgid_t gid;470u64 size;471u64 atime_sec;472u64 atime_nsec;473u64 mtime_sec;474u64 mtime_nsec;475};476477#define P9_LOCK_SUCCESS 0478#define P9_LOCK_BLOCKED 1479#define P9_LOCK_ERROR 2480#define P9_LOCK_GRACE 3481482#define P9_LOCK_FLAGS_BLOCK 1483#define P9_LOCK_FLAGS_RECLAIM 2484485/* struct p9_flock: POSIX lock structure486* @type - type of lock487* @flags - lock flags488* @start - starting offset of the lock489* @length - number of bytes490* @proc_id - process id which wants to take lock491* @client_id - client id492*/493494struct p9_flock {495u8 type;496u32 flags;497u64 start;498u64 length;499u32 proc_id;500char *client_id;501};502503/* struct p9_getlock: getlock structure504* @type - type of lock505* @start - starting offset of the lock506* @length - number of bytes507* @proc_id - process id which wants to take lock508* @client_id - client id509*/510511struct p9_getlock {512u8 type;513u64 start;514u64 length;515u32 proc_id;516char *client_id;517};518519struct p9_rstatfs {520u32 type;521u32 bsize;522u64 blocks;523u64 bfree;524u64 bavail;525u64 files;526u64 ffree;527u64 fsid;528u32 namelen;529};530531/**532* struct p9_fcall - primary packet structure533* @size: prefixed length of the structure534* @id: protocol operating identifier of type &p9_msg_t535* @tag: transaction id of the request536* @offset: used by marshalling routines to track current position in buffer537* @capacity: used by marshalling routines to track total malloc'd capacity538* @sdata: payload539* @zc: whether zero-copy is used540*541* &p9_fcall represents the structure for all 9P RPC542* transactions. Requests are packaged into fcalls, and reponses543* must be extracted from them.544*545* See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall546*/547548struct p9_fcall {549u32 size;550u8 id;551u16 tag;552553size_t offset;554size_t capacity;555556struct kmem_cache *cache;557u8 *sdata;558bool zc;559};560561int p9_errstr2errno(char *errstr, int len);562563int p9_error_init(void);564#endif /* NET_9P_H */565566567