xref: /plan9/sys/src/cmd/ratfs/ratfs.h (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <fcall.h>
5 #include <bio.h>
6 
7 enum {
8 	MAXRPC = 8192,
9 
10 	Qroot = 1,		/* fixed QID's */
11 	Qallow,
12 	Qdelay,
13 	Qblock,
14 	Qdial,
15 	Qdeny,
16 	Qtrusted,
17 	Qctl,
18 	Qdummy,
19 	Qaddr,			/* Qid's for "ip" & "account" subdirs (Qaddr-99) */
20 
21 	Qtrustedfile = 100,	/* Qid's for trusted files (100-999)*/
22 	Qaddrfile   = 1000,	/* Qid's for address files (> 1000) */
23 
24 				/* type codes in node.d.type */
25 	Directory =	0,	/* normal directory */
26 	Addrdir,		/* contains "ip" and "account" directories */
27 	IPaddr,			/* contains IP address "files" */
28 	Acctaddr,		/* contains Account address "files" */
29 	Trusted,		/* contains trusted IP files */
30 	Trustedperm,		/* permanently trusted IP pseudo-file */
31 	Trustedtemp,		/* temporarily trusted IP pseudo-file */
32 	Ctlfile,		/* ctl file under root */
33 	Dummynode,		/* place holder for Address pseudo-files */
34 };
35 
36 typedef struct Fid	Fid;
37 typedef struct Node	Node;
38 typedef	struct Address	Address;
39 typedef struct Cidraddr	Cidraddr;
40 typedef struct Keyword	Keyword;
41 
42 	/* an active fid */
43 struct Fid
44 {
45 	int	fid;
46 	int	dirindex;
47 	Node	*node;		/* current position in path */
48 	int	busy;
49 	int	open;		/* directories only */
50 	char	*name;
51 	char *uid;
52 	Fid	*next;
53 };
54 
55 struct	Cidraddr
56 {
57 	ulong	ipaddr;		/* CIDR base addr */
58 	ulong	mask;		/* CIDR mask */
59 };
60 
61 	/* an address is either an account name (domain!user) or Ip address */
62 struct	Address
63 {
64 	char	*name;		/* from the control file */
65 	Cidraddr ip;		/* CIDR Address */
66 };
67 
68 /* Fids point to either a directory or pseudo-file */
69 struct Node
70 {
71 	Dir	d;		/* d.name, d.uid, d.gid, d.muid are atoms */
72 	int	count;
73 	int	allocated;	/* number of Address structs allocated */
74 	ulong	baseqid;	/* base of Qid's in this set */
75 	Node	*parent;	/* points to self in root node*/
76 	Node	*sibs;		/* 0 in Ipaddr and Acctaddr dirs */
77 	union {
78 		Node	*children;	/* type == Directory || Addrdir || Trusted */
79 		Address	*addrs;		/* type == Ipaddr || Acctaddr */
80 		Cidraddr ip;		/* type == Trustedfile */
81 	};
82 };
83 
84 struct Keyword {
85 	char	*name;
86 	int	code;
87 };
88 
89 Node	*root;			/* root of directory tree */
90 Node	dummy;			/* dummy node for fid's pointing to an Address */
91 int	srvfd;			/* fd for 9fs */
92 uchar rbuf[IOHDRSZ+MAXRPC+1];
93 int	debugfd;
94 char	*ctlfile;
95 char	*conffile;
96 long	lastconftime;
97 long	lastctltime;
98 int	trustedqid;
99 
100 char*	atom(char*);
101 void	cidrparse(Cidraddr*, char*);
102 void	cleantrusted(void);
103 Node*	dirwalk(char*, Node*);
104 int	dread(Fid*, int);
105 void	fatal(char*, ...);
106 Node*	finddir(int);
107 int	findkey(char*, Keyword*);
108 void	getconf(void);
109 int	hread(Fid*, int);
110 void	io(void);
111 Node*	newnode(Node*, char*, ushort, int, ulong);
112 void	printfid(Fid*);
113 void	printnode(Node*);
114 void	printtree(Node*);
115 void	reload(void);
116 char*	subslash(char*);
117 char*	walk(char*, Fid*);
118 
119