fopen issue

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
radad
Posts: 246
Joined: Wed May 19, 2004 4:54 pm
Location: Melbourne, Australia

fopen issue

Post by radad »

I was using a third party library that was using the function fopen for file io. I was trying to use it on a file on the hard drive and it wasn't working. I tracked it down to the fopen function always uses fioOpen for files. I propose to add support for fileXioOpen for hard drive files.

Would anyone disagree with this approach? If not I shall implement it soon.
gawd
Posts: 28
Joined: Wed Feb 09, 2005 10:36 pm
Location: Israel
Contact:

Post by gawd »

I suggest something better.

An adapter for all stdio functions. A structure of path prefix and list of hooks to use. Each device will register its prefix and a callback to its functions, so if you're adding hdd support to fopen, I will be able to use the same code to add my romfs to fopen. IO-manager has such structure. ps2link registers it's host as a tty like this. But it's not available for EE, as far as I know. It's a really simple implementation and I'd rather want to see an LGPL code of it, other than code that wraps up Sony's IOP calls and remains undebuggable.

Something like:

typedef struct fs_device_t
{
const char *prefix;

int (*open)(const char *path, int mode);
int (*close)(int fd);
};

-- gawd.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

That's not a very good idea, as the IOP already handles all file I/O. Why would you duplicate code? The fileXio and iomanX drivers were specifically written to handle transparent access to all registered devices, whether they were the old-style or newer (HDD), so there's no reason to add yet another layer on top of that.

Changing stdio to just use fileXio is the simplest solution.
EEUG
Posts: 136
Joined: Fri May 13, 2005 4:49 am
Location: The Netherlands

Post by EEUG »

Just in case my small question: why fileXio read for "host:" is noticeable slower than fileio?
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

the latest time i tried filexio with mass it crashed, it works now?
EEUG
Posts: 136
Joined: Fri May 13, 2005 4:49 am
Location: The Netherlands

Post by EEUG »

...in SMS it worked, but then I've changed the code, so fileXio is used only for HDD access, for all other devices fileio is in charge...
radad
Posts: 246
Joined: Wed May 19, 2004 4:54 pm
Location: Melbourne, Australia

Post by radad »

It looks to me as though fileXio is supposed to be a drop in replacement for the fio functions. I fixed one bug relating to directory reading in another thread (still waiting on svn write access to check it in). I believe there is another bug in the file open function but have yet to confirm it.

I tried one solution last night that worked although I don't like the implementation. It created a dependency on fileXio from the stdclib.

I am going to try another solution soon based on the idea that you should be able to use fileXio in replacement for all fio functions.
radad
Posts: 246
Joined: Wed May 19, 2004 4:54 pm
Location: Melbourne, Australia

Post by radad »

I tried another solution last night which seemed to work. I test in on pfs, mc, mass and host. And it doesn't introduce a dependency on fileXio.

stdio.c patch:

Code: Select all

Index: stdio.c
===================================================================
--- stdio.c	(revision 1228)
+++ stdio.c	(working copy)
@@ -19,6 +19,12 @@
 #include <string.h>
 #include <limits.h>
 
+extern int &#40;*_ps2sdk_close&#41;&#40;int&#41;;
+extern int &#40;*_ps2sdk_open&#41;&#40;const char*, int&#41;;
+extern int &#40;*_ps2sdk_read&#41;&#40;int, void*, int&#41;;
+extern int &#40;*_ps2sdk_lseek&#41;&#40;int, int, int&#41;;
+extern int &#40;*_ps2sdk_write&#41;&#40;int, const void*, int&#41;;
+
 void _ps2sdk_stdio_init&#40;&#41;;
 
 /* std I/O buffer type constants. */
@@ -80,7 +86,7 @@
       ret = EOF;
       break;
     default&#58;
-      if &#40;&#40;stream->fd >= 0&#41; && &#40;fioClose&#40;stream->fd&#41; >= 0&#41;&#41; &#123;
+      if &#40;&#40;stream->fd >= 0&#41; && &#40;_ps2sdk_close&#40;stream->fd&#41; >= 0&#41;&#41; &#123;
         stream->type = STD_IOBUF_TYPE_NONE;
         stream->fd = -1;
         stream->cnt = 0;
@@ -477,7 +483,7 @@
 	    &#125;
 	  &#125;
 	&#125;
-        if &#40;&#40;fd = fioOpen&#40;&#40;char *&#41;t_fname, iomode&#41;&#41; >= 0&#41; &#123;
+        if &#40;&#40;fd = _ps2sdk_open&#40;&#40;char *&#41;t_fname, iomode&#41;&#41; >= 0&#41; &#123;
           __iob&#91;i&#93;.fd = fd;
           __iob&#91;i&#93;.cnt = 0;
           __iob&#91;i&#93;.flag = flag;
@@ -491,7 +497,7 @@
 	    cd_fname&#91;fname_len + 0&#93; = ';';
 	    cd_fname&#91;fname_len + 1&#93; = '1';
 	    cd_fname&#91;fname_len + 2&#93; = 0;
