From 978530f5f693c8ea1a37ec3c4053d40f02120450 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Mon, 11 Jul 2022 13:02:48 +0000 Subject: [PATCH] fs/ioctl: add BLKSSZGET cmd to get block sector size refer to: https://sites.uclouvain.be/SystInfo/usr/include/sys/mount.h.html Signed-off-by: Jiuzhu Dong --- fs/vfs/fs_ioctl.c | 14 ++++++++++++++ include/nuttx/fs/ioctl.h | 6 ++++++ include/sys/mount.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c index 29c5ec7b10..0d2baa16d2 100644 --- a/fs/vfs/fs_ioctl.c +++ b/fs/vfs/fs_ioctl.c @@ -110,6 +110,20 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap) ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg); } break; + +#ifndef CONFIG_DISABLE_MOUNTPOINT + case BIOC_BLKSSZGET: + if (inode->u.i_ops != NULL && inode->u.i_ops->ioctl != NULL) + { + struct geometry geo; + ret = inode->u.i_ops->ioctl(filep, BIOC_GEOMETRY, + (unsigned long)(uintptr_t)&geo); + if (ret >= 0) + { + *(FAR blksize_t *)(uintptr_t)arg = geo.geo_sectorsize; + } + } +#endif } return ret; diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index e81847002e..7985f7c3fd 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -287,6 +287,12 @@ * OUT: Partition information structure * populated with data from the block * device partition */ +#define BIOC_BLKSSZGET _BIOC(0x000f) /* Get block device sector size. + * IN: Pointer to writable instance + * of sector size in which + * to return sector size. + * OUT: Data return in user-provided + * buffer. */ /* NuttX MTD driver ioctl definitions ***************************************/ diff --git a/include/sys/mount.h b/include/sys/mount.h index 73ac285d83..c23e9246f6 100644 --- a/include/sys/mount.h +++ b/include/sys/mount.h @@ -26,11 +26,14 @@ ****************************************************************************/ #include +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#define BLKSSZGET BIOC_BLKSSZGET + /* Mount flags */ #define MS_RDONLY 1 /* Mount file system read-only */