#include "crc16.h"
/** CRC table for the CRC-16. The poly is 0x8005 (x16 + x15 + x2 + 1) */
-__u16 const crc16_table[256] = {
+static __u16 const crc16_table[256] = {
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
* @param len number of bytes in the buffer
* @return the updated CRC value
*/
-crc16_t crc16(crc16_t crc, const void *buffer, unsigned int len)
+crc16_t ext2fs_crc16(crc16_t crc, const void *buffer, unsigned int len)
{
const unsigned char *cp = buffer;
while (len--)
- crc = crc16_byte(crc, *cp++);
+ /*
+ * for an unknown reason, PPC treats __u16 as signed
+ * and keeps doing sign extension on the value.
+ * Instead, use only the low 16 bits of an unsigned
+ * int for holding the CRC value to avoid this.
+ */
+ crc = (((crc >> 8) & 0xffU) ^
+ crc16_table[(crc ^ *cp++) & 0xffU]) & 0x0000ffffU;
return crc;
}
#include <ext2fs/ext2_types.h>
-extern __u16 const crc16_table[256];
-
-#ifdef WORDS_BIGENDIAN
/* for an unknown reason, PPC treats __u16 as signed and keeps doing sign
* extension on the value. Instead, use only the low 16 bits of an
* unsigned int for holding the CRC value to avoid this.
*/
-typedef unsigned crc16_t;
-
-static inline crc16_t crc16_byte(crc16_t crc, const unsigned char data)
-{
- return (((crc >> 8) & 0xffU) ^ crc16_table[(crc ^ data) & 0xffU]) &
- 0x0000ffffU;
-}
-#else
-typedef __u16 crc16_t;
-
-static inline crc16_t crc16_byte(crc16_t crc, const unsigned char data)
-{
- return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff];
-}
-#endif
+typedef unsigned int crc16_t;
-extern crc16_t crc16(crc16_t crc, const void *buffer, unsigned int len);
+extern crc16_t ext2fs_crc16(crc16_t crc, const void *buffer, unsigned int len);
#endif /* __CRC16_H */
group = ext2fs_swab32(group);
#endif
- crc = crc16(~0, fs->super->s_uuid, sizeof(fs->super->s_uuid));
- crc = crc16(crc, &group, sizeof(group));
- crc = crc16(crc, desc, offset);
+ crc = ext2fs_crc16(~0, fs->super->s_uuid,
+ sizeof(fs->super->s_uuid));
+ crc = ext2fs_crc16(crc, &group, sizeof(group));
+ crc = ext2fs_crc16(crc, desc, offset);
offset += sizeof(desc->bg_checksum); /* skip checksum */
assert(offset == sizeof(*desc));
/* for checksum of struct ext4_group_desc do the rest...*/
if (offset < fs->super->s_desc_size) {
- crc = crc16(crc, (char *)desc + offset,
+ crc = ext2fs_crc16(crc, (char *)desc + offset,
fs->super->s_desc_size - offset);
}
}
swabgroup = group;
#endif
- crc1 = crc16(~0, sb->s_uuid, sizeof(fs->super->s_uuid));
- crc2 = crc16(crc1, &swabgroup, sizeof(swabgroup));
- crc3 = crc16(crc2, desc, offsetof(struct ext2_group_desc, bg_checksum));
+ crc1 = ext2fs_crc16(~0, sb->s_uuid, sizeof(fs->super->s_uuid));
+ crc2 = ext2fs_crc16(crc1, &swabgroup, sizeof(swabgroup));
+ crc3 = ext2fs_crc16(crc2, desc,
+ offsetof(struct ext2_group_desc, bg_checksum));
printf("%s: UUID %016Lx%016Lx(%04x), grp %u(%04x): %04x=%04x\n",
msg, *(long long *)&sb->s_uuid, *(long long *)&sb->s_uuid[8],
crc1, group, crc2, crc3, ext2fs_group_desc_csum(fs, group));