From aa0a8e8c6cec9c928b2f9a860325799d342621ce Mon Sep 17 00:00:00 2001 From: Rajko Stojadinovic Date: Sat, 28 Jul 2018 00:24:52 +0200 Subject: [PATCH] Add fsOpenFileSystem and fsOpenFileSystemWithId --- nx/include/switch/services/fs.h | 14 ++++++ nx/source/services/fs.c | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 0ff39bf5..6911de27 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -167,6 +167,20 @@ Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID); /// WARNING: You can brick when writing to SystemSaveData, if the data is corrupted etc. Result fsMount_SystemSaveData(FsFileSystem* out, u64 saveID); +typedef enum +{ + FsFileSystemType_Logo = 2, + FsFileSystemType_ContentControl = 3, + FsFileSystemType_ContentManual = 4, + FsFileSystemType_ContentMeta = 5, + FsFileSystemType_ContentData = 6, + FsFileSystemType_ApplicationPackage = 7 +} FsFileSystemType; + +/// Mount requested filesystem type from content file +Result fsOpenFileSystem(FsFileSystem* out, u64 titleId, FsFileSystemType fsType); /// only on 1.0.0, only works with registered content +Result fsOpenFileSystemWithId(FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath); /// 2.0.0+, contentPath must be resolved manually + // IFileSystem Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags); Result fsFsDeleteFile(FsFileSystem* fs, const char* path); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index af84dfe6..67bea830 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -391,6 +391,85 @@ Result fsMount_SystemSaveData(FsFileSystem* out, u64 saveID) { return fsMountSystemSaveData(out, FsSaveDataSpaceId_NandSystem, &save); } +Result fsOpenFileSystem(FsFileSystem* out, u64 titleId, FsFileSystemType fsType) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u32 fsType; + u64 titleId; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + raw->fsType = fsType; + raw->titleId = titleId; + + Result rc = serviceIpcDispatch(&g_fsSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + serviceCreate(&out->s, r.Handles[0]); + } + } + + return rc; +} + +Result fsOpenFileSystemWithId(FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath) { + IpcCommand c; + ipcInitialize(&c); + ipcAddSendStatic(&c, contentPath, strlen(contentPath)+1, 0); + + struct { + u64 magic; + u64 cmd_id; + u32 fsType; + u64 titleId; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 8; + raw->fsType = fsType; + raw->titleId = titleId; + + Result rc = serviceIpcDispatch(&g_fsSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + serviceCreate(&out->s, r.Handles[0]); + } + } + + return rc; +} + // IFileSystem impl Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags) { IpcCommand c;