PS2SDK
PS2 Homebrew Libraries
iomanX.h
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #ifndef __IOMANX_H__
17 #define __IOMANX_H__
18 
19 #include <types.h>
20 #ifdef _IOP
21 #include <irx.h>
22 #endif
23 #include <stdarg.h>
24 #include <io_common.h>
25 #include <iox_stat.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 // Rename prototype names in order to avoid clashes with other standard I/O libraries.
32 #ifndef IOMANX_OLD_NAME_COMPATIBILITY
33 #ifdef _IOP
34 #define IOMANX_OLD_NAME_COMPATIBILITY 1
35 #else
36 #define IOMANX_OLD_NAME_COMPATIBILITY 0
37 #endif /* _IOP */
38 #endif /* IOMANX_OLD_NAME_COMPATIBILITY */
39 
40 // Avoid renaming AddDrv and DelDrv to handle the case where the old ioman AddDrv/DelDrv is linked against.
41 #ifndef IOMANX_OLD_NAME_ADDDELDRV
42 #ifdef _IOP
43 #define IOMANX_OLD_NAME_ADDDELDRV 1
44 #else
45 #define IOMANX_OLD_NAME_ADDDELDRV 0
46 #endif /* _IOP */
47 #endif /* IOMANX_OLD_NAME_ADDDELDRV */
48 
49 #if IOMANX_OLD_NAME_COMPATIBILITY
50 #if IOMANX_OLD_NAME_ADDDELDRV
51 #define iomanX_AddDrv AddDrv
52 #define iomanX_DelDrv DelDrv
53 #endif
54 #endif
55 
56 /* Device drivers. */
57 
58 /* Device types. */
59 #define IOP_DT_CHAR 0x01
60 #define IOP_DT_CONS 0x02
61 #define IOP_DT_BLOCK 0x04
62 #define IOP_DT_RAW 0x08
63 #define IOP_DT_FS 0x10
64 #ifndef IOMAN_NO_EXTENDED
65 
66 #define IOP_DT_FSEXT 0x10000000
67 #endif
68 
70 typedef struct _iomanX_iop_file {
72  int mode;
74  int unit;
78  void *privdata;
80 
81 typedef struct _iomanX_iop_device {
82  const char *name;
83  unsigned int type;
85  unsigned int version;
86  const char *desc;
87  struct _iomanX_iop_device_ops *ops;
89 #define IOMANX_RETURN_VALUE_IMPL(val) \
90  static inline int my_iomanx_retval_##val##_int(void) {return -val;} \
91  static inline signed long long my_iomanx_retval_##val##_s64(void) {return -val;}
92 #define IOMANX_RETURN_VALUE(val) ((void*)&my_iomanx_retval_##val##_int)
93 #define IOMANX_RETURN_VALUE_S64(val) ((void*)&my_iomanx_retval_##val##_s64)
94 
95 typedef struct _iomanX_iop_device_ops {
96  int (*init)(iomanX_iop_device_t *device);
97  int (*deinit)(iomanX_iop_device_t *device);
98  int (*format)(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void *arg, int arglen);
99  int (*open)(iomanX_iop_file_t *f, const char *name, int flags, int mode);
100  int (*close)(iomanX_iop_file_t *f);
101  int (*read)(iomanX_iop_file_t *f, void *ptr, int size);
102  int (*write)(iomanX_iop_file_t *f, void *ptr, int size);
103  int (*lseek)(iomanX_iop_file_t *f, int offset, int mode);
104  int (*ioctl)(iomanX_iop_file_t *f, int cmd, void *param);
105  int (*remove)(iomanX_iop_file_t *f, const char *name);
106  int (*mkdir)(iomanX_iop_file_t *f, const char *path, int mode);
107  int (*rmdir)(iomanX_iop_file_t *f, const char *path);
108  int (*dopen)(iomanX_iop_file_t *f, const char *path);
109  int (*dclose)(iomanX_iop_file_t *f);
110  int (*dread)(iomanX_iop_file_t *f, iox_dirent_t *buf);
111  int (*getstat)(iomanX_iop_file_t *f, const char *name, iox_stat_t *stat_);
112  int (*chstat)(iomanX_iop_file_t *f, const char *name, iox_stat_t *stat_, unsigned int statmask);
113 
114 #ifndef IOMAN_NO_EXTENDED
115  /* Extended ops start here. */
116  int (*rename)(iomanX_iop_file_t *f, const char *old, const char *new_);
117  int (*chdir)(iomanX_iop_file_t *f, const char *name);
118  int (*sync)(iomanX_iop_file_t *f, const char *dev, int flag);
119  int (*mount)(iomanX_iop_file_t *f, const char *fsname, const char *devname, int flag, void *arg, int arglen);
120  int (*umount)(iomanX_iop_file_t *f, const char *fsname);
121  s64 (*lseek64)(iomanX_iop_file_t *f, s64 offset, int whence);
122  int (*devctl)(iomanX_iop_file_t *f, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
123  int (*symlink)(iomanX_iop_file_t *f, const char *old, const char *new_);
124  int (*readlink)(iomanX_iop_file_t *f, const char *path, char *buf, unsigned int buflen);
125  int (*ioctl2)(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
126 #endif /* IOMAN_NO_EXTENDED */
128 
129 extern iomanX_iop_device_t **iomanX_GetDeviceList(void);
130 
131 extern int iomanX_open(const char *name, int flags, ...);
132 extern int iomanX_close(int fd);
133 extern int iomanX_read(int fd, void *ptr, int size);
134 extern int iomanX_write(int fd, void *ptr, int size);
135 extern int iomanX_lseek(int fd, int offset, int mode);
136 
137 extern int iomanX_ioctl(int fd, int cmd, void *param);
138 extern int iomanX_remove(const char *name);
139 
140 extern int iomanX_mkdir(const char *path, int mode);
141 extern int iomanX_rmdir(const char *path);
142 extern int iomanX_dopen(const char *path);
143 extern int iomanX_dclose(int fd);
144 extern int iomanX_dread(int fd, iox_dirent_t *buf);
145 
146 extern int iomanX_getstat(const char *name, iox_stat_t *stat);
147 extern int iomanX_chstat(const char *name, iox_stat_t *stat, unsigned int statmask);
148 
150 extern int iomanX_format(const char *dev, const char *blockdev, void *arg, int arglen);
151 
152 #ifndef IOMAN_NO_EXTENDED
153 /* The newer calls - these are NOT supported by the older IOMAN. */
154 extern int iomanX_rename(const char *old, const char *new_);
155 extern int iomanX_chdir(const char *name);
156 extern int iomanX_sync(const char *dev, int flag);
157 extern int iomanX_mount(const char *fsname, const char *devname, int flag, void *arg, int arglen);
158 extern int iomanX_umount(const char *fsname);
159 extern s64 iomanX_lseek64(int fd, s64 offset, int whence);
160 extern int iomanX_devctl(const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
161 extern int iomanX_symlink(const char *old, const char *new_);
162 extern int iomanX_readlink(const char *path, char *buf, unsigned int buflen);
163 extern int iomanX_ioctl2(int fd, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
164 #endif /* IOMAN_NO_EXTENDED */
165 
166 extern int iomanX_AddDrv(iomanX_iop_device_t *device);
167 extern int iomanX_DelDrv(const char *name);
168 
169 extern unsigned int iomanX_GetDevType(int fd);
170 extern void iomanX_StdioInit(int mode);
171 
172 #ifdef _IOP
173 #define iomanX_IMPORTS_start DECLARE_IMPORT_TABLE(iomanx, 1, 1)
174 #define iomanX_IMPORTS_end END_IMPORT_TABLE
175 
176 #define I_iomanX_GetDeviceList DECLARE_IMPORT(3, iomanX_GetDeviceList)
177 #define I_iomanX_open DECLARE_IMPORT(4, iomanX_open)
178 #define I_iomanX_close DECLARE_IMPORT(5, iomanX_close)
179 #define I_iomanX_read DECLARE_IMPORT(6, iomanX_read)
180 #define I_iomanX_write DECLARE_IMPORT(7, iomanX_write)
181 #define I_iomanX_lseek DECLARE_IMPORT(8, iomanX_lseek)
182 #define I_iomanX_ioctl DECLARE_IMPORT(9, iomanX_ioctl)
183 #define I_iomanX_remove DECLARE_IMPORT(10, iomanX_remove)
184 #define I_iomanX_mkdir DECLARE_IMPORT(11, iomanX_mkdir)
185 #define I_iomanX_rmdir DECLARE_IMPORT(12, iomanX_rmdir)
186 #define I_iomanX_dopen DECLARE_IMPORT(13, iomanX_dopen)
187 #define I_iomanX_dclose DECLARE_IMPORT(14, iomanX_dclose)
188 #define I_iomanX_dread DECLARE_IMPORT(15, iomanX_dread)
189 #define I_iomanX_getstat DECLARE_IMPORT(16, iomanX_getstat)
190 #define I_iomanX_chstat DECLARE_IMPORT(17, iomanX_chstat)
191 #define I_iomanX_format DECLARE_IMPORT(18, iomanX_format)
192 #define I_iomanX_rename DECLARE_IMPORT(25, iomanX_rename)
193 #define I_iomanX_chdir DECLARE_IMPORT(26, iomanX_chdir)
194 #define I_iomanX_sync DECLARE_IMPORT(27, iomanX_sync)
195 #define I_iomanX_mount DECLARE_IMPORT(28, iomanX_mount)
196 #define I_iomanX_umount DECLARE_IMPORT(29, iomanX_umount)
197 #define I_iomanX_lseek64 DECLARE_IMPORT(30, iomanX_lseek64)
198 #define I_iomanX_devctl DECLARE_IMPORT(31, iomanX_devctl)
199 #define I_iomanX_symlink DECLARE_IMPORT(32, iomanX_symlink)
200 #define I_iomanX_readlink DECLARE_IMPORT(33, iomanX_readlink)
201 #define I_iomanX_ioctl2 DECLARE_IMPORT(34, iomanX_ioctl2)
202 #if IOMANX_OLD_NAME_ADDDELDRV
203 #define I_AddDrv DECLARE_IMPORT(20, AddDrv)
204 #define I_DelDrv DECLARE_IMPORT(21, DelDrv)
205 #else
206 #define I_iomanX_AddDrv DECLARE_IMPORT(20, iomanX_AddDrv)
207 #define I_iomanX_DelDrv DECLARE_IMPORT(21, iomanX_DelDrv)
208 #endif
209 #define I_iomanX_GetDevType DECLARE_IMPORT(22, iomanX_GetDevType)
210 #define I_iomanX_StdioInit DECLARE_IMPORT(23, iomanX_StdioInit)
211 #endif
212 
213 #if IOMANX_OLD_NAME_COMPATIBILITY
214 
218 
219 static inline iop_device_t **GetDeviceList(void)
220 {
221  return iomanX_GetDeviceList();
222 }
223 
224 static inline int open(const char *name, int flags, ...)
225 {
226  va_list alist;
227  int mode;
228 
229  va_start(alist, flags);
230  mode = va_arg(alist, int);
231  va_end(alist);
232 
233  return iomanX_open(name, flags, mode);
234 }
235 static inline int close(int fd)
236 {
237  return iomanX_close(fd);
238 }
239 static inline int read(int fd, void *ptr, int size)
240 {
241  return iomanX_read(fd, ptr, size);
242 }
243 static inline int write(int fd, void *ptr, int size)
244 {
245  return iomanX_write(fd, ptr, size);
246 }
247 static inline int lseek(int fd, int offset, int mode)
248 {
249  return iomanX_lseek(fd, offset, mode);
250 }
251 
252 static inline int ioctl(int fd, int cmd, void *param)
253 {
254  return iomanX_ioctl(fd, cmd, param);
255 }
256 static inline int remove(const char *name)
257 {
258  return iomanX_remove(name);
259 }
260 
261 static inline int mkdir(const char *path, int mode)
262 {
263  return iomanX_mkdir(path, mode);
264 }
265 static inline int rmdir(const char *path)
266 {
267  return iomanX_rmdir(path);
268 }
269 static inline int dopen(const char *path)
270 {
271  return iomanX_dopen(path);
272 }
273 static inline int dclose(int fd)
274 {
275  return iomanX_dclose(fd);
276 }
277 static inline int dread(int fd, iox_dirent_t *buf)
278 {
279  return iomanX_dread(fd, buf);
280 }
281 
282 static inline int getstat(const char *name, iox_stat_t *stat)
283 {
284  return iomanX_getstat(name, stat);
285 }
286 static inline int chstat(const char *name, iox_stat_t *stat, unsigned int statmask)
287 {
288  return iomanX_chstat(name, stat, statmask);
289 }
290 
292 static inline int format(const char *dev, const char *blockdev, void *arg, int arglen)
293 {
294  return iomanX_format(dev, blockdev, arg, arglen);
295 }
296 
297 #ifndef IOMAN_NO_EXTENDED
298 /* The newer calls - these are NOT supported by the older IOMAN. */
299 static inline int rename(const char *old, const char *new_)
300 {
301  return iomanX_rename(old, new_);
302 }
303 static inline int chdir(const char *name)
304 {
305  return iomanX_chdir(name);
306 }
307 static inline int sync(const char *dev, int flag)
308 {
309  return iomanX_sync(dev, flag);
310 }
311 static inline int mount(const char *fsname, const char *devname, int flag, void *arg, int arglen)
312 {
313  return iomanX_mount(fsname, devname, flag, arg, arglen);
314 }
315 static inline int umount(const char *fsname)
316 {
317  return iomanX_umount(fsname);
318 }
319 static inline s64 lseek64(int fd, s64 offset, int whence)
320 {
321  return iomanX_lseek64(fd, offset, whence);
322 }
323 static inline int devctl(const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
324 {
325  return iomanX_devctl(name, cmd, arg, arglen, buf, buflen);
326 }
327 static inline int symlink(const char *old, const char *new_)
328 {
329  return iomanX_symlink(old, new_);
330 }
331 static inline int readlink(const char *path, char *buf, unsigned int buflen)
332 {
333  return iomanX_readlink(path, buf, buflen);
334 }
335 static inline int ioctl2(int fd, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
336 {
337  return iomanX_ioctl2(fd, cmd, arg, arglen, buf, buflen);
338 }
339 #endif /* IOMAN_NO_EXTENDED */
340 
341 #if !IOMANX_OLD_NAME_ADDDELDRV
342 static inline int AddDrv(iop_device_t *device)
343 {
344  return iomanX_AddDrv(device);
345 }
346 static inline int DelDrv(const char *name)
347 {
348  return iomanX_DelDrv(name);
349 }
350 #endif
351 
352 static inline void StdioInit(int mode)
353 {
354  return iomanX_StdioInit(mode);
355 }
356 
357 #ifdef _IOP
358 #define I_GetDeviceList I_iomanX_GetDeviceList
359 #define I_open I_iomanX_open
360 #define I_close I_iomanX_close
361 #define I_read I_iomanX_read
362 #define I_write I_iomanX_write
363 #define I_lseek I_iomanX_lseek
364 #define I_ioctl I_iomanX_ioctl
365 #define I_remove I_iomanX_remove
366 #define I_mkdir I_iomanX_mkdir
367 #define I_rmdir I_iomanX_rmdir
368 #define I_dopen I_iomanX_dopen
369 #define I_dclose I_iomanX_dclose
370 #define I_dread I_iomanX_dread
371 #define I_getstat I_iomanX_getstat
372 #define I_chstat I_iomanX_chstat
373 #define I_format I_iomanX_format
374 #define I_rename I_iomanX_rename
375 #define I_chdir I_iomanX_chdir
376 #define I_sync I_iomanX_sync
377 #define I_mount I_iomanX_mount
378 #define I_umount I_iomanX_umount
379 #define I_lseek64 I_iomanX_lseek64
380 #define I_devctl I_iomanX_devctl
381 #define I_symlink I_iomanX_symlink
382 #define I_readlink I_iomanX_readlink
383 #define I_ioctl2 I_iomanX_ioctl2
384 #if !IOMANX_OLD_NAME_ADDDELDRV
385 #define I_AddDrv I_iomanX_AddDrv
386 #define I_DelDrv I_iomanX_DelDrv
387 #endif
388 #define I_StdioInit I_iomanX_StdioInit
389 #endif
390 
391 #endif /* IOMANX_OLD_NAME_COMPATIBILITY */
392 
393 #ifdef __cplusplus
394 }
395 #endif
396 
397 #endif /* __IOMANX_H__ */
io_common.h
_iomanX_iop_file::unit
int unit
Definition: iomanX.h:74
_iomanX_iop_file::device
struct _iomanX_iop_device * device
Definition: iomanX.h:76
iox_stat_t
Definition: iox_stat.h:92
_iomanX_iop_file
Definition: iomanX.h:70
_iomanX_iop_file::mode
int mode
Definition: iomanX.h:72
irx.h
_iomanX_iop_file::privdata
void * privdata
Definition: iomanX.h:78
_iomanX_iop_device_ops
Definition: iomanX.h:95
_iomanX_iop_device
Definition: iomanX.h:81
iox_dirent_t
Definition: iox_stat.h:111
_iop_device_ops
Definition: ioman.h:79
iomanX_format
int iomanX_format(const char *dev, const char *blockdev, void *arg, int arglen)
Definition: iomanX.c:708
_iop_device
Definition: ioman.h:64
iop_file_t
struct _iop_file iop_file_t
iox_stat.h
iomanX_iop_file_t
struct _iomanX_iop_file iomanX_iop_file_t
_iomanX_iop_device::version
unsigned int version
Definition: iomanX.h:85