file_sys: Cleanup to better match Switch file system constructs.

file_sys: Add factory class for RomFS file system.
This commit is contained in:
bunnei 2018-01-19 22:34:48 -05:00
parent 1c06c918af
commit 00851a5ef4
10 changed files with 136 additions and 63 deletions

View File

@ -6,15 +6,17 @@ add_library(core STATIC
core.h core.h
core_timing.cpp core_timing.cpp
core_timing.h core_timing.h
file_sys/archive_backend.cpp file_sys/directory.h
file_sys/archive_backend.h
file_sys/directory_backend.h
file_sys/errors.h file_sys/errors.h
file_sys/file_backend.h file_sys/filesystem.cpp
file_sys/filesystem.h
file_sys/path_parser.cpp file_sys/path_parser.cpp
file_sys/path_parser.h file_sys/path_parser.h
file_sys/romfs_archive.cpp file_sys/romfs_factory.cpp
file_sys/romfs_archive.h file_sys/romfs_factory.h
file_sys/romfs_filesystem.cpp
file_sys/romfs_filesystem.h
file_sys/storage.h
frontend/emu_window.cpp frontend/emu_window.cpp
frontend/emu_window.h frontend/emu_window.h
frontend/framebuffer_layout.cpp frontend/framebuffer_layout.cpp

View File

@ -1,4 +1,4 @@
// Copyright 2014 Citra Emulator Project // Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.

View File

@ -1,4 +1,4 @@
// Copyright 2015 Citra Emulator Project // Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -7,7 +7,7 @@
#include <sstream> #include <sstream>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/filesystem.h"
#include "core/memory.h" #include "core/memory.h"
namespace FileSys { namespace FileSys {

View File

@ -1,4 +1,4 @@
// Copyright 2014 Citra Emulator Project // Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -15,7 +15,7 @@
namespace FileSys { namespace FileSys {
class FileBackend; class StorageBackend;
class DirectoryBackend; class DirectoryBackend;
// Path string type // Path string type
@ -71,9 +71,9 @@ struct ArchiveFormatInfo {
}; };
static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD");
class ArchiveBackend : NonCopyable { class FileSystemBackend : NonCopyable {
public: public:
virtual ~ArchiveBackend() {} virtual ~FileSystemBackend() {}
/** /**
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) * 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 * @param mode Mode to open the file with
* @return Opened file, or error code * @return Opened file, or error code
*/ */
virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, virtual ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const Path& path,
const Mode& mode) const = 0; const Mode& mode) const = 0;
/** /**
* Open a directory specified by its path * Open a directory specified by its path
@ -155,9 +155,9 @@ public:
virtual u64 GetFreeSpaceSize() const = 0; virtual u64 GetFreeSpaceSize() const = 0;
}; };
class ArchiveFactory : NonCopyable { class FileSystemFactory : NonCopyable {
public: public:
virtual ~ArchiveFactory() {} virtual ~FileSystemFactory() {}
/** /**
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
@ -169,7 +169,7 @@ public:
* @param path Path to the archive * @param path Path to the archive
* @return An ArchiveBackend corresponding operating specified archive path. * @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 folder * Deletes the archive contents and then re-creates the base folder

View File

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "core/file_sys/archive_backend.h" #include "core/file_sys/filesystem.h"
namespace FileSys { namespace FileSys {

View File

@ -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 FileSys

View File

@ -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 FileSys

View File

@ -6,79 +6,79 @@
#include <memory> #include <memory>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/romfs_archive.h" #include "core/file_sys/romfs_filesystem.h"
namespace FileSys { namespace FileSys {
std::string ROMFSArchive::GetName() const { std::string RomFS_FileSystem::GetName() const {
return "RomFS"; return "RomFS";
} }
ResultVal<std::unique_ptr<FileBackend>> ROMFSArchive::OpenFile(const Path& path, ResultVal<std::unique_ptr<StorageBackend>> RomFS_FileSystem::OpenFile(const Path& path,
const Mode& mode) const { const Mode& mode) const {
return MakeResult<std::unique_ptr<FileBackend>>( return MakeResult<std::unique_ptr<StorageBackend>>(
std::make_unique<ROMFSFile>(romfs_file, data_offset, data_size)); 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).", LOG_CRITICAL(Service_FS, "Attempted to delete a file from an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(bunnei): Use correct error code // TODO(bunnei): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(wwylele): Use correct error code // TODO(wwylele): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(wwylele): Use correct error code // TODO(wwylele): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(wwylele): Use correct error code // TODO(wwylele): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to create a file in an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(bunnei): Use correct error code // TODO(bunnei): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(wwylele): Use correct error code // TODO(wwylele): Use correct error code
return ResultCode(-1); return 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).", LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).",
GetName().c_str()); GetName().c_str());
// TODO(wwylele): Use correct error code // TODO(wwylele): Use correct error code
return ResultCode(-1); return 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>()); 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"); LOG_WARNING(Service_FS, "Attempted to get the free space in an ROMFS archive");
return 0; 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); LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
romfs_file->Seek(data_offset + offset, SEEK_SET); romfs_file->Seek(data_offset + offset, SEEK_SET);
size_t read_length = (size_t)std::min((u64)length, data_size - offset); 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* buf
return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length)); return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
} }
ResultVal<size_t> ROMFSFile::Write(const u64 offset, const size_t length, const bool flush, ResultVal<size_t> RomFS_Storage::Write(const u64 offset, const size_t length, const bool flush,
const u8* buffer) const { const u8* buffer) const {
LOG_ERROR(Service_FS, "Attempted to write to ROMFS file"); LOG_ERROR(Service_FS, "Attempted to write to ROMFS file");
// TODO(Subv): Find error code // TODO(Subv): Find error code
return MakeResult<size_t>(0); return MakeResult<size_t>(0);
} }
u64 ROMFSFile::GetSize() const { u64 RomFS_Storage::GetSize() const {
return data_size; 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"); LOG_ERROR(Service_FS, "Attempted to set the size of an ROMFS file");
return false; return false;
} }

View File

@ -10,9 +10,9 @@
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/directory.h"
#include "core/file_sys/directory_backend.h" #include "core/file_sys/filesystem.h"
#include "core/file_sys/file_backend.h" #include "core/file_sys/storage.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace FileSys { namespace FileSys {
@ -22,15 +22,15 @@ namespace FileSys {
* archives This should be subclassed by concrete archive types, which will provide the input data * 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 * (load the raw ROMFS archive) and override any required methods
*/ */
class ROMFSArchive : public ArchiveBackend { class RomFS_FileSystem : public FileSystemBackend {
public: 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) {} : romfs_file(file), data_offset(offset), data_size(size) {}
std::string GetName() const override; std::string GetName() const override;
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const Path& path,
const Mode& mode) const override; const Mode& mode) const override;
ResultCode DeleteFile(const Path& path) const override; ResultCode DeleteFile(const Path& path) const override;
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
ResultCode DeleteDirectory(const Path& path) const override; ResultCode DeleteDirectory(const Path& path) const override;
@ -47,9 +47,9 @@ protected:
u64 data_size; u64 data_size;
}; };
class ROMFSFile : public FileBackend { class RomFS_Storage : public StorageBackend {
public: 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) {} : romfs_file(file), data_offset(offset), data_size(size) {}
ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;

View File

@ -1,4 +1,4 @@
// Copyright 2014 Citra Emulator Project // Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -8,15 +8,12 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/result.h" #include "core/hle/result.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace
namespace FileSys { namespace FileSys {
class FileBackend : NonCopyable { class StorageBackend : NonCopyable {
public: public:
FileBackend() {} StorageBackend() {}
virtual ~FileBackend() {} virtual ~StorageBackend() {}
/** /**
* Read data from the file * Read data from the file
@ -39,10 +36,9 @@ public:
const u8* buffer) const = 0; const u8* buffer) const = 0;
/** /**
* Get the size of the file in bytes * Flushes the file
* @return Size of the file in bytes
*/ */
virtual u64 GetSize() const = 0; virtual void Flush() const = 0;
/** /**
* Set the size of the file in bytes * Set the size of the file in bytes
@ -51,16 +47,17 @@ public:
*/ */
virtual bool SetSize(u64 size) const = 0; virtual bool SetSize(u64 size) const = 0;
/**
* Get the size of the file in bytes
* @return Size of the file in bytes
*/
virtual u64 GetSize() const = 0;
/** /**
* Close the file * Close the file
* @return true if the file closed correctly * @return true if the file closed correctly
*/ */
virtual bool Close() const = 0; virtual bool Close() const = 0;
/**
* Flushes the file
*/
virtual void Flush() const = 0;
}; };
} // namespace FileSys } // namespace FileSys