From f4aab7f2c2a36f46522ae0c180a82e8bb8d75c6e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 4 Oct 2020 10:54:18 +1100 Subject: [PATCH] store: add old repository code to build --- CMakeLists.txt | 4 +++ emory/store/bits.cpp | 13 +++++++++ emory/store/bits.hpp | 67 ++++++++++++++++++++++++++++++++++++++++++++ emory/store/repo.cpp | 15 ++++++++++ emory/store/repo.hpp | 59 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 emory/store/bits.cpp create mode 100644 emory/store/bits.hpp create mode 100644 emory/store/repo.cpp create mode 100644 emory/store/repo.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6292e4c..3f9ed57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,10 @@ add_library(libemory emory/fs/ostream.hpp emory/fs/xattr.cpp emory/fs/xattr.hpp + emory/store/bits.cpp + emory/store/bits.hpp + emory/store/repo.cpp + emory/store/repo.hpp ) target_link_libraries(libemory cruft acl) diff --git a/emory/store/bits.cpp b/emory/store/bits.cpp new file mode 100644 index 0000000..5dc2e2d --- /dev/null +++ b/emory/store/bits.cpp @@ -0,0 +1,13 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#include "bits.hpp" + + +/////////////////////////////////////////////////////////////////////////////// + diff --git a/emory/store/bits.hpp b/emory/store/bits.hpp new file mode 100644 index 0000000..246d204 --- /dev/null +++ b/emory/store/bits.hpp @@ -0,0 +1,67 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include +#include + +#include + +namespace emory::store::bits { + constexpr std::array MAGIC { 'e', 'r', '0', '0', 0x0d, 0x0a, 0x1a, 0x00, }; + + struct [[gnu::packed]] header { + u08 magic[8]; + u64 version; + struct [[gnu::packed]] { + u64 types; + u64 records; + } entries; + }; + + bool is_valid (header const&) noexcept; + + + struct [[gnu::packed]] type { + u16 system; + u16 index; + u08 count; + u08 length; + u16 reserved; + }; + + + namespace record { + struct data { + cruft::crypto::hash::SHA1::digest_t digest; + u64 first; + u64 last; + }; + } + + + constexpr u16 EMORY = 0x0000; + constexpr u16 POSIX = 0x0001; + + constexpr type DATA { + .system = EMORY, + .index = 0x0001, + .count = 0, + .length = sizeof (record::data), + .reserved = 0, + }; + + constexpr type PATH { + .system = POSIX, + .index = 0x0001, + .count = 0, + .length = 0, + .reserved = 0, + }; +}; diff --git a/emory/store/repo.cpp b/emory/store/repo.cpp new file mode 100644 index 0000000..a35fead --- /dev/null +++ b/emory/store/repo.cpp @@ -0,0 +1,15 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#include "repo.hpp" + + +/////////////////////////////////////////////////////////////////////////////// +struct chunker { + +}; diff --git a/emory/store/repo.hpp b/emory/store/repo.hpp new file mode 100644 index 0000000..1676b56 --- /dev/null +++ b/emory/store/repo.hpp @@ -0,0 +1,59 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include "bits.hpp" + +#include + +namespace emory::store { + struct repo { + repo (cruft::mapped_file &&src); + + cruft::view types (void) const; + + struct record_iterator { + using iterator_tag = std::input_iterator_tag; + using value_type = std::pair; + + record_iterator ( + cruft::view _types, + cruft::view _data + ); + + value_type operator* (void) const; + + record_iterator& operator++ (); + + bool operator== (record_iterator const&) const noexcept; + bool operator!= (record_iterator const&) const noexcept; + + private: + cruft::view m_types; + cruft::view m_data; + }; + + private: + cruft::mapped_file m_src; + }; + + + struct serialiser { + virtual ~serialiser (); + + virtual bits::type type (void) const; + virtual u64 write (cruft::posix::fd &dst, cruft::posix::fd &src); + virtual std::ostream& describe (std::ostream&) const; + }; + + + u64 send (cruft::posix::fd &dst, cruft::posix::fd &src); + + std::ostream& operator<< (std::ostream&, serialiser const&); +}