fs/romfs: Compute rf_endsector correctly when the file end on the sector boundary

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2024-07-28 15:39:52 +08:00 committed by GUIDINGLI
parent cca7b7cb37
commit 808beabc83
1 changed files with 11 additions and 2 deletions

View File

@ -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;