summaryrefslogtreecommitdiff
path: root/sys/src/cmd/hjfs/dat.h
blob: 0a7ff5167fd7aef748d516a361367d2bdfa33026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
enum {
	/* affects on-disk structure */
	BLOCK = 4096,
	RBLOCK = BLOCK - 1,
	SUPERMAGIC = 0x6E0DE51C,
	SUPERBLK = 0,
	
	NAMELEN = 256,
	NDIRECT = 15,
	NINDIRECT = 4,
	
	ROOTQID = 1,
	DUMPROOTQID = 2,
	
	/* affects just run-time behaviour */
	SYNCINTERVAL = 10000,
	FREELISTLEN = 256,
	BUFHASHBITS = 8,
	BUFHASH = (1<<BUFHASHBITS)-1,
	NWORKERS = 5,
	EXCLDUR = 300,

	NOUID = (short)0x8000,
	USERLEN = 64,
};

typedef struct Fs Fs;
typedef struct Buf Buf;
typedef struct Dev Dev;
typedef struct BufReq BufReq;
typedef struct ThrData ThrData;
typedef struct Superblock Superblock;
typedef struct Dentry Dentry;
typedef struct Chan Chan;
typedef struct FLoc FLoc;
typedef struct Loc Loc;
typedef struct User User;

#pragma incomplete struct User
#pragma varargck type "T" int
#pragma varargck type "T" uint
enum {
	TRAW,
	TSUPERBLOCK,
	TDENTRY,
	TINDIR,
	TREF,
	TDONTCARE = -1,
};

struct Superblock {
	ulong magic;
	uvlong size;
	uvlong fstart;
	uvlong fend;
	uvlong root;
	uvlong qidpath;
};

enum {
	DALLOC = 1<<15,
	DGONE = 1<<14,
};

struct Dentry {
	char name[NAMELEN];
	short uid;
	short muid;
	short gid;
	ushort mode;
	Qid;
	uvlong size; /* bytes for files and blocks for dirs */
	uvlong db[NDIRECT];
	uvlong ib[NINDIRECT];
	vlong atime;
	vlong mtime;
};

enum {
	DENTRYSIZ = NAMELEN + 4 * sizeof(ushort) + 13 + (3 + NDIRECT + NINDIRECT) * sizeof(uvlong),
	DEPERBLK = RBLOCK / DENTRYSIZ,
	/* Given any opportunity to make a breaking change to hjfs,
	 * make this 12 an 8. Indirect offsets to blocks used to
	 * hold an incrementing  4 byte generation number. That
	 * design has changed.
	 */
	OFFPERBLK = RBLOCK / 12,
	REFSIZ = 3,
	REFPERBLK = RBLOCK / REFSIZ,
	REFSENTINEL = (1 << 8*REFSIZ) - 1,
};

struct BufReq {
	Dev *d;
	uvlong off;
	int nodata;
	Channel *resp;
	BufReq *next;
};

enum {
	BWRITE = 1, /* used only for the worker */
	BWRIM = 2, /* write immediately after putbuf */
	BDELWRI = 4, /* write delayed */
};

struct Buf {
	uchar op, type;
	union {
		uchar data[RBLOCK];
		Superblock sb;
		Dentry de[DEPERBLK];
		uvlong offs[OFFPERBLK];
		ulong refs[REFPERBLK];
	};

	/* do not use anything below (for the bufproc only) */
	uchar busy;
	char *error;
	Buf *dnext, *dprev;
	Buf *fnext, *fprev;
	BufReq;
	BufReq *last;
	ulong callerpc; /* debugging */
	
	Buf *wnext, *wprev;
};

struct ThrData {
	Channel *resp;
};

struct Dev {
	char *name;
	int size;
	Buf buf[BUFHASH+1]; /* doubly-linked list */
	Dev *next;
	int fd;
	Rendez workr;
	QLock workl;
	Buf work;
};

extern Dev *devs;

struct FLoc {
	uvlong blk;
	int deind;
	Qid;
};

enum {
	LGONE = 1,
	LDUMPED = 2,
};

struct Loc {
	FLoc;
	int ref, flags;
	Loc *next, *child;
	Loc *cnext, *cprev;
	Loc *gnext, *gprev;
	
	QLock ex;
	Chan *exlock;
	ulong lwrite;
};

enum {
	FSNOAUTH = 1,
	FSNOPERM = 2,
	FSCHOWN = 4,
};

struct Fs {
	RWLock;
	Dev *d;
	int flags;
	uvlong root, fstart;
	
	Channel *freelist;
	Loc *rootloc, *dumprootloc;
	QLock loctree;

	User *udata;
	int nudata;
	RWLock udatal;
};

enum {
	CHREAD = 1,
	CHWRITE = 2,
	CHRCLOSE = 4,

	CHFDUMP = 1,
	CHFNOLOCK = 2,
	CHFRO = 4,
	CHFNOPERM = 8,
	
	CHWBUSY = 1,
	CHWCLUNK = 2,
};


struct Chan {
	Fs *fs;
	Loc *loc;
	uchar open;
	uchar flags;
	ushort uid;

	/* dir walk */
	uvlong dwloff;
	uvlong dwblk;
	int dwind;
	
	/* workers */
	void *freq, *lreq;
	Chan *qnext, *qprev;
	int wflags;
};

extern QLock chanqu;
extern Rendez chanre;
extern Chan readych;

extern char Eio[];
extern char Enotadir[];
extern char Enoent[];
extern char Einval[];
extern char Eperm[];
extern char Eexists[];
extern char Elocked[];

enum { /* getblk modes */
	GBREAD = 0,
	GBWRITE = 1,
	GBCREATE = 2,
	GBOVERWR = 3,
};

#define HOWMANY(a) (((a)+(RBLOCK-1))/RBLOCK)