Begin adding write support.
[bluesky.git] / bluesky.h
index 40c989b..c85fd70 100644 (file)
--- a/bluesky.h
+++ b/bluesky.h
@@ -65,6 +65,7 @@ typedef struct {
 
     /* File-specific fields */
     uint64_t size;
+    GArray *blocks;
 
     /* Directory-specific fields */
     GSequence *dirents;
@@ -79,8 +80,28 @@ typedef struct {
     gchar *name;
     uint64_t hash;
     uint64_t inum;
-} BlueSkyDirent ;
+} BlueSkyDirent;
+
+/* File data is divided into fixed-size blocks (except the last block which may
+ * be short?).  These blocks are backed by storage in a key/value store, but
+ * may also be dirty if modifications have been made in-memory that have not
+ * been committed. */
+#define BLUESKY_BLOCK_SIZE 32768ULL
+#define BLUESKY_MAX_FILE_SIZE (BLUESKY_BLOCK_SIZE << 24)
+typedef enum {
+    BLUESKY_BLOCK_ZERO = 0,     /* Data is all zeroes, not explicitly stored */
+    BLUESKY_BLOCK_REF = 1,      /* Reference to key/value store, not cached */
+    BLUESKY_BLOCK_CACHED = 2,   /* Data is cached in memory, clean */
+    BLUESKY_BLOCK_DIRTY = 3,    /* Data needs to be committed to store */
+} BlueSkyBlockType;
+
+typedef struct {
+    BlueSkyBlockType type;
+    gchar *ref;                 /* Name of data block in the backing store */
+    gchar *data;                /* Pointer to data in memory */
+} BlueSkyBlock;
 
+BlueSkyFS *bluesky_new_fs(gchar *name);
 int64_t bluesky_get_current_time();
 uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs);
 BlueSkyInode *bluesky_new_inode(uint64_t inum, BlueSkyFileType type);
@@ -95,4 +116,6 @@ gboolean bluesky_directory_insert(BlueSkyInode *dir, gchar *name,
                                   uint64_t inum);
 void bluesky_directory_dump(BlueSkyInode *dir);
 
+void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size);
+
 #endif