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
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
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
20 * Revision 2.3 1999/05/04 17:59:09 Michiel
21 * check mode, logfile, search rootblock implemented
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
44 #include <clib/macros.h>
45 #define min(a,b) MIN(a,b)
46 #define max(a,b) MAX(a,b)
49 typedef unsigned long uint32
;
50 typedef unsigned short uint16
;
51 typedef unsigned char uint8
;
55 typedef enum {false, true} bool;
57 // last two bytes used for extended file size
58 #define DELENTRYFNSIZE 16
64 #define FILENAMESIZE 32
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 /**************************************
75 **************************************/
81 #define TD_FORMAT64 27
84 /**************************************
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
99 UWORD
*SupportedCommands
;
103 #define ACCESS_UNDETECTED 0
106 #define ACCESS_TD64 3
109 /**************************************
111 **************************************/
113 /* blocknr has to be initialised on a never used blocknr
114 * to prevent it to be considered a loaded cacheline.
119 struct cacheline
*next
;
120 struct cacheline
*prev
;
121 uint32 blocknr
; /* 1 == unused */
128 struct MinList LRUqueue
;
129 struct MinList LRUpool
;
130 uint32 linesize
; // linesize in blocks
132 struct cacheline
*cachelines
;
135 extern struct cache cache
;
137 /**************************************
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)
151 reservedblock_t
*data
;
169 extensionblock_t
*data
;
170 } c_extensionblock_t
;
190 /* note: data in b allocated by build code */
191 typedef struct buildblock
193 struct buildblock
*next
;
194 struct buildblock
*prev
;
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
206 extern rootblock_t
*rbl
;
207 extern c_extensionblock_t rext
;
209 /**************************************
211 **************************************/
213 /* abort flag, filled by trap */
214 extern bool aborting
;
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 */
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
241 e_none
= 0, /* no error */
255 e_block_outside_partition
,
256 e_block_outside_reserved
,
261 e_reserved_area_error
,
262 e_outside_bitmap_error
,
271 /**************************************
273 **************************************/
278 #define BM_FINISHED 8
280 #define InvalidBitmap(bitmap) (bitmap->valid = false)
281 #define IsBitmapValid(bitmap) (bitmap && bitmap->valid)
285 bool valid
; /* fix only possible if valid */
291 uint32 lwsize
; /* size in longwords */
296 /**************************************
298 **************************************/
301 /* initialise size */
302 uint32 firstblock
; /* abs blocknr, first and last block */
304 uint32 disksize
; /* disksize in blocks */
305 uint32 lastreserved
; /* rel blocknr, last reserved block */
306 uint32 blocksize
; /* physical blocksize in bytes */
316 error_t (*getblock
)(cachedblock_t
*blok
, uint32 bloknr
);
317 error_t (*writeblock
)(cachedblock_t
*blok
);
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
);
332 bool td64mode
, nsdmode
;
333 int standardscan
; /* 0=not done/needed, 1=fixed, -1=not fixable */
336 bitmap_t
*mainbitmap
;
337 bitmap_t
*anodebitmap
;
341 struct MinList buildblocks
; /* elements are of type buildblock */
344 struct FileSysStartupMsg
*fssm
;
345 struct DosEnvec
*dosenvec
;
346 char devicename
[FNSIZE
];
347 char execdevice
[FNSIZE
];
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
);
357 extern volume_t volume
;
376 /**************************************
378 **************************************/
380 typedef struct scanelement
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 /**********************************************************************/
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) )
415 /* NewList/Remove as macro:
417 * (x)->mlh_Head = (struct MinNode *)&((x)->mlh_Tail); \
418 * (x)->mlh_Tail = NULL; \
419 * (x)->mlh_TailPred = (struct MinNode *)(x)
422 * (x)->prev->next = (x)->next;
423 * (x)->next->prev = (x)->prev;
427 /**************************************
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);
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);
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) { };
497 void __regargs
__chkabort(void);