Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"
This reverts commit 15b7df8ef1.
This commit is contained in:
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
class CacheManager {
|
||||
private:
|
||||
os::SdkMutex m_mutex;
|
||||
void *m_cache;
|
||||
size_t m_cache_size;
|
||||
s64 m_cached_file_size;
|
||||
size_t m_cached_data_size;
|
||||
s32 m_cached_handle;
|
||||
bool m_has_cached_handle;
|
||||
public:
|
||||
CacheManager(void *cache, size_t cache_size) : m_mutex(), m_cache(cache), m_cache_size(cache_size), m_cached_file_size(), m_cached_data_size(), m_cached_handle(), m_has_cached_handle() { /* ... */ }
|
||||
public:
|
||||
bool GetFileSize(s64 *out, s32 handle) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Get the cached size, if we match. */
|
||||
if (m_has_cached_handle && m_cached_handle == handle) {
|
||||
*out = m_cached_file_size;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Invalidate() {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Note that we have no handle. */
|
||||
m_has_cached_handle = false;
|
||||
}
|
||||
|
||||
void Invalidate(s32 handle) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
if (m_has_cached_handle && m_cached_handle == handle) {
|
||||
/* Note that we have no handle. */
|
||||
m_has_cached_handle = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Record(s64 file_size, const void *data, s32 handle, size_t data_size) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Set our cached file size. */
|
||||
m_cached_file_size = file_size;
|
||||
|
||||
/* Set our cached data size. */
|
||||
m_cached_data_size = std::min(m_cache_size, data_size);
|
||||
|
||||
/* Copy the data. */
|
||||
std::memcpy(m_cache, data, m_cached_data_size);
|
||||
|
||||
/* Set our cache handle. */
|
||||
m_cached_handle = handle;
|
||||
|
||||
/* Note that we have cached data. */
|
||||
m_has_cached_handle = true;
|
||||
}
|
||||
|
||||
bool ReadFile(size_t *out, void *dst, s32 handle, size_t offset, size_t size) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Check that we have a cached file. */
|
||||
if (!m_has_cached_handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the file is our cached one. */
|
||||
if (handle != m_cached_handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check that we can read data. */
|
||||
if (offset + size > m_cached_data_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Copy the cached data. */
|
||||
std::memcpy(dst, static_cast<const u8 *>(m_cache) + offset, size);
|
||||
|
||||
/* Set the output read size. */
|
||||
*out = size;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_client.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit util::TypedStorage<Client> g_client_storage = {};
|
||||
[[maybe_unused]] constinit bool g_initialized = false;
|
||||
|
||||
}
|
||||
|
||||
void InitializeClient(htclow::HtclowManager *manager) {
|
||||
AMS_ASSERT(!g_initialized);
|
||||
|
||||
util::ConstructAt(g_client_storage, manager);
|
||||
}
|
||||
|
||||
void FinalizeClient() {
|
||||
AMS_ASSERT(g_initialized);
|
||||
|
||||
util::DestroyAt(g_client_storage);
|
||||
}
|
||||
|
||||
Client &GetClient() {
|
||||
AMS_ASSERT(g_initialized);
|
||||
|
||||
return GetReference(g_client_storage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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 "htcfs_client_impl.hpp"
|
||||
#include "htcfs_result_utils.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
class Client {
|
||||
private:
|
||||
ClientImpl m_impl;
|
||||
public:
|
||||
Client(htclow::HtclowManager *manager) : m_impl(manager) { /* ... */ }
|
||||
public:
|
||||
Result OpenFile(s32 *out_handle, const char *path, fs::OpenMode mode, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.OpenFile(out_handle, path, mode, case_sensitive))); }
|
||||
Result FileExists(bool *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.FileExists(out, path, case_sensitive))); }
|
||||
Result DeleteFile(const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DeleteFile(path, case_sensitive))); }
|
||||
Result RenameFile(const char *old_path, const char *new_path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.RenameFile(old_path, new_path, case_sensitive))); }
|
||||
Result GetEntryType(fs::DirectoryEntryType *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.GetEntryType(out, path, case_sensitive))); }
|
||||
Result OpenDirectory(s32 *out_handle, const char *path, fs::OpenDirectoryMode mode, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.OpenDirectory(out_handle, path, mode, case_sensitive))); }
|
||||
Result DirectoryExists(bool *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DirectoryExists(out, path, case_sensitive))); }
|
||||
Result CreateDirectory(const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.CreateDirectory(path, case_sensitive))); }
|
||||
Result DeleteDirectory(const char *path, bool recursively, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DeleteDirectory(path, recursively, case_sensitive))); }
|
||||
Result RenameDirectory(const char *old_path, const char *new_path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.RenameDirectory(old_path, new_path, case_sensitive))); }
|
||||
Result CreateFile(const char *path, s64 size, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.CreateFile(path, size, case_sensitive))); }
|
||||
Result GetFileTimeStamp(u64 *out_create, u64 *out_access, u64 *out_modify, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.GetFileTimeStamp(out_create, out_access, out_modify, path, case_sensitive))); }
|
||||
Result GetCaseSensitivePath(char *dst, size_t dst_size, const char *path) { R_RETURN(ConvertToFsResult(m_impl.GetCaseSensitivePath(dst, dst_size, path))); }
|
||||
Result GetDiskFreeSpace(s64 *out_free, s64 *out_total, s64 *out_total_free, const char *path) { R_RETURN(ConvertToFsResult(m_impl.GetDiskFreeSpace(out_free, out_total, out_total_free, path))); }
|
||||
|
||||
Result CloseDirectory(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.CloseDirectory(handle))); }
|
||||
|
||||
Result GetEntryCount(s64 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetEntryCount(out, handle))); }
|
||||
Result ReadDirectory(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.ReadDirectory(out, out_entries, max_out_entries, handle))); }
|
||||
Result ReadDirectoryLarge(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.ReadDirectoryLarge(out, out_entries, max_out_entries, handle))); }
|
||||
Result GetPriorityForDirectory(s32 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetPriorityForDirectory(out, handle))); }
|
||||
Result SetPriorityForDirectory(s32 priority, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetPriorityForDirectory(priority, handle))); }
|
||||
|
||||
Result CloseFile(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.CloseFile(handle))); }
|
||||
|
||||
Result ReadFile(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option) { R_RETURN(ConvertToFsResult(m_impl.ReadFile(out, buffer, handle, offset, buffer_size, option))); }
|
||||
Result ReadFileLarge(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option) { R_RETURN(ConvertToFsResult(m_impl.ReadFileLarge(out, buffer, handle, offset, buffer_size, option))); }
|
||||
Result WriteFile(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option) { R_RETURN(ConvertToFsResult(m_impl.WriteFile(buffer, handle, offset, buffer_size, option))); }
|
||||
Result WriteFileLarge(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option) { R_RETURN(ConvertToFsResult(m_impl.WriteFileLarge(buffer, handle, offset, buffer_size, option))); }
|
||||
Result GetFileSize(s64 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetFileSize(out, handle))); }
|
||||
Result SetFileSize(s64 size, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetFileSize(size, handle))); }
|
||||
Result FlushFile(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.FlushFile(handle))); }
|
||||
Result GetPriorityForFile(s32 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetPriorityForFile(out, handle))); }
|
||||
Result SetPriorityForFile(s32 priority, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetPriorityForFile(priority, handle))); }
|
||||
|
||||
Result GetWorkingDirectory(char *dst, size_t dst_size) { R_RETURN(ConvertToFsResult(m_impl.GetWorkingDirectory(dst, dst_size))); }
|
||||
Result GetWorkingDirectorySize(s32 *out) { R_RETURN(ConvertToFsResult(m_impl.GetWorkingDirectorySize(out))); }
|
||||
};
|
||||
|
||||
void InitializeClient(htclow::HtclowManager *manager);
|
||||
void FinalizeClient();
|
||||
|
||||
Client &GetClient();
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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"
|
||||
#include "../htclow/htclow_default_channel_config.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
class ClientImpl {
|
||||
public:
|
||||
static constexpr size_t MaxPacketBodySize = htclow::DefaultChannelConfig.max_packet_size - sizeof(htclow::PacketHeader);
|
||||
private:
|
||||
u8 m_receive_buffer[0x1C040];
|
||||
u8 m_send_buffer[0x1C040];
|
||||
u8 m_packet_buffer[MaxPacketBodySize + sizeof(htclow::PacketHeader)];
|
||||
htclow::HtclowManager *m_htclow_manager;
|
||||
CacheManager m_cache_manager;
|
||||
HeaderFactory m_header_factory;
|
||||
os::SdkMutex m_mutex;
|
||||
htclow::Module m_module;
|
||||
htclow::Channel m_rpc_channel;
|
||||
htclow::Channel m_data_channel;
|
||||
bool m_connected;
|
||||
os::ThreadType m_monitor_thread;
|
||||
os::Event m_event;
|
||||
private:
|
||||
static void ThreadEntry(void *arg) { static_cast<ClientImpl *>(arg)->ThreadBody(); }
|
||||
|
||||
void ThreadBody();
|
||||
public:
|
||||
ClientImpl(htclow::HtclowManager *manager);
|
||||
|
||||
~ClientImpl() {
|
||||
this->Cancel();
|
||||
this->Wait();
|
||||
}
|
||||
public:
|
||||
void Start();
|
||||
void Cancel();
|
||||
void Wait();
|
||||
public:
|
||||
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);
|
||||
Result OpenDirectory(s32 *out_handle, const char *path, fs::OpenDirectoryMode mode, bool case_sensitive);
|
||||
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);
|
||||
|
||||
Result CloseDirectory(s32 handle);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
Result GetWorkingDirectory(char *dst, size_t dst_size);
|
||||
Result GetWorkingDirectorySize(s32 *out);
|
||||
private:
|
||||
int WaitAny(htclow::ChannelState state, os::EventType *event);
|
||||
|
||||
Result SetUpProtocol();
|
||||
void TearDownProtocol();
|
||||
|
||||
Result CheckResponseHeaderWithoutVersion(const Header &response, PacketType packet_type);
|
||||
Result CheckResponseHeader(const Header &response, PacketType packet_type);
|
||||
Result CheckResponseHeader(const Header &response, PacketType packet_type, s64 body_size);
|
||||
|
||||
Result GetMaxProtocolVersion(s16 *out);
|
||||
Result SetProtocolVersion(s16 version);
|
||||
|
||||
Result InitializeRpcChannel();
|
||||
|
||||
Result SendToRpcChannel(const void *src, s64 size);
|
||||
Result ReceiveFromRpcChannel(void *dst, s64 size);
|
||||
|
||||
Result ReceiveFromDataChannel(s64 size);
|
||||
Result SendToDataChannel();
|
||||
|
||||
Result SendToHtclow(const void *src, s64 size, htclow::Channel *channel);
|
||||
Result ReceiveFromHtclow(void *dst, s64 size, htclow::Channel *channel);
|
||||
|
||||
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)); }
|
||||
Result SendRequest(const Header &request, const void *arg1, size_t arg1_size, const void *arg2, size_t arg2_size);
|
||||
|
||||
void InitializeDataChannelForReceive(void *dst, size_t size);
|
||||
void InitializeDataChannelForSend(const void *src, size_t size);
|
||||
void FinalizeDataChannel();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_directory_service_object.hpp"
|
||||
#include "htcfs_client.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
DirectoryServiceObject::DirectoryServiceObject(s32 handle) : m_handle(handle) { /* ... */ }
|
||||
|
||||
DirectoryServiceObject::~DirectoryServiceObject() {
|
||||
htcfs::GetClient().CloseDirectory(m_handle);
|
||||
}
|
||||
|
||||
Result DirectoryServiceObject::GetEntryCount(ams::sf::Out<s64> out) {
|
||||
R_RETURN(htcfs::GetClient().GetEntryCount(out.GetPointer(), m_handle));
|
||||
}
|
||||
|
||||
Result DirectoryServiceObject::Read(ams::sf::Out<s64> out, const ams::sf::OutMapAliasArray<fs::DirectoryEntry> &out_entries) {
|
||||
if (out_entries.GetSize() * sizeof(fs::DirectoryEntry) >= ClientImpl::MaxPacketBodySize) {
|
||||
R_RETURN(htcfs::GetClient().ReadDirectoryLarge(out.GetPointer(), out_entries.GetPointer(), out_entries.GetSize(), m_handle));
|
||||
} else {
|
||||
R_RETURN(htcfs::GetClient().ReadDirectory(out.GetPointer(), out_entries.GetPointer(), out_entries.GetSize(), m_handle));
|
||||
}
|
||||
}
|
||||
|
||||
Result DirectoryServiceObject::SetPriorityForDirectory(s32 priority) {
|
||||
R_RETURN(htcfs::GetClient().SetPriorityForDirectory(priority, m_handle));
|
||||
}
|
||||
|
||||
Result DirectoryServiceObject::GetPriorityForDirectory(ams::sf::Out<s32> out) {
|
||||
R_RETURN(htcfs::GetClient().GetPriorityForDirectory(out.GetPointer(), m_handle));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
class DirectoryServiceObject {
|
||||
private:
|
||||
s32 m_handle;
|
||||
public:
|
||||
explicit DirectoryServiceObject(s32 handle);
|
||||
~DirectoryServiceObject();
|
||||
public:
|
||||
Result GetEntryCount(ams::sf::Out<s64> out);
|
||||
Result Read(ams::sf::Out<s64> out, const ams::sf::OutMapAliasArray<fs::DirectoryEntry> &out_entries);
|
||||
Result SetPriorityForDirectory(s32 priority);
|
||||
Result GetPriorityForDirectory(ams::sf::Out<s32> out);
|
||||
};
|
||||
static_assert(tma::IsIDirectoryAccessor<DirectoryServiceObject>);
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_file_service_object.hpp"
|
||||
#include "htcfs_client.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
FileServiceObject::FileServiceObject(s32 handle) : m_handle(handle) { /* ... */ }
|
||||
|
||||
FileServiceObject::~FileServiceObject() {
|
||||
htcfs::GetClient().CloseFile(m_handle);
|
||||
}
|
||||
|
||||
Result FileServiceObject::ReadFile(ams::sf::Out<s64> out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, ams::fs::ReadOption option) {
|
||||
/* Validate offset. */
|
||||
R_UNLESS(offset >= 0, htcfs::ResultInvalidArgument());
|
||||
|
||||
if (buffer.GetSize() >= ClientImpl::MaxPacketBodySize) {
|
||||
R_RETURN(htcfs::GetClient().ReadFileLarge(out.GetPointer(), buffer.GetPointer(), m_handle, offset, buffer.GetSize(), option));
|
||||
} else {
|
||||
R_RETURN(htcfs::GetClient().ReadFile(out.GetPointer(), buffer.GetPointer(), m_handle, offset, buffer.GetSize(), option));
|
||||
}
|
||||
}
|
||||
|
||||
Result FileServiceObject::WriteFile(s64 offset, const ams::sf::InNonSecureBuffer &buffer, ams::fs::WriteOption option) {
|
||||
/* Validate offset. */
|
||||
R_UNLESS(offset >= 0, htcfs::ResultInvalidArgument());
|
||||
|
||||
if (buffer.GetSize() >= ClientImpl::MaxPacketBodySize) {
|
||||
R_RETURN(htcfs::GetClient().WriteFileLarge(buffer.GetPointer(), m_handle, offset, buffer.GetSize(), option));
|
||||
} else {
|
||||
R_RETURN(htcfs::GetClient().WriteFile(buffer.GetPointer(), m_handle, offset, buffer.GetSize(), option));
|
||||
}
|
||||
}
|
||||
|
||||
Result FileServiceObject::GetFileSize(ams::sf::Out<s64> out) {
|
||||
R_RETURN(htcfs::GetClient().GetFileSize(out.GetPointer(), m_handle));
|
||||
}
|
||||
|
||||
Result FileServiceObject::SetFileSize(s64 size) {
|
||||
/* Validate size. */
|
||||
R_UNLESS(size >= 0, htcfs::ResultInvalidArgument());
|
||||
|
||||
R_RETURN(htcfs::GetClient().SetFileSize(size, m_handle));
|
||||
}
|
||||
|
||||
Result FileServiceObject::FlushFile() {
|
||||
R_RETURN(htcfs::GetClient().FlushFile(m_handle));
|
||||
}
|
||||
|
||||
Result FileServiceObject::SetPriorityForFile(s32 priority) {
|
||||
R_RETURN(htcfs::GetClient().SetPriorityForFile(priority, m_handle));
|
||||
}
|
||||
|
||||
Result FileServiceObject::GetPriorityForFile(ams::sf::Out<s32> out) {
|
||||
R_RETURN(htcfs::GetClient().GetPriorityForFile(out.GetPointer(), m_handle));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
class FileServiceObject {
|
||||
private:
|
||||
s32 m_handle;
|
||||
public:
|
||||
explicit FileServiceObject(s32 handle);
|
||||
~FileServiceObject();
|
||||
public:
|
||||
Result ReadFile(ams::sf::Out<s64> out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, ams::fs::ReadOption option);
|
||||
Result WriteFile(s64 offset, const ams::sf::InNonSecureBuffer &buffer, ams::fs::WriteOption option);
|
||||
Result GetFileSize(ams::sf::Out<s64> out);
|
||||
Result SetFileSize(s64 size);
|
||||
Result FlushFile();
|
||||
Result SetPriorityForFile(s32 priority);
|
||||
Result GetPriorityForFile(ams::sf::Out<s32> out);
|
||||
};
|
||||
static_assert(tma::IsIFileAccessor<FileServiceObject>);
|
||||
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_file_system_service_object.hpp"
|
||||
#include "htcfs_file_service_object.hpp"
|
||||
#include "htcfs_directory_service_object.hpp"
|
||||
#include "htcfs_client.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
namespace {
|
||||
|
||||
struct DirectoryServiceObjectAllocatorTag;
|
||||
struct FileServiceObjectAllocatorTag;
|
||||
|
||||
using DirectoryServiceObjectAllocator = ams::sf::ExpHeapStaticAllocator<4_KB, DirectoryServiceObjectAllocatorTag>;
|
||||
using FileServiceObjectAllocator = ams::sf::ExpHeapStaticAllocator<4_KB, FileServiceObjectAllocatorTag>;
|
||||
using DirectoryServiceObjectFactory = ams::sf::ObjectFactory<typename DirectoryServiceObjectAllocator::Policy>;
|
||||
using FileServiceObjectFactory = ams::sf::ObjectFactory<typename FileServiceObjectAllocator::Policy>;
|
||||
|
||||
class StaticAllocatorInitializer {
|
||||
public:
|
||||
StaticAllocatorInitializer() {
|
||||
DirectoryServiceObjectAllocator::Initialize(lmem::CreateOption_ThreadSafe);
|
||||
FileServiceObjectAllocator::Initialize(lmem::CreateOption_ThreadSafe);
|
||||
}
|
||||
} g_static_allocator_initializer;
|
||||
|
||||
constexpr bool IsValidPath(const tma::Path &path) {
|
||||
const auto len = util::Strnlen(path.str, fs::EntryNameLengthMax + 1);
|
||||
return 0 < len && len < static_cast<int>(fs::EntryNameLengthMax + 1);
|
||||
}
|
||||
|
||||
Result ConvertOpenMode(fs::OpenMode *out, u32 open_mode) {
|
||||
switch (open_mode) {
|
||||
case 1:
|
||||
*out = fs::OpenMode_Read;
|
||||
break;
|
||||
case 2:
|
||||
*out = static_cast<fs::OpenMode>(fs::OpenMode_Write | fs::OpenMode_AllowAppend);
|
||||
break;
|
||||
case 3:
|
||||
*out = static_cast<fs::OpenMode>(fs::OpenMode_ReadWrite | fs::OpenMode_AllowAppend);
|
||||
break;
|
||||
default:
|
||||
R_THROW(htcfs::ResultInvalidArgument());
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::OpenFile(sf::Out<sf::SharedPointer<tma::IFileAccessor>> out, const tma::Path &path, u32 open_mode, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Convert the open mode. */
|
||||
fs::OpenMode fs_open_mode;
|
||||
R_TRY(ConvertOpenMode(std::addressof(fs_open_mode), open_mode));
|
||||
|
||||
/* Open the file. */
|
||||
s32 handle = -1;
|
||||
R_TRY(htcfs::GetClient().OpenFile(std::addressof(handle), path.str, fs_open_mode, case_sensitive));
|
||||
|
||||
/* Set the output file. */
|
||||
*out = FileServiceObjectFactory::CreateSharedEmplaced<tma::IFileAccessor, FileServiceObject>(handle);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::FileExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get whether the file exists. */
|
||||
R_RETURN(htcfs::GetClient().FileExists(out.GetPointer(), path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::DeleteFile(const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Delete the file. */
|
||||
R_RETURN(htcfs::GetClient().DeleteFile(path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::RenameFile(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive) {
|
||||
/* Check that the paths are valid. */
|
||||
R_UNLESS(IsValidPath(old_path), htcfs::ResultInvalidArgument());
|
||||
R_UNLESS(IsValidPath(new_path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Rename the file. */
|
||||
R_RETURN(htcfs::GetClient().RenameFile(old_path.str, new_path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::GetIOType(sf::Out<s32> out, const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get the entry type. */
|
||||
static_assert(sizeof(s32) == sizeof(fs::DirectoryEntryType));
|
||||
R_RETURN(htcfs::GetClient().GetEntryType(reinterpret_cast<fs::DirectoryEntryType *>(out.GetPointer()), path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::OpenDirectory(sf::Out<sf::SharedPointer<tma::IDirectoryAccessor>> out, const tma::Path &path, s32 open_mode, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Open the directory. */
|
||||
s32 handle = -1;
|
||||
R_TRY(htcfs::GetClient().OpenDirectory(std::addressof(handle), path.str, static_cast<fs::OpenDirectoryMode>(open_mode), case_sensitive));
|
||||
|
||||
/* Set the output directory. */
|
||||
*out = DirectoryServiceObjectFactory::CreateSharedEmplaced<tma::IDirectoryAccessor, DirectoryServiceObject>(handle);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::DirectoryExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get whether the file exists. */
|
||||
R_RETURN(htcfs::GetClient().DirectoryExists(out.GetPointer(), path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::CreateDirectory(const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Create the directory. */
|
||||
R_RETURN(htcfs::GetClient().CreateDirectory(path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::DeleteDirectory(const tma::Path &path, bool recursively, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Delete the directory. */
|
||||
R_RETURN(htcfs::GetClient().DeleteDirectory(path.str, recursively, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::RenameDirectory(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive) {
|
||||
/* Check that the paths are valid. */
|
||||
R_UNLESS(IsValidPath(old_path), htcfs::ResultInvalidArgument());
|
||||
R_UNLESS(IsValidPath(new_path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Rename the file. */
|
||||
R_RETURN(htcfs::GetClient().RenameDirectory(old_path.str, new_path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::CreateFile(const tma::Path &path, s64 size, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Create the file. */
|
||||
R_RETURN(htcfs::GetClient().CreateFile(path.str, size, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::GetFileTimeStamp(sf::Out<u64> out_create, sf::Out<u64> out_access, sf::Out<u64> out_modify, const tma::Path &path, bool case_sensitive) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get the timestamp. */
|
||||
R_RETURN(htcfs::GetClient().GetFileTimeStamp(out_create.GetPointer(), out_access.GetPointer(), out_modify.GetPointer(), path.str, case_sensitive));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::GetCaseSensitivePath(const tma::Path &path, const sf::OutBuffer &out) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get the case sensitive path. */
|
||||
R_RETURN(htcfs::GetClient().GetCaseSensitivePath(reinterpret_cast<char *>(out.GetPointer()), out.GetSize(), path.str));
|
||||
}
|
||||
|
||||
Result FileSystemServiceObject::GetDiskFreeSpaceExW(sf::Out<s64> out_free, sf::Out<s64> out_total, sf::Out<s64> out_total_free, const tma::Path &path) {
|
||||
/* Check that the path is valid. */
|
||||
R_UNLESS(IsValidPath(path), htcfs::ResultInvalidArgument());
|
||||
|
||||
/* Get the timestamp. */
|
||||
R_RETURN(htcfs::GetClient().GetDiskFreeSpace(out_free.GetPointer(), out_total.GetPointer(), out_total_free.GetPointer(), path.str));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
constexpr inline bool DefaultCaseSensitivityForDeprecatedFileSystemServiceObject = false;
|
||||
|
||||
class FileSystemServiceObject {
|
||||
public:
|
||||
Result OpenFile(sf::Out<sf::SharedPointer<tma::IFileAccessor>> out, const tma::Path &path, u32 open_mode, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result FileExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result DeleteFile(const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result RenameFile(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result GetIOType(sf::Out<s32> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result OpenDirectory(sf::Out<sf::SharedPointer<tma::IDirectoryAccessor>> out, const tma::Path &path, s32 open_mode, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result DirectoryExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result CreateDirectory(const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result DeleteDirectory(const tma::Path &path, bool recursively, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result RenameDirectory(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result CreateFile(const tma::Path &path, s64 size, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result GetFileTimeStamp(sf::Out<u64> out_create, sf::Out<u64> out_access, sf::Out<u64> out_modify, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject);
|
||||
Result GetCaseSensitivePath(const tma::Path &path, const sf::OutBuffer &out);
|
||||
Result GetDiskFreeSpaceExW(sf::Out<s64> out_free, sf::Out<s64> out_total, sf::Out<s64> out_total_free, const tma::Path &path);
|
||||
};
|
||||
static_assert(tma::IsIFileManager<FileSystemServiceObject>);
|
||||
static_assert(tma::IsIDeprecatedFileManager<FileSystemServiceObject>);
|
||||
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
constexpr inline s16 HtcfsProtocol = 1;
|
||||
constexpr inline s16 MaxProtocolVersion = 1;
|
||||
|
||||
enum class PacketCategory : u16 {
|
||||
Request = 0,
|
||||
Response = 1,
|
||||
};
|
||||
|
||||
enum class PacketType : u16 {
|
||||
GetMaxProtocolVersion = 0,
|
||||
SetProtocolVersion = 1,
|
||||
GetEntryType = 16,
|
||||
OpenFile = 32,
|
||||
CloseFile = 33,
|
||||
GetPriorityForFile = 34,
|
||||
SetPriorityForFile = 35,
|
||||
CreateFile = 36,
|
||||
DeleteFile = 37,
|
||||
RenameFile = 38,
|
||||
FileExists = 39,
|
||||
ReadFile = 40,
|
||||
WriteFile = 41,
|
||||
FlushFile = 42,
|
||||
GetFileTimeStamp = 43,
|
||||
GetFileSize = 44,
|
||||
SetFileSize = 45,
|
||||
ReadFileLarge = 46,
|
||||
WriteFileLarge = 47,
|
||||
OpenDirectory = 48,
|
||||
CloseDirectory = 49,
|
||||
GetPriorityForDirectory = 50,
|
||||
SetPriorityForDirectory = 51,
|
||||
CreateDirectory = 52,
|
||||
DeleteDirectory = 53,
|
||||
RenameDirectory = 54,
|
||||
DirectoryExists = 55,
|
||||
ReadDirectory = 56,
|
||||
GetEntryCount = 57,
|
||||
GetWorkingDirectory = 58,
|
||||
GetWorkingDirectorySize = 59,
|
||||
GetCaseSensitivePath = 60,
|
||||
GetDiskFreeSpace = 61,
|
||||
ReadDirectoryLarge = 62,
|
||||
};
|
||||
|
||||
struct Header {
|
||||
s16 protocol;
|
||||
s16 version;
|
||||
PacketCategory packet_category;
|
||||
PacketType packet_type;
|
||||
s64 body_size;
|
||||
s64 params[5];
|
||||
s64 reserved;
|
||||
};
|
||||
static_assert(util::is_pod<Header>::value);
|
||||
static_assert(sizeof(Header) == 0x40);
|
||||
|
||||
class HeaderFactory {
|
||||
private:
|
||||
s16 m_version;
|
||||
public:
|
||||
HeaderFactory() : m_version() { /* ... */ }
|
||||
public:
|
||||
s16 GetVersion() const { return m_version; }
|
||||
void SetVersion(s16 version) { m_version = version; }
|
||||
public:
|
||||
ALWAYS_INLINE void MakeRequestHeader(Header *out, PacketType packet_type, s64 body_size = 0, s64 param0 = 0, s64 param1 = 0, s64 param2 = 0, s64 param3 = 0, s64 param4 = 0) {
|
||||
/* Set protocol and version. */
|
||||
out->protocol = HtcfsProtocol;
|
||||
out->version = m_version;
|
||||
|
||||
/* Set type and category. */
|
||||
out->packet_category = PacketCategory::Request;
|
||||
out->packet_type = packet_type;
|
||||
|
||||
/* Set body size. */
|
||||
out->body_size = body_size;
|
||||
|
||||
/* Set params. */
|
||||
out->params[0] = param0;
|
||||
out->params[1] = param1;
|
||||
out->params[2] = param2;
|
||||
out->params[3] = param3;
|
||||
out->params[4] = param4;
|
||||
|
||||
/* Clear reserved. */
|
||||
out->reserved = 0;
|
||||
}
|
||||
|
||||
void MakeGetMaxProtocolVersionHeader(Header *out) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetMaxProtocolVersion, 0);
|
||||
}
|
||||
|
||||
void MakeSetProtocolVersionHeader(Header *out, s16 version) {
|
||||
return this->MakeRequestHeader(out, PacketType::SetProtocolVersion, 0, version);
|
||||
}
|
||||
|
||||
void MakeOpenFileHeader(Header *out, int path_len, fs::OpenMode mode, bool case_sensitive, s64 cache_size) {
|
||||
return this->MakeRequestHeader(out, PacketType::OpenFile, path_len, static_cast<s64>(mode), case_sensitive ? 1 : 0, cache_size);
|
||||
}
|
||||
|
||||
void MakeFileExistsHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::FileExists, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeDeleteFileHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::DeleteFile, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeRenameFileHeader(Header *out, int old_path_len, int new_path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::RenameFile, old_path_len + new_path_len, old_path_len, new_path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeGetEntryTypeHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetEntryType, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeOpenDirectoryHeader(Header *out, int path_len, fs::OpenDirectoryMode mode, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::OpenDirectory, path_len, static_cast<s64>(mode), case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeDirectoryExistsHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::DirectoryExists, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeCreateDirectoryHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::CreateDirectory, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeDeleteDirectoryHeader(Header *out, int path_len, bool recursively, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::DeleteDirectory, path_len, recursively ? 1 : 0, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeRenameDirectoryHeader(Header *out, int old_path_len, int new_path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::RenameDirectory, old_path_len + new_path_len, old_path_len, new_path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeCreateFileHeader(Header *out, int path_len, s64 size, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::CreateFile, path_len, size, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeGetFileTimeStampHeader(Header *out, int path_len, bool case_sensitive) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetFileTimeStamp, path_len, case_sensitive ? 1 : 0);
|
||||
}
|
||||
|
||||
void MakeGetCaseSensitivePathHeader(Header *out, int path_len) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetCaseSensitivePath, path_len);
|
||||
}
|
||||
|
||||
void MakeGetDiskFreeSpaceHeader(Header *out, int path_len) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetDiskFreeSpace, path_len);
|
||||
}
|
||||
|
||||
void MakeCloseDirectoryHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::CloseDirectory, 0, handle);
|
||||
}
|
||||
|
||||
void MakeGetEntryCountHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetEntryCount, 0, handle);
|
||||
}
|
||||
|
||||
void MakeGetWorkingDirectoryHeader(Header *out) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetWorkingDirectory, 0);
|
||||
}
|
||||
|
||||
void MakeGetWorkingDirectorySizeHeader(Header *out) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetWorkingDirectorySize, 0);
|
||||
}
|
||||
|
||||
void MakeReadDirectoryHeader(Header *out, s32 handle, size_t max_out_entries) {
|
||||
return this->MakeRequestHeader(out, PacketType::ReadDirectory, 0, handle, max_out_entries);
|
||||
}
|
||||
|
||||
void MakeReadDirectoryLargeHeader(Header *out, s32 handle, size_t max_out_entries, u16 data_channel_id) {
|
||||
return this->MakeRequestHeader(out, PacketType::ReadDirectoryLarge, 0, handle, max_out_entries, data_channel_id);
|
||||
}
|
||||
|
||||
void MakeGetPriorityForDirectoryHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetPriorityForDirectory, 0, handle);
|
||||
}
|
||||
|
||||
void MakeSetPriorityForDirectoryHeader(Header *out, s32 handle, s32 priority) {
|
||||
return this->MakeRequestHeader(out, PacketType::SetPriorityForDirectory, 0, handle, priority);
|
||||
}
|
||||
|
||||
void MakeCloseFileHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::CloseFile, 0, handle);
|
||||
}
|
||||
|
||||
void MakeReadFileHeader(Header *out, s32 handle, s64 offset, s64 buffer_size) {
|
||||
return this->MakeRequestHeader(out, PacketType::ReadFile, 0, handle, offset, buffer_size);
|
||||
}
|
||||
|
||||
void MakeReadFileLargeHeader(Header *out, s32 handle, s64 offset, s64 buffer_size, u16 data_channel_id) {
|
||||
return this->MakeRequestHeader(out, PacketType::ReadFileLarge, 0, handle, offset, buffer_size, data_channel_id);
|
||||
}
|
||||
|
||||
void MakeWriteFileHeader(Header *out, s64 buffer_size, s32 handle, u32 option, s64 offset) {
|
||||
return this->MakeRequestHeader(out, PacketType::WriteFile, buffer_size, handle, option, offset);
|
||||
}
|
||||
|
||||
void MakeWriteFileLargeHeader(Header *out, s32 handle, u32 option, s64 offset, s64 buffer_size, u16 data_channel_id) {
|
||||
return this->MakeRequestHeader(out, PacketType::WriteFileLarge, 0, handle, option, offset, buffer_size, data_channel_id);
|
||||
}
|
||||
|
||||
void MakeGetFileSizeHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetFileSize, 0, handle);
|
||||
}
|
||||
|
||||
void MakeSetFileSizeHeader(Header *out, s32 handle, s64 size) {
|
||||
return this->MakeRequestHeader(out, PacketType::SetFileSize, 0, handle, size);
|
||||
}
|
||||
|
||||
void MakeFlushFileHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::FlushFile, 0, handle);
|
||||
}
|
||||
|
||||
void MakeGetPriorityForFileHeader(Header *out, s32 handle) {
|
||||
return this->MakeRequestHeader(out, PacketType::GetPriorityForFile, 0, handle);
|
||||
}
|
||||
|
||||
void MakeSetPriorityForFileHeader(Header *out, s32 handle, s32 priority) {
|
||||
return this->MakeRequestHeader(out, PacketType::SetPriorityForFile, 0, handle, priority);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_client.hpp"
|
||||
#include "htcfs_file_system_service_object.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
namespace {
|
||||
|
||||
static constexpr inline size_t NumServers = 1;
|
||||
static constexpr inline size_t MaxSessions = 30;
|
||||
static constexpr inline sm::ServiceName ServiceName = sm::ServiceName::Encode("file_io");
|
||||
|
||||
struct ServerOptions {
|
||||
static constexpr size_t PointerBufferSize = 0x1000;
|
||||
static constexpr size_t MaxDomains = 0x10;
|
||||
static constexpr size_t MaxDomainObjects = 0x100;
|
||||
static constexpr bool CanDeferInvokeRequest = false;
|
||||
static constexpr bool CanManageMitmServers = false;
|
||||
};
|
||||
|
||||
using ServerManager = sf::hipc::ServerManager<NumServers, ServerOptions, MaxSessions>;
|
||||
|
||||
/* Service object. */
|
||||
ServerManager g_server_manager;
|
||||
|
||||
/* Service object. */
|
||||
constinit sf::UnmanagedServiceObject<tma::IFileManager, FileSystemServiceObject> g_htcfs_service_object;
|
||||
constinit sf::UnmanagedServiceObject<tma::IDeprecatedFileManager, FileSystemServiceObject> g_htcfs_deprecated_service_object;
|
||||
|
||||
}
|
||||
|
||||
void Initialize(htclow::HtclowManager *htclow_manager) {
|
||||
/* Initialize the htcfs client library. */
|
||||
htcfs::InitializeClient(htclow_manager);
|
||||
}
|
||||
|
||||
void RegisterHipcServer() {
|
||||
/* Register the service. */
|
||||
if (hos::GetVersion() >= hos::Version_6_0_0) {
|
||||
R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_htcfs_service_object.GetShared(), ServiceName, MaxSessions));
|
||||
} else {
|
||||
R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_htcfs_deprecated_service_object.GetShared(), ServiceName, MaxSessions));
|
||||
}
|
||||
}
|
||||
|
||||
void LoopHipcServer() {
|
||||
/* Loop, servicing services. */
|
||||
g_server_manager.LoopProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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 "htcfs_client_impl.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
enum class HtcfsResult {
|
||||
Success = 0,
|
||||
UnknownError = 1,
|
||||
UnsupportedProtocolVersion = 2,
|
||||
InvalidRequest = 3,
|
||||
InvalidHandle = 4,
|
||||
OutOfHandle = 5,
|
||||
Ready = 6,
|
||||
};
|
||||
|
||||
inline Result ConvertHtcfsResult(HtcfsResult result) {
|
||||
switch (result) {
|
||||
case HtcfsResult::Success:
|
||||
R_SUCCEED();
|
||||
case HtcfsResult::UnknownError:
|
||||
R_THROW(htcfs::ResultUnknownError());
|
||||
case HtcfsResult::UnsupportedProtocolVersion:
|
||||
R_THROW(htcfs::ResultUnsupportedProtocolVersion());
|
||||
case HtcfsResult::InvalidRequest:
|
||||
R_THROW(htcfs::ResultInvalidRequest());
|
||||
case HtcfsResult::InvalidHandle:
|
||||
R_THROW(htcfs::ResultInvalidHandle());
|
||||
case HtcfsResult::OutOfHandle:
|
||||
R_THROW(htcfs::ResultOutOfHandle());
|
||||
default:
|
||||
R_THROW(htcfs::ResultUnknownError());
|
||||
}
|
||||
}
|
||||
|
||||
inline Result ConvertHtcfsResult(s64 param) {
|
||||
R_RETURN(ConvertHtcfsResult(static_cast<HtcfsResult>(param)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
inline Result ConvertToFsResult(Result result) {
|
||||
R_TRY_CATCH(result) {
|
||||
R_CONVERT(htcfs::ResultInvalidArgument, fs::ResultInvalidArgument())
|
||||
R_CONVERT(htcfs::ResultConnectionFailure, fs::ResultTargetNotFound())
|
||||
R_CONVERT(htcfs::ResultOutOfHandle, fs::ResultOpenCountLimit())
|
||||
R_CONVERT(htcfs::ResultInternalError, fs::ResultInternal())
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
R_RETURN(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcfs_client.hpp"
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
Result GetWorkingDirectory(char *dst, size_t dst_size) {
|
||||
R_RETURN(htcfs::GetClient().GetWorkingDirectory(dst, dst_size));
|
||||
}
|
||||
|
||||
Result GetWorkingDirectorySize(s32 *out) {
|
||||
R_RETURN(htcfs::GetClient().GetWorkingDirectorySize(out));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace ams::htcfs {
|
||||
|
||||
Result GetWorkingDirectory(char *dst, size_t dst_size);
|
||||
Result GetWorkingDirectorySize(s32 *out);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user