From b50c5f66383153d0ea72e1ab76a99341591a5046 Mon Sep 17 00:00:00 2001 From: yukangzhi Date: Wed, 28 May 2025 10:49:02 +0800 Subject: [PATCH] note/noteram: add FIONREAD ioctl to report unread buffer size Add handling for the FIONREAD ioctl in noteram_ioctl to return the number of unread bytes in the circular note buffer (noteram_unread_length()). Validate the argument pointer and return -EINVAL if it is NULL. Signed-off-by: yukangzhi --- drivers/note/noteram_driver.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index 0cca512e41e..d19a4cb454c 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -604,6 +604,18 @@ static int noteram_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + case FIONREAD: + if (arg == 0) + { + ret = -EINVAL; + } + else + { + *(FAR unsigned int *)arg = noteram_unread_length(drv); + ret = OK; + } + break; + default: break; }