/*-1* Copyright (c) 2017 Juniper Networks, Inc.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/* File contains 9P protocol definitions */2728#ifndef FS_P9FS_P9_PROTOCOL_H29#define FS_P9FS_P9_PROTOCOL_H3031#include <sys/types.h>3233/* 9P message types */34enum p9_cmds_t {35P9PROTO_TLERROR = 6, /* not used */36P9PROTO_RLERROR, /* response for any failed request */37P9PROTO_TSTATFS = 8, /* file system status request */38P9PROTO_RSTATFS, /* file system status response */39P9PROTO_TLOPEN = 12, /* open a file (9P2000.L) */40P9PROTO_RLOPEN, /* response to opne request (9P2000.L) */41P9PROTO_TLCREATE = 14, /* prepare for handle for I/O on a new file (9P2000.L) */42P9PROTO_RLCREATE, /* response with file access information (9P2000.L) */43P9PROTO_TSYMLINK = 16, /* symlink creation request */44P9PROTO_RSYMLINK, /* symlink creation response */45P9PROTO_TMKNOD = 18, /* create a special file object request */46P9PROTO_RMKNOD, /* create a special file object response */47P9PROTO_TRENAME = 20, /* rename a file request */48P9PROTO_RRENAME, /* rename a file response */49P9PROTO_TREADLINK = 22, /* request to read value of symbolic link */50P9PROTO_RREADLINK, /* response to read value of symbolic link request */51P9PROTO_TGETATTR = 24, /* get file attributes request */52P9PROTO_RGETATTR, /* get file attributes response */53P9PROTO_TSETATTR = 26, /* set file attributes request */54P9PROTO_RSETATTR, /* set file attributes response */55P9PROTO_TXATTRWALK = 30,/* request to read extended attributes */56P9PROTO_RXATTRWALK, /* response from server with attributes */57P9PROTO_TXATTRCREATE = 32,/* request to set extended attribute */58P9PROTO_RXATTRCREATE, /* response from server for setting extended attribute */59P9PROTO_TREADDIR = 40, /* request to read a directory */60P9PROTO_RREADDIR, /* response from server for read request */61P9PROTO_TFSYNC = 50, /* request to flush an cached data to disk */62P9PROTO_RFSYNC, /* response when cache dat is flushed */63P9PROTO_TLOCK = 52, /* acquire or release a POSIX record lock */64P9PROTO_RLOCK, /* response with the status of the lock */65P9PROTO_TGETLOCK = 54, /* request to check for presence of a POSIX record lock */66P9PROTO_RGETLOCK, /* response with the details of the lock if acquired */67P9PROTO_TLINK = 70, /* request to create hard link */68P9PROTO_RLINK, /* create hard link response */69P9PROTO_TMKDIR = 72, /* create a directory request */70P9PROTO_RMKDIR, /* create a directory response */71P9PROTO_TRENAMEAT = 74, /* request to rename a file or directory */72P9PROTO_RRENAMEAT, /* reponse to rename request */73P9PROTO_TUNLINKAT = 76, /* unlink a file or directory */74P9PROTO_RUNLINKAT, /* reponse to unlink request */75P9PROTO_TVERSION = 100, /* request for version handshake */76P9PROTO_RVERSION, /* response for version handshake */77P9PROTO_TAUTH = 102, /* request to establish authentication channel */78P9PROTO_RAUTH, /* response with authentication information */79P9PROTO_TATTACH = 104, /* establish a user access to a file system*/80P9PROTO_RATTACH, /* response with top level handle to file hierarchy */81P9PROTO_TERROR = 106, /* not used */82P9PROTO_RERROR, /* response for any failed request */83P9PROTO_TFLUSH = 108, /* request to abort a previous request */84P9PROTO_RFLUSH, /* response when previous request has been cancelled */85P9PROTO_TWALK = 110, /* descend a directory hierarchy */86P9PROTO_RWALK, /* response with new handle for position within hierarchy */87P9PROTO_TOPEN = 112, /* prepare file handle for I/O for an existing file */88P9PROTO_ROPEN, /* response with file access information */89P9PROTO_TCREATE = 114, /* prepare for handle for I/O on a new file */90P9PROTO_RCREATE, /* response with file access information */91P9PROTO_TREAD = 116, /* request to transfer data from a file */92P9PROTO_RREAD, /* response with data requested */93P9PROTO_TWRITE = 118, /* request to transfer data to a file */94P9PROTO_RWRITE, /* response with how much data was written to the file */95P9PROTO_TCLUNK = 120, /* forget about a handle to a file within the File System */96P9PROTO_RCLUNK, /* response from the server for forgetting the file handle */97P9PROTO_TREMOVE = 122, /* request to remove a file */98P9PROTO_RREMOVE, /* response when server has removed the file */99P9PROTO_TSTAT = 124, /* request file entity attributes */100P9PROTO_RSTAT, /* response with file entity attributes */101P9PROTO_TWSTAT = 126, /* request to update file entity attributes */102P9PROTO_RWSTAT, /* response when file entity attributes are updated */103};104105/* File Open Modes */106enum p9_open_mode_t {107P9PROTO_OREAD = 0x00, /* open file for reading only */108P9PROTO_OWRITE = 0x01, /* open file for writing only */109P9PROTO_ORDWR = 0x02, /* open file for both reading and writing */110P9PROTO_OEXEC = 0x03, /* open file for execution */111P9PROTO_OTRUNC = 0x10, /* truncate file to zero length before opening it */112P9PROTO_OREXEC = 0x20, /* close the file when exec system call is made */113P9PROTO_ORCLOSE = 0x40, /* remove the file when it is closed */114P9PROTO_OAPPEND = 0x80, /* open the file and seek to the end of the file */115P9PROTO_OEXCL = 0x1000, /* only create a file and not open it */116};117118/* FIle Permissions */119enum p9_perm_t {120P9PROTO_DMDIR = 0x80000000, /* permission bit for directories */121P9PROTO_DMAPPEND = 0x40000000, /* permission bit for is append-only */122P9PROTO_DMEXCL = 0x20000000, /* permission bit for exclusive use (only one open handle allowed) */123P9PROTO_DMMOUNT = 0x10000000, /* permission bit for mount points */124P9PROTO_DMAUTH = 0x08000000, /* permission bit for authentication file */125P9PROTO_DMTMP = 0x04000000, /* permission bit for non-backed-up files */126P9PROTO_DMSYMLINK = 0x02000000, /* permission bit for symbolic link (9P2000.u) */127P9PROTO_DMLINK = 0x01000000, /* permission bit for hard-link (9P2000.u) */128P9PROTO_DMDEVICE = 0x00800000, /* permission bit for device files (9P2000.u) */129P9PROTO_DMNAMEDPIPE = 0x00200000,/* permission bit for named pipe (9P2000.u) */130P9PROTO_DMSOCKET = 0x00100000, /* permission bit for socket (9P2000.u) */131P9PROTO_DMSETUID = 0x00080000, /* permission bit for setuid (9P2000.u) */132P9PROTO_DMSETGID = 0x00040000, /* permission bit for setgid (9P2000.u) */133P9PROTO_DMSETVTX = 0x00010000, /* permission bit for sticky bit (9P2000.u) */134};135136/*137* QID types - they are primarly used to138* differentiate semantics for a file system139*/140enum p9_qid_t {141P9PROTO_QTDIR = 0x80, /* directory */142P9PROTO_QTAPPEND = 0x40, /* append-only */143P9PROTO_QTEXCL = 0x20, /* exclusive use (only one open handle allowed)*/144P9PROTO_QTMOUNT = 0x10, /* mount points */145P9PROTO_QTAUTH = 0x08, /* authentication file */146P9PROTO_QTTMP = 0x04, /* non-backed-up files */147P9PROTO_QTSYMLINK = 0x02, /* symbolic links */148P9PROTO_QTLINK = 0x01, /* hard link */149P9PROTO_QTFILE = 0x00, /* normal files */150};151152/* P9 Magic Numbers */153#define P9PROTO_NOFID (uint32_t)(~0)154#define P9_DEFUNAME "nobody"155#define P9_DEFANAME ""156#define P9_NONUNAME (uint32_t)(~0)157#define P9_MAXWELEM 16158159/* Exchange unit between Qemu and Client */160struct p9_qid {161uint8_t type; /* the type of the file */162uint32_t version; /* version number for given path */163uint64_t path; /* the file servers unique id for file */164};165166/* FS information stat structure */167struct p9_statfs {168uint32_t type; /* type of file system */169uint32_t bsize; /* optimal transfer block size */170uint64_t blocks; /* total data blocks in file system */171uint64_t bfree; /* free blocks in fs */172uint64_t bavail; /* free blocks avail to non-superuser */173uint64_t files; /* total file nodes in file system */174uint64_t ffree; /* free file nodes in fs */175uint64_t fsid; /* file system id */176uint32_t namelen; /* maximum length of filenames */177};178179180/* File system metadata information */181struct p9_wstat {182uint16_t size; /* total byte count of the following data */183uint16_t type; /* type of file */184uint32_t dev; /* id of device containing file */185struct p9_qid qid; /* identifier used by server for file system entity information */186uint32_t mode; /* protection */187uint32_t atime; /* time of last access */188uint32_t mtime; /* time of last modification */189uint64_t length; /* length of file in bytes */190char *name; /* file name */191char *uid; /* user ID of owner */192char *gid; /* group ID of owner */193char *muid; /* name of the user who last modified the file */194char *extension; /* 9p2000.u extensions */195uid_t n_uid; /* 9p2000.u extensions */196gid_t n_gid; /* 9p2000.u extensions */197uid_t n_muid; /* 9p2000.u extensions */198};199200/* The linux version of FS information stat structure*/201struct p9_stat_dotl {202uint64_t st_result_mask;/* indicates fields that are requested */203struct p9_qid qid; /* identifier used by server for file system entity information */204uint32_t st_mode; /* protection */205uid_t st_uid; /* user ID of owner */206gid_t st_gid; /* group ID of owner */207uint64_t st_nlink; /* number of hard links */208uint64_t st_rdev; /* device ID (if special file) */209uint64_t st_size; /* total size, in bytes */210uint64_t st_blksize; /* blocksize for file system I/O */211uint64_t st_blocks; /* number of 512B blocks allocated */212uint64_t st_atime_sec; /* time of last access, seconds */213uint64_t st_atime_nsec; /* time of last access, nanoseconds */214uint64_t st_mtime_sec; /* time of last modification, seconds */215uint64_t st_mtime_nsec; /* time of last modifictaion, nanoseconds */216uint64_t st_ctime_sec; /* time of last status change, seconds*/217uint64_t st_ctime_nsec; /* time of last status change, nanoseconds*/218uint64_t st_btime_sec; /* following memebers are reserved for future use */219uint64_t st_btime_nsec;220uint64_t st_gen;221uint64_t st_data_version;222};223224/* P9 inode attribute for setattr */225struct p9_iattr_dotl {226uint32_t valid; /* bit fields specifying which fields are valid */227uint32_t mode; /* protection */228uid_t uid; /* user id of owner */229gid_t gid; /* group id */230uint64_t size; /* file size */231uint64_t atime_sec; /* last access time in seconds */232uint64_t atime_nsec; /* last access time in nanoseconds */233uint64_t mtime_sec; /* last modification time in seconds */234uint64_t mtime_nsec; /* last modification time in nanoseconds */235};236237#define P9PROTO_STATS_MODE 0x00000001ULL238#define P9PROTO_STATS_NLINK 0x00000002ULL239#define P9PROTO_STATS_UID 0x00000004ULL240#define P9PROTO_STATS_GID 0x00000008ULL241#define P9PROTO_STATS_RDEV 0x00000010ULL242#define P9PROTO_STATS_ATIME 0x00000020ULL243#define P9PROTO_STATS_MTIME 0x00000040ULL244#define P9PROTO_STATS_CTIME 0x00000080ULL245#define P9PROTO_STATS_INO 0x00000100ULL246#define P9PROTO_STATS_SIZE 0x00000200ULL247#define P9PROTO_STATS_BLOCKS 0x00000400ULL248249#define P9PROTO_STATS_BTIME 0x00000800ULL250#define P9PROTO_STATS_GEN 0x00001000ULL251#define P9PROTO_STATS_DATA_VERSION 0x00002000ULL252253#define P9PROTO_STATS_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */254#define P9PROTO_STATS_ALL 0x00003fffULL /* Mask for All fields above */255256#define P9PROTO_SETATTR_MODE 0x00000001UL257#define P9PROTO_SETATTR_UID 0x00000002UL258#define P9PROTO_SETATTR_GID 0x00000004UL259#define P9PROTO_SETATTR_SIZE 0x00000008UL260#define P9PROTO_SETATTR_ATIME 0x00000010UL261#define P9PROTO_SETATTR_MTIME 0x00000020UL262#define P9PROTO_SETATTR_CTIME 0x00000040UL263#define P9PROTO_SETATTR_ATIME_SET 0x00000080UL264#define P9PROTO_SETATTR_MTIME_SET 0x00000100UL265#define P9PROTO_SETATTR_MASK 0x000001bfUL266267#define P9PROTO_TGETATTR_BLK 512268269#define P9PROTO_UNLINKAT_REMOVEDIR 0x200270271/* PDU buffer used for SG lists. */272struct p9_buffer {273uint32_t size;274uint16_t tag;275uint8_t id;276size_t offset;277size_t capacity;278uint8_t *sdata;279};280281#endif /* FS_P9FS_P9_PROTOCOL_H */282283284