ncm: Add ActivateFsContentStorage

ncm: update bindings for 16.0.0 changes

ncm: fix missing rename on GetPatchContentMetaId

ncm: they broke serialization ordering by changing type alignment

ncm: remove alignment on content id/placeholder id
This commit is contained in:
Michael Scire 2023-02-21 16:04:47 -07:00
parent ada230a882
commit 1320ccdb0c
4 changed files with 100 additions and 41 deletions

View File

@ -184,9 +184,10 @@ typedef enum {
} FsWriteOption; } FsWriteOption;
typedef enum { typedef enum {
FsContentStorageId_System = 0, FsContentStorageId_System = 0, ///< System
FsContentStorageId_User = 1, FsContentStorageId_User = 1, ///< User
FsContentStorageId_SdCard = 2, FsContentStorageId_SdCard = 2, ///< SdCard
FsContentStorageId_System0 = 3, ///< [16.0.0+] System0
} FsContentStorageId; } FsContentStorageId;
typedef enum { typedef enum {
@ -298,6 +299,8 @@ typedef enum {
FsBisPartitionId_SystemProperEncryption = 32, FsBisPartitionId_SystemProperEncryption = 32,
FsBisPartitionId_SystemProperPartition = 33, FsBisPartitionId_SystemProperPartition = 33,
FsBisPartitionId_SignedSystemPartitionOnSafeMode = 34, FsBisPartitionId_SignedSystemPartitionOnSafeMode = 34,
FsBisPartitionId_DeviceTreeBlob = 35,
FsBisPartitionId_System0 = 36,
} FsBisPartitionId; } FsBisPartitionId;
/// FileSystemType /// FileSystemType

View File

@ -50,6 +50,7 @@ Result ncmInactivateContentStorage(NcmStorageId storage_id); ///< [2.0.0+]
Result ncmActivateContentMetaDatabase(NcmStorageId storage_id); ///< [2.0.0+] Result ncmActivateContentMetaDatabase(NcmStorageId storage_id); ///< [2.0.0+]
Result ncmInactivateContentMetaDatabase(NcmStorageId storage_id); ///< [2.0.0+] Result ncmInactivateContentMetaDatabase(NcmStorageId storage_id); ///< [2.0.0+]
Result ncmInvalidateRightsIdCache(void); ///< [9.0.0+] Result ncmInvalidateRightsIdCache(void); ///< [9.0.0+]
Result ncmActivateFsContentStorage(FsContentStorageId fs_storage_id); ///< [16.0.0+]
void ncmContentStorageClose(NcmContentStorage* cs); void ncmContentStorageClose(NcmContentStorage* cs);
Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmPlaceHolderId* out_id); Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmPlaceHolderId* out_id);
@ -71,15 +72,15 @@ Result ncmContentStorageDisableForcibly(NcmContentStorage* cs);
Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, const NcmContentId* old_content_id, const NcmContentId* new_content_id); ///< [2.0.0+] Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, const NcmContentId* old_content_id, const NcmContentId* new_content_id); ///< [2.0.0+]
Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, s64 size); ///< [2.0.0+] Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, s64 size); ///< [2.0.0+]
Result ncmContentStorageReadContentIdFile(NcmContentStorage* cs, void* out_data, size_t out_data_size, const NcmContentId* content_id, s64 offset); ///< [2.0.0+] Result ncmContentStorageReadContentIdFile(NcmContentStorage* cs, void* out_data, size_t out_data_size, const NcmContentId* content_id, s64 offset); ///< [2.0.0+]
Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id); ///< [2.0.0+] Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, FsContentAttributes attr); ///< [2.0.0+]
Result ncmContentStorageGetRightsIdFromContentId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* content_id); ///< [2.0.0+] Result ncmContentStorageGetRightsIdFromContentId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* content_id, FsContentAttributes attr); ///< [2.0.0+]
Result ncmContentStorageWriteContentForDebug(NcmContentStorage* cs, const NcmContentId* content_id, s64 offset, const void* data, size_t data_size); ///< [2.0.0+] Result ncmContentStorageWriteContentForDebug(NcmContentStorage* cs, const NcmContentId* content_id, s64 offset, const void* data, size_t data_size); ///< [2.0.0+]
Result ncmContentStorageGetFreeSpaceSize(NcmContentStorage* cs, s64* out_size); ///< [2.0.0+] Result ncmContentStorageGetFreeSpaceSize(NcmContentStorage* cs, s64* out_size); ///< [2.0.0+]
Result ncmContentStorageGetTotalSpaceSize(NcmContentStorage* cs, s64* out_size); ///< [2.0.0+] Result ncmContentStorageGetTotalSpaceSize(NcmContentStorage* cs, s64* out_size); ///< [2.0.0+]
Result ncmContentStorageFlushPlaceHolder(NcmContentStorage* cs); ///< [3.0.0+] Result ncmContentStorageFlushPlaceHolder(NcmContentStorage* cs); ///< [3.0.0+]
Result ncmContentStorageGetSizeFromPlaceHolderId(NcmContentStorage* cs, s64* out_size, const NcmPlaceHolderId* placeholder_id); ///< [4.0.0+] Result ncmContentStorageGetSizeFromPlaceHolderId(NcmContentStorage* cs, s64* out_size, const NcmPlaceHolderId* placeholder_id); ///< [4.0.0+]
Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs); ///< [4.0.0+] Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs); ///< [4.0.0+]
Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, const NcmContentId* cache_content_id); ///< [8.0.0+] 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 ncmContentStorageRegisterPath(NcmContentStorage* cs, const NcmContentId* content_id, const char *path); ///< [13.0.0+]
Result ncmContentStorageClearRegisteredPath(NcmContentStorage* cs); ///< [13.0.0+] Result ncmContentStorageClearRegisteredPath(NcmContentStorage* cs); ///< [13.0.0+]
@ -96,7 +97,7 @@ Result ncmContentMetaDatabaseHas(NcmContentMetaDatabase* db, bool* out, const Nc
Result ncmContentMetaDatabaseHasAll(NcmContentMetaDatabase* db, bool* out, const NcmContentMetaKey* keys, s32 count); Result ncmContentMetaDatabaseHasAll(NcmContentMetaDatabase* db, bool* out, const NcmContentMetaKey* keys, s32 count);
Result ncmContentMetaDatabaseGetSize(NcmContentMetaDatabase* db, u64* out_size, const NcmContentMetaKey* key); Result ncmContentMetaDatabaseGetSize(NcmContentMetaDatabase* db, u64* out_size, const NcmContentMetaKey* key);
Result ncmContentMetaDatabaseGetRequiredSystemVersion(NcmContentMetaDatabase* db, u32* out_version, const NcmContentMetaKey* key); Result ncmContentMetaDatabaseGetRequiredSystemVersion(NcmContentMetaDatabase* db, u32* out_version, const NcmContentMetaKey* key);
Result ncmContentMetaDatabaseGetPatchId(NcmContentMetaDatabase* db, u64* out_patch_id, const NcmContentMetaKey* key); Result ncmContentMetaDatabaseGetPatchContentMetaId(NcmContentMetaDatabase* db, u64* out_patch_id, const NcmContentMetaKey* key);
Result ncmContentMetaDatabaseDisableForcibly(NcmContentMetaDatabase* db); Result ncmContentMetaDatabaseDisableForcibly(NcmContentMetaDatabase* db);
Result ncmContentMetaDatabaseLookupOrphanContent(NcmContentMetaDatabase* db, bool* out_orphaned, const NcmContentId* content_ids, s32 count); Result ncmContentMetaDatabaseLookupOrphanContent(NcmContentMetaDatabase* db, bool* out_orphaned, const NcmContentId* content_ids, s32 count);
Result ncmContentMetaDatabaseCommit(NcmContentMetaDatabase* db); Result ncmContentMetaDatabaseCommit(NcmContentMetaDatabase* db);

View File

@ -62,12 +62,12 @@ typedef enum {
/// ContentId /// ContentId
typedef struct { typedef struct {
alignas(4) u8 c[0x10]; ///< Id u8 c[0x10]; ///< Id
} NcmContentId; } NcmContentId;
/// PlaceHolderId /// PlaceHolderId
typedef struct { typedef struct {
alignas(8) Uuid uuid; ///< UUID Uuid uuid; ///< UUID
} NcmPlaceHolderId; } NcmPlaceHolderId;
/// ContentMetaKey /// ContentMetaKey

View File

@ -43,6 +43,10 @@ static Result _ncmCmdInU8(Service* srv, u8 inval, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, inval); return serviceDispatchIn(srv, cmd_id, inval);
} }
static Result _ncmCmdInU32(Service* srv, u32 inval, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, inval);
}
static Result _ncmCmdInContentId(Service* srv, const NcmContentId* inval, u32 cmd_id) { static Result _ncmCmdInContentId(Service* srv, const NcmContentId* inval, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, *inval); return serviceDispatchIn(srv, cmd_id, *inval);
} }
@ -122,6 +126,11 @@ Result ncmInvalidateRightsIdCache(void) {
return _ncmCmdNoIO(&g_ncmSrv, 13); return _ncmCmdNoIO(&g_ncmSrv, 13);
} }
Result ncmActivateFsContentStorage(FsContentStorageId fs_storage_id) {
if (!hosversionIsAtmosphere() && hosversionBefore(16,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ncmCmdInU32(&g_ncmSrv, fs_storage_id, 15);
}
void ncmContentStorageClose(NcmContentStorage* cs) { void ncmContentStorageClose(NcmContentStorage* cs) {
serviceClose(&cs->s); serviceClose(&cs->s);
} }
@ -131,12 +140,21 @@ Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmPlaceHol
} }
Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id, s64 size) { Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id, s64 size) {
const struct { if (hosversionBefore(16,0,0)) {
NcmContentId content_id; const struct {
NcmPlaceHolderId placeholder_id; NcmContentId content_id;
s64 size; NcmPlaceHolderId placeholder_id;
} in = { *content_id, *placeholder_id, size }; s64 size;
return serviceDispatchIn(&cs->s, 1, in); } in = { *content_id, *placeholder_id, size };
return serviceDispatchIn(&cs->s, 1, in);
} else {
const struct {
NcmPlaceHolderId placeholder_id;
NcmContentId content_id;
s64 size;
} in = { *placeholder_id, *content_id, size };
return serviceDispatchIn(&cs->s, 1, in);
}
} }
Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id) { Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id) {
@ -162,11 +180,19 @@ Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmPlaceHo
} }
Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id) { Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id) {
const struct { if (hosversionBefore(16,0,0)) {
NcmContentId content_id; const struct {
NcmPlaceHolderId placeholder_id; NcmContentId content_id;
} in = { *content_id, *placeholder_id }; NcmPlaceHolderId placeholder_id;
return serviceDispatchIn(&cs->s, 5, in); } in = { *content_id, *placeholder_id };
return serviceDispatchIn(&cs->s, 5, in);
} else {
const struct {
NcmPlaceHolderId placeholder_id;
NcmContentId content_id;
} in = { *placeholder_id, *content_id };
return serviceDispatchIn(&cs->s, 5, in);
}
} }
Result ncmContentStorageDelete(NcmContentStorage* cs, const NcmContentId* content_id) { Result ncmContentStorageDelete(NcmContentStorage* cs, const NcmContentId* content_id) {
@ -238,12 +264,22 @@ Result ncmContentStorageDisableForcibly(NcmContentStorage* cs) {
Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, const NcmContentId* old_content_id, const NcmContentId* new_content_id) { Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, const NcmContentId* old_content_id, const NcmContentId* new_content_id) {
if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
const struct {
NcmContentId old_content_id; if (hosversionBefore(16,0,0)) {
NcmContentId new_content_id; const struct {
NcmPlaceHolderId placeholder_id; NcmContentId old_content_id;
} in = { *old_content_id, *new_content_id, *placeholder_id }; NcmContentId new_content_id;
return serviceDispatchIn(&cs->s, 16, in); NcmPlaceHolderId placeholder_id;
} in = { *old_content_id, *new_content_id, *placeholder_id };
return serviceDispatchIn(&cs->s, 16, in);
} else {
const struct {
NcmPlaceHolderId placeholder_id;
NcmContentId old_content_id;
NcmContentId new_content_id;
} in = { *placeholder_id, *old_content_id, *new_content_id };
return serviceDispatchIn(&cs->s, 16, in);
}
} }
Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, s64 size) { Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, s64 size) {
@ -267,21 +303,33 @@ Result ncmContentStorageReadContentIdFile(NcmContentStorage* cs, void* out_data,
); );
} }
Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id) { Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, FsContentAttributes attr) {
if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
const struct {
NcmPlaceHolderId placeholder_id;
u8 attr;
} in = { *placeholder_id, attr };
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return serviceDispatchInOut(&cs->s, 19, *placeholder_id, out_rights_id->rights_id); return serviceDispatchInOut(&cs->s, 19, in, out_rights_id->rights_id);
else else
return serviceDispatchInOut(&cs->s, 19, *placeholder_id, *out_rights_id); return serviceDispatchInOut(&cs->s, 19, in, *out_rights_id);
} }
Result ncmContentStorageGetRightsIdFromContentId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* content_id) { Result ncmContentStorageGetRightsIdFromContentId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* content_id, FsContentAttributes attr) {
if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
memset(out_rights_id, 0, sizeof(*out_rights_id)); memset(out_rights_id, 0, sizeof(*out_rights_id));
const struct {
NcmContentId content_id;
u8 attr;
} in = { *content_id, attr };
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return serviceDispatchInOut(&cs->s, 20, *content_id, out_rights_id->rights_id); return serviceDispatchInOut(&cs->s, 20, in, out_rights_id->rights_id);
else else
return serviceDispatchInOut(&cs->s, 20, *content_id, *out_rights_id); return serviceDispatchInOut(&cs->s, 20, in, *out_rights_id);
} }
Result ncmContentStorageWriteContentForDebug(NcmContentStorage* cs, const NcmContentId* content_id, s64 offset, const void* data, size_t data_size) { Result ncmContentStorageWriteContentForDebug(NcmContentStorage* cs, const NcmContentId* content_id, s64 offset, const void* data, size_t data_size) {
@ -321,17 +369,24 @@ Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs) {
return _ncmCmdNoIO(&cs->s, 26); return _ncmCmdNoIO(&cs->s, 26);
} }
Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, const NcmContentId* cache_content_id) { Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, const NcmContentId* cache_content_id, FsContentAttributes attr) {
if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
const struct {
NcmContentId cache_content_id;
NcmPlaceHolderId placeholder_id;
} in = { *cache_content_id, *placeholder_id };
if (hosversionBefore(3,0,0)) if (hosversionBefore(16,0,0)) {
return serviceDispatchInOut(&cs->s, 27, in, out_rights_id->rights_id); const struct {
else NcmContentId cache_content_id;
NcmPlaceHolderId placeholder_id;
} in = { *cache_content_id, *placeholder_id };
return serviceDispatchInOut(&cs->s, 27, in, *out_rights_id); return serviceDispatchInOut(&cs->s, 27, in, *out_rights_id);
} else {
const struct {
NcmPlaceHolderId placeholder_id;
NcmContentId cache_content_id;
u8 attr;
} in = { *placeholder_id, *cache_content_id, attr };
return serviceDispatchInOut(&cs->s, 27, in, *out_rights_id);
}
} }
Result ncmContentStorageRegisterPath(NcmContentStorage* cs, const NcmContentId* content_id, const char *path) { Result ncmContentStorageRegisterPath(NcmContentStorage* cs, const NcmContentId* content_id, const char *path) {
@ -464,7 +519,7 @@ Result ncmContentMetaDatabaseGetRequiredSystemVersion(NcmContentMetaDatabase* db
return serviceDispatchInOut(&db->s, 11, *key, *out_version); return serviceDispatchInOut(&db->s, 11, *key, *out_version);
} }
Result ncmContentMetaDatabaseGetPatchId(NcmContentMetaDatabase* db, u64* out_patch_id, const NcmContentMetaKey* key) { Result ncmContentMetaDatabaseGetPatchContentMetaId(NcmContentMetaDatabase* db, u64* out_patch_id, const NcmContentMetaKey* key) {
return serviceDispatchInOut(&db->s, 12, *key, *out_patch_id); return serviceDispatchInOut(&db->s, 12, *key, *out_patch_id);
} }