Start at writing out inode maps to cloud storage.
[bluesky.git] / bluesky / cloudlog.c
index bf7d22e..beaf1b4 100644 (file)
@@ -180,22 +180,14 @@ void bluesky_cloudlog_insert(BlueSkyCloudLog *log)
     g_mutex_unlock(log->fs->lock);
 }
 
-struct log_header {
+struct cloudlog_header {
     char magic[4];
-    uint32_t size;
+    uint8_t type;
     BlueSkyCloudID id;
-    uint32_t pointer_count;
+    uint32_t size1, size2, size3;
 } __attribute__((packed));
 
-struct logref {
-    BlueSkyCloudID id;
-    BlueSkyCloudPointer location;
-} __attribute__((packed));
-
-struct log_footer {
-    char refmagic[4];
-    struct logref refs[0];
-};
+#define CLOUDLOG_MAGIC "AgI-"
 
 /* Ensure that a cloud log item is loaded in memory, and if not read it in.
  * TODO: Make asynchronous, and make this also fetch from the cloud.  Right now
@@ -251,22 +243,29 @@ BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log,
 
     bluesky_cloudlog_stats_update(log, -1);
 
+    GString *data1 = g_string_new("");
+    GString *data2 = g_string_new("");
+    GString *data3 = g_string_new("");
+    bluesky_serialize_cloudlog(log, data1, data2, data3);
+
     /* TODO: Right now offset/size are set to the raw data, but we should add
      * header parsing to the code which loads objects back in. */
     log->location = state->location;
-    log->location.offset = state->data->len + sizeof(struct log_header);
-    log->location.size = log->data->len;
-        /* = sizeof(struct log_header) + sizeof(BlueSkyCloudID) * 0
-           + log->data->len; */
-
-    struct log_header header;
-    memcpy(header.magic, "AgI ", 4);
-    header.size = GUINT32_TO_LE(log->location.size);
+    log->location.offset = state->data->len + sizeof(struct cloudlog_header);
+    log->location.size = data1->len;
+
+    struct cloudlog_header header;
+    memcpy(header.magic, CLOUDLOG_MAGIC, 4);
+    header.type = log->type + '0';
+    header.size1 = GUINT32_TO_LE(data1->len);
+    header.size2 = GUINT32_TO_LE(data2->len);
+    header.size3 = GUINT32_TO_LE(data3->len);
     header.id = log->id;
-    header.pointer_count = GUINT32_TO_LE(0);
 
     g_string_append_len(state->data, (const char *)&header, sizeof(header));
-    g_string_append_len(state->data, log->data->data, log->data->len);
+    g_string_append_len(state->data, data1->str, data1->len);
+    g_string_append_len(state->data, data2->str, data2->len);
+    g_string_append_len(state->data, data3->str, data3->len);
 
     /* If the object we flushed was an inode, update the inode map. */
     if (log->type == LOGTYPE_INODE) {