Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / filesys / SFS / SFSchecksum / SFSchecksum.c
blob5e409eb65c1dc58c1cae6508a7427ca6ffe4b461
1 #include <dos/dos.h>
2 #include <exec/memory.h>
3 #include <proto/dos.h>
4 #include <proto/exec.h>
6 #include "/fs/blockstructure.h"
8 /* ASM prototypes */
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 */
22 LONG main() {
23 struct RDArgs *readarg;
24 UBYTE template[]="FILE/A,BLOCKSIZE/N/A,BLOCK/N\n";
26 struct {char *file;
27 ULONG *blocksize;
28 ULONG *blockno;} arglist={NULL};
30 if((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",39))!=0) {
31 if((readarg=ReadArgs(template,(LONG *)&arglist,0))!=0) {
32 ULONG *buffer;
33 ULONG blockno=0;
35 if(arglist.blockno!=0) {
36 blockno=*arglist.blockno;
39 bytes_block=*arglist.blocksize;
41 if((buffer=AllocVec(*arglist.blocksize, MEMF_PUBLIC))!=0) {
42 BPTR fh;
44 if((fh=Open(arglist.file, MODE_OLDFILE))!=0) {
45 if((Seek(fh, *arglist.blocksize * blockno, OFFSET_BEGINNING))==0) {
46 ULONG old;
48 if(Read(fh, buffer, *arglist.blocksize)==*arglist.blocksize) {
49 old=AROS_BE2LONG(buffer[1]);
51 setchecksum(buffer);
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]));
58 else {
59 PutStr("End of file reached.\n");
62 else {
63 PrintFault(IoErr(), "error while seeking in file");
66 Close(fh);
68 else {
69 PrintFault(IoErr(), "error while opening file");
72 FreeVec(buffer);
74 else {
75 PutStr("Out of memory\n");
78 FreeArgs(readarg);
80 else {
81 PutStr("wrong arguments\n");
84 CloseLibrary((struct Library *)DOSBase);
86 return(0);
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) {
103 return(TRUE);
105 return(FALSE);