diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 859dfdc9..0ff39bf5 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -199,6 +199,9 @@ void fsDirClose(FsDir* d); // IStorage Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len); +Result fsStorageWrite(FsStorage* s, u64 off, const void* buf, size_t len); +Result fsStorageFlush(FsStorage* s); +Result fsStorageSetSize(FsStorage* s, u64 sz); Result fsStorageGetSize(FsStorage* s, u64* out); void fsStorageClose(FsStorage* s); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 8acb4ae1..af84dfe6 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -1175,6 +1175,106 @@ Result fsStorageRead(FsStorage* s, u64 off, void* buf, size_t len) { return rc; } +Result fsStorageWrite(FsStorage* s, u64 off, const void* buf, size_t len) { + IpcCommand c; + ipcInitialize(&c); + ipcAddSendBuffer(&c, buf, len, 1); + + struct { + u64 magic; + u64 cmd_id; + u64 offset; + u64 write_size; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1; + raw->offset = off; + raw->write_size = len; + + Result rc = serviceIpcDispatch(&s->s); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result fsStorageFlush(FsStorage* s) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 2; + + Result rc = serviceIpcDispatch(&s->s); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result fsStorageSetSize(FsStorage* s, u64 sz) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 size; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 3; + raw->size = sz; + + Result rc = serviceIpcDispatch(&s->s); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result fsStorageGetSize(FsStorage* s, u64* out) { IpcCommand c; ipcInitialize(&c);