xfs
[Top] [All Lists]

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

To: Dave Chinner <david@xxxxxxxxxxxxx>
Subject: Re: [PATCH 1/2] xfs: add CRC infrastructure
From: Mark Tinguely <tinguely@xxxxxxx>
Date: Thu, 08 Nov 2012 08:42:56 -0600
Cc: xfs@xxxxxxxxxxx
In-reply-to: <1352295452-4726-2-git-send-email-david@xxxxxxxxxxxxx>
References: <1352295452-4726-1-git-send-email-david@xxxxxxxxxxxxx> <1352295452-4726-2-git-send-email-david@xxxxxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:9.0) Gecko/20120122 Thunderbird/9.0
On 11/07/12 07:37, Dave Chinner wrote:
+/*
+ * Calculate the intermediate checksum for a buffer that has the CRC field
+ * inside it.  The offset of the 32bit crc fields is passed as the
+ * cksum_offset parameter.
+ */
+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)));
+}

Why not zero the cksum field and then calculate the crc on the whole buffer?

--Mark.

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