-
Notifications
You must be signed in to change notification settings - Fork 224
/
usb.c
215 lines (163 loc) · 5.2 KB
/
usb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
VitaShell
Copyright (C) 2015-2018, TheFloW
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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/>.
*/
#include "main.h"
#include "usb.h"
#include "file.h"
#include "utils.h"
int mountGamecardUx0() {
// Destroy other apps
sceAppMgrDestroyOtherApp();
// Copy VitaShell
copyPath("ux0:app/VITASHELL", "ur0:temp/app", NULL);
copyPath("ux0:appmeta/VITASHELL", "ur0:temp/appmeta", NULL);
copyPath("ux0:license/app/VITASHELL", "ur0:temp/license", NULL);
// Redirect ux0: to gamecard
shellUserRedirectUx0("sdstor0:gcd-lp-ign-entire", "sdstor0:gcd-lp-ign-entire");
// Remount Memory Card
remount(0x800);
// Create dirs
sceIoMkdir("ux0:app", 0006);
sceIoMkdir("ux0:appmeta", 0006);
sceIoMkdir("ux0:license", 0006);
sceIoMkdir("ux0:license/app", 0006);
sceIoMkdir("ux0:app/VITASHELL", 0006);
sceIoMkdir("ux0:appmeta/VITASHELL", 0006);
sceIoMkdir("ux0:license/app/VITASHELL", 0006);
// Create important dirs
sceIoMkdir("ux0:data", 0777);
sceIoMkdir("ux0:temp", 0006);
// Remove lastdir.txt file
sceIoRemove("ux0:VitaShell/internal/lastdir.txt");
// Copy VitaShell
copyPath("ur0:temp/app", "ux0:app/VITASHELL", NULL);
copyPath("ur0:temp/appmeta", "ux0:appmeta/VITASHELL", NULL);
copyPath("ur0:temp/license", "ux0:license/app/VITASHELL", NULL);
return 0;
}
int umountGamecardUx0() {
// Destroy other apps
sceAppMgrDestroyOtherApp();
// Restore ux0: patch
if (checkFileExist("sdstor0:xmc-lp-ign-userext"))
shellUserRedirectUx0("sdstor0:xmc-lp-ign-userext", "sdstor0:xmc-lp-ign-userext");
else
shellUserRedirectUx0("sdstor0:int-lp-ign-userext", "sdstor0:int-lp-ign-userext");
// Remount Memory Card
remount(0x800);
return 0;
}
int mountUsbUx0() {
// Destroy other apps
sceAppMgrDestroyOtherApp();
// Create dirs
sceIoMkdir("uma0:app", 0006);
sceIoMkdir("uma0:appmeta", 0006);
sceIoMkdir("uma0:license", 0006);
sceIoMkdir("uma0:license/app", 0006);
sceIoMkdir("uma0:app/VITASHELL", 0006);
sceIoMkdir("uma0:appmeta/VITASHELL", 0006);
sceIoMkdir("uma0:license/app/VITASHELL", 0006);
// Copy VitaShell
copyPath("ux0:app/VITASHELL", "uma0:app/VITASHELL", NULL);
copyPath("ux0:appmeta/VITASHELL", "uma0:appmeta/VITASHELL", NULL);
copyPath("ux0:license/app/VITASHELL", "uma0:license/app/VITASHELL", NULL);
// Create important dirs
sceIoMkdir("uma0:data", 0777);
sceIoMkdir("uma0:temp", 0006);
// Remove lastdir.txt file
sceIoRemove("uma0:VitaShell/internal/lastdir.txt");
// Redirect ux0: to uma0:
shellUserRedirectUx0("sdstor0:uma-pp-act-a", "sdstor0:uma-lp-act-entire");
// Umount uma0:
vshIoUmount(0xF00, 0, 0, 0);
// Remount Memory Card
remount(0x800);
return 0;
}
int umountUsbUx0() {
// Destroy other apps
sceAppMgrDestroyOtherApp();
// Restore ux0: patch
if (checkFileExist("sdstor0:xmc-lp-ign-userext"))
shellUserRedirectUx0("sdstor0:xmc-lp-ign-userext", "sdstor0:xmc-lp-ign-userext");
else
shellUserRedirectUx0("sdstor0:int-lp-ign-userext", "sdstor0:int-lp-ign-userext");
// Remount Memory Card
remount(0x800);
// Remount uma0:
remount(0xF00);
return 0;
}
SceUID startUsb(const char *usbDevicePath, const char *imgFilePath, int type) {
SceUID modid = -1;
int res;
// Destroy other apps
sceAppMgrDestroyOtherApp();
// Load and start usbdevice module
res = taiLoadStartKernelModule(usbDevicePath, 0, NULL, 0);
if (res < 0)
goto ERROR_LOAD_MODULE;
modid = res;
// Stop MTP driver
res = sceMtpIfStopDriver(1);
if (res < 0 && res != 0x8054360C)
goto ERROR_STOP_DRIVER;
// Set device information
res = sceUsbstorVStorSetDeviceInfo("\"PS Vita\" MC", "1.00");
if (res < 0)
goto ERROR_USBSTOR_VSTOR;
// Set image file path
res = sceUsbstorVStorSetImgFilePath(imgFilePath);
if (res < 0)
goto ERROR_USBSTOR_VSTOR;
// Start USB storage
res = sceUsbstorVStorStart(type);
if (res < 0)
goto ERROR_USBSTOR_VSTOR;
return modid;
ERROR_USBSTOR_VSTOR:
sceMtpIfStartDriver(1);
ERROR_STOP_DRIVER:
taiStopUnloadKernelModule(modid, 0, NULL, 0, NULL, NULL);
ERROR_LOAD_MODULE:
return res;
}
int stopUsb(SceUID modid) {
int res;
// Stop USB storage
res = sceUsbstorVStorStop();
if (res < 0)
return res;
// Start MTP driver
res = sceMtpIfStartDriver(1);
if (res < 0)
return res;
// Stop and unload usbdevice module
res = taiStopUnloadKernelModule(modid, 0, NULL, 0, NULL, NULL);
if (res < 0)
return res;
// Remount Memory Card
remount(0x800);
// Remount imc0:
if (checkFolderExist("imc0:"))
remount(0xD00);
// Remount xmc0:
if (checkFolderExist("xmc0:"))
remount(0xE00);
// Remount uma0:
if (checkFolderExist("uma0:"))
remount(0xF00);
return 0;
}