From b2624de48a9a55ee7140fdb09918941a5978ecf0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 6 Jul 2016 19:40:24 -0500 Subject: [PATCH] Removed unused files --- src/ox/fs/CMakeLists.txt | 2 - src/ox/fs/filestore.cpp | 8 -- src/ox/fs/filestore.hpp | 169 +++++++++------------------------------ src/ox/fs/filesystem.hpp | 2 +- src/ox/fs/inodemgr.cpp | 14 ---- 5 files changed, 40 insertions(+), 155 deletions(-) delete mode 100644 src/ox/fs/filestore.cpp delete mode 100644 src/ox/fs/inodemgr.cpp diff --git a/src/ox/fs/CMakeLists.txt b/src/ox/fs/CMakeLists.txt index a11e144fc..86b46f99c 100644 --- a/src/ox/fs/CMakeLists.txt +++ b/src/ox/fs/CMakeLists.txt @@ -2,9 +2,7 @@ cmake_minimum_required(VERSION 2.8) add_library( OxFS - filestore.cpp filesystem.cpp - inodemgr.cpp ) add_executable( diff --git a/src/ox/fs/filestore.cpp b/src/ox/fs/filestore.cpp deleted file mode 100644 index c924f2d1a..000000000 --- a/src/ox/fs/filestore.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* - * 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 "filestore.hpp" diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index 9897fc075..eee1175c8 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -22,17 +22,17 @@ class FileStore { struct StatInfo { InodeId_t inodeId; FsSize_t size; - ox::std::uint8_t fileType; }; private: struct Inode { // the next Inode in memory FsSize_t prev, next; + + // The following variables should not be assumed to exist FsSize_t dataLen; InodeId_t m_id; ox::std::uint8_t refs; - ox::std::uint8_t fileType; FsSize_t left, right; FsSize_t size(); @@ -46,6 +46,7 @@ class FileStore { ox::std::uint32_t m_fsType; FsSize_t m_size; + FsSize_t m_firstInode; FsSize_t m_rootInode; public: @@ -55,7 +56,7 @@ class FileStore { * @param data the contents of the file * @param dataLen the number of bytes data points to */ - int write(void *data, FsSize_t dataLen, ox::std::uint8_t fileType = 0); + int write(void *data, FsSize_t dataLen); /** * Writes the given data to a "file" with the given id. @@ -63,7 +64,7 @@ class FileStore { * @param data the contents of the file * @param dataLen the number of bytes data points to */ - int write(InodeId_t id, void *data, FsSize_t dataLen, ox::std::uint8_t fileType = 0); + int write(InodeId_t id, void *data, FsSize_t dataLen); /** * Removes the inode of the given ID. @@ -103,15 +104,6 @@ class FileStore { */ Inode *getInode(Inode *root, InodeId_t id); - /** - * Gets the inode at the given id. - * @param root the root node to start comparing on - * @param id id of the "file" - * @param pathLen number of characters in pathLen - * @return the requested Inode, if available - */ - Inode *getInodeParent(Inode *root, InodeId_t id); - /** * Removes the inode of the given ID. * @param id the id of the file @@ -124,12 +116,6 @@ class FileStore { */ void unlink(Inode *node); - /** - * Gets the address of the next available inode, assuming there is a next - * available inode. - */ - FsSize_t nextInodeAddr(); - /** * Gets an address for a new Inode. * @param size the size of the Inode @@ -137,9 +123,9 @@ class FileStore { void *alloc(FsSize_t size); /** - * Compresses all of the inode into a contiguous space, starting at the first inode. + * Compresses all of the inode into a contiguous space, starting at m_firstInode. */ - void compress(FsSize_t firstInode); + void compress(); /** * Inserts the given insertValue into the tree of the given root. @@ -154,15 +140,10 @@ class FileStore { */ FsSize_t iterator(); - FsSize_t firstInode(); + Inode *firstInode(); Inode *lastInode(); - /** - * Updates the address of the inode in the tree. - */ - void updateInodeAddress(InodeId_t id, FsSize_t addr); - ox::std::uint8_t *begin() { return (ox::std::uint8_t*) this; } @@ -212,21 +193,19 @@ void *FileStore::Inode::data() { // FileStore template -int FileStore::write(void *data, FsSize_t dataLen, ox::std::uint8_t fileType) { +int FileStore::write(void *data, FsSize_t dataLen) { return 1; } template -int FileStore::write(InodeId_t id, void *data, FsSize_t dataLen, ox::std::uint8_t fileType) { +int FileStore::write(InodeId_t id, void *data, FsSize_t dataLen) { auto retval = 1; const FsSize_t size = sizeof(Inode) + dataLen; auto inode = (Inode*) alloc(size); if (inode) { - remove(id); - inode->m_id = id; - inode->fileType = fileType; - inode->setData(data, dataLen); auto root = ptr(m_rootInode); + inode->m_id = id; + inode->setData(data, dataLen); if (insert(root, inode) || root == inode) { retval = 0; } @@ -249,7 +228,7 @@ int FileStore::remove(Inode *root, InodeId_t id) { if (node->m_id != id) { err = remove(node, id); } else { - root->left = 0; + root->left = node->left; if (node->right) { insert(root, ptr(node->right)); } @@ -257,9 +236,6 @@ int FileStore::remove(Inode *root, InodeId_t id) { insert(root, ptr(node->left)); } unlink(node); - node->m_id = 0; - node->left = 0; - node->right = 0; err = 0; } } @@ -269,7 +245,7 @@ int FileStore::remove(Inode *root, InodeId_t id) { if (node->m_id != id) { err = remove(node, id); } else { - root->right = 0; + root->right = node->right; if (node->right) { insert(root, ptr(node->right)); } @@ -277,21 +253,15 @@ int FileStore::remove(Inode *root, InodeId_t id) { insert(root, ptr(node->left)); } unlink(node); - node->m_id = 0; - node->left = 0; - node->right = 0; err = 0; } } - } else if (ptr(m_rootInode)->m_id == id) { + } else { m_rootInode = root->right; if (root->left) { insert(ptr(m_rootInode), ptr(root->left)); } unlink(root); - root->m_id = 0; - root->left = 0; - root->right = 0; err = 0; } @@ -299,27 +269,11 @@ int FileStore::remove(Inode *root, InodeId_t id) { } template -void FileStore::unlink(Inode *inode) { - auto next = ptr(inode->next); - auto prev = ptr(inode->prev); +void FileStore::unlink(Inode *node) { + auto next = ptr(node->next); + auto prev = ptr(node->prev); prev->next = ptr(next); next->prev = ptr(prev); - - ox::std::memset(inode, 0, inode->size()); - inode->prev = firstInode(); - inode->next = firstInode(); -} - -template -void FileStore::updateInodeAddress(InodeId_t id, FsSize_t addr) { - auto parent = getInodeParent(ptr(m_rootInode), id); - if (parent) { - if (parent->left && ptr(parent->left)->m_id == id) { - parent->left = addr; - } else if (parent->right && ptr(parent->right)->m_id == id) { - parent->right = addr; - } - } } template @@ -368,79 +322,36 @@ typename FileStore::Inode *FileStore::getInode(Inode *root, return retval; } -template -typename FileStore::Inode *FileStore::getInodeParent(Inode *root, InodeId_t id) { - Inode *retval = nullptr; - - if (root->m_id > id) { - if (root->left) { - if (ptr(root->left)->m_id == id) { - retval = root; - } else { - retval = getInode(ptr(root->left), id); - } - } - } else if (root->m_id < id) { - if (root->right) { - if (ptr(root->right)->m_id == id) { - retval = root; - } else { - retval = getInode(ptr(root->right), id); - } - } - } - - return retval; -} - -template -FsSize_t FileStore::nextInodeAddr() { - FsSize_t next = ptr(lastInode()) + lastInode()->size(); - return next; -} - template void *FileStore::alloc(FsSize_t size) { - FsSize_t next = nextInodeAddr(); - if ((next + size) > (ox::std::uint64_t) end()) { - compress(firstInode()); - next = nextInodeAddr(); - if ((next + size) > (ox::std::uint64_t) end()) { + if ((lastInode()->next + size) > (ox::std::uint64_t) end()) { + compress(); + if ((lastInode()->next + size) > (ox::std::uint64_t) end()) { return nullptr; } } - const auto retval = next; + const auto retval = lastInode()->next; const auto inode = ptr(retval); ox::std::memset(inode, 0, size); - inode->prev = ptr(firstInode())->prev; inode->next = retval + size; - ptr(firstInode())->prev = retval; + ptr(m_firstInode)->prev = retval; return inode; } template -void FileStore::compress(FsSize_t start) { - auto dest = ptr(firstInode()); - auto current = ptr(start); - while (current->next > ptr(begin()) && current->next < ptr(end())) { - ox::std::memcpy(dest, current, current->size()); - if (dest->next != firstInode()) { - dest->next = ptr(dest) + dest->size(); +void FileStore::compress() { + auto current = ptr(m_firstInode); + while (current->next) { + auto prevEnd = current + current->size(); + auto prev = ptr(current); + current->next = ptr(current) + current->size(); + current = ptr(current->next); + current->prev = prev; + if (prevEnd != current) { + ox::std::memcpy(prevEnd, current, current->size()); + current = prevEnd; } - ptr(dest->next)->prev = ptr(dest); - current = ptr(dest->next); - dest = ptr(ptr(dest) + dest->size()); - updateInodeAddress(dest->m_id, ptr(dest)); - //auto prevEnd = current + current->size(); - //auto prev = ptr(current); - //current->next = ptr(current) + current->size(); - //current = ptr(current->next); - //current->prev = prev; - //if (prevEnd != current) { - // ox::std::memcpy(prevEnd, current, current->size()); - // current = prevEnd; - //} } } @@ -462,9 +373,6 @@ bool FileStore::insert(Inode *root, Inode *insertValue) { root->right = ptr(insertValue); retval = true; } - } else if (m_rootInode == 0) { - m_rootInode = ptr(insertValue); - retval = true; } return retval; @@ -481,13 +389,13 @@ FsSize_t FileStore::ptr(void *ptr) { } template -FsSize_t FileStore::firstInode() { - return sizeof(FileStore); +typename FileStore::Inode *FileStore::firstInode() { + return ptr(sizeof(FileStore)); } template typename FileStore::Inode *FileStore::lastInode() { - return ptr(ptr(firstInode())->prev); + return ptr(ptr(m_firstInode)->prev); } template @@ -503,7 +411,8 @@ ox::std::uint8_t *FileStore::format(ox::std::uint8_t *buffer, FsSize_t fs->m_fsType = fsType; fs->m_size = size; fs->m_rootInode = sizeof(FileStore); - ((Inode*) (fs + 1))->prev = fs->firstInode(); + fs->m_firstInode = sizeof(FileStore); + fs->firstInode()->prev = fs->m_firstInode; fs->lastInode()->next = sizeof(FileStore); return (ox::std::uint8_t*) buffer; diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 9ff65ae05..73d76ad82 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -92,7 +92,7 @@ class FileSystemTemplate: public FileSystem { int read(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size) override; - int remove(ox::std::uint64_t inode); + int remove(ox::std::uint64_t inode) override; int write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size, ox::std::uint8_t fileType) override; diff --git a/src/ox/fs/inodemgr.cpp b/src/ox/fs/inodemgr.cpp deleted file mode 100644 index 58d4e4155..000000000 --- a/src/ox/fs/inodemgr.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 { - -} -}