Services/AM: Support using FS subfiles with the CIA-related service functions.

FS subfiles are created with File::OpenSubFile, they have a start offset that must be added to all read/write operations.

The implementation in this commit is done using a new FileBackend that wraps the FS::File along with the start offset.
This commit is contained in:
Subv 2018-10-02 08:52:00 -05:00
parent fb720c00b7
commit 5165b63512
3 changed files with 73 additions and 22 deletions

View file

@ -307,6 +307,18 @@ Kernel::SharedPtr<Kernel::ClientSession> File::Connect() {
return std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions);
}
std::size_t File::GetSessionFileOffset(Kernel::SharedPtr<Kernel::ServerSession> session) {
const FileSessionSlot* slot = GetSessionData(session);
ASSERT(slot);
return slot->offset;
}
std::size_t File::GetSessionFileSize(Kernel::SharedPtr<Kernel::ServerSession> session) {
const FileSessionSlot* slot = GetSessionData(session);
ASSERT(slot);
return slot->size;
}
Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
const FileSys::Path& path)
: ServiceFramework("", 1), path(path), backend(std::move(backend)) {

View file

@ -73,6 +73,14 @@ public:
/// Creates a new session to this File and returns the ClientSession part of the connection.
Kernel::SharedPtr<Kernel::ClientSession> Connect();
// Returns the start offset of an open file represented by the input session, opened with
// OpenSubFile.
std::size_t GetSessionFileOffset(Kernel::SharedPtr<Kernel::ServerSession> session);
// Returns the size of an open file represented by the input session, opened with
// OpenSubFile.
std::size_t GetSessionFileSize(Kernel::SharedPtr<Kernel::ServerSession> session);
private:
void Read(Kernel::HLERequestContext& ctx);
void Write(Kernel::HLERequestContext& ctx);