History

20090320-1900

Charles.Forsyth committed 17 years ago

Commit d49685a1 parent 14d820f6 files · +18 −6Browse files

Showing the changes to include (1 of 6 files). Show all

Unified · Split

include/styxserver.h+98−0
@@ -0,0 +1,98 @@
1
2#define Qroot 0
3
4#define MSGMAX ((((8192+128)*2)+3) & ~3)
5
6extern char Enomem[]; /* out of memory */
7extern char Eperm[]; /* permission denied */
8extern char Enodev[]; /* no free devices */
9extern char Ehungup[]; /* i/o on hungup channel */
10extern char Eexist[]; /* file exists */
11extern char Enonexist[]; /* file does not exist */
12extern char Ebadcmd[]; /* bad command */
13extern char Ebadarg[]; /* bad arguments */
14
15typedef uvlong Path;
16typedef struct Styxserver Styxserver;
17typedef struct Styxops Styxops;
18typedef struct Styxfile Styxfile;
19typedef struct Client Client;
20typedef struct Fid Fid;
21
22struct 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
35struct 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
51struct 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
68struct 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
80char *styxinit(Styxserver *server, Styxops *ops, char *port, int perm, int needfile);
81char *styxwait(Styxserver *server);
82char *styxprocess(Styxserver *server);
83char *styxend(Styxserver *server);
84
85Client *styxclient(Styxserver *server);
86
87Styxfile *styxaddfile(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner);
88Styxfile *styxadddir(Styxserver *server, Path pqid, Path qid, char *name, int mode, char *owner);
89int styxrmfile(Styxserver *server, Path qid);
90Styxfile *styxfindfile(Styxserver *server, Path qid);
91
92int styxperm(Styxfile *file, char *uid, int mode);
93long styxreadstr(ulong off, char *buf, ulong n, char *str);
94Qid styxqid(int path, int isdir);
95void *styxmalloc(int n);
96void styxfree(void *p);
97void styxdebug(void);
98void styxsetowner(char*);