--- /dev/null
+#include "cyan_store.h"
+
+#include <fmt/format.h>
+
+#include "common/safe_io.h"
+
+void CyanStore::write_meta(const std::string& key,
+ const std::string& value)
+{
+ std::string v = value;
+ v += "\n";
+ if (int r = safe_write_file(path.c_str(), key.c_str(),
+ v.c_str(), v.length());
+ r < 0) {
+ throw std::runtime_error{fmt::format("unable to write_meta({})", key)};
+ }
+}
+
+std::string CyanStore::read_meta(const std::string& key)
+{
+ char buf[4096];
+ int r = safe_read_file(path.c_str(), key.c_str(),
+ buf, sizeof(buf));
+ if (r <= 0)
+ throw std::runtime_error{fmt::format("unable to read_meta({})", key)};
+ // drop trailing newlines
+ while (r && isspace(buf[r-1])) {
+ --r;
+ }
+ return std::string(buf, r);
+}
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <string>
+#include "include/uuid.h"
+
+// a just-enough store for reading/writing the superblock
+class CyanStore {
+ const std::string path;
+public:
+ CyanStore(const std::string& path)
+ : path{path}
+ {}
+
+ void write_meta(const std::string& key,
+ const std::string& value);
+ std::string read_meta(const std::string& key);
+};