portdat.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*
  2. * fundamental constants and types of the implementation
  3. * changing any of these changes the layout on disk
  4. */
  5. enum {
  6. SUPER_ADDR = 2, /* block address of superblock */
  7. ROOT_ADDR = 3, /* block address of root directory */
  8. };
  9. /* more fundamental types */
  10. typedef vlong Wideoff; /* type to widen Off to for printing; ≥ as wide as Off */
  11. typedef short Userid; /* signed internal representation of user-id */
  12. typedef long Timet; /* in seconds since epoch */
  13. typedef vlong Devsize; /* in bytes */
  14. /* macros */
  15. #define NEXT(x, l) (((x)+1) % (l))
  16. #define PREV(x, l) ((x) == 0? (l)-1: (x)-1)
  17. #define HOWMANY(x, y) (((x)+((y)-1)) / (y))
  18. #define ROUNDUP(x, y) (HOWMANY((x), (y)) * (y))
  19. #define TK2MS(t) (((ulong)(t)*1000)/HZ) /* ticks to ms - beware rounding */
  20. #define MS2TK(t) (((ulong)(t)*HZ)/1000) /* ms to ticks - beware rounding */
  21. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  22. /* constants that don't affect disk layout */
  23. enum {
  24. MAXDAT = 8192, /* max allowable data message */
  25. MAXMSG = 128, /* max protocol message sans data */
  26. MB = 1024*1024,
  27. HZ = 1, /* clock frequency */
  28. };
  29. /*
  30. * tunable parameters
  31. */
  32. enum {
  33. Maxword = 256, /* max bytes per command-line word */
  34. NTLOCK = 200, /* number of active file Tlocks */
  35. };
  36. typedef struct Auth Auth;
  37. typedef struct Bp Bp;
  38. typedef struct Bucket Bucket;
  39. typedef struct Cache Cache;
  40. typedef struct Centry Centry;
  41. typedef struct Chan Chan;
  42. typedef struct Command Command;
  43. typedef struct Conf Conf;
  44. typedef struct Cons Cons;
  45. typedef struct Dentry Dentry;
  46. typedef struct Device Device;
  47. typedef struct Fbuf Fbuf;
  48. typedef struct File File;
  49. typedef struct Filsys Filsys;
  50. typedef struct Filter Filter;
  51. typedef struct Flag Flag;
  52. typedef struct Hiob Hiob;
  53. typedef struct Iobuf Iobuf;
  54. typedef struct Lock Lock;
  55. typedef struct Msgbuf Msgbuf;
  56. typedef struct QLock QLock;
  57. typedef struct Qid9p1 Qid9p1;
  58. typedef struct Queue Queue;
  59. typedef union Rabuf Rabuf;
  60. typedef struct Rendez Rendez;
  61. typedef struct Rtc Rtc;
  62. typedef struct Startsb Startsb;
  63. typedef struct Super1 Super1;
  64. typedef struct Superb Superb;
  65. typedef struct Tag Tag;
  66. typedef struct Time Time;
  67. typedef struct Tlock Tlock;
  68. typedef struct Tm Tm;
  69. typedef struct Uid Uid;
  70. typedef struct Wpath Wpath;
  71. #pragma incomplete Auth
  72. struct Tag
  73. {
  74. short pad; /* make tag end at a long boundary */
  75. short tag;
  76. Off path;
  77. };
  78. /* DONT TOUCH, this is the disk structure */
  79. struct Qid9p1
  80. {
  81. Off path; /* was long */
  82. ulong version; /* should be Off */
  83. };
  84. /* DONT TOUCH, this is the disk structure */
  85. struct Super1
  86. {
  87. Off fstart;
  88. Off fsize;
  89. Off tfree;
  90. Off qidgen; /* generator for unique ids */
  91. /*
  92. * Stuff for WWC device
  93. */
  94. Off cwraddr; /* cfs root addr */
  95. Off roraddr; /* dump root addr */
  96. Off last; /* last super block addr */
  97. Off next; /* next super block addr */
  98. };
  99. /* DONT TOUCH, this is the disk structure */
  100. struct Centry
  101. {
  102. ushort age;
  103. short state;
  104. Off waddr; /* worm addr */
  105. };
  106. /* DONT TOUCH, this is the disk structure */
  107. struct Dentry
  108. {
  109. char name[NAMELEN];
  110. Userid uid;
  111. Userid gid;
  112. ushort mode;
  113. #define DALLOC 0x8000
  114. #define DDIR 0x4000
  115. #define DAPND 0x2000
  116. #define DLOCK 0x1000
  117. #define DREAD 0x4
  118. #define DWRITE 0x2
  119. #define DEXEC 0x1
  120. Userid muid;
  121. Qid9p1 qid;
  122. Off size;
  123. Off dblock[NDBLOCK];
  124. Off iblocks[NIBLOCK];
  125. long atime;
  126. long mtime;
  127. };
  128. /*
  129. * derived constants
  130. */
  131. enum {
  132. BUFSIZE = RBUFSIZE - sizeof(Tag),
  133. DIRPERBUF = BUFSIZE / sizeof(Dentry),
  134. INDPERBUF = BUFSIZE / sizeof(Off),
  135. FEPERBUF = (BUFSIZE-sizeof(Super1)-sizeof(Off)) / sizeof(Off),
  136. SMALLBUF = MAXMSG,
  137. LARGEBUF = MAXMSG+MAXDAT+256,
  138. RAGAP = (300*1024)/BUFSIZE, /* readahead parameter */
  139. BKPERBLK = 10,
  140. CEPERBK = (BUFSIZE - BKPERBLK*sizeof(Off)) /
  141. (sizeof(Centry)*BKPERBLK),
  142. };
  143. /*
  144. * send/recv queue structure
  145. */
  146. struct Queue
  147. {
  148. QLock; /* to manipulate values */
  149. Rendez empty;
  150. Rendez full;
  151. int waitedfor; /* flag */
  152. char* name; /* for debugging */
  153. int size; /* size of queue */
  154. int loc; /* circular pointer */
  155. int count; /* how many in queue */
  156. void* args[1]; /* list of saved pointers, [->size] */
  157. };
  158. struct Device
  159. {
  160. uchar type;
  161. uchar init;
  162. Device* link; /* link for mcat/mlev/mirror */
  163. Device* dlink; /* link all devices */
  164. void* private;
  165. Devsize size;
  166. union {
  167. struct { /* disk, (l)worm in j.j, sides */
  168. int ctrl; /* disks only */
  169. int targ;
  170. int lun; /* not implemented in sd(3) */
  171. int mapped;
  172. char* file; /* ordinary file or dir instead */
  173. int fd;
  174. char* sddir; /* /dev/sdXX name, for juke drives */
  175. char* sddata; /* /dev/sdXX/data or other file */
  176. } wren;
  177. struct { /* mcat mlev mirror */
  178. Device* first;
  179. Device* last;
  180. int ndev;
  181. } cat;
  182. struct { /* cw */
  183. Device* c; /* cache device */
  184. Device* w; /* worm device */
  185. Device* ro; /* dump - readonly */
  186. } cw;
  187. struct { /* juke */
  188. Device* j; /* (robotics, worm drives) - wrens */
  189. Device* m; /* (sides) - r or l devices */
  190. } j;
  191. struct { /* ro */
  192. Device* parent;
  193. } ro;
  194. struct { /* fworm */
  195. Device* fw;
  196. } fw;
  197. struct { /* part */
  198. Device* d;
  199. long base; /* percentages */
  200. long size;
  201. } part;
  202. struct { /* byte-swapped */
  203. Device* d;
  204. } swab;
  205. };
  206. };
  207. typedef struct Sidestarts {
  208. Devsize sstart; /* blocks before start of side */
  209. Devsize s1start; /* blocks before start of next side */
  210. } Sidestarts;
  211. union Rabuf {
  212. struct {
  213. Device* dev;
  214. Off addr;
  215. };
  216. Rabuf* link;
  217. };
  218. struct Hiob
  219. {
  220. Iobuf* link;
  221. Lock;
  222. };
  223. /* a 9P connection */
  224. struct Chan
  225. {
  226. char type; /* major driver type i.e. Dev* */
  227. int (*protocol)(Msgbuf*); /* version */
  228. int msize; /* version */
  229. char whochan[50];
  230. char whoname[NAMELEN];
  231. void (*whoprint)(Chan*);
  232. ulong flags;
  233. int chan; /* overall channel #, mostly for printing */
  234. int nmsgs; /* outstanding messages, set under flock -- for flush */
  235. Timet whotime;
  236. int nfile; /* used by cmd_files */
  237. RWLock reflock;
  238. Chan* next; /* link list of chans */
  239. Queue* send;
  240. Queue* reply;
  241. uchar authinfo[64];
  242. void* pdata; /* sometimes is a Netconn* */
  243. };
  244. struct Filsys
  245. {
  246. char* name; /* name of filsys */
  247. char* conf; /* symbolic configuration */
  248. Device* dev; /* device that filsys is on */
  249. int flags;
  250. #define FREAM (1<<0) /* mkfs */
  251. #define FRECOVER (1<<1) /* install last dump */
  252. #define FEDIT (1<<2) /* modified */
  253. };
  254. struct Startsb
  255. {
  256. char* name;
  257. Off startsb;
  258. };
  259. struct Time
  260. {
  261. Timet lasttoy;
  262. Timet offset;
  263. };
  264. /*
  265. * array of qids that are locked
  266. */
  267. struct Tlock
  268. {
  269. Device* dev;
  270. Timet time;
  271. Off qpath;
  272. File* file;
  273. };
  274. struct Cons
  275. {
  276. ulong flags; /* overall flags for all channels */
  277. QLock; /* generic qlock for mutex */
  278. int uid; /* botch -- used to get uid on cons_create */
  279. int gid; /* botch -- used to get gid on cons_create */
  280. int nuid; /* number of uids */
  281. int ngid; /* number of gids */
  282. Off offset; /* used to read files, c.f. fchar */
  283. int chano; /* generator for channel numbers */
  284. Chan* chan; /* console channel */
  285. Filsys* curfs; /* current filesystem */
  286. int profile; /* are we profiling? */
  287. long* profbuf;
  288. ulong minpc;
  289. ulong maxpc;
  290. ulong nprofbuf;
  291. long nlarge; /* number of large message buffers */
  292. long nsmall; /* ... small ... */
  293. long nwormre; /* worm read errors */
  294. long nwormwe; /* worm write errors */
  295. long nwormhit; /* worm read cache hits */
  296. long nwormmiss; /* worm read cache non-hits */
  297. int noage; /* dont update cache age, dump and check */
  298. long nwrenre; /* disk read errors */
  299. long nwrenwe; /* disk write errors */
  300. long nreseq; /* cache bucket resequence */
  301. // Filter work[3]; /* thruput in messages */
  302. // Filter rate[3]; /* thruput in bytes */
  303. // Filter bhit[3]; /* getbufs that hit */
  304. // Filter bread[3]; /* getbufs that miss and read */
  305. // Filter brahead[3]; /* messages to readahead */
  306. // Filter binit[3]; /* getbufs that miss and dont read */
  307. };
  308. struct File
  309. {
  310. QLock;
  311. Qid qid;
  312. Wpath* wpath;
  313. Chan* cp; /* null means a free slot */
  314. Tlock* tlock; /* if file is locked */
  315. File* next; /* in cp->flist */
  316. Filsys* fs;
  317. Off addr;
  318. long slot; /* ordinal # of Dentry with a directory block */
  319. Off lastra; /* read ahead address */
  320. ulong fid;
  321. Userid uid;
  322. Auth *auth;
  323. char open;
  324. #define FREAD 1
  325. #define FWRITE 2
  326. #define FREMOV 4
  327. Off doffset; /* directory reading */
  328. ulong dvers;
  329. long dslot;
  330. };
  331. struct Wpath
  332. {
  333. Wpath* up; /* pointer upwards in path */
  334. Off addr; /* directory entry addr */
  335. long slot; /* directory entry slot */
  336. short refs; /* number of files using this structure */
  337. };
  338. struct Iobuf
  339. {
  340. QLock;
  341. Device* dev;
  342. Iobuf* fore; /* for lru */
  343. Iobuf* back; /* for lru */
  344. char* iobuf; /* only active while locked */
  345. char* xiobuf; /* "real" buffer pointer */
  346. Off addr;
  347. int flags;
  348. };
  349. struct Uid
  350. {
  351. Userid uid; /* user id */
  352. Userid lead; /* leader of group */
  353. Userid *gtab; /* group table */
  354. int ngrp; /* number of group entries */
  355. char name[NAMELEN]; /* user name */
  356. };
  357. /* DONT TOUCH, this is the disk structure */
  358. struct Fbuf
  359. {
  360. Off nfree;
  361. Off free[FEPERBUF];
  362. };
  363. /* DONT TOUCH, this is the disk structure */
  364. struct Superb
  365. {
  366. Fbuf fbuf;
  367. Super1;
  368. };
  369. struct Conf
  370. {
  371. ulong nmach; /* processors */
  372. ulong mem; /* total physical bytes of memory */
  373. ulong nuid; /* distinct uids */
  374. ulong nserve; /* server processes */
  375. ulong nfile; /* number of fid -- system wide */
  376. ulong nwpath; /* number of active paths, derived from nfile */
  377. ulong gidspace; /* space for gid names -- derived from nuid */
  378. ulong nlgmsg; /* number of large message buffers */
  379. ulong nsmmsg; /* number of small message buffers */
  380. Off recovcw; /* recover addresses */
  381. Off recovro;
  382. Off firstsb;
  383. Off recovsb;
  384. ulong configfirst; /* configure before starting normal operation */
  385. char *confdev;
  386. char *devmap; /* name of config->file device mapping file */
  387. ulong nauth; /* number of Auth structs */
  388. uchar nodump; /* no periodic dumps */
  389. uchar dumpreread; /* read and compare in dump copy */
  390. };
  391. enum {
  392. Mbmagic = 0xb0ffe3,
  393. };
  394. /*
  395. * message buffers
  396. * 2 types, large and small
  397. */
  398. struct Msgbuf
  399. {
  400. ulong magic;
  401. short count;
  402. short flags;
  403. #define LARGE (1<<0)
  404. #define FREE (1<<1)
  405. #define BFREE (1<<2)
  406. #define BTRACE (1<<7)
  407. Chan* chan; /* file server conn within a net. conn */
  408. Msgbuf* next;
  409. uintptr param; /* misc. use; keep Conn* here */
  410. int category;
  411. uchar* data; /* rp or wp: current processing point */
  412. uchar* xdata; /* base of allocation */
  413. };
  414. /*
  415. * message buffer categories
  416. */
  417. enum
  418. {
  419. Mxxx = 0,
  420. Mbeth1,
  421. Mbreply1,
  422. Mbreply2,
  423. Mbreply3,
  424. Mbreply4,
  425. MAXCAT,
  426. };
  427. enum { PRINTSIZE = 256 };
  428. struct
  429. {
  430. Lock;
  431. int machs;
  432. int exiting;
  433. } active;
  434. struct Command
  435. {
  436. char* arg0;
  437. char* help;
  438. void (*func)(int, char*[]);
  439. };
  440. struct Flag
  441. {
  442. char* arg0;
  443. char* help;
  444. ulong flag;
  445. };
  446. struct Rtc
  447. {
  448. int sec;
  449. int min;
  450. int hour;
  451. int mday;
  452. int mon;
  453. int year;
  454. };
  455. typedef struct
  456. {
  457. /* constants during a given truncation */
  458. Dentry *d;
  459. Iobuf *p; /* the block containing *d */
  460. int uid;
  461. Off newsize;
  462. Off lastblk; /* last data block of file to keep */
  463. /* variables */
  464. Off relblk; /* # of current data blk within file */
  465. int pastlast; /* have we walked past lastblk? */
  466. int err;
  467. } Truncstate;
  468. /*
  469. * cw device
  470. */
  471. /* DONT TOUCH, this is the disk structure */
  472. struct Cache
  473. {
  474. Off maddr; /* cache map addr */
  475. Off msize; /* cache map size in buckets */
  476. Off caddr; /* cache addr */
  477. Off csize; /* cache size */
  478. Off fsize; /* current size of worm */
  479. Off wsize; /* max size of the worm */
  480. Off wmax; /* highwater write */
  481. Off sbaddr; /* super block addr */
  482. Off cwraddr; /* cw root addr */
  483. Off roraddr; /* dump root addr */
  484. Timet toytime; /* somewhere convienent */
  485. Timet time;
  486. };
  487. /* DONT TOUCH, this is the disk structure */
  488. struct Bucket
  489. {
  490. long agegen; /* generator for ages in this bkt */
  491. Centry entry[CEPERBK];
  492. };
  493. /* DONT TOUCH, this is in disk structures */
  494. enum { Labmagic = 0xfeedfacedeadbeefULL, };
  495. /* DONT TOUCH, this is the disk structure */
  496. typedef struct Label Label;
  497. struct Label /* label block on Devlworms, in last block */
  498. {
  499. uvlong magic;
  500. ushort ord; /* side number within Juke */
  501. char service[64]; /* documentation only */
  502. };
  503. typedef struct Map Map;
  504. struct Map {
  505. char *from;
  506. Device *fdev;
  507. char *to;
  508. Device *tdev;
  509. Map *next;
  510. };
  511. /*
  512. * scsi i/o
  513. */
  514. enum
  515. {
  516. SCSIread = 0,
  517. SCSIwrite = 1,
  518. };
  519. /*
  520. * Process states
  521. */
  522. enum
  523. {
  524. Dead = 0,
  525. Moribund,
  526. Zombie,
  527. Ready,
  528. Scheding,
  529. Running,
  530. Queueing,
  531. Sending,
  532. Recving,
  533. MMUing,
  534. Exiting,
  535. Inwait,
  536. Wakeme,
  537. Broken,
  538. };
  539. /*
  540. * devnone block numbers
  541. */
  542. enum
  543. {
  544. Cwio1 = 1,
  545. Cwio2,
  546. Cwxx1,
  547. Cwxx2,
  548. Cwxx3,
  549. Cwxx4,
  550. Cwdump1,
  551. Cwdump2,
  552. Cuidbuf,
  553. Cckbuf,
  554. };
  555. /*
  556. * error codes generated from the file server
  557. */
  558. enum
  559. {
  560. Ebadspc = 1,
  561. Efid,
  562. Echar,
  563. Eopen,
  564. Ecount,
  565. Ealloc,
  566. Eqid,
  567. Eaccess,
  568. Eentry,
  569. Emode,
  570. Edir1,
  571. Edir2,
  572. Ephase,
  573. Eexist,
  574. Edot,
  575. Eempty,
  576. Ebadu,
  577. Enoattach,
  578. Ewstatb,
  579. Ewstatd,
  580. Ewstatg,
  581. Ewstatl,
  582. Ewstatm,
  583. Ewstato,
  584. Ewstatp,
  585. Ewstatq,
  586. Ewstatu,
  587. Ewstatv,
  588. Ename,
  589. Ewalk,
  590. Eronly,
  591. Efull,
  592. Eoffset,
  593. Elocked,
  594. Ebroken,
  595. Eauth,
  596. Eauth2,
  597. Efidinuse,
  598. Etoolong,
  599. Econvert,
  600. Eversion,
  601. Eauthdisabled,
  602. Eauthnone,
  603. Eauthfile,
  604. Eedge,
  605. MAXERR
  606. };
  607. /*
  608. * device types
  609. */
  610. enum
  611. {
  612. Devnone = 0,
  613. Devcon, /* console */
  614. Devwren, /* disk drive */
  615. Devworm, /* scsi optical drive */
  616. Devlworm, /* scsi optical drive (labeled) */
  617. Devfworm, /* fake read-only device */
  618. Devjuke, /* scsi jukebox */
  619. Devcw, /* cache with worm */
  620. Devro, /* readonly worm */
  621. Devmcat, /* multiple cat devices */
  622. Devmlev, /* multiple interleave devices */
  623. Devnet, /* network connection */
  624. Devpart, /* partition */
  625. Devfloppy, /* floppy drive */
  626. Devswab, /* swab data between mem and device */
  627. Devmirr, /* mirror devices */
  628. MAXDEV
  629. };
  630. /*
  631. * tags on block
  632. */
  633. /* DONT TOUCH, this is in disk structures */
  634. /* also, the order from Tdir to Tmaxind is exploited in indirck() & isdirty() */
  635. enum
  636. {
  637. Tnone = 0,
  638. Tsuper, /* the super block */
  639. #ifdef COMPAT32
  640. Tdir, /* directory contents */
  641. Tind1, /* points to blocks */
  642. Tind2, /* points to Tind1 */
  643. #else
  644. Tdirold,
  645. Tind1old,
  646. Tind2old,
  647. #endif
  648. Tfile, /* file contents; also defined in disk.h */
  649. Tfree, /* in free list */
  650. Tbuck, /* cache fs bucket */
  651. Tvirgo, /* fake worm virgin bits */
  652. Tcache, /* cw cache things */
  653. Tconfig, /* configuration block */
  654. #ifndef COMPAT32
  655. /* Tdir & indirect blocks are last, to allow for greater depth */
  656. Tdir, /* directory contents */
  657. Tind1, /* points to blocks */
  658. Tind2, /* points to Tind1 */
  659. Tind3, /* points to Tind2 */
  660. Tind4, /* points to Tind3 */
  661. Maxtind,
  662. #endif
  663. /* gap for more indirect block depth in future */
  664. Tlabel = 32, /* Devlworm label in last block */
  665. MAXTAG,
  666. #ifdef COMPAT32
  667. Tmaxind = Tind2,
  668. #else
  669. Tmaxind = Maxtind - 1,
  670. #endif
  671. };
  672. /*
  673. * flags to getbuf
  674. */
  675. enum
  676. {
  677. Brd = (1<<0), /* read the block if miss */
  678. Bprobe = (1<<1), /* return null if miss */
  679. Bmod = (1<<2), /* buffer is dirty, needs writing */
  680. Bimm = (1<<3), /* write immediately on putbuf */
  681. Bres = (1<<4), /* reserved, never renamed */
  682. };
  683. Conf conf;
  684. Cons cons;
  685. #pragma varargck type "Z" Device*
  686. #pragma varargck type "T" Timet
  687. #pragma varargck type "I" uchar*
  688. #pragma varargck type "E" uchar*
  689. #pragma varargck type "G" int
  690. extern char *annstrs[];
  691. extern Biobuf bin;
  692. extern Map *devmap;
  693. extern int (*fsprotocol[])(Msgbuf*);