|
|
@ -20,9 +20,8 @@ public: |
|
|
IStorage(std::unique_ptr<FileSys::StorageBackend>&& backend) |
|
|
IStorage(std::unique_ptr<FileSys::StorageBackend>&& backend) |
|
|
: ServiceFramework("IStorage"), backend(std::move(backend)) { |
|
|
: ServiceFramework("IStorage"), backend(std::move(backend)) { |
|
|
static const FunctionInfo functions[] = { |
|
|
static const FunctionInfo functions[] = { |
|
|
{0, &IStorage::Read, "Read"}, {1, &IStorage::Write, "Write"}, |
|
|
|
|
|
{2, &IStorage::Flush, "Flush"}, {3, &IStorage::SetSize, "SetSize"}, |
|
|
|
|
|
{4, &IStorage::GetSize, "GetSize"}, |
|
|
|
|
|
|
|
|
{0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, {2, nullptr, "Flush"}, |
|
|
|
|
|
{3, nullptr, "SetSize"}, {4, nullptr, "GetSize"}, |
|
|
}; |
|
|
}; |
|
|
RegisterHandlers(functions); |
|
|
RegisterHandlers(functions); |
|
|
} |
|
|
} |
|
|
@ -32,48 +31,39 @@ private: |
|
|
|
|
|
|
|
|
void Read(Kernel::HLERequestContext& ctx) { |
|
|
void Read(Kernel::HLERequestContext& ctx) { |
|
|
IPC::RequestParser rp{ctx}; |
|
|
IPC::RequestParser rp{ctx}; |
|
|
u64 offset = rp.Pop<u64>(); |
|
|
|
|
|
u64 length = rp.Pop<u64>(); |
|
|
|
|
|
|
|
|
const s64 offset = rp.Pop<s64>(); |
|
|
|
|
|
const s64 length = rp.Pop<s64>(); |
|
|
|
|
|
const auto& descriptor = ctx.BufferDescriptorB()[0]; |
|
|
|
|
|
|
|
|
LOG_DEBUG(Service, "called, offset=0x%llx, length=0x%llx", offset, length); |
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_FS, "called, offset=0x%llx, length=0x%llx", offset, length); |
|
|
|
|
|
|
|
|
auto descriptor = ctx.BufferDescriptorB()[0]; |
|
|
|
|
|
std::vector<u8> output(length); |
|
|
|
|
|
|
|
|
|
|
|
ResultVal<size_t> res = backend->Read(offset, length, output.data()); |
|
|
|
|
|
if (res.Failed()) { |
|
|
|
|
|
|
|
|
// Error checking
|
|
|
|
|
|
ASSERT_MSG(length == descriptor.Size(), "unexpected size difference"); |
|
|
|
|
|
if (length < 0) { |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(res.Code()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Memory::WriteBlock(descriptor.Address(), output.data(), descriptor.Size()); |
|
|
|
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
|
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
|
|
|
rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength)); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Write(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
|
|
|
if (offset < 0) { |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
|
|
|
rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset)); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Flush(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
|
|
|
// Read the data from the Storage backend
|
|
|
|
|
|
std::vector<u8> output(length); |
|
|
|
|
|
ResultVal<size_t> res = backend->Read(offset, length, output.data()); |
|
|
|
|
|
if (res.Failed()) { |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
|
|
|
rb.Push(res.Code()); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SetSize(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
|
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Write the data to memory
|
|
|
|
|
|
Memory::WriteBlock(descriptor.Address(), output.data(), descriptor.Size()); |
|
|
|
|
|
|
|
|
void GetSize(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
@ -87,46 +77,62 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { |
|
|
RegisterHandlers(functions); |
|
|
RegisterHandlers(functions); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSP_SRV::TryLoadRomFS() { |
|
|
|
|
|
if (romfs) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
FileSys::Path unused; |
|
|
|
|
|
auto res = OpenFileSystem(Type::RomFS, unused); |
|
|
|
|
|
if (res.Succeeded()) { |
|
|
|
|
|
romfs = std::move(res.Unwrap()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void FSP_SRV::Initalize(Kernel::HLERequestContext& ctx) { |
|
|
void FSP_SRV::Initalize(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { |
|
|
void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 4}; |
|
|
IPC::RequestBuilder rb{ctx, 4}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.Push<u32>(5); |
|
|
rb.Push<u32>(5); |
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { |
|
|
void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { |
|
|
FileSys::Path path; |
|
|
|
|
|
auto filesystem = OpenFileSystem(Type::RomFS, path); |
|
|
|
|
|
if (filesystem.Failed()) { |
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_FS, "called"); |
|
|
|
|
|
|
|
|
|
|
|
TryLoadRomFS(); |
|
|
|
|
|
if (!romfs) { |
|
|
|
|
|
// TODO (bunnei): Find the right error code to use here
|
|
|
|
|
|
LOG_CRITICAL(Service_FS, "no file system interface available!"); |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(filesystem.Code()); |
|
|
|
|
|
|
|
|
rb.Push(ResultCode(-1)); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
auto storage = filesystem.Unwrap()->OpenFile({}, {}); |
|
|
|
|
|
|
|
|
// Attempt to open a StorageBackend interface to the RomFS
|
|
|
|
|
|
auto storage = romfs->OpenFile({}, {}); |
|
|
if (storage.Failed()) { |
|
|
if (storage.Failed()) { |
|
|
|
|
|
LOG_CRITICAL(Service_FS, "no storage interface available!"); |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
IPC::RequestBuilder rb{ctx, 2}; |
|
|
rb.Push(storage.Code()); |
|
|
rb.Push(storage.Code()); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: What if already opened?
|
|
|
|
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; |
|
|
IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.Push(RESULT_SUCCESS); |
|
|
rb.PushIpcInterface<IStorage>(std::move(storage.Unwrap())); |
|
|
rb.PushIpcInterface<IStorage>(std::move(storage.Unwrap())); |
|
|
LOG_WARNING(Service, "(STUBBED) called"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { |
|
|
void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
LOG_WARNING(Service_FS, "(STUBBED) called, using OpenDataStorageByCurrentProcess"); |
|
|
OpenDataStorageByCurrentProcess(ctx); |
|
|
OpenDataStorageByCurrentProcess(ctx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} // namespace Filesystem
|
|
|
|
|
|
|
|
|
} // namespace FileSystem
|
|
|
} // namespace Service
|
|
|
} // namespace Service
|