diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/archive.h | 14 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 20 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 14 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 18 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.h | 14 | ||||
| -rw-r--r-- | src/core/hle/kernel/archive.cpp | 32 | ||||
| -rw-r--r-- | src/core/hle/kernel/archive.h | 16 | ||||
| -rw-r--r-- | src/core/hle/service/fs_user.cpp | 92 |
8 files changed, 194 insertions, 26 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h index 1135d8804..2e79bb883 100644 --- a/src/core/file_sys/archive.h +++ b/src/core/file_sys/archive.h | |||
| @@ -185,6 +185,20 @@ public: | |||
| 185 | virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0; | 185 | virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0; |
| 186 | 186 | ||
| 187 | /** | 187 | /** |
| 188 | * Delete a file specified by its path | ||
| 189 | * @param path Path relative to the archive | ||
| 190 | * @return Whether the file could be deleted | ||
| 191 | */ | ||
| 192 | virtual bool DeleteFile(const FileSys::Path& path) const = 0; | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Delete a directory specified by its path | ||
| 196 | * @param path Path relative to the archive | ||
| 197 | * @return Whether the directory could be deleted | ||
| 198 | */ | ||
| 199 | virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; | ||
| 200 | |||
| 201 | /** | ||
| 188 | * Create a directory specified by its path | 202 | * Create a directory specified by its path |
| 189 | * @param path Path relative to the archive | 203 | * @param path Path relative to the archive |
| 190 | * @return Whether the directory could be created | 204 | * @return Whether the directory could be created |
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 551913a42..53dc57954 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -34,6 +34,26 @@ std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * Delete a file specified by its path | ||
| 38 | * @param path Path relative to the archive | ||
| 39 | * @return Whether the file could be deleted | ||
| 40 | */ | ||
| 41 | bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const { | ||
| 42 | ERROR_LOG(FILESYS, "Attempted to delete a file from ROMFS."); | ||
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Delete a directory specified by its path | ||
| 48 | * @param path Path relative to the archive | ||
| 49 | * @return Whether the directory could be deleted | ||
| 50 | */ | ||
| 51 | bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const { | ||
| 52 | ERROR_LOG(FILESYS, "Attempted to delete a directory from ROMFS."); | ||
| 53 | return false; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 37 | * Create a directory specified by its path | 57 | * Create a directory specified by its path |
| 38 | * @param path Path relative to the archive | 58 | * @param path Path relative to the archive |
| 39 | * @return Whether the directory could be created | 59 | * @return Whether the directory could be created |
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index f05327f51..0649dde99 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -37,6 +37,20 @@ public: | |||
| 37 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; | 37 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | * Delete a file specified by its path | ||
| 41 | * @param path Path relative to the archive | ||
| 42 | * @return Whether the file could be deleted | ||
| 43 | */ | ||
| 44 | bool DeleteFile(const FileSys::Path& path) const override; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Delete a directory specified by its path | ||
| 48 | * @param path Path relative to the archive | ||
| 49 | * @return Whether the directory could be deleted | ||
| 50 | */ | ||
| 51 | bool DeleteDirectory(const FileSys::Path& path) const override; | ||
| 52 | |||
| 53 | /** | ||
| 40 | * Create a directory specified by its path | 54 | * Create a directory specified by its path |
| 41 | * @param path Path relative to the archive | 55 | * @param path Path relative to the archive |
| 42 | * @return Whether the directory could be created | 56 | * @return Whether the directory could be created |
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index ecdb7f211..c2ffcd40d 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -58,6 +58,24 @@ std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /** | 60 | /** |
| 61 | * Delete a file specified by its path | ||
| 62 | * @param path Path relative to the archive | ||
| 63 | * @return Whether the file could be deleted | ||
| 64 | */ | ||
| 65 | bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const { | ||
| 66 | return FileUtil::Delete(GetMountPoint() + path.AsString()); | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Delete a directory specified by its path | ||
| 71 | * @param path Path relative to the archive | ||
| 72 | * @return Whether the directory could be deleted | ||
| 73 | */ | ||
| 74 | bool Archive_SDMC::DeleteDirectory(const FileSys::Path& path) const { | ||
| 75 | return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 61 | * Create a directory specified by its path | 79 | * Create a directory specified by its path |
| 62 | * @param path Path relative to the archive | 80 | * @param path Path relative to the archive |
| 63 | * @return Whether the directory could be created | 81 | * @return Whether the directory could be created |
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 17b9209b4..74ce29c0d 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h | |||
| @@ -41,6 +41,20 @@ public: | |||
| 41 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; | 41 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; |
| 42 | 42 | ||
| 43 | /** | 43 | /** |
| 44 | * Delete a file specified by its path | ||
| 45 | * @param path Path relative to the archive | ||
| 46 | * @return Whether the file could be deleted | ||
| 47 | */ | ||
| 48 | bool DeleteFile(const FileSys::Path& path) const override; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Delete a directory specified by its path | ||
| 52 | * @param path Path relative to the archive | ||
| 53 | * @return Whether the directory could be deleted | ||
| 54 | */ | ||
| 55 | bool DeleteDirectory(const FileSys::Path& path) const override; | ||
| 56 | |||
| 57 | /** | ||
| 44 | * Create a directory specified by its path | 58 | * Create a directory specified by its path |
| 45 | * @param path Path relative to the archive | 59 | * @param path Path relative to the archive |
| 46 | * @return Whether the directory could be created | 60 | * @return Whether the directory could be created |
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp index d9ee4682a..900f484c7 100644 --- a/src/core/hle/kernel/archive.cpp +++ b/src/core/hle/kernel/archive.cpp | |||
| @@ -392,10 +392,40 @@ Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, con | |||
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | /** | 394 | /** |
| 395 | * Delete a File from an Archive | ||
| 396 | * @param archive_handle Handle to an open Archive object | ||
| 397 | * @param path Path to the File inside of the Archive | ||
| 398 | * @return Whether deletion succeeded | ||
| 399 | */ | ||
| 400 | Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) { | ||
| 401 | Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); | ||
| 402 | if (archive == nullptr) | ||
| 403 | return -1; | ||
| 404 | if (archive->backend->DeleteFile(path)) | ||
| 405 | return 0; | ||
| 406 | return -1; | ||
| 407 | } | ||
| 408 | |||
| 409 | /** | ||
| 410 | * Delete a Directory from an Archive | ||
| 411 | * @param archive_handle Handle to an open Archive object | ||
| 412 | * @param path Path to the Directory inside of the Archive | ||
| 413 | * @return Whether deletion succeeded | ||
| 414 | */ | ||
| 415 | Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) { | ||
| 416 | Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); | ||
| 417 | if (archive == nullptr) | ||
| 418 | return -1; | ||
| 419 | if (archive->backend->DeleteDirectory(path)) | ||
| 420 | return 0; | ||
| 421 | return -1; | ||
| 422 | } | ||
| 423 | |||
| 424 | /** | ||
| 395 | * Create a Directory from an Archive | 425 | * Create a Directory from an Archive |
| 396 | * @param archive_handle Handle to an open Archive object | 426 | * @param archive_handle Handle to an open Archive object |
| 397 | * @param path Path to the Directory inside of the Archive | 427 | * @param path Path to the Directory inside of the Archive |
| 398 | * @return Opened Directory object | 428 | * @return Whether creation succeeded |
| 399 | */ | 429 | */ |
| 400 | Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) { | 430 | Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) { |
| 401 | Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); | 431 | Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); |
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h index 9c6015506..95b3c6656 100644 --- a/src/core/hle/kernel/archive.h +++ b/src/core/hle/kernel/archive.h | |||
| @@ -46,6 +46,22 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name); | |||
| 46 | Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode); | 46 | Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode); |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * Delete a File from an Archive | ||
| 50 | * @param archive_handle Handle to an open Archive object | ||
| 51 | * @param path Path to the File inside of the Archive | ||
| 52 | * @return Whether deletion succeeded | ||
| 53 | */ | ||
| 54 | Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Delete a Directory from an Archive | ||
| 58 | * @param archive_handle Handle to an open Archive object | ||
| 59 | * @param path Path to the Directory inside of the Archive | ||
| 60 | * @return Whether deletion succeeded | ||
| 61 | */ | ||
| 62 | Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path); | ||
| 63 | |||
| 64 | /** | ||
| 49 | * Create a Directory from an Archive | 65 | * Create a Directory from an Archive |
| 50 | * @param archive_handle Handle to an open Archive object | 66 | * @param archive_handle Handle to an open Archive object |
| 51 | * @param path Path to the Directory inside of the Archive | 67 | * @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 dadc89ef8..2aec1a52a 100644 --- a/src/core/hle/service/fs_user.cpp +++ b/src/core/hle/service/fs_user.cpp | |||
| @@ -138,6 +138,68 @@ static void OpenFileDirectly(Service::Interface* self) { | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | /* | 140 | /* |
| 141 | * FS_User::DeleteFile service function | ||
| 142 | * Inputs: | ||
| 143 | * 2 : Archive handle lower word | ||
| 144 | * 3 : Archive handle upper word | ||
| 145 | * 4 : File path string type | ||
| 146 | * 5 : File path string size | ||
| 147 | * 7 : File path string data | ||
| 148 | * Outputs: | ||
| 149 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 150 | */ | ||
| 151 | void DeleteFile(Service::Interface* self) { | ||
| 152 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 153 | |||
| 154 | // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to | ||
| 155 | // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. | ||
| 156 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); | ||
| 157 | auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); | ||
| 158 | u32 filename_size = cmd_buff[5]; | ||
| 159 | u32 filename_ptr = cmd_buff[7]; | ||
| 160 | |||
| 161 | FileSys::Path file_path(filename_type, filename_size, filename_ptr); | ||
| 162 | |||
| 163 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", | ||
| 164 | filename_type, filename_size, file_path.DebugStr().c_str()); | ||
| 165 | |||
| 166 | cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path); | ||
| 167 | |||
| 168 | DEBUG_LOG(KERNEL, "called"); | ||
| 169 | } | ||
| 170 | |||
| 171 | /* | ||
| 172 | * FS_User::DeleteDirectory service function | ||
| 173 | * Inputs: | ||
| 174 | * 2 : Archive handle lower word | ||
| 175 | * 3 : Archive handle upper word | ||
| 176 | * 4 : Directory path string type | ||
| 177 | * 5 : Directory path string size | ||
| 178 | * 7 : Directory path string data | ||
| 179 | * Outputs: | ||
| 180 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 181 | */ | ||
| 182 | void DeleteDirectory(Service::Interface* self) { | ||
| 183 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 184 | |||
| 185 | // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to | ||
| 186 | // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. | ||
| 187 | Handle archive_handle = static_cast<Handle>(cmd_buff[3]); | ||
| 188 | auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); | ||
| 189 | u32 dirname_size = cmd_buff[5]; | ||
| 190 | u32 dirname_ptr = cmd_buff[7]; | ||
| 191 | |||
| 192 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); | ||
| 193 | |||
| 194 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", | ||
| 195 | dirname_type, dirname_size, dir_path.DebugStr().c_str()); | ||
| 196 | |||
| 197 | cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path); | ||
| 198 | |||
| 199 | DEBUG_LOG(KERNEL, "called"); | ||
| 200 | } | ||
| 201 | |||
| 202 | /* | ||
| 141 | * FS_User::CreateDirectory service function | 203 | * FS_User::CreateDirectory service function |
| 142 | * Inputs: | 204 | * Inputs: |
| 143 | * 2 : Archive handle lower word | 205 | * 2 : Archive handle lower word |
| @@ -159,18 +221,8 @@ static void CreateDirectory(Service::Interface* self) { | |||
| 159 | u32 dirname_ptr = cmd_buff[8]; | 221 | u32 dirname_ptr = cmd_buff[8]; |
| 160 | 222 | ||
| 161 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); | 223 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); |
| 162 | std::string dir_string; | ||
| 163 | switch (dir_path.GetType()) { | ||
| 164 | case FileSys::Char: | ||
| 165 | case FileSys::Wchar: | ||
| 166 | dir_string = dir_path.AsString(); | ||
| 167 | break; | ||
| 168 | default: | ||
| 169 | cmd_buff[1] = -1; | ||
| 170 | return; | ||
| 171 | } | ||
| 172 | 224 | ||
| 173 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); | 225 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str()); |
| 174 | 226 | ||
| 175 | cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path); | 227 | cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path); |
| 176 | 228 | ||
| @@ -188,25 +240,15 @@ static void OpenDirectory(Service::Interface* self) { | |||
| 188 | u32 dirname_ptr = cmd_buff[6]; | 240 | u32 dirname_ptr = cmd_buff[6]; |
| 189 | 241 | ||
| 190 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); | 242 | FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr); |
| 191 | std::string dir_string; | ||
| 192 | switch (dir_path.GetType()) { | ||
| 193 | case FileSys::Char: | ||
| 194 | case FileSys::Wchar: | ||
| 195 | dir_string = dir_path.AsString(); | ||
| 196 | break; | ||
| 197 | default: | ||
| 198 | cmd_buff[1] = -1; | ||
| 199 | return; | ||
| 200 | } | ||
| 201 | 243 | ||
| 202 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); | 244 | DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str()); |
| 203 | 245 | ||
| 204 | Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path); | 246 | Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path); |
| 205 | if (handle) { | 247 | if (handle) { |
| 206 | cmd_buff[1] = 0; | 248 | cmd_buff[1] = 0; |
| 207 | cmd_buff[3] = handle; | 249 | cmd_buff[3] = handle; |
| 208 | } else { | 250 | } else { |
| 209 | ERROR_LOG(KERNEL, "failed to get a handle for directory %s", dir_string.c_str()); | 251 | ERROR_LOG(KERNEL, "failed to get a handle for directory"); |
| 210 | // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. | 252 | // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. |
| 211 | cmd_buff[1] = -1; | 253 | cmd_buff[1] = -1; |
| 212 | } | 254 | } |
| @@ -279,9 +321,9 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 279 | {0x08010002, Initialize, "Initialize"}, | 321 | {0x08010002, Initialize, "Initialize"}, |
| 280 | {0x080201C2, OpenFile, "OpenFile"}, | 322 | {0x080201C2, OpenFile, "OpenFile"}, |
| 281 | {0x08030204, OpenFileDirectly, "OpenFileDirectly"}, | 323 | {0x08030204, OpenFileDirectly, "OpenFileDirectly"}, |
| 282 | {0x08040142, nullptr, "DeleteFile"}, | 324 | {0x08040142, DeleteFile, "DeleteFile"}, |
| 283 | {0x08050244, nullptr, "RenameFile"}, | 325 | {0x08050244, nullptr, "RenameFile"}, |
| 284 | {0x08060142, nullptr, "DeleteDirectory"}, | 326 | {0x08060142, DeleteDirectory, "DeleteDirectory"}, |
| 285 | {0x08070142, nullptr, "DeleteDirectoryRecursively"}, | 327 | {0x08070142, nullptr, "DeleteDirectoryRecursively"}, |
| 286 | {0x08080202, nullptr, "CreateFile"}, | 328 | {0x08080202, nullptr, "CreateFile"}, |
| 287 | {0x08090182, CreateDirectory, "CreateDirectory"}, | 329 | {0x08090182, CreateDirectory, "CreateDirectory"}, |