1 /*
2  *  ADF Library. (C) 1997-2002 Laurent Clevy
3  *
4  *  adf_blk.h
5  *
6  *  $Id$
7  *
8  *  general blocks structures
9  *
10  *  This file is part of ADFLib.
11  *
12  *  ADFLib is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  ADFLib is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with Foobar; if not, write to the Free Software
24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25  *
26  */
27 
28 
29 #ifndef ADF_BLK_H
30 #define ADF_BLK_H 1
31 
32 #define ULONG   uint32_t
33 #define USHORT  uint16_t
34 #define UCHAR   uint8_t
35 
36 #define LOGICAL_BLOCK_SIZE    512
37 
38 /* ----- FILE SYSTEM ----- */
39 
40 #define FSMASK_FFS         1
41 #define FSMASK_INTL        2
42 #define FSMASK_DIRCACHE    4
43 
44 #define isFFS(c)           ((c)&FSMASK_FFS)
45 #define isOFS(c)           (!((c)&FSMASK_FFS))
46 #define isINTL(c)          ((c)&FSMASK_INTL)
47 #define isDIRCACHE(c)      ((c)&FSMASK_DIRCACHE)
48 
49 
50 /* ----- ENTRIES ----- */
51 
52 /* access constants */
53 
54 #define ACCMASK_D	(1<<0)
55 #define ACCMASK_E	(1<<1)
56 #define ACCMASK_W	(1<<2)
57 #define ACCMASK_R	(1<<3)
58 #define ACCMASK_A	(1<<4)
59 #define ACCMASK_P	(1<<5)
60 #define ACCMASK_S	(1<<6)
61 #define ACCMASK_H	(1<<7)
62 
63 #define hasD(c)    ((c)&ACCMASK_D)
64 #define hasE(c)    ((c)&ACCMASK_E)
65 #define hasW(c)    ((c)&ACCMASK_W)
66 #define hasR(c)    ((c)&ACCMASK_R)
67 #define hasA(c)    ((c)&ACCMASK_A)
68 #define hasP(c)	   ((c)&ACCMASK_P)
69 #define hasS(c)    ((c)&ACCMASK_S)
70 #define hasH(c)    ((c)&ACCMASK_H)
71 
72 
73 /* ----- BLOCKS ----- */
74 
75 /* block constants */
76 
77 #define BM_VALID	-1
78 #define BM_INVALID	0
79 
80 #define HT_SIZE		72
81 #define BM_SIZE     25
82 #define MAX_DATABLK	72
83 
84 #define MAXNAMELEN	30
85 #define MAXCMMTLEN	79
86 
87 
88 /* block primary and secondary types */
89 
90 #define T_HEADER	2
91 #define ST_ROOT		1
92 #define ST_DIR		2
93 #define ST_FILE		-3
94 #define ST_LFILE	-4
95 #define ST_LDIR		4
96 #define ST_LSOFT	3
97 #define T_LIST		16
98 #define T_DATA		8
99 #define T_DIRC		33
100 
101 
102 /*--- blocks structures --- */
103 
104 
105 struct bBootBlock {
106 /*000*/	char	dosType[4];
107 /*004*/	ULONG	checkSum;
108 /*008*/	int32_t	rootBlock;
109 /*00c*/	UCHAR	data[500+512];
110 };
111 
112 
113 struct bRootBlock {
114 /*000*/	int32_t	type;
115         int32_t	headerKey;
116         int32_t	highSeq;
117 /*00c*/	int32_t	hashTableSize;
118         int32_t	firstData;
119 /*014*/	ULONG	checkSum;
120 /*018*/	int32_t	hashTable[HT_SIZE];		/* hash table */
121 /*138*/	int32_t	bmFlag;				/* bitmap flag, -1 means VALID */
122 /*13c*/	int32_t	bmPages[BM_SIZE];
123 /*1a0*/	int32_t	bmExt;
124 /*1a4*/	int32_t	cDays; 	/* creation date FFS and OFS */
125 /*1a8*/	int32_t	cMins;
126 /*1ac*/	int32_t	cTicks;
127 /*1b0*/	char	nameLen;
128 /*1b1*/	char 	diskName[MAXNAMELEN+1];
129         char	r2[8];
130 /*1d8*/	int32_t	days;		/* last access : days after 1 jan 1978 */
131 /*1dc*/	int32_t	mins;		/* hours and minutes in minutes */
132 /*1e0*/	int32_t	ticks;		/* 1/50 seconds */
133 /*1e4*/	int32_t	coDays;	/* creation date OFS */
134 /*1e8*/	int32_t	coMins;
135 /*1ec*/	int32_t	coTicks;
136         int32_t	nextSameHash;	/* == 0 */
137         int32_t	parent;		/* == 0 */
138 /*1f8*/	int32_t	extension;		/* FFS: first directory cache block */
139 /*1fc*/	int32_t	secType;	/* == 1 */
140 };
141 
142 
143 struct bFileHeaderBlock {
144 /*000*/	int32_t	type;		/* == 2 */
145 /*004*/	int32_t	headerKey;	/* current block number */
146 /*008*/	int32_t	highSeq;	/* number of data block in this hdr block */
147 /*00c*/	int32_t	dataSize;	/* == 0 */
148 /*010*/	int32_t	firstData;
149 /*014*/	ULONG	checkSum;
150 /*018*/	int32_t	dataBlocks[MAX_DATABLK];
151 /*138*/	int32_t	r1;
152 /*13c*/	int32_t	r2;
153 /*140*/	int32_t	access;	/* bit0=del, 1=modif, 2=write, 3=read */
154 /*144*/	uint32_t	byteSize;
155 /*148*/	char	commLen;
156 /*149*/	char	comment[MAXCMMTLEN+1];
157         char	r3[91-(MAXCMMTLEN+1)];
158 /*1a4*/	int32_t	days;
159 /*1a8*/	int32_t	mins;
160 /*1ac*/	int32_t	ticks;
161 /*1b0*/	char	nameLen;
162 /*1b1*/	char	fileName[MAXNAMELEN+1];
163         int32_t	r4;
164 /*1d4*/	int32_t	real;		/* unused == 0 */
165 /*1d8*/	int32_t	nextLink;	/* link chain */
166         int32_t	r5[5];
167 /*1f0*/	int32_t	nextSameHash;	/* next entry with sane hash */
168 /*1f4*/	int32_t	parent;		/* parent directory */
169 /*1f8*/	int32_t	extension;	/* pointer to extension block */
170 /*1fc*/	int32_t	secType;	/* == -3 */
171 };
172 
173 
174 /*--- file header extension block structure ---*/
175 
176 struct bFileExtBlock {
177 /*000*/	int32_t	type;		/* == 0x10 */
178 /*004*/	int32_t	headerKey;
179 /*008*/	int32_t	highSeq;
180 /*00c*/	int32_t	dataSize;	/* == 0 */
181 /*010*/	int32_t	firstData;	/* == 0 */
182 /*014*/	ULONG	checkSum;
183 /*018*/	int32_t	dataBlocks[MAX_DATABLK];
184         int32_t	r[45];
185         int32_t	info;		/* == 0 */
186         int32_t	nextSameHash;	/* == 0 */
187 /*1f4*/	int32_t	parent;		/* header block */
188 /*1f8*/	int32_t	extension;	/* next header extension block */
189 /*1fc*/	int32_t	secType;	/* -3 */
190 };
191 
192 
193 
194 struct bDirBlock {
195 /*000*/	int32_t	type;		/* == 2 */
196 /*004*/	int32_t	headerKey;
197 /*008*/	int32_t	highSeq;	/* == 0 */
198 /*00c*/	int32_t	hashTableSize;	/* == 0 */
199         int32_t	r1;		/* == 0 */
200 /*014*/	ULONG	checkSum;
201 /*018*/	int32_t	hashTable[HT_SIZE];		/* hash table */
202         int32_t	r2[2];
203 /*140*/	int32_t	access;
204         int32_t	r4;		/* == 0 */
205 /*148*/	char	commLen;
206 /*149*/	char	comment[MAXCMMTLEN+1];
207         char	r5[91-(MAXCMMTLEN+1)];
208 /*1a4*/	int32_t	days;		/* last access */
209 /*1a8*/	int32_t	mins;
210 /*1ac*/	int32_t	ticks;
211 /*1b0*/	char	nameLen;
212 /*1b1*/	char 	dirName[MAXNAMELEN+1];
213         int32_t	r6;
214 /*1d4*/	int32_t	real;		/* ==0 */
215 /*1d8*/	int32_t	nextLink;	/* link list */
216         int32_t	r7[5];
217 /*1f0*/	int32_t	nextSameHash;
218 /*1f4*/	int32_t	parent;
219 /*1f8*/	int32_t	extension;		/* FFS : first directory cache */
220 /*1fc*/	int32_t	secType;	/* == 2 */
221 };
222 
223 
224 
225 struct bOFSDataBlock{
226 /*000*/	int32_t	type;		/* == 8 */
227 /*004*/	int32_t	headerKey;	/* pointer to file_hdr block */
228 /*008*/	int32_t	seqNum;	/* file data block number */
229 /*00c*/	int32_t	dataSize;	/* <= 0x1e8 */
230 /*010*/	int32_t	nextData;	/* next data block */
231 /*014*/	ULONG	checkSum;
232 /*018*/	UCHAR	data[488];
233 /*200*/	};
234 
235 
236 /* --- bitmap --- */
237 
238 struct bBitmapBlock {
239 /*000*/	ULONG	checkSum;
240 /*004*/	ULONG	map[127];
241 	};
242 
243 
244 struct bBitmapExtBlock {
245 /*000*/	int32_t	bmPages[127];
246 /*1fc*/	int32_t	nextBlock;
247 	};
248 
249 
250 struct bLinkBlock {
251 /*000*/	int32_t	type;		/* == 2 */
252 /*004*/	int32_t	headerKey;	/* self pointer */
253         int32_t	r1[3];
254 /*014*/	ULONG	checkSum;
255 /*018*/	char	realName[64];
256         int32_t	r2[83];
257 /*1a4*/	int32_t	days;		/* last access */
258 /*1a8*/	int32_t	mins;
259 /*1ac*/	int32_t	ticks;
260 /*1b0*/	char	nameLen;
261 /*1b1*/	char 	name[MAXNAMELEN+1];
262         int32_t	r3;
263 /*1d4*/	int32_t	realEntry;
264 /*1d8*/	int32_t	nextLink;
265         int32_t	r4[5];
266 /*1f0*/	int32_t	nextSameHash;
267 /*1f4*/	int32_t	parent;
268         int32_t	r5;
269 /*1fc*/	int32_t	secType;	/* == -4, 4, 3 */
270 	};
271 
272 
273 
274 /*--- directory cache block structure ---*/
275 
276 struct bDirCacheBlock {
277 /*000*/	int32_t	type;		/* == 33 */
278 /*004*/	int32_t	headerKey;
279 /*008*/	int32_t	parent;
280 /*00c*/	int32_t	recordsNb;
281 /*010*/	int32_t	nextDirC;
282 /*014*/	ULONG	checkSum;
283 /*018*/	uint8_t records[488];
284 	};
285 
286 
287 #endif /* ADF_BLK_H */
288 /*##########################################################################*/
289