portdat.h 15 KB

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