ncm: Added alignas within the NcmContentId struct, and added NcmPlaceHolderId. Use NcmPlaceHolderId instead of NcmContentId where needed.

This commit is contained in:
yellows8 2019-10-27 19:19:16 -04:00
parent 01133f7f6d
commit 622c0509a5
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 51 additions and 38 deletions

View File

@ -60,9 +60,14 @@ typedef enum {
/// ContentId
typedef struct {
u8 c[0x10]; ///< Id
alignas(4) u8 c[0x10]; ///< Id
} NcmContentId;
/// PlaceHolderId
typedef struct {
alignas(8) u8 c[0x10]; ///< Id
} NcmPlaceHolderId;
/// ContentMetaKey
typedef struct {
u64 title_id; ///< Title id.
@ -159,34 +164,34 @@ Result ncmInactivateContentMetaDatabase(FsStorageId storage_id); ///< [2.0.0+]
Result ncmInvalidateRightsIdCache(void); ///< [9.0.0+]
void ncmContentStorageClose(NcmContentStorage* cs);
Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmContentId* out_id);
Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmContentId* placeholder_id, u64 size);
Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmContentId* placeholder_id);
Result ncmContentStorageHasPlaceHolder(NcmContentStorage* cs, bool* out, const NcmContentId* placeholder_id);
Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmContentId* placeholder_id, u64 offset, const void* data, size_t data_size);
Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmContentId* placeholder_id);
Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmPlaceHolderId* out_id);
Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id, u64 size);
Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id);
Result ncmContentStorageHasPlaceHolder(NcmContentStorage* cs, bool* out, const NcmPlaceHolderId* placeholder_id);
Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, u64 offset, const void* data, size_t data_size);
Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id);
Result ncmContentStorageDelete(NcmContentStorage* cs, const NcmContentId* content_id);
Result ncmContentStorageHas(NcmContentStorage* cs, bool* out, const NcmContentId* content_id);
Result ncmContentStorageGetPath(NcmContentStorage* cs, char* out_path, size_t out_size, const NcmContentId* content_id);
Result ncmContentStorageGetPlaceHolderPath(NcmContentStorage* cs, char* out_path, size_t out_size, const NcmContentId* placeholder_id);
Result ncmContentStorageGetPlaceHolderPath(NcmContentStorage* cs, char* out_path, size_t out_size, const NcmPlaceHolderId* placeholder_id);
Result ncmContentStorageCleanupAllPlaceHolder(NcmContentStorage* cs);
Result ncmContentStorageListPlaceHolder(NcmContentStorage* cs, NcmContentId* out_ids, s32 count, s32* out_count);
Result ncmContentStorageListPlaceHolder(NcmContentStorage* cs, NcmPlaceHolderId* out_ids, s32 count, s32* out_count);
Result ncmContentStorageGetContentCount(NcmContentStorage* cs, s32* out_count);
Result ncmContentStorageListContentId(NcmContentStorage* cs, NcmContentId* out_ids, s32 count, s32* out_count, s32 start_offset);
Result ncmContentStorageGetSizeFromContentId(NcmContentStorage* cs, s64* out_size, const NcmContentId* content_id);
Result ncmContentStorageDisableForcibly(NcmContentStorage* cs);
Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmContentId* placeholder_id, const NcmContentId* old_content_id, const NcmContentId* new_content_id); ///< [2.0.0+]
Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmContentId* placeholder_id, s64 size); ///< [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 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 NcmContentId* placeholder_id); ///< [2.0.0+]
Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id); ///< [2.0.0+]
Result ncmContentStorageGetRightsIdFromContentId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* content_id); ///< [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 ncmContentStorageGetTotalSpaceSize(NcmContentStorage* cs, s64* out_size); ///< [2.0.0+]
Result ncmContentStorageFlushPlaceHolder(NcmContentStorage* cs); ///< [3.0.0+]
Result ncmContentStorageGetSizeFromPlaceHolderId(NcmContentStorage* cs, s64* out_size, const NcmContentId* 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 ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* 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); ///< [8.0.0+]
void ncmContentMetaDatabaseClose(NcmContentMetaDatabase* db);
Result ncmContentMetaDatabaseSet(NcmContentMetaDatabase* db, const NcmContentMetaKey* key, const void* data, u64 data_size);

