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
path: root/emubd
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2017-06-26 00:56:12 +0300
committerChristopher Haster <chaster@utexas.edu>2017-06-29 05:45:45 +0300
commit0e1022a86c3e6458db756f628f8ca83e3be0db3b (patch)
tree6fe8e2b4d47b32e9d2b1d5ed4f416d0bf8ac3d0f /emubd
parenta1138a41ce1a16b1113acb036b7049ca6263b900 (diff)
Fixed missing erase during file relocation
This was an easy fix, but highlighted the fact that the current testing framework doesn't detect when a block is written to without an associated erase. Added a quick solution that creates an empty file during an erase.
Diffstat (limited to 'emubd')
-rw-r--r--emubd/lfs_emubd.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c
index 2c3b348..9e34f6e 100644
--- a/emubd/lfs_emubd.c
+++ b/emubd/lfs_emubd.c
@@ -127,13 +127,13 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
FILE *f = fopen(emu->path, "r+b");
- if (!f && errno == ENOENT) {
- f = fopen(emu->path, "w+b");
- if (!f) {
- return -errno;
- }
+ if (!f && errno != ENOENT) {
+ return -errno;
}
+ // Check that file was erased
+ assert(f);
+
int err = fseek(f, off, SEEK_SET);
if (err) {
return -errno;
@@ -185,6 +185,18 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) {
}
}
+ if (err || S_ISREG(st.st_mode)) {
+ FILE *f = fopen(emu->path, "w");
+ if (!f) {
+ return -errno;
+ }
+
+ err = fclose(f);
+ if (err) {
+ return -errno;
+ }
+ }
+
emu->stats.erase_count += 1;
return 0;
}