From 45afc15aa6b9b1798a321bc053171deb765d7681 Mon Sep 17 00:00:00 2001
From: archshift <admin@archshift.com>
Date: Sun, 23 Nov 2014 23:20:04 -0800
Subject: [PATCH 1/3] Implemented RenameFile in FS:USER

---
 src/core/file_sys/archive.h         |  8 ++++++
 src/core/file_sys/archive_romfs.cpp | 11 ++++++++
 src/core/file_sys/archive_romfs.h   |  8 ++++++
 src/core/file_sys/archive_sdmc.cpp  | 10 +++++++
 src/core/file_sys/archive_sdmc.h    |  8 ++++++
 src/core/hle/kernel/archive.cpp     | 24 ++++++++++++++++
 src/core/hle/kernel/archive.h       | 11 ++++++++
 src/core/hle/service/fs_user.cpp    | 44 ++++++++++++++++++++++++++++-
 8 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index 2e79bb8839..703742a1f1 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -191,6 +191,14 @@ public:
      */
     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
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 53dc579545..5594c59105 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -43,6 +43,17 @@ bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
     return false;
 }
 
+/**
+ * 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
+ */
+bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
+    ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
+    return false;
+}
+
 /**
  * Delete a directory specified by its path
  * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 0649dde995..d14372a011 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -43,6 +43,14 @@ public:
      */
     bool DeleteFile(const FileSys::Path& path) const override;
 
+    /**
+     * 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
+     */
+    bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
+
     /**
      * Delete a directory specified by its path
      * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index c2ffcd40d2..24bc43a025 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -66,6 +66,16 @@ bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const {
     return FileUtil::Delete(GetMountPoint() + path.AsString());
 }
 
+/**
+ * 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
+ */
+bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
+    return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
+}
+
 /**
  * Delete a directory specified by its path
  * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 74ce29c0d0..0dbed987b0 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -47,6 +47,14 @@ public:
      */
     bool DeleteFile(const FileSys::Path& path) const override;
 
+    /**
+     * 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
+     */
+    bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
+
     /**
      * Delete a directory specified by its path
      * @param path Path relative to the archive
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index e273444c98..0bf31ea2f5 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -355,6 +355,30 @@ Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
     return -1;
 }
 
+/**
+ * Rename a File between two Archives
+ * @param src_archive_handle Handle to the source Archive object
+ * @param src_path Path to the File inside of the source Archive
+ * @param dest_archive_handle Handle to the destination Archive object
+ * @param dest_path Path to the File inside of the destination Archive
+ * @return Whether rename succeeded
+ */
+Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                 Handle dest_archive_handle, const FileSys::Path& dest_path) {
+    Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
+    Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
+    if (src_archive == nullptr || dest_archive == nullptr)
+        return -1;
+    if (src_archive == dest_archive) {
+        if (src_archive->backend->RenameFile(src_path, dest_path))
+            return 0;
+    } else {
+        // TODO: Implement renaming across archives
+        return -1;
+    }
+    return -1;
+}
+
 /**
  * Delete a Directory from an Archive
  * @param archive_handle Handle to an open Archive object
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
index 6fc4f0f256..5158fbae8c 100644
--- a/src/core/hle/kernel/archive.h
+++ b/src/core/hle/kernel/archive.h
@@ -52,6 +52,17 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
  */
 Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
 
