Make printf format specifiers 32/64-bit clean.
[bluesky.git] / bluesky / serialize.c
index 8043cc0..c806d88 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <stdint.h>
+#include <inttypes.h>
 #include <glib.h>
 #include <string.h>
 
@@ -18,7 +19,7 @@
 
 /* Magic signature for serialized inodes. */
 
-#define INODE_MAGIC 0xa6832100943d71e5ULL
+#define INODE_MAGIC 0xa6832100943d71e6ULL
 
 struct serialized_inode {
     uint64_t signature;         /* INODE_MAGIC */
@@ -55,6 +56,9 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode)
 
     switch (inode->type) {
     case BLUESKY_REGULAR:
+    {
+        uint64_t size = GUINT64_TO_LE(inode->size);
+        g_string_append_len(out, (gchar *)&size, sizeof(uint64_t));
         for (int i = 0; i < inode->blocks->len; i++) {
             BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
             if (b->ref != NULL)
@@ -62,6 +66,7 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode)
             g_string_append_c(out, '\0');
         }
         break;
+    }
 
     case BLUESKY_DIRECTORY:
     {
@@ -120,6 +125,8 @@ BlueSkyInode *bluesky_deserialize_inode(BlueSkyFS *fs, const gchar *buf)
     /* TODO: Bounds checking */
     switch (inode->type) {
     case BLUESKY_REGULAR:
+        inode->size = GINT64_FROM_LE(*(uint64_t *)buf);
+        buf += sizeof(uint64_t);
         g_array_set_size(inode->blocks,
                          (inode->size + BLUESKY_BLOCK_SIZE - 1)
                           / BLUESKY_BLOCK_SIZE);
@@ -150,7 +157,7 @@ BlueSkyInode *bluesky_deserialize_inode(BlueSkyFS *fs, const gchar *buf)
                                      bluesky_dirent_compare, NULL);
             g_hash_table_insert(inode->dirhash, dirent->name, dirent);
 
-            g_print("  dirent[%08x]: %s -> %lld\n",
+            g_print("  dirent[%08x]: %s -> %"PRIu64"\n",
                     dirent->cookie, dirent->name, dirent->inum);
 
             buf = strchr(d->name, '\0') + 1;