diff --git a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp index ba3a8249f..79f562e15 100644 --- a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp +++ b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp @@ -129,6 +129,7 @@ namespace sts::ncm::impl { this->GetPath(placeholder_path, placeholder_id); debug::DebugLog("Creating %s\n", placeholder_path); + D_LOG("size: 0x%lx\n", size); R_TRY_CATCH(fsdevCreateFile(placeholder_path, size, FS_CREATE_BIG_FILE)) { R_CATCH(ResultFsPathAlreadyExists) { return ResultNcmPlaceHolderAlreadyExists; diff --git a/stratosphere/ncm/source/ncm_contentstorage.cpp b/stratosphere/ncm/source/ncm_contentstorage.cpp index 8df832ff2..c33e78835 100644 --- a/stratosphere/ncm/source/ncm_contentstorage.cpp +++ b/stratosphere/ncm/source/ncm_contentstorage.cpp @@ -93,6 +93,9 @@ namespace sts::ncm { R_TRY(this->EnsureEnabled()); sts::rnd::GenerateRandomBytes(out.GetPointer(), sizeof(NcmNcaId)); + char placeholder_str[FS_MAX_PATH] = {0}; + GetStringFromPlaceHolderId(placeholder_str, *out.GetPointer()); + D_LOG("%s\n", placeholder_str); return ResultSuccess; R_DEBUG_END } diff --git a/stratosphere/ncm/source/ncm_fs.cpp b/stratosphere/ncm/source/ncm_fs.cpp index 03a1941b8..ea5537d6e 100644 --- a/stratosphere/ncm/source/ncm_fs.cpp +++ b/stratosphere/ncm/source/ncm_fs.cpp @@ -26,8 +26,10 @@ namespace sts::ncm { Result OpenFile(FILE** out, const char* path, u32 mode) { + R_DEBUG_START bool has = false; + D_LOG("path %s\n", path); /* Manually check if the file already exists, so it doesn't get created automatically. */ R_TRY(HasFile(&has, path)); if (!has) { @@ -36,18 +38,12 @@ namespace sts::ncm { const char* fopen_mode = ""; - if (mode & FS_OPEN_APPEND) { - if (mode & FS_OPEN_READ) { - fopen_mode = "r+b"; - } else if (mode & FS_OPEN_WRITE) { - fopen_mode = "w+b"; - } - } else { - if (mode & FS_OPEN_READ) { - fopen_mode = "rb"; - } else if (mode & FS_OPEN_WRITE) { - fopen_mode = "wb"; - } + /* Append is forced regardless of whether we set + as the mode. + We do so so the file doesn't get deleted. */ + if (mode & FS_OPEN_READ) { + fopen_mode = "r+b"; + } else if (mode & FS_OPEN_WRITE) { + fopen_mode = "w+b"; } FILE* f = fopen(path, fopen_mode); @@ -58,12 +54,23 @@ namespace sts::ncm { *out = f; return ResultSuccess; + R_DEBUG_END } Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) { R_DEBUG_START D_LOG("Writing 0x%llx to offset 0x%llx\n", size, offset); + if (fseek(f, 0, SEEK_END) != 0) { + return fsdevGetLastResult(); + } + size_t existing_size = ftell(f); + + if (offset + size > existing_size) { + D_LOG("offset: 0x%lx, size: 0x%lx, existing_size: 0x%lx\n", offset, size, existing_size); + return ResultFsFileExtensionWithoutOpenModeAllowAppend; + } + if (fseek(f, offset, SEEK_SET) != 0) { return fsdevGetLastResult(); }