ref: 9c00c613885deba1ed19e905604571ef432cab11
dir: /kern/dat.h/
#define KNAMELEN 28 /* max length of name held in kernel */
#define BLOCKALIGN 8
typedef struct Block Block;
typedef struct Chan Chan;
typedef struct Cmdbuf Cmdbuf;
typedef struct Cmdtab Cmdtab;
typedef struct Conf Conf;
typedef struct Dev Dev;
typedef struct Dirtab Dirtab;
typedef struct Egrp Egrp;
typedef struct Evalue Evalue;
typedef struct Fgrp Fgrp;
typedef struct DevConf DevConf;
typedef struct Label Label;
typedef struct Log Log;
typedef struct Logflag Logflag;
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 Path Path;
typedef struct Pgrps Pgrps;
typedef struct Pgrp Pgrp;
typedef struct Proc Proc;
typedef struct Queue Queue;
typedef struct Ref Ref;
typedef struct Rendez Rendez;
typedef struct Rgrp Rgrp;
typedef struct RWLock RWLock;
typedef struct Segment Segment;
typedef struct Ureg Ureg;
typedef struct Waitq Waitq;
typedef struct Walkqid Walkqid;
typedef struct Kmesg Kmesg;
typedef int Devgen(Chan*, char*, Dirtab*, int, int, Dir*);
#include "fcall.h"
enum
{
SnarfSize = 64*1024,
};
struct Conf
{
ulong nmach; /* processors */
ulong nproc; /* processes */
ulong pipeqsize; /* size in bytes of pipe queues */
};
struct Label
{
jmp_buf buf;
};
struct Ref
{
Lock lk;
long ref;
};
struct Rendez
{
Lock lk;
Proc *p;
};
struct RWLock /* changed from kernel */
{
int readers;
Lock lk;
QLock x;
QLock k;
};
struct Talarm
{
Lock lk;
Proc *list;
};
struct Alarms
{
QLock lk;
Proc *head;
};
/*
* Access types in namec & channel flags
*/
enum
{
Aaccess, /* as in stat, wstat */
Abind, /* for left-hand-side of bind */
Atodir, /* as in chdir */
Aopen, /* for i/o */
Amount, /* to be mounted or mounted upon */
Acreate, /* is to be created */
Aremove, /* will be removed by caller */
Aunmount, /* unmount arg */
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 */
CCACHE = 0x0080, /* client cache */
};
/* flag values */
enum
{
BINTR = (1<<0),
BFREE = (1<<1),
Bipck = (1<<2), /* ip checksum */
Budpck = (1<<3), /* udp checksum */
Btcpck = (1<<4), /* tcp checksum */
Bpktck = (1<<5), /* packet checksum */
};
enum {
NAMEMAX = 27,
NSMAX = 1000,
NNOTE = 5,
NSLOG = 7,
Nfpregs = 16,
NSCACHE = (1<<NSLOG),
flN = 1<<31,
flZ = 1<<30,
flC = 1<<29,
flV = 1<<28,
FLAGS = flN | flZ | flC | flV,
};
struct Block
{
Block* next;
Block* list;
uchar* rp; /* first unconsumed byte */
uchar* wp; /* first empty byte */
uchar* lim; /* 1 past the end of the buffer */
uchar* base; /* start of the buffer */
void (*free)(Block*);
ushort flag;
ushort checksum; /* IP checksum of complete packet (minus media header) */
};
#define BLEN(s) ((s)->wp - (s)->rp)
#define BALLOC(s) ((s)->lim - (s)->base)
struct Chan
{
Ref ref;
Lock lk;
Chan* next; /* allocation */
Chan* link;
vlong offset; /* in fd */
vlong devoffset; /* in underlying device; see read */
ushort type;
ulong dev;
ushort mode; /* read/write */
ushort flag;
Qid qid;
int fid; /* for devmnt */
ulong iounit; /* chunk size for i/o; 0==default */
Mhead* umh; /* mount point that derived Chan; used in unionread */
Chan* umc; /* channel in union; held for union read */
QLock umqlock; /* serialize unionreads */
int uri; /* union read index */
int dri; /* devdirread index */
uchar* dirrock; /* directory entry rock for translations */
int nrock;
int mrock;
QLock rockqlock;
int ismtpt;
Mnt* mux; /* Mnt for clients using me for messages */
union {
void* aux;
ulong mid; /* for ns in devproc */
};
Chan* mchan; /* channel to mounted server */
Qid mqid; /* qid of root of mount point */
Path* path;
char *srvname;
};
struct Path
{
Ref ref;
char *s;
Chan **mtpt; /* mtpt history */
int len; /* strlen(s) */
int alen; /* allocated length of s */
int mlen; /* number of path elements */
int malen; /* allocated length of mtpt */
};
struct Dev
{
int dc;
char* name;
void (*reset)(void);
void (*init)(void);
void (*shutdown)(void);
Chan* (*attach)(char*);
Walkqid* (*walk)(Chan*, Chan*, char**, int);
int (*stat)(Chan*, uchar*, int);
Chan* (*open)(Chan*, int);
Chan* (*create)(Chan*, char*, int, ulong);
void (*close)(Chan*);
long (*read)(Chan*, void*, long, vlong);
Block* (*bread)(Chan*, long, ulong);
long (*write)(Chan*, void*, long, vlong);
long (*bwrite)(Chan*, Block*, ulong);
void (*remove)(Chan*);
int (*wstat)(Chan*, uchar*, int);
void (*power)(int); /* power mgt: power(1) => on, power (0) => off */
int (*config)(int, char*, DevConf*); // returns nil on error
};
struct Dirtab
{
char name[KNAMELEN];
Qid qid;
vlong length;
long perm;
};
struct Walkqid
{
Chan *clone;
int nqid;
Qid qid[1];
};
struct Mntwalk /* state for /proc/#/ns */
{
int cddone;
ulong id;
Mhead* mh;
Mount* cm;
};
struct Mount
{
ulong mountid;
Mount* next;
Mhead* head;
Mount* copy;
Mount* order;
Chan* to; /* channel replacing channel */
int mflag;
char *spec;
};
struct Mhead
{
Ref ref;
RWLock lock;
Chan* from; /* channel mounted upon */
Mount* mount; /* what's mounted upon it */
Mhead* hash; /* Hash chain */
};
struct Mnt
{
Lock lk;
/* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
Chan *c; /* Channel to file service */
Proc *rip; /* Reader in progress */
Mntrpc *queue; /* Queue of pending requests on this channel */
ulong id; /* Multiplexer id for channel check */
Mnt *list; /* Free list */
int flags; /* cache */
int msize; /* data + IOHDRSZ */
char *version; /* 9P version */
Queue *q; /* input queue */
};
enum
{
NUser, /* note provided externally */
NExit, /* deliver note quietly */
NDebug, /* print debug message */
};
struct Note
{
char msg[ERRMAX];
int flag; /* whether system posted it */
Ref ref;
};
enum
{
RENDLOG = 5,
RENDHASH = 1<<RENDLOG, /* Hash to lookup rendezvous tags */
MNTLOG = 5,
MNTHASH = 1<<MNTLOG, /* Hash to walk mount table */
NFD = 100, /* per process file descriptors */
};
#define REND(p,s) ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
#define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
struct Pgrp
{
Ref ref; /* also used as a lock when mounting */
int noattach;
QLock debug; /* single access via devproc.c */
RWLock ns; /* Namespace n read/one write lock */
Mhead *mnthash[MNTHASH];
u64int notallowed[4];
};
typedef struct Ureg {
ulong r0;
ulong r1;
ulong r2;
ulong r3;
ulong r4;
ulong r5;
ulong r6;
ulong r7;
ulong r8;
ulong r9;
ulong r10;
ulong r11;
ulong r12; /* sb */
union {
ulong r13;
ulong sp;
};
union {
ulong r14;
ulong link;
};
ulong type; /* of exception */
ulong psr;
ulong pc; /* interrupted addr */
} Ureg;
struct Rgrp
{
Ref ref;
Lock lk;
Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */
};
struct Egrp
{
Ref ref;
RWLock lk;
Evalue **ent;
int nent;
int ment;
ulong path; /* qid.path of next Evalue to be allocated */
ulong vers; /* of Egrp */
};
struct Evalue
{
char *name;
char *value;
int len;
Evalue *link;
Qid qid;
};
struct Fgrp
{
Ref ref;
Lock lk;
Chan **fd;
int nfd; /* number allocated */
int maxfd; /* highest fd in use */
int exceed; /* debugging */
};
enum
{
DELTAFD = 20, /* incremental increase in Fgrp.fd's */
NERR = 20
};
/* Segment types */
enum
{
SG_TYPE = 07, /* Mask type of segment */
SG_TEXT = 00,
SG_DATA = 01,
SG_BSS = 02,
SG_STACK = 03,
SG_SHARED = 04,
SG_PHYSICAL = 05,
SG_FIXED = 06,
SG_STICKY = 07,
SG_RONLY = 0040, /* Segment is read only */
SG_CEXEC = 0100, /* Detach at exec */
SG_FAULT = 0200, /* Fault on access */
SG_CACHED = 0400, /* Normal cached memory */
SG_DEVICE = 01000, /* Memory mapped device */
SG_NOEXEC = 02000, /* No execute */
};
enum {
TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, NSEG,
SEGFLLOCK = 1,
};
enum
{
Dead = 0,
New,
Moribund,
Ready,
Running,
Wakeme,
Broken,
Stopped,
Rendezvous,
Proc_stopme = 1, /* devproc requests */
Proc_exitme,
Proc_traceme,
Proc_exitbig,
Proc_tracesyscall,
};
struct Proc
{
uint state;
uint mach;
ulong pid;
ulong procmode;
Pgrp *pgrp; /* Process group for namespace */
Fgrp *fgrp; /* File descriptor group */
Rgrp *rgrp;
Egrp *egrp;
QLock debug;
Lock rlock; /* sync sleep/wakeup with postnote */
Lock exl; /* rfork, etc */
Rendez *r; /* rendezvous point slept on */
Rendez rsleep; /* place for syssleep/debug */
int notepending; /* note issued but not acted on */
int kp; /* true if a kernel process */
void* rendtag; /* Tag for rendezvous */
void* rendval; /* Value for rendezvous */
Proc *rendhash; /* Hash list for tag values */
int nerrlab;
Label errlab[NERR];
char user[KNAMELEN];
char *syserrstr; /* last error from a system call, errbuf0 or 1 */
char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
char errbuf0[ERRMAX];
char errbuf1[ERRMAX];
char genbuf[128]; /* buffer used e.g. for last name element from namec */
char text[KNAMELEN];
char name[NAMEMAX+1];
Ref *path;
u32int lladdr; /* LL/SC emulation */
u32int llval;
u32int CPSR; /* status register */
u32int FPSR;
double F[Nfpregs];
/* Note handling */
Note *lastnote;
Note *note[NNOTE];
short nnote;
short notified; /* sysnoted is due */
int (*notify)(void*, char*);
Ureg *noteureg;
Ureg *dbgreg;
Chan *slash;
Chan *dot;
Proc *qnext;
Proc *parent;
Proc *child;
ulong noteid; /* Equivalent of note group */
int nchild;
int procctl;
void (*fn)(void*);
void *arg;
char oproc[1024]; /* reserved for os */
u32int R[16]; /* general purpose registers / PC (R15) */
Segment *seg[NSEG];
QLock seglock;
};
struct Segment {
Ref ref;
int flags;
RWLock rw; /* lock for SEGFLLOCK segments */
u32int start, size;
void *data;
Ref *dref;
int type;
};
enum
{
PRINTSIZE = 256,
MAXCRYPT = 127,
NUMSIZE = 12, /* size of formatted number */
MB = (1024*1024),
READSTR = 1000, /* temporary buffer size for device reads */
};
extern Dev* devtab[];
extern char *eve;
extern char hostdomain[];
extern Queue* kbdq;
extern Queue* kprintoq;
extern char* statename[];
extern char *sysname;
extern uint qiomaxatomic;
extern Conf conf;
/*
* action log
*/
struct Log {
Lock lk;
int opens;
char* buf;
char *end;
char *rptr;
int len;
int nlog;
int minread;
int logmask; /* mask of things to debug */
QLock readq;
Rendez readr;
};
struct Logflag {
char* name;
int mask;
};
enum
{
NCMDFIELD = 128
};
struct Cmdbuf
{
char *buf;
char **f;
int nf;
};
struct Cmdtab
{
int index; /* used by client to switch on result */
char *cmd; /* command name */
int narg; /* expected #args; 0 ==> variadic */
};
/* queue state bits, Qmsg, Qcoalesce, and Qkick can be set in qopen */
enum
{
/* Queue.state */
Qstarve = (1<<0), /* consumer starved */
Qmsg = (1<<1), /* message stream */
Qclosed = (1<<2), /* queue has been closed/hungup */
Qflow = (1<<3), /* producer flow controlled */
Qcoalesce = (1<<4), /* coallesce packets on read */
Qkick = (1<<5), /* always call the kick routine after qwrite */
};
#define DEVDOTDOT -1
extern Proc *_getproc(void);
extern void _setproc(Proc*);
#define up (_getproc())
/*
* Log console output so it can be retrieved via /dev/kmesg.
* This is good for catching boot-time messages after the fact.
*/
struct Kmesg {
Lock lk;
uint n;
char buf[16384];
};
extern Kmesg kmesg;