uOFW
Reverse engineered PSP kernel 6.60.
Loading...
Searching...
No Matches
iofilemgr_kernel.h
1/* Copyright (C) 2011, 2012 The uOFW team
2 See the file COPYING for copying permission.
3*/
4
5#include "common_header.h"
6
7/* flags */
8#define SCE_FREAD (0x0001) /* readable */
9#define SCE_FWRITE (0x0002) /* writable */
10#define SCE_FNBLOCK (0x0004) /* Reserved: non-blocking reads */
11#define SCE_FDIRO (0x0008) /* internal use for dopen */
12#define SCE_FRLOCK (0x0010) /* Reserved: read locked (non-shared) */
13#define SCE_FWLOCK (0x0020) /* Reserved: write locked (non-shared) */
14#define SCE_FAPPEND (0x0100) /* append on each write */
15#define SCE_FCREAT (0x0200) /* create if nonexistant */
16#define SCE_FTRUNC (0x0400) /* truncate to zero length */
17#define SCE_EXCL (0x0800) /* exclusive create */
18#define SCE_FSCAN (0x1000) /* Reserved: scan type */
19#define SCE_FRCOM (0x2000) /* Reserved: remote command entry */
20#define SCE_FNBUF (0x4000) /* Reserved: no ring buf. and console interrupt */
21#define SCE_FASYNC (0x8000) /* Reserved: asyncronous i/o */
22#define SCE_FFDEXCL (0x01000000) /* exclusive access */
23#define SCE_FPWLOCK (0x02000000) /* power control lock */
24#define SCE_FENCRYPTED (0x04000000)
25#define SCE_FGAMEDATA (0x40000000)
26
27/* flags for sceIoOpen() */
28#define SCE_O_RDONLY (SCE_FREAD) /* readable */
29#define SCE_O_WRONLY (SCE_FWRITE) /* writable */
30#define SCE_O_RDWR (SCE_FREAD|SCE_FWRITE) /* readable & writable */
31#define SCE_O_NBLOCK (SCE_FNBLOCK) /* Reserved: Non-Blocking I/O */
32#define SCE_O_APPEND (SCE_FAPPEND) /* append (writes guaranteed at the end) */
33#define SCE_O_CREAT (SCE_FCREAT) /* open with file create */
34#define SCE_O_TRUNC (SCE_FTRUNC) /* open with truncation */
35#define SCE_O_EXCL (SCE_EXCL) /* exclusive create */
36#define SCE_O_NOBUF (SCE_FNBUF) /* Reserved: no device buffer and console interrupt */
37#define SCE_O_NOWAIT (SCE_FASYNC) /* Reserved: asyncronous i/o */
38#define SCE_O_FDEXCL (SCE_FFDEXCL) /* exclusive access */
39#define SCE_O_PWLOCK (SCE_FPWLOCK) /* power control lock */
40#define SCE_O_ENCRYPTED (SCE_FENCRYPTED) /* encrypted file (uses Kernel/DNAS/NPDRM-encryption) */
41#define SCE_O_FGAMEDATA (SCE_FGAMEDATA)
42
43/* sceIoOpen().mode permission bits */
44#define SCE_STM_RWXU 00700 /* user read/write/execute permission. */
45#define SCE_STM_RUSR 00400 /* user read permission. */
46#define SCE_STM_WUSR 00200 /* user write permission. */
47#define SCE_STM_XUSR 00100 /* user execute permission. */
48
49#define SCE_STM_RWXG 00070 /* group read/write/execute permission. */
50#define SCE_STM_RGRP 00040 /* group read permission. */
51#define SCE_STM_WGRP 00020 /* group write permission. */
52#define SCE_STM_XGRP 00010 /* group execute permission. */
53
54#define SCE_STM_RWXO 00007 /* other read/write/execute permission. */
55#define SCE_STM_ROTH 00004 /* other read permission. */
56#define SCE_STM_WOTH 00002 /* other write permission. */
57#define SCE_STM_XOTH 00001 /* other execute permission. */
58
59#define SCE_STM_RWXUGO (SCE_STM_RWXU|SCE_STM_RWXG|SCE_STM_RWXO) /* user/group/other - read/write/execute. */
60#define SCE_STM_RUGO (SCE_STM_RUSR|SCE_STM_RGRP|SCE_STM_ROTH) /* user/group/other - read. */
61#define SCE_STM_WUGO (SCE_STM_WUSR|SCE_STM_WGRP|SCE_STM_WOTH) /* user/group/other - write. */
62#define SCE_STM_XUGO (SCE_STM_XUSR|SCE_STM_XGRP|SCE_STM_XOTH) /* user/group/other - execute. */
63
64/* flags for sceIoLseek().whence */
65#define SCE_SEEK_SET 0 /* Offset is the distance from the start of the file. */
66#define SCE_SEEK_CUR 1 /* Offset is the relative distance from the current position in the file. */
67#define SCE_SEEK_END 2 /* Offset is the distance from the end of the file. */
68
69typedef struct ScePspDateTime {
70 u16 year;
71 u16 month;
72 u16 day;
73 u16 hour;
74 u16 minute;
75 u16 second;
76 u32 microsecond;
77} ScePspDateTime;
78
79typedef struct SceIoStat
80{
81 SceMode st_mode;
82 u32 st_attr;
83 SceOff st_size;
84 ScePspDateTime st_ctime;
85 ScePspDateTime st_atime;
86 ScePspDateTime st_mtime;
87 u32 st_private[6];
88} SceIoStat;
89
90typedef struct SceIoDirent
91{
92 SceIoStat d_stat;
93 char d_name[256];
94 void *d_private;
95 int dummy;
96} SceIoDirent;
97
98typedef struct SceIoCwd SceIoCwd, *PSceIoCwd;
99typedef struct SceIoDeviceEntry SceIoDeviceEntry, *PSceIoDeviceEntry;
100typedef struct SceIoDeviceFunction SceIoDeviceFunction, *PSceIoDeviceFunction;
101typedef struct SceIoDeviceTable SceIoDeviceTable, *PSceIoDeviceTable;
102typedef struct SceIoIob SceIoIob, *PSceIoIob;
103typedef struct SceIoThreadCwd SceIoThreadCwd, *PSceIoThreadCwd;
104
105typedef int (* df_init_t)(struct SceIoDeviceEntry *);
106typedef int (* df_exit_t)(struct SceIoDeviceEntry *);
107typedef int (* df_close_t)(struct SceIoIob *);
108typedef int (* df_remove_t)(struct SceIoIob *, char *);
109typedef int (* df_rmdir_t)(struct SceIoIob *, char *);
110typedef int (* df_dopen_t)(struct SceIoIob *, char *);
111typedef int (* df_dclose_t)(struct SceIoIob *);
112typedef int (* df_chdir_t)(struct SceIoIob *, char *);
113typedef int (* df_umount_t)(struct SceIoIob *, char *);
114typedef int (* df_cancel_t)(struct SceIoIob *);
115
116struct SceIoDeviceFunction {
117 df_init_t df_init;
118 df_exit_t df_exit;
119 int (* df_open)(struct SceIoIob *, char *, int, SceMode);
120 df_close_t df_close;
121 SceSSize (* df_read)(struct SceIoIob *, void *, SceSize);
122 SceSSize (* df_write)(struct SceIoIob *, const void *, SceSize);
123 SceOff (* df_lseek)(struct SceIoIob *, SceOff, int);
124 int (* df_ioctl)(struct SceIoIob *, int, void *, SceSize, void *, SceSize);
125 df_remove_t df_remove;
126 int (* df_mkdir)(struct SceIoIob *, char *, SceMode);
127 df_rmdir_t df_rmdir;
128 df_dopen_t df_dopen;
129 df_dclose_t df_dclose;
130 int (* df_dread)(struct SceIoIob *, struct SceIoDirent *);
131 int (* df_getstat)(struct SceIoIob *, char *, struct SceIoStat *);
132 int (* df_chstat)(struct SceIoIob *, char *, struct SceIoStat *, u32);
133 int (* df_rename)(struct SceIoIob *, const char *, const char *);
134 df_chdir_t df_chdir;
135 int (* df_mount)(struct SceIoIob *, const char *, const char *, int, void *, int);
136 df_umount_t df_umount;
137 int (* df_devctl)(struct SceIoIob *, char *, int, void *, SceSize, void *, SceSize);
138 df_cancel_t df_cancel;
139};
140
141struct SceIoCwd {
142 struct SceIoCwd * next;
143 char * pathname;
144 struct SceIoDeviceEntry * entry;
145 void * cwd_private;
146 int refcount;
147};
148
149struct SceIoDeviceEntry {
150 struct SceIoDeviceTable * d_dp;
151 void * d_private;
152 int d_userfd_count;
153};
154
155struct SceIoDeviceTable {
156 char * dt_string;
157 int dt_type;
158 int dt_size;
159 char * dt_desc;
160 struct SceIoDeviceFunction * dt_func;
161};
162
163struct SceIoHookType;
164typedef struct SceIoHookType SceIoHookType;
165
166struct SceIoHook;
167typedef struct SceIoHook SceIoHook;
168
169typedef struct
170{
171 void (*Add)(SceIoHookType **hook);
172 int unused4;
173 int (*Preobe)(SceIoHook *hook, char *file, int flags, SceMode mode);
174 int (*Open)(SceIoHook *hook, char *file, int flags, SceMode mode);
175 int (*Close)(SceIoHook *hook);
176 int (*Read)(SceIoHook *hook, void *data, SceSize size);
177 int (*Write)(SceIoHook *hook, const void *data, SceSize size);
178 SceOff (*Lseek)(SceIoHook *hook, SceOff ofs, int whence);
179 int (*Ioctl)(SceIoHook *iob, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
180} SceIoHookFuncs;
181
182struct SceIoHookType
183{
184 char *name;
185 int unk4;
186 int unk8;
187 char *name2;
188 SceIoHookFuncs *funcs;
189};
190
191typedef struct
192{
193 int size; // 0
194 char name[32]; // 4
195 int attribute; // 36
196 int flags; // 40
197 const char *drvName; // 44
198 int fsNum; // 48
199 char *newPath; // 52
200 int retAddr; // 56
201 int curThread; // 60
202 int asyncThread; // 64
203 int isAsync; // 68
204 int asyncCmd; // 72
205 SceIoIob *iob; // 76
206 int fpos; // 80
207 int thread; // 84
208} SceIoFdDebugInfo;
209
210typedef struct
211{
212 SceIoHookType *hook;
213 void *argp;
214} SceIoHookArg;
215
216struct SceIoHook
217{
218 SceIoHookArg *arg;
219 SceIoIob *iob;
220 SceIoDeviceFunction *funcs;
221};
222
223struct SceIoIob
224{
225 int i_flgs; // 0
226 int i_unit; // 4
227 struct SceIoDeviceEntry *i_de; // 8
228 int d_type; // 12
229 void *i_private; // 16
230 struct SceIoCwd *i_cwd; // 20
231 SceOff i_fpos; // 24
232 SceUID i_thread; // 32
233 // note: structure stops here in dwarf data from the official SDK
234 // it might mean the next fields are only supposed to be accessed
235 // by iofilemgr and not fs implementations
236 int unk036; // 36
237 int unk040; // 40
238 SceUID curThread; // 44
239 char userMode; // 48
240 char powerLocked; // 49
241 char unk050;
242 char asyncPrio; // 51
243 SceUID asyncThread; // 52
244 SceUID asyncSema; // 56
245 SceUID asyncEvFlag; // 60
246 SceUID asyncCb; // 64
247 void *asyncCbArgp; // 68
248 int unused72; // 72
249 int k1; // 76
250 s64 asyncRet; // 80
251 int asyncArgs[6]; // 88
252 int asyncCmd; // 112
253 int userLevel; // 116
254 SceIoHook hook; // 120
255 int unk132; // 132
256 char *newPath; // 136
257 int retAddr; // 140
258};
259
260// TODO: unused here but present in official SDK dwarf symbols, maybe relevant in threadman
261struct SceIoThreadCwd {
262 struct SceIoThreadCwd * next;
263 void * tls;
264 struct SceIoCwd * cwd;
265};
266
267int sceIoChangeAsyncPriority(int fd, int prio);
268void sceIoCloseAll();
269int sceIoReopen(const char *file, int flags, SceMode mode, int fd);
270SceUID sceIoDopen(const char *dirname);
271int sceIoDread(int fd, SceIoDirent *dir);
272int sceIoDclose(int fd);
273int sceIoRemove(const char *file);
274int sceIoRename(const char *oldname, const char *newname);
275int sceIoDevctl(const char *dev, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
276
277/* IO-Assign mount mode flags. */
278#define SCE_MT_RDWR 0x00
279#define SCE_MT_RDONLY 0x01
280#define SCE_MT_ROBUST 0x02
281#define SCE_MT_ERRCHECK 0x04
283int sceIoAssign(const char *dev, const char *blockDev, const char *fs, int mode, void* unk1, int unk2);
284int sceIoUnassign(const char *dev);
285int sceIoChangeThreadCwd(SceUID threadId, const char *path);
286int sceIoCancel(int fd);
287int sceIoGetFdList(SceUID *fds, int numFd, int *count);
288int sceIoGetFdDebugInfo(int fd, SceIoFdDebugInfo *outInfo);
289int sceIoAddDrv(SceIoDeviceTable *drv);
290int sceIoDelDrv(const char *drv);
291int sceIoGetUID(int fd);
292int sceIoPollAsync(SceUID fd, SceInt64 *res);
293int sceIoWaitAsync(SceUID fd, SceInt64 *res);
294int sceIoWaitAsyncCB(SceUID fd, SceInt64 *res);
295int sceIoGetAsyncStat(SceUID fd, int poll, SceInt64 *res);
296int sceIoSetAsyncCallback(SceUID fd, SceUID cb, void *argp);
297int sceIoValidateFd(SceUID fd, int arg1);
298int sceIoClose(SceUID fd);
299int sceIoCloseAsync(SceUID fd);
300SceUID sceIoOpen(const char *file, int flags, SceMode mode);
301SceUID sceIoOpenAsync(const char *file, int flags, SceMode mode);
302int sceIoRead(SceUID fd, void *data, SceSize size);
303int sceIoReadAsync(SceUID fd, void *data, SceSize size);
304int sceIoWrite(SceUID fd, const void *data, SceSize size);
305int sceIoWriteAsync(SceUID fd, const void *data, SceSize size);
306SceOff sceIoLseek(SceUID fd, SceOff offset, int whence);
307SceOff sceIoLseekAsync(SceUID fd, SceOff offset, int whence);
308int sceIoLseek32(SceUID fd, int offset, int whence);
309int sceIoLseek32Async(SceUID fd, int offset, int whence);
310
311/* IOCTL */
312
313/* ioctl commands */
314#define SCE_GAMEDATA_SET_SECURE_INSTALL_ID (0x04100001)
315
316int sceIoIoctl(SceUID fd, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
317int sceIoIoctlAsync(SceUID fd, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
318
319/* Directory functions */
320int sceIoMkdir(const char *path, SceMode mode);
321int sceIoRmdir(const char *path);
322int sceIoChdir(const char *path);
323
324
325int sceIoGetstat(const char *file, SceIoStat *stat);
326int sceIoChstat(const char *file, SceIoStat *stat, int bits);
327int sceIoSync(const char *device, unsigned int unk);
328int sceIoGetDevType(SceUID fd);
329int sceIoGetThreadCwd(SceUID uid, char *dir, int len);
330int sceIoTerminateFd(char *drive);
331int sceIoAddHook(SceIoHookType *hook);
332int sceIoGetIobUserLevel(SceIoIob *iob);
333