+ fs->store = bluesky_store_new("file");
+ fs->flushd_lock = g_mutex_new();
+ fs->flushd_cond = g_cond_new();
+ fs->locations = g_hash_table_new(bluesky_cloudlog_hash,
+ bluesky_cloudlog_equal);
+ fs->inode_map = g_sequence_new(NULL);
+
+ fs->log_state = g_new0(BlueSkyCloudLogState, 1);
+ fs->log_state->data = g_string_new("");
+ fs->log_state->latest_cleaner_seq_seen = -1;
+ fs->log_state->uploads_pending_lock = g_mutex_new();
+ fs->log_state->uploads_pending_cond = g_cond_new();
+
+ bluesky_cloudlog_threads_init(fs);
+ fs->inode_fetch_thread_pool = g_thread_pool_new(inode_fetch_task, NULL,
+ bluesky_max_threads,
+ FALSE, NULL);
+
+ return fs;
+}
+
+BlueSkyFS *bluesky_init_fs(gchar *name, BlueSkyStore *store,
+ const gchar *master_key)
+{
+ BlueSkyFS *fs = bluesky_new_fs(name);
+ fs->master_key = g_strdup(master_key);
+ fs->keys = g_new(BlueSkyCryptKeys, 1);
+ bluesky_crypt_derive_keys(fs->keys, master_key);
+ fs->store = store;
+ fs->log = bluesky_log_new("journal");
+ fs->log->fs = fs;
+
+ if (bluesky_checkpoint_load(fs)) {
+ g_print("Filesystem checkpoint loaded, starting journal replay...\n");
+ bluesky_replay(fs);
+ g_print("Journal replay complete, filesystem ready.\n");
+ } else {
+ /* Initialize a fresh filesystem */
+ g_print("Initializing new filesystem...\n");
+ BlueSkyInode *root = bluesky_new_inode(BLUESKY_ROOT_INUM, fs,
+ BLUESKY_DIRECTORY);
+ root->nlink = 1;
+ root->mode = 0755;
+ bluesky_insert_inode(fs, root);
+ bluesky_inode_update_ctime(root, TRUE);
+ bluesky_inode_do_sync(root);
+ }
+
+ bluesky_cleaner_thread_launch(fs);