From 629ffed93e97912f41cc9ddeef427e8cb58a9310 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 10 Aug 2019 19:35:50 -0500 Subject: [PATCH] Implement fsOpenCustomStorageFileSystem --- nx/include/switch/services/fs.h | 7 ++++++ nx/source/services/fs.c | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 14155c5a..64aeea52 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -179,6 +179,12 @@ typedef enum FS_CONTENTSTORAGEID_SdCard = 2, } FsContentStorageId; +typedef enum +{ + FsCustomStorageId_NandUser = 0, + FsCustomStorageId_SdCard = 1, +} FsCustomStorageId; + typedef enum { FsSaveDataSpaceId_NandSystem = 0, @@ -280,6 +286,7 @@ Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save); Result fsMountSystemSaveData(FsFileSystem* out, u8 inval, FsSave *save); Result fsOpenSaveDataIterator(FsSaveDataIterator* out, s32 saveDataSpaceId); Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId content_storage_id); +Result fsOpenCustomStorageFileSystem(FsFileSystem* out, FsCustomStorageId custom_storage_id); Result fsOpenDataStorageByCurrentProcess(FsStorage* out); Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, FsStorageId storageId); Result fsOpenDeviceOperator(FsDeviceOperator* out); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 5e4fdbb2..54a0b6e0 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -427,6 +427,47 @@ Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId cont return rc; } +Result fsOpenCustomStorageFileSystem(FsFileSystem* out, FsCustomStorageId custom_storage_id) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u32 custom_storage_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_fsSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 130; + raw->custom_storage_id = custom_storage_id; + + Result rc = serviceIpcDispatch(&g_fsSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_fsSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + serviceCreateSubservice(&out->s, &g_fsSrv, &r, 0); + } + } + + return rc; +} + Result fsOpenDataStorageByCurrentProcess(FsStorage* out) { IpcCommand c; ipcInitialize(&c);