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