From ca1cc2c83c3c0107999c9c13ab19805468206d09 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 5 Jun 2020 14:16:07 +0200 Subject: [PATCH] add commands for accessing process storage --- nx/include/switch/services/fs.h | 5 ++++- nx/source/services/fs.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index dabc8e0a..9bdfefbd 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -313,9 +313,10 @@ void fsSetPriority(FsPriority prio); /// Mount requested filesystem type from content file 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 fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id); Result fsOpenBisFileSystem(FsFileSystem* out, FsBisPartitionId partitionId, const char* string); Result fsOpenBisStorage(FsStorage* out, FsBisPartitionId partitionId); @@ -346,7 +347,9 @@ Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId cont Result fsOpenCustomStorageFileSystem(FsFileSystem* out, FsCustomStorageId custom_storage_id); ///< [7.0.0+] Result fsOpenDataStorageByCurrentProcess(FsStorage* out); +Result fsOpenDataStorageByProgramId(FsStorage *out, u64 program_id); Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, NcmStorageId storageId); +Result fsOpenPatchDataStorageByCurrentProcess(FsStorage* out); Result fsOpenDeviceOperator(FsDeviceOperator* out); Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 2f9f3aac..d84535fe 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -146,6 +146,10 @@ static Result _fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, cons ); } +Result fsOpenDataFileSystemByCurrentProcess(FsFileSystem *out) { + return _fsCmdGetSession(&g_fsSrv, &out->s, 2); +} + Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 id, FsFileSystemType fsType) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -175,6 +179,13 @@ static Result _fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemTyp ); } +Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id) { + return _fsObjectDispatchIn(&g_fsSrv, 9, program_id, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath) { char sendStr[FS_MAX_PATH] = {0}; strncpy(sendStr, contentPath, sizeof(sendStr)-1); @@ -398,6 +409,13 @@ Result fsOpenDataStorageByCurrentProcess(FsStorage* out) { return _fsCmdGetSession(&g_fsSrv, &out->s, 200); } +Result fsOpenDataStorageByProgramId(FsStorage *out, u64 program_id) { + return _fsObjectDispatchIn(&g_fsSrv, 201, program_id, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, NcmStorageId storageId) { const struct { u8 storage_id; @@ -410,6 +428,10 @@ Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, NcmStorageId storag ); } +Result fsOpenPatchDataStorageByCurrentProcess(FsStorage* out) { + return _fsCmdGetSession(&g_fsSrv, &out->s, 203); +} + Result fsOpenDeviceOperator(FsDeviceOperator* out) { return _fsCmdGetSession(&g_fsSrv, &out->s, 400); }