-    	    if &#40;&#40;fd = fioOpen&#40;&#40;char *&#41;cd_fname, iomode&#41;&#41; >= 0&#41; &#123;
+    	    if &#40;&#40;fd = _ps2sdk_open&#40;&#40;char *&#41;cd_fname, iomode&#41;&#41; >= 0&#41; &#123;
               __iob&#91;i&#93;.fd = fd;
               __iob&#91;i&#93;.cnt = 0;
               __iob&#91;i&#93;.flag = flag;
@@ -661,7 +667,7 @@
       break;
     default&#58;
       /* attempt to read from the stream file. */
-      ret = &#40;fioRead&#40;stream->fd, buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
+      ret = &#40;_ps2sdk_read&#40;stream->fd, buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
   &#125;
   return &#40;ret&#41;;
 &#125;
@@ -700,7 +706,7 @@
       break;
     default&#58;
       /* attempt to seek to offset from origin. */
-      ret = &#40;&#40;fioLseek&#40;stream->fd, &#40;int&#41;offset, origin&#41; >= 0&#41; ? 0 &#58; -1&#41;;
+      ret = &#40;&#40;_ps2sdk_lseek&#40;stream->fd, &#40;int&#41;offset, origin&#41; >= 0&#41; ? 0 &#58; -1&#41;;
   &#125;
   return &#40;ret&#41;;
 &#125;
@@ -760,7 +766,7 @@
         errno = EBADF;
         ret = -1L;
       &#125;
-      else ret = &#40;&#40;&#40;n = fioLseek&#40;stream->fd, 0, SEEK_CUR&#41;&#41; >= 0&#41; ? &#40;long&#41;n &#58; -1L&#41;;
+      else ret = &#40;&#40;&#40;n = _ps2sdk_lseek&#40;stream->fd, 0, SEEK_CUR&#41;&#41; >= 0&#41; ? &#40;long&#41;n &#58; -1L&#41;;
   &#125;
   return &#40;ret&#41;;
 &#125;
@@ -794,7 +800,7 @@
       ret = r;
       break;
     case STD_IOBUF_TYPE_STDOUTHOST&#58;
-      ret = &#40;fioWrite&#40;1, &#40;void *&#41; buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
+      ret = &#40;_ps2sdk_write&#40;1, &#40;void *&#41; buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
       break;
     case STD_IOBUF_TYPE_SIO&#58;
       for &#40;i = 0, len = &#40;r * n&#41;; i < len; ++i&#41; sio_putc&#40;&#40;int&#41;&#40;&#40;char *&#41;buf&#41;&#91;i&#93;&#41;;
@@ -802,7 +808,7 @@
       break;
     default&#58;
       /* attempt to write the stream file. */
-      ret = &#40;fioWrite&#40;stream->fd, &#40;void *&#41;buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
+      ret = &#40;_ps2sdk_write&#40;stream->fd, &#40;void *&#41;buf, &#40;int&#41;&#40;r * n&#41;&#41; / &#40;int&#41;r&#41;;
   &#125;
   return &#40;ret&#41;;
 &#125;
@@ -1297,6 +1303,12 @@
 
 
 #ifdef F___stdio_internals
+int &#40;*_ps2sdk_close&#41;&#40;int&#41; = fioClose;
+int &#40;*_ps2sdk_open&#41;&#40;const char*, int&#41; = fioOpen;
+int &#40;*_ps2sdk_read&#41;&#40;int, void*, int&#41; = fioRead;
+int &#40;*_ps2sdk_lseek&#41;&#40;int, int, int&#41; = fioLseek;
+int &#40;*_ps2sdk_write&#41;&#40;int, const void*, int&#41; = fioWrite;
+
 void _ps2sdk_stdio_init&#40;&#41;
 &#123;
     int i;
fileXio_rpc.c patch:

Code: Select all

Index&#58; fileXio_rpc.c
===================================================================
--- fileXio_rpc.c	&#40;revision 1228&#41;
+++ fileXio_rpc.c	&#40;working copy&#41;
@@ -20,6 +20,18 @@
 #include "sys/stat.h"
 #include "fileXio_rpc.h"
 
+// from stdio.c
+extern int &#40;*_ps2sdk_close&#41;&#40;int&#41;;
+extern int &#40;*_ps2sdk_open&#41;&#40;const char*, int&#41;;
+extern int &#40;*_ps2sdk_read&#41;&#40;int, unsigned char*, int&#41;;
+extern int &#40;*_ps2sdk_lseek&#41;&#40;int, long, int&#41;; // assume long = int
+extern int &#40;*_ps2sdk_write&#41;&#40;int, unsigned char*, int&#41;;
+
+static int fileXioOpenHelper&#40;const char* source, int flags&#41;
+&#123;
+    return fileXioOpen&#40;source, flags, 0666&#41;;
+&#125;
+
 typedef struct &#123;
 	int  ssize;
 	int  esize;
@@ -72,6 +84,12 @@
 	fileXioInited = 1;
 	fileXioBlockMode = FXIO_WAIT;
 
+	_ps2sdk_close = fileXioClose;
+	_ps2sdk_open = fileXioOpenHelper;
+	_ps2sdk_read = fileXioRead;
+	_ps2sdk_lseek = fileXioLseek;
+	_ps2sdk_write = fileXioWrite;
+
 	return 0;
 &#125;
 
Post Reply