Revert "Removed debug code"

This reverts commit d6ff261fcc.
This commit is contained in:
Adubbz
2019-08-06 21:32:28 +10:00
parent 5e0f4130c4
commit dac951f72b
14 changed files with 562 additions and 0 deletions

View File

@@ -20,6 +20,8 @@
#include "ncm_make_path.hpp"
#include "ncm_utils.hpp"
#include "debug.hpp"
namespace sts::ncm {
ContentStorageInterface::~ContentStorageInterface() {
@@ -92,15 +94,18 @@ namespace sts::ncm {
}
Result ContentStorageInterface::GeneratePlaceHolderId(Out<PlaceHolderId> out) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
sts::rnd::GenerateRandomBytes(out.GetPointer(), sizeof(NcmNcaId));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, u64 size) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -112,17 +117,21 @@ namespace sts::ncm {
R_TRY(this->placeholder_accessor.Create(placeholder_id, size));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::DeletePlaceHolder(PlaceHolderId placeholder_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
return this->placeholder_accessor.Delete(placeholder_id);
R_DEBUG_END
}
Result ContentStorageInterface::HasPlaceHolder(Out<bool> out, PlaceHolderId placeholder_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -135,9 +144,11 @@ namespace sts::ncm {
out.SetValue(has);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::WritePlaceHolder(PlaceHolderId placeholder_id, u64 offset, InBuffer<u8> data) {
R_DEBUG_START
/* Offset is too large */
if (offset >> 0x3f != 0) {
return ResultNcmInvalidOffset;
@@ -180,9 +191,11 @@ namespace sts::ncm {
this->placeholder_accessor.StoreToCache(f, placeholder_id);
file_guard.Cancel();
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::Register(PlaceHolderId placeholder_id, ContentId content_id) {
R_DEBUG_START
this->ClearContentCache();
if (this->disabled) {
@@ -207,9 +220,11 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::Delete(ContentId content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -227,9 +242,11 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::Has(Out<bool> out, ContentId content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -242,9 +259,11 @@ namespace sts::ncm {
out.SetValue(has);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetPath(OutPointerWithServerSize<lr::Path, 0x1> out, ContentId content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -254,10 +273,13 @@ namespace sts::ncm {
this->GetContentPath(content_path, content_id);
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, content_path));
*out.pointer = common_path;
D_LOG("path: %s\n", common_path);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetPlaceHolderPath(OutPointerWithServerSize<lr::Path, 0x1> out, PlaceHolderId placeholder_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -268,9 +290,11 @@ namespace sts::ncm {
R_TRY(ConvertToFsCommonPath(common_path, FS_MAX_PATH-1, placeholder_path));
*out.pointer = common_path;
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::CleanupAllPlaceHolder() {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -288,9 +312,11 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::ListPlaceHolder(Out<u32> out_count, OutBuffer<PlaceHolderId> out_buf) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -319,9 +345,11 @@ namespace sts::ncm {
out_count.SetValue(static_cast<u32>(entry_count));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetContentCount(Out<u32> out_count) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -344,9 +372,11 @@ namespace sts::ncm {
out_count.SetValue(content_count);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::ListContentId(Out<u32> out_count, OutBuffer<ContentId> out_buf, u32 start_offset) {
R_DEBUG_START
if (start_offset >> 0x1f != 0) {
return ResultNcmInvalidOffset;
}
@@ -391,11 +421,19 @@ namespace sts::ncm {
return ResultSuccess;
}));
for (size_t i = 0; i < entry_count; i++) {
char content_name[sizeof(ContentId)*2+1] = {0};
GetStringFromContentId(content_name, out_buf[i]);
D_LOG("content id: %s.nca\n", content_name);
}
out_count.SetValue(static_cast<u32>(entry_count));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetSizeFromContentId(Out<u64> out_size, ContentId content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -410,16 +448,20 @@ namespace sts::ncm {
out_size.SetValue(st.st_size);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::DisableForcibly() {
R_DEBUG_START
this->disabled = true;
this->ClearContentCache();
this->placeholder_accessor.ClearAllCaches();
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -448,18 +490,22 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::SetPlaceHolderSize(PlaceHolderId placeholder_id, u64 size) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
R_TRY(this->placeholder_accessor.SetSize(placeholder_id, size));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::ReadContentIdFile(OutBuffer<u8> buf, ContentId content_id, u64 offset) {
R_DEBUG_START
/* Offset is too large */
if (offset >> 0x3f != 0) {
return ResultNcmInvalidOffset;
@@ -482,9 +528,11 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetRightsIdFromPlaceHolderId(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, PlaceHolderId placeholder_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -502,9 +550,11 @@ namespace sts::ncm {
out_key_generation.SetValue(static_cast<u64>(key_generation));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetRightsIdFromContentId(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, ContentId content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -563,9 +613,11 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::WriteContentForDebug(ContentId content_id, u64 offset, InBuffer<u8> data) {
R_DEBUG_START
/* Offset is too large */
if (offset >> 0x3f != 0) {
return ResultNcmInvalidOffset;
@@ -612,34 +664,44 @@ namespace sts::ncm {
fflush(f);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetFreeSpaceSize(Out<u64> out_size) {
R_DEBUG_START
struct statvfs st = {0};
if (statvfs(this->root_path, &st) == -1) {
return fsdevGetLastResult();
}
D_LOG("free space: 0x%x\n", st.f_bfree);
out_size.SetValue(st.f_bfree);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetTotalSpaceSize(Out<u64> out_size) {
R_DEBUG_START
struct statvfs st = {0};
if (statvfs(this->root_path, &st) == -1) {
return fsdevGetLastResult();
}
D_LOG("total space: 0x%x\n", st.f_blocks);
out_size.SetValue(st.f_blocks);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::FlushPlaceHolder() {
R_DEBUG_START
this->placeholder_accessor.ClearAllCaches();
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetSizeFromPlaceHolderId(Out<u64> out_size, PlaceHolderId placeholder_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -664,9 +726,11 @@ namespace sts::ncm {
out_size.SetValue(st.st_size);
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::RepairInvalidFileAttribute() {
R_DEBUG_START
char content_root_path[FS_MAX_PATH] = {0};
this->GetContentRootPath(content_root_path);
unsigned int dir_depth = this->GetContentDirectoryDepth();
@@ -695,9 +759,11 @@ namespace sts::ncm {
R_TRY(TraverseDirectory(placeholder_root_path, dir_depth, fix_file_attributes));
return ResultSuccess;
R_DEBUG_END
}
Result ContentStorageInterface::GetRightsIdFromPlaceHolderIdWithCache(Out<FsRightsId> out_rights_id, Out<u64> out_key_generation, PlaceHolderId placeholder_id, ContentId cache_content_id) {
R_DEBUG_START
if (this->disabled) {
return ResultNcmInvalidContentStorage;
}
@@ -756,6 +822,7 @@ namespace sts::ncm {
}
return ResultSuccess;
R_DEBUG_END
}
}