Address review comments
This commit is contained in:
parent
fc7e6c9cc9
commit
5055a6c262
|
@ -11,8 +11,8 @@
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
#include "core/file_sys/delay_generator.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
#include "delay_generator.h"
|
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
|
@ -155,15 +155,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual u64 GetFreeBytes() const = 0;
|
virtual u64 GetFreeBytes() const = 0;
|
||||||
|
|
||||||
u64 GetReadDelayNs(std::size_t length) {
|
|
||||||
if (delay_generator != nullptr) {
|
|
||||||
return delay_generator->GetReadDelayNs(length);
|
|
||||||
}
|
|
||||||
LOG_ERROR(Service_FS, "Delay generator was not initalized. Using default");
|
|
||||||
delay_generator = std::make_unique<DefaultDelayGenerator>();
|
|
||||||
return delay_generator->GetReadDelayNs(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 GetOpenDelayNs() {
|
u64 GetOpenDelayNs() {
|
||||||
if (delay_generator != nullptr) {
|
if (delay_generator != nullptr) {
|
||||||
return delay_generator->GetOpenDelayNs();
|
return delay_generator->GetOpenDelayNs();
|
||||||
|
|
|
@ -77,19 +77,21 @@ ResultCode ArchiveManager::RegisterArchiveType(std::unique_ptr<FileSys::ArchiveF
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<File>> ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle,
|
std::tuple<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds>
|
||||||
const FileSys::Path& path,
|
ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
|
||||||
const FileSys::Mode mode) {
|
const FileSys::Mode mode) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
|
return std::make_tuple(FileSys::ERR_INVALID_ARCHIVE_HANDLE,
|
||||||
|
static_cast<std::chrono::nanoseconds>(0));
|
||||||
|
|
||||||
|
std::chrono::nanoseconds open_timeout_ns{archive->GetOpenDelayNs()};
|
||||||
auto backend = archive->OpenFile(path, mode);
|
auto backend = archive->OpenFile(path, mode);
|
||||||
if (backend.Failed())
|
if (backend.Failed())
|
||||||
return backend.Code();
|
return std::make_tuple(backend.Code(), open_timeout_ns);
|
||||||
|
|
||||||
auto file = std::shared_ptr<File>(new File(system, std::move(backend).Unwrap(), path));
|
auto file = std::shared_ptr<File>(new File(system, std::move(backend).Unwrap(), path));
|
||||||
return MakeResult<std::shared_ptr<File>>(std::move(file));
|
return std::make_tuple(MakeResult<std::shared_ptr<File>>(std::move(file)), open_timeout_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveManager::DeleteFileFromArchive(ArchiveHandle archive_handle,
|
ResultCode ArchiveManager::DeleteFileFromArchive(ArchiveHandle archive_handle,
|
||||||
|
|
|
@ -77,11 +77,10 @@ public:
|
||||||
* @param archive_handle Handle to an open Archive object
|
* @param archive_handle Handle to an open Archive object
|
||||||
* @param path Path to the File inside of the Archive
|
* @param path Path to the File inside of the Archive
|
||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return The opened File object
|
* @return Tuple of the opened File object and the open delay
|
||||||
*/
|
*/
|
||||||
ResultVal<std::shared_ptr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
|
std::tuple<ResultVal<std::shared_ptr<File>>, std::chrono::nanoseconds> OpenFileFromArchive(
|
||||||
const FileSys::Path& path,
|
ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
|
||||||
const FileSys::Mode mode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a File from an Archive
|
* Delete a File from an Archive
|
||||||
|
@ -234,8 +233,6 @@ public:
|
||||||
/// Registers a new NCCH file with the SelfNCCH archive factory
|
/// Registers a new NCCH file with the SelfNCCH archive factory
|
||||||
void RegisterSelfNCCH(Loader::AppLoader& app_loader);
|
void RegisterSelfNCCH(Loader::AppLoader& app_loader);
|
||||||
|
|
||||||
ArchiveBackend* GetArchive(ArchiveHandle handle);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
|
|
||||||
|
@ -250,6 +247,8 @@ private:
|
||||||
/// Register all archive types
|
/// Register all archive types
|
||||||
void RegisterArchiveTypes();
|
void RegisterArchiveTypes();
|
||||||
|
|
||||||
|
ArchiveBackend* GetArchive(ArchiveHandle handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of registered archives, identified by id code. Once an archive is registered here, it is
|
* Map of registered archives, identified by id code. Once an archive is registered here, it is
|
||||||
* never removed until UnregisterArchiveTypes is called.
|
* never removed until UnregisterArchiveTypes is called.
|
||||||
|
|
|
@ -71,10 +71,10 @@ void File::Read(Kernel::HLERequestContext& ctx) {
|
||||||
rb.PushMappedBuffer(buffer);
|
rb.PushMappedBuffer(buffer);
|
||||||
|
|
||||||
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
|
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
|
||||||
ctx.SleepClientThread(system.Kernel().GetThreadManager().GetCurrentThread(), "file::read",
|
ctx.SleepClientThread(
|
||||||
read_timeout_ns,
|
system.Kernel().GetThreadManager().GetCurrentThread(), "file::read", read_timeout_ns,
|
||||||
[](Kernel::SharedPtr<Kernel::Thread> thread,
|
[](Kernel::SharedPtr<Kernel::Thread> /*thread*/, Kernel::HLERequestContext& /*ctx*/,
|
||||||
Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) {
|
Kernel::ThreadWakeupReason /*reason*/) {
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ void FS_USER::OpenFile(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_FS, "path={}, mode={} attrs={}", file_path.DebugStr(), mode.hex, attributes);
|
LOG_DEBUG(Service_FS, "path={}, mode={} attrs={}", file_path.DebugStr(), mode.hex, attributes);
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<File>> file_res =
|
const auto [file_res, open_timeout_ns] =
|
||||||
archives.OpenFileFromArchive(archive_handle, file_path, mode);
|
archives.OpenFileFromArchive(archive_handle, file_path, mode);
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
rb.Push(file_res.Code());
|
rb.Push(file_res.Code());
|
||||||
|
@ -72,15 +72,10 @@ void FS_USER::OpenFile(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for file {}", file_path.DebugStr());
|
LOG_ERROR(Service_FS, "failed to get a handle for file {}", file_path.DebugStr());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto archive = archives.GetArchive(archive_handle);
|
ctx.SleepClientThread(
|
||||||
if (archive == nullptr)
|
system.Kernel().GetThreadManager().GetCurrentThread(), "fs_user::open", open_timeout_ns,
|
||||||
return;
|
[](Kernel::SharedPtr<Kernel::Thread> /*thread*/, Kernel::HLERequestContext& /*ctx*/,
|
||||||
|
Kernel::ThreadWakeupReason /*reason*/) {
|
||||||
std::chrono::nanoseconds open_timeout_ns{archive->GetOpenDelayNs()};
|
|
||||||
ctx.SleepClientThread(system.Kernel().GetThreadManager().GetCurrentThread(), "fs_user::open",
|
|
||||||
open_timeout_ns,
|
|
||||||
[](Kernel::SharedPtr<Kernel::Thread> thread,
|
|
||||||
Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) {
|
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -123,7 +118,7 @@ void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) {
|
||||||
}
|
}
|
||||||
SCOPE_EXIT({ archives.CloseArchive(*archive_handle); });
|
SCOPE_EXIT({ archives.CloseArchive(*archive_handle); });
|
||||||
|
|
||||||
ResultVal<std::shared_ptr<File>> file_res =
|
const auto [file_res, open_timeout_ns] =
|
||||||
archives.OpenFileFromArchive(*archive_handle, file_path, mode);
|
archives.OpenFileFromArchive(*archive_handle, file_path, mode);
|
||||||
rb.Push(file_res.Code());
|
rb.Push(file_res.Code());
|
||||||
if (file_res.Succeeded()) {
|
if (file_res.Succeeded()) {
|
||||||
|
@ -134,6 +129,14 @@ void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_ERROR(Service_FS, "failed to get a handle for file {} mode={} attributes={}",
|
LOG_ERROR(Service_FS, "failed to get a handle for file {} mode={} attributes={}",
|
||||||
file_path.DebugStr(), mode.hex, attributes);
|
file_path.DebugStr(), mode.hex, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.SleepClientThread(system.Kernel().GetThreadManager().GetCurrentThread(),
|
||||||
|
"fs_user::open_directly", open_timeout_ns,
|
||||||
|
[](Kernel::SharedPtr<Kernel::Thread> /*thread*/,
|
||||||
|
Kernel::HLERequestContext& /*ctx*/,
|
||||||
|
Kernel::ThreadWakeupReason /*reason*/) {
|
||||||
|
// Nothing to do here
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FS_USER::DeleteFile(Kernel::HLERequestContext& ctx) {
|
void FS_USER::DeleteFile(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
Reference in New Issue