diff options
| -rw-r--r-- | src/core/file_sys/archive.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 11 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 10 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.h | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/archive.cpp | 24 | ||||
| -rw-r--r-- | src/core/hle/kernel/archive.h | 11 | ||||
| -rw-r--r-- | src/core/hle/service/fs_user.cpp | 44 |
8 files changed, 123 insertions, 1 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h index 2e79bb883..703742a1f 100644 --- a/src/core/file_sys/archive.h +++ b/src/core/file_sys/archive.h | |||
| @@ -192,6 +192,14 @@ public: | |||
| 192 | virtual bool DeleteFile(const FileSys::Path& path) const = 0; | 192 | virtual bool DeleteFile(const FileSys::Path& path) const = 0; |
| 193 | 193 | ||
| 194 | /** | 194 | /** |
| 195 | * Rename a File specified by its path | ||
| 196 | * @param src_path Source path relative to the archive | ||
| 197 | * @param dest_path Destination path relative to the archive | ||
| 198 | * @return Whether rename succeeded | ||
| 199 | */ | ||
| 200 | virtual bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; | ||
| 201 | |||
| 202 | /** | ||
| 195 | * Delete a directory specified by its path | 203 | * Delete a directory specified by its path |
| 196 | * @param path Path relative to the archive | 204 | * @param path Path relative to the archive |
| 197 | * @return Whether the directory could be deleted | 205 | * @return Whether the directory could be deleted |
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 53dc57954..5594c5910 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -44,6 +44,17 @@ bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const { | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * Rename a File specified by its path | ||
| 48 | * @param src_path Source path relative to the archive | ||
| 49 | * @param dest_path Destination path relative to the archive | ||
| 50 | * @return Whether rename succeeded | ||
| 51 | */ | ||
| 52 | bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { | ||
| 53 | ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS."); | ||
| 54 | return false; | ||
| 55 | } | ||
| 56 | |||
| 57 | /** | ||
| 47 | * Delete a directory specified by its path | 58 | * Delete a directory specified by its path |
| 48 | * @param path Path relative to the archive | 59 | * @param path Path relative to the archive |
| 49 | * @return Whether the directory could be deleted | 60 | * @return Whether the directory could be deleted |
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index 0649dde99..d14372a01 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -44,6 +44,14 @@ public: | |||
| 44 | bool DeleteFile(const FileSys::Path& path) const override; | 44 | bool DeleteFile(const FileSys::Path& path) const override; |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * Rename a File specified by its path | ||
| 48 | * @param src_path Source path relative to the archive | ||
| 49 | * @param dest_path Destination path relative to the archive | ||
| 50 | * @return Whether rename succeeded | ||
| 51 | */ | ||
| 52 | bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; | ||
| 53 | |||
| 54 | /** | ||
| 47 | * Delete a directory specified by its path | 55 | * Delete a directory specified by its path |
| 48 | * @param path Path relative to the archive | 56 | * @param path Path relative to the archive |
| 49 | * @return Whether the directory could be deleted | 57 | * @return Whether the directory could be deleted |
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index c2ffcd40d..24bc43a02 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -67,6 +67,16 @@ bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const { | |||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| 70 | * Rename a File specified by its path | ||
| 71 | * @param src_path Source path relative to the archive | ||
| 72 | * @param dest_path Destination path relative to the archive | ||
| 73 | * @return Whether rename succeeded | ||
| 74 | */ | ||
| 75 | bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { | ||
| 76 | return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString()); | ||
| 77 | } | ||
| 78 | |||
| 79 | /** | ||
| 70 | * Delete a directory specified by its path | 80 | * Delete a directory specified by its path |
| 71 | * @param path Path relative to the archive | 81 | * @param path Path relative to the archive |
| 72 | * @return Whether the directory could be deleted | 82 | * @return Whether the directory could be deleted |
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 74ce29c0d..0dbed987b 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h | |||
| @@ -48,6 +48,14 @@ public: | |||
| 48 | bool DeleteFile(const FileSys::Path& path) const override; | 48 | bool DeleteFile(const FileSys::Path& path) const override; |
| 49 | 49 | ||
| 50 | /** | 50 | /** |
| 51 | * Rename a File specified by its path | ||
| 52 | * @param src_path Source path relative to the archive | ||
| 53 | * @param dest_path Destination path relative to the archive | ||
| 54 | * @return Whether rename succeeded | ||
| 55 | */ | ||
| 56 | bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; | ||
| 57 | |||
| 58 | /** | ||
| 51 | * Delete a directory specified by its path | 59 | * Delete a directory specified by its path |
| 52 | * @param path Path relative to the archive | 60 | * @param path Path relative to the archive |
| 53 | * @return Whether the directory could be deleted | 61 | * @return Whether the directory could be deleted |
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp index e273444c9..0bf31ea2f 100644 --- a/src/core/hle/kernel/archive.cpp +++ b/src/core/hle/kernel/archive.cpp | |||
| @@ -356,6 +356,30 @@ Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) { | |||
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | /** | 358 | /** |
| 359 | * Rename a File between two Archives | ||
| 360 | * @param src_archive_handle Handle to the source Archive object | ||
| 361 | * @param src_path Path to the File inside of the source Archive | ||
| 362 | * @param dest_archive_handle Handle to the destination Archive object | ||
| 363 | * @param dest_path Path to the File inside of the destination Archive | ||
| 364 | * @return Whether rename succeeded | ||
| 365 | */ | ||
| 366 | Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path, | ||
| 367 | Handle dest_archive_handle, const FileSys::Path& dest_path) { | ||
| 368 | Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle); | ||
| 369 | Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle); | ||
| 370 | if (src_archive == nullptr || dest_archive == nullptr) | ||
| 371 | return -1; | ||
| 372 | if (src_archive == dest_archive) { | ||
| 373 | if (src_archive->backend->RenameFile(src_path, dest_path)) | ||
| 374 | return 0; | ||
| 375 | } else { | ||
| 376 | // TODO: Implement renaming across archives | ||
| 377 | return -1; | ||
| 378 | } | ||
| 379 | return -1; | ||
| 380 | } | ||
| 381 | |||
| 382 | /** | ||
| 359 | * Delete a Directory from an Archive | 383 | * Delete a Directory from an Archive |
| 360 | * @param archive_handle Handle to an open Archive object | 384 | * @param archive_handle Handle to an open Archive object |
| 361 | * @param path Path to the Directory inside of the Archive | 385 | * @param path Path to the Directory inside of the Archive |
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h index 6fc4f0f25..5158fbae8 100644 --- a/src/core/hle/kernel/archive.h +++ b/src/core/hle/kernel/archive.h | |||
| @@ -53,6 +53,17 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path | |||
| 53 | Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path); | 53 | Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path); |
| 54 | 54 | ||
| 55 | /** | 55 | /** |
| 56 | * Rename a File between two Archives | ||
| 57 | * @param src_archive_handle Handle to the source Archive object | ||
| 58 | * @param src_path Path to the File inside of the source Archive | ||
| 59 | * @param dest_archive_handle Handle to the destination Archive object | ||
| 60 | * @param dest_path Path to the File inside of the destination Archive | ||
| 61 | * @return Whether rename succeeded | ||
| 62 | */ | ||
| 63 | Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path, | ||
| 64 | Handle dest_archive_handle, const FileSys::Path& dest_path); | ||
| 65 | |||
| 66 | /** | ||
| 56 | * Delete a Directory from an Archive | 67 | * Delete a Directory from an Archive |
| 57 | * @param archive_handle Handle to an open Archive object | 68 | * @param archive_handle Handle to an open Archive object |
| 58 | * @param path Path to the Directory inside of the Archive | 69 | * @param path Path to the Directory inside of the Archive |
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp index 435be5b5d..e9756e2eb 100644 --- a/src/core/hle/service/fs_user.cpp +++ b/src/core/hle/service/fs_user.cpp | |||
| @@ -165,6 +165,48 @@ void DeleteFile(Service::Interface* self) { | |||
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | /* | 167 | /* |
| 168 | * FS_User::RenameFile service function | ||
| 169 | * Inputs: | ||
| 170 | * 2 : Source archive handle lower word | ||
| 171 | * 3 : Source archive handle upper word | ||
| 172 | * 4 : Source file path type | ||
| 173 | * 5 : Source file path size | ||
| 174 | * 6 : Dest archive handle lower word | ||
| 175 | * 7 : Dest archive handle upper word | ||
| 176 | * 8 : Dest file path type | ||
| 177 | * 9 : Dest file path size | ||
| 178 | * 11: Source file path string data | ||
| 179 | * 13: Dest file path string | ||
| 180 | * Outputs: | ||
| 181 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 182 | */ | ||
| 183 | void RenameFile(Service::Interface* self) { | ||
| 184 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 185 | |||
| 186 | // TODO(Link Mauve): cmd_buff[2] and cmd_buff[6], aka archive handle lower word, aren't used according to | ||
| 187 | // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. | ||
| 188 | Handle src_archive_handle = static_cast<Handle>(cmd_buff[3]); | ||
| 189 | auto src_filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); | ||
| 190 | u32 src_filename_size = cmd_buff[5]; | ||
| 191 | Handle dest_archive_handle = static_cast<Handle>(cmd_buff[7]); | ||
| 192 | auto dest_filename_type = static_cast<FileSys::LowPathType>(cmd_buff[8]); | ||
| 193 | u32 dest_filename_size = cmd_buff[9]; | ||
| 194 | u32 src_filename_ptr = cmd_buff[11]; | ||
| 195 | u32 dest_filename_ptr = cmd_buff[13]; | ||
| 196 | |||
| 197 | FileSys::Path src_file_path(src_filename_type, src_filename_size, src_filename_ptr); | ||
| 198 | FileSys::Path dest_file_path(dest_filename_type, dest_filename_size, dest_filename_ptr); | ||
| 199 | |||
| 200 | DEBUG_LOG(KERNEL, "src_type=%d src_size=%d src_data=%s dest_type=%d dest_size=%d dest_data=%s", | ||
| 201 | src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(), | ||
| 202 | dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str()); | ||
| 203 | |||
| 204 | cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path); | ||
| 205 | |||
| 206 | DEBUG_LOG(KERNEL, "called"); | ||
| 207 | } | ||
| 208 | |||
| 209 | /* | ||
| 168 | * FS_User::DeleteDirectory service function | 210 | * FS_User::DeleteDirectory service function |
| 169 | * Inputs: | 211 | * Inputs: |
| 170 | * 2 : Archive handle lower word | 212 | * 2 : Archive handle lower word |
| @@ -314,7 +356,7 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 314 | {0x080201C2, OpenFile, "OpenFile"}, | 356 | {0x080201C2, OpenFile, "OpenFile"}, |
| 315 | {0x08030204, OpenFileDirectly, "OpenFileDirectly"}, | 357 | {0x08030204, OpenFileDirectly, "OpenFileDirectly"}, |
| 316 | {0x08040142, DeleteFile, "DeleteFile"}, | 358 | {0x08040142, DeleteFile, "DeleteFile"}, |
| 317 | {0x08050244, nullptr, "RenameFile"}, | 359 | {0x08050244, RenameFile, "RenameFile"}, |
| 318 | {0x08060142, DeleteDirectory, "DeleteDirectory"}, | 360 | {0x08060142, DeleteDirectory, "DeleteDirectory"}, |
| 319 | {0x08070142, nullptr, "DeleteDirectoryRecursively"}, | 361 | {0x08070142, nullptr, "DeleteDirectoryRecursively"}, |
| 320 | {0x08080202, nullptr, "CreateFile"}, | 362 | {0x08080202, nullptr, "CreateFile"}, |