<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 19 Oct 2006 16:47:41
From   : John Kortink <kortink@...>
Subject: Re: ADFS sector checksums

On Thu, 19 Oct 2006 15:11:16 +0100, you wrote:

>Can anyone give me a definitive answer on ADFS checksums, the document
at
> 
>http://mdfs.net/Docs/Comp/Disk/Format/ADFS
> 
>States it's the sum of  adding with carry the 255 bytes of data and
then adding the sector number.

That's wrong. The sector number has no part in the calculation.
It has been mentioned many times, but it doesn't seem to have
inspired correction of the relevant documents.

A 'C' code fragment that calculates the checksum correctly is :

int ix, sum, cflag;

for (ix = 254, sum = 255, cflag = 0; ix >= 0; ix--)
  if ((cflag = ((sum += sector[ix] + cflag) > 255)) != 0)
    sum -= 256;

sector[255] = sum;

This is exactly what ADFS does itself.

Start with 255, 'clear carry', then add, with carry, all
bytes from offset 254 up to and including 0. The final
'carry out' (from adding the byte at offset 0) is discarded.

A number of messages about this appears mid march 2006 on
this mailing list.


John Kortink

-- 

Email    : kortink@...         
Homepage : http://www.inter.nl.net/users/J.Kortink

GoMMC, the ultimate BBC B/B+/Master storage system :
http://web.inter.nl.net/users/J.Kortink/home/hardware/gommc
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>