diff --git a/nx/include/switch/runtime/devices/romfs_dev.h b/nx/include/switch/runtime/devices/romfs_dev.h index b33e2418..63a0786f 100644 --- a/nx/include/switch/runtime/devices/romfs_dev.h +++ b/nx/include/switch/runtime/devices/romfs_dev.h @@ -82,6 +82,14 @@ Result romfsMountFromStorage(FsStorage storage, u64 offset, const char *name); */ Result romfsMountFromCurrentProcess(const char *name); +/** + * @brief Mounts RomFS of a running program. + * @note Permission needs to be set in the NPDM. + * @param program_id ProgramId to mount. + * @param name Device mount name. + */ +Result romfsMountDataStorageFromProgram(u64 program_id, const char *name); + /** * @brief Mounts RomFS from a file path in a mounted fsdev device. * @param path File path. diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index dabc8e0a..f7543e56 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); ///< [3.0.0+] 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); /// <[3.0.0+] 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/runtime/devices/romfs_dev.c b/nx/source/runtime/devices/romfs_dev.c index 0dd50374..b1e4c7f0 100644 --- a/nx/source/runtime/devices/romfs_dev.c +++ b/nx/source/runtime/devices/romfs_dev.c @@ -342,6 +342,16 @@ Result romfsMountFromCurrentProcess(const char *name) { return romfsMountFromStorage(storage, 0, name); } +Result romfsMountDataStorageFromProgram(u64 program_id, const char *name) { + FsStorage storage; + + Result rc = fsOpenDataStorageByProgramId(&storage, program_id); + if (R_FAILED(rc)) + return rc; + + return romfsMountFromStorage(storage, 0, name); +} + Result romfsMountFromFsdev(const char *path, u64 offset, const char *name) { FsFileSystem *tmpfs = NULL; diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 2f9f3aac..4709670a 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,16 @@ static Result _fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemTyp ); } +Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + 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 +412,16 @@ Result fsOpenDataStorageByCurrentProcess(FsStorage* out) { return _fsCmdGetSession(&g_fsSrv, &out->s, 200); } +Result fsOpenDataStorageByProgramId(FsStorage *out, u64 program_id) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + 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 +434,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); }