diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 811edf7d..0c6ecd63 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -144,6 +144,8 @@ 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 +198,7 @@ void fsDirClose(FsDir* d); // IStorage Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len); +Result fsStorageGetSize(FsStorage* s, u64* out); void fsStorageClose(FsStorage* s); // ISaveDataInfoReader diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index c40ad660..90bc6574 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* s, 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(&s->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); }