Skip to content

Commit 8367a37

Browse files
authored
Merge pull request #711 from hakanrw/master
fix ioctl failing with ENOSYS.
2 parents 69f54b9 + 9689143 commit 8367a37

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

ee/libcglue/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ GLUE_OBJS = \
7575
lstat.o \
7676
_fstat.o \
7777
access.o \
78+
_ioctl.o \
7879
_fcntl.o \
7980
getdents.o \
8081
_lseek.o \

ee/libcglue/src/glue.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,27 @@ int _fcntl(int fd, int cmd, ...)
395395
}
396396
#endif /* F__fcntl */
397397

398+
#ifdef F__ioctl
399+
// This is actually not called from newlib, but the _ioctl symbol is checked by
400+
// ps2sdkapi.c and fileXio_ps2sdkapi.c. Perhaps it was later renamed to _ps2sdk_ioctl?
401+
// For consistency, _ioctl is implemented as an errno alternative to _ps2sdk_ioctl.
402+
int _ioctl(int fd, int request, void *data) {
403+
_libcglue_fdman_fd_info_t *fdinfo;
404+
fdinfo = libcglue_get_fd_info(fd);
405+
if (fdinfo == NULL)
406+
{
407+
errno = EBADF;
408+
return -1;
409+
}
410+
if (fdinfo->ops == NULL || fdinfo->ops->ioctl == NULL)
411+
{
412+
errno = ENOSYS;
413+
return -1;
414+
}
415+
return __transform_errno(fdinfo->ops->ioctl(fdinfo->userdata, request, data));
416+
}
417+
#endif /* F__ioctl */
418+
398419
#ifdef F_getdents
399420
// Called from newlib readdir.c, readdir_r.c
400421
int getdents(int fd, void *dd_buf, int count)

ee/libcglue/src/ps2sdkapi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ int __attribute__((weak)) _read(int fd, void *buf, size_t nbytes);
458458
off_t __attribute__((weak)) _lseek(int fd, off_t offset, int whence);
459459
int __attribute__((weak)) _write(int fd, const void *buf, size_t nbytes);
460460
int __attribute__((weak)) _ioctl(int fd, int request, void *data);
461+
int __attribute__((weak)) _ps2sdk_ioctl(int fd, int request, void *data);
461462
int __attribute__((weak)) getdents(int fd, void *dd_buf, int count);
462463

463464
void __fioOpsInitializeImpl(void)
@@ -486,7 +487,7 @@ void __fioOpsInitializeImpl(void)
486487
// cppcheck-suppress knownConditionTrueFalse
487488
if (&_write) __fio_fdman_ops_file.write = __fioWriteHelper;
488489
// cppcheck-suppress knownConditionTrueFalse
489-
if (&_ioctl) __fio_fdman_ops_file.ioctl = __fioIoctlHelper;
490+
if ((&_ioctl) || (&_ps2sdk_ioctl)) __fio_fdman_ops_file.ioctl = __fioIoctlHelper;
490491

491492
memset(&__fio_fdman_ops_dir, 0, sizeof(__fio_fdman_ops_dir));
492493
__fio_fdman_ops_dir.getfd = __fioGetFdHelper;

ee/rpc/filexio/src/fileXio_ps2sdk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ off_t __attribute__((weak)) _lseek(int fd, off_t offset, int whence);
467467
off64_t __attribute__((weak)) lseek64(int fd, off64_t offset, int whence);
468468
int __attribute__((weak)) _write(int fd, const void *buf, size_t nbytes);
469469
int __attribute__((weak)) _ioctl(int fd, int request, void *data);
470+
int __attribute__((weak)) _ps2sdk_ioctl(int fd, int request, void *data);
470471
int __attribute__((weak)) getdents(int fd, void *dd_buf, int count);
471472

472473
extern void __fileXioOpsInitializeImpl(void)
@@ -503,7 +504,7 @@ extern void __fileXioOpsInitializeImpl(void)
503504
// cppcheck-suppress knownConditionTrueFalse
504505
if (&_write) __fileXio_fdman_ops_file.write = __fileXioWriteHelper;
505506
// cppcheck-suppress knownConditionTrueFalse
506-
if (&_ioctl) __fileXio_fdman_ops_file.ioctl = __fileXioIoctlHelper;
507+
if ((&_ioctl) || (&_ps2sdk_ioctl)) __fileXio_fdman_ops_file.ioctl = __fileXioIoctlHelper;
507508
__fileXio_fdman_ops_file.ioctl2 = __fileXioIoctl2Helper;
508509

509510
memset(&__fileXio_fdman_ops_dir, 0, sizeof(__fileXio_fdman_ops_dir));

0 commit comments

Comments
 (0)