Skip to content

Commit

Permalink
fs/ioctl: add BIOC_BLKGETSIZE cmd to get block sector numbers
Browse files Browse the repository at this point in the history
Signed-off-by: wanggang26 <[email protected]>
  • Loading branch information
wanggang26 committed Aug 18, 2023
1 parent 6a5d00f commit bb2a6ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions fs/vfs/fs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ static int file_vioctl(FAR struct file *filep, int req, va_list ap)
*(FAR blksize_t *)(uintptr_t)arg = geo.geo_sectorsize;
}
}
break;

case BIOC_BLKGETSIZE:
if (ret == -ENOTTY && 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_nsectors;
}
}
break;

#endif
}

Expand Down
6 changes: 6 additions & 0 deletions include/nuttx/fs/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@
* to return sector size.
* OUT: Data return in user-provided
* buffer. */
#define BIOC_BLKGETSIZE _BIOC(0x0010) /* Get block device sector numbers.
* IN: Pointer to writable instance
* of sector numbers in which
* to return sector numbers.
* OUT: Data return in user-provided
* buffer. */

/* NuttX MTD driver ioctl definitions ***************************************/

Expand Down
3 changes: 2 additions & 1 deletion include/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* Pre-processor Definitions
****************************************************************************/

#define BLKSSZGET BIOC_BLKSSZGET
#define BLKSSZGET BIOC_BLKSSZGET
#define BLKGETSIZE BIOC_BLKGETSIZE

/* Mount flags */

Expand Down

0 comments on commit bb2a6ef

Please sign in to comment.