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.
fopen issue
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.
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.
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.
Changing stdio to just use fileXio is the simplest solution.
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.
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.
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:
fileXio_rpc.c patch:
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 (*_ps2sdk_close)(int);
+extern int (*_ps2sdk_open)(const char*, int);
+extern int (*_ps2sdk_read)(int, void*, int);
+extern int (*_ps2sdk_lseek)(int, int, int);
+extern int (*_ps2sdk_write)(int, const void*, int);
+
void _ps2sdk_stdio_init();
/* std I/O buffer type constants. */
@@ -80,7 +86,7 @@
ret = EOF;
break;
default:
- if ((stream->fd >= 0) && (fioClose(stream->fd) >= 0)) {
+ if ((stream->fd >= 0) && (_ps2sdk_close(stream->fd) >= 0)) {
stream->type = STD_IOBUF_TYPE_NONE;
stream->fd = -1;
stream->cnt = 0;
@@ -477,7 +483,7 @@
}
}
}
- if ((fd = fioOpen((char *)t_fname, iomode)) >= 0) {
+ if ((fd = _ps2sdk_open((char *)t_fname, iomode)) >= 0) {
__iob[i].fd = fd;
__iob[i].cnt = 0;
__iob[i].flag = flag;
@@ -491,7 +497,7 @@
cd_fname[fname_len + 0] = ';';
cd_fname[fname_len + 1] = '1';
cd_fname[fname_len + 2] = 0;
- if ((fd = fioOpen((char *)cd_fname, iomode)) >= 0) {
+ if ((fd = _ps2sdk_open((char *)cd_fname, iomode)) >= 0) {
__iob[i].fd = fd;
__iob[i].cnt = 0;
__iob[i].flag = flag;
@@ -661,7 +667,7 @@
break;
default:
/* attempt to read from the stream file. */
- ret = (fioRead(stream->fd, buf, (int)(r * n)) / (int)r);
+ ret = (_ps2sdk_read(stream->fd, buf, (int)(r * n)) / (int)r);
}
return (ret);
}
@@ -700,7 +706,7 @@
break;
default:
/* attempt to seek to offset from origin. */
- ret = ((fioLseek(stream->fd, (int)offset, origin) >= 0) ? 0 : -1);
+ ret = ((_ps2sdk_lseek(stream->fd, (int)offset, origin) >= 0) ? 0 : -1);
}
return (ret);
}
@@ -760,7 +766,7 @@
errno = EBADF;
ret = -1L;
}
- else ret = (((n = fioLseek(stream->fd, 0, SEEK_CUR)) >= 0) ? (long)n : -1L);
+ else ret = (((n = _ps2sdk_lseek(stream->fd, 0, SEEK_CUR)) >= 0) ? (long)n : -1L);
}
return (ret);
}
@@ -794,7 +800,7 @@
ret = r;
break;
case STD_IOBUF_TYPE_STDOUTHOST:
- ret = (fioWrite(1, (void *) buf, (int)(r * n)) / (int)r);
+ ret = (_ps2sdk_write(1, (void *) buf, (int)(r * n)) / (int)r);
break;
case STD_IOBUF_TYPE_SIO:
for (i = 0, len = (r * n); i < len; ++i) sio_putc((int)((char *)buf)[i]);
@@ -802,7 +808,7 @@
break;
default:
/* attempt to write the stream file. */
- ret = (fioWrite(stream->fd, (void *)buf, (int)(r * n)) / (int)r);
+ ret = (_ps2sdk_write(stream->fd, (void *)buf, (int)(r * n)) / (int)r);
}
return (ret);
}
@@ -1297,6 +1303,12 @@
#ifdef F___stdio_internals
+int (*_ps2sdk_close)(int) = fioClose;
+int (*_ps2sdk_open)(const char*, int) = fioOpen;
+int (*_ps2sdk_read)(int, void*, int) = fioRead;
+int (*_ps2sdk_lseek)(int, int, int) = fioLseek;
+int (*_ps2sdk_write)(int, const void*, int) = fioWrite;
+
void _ps2sdk_stdio_init()
{
int i;
Code: Select all
Index: fileXio_rpc.c
===================================================================
--- fileXio_rpc.c (revision 1228)
+++ fileXio_rpc.c (working copy)
@@ -20,6 +20,18 @@
#include "sys/stat.h"
#include "fileXio_rpc.h"
+// from stdio.c
+extern int (*_ps2sdk_close)(int);
+extern int (*_ps2sdk_open)(const char*, int);
+extern int (*_ps2sdk_read)(int, unsigned char*, int);
+extern int (*_ps2sdk_lseek)(int, long, int); // assume long = int
+extern int (*_ps2sdk_write)(int, unsigned char*, int);
+
+static int fileXioOpenHelper(const char* source, int flags)
+{
+ return fileXioOpen(source, flags, 0666);
+}
+
typedef struct {
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;
}