Skip to content

Commit 106b06a

Browse files
committed
Added better handling for metadata pairs
The core algorithim that backs this filesystem's goal of fault tolerance is the alternating of "metadata pairs". Backed by a simple core function for reading and writing, makes heavy use of c99 designated initializers for passing info about multiple chunks in an erase block.
1 parent 1d36fc6 commit 106b06a

File tree

4 files changed

+204
-274
lines changed

4 files changed

+204
-274
lines changed

emubd/lfs_emubd.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <stdio.h>
1414
#include <limits.h>
1515
#include <dirent.h>
16+
#include <sys/stat.h>
1617

1718

1819
// Block device emulated on existing filesystem
@@ -168,11 +169,19 @@ lfs_error_t lfs_emubd_erase(lfs_emubd_t *emu,
168169
// Iterate and erase blocks
169170
while (size > 0) {
170171
snprintf(emu->child, LFS_NAME_MAX, "%d", ino);
171-
int err = unlink(emu->path);
172+
struct stat st;
173+
int err = stat(emu->path, &st);
172174
if (err && errno != ENOENT) {
173175
return -errno;
174176
}
175177

178+
if (!err && S_ISREG(st.st_mode)) {
179+
int err = unlink(emu->path);
180+
if (err) {
181+
return -errno;
182+
}
183+
}
184+
176185
size -= emu->info.erase_size;
177186
ino += 1;
178187
off = 0;

0 commit comments

Comments
 (0)