diff options
| author | 2014-09-12 00:44:16 +0200 | |
|---|---|---|
| committer | 2014-09-17 14:35:45 +0000 | |
| commit | e73caaefe58503f7d1d79a08e71bf66b5fe6edba (patch) | |
| tree | fda0ffc5bc226d2cefc3dfa376f4ac78a7666bfb /src/core | |
| parent | Core: Add a new File class, obtainable from an Archive, and a stub implementa... (diff) | |
| download | yuzu-e73caaefe58503f7d1d79a08e71bf66b5fe6edba.tar.gz yuzu-e73caaefe58503f7d1d79a08e71bf66b5fe6edba.tar.xz yuzu-e73caaefe58503f7d1d79a08e71bf66b5fe6edba.zip | |
Core: Add a passthrough backend for the filesystem, exposed as SDMC.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 96 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.h | 79 | ||||
| -rw-r--r-- | src/core/file_sys/file_sdmc.cpp | 63 | ||||
| -rw-r--r-- | src/core/file_sys/file_sdmc.h | 60 |
5 files changed, 302 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 14c114b63..46e11d779 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -23,7 +23,9 @@ set(SRCS | |||
| 23 | arm/interpreter/armvirt.cpp | 23 | arm/interpreter/armvirt.cpp |
| 24 | arm/interpreter/thumbemu.cpp | 24 | arm/interpreter/thumbemu.cpp |
| 25 | file_sys/archive_romfs.cpp | 25 | file_sys/archive_romfs.cpp |
| 26 | file_sys/archive_sdmc.cpp | ||
| 26 | file_sys/file_romfs.cpp | 27 | file_sys/file_romfs.cpp |
| 28 | file_sys/file_sdmc.cpp | ||
| 27 | hle/kernel/address_arbiter.cpp | 29 | hle/kernel/address_arbiter.cpp |
| 28 | hle/kernel/archive.cpp | 30 | hle/kernel/archive.cpp |
| 29 | hle/kernel/event.cpp | 31 | hle/kernel/event.cpp |
| @@ -78,8 +80,10 @@ set(HEADERS | |||
| 78 | arm/arm_interface.h | 80 | arm/arm_interface.h |
| 79 | file_sys/archive.h | 81 | file_sys/archive.h |
| 80 | file_sys/archive_romfs.h | 82 | file_sys/archive_romfs.h |
| 83 | file_sys/archive_sdmc.h | ||
| 81 | file_sys/file.h | 84 | file_sys/file.h |
| 82 | file_sys/file_romfs.h | 85 | file_sys/file_romfs.h |
| 86 | file_sys/file_sdmc.h | ||
| 83 | hle/kernel/address_arbiter.h | 87 | hle/kernel/address_arbiter.h |
| 84 | hle/kernel/archive.h | 88 | hle/kernel/archive.h |
| 85 | hle/kernel/event.h | 89 | hle/kernel/event.h |
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp new file mode 100644 index 000000000..fb155430d --- /dev/null +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | |||
| 10 | #include "core/file_sys/archive_sdmc.h" | ||
| 11 | #include "core/file_sys/file_sdmc.h" | ||
| 12 | |||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // FileSys namespace | ||
| 15 | |||
| 16 | namespace FileSys { | ||
| 17 | |||
| 18 | Archive_SDMC::Archive_SDMC(const std::string& mount_point) { | ||
| 19 | this->mount_point = mount_point; | ||
| 20 | DEBUG_LOG(FILESYS, "Directory %s set as SDMC.", mount_point.c_str()); | ||
| 21 | } | ||
| 22 | |||
| 23 | Archive_SDMC::~Archive_SDMC() { | ||
| 24 | } | ||
| 25 | |||
| 26 | bool Archive_SDMC::Initialize() { | ||
| 27 | if (!FileUtil::IsDirectory(mount_point)) { | ||
| 28 | WARN_LOG(FILESYS, "Directory %s not found, disabling SDMC.", mount_point.c_str()); | ||
| 29 | return false; | ||
| 30 | } | ||
| 31 | |||
| 32 | return true; | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Open a file specified by its path, using the specified mode | ||
| 37 | * @param path Path relative to the archive | ||
| 38 | * @param mode Mode to open the file with | ||
| 39 | * @return Opened file, or nullptr | ||
| 40 | */ | ||
| 41 | std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const { | ||
| 42 | DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode); | ||
| 43 | File_SDMC* file = new File_SDMC(this, path, mode); | ||
| 44 | return std::unique_ptr<File>(file); | ||
| 45 | } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Read data from the archive | ||
| 49 | * @param offset Offset in bytes to start reading archive from | ||
| 50 | * @param length Length in bytes to read data from archive | ||
| 51 | * @param buffer Buffer to read data into | ||
| 52 | * @return Number of bytes read | ||
| 53 | */ | ||
| 54 | size_t Archive_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const { | ||
| 55 | ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); | ||
| 56 | return -1; | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Write data to the archive | ||
| 61 | * @param offset Offset in bytes to start writing data to | ||
| 62 | * @param length Length in bytes of data to write to archive | ||
| 63 | * @param buffer Buffer to write data from | ||
| 64 | * @param flush The flush parameters (0 == do not flush) | ||
| 65 | * @return Number of bytes written | ||
| 66 | */ | ||
| 67 | size_t Archive_SDMC::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) { | ||
| 68 | ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Get the size of the archive in bytes | ||
| 74 | * @return Size of the archive in bytes | ||
| 75 | */ | ||
| 76 | size_t Archive_SDMC::GetSize() const { | ||
| 77 | ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Set the size of the archive in bytes | ||
| 83 | */ | ||
| 84 | void Archive_SDMC::SetSize(const u64 size) { | ||
| 85 | ERROR_LOG(FILESYS, "(UNIMPLEMENTED)"); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Getter for the path used for this Archive | ||
| 90 | * @return Mount point of that passthrough archive | ||
| 91 | */ | ||
| 92 | std::string Archive_SDMC::GetMountPoint() const { | ||
| 93 | return mount_point; | ||
| 94 | } | ||
| 95 | |||
| 96 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h new file mode 100644 index 000000000..931817e5b --- /dev/null +++ b/src/core/file_sys/archive_sdmc.h | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | #include "core/file_sys/archive.h" | ||
| 10 | #include "core/loader/loader.h" | ||
| 11 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 13 | // FileSys namespace | ||
| 14 | |||
| 15 | namespace FileSys { | ||
| 16 | |||
| 17 | /// File system interface to the SDMC archive | ||
| 18 | class Archive_SDMC final : public Archive { | ||
| 19 | public: | ||
| 20 | Archive_SDMC(const std::string& mount_point); | ||
| 21 | ~Archive_SDMC() override; | ||
| 22 | |||
| 23 | bool Initialize(); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | ||
| 27 | * @return IdCode of the archive | ||
| 28 | */ | ||
| 29 | IdCode GetIdCode() const override { return IdCode::SDMC; }; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Open a file specified by its path, using the specified mode | ||
| 33 | * @param path Path relative to the archive | ||
| 34 | * @param mode Mode to open the file with | ||
| 35 | * @return Opened file, or nullptr | ||
| 36 | */ | ||
| 37 | std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Read data from the archive | ||
| 41 | * @param offset Offset in bytes to start reading archive from | ||
| 42 | * @param length Length in bytes to read data from archive | ||
| 43 | * @param buffer Buffer to read data into | ||
| 44 | * @return Number of bytes read | ||
| 45 | */ | ||
| 46 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Write data to the archive | ||
| 50 | * @param offset Offset in bytes to start writing data to | ||
| 51 | * @param length Length in bytes of data to write to archive | ||
| 52 | * @param buffer Buffer to write data from | ||
| 53 | * @param flush The flush parameters (0 == do not flush) | ||
| 54 | * @return Number of bytes written | ||
| 55 | */ | ||
| 56 | size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override; | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Get the size of the archive in bytes | ||
| 60 | * @return Size of the archive in bytes | ||
| 61 | */ | ||
| 62 | size_t GetSize() const override; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Set the size of the archive in bytes | ||
| 66 | */ | ||
| 67 | void SetSize(const u64 size) override; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Getter for the path used for this Archive | ||
| 71 | * @return Mount point of that passthrough archive | ||
| 72 | */ | ||
| 73 | std::string GetMountPoint() const; | ||
| 74 | |||
| 75 | private: | ||
| 76 | std::string mount_point; | ||
| 77 | }; | ||
| 78 | |||
| 79 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp new file mode 100644 index 000000000..76adc6403 --- /dev/null +++ b/src/core/file_sys/file_sdmc.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | |||
| 10 | #include "core/file_sys/file_sdmc.h" | ||
| 11 | #include "core/file_sys/archive_sdmc.h" | ||
| 12 | |||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // FileSys namespace | ||
| 15 | |||
| 16 | namespace FileSys { | ||
| 17 | |||
| 18 | File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode) { | ||
| 19 | // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass | ||
| 20 | // the root directory we set while opening the archive. | ||
| 21 | // For example, opening /../../etc/passwd can give the emulated program your users list. | ||
| 22 | std::string real_path = archive->GetMountPoint() + path; | ||
| 23 | |||
| 24 | if (!mode.create_flag && !FileUtil::Exists(real_path)) { | ||
| 25 | file = nullptr; | ||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | std::string mode_string; | ||
| 30 | if (mode.read_flag) | ||
| 31 | mode_string += "r"; | ||
| 32 | if (mode.write_flag) | ||
| 33 | mode_string += "w"; | ||
| 34 | |||
| 35 | file = new FileUtil::IOFile(real_path, mode_string.c_str()); | ||
| 36 | } | ||
| 37 | |||
| 38 | File_SDMC::~File_SDMC() { | ||
| 39 | Close(); | ||
| 40 | } | ||
| 41 | |||
| 42 | size_t File_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const { | ||
| 43 | file->Seek(offset, SEEK_SET); | ||
| 44 | return file->ReadBytes(buffer, length); | ||
| 45 | } | ||
| 46 | |||
| 47 | size_t File_SDMC::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { | ||
| 48 | file->Seek(offset, SEEK_SET); | ||
| 49 | size_t written = file->WriteBytes(buffer, length); | ||
| 50 | if (flush) | ||
| 51 | file->Flush(); | ||
| 52 | return written; | ||
| 53 | } | ||
| 54 | |||
| 55 | size_t File_SDMC::GetSize() const { | ||
| 56 | return file->GetSize(); | ||
| 57 | } | ||
| 58 | |||
| 59 | bool File_SDMC::Close() const { | ||
| 60 | return file->Close(); | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h new file mode 100644 index 000000000..b2e46f449 --- /dev/null +++ b/src/core/file_sys/file_sdmc.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | |||
| 10 | #include "core/file_sys/file.h" | ||
| 11 | #include "core/file_sys/archive_sdmc.h" | ||
| 12 | #include "core/loader/loader.h" | ||
| 13 | |||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | // FileSys namespace | ||
| 16 | |||
| 17 | namespace FileSys { | ||
| 18 | |||
| 19 | class File_SDMC final : public File { | ||
| 20 | public: | ||
| 21 | File_SDMC(); | ||
| 22 | File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode); | ||
| 23 | ~File_SDMC() override; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Read data from the file | ||
| 27 | * @param offset Offset in bytes to start reading data from | ||
| 28 | * @param length Length in bytes of data to read from file | ||
| 29 | * @param buffer Buffer to read data into | ||
| 30 | * @return Number of bytes read | ||
| 31 | */ | ||
| 32 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Write data to the file | ||
| 36 | * @param offset Offset in bytes to start writing data to | ||
| 37 | * @param length Length in bytes of data to write to file | ||
| 38 | * @param buffer Buffer to write data from | ||
| 39 | * @param flush The flush parameters (0 == do not flush) | ||
| 40 | * @return Number of bytes written | ||
| 41 | */ | ||
| 42 | size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * Get the size of the file in bytes | ||
| 46 | * @return Size of the file in bytes | ||
| 47 | */ | ||
| 48 | size_t GetSize() const override; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Close the file | ||
| 52 | * @return true if the file closed correctly | ||
| 53 | */ | ||
| 54 | bool Close() const override; | ||
| 55 | |||
| 56 | private: | ||
| 57 | FileUtil::IOFile* file; | ||
| 58 | }; | ||
| 59 | |||
| 60 | } // namespace FileSys | ||