From 4ad67ed310b6a54725af2f4188685929ba54aad9 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 10 Jul 2016 00:55:40 -0500 Subject: [PATCH] Cleanup file naming convention in FileStore::Inode --- src/ox/fs/filestore.hpp | 66 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index 87bdcd5d8..c10ee45fb 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -30,7 +30,7 @@ class FileStore { // the next Inode in memory FsSize_t prev, next; FsSize_t dataLen; - InodeId_t m_id; + InodeId_t id; ox::std::uint8_t refs; ox::std::uint8_t fileType; FsSize_t left, right; @@ -89,6 +89,12 @@ class FileStore { */ StatInfo stat(InodeId_t id); + /** + * Returns the size of the file store. + * @return the size of the file store. + */ + FsSize_t size(); + static ox::std::uint8_t version(); static ox::std::uint8_t *format(ox::std::uint8_t *buffer, FsSize_t size, ox::std::uint32_t fsType = 0); @@ -193,7 +199,7 @@ FsSize_t FileStore::Inode::size() { template void FileStore::Inode::setId(InodeId_t id) { - this->m_id = id; + this->id = id; } template @@ -223,7 +229,7 @@ int FileStore::write(InodeId_t id, void *data, FsSize_t dataLen, ox::s auto inode = (Inode*) alloc(size); if (inode) { remove(id); - inode->m_id = id; + inode->id = id; inode->fileType = fileType; inode->setData(data, dataLen); auto root = ptr(m_rootInode); @@ -243,10 +249,10 @@ template int FileStore::remove(Inode *root, InodeId_t id) { auto err = 1; - if (root->m_id > id) { + if (root->id > id) { if (root->left) { auto node = ptr(root->left); - if (node->m_id != id) { + if (node->id != id) { err = remove(node, id); } else { root->left = 0; @@ -257,16 +263,16 @@ int FileStore::remove(Inode *root, InodeId_t id) { insert(root, ptr(node->left)); } unlink(node); - node->m_id = 0; + node->id = 0; node->left = 0; node->right = 0; err = 0; } } - } else if (root->m_id < id) { + } else if (root->id < id) { if (root->right) { auto node = ptr(root->right); - if (node->m_id != id) { + if (node->id != id) { err = remove(node, id); } else { root->right = 0; @@ -277,19 +283,19 @@ int FileStore::remove(Inode *root, InodeId_t id) { insert(root, ptr(node->left)); } unlink(node); - node->m_id = 0; + node->id = 0; node->left = 0; node->right = 0; err = 0; } } - } else if (ptr(m_rootInode)->m_id == id) { + } else if (ptr(m_rootInode)->id == id) { m_rootInode = root->right; if (root->left) { insert(ptr(m_rootInode), ptr(root->left)); } unlink(root); - root->m_id = 0; + root->id = 0; root->left = 0; root->right = 0; err = 0; @@ -314,9 +320,9 @@ 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) { + if (parent->left && ptr(parent->left)->id == id) { parent->left = addr; - } else if (parent->right && ptr(parent->right)->m_id == id) { + } else if (parent->right && ptr(parent->right)->id == id) { parent->right = addr; } } @@ -350,19 +356,24 @@ typename FileStore::StatInfo FileStore::stat(InodeId_t id) { return stat; } +template +FsSize_t FileStore::size() { + return m_size; +} + template typename FileStore::Inode *FileStore::getInode(Inode *root, InodeId_t id) { Inode *retval = nullptr; - if (root->m_id > id) { + if (root->id > id) { if (root->left) { retval = getInode(ptr(root->left), id); } - } else if (root->m_id < id) { + } else if (root->id < id) { if (root->right) { retval = getInode(ptr(root->right), id); } - } else if (root->m_id == id) { + } else if (root->id == id) { retval = root; } @@ -373,17 +384,17 @@ template typename FileStore::Inode *FileStore::getInodeParent(Inode *root, InodeId_t id) { Inode *retval = nullptr; - if (root->m_id > id) { + if (root->id > id) { if (root->left) { - if (ptr(root->left)->m_id == id) { + if (ptr(root->left)->id == id) { retval = root; } else { retval = getInode(ptr(root->left), id); } } - } else if (root->m_id < id) { + } else if (root->id < id) { if (root->right) { - if (ptr(root->right)->m_id == id) { + if (ptr(root->right)->id == id) { retval = root; } else { retval = getInode(ptr(root->right), id); @@ -432,16 +443,7 @@ void FileStore::compress(FsSize_t start) { 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; - //} + updateInodeAddress(dest->id, ptr(dest)); } } @@ -449,14 +451,14 @@ template bool FileStore::insert(Inode *root, Inode *insertValue) { auto retval = false; - if (root->m_id > insertValue->m_id) { + if (root->id > insertValue->id) { if (root->left) { retval = insert(ptr(root->left), insertValue); } else { root->left = ptr(insertValue); retval = true; } - } else if (root->m_id < insertValue->m_id) { + } else if (root->id < insertValue->id) { if (root->right) { retval = insert(ptr(root->right), insertValue); } else {