From f92c8ab577b28e108464f9b04eaa529fe0add452 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 12 May 2017 00:26:58 -0500 Subject: [PATCH] Squashed 'deps/ox/' changes from a5166e0..68c144f 68c144f Add ls to file system 1ce2797 Flatten out namespaces to only ox e0063a7 Cleanup oxfstool format output a2dfb41 Fix FS read by type to read byte by byte git-subtree-dir: deps/ox git-subtree-split: 68c144fe755e1f1a6cebb841b6c37b618a35fa43 --- src/ox/clargs/clargs.cpp | 2 - src/ox/clargs/clargs.hpp | 2 - src/ox/fs/filestore.hpp | 58 +++-- src/ox/fs/filesystem.cpp | 8 +- src/ox/fs/filesystem.hpp | 371 ++++++++++++++++++--------- src/ox/fs/oxfstool.cpp | 8 +- src/ox/fs/pathiterator.cpp | 2 - src/ox/fs/pathiterator.hpp | 2 - src/ox/fs/test/CMakeLists.txt | 1 + src/ox/fs/test/filestore_format.cpp | 2 +- src/ox/fs/test/filestoreio.cpp | 3 +- src/ox/fs/test/filesystem_format.cpp | 3 +- src/ox/fs/test/tests.cpp | 36 ++- src/ox/mc/read.hpp | 6 +- src/ox/mc/write.hpp | 6 +- src/ox/std/byteswap.hpp | 4 - src/ox/std/test/byteswap_test.cpp | 2 +- 17 files changed, 327 insertions(+), 189 deletions(-) diff --git a/src/ox/clargs/clargs.cpp b/src/ox/clargs/clargs.cpp index 999f47de..c028e308 100644 --- a/src/ox/clargs/clargs.cpp +++ b/src/ox/clargs/clargs.cpp @@ -10,7 +10,6 @@ #include "clargs.hpp" namespace ox { -namespace clargs { using namespace ::std; @@ -52,4 +51,3 @@ int ClArgs::getInt(const char *arg) { } } -} diff --git a/src/ox/clargs/clargs.hpp b/src/ox/clargs/clargs.hpp index 42acd120..4b7b740f 100644 --- a/src/ox/clargs/clargs.hpp +++ b/src/ox/clargs/clargs.hpp @@ -12,7 +12,6 @@ #include namespace ox { -namespace clargs { class ClArgs { private: @@ -31,4 +30,3 @@ class ClArgs { }; } -} diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index f7193609..20b261a5 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -11,7 +11,6 @@ #include namespace ox { -namespace fs { template struct __attribute__((packed)) FileStoreHeader { @@ -46,52 +45,52 @@ struct __attribute__((packed)) FileStoreHeader { template void FileStoreHeader::setVersion(uint16_t version) { - m_version = std::bigEndianAdapt(version); + m_version = bigEndianAdapt(version); } template uint16_t FileStoreHeader::getVersion() { - return std::bigEndianAdapt(m_version); + return bigEndianAdapt(m_version); } template void FileStoreHeader::setFsType(uint16_t fsType) { - m_fsType = std::bigEndianAdapt(fsType); + m_fsType = bigEndianAdapt(fsType); } template uint16_t FileStoreHeader::getFsType() { - return std::bigEndianAdapt(m_fsType); + return bigEndianAdapt(m_fsType); } template void FileStoreHeader::setSize(FsSize_t size) { - m_size = std::bigEndianAdapt(size); + m_size = bigEndianAdapt(size); } template FsSize_t FileStoreHeader::getSize() { - return std::bigEndianAdapt(m_size); + return bigEndianAdapt(m_size); } template void FileStoreHeader::setMemUsed(FsSize_t memUsed) { - m_memUsed = std::bigEndianAdapt(memUsed); + m_memUsed = bigEndianAdapt(memUsed); } template FsSize_t FileStoreHeader::getMemUsed() { - return std::bigEndianAdapt(m_memUsed); + return bigEndianAdapt(m_memUsed); } template void FileStoreHeader::setRootInode(FsSize_t rootInode) { - m_rootInode = std::bigEndianAdapt(rootInode); + m_rootInode = bigEndianAdapt(rootInode); } template FsSize_t FileStoreHeader::getRootInode() { - return std::bigEndianAdapt(m_rootInode); + return bigEndianAdapt(m_rootInode); } template @@ -368,72 +367,72 @@ typename Header::FsSize_t FileStore
::Inode::size() { template void FileStore
::Inode::setDataLen(typename Header::FsSize_t dataLen) { - this->m_dataLen = std::bigEndianAdapt(dataLen); + this->m_dataLen = bigEndianAdapt(dataLen); } template typename Header::FsSize_t FileStore
::Inode::getDataLen() { - return std::bigEndianAdapt(m_dataLen); + return bigEndianAdapt(m_dataLen); } template void FileStore
::Inode::setPrev(typename Header::FsSize_t prev) { - this->m_prev = std::bigEndianAdapt(prev); + this->m_prev = bigEndianAdapt(prev); } template typename Header::FsSize_t FileStore
::Inode::getPrev() { - return std::bigEndianAdapt(m_prev); + return bigEndianAdapt(m_prev); } template void FileStore
::Inode::setNext(typename Header::FsSize_t next) { - this->m_next = std::bigEndianAdapt(next); + this->m_next = bigEndianAdapt(next); } template typename Header::FsSize_t FileStore
::Inode::getNext() { - return std::bigEndianAdapt(m_next); + return bigEndianAdapt(m_next); } template void FileStore
::Inode::setId(InodeId_t id) { - this->m_id = std::bigEndianAdapt(id); + this->m_id = bigEndianAdapt(id); } template typename Header::InodeId_t FileStore
::Inode::getId() { - return std::bigEndianAdapt(m_id); + return bigEndianAdapt(m_id); } template void FileStore
::Inode::setFileType(uint8_t fileType) { - this->m_fileType = std::bigEndianAdapt(fileType); + this->m_fileType = bigEndianAdapt(fileType); } template uint8_t FileStore
::Inode::getFileType() { - return std::bigEndianAdapt(m_fileType); + return bigEndianAdapt(m_fileType); } template void FileStore
::Inode::setLeft(typename Header::FsSize_t left) { - this->m_left = std::bigEndianAdapt(left); + this->m_left = bigEndianAdapt(left); } template typename Header::FsSize_t FileStore
::Inode::getLeft() { - return std::bigEndianAdapt(m_left); + return bigEndianAdapt(m_left); } template void FileStore
::Inode::setRight(typename Header::FsSize_t right) { - this->m_right = std::bigEndianAdapt(right); + this->m_right = bigEndianAdapt(right); } template typename Header::FsSize_t FileStore
::Inode::getRight() { - return std::bigEndianAdapt(m_right); + return bigEndianAdapt(m_right); } template @@ -647,9 +646,13 @@ int FileStore
::read(Inode *inode, typename Header::FsSize_t readStart, } readSize /= sizeof(T); - T *it = (T*) &(inode->getData()[readStart]); + uint8_t *it = &(inode->getData()[readStart]); for (typename Header::FsSize_t i = 0; i < readSize; i++) { - *(data++) = *(it++); + T val; + for (size_t i = 0; i < sizeof(T); i++) { + ((uint8_t*) (&val))[i] = *(it++); + } + *(data++) = val; } return 0; } @@ -848,4 +851,3 @@ typedef FileStore> FileStore32; typedef FileStore> FileStore64; } -} diff --git a/src/ox/fs/filesystem.cpp b/src/ox/fs/filesystem.cpp index 2fef1603..1f649c92 100644 --- a/src/ox/fs/filesystem.cpp +++ b/src/ox/fs/filesystem.cpp @@ -9,7 +9,6 @@ #include "filesystem.hpp" namespace ox { -namespace fs { FileSystem *createFileSystem(void *buff, size_t buffSize) { auto version = ((FileStore16*) buff)->version(); @@ -19,13 +18,13 @@ FileSystem *createFileSystem(void *buff, size_t buffSize) { switch (version) { case 5: switch (type) { - case ox::fs::OxFS_16: + case ox::OxFS_16: fs = new FileSystem16(buff); break; - case ox::fs::OxFS_32: + case ox::OxFS_32: fs = new FileSystem32(buff); break; - case ox::fs::OxFS_64: + case ox::OxFS_64: fs = new FileSystem64(buff); break; } @@ -72,4 +71,3 @@ FileSystem *expandCopyCleanup(FileSystem *fs, size_t size) { } } -} diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index fd3e4619..3c0df7a1 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -12,7 +12,6 @@ #include "filestore.hpp" namespace ox { -namespace fs { enum FsType { OxFS_16 = 1, @@ -21,8 +20,8 @@ enum FsType { }; enum FileType { - NormalFile = 1, - Directory = 2 + FileType_NormalFile = 1, + FileType_Directory = 2 }; struct FileStat { @@ -31,6 +30,167 @@ struct FileStat { uint8_t fileType; }; +template +struct DirectoryListing { + String name; + FileStat stat; + + DirectoryListing(const char *name) { + this->name = name; + } +}; + +template +struct __attribute__((packed)) DirectoryEntry { + InodeId_t inode; + + char *getName() { + return (char*) (this + 1); + } + + void setName(const char *name) { + auto data = getName(); + auto nameLen = ox_strlen(name); + ox_memcpy(data, name, nameLen); + data[nameLen] = 0; + } + + static uint64_t spaceNeeded(const char *fileName) { + return sizeof(DirectoryEntry) + ox_strlen(fileName) + 1; + } + + /** + * The size in bytes. + */ + uint64_t size() { + return spaceNeeded(getName()); + } +}; + +template +struct __attribute__((packed)) Directory { + /** + * Number of bytes after this Directory struct. + */ + FsSize_t size = 0; + FsSize_t children = 0; + + DirectoryEntry *files() { + return size ? (DirectoryEntry*) (this + 1) : nullptr; + } + + uint64_t getFileInode(const char *name, uint64_t buffSize); + + int getChildrenInodes(InodeId_t *inodes, size_t inodesLen); + + int rmFile(const char *name); + + int copy(Directory *dirOut); + + template + int ls(List *list); +}; + +template +uint64_t Directory::getFileInode(const char *name, uint64_t buffSize) { + uint64_t inode = 0; + auto current = files(); + if (current) { + for (uint64_t i = 0; ox_strcmp(current->getName(), name) != 0;) { + i += current->size(); + if (i < this->size) { + current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); + } else { + current = nullptr; + break; + } + } + if (current) { + inode = current->inode; + } + } + return inode; +} + +template +int Directory::getChildrenInodes(InodeId_t *inodes, size_t inodesLen) { + if (inodesLen >= this->children) { + auto current = files(); + if (current) { + for (uint64_t i = 0; i < this->children; i++) { + inodes[i] = current->inode; + current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); + } + return 0; + } else { + return 1; + } + } else { + return 2; + } +} + +template +int Directory::rmFile(const char *name) { + int err = 1; + auto current = files(); + if (current) { + for (uint64_t i = 0; i < this->size;) { + i += current->size(); + if (ox_strcmp(current->getName(), name) == 0) { + auto dest = (uint8_t*) current; + auto src = dest + current->size(); + ox_memcpy(dest, src, this->size - i); + this->size -= current->size(); + this->children--; + err = 0; + break; + } + current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); + } + } + return err; +} + +template +int Directory::copy(Directory *dirOut) { + auto current = files(); + auto dirBuff = (uint8_t*) dirOut; + dirBuff += sizeof(Directory); + dirOut->size = this->size; + dirOut->children = this->children; + if (current) { + for (uint64_t i = 0; i < this->children; i++) { + auto entry = (DirectoryEntry*) dirBuff; + entry->inode = current->inode; + entry->setName(current->getName()); + + current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); + dirBuff += entry->size(); + } + return 0; + } else { + return 1; + } +} + +template +template +int Directory::ls(List *list) { + auto current = files(); + if (current) { + for (uint64_t i = 0; i < this->children; i++) { + list->push_back(current->getName()); + list->at(i).stat.inode = current->inode; + current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); + } + return 0; + } else { + return 1; + } +} + + class FileSystem { public: virtual ~FileSystem() {}; @@ -39,6 +199,9 @@ class FileSystem { virtual int mkdir(const char *path) = 0; + template + int ls(const char *path, List *list); + virtual int read(const char *path, void *buffer, size_t buffSize) = 0; virtual int read(uint64_t inode, void *buffer, size_t size) = 0; @@ -53,12 +216,14 @@ class FileSystem { virtual void resize(uint64_t size = 0) = 0; - virtual int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = NormalFile) = 0; + virtual int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) = 0; - virtual int write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = NormalFile) = 0; + virtual int write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) = 0; virtual FileStat stat(uint64_t inode) = 0; + virtual FileStat stat(const char *path) = 0; + virtual uint64_t spaceNeeded(uint64_t size) = 0; virtual uint64_t available() = 0; @@ -66,8 +231,21 @@ class FileSystem { virtual uint64_t size() = 0; virtual uint8_t *buff() = 0; + + protected: + virtual int readDirectory(const char *path, Directory *dirOut) = 0; }; +template +int FileSystem::ls(const char *path, List *list) { + auto s = stat(path); + uint8_t dirBuff[s.size * 4]; + auto dir = (Directory*) dirBuff; + auto err = readDirectory(path, dir); + dir->ls(list); + return err; +} + FileSystem *createFileSystem(void *buff, size_t buffSize); /** @@ -85,50 +263,6 @@ template class FileSystemTemplate: public FileSystem { private: - struct __attribute__((packed)) DirectoryEntry { - typename FileStore::InodeId_t inode; - - char *getName() { - return (char*) (this + 1); - } - - void setName(const char *name) { - auto data = getName(); - auto nameLen = ox_strlen(name); - ox_memcpy(data, name, nameLen); - data[nameLen] = 0; - } - - static uint64_t spaceNeeded(const char *fileName) { - return sizeof(DirectoryEntry) + ox_strlen(fileName) + 1; - } - - /** - * The size in bytes. - */ - uint64_t size() { - return spaceNeeded(getName()); - } - }; - - struct __attribute__((packed)) Directory { - /** - * Number of bytes after this Directory struct. - */ - typename FileStore::FsSize_t size = 0; - typename FileStore::FsSize_t children = 0; - - DirectoryEntry *files() { - return size ? (DirectoryEntry*) (this + 1) : nullptr; - } - - uint64_t getFileInode(const char *name, uint64_t buffSize); - - int getChildrenInodes(typename FileStore::InodeId_t *inodes, size_t inodesLen); - - int rmFile(const char *name); - }; - FileStore *m_store = nullptr; public: @@ -141,6 +275,9 @@ class FileSystemTemplate: public FileSystem { int stripDirectories() override; + template + int ls(const char *path, List *list); + int mkdir(const char *path) override; int read(const char *path, void *buffer, size_t buffSize) override; @@ -157,11 +294,11 @@ class FileSystemTemplate: public FileSystem { int remove(const char *path, bool recursive = false) override; - int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = NormalFile) override; + int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; - int write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = NormalFile) override; + int write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; - FileStat stat(const char *path); + FileStat stat(const char *path) override; FileStat stat(uint64_t inode) override; @@ -189,6 +326,9 @@ class FileSystemTemplate: public FileSystem { static uint8_t *format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories); + protected: + int readDirectory(const char *path, Directory *dirOut) override; + private: uint64_t generateInodeId(); @@ -211,13 +351,37 @@ typename FileStore::InodeId_t FileSystemTemplate::INODE_RESE template int FileSystemTemplate::stripDirectories() { - return m_store->removeAllType(FileType::Directory); + return m_store->removeAllType(FileType::FileType_Directory); +} + +template +template +int FileSystemTemplate::ls(const char *path, List *list) { + int err = 0; + auto inode = findInodeOf(path); + auto dirStat = stat(inode); + auto dirBuffLen = dirStat.size; + uint8_t dirBuff[dirBuffLen]; + auto dir = (Directory*) dirBuff; + + err = read(dirStat.inode, dirBuff, dirBuffLen); + if (!err) { + dir->ls(list); + + for (auto &i : *list) { + i.stat = stat(i.stat.inode); + } + + return 0; + } else { + return 1; + } } template int FileSystemTemplate::mkdir(const char *path) { - Directory dir; - return write(path, &dir, sizeof(dir), FileType::Directory); + Directory dir; + return write(path, &dir, sizeof(dir), FileType::FileType_Directory); } template @@ -336,14 +500,14 @@ int FileSystemTemplate::remove(const char *path, bool recurs template int FileSystemTemplate::remove(uint64_t inode, bool recursive) { auto fileType = stat(inode).fileType; - if (fileType != FileType::Directory) { + if (fileType != FileType::FileType_Directory) { return m_store->remove(inode); - } else if (fileType == FileType::Directory && recursive) { + } else if (fileType == FileType::FileType_Directory && recursive) { int err = 0; auto dirStat = stat(inode); auto dirBuffLen = dirStat.size; uint8_t dirBuff[dirBuffLen]; - auto dir = (Directory*) dirBuff; + auto dir = (Directory*) dirBuff; err = read(dirStat.inode, dirBuff, dirBuffLen); if (err) { @@ -425,11 +589,11 @@ uint64_t FileSystemTemplate::findInodeOf(const char *path) { uint64_t inode = INODE_ROOT_DIR; while (it.hasNext()) { auto dirStat = stat(inode); - if (dirStat.inode && dirStat.size >= sizeof(Directory)) { + if (dirStat.inode && dirStat.size >= sizeof(Directory)) { uint8_t dirBuffer[dirStat.size]; - auto dir = (Directory*) dirBuffer; + auto dir = (Directory*) dirBuffer; if (read(inode, dirBuffer, dirStat.size) == 0) { - if (dirStat.fileType == FileType::Directory && it.next(fileName, pathLen) == 0) { + if (dirStat.fileType == FileType::FileType_Directory && it.next(fileName, pathLen) == 0) { inode = dir->getFileInode(fileName, dirStat.size); } else { inode = 0; // null out inode and break @@ -483,9 +647,9 @@ uint8_t *FileSystemTemplate::format(void *buffer, typename F buffer = FileStore::format((uint8_t*) buffer, size, (uint16_t) FS_TYPE); if (buffer && useDirectories) { - Directory dir; + Directory dir; FileSystemTemplate fs(buffer); - fs.write(INODE_ROOT_DIR, &dir, sizeof(dir), FileType::Directory); + fs.write(INODE_ROOT_DIR, &dir, sizeof(dir), FileType::FileType_Directory); } return (uint8_t*) buffer; @@ -524,19 +688,19 @@ template int FileSystemTemplate::insertDirectoryEntry(const char *dirPath, const char *fileName, uint64_t inode) { auto s = stat(dirPath); if (s.inode) { - auto spaceNeeded = DirectoryEntry::spaceNeeded(fileName); + auto spaceNeeded = DirectoryEntry::spaceNeeded(fileName); size_t dirBuffSize = s.size + spaceNeeded; uint8_t dirBuff[dirBuffSize]; int err = read(s.inode, dirBuff, dirBuffSize); if (!err) { - auto dir = (Directory*) dirBuff; + auto dir = (Directory*) dirBuff; dir->size += spaceNeeded; dir->children++; - auto entry = (DirectoryEntry*) &dirBuff[s.size]; + auto entry = (DirectoryEntry*) &dirBuff[s.size]; entry->inode = inode; entry->setName(fileName); - return write(s.inode, dirBuff, dirBuffSize, FileType::Directory); + return write(s.inode, dirBuff, dirBuffSize, FileType::FileType_Directory); } else { return 1; } @@ -612,85 +776,38 @@ int FileSystemTemplate::rmDirectoryEntry(const char *path) { return err; } - auto dir = (Directory*) dirBuff; + auto dir = (Directory*) dirBuff; err = dir->rmFile(fileName); if (err) { return err; } - err = write(dirStat.inode, dirBuff, dirBuffLen - DirectoryEntry::spaceNeeded(fileName)); + err = write(dirStat.inode, dirBuff, dirBuffLen - DirectoryEntry::spaceNeeded(fileName)); return err; } - -// Directory - template -uint64_t FileSystemTemplate::Directory::getFileInode(const char *name, uint64_t buffSize) { - uint64_t inode = 0; - auto current = files(); - if (current) { - for (uint64_t i = 0; ox_strcmp(current->getName(), name) != 0;) { - i += current->size(); - if (i < this->size) { - current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); - } else { - current = nullptr; - break; - } - } - if (current) { - inode = current->inode; - } - } - return inode; -} +int FileSystemTemplate::readDirectory(const char *path, Directory *dirOut) { + int err = 0; + auto inode = findInodeOf(path); + auto dirStat = stat(inode); + auto dirBuffLen = dirStat.size; + uint8_t dirBuff[dirBuffLen]; + auto dir = (Directory*) dirBuff; -template -int FileSystemTemplate::Directory::getChildrenInodes(typename FileStore::InodeId_t *inodes, size_t inodesLen) { - if (inodesLen >= this->children) { - auto current = files(); - if (current) { - for (uint64_t i = 0; i < this->children; i++) { - inodes[i] = current->inode; - current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); - } - return 0; - } else { - return 1; - } + err = read(dirStat.inode, dirBuff, dirBuffLen); + if (!err) { + return dir->copy(dirOut); } else { - return 2; + return 1; } } -template -int FileSystemTemplate::Directory::rmFile(const char *name) { - int err = 1; - auto current = files(); - if (current) { - for (uint64_t i = 0; i < this->size;) { - i += current->size(); - if (ox_strcmp(current->getName(), name) == 0) { - auto dest = (uint8_t*) current; - auto src = dest + current->size(); - ox_memcpy(dest, src, this->size - i); - this->size -= current->size(); - this->children--; - err = 0; - break; - } - current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); - } - } - return err; -} typedef FileSystemTemplate FileSystem16; typedef FileSystemTemplate FileSystem32; typedef FileSystemTemplate FileSystem64; } -} diff --git a/src/ox/fs/oxfstool.cpp b/src/ox/fs/oxfstool.cpp index 6fc9e5b6..fd40e82a 100644 --- a/src/ox/fs/oxfstool.cpp +++ b/src/ox/fs/oxfstool.cpp @@ -17,7 +17,7 @@ #pragma warning(disable:4996) #endif -using namespace ox::fs; +using namespace ox; using namespace std; const static auto oxfstoolVersion = "1.3.0"; @@ -128,9 +128,9 @@ int format(int argc, char **args) { delete []buff; if (err == 0) { - cerr << "Created file system of type " << type << " " << path << endl; - cerr << "\ttype " << type << endl; - cerr << "\twrote " << size << " bytes\n"; + cerr << "Created file system " << path << endl; + cerr << " type " << type << endl; + cerr << " wrote " << size << " bytes\n"; } } else { fprintf(stderr, "Insufficient arguments\n"); diff --git a/src/ox/fs/pathiterator.cpp b/src/ox/fs/pathiterator.cpp index f82cd8be..4c14a0a3 100644 --- a/src/ox/fs/pathiterator.cpp +++ b/src/ox/fs/pathiterator.cpp @@ -11,7 +11,6 @@ #include "pathiterator.hpp" namespace ox { -namespace fs { PathIterator::PathIterator(const char *path, size_t maxSize) { m_path = path; @@ -97,4 +96,3 @@ bool PathIterator::hasNext() { } } -} diff --git a/src/ox/fs/pathiterator.hpp b/src/ox/fs/pathiterator.hpp index 789e8ac8..4d55f7f0 100644 --- a/src/ox/fs/pathiterator.hpp +++ b/src/ox/fs/pathiterator.hpp @@ -11,7 +11,6 @@ #include namespace ox { -namespace fs { class PathIterator { private: @@ -41,4 +40,3 @@ class PathIterator { }; } -} diff --git a/src/ox/fs/test/CMakeLists.txt b/src/ox/fs/test/CMakeLists.txt index 8ca81bcf..be393710 100644 --- a/src/ox/fs/test/CMakeLists.txt +++ b/src/ox/fs/test/CMakeLists.txt @@ -43,3 +43,4 @@ add_test("Test\\ FileSystem32::rmDirectoryEntry\\(string\\)" FSTests "FileSystem add_test("Test\\ FileSystem32::remove\\(string,\\ true\\)" FSTests "FileSystem32::remove(string, true)") add_test("Test\\ FileSystem32::move" FSTests "FileSystem32::move") add_test("Test\\ FileSystem32::stripDirectories" FSTests "FileSystem32::stripDirectories") +add_test("Test\\ FileSystem32::ls" FSTests "FileSystem32::ls") diff --git a/src/ox/fs/test/filestore_format.cpp b/src/ox/fs/test/filestore_format.cpp index 81fb9974..68e761ef 100644 --- a/src/ox/fs/test/filestore_format.cpp +++ b/src/ox/fs/test/filestore_format.cpp @@ -7,7 +7,7 @@ */ #include -using namespace ox::fs; +using namespace ox; int main() { const auto size = 65535; diff --git a/src/ox/fs/test/filestoreio.cpp b/src/ox/fs/test/filestoreio.cpp index 2a73c33e..26c1b641 100644 --- a/src/ox/fs/test/filestoreio.cpp +++ b/src/ox/fs/test/filestoreio.cpp @@ -9,8 +9,7 @@ #include #include -using namespace ox::fs; -using namespace ox::std; +using namespace ox; template int test() { diff --git a/src/ox/fs/test/filesystem_format.cpp b/src/ox/fs/test/filesystem_format.cpp index 7e82514c..ff4f020a 100644 --- a/src/ox/fs/test/filesystem_format.cpp +++ b/src/ox/fs/test/filesystem_format.cpp @@ -8,8 +8,7 @@ #include -using namespace ox::fs; -using namespace ox::std; +using namespace ox; template int test() { diff --git a/src/ox/fs/test/tests.cpp b/src/ox/fs/test/tests.cpp index 45810d2c..d29d3b32 100644 --- a/src/ox/fs/test/tests.cpp +++ b/src/ox/fs/test/tests.cpp @@ -16,7 +16,7 @@ #include using namespace std; -using namespace ox::fs; +using namespace ox; map tests = { { @@ -288,6 +288,40 @@ map tests = { delete []buff; delete []dataOut; + return retval; + } + }, + { + "FileSystem32::ls", + [](string) { + int retval = 0; + auto dataIn = "test string"; + auto dataOutLen = ox_strlen(dataIn) + 1; + auto dataOut = new char[dataOutLen]; + vector inodes; + vector> files; + + const auto size = 1024 * 1024; + auto buff = new uint8_t[size]; + FileSystem32::format(buff, (FileStore32::FsSize_t) size, true); + auto fs = (FileSystem32*) createFileSystem(buff, size); + + retval |= fs->mkdir("/usr"); + retval |= fs->mkdir("/usr/share"); + retval |= fs->write("/usr/share/a.txt", (void*) dataIn, ox_strlen(dataIn) + 1); + retval |= fs->write("/usr/share/b.txt", (void*) dataIn, ox_strlen(dataIn) + 1); + retval |= fs->write("/usr/share/c.txt", (void*) dataIn, ox_strlen(dataIn) + 1); + + fs->ls("/usr/share/", &files); + + retval |= !(files[0].name == "a.txt"); + retval |= !(files[1].name == "b.txt"); + retval |= !(files[2].name == "c.txt"); + + delete fs; + delete []buff; + delete []dataOut; + return retval; } }, diff --git a/src/ox/mc/read.hpp b/src/ox/mc/read.hpp index e718ae42..11b39287 100644 --- a/src/ox/mc/read.hpp +++ b/src/ox/mc/read.hpp @@ -74,7 +74,7 @@ int MetalClawReader::op(const char*, ox::bstring *val) { typedef uint32_t StringLength; size_t size = 0; if (m_buffIt + sizeof(StringLength) < m_buffLen) { - size = ox::std::bigEndianAdapt(*((StringLength*) &m_buff[m_buffIt])); + size = ox::bigEndianAdapt(*((StringLength*) &m_buff[m_buffIt])); m_buffIt += sizeof(StringLength); } else { err |= MC_BUFFENDED; @@ -103,7 +103,7 @@ int MetalClawReader::readInteger(I *val) { int err = 0; if (m_fieldPresence.get(m_field)) { if (m_buffIt + sizeof(I) < m_buffLen) { - *val = ox::std::bigEndianAdapt(*((I*) &m_buff[m_buffIt])); + *val = ox::bigEndianAdapt(*((I*) &m_buff[m_buffIt])); m_buffIt += sizeof(I); } else { err = MC_BUFFENDED; @@ -123,7 +123,7 @@ int MetalClawReader::op(const char*, T *val, size_t valLen) { typedef uint32_t ArrayLength; size_t len = 0; if (m_buffIt + sizeof(ArrayLength) < m_buffLen) { - len = ox::std::bigEndianAdapt(*((T*) &m_buff[m_buffIt])); + len = ox::bigEndianAdapt(*((T*) &m_buff[m_buffIt])); m_buffIt += sizeof(ArrayLength); } else { err = MC_BUFFENDED; diff --git a/src/ox/mc/write.hpp b/src/ox/mc/write.hpp index a68a994e..8380b3c7 100644 --- a/src/ox/mc/write.hpp +++ b/src/ox/mc/write.hpp @@ -62,7 +62,7 @@ int MetalClawWriter::op(const char*, ox::bstring *val) { // write the length typedef uint32_t StringLength; if (m_buffIt + sizeof(StringLength) + val->size() < m_buffLen) { - *((StringLength*) &m_buff[m_buffIt]) = ox::std::bigEndianAdapt((StringLength) val->size()); + *((StringLength*) &m_buff[m_buffIt]) = ox::bigEndianAdapt((StringLength) val->size()); m_buffIt += sizeof(StringLength); // write the string @@ -99,7 +99,7 @@ int MetalClawWriter::appendInteger(I val) { bool fieldSet = false; if (val) { if (m_buffIt + sizeof(I) < m_buffLen) { - *((I*) &m_buff[m_buffIt]) = ox::std::bigEndianAdapt(val); + *((I*) &m_buff[m_buffIt]) = ox::bigEndianAdapt(val); fieldSet = true; m_buffIt += sizeof(I); } else { @@ -120,7 +120,7 @@ int MetalClawWriter::op(const char*, T *val, size_t len) { // write the length typedef uint32_t ArrayLength; if (m_buffIt + sizeof(ArrayLength) < m_buffLen) { - *((T*) &m_buff[m_buffIt]) = ox::std::bigEndianAdapt((ArrayLength) len); + *((T*) &m_buff[m_buffIt]) = ox::bigEndianAdapt((ArrayLength) len); m_buffIt += sizeof(ArrayLength); } else { err = MC_BUFFENDED; diff --git a/src/ox/std/byteswap.hpp b/src/ox/std/byteswap.hpp index 22e40566..9bb199ee 100644 --- a/src/ox/std/byteswap.hpp +++ b/src/ox/std/byteswap.hpp @@ -11,8 +11,6 @@ #include "types.hpp" namespace ox { -namespace std { - inline int16_t byteSwap(int16_t i) { return (i << 8) | (i >> 8); @@ -140,6 +138,4 @@ inline uint64_t bigEndianAdapt(uint64_t i) { #endif } - -} } diff --git a/src/ox/std/test/byteswap_test.cpp b/src/ox/std/test/byteswap_test.cpp index 6bad0353..ff05de99 100644 --- a/src/ox/std/test/byteswap_test.cpp +++ b/src/ox/std/test/byteswap_test.cpp @@ -10,7 +10,7 @@ #include using namespace std; -using namespace ox::std; +using namespace ox; template int testBigEndianAdapt(string str) {