View File

@ -35,7 +35,7 @@ static Result _ncmCmdNoInOutU64(Service* srv, u64* outval, u32 cmd_id) {
return serviceDispatchOut(srv, cmd_id, *outval);
}
static Result _ncmCmdOutContentId(Service* srv, NcmContentId* outval, u32 cmd_id) {
static Result _ncmCmdOutPlaceHolderId(Service* srv, NcmPlaceHolderId* outval, u32 cmd_id) {
return serviceDispatchOut(srv, cmd_id, *outval);
}
@ -47,10 +47,18 @@ static Result _ncmCmdInContentId(Service* srv, const NcmContentId* inval, u32 cm
return serviceDispatchIn(srv, cmd_id, *inval);
}
static Result _ncmCmdInPlaceHolderId(Service* srv, const NcmPlaceHolderId* inval, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, *inval);
}
static Result _ncmCmdInContentIdOutU64(Service* srv, const NcmContentId* inval, u64* outval, u32 cmd_id) {
return serviceDispatchInOut(srv, cmd_id, *inval, *outval);
}
static Result _ncmCmdInPlaceHolderIdOutU64(Service* srv, const NcmPlaceHolderId* inval, u64* outval, u32 cmd_id) {
return serviceDispatchInOut(srv, cmd_id, *inval, *outval);
}
Result ncmCreateContentStorage(FsStorageId storage_id) {
return _ncmCmdInU8(&g_ncmSrv, storage_id, 0);
}
@ -118,33 +126,33 @@ void ncmContentStorageClose(NcmContentStorage* cs) {
serviceClose(&cs->s);
}
Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmContentId* out_id) {
return _ncmCmdOutContentId(&cs->s, out_id, 0);
Result ncmContentStorageGeneratePlaceHolderId(NcmContentStorage* cs, NcmPlaceHolderId* out_id) {
return _ncmCmdOutPlaceHolderId(&cs->s, out_id, 0);
}
Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmContentId* placeholder_id, u64 size) {
Result ncmContentStorageCreatePlaceHolder(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id, u64 size) {
const struct {
NcmContentId content_id;
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
u64 size;
} in = { *content_id, *placeholder_id, size };
return serviceDispatchIn(&cs->s, 1, in);
}
Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmContentId* placeholder_id) {
return _ncmCmdInContentId(&cs->s, placeholder_id, 2);
Result ncmContentStorageDeletePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id) {
return _ncmCmdInPlaceHolderId(&cs->s, placeholder_id, 2);
}
Result ncmContentStorageHasPlaceHolder(NcmContentStorage* cs, bool* out, const NcmContentId* placeholder_id) {
Result ncmContentStorageHasPlaceHolder(NcmContentStorage* cs, bool* out, const NcmPlaceHolderId* placeholder_id) {
u8 tmp=0;
Result rc = serviceDispatchInOut(&cs->s, 3, *placeholder_id, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmContentId* placeholder_id, u64 offset, const void* data, size_t data_size) {
Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, u64 offset, const void* data, size_t data_size) {
const struct {
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
u64 offset;
} in = { *placeholder_id, offset };
return serviceDispatchIn(&cs->s, 4, in,
@ -153,10 +161,10 @@ Result ncmContentStorageWritePlaceHolder(NcmContentStorage* cs, const NcmContent
);
}
Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmContentId* placeholder_id) {
Result ncmContentStorageRegister(NcmContentStorage* cs, const NcmContentId* content_id, const NcmPlaceHolderId* placeholder_id) {
const struct {
NcmContentId content_id;
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
} in = { *content_id, *placeholder_id };
return serviceDispatchIn(&cs->s, 5, in);
}
@ -185,7 +193,7 @@ Result ncmContentStorageGetPath(NcmContentStorage* cs, char* out_path, size_t ou
return rc;
}
Result ncmContentStorageGetPlaceHolderPath(NcmContentStorage* cs, char* out_path, size_t out_size, const NcmContentId* placeholder_id) {
Result ncmContentStorageGetPlaceHolderPath(NcmContentStorage* cs, char* out_path, size_t out_size, const NcmPlaceHolderId* placeholder_id) {
char tmpbuf[0x300]={0};
Result rc = serviceDispatchIn(&cs->s, 9, *placeholder_id,
.buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_Out },
@ -202,10 +210,10 @@ Result ncmContentStorageCleanupAllPlaceHolder(NcmContentStorage* cs) {
return _ncmCmdNoIO(&cs->s, 10);
}
Result ncmContentStorageListPlaceHolder(NcmContentStorage* cs, NcmContentId* out_ids, s32 count, s32* out_count) {
Result ncmContentStorageListPlaceHolder(NcmContentStorage* cs, NcmPlaceHolderId* out_ids, s32 count, s32* out_count) {
return serviceDispatchOut(&cs->s, 11, *out_count,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
.buffers = { { out_ids, count*sizeof(NcmContentId) } },
.buffers = { { out_ids, count*sizeof(NcmPlaceHolderId) } },
);
}
@ -228,20 +236,20 @@ Result ncmContentStorageDisableForcibly(NcmContentStorage* cs) {
return _ncmCmdNoIO(&cs->s, 15);
}
Result ncmContentStorageRevertToPlaceHolder(NcmContentStorage* cs, const NcmContentId* 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);
const struct {
NcmContentId old_content_id;
NcmContentId new_content_id;
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
} in = { *old_content_id, *new_content_id, *placeholder_id };
return serviceDispatchIn(&cs->s, 16, in);
}
Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmContentId* placeholder_id, s64 size) {
Result ncmContentStorageSetPlaceHolderSize(NcmContentStorage* cs, const NcmPlaceHolderId* placeholder_id, s64 size) {
if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
const struct {
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
s64 size;
} in = { *placeholder_id, size };
return serviceDispatchIn(&cs->s, 17, in);
@ -259,7 +267,7 @@ Result ncmContentStorageReadContentIdFile(NcmContentStorage* cs, void* out_data,
);
}
Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* placeholder_id) {
Result ncmContentStorageGetRightsIdFromPlaceHolderId(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id) {
if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
if (hosversionBefore(3,0,0))
return serviceDispatchInOut(&cs->s, 19, *placeholder_id, out_rights_id->rights_id);
@ -303,9 +311,9 @@ Result ncmContentStorageFlushPlaceHolder(NcmContentStorage* cs) {
return _ncmCmdNoIO(&cs->s, 24);
}
Result ncmContentStorageGetSizeFromPlaceHolderId(NcmContentStorage* cs, s64* out_size, const NcmContentId* placeholder_id) {
Result ncmContentStorageGetSizeFromPlaceHolderId(NcmContentStorage* cs, s64* out_size, const NcmPlaceHolderId* placeholder_id) {
if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ncmCmdInContentIdOutU64(&cs->s, placeholder_id, (u64*)out_size, 25);
return _ncmCmdInPlaceHolderIdOutU64(&cs->s, placeholder_id, (u64*)out_size, 25);
}
Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs) {
@ -313,11 +321,11 @@ Result ncmContentStorageRepairInvalidFileAttribute(NcmContentStorage* cs) {
return _ncmCmdNoIO(&cs->s, 26);
}
Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmContentId* placeholder_id, const NcmContentId* cache_content_id) {
Result ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(NcmContentStorage* cs, NcmRightsId* out_rights_id, const NcmPlaceHolderId* placeholder_id, const NcmContentId* cache_content_id) {
if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
const struct {
NcmContentId cache_content_id;
NcmContentId placeholder_id;
NcmPlaceHolderId placeholder_id;
} in = { *cache_content_id, *placeholder_id };
if (hosversionBefore(3,0,0))