summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/fs
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-10-13 03:21:49 +0200
committerbunnei <bunneidev@gmail.com>2017-10-13 03:21:49 +0200
commit72b03025ac4ef0d8633c2f3e55b513cd149c59e5 (patch)
treef1fbeb915a0b3df8e4e988a6a562a763e18ea666 /src/core/hle/service/fs
parenthle: Remove a large amount of 3ds-specific service code. (diff)
downloadyuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar.gz
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar.bz2
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar.lz
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar.xz
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.tar.zst
yuzu-72b03025ac4ef0d8633c2f3e55b513cd149c59e5.zip
Diffstat (limited to 'src/core/hle/service/fs')
-rw-r--r--src/core/hle/service/fs/archive.cpp605
-rw-r--r--src/core/hle/service/fs/archive.h276
-rw-r--r--src/core/hle/service/fs/fs_user.cpp1045
-rw-r--r--src/core/hle/service/fs/fs_user.h23
4 files changed, 0 insertions, 1949 deletions
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
deleted file mode 100644
index 4ee7df73c..000000000
--- a/src/core/hle/service/fs/archive.cpp
+++ /dev/null
@@ -1,605 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <cstddef>
-#include <memory>
-#include <system_error>
-#include <type_traits>
-#include <unordered_map>
-#include <utility>
-#include <boost/container/flat_map.hpp>
-#include "common/assert.h"
-#include "common/common_types.h"
-#include "common/file_util.h"
-#include "common/logging/log.h"
-#include "core/file_sys/archive_backend.h"
-#include "core/file_sys/archive_extsavedata.h"
-#include "core/file_sys/archive_ncch.h"
-#include "core/file_sys/archive_other_savedata.h"
-#include "core/file_sys/archive_savedata.h"
-#include "core/file_sys/archive_sdmc.h"
-#include "core/file_sys/archive_sdmcwriteonly.h"
-#include "core/file_sys/archive_selfncch.h"
-#include "core/file_sys/archive_systemsavedata.h"
-#include "core/file_sys/directory_backend.h"
-#include "core/file_sys/errors.h"
-#include "core/file_sys/file_backend.h"
-#include "core/hle/ipc.h"
-#include "core/hle/kernel/client_port.h"
-#include "core/hle/kernel/client_session.h"
-#include "core/hle/kernel/handle_table.h"
-#include "core/hle/kernel/server_session.h"
-#include "core/hle/result.h"
-#include "core/hle/service/fs/archive.h"
-#include "core/hle/service/fs/fs_user.h"
-#include "core/hle/service/service.h"
-#include "core/memory.h"
-
-// Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
-// Workaroung for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
-namespace std {
-template <>
-struct hash<Service::FS::ArchiveIdCode> {
- typedef Service::FS::ArchiveIdCode argument_type;
- typedef std::size_t result_type;
-
- result_type operator()(const argument_type& id_code) const {
- typedef std::underlying_type<argument_type>::type Type;
- return std::hash<Type>()(static_cast<Type>(id_code));
- }
-};
-} // namespace std
-
-static constexpr Kernel::Handle INVALID_HANDLE{};
-
-namespace Service {
-namespace FS {
-
-// Command to access archive file
-enum class FileCommand : u32 {
- Dummy1 = 0x000100C6,
- Control = 0x040100C4,
- OpenSubFile = 0x08010100,
- Read = 0x080200C2,
- Write = 0x08030102,
- GetSize = 0x08040000,
- SetSize = 0x08050080,
- GetAttributes = 0x08060000,
- SetAttributes = 0x08070040,
- Close = 0x08080000,
- Flush = 0x08090000,
- SetPriority = 0x080A0040,
- GetPriority = 0x080B0000,
- OpenLinkFile = 0x080C0000,
-};
-
-// Command to access directory
-enum class DirectoryCommand : u32 {
- Dummy1 = 0x000100C6,
- Control = 0x040100C4,
- Read = 0x08010042,
- Close = 0x08020000,
-};
-
-File::File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path)
- : path(path), priority(0), backend(std::move(backend)) {}
-
-File::~File() {}
-
-void File::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
- using Kernel::ClientSession;
- using Kernel::ServerSession;
- using Kernel::SharedPtr;
-
- u32* cmd_buff = Kernel::GetCommandBuffer();
- FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
- switch (cmd) {
-
- // Read from file...
- case FileCommand::Read: {
- u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
- u32 length = cmd_buff[3];
- u32 address = cmd_buff[5];
- LOG_TRACE(Service_FS, "Read %s: offset=0x%llx length=%d address=0x%x", GetName().c_str(),
- offset, length, address);
-
- if (offset + length > backend->GetSize()) {
- LOG_ERROR(Service_FS,
- "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX",
- offset, length, backend->GetSize());
- }
-
- std::vector<u8> data(length);
- ResultVal<size_t> read = backend->Read(offset, data.size(), data.data());
- if (read.Failed()) {
- cmd_buff[1] = read.Code().raw;
- return;
- }
- Memory::WriteBlock(address, data.data(), *read);
- cmd_buff[2] = static_cast<u32>(*read);
- break;
- }
-
- // Write to file...
- case FileCommand::Write: {
- u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
- u32 length = cmd_buff[3];
- u32 flush = cmd_buff[4];
- u32 address = cmd_buff[6];
- LOG_TRACE(Service_FS, "Write %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
- GetName().c_str(), offset, length, address, flush);
-
- std::vector<u8> data(length);
- Memory::ReadBlock(address, data.data(), data.size());
- ResultVal<size_t> written = backend->Write(offset, data.size(), flush != 0, data.data());
- if (written.Failed()) {
- cmd_buff[1] = written.Code().raw;
- return;
- }
- cmd_buff[2] = static_cast<u32>(*written);
- break;
- }
-
- case FileCommand::GetSize: {
- LOG_TRACE(Service_FS, "GetSize %s", GetName().c_str());
- u64 size = backend->GetSize();
- cmd_buff[2] = (u32)size;
- cmd_buff[3] = size >> 32;
- break;
- }
-
- case FileCommand::SetSize: {
- u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
- LOG_TRACE(Service_FS, "SetSize %s size=%llu", GetName().c_str(), size);
- backend->SetSize(size);
- break;
- }
-
- case FileCommand::Close: {
- LOG_TRACE(Service_FS, "Close %s", GetName().c_str());
- backend->Close();
- break;
- }
-
- case FileCommand::Flush: {
- LOG_TRACE(Service_FS, "Flush");
- backend->Flush();
- break;
- }
-
- case FileCommand::OpenLinkFile: {
- LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str());
- auto sessions = ServerSession::CreateSessionPair(GetName());
- ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
- cmd_buff[3] = Kernel::g_handle_table.Create(std::get<SharedPtr<ClientSession>>(sessions))
- .ValueOr(INVALID_HANDLE);
- break;
- }
-
- case FileCommand::SetPriority: {
- priority = cmd_buff[1];
- LOG_TRACE(Service_FS, "SetPriority %u", priority);
- break;
- }
-
- case FileCommand::GetPriority: {
- cmd_buff[2] = priority;
- LOG_TRACE(Service_FS, "GetPriority");
- break;
- }
-
- // Unknown command...
- default:
- LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
- ResultCode error = UnimplementedFunction(ErrorModule::FS);
- cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
- return;
- }
- cmd_buff[1] = RESULT_SUCCESS.raw; // No error
-}
-
-Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
- const FileSys::Path& path)
- : path(path), backend(std::move(backend)) {}
-
-Directory::~Directory() {}
-
-void Directory::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
- switch (cmd) {
- // Read from directory...
- case DirectoryCommand::Read: {
- u32 count = cmd_buff[1];
- u32 address = cmd_buff[3];
- std::vector<FileSys::Entry> entries(count);
- LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count);
-
- // Number of entries actually read
- u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data());
- cmd_buff[2] = read;
- Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry));
- break;
- }
-
- case DirectoryCommand::Close: {
- LOG_TRACE(Service_FS, "Close %s", GetName().c_str());
- backend->Close();
- break;
- }
-
- // Unknown command...
- default:
- LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
- ResultCode error = UnimplementedFunction(ErrorModule::FS);
- cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
- return;
- }
- cmd_buff[1] = RESULT_SUCCESS.raw; // No error
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-using FileSys::ArchiveBackend;
-using FileSys::ArchiveFactory;
-
-/**
- * Map of registered archives, identified by id code. Once an archive is registered here, it is
- * never removed until UnregisterArchiveTypes is called.
- */
-static boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
-
-/**
- * Map of active archive handles. Values are pointers to the archives in `idcode_map`.
- */
-static std::unordered_map<ArchiveHandle, std::unique_ptr<ArchiveBackend>> handle_map;
-static ArchiveHandle next_handle;
-
-static ArchiveBackend* GetArchive(ArchiveHandle handle) {
- auto itr = handle_map.find(handle);
- return (itr == handle_map.end()) ? nullptr : itr->second.get();
-}
-
-ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
- LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);
-
- auto itr = id_code_map.find(id_code);
- if (itr == id_code_map.end()) {
- return FileSys::ERROR_NOT_FOUND;
- }
-
- CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));
-
- // This should never even happen in the first place with 64-bit handles,
- while (handle_map.count(next_handle) != 0) {
- ++next_handle;
- }
- handle_map.emplace(next_handle, std::move(res));
- return MakeResult<ArchiveHandle>(next_handle++);
-}
-
-ResultCode CloseArchive(ArchiveHandle handle) {
- if (handle_map.erase(handle) == 0)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
- else
- return RESULT_SUCCESS;
-}
-
-// TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
-// http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
-ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory,
- ArchiveIdCode id_code) {
- auto result = id_code_map.emplace(id_code, std::move(factory));
-
- bool inserted = result.second;
- ASSERT_MSG(inserted, "Tried to register more than one archive with same id code");
-
- auto& archive = result.first->second;
- LOG_DEBUG(Service_FS, "Registered archive %s with id code 0x%08X", archive->GetName().c_str(),
- id_code);
- return RESULT_SUCCESS;
-}
-
-ResultVal<std::shared_ptr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
- const FileSys::Path& path,
- const FileSys::Mode mode) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- auto backend = archive->OpenFile(path, mode);
- if (backend.Failed())
- return backend.Code();
-
- auto file = std::shared_ptr<File>(new File(std::move(backend).Unwrap(), path));
- return MakeResult<std::shared_ptr<File>>(std::move(file));
-}
-
-ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- return archive->DeleteFile(path);
-}
-
-ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle,
- const FileSys::Path& src_path,
- ArchiveHandle dest_archive_handle,
- const FileSys::Path& dest_path) {
- ArchiveBackend* src_archive = GetArchive(src_archive_handle);
- ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
- if (src_archive == nullptr || dest_archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- if (src_archive == dest_archive) {
- return src_archive->RenameFile(src_path, dest_path);
- } else {
- // TODO: Implement renaming across archives
- return UnimplementedFunction(ErrorModule::FS);
- }
-}
-
-ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- return archive->DeleteDirectory(path);
-}
-
-ResultCode DeleteDirectoryRecursivelyFromArchive(ArchiveHandle archive_handle,
- const FileSys::Path& path) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- return archive->DeleteDirectoryRecursively(path);
-}
-
-ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
- u64 file_size) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- return archive->CreateFile(path, file_size);
-}
-
-ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- return archive->CreateDirectory(path);
-}
-
-ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle,
- const FileSys::Path& src_path,
- ArchiveHandle dest_archive_handle,
- const FileSys::Path& dest_path) {
- ArchiveBackend* src_archive = GetArchive(src_archive_handle);
- ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
- if (src_archive == nullptr || dest_archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- if (src_archive == dest_archive) {
- return src_archive->RenameDirectory(src_path, dest_path);
- } else {
- // TODO: Implement renaming across archives
- return UnimplementedFunction(ErrorModule::FS);
- }
-}
-
-ResultVal<std::shared_ptr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
- const FileSys::Path& path) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
-
- auto backend = archive->OpenDirectory(path);
- if (backend.Failed())
- return backend.Code();
-
- auto directory = std::shared_ptr<Directory>(new Directory(std::move(backend).Unwrap(), path));
- return MakeResult<std::shared_ptr<Directory>>(std::move(directory));
-}
-
-ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) {
- ArchiveBackend* archive = GetArchive(archive_handle);
- if (archive == nullptr)
- return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
- return MakeResult<u64>(archive->GetFreeBytes());
-}
-
-ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info,
- const FileSys::Path& path) {
- auto archive_itr = id_code_map.find(id_code);
- if (archive_itr == id_code_map.end()) {
- return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
- }
-
- return archive_itr->second->Format(path, format_info);
-}
-
-ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code,
- FileSys::Path& archive_path) {
- auto archive = id_code_map.find(id_code);
- if (archive == id_code_map.end()) {
- return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
- }
-
- return archive->second->GetFormatInfo(archive_path);
-}
-
-ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer,
- u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) {
- // Construct the binary path to the archive first
- FileSys::Path path =
- FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
-
- auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData
- : ArchiveIdCode::ExtSaveData);
-
- if (archive == id_code_map.end()) {
- return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
- }
-
- auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get());
-
- ResultCode result = ext_savedata->Format(path, format_info);
- if (result.IsError())
- return result;
-
- if (!Memory::IsValidVirtualAddress(icon_buffer))
- return ResultCode(-1); // TODO(Subv): Find the right error code
-
- std::vector<u8> smdh_icon(icon_size);
- Memory::ReadBlock(icon_buffer, smdh_icon.data(), smdh_icon.size());
- ext_savedata->WriteIcon(path, smdh_icon.data(), smdh_icon.size());
- return RESULT_SUCCESS;
-}
-
-ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
- // Construct the binary path to the archive first
- FileSys::Path path =
- FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
-
- std::string media_type_directory;
- if (media_type == MediaType::NAND) {
- media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
- } else if (media_type == MediaType::SDMC) {
- media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
- } else {
- LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
- return ResultCode(-1); // TODO(Subv): Find the right error code
- }
-
- // Delete all directories (/user, /boss) and the icon file.
- std::string base_path =
- FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
- std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
- if (FileUtil::Exists(extsavedata_path) && !FileUtil::DeleteDirRecursively(extsavedata_path))
- return ResultCode(-1); // TODO(Subv): Find the right error code
- return RESULT_SUCCESS;
-}
-
-ResultCode DeleteSystemSaveData(u32 high, u32 low) {
- // Construct the binary path to the archive first
- FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
-
- std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
- std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
- std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
- if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
- return ResultCode(-1); // TODO(Subv): Find the right error code
- return RESULT_SUCCESS;
-}
-
-ResultCode CreateSystemSaveData(u32 high, u32 low) {
- // Construct the binary path to the archive first
- FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
-
- std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
- std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
- std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
- if (!FileUtil::CreateFullPath(systemsavedata_path))
- return ResultCode(-1); // TODO(Subv): Find the right error code
- return RESULT_SUCCESS;
-}
-
-void RegisterArchiveTypes() {
- // TODO(Subv): Add the other archive types (see here for the known types:
- // http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
-
- std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
- std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
- auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
- if (sdmc_factory->Initialize())
- RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
- else
- LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s",
- sdmc_directory.c_str());
-
- auto sdmcwo_factory = std::make_unique<FileSys::ArchiveFactory_SDMCWriteOnly>(sdmc_directory);
- if (sdmcwo_factory->Initialize())
- RegisterArchiveType(std::move(sdmcwo_factory), ArchiveIdCode::SDMCWriteOnly);
- else
- LOG_ERROR(Service_FS, "Can't instantiate SDMCWriteOnly archive with path %s",
- sdmc_directory.c_str());
-
- // Create the SaveData archive
- auto sd_savedata_source = std::make_shared<FileSys::ArchiveSource_SDSaveData>(sdmc_directory);
- auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sd_savedata_source);
- RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData);
- auto other_savedata_permitted_factory =
- std::make_unique<FileSys::ArchiveFactory_OtherSaveDataPermitted>(sd_savedata_source);
- RegisterArchiveType(std::move(other_savedata_permitted_factory),
- ArchiveIdCode::OtherSaveDataPermitted);
- auto other_savedata_general_factory =
- std::make_unique<FileSys::ArchiveFactory_OtherSaveDataGeneral>(sd_savedata_source);
- RegisterArchiveType(std::move(other_savedata_general_factory),
- ArchiveIdCode::OtherSaveDataGeneral);
-
- auto extsavedata_factory =
- std::make_unique<FileSys::ArchiveFactory_ExtSaveData>(sdmc_directory, false);
- if (extsavedata_factory->Initialize())
- RegisterArchiveType(std::move(extsavedata_factory), ArchiveIdCode::ExtSaveData);
- else
- LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path %s",
- extsavedata_factory->GetMountPoint().c_str());
-
- auto sharedextsavedata_factory =
- std::make_unique<FileSys::ArchiveFactory_ExtSaveData>(nand_directory, true);
- if (sharedextsavedata_factory->Initialize())
- RegisterArchiveType(std::move(sharedextsavedata_factory), ArchiveIdCode::SharedExtSaveData);
- else
- LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s",
- sharedextsavedata_factory->GetMountPoint().c_str());
-
- // Create the NCCH archive, basically a small variation of the RomFS archive
- auto savedatacheck_factory = std::make_unique<FileSys::ArchiveFactory_NCCH>(nand_directory);
- RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::NCCH);
-
- auto systemsavedata_factory =
- std::make_unique<FileSys::ArchiveFactory_SystemSaveData>(nand_directory);
- RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData);
-
- auto selfncch_factory = std::make_unique<FileSys::ArchiveFactory_SelfNCCH>();
- RegisterArchiveType(std::move(selfncch_factory), ArchiveIdCode::SelfNCCH);
-}
-
-void RegisterSelfNCCH(Loader::AppLoader& app_loader) {
- auto itr = id_code_map.find(ArchiveIdCode::SelfNCCH);
- if (itr == id_code_map.end()) {
- LOG_ERROR(Service_FS,
- "Could not register a new NCCH because the SelfNCCH archive hasn't been created");
- return;
- }
-
- auto* factory = static_cast<FileSys::ArchiveFactory_SelfNCCH*>(itr->second.get());
- factory->Register(app_loader);
-}
-
-void UnregisterArchiveTypes() {
- id_code_map.clear();
-}
-
-/// Initialize archives
-void ArchiveInit() {
- next_handle = 1;
-
- AddService(new FS::Interface);
-
- RegisterArchiveTypes();
-}
-
-/// Shutdown archives
-void ArchiveShutdown() {
- handle_map.clear();
- UnregisterArchiveTypes();
-}
-
-} // namespace FS
-} // namespace Service
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
deleted file mode 100644
index e3c8fc2ef..000000000
--- a/src/core/hle/service/fs/archive.h
+++ /dev/null
@@ -1,276 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <memory>
-#include <string>
-#include "common/common_types.h"
-#include "core/file_sys/archive_backend.h"
-#include "core/hle/kernel/hle_ipc.h"
-#include "core/hle/result.h"
-
-namespace FileSys {
-class DirectoryBackend;
-class FileBackend;
-}
-
-/// The unique system identifier hash, also known as ID0
-static constexpr char SYSTEM_ID[]{"00000000000000000000000000000000"};
-/// The scrambled SD card CID, also known as ID1
-static constexpr char SDCARD_ID[]{"00000000000000000000000000000000"};
-
-namespace Loader {
-class AppLoader;
-}
-
-namespace Service {
-namespace FS {
-
-/// Supported archive types
-enum class ArchiveIdCode : u32 {
- SelfNCCH = 0x00000003,
- SaveData = 0x00000004,
- ExtSaveData = 0x00000006,
- SharedExtSaveData = 0x00000007,
- SystemSaveData = 0x00000008,
- SDMC = 0x00000009,
- SDMCWriteOnly = 0x0000000A,
- NCCH = 0x2345678A,
- OtherSaveDataGeneral = 0x567890B2,
- OtherSaveDataPermitted = 0x567890B4,
-};
-
-/// Media types for the archives
-enum class MediaType : u32 { NAND = 0, SDMC = 1, GameCard = 2 };
-
-typedef u64 ArchiveHandle;
-
-class File final : public Kernel::SessionRequestHandler {
-public:
- File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path);
- ~File();
-
- std::string GetName() const {
- return "Path: " + path.DebugStr();
- }
-
- FileSys::Path path; ///< Path of the file
- u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
- std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
-
-protected:
- void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
-};
-
-class Directory final : public Kernel::SessionRequestHandler {
-public:
- Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path);
- ~Directory();
-
- std::string GetName() const {
- return "Directory: " + path.DebugStr();
- }
-
- FileSys::Path path; ///< Path of the directory
- std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
-
-protected:
- void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
-};
-
-/**
- * Opens an archive
- * @param id_code IdCode of the archive to open
- * @param archive_path Path to the archive, used with Binary paths
- * @return Handle to the opened archive
- */
-ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path);
-
-/**
- * Closes an archive
- * @param handle Handle to the archive to close
- */
-ResultCode CloseArchive(ArchiveHandle handle);
-
-/**
- * Registers an Archive type, instances of which can later be opened using its IdCode.
- * @param factory File system backend interface to the archive
- * @param id_code Id code used to access this type of archive
- */
-ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory,
- ArchiveIdCode id_code);
-
-/**
- * Open a File from an Archive
- * @param archive_handle Handle to an open Archive object
- * @param path Path to the File inside of the Archive
- * @param mode Mode under which to open the File
- * @return The opened File object
- */
-ResultVal<std::shared_ptr<File>> OpenFileFromArchive(ArchiveHandle 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
- */
-ResultCode DeleteFileFromArchive(ArchiveHandle 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
- */
-ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle,
- const FileSys::Path& src_path,
- ArchiveHandle dest_archive_handle,
- const FileSys::Path& dest_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
- */
-ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
-
-/**
- * Delete a Directory and anything under it 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
- */
-ResultCode DeleteDirectoryRecursivelyFromArchive(ArchiveHandle archive_handle,
- const FileSys::Path& path);
-
-/**
- * Create a File in an Archive
- * @param archive_handle Handle to an open Archive object
- * @param path Path to the File inside of the Archive
- * @param file_size The size of the new file, filled with zeroes
- * @return File creation result code
- */
-ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
- u64 file_size);
-
-/**
- * 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 of directory succeeded
- */
-ResultCode CreateDirectoryFromArchive(ArchiveHandle 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
- */
-ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle,
- const FileSys::Path& src_path,
- ArchiveHandle dest_archive_handle,
- const FileSys::Path& dest_path);
-
-/**
- * Open 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 The opened Directory object
- */
-ResultVal<std::shared_ptr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
- const FileSys::Path& path);
-
-/**
- * Get the free space in an Archive
- * @param archive_handle Handle to an open Archive object
- * @return The number of free bytes in the archive
- */
-ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle);
-
-/**
- * Erases the contents of the physical folder that contains the archive
- * identified by the specified id code and path
- * @param id_code The id of the archive to format
- * @param format_info Format information about the new archive
- * @param path The path to the archive, if relevant.
- * @return ResultCode 0 on success or the corresponding code on error
- */
-ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info,
- const FileSys::Path& path = FileSys::Path());
-
-/**
- * Retrieves the format info about the archive of the specified type and path.
- * The format info is supplied by the client code when creating archives.
- * @param id_code The id of the archive
- * @param archive_path The path of the archive, if relevant
- * @return The format info of the archive, or the corresponding error code if failed.
- */
-ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code,
- FileSys::Path& archive_path);
-
-/**
- * Creates a blank SharedExtSaveData archive for the specified extdata ID
- * @param media_type The media type of the archive to create (NAND / SDMC)
- * @param high The high word of the extdata id to create
- * @param low The low word of the extdata id to create
- * @param icon_buffer VAddr of the SMDH icon for this ExtSaveData
- * @param icon_size Size of the SMDH icon
- * @param format_info Format information about the new archive
- * @return ResultCode 0 on success or the corresponding code on error
- */
-ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer,
- u32 icon_size, const FileSys::ArchiveFormatInfo& format_info);
-
-/**
- * Deletes the SharedExtSaveData archive for the specified extdata ID
- * @param media_type The media type of the archive to delete (NAND / SDMC)
- * @param high The high word of the extdata id to delete
- * @param low The low word of the extdata id to delete
- * @return ResultCode 0 on success or the corresponding code on error
- */
-ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low);
-
-/**
- * Deletes the SystemSaveData archive folder for the specified save data id
- * @param high The high word of the SystemSaveData archive to delete
- * @param low The low word of the SystemSaveData archive to delete
- * @return ResultCode 0 on success or the corresponding code on error
- */
-ResultCode DeleteSystemSaveData(u32 high, u32 low);
-
-/**
- * Creates the SystemSaveData archive folder for the specified save data id
- * @param high The high word of the SystemSaveData archive to create
- * @param low The low word of the SystemSaveData archive to create
- * @return ResultCode 0 on success or the corresponding code on error
- */
-ResultCode CreateSystemSaveData(u32 high, u32 low);
-
-/// Initialize archives
-void ArchiveInit();
-
-/// Shutdown archives
-void ArchiveShutdown();
-
-/// Registers a new NCCH file with the SelfNCCH archive factory
-void RegisterSelfNCCH(Loader::AppLoader& app_loader);
-
-/// Register all archive types
-void RegisterArchiveTypes();
-
-/// Unregister all archive types
-void UnregisterArchiveTypes();
-
-} // namespace FS
-} // namespace Service
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
deleted file mode 100644
index b9eab7838..000000000
--- a/src/core/hle/service/fs/fs_user.cpp
+++ /dev/null
@@ -1,1045 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include "common/assert.h"
-#include "common/common_types.h"
-#include "common/file_util.h"
-#include "common/logging/log.h"
-#include "common/scope_exit.h"
-#include "common/string_util.h"
-#include "core/core.h"
-#include "core/file_sys/errors.h"
-#include "core/hle/ipc.h"
-#include "core/hle/ipc_helpers.h"
-#include "core/hle/kernel/client_port.h"
-#include "core/hle/kernel/client_session.h"
-#include "core/hle/kernel/server_session.h"
-#include "core/hle/result.h"
-#include "core/hle/service/fs/archive.h"
-#include "core/hle/service/fs/fs_user.h"
-#include "core/settings.h"
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// Namespace FS_User
-
-using Kernel::ClientSession;
-using Kernel::ServerSession;
-using Kernel::SharedPtr;
-
-namespace Service {
-namespace FS {
-
-static u32 priority = -1; ///< For SetPriority and GetPriority service functions
-
-static ArchiveHandle MakeArchiveHandle(u32 low_word, u32 high_word) {
- return (u64)low_word | ((u64)high_word << 32);
-}
-
-static void Initialize(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- // TODO(Link Mauve): check the behavior when cmd_buff[1] isn't 32, as per
- // http://3dbrew.org/wiki/FS:Initialize#Request
- cmd_buff[1] = RESULT_SUCCESS.raw;
-}
-
-/**
- * FS_User::OpenFile service function
- * Inputs:
- * 1 : Transaction
- * 2 : Archive handle lower word
- * 3 : Archive handle upper word
- * 4 : Low path type
- * 5 : Low path size
- * 6 : Open flags
- * 7 : Attributes
- * 8 : (LowPathSize << 14) | 2
- * 9 : Low path data pointer
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 3 : File handle
- */
-static void OpenFile(Service::Interface* self) {
- // The helper should be passed by argument to the function
- IPC::RequestParser rp(Kernel::GetCommandBuffer(), {0x080201C2});
- rp.Pop<u32>(); // Always 0 ?
-
- ArchiveHandle archive_handle = rp.Pop<u64>();
- auto filename_type = static_cast<FileSys::LowPathType>(rp.Pop<u32>());
- u32 filename_size = rp.Pop<u32>();
- FileSys::Mode mode;
- mode.hex = rp.Pop<u32>();
- u32 attributes = rp.Pop<u32>(); // TODO(Link Mauve): do something with those attributes.
- VAddr filename_ptr = rp.PopStaticBuffer();
- FileSys::Path file_path(filename_type, filename_size, filename_ptr);
-
- LOG_DEBUG(Service_FS, "path=%s, mode=%u attrs=%u", file_path.DebugStr().c_str(), mode.hex,
- attributes);
-
- ResultVal<std::shared_ptr<File>> file_res =
- OpenFileFromArchive(archive_handle, file_path, mode);
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
- rb.Push(file_res.Code());
- if (file_res.Succeeded()) {
- std::shared_ptr<File> file = *file_res;
- auto sessions = ServerSession::CreateSessionPair(file->GetName());
- file->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
-
- rb.PushMoveHandles(
- Kernel::g_handle_table.Create(std::get<SharedPtr<ClientSession>>(sessions)).Unwrap());
- } else {
- rb.PushMoveHandles(0);
- LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
- }
-}
-
-/**
- * FS_User::OpenFileDirectly service function
- * Inputs:
- * 1 : Transaction
- * 2 : Archive ID
- * 3 : Archive low path type
- * 4 : Archive low path size
- * 5 : File low path type
- * 6 : File low path size
- * 7 : Flags
- * 8 : Attributes
- * 9 : (ArchiveLowPathSize << 14) | 0x802
- * 10 : Archive low path
- * 11 : (FileLowPathSize << 14) | 2
- * 12 : File low path
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 3 : File handle
- */
-static void OpenFileDirectly(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[2]);
- auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
- u32 archivename_size = cmd_buff[4];
- auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]);
- u32 filename_size = cmd_buff[6];
- FileSys::Mode mode;
- mode.hex = cmd_buff[7];
- u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
- u32 archivename_ptr = cmd_buff[10];
- u32 filename_ptr = cmd_buff[12];
- FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
- FileSys::Path file_path(filename_type, filename_size, filename_ptr);
-
- LOG_DEBUG(Service_FS, "archive_id=0x%08X archive_path=%s file_path=%s, mode=%u attributes=%u",
- static_cast<u32>(archive_id), archive_path.DebugStr().c_str(),
- file_path.DebugStr().c_str(), mode.hex, attributes);
-
- ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path);
- if (archive_handle.Failed()) {
- LOG_ERROR(Service_FS,
- "Failed to get a handle for archive archive_id=0x%08X archive_path=%s",
- static_cast<u32>(archive_id), archive_path.DebugStr().c_str());
- cmd_buff[1] = archive_handle.Code().raw;
- cmd_buff[3] = 0;
- return;
- }
- SCOPE_EXIT({ CloseArchive(*archive_handle); });
-
- ResultVal<std::shared_ptr<File>> file_res =
- OpenFileFromArchive(*archive_handle, file_path, mode);
- cmd_buff[1] = file_res.Code().raw;
- if (file_res.Succeeded()) {
- std::shared_ptr<File> file = *file_res;
- auto sessions = ServerSession::CreateSessionPair(file->GetName());
- file->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
-
- cmd_buff[3] =
- Kernel::g_handle_table.Create(std::get<SharedPtr<ClientSession>>(sessions)).Unwrap();
- } else {
- cmd_buff[3] = 0;
- LOG_ERROR(Service_FS, "failed to get a handle for file %s mode=%u attributes=%u",
- file_path.DebugStr().c_str(), mode.hex, attributes);
- }
-}
-
-/*
- * 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
- */
-static void DeleteFile(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], 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);
-
- LOG_DEBUG(Service_FS, "type=%u size=%u data=%s", static_cast<u32>(filename_type), filename_size,
- file_path.DebugStr().c_str());
-
- cmd_buff[1] = DeleteFileFromArchive(archive_handle, file_path).raw;
-}
-
-/*
- * 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
- */
-static void RenameFile(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle src_archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
- auto src_filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
- u32 src_filename_size = cmd_buff[5];
- ArchiveHandle dest_archive_handle = MakeArchiveHandle(cmd_buff[6], 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);
-
- LOG_DEBUG(Service_FS,
- "src_type=%u src_size=%u src_data=%s dest_type=%u dest_size=%u dest_data=%s",
- static_cast<u32>(src_filename_type), src_filename_size,
- src_file_path.DebugStr().c_str(), static_cast<u32>(dest_filename_type),
- dest_filename_size, dest_file_path.DebugStr().c_str());
-
- cmd_buff[1] = RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle,
- dest_file_path)
- .raw;
-}
-
-/*
- * 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
- */
-static void DeleteDirectory(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], 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);
-
- LOG_DEBUG(Service_FS, "type=%u size=%u data=%s", static_cast<u32>(dirname_type), dirname_size,
- dir_path.DebugStr().c_str());
-
- cmd_buff[1] = DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
-}
-
-/*
- * FS_User::DeleteDirectoryRecursively service function
- * Inputs:
- * 0 : Command header 0x08070142
- * 1 : Transaction
- * 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
- */
-static void DeleteDirectoryRecursively(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], 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);
-
- LOG_DEBUG(Service_FS, "type=%u size=%u data=%s", static_cast<u32>(dirname_type), dirname_size,
- dir_path.DebugStr().c_str());
-
- cmd_buff[1] = DeleteDirectoryRecursivelyFromArchive(archive_handle, dir_path).raw;
-}
-
-/*
- * FS_User::CreateFile service function
- * Inputs:
- * 0 : Command header 0x08080202
- * 2 : Archive handle lower word
- * 3 : Archive handle upper word
- * 4 : File path string type
- * 5 : File path string size
- * 7-8 : File size
- * 10: File path string data
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CreateFile(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
- auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
- u32 filename_size = cmd_buff[5];
- u64 file_size = ((u64)cmd_buff[8] << 32) | cmd_buff[7];
- u32 filename_ptr = cmd_buff[10];
-
- FileSys::Path file_path(filename_type, filename_size, filename_ptr);
-
- LOG_DEBUG(Service_FS, "type=%u size=%llu data=%s", static_cast<u32>(filename_type), file_size,
- file_path.DebugStr().c_str());
-
- cmd_buff[1] = CreateFileInArchive(archive_handle, file_path, file_size).raw;
-}
-
-/*
- * FS_User::CreateDirectory service function
- * Inputs:
- * 2 : Archive handle lower word
- * 3 : Archive handle upper word
- * 4 : Directory path string type
- * 5 : Directory path string size
- * 8 : Directory path string data
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CreateDirectory(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
- auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
- u32 dirname_size = cmd_buff[5];
- u32 dirname_ptr = cmd_buff[8];
-
- FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
-
- LOG_DEBUG(Service_FS, "type=%u size=%d data=%s", static_cast<u32>(dirname_type), dirname_size,
- dir_path.DebugStr().c_str());
-
- cmd_buff[1] = CreateDirectoryFromArchive(archive_handle, dir_path).raw;
-}
-
-/*
- * 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
- */
-static void RenameDirectory(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle src_archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
- auto src_dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
- u32 src_dirname_size = cmd_buff[5];
- ArchiveHandle dest_archive_handle = MakeArchiveHandle(cmd_buff[6], 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);
-
- LOG_DEBUG(
- Service_FS, "src_type=%u src_size=%u src_data=%s dest_type=%u dest_size=%u dest_data=%s",
- static_cast<u32>(src_dirname_type), src_dirname_size, src_dir_path.DebugStr().c_str(),
- static_cast<u32>(dest_dirname_type), dest_dirname_size, dest_dir_path.DebugStr().c_str());
-
- cmd_buff[1] = RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path,
- dest_archive_handle, dest_dir_path)
- .raw;
-}
-
-/**
- * FS_User::OpenDirectory service function
- * Inputs:
- * 1 : Archive handle low word
- * 2 : Archive handle high word
- * 3 : Low path type
- * 4 : Low path size
- * 7 : (LowPathSize << 14) | 2
- * 8 : Low path data pointer
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 3 : Directory handle
- */
-static void OpenDirectory(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[1], cmd_buff[2]);
- auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
- u32 dirname_size = cmd_buff[4];
- u32 dirname_ptr = cmd_buff[6];
-
- FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
-
- LOG_DEBUG(Service_FS, "type=%u size=%u data=%s", static_cast<u32>(dirname_type), dirname_size,
- dir_path.DebugStr().c_str());
-
- ResultVal<std::shared_ptr<Directory>> dir_res =
- OpenDirectoryFromArchive(archive_handle, dir_path);
- cmd_buff[1] = dir_res.Code().raw;
- if (dir_res.Succeeded()) {
- std::shared_ptr<Directory> directory = *dir_res;
- auto sessions = ServerSession::CreateSessionPair(directory->GetName());
- directory->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
-
- cmd_buff[3] =
- Kernel::g_handle_table.Create(std::get<SharedPtr<ClientSession>>(sessions)).Unwrap();
- } else {
- LOG_ERROR(Service_FS, "failed to get a handle for directory type=%d size=%d data=%s",
- dirname_type, dirname_size, dir_path.DebugStr().c_str());
- }
-}
-
-/**
- * FS_User::OpenArchive service function
- * Inputs:
- * 1 : Archive ID
- * 2 : Archive low path type
- * 3 : Archive low path size
- * 4 : (LowPathSize << 14) | 2
- * 5 : Archive low path
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : Archive handle lower word (unused)
- * 3 : Archive handle upper word (same as file handle)
- */
-static void OpenArchive(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
- auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
- u32 archivename_size = cmd_buff[3];
- u32 archivename_ptr = cmd_buff[5];
- FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
-
- LOG_DEBUG(Service_FS, "archive_id=0x%08X archive_path=%s", static_cast<u32>(archive_id),
- archive_path.DebugStr().c_str());
-
- ResultVal<ArchiveHandle> handle = OpenArchive(archive_id, archive_path);
- cmd_buff[1] = handle.Code().raw;
- if (handle.Succeeded()) {
- cmd_buff[2] = *handle & 0xFFFFFFFF;
- cmd_buff[3] = (*handle >> 32) & 0xFFFFFFFF;
- } else {
- cmd_buff[2] = cmd_buff[3] = 0;
- LOG_ERROR(Service_FS,
- "failed to get a handle for archive archive_id=0x%08X archive_path=%s",
- static_cast<u32>(archive_id), archive_path.DebugStr().c_str());
- }
-}
-
-/**
- * FS_User::CloseArchive service function
- * Inputs:
- * 0 : 0x080E0080
- * 1 : Archive handle low word
- * 2 : Archive handle high word
- * Outputs:
- * 0 : ??? TODO(yuriks): Verify return header
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CloseArchive(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[1], cmd_buff[2]);
- cmd_buff[1] = CloseArchive(archive_handle).raw;
-}
-
-/*
-* FS_User::IsSdmcDetected service function
-* Outputs:
-* 1 : Result of function, 0 on success, otherwise error code
-* 2 : Whether the Sdmc could be detected
-*/
-static void IsSdmcDetected(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- cmd_buff[1] = 0;
- cmd_buff[2] = Settings::values.use_virtual_sd ? 1 : 0;
-}
-
-/**
- * FS_User::IsSdmcWriteable service function
- * Outputs:
- * 0 : Command header 0x08180000
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : Whether the Sdmc is currently writeable
- */
-static void IsSdmcWriteable(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- cmd_buff[1] = RESULT_SUCCESS.raw;
- // If the SD isn't enabled, it can't be writeable...else, stubbed true
- cmd_buff[2] = Settings::values.use_virtual_sd ? 1 : 0;
-
- LOG_DEBUG(Service_FS, " (STUBBED)");
-}
-
-/**
- * FS_User::FormatSaveData service function,
- * formats the SaveData specified by the input path.
- * Inputs:
- * 0 : 0x084C0242
- * 1 : Archive ID
- * 2 : Archive path type
- * 3 : Archive path size
- * 4 : Size in Blocks (1 block = 512 bytes)
- * 5 : Number of directories
- * 6 : Number of files
- * 7 : Directory bucket count
- * 8 : File bucket count
- * 9 : Duplicate data
- * 10 : (PathSize << 14) | 2
- * 11 : Archive low path
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void FormatSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- LOG_WARNING(Service_FS, "(STUBBED)");
-
- auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
- auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
- u32 archivename_size = cmd_buff[3];
- u32 archivename_ptr = cmd_buff[11];
- FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
-
- LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str());
-
- if (archive_id != FS::ArchiveIdCode::SaveData) {
- LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u",
- static_cast<u32>(archive_id));
- cmd_buff[1] = FileSys::ERROR_INVALID_PATH.raw;
- return;
- }
-
- if (archive_path.GetType() != FileSys::LowPathType::Empty) {
- // TODO(Subv): Implement formatting the SaveData of other games
- LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported");
- cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
- return;
- }
-
- FileSys::ArchiveFormatInfo format_info;
- format_info.duplicate_data = cmd_buff[9] & 0xFF;
- format_info.number_directories = cmd_buff[5];
- format_info.number_files = cmd_buff[6];
- format_info.total_size = cmd_buff[4] * 512;
-
- cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData, format_info).raw;
-}
-
-/**
- * FS_User::FormatThisUserSaveData service function
- * Inputs:
- * 0: 0x080F0180
- * 1 : Size in Blocks (1 block = 512 bytes)
- * 2 : Number of directories
- * 3 : Number of files
- * 4 : Directory bucket count
- * 5 : File bucket count
- * 6 : Duplicate data
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void FormatThisUserSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- FileSys::ArchiveFormatInfo format_info;
- format_info.duplicate_data = cmd_buff[6] & 0xFF;
- format_info.number_directories = cmd_buff[2];
- format_info.number_files = cmd_buff[3];
- format_info.total_size = cmd_buff[1] * 512;
-
- cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData, format_info).raw;
-
- LOG_TRACE(Service_FS, "called");
-}
-
-/**
- * FS_User::GetFreeBytes service function
- * Inputs:
- * 0: 0x08120080
- * 1: Archive handle low word
- * 2: Archive handle high word
- * Outputs:
- * 1: Result of function, 0 on success, otherwise error code
- * 2: Free byte count low word
- * 3: Free byte count high word
- */
-static void GetFreeBytes(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[1], cmd_buff[2]);
- ResultVal<u64> bytes_res = GetFreeBytesInArchive(archive_handle);
-
- cmd_buff[1] = bytes_res.Code().raw;
- if (bytes_res.Succeeded()) {
- cmd_buff[2] = (u32)*bytes_res;
- cmd_buff[3] = *bytes_res >> 32;
- } else {
- cmd_buff[2] = 0;
- cmd_buff[3] = 0;
- }
-}
-
-/**
- * FS_User::CreateExtSaveData service function
- * Inputs:
- * 0 : 0x08510242
- * 1 : Media type (NAND / SDMC)
- * 2 : Low word of the saveid to create
- * 3 : High word of the saveid to create
- * 4 : Unknown
- * 5 : Number of directories
- * 6 : Number of files
- * 7-8 : Size limit
- * 9 : Size of the SMDH icon
- * 10: (SMDH Size << 4) | 0x0000000A
- * 11: Pointer to the SMDH icon for the new ExtSaveData
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CreateExtSaveData(Service::Interface* self) {
- // TODO(Subv): Figure out the other parameters.
- u32* cmd_buff = Kernel::GetCommandBuffer();
- MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
- u32 save_low = cmd_buff[2];
- u32 save_high = cmd_buff[3];
- u32 icon_size = cmd_buff[9];
- VAddr icon_buffer = cmd_buff[11];
-
- LOG_WARNING(
- Service_FS,
- "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
- "cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
- "icon_size=%08X icon_descriptor=%08X icon_buffer=%08X",
- save_high, save_low, cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6], cmd_buff[7],
- cmd_buff[8], icon_size, cmd_buff[10], icon_buffer);
-
- FileSys::ArchiveFormatInfo format_info;
- format_info.number_directories = cmd_buff[5];
- format_info.number_files = cmd_buff[6];
- format_info.duplicate_data = false;
- format_info.total_size = 0;
- cmd_buff[1] =
- CreateExtSaveData(media_type, save_high, save_low, icon_buffer, icon_size, format_info).raw;
-}
-
-/**
- * FS_User::DeleteExtSaveData service function
- * Inputs:
- * 0 : 0x08520100
- * 1 : Media type (NAND / SDMC)
- * 2 : Low word of the saveid to create
- * 3 : High word of the saveid to create
- * 4 : Unknown
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void DeleteExtSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
- u32 save_low = cmd_buff[2];
- u32 save_high = cmd_buff[3];
- u32 unknown = cmd_buff[4]; // TODO(Subv): Figure out what this is
-
- LOG_WARNING(Service_FS, "(STUBBED) save_low=%08X save_high=%08X media_type=%08X unknown=%08X",
- save_low, save_high, cmd_buff[1] & 0xFF, unknown);
-
- cmd_buff[1] = DeleteExtSaveData(media_type, save_high, save_low).raw;
-}
-
-/**
- * FS_User::CardSlotIsInserted service function.
- * Inputs:
- * 0 : 0x08210000
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : Whether there is a game card inserted into the slot or not.
- */
-static void CardSlotIsInserted(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- cmd_buff[1] = RESULT_SUCCESS.raw;
- cmd_buff[2] = 0;
- LOG_WARNING(Service_FS, "(STUBBED) called");
-}
-
-/**
- * FS_User::DeleteSystemSaveData service function.
- * Inputs:
- * 0 : 0x08570080
- * 1 : High word of the SystemSaveData id to delete
- * 2 : Low word of the SystemSaveData id to delete
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void DeleteSystemSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- u32 savedata_high = cmd_buff[1];
- u32 savedata_low = cmd_buff[2];
-
- cmd_buff[1] = DeleteSystemSaveData(savedata_high, savedata_low).raw;
-}
-
-/**
- * FS_User::CreateSystemSaveData service function.
- * Inputs:
- * 0 : 0x08560240
- * 1 : u8 MediaType of the system save data
- * 2 : SystemSaveData id to create
- * 3 : Total size
- * 4 : Block size
- * 5 : Number of directories
- * 6 : Number of files
- * 7 : Directory bucket count
- * 8 : File bucket count
- * 9 : u8 Whether to duplicate data or not
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CreateSystemSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- u32 savedata_high = cmd_buff[1];
- u32 savedata_low = cmd_buff[2];
-
- LOG_WARNING(
- Service_FS,
- "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
- "cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
- "cmd_buff[9]=%08X",
- savedata_high, savedata_low, cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6],
- cmd_buff[7], cmd_buff[8], cmd_buff[9]);
-
- cmd_buff[1] = CreateSystemSaveData(savedata_high, savedata_low).raw;
-}
-
-/**
- * FS_User::CreateLegacySystemSaveData service function.
- * This function appears to be obsolete and seems to have been replaced by
- * command 0x08560240 (CreateSystemSaveData).
- *
- * Inputs:
- * 0 : 0x08100200
- * 1 : SystemSaveData id to create
- * 2 : Total size
- * 3 : Block size
- * 4 : Number of directories
- * 5 : Number of files
- * 6 : Directory bucket count
- * 7 : File bucket count
- * 8 : u8 Duplicate data
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void CreateLegacySystemSaveData(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
- u32 savedata_id = cmd_buff[1];
-
- LOG_WARNING(
- Service_FS,
- "(STUBBED) savedata_id=%08X cmd_buff[3]=%08X "
- "cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
- "cmd_buff[9]=%08X",
- savedata_id, cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6], cmd_buff[7], cmd_buff[8],
- cmd_buff[9]);
-
- cmd_buff[0] = IPC::MakeHeader(0x810, 0x1, 0);
- // With this command, the SystemSaveData always has save_high = 0 (Always created in the NAND)
- cmd_buff[1] = CreateSystemSaveData(0, savedata_id).raw;
-}
-
-/**
- * FS_User::InitializeWithSdkVersion service function.
- * Inputs:
- * 0 : 0x08610042
- * 1 : Used SDK Version
- * 2 : ProcessId Header
- * 3 : placeholder for ProcessId
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void InitializeWithSdkVersion(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- const u32 version = cmd_buff[1];
- self->SetVersion(version);
-
- if (cmd_buff[2] == IPC::CallingPidDesc()) {
- LOG_WARNING(Service_FS, "(STUBBED) called, version: 0x%08X", version);
- cmd_buff[1] = RESULT_SUCCESS.raw;
- } else {
- LOG_ERROR(Service_FS, "ProcessId Header must be 0x20");
- cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw;
- }
-}
-
-/**
- * FS_User::SetPriority service function.
- * Inputs:
- * 0 : 0x08620040
- * 1 : priority
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- */
-static void SetPriority(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- priority = cmd_buff[1];
-
- cmd_buff[1] = RESULT_SUCCESS.raw;
-
- LOG_DEBUG(Service_FS, "called priority=0x%X", priority);
-}
-
-/**
- * FS_User::GetPriority service function.
- * Inputs:
- * 0 : 0x08630000
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : priority
- */
-static void GetPriority(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- if (priority == -1) {
- LOG_INFO(Service_FS, "priority was not set, priority=0x%X", priority);
- }
-
- cmd_buff[1] = RESULT_SUCCESS.raw;
- cmd_buff[2] = priority;
-
- LOG_DEBUG(Service_FS, "called priority=0x%X", priority);
-}
-
-/**
- * FS_User::GetArchiveResource service function.
- * Inputs:
- * 0 : 0x08490040
- * 1 : Media type
- * Outputs:
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : Sector byte-size
- * 3 : Cluster byte-size
- * 4 : Partition capacity in clusters
- * 5 : Available free space in clusters
- */
-static void GetArchiveResource(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- LOG_WARNING(Service_FS, "(STUBBED) called Media type=0x%08X", cmd_buff[1]);
-
- cmd_buff[1] = RESULT_SUCCESS.raw;
- cmd_buff[2] = 512;
- cmd_buff[3] = 16384;
- cmd_buff[4] = 0x80000; // 8GiB capacity
- cmd_buff[5] = 0x80000; // 8GiB free
-}
-
-/**
- * FS_User::GetFormatInfo service function.
- * Inputs:
- * 0 : 0x084500C2
- * 1 : Archive ID
- * 2 : Archive path type
- * 3 : Archive path size
- * 4 : (PathSize << 14) | 2
- * 5 : Archive low path
- * Outputs:
- * 0 : 0x08450140
- * 1 : Result of function, 0 on success, otherwise error code
- * 2 : Total size
- * 3 : Number of directories
- * 4 : Number of files
- * 5 : Duplicate data
- */
-static void GetFormatInfo(Service::Interface* self) {
- u32* cmd_buff = Kernel::GetCommandBuffer();
-
- auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
- auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
- u32 archivename_size = cmd_buff[3];
- u32 archivename_ptr = cmd_buff[5];
- FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
-
- LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str());
-
- cmd_buff[0] = IPC::MakeHeader(0x0845, 5, 0);
-
- auto format_info = GetArchiveFormatInfo(archive_id, archive_path);
-
- if (format_info.Failed()) {
- LOG_ERROR(Service_FS, "Failed to retrieve the format info");
- cmd_buff[1] = format_info.Code().raw;
- return;
- }
-
- cmd_buff[1] = RESULT_SUCCESS.raw;
- cmd_buff[2] = format_info->total_size;
- cmd_buff[3] = format_info->number_directories;
- cmd_buff[4] = format_info->number_files;
- cmd_buff[5] = format_info->duplicate_data;
-}
-
-const Interface::FunctionInfo FunctionTable[] = {
- {0x000100C6, nullptr, "Dummy1"},
- {0x040100C4, nullptr, "Control"},
- {0x08010002, Initialize, "Initialize"},
- {0x080201C2, OpenFile, "OpenFile"},
- {0x08030204, OpenFileDirectly, "OpenFileDirectly"},
- {0x08040142, DeleteFile, "DeleteFile"},
- {0x08050244, RenameFile, "RenameFile"},
- {0x08060142, DeleteDirectory, "DeleteDirectory"},
- {0x08070142, DeleteDirectoryRecursively, "DeleteDirectoryRecursively"},
- {0x08080202, CreateFile, "CreateFile"},
- {0x08090182, CreateDirectory, "CreateDirectory"},
- {0x080A0244, RenameDirectory, "RenameDirectory"},
- {0x080B0102, OpenDirectory, "OpenDirectory"},
- {0x080C00C2, OpenArchive, "OpenArchive"},
- {0x080D0144, nullptr, "ControlArchive"},
- {0x080E0080, CloseArchive, "CloseArchive"},
- {0x080F0180, FormatThisUserSaveData, "FormatThisUserSaveData"},
- {0x08100200, CreateLegacySystemSaveData, "CreateLegacySystemSaveData"},
- {0x08110040, nullptr, "DeleteSystemSaveData"},
- {0x08120080, GetFreeBytes, "GetFreeBytes"},
- {0x08130000, nullptr, "GetCardType"},
- {0x08140000, nullptr, "GetSdmcArchiveResource"},
- {0x08150000, nullptr, "GetNandArchiveResource"},
- {0x08160000, nullptr, "GetSdmcFatfsError"},
- {0x08170000, IsSdmcDetected, "IsSdmcDetected"},
- {0x08180000, IsSdmcWriteable, "IsSdmcWritable"},
- {0x08190042, nullptr, "GetSdmcCid"},
- {0x081A0042, nullptr, "GetNandCid"},
- {0x081B0000, nullptr, "GetSdmcSpeedInfo"},
- {0x081C0000, nullptr, "GetNandSpeedInfo"},
- {0x081D0042, nullptr, "GetSdmcLog"},
- {0x081E0042, nullptr, "GetNandLog"},
- {0x081F0000, nullptr, "ClearSdmcLog"},
- {0x08200000, nullptr, "ClearNandLog"},
- {0x08210000, CardSlotIsInserted, "CardSlotIsInserted"},
- {0x08220000, nullptr, "CardSlotPowerOn"},
- {0x08230000, nullptr, "CardSlotPowerOff"},
- {0x08240000, nullptr, "CardSlotGetCardIFPowerStatus"},
- {0x08250040, nullptr, "CardNorDirectCommand"},
- {0x08260080, nullptr, "CardNorDirectCommandWithAddress"},
- {0x08270082, nullptr, "CardNorDirectRead"},
- {0x082800C2, nullptr, "CardNorDirectReadWithAddress"},
- {0x08290082, nullptr, "CardNorDirectWrite"},
- {0x082A00C2, nullptr, "CardNorDirectWriteWithAddress"},
- {0x082B00C2, nullptr, "CardNorDirectRead_4xIO"},
- {0x082C0082, nullptr, "CardNorDirectCpuWriteWithoutVerify"},
- {0x082D0040, nullptr, "CardNorDirectSectorEraseWithoutVerify"},
- {0x082E0040, nullptr, "GetProductInfo"},
- {0x082F0040, nullptr, "GetProgramLaunchInfo"},
- {0x08300182, nullptr, "CreateExtSaveData"},
- {0x08310180, nullptr, "CreateSharedExtSaveData"},
- {0x08320102, nullptr, "ReadExtSaveDataIcon"},
- {0x08330082, nullptr, "EnumerateExtSaveData"},
- {0x08340082, nullptr, "EnumerateSharedExtSaveData"},
- {0x08350080, nullptr, "DeleteExtSaveData"},
- {0x08360080, nullptr, "DeleteSharedExtSaveData"},
- {0x08370040, nullptr, "SetCardSpiBaudRate"},
- {0x08380040, nullptr, "SetCardSpiBusMode"},
- {0x08390000, nullptr, "SendInitializeInfoTo9"},
- {0x083A0100, nullptr, "GetSpecialContentIndex"},
- {0x083B00C2, nullptr, "GetLegacyRomHeader"},
- {0x083C00C2, nullptr, "GetLegacyBannerData"},
- {0x083D0100, nullptr, "CheckAuthorityToAccessExtSaveData"},
- {0x083E00C2, nullptr, "QueryTotalQuotaSize"},
- {0x083F00C0, nullptr, "GetExtDataBlockSize"},
- {0x08400040, nullptr, "AbnegateAccessRight"},
- {0x08410000, nullptr, "DeleteSdmcRoot"},
- {0x08420040, nullptr, "DeleteAllExtSaveDataOnNand"},
- {0x08430000, nullptr, "InitializeCtrFileSystem"},
- {0x08440000, nullptr, "CreateSeed"},
- {0x084500C2, GetFormatInfo, "GetFormatInfo"},
- {0x08460102, nullptr, "GetLegacyRomHeader2"},
- {0x08470180, nullptr, "FormatCtrCardUserSaveData"},
- {0x08480042, nullptr, "GetSdmcCtrRootPath"},
- {0x08490040, GetArchiveResource, "GetArchiveResource"},
- {0x084A0002, nullptr, "ExportIntegrityVerificationSeed"},
- {0x084B0002, nullptr, "ImportIntegrityVerificationSeed"},
- {0x084C0242, FormatSaveData, "FormatSaveData"},
- {0x084D0102, nullptr, "GetLegacySubBannerData"},
- {0x084E0342, nullptr, "UpdateSha256Context"},
- {0x084F0102, nullptr, "ReadSpecialFile"},
- {0x08500040, nullptr, "GetSpecialFileSize"},
- {0x08510242, CreateExtSaveData, "CreateExtSaveData"},
- {0x08520100, DeleteExtSaveData, "DeleteExtSaveData"},
- {0x08530142, nullptr, "ReadExtSaveDataIcon"},
- {0x085400C0, nullptr, "GetExtDataBlockSize"},
- {0x08550102, nullptr, "EnumerateExtSaveData"},
- {0x08560240, CreateSystemSaveData, "CreateSystemSaveData"},
- {0x08570080, DeleteSystemSaveData, "DeleteSystemSaveData"},
- {0x08580000, nullptr, "StartDeviceMoveAsSource"},
- {0x08590200, nullptr, "StartDeviceMoveAsDestination"},
- {0x085A00C0, nullptr, "SetArchivePriority"},
- {0x085B0080, nullptr, "GetArchivePriority"},
- {0x085C00C0, nullptr, "SetCtrCardLatencyParameter"},
- {0x085D01C0, nullptr, "SetFsCompatibilityInfo"},
- {0x085E0040, nullptr, "ResetCardCompatibilityParameter"},
- {0x085F0040, nullptr, "SwitchCleanupInvalidSaveData"},
- {0x08600042, nullptr, "EnumerateSystemSaveData"},
- {0x08610042, InitializeWithSdkVersion, "InitializeWithSdkVersion"},
- {0x08620040, SetPriority, "SetPriority"},
- {0x08630000, GetPriority, "GetPriority"},
- {0x08640000, nullptr, "GetNandInfo"},
- {0x08650140, nullptr, "SetSaveDataSecureValue"},
- {0x086600C0, nullptr, "GetSaveDataSecureValue"},
- {0x086700C4, nullptr, "ControlSecureSave"},
- {0x08680000, nullptr, "GetMediaType"},
- {0x08690000, nullptr, "GetNandEraseCount"},
- {0x086A0082, nullptr, "ReadNandReport"},
- {0x087A0180, nullptr, "AddSeed"},
- {0x088600C0, nullptr, "CheckUpdatedDat"},
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// Interface class
-
-Interface::Interface() {
-
- priority = -1;
- Register(FunctionTable);
-}
-
-} // namespace FS
-} // namespace Service
diff --git a/src/core/hle/service/fs/fs_user.h b/src/core/hle/service/fs/fs_user.h
deleted file mode 100644
index bb6ab195e..000000000
--- a/src/core/hle/service/fs/fs_user.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "core/hle/service/service.h"
-
-namespace Service {
-namespace FS {
-
-/// Interface to "fs:USER" service
-class Interface : public Service::Interface {
-public:
- Interface();
-
- std::string GetPortName() const override {
- return "fs:USER";
- }
-};
-
-} // namespace FS
-} // namespace Service