From b5e47b6b67dcfc384dd6d5e98e790a03df724f0c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 21 Feb 2023 20:10:48 -0700 Subject: [PATCH] fs: update bindings for 16.0.0 changes fs: add new ContentAttributes enum fs: add version check fs: use hosversionBetween --- nx/include/switch/services/fs.h | 14 +++++-- nx/include/switch/services/fsldr.h | 2 +- nx/source/services/fs.c | 65 +++++++++++++++++++++--------- nx/source/services/fsldr.c | 23 ++++++++++- 4 files changed, 77 insertions(+), 27 deletions(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index f92e893e..d72fb744 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -328,6 +328,12 @@ typedef enum { FsPriority_Background = 3, } FsPriority; +/// FsContentAttributes +typedef enum { + FsContentAttributes_None = 0x0, + FsContentAttributes_All = 0xF, +} FsContentAttributes; + /// For use with fsOpenHostFileSystemWithOption typedef enum { FsMountHostOptionFlag_None = 0, ///< Host filesystem will be case insensitive. @@ -350,7 +356,7 @@ void fsSetPriority(FsPriority prio); Result fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, const char* contentPath); ///< same as calling fsOpenFileSystemWithId with 0 as id Result fsOpenDataFileSystemByCurrentProcess(FsFileSystem *out); Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 id, FsFileSystemType fsType); ///< [2.0.0+], like OpenFileSystemWithId but without content path. -Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath); ///< works on all firmwares, id is ignored on [1.0.0] +Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath, FsContentAttributes attr); ///< works on all firmwares, id is ignored on [1.0.0], attr is ignored before [16.0.0] Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id); ///< [3.0.0+] Result fsOpenBisFileSystem(FsFileSystem* out, FsBisPartitionId partitionId, const char* string); Result fsOpenBisStorage(FsStorage* out, FsBisPartitionId partitionId); @@ -399,11 +405,11 @@ Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); Result fsIsSignedSystemPartitionOnSdCardValid(bool *out); -/// Retrieves the rights id corresponding to the content path. Only available on [2.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); -/// Retrieves the rights id and key generation corresponding to the content path. Only available on [3.0.0+]. -Result fsGetRightsIdAndKeyGenerationByPath(const char* path, u8* out_key_generation, FsRightsId* out_rights_id); +/// Retrieves the rights id and key generation corresponding to the content path. Only available on [3.0.0+], attr is ignored before [16.0.0]. +Result fsGetRightsIdAndKeyGenerationByPath(const char* path, FsContentAttributes attr, u8* out_key_generation, FsRightsId* out_rights_id); Result fsDisableAutoSaveDataCreation(void); diff --git a/nx/include/switch/services/fsldr.h b/nx/include/switch/services/fsldr.h index e7f761df..2016aa07 100644 --- a/nx/include/switch/services/fsldr.h +++ b/nx/include/switch/services/fsldr.h @@ -26,5 +26,5 @@ void fsldrExit(void); /// Gets the Service object for the actual fsp-ldr service session. Service* fsldrGetServiceSession(void); -Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsFileSystem* out); +Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsContentAttributes attr, FsFileSystem* out); Result fsldrIsArchivedProgram(u64 pid, bool *out); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 527d612a..9be5b9d0 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -133,7 +133,7 @@ static Result _fsCmdNoInOutBool(Service* srv, bool *out, u32 cmd_id) { //----------------------------------------------------------------------------- Result fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, const char* contentPath) { - return fsOpenFileSystemWithId(out, 0, fsType, contentPath); + return fsOpenFileSystemWithId(out, 0, fsType, contentPath, FsContentAttributes_None); } static Result _fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, const char* contentPath) { @@ -165,18 +165,33 @@ Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 id, FsFileSystemType fsT ); } -static Result _fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath) { - const struct { - u32 fsType; - u64 id; - } in = { fsType, id }; +static Result _fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath, FsContentAttributes attr) { + if (hosversionAtLeast(16,0,0)) { + const struct { + u8 attr; + u32 fsType; + u64 id; + } in = { attr, fsType, id }; - return _fsObjectDispatchIn(&g_fsSrv, 8, in, - .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, - .buffers = { { contentPath, FS_MAX_PATH } }, - .out_num_objects = 1, - .out_objects = &out->s, - ); + return _fsObjectDispatchIn(&g_fsSrv, 10, in, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { contentPath, FS_MAX_PATH } }, + .out_num_objects = 1, + .out_objects = &out->s, + ); + } else { + const struct { + u32 fsType; + u64 id; + } in = { fsType, id }; + + return _fsObjectDispatchIn(&g_fsSrv, 8, in, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { contentPath, FS_MAX_PATH } }, + .out_num_objects = 1, + .out_objects = &out->s, + ); + } } Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id) { @@ -189,12 +204,12 @@ Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id) { ); } -Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath) { +Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath, FsContentAttributes attr) { char sendStr[FS_MAX_PATH] = {0}; strncpy(sendStr, contentPath, sizeof(sendStr)-1); if (hosversionAtLeast(2,0,0)) - return _fsOpenFileSystemWithId(out, id, fsType, sendStr); + return _fsOpenFileSystemWithId(out, id, fsType, sendStr, attr); else return _fsOpenFileSystem(out, fsType, sendStr); } @@ -520,7 +535,7 @@ Result fsIsSignedSystemPartitionOnSdCardValid(bool *out) { } Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { - if (hosversionBefore(2,0,0)) + if (!hosversionBetween(2, 16)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); char send_path[FS_MAX_PATH] = {0}; @@ -532,23 +547,33 @@ Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { ); } -Result fsGetRightsIdAndKeyGenerationByPath(const char* path, u8* out_key_generation, FsRightsId* out_rights_id) { +Result fsGetRightsIdAndKeyGenerationByPath(const char* path, FsContentAttributes attr, u8* out_key_generation, FsRightsId* out_rights_id) { if (hosversionBefore(3,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; + struct { u8 key_generation; u8 padding[0x7]; FsRightsId rights_id; } out; - Result rc = _fsObjectDispatchOut(&g_fsSrv, 610, out, - .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, - .buffers = { { send_path, sizeof(send_path) } }, - ); + Result rc; + if (hosversionAtLeast(16,0,0)) { + rc = _fsObjectDispatchInOut(&g_fsSrv, 610, in, out, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { send_path, sizeof(send_path) } }, + ); + } else { + rc = _fsObjectDispatchOut(&g_fsSrv, 610, out, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { send_path, sizeof(send_path) } }, + ); + } if (R_SUCCEEDED(rc)) { if (out_key_generation) *out_key_generation = out.key_generation; diff --git a/nx/source/services/fsldr.c b/nx/source/services/fsldr.c index 03f43edb..0d7046b8 100644 --- a/nx/source/services/fsldr.c +++ b/nx/source/services/fsldr.c @@ -32,13 +32,32 @@ Service* fsldrGetServiceSession(void) { return &g_fsldrSrv; } -Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsFileSystem* out) { +Result fsldrOpenCodeFileSystem(FsCodeInfo* out_code_info, u64 tid, const char *path, FsContentAttributes attr, FsFileSystem* out) { memset(out_code_info, 0, sizeof(*out_code_info)); char send_path[FS_MAX_PATH]={0}; strncpy(send_path, path, FS_MAX_PATH-1); - if (hosversionAtLeast(10,0,0)) { + if (hosversionAtLeast(16,0,0)) { + const struct { + u8 attr; + u64 tid; + } in = { attr, tid }; + + serviceAssumeDomain(&g_fsldrSrv); + return serviceDispatchIn(&g_fsldrSrv, 0, in, + .buffer_attrs = { + SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_Out, + SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_In, + }, + .buffers = { + { out_code_info, sizeof(*out_code_info) }, + { send_path, FS_MAX_PATH }, + }, + .out_num_objects = 1, + .out_objects = &out->s, + ); + } else if (hosversionAtLeast(10,0,0)) { serviceAssumeDomain(&g_fsldrSrv); return serviceDispatchIn(&g_fsldrSrv, 0, tid, .buffer_attrs = {