ncm/lr: Pointer placement

This commit is contained in:
Adubbz 2020-02-29 10:31:28 +11:00
parent 9c5600bf82
commit 1483df1f77
29 changed files with 201 additions and 201 deletions

View File

@ -47,7 +47,7 @@ namespace ams::ncm {
GetContentIdByTypeAndIdOffset = 20, GetContentIdByTypeAndIdOffset = 20,
}; };
protected: protected:
ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs; ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs;
char mount_name[16]; char mount_name[16];
bool disabled; bool disabled;
protected: protected:
@ -56,13 +56,13 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
public: public:
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) : IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) :
kvs(kvs), disabled(false) kvs(kvs), disabled(false)
{ {
/* ... */ /* ... */
} }
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs, const char* mount_name) : IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs, const char *mount_name) :
IContentMetaDatabase(kvs) IContentMetaDatabase(kvs)
{ {
std::strcpy(this->mount_name, mount_name); std::strcpy(this->mount_name, mount_name);
@ -92,8 +92,8 @@ namespace ams::ncm {
virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) = 0; virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) = 0;
/* APIs. */ /* APIs. */
virtual Result GetLatestProgram(ContentId* out_content_id, ProgramId program_id) = 0; virtual Result GetLatestProgram(ContentId *out_content_id, ProgramId program_id) = 0;
virtual Result GetLatestData(ContentId* out_content_id, ProgramId program_id) = 0; virtual Result GetLatestData(ContentId *out_content_id, ProgramId program_id) = 0;
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(Set), MAKE_SERVICE_COMMAND_META(Set),

View File

@ -114,8 +114,8 @@ namespace ams::ncm {
static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!"); static_assert(sizeof(ContentInfo) == 0x18, "ContentInfo definition!");
using MakeContentPathFunc = void (*)(char* out, ContentId content_id, const char* root); using MakeContentPathFunc = void (*)(char *out, ContentId content_id, const char *root);
using MakePlaceHolderPathFunc = void (*)(char* out, PlaceHolderId placeholder_id, const char* root); using MakePlaceHolderPathFunc = void (*)(char *out, PlaceHolderId placeholder_id, const char *root);
/* Storage IDs. */ /* Storage IDs. */
enum class StorageId : u8 { enum class StorageId : u8 {

View File

@ -31,7 +31,7 @@ namespace ams::lr {
} }
/* Helper function. */ /* Helper function. */
void ContentLocationResolverImpl::GetContentStoragePath(Path* out, ncm::ContentId content_id) { void ContentLocationResolverImpl::GetContentStoragePath(Path *out, ncm::ContentId content_id) {
R_ABORT_UNLESS(this->content_storage->GetPath(out, content_id)); R_ABORT_UNLESS(this->content_storage->GetPath(out, content_id));
} }

View File

@ -32,7 +32,7 @@ namespace ams::lr {
~ContentLocationResolverImpl(); ~ContentLocationResolverImpl();
private: private:
/* Helper functions. */ /* Helper functions. */
void GetContentStoragePath(Path* out, ncm::ContentId content_id); void GetContentStoragePath(Path *out, ncm::ContentId content_id);
public: public:
/* Actual commands. */ /* Actual commands. */
virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override; virtual Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) override;

View File

@ -109,7 +109,7 @@ namespace ams::lr {
} }
} }
void LocationRedirector::ClearRedirectionsExcludingOwners(const ncm::ProgramId* excluding_ids, size_t num_ids) { void LocationRedirector::ClearRedirectionsExcludingOwners(const ncm::ProgramId *excluding_ids, size_t num_ids) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) { for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) {
/* Skip removal if the redirection has an excluded owner program id. */ /* Skip removal if the redirection has an excluded owner program id. */
if (this->IsExcluded(it->GetOwnerProgramId(), excluding_ids, num_ids)) { if (this->IsExcluded(it->GetOwnerProgramId(), excluding_ids, num_ids)) {

View File

@ -44,9 +44,9 @@ namespace ams::lr {
void SetRedirectionFlags(ncm::ProgramId program_id, u32 flags); void SetRedirectionFlags(ncm::ProgramId program_id, u32 flags);
void EraseRedirection(ncm::ProgramId program_id); void EraseRedirection(ncm::ProgramId program_id);
void ClearRedirections(u32 flags = RedirectionFlags_None); void ClearRedirections(u32 flags = RedirectionFlags_None);
void ClearRedirectionsExcludingOwners(const ncm::ProgramId* excluding_ids, size_t num_ids); void ClearRedirectionsExcludingOwners(const ncm::ProgramId *excluding_ids, size_t num_ids);
private: private:
inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId* excluding_ids, size_t num_ids) const { inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId *excluding_ids, size_t num_ids) const {
for (size_t i = 0; i < num_ids; i++) { for (size_t i = 0; i < num_ids; i++) {
if (id == excluding_ids[i]) { if (id == excluding_ids[i]) {
return true; return true;

View File

@ -42,7 +42,7 @@ namespace ams::lr {
this->legal_info_redirector.ClearRedirections(flags); this->legal_info_redirector.ClearRedirections(flags);
} }
void ClearRedirections(const ncm::ProgramId* excluding_ids, size_t num_ids) { void ClearRedirections(const ncm::ProgramId *excluding_ids, size_t num_ids) {
this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); this->program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); this->debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);
this->app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); this->app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids);

View File

@ -34,7 +34,7 @@ namespace ams::lr {
Entry entries[NumEntries]; Entry entries[NumEntries];
size_t capacity; size_t capacity;
private: private:
inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId* excluding_ids, size_t num_ids) const { inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId *excluding_ids, size_t num_ids) const {
/* Try to find program id in exclusions. */ /* Try to find program id in exclusions. */
for (size_t i = 0; i < num_ids; i++) { for (size_t i = 0; i < num_ids; i++) {
if (id == excluding_ids[i]) { if (id == excluding_ids[i]) {
@ -120,7 +120,7 @@ namespace ams::lr {
} }
} }
void ClearExcluding(const ncm::ProgramId* ids, size_t num_ids) { void ClearExcluding(const ncm::ProgramId *ids, size_t num_ids) {
/* Invalidate all entries unless excluded. */ /* Invalidate all entries unless excluded. */
for (size_t i = 0; i < this->GetCapacity(); i++) { for (size_t i = 0; i < this->GetCapacity(); i++) {
Entry& entry = this->entries[i]; Entry& entry = this->entries[i];

View File

@ -57,7 +57,7 @@ namespace ams::lr {
this->program_redirector.ClearRedirections(flags); this->program_redirector.ClearRedirections(flags);
} }
Result RegisteredLocationResolverImpl::RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids) { Result RegisteredLocationResolverImpl::RefreshImpl(const ncm::ProgramId *excluding_ids, size_t num_ids) {
/* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */ /* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */
if (hos::GetVersion() < hos::Version_900) { if (hos::GetVersion() < hos::Version_900) {
this->ClearRedirections(); this->ClearRedirections();

View File

@ -43,7 +43,7 @@ namespace ams::lr {
private: private:
/* Helper functions. */ /* Helper functions. */
void ClearRedirections(u32 flags = RedirectionFlags_None); void ClearRedirections(u32 flags = RedirectionFlags_None);
Result RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids); Result RefreshImpl(const ncm::ProgramId *excluding_ids, size_t num_ids);
public: public:
RegisteredLocationResolverImpl() : registered_program_locations(GetMaxRegisteredLocations()), registered_html_docs_locations(GetMaxRegisteredLocations()) { /* ... */ } RegisteredLocationResolverImpl() : registered_program_locations(GetMaxRegisteredLocations()), registered_html_docs_locations(GetMaxRegisteredLocations()) { /* ... */ }
~RegisteredLocationResolverImpl(); ~RegisteredLocationResolverImpl();

View File

@ -167,7 +167,7 @@ namespace ams::ncm::impl {
Result FindContentStorageRoot(ContentStorageRoot **out, StorageId storage_id) { Result FindContentStorageRoot(ContentStorageRoot **out, StorageId storage_id) {
for (size_t i = 0; i < MaxContentStorageEntries; i++) { for (size_t i = 0; i < MaxContentStorageEntries; i++) {
ContentStorageRoot* root = &g_content_storage_roots[i]; ContentStorageRoot *root = &g_content_storage_roots[i];
if (root->storage_id == storage_id) { if (root->storage_id == storage_id) {
*out = root; *out = root;
@ -185,7 +185,7 @@ namespace ams::ncm::impl {
Result FindContentMetaDatabaseEntry(ContentMetaDatabaseEntry **out, StorageId storage_id) { Result FindContentMetaDatabaseEntry(ContentMetaDatabaseEntry **out, StorageId storage_id) {
for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) { for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) {
ContentMetaDatabaseEntry* entry = &g_content_meta_entries[i]; ContentMetaDatabaseEntry *entry = &g_content_meta_entries[i];
if (entry->storage_id == storage_id) { if (entry->storage_id == storage_id) {
*out = entry; *out = entry;
@ -255,12 +255,12 @@ namespace ams::ncm::impl {
R_UNLESS(!g_initialized, ResultSuccess()); R_UNLESS(!g_initialized, ResultSuccess());
for (size_t i = 0; i < MaxContentStorageEntries; i++) { for (size_t i = 0; i < MaxContentStorageEntries; i++) {
ContentStorageRoot* entry = &g_content_storage_roots[i]; ContentStorageRoot *entry = &g_content_storage_roots[i];
entry->storage_id = StorageId::None; entry->storage_id = StorageId::None;
} }
for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) { for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) {
ContentMetaDatabaseEntry* entry = &g_content_meta_entries[i]; ContentMetaDatabaseEntry *entry = &g_content_meta_entries[i];
entry->storage_id = StorageId::None; entry->storage_id = StorageId::None;
} }
@ -314,23 +314,23 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
for (size_t i = 0; i < MaxContentStorageEntries; i++) { for (size_t i = 0; i < MaxContentStorageEntries; i++) {
ContentStorageRoot* entry = &g_content_storage_roots[i]; ContentStorageRoot *entry = &g_content_storage_roots[i];
InactivateContentStorage(entry->storage_id); InactivateContentStorage(entry->storage_id);
} }
for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) { for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) {
ContentMetaDatabaseEntry* entry = &g_content_meta_entries[i]; ContentMetaDatabaseEntry *entry = &g_content_meta_entries[i];
InactivateContentMetaDatabase(entry->storage_id); InactivateContentMetaDatabase(entry->storage_id);
} }
} }
for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) { for (size_t i = 0; i < MaxContentMetaDatabaseEntries; i++) {
ContentMetaDatabaseEntry* entry = &g_content_meta_entries[i]; ContentMetaDatabaseEntry *entry = &g_content_meta_entries[i];
entry->kvs.reset(); entry->kvs.reset();
} }
for (size_t i = 0; i < MaxContentStorageEntries; i++) { for (size_t i = 0; i < MaxContentStorageEntries; i++) {
ContentStorageRoot* entry = &g_content_storage_roots[i]; ContentStorageRoot *entry = &g_content_storage_roots[i];
entry->content_storage = nullptr; entry->content_storage = nullptr;
} }
} }
@ -338,7 +338,7 @@ 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);
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id)); R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id));
R_TRY(fs::MountContentStorage(root->mount_point, root->content_storage_id)); R_TRY(fs::MountContentStorage(root->mount_point, root->content_storage_id));
@ -353,7 +353,7 @@ 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);
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id)); R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id));
char mount_root[0x80] = {}; char mount_root[0x80] = {};
@ -368,10 +368,10 @@ namespace ams::ncm::impl {
return ResultSuccess(); return ResultSuccess();
} }
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);
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id)); R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id));
auto content_storage = root->content_storage; auto content_storage = root->content_storage;
@ -394,7 +394,7 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
R_UNLESS(storage_id != StorageId::None, ncm::ResultUnknownStorage()); R_UNLESS(storage_id != StorageId::None, ncm::ResultUnknownStorage());
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(FindContentStorageRoot(std::addressof(root), storage_id)); R_TRY(FindContentStorageRoot(std::addressof(root), storage_id));
if (root->content_storage) { if (root->content_storage) {
@ -410,7 +410,7 @@ 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);
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id)); R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id));
/* Already activated. */ /* Already activated. */
@ -460,7 +460,7 @@ 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);
ContentStorageRoot* root; ContentStorageRoot *root;
R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id)); R_TRY(GetUniqueContentStorageRoot(std::addressof(root), storage_id));
/* Already inactivated. */ /* Already inactivated. */
@ -476,7 +476,7 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
R_UNLESS(storage_id != StorageId::GameCard, ncm::ResultUnknownStorage()); R_UNLESS(storage_id != StorageId::GameCard, ncm::ResultUnknownStorage());
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
/* N doesn't bother checking the result of this. */ /* N doesn't bother checking the result of this. */
@ -495,7 +495,7 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
R_UNLESS(storage_id != StorageId::GameCard, ResultSuccess()); R_UNLESS(storage_id != StorageId::GameCard, ResultSuccess());
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
auto mount_guard = SCOPE_GUARD { fs::Unmount(entry->mount_point); }; auto mount_guard = SCOPE_GUARD { fs::Unmount(entry->mount_point); };
@ -512,10 +512,10 @@ namespace ams::ncm::impl {
return ResultSuccess(); return ResultSuccess();
} }
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);
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
auto content_meta_db = entry->content_meta_database; auto content_meta_db = entry->content_meta_database;
@ -538,7 +538,7 @@ namespace ams::ncm::impl {
std::scoped_lock lk(g_mutex); std::scoped_lock lk(g_mutex);
R_UNLESS(storage_id != StorageId::None, ncm::ResultUnknownStorage()); R_UNLESS(storage_id != StorageId::None, ncm::ResultUnknownStorage());
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(FindContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(FindContentMetaDatabaseEntry(&entry, storage_id));
auto content_meta_db = entry->content_meta_database; auto content_meta_db = entry->content_meta_database;
@ -561,7 +561,7 @@ 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);
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
R_TRY(fsDeleteSaveDataFileSystemBySaveDataSpaceId(entry->save_meta.space_id, entry->save_meta.id)); R_TRY(fsDeleteSaveDataFileSystemBySaveDataSpaceId(entry->save_meta.space_id, entry->save_meta.id));
@ -571,7 +571,7 @@ 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);
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
/* Already activated. */ /* Already activated. */
@ -599,7 +599,7 @@ 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);
ContentMetaDatabaseEntry* entry; ContentMetaDatabaseEntry *entry;
R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id)); R_TRY(GetUniqueContentMetaDatabaseEntry(&entry, storage_id));
/* Already inactivated. */ /* Already inactivated. */

