Encrypt data blocks being stored to S3.
[bluesky.git] / bluesky / bluesky.h
index 856dd75..afb2304 100644 (file)
@@ -31,6 +31,11 @@ void bluesky_string_ref(BlueSkyRCStr *string);
 void bluesky_string_unref(BlueSkyRCStr *string);
 BlueSkyRCStr *bluesky_string_dup(BlueSkyRCStr *string);
 
+/* Cryptographic operations. */
+void bluesky_crypt_init();
+void bluesky_crypt_random_bytes(guchar *buf, gint len);
+BlueSkyRCStr *bluesky_crypt_encrypt(BlueSkyRCStr *in, const uint8_t *key);
+
 /* File types.  The numeric values are chosen to match with those used in
  * NFSv3. */
 typedef enum {
@@ -53,6 +58,8 @@ typedef struct {
     uint64_t next_inum;         /* Next available inode for allocation */
 
     struct S3Store *store;
+
+    uint8_t *encryption_key;
 } BlueSkyFS;
 
 /* Inode number of the root directory. */
@@ -63,10 +70,18 @@ typedef int64_t bluesky_time;
 
 /* In-memory representation of an inode within a Blue Sky server.  This
  * corresponds roughly with information that is committed to persistent
- * storage. */
+ * storage.  Locking/refcounting rules:
+ *   - To access or modify any data fields, the lock must be held.  This
+ *     includes file blocks.
+ *   - One reference is held by the BlueSkyFS inode hash table.  If that is the
+ *     only reference (and the inode is unlocked), the inode is subject to
+ *     dropping from the cache.
+ *   - Any pending operations should hold extra references to the inode as
+ *     appropriate to keep it available until the operation completes.
+ * */
 typedef struct {
-    gint refcnt;                /* May be accessed atomically without lock */
     GMutex *lock;
+    gint refcount;
 
     BlueSkyFS *fs;