/*
 * Filesystem object
 *
 * This provides a simple object meant for carrying around the
 * coherent state of the file system.  A file system is defined by a
 * couple of objects (a superblob, a blob index, and an inode log).
 * This bundles them together for ease of use.
 */

#ifndef FS_H
#define FS_H

#include "persifs.h"
#include "memblobindex.h"
#include "disksuperblob.h"
#include "inodelog.h"

class FS
{
public:
  /**
   * Load an entire file system.  filebase is used as the base name
   * from which the file names for the various structures are derived.
   * If the files don't already exist, this creates a new, empty file
   * system.  Otherwise, this loads the file system from those files.
   * This is a factory function.
   */
  static void create(str filebase,
                     callback<void, ref<FS> >::ref cb, cbe error);

  // The superblob of this file system
  ref<superblob> blob;
  // The inode log of this file system
  ref<inodeLog> log;

protected:
  FS(ref<superblob> blob, ref<inodeLog> log);

private:
  static void create_afterBlobIndex(str filebase,
                                    callback<void, ref<FS> >::ref cb, cbe error,
                                    ref<memBlobIndex> bi);
  static void create_afterSuperblob(str filebase,
                                    callback<void, ref<FS> >::ref cb, cbe error,
                                    ref<diskSuperblob> blob);
  static void create_afterInodeLog(str filebase, ref<superblob> blob,
                                   callback<void, ref<FS> >::ref cb, cbe error,
                                   ref<inodeLog> log);
};

#endif // FS_H
