Whamcloud - gitweb
libext2fs: fix Direct I/O fallback code so it implements RMW correctly
[tools/e2fsprogs.git] / lib / ext2fs / crc32c.c
index c9b610b..2512528 100644 (file)
  */
 #include "config.h"
 #include <stdint.h>
-#include <endian.h>
 #include <stdlib.h>
 #include <stdio.h>
 #define __force
 #define min(x, y)              ((x) > (y) ? (y) : (x))
 #define __ALIGN_KERNEL_MASK(x, mask)   (((x) + (mask)) & ~(mask))
-#define __ALIGN_KERNEL(x, a)   __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_KERNEL(x, a)   __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
 #define ALIGN(x, a)            __ALIGN_KERNEL((x), (a))
-#define PTR_ALIGN(p, a)                ((typeof(p))ALIGN((unsigned long)(p), (a)))
+#define PTR_ALIGN(p, a)                ((__typeof__(p))ALIGN((unsigned long)(p), (a)))
 #include "crc32c_defs.h"
 
+#include "ext2fs.h"
+#ifdef WORDS_BIGENDIAN
+#define __constant_cpu_to_le32(x) ___constant_swab32((x))
+#define __constant_cpu_to_be32(x) (x)
+#define __be32_to_cpu(x) (x)
+#define __cpu_to_be32(x) (x)
+#define __cpu_to_le32(x) (ext2fs_cpu_to_le32((x)))
+#define __le32_to_cpu(x) (ext2fs_le32_to_cpu((x)))
+#else
+#define __constant_cpu_to_le32(x) (x)
+#define __constant_cpu_to_be32(x) ___constant_swab32((x))
+#define __be32_to_cpu(x) (ext2fs_be32_to_cpu((x)))
+#define __cpu_to_be32(x) (ext2fs_cpu_to_be32((x)))
+#define __cpu_to_le32(x) (x)
+#define __le32_to_cpu(x) (x)
+#endif
+
 #if CRC_LE_BITS > 8
 # define tole(x) (__force uint32_t) __constant_cpu_to_le32(x)
 #else
@@ -208,7 +224,7 @@ static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len)
        crc = (__force uint32_t) __cpu_to_le32(crc);
 
        p8 = buf;
-       p32 = (uint32_t *)PTR_ALIGN(p8, 8);
+       p32 = (const uint32_t *)PTR_ALIGN(p8, 8);
        init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len);
        words = (len - init_bytes) >> 3;
        end_bytes = (len - init_bytes) & 7;
@@ -257,7 +273,7 @@ static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len)
 #endif
        }
 
-       p8 = (uint8_t *)(++p32);
+       p8 = (const uint8_t *)(++p32);
 
        for (i = 0; i < end_bytes; i++) {
 #ifndef WORDS_BIGENDIAN
@@ -288,7 +304,7 @@ static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len)
        crc = (__force uint32_t) __cpu_to_be32(crc);
 
        p8 = buf;
-       p32 = (uint32_t *)PTR_ALIGN(p8, 8);
+       p32 = (const uint32_t *)PTR_ALIGN(p8, 8);
        init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len);
        words = (len - init_bytes) >> 3;
        end_bytes = (len - init_bytes) & 7;
@@ -337,7 +353,7 @@ static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len)
 #endif
        }
 
-       p8 = (uint8_t *)(++p32);
+       p8 = (const uint8_t *)(++p32);
 
        for (i = 0; i < end_bytes; i++) {
 #ifndef WORDS_BIGENDIAN
@@ -1101,12 +1117,12 @@ static int test_crc32c(void)
                be = ext2fs_crc32c_be(t->crc, test_buf + t->start, t->length);
                if (le != t->crc_le) {
                        printf("Test %d LE fails, %x != %x\n",
-                              (t - test), le, t->crc_le);
+                              (int) (t - test), le, t->crc_le);
                        failures++;
                }
                if (be != t->crc_be) {
                        printf("Test %d BE fails, %x != %x\n",
-                              (t - test), be, t->crc_be);
+                              (int) (t - test), be, t->crc_be);
                        failures++;
                }
                t++;