PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
fakehost.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
20//#define DEBUG
21
22#include "types.h"
23#include "loadcore.h"
24#include "stdio.h"
25#include "sysclib.h"
26#include <errno.h>
27#include "thbase.h"
28#include "intrman.h"
29#include "sysmem.h"
30#include "sifman.h"
31#include "sifcmd.h"
32
33#include "iomanX.h"
34#include "ioman_mod.h"
35
36#define TRUE 1
37#define FALSE 0
38
41#define MODNAME "fakehost"
42
43// This is the filesystem to replace
44#define FS_REPNAME "host"
45
46IRX_ID(MODNAME, 1, 1);
47
48#define M_PRINTF(format, args...) \
49 printf(MODNAME ": " format, ##args)
50
51#ifdef DEBUG
52#define M_DEBUG M_PRINTF
53#else
54#define M_DEBUG(format, args...)
55#endif
56
57// Host base location
58static char base[100];
59
60static int fd_global;
61
62extern int ttyMount(void);
63extern int naplinkRpcInit(void);
64
75char * fd_name( char * buffer, const char * name )
76{
77 strcpy( buffer, base );
78 strcat( buffer, name );
79 return buffer;
80}
81
89int fd_save( int fd, iop_io_file_t *f )
90{
91 f->unit = ++fd_global;
92 f->privdata = (void *) fd;
93 return f->unit;
94}
95
103{
104 return (int) f->privdata;
105}
106
110int dummy()
111{
112 M_DEBUG("dummy function called\n");
113 return -EIO;
114}
115
123{
124 M_PRINTF( "initializing '%s' file driver.\n", driver->name );
125 return 0;
126}
127
136int fd_open( iop_io_file_t *f, const char *name, int mode)
137{
138 char nameBuffer[ 250 ];
139 int fd;
140
141 M_DEBUG("open %i %s %s\n", f->unit, name ,base);
142 fd = iomanX_open( fd_name( nameBuffer, name), mode, 0 );
143 if ( fd < 0 ) return fd;
144
145 return fd_save( fd, f );
146}
147
155{
156 return iomanX_close( realfd(f) );
157}
158
167int fd_read( iop_io_file_t *f, void * buffer, int size )
168{
169 return iomanX_read( realfd(f), buffer, size );
170}
171
180int fd_write( iop_io_file_t *fd, void *buffer, int size )
181{
182 return iomanX_write( realfd(fd), buffer, size );
183}
184
193int fd_lseek( iop_io_file_t *fd, int offset, int whence)
194{
195 return iomanX_lseek( realfd(fd), offset, whence );
196}
197
198// Function array for fileio structure.
199static iop_io_device_ops_t functions = {
201 (void *)&dummy,
202 (void *)&dummy,
203 &fd_open,
204 &fd_close,
205 &fd_read,
206 (void *)&dummy,
207 &fd_lseek,
208 (void *)&dummy,
209 (void *)&dummy,
210 (void *)&dummy,
211 (void *)&dummy,
212 (void *)&dummy,
213 (void *)&dummy,
214 (void *)&dummy,
215 (void *)&dummy,
216 (void *)&dummy,
217};
218
219// FileIO structure.
220static iop_io_device_t driver = {
221 FS_REPNAME,
222 16,
223 1,
224 "host redirection driver",
225 &functions,
226};
227
245int _start( int argc, char *argv[] )
246{
247 M_PRINTF( "Copyright (c) 2004 adresd\n" );
248
249 if ( argc != 2 )
250 {
251 M_PRINTF( "HOST requires based argument\n" );
252 return MODULE_NO_RESIDENT_END;
253 }
254 else
255 {
256 // Copy the base location.
257 strncpy( base, argv[1] ,sizeof(base) - 1);
258 base[sizeof(base) - 1] = '\0';
259
260 M_PRINTF( "redirecting '%s:' to '%s'\n",FS_REPNAME,base);
261 fd_global = 1;
262
263 M_PRINTF( "HOST final step, bye\n" );
264
265 // Install naplink RPC handler
267
268 // now install the fileio driver
269 io_DelDrv( FS_REPNAME );
270 io_AddDrv( &driver );
271 }
272 return MODULE_RESIDENT_END;
273}
274
275
#define EIO
Definition errno.h:29
int fd_open(iop_io_file_t *f, const char *name, int mode)
Definition fakehost.c:136
int fd_save(int fd, iop_io_file_t *f)
Definition fakehost.c:89
char * fd_name(char *buffer, const char *name)
Definition fakehost.c:75
int fd_close(iop_io_file_t *f)
Definition fakehost.c:154
int _start(int argc, char *argv[])
Definition fakehost.c:245
int fd_initialize(iop_io_device_t *driver)
Definition fakehost.c:122
int dummy()
Definition fakehost.c:110
int fd_read(iop_io_file_t *f, void *buffer, int size)
Definition fakehost.c:167
int naplinkRpcInit(void)
Definition nprintf.c:80
int realfd(iop_io_file_t *f)
Definition fakehost.c:102
int fd_lseek(iop_io_file_t *fd, int offset, int whence)
Definition fakehost.c:193
int fd_write(iop_io_file_t *fd, void *buffer, int size)
Definition fakehost.c:180
void * privdata
Definition ioman_mod.h:63