Switch to refcounted strings for storing cached file blocks.
[bluesky.git] / bluesky.h
index 5571db6..856dd75 100644 (file)
--- a/bluesky.h
+++ b/bluesky.h
 #include <stdint.h>
 #include <glib.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct S3Store;
+
 /* Reference-counted blocks of memory, used for passing data in and out of
  * storage backends and in other places. */
 typedef struct {
     gint refcount;
-    gpointer data;
+    gchar *data;
     gsize len;
 } BlueSkyRCStr;
 
@@ -45,6 +51,8 @@ typedef struct {
     gchar *name;                /* Descriptive name for the filesystem */
     GHashTable *inodes;         /* Cached inodes */
     uint64_t next_inum;         /* Next available inode for allocation */
+
+    struct S3Store *store;
 } BlueSkyFS;
 
 /* Inode number of the root directory. */
@@ -60,6 +68,8 @@ typedef struct {
     gint refcnt;                /* May be accessed atomically without lock */
     GMutex *lock;
 
+    BlueSkyFS *fs;
+
     BlueSkyFileType type;
     uint32_t mode;
     uint32_t uid, gid;
@@ -113,14 +123,14 @@ typedef enum {
 typedef struct {
     BlueSkyBlockType type;
     gchar *ref;                 /* Name of data block in the backing store */
-    gchar *data;                /* Pointer to data in memory */
+    BlueSkyRCStr *data;         /* Pointer to data in memory if cached */
 } BlueSkyBlock;
 
 BlueSkyFS *bluesky_new_fs(gchar *name);
 int64_t bluesky_get_current_time();
 void bluesky_inode_update_ctime(BlueSkyInode *inode, gboolean update_mtime);
 uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs);
-BlueSkyInode *bluesky_new_inode(uint64_t inum, BlueSkyFileType type);
+BlueSkyInode *bluesky_new_inode(uint64_t inum, BlueSkyFS *fs, BlueSkyFileType type);
 
 BlueSkyInode *bluesky_get_inode(BlueSkyFS *fs, uint64_t inum);
 void bluesky_insert_inode(BlueSkyFS *fs, BlueSkyInode *inode);
@@ -133,11 +143,20 @@ gboolean bluesky_directory_insert(BlueSkyInode *dir, gchar *name,
 void bluesky_directory_dump(BlueSkyInode *dir);
 
 void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
-void bluesky_block_flush(BlueSkyBlock *block);
+void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block);
+void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block);
 void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size);
 void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
                         const char *data, gint len);
 void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
                        char *buf, gint len);
 
+struct S3Store *s3store_new();
+BlueSkyRCStr *s3store_get(struct S3Store *store, const gchar *key);
+void s3store_put(struct S3Store *store, const gchar *key, BlueSkyRCStr *val);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif