Added initFs.
This commit is contained in:
@@ -19,6 +19,8 @@ add_definitions(
|
||||
|
||||
enable_testing()
|
||||
|
||||
include_directories("src")
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(test)
|
||||
|
||||
|
||||
+1
-13
@@ -1,15 +1,3 @@
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
|
||||
add_library(
|
||||
Memphis
|
||||
memfs.cpp
|
||||
_memops.cpp
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
memfs.hpp
|
||||
_memops.hpp
|
||||
DESTINATION
|
||||
include/Memphis
|
||||
)
|
||||
add_subdirectory(memphis)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
@@ -15,6 +15,12 @@ namespace memphis {
|
||||
|
||||
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() {
|
||||
return offsetof(MemFs::Record, m_id) + dataLen;
|
||||
}
|
||||
@@ -8,14 +8,18 @@
|
||||
#ifndef MEMPHIS_MEMFS_HPP
|
||||
#define MEMPHIS_MEMFS_HPP
|
||||
|
||||
#include "types.hpp"
|
||||
#include "_types.hpp"
|
||||
|
||||
namespace memphis {
|
||||
|
||||
typedef uint32_t MemFsPtr;
|
||||
|
||||
typedef uint32_t RecordId;
|
||||
|
||||
struct MemFsHeader {
|
||||
uint32_t version;
|
||||
bool hasDirectories;
|
||||
};
|
||||
|
||||
class MemFs {
|
||||
public:
|
||||
static uint32_t version;
|
||||
@@ -124,6 +128,8 @@ T MemFs::ptr(MemFsPtr ptr) {
|
||||
return (T) m_begin + ptr;
|
||||
}
|
||||
|
||||
uint8_t *initFs(uint8_t *buffer, size_t size, bool hasDirectories);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,3 +4,5 @@ add_executable(
|
||||
MemFsTest
|
||||
test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MemFsTest Memphis)
|
||||
|
||||
+10
-1
@@ -1,3 +1,12 @@
|
||||
#include <memphis/memfs.hpp>
|
||||
|
||||
using namespace memphis;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user