From 41fc8bb17cff06d5ab05680028ce32a2d1429512 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Tue, 15 Dec 2020 00:20:03 -0400 Subject: [PATCH] fs: Added fsCreateSaveDataFileSystem(), fsDeleteSaveDataFileSystem() and fsDeleteSaveDataFileSystemBySaveDataAttribute(). #518 --- nx/include/switch/services/fs.h | 17 +++++++++++++++++ nx/source/services/fs.c | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index e2e1d38e..6a0b87b6 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -88,6 +88,13 @@ typedef struct { u8 unused[0x190]; ///< Uninitialized. } FsSaveDataExtraData; +/// SaveDataMetaInfo +typedef struct { + u32 size; + u8 type; ///< \ref FsSaveDataMetaType + u8 reserved[0x0B]; +} FsSaveDataMetaInfo; + /// SaveDataCreationInfo typedef struct { s64 save_data_size; ///< Size of the save data. @@ -219,6 +226,13 @@ typedef enum { FsSaveDataFlags_NeedsSecureDelete = BIT(3), } FsSaveDataFlags; +/// SaveDataMetaType +typedef enum { + FsSaveDataMetaType_None = 0, + FsSaveDataMetaType_Thumbnail = 1, + FsSaveDataMetaType_ExtensionContext = 2, +} FsSaveDataMetaType; + typedef enum { FsGameCardAttribute_AutoBootFlag = BIT(0), ///< Causes the cartridge to automatically start on bootup FsGameCardAttribute_HistoryEraseFlag = BIT(1), ///< Causes NS to throw an error on attempt to load the cartridge @@ -323,8 +337,11 @@ Result fsOpenBisStorage(FsStorage* out, FsBisPartitionId partitionId); /// Do not call this directly, see fs_dev.h. Result fsOpenSdCardFileSystem(FsFileSystem* out); +Result fsDeleteSaveDataFileSystem(u64 application_id); +Result fsCreateSaveDataFileSystem(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info, const FsSaveDataMetaInfo* meta); Result fsCreateSaveDataFileSystemBySystemSaveDataId(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info); Result fsDeleteSaveDataFileSystemBySaveDataSpaceId(FsSaveDataSpaceId save_data_space_id, u64 saveID); ///< [2.0.0+] +Result fsDeleteSaveDataFileSystemBySaveDataAttribute(FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute* attr); ///< [4.0.0+] Result fsIsExFatSupported(bool* out); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index d4b6321c..7667e812 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -224,6 +224,20 @@ Result fsOpenSdCardFileSystem(FsFileSystem* out) { return _fsCmdGetSession(&g_fsSrv, &out->s, 18); } +Result fsDeleteSaveDataFileSystem(u64 application_id) { + return _fsObjectDispatchIn(&g_fsSrv, 21, application_id); +} + +Result fsCreateSaveDataFileSystem(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info, const FsSaveDataMetaInfo* meta) { + const struct { + FsSaveDataAttribute attr; + FsSaveDataCreationInfo creation_info; + FsSaveDataMetaInfo meta; + } in = { *attr, *creation_info, *meta }; + + return _fsObjectDispatchIn(&g_fsSrv, 22, in); +} + Result fsCreateSaveDataFileSystemBySystemSaveDataId(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info) { const struct { FsSaveDataAttribute attr; @@ -245,6 +259,18 @@ Result fsDeleteSaveDataFileSystemBySaveDataSpaceId(FsSaveDataSpaceId save_data_s return _fsObjectDispatchIn(&g_fsSrv, 25, in); } +Result fsDeleteSaveDataFileSystemBySaveDataAttribute(FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute* attr) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + const struct { + u8 save_data_space_id; + FsSaveDataAttribute attr; + } in = { (u8)save_data_space_id, *attr }; + + return _fsObjectDispatchIn(&g_fsSrv, 28, in); +} + Result fsIsExFatSupported(bool* out) { if (hosversionBefore(2,0,0)) { *out = false;