mirror of
https://github.com/citra-mirror/citra.git
synced 2024-08-21 10:53:23 +02:00
Archives: Expose the File and Directory classes to HLE
This commit is contained in:
parent
ca1a87ef7d
commit
071663e074
@ -20,7 +20,6 @@
|
|||||||
#include "core/file_sys/archive_sdmc.h"
|
#include "core/file_sys/archive_sdmc.h"
|
||||||
#include "core/file_sys/directory_backend.h"
|
#include "core/file_sys/directory_backend.h"
|
||||||
#include "core/hle/service/fs/archive.h"
|
#include "core/hle/service/fs/archive.h"
|
||||||
#include "core/hle/kernel/session.h"
|
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
// Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
|
// Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
|
||||||
@ -76,31 +75,19 @@ enum class DirectoryCommand : u32 {
|
|||||||
Close = 0x08020000,
|
Close = 0x08020000,
|
||||||
};
|
};
|
||||||
|
|
||||||
class File : public Kernel::Session {
|
ResultVal<bool> File::SyncRequest() {
|
||||||
public:
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||||
File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path)
|
FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
|
||||||
: path(path), priority(0), backend(std::move(backend)) {
|
switch (cmd) {
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetName() const override { 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
|
|
||||||
|
|
||||||
ResultVal<bool> SyncRequest() override {
|
|
||||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
||||||
FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
|
|
||||||
switch (cmd) {
|
|
||||||
|
|
||||||
// Read from file...
|
// Read from file...
|
||||||
case FileCommand::Read:
|
case FileCommand::Read:
|
||||||
{
|
{
|
||||||
u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32;
|
u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
|
||||||
u32 length = cmd_buff[3];
|
u32 length = cmd_buff[3];
|
||||||
u32 address = cmd_buff[5];
|
u32 address = cmd_buff[5];
|
||||||
LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x",
|
LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x",
|
||||||
GetTypeName().c_str(), GetName().c_str(), offset, length, address);
|
GetTypeName().c_str(), GetName().c_str(), offset, length, address);
|
||||||
cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address));
|
cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -108,12 +95,12 @@ public:
|
|||||||
// Write to file...
|
// Write to file...
|
||||||
case FileCommand::Write:
|
case FileCommand::Write:
|
||||||
{
|
{
|
||||||
u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32;
|
u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
|
||||||
u32 length = cmd_buff[3];
|
u32 length = cmd_buff[3];
|
||||||
u32 flush = cmd_buff[4];
|
u32 flush = cmd_buff[4];
|
||||||
u32 address = cmd_buff[6];
|
u32 address = cmd_buff[6];
|
||||||
LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
|
LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
|
||||||
GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
|
GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
|
||||||
cmd_buff[2] = backend->Write(offset, length, flush, Memory::GetPointer(address));
|
cmd_buff[2] = backend->Write(offset, length, flush, Memory::GetPointer(address));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -131,7 +118,7 @@ public:
|
|||||||
{
|
{
|
||||||
u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
|
u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
|
||||||
LOG_TRACE(Service_FS, "SetSize %s %s size=%llu",
|
LOG_TRACE(Service_FS, "SetSize %s %s size=%llu",
|
||||||
GetTypeName().c_str(), GetName().c_str(), size);
|
GetTypeName().c_str(), GetName().c_str(), size);
|
||||||
backend->SetSize(size);
|
backend->SetSize(size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -177,27 +164,15 @@ public:
|
|||||||
ResultCode error = UnimplementedFunction(ErrorModule::FS);
|
ResultCode error = UnimplementedFunction(ErrorModule::FS);
|
||||||
cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
|
cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
|
||||||
return error;
|
return error;
|
||||||
}
|
|
||||||
cmd_buff[1] = 0; // No error
|
|
||||||
return MakeResult<bool>(false);
|
|
||||||
}
|
}
|
||||||
};
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
||||||
|
return MakeResult<bool>(false);
|
||||||
|
}
|
||||||
|
|
||||||
class Directory : public Kernel::Session {
|
ResultVal<bool> Directory::SyncRequest() {
|
||||||
public:
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||||
Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path)
|
DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
|
||||||
: path(path), backend(std::move(backend)) {
|
switch (cmd) {
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetName() const override { return "Directory: " + path.DebugStr(); }
|
|
||||||
|
|
||||||
FileSys::Path path; ///< Path of the directory
|
|
||||||
std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
|
|
||||||
|
|
||||||
ResultVal<bool> SyncRequest() override {
|
|
||||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
||||||
DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
|
|
||||||
switch (cmd) {
|
|
||||||
|
|
||||||
// Read from directory...
|
// Read from directory...
|
||||||
case DirectoryCommand::Read:
|
case DirectoryCommand::Read:
|
||||||
@ -206,7 +181,7 @@ public:
|
|||||||
u32 address = cmd_buff[3];
|
u32 address = cmd_buff[3];
|
||||||
auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
|
auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
|
||||||
LOG_TRACE(Service_FS, "Read %s %s: count=%d",
|
LOG_TRACE(Service_FS, "Read %s %s: count=%d",
|
||||||
GetTypeName().c_str(), GetName().c_str(), count);
|
GetTypeName().c_str(), GetName().c_str(), count);
|
||||||
|
|
||||||
// Number of entries actually read
|
// Number of entries actually read
|
||||||
cmd_buff[2] = backend->Read(count, entries);
|
cmd_buff[2] = backend->Read(count, entries);
|
||||||
@ -226,11 +201,10 @@ public:
|
|||||||
ResultCode error = UnimplementedFunction(ErrorModule::FS);
|
ResultCode error = UnimplementedFunction(ErrorModule::FS);
|
||||||
cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
|
cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
|
||||||
return MakeResult<bool>(false);
|
return MakeResult<bool>(false);
|
||||||
}
|
|
||||||
cmd_buff[1] = 0; // No error
|
|
||||||
return MakeResult<bool>(false);
|
|
||||||
}
|
}
|
||||||
};
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
||||||
|
return MakeResult<bool>(false);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -294,7 +268,7 @@ ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factor
|
|||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
||||||
const FileSys::Path& path, const FileSys::Mode mode) {
|
const FileSys::Path& path, const FileSys::Mode mode) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
@ -307,7 +281,7 @@ ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path));
|
auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path));
|
||||||
return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(file));
|
return MakeResult<Kernel::SharedPtr<File>>(std::move(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
|
ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
|
||||||
@ -393,7 +367,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
|
|||||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
||||||
const FileSys::Path& path) {
|
const FileSys::Path& path) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
@ -406,7 +380,7 @@ ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
|
auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
|
||||||
return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(directory));
|
return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode FormatSaveData() {
|
ResultCode FormatSaveData() {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "core/file_sys/archive_backend.h"
|
#include "core/file_sys/archive_backend.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/session.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
/// The unique system identifier hash, also known as ID0
|
/// The unique system identifier hash, also known as ID0
|
||||||
@ -36,6 +37,35 @@ enum class ArchiveIdCode : u32 {
|
|||||||
|
|
||||||
typedef u64 ArchiveHandle;
|
typedef u64 ArchiveHandle;
|
||||||
|
|
||||||
|
class File : public Kernel::Session {
|
||||||
|
public:
|
||||||
|
File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path)
|
||||||
|
: path(path), priority(0), backend(std::move(backend)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetName() const override { 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
|
||||||
|
|
||||||
|
ResultVal<bool> SyncRequest() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Directory : public Kernel::Session {
|
||||||
|
public:
|
||||||
|
Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path)
|
||||||
|
: path(path), backend(std::move(backend)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetName() const override { return "Directory: " + path.DebugStr(); }
|
||||||
|
|
||||||
|
FileSys::Path path; ///< Path of the directory
|
||||||
|
std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
|
||||||
|
|
||||||
|
ResultVal<bool> SyncRequest() override;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens an archive
|
* Opens an archive
|
||||||
* @param id_code IdCode of the archive to open
|
* @param id_code IdCode of the archive to open
|
||||||
@ -64,7 +94,7 @@ ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factor
|
|||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return The opened File object as a Session
|
* @return The opened File object as a Session
|
||||||
*/
|
*/
|
||||||
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
||||||
const FileSys::Path& path, const FileSys::Mode mode);
|
const FileSys::Path& path, const FileSys::Mode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,7 +158,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
|
|||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return The opened Directory object as a Session
|
* @return The opened Directory object as a Session
|
||||||
*/
|
*/
|
||||||
ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
|
||||||
const FileSys::Path& path);
|
const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,7 @@ static void OpenFile(Service::Interface* self) {
|
|||||||
|
|
||||||
LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);
|
LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);
|
||||||
|
|
||||||
ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(archive_handle, file_path, mode);
|
ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(archive_handle, file_path, mode);
|
||||||
cmd_buff[1] = file_res.Code().raw;
|
cmd_buff[1] = file_res.Code().raw;
|
||||||
if (file_res.Succeeded()) {
|
if (file_res.Succeeded()) {
|
||||||
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
||||||
@ -117,7 +117,7 @@ static void OpenFileDirectly(Service::Interface* self) {
|
|||||||
}
|
}
|
||||||
SCOPE_EXIT({ CloseArchive(*archive_handle); });
|
SCOPE_EXIT({ CloseArchive(*archive_handle); });
|
||||||
|
|
||||||
ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode);
|
ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode);
|
||||||
cmd_buff[1] = file_res.Code().raw;
|
cmd_buff[1] = file_res.Code().raw;
|
||||||
if (file_res.Succeeded()) {
|
if (file_res.Succeeded()) {
|
||||||
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
|
||||||
@ -337,7 +337,7 @@ static void OpenDirectory(Service::Interface* self) {
|
|||||||
|
|
||||||
LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
ResultVal<SharedPtr<Session>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path);
|
ResultVal<SharedPtr<Directory>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path);
|
||||||
cmd_buff[1] = dir_res.Code().raw;
|
cmd_buff[1] = dir_res.Code().raw;
|
||||||
if (dir_res.Succeeded()) {
|
if (dir_res.Succeeded()) {
|
||||||
cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom();
|
cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom();
|
||||||
|
Loading…
Reference in New Issue
Block a user