+/**
+ * Rename a File between two Archives
+ * @param src_archive_handle Handle to the source Archive object
+ * @param src_path Path to the File inside of the source Archive
+ * @param dest_archive_handle Handle to the destination Archive object
+ * @param dest_path Path to the File inside of the destination Archive
+ * @return Whether rename succeeded
+ */
+Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                 Handle dest_archive_handle, const FileSys::Path& dest_path);
+
 /**
  * Delete a Directory from an Archive
  * @param archive_handle Handle to an open Archive object
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 435be5b5dd..e9756e2eb3 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -164,6 +164,48 @@ void DeleteFile(Service::Interface* self) {
     DEBUG_LOG(KERNEL, "called");
 }
 
+/*
+ * FS_User::RenameFile service function
+ *  Inputs:
+ *      2 : Source archive handle lower word
+ *      3 : Source archive handle upper word
+ *      4 : Source file path type
+ *      5 : Source file path size
+ *      6 : Dest archive handle lower word
+ *      7 : Dest archive handle upper word
+ *      8 : Dest file path type
+ *      9 : Dest file path size
+ *      11: Source file path string data
+ *      13: Dest file path string
+ *  Outputs:
+ *      1 : Result of function, 0 on success, otherwise error code
+ */
+void RenameFile(Service::Interface* self) {
+    u32* cmd_buff = Service::GetCommandBuffer();
+
+    // TODO(Link Mauve): cmd_buff[2] and cmd_buff[6], aka archive handle lower word, aren't used according to
+    // 3dmoo's or ctrulib's implementations.  Triple check if it's really the case.
+    Handle src_archive_handle  = static_cast<Handle>(cmd_buff[3]);
+    auto src_filename_type     = static_cast<FileSys::LowPathType>(cmd_buff[4]);
+    u32 src_filename_size      = cmd_buff[5];
+    Handle dest_archive_handle = static_cast<Handle>(cmd_buff[7]);
+    auto dest_filename_type    = static_cast<FileSys::LowPathType>(cmd_buff[8]);
+    u32 dest_filename_size     = cmd_buff[9];
+    u32 src_filename_ptr       = cmd_buff[11];
+    u32 dest_filename_ptr      = cmd_buff[13];
+
+    FileSys::Path src_file_path(src_filename_type, src_filename_size, src_filename_ptr);
+    FileSys::Path dest_file_path(dest_filename_type, dest_filename_size, dest_filename_ptr);
+
+    DEBUG_LOG(KERNEL, "src_type=%d src_size=%d src_data=%s dest_type=%d dest_size=%d dest_data=%s",
+              src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(),
+              dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str());
+
+    cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path);
+    
+    DEBUG_LOG(KERNEL, "called");
+}
+
 /*
  * FS_User::DeleteDirectory service function
  *  Inputs:
@@ -314,7 +356,7 @@ const Interface::FunctionInfo FunctionTable[] = {
     {0x080201C2, OpenFile,              "OpenFile"},
     {0x08030204, OpenFileDirectly,      "OpenFileDirectly"},
     {0x08040142, DeleteFile,            "DeleteFile"},
-    {0x08050244, nullptr,               "RenameFile"},
+    {0x08050244, RenameFile,            "RenameFile"},
     {0x08060142, DeleteDirectory,       "DeleteDirectory"},
     {0x08070142, nullptr,               "DeleteDirectoryRecursively"},
     {0x08080202, nullptr,               "CreateFile"},

From e5ff01c2cde0fe903140f0215461a68d4f489132 Mon Sep 17 00:00:00 2001
From: archshift <admin@archshift.com>
Date: Mon, 24 Nov 2014 01:12:58 -0800
Subject: [PATCH 2/3] Implemented RenameDirectory in FS:USER

---
 src/core/file_sys/archive.h         |  8 ++++++
 src/core/file_sys/archive_romfs.cpp | 11 ++++++++
 src/core/file_sys/archive_romfs.h   |  8 ++++++
 src/core/file_sys/archive_sdmc.cpp  | 10 +++++++
 src/core/file_sys/archive_sdmc.h    |  8 ++++++
 src/core/hle/kernel/archive.cpp     | 24 ++++++++++++++++
 src/core/hle/kernel/archive.h       | 11 ++++++++
 src/core/hle/service/fs_user.cpp    | 44 ++++++++++++++++++++++++++++-
 8 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index 703742a1f1..5ea75361e1 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -213,6 +213,14 @@ public:
      */
     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
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 5594c59105..d0ca7d3803 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -74,6 +74,17 @@ bool Archive_RomFS::CreateDirectory(const Path& path) const {
     return false;
 }
 
+/**
+ * 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
+ */
+bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
+    ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
+    return false;
+}
+
 /**
  * Open a directory specified by its path
  * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index d14372a011..222bdc3567 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -65,6 +65,14 @@ public:
      */
     bool CreateDirectory(const Path& path) const override;
 
+    /**
+     * 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
+     */
+    bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
+
     /**
      * Open a directory specified by its path
      * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 24bc43a025..c8958a0ebc 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -94,6 +94,16 @@ bool Archive_SDMC::CreateDirectory(const Path& path) const {
     return FileUtil::CreateDir(GetMountPoint() + path.AsString());
 }
 
+/**
+ * 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
+ */
+bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
+    return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
+}
+
 /**
  * Open a directory specified by its path
  * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 0dbed987b0..19f563a628 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -69,6 +69,14 @@ public:
      */
     bool CreateDirectory(const Path& path) const override;
 
