typedef struct Alarms Alarms; typedef struct Block Block; typedef struct Chan Chan; typedef struct Crypt Crypt; typedef struct Dev Dev; typedef struct Dirtab Dirtab; typedef struct Egrp Egrp; typedef struct Evalue Evalue; typedef struct Fgrp Fgrp; typedef struct Image Image; typedef struct IOQ IOQ; typedef struct KIOQ KIOQ; typedef struct List List; typedef struct Mount Mount; typedef struct Mntrpc Mntrpc; typedef struct Mntwalk Mntwalk; typedef struct Mnt Mnt; typedef struct Mhead Mhead; typedef struct Note Note; typedef struct Page Page; typedef struct Path Path; typedef struct Palloc Palloc; typedef struct Pgrps Pgrps; typedef struct Pgrp Pgrp; typedef struct Physseg Physseg; typedef struct Proc Proc; typedef struct Pte Pte; typedef struct Pthash Pthash; typedef struct QLock QLock; typedef struct Queue Queue; typedef struct Ref Ref; typedef struct Rendez Rendez; typedef struct RWlock RWlock; typedef struct Sargs Sargs; typedef struct Scsi Scsi; typedef struct Scsibuf Scsibuf; typedef struct Scsidata Scsidata; typedef struct Segment Segment; typedef struct Session Session; typedef struct Talarm Talarm; typedef struct Waitq Waitq; typedef int Devgen(Chan*, Dirtab*, int, int, Dir*); #include #include struct Ref { Lock; long ref; }; struct Rendez { Lock; Proc *p; }; struct QLock { Lock use; /* to access Qlock structure */ Proc *head; /* next process waiting for object */ Proc *tail; /* last process waiting for object */ int locked; /* flag */ }; struct RWlock { Lock; /* Lock modify lock */ QLock x; /* Mutual exclusion lock */ QLock k; /* Lock for waiting writers */ int readers; /* Count of readers in lock */ }; struct Talarm { Lock; Proc *list; }; struct Alarms { QLock; Proc *head; }; #define MAXSYSARG 5 /* for mount(fd, mpt, flag, arg, srv) */ struct Sargs { ulong args[MAXSYSARG]; }; /* * Access types in namec & channel flags */ enum { Aaccess, /* as in access, stat */ Atodir, /* as in chdir */ Aopen, /* for i/o */ Amount, /* to be mounted upon */ Acreate, /* file is to be created */ COPEN = 0x0001, /* for i/o */ CMSG = 0x0002, /* the message channel for a mount */ CCREATE = 0x0004, /* permits creation if c->mnt */ CCEXEC = 0x0008, /* close on exec */ CFREE = 0x0010, /* not in use */ CRCLOSE = 0x0020, /* remove on close */ CRECOV = 0x0040, /* requires recovery */ }; struct Path { Ref; Path *hash; Path *parent; Pthash *pthash; char elem[NAMELEN]; }; struct Chan { Ref; Chan *next; /* allocation */ Chan *link; ulong offset; /* in file */ ushort type; ushort dev; ushort mode; /* read/write */ ushort flag; Qid qid; int fid; /* for devmnt */ Path *path; Mount *mnt; /* mount point that derived Chan */ Mount *xmnt; /* Last mount point crossed */ ulong mountid; union { void *aux; Qid pgrpid; /* for #p/notepg */ Mnt *mntptr; /* for devmnt */ ulong mid; /* for ns in devproc */ }; Chan *mchan; /* channel to mounted server */ Qid mqid; /* qid of root of mount point */ Session *session; }; struct Dev { void (*reset)(void); void (*init)(void); Chan* (*attach)(char*); Chan* (*clone)(Chan*, Chan*); int (*walk)(Chan*, char*); void (*stat)(Chan*, char*); Chan* (*open)(Chan*, int); void (*create)(Chan*, char*, int, ulong); void (*close)(Chan*); long (*read)(Chan*, void*, long, ulong); long (*write)(Chan*, void*, long, ulong); void (*remove)(Chan*); void (*wstat)(Chan*, char*); }; struct Dirtab { char name[NAMELEN]; Qid qid; long length; long perm; }; /* SCSI devices. */ enum { ScsiTestunit = 0x00, ScsiExtsens = 0x03, ScsiInquiry = 0x12, ScsiModesense = 0x1a, ScsiStartunit = 0x1B, ScsiStopunit = 0x1B, ScsiGetcap = 0x25, ScsiRead = 0x08, ScsiWrite = 0x0a, /* data direction */ ScsiIn = 1, ScsiOut = 0, }; struct Scsibuf { void* virt; void* phys; Scsibuf* next; }; struct Scsidata { uchar* base; uchar* lim; uchar* ptr; }; struct Scsi { QLock; ulong pid; ushort target; ushort lun; ushort rflag; ushort status; Scsidata cmd; Scsidata data; Scsibuf* b; uchar* save; uchar cmdblk[16]; }; enum { NSMAX = 1000, NSLOG = 7, NSCACHE = (1<rendhash[(s)%RENDHASH]) #define MOUNTH(p,s) ((p)->mnthash[(s)->qid.path%MNTHASH]) struct Pgrp { Ref; /* also used as a lock when mounting */ Pgrp *next; /* free list */ ulong pgrpid; QLock debug; /* single access via devproc.c */ RWlock ns; /* Namespace n read/one write lock */ QLock nsh; Mhead *mnthash[MNTHASH]; Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */ }; struct Egrp { Ref; QLock; Evalue *entries; ulong path; }; struct Evalue { char *name; char *value; int len; ulong path; Evalue *link; }; struct Fgrp { Ref; Chan *fd[NFD]; int maxfd; /* highest fd in use */ }; struct Palloc { Lock; ulong p0, p1; /* base of pages in bank 0/1 */ ulong np0, np1; /* number of pages in bank 0/1 */ Page *head; /* most recently used */ Page *tail; /* least recently used */ ulong freecount; ulong freecol[NCOLOR]; /* how many pages on free list now */ ulong user; /* how many user pages */ Page *hash[PGHSIZE]; Lock hashlock; Rendez r; /* Sleep for free mem */ QLock pwait; /* Queue of procs waiting for memory */ int wanted; /* Do the wakeup at free */ ulong cmembase; /* Key memory */ ulong cmemtop; }; struct Waitq { Waitmsg w; Waitq *next; }; enum { RFNAMEG = (1<<0), RFENVG = (1<<1), RFFDG = (1<<2), RFNOTEG = (1<<3), RFPROC = (1<<4), RFMEM = (1<<5), RFNOWAIT = (1<<6), RFCNAMEG = (1<<10), RFCENVG = (1<<11), RFCFDG = (1<<12) }; /* * process memory segments - NSEG always last ! */ enum { SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, NSEG }; enum { Dead = 0, /* Process states */ Moribund, Ready, Scheding, Running, Queueing, Wakeme, Broken, Stopped, Rendezvous, Proc_stopme = 1, /* devproc requests */ Proc_exitme, Proc_traceme, TUser = 0, /* Proc.time */ TSys, TReal, TCUser, TCSys, TCReal, NERR = 15, NNOTE = 5, }; struct Proc { Label sched; /* known to l.s */ char *kstack; /* known to l.s */ Mach *mach; /* machine running this proc */ char text[NAMELEN]; char user[NAMELEN]; Proc *rnext; /* next process in run queue */ Proc *qnext; /* next process on queue for a QLock */ QLock *qlock; /* addrof qlock being queued for DEBUG */ int state; char *psstate; /* What /proc/#/status reports */ Page *upage; /* page from palloc */ Segment *seg[NSEG]; ulong pid; ulong noteid; /* Equivalent of note group */ Lock exl; /* Lock count and waitq */ Waitq *waitq; /* Exited processes wait children */ int nchild; /* Number of living children */ int nwait; /* Number of uncollected wait records */ QLock qwaitr; Rendez waitr; /* Place to hang out in wait */ Proc *parent; Pgrp *pgrp; /* Process group for namespace */ Egrp *egrp; /* Environment group */ Fgrp *fgrp; /* File descriptor group */ ulong parentpid; ulong time[6]; /* User, Sys, Real; child U, S, R */ short insyscall; int fpstate; QLock debug; /* to access debugging elements of User */ Proc *pdbg; /* the debugging process */ ulong procmode; /* proc device file mode */ int hang; /* hang at next exec for debug */ int procctl; /* Control for /proc debugging */ ulong pc; /* DEBUG only */ Rendez *r; /* rendezvous point slept on */ Rendez sleep; /* place for syssleep/debug */ int notepending; /* note issued but not acted on */ int kp; /* true if a kernel process */ Proc *palarm; /* Next alarm time */ ulong alarm; /* Time of call */ int newtlb; /* Pager has changed my pte's, I must flush */ ulong rendtag; /* Tag for rendezvous */ ulong rendval; /* Value for rendezvous */ Proc *rendhash; /* Hash list for tag values */ ulong twhen; Rendez *trend; Proc *tlink; int (*tfn)(void*); void (*kpfun)(void*); void *kparg; FPsave fpsave; /* address of this is known by db */ int scallnr; /* sys call number - known by db */ Sargs s; /* address of this is known by db */ int nerrlab; Label errlab[NERR]; char error[ERRLEN]; char elem[NAMELEN]; /* last name element from namec */ Chan *slash; Chan *dot; Note note[NNOTE]; short nnote; short notified; /* sysnoted is due */ Note lastnote; int (*notify)(void*, char*); void *ureg; /* User registers for notes */ void *dbgreg; /* User registers for devproc */ ulong svstatus; ulong svr1; /* * machine specific MMU */ PMMU; }; enum { PRINTSIZE = 256, MAXCRYPT = 127, NUMSIZE = 12, /* size of formatted number */ MB = (1024*1024), }; extern Conf conf; extern char* conffile; extern int cpuserver; extern int cpuserver; extern Rune* devchar; extern Dev devtab[]; extern char eve[]; extern char hostdomain[]; extern uchar initcode[]; extern FPsave initfp; extern Queue *kbdq; extern Queue *mouseq; extern Ref noteidalloc; extern int nrdy; extern Palloc palloc; extern Queue *printq; extern char* statename[]; extern Image swapimage; extern char sysname[NAMELEN]; extern Pthash syspt; extern Talarm talarm; enum { CHDIR = 0x80000000L, CHAPPEND = 0x40000000L, CHEXCL = 0x20000000L, CHMOUNT = 0x10000000L, }; /* * auth messages */ enum { FScchal = 1, FSschal, FSok, FSctick, FSstick, FSerr, RXschal = 0, RXstick = 1, AUTHLEN = 8, }; /* * mouse types */ enum { Mouseother= 0, Mouseserial= 1, MousePS2= 2, }; extern int mouseshifted; extern int mousetype;