Added initFs.

This commit is contained in:
2015-09-07 03:25:04 -05:00
parent 1ed0991f3b
commit 3d68fa45e5
10 changed files with 44 additions and 16 deletions
+2
View File
@@ -19,6 +19,8 @@ add_definitions(
enable_testing() enable_testing()
include_directories("src")
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(test) add_subdirectory(test)
+1 -13
View File
@@ -1,15 +1,3 @@
cmake_minimum_required(VERSION 2.8.8) cmake_minimum_required(VERSION 2.8.8)
add_library( add_subdirectory(memphis)
Memphis
memfs.cpp
_memops.cpp
)
install(
FILES
memfs.hpp
_memops.hpp
DESTINATION
include/Memphis
)
+15
View File
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.8)
add_library(
Memphis
memfs.cpp
_memops.cpp
)
install(
FILES
memfs.hpp
_memops.hpp
DESTINATION
include/Memphis
)
+6
View File
@@ -15,6 +15,12 @@ namespace memphis {
uint32_t MemFs::version = 0; uint32_t MemFs::version = 0;
uint8_t *initFs(uint8_t *buffer, size_t size, bool hasDirectories) {
auto fs = (MemFsHeader*) (buffer ? buffer : malloc(size));
fs->version = MemFs::version;
return (uint8_t*) fs;
}
MemFsPtr MemFs::Record::size() { MemFsPtr MemFs::Record::size() {
return offsetof(MemFs::Record, m_id) + dataLen; return offsetof(MemFs::Record, m_id) + dataLen;
} }
+8 -2
View File
@@ -8,14 +8,18 @@
#ifndef MEMPHIS_MEMFS_HPP #ifndef MEMPHIS_MEMFS_HPP
#define MEMPHIS_MEMFS_HPP #define MEMPHIS_MEMFS_HPP
#include "types.hpp" #include "_types.hpp"
namespace memphis { namespace memphis {
typedef uint32_t MemFsPtr; typedef uint32_t MemFsPtr;
typedef uint32_t RecordId; typedef uint32_t RecordId;
struct MemFsHeader {
uint32_t version;
bool hasDirectories;
};
class MemFs { class MemFs {
public: public:
static uint32_t version; static uint32_t version;
@@ -124,6 +128,8 @@ T MemFs::ptr(MemFsPtr ptr) {
return (T) m_begin + ptr; return (T) m_begin + ptr;
} }
uint8_t *initFs(uint8_t *buffer, size_t size, bool hasDirectories);
} }
#endif #endif
+2
View File
@@ -4,3 +4,5 @@ add_executable(
MemFsTest MemFsTest
test.cpp test.cpp
) )
target_link_libraries(MemFsTest Memphis)
+10 -1
View File
@@ -1,3 +1,12 @@
#include <memphis/memfs.hpp>
using namespace memphis;
int main() { int main() {
return 0; const auto size = 1024;
uint8_t volume[size];
uint32_t err;
initFs(volume, size, false);
MemFs memfs(volume, volume + size, &err);
return err;
} }