From 808beabc8374f7ce6773f6805a22d03f9233cd96 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 28 Jul 2024 15:39:52 +0800 Subject: [PATCH] fs/romfs: Compute rf_endsector correctly when the file end on the sector boundary Signed-off-by: Xiang Xiao --- fs/romfs/fs_romfsutil.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 3b14516b41..2e6d691543 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -1020,10 +1020,19 @@ int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm, } else { + uint32_t startsector; + uint32_t endoffset; uint32_t nsectors; - rf->rf_endsector = SEC_NSECTORS(rm, rf->rf_startoffset + rf->rf_size); - nsectors = rf->rf_endsector - SEC_NSECTORS(rm, rf->rf_startoffset) + 1; + endoffset = rf->rf_startoffset + rf->rf_size; + if (rf->rf_size) + { + endoffset--; + } + + rf->rf_endsector = SEC_NSECTORS(rm, endoffset); + startsector = SEC_NSECTORS(rm, rf->rf_startoffset); + nsectors = rf->rf_endsector - startsector + 1; if (nsectors > CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS) { nsectors = CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS;