portdat.h 6.4 KB

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