X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fserialize.c;h=792b01a61b5dd4d08a5c67fd1647c7ef5cf19abe;hb=337e1b04c921c92697b74aed630343c86fabfcbd;hp=44233a147be0a4aceaae1f4b6a813686dedc51aa;hpb=8ec7f79f834ff8c3493b1bbdd63314d276786aa4;p=bluesky.git diff --git a/bluesky/serialize.c b/bluesky/serialize.c index 44233a1..792b01a 100644 --- a/bluesky/serialize.c +++ b/bluesky/serialize.c @@ -67,10 +67,16 @@ BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf) return fs; } -void bluesky_serialize_inode(GString *out, BlueSkyInode *inode) +BlueSkyCloudLog *bluesky_serialize_inode(BlueSkyInode *inode) { + BlueSkyFS *fs = inode->fs; + GString *out = g_string_new(""); struct serialized_inode buf; + BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs, NULL); + cloudlog->type = LOGTYPE_INODE; + cloudlog->inum = inode->inum; + buf.signature = GUINT64_TO_LE(INODE_MAGIC); buf.type = GUINT32_TO_LE(inode->type); buf.mode = GUINT32_TO_LE(inode->mode); @@ -93,11 +99,9 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode) 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); - BlueSkyCloudID id; - memset(&id, 0, sizeof(id)); - if (b->cloudref != NULL) - id = b->cloudref->id; - g_string_append_len(out, (const char *)&id, sizeof(id)); + BlueSkyCloudLog *ref = (b->type == BLUESKY_BLOCK_REF ? b->ref : NULL); + bluesky_cloudlog_ref(ref); + g_array_append_val(cloudlog->links, ref); } break; } @@ -138,12 +142,21 @@ void bluesky_serialize_inode(GString *out, BlueSkyInode *inode) g_warning("Serialization for inode type %d not implemented!\n", inode->type); } + + cloudlog->data = bluesky_string_new_from_gstring(out); + bluesky_cloudlog_insert(cloudlog); + bluesky_cloudlog_stats_update(cloudlog, 1); + + return cloudlog; } /* Deserialize an inode into an in-memory representation. Returns a boolean * indicating whether the deserialization was successful. */ -gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) +gboolean bluesky_deserialize_inode(BlueSkyInode *inode, BlueSkyCloudLog *item) { + g_assert(item->data != NULL); + const char *buf = item->data->data; + if (bluesky_verbose) { g_log("bluesky/serialize", G_LOG_LEVEL_DEBUG, "Deserializing inode %lld...", (long long)inode->inum); @@ -180,15 +193,14 @@ gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) g_array_set_size(inode->blocks, (inode->size + BLUESKY_BLOCK_SIZE - 1) / BLUESKY_BLOCK_SIZE); - // TODO -#if 0 + g_assert(inode->blocks->len == item->links->len); for (int i = 0; i < inode->blocks->len; i++) { BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i); b->type = BLUESKY_BLOCK_REF; - b->ref = g_strdup(buf); - buf += strlen(b->ref) + 1; + b->ref = g_array_index(item->links, BlueSkyCloudLog *, i); + bluesky_cloudlog_ref(b->ref); + b->dirty = NULL; } -#endif break; case BLUESKY_DIRECTORY: @@ -232,3 +244,29 @@ gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) return TRUE; } + +/* Convert an in-memory cloud log item to a more serialized form, suitable + * either for writing to the local journal or the the cloud. */ +void bluesky_serialize_cloudlog(BlueSkyCloudLog *log, + GString *encrypted, // Raw data payload + GString *authenticated, // Block links + GString *writable) // Writable block links +{ + g_string_append_len(encrypted, log->data->data, log->data->len); + for (int i = 0; i < log->links->len; i++) { + BlueSkyCloudLog *ref = g_array_index(log->links, BlueSkyCloudLog *, i); + if (ref != NULL) { + g_string_append_len(authenticated, + (const char *)&ref->id, + sizeof(BlueSkyCloudID)); + // TODO: Fix endianness of output + g_string_append_len(writable, + (const char *)&ref->location, + sizeof(ref->location)); + } else { + BlueSkyCloudID id; + memset(&id, 0, sizeof(id)); + g_string_append_len(authenticated, (const char *)&id, sizeof(id)); + } + } +}