|
|
@@ -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;
|
|
|
}
|