]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
endianness
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 15 Jan 2016 15:34:30 +0000 (06:34 -0900)
committerKent Overstreet <kent.overstreet@gmail.com>
Sat, 12 Mar 2016 06:18:57 +0000 (21:18 -0900)
bcache-format.c
util.h

index 984d869f3b3aa0a9e82fb3102cb54452e75671bb..665a309c55a5eaedc8bcbc4d30ba3e6f731d3c1b 100644 (file)
@@ -331,8 +331,8 @@ static void format_v0(void)
        sb->offset              = SB_SECTOR;
        sb->version             = BCACHE_SB_VERSION_CDEV_WITH_UUID;
        sb->magic               = BCACHE_MAGIC;
-       sb->block_size  = block_size;
-       sb->bucket_size = bucket_size;
+       sb->block_size          = block_size;
+       sb->bucket_size         = bucket_size;
        sb->set_uuid            = set_uuid;
        sb->nr_in_set           = darray_size(cache_devices);
 
@@ -380,10 +380,10 @@ static void format_v1(void)
        sb = calloc(1, sizeof(*sb) + sizeof(struct cache_member) *
                    darray_size(cache_devices));
 
-       sb->offset      = SB_SECTOR;
-       sb->version     = BCACHE_SB_VERSION_CDEV_V3;
+       sb->offset      = __cpu_to_le64(SB_SECTOR);
+       sb->version     = __cpu_to_le64(BCACHE_SB_VERSION_CDEV_V3);
        sb->magic       = BCACHE_MAGIC;
-       sb->block_size  = block_size;
+       sb->block_size  = __cpu_to_le16(block_size);
        sb->set_uuid    = set_uuid;
        sb->user_uuid   = user_uuid;
        sb->nr_in_set   = darray_size(cache_devices);
@@ -412,13 +412,13 @@ static void format_v1(void)
                        (i - cache_devices.item);
 
                uuid_generate(m->uuid.b);
-               m->nbuckets     = i->nbuckets;
-               m->first_bucket = i->first_bucket;
-               m->bucket_size  = i->bucket_size;
+               m->nbuckets     = __cpu_to_le64(i->nbuckets);
+               m->first_bucket = __cpu_to_le16(i->first_bucket);
+               m->bucket_size  = __cpu_to_le16(i->bucket_size);
 
-               if (m->nbuckets < 1 << 7)
+               if (__le64_to_cpu(m->nbuckets < 1 << 7))
                        die("Not enough buckets: %llu, need %u",
-                           m->nbuckets, 1 << 7);
+                           __le64_to_cpu(m->nbuckets), 1 << 7);
 
                SET_CACHE_TIER(m,               i->tier);
                SET_CACHE_REPLICATION_SET(m,    i->replication_set);
@@ -426,7 +426,7 @@ static void format_v1(void)
                SET_CACHE_DISCARD(m,            discard);
        }
 
-       sb->u64s = bch_journal_buckets_offset(sb);
+       sb->u64s = __cpu_to_le16(bch_journal_buckets_offset(sb));
 
        darray_foreach(i, cache_devices) {
                char uuid_str[40], set_uuid_str[40];
@@ -435,7 +435,8 @@ static void format_v1(void)
 
                sb->disk_uuid   = m->uuid;
                sb->nr_this_dev = i - cache_devices.item;
-               sb->csum        = csum_set(sb, CACHE_SB_CSUM_TYPE(sb));
+               sb->csum        = __cpu_to_le64(__csum_set(sb, __le16_to_cpu(sb->u64s),
+                                                          CACHE_SB_CSUM_TYPE(sb)));
 
                uuid_unparse(sb->disk_uuid.b, uuid_str);
                uuid_unparse(sb->user_uuid.b, set_uuid_str);
@@ -450,12 +451,12 @@ static void format_v1(void)
                       "first_bucket:           %u\n",
                       uuid_str, set_uuid_str,
                       (unsigned) sb->version,
-                      m->nbuckets,
-                      sb->block_size,
-                      m->bucket_size,
+                      __le64_to_cpu(m->nbuckets),
+                      __le16_to_cpu(sb->block_size),
+                      __le16_to_cpu(m->bucket_size),
                       sb->nr_in_set,
                       sb->nr_this_dev,
-                      m->first_bucket);
+                      __le16_to_cpu(m->first_bucket));
 
                do_write_sb(i->fd, sb);
        }
diff --git a/util.h b/util.h
index 89222665cb113f1292119f40dadba63d9858a1d0..2af277a1415c4d3434fcf03b60a9215ec6b64482 100644 (file)
--- a/util.h
+++ b/util.h
@@ -72,14 +72,16 @@ u64 bch_checksum(unsigned, const void *, size_t);
 #define __bset_bkey_last(_set)                                         \
         __bkey_idx((_set), (_set)->u64s)
 
-#define csum_set(i, type)                                              \
+#define __csum_set(i, u64s, type)                                      \
 ({                                                                     \
-       void *start = ((void *) (i)) + sizeof(uint64_t);                \
-       void *end = __bset_bkey_last(i);                                \
+       const void *start = ((const void *) (i)) + sizeof(u64);         \
+       const void *end = __bkey_idx(i, u64s);                          \
                                                                        \
        bch_checksum(type, start, end - start);                         \
 })
 
+#define csum_set(i, type)      __csum_set(i, (i)->u64s, type)
+
 int bcachectl_open(void);
 
 #include <dirent.h>