Adopted R_UNLESS and R_CONVERT

This commit is contained in:
Adubbz 2020-02-24 23:53:39 +11:00
parent cf7412df06
commit 9fc43120b8
15 changed files with 163 additions and 441 deletions

View File

@ -66,9 +66,7 @@ namespace ams::lr::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
auto resolver = g_location_resolvers.Find(storage_id); auto resolver = g_location_resolvers.Find(storage_id);
if (!resolver) { R_UNLESS(resolver, ResultUnknownStorageId());
return ResultUnknownStorageId();
}
if (storage_id != ncm::StorageId::Host) { if (storage_id != ncm::StorageId::Host) {
(*resolver)->Refresh(); (*resolver)->Refresh();

View File

@ -148,9 +148,7 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
/* Already initialized. */ /* Already initialized. */
if (g_initialized) { R_UNLESS(!g_initialized, ResultSuccess());
return ResultSuccess();
}
size_t cur_storage_index = g_num_content_storage_entries; size_t cur_storage_index = g_num_content_storage_entries;
@ -283,16 +281,11 @@ namespace ams::ncm::impl {
Result CreateContentStorage(StorageId storage_id) { Result CreateContentStorage(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
R_TRY(fs::MountContentStorage(entry->mount_point, entry->content_storage_id)); R_TRY(fs::MountContentStorage(entry->mount_point, entry->content_storage_id));
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
@ -308,15 +301,11 @@ namespace ams::ncm::impl {
Result VerifyContentStorage(StorageId storage_id) { Result VerifyContentStorage(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
MountName mount_name = fs::CreateUniqueMountName(); MountName mount_name = fs::CreateUniqueMountName();
char mount_root[128] = {0}; char mount_root[128] = {0};
@ -336,15 +325,11 @@ namespace ams::ncm::impl {
Result OpenContentStorage(std::shared_ptr<IContentStorage>* out, StorageId storage_id) { Result OpenContentStorage(std::shared_ptr<IContentStorage>* out, StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
auto content_storage = entry->content_storage; auto content_storage = entry->content_storage;
@ -380,19 +365,11 @@ namespace ams::ncm::impl {
Result CloseContentStorageForcibly(StorageId storage_id) { Result CloseContentStorageForcibly(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage();
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) { R_UNLESS(entry->content_storage, ResultSuccess());
return ResultUnknownStorage();
}
if (!entry->content_storage) {
return ResultSuccess();
}
/* N doesn't bother checking the result of this */ /* N doesn't bother checking the result of this */
entry->content_storage->DisableForcibly(); entry->content_storage->DisableForcibly();
@ -404,20 +381,13 @@ namespace ams::ncm::impl {
Result ActivateContentStorage(StorageId storage_id) { Result ActivateContentStorage(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
/* Already activated. */ /* Already activated. */
if (entry->content_storage != nullptr) { R_UNLESS(entry->content_storage == nullptr, ResultSuccess());
return ResultSuccess();
}
if (storage_id == StorageId::GameCard) { if (storage_id == StorageId::GameCard) {
FsGameCardHandle gc_hnd; FsGameCardHandle gc_hnd;
@ -462,20 +432,13 @@ namespace ams::ncm::impl {
Result InactivateContentStorage(StorageId storage_id) { Result InactivateContentStorage(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentStorageEntry* entry = FindContentStorageEntry(storage_id); ContentStorageEntry* entry = FindContentStorageEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
/* Already inactivated. */ /* Already inactivated. */
if (entry->content_storage == nullptr) { R_UNLESS(entry->content_storage != nullptr, ResultSuccess());
return ResultSuccess();
}
entry->content_storage->DisableForcibly(); entry->content_storage->DisableForcibly();
entry->content_storage = nullptr; entry->content_storage = nullptr;
@ -486,15 +449,12 @@ namespace ams::ncm::impl {
Result CreateContentMetaDatabase(StorageId storage_id) { Result CreateContentMetaDatabase(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || storage_id == StorageId::GameCard || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(storage_id != StorageId::GameCard, ResultUnknownStorage());
} R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
/* N doesn't bother checking the result of this. */ /* N doesn't bother checking the result of this. */
fsDisableAutoSaveDataCreation(); fsDisableAutoSaveDataCreation();
@ -519,22 +479,14 @@ namespace ams::ncm::impl {
Result VerifyContentMetaDatabase(StorageId storage_id) { Result VerifyContentMetaDatabase(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::GameCard) { R_UNLESS(storage_id != StorageId::GameCard, ResultSuccess());
return ResultSuccess(); R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
} R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) {
return ResultUnknownStorage();
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
bool mounted_save_data = false; bool mounted_save_data = false;
if (!entry->content_meta_database) { if (!entry->content_meta_database) {
R_TRY(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id)); R_TRY(fs::MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id));
mounted_save_data = true; mounted_save_data = true;
@ -548,9 +500,7 @@ namespace ams::ncm::impl {
bool has_meta_path = false; bool has_meta_path = false;
R_TRY(fs::HasDirectory(&has_meta_path, entry->meta_path)); R_TRY(fs::HasDirectory(&has_meta_path, entry->meta_path));
if (!has_meta_path) { R_UNLESS(has_meta_path, ResultInvalidContentMetaDatabase());
return ResultInvalidContentMetaDatabase();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -558,15 +508,11 @@ namespace ams::ncm::impl {
Result OpenContentMetaDatabase(std::shared_ptr<IContentMetaDatabase>* out, StorageId storage_id) { Result OpenContentMetaDatabase(std::shared_ptr<IContentMetaDatabase>* out, StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
std::shared_ptr<IContentMetaDatabase> content_meta_db = entry->content_meta_database; std::shared_ptr<IContentMetaDatabase> content_meta_db = entry->content_meta_database;
@ -602,21 +548,13 @@ namespace ams::ncm::impl {
Result CloseContentMetaDatabaseForcibly(StorageId storage_id) { Result CloseContentMetaDatabaseForcibly(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage();
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
std::shared_ptr<IContentMetaDatabase> content_meta_db = entry->content_meta_database; std::shared_ptr<IContentMetaDatabase> content_meta_db = entry->content_meta_database;
R_UNLESS(content_meta_db, ResultSuccess());
if (!content_meta_db) {
return ResultSuccess();
}
/* N doesn't bother checking the result of this */ /* N doesn't bother checking the result of this */
content_meta_db->DisableForcibly(); content_meta_db->DisableForcibly();
@ -633,15 +571,11 @@ namespace ams::ncm::impl {
Result CleanupContentMetaDatabase(StorageId storage_id) { Result CleanupContentMetaDatabase(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
if (!entry) {
return ResultUnknownStorage();
}
R_TRY(fsDeleteSaveDataFileSystemBySaveDataSpaceId(entry->save_meta.space_id, entry->save_meta.id)); R_TRY(fsDeleteSaveDataFileSystemBySaveDataSpaceId(entry->save_meta.space_id, entry->save_meta.id));
return ResultSuccess(); return ResultSuccess();
@ -650,16 +584,13 @@ namespace ams::ncm::impl {
Result ActivateContentMetaDatabase(StorageId storage_id) { Result ActivateContentMetaDatabase(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
/* Already activated. */ /* Already activated. */
if (entry->content_meta_database != nullptr) { R_UNLESS(entry->content_meta_database == nullptr, ResultSuccess());
return ResultSuccess();
}
/* Make a brand new kvs. N doesn't quite do this, but we will for cleanliness. */ /* Make a brand new kvs. N doesn't quite do this, but we will for cleanliness. */
entry->kvs.emplace(); entry->kvs.emplace();
@ -686,16 +617,13 @@ namespace ams::ncm::impl {
Result InactivateContentMetaDatabase(StorageId storage_id) { Result InactivateContentMetaDatabase(StorageId storage_id) {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
if (storage_id == StorageId::None || static_cast<u8>(storage_id) == 6) { R_UNLESS(storage_id != StorageId::None, ResultUnknownStorage());
return ResultUnknownStorage(); R_UNLESS(static_cast<u8>(storage_id) != 6, ResultUnknownStorage());
}
ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id); ContentMetaDBEntry* entry = FindContentMetaDBEntry(storage_id);
R_UNLESS(entry, ResultUnknownStorage());
/* Already inactivated. */ /* Already inactivated. */
if (entry->content_meta_database == nullptr) { R_UNLESS(entry->content_meta_database != nullptr, ResultSuccess());
return ResultSuccess();
}
entry->content_meta_database->DisableForcibly(); entry->content_meta_database->DisableForcibly();
entry->content_meta_database = nullptr; entry->content_meta_database = nullptr;

View File

@ -23,9 +23,7 @@
namespace ams::ncm::impl { namespace ams::ncm::impl {
Result PlaceHolderAccessor::Open(FILE** out_handle, PlaceHolderId placeholder_id) { Result PlaceHolderAccessor::Open(FILE** out_handle, PlaceHolderId placeholder_id) {
if (this->LoadFromCache(out_handle, placeholder_id)) { R_UNLESS(!this->LoadFromCache(out_handle, placeholder_id), ResultSuccess());
return ResultSuccess();
}
char placeholder_path[FS_MAX_PATH] = {0}; char placeholder_path[FS_MAX_PATH] = {0};
this->MakePath(placeholder_path, placeholder_id); this->MakePath(placeholder_path, placeholder_id);
@ -127,9 +125,7 @@ namespace ams::ncm::impl {
this->GetPath(placeholder_path, placeholder_id); this->GetPath(placeholder_path, placeholder_id);
R_TRY_CATCH(fsdevCreateFile(placeholder_path, size, FsCreateOption_BigFile)) { R_TRY_CATCH(fsdevCreateFile(placeholder_path, size, FsCreateOption_BigFile)) {
R_CATCH(ams::fs::ResultPathAlreadyExists) { R_CONVERT(ams::fs::ResultPathAlreadyExists, ResultPlaceHolderAlreadyExists())
return ResultPlaceHolderAlreadyExists();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
return ResultSuccess(); return ResultSuccess();
@ -142,9 +138,7 @@ namespace ams::ncm::impl {
if (std::remove(placeholder_path) != 0) { if (std::remove(placeholder_path) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultPlaceHolderNotFound())
return ResultPlaceHolderNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
} }
@ -155,9 +149,7 @@ namespace ams::ncm::impl {
FILE* f = nullptr; FILE* f = nullptr;
R_TRY_CATCH(this->Open(&f, placeholder_id)) { R_TRY_CATCH(this->Open(&f, placeholder_id)) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultPlaceHolderNotFound())
return ResultPlaceHolderNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
@ -173,9 +165,7 @@ namespace ams::ncm::impl {
this->MakePath(placeholder_path, placeholder_id); this->MakePath(placeholder_path, placeholder_id);
if (truncate(placeholder_path, size) == -1) { if (truncate(placeholder_path, size) == -1) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultPlaceHolderNotFound())
return ResultPlaceHolderNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
} }
@ -207,13 +197,9 @@ namespace ams::ncm::impl {
this->StoreToCache(f, placeholder_id); this->StoreToCache(f, placeholder_id);
if (fseek(f, 0L, SEEK_END) != 0) { R_UNLESS(fseek(f, 0L, SEEK_END) == 0, fsdevGetLastResult());
return fsdevGetLastResult();
}
size_t size = ftell(f); size_t size = ftell(f);
if (fseek(f, 0L, SEEK_SET) != 0) { R_UNLESS(fseek(f, 0L, SEEK_SET) == 0, fsdevGetLastResult());
return fsdevGetLastResult();
}
*found_in_cache = true; *found_in_cache = true;
*out_size = size; *out_size = size;

View File

@ -21,13 +21,9 @@ namespace ams::lr {
Result AddOnContentLocationResolverInterface::ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) { Result AddOnContentLocationResolverInterface::ResolveAddOnContentPath(sf::Out<Path> out, ncm::ProgramId id) {
ncm::StorageId storage_id = ncm::StorageId::None; ncm::StorageId storage_id = ncm::StorageId::None;
R_UNLESS(this->registered_storages.Find(&storage_id, id), ResultAddOnContentNotFound());
if (!this->registered_storages.Find(&storage_id, id)) {
return ResultAddOnContentNotFound();
}
std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database; std::shared_ptr<ncm::IContentMetaDatabase> content_meta_database;
ncm::ContentId data_content_id; ncm::ContentId data_content_id;
R_TRY(ncm::impl::OpenContentMetaDatabase(&content_meta_database, storage_id)); R_TRY(ncm::impl::OpenContentMetaDatabase(&content_meta_database, storage_id));
R_TRY(content_meta_database->GetLatestData(&data_content_id, id)); R_TRY(content_meta_database->GetLatestData(&data_content_id, id));
@ -40,18 +36,12 @@ namespace ams::lr {
} }
Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) { Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorageDeprecated(ncm::StorageId storage_id, ncm::ProgramId id) {
if (!this->registered_storages.Register(id, storage_id, ncm::ProgramId::Invalid)) { R_UNLESS(this->registered_storages.Register(id, storage_id, ncm::ProgramId::Invalid), ResultTooManyRegisteredPaths());
return ResultTooManyRegisteredPaths();
}
return ResultSuccess(); return ResultSuccess();
} }
Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) { Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::ProgramId id, ncm::ProgramId application_id) {
if (!this->registered_storages.Register(id, storage_id, application_id)) { R_UNLESS(this->registered_storages.Register(id, storage_id, application_id), ResultTooManyRegisteredPaths());
return ResultTooManyRegisteredPaths();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -63,10 +53,10 @@ namespace ams::lr {
Result AddOnContentLocationResolverInterface::RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) { Result AddOnContentLocationResolverInterface::RefreshApplicationAddOnContent(const sf::InArray<ncm::ProgramId> &ids) {
if (ids.GetSize() == 0) { if (ids.GetSize() == 0) {
this->registered_storages.Clear(); this->registered_storages.Clear();
return ResultSuccess(); } else {
this->registered_storages.ClearExcluding(ids.GetPointer(), ids.GetSize());
} }
this->registered_storages.ClearExcluding(ids.GetPointer(), ids.GetSize());
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -28,16 +28,11 @@ namespace ams::lr {
} }
Result ContentLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id)) { R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id), ResultSuccess());
return ResultSuccess();
}
ncm::ContentId program_content_id; ncm::ContentId program_content_id;
R_TRY_CATCH(this->content_meta_database->GetLatestProgram(&program_content_id, id)) { R_TRY_CATCH(this->content_meta_database->GetLatestProgram(&program_content_id, id)) {
R_CATCH(ncm::ResultContentMetaNotFound) { R_CONVERT(ncm::ResultContentMetaNotFound, ResultProgramNotFound())
return ResultProgramNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
this->GetContentStoragePath(out.GetPointer(), program_content_id); this->GetContentStoragePath(out.GetPointer(), program_content_id);
@ -50,19 +45,13 @@ namespace ams::lr {
} }
Result ContentLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id), ResultControlNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultControlNotFound();
} }
Result ContentLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id), ResultHtmlDocumentNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultHtmlDocumentNotFound();
} }
Result ContentLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) {
@ -94,11 +83,8 @@ namespace ams::lr {
} }
Result ContentLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id), ResultLegalInformationNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultLegalInformationNotFound();
} }
Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
@ -120,7 +106,6 @@ namespace ams::lr {
this->content_meta_database = std::move(content_meta_database); this->content_meta_database = std::move(content_meta_database);
this->content_storage = std::move(content_storage); this->content_storage = std::move(content_storage);
this->ClearRedirections(); this->ClearRedirections();
return ResultSuccess(); return ResultSuccess();
} }
@ -165,14 +150,10 @@ namespace ams::lr {
} }
Result ContentLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) { Result ContentLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id)) { R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id), ResultSuccess());
return ResultSuccess();
}
R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) { R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) {
R_CATCH(ResultProgramNotFound) { R_CONVERT(ResultProgramNotFound, ResultDebugProgramNotFound())
return ResultDebugProgramNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
return ResultSuccess(); return ResultSuccess();

View File

@ -28,11 +28,8 @@ namespace ams::lr {
} }
Result RedirectOnlyLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id), ResultProgramNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultProgramNotFound();
} }
Result RedirectOnlyLocationResolverInterface::RedirectProgramPath(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::RedirectProgramPath(const Path &path, ncm::ProgramId id) {
@ -41,19 +38,13 @@ namespace ams::lr {
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id), ResultControlNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultControlNotFound();
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id), ResultHtmlDocumentNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultHtmlDocumentNotFound();
} }
Result RedirectOnlyLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveDataPath(sf::Out<Path> out, ncm::ProgramId id) {
@ -81,11 +72,8 @@ namespace ams::lr {
} }
Result RedirectOnlyLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id)) { R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id), ResultLegalInformationNotFound());
return ResultSuccess(); return ResultSuccess();
}
return ResultLegalInformationNotFound();
} }
Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) {
@ -152,14 +140,10 @@ namespace ams::lr {
} }
Result RedirectOnlyLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) { Result RedirectOnlyLocationResolverInterface::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
if (this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id)) { R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id), ResultSuccess());
return ResultSuccess();
}
R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) { R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) {
R_CATCH(ResultProgramNotFound) { R_CONVERT(ResultProgramNotFound, ResultDebugProgramNotFound())
return ResultDebugProgramNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
return ResultSuccess(); return ResultSuccess();

View File

@ -63,10 +63,7 @@ namespace ams::lr {
} }
Result RegisteredLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { Result RegisteredLocationResolverInterface::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
if (!this->ResolvePath(out.GetPointer(), &this->program_redirector, &this->registered_program_locations, id)) { R_UNLESS(this->ResolvePath(out.GetPointer(), &this->program_redirector, &this->registered_program_locations, id), ResultProgramNotFound());
return ResultProgramNotFound();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -96,10 +93,7 @@ namespace ams::lr {
} }
Result RegisteredLocationResolverInterface::ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { Result RegisteredLocationResolverInterface::ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) {
if (!this->ResolvePath(out.GetPointer(), &this->html_docs_redirector, &this->registered_html_docs_locations, id)) { R_UNLESS(this->ResolvePath(out.GetPointer(), &this->html_docs_redirector, &this->registered_html_docs_locations, id), ResultHtmlDocumentNotFound());
return ResultHtmlDocumentNotFound();
}
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -74,9 +74,7 @@ namespace ams::ncm {
Result GetContentMetaSize(size_t *out, const ContentMetaKey &key, const kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) { Result GetContentMetaSize(size_t *out, const ContentMetaKey &key, const kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) {
R_TRY_CATCH(kvs->GetValueSize(out, key)) { R_TRY_CATCH(kvs->GetValueSize(out, key)) {
R_CATCH(kvdb::ResultKeyNotFound) { R_CONVERT(kvdb::ResultKeyNotFound, ResultContentMetaNotFound())
return ResultContentMetaNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
return ResultSuccess(); return ResultSuccess();
@ -94,9 +92,8 @@ namespace ams::ncm {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
const auto it = this->kvs->lower_bound(key); const auto it = this->kvs->lower_bound(key);
if (it == this->kvs->end() || it->GetKey().id != key.id) { R_UNLESS(it != this->kvs->end(), ResultContentMetaNotFound());
return ResultContentMetaNotFound(); R_UNLESS(it->GetKey().id == key.id, ResultContentMetaNotFound());
}
const auto stored_key = it->GetKey(); const auto stored_key = it->GetKey();
const void* value = nullptr; const void* value = nullptr;
@ -105,9 +102,7 @@ namespace ams::ncm {
R_TRY(GetContentMetaValuePointer(&value, &value_size, stored_key, this->kvs)); R_TRY(GetContentMetaValuePointer(&value, &value_size, stored_key, this->kvs));
const auto header = GetValueHeader(value); const auto header = GetValueHeader(value);
if (header->content_count == 0) { R_UNLESS(header->content_count != 0, ResultContentNotFound());
return ResultContentNotFound();
}
const ContentInfo* content_infos = GetValueContentInfos(value); const ContentInfo* content_infos = GetValueContentInfos(value);
const ContentInfo* found_content_info = nullptr; const ContentInfo* found_content_info = nullptr;
@ -135,10 +130,7 @@ namespace ams::ncm {
found_content_info = lowest_id_offset_info; found_content_info = lowest_id_offset_info;
} }
if (!found_content_info) { R_UNLESS(found_content_info, ResultContentNotFound());
return ResultContentNotFound();
}
*out = found_content_info->content_id; *out = found_content_info->content_id;
return ResultSuccess(); return ResultSuccess();
} }
@ -161,10 +153,7 @@ namespace ams::ncm {
} }
} }
if (!found_key) { R_UNLESS(found_key, ResultContentMetaNotFound());
return ResultContentMetaNotFound();
}
*out_key = key; *out_key = key;
return ResultSuccess(); return ResultSuccess();
} }
@ -195,11 +184,9 @@ namespace ams::ncm {
} }
Result ContentMetaDatabaseInterface::ListContentInfo(sf::Out<u32> out_count, const sf::OutArray<ContentInfo> &out_info, ContentMetaKey key, u32 offset) { Result ContentMetaDatabaseInterface::ListContentInfo(sf::Out<u32> out_count, const sf::OutArray<ContentInfo> &out_info, ContentMetaKey key, u32 offset) {
if (offset >> 0x1f != 0) { R_UNLESS(offset >> 0x1f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
const void *value = nullptr; const void *value = nullptr;
size_t value_size = 0; size_t value_size = 0;
R_TRY(GetContentMetaValuePointer(&value, &value_size, key, this->kvs)); R_TRY(GetContentMetaValuePointer(&value, &value_size, key, this->kvs));
@ -367,15 +354,11 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::GetSize(sf::Out<u64> out_size, ContentMetaKey key) { Result ContentMetaDatabaseInterface::GetSize(sf::Out<u64> out_size, ContentMetaKey key) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(this->kvs->GetCount() != 0, ResultContentMetaNotFound());
if (this->kvs->GetCount() == 0) {
return ResultContentMetaNotFound();
}
const auto it = this->kvs->lower_bound(key); const auto it = this->kvs->lower_bound(key);
if (it == this->kvs->end() || it->GetKey() != key) { R_UNLESS(it != this->kvs->end(), ResultContentMetaNotFound());
return ResultContentMetaNotFound(); R_UNLESS(it->GetKey() == key, ResultContentMetaNotFound());
}
out_size.SetValue(it->GetValueSize()); out_size.SetValue(it->GetValueSize());
return ResultSuccess(); return ResultSuccess();
@ -383,10 +366,7 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::GetRequiredSystemVersion(sf::Out<u32> out_version, ContentMetaKey key) { Result ContentMetaDatabaseInterface::GetRequiredSystemVersion(sf::Out<u32> out_version, ContentMetaKey key) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch, ResultInvalidContentMetaKey());
if (key.type != ContentMetaType::Application && key.type != ContentMetaType::Patch) {
return ResultInvalidContentMetaKey();
}
const void* value = nullptr; const void* value = nullptr;
size_t value_size = 0; size_t value_size = 0;
@ -401,10 +381,7 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::GetPatchId(sf::Out<ProgramId> out_patch_id, ContentMetaKey key) { Result ContentMetaDatabaseInterface::GetPatchId(sf::Out<ProgramId> out_patch_id, ContentMetaKey key) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(key.type != ContentMetaType::Application, ResultInvalidContentMetaKey());
if (key.type != ContentMetaType::Application) {
return ResultInvalidContentMetaKey();
}
const void* value = nullptr; const void* value = nullptr;
size_t value_size = 0; size_t value_size = 0;
@ -422,19 +399,14 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) { Result ContentMetaDatabaseInterface::LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(out_orphaned.GetSize() >= content_ids.GetSize(), ResultBufferInsufficient());
if (out_orphaned.GetSize() < content_ids.GetSize()) {
return ResultBufferInsufficient();
}
/* Default to orphaned for all content ids. */ /* Default to orphaned for all content ids. */
if (out_orphaned.GetSize() > 0) { if (out_orphaned.GetSize() > 0) {
std::fill_n(out_orphaned.GetPointer(), out_orphaned.GetSize(), true); std::fill_n(out_orphaned.GetPointer(), out_orphaned.GetSize(), true);
} }
if (this->kvs->GetCount() == 0) { R_UNLESS(this->kvs->GetCount() != 0, ResultSuccess());
return ResultSuccess();
}
for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) {
const auto value = entry->GetValuePointer(); const auto value = entry->GetValuePointer();
@ -498,10 +470,7 @@ namespace ams::ncm {
} }
Result ContentMetaDatabaseInterface::ListContentMetaInfo(sf::Out<u32> out_entries_written, const sf::OutArray<ContentMetaInfo> &out_meta_info, ContentMetaKey key, u32 start_index) { Result ContentMetaDatabaseInterface::ListContentMetaInfo(sf::Out<u32> out_entries_written, const sf::OutArray<ContentMetaInfo> &out_meta_info, ContentMetaKey key, u32 start_index) {
if (start_index >> 0x1f != 0) { R_UNLESS(start_index >> 0x1f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
const void* value = nullptr; const void* value = nullptr;
@ -555,9 +524,7 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
if (key.type != ContentMetaType::AddOnContent) { R_UNLESS(key.type == ContentMetaType::AddOnContent, ResultInvalidContentMetaKey());
return ResultInvalidContentMetaKey();
}
const auto ext_header = GetValueExtendedHeader<AddOnContentMetaExtendedHeader>(value); const auto ext_header = GetValueExtendedHeader<AddOnContentMetaExtendedHeader>(value);
out_version.SetValue(ext_header->required_application_version); out_version.SetValue(ext_header->required_application_version);
return ResultSuccess(); return ResultSuccess();
@ -600,10 +567,7 @@ namespace ams::ncm {
found_key = entry->GetKey(); found_key = entry->GetKey();
} }
if (!found_key) { R_UNLESS(found_key, ResultContentMetaNotFound());
return ResultContentMetaNotFound();
}
*out_key = *found_key; *out_key = *found_key;
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -68,18 +68,14 @@ namespace ams::ncm {
} }
Result ContentStorageInterface::OpenCachedContentFile(ContentId content_id) { Result ContentStorageInterface::OpenCachedContentFile(ContentId content_id) {
if (this->cached_content_id == content_id) { R_UNLESS(this->cached_content_id != content_id, ResultSuccess());
return ResultSuccess();
}
this->ClearContentCache(); this->ClearContentCache();
char content_path[FS_MAX_PATH] = {0}; char content_path[FS_MAX_PATH] = {0};
this->GetContentPath(content_path, content_id); this->GetContentPath(content_path, content_id);
R_TRY_CATCH(fs::OpenFile(&this->content_cache_file_handle, content_path, FsOpenMode_Read)) { R_TRY_CATCH(fs::OpenFile(&this->content_cache_file_handle, content_path, FsOpenMode_Read)) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultContentNotFound())
return ResultContentNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
this->cached_content_id = content_id; this->cached_content_id = content_id;
@ -127,10 +123,7 @@ namespace ams::ncm {
Result ContentStorageInterface::WritePlaceHolder(PlaceHolderId placeholder_id, u64 offset, sf::InBuffer data) { Result ContentStorageInterface::WritePlaceHolder(PlaceHolderId placeholder_id, u64 offset, sf::InBuffer data) {
/* Offset is too large */ /* Offset is too large */
if (offset >> 0x3f != 0) { R_UNLESS(offset >> 0x3f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_TRY(this->placeholder_accessor.Write(placeholder_id, offset, data.GetPointer(), data.GetSize())); R_TRY(this->placeholder_accessor.Write(placeholder_id, offset, data.GetPointer(), data.GetSize()));
return ResultSuccess(); return ResultSuccess();
@ -148,12 +141,8 @@ namespace ams::ncm {
if (rename(placeholder_path, content_path) != 0) { if (rename(placeholder_path, content_path) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultPlaceHolderNotFound())
return ResultPlaceHolderNotFound(); R_CONVERT(ams::fs::ResultPathAlreadyExists, ResultContentAlreadyExists())
}
R_CATCH(ams::fs::ResultPathAlreadyExists) {
return ResultContentAlreadyExists();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
} }
@ -169,9 +158,7 @@ namespace ams::ncm {
if (std::remove(content_path) != 0) { if (std::remove(content_path) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultContentNotFound())
return ResultContentNotFound();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
} }
@ -223,11 +210,7 @@ namespace ams::ncm {
/* Nintendo uses CleanDirectoryRecursively which is 3.0.0+. /* Nintendo uses CleanDirectoryRecursively which is 3.0.0+.
We'll just delete the directory and recreate it to support all firmwares. */ We'll just delete the directory and recreate it to support all firmwares. */
R_TRY(fsdevDeleteDirectoryRecursively(placeholder_root_path)); R_TRY(fsdevDeleteDirectoryRecursively(placeholder_root_path));
R_UNLESS(mkdir(placeholder_root_path, S_IRWXU) != -1, fsdevGetLastResult());
if (mkdir(placeholder_root_path, S_IRWXU) == -1) {
return fsdevGetLastResult();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -244,9 +227,7 @@ namespace ams::ncm {
*should_retry_dir_read = false; *should_retry_dir_read = false;
if (dir_entry->d_type == DT_REG) { if (dir_entry->d_type == DT_REG) {
if (entry_count > out_buf.GetSize()) { R_UNLESS(entry_count <= out_buf.GetSize(), ResultBufferInsufficient());
return ResultBufferInsufficient();
}
PlaceHolderId cur_entry_placeholder_id = {0}; PlaceHolderId cur_entry_placeholder_id = {0};
R_TRY(GetPlaceHolderIdFromDirEntry(&cur_entry_placeholder_id, dir_entry)); R_TRY(GetPlaceHolderIdFromDirEntry(&cur_entry_placeholder_id, dir_entry));
@ -283,11 +264,8 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentStorageInterface::ListContentId(sf::Out<u32> out_count, const sf::OutArray<ContentId> &out_buf, u32 start_offset) { Result ContentStorageInterface::ListContentId(sf::Out<u32> out_count, const sf::OutArray<ContentId> &out_buf, u32 start_offset) {
if (start_offset >> 0x1f != 0) { R_UNLESS(start_offset >> 0x1f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
char content_root_path[FS_MAX_PATH] = {0}; char content_root_path[FS_MAX_PATH] = {0};
@ -342,10 +320,7 @@ namespace ams::ncm {
this->GetContentPath(content_path, content_id); this->GetContentPath(content_path, content_id);
struct stat st; struct stat st;
if (stat(content_path, &st) == -1) { R_UNLESS(stat(content_path, &st) != -1, fsdevGetLastResult());
return fsdevGetLastResult();
}
out_size.SetValue(st.st_size); out_size.SetValue(st.st_size);
return ResultSuccess(); return ResultSuccess();
} }
@ -374,12 +349,8 @@ namespace ams::ncm {
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id); this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
if (rename(old_content_path, placeholder_path) != 0) { if (rename(old_content_path, placeholder_path) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathNotFound) { R_CONVERT(ams::fs::ResultPathNotFound, ResultPlaceHolderNotFound())
return ResultPlaceHolderNotFound(); R_CONVERT(ams::fs::ResultPathAlreadyExists, ResultPlaceHolderAlreadyExists())
}
R_CATCH(ams::fs::ResultPathAlreadyExists) {
return ResultPlaceHolderAlreadyExists();
}
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
} }
@ -394,10 +365,7 @@ namespace ams::ncm {
Result ContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) { Result ContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) {
/* Offset is too large */ /* Offset is too large */
if (offset >> 0x3f != 0) { R_UNLESS(offset >> 0x3f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
char content_path[FS_MAX_PATH] = {0}; char content_path[FS_MAX_PATH] = {0};
this->GetContentPath(content_path, content_id); this->GetContentPath(content_path, content_id);
@ -484,10 +452,7 @@ namespace ams::ncm {
Result ContentStorageInterface::WriteContentForDebug(ContentId content_id, u64 offset, sf::InBuffer data) { Result ContentStorageInterface::WriteContentForDebug(ContentId content_id, u64 offset, sf::InBuffer data) {
/* Offset is too large */ /* Offset is too large */
if (offset >> 0x3f != 0) { R_UNLESS(offset >> 0x3f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
bool is_development = false; bool is_development = false;
@ -515,20 +480,14 @@ namespace ams::ncm {
Result ContentStorageInterface::GetFreeSpaceSize(sf::Out<u64> out_size) { Result ContentStorageInterface::GetFreeSpaceSize(sf::Out<u64> out_size) {
struct statvfs st = {0}; struct statvfs st = {0};
if (statvfs(this->root_path, &st) == -1) { R_UNLESS(statvfs(this->root_path, &st) != -1, fsdevGetLastResult());
return fsdevGetLastResult();
}
out_size.SetValue(st.f_bfree); out_size.SetValue(st.f_bfree);
return ResultSuccess(); return ResultSuccess();
} }
Result ContentStorageInterface::GetTotalSpaceSize(sf::Out<u64> out_size) { Result ContentStorageInterface::GetTotalSpaceSize(sf::Out<u64> out_size) {
struct statvfs st = {0}; struct statvfs st = {0};
if (statvfs(this->root_path, &st) == -1) { R_UNLESS(statvfs(this->root_path, &st) != -1, fsdevGetLastResult());
return fsdevGetLastResult();
}
out_size.SetValue(st.f_blocks); out_size.SetValue(st.f_blocks);
return ResultSuccess(); return ResultSuccess();
} }
@ -555,9 +514,7 @@ namespace ams::ncm {
struct stat st; struct stat st;
this->placeholder_accessor.GetPath(placeholder_path, placeholder_id); this->placeholder_accessor.GetPath(placeholder_path, placeholder_id);
if (stat(placeholder_path, &st) == -1) { R_UNLESS(stat(placeholder_path, &st) != -1, fsdevGetLastResult());
return fsdevGetLastResult();
}
out_size.SetValue(st.st_size); out_size.SetValue(st.st_size);
return ResultSuccess(); return ResultSuccess();

View File

@ -28,9 +28,7 @@ namespace ams::ncm::fs {
/* Manually check if the file already exists, so it doesn't get created automatically. */ /* Manually check if the file already exists, so it doesn't get created automatically. */
R_TRY(HasFile(&has, path)); R_TRY(HasFile(&has, path));
if (!has) { R_UNLESS(has, ams::fs::ResultPathNotFound());
return ams::fs::ResultPathNotFound();
}
const char* fopen_mode = ""; const char* fopen_mode = "";
@ -40,32 +38,19 @@ namespace ams::ncm::fs {
fopen_mode = "rb"; fopen_mode = "rb";
} }
FILE* f = fopen(path, fopen_mode); FILE* f = fopen(path, fopen_mode);
R_UNLESS(f != nullptr, fsdevGetLastResult());
if (f == nullptr) {
return fsdevGetLastResult();
}
*out = f; *out = f;
return ResultSuccess(); return ResultSuccess();
} }
Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) { Result WriteFile(FILE* f, size_t offset, const void* buffer, size_t size, u32 option) {
if (fseek(f, 0, SEEK_END) != 0) { R_UNLESS(fseek(f, 0, SEEK_END) == 0, fsdevGetLastResult());
return fsdevGetLastResult();
}
size_t existing_size = ftell(f); size_t existing_size = ftell(f);
if (offset + size > existing_size) { R_UNLESS(offset + size <= existing_size, ams::fs::ResultFileExtensionWithoutOpenModeAllowAppend());
return ams::fs::ResultFileExtensionWithoutOpenModeAllowAppend(); R_UNLESS(fseek(f, offset, SEEK_SET) == 0, fsdevGetLastResult());
} R_UNLESS(fwrite(buffer, 1, size, f) == size, fsdevGetLastResult());
if (fseek(f, offset, SEEK_SET) != 0) {
return fsdevGetLastResult();
}
if (fwrite(buffer, 1, size, f) != size) {
return fsdevGetLastResult();
}
if (option & FsWriteOption_Flush) { if (option & FsWriteOption_Flush) {
fflush(f); fflush(f);
@ -75,14 +60,8 @@ namespace ams::ncm::fs {
} }
Result ReadFile(FILE* f, size_t offset, void* buffer, size_t size) { Result ReadFile(FILE* f, size_t offset, void* buffer, size_t size) {
if (fseek(f, offset, SEEK_SET) != 0) { R_UNLESS(fseek(f, offset, SEEK_SET) == 0, fsdevGetLastResult());
return fsdevGetLastResult(); R_UNLESS(fread(buffer, 1, size, f) == size || !ferror(f), fsdevGetLastResult());
}
if (fread(buffer, 1, size, f) != size && ferror(f)) {
return fsdevGetLastResult();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -124,25 +103,17 @@ namespace ams::ncm::fs {
bool has_root = false; bool has_root = false;
R_TRY(HasDirectory(&has_root, root_path)); R_TRY(HasDirectory(&has_root, root_path));
if (!has_root) { R_UNLESS(has_root, ResultStorageRootNotFound());
return ResultStorageRootNotFound();
}
path::GetContentRootPath(content_root, root_path); path::GetContentRootPath(content_root, root_path);
bool has_content_root = false; bool has_content_root = false;
R_TRY(HasDirectory(&has_content_root, content_root)); R_TRY(HasDirectory(&has_content_root, content_root));
if (!has_content_root) { R_UNLESS(has_content_root, ResultStoragePathNotFound());
return ResultStoragePathNotFound();
}
path::GetPlaceHolderRootPath(placeholder_root, root_path); path::GetPlaceHolderRootPath(placeholder_root, root_path);
bool has_placeholder_root = false; bool has_placeholder_root = false;
R_TRY(HasDirectory(&has_placeholder_root, placeholder_root)); R_TRY(HasDirectory(&has_placeholder_root, placeholder_root));
if (!has_placeholder_root) { R_UNLESS(has_placeholder_root, ResultStoragePathNotFound());
return ResultStoragePathNotFound();
}
return ResultSuccess(); return ResultSuccess();
} }
@ -172,36 +143,31 @@ namespace ams::ncm::fs {
} }
Result EnsureRecursively(const char* path) { Result EnsureRecursively(const char* path) {
if (!path) { R_UNLESS(path, ams::fs::ResultNullptrArgument());
return ams::fs::ResultNullptrArgument();
}
size_t path_len = strlen(path); size_t path_len = strlen(path);
char working_path_buf[FS_MAX_PATH] = {0}; char working_path_buf[FS_MAX_PATH] = {0};
if (path_len + 1 < FS_MAX_PATH) { R_UNLESS(path_len + 1 < FS_MAX_PATH, ResultAllocationFailed());
strncpy(working_path_buf + 1, path, FS_MAX_PATH-1); strncpy(working_path_buf + 1, path, FS_MAX_PATH-1);
if (path_len != 0) { if (path_len != 0) {
for (size_t i = 0; i < path_len; i++) { for (size_t i = 0; i < path_len; i++) {
if (i != 0 && working_path_buf[i + 1] == '/' && working_path_buf[i] != ':') { if (i != 0 && working_path_buf[i + 1] == '/' && working_path_buf[i] != ':') {
/* Temporarily make the path terminate before the '/' */ /* Temporarily make the path terminate before the '/' */
working_path_buf[i + 1] = 0; working_path_buf[i + 1] = 0;
if (mkdir(working_path_buf + 1, S_IRWXU) == -1) { if (mkdir(working_path_buf + 1, S_IRWXU) == -1) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ams::fs::ResultPathAlreadyExists) { R_CATCH(ams::fs::ResultPathAlreadyExists) {
/* If the path already exists, that's okay. Anything else is an error. */ /* If the path already exists, that's okay. Anything else is an error. */
} }
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
}
/* Restore the path to its former state */
working_path_buf[i + 1] = '/';
} }
/* Restore the path to its former state */
working_path_buf[i + 1] = '/';
} }
} }
} else {
return ResultAllocationFailed();
} }
return ResultSuccess(); return ResultSuccess();
@ -237,18 +203,15 @@ namespace ams::ncm::fs {
const char* unqual_path = strchr(path, ':'); const char* unqual_path = strchr(path, ':');
/* We should be given a qualified path. */ /* We should be given a qualified path. */
if (!unqual_path || unqual_path > path + 0xf) { R_UNLESS(unqual_path, ams::fs::ResultInvalidMountName());
return ams::fs::ResultInvalidMountName(); R_UNLESS(unqual_path <= path + 0xf, ams::fs::ResultInvalidMountName());
}
strncpy(mount_name->name, path, unqual_path - path); strncpy(mount_name->name, path, unqual_path - path);
return ResultSuccess(); return ResultSuccess();
} }
Result MountSystemSaveData(const char* mount_point, FsSaveDataSpaceId space_id, u64 save_id) { Result MountSystemSaveData(const char* mount_point, FsSaveDataSpaceId space_id, u64 save_id) {
if (!mount_point) { R_UNLESS(mount_point, ams::fs::ResultNullptrArgument());
return ams::fs::ResultNullptrArgument();
}
FsSaveDataAttribute save = { FsSaveDataAttribute save = {
.system_save_data_id = save_id, .system_save_data_id = save_id,
@ -276,9 +239,7 @@ namespace ams::ncm::fs {
std::map<std::string, std::string> g_mount_content_storage; std::map<std::string, std::string> g_mount_content_storage;
Result MountContentStorage(const char* mount_point, FsContentStorageId id) { Result MountContentStorage(const char* mount_point, FsContentStorageId id) {
if (!mount_point) { R_UNLESS(mount_point, ams::fs::ResultNullptrArgument());
return ams::fs::ResultNullptrArgument();
}
FsFileSystem fs; FsFileSystem fs;
R_TRY(fsOpenContentStorageFileSystem(&fs, id)); R_TRY(fsOpenContentStorageFileSystem(&fs, id));
@ -325,9 +286,7 @@ namespace ams::ncm::fs {
} }
Result Unmount(const char* mount_point) { Result Unmount(const char* mount_point) {
if (!mount_point) { R_UNLESS(mount_point, ams::fs::ResultNullptrArgument());
return ams::fs::ResultNullptrArgument();
}
/* Erase any content storage mappings which may potentially exist. */ /* Erase any content storage mappings which may potentially exist. */
g_mount_content_storage.erase(mount_point); g_mount_content_storage.erase(mount_point);
@ -340,16 +299,13 @@ namespace ams::ncm::fs {
} }
Result ConvertToFsCommonPath(char* out_common_path, size_t out_len, const char* path) { Result ConvertToFsCommonPath(char* out_common_path, size_t out_len, const char* path) {
if (!out_common_path || !path) { R_UNLESS(out_common_path, ams::fs::ResultNullptrArgument());
return ams::fs::ResultNullptrArgument(); R_UNLESS(path, ams::fs::ResultNullptrArgument());
}
MountName mount_name = {0}; MountName mount_name = {0};
R_TRY(GetMountNameFromPath(&mount_name, path)); R_TRY(GetMountNameFromPath(&mount_name, path));
R_UNLESS(fsdevGetDeviceFileSystem(mount_name.name), ams::fs::ResultNotMounted());
if (!fsdevGetDeviceFileSystem(mount_name.name) || g_mount_content_storage.find(mount_name.name) == g_mount_content_storage.end()) { R_UNLESS(g_mount_content_storage.find(mount_name.name) != g_mount_content_storage.end(), ams::fs::ResultNotMounted());
return ams::fs::ResultNotMounted();
}
char translated_path[FS_MAX_PATH] = {0}; char translated_path[FS_MAX_PATH] = {0};
std::string common_mount_name = g_mount_content_storage[mount_name.name]; std::string common_mount_name = g_mount_content_storage[mount_name.name];

View File

@ -54,17 +54,13 @@ namespace ams::ncm::fs {
Result TraverseDirectory(bool* out_should_continue, const char* root_path, int max_level, F f) { Result TraverseDirectory(bool* out_should_continue, const char* root_path, int max_level, F f) {
DIR *dir; DIR *dir;
struct dirent* dir_entry = nullptr; struct dirent* dir_entry = nullptr;
if (max_level < 1) { R_UNLESS(max_level >= 1, ResultSuccess());
return ResultSuccess();
}
bool retry_dir_read = true; bool retry_dir_read = true;
while (retry_dir_read) { while (retry_dir_read) {
retry_dir_read = false; retry_dir_read = false;
if ((dir = opendir(root_path)) == nullptr) { R_UNLESS((dir = opendir(root_path)) != nullptr, fsdevGetLastResult());
return fsdevGetLastResult();
}
ON_SCOPE_EXIT { closedir(dir); }; ON_SCOPE_EXIT { closedir(dir); };
while ((dir_entry = readdir(dir)) != nullptr) { while ((dir_entry = readdir(dir)) != nullptr) {

View File

@ -52,9 +52,7 @@ namespace ams::ncm {
bool disabled; bool disabled;
protected: protected:
Result EnsureEnabled() { Result EnsureEnabled() {
if (this->disabled) { R_UNLESS(!this->disabled, ResultInvalidContentMetaDatabase());
return ResultInvalidContentMetaDatabase();
}
return ResultSuccess(); return ResultSuccess();
} }
public: public:

View File

@ -58,9 +58,7 @@ namespace ams::ncm {
bool disabled; bool disabled;
protected: protected:
Result EnsureEnabled() { Result EnsureEnabled() {
if (this->disabled) { R_UNLESS(!this->disabled, ResultInvalidContentStorage());
return ResultInvalidContentStorage();
}
return ResultSuccess(); return ResultSuccess();
} }
public: public:

View File

@ -134,10 +134,7 @@ namespace ams::ncm {
} }
struct stat st; struct stat st;
if (stat(content_path, &st) == -1) { R_UNLESS(stat(content_path, &st) != -1, fsdevGetLastResult());
return fsdevGetLastResult();
}
out_size.SetValue(st.st_size); out_size.SetValue(st.st_size);
return ResultSuccess(); return ResultSuccess();
} }
@ -157,10 +154,7 @@ namespace ams::ncm {
Result ReadOnlyContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) { Result ReadOnlyContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) {
/* Offset is too large */ /* Offset is too large */
if (offset >> 0x3f != 0) { R_UNLESS(offset >> 0x3f == 0, ResultInvalidOffset());
return ResultInvalidOffset();
}
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
char content_path[FS_MAX_PATH] = {0}; char content_path[FS_MAX_PATH] = {0};
@ -181,7 +175,6 @@ namespace ams::ncm {
}; };
R_TRY(fs::ReadFile(f, offset, buf.GetPointer(), buf.GetSize())); R_TRY(fs::ReadFile(f, offset, buf.GetPointer(), buf.GetSize()));
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -31,9 +31,8 @@ namespace ams::ncm {
} }
Result GetPlaceHolderIdFromDirEntry(PlaceHolderId* out, struct dirent* dir_entry) { Result GetPlaceHolderIdFromDirEntry(PlaceHolderId* out, struct dirent* dir_entry) {
if (strnlen(dir_entry->d_name, 0x30) != 0x24 || strncmp(dir_entry->d_name + 0x20, ".nca", 4) != 0) { R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ResultInvalidPlaceHolderDirectoryEntry());
return ResultInvalidPlaceHolderDirectoryEntry(); R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ResultInvalidPlaceHolderDirectoryEntry());
}
PlaceHolderId placeholder_id = {0}; PlaceHolderId placeholder_id = {0};
char byte_string[2]; char byte_string[2];