1
0

9.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <auth.h>
  10. #include <fcall.h>
  11. enum {
  12. NFidHash = 503,
  13. };
  14. typedef struct Con Con;
  15. typedef struct DirBuf DirBuf;
  16. typedef struct Excl Excl;
  17. typedef struct Fid Fid;
  18. typedef struct Fsys Fsys;
  19. typedef struct Msg Msg;
  20. #pragma incomplete DirBuf
  21. #pragma incomplete Excl
  22. #pragma incomplete Fsys
  23. struct Msg {
  24. unsigned char* data;
  25. uint32_t msize; /* actual size of data */
  26. Fcall t;
  27. Fcall r;
  28. Con* con;
  29. Msg* anext; /* allocation free list */
  30. Msg* mnext; /* all active messsages on this Con */
  31. Msg* mprev;
  32. int state; /* */
  33. Msg* flush; /* flushes waiting for this Msg */
  34. Msg* rwnext; /* read/write queue */
  35. int nowq; /* do not place on write queue */
  36. };
  37. enum {
  38. MsgN = 0,
  39. MsgR = 1,
  40. Msg9 = 2,
  41. MsgW = 3,
  42. MsgF = 4,
  43. };
  44. enum {
  45. ConNoneAllow = 1<<0,
  46. ConNoAuthCheck = 1<<1,
  47. ConNoPermCheck = 1<<2,
  48. ConWstatAllow = 1<<3,
  49. ConIPCheck = 1<<4,
  50. };
  51. struct Con {
  52. char* name;
  53. unsigned char* data; /* max, not negotiated */
  54. int isconsole; /* immutable */
  55. int flags; /* immutable */
  56. char remote[128]; /* immutable */
  57. VtLock* lock;
  58. int state;
  59. int fd;
  60. Msg* version;
  61. uint32_t msize; /* negotiated with Tversion */
  62. VtRendez* rendez;
  63. Con* anext; /* alloc */
  64. Con* cnext; /* in use */
  65. Con* cprev;
  66. VtLock* alock;
  67. int aok; /* authentication done */
  68. VtLock* mlock;
  69. Msg* mhead; /* all Msgs on this connection */
  70. Msg* mtail;
  71. VtRendez* mrendez;
  72. VtLock* wlock;
  73. Msg* whead; /* write queue */
  74. Msg* wtail;
  75. VtRendez* wrendez;
  76. VtLock* fidlock; /* */
  77. Fid* fidhash[NFidHash];
  78. Fid* fhead;
  79. Fid* ftail;
  80. int nfid;
  81. };
  82. enum {
  83. ConDead = 0,
  84. ConNew = 1,
  85. ConDown = 2,
  86. ConInit = 3,
  87. ConUp = 4,
  88. ConMoribund = 5,
  89. };
  90. struct Fid {
  91. VtLock* lock;
  92. Con* con;
  93. uint32_t fidno;
  94. int ref; /* inc/dec under Con.fidlock */
  95. int flags;
  96. int open;
  97. Fsys* fsys;
  98. File* file;
  99. Qid qid;
  100. char* uid;
  101. char* uname;
  102. DirBuf* db;
  103. Excl* excl;
  104. VtLock* alock; /* Tauth/Tattach */
  105. AuthRpc* rpc;
  106. char* cuname;
  107. Fid* sort; /* sorted by uname in cmdWho */
  108. Fid* hash; /* lookup by fidno */
  109. Fid* next; /* clunk session with Tversion */
  110. Fid* prev;
  111. };
  112. enum { /* Fid.flags and fidGet(..., flags) */
  113. FidFCreate = 0x01,
  114. FidFWlock = 0x02,
  115. };
  116. enum { /* Fid.open */
  117. FidOCreate = 0x01,
  118. FidORead = 0x02,
  119. FidOWrite = 0x04,
  120. FidORclose = 0x08,
  121. };
  122. /*
  123. * 9p.c
  124. */
  125. extern int (*rFcall[Tmax])(Msg*);
  126. extern int validFileName(char*);
  127. /*
  128. * 9auth.c
  129. */
  130. extern int authCheck(Fcall*, Fid*, Fsys*);
  131. extern int authRead(Fid*, void*, int);
  132. extern int authWrite(Fid*, void*, int);
  133. /*
  134. * 9dir.c
  135. */
  136. extern void dirBufFree(DirBuf*);
  137. extern int dirDe2M(DirEntry*, unsigned char*, int);
  138. extern int dirRead(Fid*, unsigned char*, int, int64_t);
  139. /*
  140. * 9excl.c
  141. */
  142. extern int exclAlloc(Fid*);
  143. extern void exclFree(Fid*);
  144. extern void exclInit(void);
  145. extern int exclUpdate(Fid*);
  146. /*
  147. * 9fid.c
  148. */
  149. extern void fidClunk(Fid*);
  150. extern void fidClunkAll(Con*);
  151. extern Fid* fidGet(Con*, uint32_t, int);
  152. extern void fidInit(void);
  153. extern void fidPut(Fid*);
  154. /*
  155. * 9fsys.c
  156. */
  157. extern void fsysFsRlock(Fsys*);
  158. extern void fsysFsRUnlock(Fsys*);
  159. extern Fs* fsysGetFs(Fsys*);
  160. extern Fsys* fsysGet(char*);
  161. extern char* fsysGetName(Fsys*);
  162. extern File* fsysGetRoot(Fsys*, char*);
  163. extern Fsys* fsysIncRef(Fsys*);
  164. extern int fsysInit(void);
  165. extern int fsysNoAuthCheck(Fsys*);
  166. extern int fsysNoPermCheck(Fsys*);
  167. extern void fsysPut(Fsys*);
  168. extern int fsysWstatAllow(Fsys*);
  169. /*
  170. * 9lstn.c
  171. */
  172. extern int lstnInit(void);
  173. /*
  174. * 9proc.c
  175. */
  176. extern Con* conAlloc(int, char*, int);
  177. extern void conInit(void);
  178. extern void msgFlush(Msg*);
  179. extern void msgInit(void);
  180. /*
  181. * 9srv.c
  182. */
  183. extern int srvInit(void);
  184. /*
  185. * 9user.c
  186. */
  187. extern int groupLeader(char*, char*);
  188. extern int groupMember(char*, char*);
  189. extern int groupWriteMember(char*);
  190. extern char* unameByUid(char*);
  191. extern char* uidByUname(char*);
  192. extern int usersInit(void);
  193. extern int usersFileRead(char*);
  194. extern int validUserName(char*);
  195. extern char* uidadm;
  196. extern char* unamenone;
  197. extern char* uidnoworld;
  198. /*
  199. * Ccli.c
  200. */
  201. extern int cliAddCmd(char*, int (*)(int, char*[]));
  202. extern int cliError(char*, ...);
  203. extern int cliInit(void);
  204. extern int cliExec(char*);
  205. #pragma varargck argpos cliError 1
  206. /*
  207. * Ccmd.c
  208. */
  209. extern int cmdInit(void);
  210. /*
  211. * Ccons.c
  212. */
  213. extern int consPrompt(char*);
  214. extern int consInit(void);
  215. extern int consOpen(int, int, int);
  216. extern int consTTY(void);
  217. extern int consWrite(char*, int);
  218. /*
  219. * Clog.c
  220. */
  221. extern int consPrint(char*, ...);
  222. extern int consVPrint(char*, va_list);
  223. #pragma varargck argpos consPrint 1
  224. /*
  225. * fossil.c
  226. */
  227. extern int Dflag;