From 867060b147e7b4546cc09b68fe7347eb424702d2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 9 Jun 2016 20:03:34 -0500 Subject: [PATCH] Renamed RecordId to InodeId. --- src/filestore.hpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/filestore.hpp b/src/filestore.hpp index c449bc90f..b1b450f4d 100644 --- a/src/filestore.hpp +++ b/src/filestore.hpp @@ -21,9 +21,10 @@ class FileStore { struct FsHeader { uint32_t version; FsSize_t rootDir = -1; + bool insertLeft = false; // crude tree balancing mechanism }; - typedef FsSize_t RecordId; + typedef uint16_t InodeId_t; private: struct Inode { @@ -36,7 +37,7 @@ class FileStore { FsSize_t m_data; FsSize_t size(); - void setId(RecordId); + void setId(InodeId_t); void setData(uint8_t *data, int size); private: @@ -70,7 +71,15 @@ class FileStore { * @param data the contents of the file * @param dataLen the number of bytes data points to */ - void write(RecordId id, void *data, FsSize_t dataLen); + void write(void *data, FsSize_t dataLen); + + /** + * Writes the given data to a "file" with the given id. + * @param id the id of the file + * @param data the contents of the file + * @param dataLen the number of bytes data points to + */ + void write(InodeId_t id, void *data, FsSize_t dataLen); /** * Reads the "file" at the given id. You are responsible for freeing @@ -80,13 +89,19 @@ class FileStore { * @param size pointer to a value that will be assigned the size of data * @return 0 if read is a success */ - int read(RecordId id, void *data, FsSize_t *size); + int read(InodeId_t id, void *data, FsSize_t *size); static uint8_t version(); static uint8_t *format(uint8_t *buffer, size_t size, bool hasDirectories); private: + /** + * Gets the header section of the file system. + * @return the header section of the file system. + */ + FsHeader *getHeader(); + /** * Gets the record at the given id. * @param root the root node to start comparing on @@ -94,7 +109,7 @@ class FileStore { * @param pathLen number of characters in pathLen * @return the requested Inode, if available */ - Inode *getRecord(FileStore::Inode *root, RecordId id); + Inode *getRecord(FileStore::Inode *root, InodeId_t id); /** * Gets an address for a new Inode. @@ -140,7 +155,7 @@ FsSize_t FileStore::Inode::size() { } template -void FileStore::Inode::setId(RecordId id) { +void FileStore::Inode::setId(InodeId_t id) { this->m_id = id; } @@ -174,19 +189,19 @@ FileStore::FileStore(uint8_t *begin, uint8_t *end, Error *error): m_ve template void FileStore::init() { memset(m_begin, 0, m_end - m_begin); - m_version = version; + m_version = version(); } template -void FileStore::write(RecordId id, void *data, FsSize_t dataLen) { - const FsSize_t size = offsetof(FileStore::Inode, m_id) + dataLen; +void FileStore::write(InodeId_t id, void *data, FsSize_t dataLen) { + const FsSize_t size = offsetof(Inode, m_id) + dataLen; auto rec = (Inode*) alloc(size); rec->dataLen = dataLen; insert(m_root, rec); } template -int FileStore::read(RecordId id, void *data, FsSize_t *size) { +int FileStore::read(InodeId_t id, void *data, FsSize_t *size) { auto rec = getRecord(m_root, id); int retval = 1; if (rec) { @@ -200,7 +215,12 @@ int FileStore::read(RecordId id, void *data, FsSize_t *size) { } template -typename FileStore::Inode *FileStore::getRecord(FileStore::Inode *root, RecordId id) { +typename FileStore::FsHeader *FileStore::getHeader() { + return (FsHeader*) m_begin; +} + +template +typename FileStore::Inode *FileStore::getRecord(FileStore::Inode *root, InodeId_t id) { auto cmp = root->m_id > id; FsSize_t recPt; if (cmp) {