diff --git a/lfs.c b/lfs.c index ca6d587..c554135 100644 --- a/lfs.c +++ b/lfs.c @@ -194,7 +194,7 @@ static int lfs_bd_prog(lfs_t *lfs, off += diff; size -= diff; - pcache->size = off - pcache->off; + pcache->size = lfs_max(pcache->size, off - pcache->off); if (pcache->size == lfs->cfg->cache_size) { // eagerly flush out pcache if we fill up int err = lfs_bd_flush(lfs, pcache, rcache, validate); @@ -617,7 +617,7 @@ static int lfs_dir_getread(lfs_t *lfs, const lfs_mdir_t *dir, lfs->cfg->cache_size); int err = lfs_dir_getslice(lfs, dir, gmask, gtag, rcache->off, rcache->buffer, rcache->size); - if (err) { + if (err < 0) { return err; } } diff --git a/tests/test_seek.sh b/tests/test_seek.sh index 1803317..97a6f15 100755 --- a/tests/test_seek.sh +++ b/tests/test_seek.sh @@ -395,6 +395,16 @@ tests/test.py << TEST lfs_file_sync(&lfs, &file[0]) => 0; lfs_file_tell(&lfs, &file[0]) => i+1; lfs_file_size(&lfs, &file[0]) => $SIZE; + if (i < $SIZE-2) { + uint8_t c[3]; + lfs_file_seek(&lfs, &file[0], -1, LFS_SEEK_CUR) => i; + lfs_file_read(&lfs, &file[0], &c, 3) => 3; + lfs_file_tell(&lfs, &file[0]) => i+3; + lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_seek(&lfs, &file[0], i+1, LFS_SEEK_SET) => i+1; + lfs_file_tell(&lfs, &file[0]) => i+1; + lfs_file_size(&lfs, &file[0]) => $SIZE; + } } lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => 0;