diff --git a/ee/libcglue/Makefile b/ee/libcglue/Makefile index 78696635a7a..ca8ddab9d6d 100644 --- a/ee/libcglue/Makefile +++ b/ee/libcglue/Makefile @@ -75,6 +75,7 @@ GLUE_OBJS = \ lstat.o \ _fstat.o \ access.o \ + _ioctl.o \ _fcntl.o \ getdents.o \ _lseek.o \ diff --git a/ee/libcglue/src/glue.c b/ee/libcglue/src/glue.c index cf74b9b9d56..1da268a20e8 100644 --- a/ee/libcglue/src/glue.c +++ b/ee/libcglue/src/glue.c @@ -395,6 +395,27 @@ int _fcntl(int fd, int cmd, ...) } #endif /* F__fcntl */ +#ifdef F__ioctl +// This is actually not called from newlib, but the _ioctl symbol is checked by +// ps2sdkapi.c and fileXio_ps2sdkapi.c. Perhaps it was later renamed to _ps2sdk_ioctl? +// For consistency, _ioctl is implemented as an errno alternative to _ps2sdk_ioctl. +int _ioctl(int fd, int request, void *data) { + _libcglue_fdman_fd_info_t *fdinfo; + fdinfo = libcglue_get_fd_info(fd); + if (fdinfo == NULL) + { + errno = EBADF; + return -1; + } + if (fdinfo->ops == NULL || fdinfo->ops->ioctl == NULL) + { + errno = ENOSYS; + return -1; + } + return __transform_errno(fdinfo->ops->ioctl(fdinfo->userdata, request, data)); +} +#endif /* F__ioctl */ + #ifdef F_getdents // Called from newlib readdir.c, readdir_r.c int getdents(int fd, void *dd_buf, int count) diff --git a/ee/libcglue/src/ps2sdkapi.c b/ee/libcglue/src/ps2sdkapi.c index 375d852736d..1e73a946675 100644 --- a/ee/libcglue/src/ps2sdkapi.c +++ b/ee/libcglue/src/ps2sdkapi.c @@ -458,6 +458,7 @@ int __attribute__((weak)) _read(int fd, void *buf, size_t nbytes); off_t __attribute__((weak)) _lseek(int fd, off_t offset, int whence); int __attribute__((weak)) _write(int fd, const void *buf, size_t nbytes); int __attribute__((weak)) _ioctl(int fd, int request, void *data); +int __attribute__((weak)) _ps2sdk_ioctl(int fd, int request, void *data); int __attribute__((weak)) getdents(int fd, void *dd_buf, int count); void __fioOpsInitializeImpl(void) @@ -486,7 +487,7 @@ void __fioOpsInitializeImpl(void) // cppcheck-suppress knownConditionTrueFalse if (&_write) __fio_fdman_ops_file.write = __fioWriteHelper; // cppcheck-suppress knownConditionTrueFalse - if (&_ioctl) __fio_fdman_ops_file.ioctl = __fioIoctlHelper; + if ((&_ioctl) || (&_ps2sdk_ioctl)) __fio_fdman_ops_file.ioctl = __fioIoctlHelper; memset(&__fio_fdman_ops_dir, 0, sizeof(__fio_fdman_ops_dir)); __fio_fdman_ops_dir.getfd = __fioGetFdHelper; diff --git a/ee/rpc/filexio/src/fileXio_ps2sdk.c b/ee/rpc/filexio/src/fileXio_ps2sdk.c index fd419c93b54..77b750d434c 100644 --- a/ee/rpc/filexio/src/fileXio_ps2sdk.c +++ b/ee/rpc/filexio/src/fileXio_ps2sdk.c @@ -467,6 +467,7 @@ off_t __attribute__((weak)) _lseek(int fd, off_t offset, int whence); off64_t __attribute__((weak)) lseek64(int fd, off64_t offset, int whence); int __attribute__((weak)) _write(int fd, const void *buf, size_t nbytes); int __attribute__((weak)) _ioctl(int fd, int request, void *data); +int __attribute__((weak)) _ps2sdk_ioctl(int fd, int request, void *data); int __attribute__((weak)) getdents(int fd, void *dd_buf, int count); extern void __fileXioOpsInitializeImpl(void) @@ -503,7 +504,7 @@ extern void __fileXioOpsInitializeImpl(void) // cppcheck-suppress knownConditionTrueFalse if (&_write) __fileXio_fdman_ops_file.write = __fileXioWriteHelper; // cppcheck-suppress knownConditionTrueFalse - if (&_ioctl) __fileXio_fdman_ops_file.ioctl = __fileXioIoctlHelper; + if ((&_ioctl) || (&_ps2sdk_ioctl)) __fileXio_fdman_ops_file.ioctl = __fileXioIoctlHelper; __fileXio_fdman_ops_file.ioctl2 = __fileXioIoctl2Helper; memset(&__fileXio_fdman_ops_dir, 0, sizeof(__fileXio_fdman_ops_dir));