From 2939557f88f713a55a46755f0c685702de5466c3 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 23 Aug 2019 15:05:19 +1000 Subject: [PATCH] ncm: Move ncm_types to libstrat --- .../include/stratosphere/ncm/ncm_types.hpp | 160 ++++++++++++++ .../include/stratosphere/util.hpp | 1 + .../include/stratosphere/util/util_uuid.hpp | 42 ++++ .../source/impl/ncm_placeholder_accessor.hpp | 1 - .../ncm/source/impl/ncm_rights_cache.hpp | 4 +- stratosphere/ncm/source/ncm_fs.hpp | 2 - .../ncm/source/ncm_icontentmetadatabase.hpp | 2 - .../ncm/source/ncm_icontentstorage.hpp | 2 - stratosphere/ncm/source/ncm_make_path.cpp | 8 +- stratosphere/ncm/source/ncm_make_path.hpp | 2 - stratosphere/ncm/source/ncm_path_utils.cpp | 2 +- stratosphere/ncm/source/ncm_path_utils.hpp | 2 - stratosphere/ncm/source/ncm_types.hpp | 201 ------------------ stratosphere/ncm/source/ncm_utils.hpp | 2 - 14 files changed, 209 insertions(+), 222 deletions(-) create mode 100644 stratosphere/libstratosphere/include/stratosphere/util/util_uuid.hpp delete mode 100644 stratosphere/ncm/source/ncm_types.hpp diff --git a/stratosphere/libstratosphere/include/stratosphere/ncm/ncm_types.hpp b/stratosphere/libstratosphere/include/stratosphere/ncm/ncm_types.hpp index 722fc4acc..89b13e158 100644 --- a/stratosphere/libstratosphere/include/stratosphere/ncm/ncm_types.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ncm/ncm_types.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include "../util/util_uuid.hpp" namespace sts::ncm { @@ -30,6 +31,104 @@ namespace sts::ncm { SdCard = 5, }; + enum class ContentMetaType : u8 { + Unknown = 0x0, + SystemProgram = 0x1, + SystemData = 0x2, + SystemUpdate = 0x3, + BootImagePackage = 0x4, + BootImagePackageSafe = 0x5, + Application = 0x80, + Patch = 0x81, + AddOnContent = 0x82, + Delta = 0x83, + }; + + enum class ContentType : u8 { + Meta = 0, + Program = 1, + Data = 2, + Control = 3, + HtmlDocument = 4, + LegalInformation = 5, + DeltaFragment = 6, + }; + + enum class ContentMetaAttribute : u8 { + None = 0, + IncludesExFatDriver = 1, + Rebootless = 2, + }; + + enum class ContentInstallType : u8 { + Full = 0, + FragmentOnly = 1, + Unknown = 7, + }; + + struct MountName { + char name[0x10]; + }; + + struct PlaceHolderId { + util::Uuid uuid; + + bool operator==(const PlaceHolderId& other) const { + return this->uuid == other.uuid; + } + + bool operator!=(const PlaceHolderId& other) const { + return this->uuid != other.uuid; + } + + bool operator==(const util::Uuid& other) const { + return this->uuid == other; + } + + bool operator!=(const util::Uuid& other) const { + return this->uuid != other; + } + } __attribute__((aligned(8))); + + static_assert(__alignof__(PlaceHolderId) == 8, "PlaceHolderId definition!"); + + struct ContentId { + util::Uuid uuid; + + bool operator==(const ContentId& other) const { + return this->uuid == other.uuid; + } + + bool operator!=(const ContentId& other) const { + return this->uuid != other.uuid; + } + + bool operator==(const util::Uuid& other) const { + return this->uuid == other; + } + + bool operator!=(const util::Uuid& other) const { + return this->uuid != other; + } + } __attribute__((aligned(4))); + + static_assert(__alignof__(ContentId) == 4, "ContentId definition!"); + + static constexpr PlaceHolderId InvalidPlaceHolderId = { util::InvalidUuid }; + static constexpr ContentId InvalidContentId = { util::InvalidUuid }; + + struct ContentInfo { + ContentId content_id; + u8 size[6]; + ContentType content_type; + u8 id_offset; + }; + + static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!"); + + typedef void (*MakeContentPathFunc)(char* out, ContentId content_id, const char* root); + typedef void (*MakePlaceHolderPathFunc)(char* out, PlaceHolderId placeholder_id, const char* root); + /* Title IDs. */ struct TitleId { u64 value; @@ -431,4 +530,65 @@ namespace sts::ncm { static_assert(sizeof(TitleLocation) == 0x10 && std::is_pod::value, "TitleLocation definition!"); + struct ContentMetaKey { + TitleId id; + u32 version; + ContentMetaType type; + ContentInstallType install_type; + u8 padding[2]; + + bool operator<(const ContentMetaKey& other) const { + if (this->id < other.id) { + return true; + } else if (this->id != other.id) { + return false; + } + + if (this->version < other.version) { + return true; + } else if (this->version != other.version) { + return false; + } + + if (this->type < other.type) { + return true; + } else if (this->type != other.type) { + return false; + } + + return this->install_type < other.install_type; + } + + bool operator==(const ContentMetaKey& other) const { + return this->id == other.id && + this->version == other.version && + this->type == other.type && + this->install_type == other.install_type; + } + + bool operator!=(const ContentMetaKey& other) const { + return !(*this == other); + } + + static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type) { + return { .id = title_id, .version = version, .type = type }; + } + + static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type, ContentInstallType install_type) { + return { .id = title_id, .version = version, .type = type, .install_type = install_type }; + } + }; + + static_assert(sizeof(ContentMetaKey) == 0x10, "ContentMetaKey definition!"); + + /* Used by system updates. They share the exact same struct as ContentMetaKey */ + typedef ContentMetaKey ContentMetaInfo; + + struct ApplicationContentMetaKey { + ContentMetaKey key; + TitleId application_title_id; + }; + + static_assert(sizeof(ApplicationContentMetaKey) == 0x18, "ApplicationContentMetaKey definition!"); + } diff --git a/stratosphere/libstratosphere/include/stratosphere/util.hpp b/stratosphere/libstratosphere/include/stratosphere/util.hpp index d33453d60..a278887f3 100644 --- a/stratosphere/libstratosphere/include/stratosphere/util.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/util.hpp @@ -21,3 +21,4 @@ #include "util/util_ini.hpp" #include "util/util_intrusive_list.hpp" #include "util/util_intrusive_red_black_tree.hpp" +#include "util/util_uuid.hpp" diff --git a/stratosphere/libstratosphere/include/stratosphere/util/util_uuid.hpp b/stratosphere/libstratosphere/include/stratosphere/util/util_uuid.hpp new file mode 100644 index 000000000..34f08eedb --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/util/util_uuid.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2019 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 sts::util { + + struct Uuid { + u8 uuid[0x10]; + + bool operator==(const Uuid& other) const { + return memcmp(this->uuid, other.uuid, sizeof(Uuid)) == 0; + } + + bool operator!=(const Uuid& other) const { + return !(*this == other); + } + + u8& operator[](size_t i) { + return uuid[i]; + } + }; + + static_assert(sizeof(Uuid) == 0x10, "Uuid definition!"); + + static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; + +} \ No newline at end of file diff --git a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp index fd43a8b37..07baefa7e 100644 --- a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp +++ b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp @@ -18,7 +18,6 @@ #include #include -#include "../ncm_types.hpp" #include "../ncm_path_utils.hpp" namespace sts::ncm::impl { diff --git a/stratosphere/ncm/source/impl/ncm_rights_cache.hpp b/stratosphere/ncm/source/impl/ncm_rights_cache.hpp index 9750c2a13..1f1d74332 100644 --- a/stratosphere/ncm/source/impl/ncm_rights_cache.hpp +++ b/stratosphere/ncm/source/impl/ncm_rights_cache.hpp @@ -18,8 +18,6 @@ #include #include -#include "../ncm_types.hpp" - namespace sts::ncm::impl { class RightsIdCache { @@ -28,7 +26,7 @@ namespace sts::ncm::impl { public: struct Entry { public: - Uuid uuid; + util::Uuid uuid; FsRightsId rights_id; u64 key_generation; u64 last_accessed = 1; diff --git a/stratosphere/ncm/source/ncm_fs.hpp b/stratosphere/ncm/source/ncm_fs.hpp index 1194dbea9..e59b0417a 100644 --- a/stratosphere/ncm/source/ncm_fs.hpp +++ b/stratosphere/ncm/source/ncm_fs.hpp @@ -19,8 +19,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm { Result OpenFile(FILE** out, const char* path, u32 mode); diff --git a/stratosphere/ncm/source/ncm_icontentmetadatabase.hpp b/stratosphere/ncm/source/ncm_icontentmetadatabase.hpp index 8eed6285c..194b4e541 100644 --- a/stratosphere/ncm/source/ncm_icontentmetadatabase.hpp +++ b/stratosphere/ncm/source/ncm_icontentmetadatabase.hpp @@ -19,8 +19,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm { class IContentMetaDatabase : public IServiceObject { diff --git a/stratosphere/ncm/source/ncm_icontentstorage.hpp b/stratosphere/ncm/source/ncm_icontentstorage.hpp index 11b4a0661..01300b583 100644 --- a/stratosphere/ncm/source/ncm_icontentstorage.hpp +++ b/stratosphere/ncm/source/ncm_icontentstorage.hpp @@ -18,8 +18,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm { class IContentStorage : public IServiceObject { diff --git a/stratosphere/ncm/source/ncm_make_path.cpp b/stratosphere/ncm/source/ncm_make_path.cpp index d1e82b2cb..7ca9a7047 100644 --- a/stratosphere/ncm/source/ncm_make_path.cpp +++ b/stratosphere/ncm/source/ncm_make_path.cpp @@ -21,15 +21,15 @@ namespace sts::ncm::path { namespace { - u16 Get16BitSha256HashPrefix(Uuid uuid) { + u16 Get16BitSha256HashPrefix(util::Uuid uuid) { u8 hash[SHA256_HASH_SIZE]; - sha256CalculateHash(hash, uuid.uuid, sizeof(Uuid)); + sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid)); return static_cast(hash[0]) | (static_cast(hash[1]) << 8); } - u8 Get8BitSha256HashPrefix(Uuid uuid) { + u8 Get8BitSha256HashPrefix(util::Uuid uuid) { u8 hash[SHA256_HASH_SIZE]; - sha256CalculateHash(hash, uuid.uuid, sizeof(Uuid)); + sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid)); return hash[0]; } diff --git a/stratosphere/ncm/source/ncm_make_path.hpp b/stratosphere/ncm/source/ncm_make_path.hpp index b8cd03224..f71458815 100644 --- a/stratosphere/ncm/source/ncm_make_path.hpp +++ b/stratosphere/ncm/source/ncm_make_path.hpp @@ -18,8 +18,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm::path { void MakeContentPathFlat(char* out_path, ContentId content_id, const char* root); diff --git a/stratosphere/ncm/source/ncm_path_utils.cpp b/stratosphere/ncm/source/ncm_path_utils.cpp index cf51fcbd2..c0bb22481 100644 --- a/stratosphere/ncm/source/ncm_path_utils.cpp +++ b/stratosphere/ncm/source/ncm_path_utils.cpp @@ -66,7 +66,7 @@ namespace sts::ncm::path { return false; } - for (size_t i = 0; i < sizeof(Uuid)*2; i++) { + for (size_t i = 0; i < sizeof(util::Uuid)*2; i++) { if (!std::isxdigit(file_name.at(i))) { return false; } diff --git a/stratosphere/ncm/source/ncm_path_utils.hpp b/stratosphere/ncm/source/ncm_path_utils.hpp index e538a1aec..cf13e2fae 100644 --- a/stratosphere/ncm/source/ncm_path_utils.hpp +++ b/stratosphere/ncm/source/ncm_path_utils.hpp @@ -18,8 +18,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm::path { inline void GetContentRootPath(char* out_content_root, const char* root_path) { diff --git a/stratosphere/ncm/source/ncm_types.hpp b/stratosphere/ncm/source/ncm_types.hpp deleted file mode 100644 index 44e1192d2..000000000 --- a/stratosphere/ncm/source/ncm_types.hpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2019 Adubbz - * - * 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 - -namespace sts::ncm { - - struct MountName { - char name[0x10]; - }; - - struct Uuid { - u8 uuid[0x10]; - - bool operator==(const Uuid& other) const { - return memcmp(this->uuid, other.uuid, sizeof(Uuid)) == 0; - } - - bool operator!=(const Uuid& other) const { - return !(*this == other); - } - - u8& operator[](size_t i) { - return uuid[i]; - } - }; - - static_assert(sizeof(Uuid) == 0x10, "Uuid definition!"); - - struct PlaceHolderId { - Uuid uuid; - - bool operator==(const PlaceHolderId& other) const { - return this->uuid == other.uuid; - } - - bool operator!=(const PlaceHolderId& other) const { - return this->uuid != other.uuid; - } - - bool operator==(const Uuid& other) const { - return this->uuid == other; - } - - bool operator!=(const Uuid& other) const { - return this->uuid != other; - } - } __attribute__((aligned(8))); - - static_assert(__alignof__(PlaceHolderId) == 8, "PlaceHolderId definition!"); - - struct ContentId { - Uuid uuid; - - bool operator==(const ContentId& other) const { - return this->uuid == other.uuid; - } - - bool operator!=(const ContentId& other) const { - return this->uuid != other.uuid; - } - - bool operator==(const Uuid& other) const { - return this->uuid == other; - } - - bool operator!=(const Uuid& other) const { - return this->uuid != other; - } - } __attribute__((aligned(4))); - - static_assert(__alignof__(ContentId) == 4, "ContentId definition!"); - - static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; - static constexpr PlaceHolderId InvalidPlaceHolderId = { InvalidUuid }; - static constexpr ContentId InvalidContentId = { InvalidUuid }; - - enum class ContentMetaType : u8 { - Unknown = 0x0, - SystemProgram = 0x1, - SystemData = 0x2, - SystemUpdate = 0x3, - BootImagePackage = 0x4, - BootImagePackageSafe = 0x5, - Application = 0x80, - Patch = 0x81, - AddOnContent = 0x82, - Delta = 0x83, - }; - - enum class ContentType : u8 { - Meta = 0, - Program = 1, - Data = 2, - Control = 3, - HtmlDocument = 4, - LegalInformation = 5, - DeltaFragment = 6, - }; - - enum class ContentMetaAttribute : u8 { - None = 0, - IncludesExFatDriver = 1, - Rebootless = 2, - }; - - enum class ContentInstallType : u8 { - Full = 0, - FragmentOnly = 1, - Unknown = 7, - }; - - struct ContentMetaKey { - TitleId id; - u32 version; - ContentMetaType type; - ContentInstallType install_type; - u8 padding[2]; - - bool operator<(const ContentMetaKey& other) const { - if (this->id < other.id) { - return true; - } else if (this->id != other.id) { - return false; - } - - if (this->version < other.version) { - return true; - } else if (this->version != other.version) { - return false; - } - - if (this->type < other.type) { - return true; - } else if (this->type != other.type) { - return false; - } - - return this->install_type < other.install_type; - } - - bool operator==(const ContentMetaKey& other) const { - return this->id == other.id && - this->version == other.version && - this->type == other.type && - this->install_type == other.install_type; - } - - bool operator!=(const ContentMetaKey& other) const { - return !(*this == other); - } - - static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type) { - return { .id = title_id, .version = version, .type = type }; - } - - static constexpr ContentMetaKey Make(TitleId title_id, u32 version, ContentMetaType type, ContentInstallType install_type) { - return { .id = title_id, .version = version, .type = type, .install_type = install_type }; - } - }; - - static_assert(sizeof(ContentMetaKey) == 0x10, "ContentMetaKey definition!"); - - // Used by system updates. They share the exact same struct as ContentMetaKey; - typedef ContentMetaKey ContentMetaInfo; - - struct ApplicationContentMetaKey { - ContentMetaKey key; - TitleId application_title_id; - }; - - static_assert(sizeof(ApplicationContentMetaKey) == 0x18, "ApplicationContentMetaKey definition!"); - - struct ContentInfo { - ContentId content_id; - u8 size[6]; - ContentType content_type; - u8 id_offset; - }; - - static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!"); - - typedef void (*MakeContentPathFunc)(char* out, ContentId content_id, const char* root); - typedef void (*MakePlaceHolderPathFunc)(char* out, PlaceHolderId placeholder_id, const char* root); - -} diff --git a/stratosphere/ncm/source/ncm_utils.hpp b/stratosphere/ncm/source/ncm_utils.hpp index 10aeb248a..920357a8b 100644 --- a/stratosphere/ncm/source/ncm_utils.hpp +++ b/stratosphere/ncm/source/ncm_utils.hpp @@ -19,8 +19,6 @@ #include #include -#include "ncm_types.hpp" - namespace sts::ncm { void GetStringFromContentId(char* out, ContentId content_id);