2 * fundamental constants and types of the implementation
3 * changing any of these changes the layout on disk
6 SUPER_ADDR = 2, /* block address of superblock */
7 ROOT_ADDR = 3, /* block address of root directory */
10 /* more fundamental types */
11 typedef vlong Wideoff; /* type to widen Off to for printing; ≥ as wide as Off */
12 typedef short Userid; /* signed internal representation of user-id */
13 typedef long Timet; /* in seconds since epoch */
14 typedef vlong Devsize; /* in bytes */
18 #define NEXT(x, l) (((x)+1) % (l))
19 #define PREV(x, l) ((x) == 0? (l)-1: (x)-1)
20 #define HOWMANY(x, y) (((x)+((y)-1)) / (y))
21 #define ROUNDUP(x, y) (HOWMANY((x), (y)) * (y))
23 #define TK2MS(t) (((ulong)(t)*1000)/HZ) /* ticks to ms - beware rounding */
24 #define MS2TK(t) (((ulong)(t)*HZ)/1000) /* ms to ticks - beware rounding */
25 #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
27 /* constants that don't affect disk layout */
29 MAXDAT = 8192, /* max allowable data message */
30 MAXMSG = 128, /* max protocol message sans data */
34 HZ = 1, /* clock frequency */
41 Maxword = 256, /* max bytes per command-line word */
42 NTLOCK = 200, /* number of active file Tlocks */
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;
77 typedef struct Uid Uid;
78 typedef struct Wpath Wpath;
82 /* DONT TOUCH, this is the disk structure */
85 short pad; /* make tag end at a long boundary */
90 /* DONT TOUCH, this is the disk structure */
93 Off path; /* was long */
94 ulong version; /* should be Off */
97 /* DONT TOUCH, this is the disk structure */
103 Off qidgen; /* generator for unique ids */
105 * Stuff for WWC device
107 Off cwraddr; /* cfs root addr */
108 Off roraddr; /* dump root addr */
109 Off last; /* last super block addr */
110 Off next; /* next super block addr */
113 /* DONT TOUCH, this is the disk structure */
118 Off waddr; /* worm addr */
121 /* DONT TOUCH, this is the disk structure */
128 #define DALLOC 0x8000
140 Off iblocks[NIBLOCK];
151 BUFSIZE = RBUFSIZE - sizeof(Tag),
152 DIRPERBUF = BUFSIZE / sizeof(Dentry),
153 INDPERBUF = BUFSIZE / sizeof(Off),
154 FEPERBUF = (BUFSIZE-sizeof(Super1)-sizeof(Off)) / sizeof(Off),
156 LARGEBUF = MAXMSG+MAXDAT+256,
157 RAGAP = (300*1024)/BUFSIZE, /* readahead parameter */
159 CEPERBK = (BUFSIZE - BKPERBLK*sizeof(Off)) /
160 (sizeof(Centry)*BKPERBLK),
164 * send/recv queue structure
168 char* name; /* for debugging */
170 int size; /* size of queue */
172 long count; /* how many in queue (semaphore) */
173 long avail; /* how many available to send (semaphore) */
175 Lock rl, wl; /* circular pointers */
179 void* args[1]; /* list of saved pointers, [->size] */
186 Device* link; /* link for mcat/mlev/mirror */
187 Device* dlink; /* link all devices */
191 struct { /* disk, (l)worm in j.j, sides */
192 int ctrl; /* disks only */
194 int lun; /* not implemented in sd(3) */
197 char* file; /* ordinary file or dir instead */
200 char* sddir; /* /dev/sdXX name, for juke drives */
201 char* sddata; /* /dev/sdXX/data or other file */
203 struct { /* mcat mlev mirror */
209 Device* c; /* cache device */
210 Device* w; /* worm device */
211 Device* ro; /* dump - readonly */
214 Device* j; /* (robotics, worm drives) - wrens */
215 Device* m; /* (sides) - r or l devices */
225 long base; /* percentages */
228 struct { /* byte-swapped */
234 typedef struct Sidestarts {
235 Devsize sstart; /* blocks before start of side */
236 Devsize s1start; /* blocks before start of next side */
253 /* a 9P connection */
256 int (*protocol)(Msgbuf*); /* version */
257 int msize; /* version */
259 char whoname[NAMELEN];
260 void (*whoprint)(Chan*);
262 int chan; /* overall channel #, mostly for printing */
263 int nmsgs; /* outstanding messages, set under flock -- for flush */
266 int nfile; /* used by cmd_files */
269 Chan* next; /* link list of chans */
276 void* pdata; /* sometimes is a Netconn* */
283 char* name; /* name of filsys */
284 char* conf; /* symbolic configuration */
285 Device* dev; /* device that filsys is on */
287 #define FREAM (1<<0) /* mkfs */
288 #define FRECOVER (1<<1) /* install last dump */
289 #define FEDIT (1<<2) /* modified */
305 * array of qids that are locked
317 ulong flags; /* overall flags for all channels */
318 QLock; /* generic qlock for mutex */
319 int uid; /* botch -- used to get uid on cons_create */
320 int gid; /* botch -- used to get gid on cons_create */
321 int nuid; /* number of uids */
322 int ngid; /* number of gids */
323 Off offset; /* used to read files, c.f. fchar */
324 int chano; /* generator for channel numbers */
325 Chan* chan; /* console channel */
326 Filsys* curfs; /* current filesystem */
328 int profile; /* are we profiling? */
334 long nlarge; /* number of large message buffers */
335 long nsmall; /* ... small ... */
336 long nwormre; /* worm read errors */
337 long nwormwe; /* worm write errors */
338 long nwormhit; /* worm read cache hits */
339 long nwormmiss; /* worm read cache non-hits */
340 int noage; /* dont update cache age, dump and check */
341 long nwrenre; /* disk read errors */
342 long nwrenwe; /* disk write errors */
343 long nreseq; /* cache bucket resequence */
345 // Filter work[3]; /* thruput in messages */
346 // Filter rate[3]; /* thruput in bytes */
347 // Filter bhit[3]; /* getbufs that hit */
348 // Filter bread[3]; /* getbufs that miss and read */
349 // Filter brahead[3]; /* messages to readahead */
350 // Filter binit[3]; /* getbufs that miss and dont read */
358 Chan* cp; /* null means a free slot */
359 Tlock* tlock; /* if file is locked */
360 File* next; /* in cp->flist */
363 long slot; /* ordinal # of Dentry with a directory block */
364 Off lastra; /* read ahead address */
373 Off doffset; /* directory reading */
380 Wpath* up; /* pointer upwards in path */
381 Off addr; /* directory entry addr */
382 long slot; /* directory entry slot */
383 short refs; /* number of files using this structure */
390 Iobuf* fore; /* for lru */
391 Iobuf* back; /* for lru */
392 char* iobuf; /* only active while locked */
393 char* xiobuf; /* "real" buffer pointer */
400 Userid uid; /* user id */
401 Userid lead; /* leader of group */
402 Userid *gtab; /* group table */
403 int ngrp; /* number of group entries */
404 char name[NAMELEN]; /* user name */
409 /* DONT TOUCH, this is the disk structure */
416 /* DONT TOUCH, this is the disk structure */
427 ulong nmach; /* processors */
428 ulong nuid; /* distinct uids */
429 ulong nserve; /* server processes */
430 ulong nfile; /* number of fid -- system wide */
431 ulong nwpath; /* number of active paths, derived from nfile */
432 ulong gidspace; /* space for gid names -- derived from nuid */
434 ulong nlgmsg; /* number of large message buffers */
435 ulong nsmmsg; /* number of small message buffers */
437 Off recovcw; /* recover addresses */
442 ulong configfirst; /* configure before starting normal operation */
444 char *devmap; /* name of config->file device mapping file */
446 uchar nodump; /* no periodic dumps */
447 uchar dumpreread; /* read and compare in dump copy */
457 * 2 types, large and small
467 #define BTRACE (1<<7)
468 Chan* chan; /* file server conn within a net. conn */
470 uintptr param; /* misc. use; keep Conn* here */
473 uchar* data; /* rp or wp: current processing point */
474 uchar* xdata; /* base of allocation */
478 * message buffer categories
491 enum { PRINTSIZE = 256 };
504 void (*func)(int, char*[]);
526 /* constants during a given truncation */
528 Iobuf *p; /* the block containing *d */
531 Off lastblk; /* last data block of file to keep */
534 Off relblk; /* # of current data blk within file */
535 int pastlast; /* have we walked past lastblk? */
544 /* DONT TOUCH, this is the disk structure */
547 Off maddr; /* cache map addr */
548 Off msize; /* cache map size in buckets */
549 Off caddr; /* cache addr */
550 Off csize; /* cache size */
551 Off fsize; /* current size of worm */
552 Off wsize; /* max size of the worm */
553 Off wmax; /* highwater write */
555 Off sbaddr; /* super block addr */
556 Off cwraddr; /* cw root addr */
557 Off roraddr; /* dump root addr */
559 Timet toytime; /* somewhere convienent */
563 /* DONT TOUCH, this is the disk structure */
566 long agegen; /* generator for ages in this bkt */
567 Centry entry[CEPERBK];
570 /* DONT TOUCH, this is in disk structures */
571 enum { Labmagic = 0xfeedfacedeadbeefULL, };
573 /* DONT TOUCH, this is the disk structure */
574 typedef struct Label Label;
575 struct Label /* label block on Devlworms, in last block */
578 ushort ord; /* side number within Juke */
579 char service[64]; /* documentation only */
584 typedef struct Map Map;
624 * devnone block numbers
642 * error codes generated from the file server
700 Devwren, /* disk drive */
701 Devworm, /* scsi optical drive */
702 Devlworm, /* scsi optical drive (labeled) */
703 Devfworm, /* fake read-only device */
704 Devjuke, /* scsi jukebox */
705 Devcw, /* cache with worm */
706 Devro, /* readonly worm */
707 Devmcat, /* multiple cat devices */
708 Devmlev, /* multiple interleave devices */
709 Devnet, /* network connection */
710 Devpart, /* partition */
711 Devfloppy, /* floppy drive */
712 Devswab, /* swab data between mem and device */
713 Devmirr, /* mirror devices */
720 /* DONT TOUCH, this is in disk structures */
721 /* also, the order from Tdir to Tmaxind is exploited in indirck() & isdirty() */
725 Tsuper, /* the super block */
727 Tdir, /* directory contents */
728 Tind1, /* points to blocks */
729 Tind2, /* points to Tind1 */
735 Tfile, /* file contents; also defined in disk.h */
736 Tfree, /* in free list */
737 Tbuck, /* cache fs bucket */
738 Tvirgo, /* fake worm virgin bits */
739 Tcache, /* cw cache things */
740 Tconfig, /* configuration block */
742 /* Tdir & indirect blocks are last, to allow for greater depth */
743 Tdir, /* directory contents */
744 Tind1, /* points to blocks */
745 Tind2, /* points to Tind1 */
746 Tind3, /* points to Tind2 */
747 Tind4, /* points to Tind3 */
750 /* gap for more indirect block depth in future */
751 Tlabel = 32, /* Devlworm label in last block */
757 Tmaxind = Maxtind - 1,
766 Brd = (1<<0), /* read the block if miss */
767 Bprobe = (1<<1), /* return null if miss */
768 Bmod = (1<<2), /* buffer is dirty, needs writing */
769 Bimm = (1<<3), /* write immediately on putbuf */
770 Bres = (1<<4), /* reserved, never renamed */
776 #pragma varargck type "Z" Device*
777 #pragma varargck type "T" Timet
778 #pragma varargck type "I" uchar*
779 #pragma varargck type "E" uchar*
780 #pragma varargck type "G" int
782 extern char *annstrs[];
785 extern int (*fsprotocol[])(Msgbuf*);