From 4a44a23014bbbab8e35b80d54f666566c6bcb170 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 12 May 2017 02:34:11 -0500 Subject: [PATCH 1/4] Add default constructor for DirectoryListing --- src/ox/fs/filesystem.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 3c0df7a10..cd4378ef1 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -35,6 +35,8 @@ struct DirectoryListing { String name; FileStat stat; + DirectoryListing() = default; + DirectoryListing(const char *name) { this->name = name; } @@ -181,7 +183,7 @@ int Directory::ls(List *list) { if (current) { for (uint64_t i = 0; i < this->children; i++) { list->push_back(current->getName()); - list->at(i).stat.inode = current->inode; + (*list)[i].stat.inode = current->inode; current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); } return 0; From c19a71793ff1cb5d55b37ca2cb3c1c33a75a7e7c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 12 May 2017 16:26:59 -0500 Subject: [PATCH 2/4] Fix readDirectory use the right type of directory --- src/ox/fs/filesystem.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index cd4378ef1..5ed98b0ca 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -157,18 +157,18 @@ int Directory::rmFile(const char *name) { template int Directory::copy(Directory *dirOut) { auto current = files(); - auto dirBuff = (uint8_t*) dirOut; - dirBuff += sizeof(Directory); + auto dirOutBuff = (uint8_t*) dirOut; + dirOutBuff += 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; + auto entry = (DirectoryEntry*) dirOutBuff; entry->inode = current->inode; entry->setName(current->getName()); current = (DirectoryEntry*) (((uint8_t*) current) + current->size()); - dirBuff += entry->size(); + dirOutBuff += entry->size(); } return 0; } else { @@ -797,7 +797,7 @@ int FileSystemTemplate::readDirectory(const char *path, Dire 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) { From ac3f12fbe4b836e8ee58dad3d0df20a9efcaa54c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 13 May 2017 23:14:21 -0500 Subject: [PATCH 3/4] Remove unnecessary ls from FileSystemTemplate --- src/ox/fs/filesystem.hpp | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 5ed98b0ca..2576ffafb 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -277,9 +277,6 @@ 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; @@ -356,30 +353,6 @@ int FileSystemTemplate::stripDirectories() { 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; From 038ca96f9efe88f170429459d3d6619eaa5c17e9 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 13 May 2017 23:19:17 -0500 Subject: [PATCH 4/4] Add missing error reporting to file system ls --- src/ox/fs/filesystem.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 2576ffafb..47810a95d 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -244,7 +244,7 @@ int FileSystem::ls(const char *path, List *list) { uint8_t dirBuff[s.size * 4]; auto dir = (Directory*) dirBuff; auto err = readDirectory(path, dir); - dir->ls(list); + err |= dir->ls(list); return err; }