Improve object deserialization: properly parse object headers.
[bluesky.git] / bluesky / bluesky-private.h
index 9f973a3..f1f8ffc 100644 (file)
@@ -181,6 +181,33 @@ typedef enum {
     LOGTYPE_CHECKPOINT_PTR = 5,
 } BlueSkyCloudLogType;
 
+/* Headers that go on items in local log segments and cloud log segments. */
+struct log_header {
+    uint32_t magic;             // HEADER_MAGIC
+    uint8_t type;               // Object type + '0'
+    uint32_t offset;            // Starting byte offset of the log header
+    uint32_t size1;             // Size of the data item (bytes)
+    uint32_t size2;             //
+    uint32_t size3;             //
+    uint64_t inum;              // Inode which owns this data, if any
+    BlueSkyCloudID id;          // Object identifier
+} __attribute__((packed));
+
+struct log_footer {
+    uint32_t magic;             // FOOTER_MAGIC
+    uint32_t crc;               // Computed from log_header to log_footer.magic
+} __attribute__((packed));
+
+struct cloudlog_header {
+    char magic[4];
+    uint8_t type;
+    BlueSkyCloudID id;
+    uint32_t size1, size2, size3;
+} __attribute__((packed));
+
+#define JOURNAL_MAGIC "\nLog"
+#define CLOUDLOG_MAGIC "AgI-"
+
 /* A record which tracks an object which has been written to a local log,
  * cached, locally, and/or written to the cloud. */
 #define CLOUDLOG_JOURNAL    0x01
@@ -208,6 +235,9 @@ struct _BlueSkyCloudLog {
     uint64_t inum;
     int32_t inum_offset;
 
+    // The size of encrypted object data, not including any headers
+    int data_size;
+
     // The location of the object in the cloud, if available.
     BlueSkyCloudPointer location;
 
@@ -245,6 +275,7 @@ void bluesky_cloudlog_unref(BlueSkyCloudLog *log);
 void bluesky_cloudlog_stats_update(BlueSkyCloudLog *log, int type);
 void bluesky_cloudlog_sync(BlueSkyCloudLog *log);
 void bluesky_cloudlog_insert(BlueSkyCloudLog *log);
+BlueSkyCloudLog *bluesky_cloudlog_get(BlueSkyFS *fs, BlueSkyCloudID id);
 void bluesky_cloudlog_fetch(BlueSkyCloudLog *log);
 BlueSkyCloudPointer bluesky_cloudlog_serialize(BlueSkyCloudLog *log,
                                                BlueSkyFS *fs);