portdat.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * fundamental constants
  3. */
  4. #define NAMELEN 28 /* size of names */
  5. #define NDBLOCK 6 /* number of direct blocks in Dentry */
  6. #define MAXDAT 8192 /* max allowable data message */
  7. #define NTLOCK 200 /* number of active file Tlocks */
  8. typedef struct Fbuf Fbuf;
  9. typedef struct Super1 Super1;
  10. typedef struct Superb Superb;
  11. // typedef struct Qid Qid;
  12. typedef struct Dentry Dentry;
  13. typedef struct Tag Tag;
  14. typedef struct Device Device;
  15. typedef struct Qid9p1 Qid9p1;
  16. typedef struct File File;
  17. typedef struct Filsys Filsys;
  18. typedef struct Filta Filta;
  19. typedef struct Filter Filter;
  20. typedef ulong Float;
  21. typedef struct Hiob Hiob;
  22. typedef struct Iobuf Iobuf;
  23. typedef struct P9call P9call;
  24. typedef struct Tlock Tlock;
  25. // typedef struct Tm Tm;
  26. typedef struct Uid Uid;
  27. typedef struct Wpath Wpath;
  28. typedef struct AuthRpc AuthRpc;
  29. /*
  30. * DONT TOUCH -- data structures stored on disk
  31. */
  32. /* DONT TOUCH, this is the disk structure */
  33. struct Qid9p1
  34. {
  35. long path;
  36. long version;
  37. };
  38. /* DONT TOUCH, this is the disk structure */
  39. struct Dentry
  40. {
  41. char name[NAMELEN];
  42. short uid;
  43. short gid;
  44. ushort mode;
  45. #define DALLOC 0x8000
  46. #define DDIR 0x4000
  47. #define DAPND 0x2000
  48. #define DLOCK 0x1000
  49. #define DREAD 0x4
  50. #define DWRITE 0x2
  51. #define DEXEC 0x1
  52. Qid9p1 qid;
  53. long size;
  54. long dblock[NDBLOCK];
  55. long iblock;
  56. long diblock;
  57. long atime;
  58. long mtime;
  59. };
  60. /* DONT TOUCH, this is the disk structure */
  61. struct Tag
  62. {
  63. short pad;
  64. short tag;
  65. long path;
  66. };
  67. /* DONT TOUCH, this is the disk structure */
  68. struct Super1
  69. {
  70. long fstart;
  71. long fsize;
  72. long tfree;
  73. long qidgen; /* generator for unique ids */
  74. long fsok; /* file system ok */
  75. /*
  76. * garbage for WWC device
  77. */
  78. long roraddr; /* dump root addr */
  79. long last; /* last super block addr */
  80. long next; /* next super block addr */
  81. };
  82. /* DONT TOUCH, this is the disk structure */
  83. struct Fbuf
  84. {
  85. long nfree;
  86. long free[1]; /* changes based on BUFSIZE */
  87. };
  88. /* DONT TOUCH, this is the disk structure */
  89. struct Superb
  90. {
  91. Super1;
  92. Fbuf fbuf;
  93. };
  94. struct Device
  95. {
  96. char type;
  97. char ctrl;
  98. char unit;
  99. char part;
  100. };
  101. /*
  102. * for load stats
  103. */
  104. struct Filter
  105. {
  106. ulong count; /* count and old count kept separate */
  107. ulong oldcount; /* so interrput can read them */
  108. Float filter[3]; /* filters for 1m 10m 100m */
  109. };
  110. struct Filta
  111. {
  112. Filter* f;
  113. int scale;
  114. };
  115. /*
  116. * array of qids that are locked
  117. */
  118. struct Tlock
  119. {
  120. Device dev;
  121. long time;
  122. long qpath;
  123. File* file;
  124. };
  125. struct File
  126. {
  127. QLock;
  128. Qid qid;
  129. Wpath* wpath;
  130. Chan* cp; /* null means a free slot */
  131. Tlock* tlock; /* if file is locked */
  132. File* next; /* in cp->flist */
  133. File* list; /* in list of free files */
  134. Filsys* fs;
  135. long addr;
  136. long slot;
  137. long lastra; /* read ahead address */
  138. short fid;
  139. short uid;
  140. char open;
  141. #define FREAD 1
  142. #define FWRITE 2
  143. #define FREMOV 4
  144. #define FWSTAT 8
  145. long doffset; /* directory reading */
  146. ulong dvers;
  147. long dslot;
  148. /* for network authentication */
  149. AuthRpc *rpc;
  150. short cuid;
  151. };
  152. struct Filsys
  153. {
  154. char* name; /* name of filesys */
  155. Device dev; /* device that filesys is on */
  156. int flags;
  157. #define FREAM (1<<1) /* mkfs */
  158. #define FRECOVER (1<<2) /* install last dump */
  159. };
  160. struct Hiob
  161. {
  162. Iobuf* link;
  163. Lock;
  164. };
  165. struct Iobuf
  166. {
  167. QLock;
  168. Device dev;
  169. Iobuf *next; /* for hash */
  170. Iobuf *fore; /* for lru */
  171. Iobuf *back; /* for lru */
  172. char *iobuf; /* only active while locked */
  173. char *xiobuf; /* "real" buffer pointer */
  174. long addr;
  175. int flags;
  176. };
  177. struct P9call
  178. {
  179. uchar calln;
  180. uchar rxflag;
  181. short msize;
  182. void (*func)(Chan*, int);
  183. };
  184. // struct Tm
  185. // {
  186. // /* see ctime(3) */
  187. // int sec;
  188. // int min;
  189. // int hour;
  190. // int mday;
  191. // int mon;
  192. // int year;
  193. // int wday;
  194. // int yday;
  195. // int isdst;
  196. // };
  197. struct Uid
  198. {
  199. short uid; /* user id */
  200. short lead; /* leader of group */
  201. short offset; /* byte offset in uidspace */
  202. };
  203. struct Wpath
  204. {
  205. Wpath *up; /* pointer upwards in path */
  206. Wpath *list; /* link in free chain */
  207. long addr; /* directory entry addr of parent */
  208. long slot; /* directory entry slot of parent */
  209. short refs; /* number of files using this structure */
  210. };
  211. #define MAXFDATA 8192
  212. /*
  213. * error codes generated from the file server
  214. */
  215. enum
  216. {
  217. Ebadspc = 1,
  218. Efid,
  219. Efidinuse,
  220. Echar,
  221. Eopen,
  222. Ecount,
  223. Ealloc,
  224. Eqid,
  225. Eauth,
  226. Eauthmsg,
  227. Eaccess,
  228. Eentry,
  229. Emode,
  230. Edir1,
  231. Edir2,
  232. Ephase,
  233. Eexist,
  234. Edot,
  235. Eempty,
  236. Ebadu,
  237. Enotu,
  238. Enotg,
  239. Ename,
  240. Ewalk,
  241. Eronly,
  242. Efull,
  243. Eoffset,
  244. Elocked,
  245. Ebroken,
  246. Etoolong,
  247. Ersc,
  248. Eqidmode,
  249. Econvert,
  250. Enotm,
  251. Enotd,
  252. Enotl,
  253. Enotw,
  254. Esystem,
  255. MAXERR
  256. };
  257. /*
  258. * devnone block numbers
  259. */
  260. enum
  261. {
  262. Cwio1 = 1,
  263. Cwio2,
  264. Cwxx1,
  265. Cwxx2,
  266. Cwxx3,
  267. Cwxx4,
  268. Cwdump1,
  269. Cwdump2,
  270. Cuidbuf,
  271. };
  272. /*
  273. * tags on block
  274. */
  275. enum
  276. {
  277. Tnone = 0,
  278. Tsuper, /* the super block */
  279. Tdir, /* directory contents */
  280. Tind1, /* points to blocks */
  281. Tind2, /* points to Tind1 */
  282. Tfile, /* file contents */
  283. Tfree, /* in free list */
  284. Tbuck, /* cache fs bucket */
  285. Tvirgo, /* fake worm virgin bits */
  286. Tcache, /* cw cache things */
  287. MAXTAG
  288. };
  289. /*
  290. * flags to getbuf
  291. */
  292. enum
  293. {
  294. Bread = (1<<0), /* read the block if miss */
  295. Bprobe = (1<<1), /* return null if miss */
  296. Bmod = (1<<2), /* set modified bit in buffer */
  297. Bimm = (1<<3), /* set immediate bit in buffer */
  298. Bres = (1<<4), /* reserved, never renammed */
  299. };
  300. /*
  301. * open modes passed into P9 open/create
  302. */
  303. enum
  304. {
  305. MREAD = 0,
  306. MWRITE,
  307. MBOTH,
  308. MEXEC,
  309. MTRUNC = (1<<4), /* truncate on open */
  310. MCEXEC = (1<<5), /* close on exec (host) */
  311. MRCLOSE = (1<<6), /* remove on close */
  312. };
  313. /*
  314. * check flags
  315. */
  316. enum
  317. {
  318. Crdall = (1<<0), /* read all files */
  319. Ctag = (1<<1), /* rebuild tags */
  320. Cpfile = (1<<2), /* print files */
  321. Cpdir = (1<<3), /* print directories */
  322. Cfree = (1<<4), /* rebuild free list */
  323. Cream = (1<<6), /* clear all bad tags */
  324. Cbad = (1<<7), /* clear all bad blocks */
  325. Ctouch = (1<<8), /* touch old dir and indir */
  326. Cquiet = (1<<9), /* report just nasty things */
  327. };
  328. /*
  329. * buffer size variables
  330. */
  331. extern int RBUFSIZE;
  332. extern int BUFSIZE;
  333. extern int DIRPERBUF;
  334. extern int INDPERBUF;
  335. extern int INDPERBUF2;
  336. extern int FEPERBUF;