From cdf0445982d207e8c44f2578f8bb40dd8ac4bc7d Mon Sep 17 00:00:00 2001 From: Adubbz Date: Tue, 3 Mar 2020 23:13:20 +1100 Subject: [PATCH] ncm: FS_MAX_PATH-1 -> fs::EntryNameLengthMax --- .../include/stratosphere/ncm/ncm_path.hpp | 2 ++ .../ncm/source/ncm_content_storage_impl.cpp | 14 +++++++------- .../source/ncm_content_storage_impl_base.hpp | 2 +- stratosphere/ncm/source/ncm_fs.cpp | 2 +- stratosphere/ncm/source/ncm_fs.hpp | 2 +- stratosphere/ncm/source/ncm_make_path.cpp | 12 ++++++------ stratosphere/ncm/source/ncm_path_utils.cpp | 18 +++++++++--------- stratosphere/ncm/source/ncm_path_utils.hpp | 2 +- .../ncm_read_only_content_storage_impl.cpp | 8 ++++---- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_path.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_path.hpp index a0d1cd1fb..79799c674 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_path.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_path.hpp @@ -37,4 +37,6 @@ namespace ams::ncm { } }; + using PathString = kvdb::BoundedString; + } diff --git a/stratosphere/ncm/source/ncm_content_storage_impl.cpp b/stratosphere/ncm/source/ncm_content_storage_impl.cpp index 08d75840f..fe586f1bc 100644 --- a/stratosphere/ncm/source/ncm_content_storage_impl.cpp +++ b/stratosphere/ncm/source/ncm_content_storage_impl.cpp @@ -28,9 +28,9 @@ namespace ams::ncm { Result ContentStorageImpl::Initialize(const char *root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush, impl::RightsIdCache *rights_id_cache) { R_TRY(this->EnsureEnabled()); R_TRY(fs::CheckContentStorageDirectoriesExist(root_path)); - const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1); + const size_t root_path_len = strnlen(root_path, ams::fs::EntryNameLengthMax); - AMS_ABORT_UNLESS(root_path_len < FS_MAX_PATH-1); + AMS_ABORT_UNLESS(root_path_len < ams::fs::EntryNameLengthMax); strncpy(this->root_path, root_path, FS_MAX_PATH-2); this->make_content_path_func = *content_path_func; @@ -179,7 +179,7 @@ namespace ams::ncm { char content_path[FS_MAX_PATH] = {0}; char common_path[FS_MAX_PATH] = {0}; this->GetContentPath(content_path, content_id); - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, content_path)); out.SetValue(Path::Encode(common_path)); return ResultSuccess(); } @@ -190,7 +190,7 @@ namespace ams::ncm { char placeholder_path[FS_MAX_PATH] = {0}; char common_path[FS_MAX_PATH] = {0}; this->placeholder_accessor.GetPath(placeholder_path, placeholder_id); - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, placeholder_path)); out.SetValue(Path::Encode(common_path)); return ResultSuccess(); } @@ -383,7 +383,7 @@ namespace ams::ncm { char placeholder_path[FS_MAX_PATH] = {0}; char common_path[FS_MAX_PATH] = {0}; this->placeholder_accessor.GetPath(placeholder_path, placeholder_id); - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, placeholder_path)); ncm::RightsId rights_id; R_TRY(GetRightsId(&rights_id, common_path)); @@ -409,7 +409,7 @@ namespace ams::ncm { char content_path[FS_MAX_PATH] = {0}; char common_path[FS_MAX_PATH] = {0}; this->GetContentPath(content_path, content_id); - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, content_path)); ncm::RightsId rights_id; R_TRY(GetRightsId(&rights_id, common_path)); @@ -531,7 +531,7 @@ namespace ams::ncm { char placeholder_path[FS_MAX_PATH] = {0}; this->placeholder_accessor.GetPath(placeholder_path, placeholder_id); - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, placeholder_path)); ncm::RightsId rights_id; R_TRY(GetRightsId(&rights_id, common_path)); diff --git a/stratosphere/ncm/source/ncm_content_storage_impl_base.hpp b/stratosphere/ncm/source/ncm_content_storage_impl_base.hpp index 10f991fd3..3f32a6b42 100644 --- a/stratosphere/ncm/source/ncm_content_storage_impl_base.hpp +++ b/stratosphere/ncm/source/ncm_content_storage_impl_base.hpp @@ -23,7 +23,7 @@ namespace ams::ncm { NON_COPYABLE(ContentStorageImplBase); NON_MOVEABLE(ContentStorageImplBase); protected: - char root_path[FS_MAX_PATH-1]; + char root_path[ams::fs::EntryNameLengthMax]; MakeContentPathFunc make_content_path_func; bool disabled; protected: diff --git a/stratosphere/ncm/source/ncm_fs.cpp b/stratosphere/ncm/source/ncm_fs.cpp index df71bea82..d001e375e 100644 --- a/stratosphere/ncm/source/ncm_fs.cpp +++ b/stratosphere/ncm/source/ncm_fs.cpp @@ -150,7 +150,7 @@ namespace ams::ncm::fs { char working_path_buf[FS_MAX_PATH] = {0}; R_UNLESS(path_len + 1 < FS_MAX_PATH, ncm::ResultAllocationFailed()); - strncpy(working_path_buf + 1, path, FS_MAX_PATH-1); + strncpy(working_path_buf + 1, path, ams::fs::EntryNameLengthMax); if (path_len != 0) { for (size_t i = 0; i < path_len; i++) { diff --git a/stratosphere/ncm/source/ncm_fs.hpp b/stratosphere/ncm/source/ncm_fs.hpp index 6a7797c5b..e743c5a07 100644 --- a/stratosphere/ncm/source/ncm_fs.hpp +++ b/stratosphere/ncm/source/ncm_fs.hpp @@ -69,7 +69,7 @@ namespace ams::ncm::fs { } char current_path[FS_MAX_PATH]; - AMS_ABORT_UNLESS(snprintf(current_path, FS_MAX_PATH-1, "%s/%s", root_path, dir_entry->d_name) >= 0); + AMS_ABORT_UNLESS(snprintf(current_path, ams::fs::EntryNameLengthMax, "%s/%s", root_path, dir_entry->d_name) >= 0); bool should_continue = true; bool should_retry_dir_read = false; diff --git a/stratosphere/ncm/source/ncm_make_path.cpp b/stratosphere/ncm/source/ncm_make_path.cpp index 1a4dee1a9..fa940edaf 100644 --- a/stratosphere/ncm/source/ncm_make_path.cpp +++ b/stratosphere/ncm/source/ncm_make_path.cpp @@ -38,7 +38,7 @@ namespace ams::ncm::path { void MakeContentPathFlat(char *path_out, ContentId content_id, const char *root) { char content_name[FS_MAX_PATH] = {0}; GetContentFileName(content_name, content_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, content_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%s", root, content_name) >= 0); } void MakeContentPathDualLayered(char *path_out, ContentId content_id, const char *root) { @@ -48,34 +48,34 @@ namespace ams::ncm::path { const u32 hash_upper = (hash >> 10) & 0x3f; GetContentFileName(content_name, content_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%08X/%s", root, hash_upper, hash_lower, content_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%08X/%08X/%s", root, hash_upper, hash_lower, content_name) >= 0); } void MakeContentPath10BitLayered(char *path_out, ContentId content_id, const char *root) { char content_name[FS_MAX_PATH] = {0}; const u32 hash = (Get16BitSha256HashPrefix(content_id.uuid) >> 6) & 0x3FF; GetContentFileName(content_name, content_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash, content_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%08X/%s", root, hash, content_name) >= 0); } void MakeContentPathHashByteLayered(char *path_out, ContentId content_id, const char *root) { char content_name[FS_MAX_PATH] = {0}; const u32 hash_byte = static_cast(Get8BitSha256HashPrefix(content_id.uuid)); GetContentFileName(content_name, content_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, content_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%08X/%s", root, hash_byte, content_name) >= 0); } void MakePlaceHolderPathFlat(char *path_out, PlaceHolderId placeholder_id, const char *root) { char placeholder_name[FS_MAX_PATH] = {0}; GetPlaceHolderFileName(placeholder_name, placeholder_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%s", root, placeholder_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%s", root, placeholder_name) >= 0); } void MakePlaceHolderPathHashByteLayered(char *path_out, PlaceHolderId placeholder_id, const char *root) { char placeholder_name[FS_MAX_PATH] = {0}; const u32 hash_byte = static_cast(Get8BitSha256HashPrefix(placeholder_id.uuid)); GetPlaceHolderFileName(placeholder_name, placeholder_id); - AMS_ABORT_UNLESS(snprintf(path_out, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, placeholder_name) >= 0); + AMS_ABORT_UNLESS(snprintf(path_out, ams::fs::EntryNameLengthMax, "%s/%08X/%s", root, hash_byte, placeholder_name) >= 0); } } diff --git a/stratosphere/ncm/source/ncm_path_utils.cpp b/stratosphere/ncm/source/ncm_path_utils.cpp index d001042a6..0b4df999f 100644 --- a/stratosphere/ncm/source/ncm_path_utils.cpp +++ b/stratosphere/ncm/source/ncm_path_utils.cpp @@ -20,33 +20,33 @@ namespace ams::ncm::path { void GetContentMetaPath(char *out, ContentId content_id, MakeContentPathFunc path_func, const char *root_path) { - char tmp_path[FS_MAX_PATH-1] = {0}; - char content_path[FS_MAX_PATH-1] = {0}; + char tmp_path[ams::fs::EntryNameLengthMax] = {0}; + char content_path[ams::fs::EntryNameLengthMax] = {0}; path_func(content_path, content_id, root_path); - const size_t len = strnlen(content_path, FS_MAX_PATH-1); + const size_t len = strnlen(content_path, ams::fs::EntryNameLengthMax); const size_t len_no_extension = len - 4; AMS_ABORT_UNLESS(len_no_extension <= len); - AMS_ABORT_UNLESS(len_no_extension < FS_MAX_PATH-1); + AMS_ABORT_UNLESS(len_no_extension < ams::fs::EntryNameLengthMax); strncpy(tmp_path, content_path, len_no_extension); - memcpy(out, tmp_path, FS_MAX_PATH-1); - const size_t out_len = strnlen(out, FS_MAX_PATH-1); + memcpy(out, tmp_path, ams::fs::EntryNameLengthMax); + const size_t out_len = strnlen(out, ams::fs::EntryNameLengthMax); - AMS_ABORT_UNLESS(out_len + 9 < FS_MAX_PATH-1); + AMS_ABORT_UNLESS(out_len + 9 < ams::fs::EntryNameLengthMax); strncat(out, ".cnmt.nca", 0x2ff - out_len); } void GetContentFileName(char *out, ContentId content_id) { char content_name[sizeof(ContentId)*2+1] = {0}; GetStringFromContentId(content_name, content_id); - snprintf(out, FS_MAX_PATH-1, "%s%s", content_name, ".nca"); + snprintf(out, ams::fs::EntryNameLengthMax, "%s%s", content_name, ".nca"); } void GetPlaceHolderFileName(char *out, PlaceHolderId placeholder_id) { char placeholder_name[sizeof(PlaceHolderId)*2+1] = {0}; GetStringFromPlaceHolderId(placeholder_name, placeholder_id); - snprintf(out, FS_MAX_PATH-1, "%s%s", placeholder_name, ".nca"); + snprintf(out, ams::fs::EntryNameLengthMax, "%s%s", placeholder_name, ".nca"); } bool IsNcaPath(const char *path) { diff --git a/stratosphere/ncm/source/ncm_path_utils.hpp b/stratosphere/ncm/source/ncm_path_utils.hpp index 1e1a8669c..b2663710f 100644 --- a/stratosphere/ncm/source/ncm_path_utils.hpp +++ b/stratosphere/ncm/source/ncm_path_utils.hpp @@ -22,7 +22,7 @@ namespace ams::ncm::path { inline void GetContentRootPath(char *out_content_root, const char *root_path) { /* TODO: Replace with BoundedString? */ - AMS_ABORT_UNLESS(snprintf(out_content_root, FS_MAX_PATH-1, "%s%s", root_path, "/registered") >= 0); + AMS_ABORT_UNLESS(snprintf(out_content_root, ams::fs::EntryNameLengthMax, "%s%s", root_path, "/registered") >= 0); } inline void GetPlaceHolderRootPath(char *out_placeholder_root, const char *root_path) { diff --git a/stratosphere/ncm/source/ncm_read_only_content_storage_impl.cpp b/stratosphere/ncm/source/ncm_read_only_content_storage_impl.cpp index a99176d65..b2c797c30 100644 --- a/stratosphere/ncm/source/ncm_read_only_content_storage_impl.cpp +++ b/stratosphere/ncm/source/ncm_read_only_content_storage_impl.cpp @@ -23,8 +23,8 @@ namespace ams::ncm { Result ReadOnlyContentStorageImpl::Initialize(const char *root_path, MakeContentPathFunc content_path_func) { R_TRY(this->EnsureEnabled()); - const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1); - AMS_ABORT_UNLESS(root_path_len < FS_MAX_PATH-1); + const size_t root_path_len = strnlen(root_path, ams::fs::EntryNameLengthMax); + AMS_ABORT_UNLESS(root_path_len < ams::fs::EntryNameLengthMax); strncpy(this->root_path, root_path, FS_MAX_PATH-2); this->make_content_path_func = *content_path_func; return ResultSuccess(); @@ -90,7 +90,7 @@ namespace ams::ncm { this->make_content_path_func(content_path, content_id, this->root_path); } - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, content_path)); out.SetValue(Path::Encode(common_path)); return ResultSuccess(); @@ -203,7 +203,7 @@ namespace ams::ncm { this->make_content_path_func(content_path, content_id, this->root_path); } - R_TRY(fs::ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path)); + R_TRY(fs::ConvertToFsCommonPath(common_path, ams::fs::EntryNameLengthMax, content_path)); ncm::RightsId rights_id; R_TRY(GetRightsId(&rights_id, common_path));