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 short pad; /* make tag end at a long boundary */
87 /* DONT TOUCH, this is the disk structure */
90 Off path; /* was long */
91 ulong version; /* should be Off */
94 /* DONT TOUCH, this is the disk structure */
100 Off qidgen; /* generator for unique ids */
102 * Stuff for WWC device
104 Off cwraddr; /* cfs root addr */
105 Off roraddr; /* dump root addr */
106 Off last; /* last super block addr */
107 Off next; /* next super block addr */
110 /* DONT TOUCH, this is the disk structure */
115 Off waddr; /* worm addr */
118 /* DONT TOUCH, this is the disk structure */
125 #define DALLOC 0x8000
137 Off iblocks[NIBLOCK];
146 BUFSIZE = RBUFSIZE - sizeof(Tag),
147 DIRPERBUF = BUFSIZE / sizeof(Dentry),
148 INDPERBUF = BUFSIZE / sizeof(Off),
149 FEPERBUF = (BUFSIZE-sizeof(Super1)-sizeof(Off)) / sizeof(Off),
151 LARGEBUF = MAXMSG+MAXDAT+256,
152 RAGAP = (300*1024)/BUFSIZE, /* readahead parameter */
154 CEPERBK = (BUFSIZE - BKPERBLK*sizeof(Off)) /
155 (sizeof(Centry)*BKPERBLK),
159 * send/recv queue structure
163 char* name; /* for debugging */
165 int size; /* size of queue */
167 long count; /* how many in queue (semaphore) */
168 long avail; /* how many available to send (semaphore) */
170 Lock rl, wl; /* circular pointers */
174 void* args[1]; /* list of saved pointers, [->size] */
181 Device* link; /* link for mcat/mlev/mirror */
182 Device* dlink; /* link all devices */
186 struct { /* disk, (l)worm in j.j, sides */
187 int ctrl; /* disks only */
189 int lun; /* not implemented in sd(3) */
192 char* file; /* ordinary file or dir instead */
195 char* sddir; /* /dev/sdXX name, for juke drives */
196 char* sddata; /* /dev/sdXX/data or other file */
198 struct { /* mcat mlev mirror */
204 Device* c; /* cache device */
205 Device* w; /* worm device */
206 Device* ro; /* dump - readonly */
209 Device* j; /* (robotics, worm drives) - wrens */
210 Device* m; /* (sides) - r or l devices */
220 long base; /* percentages */
223 struct { /* byte-swapped */
229 typedef struct Sidestarts {
230 Devsize sstart; /* blocks before start of side */
231 Devsize s1start; /* blocks before start of next side */
248 /* a 9P connection */
251 int (*protocol)(Msgbuf*); /* version */
252 int msize; /* version */
254 char whoname[NAMELEN];
255 void (*whoprint)(Chan*);
257 int chan; /* overall channel #, mostly for printing */
258 int nmsgs; /* outstanding messages, set under flock -- for flush */
261 int nfile; /* used by cmd_files */
264 Chan* next; /* link list of chans */
271 void* pdata; /* sometimes is a Netconn* */
278 char* name; /* name of filsys */
279 char* conf; /* symbolic configuration */
280 Device* dev; /* device that filsys is on */
282 #define FREAM (1<<0) /* mkfs */
283 #define FRECOVER (1<<1) /* install last dump */
284 #define FEDIT (1<<2) /* modified */
300 * array of qids that are locked
312 ulong flags; /* overall flags for all channels */
313 QLock; /* generic qlock for mutex */
314 int uid; /* botch -- used to get uid on cons_create */
315 int gid; /* botch -- used to get gid on cons_create */
316 int nuid; /* number of uids */
317 int ngid; /* number of gids */
318 Off offset; /* used to read files, c.f. fchar */
319 int chano; /* generator for channel numbers */
320 Chan* chan; /* console channel */
321 Filsys* curfs; /* current filesystem */
323 int profile; /* are we profiling? */
329 long nlarge; /* number of large message buffers */
330 long nsmall; /* ... small ... */
331 long nwormre; /* worm read errors */
332 long nwormwe; /* worm write errors */
333 long nwormhit; /* worm read cache hits */
334 long nwormmiss; /* worm read cache non-hits */
335 int noage; /* dont update cache age, dump and check */
336 long nwrenre; /* disk read errors */
337 long nwrenwe; /* disk write errors */
338 long nreseq; /* cache bucket resequence */
340 // Filter work[3]; /* thruput in messages */
341 // Filter rate[3]; /* thruput in bytes */
342 // Filter bhit[3]; /* getbufs that hit */
343 // Filter bread[3]; /* getbufs that miss and read */
344 // Filter brahead[3]; /* messages to readahead */
345 // Filter binit[3]; /* getbufs that miss and dont read */
353 Chan* cp; /* null means a free slot */
354 Tlock* tlock; /* if file is locked */
355 File* next; /* in cp->flist */
358 long slot; /* ordinal # of Dentry with a directory block */
359 Off lastra; /* read ahead address */
368 Off doffset; /* directory reading */
375 Wpath* up; /* pointer upwards in path */
376 Off addr; /* directory entry addr */
377 long slot; /* directory entry slot */
378 short refs; /* number of files using this structure */
385 Iobuf* fore; /* for lru */
386 Iobuf* back; /* for lru */
387 char* iobuf; /* only active while locked */
388 char* xiobuf; /* "real" buffer pointer */
395 Userid uid; /* user id */
396 Userid lead; /* leader of group */
397 Userid *gtab; /* group table */
398 int ngrp; /* number of group entries */
399 char name[NAMELEN]; /* user name */
402 /* DONT TOUCH, this is the disk structure */
409 /* DONT TOUCH, this is the disk structure */
418 ulong nmach; /* processors */
419 ulong nuid; /* distinct uids */
420 ulong nserve; /* server processes */
421 ulong nfile; /* number of fid -- system wide */
422 ulong nwpath; /* number of active paths, derived from nfile */
423 ulong gidspace; /* space for gid names -- derived from nuid */
425 ulong nlgmsg; /* number of large message buffers */
426 ulong nsmmsg; /* number of small message buffers */
428 Off recovcw; /* recover addresses */
433 ulong configfirst; /* configure before starting normal operation */
435 char *devmap; /* name of config->file device mapping file */
437 uchar nodump; /* no periodic dumps */
438 uchar dumpreread; /* read and compare in dump copy */
448 * 2 types, large and small
458 #define BTRACE (1<<7)
459 Chan* chan; /* file server conn within a net. conn */
461 uintptr param; /* misc. use; keep Conn* here */
464 uchar* data; /* rp or wp: current processing point */
465 uchar* xdata; /* base of allocation */
469 * message buffer categories
482 enum { PRINTSIZE = 256 };
495 void (*func)(int, char*[]);
517 /* constants during a given truncation */
519 Iobuf *p; /* the block containing *d */
522 Off lastblk; /* last data block of file to keep */
525 Off relblk; /* # of current data blk within file */
526 int pastlast; /* have we walked past lastblk? */
534 /* DONT TOUCH, this is the disk structure */
537 Off maddr; /* cache map addr */
538 Off msize; /* cache map size in buckets */
539 Off caddr; /* cache addr */
540 Off csize; /* cache size */
541 Off fsize; /* current size of worm */
542 Off wsize; /* max size of the worm */
543 Off wmax; /* highwater write */
545 Off sbaddr; /* super block addr */
546 Off cwraddr; /* cw root addr */
547 Off roraddr; /* dump root addr */
549 Timet toytime; /* somewhere convienent */
553 /* DONT TOUCH, this is the disk structure */
556 long agegen; /* generator for ages in this bkt */
557 Centry entry[CEPERBK];
560 /* DONT TOUCH, this is in disk structures */
561 enum { Labmagic = 0xfeedfacedeadbeefULL, };
563 /* DONT TOUCH, this is the disk structure */
564 typedef struct Label Label;
565 struct Label /* label block on Devlworms, in last block */
568 ushort ord; /* side number within Juke */
569 char service[64]; /* documentation only */
572 typedef struct Map Map;
612 * devnone block numbers
630 * error codes generated from the file server
688 Devwren, /* disk drive */
689 Devworm, /* scsi optical drive */
690 Devlworm, /* scsi optical drive (labeled) */
691 Devfworm, /* fake read-only device */
692 Devjuke, /* scsi jukebox */
693 Devcw, /* cache with worm */
694 Devro, /* readonly worm */
695 Devmcat, /* multiple cat devices */
696 Devmlev, /* multiple interleave devices */
697 Devnet, /* network connection */
698 Devpart, /* partition */
699 Devfloppy, /* floppy drive */
700 Devswab, /* swab data between mem and device */
701 Devmirr, /* mirror devices */
708 /* DONT TOUCH, this is in disk structures */
709 /* also, the order from Tdir to Tmaxind is exploited in indirck() & isdirty() */
713 Tsuper, /* the super block */
715 Tdir, /* directory contents */
716 Tind1, /* points to blocks */
717 Tind2, /* points to Tind1 */
723 Tfile, /* file contents; also defined in disk.h */
724 Tfree, /* in free list */
725 Tbuck, /* cache fs bucket */
726 Tvirgo, /* fake worm virgin bits */
727 Tcache, /* cw cache things */
728 Tconfig, /* configuration block */
730 /* Tdir & indirect blocks are last, to allow for greater depth */
731 Tdir, /* directory contents */
732 Tind1, /* points to blocks */
733 Tind2, /* points to Tind1 */
734 Tind3, /* points to Tind2 */
735 Tind4, /* points to Tind3 */
738 /* gap for more indirect block depth in future */
739 Tlabel = 32, /* Devlworm label in last block */
745 Tmaxind = Maxtind - 1,
754 Brd = (1<<0), /* read the block if miss */
755 Bprobe = (1<<1), /* return null if miss */
756 Bmod = (1<<2), /* buffer is dirty, needs writing */
757 Bimm = (1<<3), /* write immediately on putbuf */
758 Bres = (1<<4), /* reserved, never renamed */
764 #pragma varargck type "Z" Device*
765 #pragma varargck type "T" Timet
766 #pragma varargck type "I" uchar*
767 #pragma varargck type "E" uchar*
768 #pragma varargck type "G" int
770 extern char *annstrs[];
773 extern int (*fsprotocol[])(Msgbuf*);