configure: when detecting linux include directory for kernel compiler use target...
[AROS.git] / rom / filesys / pfs3 / pfsdoctor / doctor.h
blob6afa8747ec83688ec3b202b33c053cfdbbf72bc1
1 /* $Id$
2 * $Log: doctor.h $
3 * Revision 2.8 1999/09/11 16:45:50 Michiel
4 * Versie 1.5 with Unformat and Repair nodos
6 * Revision 2.7 1999/09/10 22:15:35 Michiel
7 * Bugfixes etc (1.4)
9 * Revision 2.6 1999/05/28 05:07:33 Michiel
10 * Fixed bug occuring on empty directory blocks
11 * Added rbl.always fix; improved rbl.disksize fix
12 * Reduced cachesize
14 * Revision 2.5 1999/05/17 10:32:39 Michiel
15 * long filename support, verbose fixes
17 * Revision 2.4 1999/05/07 16:49:00 Michiel
18 * bugfixes etc
20 * Revision 2.3 1999/05/04 17:59:09 Michiel
21 * check mode, logfile, search rootblock implemented
22 * bugfixes
24 * Revision 2.2 1999/05/04 04:27:13 Michiel
25 * debugged upto buildrext
27 * Revision 2.1 1999/04/30 12:17:58 Michiel
28 * Accepts OK disks, bitmapfix and hardlink fix works
30 * Revision 1.1 1999/04/19 22:16:53 Michiel
31 * Initial revision
34 * Doctor headerfile
35 * date: 1999/03/01
36 * author: Michiel
37 */
39 #define __USE_SYSBASE
43 #ifndef min
44 #include <clib/macros.h>
45 #define min(a,b) MIN(a,b)
46 #define max(a,b) MAX(a,b)
47 #endif
49 typedef unsigned long uint32;
50 typedef unsigned short uint16;
51 typedef unsigned char uint8;
52 typedef long int32;
53 typedef short int16;
54 typedef char int8;
55 typedef enum {false, true} bool;
57 // last two bytes used for extended file size
58 #define DELENTRYFNSIZE 16
60 #define BOOTBLOCK 0
61 #define ROOTBLOCK 2
62 #define FNSIZE 108
63 #define PATHSIZE 256
64 #define FILENAMESIZE 32
65 #define DNSIZE 32
66 #define CMSIZE 80
67 #define MAX_ENTRYSIZE (sizeof(struct direntry) + FILENAMESIZE + CMSIZE + 32)
68 #define LONGS_PER_BMB ((rbl->reserved_blksize/4)-3)
69 #define INDEX_PER_BLOCK ((rbl->reserved_blksize - 3*4) / sizeof(LONG))
70 #define ANODES_PER_BLOCK ((rbl->reserved_blksize - 4*4) / sizeof(anode_t))
71 #define FIRSTENTRY(blok) ((struct direntry*)((blok)->data->entries))
73 /**************************************
74 * TD64 support
75 **************************************/
77 #ifndef TD_READ64
78 #define TD_READ64 24
79 #define TD_WRITE64 25
80 #define TD_SEEK64 26
81 #define TD_FORMAT64 27
82 #endif
84 /**************************************
85 * NSD support
86 **************************************/
88 #ifndef NSCMD_DEVICEQUERY
89 #define NSCMD_DEVICEQUERY 0x4000
90 #define NSCMD_TD_READ64 0xc000
91 #define NSCMD_TD_WRITE64 0xc001
92 #define NSDEVTYPE_TRACKDISK 5
93 struct NSDeviceQueryResult
95 ULONG DevQueryFormat;
96 ULONG SizeAvailable;
97 UWORD DeviceType;
98 UWORD DeviceSubType;
99 UWORD *SupportedCommands;
101 #endif
103 #define ACCESS_UNDETECTED 0
104 #define ACCESS_STD 1
105 #define ACCESS_DS 2
106 #define ACCESS_TD64 3
107 #define ACCESS_NSD 4
109 /**************************************
110 * Cache
111 **************************************/
113 /* blocknr has to be initialised on a never used blocknr
114 * to prevent it to be considered a loaded cacheline.
116 #define CL_UNUSED 1
117 struct cacheline
119 struct cacheline *next;
120 struct cacheline *prev;
121 uint32 blocknr; /* 1 == unused */
122 bool dirty;
123 uint8 *data;
126 struct cache
128 struct MinList LRUqueue;
129 struct MinList LRUpool;
130 uint32 linesize; // linesize in blocks
131 uint32 nolines;
132 struct cacheline *cachelines;
135 extern struct cache cache;
137 /**************************************
138 * Blocks
139 **************************************/
141 enum mode {check=0, build, repair, search, unformat, done};
142 extern enum mode mode;
144 /* mode for cached block can be:
145 * 'check' -- loaded in cache voor check etc --> indirect (by value) edit
146 * 'build' -- loaded in buildblock cache. --> direct edit (by reference)
148 typedef struct {
149 uint32 blocknr;
150 enum mode mode;
151 reservedblock_t *data;
152 } cachedblock_t;
154 typedef struct {
155 uint32 blocknr;
156 enum mode mode;
157 dirblock_t *data;
158 } c_dirblock_t;
160 typedef struct {
161 uint32 blocknr;
162 enum mode mode;
163 indexblock_t *data;
164 } c_indexblock_t;
166 typedef struct {
167 uint32 blocknr;
168 enum mode mode;
169 extensionblock_t *data;
170 } c_extensionblock_t;
172 typedef struct {
173 uint32 blocknr;
174 enum mode mode;
175 deldirblock_t *data;
176 } c_deldirblock_t;
178 typedef struct {
179 uint32 blocknr;
180 enum mode mode;
181 anodeblock_t *data;
182 } c_anodeblock_t;
184 typedef struct {
185 uint32 blocknr;
186 enum mode mode;
187 bitmapblock_t *data;
188 } c_bitmapblock_t;
190 /* note: data in b allocated by build code */
191 typedef struct buildblock
193 struct buildblock *next;
194 struct buildblock *prev;
195 cachedblock_t b;
196 } buildblock_t;
198 typedef struct canode
200 ULONG clustersize; // number of blocks in cluster
201 ULONG blocknr; // the block number
202 ULONG next; // next anode (anode number), 0 = eof
203 ULONG nr; // the anode number
204 } canode_t;
206 extern rootblock_t *rbl;
207 extern c_extensionblock_t rext;
209 /**************************************
210 * StandardScan
211 **************************************/
213 /* abort flag, filled by trap */
214 extern bool aborting;
216 /* maxima
218 #define MAX_PASS 7
220 /* options for StandardScan() (flags)
222 #define SSF_CHECK 1 /* check consistency? */
223 #define SSF_FIX 2 /* fix errors? */
224 #define SSF_ANALYSE 4 /* analyse volume, count things etc ? */
225 #define SSF_UNFORMAT 8 /* undo fast format */
227 /* option flags
229 #define SSF_GEN_RESBITMAP 16
230 #define SSF_GEN_ANODEBITMAP 32
231 #define SSF_GEN_MAINBITMAP 64
232 #define SSF_GEN_BMMASK (SSF_GEN_RESBITMAP|SSF_GEN_ANODEBITMAP|SSF_GEN_MAINBITMAP)
233 #define SSF_VERBOSE 128
235 /* ready flags
238 /* errors
240 typedef enum {
241 e_none = 0, /* no error */
242 e_aborted,
243 e_dirty,
244 e_remove,
245 e_repartition,
246 e_empty,
247 e_not_found,
248 e_out_of_memory,
249 e_fatal_error,
250 e_rbl_not_found,
251 e_max_pass_exceeded,
252 e_res_bitmap_fail,
253 e_main_bitmap_fail,
254 e_anode_bitmap_fail,
255 e_block_outside_partition,
256 e_block_outside_reserved,
257 e_options_error,
258 e_direntry_error,
259 e_invalid_softlink,
260 e_anode_error,
261 e_reserved_area_error,
262 e_outside_bitmap_error,
263 e_double_allocation,
264 e_number_error,
265 e_syntax_error,
266 e_read_error,
267 e_write_error,
268 e_alloc_fail
269 } error_t;
271 /**************************************
272 * Bitmap
273 **************************************/
275 #define BM_ENABLED 1
276 #define BM_REBUILD 2
277 #define BM_COMPARE 4
278 #define BM_FINISHED 8
280 #define InvalidBitmap(bitmap) (bitmap->valid = false)
281 #define IsBitmapValid(bitmap) (bitmap && bitmap->valid)
283 typedef struct
285 bool valid; /* fix only possible if valid */
286 uint32 errorsfound;
287 uint32 errorsfixed;
288 uint32 start;
289 uint32 stop;
290 uint32 step;
291 uint32 lwsize; /* size in longwords */
293 uint32 *map;
294 } bitmap_t;
296 /**************************************
297 * Volume
298 **************************************/
300 typedef struct {
301 /* initialise size */
302 uint32 firstblock; /* abs blocknr, first and last block */
303 uint32 lastblock;
304 uint32 disksize; /* disksize in blocks */
305 uint32 lastreserved; /* rel blocknr, last reserved block */
306 uint32 blocksize; /* physical blocksize in bytes */
307 int16 blockshift;
308 uint32 rescluster;
310 /* info
312 char diskname[34];
313 int fnsize;
315 /* Access */
316 error_t (*getblock)(cachedblock_t *blok, uint32 bloknr);
317 error_t (*writeblock)(cachedblock_t *blok);
319 /* status
320 * keep message if message==NULL
321 * status 0 = diskname
323 void (*status)(int level, char *message, long maxval);
324 void (*progress)(int level, long progress);
325 void (*updatestats)(void);
326 void (*showmsg)(const char *format, ...);
327 int (*askuser)(char *message, char *okstr, char *cancelstr);
329 /* flags */
330 bool repartitioned;
331 int accessmode;
332 bool td64mode, nsdmode;
333 int standardscan; /* 0=not done/needed, 1=fixed, -1=not fixable */
335 /* bitmaps */
336 bitmap_t *mainbitmap;
337 bitmap_t *anodebitmap;
338 bitmap_t *resbitmap;
340 /* full scan */
341 struct MinList buildblocks; /* elements are of type buildblock */
343 /* private */
344 struct FileSysStartupMsg *fssm;
345 struct DosEnvec *dosenvec;
346 char devicename[FNSIZE];
347 char execdevice[FNSIZE];
348 int execunit;
350 /* device stuff */
351 struct MsgPort *port;
352 struct IOExtTD *request;
353 error_t (*getrawblocks)(uint8 *data, int32 numblock, uint32 bloknr);
354 error_t (*writerawblocks)(uint8 *data, int32 numblock, uint32 bloknr);
355 } volume_t;
357 extern volume_t volume;
359 extern struct stats
361 uint32 blocknr;
362 uint32 prevblknr;
363 int pass;
364 int blockschecked;
365 int numerrors;
366 int errorsfixed;
367 int numfiles;
368 int numdirs;
369 int numsoftlink;
370 int numhardlink;
371 int numrollover;
372 int fragmentedfiles;
373 int anodesused;
374 } stats;
376 /**************************************
377 * Fullscan
378 **************************************/
380 typedef struct scanelement
382 uint32 blocknr;
383 uint32 datestamp;
384 } scanelement_t;
386 void InitFullScan(void);
387 void ExitFullScan(void);
388 error_t AllocBuildBlocks(void);
389 uint32 fs_AllocResBlock(void);
390 error_t Repartition(uint32 bloknr);
391 error_t BuildBootBlock(void);
392 error_t BuildRootBlock(rootblock_t *rbl);
393 error_t BuildRext(c_extensionblock_t *rext);
394 error_t BuildIndexBlock(c_indexblock_t *blk, uint16 bloktype, uint32 seqnr);
395 error_t BuildBitmapBlock(c_bitmapblock_t *blk, uint32 seqnr);
396 void SearchBlocks(scanelement_t el[], uint32 seqlow, uint32 seqhigh, uint32 start, uint32 stop, uint16 bloktype);
397 uint32 SearchBlock(uint16 bloktype, uint32 seqnr, uint32 last, uint32 datestamp, uint32 anodenr, uint32 parent);
398 uint32 SearchLastReserved(volume_t *vol);
399 uint32 SearchFileSystem(int32 startblok, int32 endblok);
401 /**********************************************************************/
402 /* Lists */
403 /**********************************************************************/
404 #define MinAddHead(list, node) AddHead((struct List *)(list), (struct Node *)(node))
405 #define MinAddTail(list, node) AddTail((struct List *)(list), (struct Node *)(node))
406 #define MinInsert(list, node, listnode) Insert((struct List *)list, (struct Node *)node, (struct Node *)listnode)
407 #define MinRemove(node) Remove((struct Node *)node)
408 #define HeadOf(list) ((void *)((list)->mlh_Head))
409 #define IsHead(node) (!((node)->prev->prev))
410 #define IsTail(node) (!((node)->next->next))
411 #ifndef IsMinListEmpty
412 #define IsMinListEmpty(x) ( ((x)->mlh_TailPred) == (struct MinNode *)(x) )
413 #endif
415 /* NewList/Remove as macro:
416 * NewList(x) \
417 * (x)->mlh_Head = (struct MinNode *)&((x)->mlh_Tail); \
418 * (x)->mlh_Tail = NULL; \
419 * (x)->mlh_TailPred = (struct MinNode *)(x)
421 * Remove(x) \
422 * (x)->prev->next = (x)->next;
423 * (x)->next->prev = (x)->prev;
427 /**************************************
428 * Proto
429 **************************************/
431 BOOL OpenDiskDevice(struct FileSysStartupMsg *startup, struct MsgPort **port, struct IOExtTD **request, BOOL *trackdisk);
432 error_t dev_GetBlocks(uint8 *buffer, int32 blocks, uint32 blocknr);
433 error_t dev_GetBlocksDS(uint8 *buffer, int32 blocks, uint32 blocknr);
434 error_t dev_WriteBlocksDS(uint8 *buffer, int32 blocks, uint32 blocknr);
435 error_t dev_WriteBlocks(uint8 *buffer, int32 blocks, uint32 blocknr);
436 error_t dev_WriteBlocksDummy(uint8 *buffer, int32 blocks, uint32 blocknr);
437 void *AllocBufMem(uint32 size);
438 void FreeBufMem (void *mem);
439 int DoSCSICommand(UBYTE *data, ULONG datalen, UBYTE *command, UWORD commandlen, UBYTE direction);
440 UBYTE *BCPLtoCString(STRPTR dest, UBYTE *src);
441 BOOL DetectAccessmode(UBYTE *buffer, BOOL scsidirectfirst);
443 /* reflect updated stats in gui */
444 void guiUpdateStats(void);
445 void guiStatus(int level, char *message, long maxval);
446 void guiProgress(int level, long progress);
447 void guiMsg(const char *format, ...);
448 void dummyMsg(char *message);
449 int guiAskUser(char *message, char *okstr, char *cancelstr);
451 /* functions to call when error found or fixed and new block started */
452 void clearstats(void);
453 void adderror(char *message);
454 void fixederror(char *message);
455 void enterblock(uint32 blocknr);
456 void exitblock(void);
458 /* device.c */
459 error_t InitCache(uint32 linesize, uint32 nolines);
460 error_t c_GetBlock(uint8 *data, uint32 bloknr, uint32 bytes);
461 error_t c_WriteBlock(uint8 *data, uint32 bloknr, uint32 bytes);
462 void UpdateCache(void);
463 void FreeCache(void);
465 /* access.c */
466 BOOL AccessTest(void);
467 cachedblock_t *GetBuildBlock(uint16 bloktype, uint32 seqnr);
468 error_t GetResBlock(cachedblock_t *blok, uint16 bloktype, uint32 seqnr, bool fix);
469 bool GetAnode(canode_t *anode, uint32 anodenr, bool fix);
470 bool SaveAnode(canode_t *anode, uint32 nr);
472 /* standardsscan.c */
473 error_t StandardScan(uint32 opties);
474 bool GetPFS2Revision(char *vstring);
475 error_t vol_GetBlock(cachedblock_t *blok, ULONG bloknr);
476 error_t vol_WriteBlock(cachedblock_t *blok);
477 bool IsRootBlock(rootblock_t *r);
478 error_t ResBlockUsed(uint32 bloknr);
479 error_t RepairSuperIndex(uint32 *bloknr, uint32 seqnr);
480 error_t RepairAnodeIndex(uint32 *bloknr, uint32 seqnr);
481 error_t RepairAnodeBlock(uint32 *bloknr, uint32 seqnr);
482 error_t RepairBitmapIndex(uint32 *bloknr, uint32 seqnr);
483 error_t RepairBitmapBlock(uint32 *bloknr, uint32 seqnr);
484 error_t RepairIndexBlock(uint16 bloktype, error_t (*repairchild)(uint32 *, uint32),
485 uint32 *bloknr, uint32 seqnr);
486 void KillAnodeBitmap(void);
487 void KillMainBitmap(void);
488 void KillReservedBitmap(void);
490 ULONG GetDEFileSize(struct direntry *direntry, struct extrafields *extra, ULONG *high);
491 ULONG GetDDFileSize(struct deldirentry *dde, ULONG *high);
493 #if defined(__GNUC__)
494 static __inline void __chkabort(void) { };
495 #endif
496 #if defined(__SASC)
497 void __regargs __chkabort(void);
498 #endif