diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2016-12-23 22:19:13 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2016-12-23 23:22:22 +0100 |
| commit | 31bb7fd29bca88f86860bdc8aa7f09c3e8e3f111 (patch) | |
| tree | 4e98d54eb2ec60d9536c8fe2b322440a7b4dbf78 /src | |
| download | extfs-31bb7fd29bca88f86860bdc8aa7f09c3e8e3f111.tar.xz extfs-31bb7fd29bca88f86860bdc8aa7f09c3e8e3f111.zip | |
Initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/extsh.cpp | 19 | ||||
| -rw-r--r-- | src/fs/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/fs/extfs.cpp | 35 |
4 files changed, 72 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..e09c4a2 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +add_subdirectory(fs) + +add_executable(extsh + extsh.cpp + ) +target_link_libraries(extsh + extfs + ) diff --git a/src/extsh.cpp b/src/extsh.cpp new file mode 100644 index 0000000..477f6c8 --- /dev/null +++ b/src/extsh.cpp @@ -0,0 +1,19 @@ +#include "fs/extfs.hpp" + +#include <iostream> +#include <string> + +int main(int argc, char const * argv[]) + { + auto const & path = [&]{ return std::string{argc > 1 ? argv[1] : "vdisk.img"}; }(); + auto const & disk = fs::extfs{path}; + + if(disk) + { + std::clog << "[EXT2] Successfully opened ext*fs at: '" << path << "'\n"; + } + else + { + std::clog << "[EXT2] Failed to open ext*fs at: '" << path << "'\n"; + } + } 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; + } + + } |
