Page 1 of 1

fopen issue

Posted: Wed Nov 09, 2005 8:57 am
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.

Posted: Wed Nov 09, 2005 5:04 pm
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.

Posted: Wed Nov 09, 2005 5:20 pm
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.

Posted: Wed Nov 09, 2005 6:55 pm
by EEUG
Just in case my small question: why fileXio read for "host:" is noticeable slower than fileio?

Posted: Wed Nov 09, 2005 10:13 pm
by weltall
the latest time i tried filexio with mass it crashed, it works now?

Posted: Wed Nov 09, 2005 10:40 pm
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...

Posted: Thu Nov 10, 2005 9:02 am
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.

Posted: Fri Nov 11, 2005 8:37 am
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;