1 2 #define Qroot 0 3 4 #define MSGMAX ((((8192+128)*2)+3) & ~3) 5 6 extern char Enomem[]; /* out of memory */ 7 extern char Eperm[]; /* permission denied */ 8 extern char Enodev[]; /* no free devices */ 9 extern char Ehungup[]; /* i/o on hungup channel */ 10 extern char Eexist[]; /* file exists */ 11 extern char Enonexist[]; /* file does not exist */ 12 extern char Ebadcmd[]; /* bad command */ 13 extern char Ebadarg[]; /* bad arguments */ 14 15 typedef uvlong Path; 16 typedef struct Styxserver Styxserver; 17 typedef struct Styxops Styxops; 18 typedef struct Styxfile Styxfile; 19 typedef struct Client Client; 20 typedef struct Fid Fid; 21 22 struct Styxserver 23 { 24 Styxops *ops; 25 Path qidgen; 26 int connfd; 27 int needfile; 28 Client *clients; 29 Client *curc; 30 Styxfile *root; 31 Styxfile **ftab; 32 void *priv; /* private */ 33 }; 34 35 struct Client 36 { 37 Styxserver *server; 38 Client *next; 39 int fd; 40 char msg[MSGMAX]; 41 uint nread; /* valid bytes in msg (including nc)*/ 42 int nc; /* bytes consumed from front of msg by convM2S */ 43 char data[MSGMAX]; /* Tread/Rread data */ 44 int state; 45 Fid *fids; 46 char *uname; /* uid */ 47 char *aname; /* attach name */ 48 void *u; 49 }; 50 51 struct Styxops 52 { 53 char *(*newclient)(Client *c); 54 char *(*freeclient)(Client *c); 55 56 char *(*attach)(char *uname, char *aname); 57 char *(*walk)(Qid *qid, char *name); 58 char *(*open)(Qid *qid, int mode); 59 char *(*create)(Qid *qid, char *name, int perm, int mode); 60 char *(*read)(Qid qid, char *buf, ulong *n, vlong offset); 61 char *(*write)(Qid qid, char *buf, ulong *n, vlong offset); 62 char *(*close)(Qid qid, int mode); 63 char *(*remove)(Qid qid); 64 char *(*stat)(Qid qid, Dir *d); 65 char *(*wstat)(Qid qid, Dir *d); 66 }; 67 68 struct Styxfile 69 { 70 Dir d; 71 Styxfile *parent; 72 Styxfile *child; 73 Styxfile *sibling; 74 Styxfile *next; 75 int ref; 76 int open; 77 void *u; 78 }; 79 80 char *styxinit(Styxserver *server, Styxops *ops, char *port, int perm, int needfile); 81 char *styxwait(Styxserver *server); 82 char *styxprocess(Styxserver *server); 83 char *styxend(Styxserver *server); 84 85 Client *styxclient(Styxserver *server); 86 87 Styxfile *styxaddfile(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner); 88 Styxfile *styxadddir(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner); 89 int styxrmfile(Styxserver *server, Path qid); 90 Styxfile *styxfindfile(Styxserver *server, Path qid); 91 92 int styxperm(Styxfile *file, char *uid, int mode); 93 long styxreadstr(ulong off, char *buf, ulong n, char *str); 94 Qid styxqid(int path, int isdir); 95 void *styxmalloc(int n); 96 void styxfree(void *p); 97 void styxdebug(void); 98 void styxsetowner(char*); 99