diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 56e1ac22..811edf7d 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -40,6 +40,14 @@ typedef struct { Service s; } FsSaveDataIterator; +typedef struct { + Service s; +} FsEventNotifier; + +typedef struct { + Service s; +} FsDeviceOperator; + /// Directory entry. typedef struct { @@ -143,6 +151,8 @@ Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save); Result fsMountSystemSaveData(FsFileSystem* out, u8 inval, FsSave *save); Result fsOpenSaveDataIterator(FsSaveDataIterator* out, s32 SaveDataSpaceId); Result fsOpenDataStorageByCurrentProcess(FsStorage* out); +Result fsOpenDeviceOperator(FsDeviceOperator* out); +Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); // todo: Rest of commands here /// 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. Result fsSaveDataIteratorRead(FsSaveDataIterator *s, FsSaveDataInfo* buf, size_t max_entries, size_t* total_entries); 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); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 85fcb5be..e9485c8c 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -262,6 +262,76 @@ Result fsOpenDataStorageByCurrentProcess(FsStorage* out) { 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. Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID) { FsSave save; @@ -1082,3 +1152,83 @@ void fsSaveDataIteratorClose(FsSaveDataIterator* 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); +}