W.I.P AROS port of SDI examples
[AROS.git] / rom / filesys / pfs3 / fs / blocks.h
blob90fc95d959eace9dcdf380e147998e6e4fef352b
1 /* $Id$
2 * $Log: blocks.h $
3 * Revision 1.21 1999/06/13 16:46:01 Michiel
4 * MAXNUMRESERVED raised
6 * Revision 1.20 1999/05/14 11:31:34 Michiel
7 * Long filename support implemented; bugfixes
9 * Revision 1.19 1999/03/09 10:40:11 Michiel
10 * Deldir extension and bitwise reserved roving
12 * Revision 1.18 1998/09/27 11:26:37 Michiel
13 * MAXNUMRESERVED increased
14 * BETA id changed
16 * Revision 1.17 1998/09/03 07:12:14 Michiel
17 * version 17.4
18 * bugfixes 118, 121, 123 and superindexblocks and td64 support
20 * Revision 1.16 1998/08/05 00:33:23 Michiel
21 * MAXDISKSIZE, ID_MUPFS_DISK added
23 * Revision 1.15 1998/05/29 19:13:27 Michiel
24 * Wrongly defined ID_PFS2_DISK
26 * Revision 1.14 1998/05/27 22:35:51 Michiel
27 * Version 17.1 update
29 * Revision 1.12 1998/05/22 22:59:58 Michiel
30 * Datestamps added
32 * Revision 1.11 1998/05/22 21:00:22 Michiel
33 * Added anode roving pointer (overdue checkin)
35 * Revision 1.10 1995/12/29 11:01:53 Michiel
36 * rollover extrafields added
37 * reserved roving stored in rootblockextension
39 * Revision 1.9 1995/11/15 15:38:27 Michiel
40 * rootblock extension defined
41 * cachedblock 'done' field removed
43 * Revision 1.8 1995/11/07 17:31:22 Michiel
44 * cachedblock changeflag and done now are bytes (instead of words)
46 * Revision 1.7 1995/08/04 04:15:30 Michiel
47 * added DELENTRY_PROT_AND_MASK and DELENTRY_PROT_OR_MASK
48 * added disksize (MODE_SIZEFIELD) to rootblock
50 * Revision 1.6 1995/07/28 08:26:55 Michiel
51 * FNSIZE replaced by PATHSIZE and FILENAMESIZE
53 * Revision 1.5 1995/07/21 06:42:07 Michiel
54 * More deldir stuff
56 * Revision 1.4 1995/07/11 09:24:38 Michiel
57 * DELDIR stuff
59 * Revision 1.3 1995/07/10 15:17:13 Michiel
60 * ID_MUAF_DISK and ID_AFS_DISK added
62 * Revision 1.2 1995/02/28 18:29:28 Michiel
63 * extrafields added
65 * Revision 1.1 1995/02/15 16:46:45 Michiel
66 * Initial revision
70 #ifndef _BLOCKS_H
71 #define _BLOCKS_H 1
73 #ifndef DOS_DOSEXTENS_H
74 #include <dos/dosextens.h>
75 #endif
76 #ifndef DEVICES_TRACKDISK_H
77 #include <devices/trackdisk.h>
78 #endif
79 #ifndef PROTO_EXEC_H
80 #include <proto/exec.h>
81 #endif
82 #ifndef PROTO_DOS_H
83 #include <proto/dos.h>
84 #endif
85 #ifndef _STDDEFH
86 #include <stddef.h>
87 #endif
89 #if defined(__GNUC__) || defined(__VBCC__)
90 /* Force SAS/C compatible alignment rules for all these structures */
91 #pragma pack(2)
92 #endif
94 struct bootblock
96 LONG disktype; /* PFS\1 */
97 UBYTE reserved[508];
100 typedef struct rootblock
102 LONG disktype;
103 ULONG options; /* bit 0 is harddisk mode */
104 ULONG datestamp; /* current datestamp */
105 UWORD creationday; /* days since Jan. 1, 1978 (like ADOS; WORD instead of LONG) */
106 UWORD creationminute; /* minutes past modnight */
107 UWORD creationtick; /* ticks past minute */
108 UWORD protection; /* protection bits (ala ADOS) */
109 UBYTE diskname[32]; /* disk label (pascal string) */
110 ULONG lastreserved; /* reserved area. sector number of last reserved block */
111 ULONG firstreserved; /* sector number of first reserved block */
112 ULONG reserved_free; /* number of reserved blocks (blksize blocks) free */
113 UWORD reserved_blksize; /* size of reserved blocks in bytes */
114 UWORD rblkcluster; /* number of sectors in rootblock, including bitmap */
115 ULONG blocksfree; /* blocks free */
116 ULONG alwaysfree; /* minimum number of blocks free */
117 ULONG roving_ptr; /* current LONG bitmapfield nr for allocation */
118 ULONG deldir; /* deldir location (<= 17.8) */
119 ULONG disksize; /* disksize in sectors */
120 ULONG extension; /* rootblock extension (16.4) */
121 ULONG not_used;
122 union
124 UWORD anodeblocks[208]; /* SMALL: 200*84 = 16800 anodes */
125 struct
127 ULONG bitmapindex[5]; /* 5 bitmap indexblocks with 253 bitmap blocks each */
128 ULONG indexblocks[99]; /* 99 index blocks with 253 anode blocks each */
129 } small;
130 struct
132 ULONG bitmapindex[104]; /* 104 bitmap indexblocks = max 104 G */
133 } large;
134 } idx;
135 } rootblock_t;
138 /* structure for both normal as reserved bitmap
139 * normal: normal clustersize
140 * reserved: directly behind rootblock. As long as necessary
142 typedef struct bitmapblock
144 UWORD id; /* BM (bitmap block) */
145 UWORD not_used;
146 ULONG datestamp;
147 ULONG seqnr;
148 ULONG bitmap[0]; /* the bitmap. */
149 } bitmapblock_t;
151 #if defined(__GNUC__) || defined(__VBCC__)
152 #pragma pack()
153 #endif
155 typedef struct cbitmapblock
157 struct cbitmapblock *next;
158 struct cbitmapblock *prev;
159 struct volumedata *volume;
160 ULONG blocknr;
161 ULONG oldblocknr;
162 UWORD used;
163 UBYTE changeflag;
164 UBYTE dummy;
165 struct bitmapblock blk;
166 } cbitmapblock_t;
168 #if defined(__GNUC__) || defined(__VBCC__)
169 #pragma pack(2)
170 #endif
172 typedef struct indexblock
174 UWORD id; /* AI or BI (anode- bitmap index) */
175 UWORD not_used;
176 ULONG datestamp;
177 ULONG seqnr;
178 LONG index[0]; /* the indices */
179 } indexblock_t;
181 #if defined(__GNUC__) || defined(__VBCC__)
182 #pragma pack()
183 #endif
185 typedef struct cindexblock
187 struct cindexblock *next;
188 struct cindexblock *prev;
189 struct volumedata *volume;
190 ULONG blocknr;
191 ULONG oldblocknr;
192 UWORD used;
193 UBYTE changeflag;
194 UBYTE dummy;
195 struct indexblock blk;
196 } cindexblock_t;
198 #if defined(__GNUC__) || defined(__VBCC__)
199 #pragma pack(2)
200 #endif
202 typedef struct anode
204 ULONG clustersize;
205 ULONG blocknr;
206 ULONG next;
207 } anode_t;
209 typedef struct
211 UWORD seqnr;
212 UWORD offset;
213 } anodenr_t;
215 typedef struct anodeblock
217 UWORD id; /* AB */
218 UWORD not_used;
219 ULONG datestamp;
220 ULONG seqnr;
221 ULONG not_used_2;
222 struct anode nodes[0];
223 } anodeblock_t;
225 #if defined(__GNUC__) || defined(__VBCC__)
226 #pragma pack()
227 #endif
229 struct canodeblock
231 struct canodeblock *next; /* for cache list */
232 struct canodeblock *prev;
233 struct volumedata *volume;
234 ULONG blocknr; /* for already cached check */
235 ULONG oldblocknr;
236 UWORD used; /* locknr */
237 UBYTE changeflag; /* dirty flag */
238 UBYTE dummy;
239 struct anodeblock blk;
242 #if defined(__GNUC__) || defined(__VBCC__)
243 #pragma pack(2)
244 #endif
246 // Cached Allocation NODE
247 typedef struct canode
249 ULONG clustersize; // number of blocks in a cluster
250 ULONG blocknr; // the block number
251 ULONG next; // next anode (anodenummer), 0 = eof
252 ULONG nr; // the anodenr
253 } canode_t;
255 struct dirblock
257 UWORD id; /* 'DB' */
258 UWORD not_used;
259 ULONG datestamp;
260 UWORD not_used_2[2];
261 ULONG anodenr; /* anodenr belonging to this directory (points to FIRST block of dir) */
262 ULONG parent; /* parent */
263 UBYTE entries[0]; /* entries */
266 #if defined(__GNUC__) || defined(__VBCC__)
267 #pragma pack()
268 #endif
270 struct cdirblock
272 struct cdirblock *next; // volume cachelist
273 struct cdirblock *prev;
274 struct volumedata *volume;
275 ULONG blocknr; // voor already cached check
276 ULONG oldblocknr;
277 UWORD used;
278 UBYTE changeflag; // size is word, could be byte
279 UBYTE dummy;
280 struct dirblock blk;
283 struct lru_cdirblock
285 struct lru_cdirblock *next;
286 struct lru_cdirblock *prev;
287 struct cdirblock cblk;
290 #if defined(__GNUC__) || defined(__VBCC__)
291 #pragma pack(2)
292 #endif
294 struct direntry
296 UBYTE next; /* sizeof direntry */
297 BYTE type; /* dir, file, link etc */
298 ULONG anode; /* anode number */
299 ULONG fsize; /* sizeof file */
300 UWORD creationday; /* days since Jan. 1, 1978 (like ADOS; WORD instead of LONG) */
301 UWORD creationminute; /* minutes past modnight */
302 UWORD creationtick; /* ticks past minute */
303 UBYTE protection; /* protection bits (like DOS) */
304 UBYTE nlength; /* lenght of filename */
305 UBYTE startofname; /* filename, followed by filenote length & filenote */
306 UBYTE pad; /* make size even */
309 struct extrafields
311 ULONG link; /* link anodenr */
312 UWORD uid; /* user id */
313 UWORD gid; /* group id */
314 ULONG prot; /* byte 1-3 of protection */
315 // rollover fields
316 ULONG virtualsize; /* virtual rollover filesize in bytes (as shown by Examine()) */
317 ULONG rollpointer; /* current start of file AND end of file pointer */
318 // extended file size
319 UWORD fsizex; /* extended bits 32-47 of direntry.fsize */
322 #if defined(__GNUC__) || defined(__VBCC__)
323 #pragma pack()
324 #endif
326 #if DELDIR
328 * del dir
331 #if defined(__GNUC__) || defined(__VBCC__)
332 #pragma pack(2)
333 #endif
335 struct deldirentry
337 ULONG anodenr; /* anodenr */
338 ULONG fsize; /* size of file */
339 UWORD creationday; /* datestamp */
340 UWORD creationminute;
341 UWORD creationtick;
342 UBYTE filename[16]; /* filename; filling up to 30 chars */
343 // was previously filename[18]
344 // now last two bytes used for extended file size
345 UWORD fsizex; /* extended bits 32-47 of fsize */
348 struct deldirblock
350 UWORD id; /* 'DD' */
351 UWORD not_used;
352 ULONG datestamp;
353 ULONG seqnr;
354 UWORD not_used_2[2];
355 UWORD not_used_3; /* roving in older versions (<17.9) */
356 UWORD uid; /* user id */
357 UWORD gid; /* group id */
358 ULONG protection;
359 UWORD creationday;
360 UWORD creationminute;
361 UWORD creationtick;
362 struct deldirentry entries[0]; /* 31 entries */
365 #if defined(__GNUC__) || defined(__VBCC__)
366 #pragma pack()
367 #endif
369 struct cdeldirblock
371 struct cdeldirblock *next; /* currently not used */
372 struct cdeldirblock *prev; /* currently not used */
373 struct volumedata *volume;
374 ULONG blocknr;
375 ULONG oldblocknr;
376 UWORD used;
377 UBYTE changeflag;
378 UBYTE dummy;
379 struct deldirblock blk;
382 #endif
384 #if VERSION23
386 #if defined(__GNUC__) || defined(__VBCC__)
387 #pragma pack(2)
388 #endif
390 struct postponed_op
392 ULONG operation_id; /* which operation is postponed */
393 ULONG argument1; /* operation arguments, e.g. number of blocks */
394 ULONG argument2;
395 ULONG argument3;
398 struct rootblockextension
400 UWORD id; /* id ('EX') */
401 UWORD not_used_1;
402 ULONG ext_options;
403 ULONG datestamp;
404 ULONG pfs2version; /* pfs2 revision under which the disk was formatted */
405 UWORD root_date[3]; /* root directory datestamp */
406 UWORD volume_date[3]; /* volume datestamp */
407 struct postponed_op tobedone; /* postponed operation (curr. only delete) */
408 ULONG reserved_roving; /* reserved roving pointer */
409 UWORD rovingbit; /* bitnr in rootblock->roving_ptr bitmap field */
410 UWORD curranseqnr; /* anodeallocation roving pointer */
411 UWORD deldirroving; /* deldir roving pointer */
412 UWORD deldirsize; /* size of deldir */
413 UWORD fnsize; /* filename size (18.1) */
414 UWORD not_used_2[3];
415 ULONG superindex[16]; /* MODE_SUPERINDEX only. */
416 UWORD dd_uid; /* deldir user id (17.9) */
417 UWORD dd_gid; /* deldir group id */
418 ULONG dd_protection; /* deldir protection */
419 UWORD dd_creationday; /* deldir datestamp */
420 UWORD dd_creationminute;
421 UWORD dd_creationtick;
422 UWORD not_used_3;
423 ULONG deldir[32]; /* 32 deldir blocks */
426 #if defined(__GNUC__) || defined(__VBCC__)
427 #pragma pack()
428 #endif
430 struct crootblockextension
432 struct crootblockextension *next; /* currently not used */
433 struct crootblockextension *prev; /* currently not used */
434 struct volumedata *volume;
435 ULONG blocknr;
436 ULONG oldblocknr;
437 UWORD used;
438 UBYTE changeflag;
439 UBYTE dummy;
440 struct rootblockextension blk;
443 typedef struct crootblockextension crootblockextension_t;
445 /* postponed operations operation_id's */
446 #define PP_FREEBLOCKS_FREE 1
447 #define PP_FREEBLOCKS_KEEP 2
448 #define PP_FREEANODECHAIN 3
450 /* */
451 #endif
453 /* Cached blocks in general
455 struct cachedblock
457 struct cachedblock *next;
458 struct cachedblock *prev;
459 struct volumedata *volume;
460 ULONG blocknr; // the current (new) blocknumber of the block
461 ULONG oldblocknr; // the blocknr before reallocation. NULL if not reallocated.
462 UWORD used; // block locked if used == g->locknr
463 UBYTE changeflag; // dirtyflag
464 UBYTE dummy; // pad to make offset even
465 UBYTE data[0]; // the datablock;
468 struct lru_cachedblock
470 struct lru_cachedblock *next;
471 struct lru_cachedblock *prev;
472 struct cachedblock cblk;
476 /* max length of filename, diskname and comment
477 * FNSIZE is 108 for compatibilty. Used for searching
478 * files.
480 #define FNSIZE 108
481 #define PATHSIZE 256
482 #define FILENAMESIZE (g->fnsize)
483 #define DNSIZE 32
484 #define CMSIZE 80
485 #define MAX_ENTRYSIZE (sizeof(struct direntry) + FNSIZE + CMSIZE + 34)
487 /* limits */
488 #define MAXSMALLBITMAPINDEX 4
489 #define MAXBITMAPINDEX 103
490 // was 28576. was 119837. Nu max reserved bitmap 256K.
491 #define MAXNUMRESERVED (4096 + 255*1024*8)
492 #define MAXSUPER 15
493 #define MAXSMALLINDEXNR 98
494 #if LARGE_FILE_SIZE
495 // last two bytes used for extended file size
496 #define DELENTRYFNSIZE 16
497 #else
498 #define DELENTRYFNSIZE 18
499 #endif
500 /* maximum disksize in sectors, limited by number of bitmapindexblocks
501 * smalldisk = 10.241.440 blocks of 512 byte = 5G
502 * normaldisk = 213.021.952 blocks of 512 byte = 104G
503 * 2k reserved blocks = 104*509*509*32 blocks of 512 byte = 411G
504 * 4k reserved blocks = 1,6T
505 * */
506 #define MAXSMALLDISK (5*253*253*32)
507 #define MAXDISKSIZE1K (104*253*253*32)
508 #define MAXDISKSIZE2K (104*509*509*32)
509 #define MAXDISKSIZE4K ((ULONG)104*1021*1021*32)
510 #define MAXDISKSIZE MAXDISKSIZE4K
512 /* disk id 'PFS\1' */
513 //#ifdef BETAVERSION
514 //#define ID_PFS_DISK (0x42455441L) /* 'BETA' */
515 //#else
516 #define ID_PFS_DISK (0x50465301L) /* 'PFS\1' */
517 //#endif
518 #define ID_BUSY (0x42555359L) /* 'BUSY' */
520 #define ID_MUAF_DISK (0x6d754146L) /* 'muAF' */
521 #define ID_MUPFS_DISK (0x6d755046L) /* 'muPF' */
522 #define ID_AFS_DISK (0x41465301L) /* 'AFS\1' */
523 #define ID_PFS2_DISK (0x50465302L) /* 'PFS\2' */
524 #define ID_AFS_USER_TEST (0x41465355L) /* 'AFSU' */
526 /* block id's */
527 #define DBLKID 0x4442
528 #define ABLKID 0x4142
529 #define IBLKID 0x4942
530 #define BMBLKID 0x424D
531 #define BMIBLKID 0x4D49
532 #define DELDIRID 0x4444
533 #define EXTENSIONID 0x4558 /* 'EX' */
534 #define SBLKID 0x5342 /* 'SB' */
536 /* macros on cachedblocks */
537 #define IsDirBlock(blk) (((UWORD *)(blk->data))[0] == DBLKID)
538 #define IsAnodeBlock(blk) (((UWORD *)(blk->data))[0] == ABLKID)
539 #define IsIndexBlock(blk) (((UWORD *)(blk->data))[0] == IBLKID)
540 #define IsBitmapBlock(blk) (((UWORD *)(blk->data))[0] == BMBLKID)
541 #define IsBitmapIndexBlock(blk) (((UWORD *)(blk->data))[0] == BMIBLKID)
542 #define IsDeldir(blk) (((UWORD *)(blk->data))[0] == DELDIRID)
543 #define IsSuperBlock(blk) (((UWORD *)(blk->data))[0] == SBLKID)
545 /* size of reserved blocks in bytes and blocks
546 * place you can find rootblock
548 #define SIZEOF_RESBLOCK (g->rootblock->reserved_blksize)
549 #define SIZEOF_CACHEDBLOCK (sizeof(struct cachedblock) + SIZEOF_RESBLOCK)
550 #define SIZEOF_LRUBLOCK (sizeof(struct lru_cachedblock) + SIZEOF_RESBLOCK)
551 #define RESCLUSTER (g->currentvolume->rescluster)
552 #define BOOTBLOCK1 0
553 #define BOOTBLOCK2 1
554 #define ROOTBLOCK 2
556 /* Longs per bitmapblock */
557 #define LONGS_PER_BMB ((g->rootblock->reserved_blksize/4)-3)
559 /* get filenote from directory entry */
560 #define FILENOTE(de) ((UBYTE*)(&((de)->startofname) + (de)->nlength))
562 /* get next directory entry */
563 #define NEXTENTRY(de) ((struct direntry*)((UBYTE*)(de) + (de)->next))
564 #define DB_HEADSPACE (sizeof(struct dirblock))
565 #define DB_ENTRYSPACE (SIZEOF_RESBLOCK - sizeof(struct dirblock))
567 /* disk options */
568 #define MODE_HARDDISK 1
569 #define MODE_SPLITTED_ANODES 2
570 #define MODE_DIR_EXTENSION 4
571 #define MODE_DELDIR 8
572 #define MODE_SIZEFIELD 16
573 // rootblock extension
574 #define MODE_EXTENSION 32
575 // if enabled the datestamp was on at format time (!)
576 #define MODE_DATESTAMP 64
577 #define MODE_SUPERINDEX 128
578 #define MODE_SUPERDELDIR 256
579 #define MODE_EXTROVING 512
580 #define MODE_LONGFN 1024
581 #define MODE_LARGEFILE 2048
583 /* direntry macros */
584 // comment: de is struct direntry *
585 #define COMMENT(de) ((UBYTE*)(&((de)->startofname) + (de)->nlength))
586 /* DIRENTRYNAME: DSTR of name. */
587 #define DIRENTRYNAME(de) ((UBYTE*)(&(de->nlength)))
588 // get a pointer to the next direntry; de = struct direntry *
589 #define NEXTENTRY(de) ((struct direntry*)((UBYTE*)(de) + (de)->next))
590 // get first direntry; blok is dirblock
591 #define FIRSTENTRY(blok) ((struct direntry*)((blok)->blk.entries))
592 #define ENTRYLEN(de, comment) ((sizeof(struct direntry) + (de)->nlength + strlen(comment))&0xfffe)
594 #if DELDIR
595 #define DELENTRY_SEP '@'
596 #define DELENTRY_PROT 0x0005
597 #define DELENTRY_PROT_AND_MASK 0xaa0f
598 #define DELENTRY_PROT_OR_MASK 0x0005
599 /* maximum number of entries per block, max deldirblock seqnr */
600 #define DELENTRIES_PER_BLOCK 31
601 #define MAXDELDIR 31
602 #endif /* DELDIR */
604 #if ROLLOVER
605 #define ST_ROLLOVERFILE -16
606 #endif
608 /* predefined anodes */
609 #define ANODE_EOF 0
610 #define ANODE_RESERVED_1 1 // not used by MODE_BIG
611 #define ANODE_RESERVED_2 2 // not used by MODE_BIG
612 #define ANODE_RESERVED_3 3 // not used by MODE_BIG
613 #define ANODE_BADBLOCKS 4 // not used yet
614 #define ANODE_ROOTDIR 5
615 #define ANODE_USERFIRST 6
617 /* Max size reported in DOS ULONG size fields */
618 #define MAXFILESIZE32 0x7fffffff
620 #endif /* _BLOCKS_H */