libs/libc: Fix divide-by-zero in stat() with large filesystem block sizes

blksize_t is currently defined as int16_t, which overflows when a
filesystem reports a block size larger than 32767 bytes. This causes
st_blksize to become zero, leading to an integer divide-by-zero when
st_blocks is calculated in stat().

Widen blksize_t to int32_t to support larger filesystem block sizes.

Update nuttx_blksize_t in include/nuttx/fs/hostfs.h to keep it
consistent with include/sys/types.h.

struct geometry.geo_sectorsize (include/nuttx/fs/ioctl.h) is also
typed blksize_t, so every debug print of that field using a 16-bit
format specifier is updated to PRId32 to match the new width:
drivers/misc/ramdisk.c, drivers/mmcsd/mmcsd_spi.c, drivers/mtd/ftl.c,
fs/driver/fs_blockmerge.c, drivers/mtd/smart.c,
drivers/usbhost/usbhost_storage.c, drivers/mmcsd/mmcsd_sdio.c,
arch/arm/src/s32k1xx/s32k1xx_eeeprom.c,
arch/arm/src/lc823450/lc823450_mmcl.c.

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
Signed-off-by: root <root@LAPTOP-9C7LKDC5.localdomain>
This commit is contained in:
Ansh Rai 2026-07-15 19:55:22 +05:30 committed by Xiang Xiao
parent 26ec938064
commit 54b0066a69
11 changed files with 12 additions and 12 deletions

View file

@ -123,7 +123,7 @@
/* These must match the definitions in include/sys/types.h */
typedef int16_t nuttx_blksize_t;
typedef int32_t nuttx_blksize_t;
# ifdef CONFIG_SMALL_MEMORY
typedef uint16_t nuttx_size_t;

View file

@ -229,7 +229,7 @@ typedef off_t loff_t;
/* blksize_t is a signed integer value used for file block sizes */
typedef int16_t blksize_t;
typedef int32_t blksize_t;
/* Network related */