View File

@ -27,7 +27,7 @@ namespace ams::ncm::impl {
/* Content Storage Management. */ /* Content Storage Management. */
Result CreateContentStorage(StorageId storage_id); Result CreateContentStorage(StorageId storage_id);
Result VerifyContentStorage(StorageId storage_id); Result VerifyContentStorage(StorageId storage_id);
Result OpenContentStorage(std::shared_ptr<IContentStorage>* out, StorageId storage_id); Result OpenContentStorage(std::shared_ptr<IContentStorage> *out, StorageId storage_id);
Result CloseContentStorageForcibly(StorageId storage_id); Result CloseContentStorageForcibly(StorageId storage_id);
Result ActivateContentStorage(StorageId storage_id); Result ActivateContentStorage(StorageId storage_id);
Result InactivateContentStorage(StorageId storage_id); Result InactivateContentStorage(StorageId storage_id);
@ -35,7 +35,7 @@ namespace ams::ncm::impl {
/* Content Meta Database Management. */ /* Content Meta Database Management. */
Result CreateContentMetaDatabase(StorageId storage_id); Result CreateContentMetaDatabase(StorageId storage_id);
Result VerifyContentMetaDatabase(StorageId storage_id); Result VerifyContentMetaDatabase(StorageId storage_id);
Result OpenContentMetaDatabase(std::shared_ptr<IContentMetaDatabase>* out, StorageId storage_id); Result OpenContentMetaDatabase(std::shared_ptr<IContentMetaDatabase> *out, StorageId storage_id);
Result CloseContentMetaDatabaseForcibly(StorageId storage_id); Result CloseContentMetaDatabaseForcibly(StorageId storage_id);
Result CleanupContentMetaDatabase(StorageId storage_id); Result CleanupContentMetaDatabase(StorageId storage_id);
Result ActivateContentMetaDatabase(StorageId storage_id); Result ActivateContentMetaDatabase(StorageId storage_id);

View File

@ -27,7 +27,7 @@ namespace ams::ncm::impl {
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);
FILE* f = nullptr; FILE *f = nullptr;
R_TRY(fs::OpenFile(&f, placeholder_path, FsOpenMode_Write)); R_TRY(fs::OpenFile(&f, placeholder_path, FsOpenMode_Write));
*out_handle = f; *out_handle = f;
@ -57,7 +57,7 @@ namespace ams::ncm::impl {
PlaceHolderAccessor::CacheEntry *PlaceHolderAccessor::GetFreeEntry() { PlaceHolderAccessor::CacheEntry *PlaceHolderAccessor::GetFreeEntry() {
/* Try to find an already free entry. */ /* Try to find an already free entry. */
CacheEntry* entry = this->FindInCache(InvalidPlaceHolderId); CacheEntry *entry = this->FindInCache(InvalidPlaceHolderId);
if (entry) { if (entry) {
return entry; return entry;
@ -76,7 +76,7 @@ namespace ams::ncm::impl {
} }
} }
void PlaceHolderAccessor::StoreToCache(FILE* handle, PlaceHolderId placeholder_id) { void PlaceHolderAccessor::StoreToCache(FILE *handle, PlaceHolderId placeholder_id) {
std::scoped_lock lk(this->cache_mutex); std::scoped_lock lk(this->cache_mutex);
CacheEntry *entry = this->GetFreeEntry(); CacheEntry *entry = this->GetFreeEntry();
entry->id = placeholder_id; entry->id = placeholder_id;
@ -95,7 +95,7 @@ namespace ams::ncm::impl {
} }
} }
void PlaceHolderAccessor::Initialize(char* root, MakePlaceHolderPathFunc path_func, bool delay_flush) { void PlaceHolderAccessor::Initialize(char *root, MakePlaceHolderPathFunc path_func, bool delay_flush) {
this->root_path = root; this->root_path = root;
this->make_placeholder_path_func = path_func; this->make_placeholder_path_func = path_func;
this->delay_flush = delay_flush; this->delay_flush = delay_flush;
@ -111,9 +111,9 @@ namespace ams::ncm::impl {
AMS_ABORT(); AMS_ABORT();
} }
void PlaceHolderAccessor::GetPath(char* placeholder_path_out, PlaceHolderId placeholder_id) { void PlaceHolderAccessor::GetPath(char *placeholder_path_out, PlaceHolderId placeholder_id) {
std::scoped_lock lock(this->cache_mutex); std::scoped_lock lock(this->cache_mutex);
CacheEntry* entry = this->FindInCache(placeholder_id); CacheEntry *entry = this->FindInCache(placeholder_id);
this->Invalidate(entry); this->Invalidate(entry);
this->MakePath(placeholder_path_out, placeholder_id); this->MakePath(placeholder_path_out, placeholder_id);
} }
@ -145,8 +145,8 @@ namespace ams::ncm::impl {
return ResultSuccess(); return ResultSuccess();
} }
Result PlaceHolderAccessor::Write(PlaceHolderId placeholder_id, size_t offset, const void* buffer, size_t size) { Result PlaceHolderAccessor::Write(PlaceHolderId placeholder_id, size_t offset, const void *buffer, size_t size) {
FILE* f = nullptr; FILE *f = nullptr;
R_TRY_CATCH(this->Open(&f, placeholder_id)) { R_TRY_CATCH(this->Open(&f, placeholder_id)) {
R_CONVERT(ams::fs::ResultPathNotFound, ncm::ResultPlaceHolderNotFound()) R_CONVERT(ams::fs::ResultPathNotFound, ncm::ResultPlaceHolderNotFound())
@ -172,8 +172,8 @@ namespace ams::ncm::impl {
return ResultSuccess(); return ResultSuccess();
} }
Result PlaceHolderAccessor::GetSize(bool* found_in_cache, size_t* out_size, PlaceHolderId placeholder_id) { Result PlaceHolderAccessor::GetSize(bool *found_in_cache, size_t *out_size, PlaceHolderId placeholder_id) {
FILE* f = NULL; FILE *f = NULL;
/* Set the scope for the scoped_lock. */ /* Set the scope for the scoped_lock. */
{ {
@ -184,7 +184,7 @@ namespace ams::ncm::impl {
return ResultSuccess(); return ResultSuccess();
} }
CacheEntry* cache_entry = this->FindInCache(placeholder_id); CacheEntry *cache_entry = this->FindInCache(placeholder_id);
if (cache_entry == nullptr) { if (cache_entry == nullptr) {
*found_in_cache = false; *found_in_cache = false;

View File

@ -27,14 +27,14 @@ namespace ams::ncm::impl {
class CacheEntry { class CacheEntry {
public: public:
PlaceHolderId id; PlaceHolderId id;
FILE* handle; FILE *handle;
u64 counter; u64 counter;
}; };
private: private:
static constexpr size_t MaxCaches = 0x2; static constexpr size_t MaxCaches = 0x2;
std::array<CacheEntry, MaxCaches> caches; std::array<CacheEntry, MaxCaches> caches;
char* root_path; char *root_path;
u64 cur_counter; u64 cur_counter;
os::Mutex cache_mutex; os::Mutex cache_mutex;
MakePlaceHolderPathFunc make_placeholder_path_func; MakePlaceHolderPathFunc make_placeholder_path_func;
@ -44,7 +44,7 @@ namespace ams::ncm::impl {
CacheEntry *FindInCache(PlaceHolderId placeholder_id); CacheEntry *FindInCache(PlaceHolderId placeholder_id);
bool LoadFromCache(FILE** out_handle, PlaceHolderId placeholder_id); bool LoadFromCache(FILE** out_handle, PlaceHolderId placeholder_id);
CacheEntry *GetFreeEntry(); CacheEntry *GetFreeEntry();
void StoreToCache(FILE* handle, PlaceHolderId placeholder_id); void StoreToCache(FILE *handle, PlaceHolderId placeholder_id);
void Invalidate(CacheEntry *entry); void Invalidate(CacheEntry *entry);
public: public:
PlaceHolderAccessor() : cur_counter(0), delay_flush(false) { PlaceHolderAccessor() : cur_counter(0), delay_flush(false) {
@ -53,24 +53,24 @@ namespace ams::ncm::impl {
} }
} }
inline void MakeRootPath(char* out_placeholder_root) { inline void MakeRootPath(char *out_placeholder_root) {
path::GetPlaceHolderRootPath(out_placeholder_root, this->root_path); path::GetPlaceHolderRootPath(out_placeholder_root, this->root_path);
} }
inline void MakePath(char* out_placeholder_path, PlaceHolderId placeholder_id) { inline void MakePath(char *out_placeholder_path, PlaceHolderId placeholder_id) {
char placeholder_root_path[FS_MAX_PATH] = {0}; char placeholder_root_path[FS_MAX_PATH] = {0};
this->MakeRootPath(placeholder_root_path); this->MakeRootPath(placeholder_root_path);
this->make_placeholder_path_func(out_placeholder_path, placeholder_id, placeholder_root_path); this->make_placeholder_path_func(out_placeholder_path, placeholder_id, placeholder_root_path);
} }
void Initialize(char* root, MakePlaceHolderPathFunc path_func, bool delay_flush); void Initialize(char *root, MakePlaceHolderPathFunc path_func, bool delay_flush);
unsigned int GetDirectoryDepth(); unsigned int GetDirectoryDepth();
void GetPath(char* out_placeholder_path, PlaceHolderId placeholder_id); void GetPath(char *out_placeholder_path, PlaceHolderId placeholder_id);
Result Create(PlaceHolderId placeholder_id, size_t size); Result Create(PlaceHolderId placeholder_id, size_t size);
Result Delete(PlaceHolderId placeholder_id); Result Delete(PlaceHolderId placeholder_id);
Result Write(PlaceHolderId placeholder_id, size_t offset, const void* buffer, size_t size); Result Write(PlaceHolderId placeholder_id, size_t offset, const void *buffer, size_t size);
Result SetSize(PlaceHolderId placeholder_id, size_t size); Result SetSize(PlaceHolderId placeholder_id, size_t size);
Result GetSize(bool* found_in_cache, size_t* out_size, PlaceHolderId placeholder_id); Result GetSize(bool *found_in_cache, size_t *out_size, PlaceHolderId placeholder_id);
Result EnsureRecursively(PlaceHolderId placeholder_id); Result EnsureRecursively(PlaceHolderId placeholder_id);
void InvalidateAll(); void InvalidateAll();
}; };

View File

@ -54,20 +54,20 @@ namespace ams::ncm {
u32 extended_data_size; u32 extended_data_size;
}; };
inline const ContentMetaHeader* GetValueHeader(const void* value) { inline const ContentMetaHeader *GetValueHeader(const void *value) {
return reinterpret_cast<const ContentMetaHeader*>(value); return reinterpret_cast<const ContentMetaHeader*>(value);
} }
template<typename ExtendedHeaderType> template<typename ExtendedHeaderType>
inline const ExtendedHeaderType* GetValueExtendedHeader(const void* value) { inline const ExtendedHeaderType *GetValueExtendedHeader(const void *value) {
return reinterpret_cast<const ExtendedHeaderType*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader)); return reinterpret_cast<const ExtendedHeaderType*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader));
} }
inline const ContentInfo* GetValueContentInfos(const void* value) { inline const ContentInfo *GetValueContentInfos(const void *value) {
return reinterpret_cast<const ContentInfo*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader) + GetValueHeader(value)->extended_header_size); return reinterpret_cast<const ContentInfo*>(reinterpret_cast<const u8*>(value) + sizeof(ContentMetaHeader) + GetValueHeader(value)->extended_header_size);
} }
inline const ContentMetaInfo* GetValueContentMetaInfos(const void* value) { inline const ContentMetaInfo *GetValueContentMetaInfos(const void *value) {
auto header = GetValueHeader(value); auto header = GetValueHeader(value);
return reinterpret_cast<const ContentMetaInfo*>(reinterpret_cast<const u8*>(GetValueContentInfos(value)) + sizeof(ContentInfo) * header->content_count); return reinterpret_cast<const ContentMetaInfo*>(reinterpret_cast<const u8*>(GetValueContentInfos(value)) + sizeof(ContentInfo) * header->content_count);
} }
@ -88,7 +88,7 @@ namespace ams::ncm {
} }
Result ContentMetaDatabaseInterface::GetContentIdByTypeImpl(ContentId* out, const ContentMetaKey& key, ContentType type, std::optional<u8> id_offset) { Result ContentMetaDatabaseInterface::GetContentIdByTypeImpl(ContentId *out, const ContentMetaKey& key, ContentType type, std::optional<u8> id_offset) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
const auto it = this->kvs->lower_bound(key); const auto it = this->kvs->lower_bound(key);
@ -96,7 +96,7 @@ namespace ams::ncm {
R_UNLESS(it->GetKey().id == key.id, ncm::ResultContentMetaNotFound()); R_UNLESS(it->GetKey().id == key.id, ncm::ResultContentMetaNotFound());
const auto stored_key = it->GetKey(); const auto stored_key = it->GetKey();
const void* value = nullptr; const void *value = nullptr;
size_t value_size = 0; size_t value_size = 0;
R_TRY(GetContentMetaValuePointer(&value, &value_size, stored_key, this->kvs)); R_TRY(GetContentMetaValuePointer(&value, &value_size, stored_key, this->kvs));
@ -104,12 +104,12 @@ namespace ams::ncm {
R_UNLESS(header->content_count != 0, ncm::ResultContentNotFound()); R_UNLESS(header->content_count != 0, ncm::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;
if (id_offset) { if (id_offset) {
for (size_t i = 0; i < header->content_count; i++) { for (size_t i = 0; i < header->content_count; i++) {
const ContentInfo* content_info = &content_infos[i]; const ContentInfo *content_info = &content_infos[i];
if (content_info->content_type == type && content_info->id_offset == *id_offset) { if (content_info->content_type == type && content_info->id_offset == *id_offset) {
found_content_info = content_info; found_content_info = content_info;
@ -117,10 +117,10 @@ namespace ams::ncm {
} }
} }
} else { } else {
const ContentInfo* lowest_id_offset_info = nullptr; const ContentInfo *lowest_id_offset_info = nullptr;
for (size_t i = 0; i < header->content_count; i++) { for (size_t i = 0; i < header->content_count; i++) {
const ContentInfo* content_info = &content_infos[i]; const ContentInfo *content_info = &content_infos[i];
if (content_info->content_type == type && (!lowest_id_offset_info || lowest_id_offset_info->id_offset > content_info->id_offset)) { if (content_info->content_type == type && (!lowest_id_offset_info || lowest_id_offset_info->id_offset > content_info->id_offset)) {
lowest_id_offset_info = content_info; lowest_id_offset_info = content_info;
@ -135,7 +135,7 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentMetaDatabaseInterface::GetLatestContentMetaKeyImpl(ContentMetaKey* out_key, ProgramId id) { Result ContentMetaDatabaseInterface::GetLatestContentMetaKeyImpl(ContentMetaKey *out_key, ProgramId id) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
ContentMetaKey key = {0}; ContentMetaKey key = {0};
@ -224,7 +224,7 @@ namespace ams::ncm {
} }
if (static_cast<u64>(application_program_id) != 0) { if (static_cast<u64>(application_program_id) != 0) {
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));
@ -290,7 +290,7 @@ namespace ams::ncm {
continue; continue;
} }
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));
@ -307,7 +307,7 @@ namespace ams::ncm {
/* Write the entry to the output buffer. */ /* Write the entry to the output buffer. */
if (entries_written < out_keys.GetSize()) { if (entries_written < out_keys.GetSize()) {
ApplicationContentMetaKey* out_app_key = &out_keys[entries_written]; ApplicationContentMetaKey *out_app_key = &out_keys[entries_written];
out_app_key->application_program_id = application_id; out_app_key->application_program_id = application_id;
out_app_key->key = key; out_app_key->key = key;
entries_written++; entries_written++;
@ -368,7 +368,7 @@ namespace ams::ncm {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch, ncm::ResultInvalidContentMetaKey()); R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch, ncm::ResultInvalidContentMetaKey());
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));
@ -383,7 +383,7 @@ namespace ams::ncm {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
R_UNLESS(key.type == ContentMetaType::Application, ncm::ResultInvalidContentMetaKey()); R_UNLESS(key.type == ContentMetaType::Application, ncm::ResultInvalidContentMetaKey());
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));
const auto ext_header = GetValueExtendedHeader<ApplicationMetaExtendedHeader>(value); const auto ext_header = GetValueExtendedHeader<ApplicationMetaExtendedHeader>(value);
@ -420,9 +420,9 @@ namespace ams::ncm {
continue; continue;
} }
const ContentInfo* content_infos = GetValueContentInfos(value); const ContentInfo *content_infos = GetValueContentInfos(value);
for (size_t i = 0; i < header->content_count; i++) { for (size_t i = 0; i < header->content_count; i++) {
const ContentInfo* content_info = &content_infos[i]; const ContentInfo *content_info = &content_infos[i];
/* Check if any of this entry's content infos matches one of the provided content ids. /* Check if any of this entry's content infos matches one of the provided content ids.
If they do, then the content id isn't orphaned. */ If they do, then the content id isn't orphaned. */
@ -448,15 +448,15 @@ namespace ams::ncm {
} }
Result ContentMetaDatabaseInterface::HasContent(sf::Out<bool> out, ContentMetaKey key, ContentId content_id) { Result ContentMetaDatabaseInterface::HasContent(sf::Out<bool> out, ContentMetaKey key, ContentId content_id) {
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));
const auto header = GetValueHeader(value); const auto header = GetValueHeader(value);
const ContentInfo* content_infos = GetValueContentInfos(value); const ContentInfo *content_infos = GetValueContentInfos(value);
if (header->content_count > 0) { if (header->content_count > 0) {
for (size_t i = 0; i < header->content_count; i++) { for (size_t i = 0; i < header->content_count; i++) {
const ContentInfo* content_info = &content_infos[i]; const ContentInfo *content_info = &content_infos[i];
if (content_id == content_info->content_id) { if (content_id == content_info->content_id) {
out.SetValue(false); out.SetValue(false);
@ -473,7 +473,7 @@ namespace ams::ncm {
R_UNLESS(start_index <= std::numeric_limits<s32>::max(), ncm::ResultInvalidOffset()); R_UNLESS(start_index <= std::numeric_limits<s32>::max(), ncm::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));
const auto header = GetValueHeader(value); const auto header = GetValueHeader(value);
@ -502,7 +502,7 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::GetAttributes(sf::Out<ContentMetaAttribute> out_attributes, ContentMetaKey key) { Result ContentMetaDatabaseInterface::GetAttributes(sf::Out<ContentMetaAttribute> out_attributes, ContentMetaKey key) {
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));
const auto header = GetValueHeader(value); const auto header = GetValueHeader(value);
@ -513,7 +513,7 @@ namespace ams::ncm {
Result ContentMetaDatabaseInterface::GetRequiredApplicationVersion(sf::Out<u32> out_version, ContentMetaKey key) { Result ContentMetaDatabaseInterface::GetRequiredApplicationVersion(sf::Out<u32> out_version, ContentMetaKey key) {
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));
@ -537,7 +537,7 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentMetaDatabaseInterface::GetLatestProgram(ContentId* out_content_id, ProgramId program_id) { Result ContentMetaDatabaseInterface::GetLatestProgram(ContentId *out_content_id, ProgramId program_id) {
ContentMetaKey key; ContentMetaKey key;
R_TRY(this->GetLatestContentMetaKey(&key, program_id)); R_TRY(this->GetLatestContentMetaKey(&key, program_id));
@ -545,7 +545,7 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
Result ContentMetaDatabaseInterface::GetLatestData(ContentId* out_content_id, ProgramId program_id) { Result ContentMetaDatabaseInterface::GetLatestData(ContentId *out_content_id, ProgramId program_id) {
ContentMetaKey key; ContentMetaKey key;
R_TRY(this->GetLatestContentMetaKey(&key, program_id)); R_TRY(this->GetLatestContentMetaKey(&key, program_id));

View File

@ -22,13 +22,13 @@ namespace ams::ncm {
class ContentMetaDatabaseInterface : public IContentMetaDatabase { class ContentMetaDatabaseInterface : public IContentMetaDatabase {
public: public:
ContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs, const char* mount_name) : IContentMetaDatabase(kvs, mount_name) { ContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs, const char *mount_name) : IContentMetaDatabase(kvs, mount_name) {
} }
ContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) : IContentMetaDatabase(kvs) { ContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) : IContentMetaDatabase(kvs) {
} }
private: private:
Result GetContentIdByTypeImpl(ContentId* out, const ContentMetaKey& key, ContentType type, std::optional<u8> id_offset); Result GetContentIdByTypeImpl(ContentId *out, const ContentMetaKey& key, ContentType type, std::optional<u8> id_offset);
Result GetLatestContentMetaKeyImpl(ContentMetaKey* out_key, ProgramId id); Result GetLatestContentMetaKeyImpl(ContentMetaKey *out_key, ProgramId id);
public: public:
virtual Result Set(ContentMetaKey key, sf::InBuffer value) override; virtual Result Set(ContentMetaKey key, sf::InBuffer value) override;
virtual Result Get(sf::Out<u64> out_size, ContentMetaKey key, sf::OutBuffer out_value) override; virtual Result Get(sf::Out<u64> out_size, ContentMetaKey key, sf::OutBuffer out_value) override;
@ -53,13 +53,13 @@ namespace ams::ncm {
virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) override; virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) override;
/* APIs. */ /* APIs. */
virtual Result GetLatestProgram(ContentId* out_content_id, ProgramId program_id) override; virtual Result GetLatestProgram(ContentId *out_content_id, ProgramId program_id) override;
virtual Result GetLatestData(ContentId* out_content_id, ProgramId program_id) override; virtual Result GetLatestData(ContentId *out_content_id, ProgramId program_id) override;
}; };
class OnMemoryContentMetaDatabaseInterface : public ContentMetaDatabaseInterface { class OnMemoryContentMetaDatabaseInterface : public ContentMetaDatabaseInterface {
public: public:
OnMemoryContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) : ContentMetaDatabaseInterface(kvs) { OnMemoryContentMetaDatabaseInterface(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) : ContentMetaDatabaseInterface(kvs) {
} }
public: public:
virtual Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, ProgramId id) override; virtual Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, ProgramId id) override;

View File

@ -25,7 +25,7 @@ namespace ams::ncm {
this->Finalize(); this->Finalize();
} }
Result ContentStorageInterface::Initialize(const char* root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush, impl::RightsIdCache* rights_id_cache) { Result ContentStorageInterface::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(this->EnsureEnabled());
R_TRY(fs::CheckContentStorageDirectoriesExist(root_path)); 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, FS_MAX_PATH-1);
@ -217,7 +217,7 @@ namespace ams::ncm {
const unsigned int dir_depth = this->placeholder_accessor.GetDirectoryDepth(); const unsigned int dir_depth = this->placeholder_accessor.GetDirectoryDepth();
size_t entry_count = 0; size_t entry_count = 0;
R_TRY(fs::TraverseDirectory(placeholder_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) -> Result { R_TRY(fs::TraverseDirectory(placeholder_root_path, dir_depth, [&](bool *should_continue, bool *should_retry_dir_read, const char *current_path, struct dirent *dir_entry) -> Result {
*should_continue = true; *should_continue = true;
*should_retry_dir_read = false; *should_retry_dir_read = false;
@ -244,7 +244,7 @@ namespace ams::ncm {
const unsigned int dir_depth = this->GetContentDirectoryDepth(); const unsigned int dir_depth = this->GetContentDirectoryDepth();
u32 content_count = 0; u32 content_count = 0;
R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) -> Result { R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool *should_continue, bool *should_retry_dir_read, const char *current_path, struct dirent *dir_entry) -> Result {
*should_continue = true; *should_continue = true;
*should_retry_dir_read = false; *should_retry_dir_read = false;
@ -268,7 +268,7 @@ namespace ams::ncm {
const unsigned int dir_depth = this->GetContentDirectoryDepth(); const unsigned int dir_depth = this->GetContentDirectoryDepth();
size_t entry_count = 0; size_t entry_count = 0;
R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) { R_TRY(fs::TraverseDirectory(content_root_path, dir_depth, [&](bool *should_continue, bool *should_retry_dir_read, const char *current_path, struct dirent *dir_entry) {
*should_retry_dir_read = false; *should_retry_dir_read = false;
*should_continue = true; *should_continue = true;
@ -396,7 +396,7 @@ namespace ams::ncm {
/* Attempt to locate the content id in the cache. */ /* Attempt to locate the content id in the cache. */
for (size_t i = 0; i < impl::RightsIdCache::MaxEntries; i++) { for (size_t i = 0; i < impl::RightsIdCache::MaxEntries; i++) {
impl::RightsIdCache::Entry* entry = &this->rights_id_cache->entries[i]; impl::RightsIdCache::Entry *entry = &this->rights_id_cache->entries[i];
if (entry->last_accessed != 1 && content_id == entry->uuid) { if (entry->last_accessed != 1 && content_id == entry->uuid) {
entry->last_accessed = this->rights_id_cache->counter; entry->last_accessed = this->rights_id_cache->counter;
@ -418,11 +418,11 @@ namespace ams::ncm {
{ {
std::scoped_lock lk(this->rights_id_cache->mutex); std::scoped_lock lk(this->rights_id_cache->mutex);
impl::RightsIdCache::Entry* eviction_candidate = &this->rights_id_cache->entries[0]; impl::RightsIdCache::Entry *eviction_candidate = &this->rights_id_cache->entries[0];
/* Find a suitable existing entry to store our new one at. */ /* Find a suitable existing entry to store our new one at. */
for (size_t i = 1; i < impl::RightsIdCache::MaxEntries; i++) { for (size_t i = 1; i < impl::RightsIdCache::MaxEntries; i++) {
impl::RightsIdCache::Entry* entry = &this->rights_id_cache->entries[i]; impl::RightsIdCache::Entry *entry = &this->rights_id_cache->entries[i];
/* Change eviction candidates if the uuid already matches ours, or if the uuid doesn't already match and the last_accessed count is lower */ /* Change eviction candidates if the uuid already matches ours, or if the uuid doesn't already match and the last_accessed count is lower */
if (content_id == entry->uuid || (content_id != eviction_candidate->uuid && entry->last_accessed < eviction_candidate->last_accessed)) { if (content_id == entry->uuid || (content_id != eviction_candidate->uuid && entry->last_accessed < eviction_candidate->last_accessed)) {
@ -460,7 +460,7 @@ namespace ams::ncm {
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);
FILE* f = nullptr; FILE *f = nullptr;
R_TRY(fs::OpenFile(&f, content_path, FsOpenMode_Write)); R_TRY(fs::OpenFile(&f, content_path, FsOpenMode_Write));
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
@ -518,7 +518,7 @@ namespace ams::ncm {
char content_root_path[FS_MAX_PATH] = {0}; char content_root_path[FS_MAX_PATH] = {0};
this->GetContentRootPath(content_root_path); this->GetContentRootPath(content_root_path);
unsigned int dir_depth = this->GetContentDirectoryDepth(); unsigned int dir_depth = this->GetContentDirectoryDepth();
auto fix_file_attributes = [&](bool* should_continue, bool* should_retry_dir_read, const char* current_path, struct dirent* dir_entry) { auto fix_file_attributes = [&](bool *should_continue, bool *should_retry_dir_read, const char *current_path, struct dirent *dir_entry) {
*should_retry_dir_read = false; *should_retry_dir_read = false;
*should_continue = true; *should_continue = true;
@ -553,7 +553,7 @@ namespace ams::ncm {
/* Attempt to locate the content id in the cache. */ /* Attempt to locate the content id in the cache. */
for (size_t i = 0; i < impl::RightsIdCache::MaxEntries; i++) { for (size_t i = 0; i < impl::RightsIdCache::MaxEntries; i++) {
impl::RightsIdCache::Entry* entry = &this->rights_id_cache->entries[i]; impl::RightsIdCache::Entry *entry = &this->rights_id_cache->entries[i];
if (entry->last_accessed != 1 && cache_content_id == entry->uuid) { if (entry->last_accessed != 1 && cache_content_id == entry->uuid) {
entry->last_accessed = this->rights_id_cache->counter; entry->last_accessed = this->rights_id_cache->counter;
@ -575,11 +575,11 @@ namespace ams::ncm {
{ {
std::scoped_lock lk(this->rights_id_cache->mutex); std::scoped_lock lk(this->rights_id_cache->mutex);
impl::RightsIdCache::Entry* eviction_candidate = &this->rights_id_cache->entries[0]; impl::RightsIdCache::Entry *eviction_candidate = &this->rights_id_cache->entries[0];
/* Find a suitable existing entry to store our new one at. */ /* Find a suitable existing entry to store our new one at. */
for (size_t i = 1; i < impl::RightsIdCache::MaxEntries; i++) { for (size_t i = 1; i < impl::RightsIdCache::MaxEntries; i++) {
impl::RightsIdCache::Entry* entry = &this->rights_id_cache->entries[i]; impl::RightsIdCache::Entry *entry = &this->rights_id_cache->entries[i];
/* Change eviction candidates if the uuid already matches ours, or if the uuid doesn't already match and the last_accessed count is lower */ /* Change eviction candidates if the uuid already matches ours, or if the uuid doesn't already match and the last_accessed count is lower */
if (cache_content_id == entry->uuid || (cache_content_id != eviction_candidate->uuid && entry->last_accessed < eviction_candidate->last_accessed)) { if (cache_content_id == entry->uuid || (cache_content_id != eviction_candidate->uuid && entry->last_accessed < eviction_candidate->last_accessed)) {

View File

@ -28,23 +28,23 @@ namespace ams::ncm {
protected: protected:
impl::PlaceHolderAccessor placeholder_accessor; impl::PlaceHolderAccessor placeholder_accessor;
ContentId cached_content_id; ContentId cached_content_id;
FILE* content_cache_file_handle; FILE *content_cache_file_handle;
impl::RightsIdCache* rights_id_cache; impl::RightsIdCache *rights_id_cache;
public: public:
~ContentStorageInterface(); ~ContentStorageInterface();
Result Initialize(const char* root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush, impl::RightsIdCache* rights_id_cache); Result Initialize(const char *root_path, MakeContentPathFunc content_path_func, MakePlaceHolderPathFunc placeholder_path_func, bool delay_flush, impl::RightsIdCache *rights_id_cache);
void Finalize(); void Finalize();
private: private:
void ClearContentCache(); void ClearContentCache();
unsigned int GetContentDirectoryDepth(); unsigned int GetContentDirectoryDepth();
Result OpenCachedContentFile(ContentId content_id); Result OpenCachedContentFile(ContentId content_id);
inline void GetContentRootPath(char* out_content_root) { inline void GetContentRootPath(char *out_content_root) {
path::GetContentRootPath(out_content_root, this->root_path); path::GetContentRootPath(out_content_root, this->root_path);
} }
inline void GetContentPath(char* out_content_path, ContentId content_id) { inline void GetContentPath(char *out_content_path, ContentId content_id) {
char content_root_path[FS_MAX_PATH] = {0}; char content_root_path[FS_MAX_PATH] = {0};
this->GetContentRootPath(content_root_path); this->GetContentRootPath(content_root_path);

View File

@ -23,28 +23,28 @@
namespace ams::ncm::fs { namespace ams::ncm::fs {
Result OpenFile(FILE** out, const char* path, u32 mode) { Result OpenFile(FILE** out, const char *path, u32 mode) {
bool has = false; bool has = false;
/* 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));
R_UNLESS(has, ams::fs::ResultPathNotFound()); R_UNLESS(has, ams::fs::ResultPathNotFound());
const char* fopen_mode = ""; const char *fopen_mode = "";
if (mode & FsOpenMode_Write) { if (mode & FsOpenMode_Write) {
fopen_mode = "r+b"; fopen_mode = "r+b";
} else if (mode & FsOpenMode_Read) { } else if (mode & FsOpenMode_Read) {
fopen_mode = "rb"; fopen_mode = "rb";
} }
FILE* f = fopen(path, fopen_mode); FILE *f = fopen(path, fopen_mode);
R_UNLESS(f != nullptr, fsdevGetLastResult()); R_UNLESS(f != nullptr, 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) {
R_UNLESS(fseek(f, 0, SEEK_END) == 0, fsdevGetLastResult()); R_UNLESS(fseek(f, 0, SEEK_END) == 0, fsdevGetLastResult());
size_t existing_size = ftell(f); size_t existing_size = ftell(f);
@ -59,14 +59,14 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result ReadFile(FILE* f, size_t offset, void* buffer, size_t size) { Result ReadFile(FILE *f, size_t offset, void *buffer, size_t size) {
R_UNLESS(fseek(f, offset, SEEK_SET) == 0, fsdevGetLastResult()); R_UNLESS(fseek(f, offset, SEEK_SET) == 0, fsdevGetLastResult());
R_UNLESS(fread(buffer, 1, size, f) == size, fsdevGetLastResult()); R_UNLESS(fread(buffer, 1, size, f) == size, fsdevGetLastResult());
R_UNLESS(!ferror(f), fsdevGetLastResult()); R_UNLESS(!ferror(f), fsdevGetLastResult());
return ResultSuccess(); return ResultSuccess();
} }
Result HasFile(bool* out, const char* path) { Result HasFile(bool *out, const char *path) {
struct stat st; struct stat st;
if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) {
@ -82,7 +82,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result HasDirectory(bool* out, const char* path) { Result HasDirectory(bool *out, const char *path) {
struct stat st; struct stat st;
if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) { if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
@ -98,7 +98,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result CheckContentStorageDirectoriesExist(const char* root_path) { Result CheckContentStorageDirectoriesExist(const char *root_path) {
char content_root[FS_MAX_PATH] = {0}; char content_root[FS_MAX_PATH] = {0};
char placeholder_root[FS_MAX_PATH] = {0}; char placeholder_root[FS_MAX_PATH] = {0};
@ -119,7 +119,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result EnsureContentAndPlaceHolderRoot(const char* root_path) { Result EnsureContentAndPlaceHolderRoot(const char *root_path) {
char content_root[FS_MAX_PATH] = {0}; char content_root[FS_MAX_PATH] = {0};
char placeholder_root[FS_MAX_PATH] = {0}; char placeholder_root[FS_MAX_PATH] = {0};
@ -131,7 +131,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result EnsureDirectoryRecursively(const char* dir_path) { Result EnsureDirectoryRecursively(const char *dir_path) {
R_TRY(EnsureRecursively(dir_path)); R_TRY(EnsureRecursively(dir_path));
if (mkdir(dir_path, S_IRWXU) == -1) { if (mkdir(dir_path, S_IRWXU) == -1) {
R_TRY_CATCH(fsdevGetLastResult()) { R_TRY_CATCH(fsdevGetLastResult()) {
@ -143,7 +143,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result EnsureRecursively(const char* path) { Result EnsureRecursively(const char *path) {
R_UNLESS(path, ams::fs::ResultNullptrArgument()); R_UNLESS(path, ams::fs::ResultNullptrArgument());
size_t path_len = strlen(path); size_t path_len = strlen(path);
@ -174,11 +174,11 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result EnsureParentDirectoryRecursively(const char* path) { Result EnsureParentDirectoryRecursively(const char *path) {
return EnsureRecursively(path); return EnsureRecursively(path);
} }
Result GetGameCardHandle(FsGameCardHandle* out_handle) { Result GetGameCardHandle(FsGameCardHandle *out_handle) {
FsDeviceOperator devop; FsDeviceOperator devop;
R_TRY(fsOpenDeviceOperator(&devop)); R_TRY(fsOpenDeviceOperator(&devop));
@ -200,8 +200,8 @@ namespace ams::ncm::fs {
return mount_name; return mount_name;
} }
Result GetMountNameFromPath(MountName* mount_name, const char* path) { Result GetMountNameFromPath(MountName *mount_name, const char *path) {
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. */
R_UNLESS(unqual_path, ams::fs::ResultInvalidMountName()); R_UNLESS(unqual_path, ams::fs::ResultInvalidMountName());
@ -211,7 +211,7 @@ namespace ams::ncm::fs {
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) {
R_UNLESS(mount_point, ams::fs::ResultNullptrArgument()); R_UNLESS(mount_point, ams::fs::ResultNullptrArgument());
FsSaveDataAttribute save = { FsSaveDataAttribute save = {
@ -226,17 +226,17 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
constexpr const char* SystemContentMountName = "@SystemContent"; constexpr const char *SystemContentMountName = "@SystemContent";
constexpr const char* UserContentMountName = "@UserContent"; constexpr const char *UserContentMountName = "@UserContent";
constexpr const char* SdCardContentMountName = "@SdCardContent"; constexpr const char *SdCardContentMountName = "@SdCardContent";
constexpr const char* GameCardMountNameBase = "@Gc"; constexpr const char *GameCardMountNameBase = "@Gc";
constexpr const char* GameCardPartitionLetters[3] = { "U", "N", "S" }; constexpr const char *GameCardPartitionLetters[3] = { "U", "N", "S" };
/* Maps mount names to their common mount names. */ /* Maps mount names to their common mount names. */
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) {
R_UNLESS(mount_point, ams::fs::ResultNullptrArgument()); R_UNLESS(mount_point, ams::fs::ResultNullptrArgument());
FsFileSystem fs; FsFileSystem fs;
@ -262,7 +262,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result MountGameCardPartition(const char* mount_point, const FsGameCardHandle handle, FsGameCardPartition partition) { Result MountGameCardPartition(const char *mount_point, const FsGameCardHandle handle, FsGameCardPartition partition) {
AMS_ABORT_UNLESS(partition <= 2); AMS_ABORT_UNLESS(partition <= 2);
FsFileSystem fs; FsFileSystem fs;
@ -275,7 +275,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result Unmount(const char* mount_point) { Result Unmount(const char *mount_point) {
R_UNLESS(mount_point, ams::fs::ResultNullptrArgument()); R_UNLESS(mount_point, 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);
@ -283,7 +283,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
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) {
R_UNLESS(out_common_path, ams::fs::ResultNullptrArgument()); R_UNLESS(out_common_path, ams::fs::ResultNullptrArgument());
R_UNLESS(path, ams::fs::ResultNullptrArgument()); R_UNLESS(path, ams::fs::ResultNullptrArgument());
@ -300,7 +300,7 @@ namespace ams::ncm::fs {
return ResultSuccess(); return ResultSuccess();
} }
Result GetSaveDataFlags(u32* out_flags, u64 save_id) { Result GetSaveDataFlags(u32 *out_flags, u64 save_id) {
FsSaveDataExtraData extra_data; FsSaveDataExtraData extra_data;
R_TRY(fsReadSaveDataFileSystemExtraData(&extra_data, sizeof(FsSaveDataExtraData), save_id)); R_TRY(fsReadSaveDataFileSystemExtraData(&extra_data, sizeof(FsSaveDataExtraData), save_id));

View File

@ -21,39 +21,39 @@
namespace ams::ncm::fs { namespace ams::ncm::fs {
Result OpenFile(FILE** out, const char* path, u32 mode); Result OpenFile(FILE** out, const char *path, u32 mode);
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);
Result ReadFile(FILE* f, size_t offset, void* buffer, size_t size); Result ReadFile(FILE *f, size_t offset, void *buffer, size_t size);
Result HasFile(bool* out, const char* path); Result HasFile(bool *out, const char *path);
Result HasDirectory(bool* out, const char* path); Result HasDirectory(bool *out, const char *path);
Result CheckContentStorageDirectoriesExist(const char* root_path); Result CheckContentStorageDirectoriesExist(const char *root_path);
Result EnsureContentAndPlaceHolderRoot(const char* root_path); Result EnsureContentAndPlaceHolderRoot(const char *root_path);
Result EnsureDirectoryRecursively(const char* dir_path); Result EnsureDirectoryRecursively(const char *dir_path);
Result EnsureRecursively(const char* path); Result EnsureRecursively(const char *path);
/* Create all parent directories for a file path */ /* Create all parent directories for a file path */
Result EnsureParentDirectoryRecursively(const char* path); Result EnsureParentDirectoryRecursively(const char *path);
Result GetGameCardHandle(FsGameCardHandle* out_handle); Result GetGameCardHandle(FsGameCardHandle *out_handle);
MountName CreateUniqueMountName(); MountName CreateUniqueMountName();
Result GetMountNameFromPath(MountName* mount_name, const char* path); Result GetMountNameFromPath(MountName *mount_name, const char *path);
Result MountSystemSaveData(const char* mount_point, FsSaveDataSpaceId space_id, u64 save_id); Result MountSystemSaveData(const char *mount_point, FsSaveDataSpaceId space_id, u64 save_id);
Result MountContentStorage(const char* mount_point, FsContentStorageId id); Result MountContentStorage(const char *mount_point, FsContentStorageId id);
Result MountGameCardPartition(const char* mount_point, const FsGameCardHandle handle, FsGameCardPartition partition); Result MountGameCardPartition(const char *mount_point, const FsGameCardHandle handle, FsGameCardPartition partition);
Result Unmount(const char* mount_point); Result Unmount(const char *mount_point);
Result ConvertToFsCommonPath(char* out_common_path, size_t len, const char* path); Result ConvertToFsCommonPath(char *out_common_path, size_t len, const char *path);
Result GetSaveDataFlags(u32* out_flags, u64 save_id); Result GetSaveDataFlags(u32 *out_flags, u64 save_id);
Result SetSaveDataFlags(u64 save_id, FsSaveDataSpaceId space_id, u32 flags); Result SetSaveDataFlags(u64 save_id, FsSaveDataSpaceId space_id, u32 flags);
template<typename F> template<typename F>
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;
R_UNLESS(max_level >= 1, ResultSuccess()); R_UNLESS(max_level >= 1, ResultSuccess());
bool retry_dir_read = true; bool retry_dir_read = true;
@ -100,7 +100,7 @@ namespace ams::ncm::fs {
}; };
template<typename F> template<typename F>
Result TraverseDirectory(const char* root_path, int max_level, F f) { Result TraverseDirectory(const char *root_path, int max_level, F f) {
bool should_continue = false; bool should_continue = false;
return TraverseDirectory(&should_continue, root_path, max_level, f); return TraverseDirectory(&should_continue, root_path, max_level, f);
} }

View File

@ -58,12 +58,12 @@ void __libnx_exception_handler(ThreadExceptionDump *ctx) {
} }
void __libnx_initheap(void) { void __libnx_initheap(void) {
void* addr = nx_inner_heap; void * addr = nx_inner_heap;
size_t size = nx_inner_heap_size; size_t size = nx_inner_heap_size;
/* Newlib */ /* Newlib */
extern char* fake_heap_start; extern char *fake_heap_start;
extern char* fake_heap_end; extern char *fake_heap_end;
fake_heap_start = (char*)addr; fake_heap_start = (char*)addr;
fake_heap_end = (char*)addr + size; fake_heap_end = (char*)addr + size;
@ -153,7 +153,7 @@ namespace {
} }
void ContentManagerServerMain(void* arg) { void ContentManagerServerMain(void *arg) {
/* Create services. */ /* Create services. */
R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer<ncm::ContentManagerService>(ContentManagerServiceName, ContentManagerManagerSessions)); R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer<ncm::ContentManagerService>(ContentManagerServiceName, ContentManagerManagerSessions));

View File

@ -35,13 +35,13 @@ namespace ams::ncm::path {
} }
void MakeContentPathFlat(char* path_out, ContentId content_id, const char* root) { void MakeContentPathFlat(char *path_out, ContentId content_id, const char *root) {
char content_name[FS_MAX_PATH] = {0}; char content_name[FS_MAX_PATH] = {0};
GetContentFileName(content_name, content_id); 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, FS_MAX_PATH-1, "%s/%s", root, content_name) >= 0);
} }
void MakeContentPathDualLayered(char* path_out, ContentId content_id, const char* root) { void MakeContentPathDualLayered(char *path_out, ContentId content_id, const char *root) {
char content_name[FS_MAX_PATH] = {0}; char content_name[FS_MAX_PATH] = {0};
const u16 hash = Get16BitSha256HashPrefix(content_id.uuid); const u16 hash = Get16BitSha256HashPrefix(content_id.uuid);
const u32 hash_lower = (hash >> 4) & 0x3f; const u32 hash_lower = (hash >> 4) & 0x3f;
@ -51,27 +51,27 @@ namespace ams::ncm::path {
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, FS_MAX_PATH-1, "%s/%08X/%08X/%s", root, hash_upper, hash_lower, content_name) >= 0);
} }
void MakeContentPath10BitLayered(char* path_out, ContentId content_id, const char* root) { void MakeContentPath10BitLayered(char *path_out, ContentId content_id, const char *root) {
char content_name[FS_MAX_PATH] = {0}; char content_name[FS_MAX_PATH] = {0};
const u32 hash = (Get16BitSha256HashPrefix(content_id.uuid) >> 6) & 0x3FF; const u32 hash = (Get16BitSha256HashPrefix(content_id.uuid) >> 6) & 0x3FF;
GetContentFileName(content_name, content_id); 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, FS_MAX_PATH-1, "%s/%08X/%s", root, hash, content_name) >= 0);
} }
void MakeContentPathHashByteLayered(char* path_out, ContentId content_id, const char* root) { void MakeContentPathHashByteLayered(char *path_out, ContentId content_id, const char *root) {
char content_name[FS_MAX_PATH] = {0}; char content_name[FS_MAX_PATH] = {0};
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(content_id.uuid)); const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(content_id.uuid));
GetContentFileName(content_name, content_id); 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, FS_MAX_PATH-1, "%s/%08X/%s", root, hash_byte, content_name) >= 0);
} }
void MakePlaceHolderPathFlat(char* path_out, PlaceHolderId placeholder_id, const char* root) { void MakePlaceHolderPathFlat(char *path_out, PlaceHolderId placeholder_id, const char *root) {
char placeholder_name[FS_MAX_PATH] = {0}; char placeholder_name[FS_MAX_PATH] = {0};
GetPlaceHolderFileName(placeholder_name, placeholder_id); 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, FS_MAX_PATH-1, "%s/%s", root, placeholder_name) >= 0);
} }
void MakePlaceHolderPathHashByteLayered(char* path_out, PlaceHolderId placeholder_id, const char* root) { void MakePlaceHolderPathHashByteLayered(char *path_out, PlaceHolderId placeholder_id, const char *root) {
char placeholder_name[FS_MAX_PATH] = {0}; char placeholder_name[FS_MAX_PATH] = {0};
const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(placeholder_id.uuid)); const u32 hash_byte = static_cast<u32>(Get8BitSha256HashPrefix(placeholder_id.uuid));
GetPlaceHolderFileName(placeholder_name, placeholder_id); GetPlaceHolderFileName(placeholder_name, placeholder_id);

View File

@ -20,12 +20,12 @@
namespace ams::ncm::path { namespace ams::ncm::path {
void MakeContentPathFlat(char* out_path, ContentId content_id, const char* root); void MakeContentPathFlat(char *out_path, ContentId content_id, const char *root);
void MakeContentPathHashByteLayered(char* out_path, ContentId content_id, const char* root); void MakeContentPathHashByteLayered(char *out_path, ContentId content_id, const char *root);
void MakeContentPath10BitLayered(char* out_path, ContentId content_id, const char* root); void MakeContentPath10BitLayered(char *out_path, ContentId content_id, const char *root);
void MakeContentPathDualLayered(char* out_path, ContentId content_id, const char* root); void MakeContentPathDualLayered(char *out_path, ContentId content_id, const char *root);
void MakePlaceHolderPathFlat(char* out_path, PlaceHolderId placeholder_id, const char* root); void MakePlaceHolderPathFlat(char *out_path, PlaceHolderId placeholder_id, const char *root);
void MakePlaceHolderPathHashByteLayered(char* out_path, PlaceHolderId placeholder_id, const char* root); void MakePlaceHolderPathHashByteLayered(char *out_path, PlaceHolderId placeholder_id, const char *root);
} }

View File

@ -19,7 +19,7 @@
namespace ams::ncm::path { namespace ams::ncm::path {
void GetContentMetaPath(char* out, ContentId content_id, MakeContentPathFunc path_func, const char* root_path) { void GetContentMetaPath(char *out, ContentId content_id, MakeContentPathFunc path_func, const char *root_path) {
char tmp_path[FS_MAX_PATH-1] = {0}; char tmp_path[FS_MAX_PATH-1] = {0};
char content_path[FS_MAX_PATH-1] = {0}; char content_path[FS_MAX_PATH-1] = {0};
path_func(content_path, content_id, root_path); path_func(content_path, content_id, root_path);
@ -37,19 +37,19 @@ namespace ams::ncm::path {
strncat(out, ".cnmt.nca", 0x2ff - out_len); strncat(out, ".cnmt.nca", 0x2ff - out_len);
} }
void GetContentFileName(char* out, ContentId content_id) { void GetContentFileName(char *out, ContentId content_id) {
char content_name[sizeof(ContentId)*2+1] = {0}; char content_name[sizeof(ContentId)*2+1] = {0};
GetStringFromContentId(content_name, content_id); GetStringFromContentId(content_name, content_id);
snprintf(out, FS_MAX_PATH-1, "%s%s", content_name, ".nca"); snprintf(out, FS_MAX_PATH-1, "%s%s", content_name, ".nca");
} }
void GetPlaceHolderFileName(char* out, PlaceHolderId placeholder_id) { void GetPlaceHolderFileName(char *out, PlaceHolderId placeholder_id) {
char placeholder_name[sizeof(PlaceHolderId)*2+1] = {0}; char placeholder_name[sizeof(PlaceHolderId)*2+1] = {0};
GetStringFromPlaceHolderId(placeholder_name, placeholder_id); GetStringFromPlaceHolderId(placeholder_name, placeholder_id);
snprintf(out, FS_MAX_PATH-1, "%s%s", placeholder_name, ".nca"); snprintf(out, FS_MAX_PATH-1, "%s%s", placeholder_name, ".nca");
} }
bool IsNcaPath(const char* path) { bool IsNcaPath(const char *path) {
PathView path_view(path); PathView path_view(path);
if (!path_view.HasSuffix(".nca")) { if (!path_view.HasSuffix(".nca")) {

View File

@ -20,20 +20,20 @@
namespace ams::ncm::path { namespace ams::ncm::path {
inline void GetContentRootPath(char* out_content_root, const char* root_path) { inline void GetContentRootPath(char *out_content_root, const char *root_path) {
/* TODO: Replace with BoundedString? */ /* 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, FS_MAX_PATH-1, "%s%s", root_path, "/registered") >= 0);
} }
inline void GetPlaceHolderRootPath(char* out_placeholder_root, const char* root_path) { inline void GetPlaceHolderRootPath(char *out_placeholder_root, const char *root_path) {
/* TODO: Replace with BoundedString? */ /* TODO: Replace with BoundedString? */
AMS_ABORT_UNLESS(snprintf(out_placeholder_root, FS_MAX_PATH, "%s%s", root_path, "/placehld") >= 0); AMS_ABORT_UNLESS(snprintf(out_placeholder_root, FS_MAX_PATH, "%s%s", root_path, "/placehld") >= 0);
} }
void GetContentMetaPath(char* out, ContentId content_id, MakeContentPathFunc path_func, const char* root_path); void GetContentMetaPath(char *out, ContentId content_id, MakeContentPathFunc path_func, const char *root_path);
void GetContentFileName(char* out, ContentId content_id); void GetContentFileName(char *out, ContentId content_id);
void GetPlaceHolderFileName(char* out, PlaceHolderId placeholder_id); void GetPlaceHolderFileName(char *out, PlaceHolderId placeholder_id);
bool IsNcaPath(const char* path); bool IsNcaPath(const char *path);
class PathView { class PathView {
private: private:

View File

@ -20,7 +20,7 @@
namespace ams::ncm { namespace ams::ncm {
Result ReadOnlyContentStorageInterface::Initialize(const char* root_path, MakeContentPathFunc content_path_func) { Result ReadOnlyContentStorageInterface::Initialize(const char *root_path, MakeContentPathFunc content_path_func) {
R_TRY(this->EnsureEnabled()); R_TRY(this->EnsureEnabled());
const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1); const size_t root_path_len = strnlen(root_path, FS_MAX_PATH-1);
@ -163,7 +163,7 @@ namespace ams::ncm {
path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path); path::GetContentMetaPath(content_path, content_id, this->make_content_path_func, this->root_path);
} }
FILE* f = nullptr; FILE *f = nullptr;
R_TRY(fs::OpenFile(&f, content_path, FsOpenMode_Read)); R_TRY(fs::OpenFile(&f, content_path, FsOpenMode_Read));
ON_SCOPE_EXIT { ON_SCOPE_EXIT {

View File

@ -22,7 +22,7 @@ namespace ams::ncm {
class ReadOnlyContentStorageInterface : public IContentStorage { class ReadOnlyContentStorageInterface : public IContentStorage {
public: public:
Result Initialize(const char* root_path, MakeContentPathFunc content_path_func); Result Initialize(const char *root_path, MakeContentPathFunc content_path_func);
public: public:
virtual Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) override; virtual Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) override;
virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, u64 size) override; virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, u64 size) override;

View File

@ -18,29 +18,29 @@
namespace ams::ncm { namespace ams::ncm {
void GetStringFromContentId(char* out, ContentId content_id) { void GetStringFromContentId(char *out, ContentId content_id) {
for (size_t i = 0; i < sizeof(ContentId); i++) { for (size_t i = 0; i < sizeof(ContentId); i++) {
snprintf(out+i*2, 3, "%02x", content_id.uuid[i]); snprintf(out+i*2, 3, "%02x", content_id.uuid[i]);
} }
} }
void GetStringFromPlaceHolderId(char* out, PlaceHolderId placeholder_id) { void GetStringFromPlaceHolderId(char *out, PlaceHolderId placeholder_id) {
for (size_t i = 0; i < sizeof(PlaceHolderId); i++) { for (size_t i = 0; i < sizeof(PlaceHolderId); i++) {
snprintf(out+i*2, 3, "%02x", placeholder_id.uuid[i]); snprintf(out+i*2, 3, "%02x", placeholder_id.uuid[i]);
} }
} }
Result GetPlaceHolderIdFromDirEntry(PlaceHolderId* out, struct dirent* dir_entry) { Result GetPlaceHolderIdFromDirEntry(PlaceHolderId *out, struct dirent *dir_entry) {
R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderFile()); R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderFile());
R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderFile()); R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderFile());
u8 tmp[sizeof(PlaceHolderId)] = {}; u8 tmp[sizeof(PlaceHolderId)] = {};
char byte_string[2]; char byte_string[2];
char* end_ptr; char *end_ptr;
u64 converted_val; u64 converted_val;
for (size_t i = 0; i < sizeof(PlaceHolderId); i++) { for (size_t i = 0; i < sizeof(PlaceHolderId); i++) {
char* name_char_pair = dir_entry->d_name + i * 2; char *name_char_pair = dir_entry->d_name + i * 2;
byte_string[0] = name_char_pair[0]; byte_string[0] = name_char_pair[0];
byte_string[1] = name_char_pair[1]; byte_string[1] = name_char_pair[1];
@ -55,18 +55,18 @@ namespace ams::ncm {
return ResultSuccess(); return ResultSuccess();
} }
std::optional<ContentId> GetContentIdFromString(const char* str, size_t len) { std::optional<ContentId> GetContentIdFromString(const char *str, size_t len) {
if (len < 0x20) { if (len < 0x20) {
return std::nullopt; return std::nullopt;
} }
u8 tmp[sizeof(ContentId)] = {}; u8 tmp[sizeof(ContentId)] = {};
char byte_string[2]; char byte_string[2];
char* end_ptr; char *end_ptr;
u64 converted_val; u64 converted_val;
for (size_t i = 0; i < sizeof(ContentId); i++) { for (size_t i = 0; i < sizeof(ContentId); i++) {
const char* char_par = str + i * 2; const char *char_par = str + i * 2;
byte_string[0] = char_par[0]; byte_string[0] = char_par[0];
byte_string[1] = char_par[1]; byte_string[1] = char_par[1];

View File

@ -21,10 +21,10 @@
namespace ams::ncm { namespace ams::ncm {
void GetStringFromContentId(char* out, ContentId content_id); void GetStringFromContentId(char *out, ContentId content_id);
void GetStringFromPlaceHolderId(char* out, PlaceHolderId placeholder_id); void GetStringFromPlaceHolderId(char *out, PlaceHolderId placeholder_id);
Result GetPlaceHolderIdFromDirEntry(PlaceHolderId* out, struct dirent* dir_entry); Result GetPlaceHolderIdFromDirEntry(PlaceHolderId *out, struct dirent *dir_entry);
std::optional<ContentId> GetContentIdFromString(const char* str, size_t len); std::optional<ContentId> GetContentIdFromString(const char *str, size_t len);
}; };