Add nsGetSpace commands (#111)

* Add nsGetSpace commands
This commit is contained in:
Joel 2018-06-05 21:15:52 -05:00 committed by yellows8
parent d3889fb9ed
commit 1abfb02460
2 changed files with 89 additions and 0 deletions

View File

@ -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);

View File

@ -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())