9p.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * include/net/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. #ifndef NET_9P_H
  27. #define NET_9P_H
  28. #ifdef CONFIG_NET_9P_DEBUG
  29. #define P9_DEBUG_ERROR (1<<0)
  30. #define P9_DEBUG_9P (1<<2)
  31. #define P9_DEBUG_VFS (1<<3)
  32. #define P9_DEBUG_CONV (1<<4)
  33. #define P9_DEBUG_MUX (1<<5)
  34. #define P9_DEBUG_TRANS (1<<6)
  35. #define P9_DEBUG_SLABS (1<<7)
  36. #define P9_DEBUG_FCALL (1<<8)
  37. extern unsigned int p9_debug_level;
  38. #define P9_DPRINTK(level, format, arg...) \
  39. do { \
  40. if ((p9_debug_level & level) == level) \
  41. printk(KERN_NOTICE "-- %s (%d): " \
  42. format , __FUNCTION__, current->pid , ## arg); \
  43. } while (0)
  44. #define PRINT_FCALL_ERROR(s, fcall) P9_DPRINTK(P9_DEBUG_ERROR, \
  45. "%s: %.*s\n", s, fcall?fcall->params.rerror.error.len:0, \
  46. fcall?fcall->params.rerror.error.str:"");
  47. #else
  48. #define P9_DPRINTK(level, format, arg...) do { } while (0)
  49. #define PRINT_FCALL_ERROR(s, fcall) do { } while (0)
  50. #endif
  51. #define P9_EPRINTK(level, format, arg...) \
  52. do { \
  53. printk(level "9p: %s (%d): " \
  54. format , __FUNCTION__, current->pid , ## arg); \
  55. } while (0)
  56. /* Message Types */
  57. enum {
  58. P9_TVERSION = 100,
  59. P9_RVERSION,
  60. P9_TAUTH = 102,
  61. P9_RAUTH,
  62. P9_TATTACH = 104,
  63. P9_RATTACH,
  64. P9_TERROR = 106,
  65. P9_RERROR,
  66. P9_TFLUSH = 108,
  67. P9_RFLUSH,
  68. P9_TWALK = 110,
  69. P9_RWALK,
  70. P9_TOPEN = 112,
  71. P9_ROPEN,
  72. P9_TCREATE = 114,
  73. P9_RCREATE,
  74. P9_TREAD = 116,
  75. P9_RREAD,
  76. P9_TWRITE = 118,
  77. P9_RWRITE,
  78. P9_TCLUNK = 120,
  79. P9_RCLUNK,
  80. P9_TREMOVE = 122,
  81. P9_RREMOVE,
  82. P9_TSTAT = 124,
  83. P9_RSTAT,
  84. P9_TWSTAT = 126,
  85. P9_RWSTAT,
  86. };
  87. /* open modes */
  88. enum {
  89. P9_OREAD = 0x00,
  90. P9_OWRITE = 0x01,
  91. P9_ORDWR = 0x02,
  92. P9_OEXEC = 0x03,
  93. P9_OEXCL = 0x04,
  94. P9_OTRUNC = 0x10,
  95. P9_OREXEC = 0x20,
  96. P9_ORCLOSE = 0x40,
  97. P9_OAPPEND = 0x80,
  98. };
  99. /* permissions */
  100. enum {
  101. P9_DMDIR = 0x80000000,
  102. P9_DMAPPEND = 0x40000000,
  103. P9_DMEXCL = 0x20000000,
  104. P9_DMMOUNT = 0x10000000,
  105. P9_DMAUTH = 0x08000000,
  106. P9_DMTMP = 0x04000000,
  107. P9_DMSYMLINK = 0x02000000,
  108. P9_DMLINK = 0x01000000,
  109. /* 9P2000.u extensions */
  110. P9_DMDEVICE = 0x00800000,
  111. P9_DMNAMEDPIPE = 0x00200000,
  112. P9_DMSOCKET = 0x00100000,
  113. P9_DMSETUID = 0x00080000,
  114. P9_DMSETGID = 0x00040000,
  115. };
  116. /* qid.types */
  117. enum {
  118. P9_QTDIR = 0x80,
  119. P9_QTAPPEND = 0x40,
  120. P9_QTEXCL = 0x20,
  121. P9_QTMOUNT = 0x10,
  122. P9_QTAUTH = 0x08,
  123. P9_QTTMP = 0x04,
  124. P9_QTSYMLINK = 0x02,
  125. P9_QTLINK = 0x01,
  126. P9_QTFILE = 0x00,
  127. };
  128. #define P9_NOTAG (u16)(~0)
  129. #define P9_NOFID (u32)(~0)
  130. #define P9_MAXWELEM 16
  131. /* ample room for Twrite/Rread header */
  132. #define P9_IOHDRSZ 24
  133. struct p9_str {
  134. u16 len;
  135. char *str;
  136. };
  137. /* qids are the unique ID for a file (like an inode */
  138. struct p9_qid {
  139. u8 type;
  140. u32 version;
  141. u64 path;
  142. };
  143. /* Plan 9 file metadata (stat) structure */
  144. struct p9_stat {
  145. u16 size;
  146. u16 type;
  147. u32 dev;
  148. struct p9_qid qid;
  149. u32 mode;
  150. u32 atime;
  151. u32 mtime;
  152. u64 length;
  153. struct p9_str name;
  154. struct p9_str uid;
  155. struct p9_str gid;
  156. struct p9_str muid;
  157. struct p9_str extension; /* 9p2000.u extensions */
  158. u32 n_uid; /* 9p2000.u extensions */
  159. u32 n_gid; /* 9p2000.u extensions */
  160. u32 n_muid; /* 9p2000.u extensions */
  161. };
  162. /* file metadata (stat) structure used to create Twstat message
  163. The is similar to p9_stat, but the strings don't point to
  164. the same memory block and should be freed separately
  165. */
  166. struct p9_wstat {
  167. u16 size;
  168. u16 type;
  169. u32 dev;
  170. struct p9_qid qid;
  171. u32 mode;
  172. u32 atime;
  173. u32 mtime;
  174. u64 length;
  175. char *name;
  176. char *uid;
  177. char *gid;
  178. char *muid;
  179. char *extension; /* 9p2000.u extensions */
  180. u32 n_uid; /* 9p2000.u extensions */
  181. u32 n_gid; /* 9p2000.u extensions */
  182. u32 n_muid; /* 9p2000.u extensions */
  183. };
  184. /* Structures for Protocol Operations */
  185. struct p9_tversion {
  186. u32 msize;
  187. struct p9_str version;
  188. };
  189. struct p9_rversion {
  190. u32 msize;
  191. struct p9_str version;
  192. };
  193. struct p9_tauth {
  194. u32 afid;
  195. struct p9_str uname;
  196. struct p9_str aname;
  197. };
  198. struct p9_rauth {
  199. struct p9_qid qid;
  200. };
  201. struct p9_rerror {
  202. struct p9_str error;
  203. u32 errno; /* 9p2000.u extension */
  204. };
  205. struct p9_tflush {
  206. u16 oldtag;
  207. };
  208. struct p9_rflush {
  209. };
  210. struct p9_tattach {
  211. u32 fid;
  212. u32 afid;
  213. struct p9_str uname;
  214. struct p9_str aname;
  215. };
  216. struct p9_rattach {
  217. struct p9_qid qid;
  218. };
  219. struct p9_twalk {
  220. u32 fid;
  221. u32 newfid;
  222. u16 nwname;
  223. struct p9_str wnames[16];
  224. };
  225. struct p9_rwalk {
  226. u16 nwqid;
  227. struct p9_qid wqids[16];
  228. };
  229. struct p9_topen {
  230. u32 fid;
  231. u8 mode;
  232. };
  233. struct p9_ropen {
  234. struct p9_qid qid;
  235. u32 iounit;
  236. };
  237. struct p9_tcreate {
  238. u32 fid;
  239. struct p9_str name;
  240. u32 perm;
  241. u8 mode;
  242. struct p9_str extension;
  243. };
  244. struct p9_rcreate {
  245. struct p9_qid qid;
  246. u32 iounit;
  247. };
  248. struct p9_tread {
  249. u32 fid;
  250. u64 offset;
  251. u32 count;
  252. };
  253. struct p9_rread {
  254. u32 count;
  255. u8 *data;
  256. };
  257. struct p9_twrite {
  258. u32 fid;
  259. u64 offset;
  260. u32 count;
  261. u8 *data;
  262. };
  263. struct p9_rwrite {
  264. u32 count;
  265. };
  266. struct p9_tclunk {
  267. u32 fid;
  268. };
  269. struct p9_rclunk {
  270. };
  271. struct p9_tremove {
  272. u32 fid;
  273. };
  274. struct p9_rremove {
  275. };
  276. struct p9_tstat {
  277. u32 fid;
  278. };
  279. struct p9_rstat {
  280. struct p9_stat stat;
  281. };
  282. struct p9_twstat {
  283. u32 fid;
  284. struct p9_stat stat;
  285. };
  286. struct p9_rwstat {
  287. };
  288. /*
  289. * fcall is the primary packet structure
  290. *
  291. */
  292. struct p9_fcall {
  293. u32 size;
  294. u8 id;
  295. u16 tag;
  296. void *sdata;
  297. union {
  298. struct p9_tversion tversion;
  299. struct p9_rversion rversion;
  300. struct p9_tauth tauth;
  301. struct p9_rauth rauth;
  302. struct p9_rerror rerror;
  303. struct p9_tflush tflush;
  304. struct p9_rflush rflush;
  305. struct p9_tattach tattach;
  306. struct p9_rattach rattach;
  307. struct p9_twalk twalk;
  308. struct p9_rwalk rwalk;
  309. struct p9_topen topen;
  310. struct p9_ropen ropen;
  311. struct p9_tcreate tcreate;
  312. struct p9_rcreate rcreate;
  313. struct p9_tread tread;
  314. struct p9_rread rread;
  315. struct p9_twrite twrite;
  316. struct p9_rwrite rwrite;
  317. struct p9_tclunk tclunk;
  318. struct p9_rclunk rclunk;
  319. struct p9_tremove tremove;
  320. struct p9_rremove rremove;
  321. struct p9_tstat tstat;
  322. struct p9_rstat rstat;
  323. struct p9_twstat twstat;
  324. struct p9_rwstat rwstat;
  325. } params;
  326. };
  327. struct p9_idpool;
  328. int p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
  329. int dotu);
  330. int p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *fc, int dotu);
  331. void p9_set_tag(struct p9_fcall *fc, u16 tag);
  332. struct p9_fcall *p9_create_tversion(u32 msize, char *version);
  333. struct p9_fcall *p9_create_tattach(u32 fid, u32 afid, char *uname,
  334. char *aname);
  335. struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname);
  336. struct p9_fcall *p9_create_tflush(u16 oldtag);
  337. struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname,
  338. char **wnames);
  339. struct p9_fcall *p9_create_topen(u32 fid, u8 mode);
  340. struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode,
  341. char *extension, int dotu);
  342. struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count);
  343. struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count,
  344. const char *data);
  345. struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count,
  346. const char __user *data);
  347. struct p9_fcall *p9_create_tclunk(u32 fid);
  348. struct p9_fcall *p9_create_tremove(u32 fid);
  349. struct p9_fcall *p9_create_tstat(u32 fid);
  350. struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat,
  351. int dotu);
  352. int p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int dotu);
  353. int p9_errstr2errno(char *errstr, int len);
  354. struct p9_idpool *p9_idpool_create(void);
  355. void p9_idpool_destroy(struct p9_idpool *);
  356. int p9_idpool_get(struct p9_idpool *p);
  357. void p9_idpool_put(int id, struct p9_idpool *p);
  358. int p9_idpool_check(int id, struct p9_idpool *p);
  359. int p9_error_init(void);
  360. int p9_errstr2errno(char *, int);
  361. int __init p9_sysctl_register(void);
  362. void __exit p9_sysctl_unregister(void);
  363. #endif /* NET_9P_H */