From 25a8f217965ef7d7329711e5c02eeeac9c39a928 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 11 Oct 2023 12:32:59 -0700 Subject: [PATCH] ncm/fs: add new 17.0.0 commands --- nx/include/switch/services/fs.h | 2 ++ nx/include/switch/services/ncm.h | 2 ++ nx/include/switch/services/ncm_types.h | 5 +++++ nx/source/services/fs.c | 14 ++++++++++++++ nx/source/services/ncm.c | 16 ++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index d72fb744..4aaf86c4 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -405,6 +405,8 @@ Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); Result fsIsSignedSystemPartitionOnSdCardValid(bool *out); +Result fsGetProgramId(u64* out, const char *path, FsContentAttributes attr); ///< [17.0.0+] + /// Retrieves the rights id corresponding to the content path. Only available on [2.0.0-15.0.1]. Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id); diff --git a/nx/include/switch/services/ncm.h b/nx/include/switch/services/ncm.h index 7df2a870..3c9bf127 100644 --- a/nx/include/switch/services/ncm.h +++ b/nx/include/switch/services/ncm.h @@ -83,6 +83,7 @@ Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs); ///< Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, const NcmContentId* cache_content_id, FsContentAttributes attr); ///< [8.0.0+] Result ncmContentStorageRegisterPath(NcmContentStorage* cs, const NcmContentId* content_id, const char *path); ///< [13.0.0+] Result ncmContentStorageClearRegisteredPath(NcmContentStorage* cs); ///< [13.0.0+] +Result ncmContentStorageGetProgramId(NcmContentStorage* cs, u64* out, const NcmContentId* content_id, FsContentAttributes attr); ///< [17.0.0+] void ncmContentMetaDatabaseClose(NcmContentMetaDatabase* db); Result ncmContentMetaDatabaseSet(NcmContentMetaDatabase* db, const NcmContentMetaKey* key, const void* data, u64 data_size); @@ -106,3 +107,4 @@ Result ncmContentMetaDatabaseListContentMetaInfo(NcmContentMetaDatabase* db, s32 Result ncmContentMetaDatabaseGetAttributes(NcmContentMetaDatabase* db, const NcmContentMetaKey* key, u8* out); Result ncmContentMetaDatabaseGetRequiredApplicationVersion(NcmContentMetaDatabase* db, u32* out_version, const NcmContentMetaKey* key); ///< [2.0.0+] Result ncmContentMetaDatabaseGetContentIdByTypeAndIdOffset(NcmContentMetaDatabase* db, NcmContentId* out_content_id, const NcmContentMetaKey* key, NcmContentType type, u8 id_offset); ///< [5.0.0+] +Result ncmContentMetaDatabaseGetPlatform(NcmContentMetaDatabase* db, u8* out, const NcmContentMetaKey* key); ///< [17.0.0+] diff --git a/nx/include/switch/services/ncm_types.h b/nx/include/switch/services/ncm_types.h index 49a5bf9e..1247fed6 100644 --- a/nx/include/switch/services/ncm_types.h +++ b/nx/include/switch/services/ncm_types.h @@ -60,6 +60,11 @@ typedef enum { NcmContentInstallType_Unknown = 7, ///< Unknown } NcmContentInstallType; +/// ContentMetaPlatform +typedef enum { + NcmContentMetaPlatform_Nx = 0, ///< Nx +} NcmContentMetaPlatform; + /// ContentId typedef struct { u8 c[0x10]; ///< Id diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 0ac23174..1fcb74ea 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -538,6 +538,20 @@ Result fsIsSignedSystemPartitionOnSdCardValid(bool *out) { return _fsCmdNoInOutBool(&g_fsSrv, out, 640); } +Result fsGetProgramId(u64* out, const char *path, FsContentAttributes attr) { + if (hosversionBefore(17,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + char send_path[FS_MAX_PATH] = {0}; + strncpy(send_path, path, FS_MAX_PATH-1); + + const u8 in = attr; + return _fsObjectDispatchInOut(&g_fsSrv, 618, in, out, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { send_path, sizeof(send_path) } }, + ); +} + Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { if (!hosversionBetween(2, 16)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); diff --git a/nx/source/services/ncm.c b/nx/source/services/ncm.c index 18ad3ee6..d594d360 100644 --- a/nx/source/services/ncm.c +++ b/nx/source/services/ncm.c @@ -407,6 +407,16 @@ Result ncmContentStorageClearRegisteredPath(NcmContentStorage* cs) { return _ncmCmdNoIO(&cs->s, 29); } +Result ncmContentStorageGetProgramId(NcmContentStorage* cs, u64* out, const NcmContentId* content_id, FsContentAttributes attr) { + if (hosversionBefore(17,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + const struct { + NcmContentId content_id; + u8 attr; + } in = { *content_id, attr }; + return serviceDispatchInOut(&cs->s, 30, in, *out); +} + void ncmContentMetaDatabaseClose(NcmContentMetaDatabase* db) { serviceClose(&db->s); } @@ -586,3 +596,9 @@ Result ncmContentMetaDatabaseGetContentIdByTypeAndIdOffset(NcmContentMetaDatabas } in = { type, id_offset, {0}, *key }; return serviceDispatchInOut(&db->s, 20, in, *out_content_id); } + +Result ncmContentMetaDatabaseGetPlatform(NcmContentMetaDatabase* db, u8* out, const NcmContentMetaKey* key) { + if (hosversionBefore(17,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchInOut(&db->s, 26, *key, *out); +}