diff --git a/libraries/libstratosphere/include/stratosphere/htcfs.hpp b/libraries/libstratosphere/include/stratosphere/htcfs.hpp index 999d1a35e..1e9368003 100644 --- a/libraries/libstratosphere/include/stratosphere/htcfs.hpp +++ b/libraries/libstratosphere/include/stratosphere/htcfs.hpp @@ -15,3 +15,4 @@ */ #pragma once +#include diff --git a/libraries/libstratosphere/include/stratosphere/htcfs/htcfs_hipc_server.hpp b/libraries/libstratosphere/include/stratosphere/htcfs/htcfs_hipc_server.hpp new file mode 100644 index 000000000..eb79d1c71 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/htcfs/htcfs_hipc_server.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +namespace ams::htclow { + + class HtclowManager; + +} + +namespace ams::htcfs { + + void Initialize(htclow::HtclowManager *htclow_manager); + + void RegisterHipcServer(); + void LoopHipcServer(); + +} diff --git a/libraries/libstratosphere/include/stratosphere/tma/tma_i_file_manager.hpp b/libraries/libstratosphere/include/stratosphere/tma/tma_i_file_manager.hpp index 43a7d77f3..6bd0190cf 100644 --- a/libraries/libstratosphere/include/stratosphere/tma/tma_i_file_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tma/tma_i_file_manager.hpp @@ -37,3 +37,22 @@ AMS_SF_METHOD_INFO(C, H, 13, Result, GetDiskFreeSpaceExW, (sf::Out out_free, sf::Out out_total, sf::Out out_total_free, const tma::Path &path), (out_free, out_total, out_total_free, path)) AMS_SF_DEFINE_INTERFACE(ams::tma, IFileManager, AMS_TMA_I_FILE_MANAGER_INTERFACE_INFO) + +/* Prior to system version 6.0.0, case sensitivity was not parameterized. */ +#define AMS_TMA_I_DEPRECATED_FILE_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenFile, (sf::Out> out, const tma::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FileExists, (sf::Out out, const tma::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, DeleteFile, (const tma::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RenameFile, (const tma::Path &old_path, const tma::Path &new_path), (old_path, new_path)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetIOType, (sf::Out out, const tma::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OpenDirectory, (sf::Out> out, const tma::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, DirectoryExists, (sf::Out out, const tma::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, CreateDirectory, (const tma::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, DeleteDirectory, (const tma::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, RenameDirectory, (const tma::Path &old_path, const tma::Path &new_path), (old_path, new_path)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, CreateFile, (const tma::Path &path, s64 size), (path, size)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, GetFileTimeStamp, (sf::Out out_create, sf::Out out_access, sf::Out out_modify, const tma::Path &path), (out_create, out_access, out_modify, path)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetCaseSensitivePath, (const tma::Path &path, const sf::OutBuffer &out), (path, out)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, GetDiskFreeSpaceExW, (sf::Out out_free, sf::Out out_total, sf::Out out_total_free, const tma::Path &path), (out_free, out_total, out_total_free, path)) + +AMS_SF_DEFINE_INTERFACE(ams::tma, IDeprecatedFileManager, AMS_TMA_I_DEPRECATED_FILE_MANAGER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/htcfs/htcfs_cache_manager.hpp b/libraries/libstratosphere/source/htcfs/htcfs_cache_manager.hpp new file mode 100644 index 000000000..deb65fc35 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_cache_manager.hpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +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 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(m_cache) + offset, size); + + /* Set the output read size. */ + *out = size; + + return true; + } + }; + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_client.cpp b/libraries/libstratosphere/source/htcfs/htcfs_client.cpp new file mode 100644 index 000000000..0d871278d --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_client.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#include +#include "htcfs_client.hpp" + +namespace ams::htcfs { + + namespace { + + constinit TYPED_STORAGE(Client) g_client_storage; + constinit bool g_initialized; + + } + + void InitializeClient(htclow::HtclowManager *manager) { + AMS_ASSERT(!g_initialized); + + std::construct_at(GetPointer(g_client_storage), manager); + } + + void FinalizeClient() { + AMS_ASSERT(g_initialized); + + std::destroy_at(GetPointer(g_client_storage)); + } + + Client &GetClient() { + AMS_ASSERT(g_initialized); + + return GetReference(g_client_storage); + } + + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_client.hpp b/libraries/libstratosphere/source/htcfs/htcfs_client.hpp new file mode 100644 index 000000000..974342703 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_client.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include +#include "htcfs_client_impl.hpp" + +namespace ams::htcfs { + + class Client { + private: + ClientImpl m_impl; + public: + Client(htclow::HtclowManager *manager); + }; + + void InitializeClient(htclow::HtclowManager *manager); + void FinalizeClient(); + + Client &GetClient(); + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_client_impl.hpp b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.hpp new file mode 100644 index 000000000..fd5508c62 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.hpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include +#include "../htclow/htclow_manager.hpp" +#include "../htclow/htclow_channel.hpp" +#include "htcfs_cache_manager.hpp" +#include "htcfs_header_factory.hpp" + +namespace ams::htcfs { + + class ClientImpl { + private: + u8 m_receive_buffer[0x1C040]; + u8 m_send_buffer[0x1C040]; + u8 m_packet_buffer[0xE020]; + htclow::HtclowManager *m_htclow_manager; + CacheManager m_cache_manager; + HeaderFactory m_header_factory; + os::SdkMutex m_mutex; + htclow::Module m_module; + htclow::Channel m_channel; + htclow::Channel m_data_channel; + bool m_connected; + os::ThreadType m_monitor_thread; + os::Event m_event; + public: + ClientImpl(htclow::HtclowManager *manager); + + ~ClientImpl() { + this->Cancel(); + this->Wait(); + } + public: + void Start(); + void Cancel(); + void Wait(); + }; + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp new file mode 100644 index 000000000..1d0e53f80 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#include +#include "htcfs_directory_service_object.hpp" + +namespace ams::htcfs { + + DirectoryServiceObject::DirectoryServiceObject(s32 handle) : m_handle(handle) { /* ... */ } + + DirectoryServiceObject::~DirectoryServiceObject() { + /* TODO */ + AMS_ABORT("htcfs::GetClient().CloseDirectory(m_handle);"); + } + + Result DirectoryServiceObject::GetEntryCount(ams::sf::Out out) { + AMS_ABORT("DirectoryServiceObject::GetEntryCount"); + } + + Result DirectoryServiceObject::Read(ams::sf::Out out, const ams::sf::OutMapAliasArray &out_entries) { + AMS_ABORT("DirectoryServiceObject::Read"); + } + + Result DirectoryServiceObject::SetPriorityForDirectory(s32 priority) { + AMS_ABORT("DirectoryServiceObject::SetPriorityForDirectory"); + } + + Result DirectoryServiceObject::GetPriorityForDirectory(ams::sf::Out out) { + AMS_ABORT("DirectoryServiceObject::GetPriorityForDirectory"); + } + + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.hpp b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.hpp new file mode 100644 index 000000000..8e27f6254 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +namespace ams::htcfs { + + class DirectoryServiceObject { + private: + s32 m_handle; + public: + explicit DirectoryServiceObject(s32 handle); + ~DirectoryServiceObject(); + public: + Result GetEntryCount(ams::sf::Out out); + Result Read(ams::sf::Out out, const ams::sf::OutMapAliasArray &out_entries); + Result SetPriorityForDirectory(s32 priority); + Result GetPriorityForDirectory(ams::sf::Out out); + }; + static_assert(tma::IsIDirectoryAccessor); + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp new file mode 100644 index 000000000..edae19ad0 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#include +#include "htcfs_file_service_object.hpp" + +namespace ams::htcfs { + + FileServiceObject::FileServiceObject(s32 handle) : m_handle(handle) { /* ... */ } + + FileServiceObject::~FileServiceObject() { + /* TODO */ + AMS_ABORT("htcfs::GetClient().CloseFile(m_handle);"); + } + + Result FileServiceObject::ReadFile(ams::sf::Out out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, ams::fs::ReadOption option) { + AMS_ABORT("FileServiceObject::ReadFile"); + } + + Result FileServiceObject::WriteFile(s64 offset, const ams::sf::InNonSecureBuffer &buffer, ams::fs::WriteOption option) { + AMS_ABORT("FileServiceObject::WriteFile"); + } + + Result FileServiceObject::GetFileSize(ams::sf::Out out) { + AMS_ABORT("FileServiceObject::GetFileSize"); + } + + Result FileServiceObject::SetFileSize(s64 size) { + AMS_ABORT("FileServiceObject::SetFileSize"); + } + + Result FileServiceObject::FlushFile() { + AMS_ABORT("FileServiceObject::FlushFile"); + } + + Result FileServiceObject::SetPriorityForFile(s32 priority) { + AMS_ABORT("FileServiceObject::SetPriorityForFile"); + } + + Result FileServiceObject::GetPriorityForFile(ams::sf::Out out) { + AMS_ABORT("FileServiceObject::GetPriorityForFile"); + } + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.hpp b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.hpp new file mode 100644 index 000000000..b546efbb4 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +namespace ams::htcfs { + + class FileServiceObject { + private: + s32 m_handle; + public: + explicit FileServiceObject(s32 handle); + ~FileServiceObject(); + public: + Result ReadFile(ams::sf::Out 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 out); + Result SetFileSize(s64 size); + Result FlushFile(); + Result SetPriorityForFile(s32 priority); + Result GetPriorityForFile(ams::sf::Out out); + }; + static_assert(tma::IsIFileAccessor); + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.cpp b/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.cpp new file mode 100644 index 000000000..e1e75af0d --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#include +#include "htcfs_file_system_service_object.hpp" + +namespace ams::htcfs { + + Result FileSystemServiceObject::OpenFile(sf::Out> out, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::OpenFile"); + } + + Result FileSystemServiceObject::FileExists(sf::Out out, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::FileExists"); + } + + Result FileSystemServiceObject::DeleteFile(const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::DeleteFile"); + } + + Result FileSystemServiceObject::RenameFile(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::RenameFile"); + } + + Result FileSystemServiceObject::GetIOType(sf::Out out, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::GetIOType"); + } + + Result FileSystemServiceObject::OpenDirectory(sf::Out> out, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::OpenDirectory"); + } + + Result FileSystemServiceObject::DirectoryExists(sf::Out out, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::DirectoryExists"); + } + + Result FileSystemServiceObject::CreateDirectory(const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::CreateDirectory"); + } + + Result FileSystemServiceObject::DeleteDirectory(const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::DeleteDirectory"); + } + + Result FileSystemServiceObject::RenameDirectory(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::RenameDirectory"); + } + + Result FileSystemServiceObject::CreateFile(const tma::Path &path, s64 size, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::CreateFile"); + } + + Result FileSystemServiceObject::GetFileTimeStamp(sf::Out out_create, sf::Out out_access, sf::Out out_modify, const tma::Path &path, bool case_sensitive) { + AMS_ABORT("FileSystemServiceObject::GetFileTimeStamp"); + } + + Result FileSystemServiceObject::GetCaseSensitivePath(const tma::Path &path, const sf::OutBuffer &out) { + AMS_ABORT("FileSystemServiceObject::GetCaseSensitivePath"); + } + + Result FileSystemServiceObject::GetDiskFreeSpaceExW(sf::Out out_free, sf::Out out_total, sf::Out out_total_free, const tma::Path &path) { + AMS_ABORT("FileSystemServiceObject::GetDiskFreeSpaceExW"); + } + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.hpp b/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.hpp new file mode 100644 index 000000000..8c1546aa2 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +namespace ams::htcfs { + + constexpr inline bool DefaultCaseSensitivityForDeprecatedFileSystemServiceObject = false; + + class FileSystemServiceObject { + public: + Result OpenFile(sf::Out> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); + Result FileExists(sf::Out 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 out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); + Result OpenDirectory(sf::Out> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); + Result DirectoryExists(sf::Out 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 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 out_create, sf::Out out_access, sf::Out out_modify, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); + Result GetCaseSensitivePath(const tma::Path &path, const sf::OutBuffer &out); + Result GetDiskFreeSpaceExW(sf::Out out_free, sf::Out out_total, sf::Out out_total_free, const tma::Path &path); + }; + static_assert(tma::IsIFileManager); + static_assert(tma::IsIDeprecatedFileManager); + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_header_factory.hpp b/libraries/libstratosphere/source/htcfs/htcfs_header_factory.hpp new file mode 100644 index 000000000..643c98653 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_header_factory.hpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#pragma once +#include + +namespace ams::htcfs { + + class HeaderFactory { + private: + s16 m_version; + public: + HeaderFactory() : m_version() { /* ... */ } + public: + /* ... */ + }; + +} diff --git a/libraries/libstratosphere/source/htcfs/htcfs_hipc_server.cpp b/libraries/libstratosphere/source/htcfs/htcfs_hipc_server.cpp new file mode 100644 index 000000000..f550aa9b4 --- /dev/null +++ b/libraries/libstratosphere/source/htcfs/htcfs_hipc_server.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018-2020 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 . + */ +#include +#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("htcfs"); + + struct ServerOptions { + static constexpr size_t PointerBufferSize = 0x1000; + static constexpr size_t MaxDomains = 0x10; + static constexpr size_t MaxDomainObjects = 0x100; + }; + + using ServerManager = sf::hipc::ServerManager; + + /* Service object. */ + ServerManager g_server_manager; + + /* Service object. */ + constinit sf::UnmanagedServiceObject g_htcfs_service_object; + constinit sf::UnmanagedServiceObject 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(); + } + +} diff --git a/libraries/libstratosphere/source/htcs/server/htcs_manager_service_object.cpp b/libraries/libstratosphere/source/htcs/server/htcs_manager_service_object.cpp index a01a6df4f..e3a328f0f 100644 --- a/libraries/libstratosphere/source/htcs/server/htcs_manager_service_object.cpp +++ b/libraries/libstratosphere/source/htcs/server/htcs_manager_service_object.cpp @@ -51,12 +51,12 @@ namespace ams::htcs::server { } Result ManagerServiceObject::RegisterProcessId(const sf::ClientProcessId &client_pid) { - /* NOTE: Nintend does nothing here. */ + /* NOTE: Nintendo does nothing here. */ return ResultSuccess(); } Result ManagerServiceObject::MonitorManager(const sf::ClientProcessId &client_pid) { - /* NOTE: Nintend does nothing here. */ + /* NOTE: Nintendo does nothing here. */ return ResultSuccess(); } diff --git a/stratosphere/htc/source/htc_main.cpp b/stratosphere/htc/source/htc_main.cpp index 4f4bd1c2a..893a98e5a 100644 --- a/stratosphere/htc/source/htc_main.cpp +++ b/stratosphere/htc/source/htc_main.cpp @@ -210,7 +210,7 @@ namespace ams::htc { } void HtcfsIpcThreadFunction(void *arg) { - //htcfs::LoopHipcServer(); + htcfs::LoopHipcServer(); } void HtcsIpcThreadFunction(void *arg) { @@ -254,8 +254,8 @@ int main(int argc, char **argv) os::SetThreadNamePointer(std::addressof(htc_ipc_thread), AMS_GET_SYSTEM_THREAD_NAME(htc, HtcIpc)); /* Initialize the htcfs server. */ - //htcfs::Initialize(); - //htcfs::RegisterHipcServer(); + htcfs::Initialize(htclow_manager); + htcfs::RegisterHipcServer(); /* Create the htcfs ipc thread. */ os::ThreadType htcfs_ipc_thread;