+    /**
+     * 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
+     */
+    bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
+
     /**
      * Open a directory specified by its path
      * @param path Path relative to the archive
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 0bf31ea2f5..bffe599528 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -409,6 +409,30 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
     return -1;
 }
 
+/**
+ * Rename a Directory between two Archives
+ * @param src_archive_handle Handle to the source Archive object
+ * @param src_path Path to the Directory inside of the source Archive
+ * @param dest_archive_handle Handle to the destination Archive object
+ * @param dest_path Path to the Directory inside of the destination Archive
+ * @return Whether rename succeeded
+ */
+Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                      Handle dest_archive_handle, const FileSys::Path& dest_path) {
+    Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
+    Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
+    if (src_archive == nullptr || dest_archive == nullptr)
+        return -1;
+    if (src_archive == dest_archive) {
+        if (src_archive->backend->RenameDirectory(src_path, dest_path))
+            return 0;
+    } else {
+        // TODO: Implement renaming across archives
+        return -1;
+    }
+    return -1;
+}
+
 /**
  * Open a Directory from an Archive
  * @param archive_handle Handle to an open Archive object
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
index 5158fbae8c..9d071d3157 100644
--- a/src/core/hle/kernel/archive.h
+++ b/src/core/hle/kernel/archive.h
@@ -79,6 +79,17 @@ Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
  */
 Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
 
+/**
+ * Rename a Directory between two Archives
+ * @param src_archive_handle Handle to the source Archive object
+ * @param src_path Path to the Directory inside of the source Archive
+ * @param dest_archive_handle Handle to the destination Archive object
+ * @param dest_path Path to the Directory inside of the destination Archive
+ * @return Whether rename succeeded
+ */
+Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                      Handle dest_archive_handle, const FileSys::Path& dest_path);
+
 /**
  * Open a Directory from an Archive
  * @param archive_handle Handle to an open Archive object
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index e9756e2eb3..f4b1a879cc 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -267,6 +267,48 @@ static void CreateDirectory(Service::Interface* self) {
     DEBUG_LOG(KERNEL, "called");
 }
 
+/*
+ * FS_User::RenameDirectory service function
+ *  Inputs:
+ *      2 : Source archive handle lower word
+ *      3 : Source archive handle upper word
+ *      4 : Source dir path type
+ *      5 : Source dir path size
+ *      6 : Dest archive handle lower word
+ *      7 : Dest archive handle upper word
+ *      8 : Dest dir path type
+ *      9 : Dest dir path size
+ *      11: Source dir path string data
+ *      13: Dest dir path string
+ *  Outputs:
+ *      1 : Result of function, 0 on success, otherwise error code
+ */
+void RenameDirectory(Service::Interface* self) {
+    u32* cmd_buff = Service::GetCommandBuffer();
+
+    // TODO(Link Mauve): cmd_buff[2] and cmd_buff[6], aka archive handle lower word, aren't used according to
+    // 3dmoo's or ctrulib's implementations.  Triple check if it's really the case.
+    Handle src_archive_handle  = static_cast<Handle>(cmd_buff[3]);
+    auto src_dirname_type      = static_cast<FileSys::LowPathType>(cmd_buff[4]);
+    u32 src_dirname_size       = cmd_buff[5];
+    Handle dest_archive_handle = static_cast<Handle>(cmd_buff[7]);
+    auto dest_dirname_type     = static_cast<FileSys::LowPathType>(cmd_buff[8]);
+    u32 dest_dirname_size      = cmd_buff[9];
+    u32 src_dirname_ptr        = cmd_buff[11];
+    u32 dest_dirname_ptr       = cmd_buff[13];
+
+    FileSys::Path src_dir_path(src_dirname_type, src_dirname_size, src_dirname_ptr);
+    FileSys::Path dest_dir_path(dest_dirname_type, dest_dirname_size, dest_dirname_ptr);
+
+    DEBUG_LOG(KERNEL, "src_type=%d src_size=%d src_data=%s dest_type=%d dest_size=%d dest_data=%s",
+              src_dirname_type, src_dirname_size, src_dir_path.DebugStr().c_str(),
+              dest_dirname_type, dest_dirname_size, dest_dir_path.DebugStr().c_str());
+
+    cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path);
+    
+    DEBUG_LOG(KERNEL, "called");
+}
+
 static void OpenDirectory(Service::Interface* self) {
     u32* cmd_buff = Service::GetCommandBuffer();
 
@@ -361,7 +403,7 @@ const Interface::FunctionInfo FunctionTable[] = {
     {0x08070142, nullptr,               "DeleteDirectoryRecursively"},
     {0x08080202, nullptr,               "CreateFile"},
     {0x08090182, CreateDirectory,       "CreateDirectory"},
-    {0x080A0244, nullptr,               "RenameDirectory"},
+    {0x080A0244, RenameDirectory,       "RenameDirectory"},
     {0x080B0102, OpenDirectory,         "OpenDirectory"},
     {0x080C00C2, OpenArchive,           "OpenArchive"},
     {0x080D0144, nullptr,               "ControlArchive"},

From 139a4d91d9e8482d8ceeef591b08ab20b0f7e8ee Mon Sep 17 00:00:00 2001
From: archshift <admin@archshift.com>
Date: Mon, 24 Nov 2014 15:45:20 -0800
Subject: [PATCH 3/3] Updated archive.cpp functions for proper error handling

---
 src/core/file_sys/archive_romfs.cpp | 12 ----
 src/core/file_sys/archive_sdmc.cpp  | 12 ----
 src/core/hle/kernel/archive.cpp     | 87 ++++++++++-------------------
 src/core/hle/kernel/archive.h       | 14 ++---
 src/core/hle/service/fs_user.cpp    | 10 ++--
 5 files changed, 41 insertions(+), 94 deletions(-)

diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index d0ca7d3803..8c2dbeda54 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -43,12 +43,6 @@ bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
     return false;
 }
 
-/**
- * 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
- */
 bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
     ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
     return false;
@@ -74,12 +68,6 @@ bool Archive_RomFS::CreateDirectory(const Path& path) const {
     return false;
 }
 
-/**
- * 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
- */
 bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
     ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
     return false;
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index c8958a0ebc..a740a3d590 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -66,12 +66,6 @@ bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const {
     return FileUtil::Delete(GetMountPoint() + path.AsString());
 }
 
-/**
- * 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
- */
 bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
     return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
 }
