mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 12:34:47 +00:00
ncm: FS_MAX_PATH-1 -> fs::EntryNameLengthMax
This commit is contained in:
parent
10777622e2
commit
cdf0445982
9 changed files with 32 additions and 30 deletions
|
@ -37,4 +37,6 @@ namespace ams::ncm {
|
|||
}
|
||||
};
|
||||
|
||||
using PathString = kvdb::BoundedString<fs::EntryNameLengthMax>;
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<u32>(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<u32>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Reference in a new issue