From: Michael Vrable Date: Fri, 11 Sep 2009 21:02:53 +0000 (-0700) Subject: Ensure file size is properly serialized/deserialized. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=07eac8709bced5f814a65fa0d5dd62e4bd649a9a;p=bluesky.git Ensure file size is properly serialized/deserialized. --- diff --git a/bluesky/inode.c b/bluesky/inode.c index 3430b19..4d07a52 100644 --- a/bluesky/inode.c +++ b/bluesky/inode.c @@ -180,6 +180,8 @@ void bluesky_inode_fetch(BlueSkyFS *fs, uint64_t inum) char key[64]; sprintf(key, "inode-%016llx", inum); BlueSkyRCStr *data = bluesky_store_get(fs->store, key); + if (data == NULL) + return; BlueSkyInode *inode = bluesky_deserialize_inode(fs, data->data); if (inode != NULL) { diff --git a/bluesky/serialize.c b/bluesky/serialize.c index 8043cc0..eaa9258 100644 --- a/bluesky/serialize.c +++ b/bluesky/serialize.c @@ -18,7 +18,7 @@ /* Magic signature for serialized inodes. */ -#define INODE_MAGIC 0xa6832100943d71e5ULL +#define INODE_MAGIC 0xa6832100943d71e6ULL struct serialized_inode { uint64_t signature; /* INODE_MAGIC */ @@ -55,6 +55,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 +65,7 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode) g_string_append_c(out, '\0'); } break; + } case BLUESKY_DIRECTORY: { @@ -120,6 +124,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); diff --git a/bluesky/store.c b/bluesky/store.c index abe7020..9e0fca1 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -178,7 +178,7 @@ static BlueSkyRCStr *filestore_get(gpointer s, const gchar *key) { gchar *contents = NULL; gsize length; - GError *error; + GError *error = NULL; g_file_get_contents(key, &contents, &length, &error); if (contents == NULL)