#pragma once

#include <hilbert/kernel/storage.hpp>

namespace hilbert::kernel::storage::fs {

  class tarfs_instance : public file_system_instance {

  private:
    block_device *bd;

    fs_result next_node(node_id_t node, node_id_t &out);
    fs_result read_full_name(node_id_t node, utility::string &out);
    //len <= 12
    fs_result read_num(uint64_t offset, unsigned len, uint64_t &out);
    fs_result first_child_starting_at(
      node_id_t parent, node_id_t start, node_id_t &out);
    fs_result get_dir_entry(node_id_t node, dir_entry &entry);

  public:
    tarfs_instance(block_device *bd);

    fs_result get_root_node(node_id_t &out);
    fs_result get_first_child(node_id_t node,
      dir_entry &out, directory_iter_t &iter_out);
    fs_result get_next_child(
      node_id_t node, dir_entry &out, directory_iter_t &iter);
    fs_result read_bytes_from_file(
      node_id_t node, uint64_t start, uint64_t count, void *into);

  };

}