@@ -94,12 +88,6 @@ bool Archive_SDMC::CreateDirectory(const Path& path) const {
     return FileUtil::CreateDir(GetMountPoint() + path.AsString());
 }
 
-/**
- * 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
- */
 bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
     return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
 }
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index bffe599528..647f0dea94 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -340,97 +340,68 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
     return MakeResult<Handle>(handle);
 }
 
-/**
- * Delete a File from an Archive
- * @param archive_handle Handle to an open Archive object
- * @param path Path to the File inside of the Archive
- * @return Whether deletion succeeded
- */
-Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
+ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
     Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
     if (archive == nullptr)
-        return -1;
+        return InvalidHandle(ErrorModule::FS);
     if (archive->backend->DeleteFile(path))
-        return 0;
-    return -1;
+        return RESULT_SUCCESS;
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+                      ErrorSummary::Canceled, ErrorLevel::Status);
 }
 
-/**
- * Rename a File between two Archives
- * @param src_archive_handle Handle to the source Archive object
- * @param src_path Path to the File inside of the source Archive
- * @param dest_archive_handle Handle to the destination Archive object
- * @param dest_path Path to the File inside of the destination Archive
- * @return Whether rename succeeded
- */
-Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
-                                 Handle dest_archive_handle, const FileSys::Path& dest_path) {
+ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                     Handle dest_archive_handle, const FileSys::Path& dest_path) {
     Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
     Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
     if (src_archive == nullptr || dest_archive == nullptr)
-        return -1;
+        return InvalidHandle(ErrorModule::FS);
     if (src_archive == dest_archive) {
         if (src_archive->backend->RenameFile(src_path, dest_path))
-            return 0;
+            return RESULT_SUCCESS;
     } else {
         // TODO: Implement renaming across archives
-        return -1;
+        return UnimplementedFunction(ErrorModule::FS);
     }
-    return -1;
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+                      ErrorSummary::NothingHappened, ErrorLevel::Status);
 }
 
-/**
- * Delete a Directory from an Archive
- * @param archive_handle Handle to an open Archive object
- * @param path Path to the Directory inside of the Archive
- * @return Whether deletion succeeded
- */
-Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
+ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
     Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
     if (archive == nullptr)
-        return -1;
+        return InvalidHandle(ErrorModule::FS);
     if (archive->backend->DeleteDirectory(path))
-        return 0;
-    return -1;
+        return RESULT_SUCCESS;
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+                      ErrorSummary::Canceled, ErrorLevel::Status);
 }
 
