Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * 9P protocol definitions.
0004  *
0005  *  Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
0006  *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
0007  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
0008  */
0009 
0010 #ifndef NET_9P_H
0011 #define NET_9P_H
0012 
0013 /**
0014  * enum p9_debug_flags - bits for mount time debug parameter
0015  * @P9_DEBUG_ERROR: more verbose error messages including original error string
0016  * @P9_DEBUG_9P: 9P protocol tracing
0017  * @P9_DEBUG_VFS: VFS API tracing
0018  * @P9_DEBUG_CONV: protocol conversion tracing
0019  * @P9_DEBUG_MUX: trace management of concurrent transactions
0020  * @P9_DEBUG_TRANS: transport tracing
0021  * @P9_DEBUG_SLABS: memory management tracing
0022  * @P9_DEBUG_FCALL: verbose dump of protocol messages
0023  * @P9_DEBUG_FID: fid allocation/deallocation tracking
0024  * @P9_DEBUG_PKT: packet marshalling/unmarshalling
0025  * @P9_DEBUG_FSC: FS-cache tracing
0026  * @P9_DEBUG_VPKT: Verbose packet debugging (full packet dump)
0027  *
0028  * These flags are passed at mount time to turn on various levels of
0029  * verbosity and tracing which will be output to the system logs.
0030  */
0031 
0032 enum p9_debug_flags {
0033     P9_DEBUG_ERROR =    (1<<0),
0034     P9_DEBUG_9P =       (1<<2),
0035     P9_DEBUG_VFS =      (1<<3),
0036     P9_DEBUG_CONV =     (1<<4),
0037     P9_DEBUG_MUX =      (1<<5),
0038     P9_DEBUG_TRANS =    (1<<6),
0039     P9_DEBUG_SLABS =    (1<<7),
0040     P9_DEBUG_FCALL =    (1<<8),
0041     P9_DEBUG_FID =      (1<<9),
0042     P9_DEBUG_PKT =      (1<<10),
0043     P9_DEBUG_FSC =      (1<<11),
0044     P9_DEBUG_VPKT =     (1<<12),
0045 };
0046 
0047 #ifdef CONFIG_NET_9P_DEBUG
0048 extern unsigned int p9_debug_level;
0049 __printf(3, 4)
0050 void _p9_debug(enum p9_debug_flags level, const char *func,
0051            const char *fmt, ...);
0052 #define p9_debug(level, fmt, ...)           \
0053     _p9_debug(level, __func__, fmt, ##__VA_ARGS__)
0054 #else
0055 #define p9_debug(level, fmt, ...)           \
0056     no_printk(fmt, ##__VA_ARGS__)
0057 #endif
0058 
0059 /**
0060  * enum p9_msg_t - 9P message types
0061  * @P9_TLERROR: not used
0062  * @P9_RLERROR: response for any failed request for 9P2000.L
0063  * @P9_TSTATFS: file system status request
0064  * @P9_RSTATFS: file system status response
0065  * @P9_TSYMLINK: make symlink request
0066  * @P9_RSYMLINK: make symlink response
0067  * @P9_TMKNOD: create a special file object request
0068  * @P9_RMKNOD: create a special file object response
0069  * @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L
0070  * @P9_RLCREATE: response with file access information for 9P2000.L
0071  * @P9_TRENAME: rename request
0072  * @P9_RRENAME: rename response
0073  * @P9_TMKDIR: create a directory request
0074  * @P9_RMKDIR: create a directory response
0075  * @P9_TVERSION: version handshake request
0076  * @P9_RVERSION: version handshake response
0077  * @P9_TAUTH: request to establish authentication channel
0078  * @P9_RAUTH: response with authentication information
0079  * @P9_TATTACH: establish user access to file service
0080  * @P9_RATTACH: response with top level handle to file hierarchy
0081  * @P9_TERROR: not used
0082  * @P9_RERROR: response for any failed request
0083  * @P9_TFLUSH: request to abort a previous request
0084  * @P9_RFLUSH: response when previous request has been cancelled
0085  * @P9_TWALK: descend a directory hierarchy
0086  * @P9_RWALK: response with new handle for position within hierarchy
0087  * @P9_TOPEN: prepare a handle for I/O on an existing file
0088  * @P9_ROPEN: response with file access information
0089  * @P9_TCREATE: prepare a handle for I/O on a new file
0090  * @P9_RCREATE: response with file access information
0091  * @P9_TREAD: request to transfer data from a file or directory
0092  * @P9_RREAD: response with data requested
0093  * @P9_TWRITE: reuqest to transfer data to a file
0094  * @P9_RWRITE: response with out much data was transferred to file
0095  * @P9_TCLUNK: forget about a handle to an entity within the file system
0096  * @P9_RCLUNK: response when server has forgotten about the handle
0097  * @P9_TREMOVE: request to remove an entity from the hierarchy
0098  * @P9_RREMOVE: response when server has removed the entity
0099  * @P9_TSTAT: request file entity attributes
0100  * @P9_RSTAT: response with file entity attributes
0101  * @P9_TWSTAT: request to update file entity attributes
0102  * @P9_RWSTAT: response when file entity attributes are updated
0103  *
0104  * There are 14 basic operations in 9P2000, paired as
0105  * requests and responses.  The one special case is ERROR
0106  * as there is no @P9_TERROR request for clients to transmit to
0107  * the server, but the server may respond to any other request
0108  * with an @P9_RERROR.
0109  *
0110  * See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html
0111  */
0112 
0113 enum p9_msg_t {
0114     P9_TLERROR = 6,
0115     P9_RLERROR,
0116     P9_TSTATFS = 8,
0117     P9_RSTATFS,
0118     P9_TLOPEN = 12,
0119     P9_RLOPEN,
0120     P9_TLCREATE = 14,
0121     P9_RLCREATE,
0122     P9_TSYMLINK = 16,
0123     P9_RSYMLINK,
0124     P9_TMKNOD = 18,
0125     P9_RMKNOD,
0126     P9_TRENAME = 20,
0127     P9_RRENAME,
0128     P9_TREADLINK = 22,
0129     P9_RREADLINK,
0130     P9_TGETATTR = 24,
0131     P9_RGETATTR,
0132     P9_TSETATTR = 26,
0133     P9_RSETATTR,
0134     P9_TXATTRWALK = 30,
0135     P9_RXATTRWALK,
0136     P9_TXATTRCREATE = 32,
0137     P9_RXATTRCREATE,
0138     P9_TREADDIR = 40,
0139     P9_RREADDIR,
0140     P9_TFSYNC = 50,
0141     P9_RFSYNC,
0142     P9_TLOCK = 52,
0143     P9_RLOCK,
0144     P9_TGETLOCK = 54,
0145     P9_RGETLOCK,
0146     P9_TLINK = 70,
0147     P9_RLINK,
0148     P9_TMKDIR = 72,
0149     P9_RMKDIR,
0150     P9_TRENAMEAT = 74,
0151     P9_RRENAMEAT,
0152     P9_TUNLINKAT = 76,
0153     P9_RUNLINKAT,
0154     P9_TVERSION = 100,
0155     P9_RVERSION,
0156     P9_TAUTH = 102,
0157     P9_RAUTH,
0158     P9_TATTACH = 104,
0159     P9_RATTACH,
0160     P9_TERROR = 106,
0161     P9_RERROR,
0162     P9_TFLUSH = 108,
0163     P9_RFLUSH,
0164     P9_TWALK = 110,
0165     P9_RWALK,
0166     P9_TOPEN = 112,
0167     P9_ROPEN,
0168     P9_TCREATE = 114,
0169     P9_RCREATE,
0170     P9_TREAD = 116,
0171     P9_RREAD,
0172     P9_TWRITE = 118,
0173     P9_RWRITE,
0174     P9_TCLUNK = 120,
0175     P9_RCLUNK,
0176     P9_TREMOVE = 122,
0177     P9_RREMOVE,
0178     P9_TSTAT = 124,
0179     P9_RSTAT,
0180     P9_TWSTAT = 126,
0181     P9_RWSTAT,
0182 };
0183 
0184 /**
0185  * enum p9_open_mode_t - 9P open modes
0186  * @P9_OREAD: open file for reading only
0187  * @P9_OWRITE: open file for writing only
0188  * @P9_ORDWR: open file for reading or writing
0189  * @P9_OEXEC: open file for execution
0190  * @P9_OTRUNC: truncate file to zero-length before opening it
0191  * @P9_OREXEC: close the file when an exec(2) system call is made
0192  * @P9_ORCLOSE: remove the file when the file is closed
0193  * @P9_OAPPEND: open the file and seek to the end
0194  * @P9_OEXCL: only create a file, do not open it
0195  *
0196  * 9P open modes differ slightly from Posix standard modes.
0197  * In particular, there are extra modes which specify different
0198  * semantic behaviors than may be available on standard Posix
0199  * systems.  For example, @P9_OREXEC and @P9_ORCLOSE are modes that
0200  * most likely will not be issued from the Linux VFS client, but may
0201  * be supported by servers.
0202  *
0203  * See Also: http://plan9.bell-labs.com/magic/man2html/2/open
0204  */
0205 
0206 enum p9_open_mode_t {
0207     P9_OREAD = 0x00,
0208     P9_OWRITE = 0x01,
0209     P9_ORDWR = 0x02,
0210     P9_OEXEC = 0x03,
0211     P9_OTRUNC = 0x10,
0212     P9_OREXEC = 0x20,
0213     P9_ORCLOSE = 0x40,
0214     P9_OAPPEND = 0x80,
0215     P9_OEXCL = 0x1000,
0216 };
0217 
0218 /**
0219  * enum p9_perm_t - 9P permissions
0220  * @P9_DMDIR: mode bit for directories
0221  * @P9_DMAPPEND: mode bit for is append-only
0222  * @P9_DMEXCL: mode bit for excluse use (only one open handle allowed)
0223  * @P9_DMMOUNT: mode bit for mount points
0224  * @P9_DMAUTH: mode bit for authentication file
0225  * @P9_DMTMP: mode bit for non-backed-up files
0226  * @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u)
0227  * @P9_DMLINK: mode bit for hard-link (9P2000.u)
0228  * @P9_DMDEVICE: mode bit for device files (9P2000.u)
0229  * @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u)
0230  * @P9_DMSOCKET: mode bit for socket (9P2000.u)
0231  * @P9_DMSETUID: mode bit for setuid (9P2000.u)
0232  * @P9_DMSETGID: mode bit for setgid (9P2000.u)
0233  * @P9_DMSETVTX: mode bit for sticky bit (9P2000.u)
0234  *
0235  * 9P permissions differ slightly from Posix standard modes.
0236  *
0237  * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
0238  */
0239 enum p9_perm_t {
0240     P9_DMDIR = 0x80000000,
0241     P9_DMAPPEND = 0x40000000,
0242     P9_DMEXCL = 0x20000000,
0243     P9_DMMOUNT = 0x10000000,
0244     P9_DMAUTH = 0x08000000,
0245     P9_DMTMP = 0x04000000,
0246 /* 9P2000.u extensions */
0247     P9_DMSYMLINK = 0x02000000,
0248     P9_DMLINK = 0x01000000,
0249     P9_DMDEVICE = 0x00800000,
0250     P9_DMNAMEDPIPE = 0x00200000,
0251     P9_DMSOCKET = 0x00100000,
0252     P9_DMSETUID = 0x00080000,
0253     P9_DMSETGID = 0x00040000,
0254     P9_DMSETVTX = 0x00010000,
0255 };
0256 
0257 /* 9p2000.L open flags */
0258 #define P9_DOTL_RDONLY        00000000
0259 #define P9_DOTL_WRONLY        00000001
0260 #define P9_DOTL_RDWR          00000002
0261 #define P9_DOTL_NOACCESS      00000003
0262 #define P9_DOTL_CREATE        00000100
0263 #define P9_DOTL_EXCL          00000200
0264 #define P9_DOTL_NOCTTY        00000400
0265 #define P9_DOTL_TRUNC         00001000
0266 #define P9_DOTL_APPEND        00002000
0267 #define P9_DOTL_NONBLOCK      00004000
0268 #define P9_DOTL_DSYNC         00010000
0269 #define P9_DOTL_FASYNC        00020000
0270 #define P9_DOTL_DIRECT        00040000
0271 #define P9_DOTL_LARGEFILE     00100000
0272 #define P9_DOTL_DIRECTORY     00200000
0273 #define P9_DOTL_NOFOLLOW      00400000
0274 #define P9_DOTL_NOATIME       01000000
0275 #define P9_DOTL_CLOEXEC       02000000
0276 #define P9_DOTL_SYNC          04000000
0277 
0278 /* 9p2000.L at flags */
0279 #define P9_DOTL_AT_REMOVEDIR        0x200
0280 
0281 /* 9p2000.L lock type */
0282 #define P9_LOCK_TYPE_RDLCK 0
0283 #define P9_LOCK_TYPE_WRLCK 1
0284 #define P9_LOCK_TYPE_UNLCK 2
0285 
0286 /**
0287  * enum p9_qid_t - QID types
0288  * @P9_QTDIR: directory
0289  * @P9_QTAPPEND: append-only
0290  * @P9_QTEXCL: excluse use (only one open handle allowed)
0291  * @P9_QTMOUNT: mount points
0292  * @P9_QTAUTH: authentication file
0293  * @P9_QTTMP: non-backed-up files
0294  * @P9_QTSYMLINK: symbolic links (9P2000.u)
0295  * @P9_QTLINK: hard-link (9P2000.u)
0296  * @P9_QTFILE: normal files
0297  *
0298  * QID types are a subset of permissions - they are primarily
0299  * used to differentiate semantics for a file system entity via
0300  * a jump-table.  Their value is also the most significant 16 bits
0301  * of the permission_t
0302  *
0303  * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
0304  */
0305 enum p9_qid_t {
0306     P9_QTDIR = 0x80,
0307     P9_QTAPPEND = 0x40,
0308     P9_QTEXCL = 0x20,
0309     P9_QTMOUNT = 0x10,
0310     P9_QTAUTH = 0x08,
0311     P9_QTTMP = 0x04,
0312     P9_QTSYMLINK = 0x02,
0313     P9_QTLINK = 0x01,
0314     P9_QTFILE = 0x00,
0315 };
0316 
0317 /* 9P Magic Numbers */
0318 #define P9_NOTAG    ((u16)(~0))
0319 #define P9_NOFID    ((u32)(~0))
0320 #define P9_MAXWELEM 16
0321 
0322 /* Minimal header size: size[4] type[1] tag[2] */
0323 #define P9_HDRSZ    7
0324 
0325 /* ample room for Twrite/Rread header */
0326 #define P9_IOHDRSZ  24
0327 
0328 /* Room for readdir header */
0329 #define P9_READDIRHDRSZ 24
0330 
0331 /* size of header for zero copy read/write */
0332 #define P9_ZC_HDR_SZ 4096
0333 
0334 /**
0335  * struct p9_qid - file system entity information
0336  * @type: 8-bit type &p9_qid_t
0337  * @version: 16-bit monotonically incrementing version number
0338  * @path: 64-bit per-server-unique ID for a file system element
0339  *
0340  * qids are identifiers used by 9P servers to track file system
0341  * entities.  The type is used to differentiate semantics for operations
0342  * on the entity (ie. read means something different on a directory than
0343  * on a file).  The path provides a server unique index for an entity
0344  * (roughly analogous to an inode number), while the version is updated
0345  * every time a file is modified and can be used to maintain cache
0346  * coherency between clients and serves.
0347  * Servers will often differentiate purely synthetic entities by setting
0348  * their version to 0, signaling that they should never be cached and
0349  * should be accessed synchronously.
0350  *
0351  * See Also://plan9.bell-labs.com/magic/man2html/2/stat
0352  */
0353 
0354 struct p9_qid {
0355     u8 type;
0356     u32 version;
0357     u64 path;
0358 };
0359 
0360 /**
0361  * struct p9_wstat - file system metadata information
0362  * @size: length prefix for this stat structure instance
0363  * @type: the type of the server (equivalent to a major number)
0364  * @dev: the sub-type of the server (equivalent to a minor number)
0365  * @qid: unique id from the server of type &p9_qid
0366  * @mode: Plan 9 format permissions of type &p9_perm_t
0367  * @atime: Last access/read time
0368  * @mtime: Last modify/write time
0369  * @length: file length
0370  * @name: last element of path (aka filename)
0371  * @uid: owner name
0372  * @gid: group owner
0373  * @muid: last modifier
0374  * @extension: area used to encode extended UNIX support
0375  * @n_uid: numeric user id of owner (part of 9p2000.u extension)
0376  * @n_gid: numeric group id (part of 9p2000.u extension)
0377  * @n_muid: numeric user id of laster modifier (part of 9p2000.u extension)
0378  *
0379  * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
0380  */
0381 
0382 struct p9_wstat {
0383     u16 size;
0384     u16 type;
0385     u32 dev;
0386     struct p9_qid qid;
0387     u32 mode;
0388     u32 atime;
0389     u32 mtime;
0390     u64 length;
0391     const char *name;
0392     const char *uid;
0393     const char *gid;
0394     const char *muid;
0395     char *extension;    /* 9p2000.u extensions */
0396     kuid_t n_uid;       /* 9p2000.u extensions */
0397     kgid_t n_gid;       /* 9p2000.u extensions */
0398     kuid_t n_muid;      /* 9p2000.u extensions */
0399 };
0400 
0401 struct p9_stat_dotl {
0402     u64 st_result_mask;
0403     struct p9_qid qid;
0404     u32 st_mode;
0405     kuid_t st_uid;
0406     kgid_t st_gid;
0407     u64 st_nlink;
0408     u64 st_rdev;
0409     u64 st_size;
0410     u64 st_blksize;
0411     u64 st_blocks;
0412     u64 st_atime_sec;
0413     u64 st_atime_nsec;
0414     u64 st_mtime_sec;
0415     u64 st_mtime_nsec;
0416     u64 st_ctime_sec;
0417     u64 st_ctime_nsec;
0418     u64 st_btime_sec;
0419     u64 st_btime_nsec;
0420     u64 st_gen;
0421     u64 st_data_version;
0422 };
0423 
0424 #define P9_STATS_MODE       0x00000001ULL
0425 #define P9_STATS_NLINK      0x00000002ULL
0426 #define P9_STATS_UID        0x00000004ULL
0427 #define P9_STATS_GID        0x00000008ULL
0428 #define P9_STATS_RDEV       0x00000010ULL
0429 #define P9_STATS_ATIME      0x00000020ULL
0430 #define P9_STATS_MTIME      0x00000040ULL
0431 #define P9_STATS_CTIME      0x00000080ULL
0432 #define P9_STATS_INO        0x00000100ULL
0433 #define P9_STATS_SIZE       0x00000200ULL
0434 #define P9_STATS_BLOCKS     0x00000400ULL
0435 
0436 #define P9_STATS_BTIME      0x00000800ULL
0437 #define P9_STATS_GEN        0x00001000ULL
0438 #define P9_STATS_DATA_VERSION   0x00002000ULL
0439 
0440 #define P9_STATS_BASIC      0x000007ffULL /* Mask for fields up to BLOCKS */
0441 #define P9_STATS_ALL        0x00003fffULL /* Mask for All fields above */
0442 
0443 /**
0444  * struct p9_iattr_dotl - P9 inode attribute for setattr
0445  * @valid: bitfield specifying which fields are valid
0446  *         same as in struct iattr
0447  * @mode: File permission bits
0448  * @uid: user id of owner
0449  * @gid: group id
0450  * @size: File size
0451  * @atime_sec: Last access time, seconds
0452  * @atime_nsec: Last access time, nanoseconds
0453  * @mtime_sec: Last modification time, seconds
0454  * @mtime_nsec: Last modification time, nanoseconds
0455  */
0456 
0457 struct p9_iattr_dotl {
0458     u32 valid;
0459     u32 mode;
0460     kuid_t uid;
0461     kgid_t gid;
0462     u64 size;
0463     u64 atime_sec;
0464     u64 atime_nsec;
0465     u64 mtime_sec;
0466     u64 mtime_nsec;
0467 };
0468 
0469 #define P9_LOCK_SUCCESS 0
0470 #define P9_LOCK_BLOCKED 1
0471 #define P9_LOCK_ERROR 2
0472 #define P9_LOCK_GRACE 3
0473 
0474 #define P9_LOCK_FLAGS_BLOCK 1
0475 #define P9_LOCK_FLAGS_RECLAIM 2
0476 
0477 /* struct p9_flock: POSIX lock structure
0478  * @type - type of lock
0479  * @flags - lock flags
0480  * @start - starting offset of the lock
0481  * @length - number of bytes
0482  * @proc_id - process id which wants to take lock
0483  * @client_id - client id
0484  */
0485 
0486 struct p9_flock {
0487     u8 type;
0488     u32 flags;
0489     u64 start;
0490     u64 length;
0491     u32 proc_id;
0492     char *client_id;
0493 };
0494 
0495 /* struct p9_getlock: getlock structure
0496  * @type - type of lock
0497  * @start - starting offset of the lock
0498  * @length - number of bytes
0499  * @proc_id - process id which wants to take lock
0500  * @client_id - client id
0501  */
0502 
0503 struct p9_getlock {
0504     u8 type;
0505     u64 start;
0506     u64 length;
0507     u32 proc_id;
0508     char *client_id;
0509 };
0510 
0511 struct p9_rstatfs {
0512     u32 type;
0513     u32 bsize;
0514     u64 blocks;
0515     u64 bfree;
0516     u64 bavail;
0517     u64 files;
0518     u64 ffree;
0519     u64 fsid;
0520     u32 namelen;
0521 };
0522 
0523 /**
0524  * struct p9_fcall - primary packet structure
0525  * @size: prefixed length of the structure
0526  * @id: protocol operating identifier of type &p9_msg_t
0527  * @tag: transaction id of the request
0528  * @offset: used by marshalling routines to track current position in buffer
0529  * @capacity: used by marshalling routines to track total malloc'd capacity
0530  * @sdata: payload
0531  *
0532  * &p9_fcall represents the structure for all 9P RPC
0533  * transactions.  Requests are packaged into fcalls, and reponses
0534  * must be extracted from them.
0535  *
0536  * See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall
0537  */
0538 
0539 struct p9_fcall {
0540     u32 size;
0541     u8 id;
0542     u16 tag;
0543 
0544     size_t offset;
0545     size_t capacity;
0546 
0547     struct kmem_cache *cache;
0548     u8 *sdata;
0549 };
0550 
0551 int p9_errstr2errno(char *errstr, int len);
0552 
0553 int p9_error_init(void);
0554 #endif /* NET_9P_H */