 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Wed Nov 09, 2005 8:57 am Post subject: fopen issue |
|
|
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. |
|
| Back to top |
|
 |
gawd
Joined: 09 Feb 2005 Posts: 28 Location: Israel
|
Posted: Wed Nov 09, 2005 5:04 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Wed Nov 09, 2005 5:20 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
EEUG
Joined: 13 May 2005 Posts: 136 Location: The Netherlands
|
Posted: Wed Nov 09, 2005 6:55 pm Post subject: |
|
|
| Just in case my small question: why fileXio read for "host:" is noticeable slower than fileio? |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Wed Nov 09, 2005 10:13 pm Post subject: |
|
|
| the latest time i tried filexio with mass it crashed, it works now? |
|
| Back to top |
|
 |
EEUG
Joined: 13 May 2005 Posts: 136 Location: The Netherlands
|
Posted: Wed Nov 09, 2005 10:40 pm Post subject: |
|
|
| ...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... |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Thu Nov 10, 2005 9:02 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Fri Nov 11, 2005 8:37 am Post subject: |
|
|
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: | 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;
|
fileXio_rpc.c patch:
| Code: | 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;
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|