diff options
Diffstat (limited to 'src/fs')
| -rw-r--r-- | src/fs/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/fs/extfs.cpp | 35 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/fs/CMakeLists.txt b/src/fs/CMakeLists.txt new file mode 100644 index 0000000..3ca33b8 --- /dev/null +++ b/src/fs/CMakeLists.txt @@ -0,0 +1,10 @@ +if(EXTFS_BUILD_STATIC) + set(LIBRARY_TYPE "STATIC") +else() + set(LIBRARY_TYPE "SHARED") +endif() + +add_library(extfs + ${LIBRARY_TYPE} + extfs.cpp + ) diff --git a/src/fs/extfs.cpp b/src/fs/extfs.cpp new file mode 100644 index 0000000..19c294b --- /dev/null +++ b/src/fs/extfs.cpp @@ -0,0 +1,35 @@ +#include "fs/detail/superblock.hpp" +#include "fs/extfs.hpp" + +#include <fstream> +#include <string> + +namespace + { + auto constexpr kPrimarySuperblockLocation = 1024; + auto constexpr kExtfsMagic = 0xef53; + + auto read_superblock(std::fstream & stream, fs::detail::extfs_superblock & superblock) + { + auto const originalPosition = stream.tellg(); + stream.seekg(kPrimarySuperblockLocation); + stream.read(reinterpret_cast<char *>(&superblock), sizeof(fs::detail::extfs_superblock)); + stream.seekg(originalPosition); + } + } + +namespace fs + { + + extfs::extfs(std::string const & path, extfs::mode const openMode) : + m_stream{path, std::ios::binary | (openMode == mode::read_only ? std::ios::in : std::ios::in | std::ios::out)} + { + read_superblock(m_stream, m_primarySuperblock); + } + + extfs::operator bool() const + { + return m_stream && m_primarySuperblock.magic_number == kExtfsMagic; + } + + } |
