]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - e2fsck/jfs_user.h
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / e2fsck / jfs_user.h
index 16185a5b23d1b94ac773578bc66fef72c8342d4d..d30b728d1e8525210964d377f8612ee0abe6348c 100644 (file)
@@ -38,10 +38,10 @@ struct buffer_head {
 #endif
        io_channel      b_io;
        int             b_size;
-       unsigned long long b_blocknr;
-       int             b_dirty;
-       int             b_uptodate;
        int             b_err;
+       unsigned int    b_dirty:1;
+       unsigned int    b_uptodate:1;
+       unsigned long long b_blocknr;
        char            b_data[1024];
 };
 
@@ -137,6 +137,32 @@ _INLINE_ void do_cache_destroy(lkmem_cache_t *cache)
        free(cache);
 }
 
+/* generic hashing taken from the Linux kernel */
+#define GOLDEN_RATIO_32 0x61C88647
+#define GOLDEN_RATIO_64 0x61C8864680B583EBull
+
+_INLINE_ __u32 __hash_32(__u32 val)
+{
+       return val * GOLDEN_RATIO_32;
+}
+
+_INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
+{
+       /* High bits are more random, so use them. */
+       return __hash_32(val) >> (32 - bits);
+}
+
+_INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
+{
+       if (sizeof(long) >= 8) {
+               /* 64x64-bit multiply is efficient on all 64-bit processors */
+               return val * GOLDEN_RATIO_64 >> (64 - bits);
+       } else {
+               /* Hash 64 bits using only 32x32-bit multiply. */
+               return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
+       }
+}
+
 #undef _INLINE_
 #endif