summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-11-11 19:37:26 +0100
committerarchshift <admin@archshift.com>2014-11-23 09:33:43 +0100
commit8aeadbd95a85e2d42d282897d7d286d645d61f27 (patch)
tree5cc15bf131a6cfb3e6a0834e07ca2d007f612a7e /src
parentMerge pull request #192 from bunnei/fs-fix-paths (diff)
downloadyuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar.gz
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar.bz2
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar.lz
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar.xz
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.tar.zst
yuzu-8aeadbd95a85e2d42d282897d7d286d645d61f27.zip
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/archive.h14
-rw-r--r--src/core/file_sys/archive_romfs.cpp20
-rw-r--r--src/core/file_sys/archive_romfs.h14
-rw-r--r--src/core/file_sys/archive_sdmc.cpp18
-rw-r--r--src/core/file_sys/archive_sdmc.h14
-rw-r--r--src/core/hle/kernel/archive.cpp32
-rw-r--r--src/core/hle/kernel/archive.h16
-rw-r--r--src/core/hle/service/fs_user.cpp92
8 files changed, 194 insertions, 26 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index dc2d2ced9..4cf47f30a 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -185,6 +185,20 @@ public:
virtual std::unique_ptr<File> 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;
+
+ /**
+ * 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
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 3ea60134f..05fc1f87f 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)
}
/**
+ * Delete a file specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the file could be deleted
+ */
+bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
+ ERROR_LOG(FILESYS, "Attempted to delete a file from ROMFS.");
+ return false;
+}
+
+/**
+ * Delete a directory specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the directory could be deleted
+ */
+bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const {
+ ERROR_LOG(FILESYS, "Attempted to delete a directory from ROMFS.");
+ return false;
+}
+
+/**
* Create a directory specified by its path
* @param path Path relative to the archive
* @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 8d5715734..aa6446c51 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -37,6 +37,20 @@ public:
std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
/**
+ * Delete a file specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the file could be deleted
+ */
+ bool DeleteFile(const FileSys::Path& path) const override;
+
+ /**
+ * Delete a directory specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the directory could be deleted
+ */
+ bool DeleteDirectory(const FileSys::Path& path) const override;
+
+ /**
* Create a directory specified by its path
* @param path Path relative to the archive
* @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)
}
/**
+ * Delete a file specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the file could be deleted
+ */
+bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const {
+ return FileUtil::Delete(GetMountPoint() + path.AsString());
+}
+
+/**
+ * Delete a directory specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the directory could be deleted
+ */
+bool Archive_SDMC::DeleteDirectory(const FileSys::Path& path) const {
+ return FileUtil::DeleteDir(GetMountPoint() + path.AsString());
+}
+
+/**
* Create a directory specified by its path
* @param path Path relative to the archive
* @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 1f621b3f7..8ac06484c 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -41,6 +41,20 @@ public:
std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
/**
+ * Delete a file specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the file could be deleted
+ */
+ bool DeleteFile(const FileSys::Path& path) const override;
+
+ /**
+ * Delete a directory specified by its path
+ * @param path Path relative to the archive
+ * @return Whether the directory could be deleted
+ */
+ bool DeleteDirectory(const FileSys::Path& path) const override;
+
+ /**
* Create a directory specified by its path
* @param path Path relative to the archive
* @return Whether the directory could be created
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 8f1c95d0f..85defeb7a 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
}
/**
+ * 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) {
+ Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
+ if (archive == nullptr)
+ return -1;
+ if (archive->backend->DeleteFile(path))
+ return 0;
+ return -1;
+}
+
+/**
+ * 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) {
+ Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
+ if (archive == nullptr)
+ return -1;
+ if (archive->backend->DeleteDirectory(path))
+ return 0;
+ return -1;
+}
+
+/**
* 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 Opened Directory object
+ * @return Whether creation succeeded
*/
Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
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);
Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
/**
+ * 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);
+
+/**
+ * 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);
+
+/**
* 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
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 8d8f0a201..609c1cb0a 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -138,6 +138,68 @@ void OpenFileDirectly(Service::Interface* self) {
}
/*
+ * FS_User::DeleteFile service function
+ * Inputs:
+ * 2 : Archive handle lower word
+ * 3 : Archive handle upper word
+ * 4 : File path string type
+ * 5 : File path string size
+ * 7 : File path string data
+ * Outputs:
+ * 1 : Result of function, 0 on success, otherwise error code
+ */
+void DeleteFile(Service::Interface* self) {
+ u32* cmd_buff = Service::GetCommandBuffer();
+
+ // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
+ // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
+ Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
+ auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
+ u32 filename_size = cmd_buff[5];
+ u32 filename_ptr = cmd_buff[7];
+
+ FileSys::Path file_path(filename_type, filename_size, filename_ptr);
+
+ 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);
+
+ DEBUG_LOG(KERNEL, "called");
+}
+
+/*
+ * FS_User::DeleteDirectory service function
+ * Inputs:
+ * 2 : Archive handle lower word
+ * 3 : Archive handle upper word
+ * 4 : Directory path string type
+ * 5 : Directory path string size
+ * 7 : Directory path string data
+ * Outputs:
+ * 1 : Result of function, 0 on success, otherwise error code
+ */
+void DeleteDirectory(Service::Interface* self) {
+ u32* cmd_buff = Service::GetCommandBuffer();
+
+ // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
+ // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
+ Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
+ auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
+ u32 dirname_size = cmd_buff[5];
+ u32 dirname_ptr = cmd_buff[7];
+
+ FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
+
+ 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);
+
+ DEBUG_LOG(KERNEL, "called");
+}
+
+/*
* FS_User::CreateDirectory service function
* Inputs:
* 2 : Archive handle lower word
@@ -159,18 +221,8 @@ void CreateDirectory(Service::Interface* self) {
u32 dirname_ptr = cmd_buff[8];
FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
- std::string dir_string;
- switch (dir_path.GetType()) {
- case FileSys::Char:
- case FileSys::Wchar:
- dir_string = dir_path.AsString();
- break;
- default:
- cmd_buff[1] = -1;
- return;
- }
- DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
+ 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);
@@ -188,25 +240,15 @@ void OpenDirectory(Service::Interface* self) {
u32 dirname_ptr = cmd_buff[6];
FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
- std::string dir_string;
- switch (dir_path.GetType()) {
- case FileSys::Char:
- case FileSys::Wchar:
- dir_string = dir_path.AsString();
- break;
- default:
- cmd_buff[1] = -1;
- return;
- }
- DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
+ DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path);
if (handle) {
cmd_buff[1] = 0;
cmd_buff[3] = handle;
} else {
- ERROR_LOG(KERNEL, "failed to get a handle for directory %s", dir_string.c_str());
+ ERROR_LOG(KERNEL, "failed to get a handle for directory");
// TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
cmd_buff[1] = -1;
}
@@ -279,9 +321,9 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x08010002, Initialize, "Initialize"},
{0x080201C2, OpenFile, "OpenFile"},
{0x08030204, OpenFileDirectly, "OpenFileDirectly"},
- {0x08040142, nullptr, "DeleteFile"},
+ {0x08040142, DeleteFile, "DeleteFile"},
{0x08050244, nullptr, "RenameFile"},
- {0x08060142, nullptr, "DeleteDirectory"},
+ {0x08060142, DeleteDirectory, "DeleteDirectory"},
{0x08070142, nullptr, "DeleteDirectoryRecursively"},
{0x08080202, nullptr, "CreateFile"},
{0x08090182, CreateDirectory, "CreateDirectory"},