1 /*********************************************************************
2 * Copyright (C) 2003 Tord Lindstrom (pukko@home.se)
3 * Copyright (C) 2004 adresd (adresd_ps2dev@yahoo.com)
4 * This file is subject to the terms and conditions of the PS2Link License.
5 * See the file LICENSE in the main directory of this distribution for more
21 #define dbgprintf(args...) printf(args)
23 #define dbgprintf(args...) do { } while(0)
26 static char fsname
[] = "host";
28 ////////////////////////////////////////////////////////////////////////
29 //static iop_device_t fsys_driver;
31 /* File desc struct is probably larger than this, but we only
32 * need to access the word @ offset 0x0C (in which we put our identifier)
38 int device_id
; // the X in hostX
42 ////////////////////////////////////////////////////////////////////////
43 /* We need(?) to protect the net access, so the server doesn't get
44 * confused if two processes calls a fsys func at the same time
47 static int fsys_pid
= 0;
48 //static iop_device_t fsys_driver;
50 ////////////////////////////////////////////////////////////////////////
53 printf("dummy function called\n");
57 ////////////////////////////////////////////////////////////////////////
58 static void fsysInit(iop_device_t
*driver
)
60 struct _iop_thread mythread
;
64 dbgprintf("initializing %s\n", driver
->name
);
66 // Start socket server thread
68 mythread
.attr
= 0x02000000; // attr
69 mythread
.option
= 0; // option
70 mythread
.thread
= (void *)pko_file_serv
; // entry
71 mythread
.stacksize
= 0x800;
72 mythread
.priority
= 9; // We really should choose prio w more effort
74 pid
= CreateThread(&mythread
);
77 if ((i
=StartThread(pid
, NULL
)) < 0) {
78 printf("StartThread failed (%d)\n", i
);
82 printf("CreateThread failed (%d)\n", pid
);
86 dbgprintf("Thread id: %x\n", pid
);
89 ////////////////////////////////////////////////////////////////////////
90 static int fsysDestroy(void)
94 // ExitDeleteThread(fsys_pid);
95 SignalSema(fsys_sema
);
96 DeleteSema(fsys_sema
);
101 ////////////////////////////////////////////////////////////////////////
102 static int fsysOpen( int fd
, char *name
, int mode
)
104 struct filedesc_info
*fd_info
;
107 dbgprintf("fsysOpen..\n");
108 dbgprintf(" fd: %x, name: %s, mode: %d\n\n", fd
, name
, mode
);
110 fd_info
= (struct filedesc_info
*)fd
;
113 fsys_fd
= pko_open_file(name
, mode
);
114 SignalSema(fsys_sema
);
115 fd_info
->own_fd
= fsys_fd
;
122 ////////////////////////////////////////////////////////////////////////
123 static int fsysClose( int fd
)
125 struct filedesc_info
*fd_info
;
128 dbgprintf("fsys_close..\n"
131 fd_info
= (struct filedesc_info
*)fd
;
133 ret
= pko_close_file(fd_info
->own_fd
);
134 SignalSema(fsys_sema
);
141 ////////////////////////////////////////////////////////////////////////
142 static int fsysRead( int fd
, char *buf
, int size
)
144 struct filedesc_info
*fd_info
;
147 fd_info
= (struct filedesc_info
*)fd
;
149 dbgprintf("fsysRead..."
153 " ow: %d\n\n", fd
, (int)buf
, size
, fd_info
->own_fd
);
156 ret
= pko_read_file(fd_info
->own_fd
, buf
, size
);
157 SignalSema(fsys_sema
);
165 ////////////////////////////////////////////////////////////////////////
166 static int fsysWrite( int fd
, char *buf
, int size
)
168 struct filedesc_info
*fd_info
;
171 dbgprintf("fsysWrite..."
174 fd_info
= (struct filedesc_info
*)fd
;
176 ret
= pko_write_file(fd_info
->own_fd
, buf
, size
);
177 SignalSema(fsys_sema
);
183 ////////////////////////////////////////////////////////////////////////
184 static int fsysLseek( int fd
, unsigned int offset
, int whence
)
186 struct filedesc_info
*fd_info
;
189 dbgprintf("fsysLseek..\n"
192 " wh: %x\n\n", fd
, offset
, whence
);
194 fd_info
= (struct filedesc_info
*)fd
;
196 ret
= pko_lseek_file(fd_info
->own_fd
, offset
, whence
);
197 SignalSema(fsys_sema
);
201 ////////////////////////////////////////////////////////////////////////
202 static int fsysRemove(iop_file_t
* file
, char *name
)
205 dbgprintf("fsysRemove..\n");
206 dbgprintf(" name: %s\n\n", name
);
209 ret
= pko_remove(name
);
210 SignalSema(fsys_sema
);
215 ////////////////////////////////////////////////////////////////////////
216 static int fsysMkdir(iop_file_t
* file
, char *name
, int mode
)
219 dbgprintf("fsysMkdir..\n");
220 dbgprintf(" name: '%s'\n\n", name
);
223 ret
= pko_mkdir(name
, mode
);
224 SignalSema(fsys_sema
);
229 ////////////////////////////////////////////////////////////////////////
230 static int fsysRmdir(iop_file_t
* file
, char *name
)
233 dbgprintf("fsysRmdir..\n");
234 dbgprintf(" name: %s\n\n", name
);
237 ret
= pko_rmdir(name
);
238 SignalSema(fsys_sema
);
244 ////////////////////////////////////////////////////////////////////////
245 static int fsysDopen(int fd
, char *name
)
247 struct filedesc_info
*fd_info
;
250 dbgprintf("fsysDopen..\n");
251 dbgprintf(" fd: %x, name: %s\n\n", fd
, name
);
253 fd_info
= (struct filedesc_info
*)fd
;
256 fsys_fd
= pko_open_dir(name
);
257 SignalSema(fsys_sema
);
258 fd_info
->own_fd
= fsys_fd
;
263 ////////////////////////////////////////////////////////////////////////
264 static int fsysDread(int fd
, void *buf
)
266 struct filedesc_info
*fd_info
;
269 fd_info
= (struct filedesc_info
*)fd
;
271 dbgprintf("fsysDread..."
274 " ow: %d\n\n", fd
, (int)buf
, fd_info
->own_fd
);
277 ret
= pko_read_dir(fd_info
->own_fd
, buf
);
278 SignalSema(fsys_sema
);
284 ////////////////////////////////////////////////////////////////////////
285 static int fsysDclose(int fd
)
287 struct filedesc_info
*fd_info
;
290 dbgprintf("fsys_dclose..\n"
293 fd_info
= (struct filedesc_info
*)fd
;
295 ret
= pko_close_dir(fd_info
->own_fd
);
296 SignalSema(fsys_sema
);
301 iop_device_ops_t fsys_functarray
= { (void *)fsysInit
, (void *)fsysDestroy
, (void *)dummy5
,
302 (void *)fsysOpen
, (void *)fsysClose
, (void *)fsysRead
,
303 (void *)fsysWrite
, (void *)fsysLseek
, (void *)dummy5
,
304 (void *)fsysRemove
, (void *)fsysMkdir
, (void *)fsysRmdir
,
305 (void *)fsysDopen
, (void *)fsysDclose
, (void *)fsysDread
,
306 (void *)dummy5
, (void *)dummy5
};
308 iop_device_t fsys_driver
= { fsname
, 16, 1, "fsys driver",
310 ////////////////////////////////////////////////////////////////////////
311 // Entry point for mounting the file system
314 iop_sema_t sema_info
;
317 sema_info
.option
= 0;
318 sema_info
.initial
= 1;
320 fsys_sema
= CreateSema(&sema_info
);
323 AddDrv(&fsys_driver
);
328 int fsysUnmount(void)