xfs
[Top] [All Lists]

Re: [PATCH 1/2] xfs: add CRC infrastructure

To: Andi Kleen <andi@xxxxxxxxxxxxxx>
Subject: Re: [PATCH 1/2] xfs: add CRC infrastructure
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Thu, 8 Nov 2012 07:31:05 +1100
Cc: xfs@xxxxxxxxxxx
In-reply-to: <m2ehk5qt88.fsf@xxxxxxxxxxxxxx>
References: <1352295452-4726-1-git-send-email-david@xxxxxxxxxxxxx> <1352295452-4726-2-git-send-email-david@xxxxxxxxxxxxx> <m2ehk5qt88.fsf@xxxxxxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Wed, Nov 07, 2012 at 08:21:27AM -0800, Andi Kleen wrote:
> Dave Chinner <david@xxxxxxxxxxxxx> writes:
> > + */
> > +static inline __uint32_t
> > +xfs_start_cksum(char *buffer, size_t length, unsigned long cksum_offset)
> > +{
> > +   __uint32_t zero = 0;
> > +   __uint32_t crc;
> > +
> > +   /* Calculate CRC up to the checksum. */
> > +   crc = crc32c(XFS_CRC_SEED, buffer, cksum_offset);
> > +
> > +   /* Skip checksum field */
> > +   crc = crc32c(crc, &zero, sizeof(__u32));
> > +
> > +   /* Calculate the rest of the CRC. */
> > +   return crc32c(crc, &buffer[cksum_offset + sizeof(__be32)],
> > +                 length - (cksum_offset + sizeof(__be32)));
> 
> Don't you need to remap a zero result to some other value, otherwise a
> real zero checksum will never be checked?

Why would that be necessary? We never include the checksum field in
the calculation when setting it or verifiying it, and the
verification uses exactly the same method as the original
calculation to check the CRC, so it doesn't matter if the CRC value
is zero or not - if it matches (zero or otherwise), the validation
passes....

Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>