@@ -93,6 +93,7 @@ static int lfs_bd_read(lfs_t *lfs,
9393 // bypass cache?
9494 diff = lfs_aligndown (diff , lfs -> cfg -> read_size );
9595 int err = lfs -> cfg -> read (lfs -> cfg , block , off , data , diff );
96+ LFS_ASSERT (err <= 0 );
9697 if (err ) {
9798 return err ;
9899 }
@@ -739,6 +740,7 @@ static lfs_stag_t lfs_dir_getslice(lfs_t *lfs, const lfs_mdir_t *dir,
739740 int err = lfs_bd_read (lfs ,
740741 NULL , & lfs -> rcache , sizeof (ntag ),
741742 dir -> pair [0 ], off , & ntag , sizeof (ntag ));
743+ LFS_ASSERT (err <= 0 );
742744 if (err ) {
743745 return err ;
744746 }
@@ -767,6 +769,7 @@ static lfs_stag_t lfs_dir_getslice(lfs_t *lfs, const lfs_mdir_t *dir,
767769 err = lfs_bd_read (lfs ,
768770 NULL , & lfs -> rcache , diff ,
769771 dir -> pair [0 ], off + sizeof (tag )+ goff , gbuffer , diff );
772+ LFS_ASSERT (err <= 0 );
770773 if (err ) {
771774 return err ;
772775 }
@@ -1279,6 +1282,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs,
12791282 if (err == LFS_ERR_CORRUPT ) {
12801283 break ;
12811284 }
1285+ return err ;
12821286 }
12831287
12841288 lfs_fcrc_fromle32 (& fcrc );
@@ -2264,7 +2268,7 @@ static int lfs_dir_relocatingcommit(lfs_t *lfs, lfs_mdir_t *dir,
22642268 }
22652269 }
22662270
2267- if (dir -> erased ) {
2271+ if (dir -> erased && dir -> count < 0xff ) {
22682272 // try to commit
22692273 struct lfs_commit commit = {
22702274 .block = dir -> pair [0 ],
0 commit comments