9p.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. /* ample room for Twrite/Rread header (iounit) */
  99. #define V9FS_IOHDRSZ 24
  100. /* qids are the unique ID for a file (like an inode */
  101. struct v9fs_qid {
  102. u8 type;
  103. u32 version;
  104. u64 path;
  105. };
  106. /* Plan 9 file metadata (stat) structure */
  107. struct v9fs_stat {
  108. u16 size;
  109. u16 type;
  110. u32 dev;
  111. struct v9fs_qid qid;
  112. u32 mode;
  113. u32 atime;
  114. u32 mtime;
  115. u64 length;
  116. char *name;
  117. char *uid;
  118. char *gid;
  119. char *muid;
  120. char *extension; /* 9p2000.u extensions */
  121. u32 n_uid; /* 9p2000.u extensions */
  122. u32 n_gid; /* 9p2000.u extensions */
  123. u32 n_muid; /* 9p2000.u extensions */
  124. char data[0];
  125. };
  126. /* Structures for Protocol Operations */
  127. struct Tversion {
  128. u32 msize;
  129. char *version;
  130. };
  131. struct Rversion {
  132. u32 msize;
  133. char *version;
  134. };
  135. struct Tauth {
  136. u32 afid;
  137. char *uname;
  138. char *aname;
  139. };
  140. struct Rauth {
  141. struct v9fs_qid qid;
  142. };
  143. struct Rerror {
  144. char *error;
  145. u32 errno; /* 9p2000.u extension */
  146. };
  147. struct Tflush {
  148. u32 oldtag;
  149. };
  150. struct Rflush {
  151. };
  152. struct Tattach {
  153. u32 fid;
  154. u32 afid;
  155. char *uname;
  156. char *aname;
  157. };
  158. struct Rattach {
  159. struct v9fs_qid qid;
  160. };
  161. struct Twalk {
  162. u32 fid;
  163. u32 newfid;
  164. u32 nwname;
  165. char **wnames;
  166. };
  167. struct Rwalk {
  168. u32 nwqid;
  169. struct v9fs_qid *wqids;
  170. };
  171. struct Topen {
  172. u32 fid;
  173. u8 mode;
  174. };
  175. struct Ropen {
  176. struct v9fs_qid qid;
  177. u32 iounit;
  178. };
  179. struct Tcreate {
  180. u32 fid;
  181. char *name;
  182. u32 perm;
  183. u8 mode;
  184. };
  185. struct Rcreate {
  186. struct v9fs_qid qid;
  187. u32 iounit;
  188. };
  189. struct Tread {
  190. u32 fid;
  191. u64 offset;
  192. u32 count;
  193. };
  194. struct Rread {
  195. u32 count;
  196. u8 *data;
  197. };
  198. struct Twrite {
  199. u32 fid;
  200. u64 offset;
  201. u32 count;
  202. u8 *data;
  203. };
  204. struct Rwrite {
  205. u32 count;
  206. };
  207. struct Tclunk {
  208. u32 fid;
  209. };
  210. struct Rclunk {
  211. };
  212. struct Tremove {
  213. u32 fid;
  214. };
  215. struct Rremove {
  216. };
  217. struct Tstat {
  218. u32 fid;
  219. };
  220. struct Rstat {
  221. struct v9fs_stat *stat;
  222. };
  223. struct Twstat {
  224. u32 fid;
  225. struct v9fs_stat *stat;
  226. };
  227. struct Rwstat {
  228. };
  229. /*
  230. * fcall is the primary packet structure
  231. *
  232. */
  233. struct v9fs_fcall {
  234. u32 size;
  235. u8 id;
  236. u16 tag;
  237. union {
  238. struct Tversion tversion;
  239. struct Rversion rversion;
  240. struct Tauth tauth;
  241. struct Rauth rauth;
  242. struct Rerror rerror;
  243. struct Tflush tflush;
  244. struct Rflush rflush;
  245. struct Tattach tattach;
  246. struct Rattach rattach;
  247. struct Twalk twalk;
  248. struct Rwalk rwalk;
  249. struct Topen topen;
  250. struct Ropen ropen;
  251. struct Tcreate tcreate;
  252. struct Rcreate rcreate;
  253. struct Tread tread;
  254. struct Rread rread;
  255. struct Twrite twrite;
  256. struct Rwrite rwrite;
  257. struct Tclunk tclunk;
  258. struct Rclunk rclunk;
  259. struct Tremove tremove;
  260. struct Rremove rremove;
  261. struct Tstat tstat;
  262. struct Rstat rstat;
  263. struct Twstat twstat;
  264. struct Rwstat rwstat;
  265. } params;
  266. };
  267. #define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")
  268. int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
  269. char *version, struct v9fs_fcall **rcall);
  270. int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
  271. u32 fid, u32 afid, struct v9fs_fcall **rcall);
  272. int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid,
  273. struct v9fs_fcall **rcall);
  274. int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);
  275. int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
  276. struct v9fs_fcall **rcall);
  277. int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
  278. struct v9fs_stat *stat, struct v9fs_fcall **rcall);
  279. int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
  280. char *name, struct v9fs_fcall **rcall);
  281. int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
  282. struct v9fs_fcall **rcall);
  283. int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
  284. struct v9fs_fcall **rcall);
  285. int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
  286. u32 perm, u8 mode, struct v9fs_fcall **rcall);
  287. int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
  288. u64 offset, u32 count, struct v9fs_fcall **rcall);
  289. int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
  290. u32 count, void *data, struct v9fs_fcall **rcall);