9p.h 6.9 KB

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