mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +02:00
Add FS commands for SD card state change detection.
This commit is contained in:
parent
17bb2c1432
commit
6f248b9b9e
@ -40,6 +40,14 @@ typedef struct {
|
|||||||
Service s;
|
Service s;
|
||||||
} FsSaveDataIterator;
|
} FsSaveDataIterator;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Service s;
|
||||||
|
} FsEventNotifier;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Service s;
|
||||||
|
} FsDeviceOperator;
|
||||||
|
|
||||||
/// Directory entry.
|
/// Directory entry.
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -143,6 +151,8 @@ Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save);
|
|||||||
Result fsMountSystemSaveData(FsFileSystem* out, u8 inval, FsSave *save);
|
Result fsMountSystemSaveData(FsFileSystem* out, u8 inval, FsSave *save);
|
||||||
Result fsOpenSaveDataIterator(FsSaveDataIterator* out, s32 SaveDataSpaceId);
|
Result fsOpenSaveDataIterator(FsSaveDataIterator* out, s32 SaveDataSpaceId);
|
||||||
Result fsOpenDataStorageByCurrentProcess(FsStorage* out);
|
Result fsOpenDataStorageByCurrentProcess(FsStorage* out);
|
||||||
|
Result fsOpenDeviceOperator(FsDeviceOperator* out);
|
||||||
|
Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out);
|
||||||
// todo: Rest of commands here
|
// todo: Rest of commands here
|
||||||
|
|
||||||
/// FsFileSystem can be mounted with fs_dev for use with stdio, see fs_dev.h.
|
/// FsFileSystem can be mounted with fs_dev for use with stdio, see fs_dev.h.
|
||||||
@ -193,3 +203,11 @@ void fsStorageClose(FsStorage* s);
|
|||||||
/// Read FsSaveDataInfo data into the buf array.
|
/// Read FsSaveDataInfo data into the buf array.
|
||||||
Result fsSaveDataIteratorRead(FsSaveDataIterator *s, FsSaveDataInfo* buf, size_t max_entries, size_t* total_entries);
|
Result fsSaveDataIteratorRead(FsSaveDataIterator *s, FsSaveDataInfo* buf, size_t max_entries, size_t* total_entries);
|
||||||
void fsSaveDataIteratorClose(FsSaveDataIterator *s);
|
void fsSaveDataIteratorClose(FsSaveDataIterator *s);
|
||||||
|
|
||||||
|
// IEventNotifier
|
||||||
|
Result fsEventNotifierGetEventHandle(FsEventNotifier* e, Handle* out);
|
||||||
|
void fsEventNotifierClose(FsEventNotifier* e);
|
||||||
|
|
||||||
|
// IDeviceOperator
|
||||||
|
Result fsDeviceOperatorIsSdCardInserted(FsDeviceOperator* d, bool* out);
|
||||||
|
void fsDeviceOperatorClose(FsDeviceOperator* d);
|
||||||
|
@ -262,6 +262,76 @@ Result fsOpenDataStorageByCurrentProcess(FsStorage* out) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result fsOpenDeviceOperator(FsDeviceOperator* out) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 400;
|
||||||
|
|
||||||
|
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 fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 500;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// Wrapper(s) for fsMountSaveData.
|
// Wrapper(s) for fsMountSaveData.
|
||||||
Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID) {
|
Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID) {
|
||||||
FsSave save;
|
FsSave save;
|
||||||
@ -1082,3 +1152,83 @@ void fsSaveDataIteratorClose(FsSaveDataIterator* s) {
|
|||||||
serviceClose(&s->s);
|
serviceClose(&s->s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IEventNotifier
|
||||||
|
Result fsEventNotifierGetEventHandle(FsEventNotifier* e, Handle* out) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 0;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&e->s);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*out = r.Handles[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsEventNotifierClose(FsEventNotifier* e) {
|
||||||
|
serviceClose(&e->s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDeviceOperator
|
||||||
|
Result fsDeviceOperatorIsSdCardInserted(FsDeviceOperator* d, bool* out) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 0;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&d->s);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
ipcParse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
u8 is_inserted;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*out = resp->is_inserted != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsDeviceOperatorClose(FsDeviceOperator* d) {
|
||||||
|
serviceClose(&d->s);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user