9p.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * linux/fs/9p/9p.h
  3. *
  4. * 9P protocol definitions.
  5. *
  6. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to:
  21. * Free Software Foundation
  22. * 51 Franklin Street, Fifth Floor
  23. * Boston, MA 02111-1301 USA
  24. *
  25. */
  26. /* Message Types */
  27. enum {
  28. TVERSION = 100,
  29. RVERSION,
  30. TAUTH = 102,
  31. RAUTH,
  32. TATTACH = 104,
  33. RATTACH,
  34. TERROR = 106,
  35. RERROR,
  36. TFLUSH = 108,
  37. RFLUSH,
  38. TWALK = 110,
  39. RWALK,
  40. TOPEN = 112,
  41. ROPEN,
  42. TCREATE = 114,
  43. RCREATE,
  44. TREAD = 116,
  45. RREAD,
  46. TWRITE = 118,
  47. RWRITE,
  48. TCLUNK = 120,
  49. RCLUNK,
  50. TREMOVE = 122,
  51. RREMOVE,
  52. TSTAT = 124,
  53. RSTAT,
  54. TWSTAT = 126,
  55. RWSTAT,
  56. };
  57. /* modes */
  58. enum {
  59. V9FS_OREAD = 0x00,
  60. V9FS_OWRITE = 0x01,
  61. V9FS_ORDWR = 0x02,
  62. V9FS_OEXEC = 0x03,
  63. V9FS_OEXCL = 0x04,
  64. V9FS_OTRUNC = 0x10,
  65. V9FS_OREXEC = 0x20,
  66. V9FS_ORCLOSE = 0x40,
  67. V9FS_OAPPEND = 0x80,
  68. };
  69. /* permissions */
  70. enum {
  71. V9FS_DMDIR = 0x80000000,
  72. V9FS_DMAPPEND = 0x40000000,
  73. V9FS_DMEXCL = 0x20000000,
  74. V9FS_DMMOUNT = 0x10000000,
  75. V9FS_DMAUTH = 0x08000000,
  76. V9FS_DMTMP = 0x04000000,
  77. V9FS_DMSYMLINK = 0x02000000,
  78. V9FS_DMLINK = 0x01000000,
  79. /* 9P2000.u extensions */
  80. V9FS_DMDEVICE = 0x00800000,
  81. V9FS_DMNAMEDPIPE = 0x00200000,
  82. V9FS_DMSOCKET = 0x00100000,
  83. V9FS_DMSETUID = 0x00080000,
  84. V9FS_DMSETGID = 0x00040000,
  85. };
  86. /* qid.types */
  87. enum {
  88. V9FS_QTDIR = 0x80,
  89. V9FS_QTAPPEND = 0x40,
  90. V9FS_QTEXCL = 0x20,
  91. V9FS_QTMOUNT = 0x10,
  92. V9FS_QTAUTH = 0x08,
  93. V9FS_QTTMP = 0x04,
  94. V9FS_QTSYMLINK = 0x02,
  95. V9FS_QTLINK = 0x01,
  96. V9FS_QTFILE = 0x00,
  97. };
  98. #define V9FS_NOTAG (u16)(~0)
  99. #define V9FS_NOFID (u32)(~0)
  100. /* ample room for Twrite/Rread header (iounit) */
  101. #define V9FS_IOHDRSZ 24
  102. /* qids are the unique ID for a file (like an inode */
  103. struct v9fs_qid {
  104. u8 type;
  105. u32 version;
  106. u64 path;
  107. };
  108. /* Plan 9 file metadata (stat) structure */
  109. struct v9fs_stat {
  110. u16 size;
  111. u16 type;
  112. u32 dev;
  113. struct v9fs_qid qid;
  114. u32 mode;
  115. u32 atime;
  116. u32 mtime;
  117. u64 length;
  118. char *name;
  119. char *uid;
  120. char *gid;
  121. char *muid;
  122. char *extension; /* 9p2000.u extensions */
  123. u32 n_uid; /* 9p2000.u extensions */
  124. u32 n_gid; /* 9p2000.u extensions */
  125. u32 n_muid; /* 9p2000.u extensions */
  126. char data[0];
  127. };
  128. /* Structures for Protocol Operations */
  129. struct Tversion {
  130. u32 msize;
  131. char *version;
  132. };
  133. struct Rversion {
  134. u32 msize;
  135. char *version;
  136. };
  137. struct Tauth {
  138. u32 afid;
  139. char *uname;
  140. char *aname;
  141. };
  142. struct Rauth {
  143. struct v9fs_qid qid;
  144. };
  145. struct Rerror {
  146. char *error;
  147. u32 errno; /* 9p2000.u extension */
  148. };
  149. struct Tflush {
  150. u32 oldtag;
  151. };
  152. struct Rflush {
  153. };
  154. struct Tattach {
  155. u32 fid;
  156. u32 afid;
  157. char *uname;
  158. char *aname;
  159. };
  160. struct Rattach {
  161. struct v9fs_qid qid;
  162. };
  163. struct Twalk {
  164. u32 fid;
  165. u32 newfid;
  166. u32 nwname;
  167. char **wnames;
  168. };
  169. struct Rwalk {
  170. u32 nwqid;
  171. struct v9fs_qid *wqids;
  172. };
  173. struct Topen {
  174. u32 fid;
  175. u8 mode;
  176. };
  177. struct Ropen {
  178. struct v9fs_qid qid;
  179. u32 iounit;
  180. };
  181. struct Tcreate {
  182. u32 fid;
  183. char *name;
  184. u32 perm;
  185. u8 mode;
  186. };
  187. struct Rcreate {
  188. struct v9fs_qid qid;
  189. u32 iounit;
  190. };
  191. struct Tread {
  192. u32 fid;
  193. u64 offset;
  194. u32 count;
  195. };
  196. struct Rread {
  197. u32 count;
  198. u8 *data;
  199. };
  200. struct Twrite {
  201. u32 fid;
  202. u64 offset;
  203. u32 count;
  204. u8 *data;
  205. };
  206. struct Rwrite {
  207. u32 count;
  208. };
  209. struct Tclunk {
  210. u32 fid;
  211. };
  212. struct Rclunk {
  213. };
  214. struct Tremove {
  215. u32 fid;
  216. };
  217. struct Rremove {
  218. };
  219. struct Tstat {
  220. u32 fid;
  221. };
  222. struct Rstat {
  223. struct v9fs_stat *stat;
  224. };
  225. struct Twstat {
  226. u32 fid;
  227. struct v9fs_stat *stat;
  228. };
  229. struct Rwstat {
  230. };
  231. /*
  232. * fcall is the primary packet structure
  233. *
  234. */
  235. struct v9fs_fcall {
  236. u32 size;
  237. u8 id;
  238. u16 tag;
  239. union {
  240. struct Tversion tversion;
  241. struct Rversion rversion;
  242. struct Tauth tauth;
  243. struct Rauth rauth;
  244. struct Rerror rerror;
  245. struct Tflush tflush;
  246. struct Rflush rflush;
  247. struct Tattach tattach;
  248. struct Rattach rattach;
  249. struct Twalk twalk;
  250. struct Rwalk rwalk;
  251. struct Topen topen;
  252. struct Ropen ropen;
  253. struct Tcreate tcreate;
  254. struct Rcreate rcreate;
  255. struct Tread tread;
  256. struct Rread rread;
  257. struct Twrite twrite;
  258. struct Rwrite rwrite;
  259. struct Tclunk tclunk;
  260. struct Rclunk rclunk;
  261. struct Tremove tremove;
  262. struct Rremove rremove;
  263. struct Tstat tstat;
  264. struct Rstat rstat;
  265. struct Twstat twstat;
  266. struct Rwstat rwstat;
  267. } params;
  268. };
  269. #define V9FS_FCALLHDRSZ (sizeof(struct v9fs_fcall) + \
  270. sizeof(struct v9fs_stat) + 16*sizeof(struct v9fs_qid) + 16)
  271. #define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")
  272. int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
  273. char *version, struct v9fs_fcall **rcall);
  274. int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
  275. u32 fid, u32 afid, struct v9fs_fcall **rcall);
  276. int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
  277. int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);
  278. int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
  279. struct v9fs_fcall **rcall);
  280. int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
  281. struct v9fs_stat *stat, struct v9fs_fcall **rcall);
  282. int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
  283. char *name, struct v9fs_fcall **rcall);
  284. int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
  285. struct v9fs_fcall **rcall);
  286. int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
  287. struct v9fs_fcall **rcall);
  288. int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
  289. u32 perm, u8 mode, struct v9fs_fcall **rcall);
  290. int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
  291. u64 offset, u32 count, struct v9fs_fcall **rcall);
  292. int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
  293. u32 count, void *data, struct v9fs_fcall **rcall);