From b23deda5bc62c32b843ea17df131fc2bca8e0eb4 Mon Sep 17 00:00:00 2001 From: Aleksander Kaminski Date: Thu, 20 Jul 2023 11:24:10 +0200 Subject: [PATCH] libstorage: Fix ioctl() handling on fs - return devctl error only via output argument, - return -ENOTTY when no devctl handler is provided to return valid errno from ioctl() JIRA: RTOS-525 --- libstorage/fs.c | 6 ++++-- libstorage/include/storage/fs.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libstorage/fs.c b/libstorage/fs.c index 6895a593..6a7d842e 100644 --- a/libstorage/fs.c +++ b/libstorage/fs.c @@ -75,10 +75,12 @@ void storage_fsHandler(void *data, msg_t *msg) case mtDevCtl: if (fs->ops->devctl == NULL) { - msg->o.io.err = -ENOSYS; + /* FIXME this error passing works by accident on ioctl(), + * there's no dedicated error field for devctl. */ + msg->o.io.err = -ENOTTY; /* To return valid errno on ioctl() */ break; } - (void)fs->ops->devctl(fs->info, &msg->i.io.oid, msg->i.raw, msg->o.raw); + fs->ops->devctl(fs->info, &msg->i.io.oid, msg->i.raw, msg->o.raw); break; case mtCreate: diff --git a/libstorage/include/storage/fs.h b/libstorage/include/storage/fs.h index 17ad1f4e..30650247 100644 --- a/libstorage/include/storage/fs.h +++ b/libstorage/include/storage/fs.h @@ -32,7 +32,7 @@ typedef struct { int (*setattr)(void *info, oid_t *oid, int type, long long attr, void *data, size_t len); int (*getattr)(void *info, oid_t *oid, int type, long long *attr); int (*truncate)(void *info, oid_t *oid, size_t size); - int (*devctl)(void *info, oid_t *oid, const void *in, void *out); + void (*devctl)(void *info, oid_t *oid, const void *in, void *out); int (*create)(void *info, oid_t *oid, const char *name, oid_t *dev, unsigned mode, int type, oid_t *res); int (*destroy)(void *info, oid_t *oid);