Skip to content

Commit 808beab

Browse files
xiaoxiang781216GUIDINGLI
authored andcommitted
fs/romfs: Compute rf_endsector correctly when the file end on the sector boundary
Signed-off-by: Xiang Xiao <[email protected]>
1 parent cca7b7c commit 808beab

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/romfs/fs_romfsutil.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,19 @@ int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
10201020
}
10211021
else
10221022
{
1023+
uint32_t startsector;
1024+
uint32_t endoffset;
10231025
uint32_t nsectors;
10241026

1025-
rf->rf_endsector = SEC_NSECTORS(rm, rf->rf_startoffset + rf->rf_size);
1026-
nsectors = rf->rf_endsector - SEC_NSECTORS(rm, rf->rf_startoffset) + 1;
1027+
endoffset = rf->rf_startoffset + rf->rf_size;
1028+
if (rf->rf_size)
1029+
{
1030+
endoffset--;
1031+
}
1032+
1033+
rf->rf_endsector = SEC_NSECTORS(rm, endoffset);
1034+
startsector = SEC_NSECTORS(rm, rf->rf_startoffset);
1035+
nsectors = rf->rf_endsector - startsector + 1;
10271036
if (nsectors > CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS)
10281037
{
10291038
nsectors = CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS;

0 commit comments

Comments
 (0)