Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2019-05-31 08:58:48 +0300
committerChristopher Haster <chaster@utexas.edu>2019-07-01 23:11:53 +0300
commitb73ac594f23e47382adcc7d541c314a918a8480d (patch)
tree3a9a08a3099d45a2e5f88639519f7e448fcda389
parent614f7b1e68ca796af6074fd21ceb812f3c609fa1 (diff)
Fixed issues with reading and caching inline files
Kind of a two-fold issue. One, the programming to the middle of inline files was causing the cache to get updated to a half programmed state. While fine, as all programs do occur in order in a block, this is less efficient when writing to inline files as it would cause the inline file to need to be reread even if it fits in the cache. Two, the rereading of the inline file was broken and passed the file's tag all the way to where a user would expect an error. This was easy to fix but adds to the reasons we should have test coverage information. Found by ebinans
-rw-r--r--lfs.c4
-rwxr-xr-xtests/test_seek.sh10
2 files changed, 12 insertions, 2 deletions
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;