From 77059d4cdbd74d36f6f488e5e499e750275c30c4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 27 Jun 2016 21:21:01 -0500 Subject: [PATCH] Started on inode manager file. --- src/ox/fs/CMakeLists.txt | 2 ++ src/ox/fs/filesystem.hpp | 4 +-- src/ox/fs/inodemgr.cpp | 14 ++++++++ src/ox/fs/inodemgr.hpp | 53 ++++++++++++++++++++++++++++ src/ox/fs/test/filestoreio.cpp | 3 +- src/ox/fs/test/filesystem_format.cpp | 4 ++- 6 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/ox/fs/inodemgr.cpp create mode 100644 src/ox/fs/inodemgr.hpp diff --git a/src/ox/fs/CMakeLists.txt b/src/ox/fs/CMakeLists.txt index 5c057a356..408efe096 100644 --- a/src/ox/fs/CMakeLists.txt +++ b/src/ox/fs/CMakeLists.txt @@ -4,12 +4,14 @@ add_library( OxFS filestore.cpp filesystem.cpp + inodemgr.cpp ) install( FILES filestore.hpp filesystem.hpp + inodemgr.hpp DESTINATION include/ox/fs ) diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 254cb0811..7db48ae94 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -94,7 +94,7 @@ 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); + auto *dir = (Directory*) dirBuff; DirectoryEntry entry; entry.inode = INODE_ROOT_DIR; entry.setName("/"); @@ -102,7 +102,7 @@ uint8_t *FileSystem::format(uint8_t *buffer, typename FileStore::FsSi if (buffer) { uint32_t err; FileStore fs(buffer, buffer + size, &err); - dir.files(); + dir->files(); } return buffer; diff --git a/src/ox/fs/inodemgr.cpp b/src/ox/fs/inodemgr.cpp new file mode 100644 index 000000000..58d4e4155 --- /dev/null +++ b/src/ox/fs/inodemgr.cpp @@ -0,0 +1,14 @@ +/* + * 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 "inodemgr.hpp" + +namespace ox { +namespace fs { + +} +} diff --git a/src/ox/fs/inodemgr.hpp b/src/ox/fs/inodemgr.hpp new file mode 100644 index 000000000..abf70bb87 --- /dev/null +++ b/src/ox/fs/inodemgr.hpp @@ -0,0 +1,53 @@ +/* + * 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/. + */ +#pragma once + +namespace ox { +namespace fs { + +/** + * Used to track unused inodes. + */ +template +struct InodeFile { + InodeId_t length; + + InodeId_t *inodes(); +}; + +template +InodeId_t *InodeFile::inodes() { + return (InodeId_t*) (this + 1); +} + +template +int generateInodeFile(InodeId_t *inodes, int count) { + const static InodeId_t endPoint = ~0; + auto it = count; + auto multiplier = 1; + auto current = endPoint / 2; + auto lowestNode = current; + + inodes[0] = count; + + while (it > 0) { + current = lowestNode * multiplier; + if (current < endPoint) { + inodes[it--] = current; + multiplier += 2; + } else { + multiplier = 1; + lowestNode /= 2; + } + } + + return 0; +} + +} +} diff --git a/src/ox/fs/test/filestoreio.cpp b/src/ox/fs/test/filestoreio.cpp index f5a31e2f2..77f1f610c 100644 --- a/src/ox/fs/test/filestoreio.cpp +++ b/src/ox/fs/test/filestoreio.cpp @@ -9,10 +9,11 @@ #include using namespace ox::fs; +using namespace ox::std; template int test() { - const auto size = 65535; + const uint16_t size = ~0; uint8_t volume[size]; char out[6]; uint32_t err; diff --git a/src/ox/fs/test/filesystem_format.cpp b/src/ox/fs/test/filesystem_format.cpp index 96cd01188..8052cb5ed 100644 --- a/src/ox/fs/test/filesystem_format.cpp +++ b/src/ox/fs/test/filesystem_format.cpp @@ -6,12 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#include using namespace ox::fs; +using namespace ox::std; template int test() { - const auto size = 65535; + const uint16_t size = ~0; uint8_t volume[size]; FileSystem::format(volume, size); return 0;