9p.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 version 2
  12. * as published by the Free Software Foundation.
  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. #define V9FS_MAXWELEM 16
  101. /* ample room for Twrite/Rread header (iounit) */
  102. #define V9FS_IOHDRSZ 24
  103. struct v9fs_str {
  104. u16 len;
  105. char *str;
  106. };
  107. /* qids are the unique ID for a file (like an inode */
  108. struct v9fs_qid {
  109. u8 type;
  110. u32 version;
  111. u64 path;
  112. };
  113. /* Plan 9 file metadata (stat) structure */
  114. struct v9fs_stat {
  115. u16 size;
  116. u16 type;
  117. u32 dev;
  118. struct v9fs_qid qid;
  119. u32 mode;
  120. u32 atime;
  121. u32 mtime;
  122. u64 length;
  123. struct v9fs_str name;
  124. struct v9fs_str uid;
  125. struct v9fs_str gid;
  126. struct v9fs_str muid;
  127. struct v9fs_str extension; /* 9p2000.u extensions */
  128. u32 n_uid; /* 9p2000.u extensions */
  129. u32 n_gid; /* 9p2000.u extensions */
  130. u32 n_muid; /* 9p2000.u extensions */
  131. };
  132. /* file metadata (stat) structure used to create Twstat message
  133. The is similar to v9fs_stat, but the strings don't point to
  134. the same memory block and should be freed separately
  135. */
  136. struct v9fs_wstat {
  137. u16 size;
  138. u16 type;
  139. u32 dev;
  140. struct v9fs_qid qid;
  141. u32 mode;
  142. u32 atime;
  143. u32 mtime;
  144. u64 length;
  145. char *name;
  146. char *uid;
  147. char *gid;
  148. char *muid;
  149. char *extension; /* 9p2000.u extensions */
  150. u32 n_uid; /* 9p2000.u extensions */
  151. u32 n_gid; /* 9p2000.u extensions */
  152. u32 n_muid; /* 9p2000.u extensions */
  153. };
  154. /* Structures for Protocol Operations */
  155. struct Tversion {
  156. u32 msize;
  157. struct v9fs_str version;
  158. };
  159. struct Rversion {
  160. u32 msize;
  161. struct v9fs_str version;
  162. };
  163. struct Tauth {
  164. u32 afid;
  165. struct v9fs_str uname;
  166. struct v9fs_str aname;
  167. };
  168. struct Rauth {
  169. struct v9fs_qid qid;
  170. };
  171. struct Rerror {
  172. struct v9fs_str error;
  173. u32 errno; /* 9p2000.u extension */
  174. };
  175. struct Tflush {
  176. u16 oldtag;
  177. };
  178. struct Rflush {
  179. };
  180. struct Tattach {
  181. u32 fid;
  182. u32 afid;
  183. struct v9fs_str uname;
  184. struct v9fs_str aname;
  185. };
  186. struct Rattach {
  187. struct v9fs_qid qid;
  188. };
  189. struct Twalk {
  190. u32 fid;
  191. u32 newfid;
  192. u16 nwname;
  193. struct v9fs_str wnames[16];
  194. };
  195. struct Rwalk {
  196. u16 nwqid;
  197. struct v9fs_qid wqids[16];
  198. };
  199. struct Topen {
  200. u32 fid;
  201. u8 mode;
  202. };
  203. struct Ropen {
  204. struct v9fs_qid qid;
  205. u32 iounit;
  206. };
  207. struct Tcreate {
  208. u32 fid;
  209. struct v9fs_str name;
  210. u32 perm;
  211. u8 mode;
  212. struct v9fs_str extension;
  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_stat(struct v9fs_session_info *v9ses, u32 fid,
  306. struct v9fs_fcall **rcall);
  307. int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
  308. struct v9fs_wstat *wstat, struct v9fs_fcall **rcall);
  309. int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
  310. char *name, struct v9fs_fcall **rcall);
  311. int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
  312. struct v9fs_fcall **rcall);
  313. int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
  314. struct v9fs_fcall **rcall);
  315. int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
  316. u32 perm, u8 mode, char *extension, struct v9fs_fcall **rcall);
  317. int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
  318. u64 offset, u32 count, struct v9fs_fcall **rcall);
  319. int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
  320. u32 count, const char __user * data,
  321. struct v9fs_fcall **rcall);
  322. int v9fs_printfcall(char *, int, struct v9fs_fcall *, int);