-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfios.c
99 lines (83 loc) · 3.13 KB
/
fios.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
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <vitasdk.h>
#include "games.h"
#include "fios.h"
#define MAX_PATH_LENGTH 256
#define RAMCACHEBLOCKSIZE (128 * 1024)
#define PSARCCACHEBLOCKSIZE (192 * 1024)
#define RAMCACHEBLOCKNUM 512
static int64_t g_OpStorage[SCE_FIOS_OP_STORAGE_SIZE(64, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
static int64_t g_ChunkStorage[SCE_FIOS_CHUNK_STORAGE_SIZE(1024) / sizeof(int64_t) + 1];
static int64_t g_FHStorage[SCE_FIOS_FH_STORAGE_SIZE(1024, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
static int64_t g_DHStorage[SCE_FIOS_DH_STORAGE_SIZE(32, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
static SceFiosRamCacheContext g_RamCacheContext = SCE_FIOS_RAM_CACHE_CONTEXT_INITIALIZER;
static SceFiosPsarcDearchiverContext g_PsarcContext;
static char *g_RamCacheWorkBuffer;
static int32_t g_PsarcHandle;
static SceFiosBuffer g_MountBuffer;
int fios_init(void) {
int res;
SceFiosParams params = SCE_FIOS_PARAMS_INITIALIZER;
params.opStorage.pPtr = g_OpStorage;
params.opStorage.length = sizeof(g_OpStorage);
params.chunkStorage.pPtr = g_ChunkStorage;
params.chunkStorage.length = sizeof(g_ChunkStorage);
params.fhStorage.pPtr = g_FHStorage;
params.fhStorage.length = sizeof(g_FHStorage);
params.dhStorage.pPtr = g_DHStorage;
params.dhStorage.length = sizeof(g_DHStorage);
params.pathMax = MAX_PATH_LENGTH;
params.threadAffinity[SCE_FIOS_IO_THREAD] = 0x20000;
params.threadAffinity[SCE_FIOS_CALLBACK_THREAD] = 0;
params.threadAffinity[SCE_FIOS_DECOMPRESSOR_THREAD] = 0;
params.threadPriority[SCE_FIOS_IO_THREAD] = 64;
params.threadPriority[SCE_FIOS_CALLBACK_THREAD] = 191;
params.threadPriority[SCE_FIOS_DECOMPRESSOR_THREAD] = 191;
res = sceFiosInitialize(¶ms);
if (res < 0) {
#ifdef DEBUG
printf("Failed to init sceFios: 0x%08X\n", res);
#endif
return res;
}
sceClibMemset(&g_PsarcContext, 0, sizeof(SceFiosPsarcDearchiverContext));
g_PsarcContext.size = sizeof(SceFiosPsarcDearchiverContext);
g_PsarcContext.pWorkBuffer = memalign(64, PSARCCACHEBLOCKSIZE);
g_PsarcContext.workBufferSize = PSARCCACHEBLOCKSIZE;
res = sceFiosIOFilterAdd(0, sceFiosIOFilterPsarcDearchiver, &g_PsarcContext);
if (res < 0) {
#ifdef DEBUG
printf("Failed to init sceFios dearchiver: 0x%08X\n", res);
#endif
return res;
}
res = sceFiosArchiveGetMountBufferSizeSync(NULL, VIDEOS_FILE, NULL);
if (res < 0)
return res;
g_MountBuffer.length = res;
g_MountBuffer.pPtr = malloc(res);
res = sceFiosArchiveMountSync(NULL, &g_PsarcHandle, VIDEOS_FILE, "/", g_MountBuffer, NULL);
if (res < 0) {
#ifdef DEBUG
printf("Failed to mount %s: 0x%08X\n", VIDEOS_FILE, res);
#endif
return res;
}
g_RamCacheWorkBuffer = memalign(8, RAMCACHEBLOCKNUM * RAMCACHEBLOCKSIZE);
if (!g_RamCacheWorkBuffer)
return -1;
g_RamCacheContext.pPath = "ux0:data/Late Shift";
g_RamCacheContext.pWorkBuffer = g_RamCacheWorkBuffer;
g_RamCacheContext.workBufferSize = RAMCACHEBLOCKNUM * RAMCACHEBLOCKSIZE;
g_RamCacheContext.blockSize = RAMCACHEBLOCKSIZE;
res = sceFiosIOFilterAdd(1, sceFiosIOFilterCache, &g_RamCacheContext);
if (res < 0)
return res;
return 0;
}
void fios_terminate(void) {
sceFiosTerminate();
free(g_RamCacheWorkBuffer);
}