VERY experimental Nintendo Switch 2 emulator
C++
file_sys: Cleanup to better match Switch file system constructs.
bunnei0446482361ed
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex b2dcc039a4..5ff1311a29 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -6,15 +6,17 @@ add_library(core STATICcore.hcore_timing.cppcore_timing.h- file_sys/archive_backend.cpp- file_sys/archive_backend.h- file_sys/directory_backend.h+ file_sys/directory.hfile_sys/errors.h- file_sys/file_backend.h+ file_sys/filesystem.cpp+ file_sys/filesystem.hfile_sys/path_parser.cppfile_sys/path_parser.h- file_sys/romfs_archive.cpp- file_sys/romfs_archive.h+ file_sys/romfs_factory.cpp+ file_sys/romfs_factory.h+ file_sys/romfs_filesystem.cpp+ file_sys/romfs_filesystem.h+ file_sys/storage.hfrontend/emu_window.cppfrontend/emu_window.hfrontend/framebuffer_layout.cppdiff --git a/src/core/file_sys/directory_backend.h b/src/core/file_sys/directory.hsimilarity index 98%rename from src/core/file_sys/directory_backend.hrename to src/core/file_sys/directory.hindex 0c93f20746..5a40bf472d 100644--- a/src/core/file_sys/directory_backend.h+++ b/src/core/file_sys/directory.h@@ -1,4 +1,4 @@-// Copyright 2014 Citra Emulator Project+// Copyright 2018 yuzu emulator team// Licensed under GPLv2 or any later version// Refer to the license.txt file included.diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/filesystem.cppsimilarity index 97%rename from src/core/file_sys/archive_backend.cpprename to src/core/file_sys/filesystem.cppindex fc472b44f3..82fdb3c464 100644--- a/src/core/file_sys/archive_backend.cpp+++ b/src/core/file_sys/filesystem.cpp@@ -1,4 +1,4 @@-// Copyright 2015 Citra Emulator Project+// Copyright 2018 yuzu emulator team// Licensed under GPLv2 or any later version// Refer to the license.txt file included.@@ -7,7 +7,7 @@#include <sstream>#include "common/logging/log.h"#include "common/string_util.h"-#include "core/file_sys/archive_backend.h"+#include "core/file_sys/filesystem.h"#include "core/memory.h"namespace FileSys {diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/filesystem.hsimilarity index 92%rename from src/core/file_sys/archive_backend.hrename to src/core/file_sys/filesystem.hindex 2255bee42d..eb3d9c4d66 100644--- a/src/core/file_sys/archive_backend.h+++ b/src/core/file_sys/filesystem.h@@ -1,4 +1,4 @@-// Copyright 2014 Citra Emulator Project+// Copyright 2018 yuzu emulator team// Licensed under GPLv2 or any later version// Refer to the license.txt file included.@@ -15,7 +15,7 @@namespace FileSys {-class FileBackend;+class StorageBackend;class DirectoryBackend;// Path string type@@ -71,9 +71,9 @@ struct ArchiveFormatInfo {};static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD");-class ArchiveBackend : NonCopyable {+class FileSystemBackend : NonCopyable {public:- virtual ~ArchiveBackend() {}+ virtual ~FileSystemBackend() {}/*** Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)@@ -138,8 +138,8 @@ public:* @param mode Mode to open the file with* @return Opened file, or error code*/- virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,- const Mode& mode) const = 0;+ virtual ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const Path& path,+ const Mode& mode) const = 0;/*** Open a directory specified by its path@@ -155,9 +155,9 @@ public:virtual u64 GetFreeSpaceSize() const = 0;};-class ArchiveFactory : NonCopyable {+class FileSystemFactory : NonCopyable {public:- virtual ~ArchiveFactory() {}+ virtual ~FileSystemFactory() {}/*** Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)@@ -169,7 +169,7 @@ public:* @param path Path to the archive* @return An ArchiveBackend corresponding operating specified archive path.*/- virtual ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) = 0;+ virtual ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) = 0;/*** Deletes the archive contents and then re-creates the base folderdiff --git a/src/core/file_sys/path_parser.h b/src/core/file_sys/path_parser.hindex b9f52f65da..184f59d553 100644--- a/src/core/file_sys/path_parser.h+++ b/src/core/file_sys/path_parser.h@@ -6,7 +6,7 @@#include <string>#include <vector>-#include "core/file_sys/archive_backend.h"+#include "core/file_sys/filesystem.h"namespace FileSys {diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cppnew file mode 100644index 0000000000..590c2acb30--- /dev/null+++ b/src/core/file_sys/romfs_factory.cpp@@ -0,0 +1,39 @@+// Copyright 2018 yuzu emulator team+// Licensed under GPLv2 or any later version+// Refer to the license.txt file included.++#include <algorithm>+#include <memory>+#include "common/common_types.h"+#include "common/logging/log.h"+#include "core/file_sys/romfs_factory.h"+#include "core/file_sys/romfs_filesystem.h"++namespace FileSys {++RomFS_Factory::RomFS_Factory(Loader::AppLoader& app_loader) {+ // Load the RomFS from the app+ if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) {+ LOG_ERROR(Service_FS, "Unable to read RomFS!");+ }+}++ResultVal<std::unique_ptr<FileSystemBackend>> RomFS_Factory::Open(const Path& path) {+ auto archive = std::make_unique<RomFS_FileSystem>(romfs_file, data_offset, data_size);+ return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));+}++ResultCode RomFS_Factory::Format(const Path& path,+ const FileSys::ArchiveFormatInfo& format_info) {+ LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str());+ // TODO(bunnei): Find the right error code for this+ return ResultCode(-1);+}++ResultVal<ArchiveFormatInfo> RomFS_Factory::GetFormatInfo(const Path& path) const {+ LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str());+ // TODO(bunnei): Find the right error code for this+ return ResultCode(-1);+}++} // namespace FileSysdiff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.hnew file mode 100644index 0000000000..10ea139667--- /dev/null+++ b/src/core/file_sys/romfs_factory.h@@ -0,0 +1,35 @@+// Copyright 2018 yuzu emulator team+// Licensed under GPLv2 or any later version+// Refer to the license.txt file included.++#pragma once++#include <memory>+#include <string>+#include <vector>+#include "common/common_types.h"+#include "core/file_sys/filesystem.h"+#include "core/hle/result.h"+#include "core/loader/loader.h"++namespace FileSys {++/// File system interface to the RomFS archive+class RomFS_Factory final : public FileSystemFactory {+public:+ explicit RomFS_Factory(Loader::AppLoader& app_loader);++ std::string GetName() const override {+ return "ArchiveFactory_RomFS";+ }+ ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override;+ ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;+ ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;++private:+ std::shared_ptr<FileUtil::IOFile> romfs_file;+ u64 data_offset;+ u64 data_size;+};++} // namespace FileSysdiff --git a/src/core/file_sys/romfs_archive.cpp b/src/core/file_sys/romfs_filesystem.cppsimilarity index 62%rename from src/core/file_sys/romfs_archive.cpprename to src/core/file_sys/romfs_filesystem.cppindex 0d93fccd47..5b5c5a73e4 100644--- a/src/core/file_sys/romfs_archive.cpp+++ b/src/core/file_sys/romfs_filesystem.cpp@@ -6,79 +6,79 @@#include <memory>#include "common/common_types.h"#include "common/logging/log.h"-#include "core/file_sys/romfs_archive.h"+#include "core/file_sys/romfs_filesystem.h"namespace FileSys {-std::string ROMFSArchive::GetName() const {+std::string RomFS_FileSystem::GetName() const {return "RomFS";}-ResultVal<std::unique_ptr<FileBackend>> ROMFSArchive::OpenFile(const Path& path,- const Mode& mode) const {- return MakeResult<std::unique_ptr<FileBackend>>(- std::make_unique<ROMFSFile>(romfs_file, data_offset, data_size));+ResultVal<std::unique_ptr<StorageBackend>> RomFS_FileSystem::OpenFile(const Path& path,+ const Mode& mode) const {+ return MakeResult<std::unique_ptr<StorageBackend>>(+ std::make_unique<RomFS_Storage>(romfs_file, data_offset, data_size));}-ResultCode ROMFSArchive::DeleteFile(const Path& path) const {+ResultCode RomFS_FileSystem::DeleteFile(const Path& path) const {LOG_CRITICAL(Service_FS, "Attempted to delete a file from an ROMFS archive (%s).",GetName().c_str());// TODO(bunnei): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::RenameFile(const Path& src_path, const Path& dest_path) const {+ResultCode RomFS_FileSystem::RenameFile(const Path& src_path, const Path& dest_path) const {LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",GetName().c_str());// TODO(wwylele): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::DeleteDirectory(const Path& path) const {+ResultCode RomFS_FileSystem::DeleteDirectory(const Path& path) const {LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",GetName().c_str());// TODO(wwylele): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::DeleteDirectoryRecursively(const Path& path) const {+ResultCode RomFS_FileSystem::DeleteDirectoryRecursively(const Path& path) const {LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",GetName().c_str());// TODO(wwylele): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::CreateFile(const Path& path, u64 size) const {+ResultCode RomFS_FileSystem::CreateFile(const Path& path, u64 size) const {LOG_CRITICAL(Service_FS, "Attempted to create a file in an ROMFS archive (%s).",GetName().c_str());// TODO(bunnei): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::CreateDirectory(const Path& path) const {+ResultCode RomFS_FileSystem::CreateDirectory(const Path& path) const {LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).",GetName().c_str());// TODO(wwylele): Use correct error codereturn ResultCode(-1);}-ResultCode ROMFSArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {+ResultCode RomFS_FileSystem::RenameDirectory(const Path& src_path, const Path& dest_path) const {LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",GetName().c_str());// TODO(wwylele): Use correct error codereturn ResultCode(-1);}-ResultVal<std::unique_ptr<DirectoryBackend>> ROMFSArchive::OpenDirectory(const Path& path) const {+ResultVal<std::unique_ptr<DirectoryBackend>> RomFS_FileSystem::OpenDirectory(const Path& path) const {return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<ROMFSDirectory>());}-u64 ROMFSArchive::GetFreeSpaceSize() const {+u64 RomFS_FileSystem::GetFreeSpaceSize() const {LOG_WARNING(Service_FS, "Attempted to get the free space in an ROMFS archive");return 0;}-ResultVal<size_t> ROMFSFile::Read(const u64 offset, const size_t length, u8* buffer) const {+ResultVal<size_t> RomFS_Storage::Read(const u64 offset, const size_t length, u8* buffer) const {LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);romfs_file->Seek(data_offset + offset, SEEK_SET);size_t read_length = (size_t)std::min((u64)length, data_size - offset);@@ -86,18 +86,18 @@ ResultVal<size_t> ROMFSFile::Read(const u64 offset, const size_t length, u8* bufreturn MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));}-ResultVal<size_t> ROMFSFile::Write(const u64 offset, const size_t length, const bool flush,- const u8* buffer) const {+ResultVal<size_t> RomFS_Storage::Write(const u64 offset, const size_t length, const bool flush,+ const u8* buffer) const {LOG_ERROR(Service_FS, "Attempted to write to ROMFS file");// TODO(Subv): Find error codereturn MakeResult<size_t>(0);}-u64 ROMFSFile::GetSize() const {+u64 RomFS_Storage::GetSize() const {return data_size;}-bool ROMFSFile::SetSize(const u64 size) const {+bool RomFS_Storage::SetSize(const u64 size) const {LOG_ERROR(Service_FS, "Attempted to set the size of an ROMFS file");return false;}diff --git a/src/core/file_sys/romfs_archive.h b/src/core/file_sys/romfs_filesystem.hsimilarity index 80%rename from src/core/file_sys/romfs_archive.hrename to src/core/file_sys/romfs_filesystem.hindex 2b6c573bad..900ea567a0 100644--- a/src/core/file_sys/romfs_archive.h+++ b/src/core/file_sys/romfs_filesystem.h@@ -10,9 +10,9 @@#include <vector>#include "common/common_types.h"#include "common/file_util.h"-#include "core/file_sys/archive_backend.h"-#include "core/file_sys/directory_backend.h"-#include "core/file_sys/file_backend.h"+#include "core/file_sys/directory.h"+#include "core/file_sys/filesystem.h"+#include "core/file_sys/storage.h"#include "core/hle/result.h"namespace FileSys {@@ -22,15 +22,15 @@ namespace FileSys {* archives This should be subclassed by concrete archive types, which will provide the input data* (load the raw ROMFS archive) and override any required methods*/-class ROMFSArchive : public ArchiveBackend {+class RomFS_FileSystem : public FileSystemBackend {public:- ROMFSArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)+ RomFS_FileSystem(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size): romfs_file(file), data_offset(offset), data_size(size) {}std::string GetName() const override;- ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,- const Mode& mode) const override;+ ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const Path& path,+ const Mode& mode) const override;ResultCode DeleteFile(const Path& path) const override;ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;ResultCode DeleteDirectory(const Path& path) const override;@@ -47,9 +47,9 @@ protected:u64 data_size;};-class ROMFSFile : public FileBackend {+class RomFS_Storage : public StorageBackend {public:- ROMFSFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)+ RomFS_Storage(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size): romfs_file(file), data_offset(offset), data_size(size) {}ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/storage.hsimilarity index 86%rename from src/core/file_sys/file_backend.hrename to src/core/file_sys/storage.hindex 5e7c2bab48..2a68118310 100644--- a/src/core/file_sys/file_backend.h+++ b/src/core/file_sys/storage.h@@ -1,4 +1,4 @@-// Copyright 2014 Citra Emulator Project+// Copyright 2018 yuzu emulator team// Licensed under GPLv2 or any later version// Refer to the license.txt file included.@@ -8,15 +8,12 @@#include "common/common_types.h"#include "core/hle/result.h"-////////////////////////////////////////////////////////////////////////////////////////////////////-// FileSys namespace-namespace FileSys {-class FileBackend : NonCopyable {+class StorageBackend : NonCopyable {public:- FileBackend() {}- virtual ~FileBackend() {}+ StorageBackend() {}+ virtual ~StorageBackend() {}/*** Read data from the file@@ -39,10 +36,9 @@ public:const u8* buffer) const = 0;/**- * Get the size of the file in bytes- * @return Size of the file in bytes+ * Flushes the file*/- virtual u64 GetSize() const = 0;+ virtual void Flush() const = 0;/*** Set the size of the file in bytes@@ -52,15 +48,16 @@ public:virtual bool SetSize(u64 size) const = 0;/**- * Close the file- * @return true if the file closed correctly+ * Get the size of the file in bytes+ * @return Size of the file in bytes*/- virtual bool Close() const = 0;+ virtual u64 GetSize() const = 0;/**- * Flushes the file+ * Close the file+ * @return true if the file closed correctly*/- virtual void Flush() const = 0;+ virtual bool Close() const = 0;};} // namespace FileSys