From def16ce43f16aa21a5b1b6cb88da4c3d83a9c718 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 26 Jun 2016 17:54:12 -0500 Subject: [PATCH] Started on FileSystem format. --- CMakeLists.txt | 1 + src/ox/fs/filesystem.hpp | 47 +++++++++++++++++++ src/ox/fs/test/CMakeLists.txt | 15 ++++-- .../test/{format.cpp => filestore_format.cpp} | 0 src/ox/fs/test/filesystem_format.cpp | 22 +++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) rename src/ox/fs/test/{format.cpp => filestore_format.cpp} (100%) create mode 100644 src/ox/fs/test/filesystem_format.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d935c7dd..39e991abc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ if(NOT MSVC) -fno-exceptions -fno-rtti -Wsign-compare + -Wunused-variable #-Werror #--analyze #-Os # GCC size optimization flag diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 6e9a49e39..06eb8469c 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -13,6 +13,8 @@ namespace ox { namespace fs { +using namespace std; + struct FileStat { uint64_t inode; uint64_t size; @@ -22,16 +24,42 @@ template class FileSystem { private: + struct DirectoryEntry { + typename FileStore::InodeId_t inode; + uint8_t nameLen; + char name; + }; + + struct Directory { + /** + * Number of files in this directory. + */ + typename FileStore::InodeId_t size = 0; + + DirectoryEntry *files() { + return (DirectoryEntry*) (this + 1); + } + }; + FileStore *store = nullptr; public: + int mkdir(const char *path); + int read(const char *path, void *buffer); FileStat stat(const char *path); FileStat stat(typename FileStore::InodeId_t inode); + + static uint8_t *format(uint8_t *buffer, typename FileStore::FsSize_t size); }; +template +int FileSystem::mkdir(const char *path) { + return 0; +} + template FileStat FileSystem::stat(const char *path) { FileStat stat; @@ -47,6 +75,25 @@ FileStat FileSystem::stat(typename FileStore::InodeId_t inode) { return stat; } +template +uint8_t *FileSystem::format(uint8_t *buffer, typename FileStore::FsSize_t size) { + buffer = FileStore::format(buffer, size); + char dirBuff[sizeof(Directory) + sizeof(Directory)]; + Directory &dir = *((Directory*) dirBuff); + DirectoryEntry entry; + entry.inode = 2; + entry.name = '/'; + entry.nameLen = 1; + + if (buffer) { + uint32_t err; + FileStore fs(buffer, buffer + size, &err); + dir.files(); + } + + return buffer; +} + typedef FileSystem FileSystem16; typedef FileSystem FileSystem32; typedef FileSystem FileSystem64; diff --git a/src/ox/fs/test/CMakeLists.txt b/src/ox/fs/test/CMakeLists.txt index c6a2a18e1..9114a83e8 100644 --- a/src/ox/fs/test/CMakeLists.txt +++ b/src/ox/fs/test/CMakeLists.txt @@ -1,8 +1,13 @@ cmake_minimum_required(VERSION 2.8) add_executable( - Format - format.cpp + FileStoreFormat + filestore_format.cpp +) + +add_executable( + FileSystemFormat + filesystem_format.cpp ) add_executable( @@ -10,8 +15,10 @@ add_executable( filestoreio.cpp ) -target_link_libraries(Format OxFS OxStd) +target_link_libraries(FileStoreFormat OxFS OxStd) +target_link_libraries(FileSystemFormat OxFS OxStd) target_link_libraries(FileStoreIO OxFS OxStd) -add_test("Format" Format) +add_test("FileStoreFormat" FileStoreFormat) +add_test("FileSystemFormat" FileSystemFormat) add_test("FileStoreIO" FileStoreIO) diff --git a/src/ox/fs/test/format.cpp b/src/ox/fs/test/filestore_format.cpp similarity index 100% rename from src/ox/fs/test/format.cpp rename to src/ox/fs/test/filestore_format.cpp diff --git a/src/ox/fs/test/filesystem_format.cpp b/src/ox/fs/test/filesystem_format.cpp new file mode 100644 index 000000000..96cd01188 --- /dev/null +++ b/src/ox/fs/test/filesystem_format.cpp @@ -0,0 +1,22 @@ +/* + * Copyright 2015 - 2016 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include + +using namespace ox::fs; + +template +int test() { + const auto size = 65535; + uint8_t volume[size]; + FileSystem::format(volume, size); + return 0; +} + +int main() { + return test() | test() | test(); +}