2 #include <exec/memory.h>
4 #include <proto/exec.h>
6 #include "/fs/blockstructure.h"
10 extern ULONG __asm
RANDOM(register __d0 ULONG
);
11 extern LONG __asm
STACKSWAP(void);
12 extern ULONG __asm
CALCCHECKSUM(register __d0 ULONG
,register __a0 ULONG
*);
13 extern ULONG __asm
MULU64(register __d0 ULONG
,register __d1 ULONG
,register __a0 ULONG
*);
14 extern WORD __asm
COMPRESSFROMZERO(register __a0 UWORD
*,register __a1 UBYTE
*,register __d0 ULONG
);
16 void setchecksum(void *cb
);
18 const char version
[]="\0$VER: SFSchecksum 1.0 (" ADATE
")\r\n";
20 ULONG bytes_block
; /* size of a block in bytes */
23 struct RDArgs
*readarg
;
24 UBYTE
template[]="FILE/A,BLOCKSIZE/N/A,BLOCK/N\n";
28 ULONG
*blockno
;} arglist
={NULL
};
30 if((DOSBase
=(struct DosLibrary
*)OpenLibrary("dos.library",39))!=0) {
31 if((readarg
=ReadArgs(template,(LONG
*)&arglist
,0))!=0) {
35 if(arglist
.blockno
!=0) {
36 blockno
=*arglist
.blockno
;
39 bytes_block
=*arglist
.blocksize
;
41 if((buffer
=AllocVec(*arglist
.blocksize
, MEMF_PUBLIC
))!=0) {
44 if((fh
=Open(arglist
.file
, MODE_OLDFILE
))!=0) {
45 if((Seek(fh
, *arglist
.blocksize
* blockno
, OFFSET_BEGINNING
))==0) {
48 if(Read(fh
, buffer
, *arglist
.blocksize
)==*arglist
.blocksize
) {
49 old
=AROS_BE2LONG(buffer
[1]);
53 Printf("Block is of type 0x%08lx;", AROS_BE2LONG(buffer
[0]));
54 Printf(" ownblock is 0x%08lx\n", AROS_BE2LONG(buffer
[2]));
55 Printf("Checksum for this block was 0x%08lx",old
);
56 Printf(" but should be 0x%08lx\n",AROS_BE2LONG(buffer
[1]));
59 PutStr("End of file reached.\n");
63 PrintFault(IoErr(), "error while seeking in file");
69 PrintFault(IoErr(), "error while opening file");
75 PutStr("Out of memory\n");
81 PutStr("wrong arguments\n");
84 CloseLibrary((struct Library
*)DOSBase
);
91 void setchecksum(void *cb
) {
92 struct fsBlockHeader
*bh
=cb
;
94 bh
->checksum
=0; /* Important! */
95 bh
->checksum
=-CALCCHECKSUM(bytes_block
,cb
);
99 BOOL
checkchecksum(void *d
) {
100 ULONG
*data
=(ULONG
*)d
;
102 if(CALCCHECKSUM(bytes_block
,data
)==0) {