xref: /plan9/sys/src/cmd/disk/kfs/portdat.h (revision ebe1d0a8b9996624470441a63d49d0fee1ba744c)
1 /*
2  * fundamental constants
3  */
4 #define	NAMELEN		28		/* size of names */
5 #define	NDBLOCK		6		/* number of direct blocks in Dentry */
6 #define	MAXDAT		8192		/* max allowable data message */
7 #define NTLOCK		200		/* number of active file Tlocks */
8 
9 typedef	struct	Fbuf	Fbuf;
10 typedef	struct	Super1	Super1;
11 typedef	struct	Superb	Superb;
12 // typedef struct	Qid	Qid;
13 typedef	struct	Dentry	Dentry;
14 typedef	struct	Tag	Tag;
15 
16 typedef struct	Device	Device;
17 typedef struct	Qid9p1	Qid9p1;
18 typedef	struct	File	File;
19 typedef	struct	Filsys	Filsys;
20 typedef	struct	Filta	Filta;
21 typedef	struct	Filter	Filter;
22 typedef		ulong	Float;
23 typedef	struct	Hiob	Hiob;
24 typedef	struct	Iobuf	Iobuf;
25 typedef	struct	P9call	P9call;
26 typedef	struct	Tlock	Tlock;
27 // typedef	struct	Tm	Tm;
28 typedef	struct	Uid	Uid;
29 typedef	struct	Wpath	Wpath;
30 typedef struct	AuthRpc	AuthRpc;
31 
32 /*
33  * DONT TOUCH -- data structures stored on disk
34  */
35 /* DONT TOUCH, this is the disk structure */
36 struct	Qid9p1
37 {
38 	long	path;
39 	long	version;
40 };
41 
42 /* DONT TOUCH, this is the disk structure */
43 struct	Dentry
44 {
45 	char	name[NAMELEN];
46 	short	uid;
47 	short	gid;
48 	ushort	mode;
49 		#define	DALLOC	0x8000
50 		#define	DDIR	0x4000
51 		#define	DAPND	0x2000
52 		#define	DLOCK	0x1000
53 		#define	DREAD	0x4
54 		#define	DWRITE	0x2
55 		#define	DEXEC	0x1
56 	Qid9p1	qid;
57 	long	size;
58 	long	dblock[NDBLOCK];
59 	long	iblock;
60 	long	diblock;
61 	long	atime;
62 	long	mtime;
63 };
64 
65 /* DONT TOUCH, this is the disk structure */
66 struct	Tag
67 {
68 	short	pad;
69 	short	tag;
70 	long	path;
71 };
72 
73 /* DONT TOUCH, this is the disk structure */
74 struct	Super1
75 {
76 	long	fstart;
77 	long	fsize;
78 	long	tfree;
79 	long	qidgen;		/* generator for unique ids */
80 
81 	long	fsok;		/* file system ok */
82 
83 	/*
84 	 * garbage for WWC device
85 	 */
86 	long	roraddr;	/* dump root addr */
87 	long	last;		/* last super block addr */
88 	long	next;		/* next super block addr */
89 };
90 
91 /* DONT TOUCH, this is the disk structure */
92 struct	Fbuf
93 {
94 	long	nfree;
95 	long	free[1];		/* changes based on BUFSIZE */
96 };
97 
98 /* DONT TOUCH, this is the disk structure */
99 struct	Superb
100 {
101 	Super1;
102 	Fbuf	fbuf;
103 };
104 
105 struct	Device
106 {
107 	char	type;
108 	char	ctrl;
109 	char	unit;
110 	char	part;
111 };
112 
113 /*
114  * for load stats
115  */
116 struct	Filter
117 {
118 	ulong	count;			/* count and old count kept separate */
119 	ulong	oldcount;		/* so interrput can read them */
120 	Float	filter[3];		/* filters for 1m 10m 100m */
121 };
122 
123 struct	Filta
124 {
125 	Filter*	f;
126 	int	scale;
127 };
128 
129 /*
130  * array of qids that are locked
131  */
132 struct	Tlock
133 {
134 	Device	dev;
135 	long	time;
136 	long	qpath;
137 	File*	file;
138 };
139 
140 struct	File
141 {
142 	QLock;
143 	Qid	qid;
144 	Wpath*	wpath;
145 	Chan*	cp;		/* null means a free slot */
146 	Tlock*	tlock;		/* if file is locked */
147 	File*	next;		/* in cp->flist */
148 	File*	list;		/* in list of free files */
149 	Filsys*	fs;
150 	long	addr;
151 	long	slot;
152 	long	lastra;		/* read ahead address */
153 	short	fid;
154 	short	uid;
155 	char	open;
156 		#define	FREAD	1
157 		#define	FWRITE	2
158 		#define	FREMOV	4
159 		#define	FWSTAT	8
160 	long	doffset;	/* directory reading */
161 	ulong	dvers;
162 	long	dslot;
163 
164 	/* for network authentication */
165 	AuthRpc	*rpc;
166 	short	cuid;
167 };
168 
169 struct	Filsys
170 {
171 	char*	name;		/* name of filesys */
172 	Device	dev;		/* device that filesys is on */
173 	int	flags;
174 		#define	FREAM		(1<<1)	/* mkfs */
175 		#define	FRECOVER	(1<<2)	/* install last dump */
176 };
177 
178 struct	Hiob
179 {
180 	Iobuf*	link;
181 	Lock;
182 };
183 
184 struct	Iobuf
185 {
186 	QLock;
187 	Device	dev;
188 	Iobuf	*next;		/* for hash */
189 	Iobuf	*fore;		/* for lru */
190 	Iobuf	*back;		/* for lru */
191 	char	*iobuf;		/* only active while locked */
192 	char	*xiobuf;	/* "real" buffer pointer */
193 	long	addr;
194 	int	flags;
195 };
196 
197 struct	P9call
198 {
199 	uchar	calln;
200 	uchar	rxflag;
201 	short	msize;
202 	void	(*func)(Chan*, int);
203 };
204 
205 // struct	Tm
206 // {
207 // 	/* see ctime(3) */
208 // 	int	sec;
209 // 	int	min;
210 // 	int	hour;
211 // 	int	mday;
212 // 	int	mon;
213 // 	int	year;
214 // 	int	wday;
215 // 	int	yday;
216 // 	int	isdst;
217 // };
218 
219 struct	Uid
220 {
221 	short	uid;		/* user id */
222 	short	lead;		/* leader of group */
223 	short	offset;		/* byte offset in uidspace */
224 };
225 
226 struct	Wpath
227 {
228 	Wpath	*up;		/* pointer upwards in path */
229 	Wpath	*list;		/* link in free chain */
230 	long	addr;		/* directory entry addr of parent */
231 	long	slot;		/* directory entry slot of parent */
232 	short	refs;		/* number of files using this structure */
233 };
234 
235 #define	MAXFDATA	8192
236 
237 /*
238  * error codes generated from the file server
239  */
240 enum
241 {
242 	Ebadspc = 1,
243 	Efid,
244 	Efidinuse,
245 	Echar,
246 	Eopen,
247 	Ecount,
248 	Ealloc,
249 	Eqid,
250 	Eauth,
251 	Eauthmsg,
252 	Eaccess,
253 	Eentry,
254 	Emode,
255 	Edir1,
256 	Edir2,
257 	Ephase,
258 	Eexist,
259 	Edot,
260 	Eempty,
261 	Ebadu,
262 	Enotu,
263 	Enotg,
264 	Ename,
265 	Ewalk,
266 	Eronly,
267 	Efull,
268 	Eoffset,
269 	Elocked,
270 	Ebroken,
271 	Etoolong,
272 	Ersc,
273 	Eqidmode,
274 	Econvert,
275 	Enotm,
276 	Enotd,
277 	Enotl,
278 	Enotw,
279 	Esystem,
280 
281 	MAXERR
282 };
283 
284 /*
285  * devnone block numbers
286  */
287 enum
288 {
289 	Cwio1 	= 1,
290 	Cwio2,
291 	Cwxx1,
292 	Cwxx2,
293 	Cwxx3,
294 	Cwxx4,
295 	Cwdump1,
296 	Cwdump2,
297 	Cuidbuf,
298 };
299 
300 /*
301  * tags on block
302  */
303 enum
304 {
305 	Tnone		= 0,
306 	Tsuper,			/* the super block */
307 	Tdir,			/* directory contents */
308 	Tind1,			/* points to blocks */
309 	Tind2,			/* points to Tind1 */
310 	Tfile,			/* file contents */
311 	Tfree,			/* in free list */
312 	Tbuck,			/* cache fs bucket */
313 	Tvirgo,			/* fake worm virgin bits */
314 	Tcache,			/* cw cache things */
315 	MAXTAG
316 };
317 
318 /*
319  * flags to getbuf
320  */
321 enum
322 {
323 	Bread	= (1<<0),	/* read the block if miss */
324 	Bprobe	= (1<<1),	/* return null if miss */
325 	Bmod	= (1<<2),	/* set modified bit in buffer */
326 	Bimm	= (1<<3),	/* set immediate bit in buffer */
327 	Bres	= (1<<4),	/* reserved, never renammed */
328 };
329 
330 /*
331  * open modes passed into P9 open/create
332  */
333 enum
334 {
335 	MREAD	= 0,
336 	MWRITE,
337 	MBOTH,
338 	MEXEC,
339 	MTRUNC	= (1<<4),	/* truncate on open */
340 	MCEXEC	= (1<<5),	/* close on exec (host) */
341 	MRCLOSE	= (1<<6),	/* remove on close */
342 };
343 
344 /*
345  * check flags
346  */
347 enum
348 {
349 	Crdall	= (1<<0),	/* read all files */
350 	Ctag	= (1<<1),	/* rebuild tags */
351 	Cpfile	= (1<<2),	/* print files */
352 	Cpdir	= (1<<3),	/* print directories */
353 	Cfree	= (1<<4),	/* rebuild free list */
354 	Cream	= (1<<6),	/* clear all bad tags */
355 	Cbad	= (1<<7),	/* clear all bad blocks */
356 	Ctouch	= (1<<8),	/* touch old dir and indir */
357 	Cquiet	= (1<<9),	/* report just nasty things */
358 };
359 
360 /*
361  * buffer size variables
362  */
363 extern int	RBUFSIZE;
364 extern int	BUFSIZE;
365 extern int	DIRPERBUF;
366 extern int	INDPERBUF;
367 extern int	INDPERBUF2;
368 extern int	FEPERBUF;
369