-/**
- * Create a Directory from an Archive
- * @param archive_handle Handle to an open Archive object
- * @param path Path to the Directory inside of the Archive
- * @return Whether creation succeeded
- */
-Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
+ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
     Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
     if (archive == nullptr)
-        return -1;
+        return InvalidHandle(ErrorModule::FS);
     if (archive->backend->CreateDirectory(path))
-        return 0;
-    return -1;
+        return RESULT_SUCCESS;
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+                      ErrorSummary::Canceled, ErrorLevel::Status);
 }
 
-/**
- * Rename a Directory between two Archives
- * @param src_archive_handle Handle to the source Archive object
- * @param src_path Path to the Directory inside of the source Archive
- * @param dest_archive_handle Handle to the destination Archive object
- * @param dest_path Path to the Directory inside of the destination Archive
- * @return Whether rename succeeded
- */
-Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
-                                      Handle dest_archive_handle, const FileSys::Path& dest_path) {
+ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                          Handle dest_archive_handle, const FileSys::Path& dest_path) {
     Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
     Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
     if (src_archive == nullptr || dest_archive == nullptr)
-        return -1;
+        return InvalidHandle(ErrorModule::FS);
     if (src_archive == dest_archive) {
         if (src_archive->backend->RenameDirectory(src_path, dest_path))
-            return 0;
+            return RESULT_SUCCESS;
     } else {
         // TODO: Implement renaming across archives
-        return -1;
+        return UnimplementedFunction(ErrorModule::FS);
     }
-    return -1;
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+                      ErrorSummary::NothingHappened, ErrorLevel::Status);
 }
 
 /**
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
index 9d071d3157..b50833a2be 100644
--- a/src/core/hle/kernel/archive.h
+++ b/src/core/hle/kernel/archive.h
@@ -50,7 +50,7 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
  * @param path Path to the File inside of the Archive
  * @return Whether deletion succeeded
  */
-Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
+ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
 
 /**
  * Rename a File between two Archives
@@ -60,8 +60,8 @@ Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
  * @param dest_path Path to the File inside of the destination Archive
  * @return Whether rename succeeded
  */
-Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
-                                 Handle dest_archive_handle, const FileSys::Path& dest_path);
+ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                     Handle dest_archive_handle, const FileSys::Path& dest_path);
 
 /**
  * Delete a Directory from an Archive
@@ -69,7 +69,7 @@ Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path&
  * @param path Path to the Directory inside of the Archive
  * @return Whether deletion succeeded
  */
-Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
+ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
 
 /**
  * Create a Directory from an Archive
@@ -77,7 +77,7 @@ Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
  * @param path Path to the Directory inside of the Archive
  * @return Whether creation of directory succeeded
  */
-Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
+ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
 
 /**
  * Rename a Directory between two Archives
@@ -87,8 +87,8 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
  * @param dest_path Path to the Directory inside of the destination Archive
  * @return Whether rename succeeded
  */
-Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
-                                      Handle dest_archive_handle, const FileSys::Path& dest_path);
+ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
+                                          Handle dest_archive_handle, const FileSys::Path& dest_path);
 
 /**
  * Open a Directory from an Archive
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index f4b1a879cc..95663b9051 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -159,7 +159,7 @@ void DeleteFile(Service::Interface* self) {
     DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
               filename_type, filename_size, file_path.DebugStr().c_str());
 
-    cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path);
+    cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path).raw;
     
     DEBUG_LOG(KERNEL, "called");
 }
@@ -201,7 +201,7 @@ void RenameFile(Service::Interface* self) {
               src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(),
               dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str());
 
-    cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path);
+    cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path).raw;
     
     DEBUG_LOG(KERNEL, "called");
 }
@@ -232,7 +232,7 @@ void DeleteDirectory(Service::Interface* self) {
     DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
               dirname_type, dirname_size, dir_path.DebugStr().c_str());
     
-    cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path);
+    cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
     
     DEBUG_LOG(KERNEL, "called");
 }
@@ -262,7 +262,7 @@ static void CreateDirectory(Service::Interface* self) {
 
     DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
 
-    cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path);
+    cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path).raw;
 
     DEBUG_LOG(KERNEL, "called");
 }
@@ -304,7 +304,7 @@ void RenameDirectory(Service::Interface* self) {
               src_dirname_type, src_dirname_size, src_dir_path.DebugStr().c_str(),
               dest_dirname_type, dest_dirname_size, dest_dir_path.DebugStr().c_str());
 
-    cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path);
+    cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path).raw;
     
     DEBUG_LOG(KERNEL, "called");
 }