portdat.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. long doffset; /* directory reading */
  145. ulong dvers;
  146. long dslot;
  147. /* for network authentication */
  148. AuthRpc *rpc;
  149. short cuid;
  150. };
  151. struct Filsys
  152. {
  153. char* name; /* name of filesys */
  154. Device dev; /* device that filesys is on */
  155. int flags;
  156. #define FREAM (1<<1) /* mkfs */
  157. #define FRECOVER (1<<2) /* install last dump */
  158. };
  159. struct Hiob
  160. {
  161. Iobuf* link;
  162. Lock;
  163. };
  164. struct Iobuf
  165. {
  166. QLock;
  167. Device dev;
  168. Iobuf *next; /* for hash */
  169. Iobuf *fore; /* for lru */
  170. Iobuf *back; /* for lru */
  171. char *iobuf; /* only active while locked */
  172. char *xiobuf; /* "real" buffer pointer */
  173. long addr;
  174. int flags;
  175. };
  176. struct P9call
  177. {
  178. uchar calln;
  179. uchar rxflag;
  180. short msize;
  181. void (*func)(Chan*, int);
  182. };
  183. // struct Tm
  184. // {
  185. // /* see ctime(3) */
  186. // int sec;
  187. // int min;
  188. // int hour;
  189. // int mday;
  190. // int mon;
  191. // int year;
  192. // int wday;
  193. // int yday;
  194. // int isdst;
  195. // };
  196. struct Uid
  197. {
  198. short uid; /* user id */
  199. short lead; /* leader of group */
  200. short offset; /* byte offset in uidspace */
  201. };
  202. struct Wpath
  203. {
  204. Wpath *up; /* pointer upwards in path */
  205. Wpath *list; /* link in free chain */
  206. long addr; /* directory entry addr of parent */
  207. long slot; /* directory entry slot of parent */
  208. long faddr; /* directory entry addr */
  209. long fslot; /* directory entry slot */
  210. Qid qid; /* qid of current */
  211. short refs; /* number of files using this structure */
  212. };
  213. #define MAXFDATA 8192
  214. /*
  215. * error codes generated from the file server
  216. */
  217. enum
  218. {
  219. Ebadspc = 1,
  220. Efid,
  221. Efidinuse,
  222. Echar,
  223. Eopen,
  224. Ecount,
  225. Ealloc,
  226. Eqid,
  227. Eauth,
  228. Eauthmsg,
  229. Eaccess,
  230. Eentry,
  231. Emode,
  232. Edir1,
  233. Edir2,
  234. Ephase,
  235. Eexist,
  236. Edot,
  237. Eempty,
  238. Ebadu,
  239. Enotu,
  240. Enotg,
  241. Ename,
  242. Ewalk,
  243. Eronly,
  244. Efull,
  245. Eoffset,
  246. Elocked,
  247. Ebroken,
  248. Etoolong,
  249. Ersc,
  250. Eqidmode,
  251. Econvert,
  252. Enotm,
  253. Enotd,
  254. Enotl,
  255. Enotw,
  256. Esystem,
  257. MAXERR
  258. };
  259. /*
  260. * devnone block numbers
  261. */
  262. enum
  263. {
  264. Cwio1 = 1,
  265. Cwio2,
  266. Cwxx1,
  267. Cwxx2,
  268. Cwxx3,
  269. Cwxx4,
  270. Cwdump1,
  271. Cwdump2,
  272. Cuidbuf,
  273. };
  274. /*
  275. * tags on block
  276. */
  277. enum
  278. {
  279. Tnone = 0,
  280. Tsuper, /* the super block */
  281. Tdir, /* directory contents */
  282. Tind1, /* points to blocks */
  283. Tind2, /* points to Tind1 */
  284. Tfile, /* file contents */
  285. Tfree, /* in free list */
  286. Tbuck, /* cache fs bucket */
  287. Tvirgo, /* fake worm virgin bits */
  288. Tcache, /* cw cache things */
  289. MAXTAG
  290. };
  291. /*
  292. * flags to getbuf
  293. */
  294. enum
  295. {
  296. Bread = (1<<0), /* read the block if miss */
  297. Bprobe = (1<<1), /* return null if miss */
  298. Bmod = (1<<2), /* set modified bit in buffer */
  299. Bimm = (1<<3), /* set immediate bit in buffer */
  300. Bres = (1<<4), /* reserved, never renammed */
  301. };
  302. /*
  303. * open modes passed into P9 open/create
  304. */
  305. enum
  306. {
  307. MREAD = 0,
  308. MWRITE,
  309. MBOTH,
  310. MEXEC,
  311. MTRUNC = (1<<4), /* truncate on open */
  312. MCEXEC = (1<<5), /* close on exec (host) */
  313. MRCLOSE = (1<<6), /* remove on close */
  314. };
  315. /*
  316. * check flags
  317. */
  318. enum
  319. {
  320. Crdall = (1<<0), /* read all files */
  321. Ctag = (1<<1), /* rebuild tags */
  322. Cpfile = (1<<2), /* print files */
  323. Cpdir = (1<<3), /* print directories */
  324. Cfree = (1<<4), /* rebuild free list */
  325. Cream = (1<<6), /* clear all bad tags */
  326. Cbad = (1<<7), /* clear all bad blocks */
  327. Ctouch = (1<<8), /* touch old dir and indir */
  328. Cquiet = (1<<9), /* report just nasty things */
  329. };
  330. /*
  331. * buffer size variables
  332. */
  333. extern int RBUFSIZE;
  334. extern int BUFSIZE;
  335. extern int DIRPERBUF;
  336. extern int INDPERBUF;
  337. extern int INDPERBUF2;
  338. extern int FEPERBUF;