Skip to content

Commit 931442a

Browse files
committed
Adopted redundant cache read in lfs_file_relocate
Previously had some custom logic that could be reduced
1 parent 0e1022a commit 931442a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lfs.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,10 @@ static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
12071207
// either read from dirty cache or disk
12081208
for (lfs_off_t i = 0; i < file->off; i++) {
12091209
uint8_t data;
1210-
if (file->cache.block == file->block && i >= file->cache.off) {
1211-
data = file->cache.buffer[i - file->cache.off];
1212-
} else {
1213-
// just read from disk
1214-
err = lfs_bd_read(lfs, file->block, i, &data, 1);
1215-
if (err) {
1216-
return err;
1217-
}
1210+
err = lfs_cache_read(lfs, &lfs->rcache, &file->cache,
1211+
file->block, i, &data, 1);
1212+
if (err) {
1213+
return err;
12181214
}
12191215

12201216
err = lfs_cache_prog(lfs, &lfs->pcache, &lfs->rcache,

0 commit comments

Comments
 (0)