2018-09-28 14:45:35 +00:00
|
|
|
// Copyright 2018 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/file_sys/archive_backend.h"
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2018-10-13 20:11:20 +00:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-09-28 14:45:35 +00:00
|
|
|
namespace Service::FS {
|
|
|
|
|
|
|
|
struct FileSessionSlot : public Kernel::SessionRequestHandler::SessionDataBase {
|
|
|
|
u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
|
|
|
|
u64 offset; ///< Offset that this session will start reading from.
|
|
|
|
u64 size; ///< Max size of the file that this session is allowed to access
|
|
|
|
bool subfile; ///< Whether this file was opened via OpenSubFile or not.
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: File is not a real service, but it can still utilize ServiceFramework::RegisterHandlers.
|
|
|
|
// Consider splitting ServiceFramework interface.
|
|
|
|
class File final : public ServiceFramework<File, FileSessionSlot> {
|
|
|
|
public:
|
2018-10-13 20:11:20 +00:00
|
|
|
File(Core::System& system, std::unique_ptr<FileSys::FileBackend>&& backend,
|
|
|
|
const FileSys::Path& path);
|
2018-09-28 14:45:35 +00:00
|
|
|
~File() = default;
|
|
|
|
|
|
|
|
std::string GetName() const {
|
|
|
|
return "Path: " + path.DebugStr();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSys::Path path; ///< Path of the file
|
|
|
|
std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
|
|
|
|
|
|
|
|
/// Creates a new session to this File and returns the ClientSession part of the connection.
|
2019-03-23 20:04:19 +00:00
|
|
|
std::shared_ptr<Kernel::ClientSession> Connect();
|
2018-09-28 14:45:35 +00:00
|
|
|
|
|
|
|
// Returns the start offset of an open file represented by the input session, opened with
|
|
|
|
// OpenSubFile.
|
2019-03-23 20:04:19 +00:00
|
|
|
std::size_t GetSessionFileOffset(std::shared_ptr<Kernel::ServerSession> session);
|
2018-09-28 14:45:35 +00:00
|
|
|
|
|
|
|
// Returns the size of an open file represented by the input session, opened with
|
|
|
|
// OpenSubFile.
|
2019-03-23 20:04:19 +00:00
|
|
|
std::size_t GetSessionFileSize(std::shared_ptr<Kernel::ServerSession> session);
|
2018-09-28 14:45:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Read(Kernel::HLERequestContext& ctx);
|
|
|
|
void Write(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetSize(Kernel::HLERequestContext& ctx);
|
|
|
|
void SetSize(Kernel::HLERequestContext& ctx);
|
|
|
|
void Close(Kernel::HLERequestContext& ctx);
|
|
|
|
void Flush(Kernel::HLERequestContext& ctx);
|
|
|
|
void SetPriority(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetPriority(Kernel::HLERequestContext& ctx);
|
|
|
|
void OpenLinkFile(Kernel::HLERequestContext& ctx);
|
|
|
|
void OpenSubFile(Kernel::HLERequestContext& ctx);
|
2018-10-13 20:11:20 +00:00
|
|
|
|
|
|
|
Core::System& system;
|
2018-09-28 14:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Service::FS
|