]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/cwfs/portdat.h
audiohda: fix syntax error
[plan9front.git] / sys / src / cmd / cwfs / portdat.h
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
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 */
15
16
17 /* macros */
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))
22
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 */
26
27 /* constants that don't affect disk layout */
28 enum {
29         MAXDAT          = 8192,         /* max allowable data message */
30         MAXMSG          = 128,          /* max protocol message sans data */
31
32         MB              = 1024*1024,
33
34         HZ              = 1,            /* clock frequency */
35 };
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
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
80 #pragma pack on
81
82 /* DONT TOUCH, this is the disk structure */
83 struct  Tag
84 {
85         short   pad;            /* make tag end at a long boundary */
86         short   tag;
87         Off     path;
88 };
89
90 /* DONT TOUCH, this is the disk structure */
91 struct  Qid9p1
92 {
93         Off     path;                   /* was long */
94         ulong   version;                /* should be Off */
95 };
96
97 /* DONT TOUCH, this is the disk structure */
98 struct  Super1
99 {
100         Off     fstart;
101         Off     fsize;
102         Off     tfree;
103         Off     qidgen;         /* generator for unique ids */
104         /*
105          * Stuff for WWC device
106          */
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 */
111 };
112
113 /* DONT TOUCH, this is the disk structure */
114 struct  Centry
115 {
116         ushort  age;
117         short   state;
118         Off     waddr;          /* worm addr */
119 };
120
121 /* DONT TOUCH, this is the disk structure */
122 struct  Dentry
123 {
124         char    name[NAMELEN];
125         Userid  uid;
126         Userid  gid;
127         ushort  mode;
128                 #define DALLOC  0x8000
129                 #define DDIR    0x4000
130                 #define DAPND   0x2000
131                 #define DLOCK   0x1000
132                 #define DTMP    0x0800
133                 #define DREAD   0x4
134                 #define DWRITE  0x2
135                 #define DEXEC   0x1
136         Userid  muid;
137         Qid9p1  qid;
138         Off     size;
139         Off     dblock[NDBLOCK];
140         Off     iblocks[NIBLOCK];
141         long    atime;
142         long    mtime;
143 };
144
145 #pragma pack off
146
147 /*
148  * derived constants
149  */
150 enum {
151         BUFSIZE         = RBUFSIZE - sizeof(Tag),
152         DIRPERBUF       = BUFSIZE / sizeof(Dentry),
153         INDPERBUF       = BUFSIZE / sizeof(Off),
154         FEPERBUF        = (BUFSIZE-sizeof(Super1)-sizeof(Off)) / sizeof(Off),
155         SMALLBUF        = MAXMSG,
156         LARGEBUF        = MAXMSG+MAXDAT+256,
157         RAGAP           = (300*1024)/BUFSIZE,   /* readahead parameter */
158         BKPERBLK        = 10,
159         CEPERBK         = (BUFSIZE - BKPERBLK*sizeof(Off)) /
160                                 (sizeof(Centry)*BKPERBLK),
161 };
162
163 /*
164  * send/recv queue structure
165  */
166 struct  Queue
167 {
168         char*   name;           /* for debugging */
169
170         int     size;           /* size of queue */
171
172         long    count;          /* how many in queue (semaphore) */
173         long    avail;          /* how many available to send (semaphore) */
174
175         Lock    rl, wl;         /* circular pointers */
176         void    **rp;
177         void    **wp;
178
179         void*   args[1];        /* list of saved pointers, [->size] */
180 };
181
182 struct  Device
183 {
184         uchar   type;
185         uchar   init;
186         Device* link;                   /* link for mcat/mlev/mirror */
187         Device* dlink;                  /* link all devices */
188         void*   private;
189         Devsize size;
190         union {
191                 struct {                /* disk, (l)worm in j.j, sides */
192                         int     ctrl;   /* disks only */
193                         int     targ;
194                         int     lun;    /* not implemented in sd(3) */
195
196                         int     mapped;
197                         char*   file;   /* ordinary file or dir instead */
198
199                         int     fd;
200                         char*   sddir;  /* /dev/sdXX name, for juke drives */
201                         char*   sddata; /* /dev/sdXX/data or other file */
202                 } wren;
203                 struct {                /* mcat mlev mirror */
204                         Device* first;
205                         Device* last;
206                         int     ndev;
207                 } cat;
208                 struct {                /* cw */
209                         Device* c;      /* cache device */
210                         Device* w;      /* worm device */
211                         Device* ro;     /* dump - readonly */
212                 } cw;
213                 struct {                /* juke */
214                         Device* j;      /* (robotics, worm drives) - wrens */
215                         Device* m;      /* (sides) - r or l devices */
216                 } j;
217                 struct {                /* ro */
218                         Device* parent;
219                 } ro;
220                 struct {                /* fworm */
221                         Device* fw;
222                 } fw;
223                 struct {                /* part */
224                         Device* d;
225                         long    base;   /* percentages */
226                         long    size;
227                 } part;
228                 struct {                /* byte-swapped */
229                         Device* d;
230                 } swab;
231         };
232 };
233
234 typedef struct Sidestarts {
235         Devsize sstart;                 /* blocks before start of side */
236         Devsize s1start;                /* blocks before start of next side */
237 } Sidestarts;
238
239 union Rabuf {
240         struct {
241                 Device* dev;
242                 Off     addr;
243         };
244         Rabuf*  link;
245 };
246
247 struct  Hiob
248 {
249         Iobuf*  link;
250         Lock;
251 };
252
253 /* a 9P connection */
254 struct  Chan
255 {
256         int     (*protocol)(Msgbuf*);   /* version */
257         int     msize;                  /* version */
258         char    whochan[50];
259         char    whoname[NAMELEN];
260         void    (*whoprint)(Chan*);
261         ulong   flags;
262         int     chan;                   /* overall channel #, mostly for printing */
263         int     nmsgs;                  /* outstanding messages, set under flock -- for flush */
264
265         Timet   whotime;
266         int     nfile;                  /* used by cmd_files */
267
268         RWLock  reflock;
269         Chan*   next;                   /* link list of chans */
270         Queue*  send;
271         Queue*  reply;
272
273         int     authok;
274         uchar   authinfo[64];
275
276         void*   pdata;                  /* sometimes is a Netconn* */
277
278         char    err[ERRMAX];
279 };
280
281 struct  Filsys
282 {
283         char*   name;                   /* name of filsys */
284         char*   conf;                   /* symbolic configuration */
285         Device* dev;                    /* device that filsys is on */
286         int     flags;
287                 #define FREAM           (1<<0)  /* mkfs */
288                 #define FRECOVER        (1<<1)  /* install last dump */
289                 #define FEDIT           (1<<2)  /* modified */
290 };
291
292 struct  Startsb
293 {
294         char*   name;
295         Off     startsb;
296 };
297
298 struct  Time
299 {
300         Timet   lasttoy;
301         Timet   offset;
302 };
303
304 /*
305  * array of qids that are locked
306  */
307 struct  Tlock
308 {
309         Device* dev;
310         Timet   time;
311         Off     qpath;
312         File*   file;
313 };
314
315 struct  Cons
316 {
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 */
327
328         int     profile;        /* are we profiling? */
329         long*   profbuf;
330         ulong   minpc;
331         ulong   maxpc;
332         ulong   nprofbuf;
333
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 */
344
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 */
351 };
352
353 struct  File
354 {
355         QLock;
356         Qid     qid;
357         Wpath*  wpath;
358         Chan*   cp;             /* null means a free slot */
359         Tlock*  tlock;          /* if file is locked */
360         File*   next;           /* in cp->flist */
361         Filsys* fs;
362         Off     addr;
363         long    slot;           /* ordinal # of Dentry with a directory block */
364         Off     lastra;         /* read ahead address */
365         ulong   fid;
366         Userid  uid;
367         void    *auth;
368         char    open;
369                 #define FREAD   1
370                 #define FWRITE  2
371                 #define FREMOV  4
372
373         Off     doffset;        /* directory reading */
374         ulong   dvers;
375         long    dslot;
376 };
377
378 struct  Wpath
379 {
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 */
384 };
385
386 struct  Iobuf
387 {
388         QLock;
389         Device* dev;
390         Iobuf*  fore;           /* for lru */
391         Iobuf*  back;           /* for lru */
392         char*   iobuf;          /* only active while locked */
393         char*   xiobuf;         /* "real" buffer pointer */
394         Off     addr;
395         int     flags;
396 };
397
398 struct  Uid
399 {
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 */
405 };
406
407 #pragma pack on
408
409 /* DONT TOUCH, this is the disk structure */
410 struct  Fbuf
411 {
412         Off     nfree;
413         Off     free[FEPERBUF];
414 };
415
416 /* DONT TOUCH, this is the disk structure */
417 struct  Superb
418 {
419         Fbuf    fbuf;
420         Super1;
421 };
422
423 #pragma pack off
424
425 struct  Conf
426 {
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 */
433
434         ulong   nlgmsg;         /* number of large message buffers */
435         ulong   nsmmsg;         /* number of small message buffers */
436
437         Off     recovcw;        /* recover addresses */
438         Off     recovro;
439         Off     firstsb;
440         Off     recovsb;
441
442         ulong   configfirst;    /* configure before starting normal operation */
443         char    *confdev;
444         char    *devmap;        /* name of config->file device mapping file */
445
446         uchar   nodump;         /* no periodic dumps */
447         uchar   dumpreread;     /* read and compare in dump copy */
448         uchar   newcache;
449 };
450
451 enum {
452         Mbmagic = 0xb0ffe3,
453 };
454
455 /*
456  * message buffers
457  * 2 types, large and small
458  */
459 struct  Msgbuf
460 {
461         ulong   magic;
462         short   count;
463         short   flags;
464                 #define LARGE   (1<<0)
465                 #define FREE    (1<<1)
466                 #define BFREE   (1<<2)
467                 #define BTRACE  (1<<7)
468         Chan*   chan;           /* file server conn within a net. conn */
469         Msgbuf* next;
470         uintptr param;          /* misc. use; keep Conn* here */
471
472         int     category;
473         uchar*  data;           /* rp or wp: current processing point */
474         uchar*  xdata;          /* base of allocation */
475 };
476
477 /*
478  * message buffer categories
479  */
480 enum
481 {
482         Mxxx            = 0,
483         Mbeth1,
484         Mbreply1,
485         Mbreply2,
486         Mbreply3,
487         Mbreply4,
488         MAXCAT,
489 };
490
491 enum { PRINTSIZE = 256 };
492
493 struct
494 {
495         Lock;
496         int     machs;
497         int     exiting;
498 } active;
499
500 struct  Command
501 {
502         char*   arg0;
503         char*   help;
504         void    (*func)(int, char*[]);
505 };
506
507 struct  Flag
508 {
509         char*   arg0;
510         char*   help;
511         ulong   flag;
512 };
513
514 struct  Rtc
515 {
516         int     sec;
517         int     min;
518         int     hour;
519         int     mday;
520         int     mon;
521         int     year;
522 };
523
524 typedef struct
525 {
526         /* constants during a given truncation */
527         Dentry  *d;
528         Iobuf   *p;                     /* the block containing *d */
529         int     uid;
530         Off     newsize;
531         Off     lastblk;                /* last data block of file to keep */
532
533         /* variables */
534         Off     relblk;                 /* # of current data blk within file */
535         int     pastlast;               /* have we walked past lastblk? */
536         int     err;
537 } Truncstate;
538
539 /*
540  * cw device
541  */
542 #pragma pack on
543
544 /* DONT TOUCH, this is the disk structure */
545 struct  Cache
546 {
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 */
554
555         Off     sbaddr;         /* super block addr */
556         Off     cwraddr;        /* cw root addr */
557         Off     roraddr;        /* dump root addr */
558
559         Timet   toytime;        /* somewhere convienent */
560         Timet   time;
561 };
562
563 /* DONT TOUCH, this is the disk structure */
564 struct  Bucket
565 {
566         long    agegen;         /* generator for ages in this bkt */
567         Centry  entry[CEPERBK];
568 };
569
570 /* DONT TOUCH, this is in disk structures */
571 enum { Labmagic = 0xfeedfacedeadbeefULL, };
572
573 /* DONT TOUCH, this is the disk structure */
574 typedef struct Label Label;
575 struct Label                    /* label block on Devlworms, in last block */
576 {
577         uvlong  magic;
578         ushort  ord;            /* side number within Juke */
579         char    service[64];    /* documentation only */
580 };
581
582 #pragma pack off
583
584 typedef struct Map Map;
585 struct Map {
586         char    *from;
587         Device  *fdev;
588         char    *to;
589         Device  *tdev;
590         Map     *next;
591 };
592
593 /*
594  * scsi i/o
595  */
596 enum
597 {
598         SCSIread = 0,
599         SCSIwrite = 1,
600 };
601
602 /*
603  * Process states
604  */
605 enum
606 {
607         Dead = 0,
608         Moribund,
609         Zombie,
610         Ready,
611         Scheding,
612         Running,
613         Queueing,
614         Sending,
615         Recving,
616         MMUing,
617         Exiting,
618         Inwait,
619         Wakeme,
620         Broken,
621 };
622
623 /*
624  * devnone block numbers
625  */
626 enum
627 {
628         Cwio1   = 1,
629         Cwio2,
630         Cwxx1,
631         Cwxx2,
632         Cwxx3,
633         Cwxx4,
634         Cwdump1,
635         Cwdump2,
636         Cuidbuf,
637         Cckbuf,
638         Cwtmp,
639 };
640
641 /*
642  * error codes generated from the file server
643  */
644 enum
645 {
646         Ebadspc = 1,
647         Efid,
648         Echar,
649         Eopen,
650         Ecount,
651         Ealloc,
652         Eqid,
653         Eaccess,
654         Eentry,
655         Emode,
656         Edir1,
657         Edir2,
658         Ephase,
659         Eexist,
660         Edot,
661         Eempty,
662         Ebadu,
663         Enoattach,
664         Ewstatb,
665         Ewstatd,
666         Ewstatg,
667         Ewstatl,
668         Ewstatm,
669         Ewstato,
670         Ewstatp,
671         Ewstatq,
672         Ewstatu,
673         Ewstatv,
674         Ename,
675         Ewalk,
676         Eronly,
677         Efull,
678         Eoffset,
679         Elocked,
680         Ebroken,
681         Eauth,
682         Eauth2,
683         Efidinuse,
684         Etoolong,
685         Econvert,
686         Eversion,
687         Eauthdisabled,
688         Eauthnone,
689         Eauthfile,
690         Eedge,
691         MAXERR
692 };
693
694 /*
695  * device types
696  */
697 enum
698 {
699         Devnone = 0,
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 */
714         MAXDEV
715 };
716
717 /*
718  * tags on block
719  */
720 /* DONT TOUCH, this is in disk structures */
721 /* also, the order from Tdir to Tmaxind is exploited in indirck() & isdirty() */
722 enum
723 {
724         Tnone           = 0,
725         Tsuper,                 /* the super block */
726 #ifdef COMPAT32
727         Tdir,                   /* directory contents */
728         Tind1,                  /* points to blocks */
729         Tind2,                  /* points to Tind1 */
730 #else
731         Tdirold,
732         Tind1old,
733         Tind2old,
734 #endif
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 */
741 #ifndef COMPAT32
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 */
748         Maxtind,
749 #endif
750         /* gap for more indirect block depth in future */
751         Tlabel = 32,            /* Devlworm label in last block */
752         MAXTAG,
753
754 #ifdef COMPAT32
755         Tmaxind = Tind2,
756 #else
757         Tmaxind = Maxtind - 1,
758 #endif
759 };
760
761 /*
762  * flags to getbuf
763  */
764 enum
765 {
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 */
771 };
772
773 Conf    conf;
774 Cons    cons;
775
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
781
782 extern char     *annstrs[];
783 extern Biobuf   bin;
784 extern Map      *devmap;
785 extern int      (*fsprotocol[])(Msgbuf*);
786 extern int      chatty;