summaryrefslogtreecommitdiff
path: root/src/fs/extfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/extfs.cpp')
-rw-r--r--src/fs/extfs.cpp35
1 files changed, 35 insertions, 0 deletions
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;
+ }
+
+ }