From a320fed3b5fd55a7e914ac9a6630d22b6d2ebc06 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 4 Oct 2017 09:24:40 +1100 Subject: [PATCH] vfs: Add ioctl() to filesystem set --- components/vfs/include/esp_vfs.h | 4 ++++ components/vfs/vfs.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index 6ced2ce2b..fcd2e66bb 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -145,6 +145,10 @@ typedef struct int (*fcntl_p)(void* ctx, int fd, int cmd, va_list args); int (*fcntl)(int fd, int cmd, va_list args); }; + union { + int (*ioctl_p)(void* ctx, int fd, int cmd, va_list args); + int (*ioctl)(int fd, int cmd, va_list args); + }; } esp_vfs_t; diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index f07bf7c37..c307fdef1 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -489,3 +489,20 @@ int fcntl(int fd, int cmd, ...) va_end(args); return ret; } + +int ioctl(int fd, int cmd, ...) +{ + const vfs_entry_t* vfs = get_vfs_for_fd(fd); + struct _reent* r = __getreent(); + if (vfs == NULL) { + __errno_r(r) = EBADF; + return -1; + } + int local_fd = translate_fd(vfs, fd); + int ret; + va_list args; + va_start(args, cmd); + CHECK_AND_CALL(ret, r, vfs, ioctl, local_fd, cmd, args); + va_end(args); + return ret; +}