diff --git a/nx/include/switch/runtime/devices/fs_dev.h b/nx/include/switch/runtime/devices/fs_dev.h index 7aff1308..8b9041c0 100644 --- a/nx/include/switch/runtime/devices/fs_dev.h +++ b/nx/include/switch/runtime/devices/fs_dev.h @@ -30,15 +30,22 @@ NX_CONSTEXPR FsDirectoryEntry* fsdevDirGetEntries(fsdev_dir_t *dir) /// Initializes and mounts the sdmc device if accessible. Result fsdevMountSdmc(void); -/// Mounts the specified save data. +/// Mounts the specified SaveData. Result fsdevMountSaveData(const char *name, u64 application_id, AccountUid uid); +/// Mounts the specified BcatSaveData. +Result fsdevMountBcatSaveData(const char *name, u64 application_id); + /// Mounts the specified DeviceSaveData. Result fsdevMountDeviceSaveData(const char *name, u64 application_id); -/// Mounts the specified system save data. +/// Mounts the specified SystemSaveData. Result fsdevMountSystemSaveData(const char *name, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid); +/// Mounts the specified SystemBcatSaveData. +/// Only available on [4.0.0+]. +Result fsdevMountSystemBcatSaveData(const char *name, u64 system_save_data_id); + /// 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. /// Input device name string shouldn't exceed 31 characters, and shouldn't have a trailing colon. diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 99871a22..49cf1199 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -371,14 +371,21 @@ Result fsCreate_SystemSaveData(FsSaveDataSpaceId save_data_space_id, u64 system_ /// See \ref FsSaveDataAttribute for application_id and uid. Result fsOpen_SaveData(FsFileSystem* out, u64 application_id, AccountUid uid); +/// Wrapper for fsOpenSaveDataFileSystem, for opening BcatSaveData. +Result fsOpen_BcatSaveData(FsFileSystem* out, u64 application_id); + /// Wrapper for fsOpenSaveDataFileSystem, for opening DeviceSaveData. /// See \ref FsSaveDataAttribute for application_id. Result fsOpen_DeviceSaveData(FsFileSystem* out, u64 application_id); -/// Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId. +/// Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemSaveData. /// WARNING: You can brick when writing to SystemSaveData, if the data is corrupted etc. Result fsOpen_SystemSaveData(FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid); +/// Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemBcatSaveData. +/// Only available on [4.0.0+]. +Result fsOpen_SystemBcatSaveData(FsFileSystem* out, u64 system_save_data_id); + // IFileSystem Result fsFsCreateFile(FsFileSystem* fs, const char* path, s64 size, u32 option); Result fsFsDeleteFile(FsFileSystem* fs, const char* path); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index a9ef1bf1..1db2bd6a 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -465,6 +465,19 @@ Result fsdevMountSaveData(const char *name, u64 application_id, AccountUid uid) return rc; } +Result fsdevMountBcatSaveData(const char *name, u64 application_id) +{ + FsFileSystem fs; + Result rc = fsOpen_BcatSaveData(&fs, application_id); + if(R_SUCCEEDED(rc)) + { + int ret = fsdevMountDevice(name, fs); + if(ret==-1) + rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + } + return rc; +} + Result fsdevMountDeviceSaveData(const char *name, u64 application_id) { FsFileSystem fs; @@ -491,6 +504,19 @@ Result fsdevMountSystemSaveData(const char *name, FsSaveDataSpaceId save_data_sp return rc; } +Result fsdevMountSystemBcatSaveData(const char *name, u64 system_save_data_id) +{ + FsFileSystem fs; + Result rc = fsOpen_SystemBcatSaveData(&fs, system_save_data_id); + 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) diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 5adc51e4..5d84a189 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -498,6 +498,16 @@ Result fsOpen_SaveData(FsFileSystem* out, u64 application_id, AccountUid uid) { return _fsOpen_SaveDataFs(out, &attr); } +Result fsOpen_BcatSaveData(FsFileSystem* out, u64 application_id) { + FsSaveDataAttribute attr; + + memset(&attr, 0, sizeof(attr)); + attr.application_id = application_id; + attr.save_data_type = FsSaveDataType_Bcat; + + return _fsOpen_SaveDataFs(out, &attr); +} + Result fsOpen_DeviceSaveData(FsFileSystem* out, u64 application_id) { FsSaveDataAttribute attr; @@ -519,6 +529,19 @@ Result fsOpen_SystemSaveData(FsFileSystem* out, FsSaveDataSpaceId save_data_spac return fsOpenSaveDataFileSystemBySystemSaveDataId(out, save_data_space_id, &attr); } +Result fsOpen_SystemBcatSaveData(FsFileSystem* out, u64 system_save_data_id) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + FsSaveDataAttribute attr; + + memset(&attr, 0, sizeof(attr)); + attr.system_save_data_id = system_save_data_id; + attr.save_data_type = FsSaveDataType_SystemBcat; + + return fsOpenSaveDataFileSystemBySystemSaveDataId(out, FsSaveDataSpaceId_System, &attr); +} + //----------------------------------------------------------------------------- // IFileSystem //-----------------------------------------------------------------------------