Skip to content

Commit

Permalink
Merge pull request #711 from hakanrw/master
Browse files Browse the repository at this point in the history
fix ioctl failing with ENOSYS.
  • Loading branch information
uyjulian authored Jan 3, 2025
2 parents 69f54b9 + 9689143 commit 8367a37
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions ee/libcglue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GLUE_OBJS = \
lstat.o \
_fstat.o \
access.o \
_ioctl.o \
_fcntl.o \
getdents.o \
_lseek.o \
Expand Down
21 changes: 21 additions & 0 deletions ee/libcglue/src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ee/libcglue/src/ps2sdkapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ee/rpc/filexio/src/fileXio_ps2sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 8367a37

Please sign in to comment.