return fs;
}
+/* Inode reference counting. */
+void bluesky_inode_ref(BlueSkyInode *inode)
+{
+ g_atomic_int_inc(&inode->refcount);
+}
+
+void bluesky_inode_unref(BlueSkyInode *inode)
+{
+ if (g_atomic_int_dec_and_test(&inode->refcount)) {
+ g_error("Reference count for inode %lld dropped to zero!\n",
+ inode->inum);
+ }
+}
+
/* Allocate a fresh inode number which has not been used before within a
* filesystem. */
uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs)
BlueSkyInode *i = g_new0(BlueSkyInode, 1);
i->lock = g_mutex_new();
+ i->refcount = 1;
i->type = type;
i->fs = fs;
i->inum = inum;
BlueSkyRCStr *string = s3store_get(fs->store, block->ref);
bluesky_string_unref(block->data);
- block->data = string;
+ block->data = bluesky_crypt_decrypt(string, fs->encryption_key);
block->type = BLUESKY_BLOCK_CACHED;
+ bluesky_string_unref(string);
}
/* Write the given block to cloud-backed storage and mark it clean. */
if (block->type != BLUESKY_BLOCK_DIRTY)
return;
+ BlueSkyRCStr *data = block->data;
+ data = bluesky_crypt_encrypt(data, fs->encryption_key);
+
GChecksum *csum = g_checksum_new(G_CHECKSUM_SHA256);
- g_checksum_update(csum, block->data->data, block->data->len);
+ g_checksum_update(csum, data->data, data->len);
gchar *name = g_strdup(g_checksum_get_string(csum));
g_print("Flushing block as %s\n", name);
- s3store_put(fs->store, name, block->data);
+ s3store_put(fs->store, name, data);
g_free(block->ref);
block->ref = name;
block->type = BLUESKY_BLOCK_REF;
g_checksum_free(csum);
+ bluesky_string_unref(data);
}