dat.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. #define KNAMELEN 28 /* max length of name held in kernel */
  2. #define DOMLEN 64
  3. #define BLOCKALIGN 8
  4. typedef struct Alarms Alarms;
  5. typedef struct Block Block;
  6. typedef struct CSN CSN;
  7. typedef struct Chan Chan;
  8. typedef struct Cmdbuf Cmdbuf;
  9. typedef struct Cmdtab Cmdtab;
  10. typedef struct Cname Cname;
  11. typedef struct Conf Conf;
  12. typedef struct Dev Dev;
  13. typedef struct Dirtab Dirtab;
  14. typedef struct Edfinterface Edfinterface;
  15. typedef struct Egrp Egrp;
  16. typedef struct Evalue Evalue;
  17. typedef struct Fgrp Fgrp;
  18. typedef struct FPsave FPsave;
  19. typedef struct DevConf DevConf;
  20. typedef struct Label Label;
  21. typedef struct List List;
  22. typedef struct Log Log;
  23. typedef struct Logflag Logflag;
  24. typedef struct Mntcache Mntcache;
  25. typedef struct Mount Mount;
  26. typedef struct Mntrpc Mntrpc;
  27. typedef struct Mntwalk Mntwalk;
  28. typedef struct Mnt Mnt;
  29. typedef struct Mhead Mhead;
  30. typedef struct Note Note;
  31. typedef struct Page Page;
  32. typedef struct Palloc Palloc;
  33. typedef struct Perf Perf;
  34. typedef struct Pgrps Pgrps;
  35. typedef struct PhysUart PhysUart;
  36. typedef struct Pgrp Pgrp;
  37. typedef struct Physseg Physseg;
  38. typedef struct Proc Proc;
  39. typedef struct Pte Pte;
  40. typedef struct Pthash Pthash;
  41. typedef struct Queue Queue;
  42. typedef struct Ref Ref;
  43. typedef struct Rendez Rendez;
  44. typedef struct Rgrp Rgrp;
  45. typedef struct RWlock RWlock;
  46. typedef struct Schedq Schedq;
  47. typedef struct Segment Segment;
  48. typedef struct Session Session;
  49. typedef struct Task Task;
  50. typedef struct Talarm Talarm;
  51. typedef struct Timer Timer;
  52. typedef struct Uart Uart;
  53. typedef struct Ureg Ureg;
  54. typedef struct Waitq Waitq;
  55. typedef struct Walkqid Walkqid;
  56. typedef int Devgen(Chan*, char*, Dirtab*, int, int, Dir*);
  57. #include "fcall.h"
  58. enum
  59. {
  60. SnarfSize = 64*1024,
  61. };
  62. struct Conf
  63. {
  64. ulong nmach; /* processors */
  65. ulong nproc; /* processes */
  66. ulong monitor; /* has monitor? */
  67. ulong npage0; /* total physical pages of memory */
  68. ulong npage1; /* total physical pages of memory */
  69. ulong npage; /* total physical pages of memory */
  70. ulong upages; /* user page pool */
  71. ulong nimage; /* number of page cache image headers */
  72. ulong nswap; /* number of swap pages */
  73. int nswppo; /* max # of pageouts per segment pass */
  74. ulong base0; /* base of bank 0 */
  75. ulong base1; /* base of bank 1 */
  76. ulong copymode; /* 0 is copy on write, 1 is copy on reference */
  77. ulong ialloc; /* max interrupt time allocation in bytes */
  78. ulong pipeqsize; /* size in bytes of pipe queues */
  79. int nuart; /* number of uart devices */
  80. };
  81. struct Label
  82. {
  83. jmp_buf buf;
  84. };
  85. struct Ref
  86. {
  87. Lock lk;
  88. long ref;
  89. };
  90. struct Rendez
  91. {
  92. Lock lk;
  93. Proc *p;
  94. };
  95. struct RWlock /* changed from kernel */
  96. {
  97. int readers;
  98. Lock lk;
  99. QLock x;
  100. QLock k;
  101. };
  102. struct Talarm
  103. {
  104. Lock lk;
  105. Proc *list;
  106. };
  107. struct Alarms
  108. {
  109. QLock lk;
  110. Proc *head;
  111. };
  112. /*
  113. * Access types in namec & channel flags
  114. */
  115. enum
  116. {
  117. Aaccess, /* as in stat, wstat */
  118. Abind, /* for left-hand-side of bind */
  119. Atodir, /* as in chdir */
  120. Aopen, /* for i/o */
  121. Amount, /* to be mounted or mounted upon */
  122. Acreate, /* is to be created */
  123. Aremove, /* will be removed by caller */
  124. COPEN = 0x0001, /* for i/o */
  125. CMSG = 0x0002, /* the message channel for a mount */
  126. /* CCREATE = 0x0004, permits creation if c->mnt */
  127. CCEXEC = 0x0008, /* close on exec */
  128. CFREE = 0x0010, /* not in use */
  129. CRCLOSE = 0x0020, /* remove on close */
  130. CCACHE = 0x0080, /* client cache */
  131. };
  132. /* flag values */
  133. enum
  134. {
  135. BINTR = (1<<0),
  136. BFREE = (1<<1),
  137. Bipck = (1<<2), /* ip checksum */
  138. Budpck = (1<<3), /* udp checksum */
  139. Btcpck = (1<<4), /* tcp checksum */
  140. Bpktck = (1<<5), /* packet checksum */
  141. };
  142. struct Block
  143. {
  144. Block* next;
  145. Block* list;
  146. uchar* rp; /* first unconsumed byte */
  147. uchar* wp; /* first empty byte */
  148. uchar* lim; /* 1 past the end of the buffer */
  149. uchar* base; /* start of the buffer */
  150. void (*free)(Block*);
  151. ushort flag;
  152. ushort checksum; /* IP checksum of complete packet (minus media header) */
  153. };
  154. #define BLEN(s) ((s)->wp - (s)->rp)
  155. #define BALLOC(s) ((s)->lim - (s)->base)
  156. struct Chan
  157. {
  158. Ref ref;
  159. Chan* next; /* allocation */
  160. Chan* link;
  161. vlong offset; /* in file */
  162. ushort type;
  163. ulong dev;
  164. ushort mode; /* read/write */
  165. ushort flag;
  166. Qid qid;
  167. int fid; /* for devmnt */
  168. ulong iounit; /* chunk size for i/o; 0==default */
  169. Mhead* umh; /* mount point that derived Chan; used in unionread */
  170. Chan* umc; /* channel in union; held for union read */
  171. QLock umqlock; /* serialize unionreads */
  172. int uri; /* union read index */
  173. int dri; /* devdirread index */
  174. ulong mountid;
  175. Mntcache *mcp; /* Mount cache pointer */
  176. Mnt *mux; /* Mnt for clients using me for messages */
  177. void* aux;
  178. Qid pgrpid; /* for #p/notepg */
  179. ulong mid; /* for ns in devproc */
  180. Chan* mchan; /* channel to mounted server */
  181. Qid mqid; /* qid of root of mount point */
  182. Session*session;
  183. Cname *name;
  184. };
  185. struct Cname
  186. {
  187. Ref ref;
  188. int alen; /* allocated length */
  189. int len; /* strlen(s) */
  190. char *s;
  191. };
  192. struct Dev
  193. {
  194. int dc;
  195. char* name;
  196. void (*reset)(void);
  197. void (*init)(void);
  198. void (*shutdown)(void);
  199. Chan* (*attach)(char*);
  200. Walkqid* (*walk)(Chan*, Chan*, char**, int);
  201. int (*stat)(Chan*, uchar*, int);
  202. Chan* (*open)(Chan*, int);
  203. void (*create)(Chan*, char*, int, ulong);
  204. void (*close)(Chan*);
  205. long (*read)(Chan*, void*, long, vlong);
  206. Block* (*bread)(Chan*, long, ulong);
  207. long (*write)(Chan*, void*, long, vlong);
  208. long (*bwrite)(Chan*, Block*, ulong);
  209. void (*remove)(Chan*);
  210. int (*wstat)(Chan*, uchar*, int);
  211. void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
  212. int (*config)(int, char*, DevConf*); // returns nil on error
  213. };
  214. struct Dirtab
  215. {
  216. char name[KNAMELEN];
  217. Qid qid;
  218. vlong length;
  219. ulong perm;
  220. };
  221. struct Walkqid
  222. {
  223. Chan *clone;
  224. int nqid;
  225. Qid qid[1];
  226. };
  227. enum
  228. {
  229. NSMAX = 1000,
  230. NSLOG = 7,
  231. NSCACHE = (1<<NSLOG),
  232. };
  233. struct Mntwalk /* state for /proc/#/ns */
  234. {
  235. int cddone;
  236. ulong id;
  237. Mhead* mh;
  238. Mount* cm;
  239. };
  240. struct Mount
  241. {
  242. ulong mountid;
  243. Mount* next;
  244. Mhead* head;
  245. Mount* copy;
  246. Mount* order;
  247. Chan* to; /* channel replacing channel */
  248. int mflag;
  249. char *spec;
  250. };
  251. struct Mhead
  252. {
  253. Ref ref;
  254. RWlock lock;
  255. Chan* from; /* channel mounted upon */
  256. Mount* mount; /* what's mounted upon it */
  257. Mhead* hash; /* Hash chain */
  258. };
  259. struct Mnt
  260. {
  261. Lock lk;
  262. /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
  263. Chan *c; /* Channel to file service */
  264. Proc *rip; /* Reader in progress */
  265. Mntrpc *queue; /* Queue of pending requests on this channel */
  266. ulong id; /* Multiplexer id for channel check */
  267. Mnt *list; /* Free list */
  268. int flags; /* cache */
  269. int msize; /* data + IOHDRSZ */
  270. char *version; /* 9P version */
  271. Queue *q; /* input queue */
  272. };
  273. enum
  274. {
  275. NUser, /* note provided externally */
  276. NExit, /* deliver note quietly */
  277. NDebug, /* print debug message */
  278. };
  279. struct Note
  280. {
  281. char msg[ERRMAX];
  282. int flag; /* whether system posted it */
  283. };
  284. enum
  285. {
  286. RENDLOG = 5,
  287. RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
  288. MNTLOG = 5,
  289. MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
  290. NFD = 100, /* per process file descriptors */
  291. PGHLOG = 9,
  292. PGHSIZE = 1<<PGHLOG, /* Page hash for image lookup */
  293. };
  294. #define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
  295. #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
  296. struct Pgrp
  297. {
  298. Ref ref; /* also used as a lock when mounting */
  299. int noattach;
  300. ulong pgrpid;
  301. QLock debug; /* single access via devproc.c */
  302. RWlock ns; /* Namespace n read/one write lock */
  303. Mhead *mnthash[MNTHASH];
  304. };
  305. struct Rgrp
  306. {
  307. Ref ref;
  308. Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
  309. };
  310. struct Egrp
  311. {
  312. Ref ref;
  313. RWlock lk;
  314. Evalue **ent;
  315. int nent;
  316. int ment;
  317. ulong path; /* qid.path of next Evalue to be allocated */
  318. ulong vers; /* of Egrp */
  319. };
  320. struct Evalue
  321. {
  322. char *name;
  323. char *value;
  324. int len;
  325. Evalue *link;
  326. Qid qid;
  327. };
  328. struct Fgrp
  329. {
  330. Ref ref;
  331. Chan **fd;
  332. int nfd; /* number allocated */
  333. int maxfd; /* highest fd in use */
  334. int exceed; /* debugging */
  335. };
  336. enum
  337. {
  338. DELTAFD = 20, /* incremental increase in Fgrp.fd's */
  339. NERR = 20
  340. };
  341. typedef uvlong Ticks;
  342. enum
  343. {
  344. Running,
  345. Rendezvous,
  346. Wakeme,
  347. };
  348. struct Proc
  349. {
  350. uint state;
  351. uint mach;
  352. ulong pid;
  353. ulong parentpid;
  354. Pgrp *pgrp; /* Process group for namespace */
  355. Fgrp *fgrp; /* File descriptor group */
  356. Rgrp *rgrp;
  357. Lock rlock; /* sync sleep/wakeup with postnote */
  358. Rendez *r; /* rendezvous point slept on */
  359. Rendez sleep; /* place for syssleep/debug */
  360. int notepending; /* note issued but not acted on */
  361. int kp; /* true if a kernel process */
  362. void* rendtag; /* Tag for rendezvous */
  363. void* rendval; /* Value for rendezvous */
  364. Proc *rendhash; /* Hash list for tag values */
  365. int nerrlab;
  366. Label errlab[NERR];
  367. char user[KNAMELEN];
  368. char *syserrstr; /* last error from a system call, errbuf0 or 1 */
  369. char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
  370. char errbuf0[ERRMAX];
  371. char errbuf1[ERRMAX];
  372. char genbuf[128]; /* buffer used e.g. for last name element from namec */
  373. char text[KNAMELEN];
  374. Chan *slash;
  375. Chan *dot;
  376. Proc *qnext;
  377. void (*fn)(void*);
  378. void *arg;
  379. char oproc[1024]; /* reserved for os */
  380. };
  381. enum
  382. {
  383. PRINTSIZE = 256,
  384. MAXCRYPT = 127,
  385. NUMSIZE = 12, /* size of formatted number */
  386. MB = (1024*1024),
  387. READSTR = 1000, /* temporary buffer size for device reads */
  388. };
  389. extern char* conffile;
  390. extern int cpuserver;
  391. extern Dev* devtab[];
  392. extern char *eve;
  393. extern char hostdomain[];
  394. extern uchar initcode[];
  395. extern Queue* kbdq;
  396. extern Queue* kprintoq;
  397. extern Ref noteidalloc;
  398. extern Palloc palloc;
  399. extern Queue *serialoq;
  400. extern char* statename[];
  401. extern int nsyscall;
  402. extern char *sysname;
  403. extern uint qiomaxatomic;
  404. extern Conf conf;
  405. enum
  406. {
  407. LRESPROF = 3,
  408. };
  409. /*
  410. * action log
  411. */
  412. struct Log {
  413. Lock lk;
  414. int opens;
  415. char* buf;
  416. char *end;
  417. char *rptr;
  418. int len;
  419. int nlog;
  420. int minread;
  421. int logmask; /* mask of things to debug */
  422. QLock readq;
  423. Rendez readr;
  424. };
  425. struct Logflag {
  426. char* name;
  427. int mask;
  428. };
  429. enum
  430. {
  431. NCMDFIELD = 128
  432. };
  433. struct Cmdbuf
  434. {
  435. char *buf;
  436. char **f;
  437. int nf;
  438. };
  439. struct Cmdtab
  440. {
  441. int index; /* used by client to switch on result */
  442. char *cmd; /* command name */
  443. int narg; /* expected #args; 0 ==> variadic */
  444. };
  445. /* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
  446. enum
  447. {
  448. /* Queue.state */
  449. Qstarve = (1<<0), /* consumer starved */
  450. Qmsg = (1<<1), /* message stream */
  451. Qclosed = (1<<2), /* queue has been closed/hungup */
  452. Qflow = (1<<3), /* producer flow controlled */
  453. Qcoalesce = (1<<4), /* coallesce packets on read */
  454. Qkick = (1<<5), /* always call the kick routine after qwrite */
  455. };
  456. #define DEVDOTDOT -1
  457. extern Proc *_getproc(void);
  458. extern void _setproc(Proc*);
  459. #define up (_getproc())