diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index ea040a7f..a67cb802 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -7,6 +7,7 @@ #pragma once #include "../types.h" #include "../nacp.h" +#include "../services/fs.h" typedef struct { NacpStruct nacp; @@ -18,6 +19,20 @@ void nsExit(void); Result nsGetApplicationControlData(u8 flag, u64 titleID, NsApplicationControlData* buffer, size_t size, size_t* actual_size); +/** + * @brief Returns the total storage capacity (used + free) from content manager services. + * @param storage_id Specified FsStorageId. (Must be FsStorageId_SdCard) + * @param size Pointer to output the total storage size to. + */ +Result nsGetTotalSpaceSize(FsStorageId storage_id, u64 *size); + +/** + * @brief Returns the available storage capacity from content manager services. + * @param storage_id Specified FsStorageId. (Must be FsStorageId_SdCard) + * @param size Pointer to output the free storage size to. + */ +Result nsGetFreeSpaceSize(FsStorageId storage_id, u64 *size); + Result nsvmInitialize(void); void nsvmExit(void); diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 1c64f6e6..6efe6677 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -117,6 +117,80 @@ Result nsGetApplicationControlData(u8 flag, u64 titleID, NsApplicationControlDat return rc; } +Result nsGetTotalSpaceSize(FsStorageId storage_id, u64 *size) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 storage_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 47; + raw->storage_id = storage_id; + + Result rc = serviceIpcDispatch(&g_nsAppManSrv); + + 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) && size) *size = resp->size; + } + + return rc; +} + +Result nsGetFreeSpaceSize(FsStorageId storage_id, u64 *size) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 storage_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 48; + raw->storage_id = storage_id; + + Result rc = serviceIpcDispatch(&g_nsAppManSrv); + + 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) && size) *size = resp->size; + } + + return rc; +} + Result nsvmInitialize(void) { if (!kernelAbove300())