From a9ba2c2000d9f2e4c6018aa6fc1e754eca82f72c Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 19 Mar 2018 22:58:55 -0500 Subject: FS: Updated the Directory Entry structure to match the Switch. --- src/core/file_sys/disk_filesystem.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/disk_filesystem.h') diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h index 53767b949..29383dbf7 100644 --- a/src/core/file_sys/disk_filesystem.h +++ b/src/core/file_sys/disk_filesystem.h @@ -59,8 +59,26 @@ private: class Disk_Directory : public DirectoryBackend { public: - u32 Read(const u32 count, Entry* entries) override; - bool Close() const override; + Disk_Directory(const std::string& path); + + ~Disk_Directory() override { + Close(); + } + + u64 Read(const u64 count, Entry* entries) override; + u64 GetEntryCount() const override; + + bool Close() const override { + return true; + } + +protected: + u32 total_entries_in_directory; + FileUtil::FSTEntry directory; + + // We need to remember the last entry we returned, so a subsequent call to Read will continue + // from the next one. This iterator will always point to the next unread entry. + std::vector::iterator children_iterator; }; } // namespace FileSys -- cgit v1.2.3 From 6d90d99d12c6a1e7ec27831d93052a30c0e689b5 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 19 Mar 2018 23:00:37 -0500 Subject: FS: Implement DiskFileSystem's OpenDirectory interface. --- src/core/file_sys/disk_filesystem.cpp | 13 +++++++++++-- src/core/file_sys/disk_filesystem.h | 3 ++- src/core/file_sys/filesystem.h | 3 ++- src/core/file_sys/romfs_filesystem.cpp | 3 ++- src/core/file_sys/romfs_filesystem.h | 3 ++- 5 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/core/file_sys/disk_filesystem.h') diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index e02b20faf..f620b7961 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -108,8 +108,17 @@ ResultCode Disk_FileSystem::RenameDirectory(const Path& src_path, const Path& de } ResultVal> Disk_FileSystem::OpenDirectory( - const Path& path) const { - return MakeResult>(std::make_unique()); + const std::string& path) const { + + std::string full_path = base_directory + path; + + if (!FileUtil::IsDirectory(full_path)) { + // TODO(Subv): Find the correct error code for this. + return ResultCode(-1); + } + + auto directory = std::make_unique(full_path); + return MakeResult>(std::move(directory)); } u64 Disk_FileSystem::GetFreeSpaceSize() const { diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h index 29383dbf7..72a0afedf 100644 --- a/src/core/file_sys/disk_filesystem.h +++ b/src/core/file_sys/disk_filesystem.h @@ -32,7 +32,8 @@ public: ResultCode CreateFile(const std::string& path, u64 size) const override; ResultCode CreateDirectory(const Path& path) const override; ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; - ResultVal> OpenDirectory(const Path& path) const override; + ResultVal> OpenDirectory( + const std::string& path) const override; u64 GetFreeSpaceSize() const override; ResultVal GetEntryType(const std::string& path) const override; diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h index 5c91a46c2..22ad24143 100644 --- a/src/core/file_sys/filesystem.h +++ b/src/core/file_sys/filesystem.h @@ -150,7 +150,8 @@ public: * @param path Path relative to the archive * @return Opened directory, or error code */ - virtual ResultVal> OpenDirectory(const Path& path) const = 0; + virtual ResultVal> OpenDirectory( + const std::string& path) const = 0; /** * Get the free space diff --git a/src/core/file_sys/romfs_filesystem.cpp b/src/core/file_sys/romfs_filesystem.cpp index f1f9b4d04..169f0d4f6 100644 --- a/src/core/file_sys/romfs_filesystem.cpp +++ b/src/core/file_sys/romfs_filesystem.cpp @@ -70,7 +70,8 @@ ResultCode RomFS_FileSystem::RenameDirectory(const Path& src_path, const Path& d } ResultVal> RomFS_FileSystem::OpenDirectory( - const Path& path) const { + const std::string& path) const { + LOG_WARNING(Service_FS, "Opening Directory in a ROMFS archive"); return MakeResult>(std::make_unique()); } diff --git a/src/core/file_sys/romfs_filesystem.h b/src/core/file_sys/romfs_filesystem.h index be52f20ef..ee41c2d02 100644 --- a/src/core/file_sys/romfs_filesystem.h +++ b/src/core/file_sys/romfs_filesystem.h @@ -38,7 +38,8 @@ public: ResultCode CreateFile(const std::string& path, u64 size) const override; ResultCode CreateDirectory(const Path& path) const override; ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; - ResultVal> OpenDirectory(const Path& path) const override; + ResultVal> OpenDirectory( + const std::string& path) const override; u64 GetFreeSpaceSize() const override; ResultVal GetEntryType(const std::string& path) const override; -- cgit v1.2.3 From eff3f60b73343365ad65638f55591965df6f7e25 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 21 Mar 2018 09:36:26 -0500 Subject: FS: Implemented IFileSystem::CreateDirectory. --- src/core/file_sys/disk_filesystem.cpp | 13 ++++++++++--- src/core/file_sys/disk_filesystem.h | 2 +- src/core/file_sys/filesystem.h | 2 +- src/core/file_sys/romfs_filesystem.cpp | 2 +- src/core/file_sys/romfs_filesystem.h | 2 +- src/core/hle/service/filesystem/fsp_srv.cpp | 15 +++++++++++++++ 6 files changed, 29 insertions(+), 7 deletions(-) (limited to 'src/core/file_sys/disk_filesystem.h') diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index f620b7961..9383bf856 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -18,7 +18,7 @@ std::string Disk_FileSystem::GetName() const { ResultVal> Disk_FileSystem::OpenFile(const std::string& path, Mode mode) const { - std::string mode_str = ""; + std::string mode_str; u32 mode_flags = static_cast(mode); // Calculate the correct open mode for the file. @@ -95,8 +95,15 @@ ResultCode Disk_FileSystem::CreateFile(const std::string& path, u64 size) const return ResultCode(-1); } -ResultCode Disk_FileSystem::CreateDirectory(const Path& path) const { - LOG_WARNING(Service_FS, "(STUBBED) called"); +ResultCode Disk_FileSystem::CreateDirectory(const std::string& path) const { + // TODO(Subv): Perform path validation to prevent escaping the emulator sandbox. + std::string full_path = base_directory + path; + + if (FileUtil::CreateDir(full_path)) { + return RESULT_SUCCESS; + } + + LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating %s", full_path.c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h index 72a0afedf..742d7db1a 100644 --- a/src/core/file_sys/disk_filesystem.h +++ b/src/core/file_sys/disk_filesystem.h @@ -30,7 +30,7 @@ public: ResultCode DeleteDirectory(const Path& path) const override; ResultCode DeleteDirectoryRecursively(const Path& path) const override; ResultCode CreateFile(const std::string& path, u64 size) const override; - ResultCode CreateDirectory(const Path& path) const override; + ResultCode CreateDirectory(const std::string& path) const override; ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; ResultVal> OpenDirectory( const std::string& path) const override; diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h index 22ad24143..399427ca2 100644 --- a/src/core/file_sys/filesystem.h +++ b/src/core/file_sys/filesystem.h @@ -104,7 +104,7 @@ public: * @param path Path relative to the archive * @return Result of the operation */ - virtual ResultCode CreateDirectory(const Path& path) const = 0; + virtual ResultCode CreateDirectory(const std::string& path) const = 0; /** * Delete a directory specified by its path diff --git a/src/core/file_sys/romfs_filesystem.cpp b/src/core/file_sys/romfs_filesystem.cpp index 169f0d4f6..0c6cc3157 100644 --- a/src/core/file_sys/romfs_filesystem.cpp +++ b/src/core/file_sys/romfs_filesystem.cpp @@ -55,7 +55,7 @@ ResultCode RomFS_FileSystem::CreateFile(const std::string& path, u64 size) const return ResultCode(-1); } -ResultCode RomFS_FileSystem::CreateDirectory(const Path& path) const { +ResultCode RomFS_FileSystem::CreateDirectory(const std::string& path) const { LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code diff --git a/src/core/file_sys/romfs_filesystem.h b/src/core/file_sys/romfs_filesystem.h index ee41c2d02..3f94c04d0 100644 --- a/src/core/file_sys/romfs_filesystem.h +++ b/src/core/file_sys/romfs_filesystem.h @@ -36,7 +36,7 @@ public: ResultCode DeleteDirectory(const Path& path) const override; ResultCode DeleteDirectoryRecursively(const Path& path) const override; ResultCode CreateFile(const std::string& path, u64 size) const override; - ResultCode CreateDirectory(const Path& path) const override; + ResultCode CreateDirectory(const std::string& path) const override; ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; ResultVal> OpenDirectory( const std::string& path) const override; diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 6f539316e..cbb7552d9 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -208,6 +208,7 @@ public: : ServiceFramework("IFileSystem"), backend(std::move(backend)) { static const FunctionInfo functions[] = { {0, &IFileSystem::CreateFile, "CreateFile"}, + {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, {7, &IFileSystem::GetEntryType, "GetEntryType"}, {8, &IFileSystem::OpenFile, "OpenFile"}, {9, &IFileSystem::OpenDirectory, "OpenDirectory"}, @@ -234,6 +235,20 @@ public: rb.Push(backend->CreateFile(name, size)); } + void CreateDirectory(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + auto file_buffer = ctx.ReadBuffer(); + auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0'); + + std::string name(file_buffer.begin(), end); + + LOG_DEBUG(Service_FS, "called directory %s", name.c_str()); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(backend->CreateDirectory(name)); + } + void OpenFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; -- cgit v1.2.3