Started on FileSystem format.
This commit is contained in:
@@ -13,6 +13,7 @@ if(NOT MSVC)
|
|||||||
-fno-exceptions
|
-fno-exceptions
|
||||||
-fno-rtti
|
-fno-rtti
|
||||||
-Wsign-compare
|
-Wsign-compare
|
||||||
|
-Wunused-variable
|
||||||
#-Werror
|
#-Werror
|
||||||
#--analyze
|
#--analyze
|
||||||
#-Os # GCC size optimization flag
|
#-Os # GCC size optimization flag
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
namespace ox {
|
namespace ox {
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct FileStat {
|
struct FileStat {
|
||||||
uint64_t inode;
|
uint64_t inode;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
@@ -22,16 +24,42 @@ template<typename FileStore>
|
|||||||
class FileSystem {
|
class FileSystem {
|
||||||
|
|
||||||
private:
|
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;
|
FileStore *store = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int mkdir(const char *path);
|
||||||
|
|
||||||
int read(const char *path, void *buffer);
|
int read(const char *path, void *buffer);
|
||||||
|
|
||||||
FileStat stat(const char *path);
|
FileStat stat(const char *path);
|
||||||
|
|
||||||
FileStat stat(typename FileStore::InodeId_t inode);
|
FileStat stat(typename FileStore::InodeId_t inode);
|
||||||
|
|
||||||
|
static uint8_t *format(uint8_t *buffer, typename FileStore::FsSize_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename FileStore>
|
||||||
|
int FileSystem<FileStore>::mkdir(const char *path) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FileStore>
|
template<typename FileStore>
|
||||||
FileStat FileSystem<FileStore>::stat(const char *path) {
|
FileStat FileSystem<FileStore>::stat(const char *path) {
|
||||||
FileStat stat;
|
FileStat stat;
|
||||||
@@ -47,6 +75,25 @@ FileStat FileSystem<FileStore>::stat(typename FileStore::InodeId_t inode) {
|
|||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FileStore>
|
||||||
|
uint8_t *FileSystem<FileStore>::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<FileStore16> FileSystem16;
|
typedef FileSystem<FileStore16> FileSystem16;
|
||||||
typedef FileSystem<FileStore32> FileSystem32;
|
typedef FileSystem<FileStore32> FileSystem32;
|
||||||
typedef FileSystem<FileStore64> FileSystem64;
|
typedef FileSystem<FileStore64> FileSystem64;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
Format
|
FileStoreFormat
|
||||||
format.cpp
|
filestore_format.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(
|
||||||
|
FileSystemFormat
|
||||||
|
filesystem_format.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
@@ -10,8 +15,10 @@ add_executable(
|
|||||||
filestoreio.cpp
|
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)
|
target_link_libraries(FileStoreIO OxFS OxStd)
|
||||||
|
|
||||||
add_test("Format" Format)
|
add_test("FileStoreFormat" FileStoreFormat)
|
||||||
|
add_test("FileSystemFormat" FileSystemFormat)
|
||||||
add_test("FileStoreIO" FileStoreIO)
|
add_test("FileStoreIO" FileStoreIO)
|
||||||
|
|||||||
@@ -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 <ox/fs/filesystem.hpp>
|
||||||
|
|
||||||
|
using namespace ox::fs;
|
||||||
|
|
||||||
|
template<typename FileSystem>
|
||||||
|
int test() {
|
||||||
|
const auto size = 65535;
|
||||||
|
uint8_t volume[size];
|
||||||
|
FileSystem::format(volume, size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return test<FileSystem16>() | test<FileSystem32>() | test<FileSystem64>();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user