2018-09-07 15:00:13 +00:00
|
|
|
/*
|
2019-04-08 02:00:49 +00:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2018-09-07 15:00:13 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-06-20 20:00:32 +00:00
|
|
|
|
2018-06-10 17:11:05 +00:00
|
|
|
#include <switch.h>
|
2019-03-28 17:51:51 +00:00
|
|
|
#include <string.h>
|
2018-06-10 17:11:05 +00:00
|
|
|
#include "fs_shim.h"
|
|
|
|
|
|
|
|
/* Missing fsp-srv commands. */
|
2019-06-03 19:15:39 +00:00
|
|
|
Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisStorageId PartitionId) {
|
2018-11-15 02:39:48 +00:00
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
u32 PartitionId;
|
|
|
|
} *raw;
|
|
|
|
|
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 12;
|
|
|
|
raw->PartitionId = PartitionId;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
} *resp;
|
|
|
|
|
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-06-14 23:50:01 +00:00
|
|
|
Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out) {
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
} *raw;
|
|
|
|
|
2018-10-16 20:33:45 +00:00
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
2018-06-14 23:50:01 +00:00
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 200;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
2018-10-16 20:33:45 +00:00
|
|
|
} *resp;
|
2019-06-20 20:00:32 +00:00
|
|
|
|
2018-10-16 20:33:45 +00:00
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
2018-06-14 23:50:01 +00:00
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
2018-10-16 20:33:45 +00:00
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-10-16 20:33:45 +00:00
|
|
|
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorageId storage_id, u64 data_id, FsStorage* out) {
|
2018-06-10 17:11:05 +00:00
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
FsStorageId storage_id;
|
|
|
|
u64 data_id;
|
|
|
|
} *raw;
|
|
|
|
|
2018-10-16 20:33:45 +00:00
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
2018-06-10 17:11:05 +00:00
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 202;
|
|
|
|
raw->storage_id = storage_id;
|
|
|
|
raw->data_id = data_id;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
2018-10-16 20:33:45 +00:00
|
|
|
} *resp;
|
2019-06-20 20:00:32 +00:00
|
|
|
|
2018-10-16 20:33:45 +00:00
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
2018-06-10 17:11:05 +00:00
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
2018-10-16 20:33:45 +00:00
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
2018-06-12 22:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:53:30 +00:00
|
|
|
Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType) {
|
|
|
|
if (hosversionBefore(2, 0, 0)) {
|
|
|
|
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
u32 fsType;
|
|
|
|
u64 titleId;
|
|
|
|
} *raw;
|
|
|
|
|
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 7;
|
|
|
|
raw->fsType = fsType;
|
|
|
|
raw->titleId = titleId;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
} *resp;
|
|
|
|
|
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath) {
|
|
|
|
if (hosversionBefore(2, 0, 0)) {
|
|
|
|
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
|
|
|
}
|
|
|
|
|
|
|
|
char sendStr[FS_MAX_PATH] = {0};
|
|
|
|
strncpy(sendStr, contentPath, sizeof(sendStr)-1);
|
|
|
|
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
ipcAddSendStatic(&c, sendStr, sizeof(sendStr), 0);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
u32 fsType;
|
|
|
|
u64 titleId;
|
|
|
|
} *raw;
|
|
|
|
|
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 8;
|
|
|
|
raw->fsType = fsType;
|
|
|
|
raw->titleId = titleId;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
2019-04-05 20:36:38 +00:00
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
} *resp;
|
|
|
|
|
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result fsOpenSaveDataFileSystemFwd(Service *s, FsFileSystem* out, u8 inval, FsSave *save) {
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
u64 inval;//Actually u8.
|
|
|
|
FsSave save;
|
|
|
|
} PACKED *raw;
|
|
|
|
|
|
|
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 51;
|
|
|
|
raw->inval = (u64)inval;
|
|
|
|
memcpy(&raw->save, save, sizeof(FsSave));
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(s);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
2019-03-26 18:53:30 +00:00
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
} *resp;
|
|
|
|
|
|
|
|
serviceIpcParse(s, &r, sizeof(*resp));
|
|
|
|
resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|