From e18db20630b276375f4030db8b543dd11eedfad7 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 8 Aug 2015 16:17:28 +0300 Subject: [PATCH] VFS cleanup, some methods added VFS::DeleteAll, VFS::GetDirSize, VFS::Exists, VFS::Rename (VFS::RenameFile, VFS::RenameDir removed) --- rpcs3/Emu/FS/VFS.cpp | 135 ++++++++++++++---------- rpcs3/Emu/FS/VFS.h | 6 +- rpcs3/Emu/FS/vfsDir.cpp | 33 ------ rpcs3/Emu/FS/vfsDir.h | 6 -- rpcs3/Emu/FS/vfsDirBase.cpp | 12 +-- rpcs3/Emu/FS/vfsDirBase.h | 5 - rpcs3/Emu/FS/vfsFile.cpp | 15 --- rpcs3/Emu/FS/vfsFile.h | 3 - rpcs3/Emu/FS/vfsFileBase.h | 3 - rpcs3/Emu/FS/vfsLocalDir.cpp | 20 ---- rpcs3/Emu/FS/vfsLocalDir.h | 5 - rpcs3/Emu/FS/vfsLocalFile.cpp | 15 --- rpcs3/Emu/FS/vfsLocalFile.h | 3 - rpcs3/Emu/HDD/HDD.h | 2 +- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 4 +- rpcs3/Emu/SysCalls/lv2/sys_fs.cpp | 26 +---- 16 files changed, 92 insertions(+), 201 deletions(-) diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index dcf050cb02..e16bafc4d9 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "VFS.h" +#include "vfsDir.h" +#include "vfsFile.h" #include "vfsDirBase.h" #include "Emu/HDD/HDD.h" #include "vfsDeviceLocalFile.h" @@ -168,12 +170,8 @@ bool VFS::CreateDir(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - std::unique_ptr res(dev->GetNewDirStream()); - - if (res) - { - return res->Create(path); - } + // return dev->create_dir(path); + return fs::create_dir(path); } return false; @@ -185,6 +183,7 @@ bool VFS::CreatePath(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { + // return dev->create_path(path); return fs::create_path(path); } @@ -197,12 +196,8 @@ bool VFS::RemoveFile(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - std::unique_ptr res(dev->GetNewFileStream()); - - if (res) - { - return res->Remove(path); - } + // return dev->remove_file(path); + return fs::remove_file(path); } return false; @@ -214,29 +209,68 @@ bool VFS::RemoveDir(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - std::unique_ptr res(dev->GetNewDirStream()); - - if (res) - { - return res->Remove(path); - } + // return dev->remove_dir(path); + return fs::remove_dir(path); } return false; } +void VFS::DeleteAll(const std::string& ps3_path) const +{ + // Delete directory and all its contents recursively + for (const auto entry : vfsDir(ps3_path)) + { + if (entry->name == "." || entry->name == "..") + { + continue; + } + + if (entry->flags & DirEntry_TypeFile) + { + RemoveFile(ps3_path + "/" + entry->name); + } + + if (entry->flags & DirEntry_TypeDir) + { + DeleteAll(ps3_path + "/" + entry->name); + } + } +} + +u64 VFS::GetDirSize(const std::string& ps3_path) const +{ + u64 result = 0; + + for (const auto entry : vfsDir(ps3_path)) + { + if (entry->name == "." || entry->name == "..") + { + continue; + } + + if (entry->flags & DirEntry_TypeFile) + { + result += entry->size; + } + + if (entry->flags & DirEntry_TypeDir) + { + result += GetDirSize(ps3_path + "/" + entry->name); + } + } + + return result; +} + bool VFS::ExistsFile(const std::string& ps3_path) const { std::string path; if (vfsDevice* dev = GetDevice(ps3_path, path)) { - std::unique_ptr res(dev->GetNewFileStream()); - - if (res) - { - return res->Exists(path); - } + // return dev->is_file(path); + return fs::is_file(path); } return false; @@ -248,18 +282,27 @@ bool VFS::ExistsDir(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - std::unique_ptr res(dev->GetNewDirStream()); - - if (res) - { - return res->IsExists(path); - } + // return dev->is_dir(path); + return fs::is_dir(path); } return false; } -bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const +bool VFS::Exists(const std::string& ps3_path) const +{ + std::string path; + + if (vfsDevice* dev = GetDevice(ps3_path, path)) + { + // return dev->exists(path); + return fs::exists(path); + } + + return false; +} + +bool VFS::Rename(const std::string& ps3_path_from, const std::string& ps3_path_to) const { std::string path_from, path_to; @@ -267,32 +310,8 @@ bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_pa { if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) { - std::unique_ptr res(dev->GetNewFileStream()); - - if (res) - { - return res->Rename(path_from, path_to); - } - } - } - - return false; -} - -bool VFS::RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const -{ - std::string path_from, path_to; - - if (vfsDevice* dev = GetDevice(ps3_path_from, path_from)) - { - if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) - { - std::unique_ptr res(dev->GetNewDirStream()); - - if (res) - { - return res->Rename(path_from, path_to); - } + // return dev->rename(dev_, path_from, path_to); + return fs::rename(path_from, path_to); } } @@ -307,6 +326,7 @@ bool VFS::CopyFile(const std::string& ps3_path_from, const std::string& ps3_path { if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) { + // return dev->copy_file(dev_, path_from, path_to, overwrite); return fs::copy_file(path_from, path_to, overwrite); } } @@ -320,6 +340,7 @@ bool VFS::TruncateFile(const std::string& ps3_path, u64 length) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { + // return dev->truncate_file(path, length); return fs::truncate_file(path, length); } diff --git a/rpcs3/Emu/FS/VFS.h b/rpcs3/Emu/FS/VFS.h index c2f2d532df..4418ea33f1 100644 --- a/rpcs3/Emu/FS/VFS.h +++ b/rpcs3/Emu/FS/VFS.h @@ -81,10 +81,12 @@ struct VFS bool CreatePath(const std::string& ps3_path) const; bool RemoveFile(const std::string& ps3_path) const; bool RemoveDir(const std::string& ps3_path) const; + void DeleteAll(const std::string& ps3_path) const; + u64 GetDirSize(const std::string& ps3_path) const; bool ExistsFile(const std::string& ps3_path) const; bool ExistsDir(const std::string& ps3_path) const; - bool RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const; - bool RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const; + bool Exists(const std::string& ps3_path) const; + bool Rename(const std::string& ps3_path_from, const std::string& ps3_path_to) const; bool CopyFile(const std::string& ps3_path_from, const std::string& ps3_path_to, bool overwrite = true) const; bool TruncateFile(const std::string& ps3_path, u64 length) const; diff --git a/rpcs3/Emu/FS/vfsDir.cpp b/rpcs3/Emu/FS/vfsDir.cpp index c8c7c0a9d4..3307561401 100644 --- a/rpcs3/Emu/FS/vfsDir.cpp +++ b/rpcs3/Emu/FS/vfsDir.cpp @@ -68,39 +68,6 @@ bool vfsDir::Open(const std::string& path) return !m_entries.empty(); } -bool vfsDir::Create(const std::string& path) -{ - return Emu.GetVFS().CreateDir(path); -} - -bool vfsDir::IsExists(const std::string& path) const -{ - auto path_blocks = simplify_path_blocks(path); - - if (path_blocks.empty()) - return false; - - std::string dir_name = path_blocks[path_blocks.size() - 1]; - - for (const auto entry : vfsDir(path + "/..")) - { - if (!strcmp(entry->name.c_str(), dir_name.c_str())) - return true; - } - - return false; -} - -bool vfsDir::Rename(const std::string& from, const std::string& to) -{ - return Emu.GetVFS().RenameDir(from, to); -} - -bool vfsDir::Remove(const std::string& path) -{ - return Emu.GetVFS().RemoveDir(path); -} - void vfsDir::Close() { m_stream.reset(); diff --git a/rpcs3/Emu/FS/vfsDir.h b/rpcs3/Emu/FS/vfsDir.h index 5dd2b8897e..61a2004875 100644 --- a/rpcs3/Emu/FS/vfsDir.h +++ b/rpcs3/Emu/FS/vfsDir.h @@ -12,12 +12,6 @@ public: virtual bool Open(const std::string& path) override; virtual bool IsOpened() const override; - virtual bool IsExists(const std::string& path) const override; virtual void Close() override; //virtual std::string GetPath() const override; - - virtual bool Create(const std::string& path) override; - //virtual bool Create(const DirEntryInfo& info) override; - virtual bool Rename(const std::string& from, const std::string& to) override; - virtual bool Remove(const std::string& path) override; }; diff --git a/rpcs3/Emu/FS/vfsDirBase.cpp b/rpcs3/Emu/FS/vfsDirBase.cpp index 4a001e43fe..554fe8823f 100644 --- a/rpcs3/Emu/FS/vfsDirBase.cpp +++ b/rpcs3/Emu/FS/vfsDirBase.cpp @@ -14,11 +14,10 @@ vfsDirBase::~vfsDirBase() bool vfsDirBase::Open(const std::string& path) { - if(IsOpened()) + if (IsOpened()) + { Close(); - - if(!IsExists(path)) - return false; + } m_pos = 0; m_cwd += '/' + path; @@ -30,11 +29,6 @@ bool vfsDirBase::IsOpened() const return !m_cwd.empty(); } -bool vfsDirBase::IsExists(const std::string& path) const -{ - return false; -} - const std::vector& vfsDirBase::GetEntries() const { return m_entries; diff --git a/rpcs3/Emu/FS/vfsDirBase.h b/rpcs3/Emu/FS/vfsDirBase.h index 4bb707a941..ee43cb602d 100644 --- a/rpcs3/Emu/FS/vfsDirBase.h +++ b/rpcs3/Emu/FS/vfsDirBase.h @@ -45,15 +45,10 @@ public: virtual bool Open(const std::string& path); virtual bool IsOpened() const; - virtual bool IsExists(const std::string& path) const; virtual const std::vector& GetEntries() const; virtual void Close(); virtual std::string GetPath() const; - virtual bool Create(const std::string& path) = 0; - //virtual bool Create(const DirEntryInfo& info)=0; - virtual bool Rename(const std::string& from, const std::string& to) = 0; - virtual bool Remove(const std::string& path) = 0; virtual const DirEntryInfo* Read(); virtual const DirEntryInfo* First(); diff --git a/rpcs3/Emu/FS/vfsFile.cpp b/rpcs3/Emu/FS/vfsFile.cpp index 649a03fcda..1391d5103e 100644 --- a/rpcs3/Emu/FS/vfsFile.cpp +++ b/rpcs3/Emu/FS/vfsFile.cpp @@ -26,21 +26,6 @@ bool vfsFile::Open(const std::string& path, u32 mode) return m_stream && m_stream->IsOpened(); } -bool vfsFile::Exists(const std::string& path) -{ - return m_stream->Exists(path); -} - -bool vfsFile::Rename(const std::string& from, const std::string& to) -{ - return m_stream->Rename(from, to); -} - -bool vfsFile::Remove(const std::string& path) -{ - return m_stream->Remove(path); -} - bool vfsFile::Close() { m_stream.reset(); diff --git a/rpcs3/Emu/FS/vfsFile.h b/rpcs3/Emu/FS/vfsFile.h index dfb211cbd4..e1bcbbc839 100644 --- a/rpcs3/Emu/FS/vfsFile.h +++ b/rpcs3/Emu/FS/vfsFile.h @@ -11,9 +11,6 @@ public: vfsFile(const std::string& path, u32 mode = vfsRead); virtual bool Open(const std::string& path, u32 mode = vfsRead) override; - virtual bool Exists(const std::string& path) override; - virtual bool Rename(const std::string& from, const std::string& to) override; - virtual bool Remove(const std::string& path) override; virtual bool Close() override; virtual u64 GetSize() const override; diff --git a/rpcs3/Emu/FS/vfsFileBase.h b/rpcs3/Emu/FS/vfsFileBase.h index 9639d76992..239d7251e0 100644 --- a/rpcs3/Emu/FS/vfsFileBase.h +++ b/rpcs3/Emu/FS/vfsFileBase.h @@ -24,9 +24,6 @@ public: virtual bool Open(const std::string& path, u32 mode); virtual bool Close() override; - virtual bool Exists(const std::string& path) { return false; } - virtual bool Rename(const std::string& from, const std::string& to) { return false; } - virtual bool Remove(const std::string& path) { return false; } virtual bool IsOpened() const override { return !m_path.empty(); } std::string GetPath() const; diff --git a/rpcs3/Emu/FS/vfsLocalDir.cpp b/rpcs3/Emu/FS/vfsLocalDir.cpp index 5b70be56d6..063b7d5427 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.cpp +++ b/rpcs3/Emu/FS/vfsLocalDir.cpp @@ -38,26 +38,6 @@ bool vfsLocalDir::Open(const std::string& path) return true; } -bool vfsLocalDir::Create(const std::string& path) -{ - return fs::create_dir(path); -} - -bool vfsLocalDir::IsExists(const std::string& path) const -{ - return fs::is_dir(path); -} - -bool vfsLocalDir::Rename(const std::string& from, const std::string& to) -{ - return fs::rename(from, to); -} - -bool vfsLocalDir::Remove(const std::string& path) -{ - return fs::remove_dir(path); -} - bool vfsLocalDir::IsOpened() const { return m_dir && vfsDirBase::IsOpened(); diff --git a/rpcs3/Emu/FS/vfsLocalDir.h b/rpcs3/Emu/FS/vfsLocalDir.h index 06fe0eb2de..0eafef70d7 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.h +++ b/rpcs3/Emu/FS/vfsLocalDir.h @@ -13,10 +13,5 @@ public: virtual ~vfsLocalDir(); virtual bool Open(const std::string& path) override; - - virtual bool Create(const std::string& path) override; - virtual bool Rename(const std::string& from, const std::string& to) override; - virtual bool Remove(const std::string& path) override; virtual bool IsOpened() const override; - virtual bool IsExists(const std::string& path) const override; }; diff --git a/rpcs3/Emu/FS/vfsLocalFile.cpp b/rpcs3/Emu/FS/vfsLocalFile.cpp index c0a1d57935..057fcf7d85 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.cpp +++ b/rpcs3/Emu/FS/vfsLocalFile.cpp @@ -47,18 +47,3 @@ bool vfsLocalFile::IsOpened() const { return m_file && vfsFileBase::IsOpened(); } - -bool vfsLocalFile::Exists(const std::string& path) -{ - return fs::is_file(path); -} - -bool vfsLocalFile::Rename(const std::string& from, const std::string& to) -{ - return fs::rename(from, to); -} - -bool vfsLocalFile::Remove(const std::string& path) -{ - return fs::remove_file(path); -} diff --git a/rpcs3/Emu/FS/vfsLocalFile.h b/rpcs3/Emu/FS/vfsLocalFile.h index d6e0b5c493..f3a656e089 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.h +++ b/rpcs3/Emu/FS/vfsLocalFile.h @@ -11,9 +11,6 @@ public: virtual bool Open(const std::string& path, u32 mode = vfsRead) override; virtual bool Close() override; - virtual bool Exists(const std::string& path) override; - virtual bool Rename(const std::string& from, const std::string& to) override; - virtual bool Remove(const std::string& path) override; virtual u64 GetSize() const override; diff --git a/rpcs3/Emu/HDD/HDD.h b/rpcs3/Emu/HDD/HDD.h index 8818ba56cd..62a529d837 100644 --- a/rpcs3/Emu/HDD/HDD.h +++ b/rpcs3/Emu/HDD/HDD.h @@ -158,7 +158,7 @@ public: int OpenDir(const std::string& name); - bool Rename(const std::string& from, const std::string& to) override; + bool Rename(const std::string& from, const std::string& to); u64 FindFreeBlock(); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index 9c4fd5be19..4f4eccbcc9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -48,7 +48,7 @@ struct content_permission_t final { if (is_temporary) { - // TODO: delete temporary directory and all its contents + Emu.GetVFS().DeleteAll("/dev_hdd1/game/" + dir); } } }; @@ -342,7 +342,7 @@ s32 cellGameContentPermit(vm::ptr contentInfoPath, vm: const std::string dir = "/dev_hdd0/game/" + path_set->dir; // make temporary directory persistent - if (Emu.GetVFS().RenameDir("/dev_hdd1/game/" + path_set->dir, dir)) + if (Emu.GetVFS().Rename("/dev_hdd1/game/" + path_set->dir, dir)) { cellGame.Success("cellGameContentPermit(): '%s' directory created", dir); } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp index 13e208fe5f..e1b63c2b81 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp @@ -388,31 +388,13 @@ s32 sys_fs_rename(vm::cptr from, vm::cptr to) sys_fs.Warning("*** from = '%s'", from.get_ptr()); sys_fs.Warning("*** to = '%s'", to.get_ptr()); - std::string ps3_path = from.get_ptr(); - - if (Emu.GetVFS().ExistsDir(ps3_path)) + if (!Emu.GetVFS().Rename(from.get_ptr(), to.get_ptr())) { - if (!Emu.GetVFS().RenameDir(ps3_path, to.get_ptr())) - { - return CELL_FS_EIO; // ??? - } - - sys_fs.Notice("sys_fs_rename(): directory '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); - return CELL_OK; + return CELL_FS_ENOENT; // ??? } - if (Emu.GetVFS().ExistsFile(ps3_path)) - { - if (!Emu.GetVFS().RenameFile(ps3_path, to.get_ptr())) - { - return CELL_FS_EIO; // ??? - } - - sys_fs.Notice("sys_fs_rename(): file '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); - return CELL_OK; - } - - return CELL_FS_ENOENT; + sys_fs.Notice("sys_fs_rename(): '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); + return CELL_OK; } s32 sys_fs_rmdir(vm::cptr path)