2021-02-11 13:47:41 +00:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-02-11 13:47:41 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "../htclow/htclow_manager.hpp"
|
|
|
|
#include "../htclow/htclow_channel.hpp"
|
|
|
|
#include "htcfs_cache_manager.hpp"
|
|
|
|
#include "htcfs_header_factory.hpp"
|
2021-02-13 13:39:02 +00:00
|
|
|
#include "../htclow/htclow_default_channel_config.hpp"
|
2021-02-11 13:47:41 +00:00
|
|
|
|
|
|
|
namespace ams::htcfs {
|
|
|
|
|
|
|
|
class ClientImpl {
|
2021-02-13 13:39:02 +00:00
|
|
|
public:
|
|
|
|
static constexpr size_t MaxPacketBodySize = htclow::DefaultChannelConfig.max_packet_size - sizeof(htclow::PacketHeader);
|
2021-02-11 13:47:41 +00:00
|
|
|
private:
|
|
|
|
u8 m_receive_buffer[0x1C040];
|
|
|
|
u8 m_send_buffer[0x1C040];
|
2021-02-13 13:39:02 +00:00
|
|
|
u8 m_packet_buffer[MaxPacketBodySize + sizeof(htclow::PacketHeader)];
|
2021-02-11 13:47:41 +00:00
|
|
|
htclow::HtclowManager *m_htclow_manager;
|
|
|
|
CacheManager m_cache_manager;
|
|
|
|
HeaderFactory m_header_factory;
|
|
|
|
os::SdkMutex m_mutex;
|
|
|
|
htclow::Module m_module;
|
2021-02-12 14:08:16 +00:00
|
|
|
htclow::Channel m_rpc_channel;
|
2021-02-11 13:47:41 +00:00
|
|
|
htclow::Channel m_data_channel;
|
|
|
|
bool m_connected;
|
|
|
|
os::ThreadType m_monitor_thread;
|
|
|
|
os::Event m_event;
|
2021-02-12 14:08:16 +00:00
|
|
|
private:
|
|
|
|
static void ThreadEntry(void *arg) { static_cast<ClientImpl *>(arg)->ThreadBody(); }
|
|
|
|
|
|
|
|
void ThreadBody();
|
2021-02-11 13:47:41 +00:00
|
|
|
public:
|
|
|
|
ClientImpl(htclow::HtclowManager *manager);
|
|
|
|
|
|
|
|
~ClientImpl() {
|
|
|
|
this->Cancel();
|
|
|
|
this->Wait();
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
void Start();
|
|
|
|
void Cancel();
|
|
|
|
void Wait();
|
2021-02-13 09:57:24 +00:00
|
|
|
public:
|
2021-02-16 02:56:22 +00:00
|
|
|
Result OpenFile(s32 *out_handle, const char *path, fs::OpenMode mode, bool case_sensitive);
|
|
|
|
Result FileExists(bool *out, const char *path, bool case_sensitive);
|
|
|
|
Result DeleteFile(const char *path, bool case_sensitive);
|
|
|
|
Result RenameFile(const char *old_path, const char *new_path, bool case_sensitive);
|
|
|
|
Result GetEntryType(fs::DirectoryEntryType *out, const char *path, bool case_sensitive);
|
2021-02-13 09:57:24 +00:00
|
|
|
Result OpenDirectory(s32 *out_handle, const char *path, fs::OpenDirectoryMode mode, bool case_sensitive);
|
2021-02-16 02:56:22 +00:00
|
|
|
Result DirectoryExists(bool *out, const char *path, bool case_sensitive);
|
|
|
|
Result CreateDirectory(const char *path, bool case_sensitive);
|
|
|
|
Result DeleteDirectory(const char *path, bool recursively, bool case_sensitive);
|
|
|
|
Result RenameDirectory(const char *old_path, const char *new_path, bool case_sensitive);
|
|
|
|
Result CreateFile(const char *path, s64 size, bool case_sensitive);
|
|
|
|
Result GetFileTimeStamp(u64 *out_create, u64 *out_access, u64 *out_modify, const char *path, bool case_sensitive);
|
|
|
|
Result GetCaseSensitivePath(char *dst, size_t dst_size, const char *path);
|
|
|
|
Result GetDiskFreeSpace(s64 *out_free, s64 *out_total, s64 *out_total_free, const char *path);
|
|
|
|
|
2021-02-13 09:57:24 +00:00
|
|
|
Result CloseDirectory(s32 handle);
|
2021-02-13 13:39:02 +00:00
|
|
|
|
|
|
|
Result GetEntryCount(s64 *out, s32 handle);
|
|
|
|
Result ReadDirectory(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle);
|
|
|
|
Result ReadDirectoryLarge(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle);
|
|
|
|
Result GetPriorityForDirectory(s32 *out, s32 handle);
|
|
|
|
Result SetPriorityForDirectory(s32 priority, s32 handle);
|
2021-02-16 02:56:22 +00:00
|
|
|
|
|
|
|
Result CloseFile(s32 handle);
|
|
|
|
|
|
|
|
Result ReadFile(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option);
|
|
|
|
Result ReadFileLarge(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option);
|
|
|
|
Result WriteFile(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option);
|
|
|
|
Result WriteFileLarge(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option);
|
|
|
|
Result GetFileSize(s64 *out, s32 handle);
|
|
|
|
Result SetFileSize(s64 size, s32 handle);
|
|
|
|
Result FlushFile(s32 handle);
|
|
|
|
Result GetPriorityForFile(s32 *out, s32 handle);
|
|
|
|
Result SetPriorityForFile(s32 priority, s32 handle);
|
2021-02-23 23:47:28 +00:00
|
|
|
|
|
|
|
Result GetWorkingDirectory(char *dst, size_t dst_size);
|
|
|
|
Result GetWorkingDirectorySize(s32 *out);
|
2021-02-12 14:08:16 +00:00
|
|
|
private:
|
|
|
|
int WaitAny(htclow::ChannelState state, os::EventType *event);
|
|
|
|
|
|
|
|
Result SetUpProtocol();
|
|
|
|
void TearDownProtocol();
|
2021-02-13 06:07:34 +00:00
|
|
|
|
|
|
|
Result CheckResponseHeaderWithoutVersion(const Header &response, PacketType packet_type);
|
2021-02-13 09:57:24 +00:00
|
|
|
Result CheckResponseHeader(const Header &response, PacketType packet_type);
|
|
|
|
Result CheckResponseHeader(const Header &response, PacketType packet_type, s64 body_size);
|
2021-02-13 06:07:34 +00:00
|
|
|
|
|
|
|
Result GetMaxProtocolVersion(s16 *out);
|
|
|
|
Result SetProtocolVersion(s16 version);
|
|
|
|
|
2021-02-13 09:57:24 +00:00
|
|
|
Result InitializeRpcChannel();
|
|
|
|
|
2021-02-13 06:07:34 +00:00
|
|
|
Result SendToRpcChannel(const void *src, s64 size);
|
|
|
|
Result ReceiveFromRpcChannel(void *dst, s64 size);
|
|
|
|
|
2021-02-13 18:01:19 +00:00
|
|
|
Result ReceiveFromDataChannel(s64 size);
|
|
|
|
Result SendToDataChannel();
|
|
|
|
|
2021-02-13 06:07:34 +00:00
|
|
|
Result SendToHtclow(const void *src, s64 size, htclow::Channel *channel);
|
|
|
|
Result ReceiveFromHtclow(void *dst, s64 size, htclow::Channel *channel);
|
2021-02-13 09:57:24 +00:00
|
|
|
|
2022-03-26 21:48:33 +00:00
|
|
|
Result SendRequest(const Header &request) { R_RETURN(this->SendRequest(request, nullptr, 0, nullptr, 0)); }
|
|
|
|
Result SendRequest(const Header &request, const void *arg1, size_t arg1_size) { R_RETURN(this->SendRequest(request, arg1, arg1_size, nullptr, 0)); }
|
2021-02-13 09:57:24 +00:00
|
|
|
Result SendRequest(const Header &request, const void *arg1, size_t arg1_size, const void *arg2, size_t arg2_size);
|
2021-02-13 18:01:19 +00:00
|
|
|
|
|
|
|
void InitializeDataChannelForReceive(void *dst, size_t size);
|
|
|
|
void InitializeDataChannelForSend(const void *src, size_t size);
|
|
|
|
void FinalizeDataChannel();
|
2021-02-11 13:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|