From 7d36668d213efe1cdb46717dede0747b45d7ec8c Mon Sep 17 00:00:00 2001 From: tesnos Date: Mon, 9 Jul 2018 20:18:54 -0400 Subject: [PATCH] add fsOpenBisStorage and fsStorageGetSize --- nx/include/switch/services/fs.h | 2 + nx/source/services/fs.c | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 811edf7d..5352fc44 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -144,6 +144,7 @@ void fsExit(void); Service* fsGetServiceSession(void); +Result fsOpenBisStorage(FsStorage* out, u32 PartitionId); /// Do not call this directly, see fs_dev.h. Result fsMountSdcard(FsFileSystem* out); @@ -196,6 +197,7 @@ void fsDirClose(FsDir* d); // IStorage Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len); +Result fsStorageGetSize(FsStorage* f, u64* out); void fsStorageClose(FsStorage* s); // ISaveDataInfoReader diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index c40ad660..f795546f 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -64,6 +64,43 @@ Service* fsGetServiceSession(void) { return &g_fsSrv; } +Result fsOpenBisStorage(FsStorage* out, u32 PartitionId) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u32 PartitionId; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 12; + raw->PartitionId = PartitionId; + + 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 fsMountSdcard(FsFileSystem* out) { IpcCommand c; ipcInitialize(&c); @@ -1106,6 +1143,39 @@ Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len) { return rc; } +Result fsStorageGetSize(FsStorage* f, u64* out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 4; + + Result rc = serviceIpcDispatch(&f->s); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u64 size; + } *resp = r.Raw; + + rc = resp->result; + if (R_SUCCEEDED(rc) && out) *out = resp->size; + } + + return rc; +} + void fsStorageClose(FsStorage* s) { serviceClose(&s->s); }