From 13fbde91b0d4e74b32855559893701ff9fc169c6 Mon Sep 17 00:00:00 2001 From: fincs Date: Mon, 21 Oct 2019 12:38:18 +0200 Subject: [PATCH] fsdev: Added fsdevMountSaveData/SystemSaveData wrappers --- nx/include/switch/runtime/devices/fs_dev.h | 6 +++++ nx/source/runtime/devices/fs_dev.c | 26 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/nx/include/switch/runtime/devices/fs_dev.h b/nx/include/switch/runtime/devices/fs_dev.h index 0c154a1a..e8ab490f 100644 --- a/nx/include/switch/runtime/devices/fs_dev.h +++ b/nx/include/switch/runtime/devices/fs_dev.h @@ -30,6 +30,12 @@ NX_CONSTEXPR FsDirectoryEntry* fsdevDirGetEntries(fsdev_dir_t *dir) /// Initializes and mounts the sdmc device if accessible. Result fsdevMountSdmc(void); +/// Mounts the specified save data. +Result fsdevMountSaveData(const char *name, u64 titleID, AccountUid *userID); + +/// Mounts the specified system save data. +Result fsdevMountSystemSaveData(const char *name, u64 saveID); + /// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails. /// Returns -1 when any errors occur. int fsdevMountDevice(const char *name, FsFileSystem fs); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index baf89b1f..f72722dd 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -443,6 +443,32 @@ Result fsdevMountSdmc(void) return rc; } +Result fsdevMountSaveData(const char *name, u64 titleID, AccountUid *userID) +{ + FsFileSystem fs; + Result rc = fsOpen_SaveData(&fs, titleID, userID); + if(R_SUCCEEDED(rc)) + { + int ret = fsdevMountDevice(name, fs); + if(ret==-1) + rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + } + return rc; +} + +Result fsdevMountSystemSaveData(const char *name, u64 saveID) +{ + FsFileSystem fs; + Result rc = fsOpen_SystemSaveData(&fs, saveID); + if(R_SUCCEEDED(rc)) + { + int ret = fsdevMountDevice(name, fs); + if(ret==-1) + rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + } + return rc; +} + void __libnx_init_cwd(void) { if(envIsNso() || __system_argc==0 || __system_argv[0] == NULL)