From 82fe821e8734faab6cad29bc0377c2f630c1f876 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 15 Dec 2014 02:51:38 -0200 Subject: Service.FS: Rename FileSys::Archive to ArchiveBackend --- src/core/file_sys/archive_backend.h | 255 ++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 src/core/file_sys/archive_backend.h (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h new file mode 100644 index 000000000..0558698f6 --- /dev/null +++ b/src/core/file_sys/archive_backend.h @@ -0,0 +1,255 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "common/common_types.h" +#include "common/string_util.h" +#include "common/bit_field.h" + +#include "core/file_sys/file.h" +#include "core/file_sys/directory.h" + +#include "core/mem_map.h" +#include "core/hle/kernel/kernel.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// FileSys namespace + +namespace FileSys { + +// Path string type +enum LowPathType : u32 { + Invalid = 0, + Empty = 1, + Binary = 2, + Char = 3, + Wchar = 4 +}; + +union Mode { + u32 hex; + BitField<0, 1, u32> read_flag; + BitField<1, 1, u32> write_flag; + BitField<2, 1, u32> create_flag; +}; + +class Path { +public: + + Path(): + type(Invalid) + { + } + + Path(LowPathType type, u32 size, u32 pointer): + type(type) + { + switch (type) { + case Binary: + { + u8* data = Memory::GetPointer(pointer); + binary = std::vector(data, data + size); + break; + } + case Char: + { + const char* data = reinterpret_cast(Memory::GetPointer(pointer)); + string = std::string(data, size - 1); // Data is always null-terminated. + break; + } + case Wchar: + { + const char16_t* data = reinterpret_cast(Memory::GetPointer(pointer)); + u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. + break; + } + default: + break; + } + } + + LowPathType GetType() const { + return type; + } + + /** + * Gets the string representation of the path for debugging + * @return String representation of the path for debugging + */ + const std::string DebugStr() const { + switch (GetType()) { + case Invalid: + return "[Invalid]"; + case Empty: + return "[Empty]"; + case Binary: + { + std::stringstream res; + res << "[Binary: "; + for (unsigned byte : binary) + res << std::hex << std::setw(2) << std::setfill('0') << byte; + res << ']'; + return res.str(); + } + case Char: + return "[Char: " + AsString() + ']'; + case Wchar: + return "[Wchar: " + AsString() + ']'; + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); + return {}; + } + } + + const std::string AsString() const { + switch (GetType()) { + case Char: + return string; + case Wchar: + return Common::UTF16ToUTF8(u16str); + case Empty: + return {}; + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); + return {}; + } + } + + const std::u16string AsU16Str() const { + switch (GetType()) { + case Char: + return Common::UTF8ToUTF16(string); + case Wchar: + return u16str; + case Empty: + return {}; + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); + return {}; + } + } + + const std::vector AsBinary() const { + switch (GetType()) { + case Binary: + return binary; + case Char: + return std::vector(string.begin(), string.end()); + case Wchar: + return std::vector(u16str.begin(), u16str.end()); + case Empty: + return {}; + default: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); + return {}; + } + } + +private: + LowPathType type; + std::vector binary; + std::string string; + std::u16string u16str; +}; + +class ArchiveBackend : NonCopyable { +public: + virtual ~ArchiveBackend() { } + + /** + * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) + */ + virtual std::string GetName() const = 0; + + /** + * Open a file specified by its path, using the specified mode + * @param path Path relative to the archive + * @param mode Mode to open the file with + * @return Opened file, or nullptr + */ + virtual std::unique_ptr OpenFile(const Path& path, const Mode mode) const = 0; + + /** + * Delete a file specified by its path + * @param path Path relative to the archive + * @return Whether the file could be deleted + */ + virtual bool DeleteFile(const FileSys::Path& path) const = 0; + + /** + * Rename a File specified by its path + * @param src_path Source path relative to the archive + * @param dest_path Destination path relative to the archive + * @return Whether rename succeeded + */ + virtual bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; + + /** + * Delete a directory specified by its path + * @param path Path relative to the archive + * @return Whether the directory could be deleted + */ + virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; + + /** + * Create a directory specified by its path + * @param path Path relative to the archive + * @return Whether the directory could be created + */ + virtual bool CreateDirectory(const Path& path) const = 0; + + /** + * Rename a Directory specified by its path + * @param src_path Source path relative to the archive + * @param dest_path Destination path relative to the archive + * @return Whether rename succeeded + */ + virtual bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; + + /** + * Open a directory specified by its path + * @param path Path relative to the archive + * @return Opened directory, or nullptr + */ + virtual std::unique_ptr OpenDirectory(const Path& path) const = 0; + + /** + * Read data from the archive + * @param offset Offset in bytes to start reading data from + * @param length Length in bytes of data to read from archive + * @param buffer Buffer to read data into + * @return Number of bytes read + */ + virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; + + /** + * Write data to the archive + * @param offset Offset in bytes to start writing data to + * @param length Length in bytes of data to write to archive + * @param buffer Buffer to write data from + * @param flush The flush parameters (0 == do not flush) + * @return Number of bytes written + */ + virtual size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) = 0; + + /** + * Get the size of the archive in bytes + * @return Size of the archive in bytes + */ + virtual size_t GetSize() const = 0; + + /** + * Set the size of the archive in bytes + */ + virtual void SetSize(const u64 size) = 0; +}; + +} // namespace FileSys -- cgit v1.2.3 From d51afab0bc3a7e06a73f9f51afaf26cf83d87cd2 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 15 Dec 2014 04:59:29 -0200 Subject: Service.FS: Rename FileSys::Directory to DirectoryBackend --- src/core/file_sys/archive_backend.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 0558698f6..49a310383 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -11,7 +11,7 @@ #include "common/bit_field.h" #include "core/file_sys/file.h" -#include "core/file_sys/directory.h" +#include "core/file_sys/directory_backend.h" #include "core/mem_map.h" #include "core/hle/kernel/kernel.h" @@ -219,7 +219,7 @@ public: * @param path Path relative to the archive * @return Opened directory, or nullptr */ - virtual std::unique_ptr OpenDirectory(const Path& path) const = 0; + virtual std::unique_ptr OpenDirectory(const Path& path) const = 0; /** * Read data from the archive -- cgit v1.2.3 From 0931a42af0c0666dd9fbc20484b399c0e1ad3361 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 15 Dec 2014 05:03:17 -0200 Subject: Service.FS: Rename FileSys::File to FileBackend --- src/core/file_sys/archive_backend.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 49a310383..8d7a6a057 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -10,7 +10,7 @@ #include "common/string_util.h" #include "common/bit_field.h" -#include "core/file_sys/file.h" +#include "core/file_sys/file_backend.h" #include "core/file_sys/directory_backend.h" #include "core/mem_map.h" @@ -175,7 +175,7 @@ public: * @param mode Mode to open the file with * @return Opened file, or nullptr */ - virtual std::unique_ptr OpenFile(const Path& path, const Mode mode) const = 0; + virtual std::unique_ptr OpenFile(const Path& path, const Mode mode) const = 0; /** * Delete a file specified by its path -- cgit v1.2.3 From 83e6e4ffec9ca67fbca5536bb0ed7b4876ade0db Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 15 Dec 2014 06:41:02 -0200 Subject: FS.Archive: Clean up treatment of archives and their handles - Refactor FS::Archive internals to make Archive creation and lifetime management clearer. - Remove the "Archive as a File" hack. - Implement 64-bit Archive handles. --- src/core/file_sys/archive_backend.h | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 8d7a6a057..18c314884 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -220,36 +220,6 @@ public: * @return Opened directory, or nullptr */ virtual std::unique_ptr OpenDirectory(const Path& path) const = 0; - - /** - * Read data from the archive - * @param offset Offset in bytes to start reading data from - * @param length Length in bytes of data to read from archive - * @param buffer Buffer to read data into - * @return Number of bytes read - */ - virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; - - /** - * Write data to the archive - * @param offset Offset in bytes to start writing data to - * @param length Length in bytes of data to write to archive - * @param buffer Buffer to write data from - * @param flush The flush parameters (0 == do not flush) - * @return Number of bytes written - */ - virtual size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) = 0; - - /** - * Get the size of the archive in bytes - * @return Size of the archive in bytes - */ - virtual size_t GetSize() const = 0; - - /** - * Set the size of the archive in bytes - */ - virtual void SetSize(const u64 size) = 0; }; } // namespace FileSys -- cgit v1.2.3 From e7956926147d2d2ac6741aee8a150466a5438ca3 Mon Sep 17 00:00:00 2001 From: Chin Date: Fri, 19 Dec 2014 22:16:34 -0500 Subject: Clean up some warnings --- src/core/file_sys/archive_backend.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 18c314884..d7959b2ca 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -143,7 +143,16 @@ public: case Char: return std::vector(string.begin(), string.end()); case Wchar: - return std::vector(u16str.begin(), u16str.end()); + { + // use two u8 for each character of u16str + std::vector to_return(u16str.size() * 2); + for (size_t i = 0; i < u16str.size(); ++i) { + u16 tmp_char = u16str.at(i); + to_return[i*2] = (tmp_char & 0xFF00) >> 8; + to_return[i*2 + 1] = (tmp_char & 0x00FF); + } + return to_return; + } case Empty: return {}; default: -- cgit v1.2.3 From ebfd831ccba32bce097491db3d6bdff0be05935e Mon Sep 17 00:00:00 2001 From: purpasmart96 Date: Tue, 16 Dec 2014 21:38:14 -0800 Subject: License change --- src/core/file_sys/archive_backend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 18c314884..065b22e5d 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -1,5 +1,5 @@ // Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once -- cgit v1.2.3 From 0625dd09eaf9158696a9255cb6c6b2bd73122301 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 20 Dec 2014 12:43:50 -0300 Subject: Added CreateFile to the FS_USER service Tested with hwtests. --- src/core/file_sys/archive_backend.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 18c314884..1b510b695 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -199,6 +199,14 @@ public: */ virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; + /** + * Create a file specified by its path + * @param path Path relative to the Archive + * @param size The size of the new file, filled with zeroes + * @return File creation result code + */ + virtual ResultCode CreateFile(const Path& path, u32 size) const = 0; + /** * Create a directory specified by its path * @param path Path relative to the archive -- cgit v1.2.3 From fa3d72ab3e5ba8b3e8dccdb1d3bd9b976dbc28e2 Mon Sep 17 00:00:00 2001 From: Subv Date: Thu, 18 Dec 2014 23:35:24 -0500 Subject: CFG: Implemented the GetConfigInfoBlk2 function. Added a "config" file to the CFG process service (CFG:U), and added a few default blocks to it. Implemented GetSystemModel and GetModelNintendo2DS --- src/core/file_sys/archive_backend.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index eb1fdaa1f..e2979be17 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -45,6 +45,11 @@ public: { } + Path(const char* path): + type(Char), string(path) + { + } + Path(LowPathType type, u32 size, u32 pointer): type(type) { -- cgit v1.2.3 From bbe0bf133252c75ce2485aebc6eb5a7c497fe5ad Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 18 Dec 2014 14:06:37 +0000 Subject: FileSys: Clean up according to the coding style, and remove redundant namespaced names. --- src/core/file_sys/archive_backend.h | 152 ++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 78 deletions(-) (limited to 'src/core/file_sys/archive_backend.h') diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index e2979be17..e153917ea 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -40,40 +40,37 @@ union Mode { class Path { public: - Path(): - type(Invalid) - { + Path() : type(Invalid) { } - Path(const char* path): - type(Char), string(path) - { + Path(const char* path) : type(Char), string(path) { } - Path(LowPathType type, u32 size, u32 pointer): - type(type) - { + Path(LowPathType type, u32 size, u32 pointer) : type(type) { switch (type) { - case Binary: - { - u8* data = Memory::GetPointer(pointer); - binary = std::vector(data, data + size); - break; - } - case Char: - { - const char* data = reinterpret_cast(Memory::GetPointer(pointer)); - string = std::string(data, size - 1); // Data is always null-terminated. - break; - } - case Wchar: - { - const char16_t* data = reinterpret_cast(Memory::GetPointer(pointer)); - u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. - break; - } - default: - break; + case Binary: + { + u8* data = Memory::GetPointer(pointer); + binary = std::vector(data, data + size); + break; + } + + case Char: + { + const char* data = reinterpret_cast(Memory::GetPointer(pointer)); + string = std::string(data, size - 1); // Data is always null-terminated. + break; + } + + case Wchar: + { + const char16_t* data = reinterpret_cast(Memory::GetPointer(pointer)); + u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. + break; + } + + default: + break; } } @@ -104,66 +101,64 @@ public: return "[Char: " + AsString() + ']'; case Wchar: return "[Wchar: " + AsString() + ']'; - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); - return {}; } } const std::string AsString() const { switch (GetType()) { - case Char: - return string; - case Wchar: - return Common::UTF16ToUTF8(u16str); - case Empty: - return {}; - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); - return {}; + case Char: + return string; + case Wchar: + return Common::UTF16ToUTF8(u16str); + case Empty: + return {}; + case Invalid: + case Binary: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); + return {}; } } const std::u16string AsU16Str() const { switch (GetType()) { - case Char: - return Common::UTF8ToUTF16(string); - case Wchar: - return u16str; - case Empty: - return {}; - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); - return {}; + case Char: + return Common::UTF8ToUTF16(string); + case Wchar: + return u16str; + case Empty: + return {}; + case Invalid: + case Binary: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); + return {}; } } const std::vector AsBinary() const { switch (GetType()) { - case Binary: - return binary; - case Char: - return std::vector(string.begin(), string.end()); - case Wchar: - { - // use two u8 for each character of u16str - std::vector to_return(u16str.size() * 2); - for (size_t i = 0; i < u16str.size(); ++i) { - u16 tmp_char = u16str.at(i); - to_return[i*2] = (tmp_char & 0xFF00) >> 8; - to_return[i*2 + 1] = (tmp_char & 0x00FF); - } - return to_return; + case Binary: + return binary; + case Char: + return std::vector(string.begin(), string.end()); + case Wchar: + { + // use two u8 for each character of u16str + std::vector to_return(u16str.size() * 2); + for (size_t i = 0; i < u16str.size(); ++i) { + u16 tmp_char = u16str.at(i); + to_return[i*2] = (tmp_char & 0xFF00) >> 8; + to_return[i*2 + 1] = (tmp_char & 0x00FF); } - case Empty: - return {}; - default: - // TODO(yuriks): Add assert - LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); - return {}; + return to_return; + } + case Empty: + return {}; + case Invalid: + // TODO(yuriks): Add assert + LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); + return {}; } } @@ -176,7 +171,8 @@ private: class ArchiveBackend : NonCopyable { public: - virtual ~ArchiveBackend() { } + virtual ~ArchiveBackend() { + } /** * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) @@ -196,7 +192,7 @@ public: * @param path Path relative to the archive * @return Whether the file could be deleted */ - virtual bool DeleteFile(const FileSys::Path& path) const = 0; + virtual bool DeleteFile(const Path& path) const = 0; /** * Rename a File specified by its path @@ -204,14 +200,14 @@ public: * @param dest_path Destination path relative to the archive * @return Whether rename succeeded */ - virtual bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; + virtual bool RenameFile(const Path& src_path, const Path& dest_path) const = 0; /** * Delete a directory specified by its path * @param path Path relative to the archive * @return Whether the directory could be deleted */ - virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; + virtual bool DeleteDirectory(const Path& path) const = 0; /** * Create a file specified by its path @@ -234,7 +230,7 @@ public: * @param dest_path Destination path relative to the archive * @return Whether rename succeeded */ - virtual bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; + virtual bool RenameDirectory(const Path& src_path, const Path& dest_path) const = 0; /** * Open a directory specified by its path -- cgit v1.2.3