// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "core/file_sys/errors.h" #include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/fsp/fs_i_file.h" namespace Service::FileSystem { IFile::IFile(Core::System& system_, FileSys::VirtualFile file_) : ServiceFramework{system_, "IFile"}, backend{std::make_unique(file_)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IFile::Read>, "Read"}, {1, D<&IFile::Write>, "Write"}, {2, D<&IFile::Flush>, "Flush"}, {3, D<&IFile::SetSize>, "SetSize"}, {4, D<&IFile::GetSize>, "GetSize"}, {5, nullptr, "OperateRange"}, {6, nullptr, "OperateRangeWithBuffer"}, }; // clang-format on RegisterHandlers(functions); } Result IFile::Read( FileSys::ReadOption option, Out out_size, s64 offset, const OutBuffer out_buffer, s64 size) { LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, size); // Read the data from the Storage backend R_RETURN( backend->Read(reinterpret_cast(out_size.Get()), offset, out_buffer.data(), size)); } Result IFile::Write( const InBuffer buffer, FileSys::WriteOption option, s64 offset, s64 size) { LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, size); R_RETURN(backend->Write(offset, buffer.data(), size, option)); } Result IFile::Flush() { LOG_DEBUG(Service_FS, "called"); R_RETURN(backend->Flush()); } Result IFile::SetSize(s64 size) { LOG_DEBUG(Service_FS, "called, size={}", size); R_RETURN(backend->SetSize(size)); } Result IFile::GetSize(Out out_size) { LOG_DEBUG(Service_FS, "called"); R_RETURN(backend->GetSize(out_size)); } } // namespace Service::FileSystem