From 106b06a45778a227bfd934f0065c5f440582738f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 12 Mar 2017 14:11:52 -0600 Subject: 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. --- emubd/lfs_emubd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'emubd') diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 98a3af5..97edddb 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -13,6 +13,7 @@ #include #include #include +#include // Block device emulated on existing filesystem @@ -168,11 +169,19 @@ lfs_error_t lfs_emubd_erase(lfs_emubd_t *emu, // Iterate and erase blocks while (size > 0) { snprintf(emu->child, LFS_NAME_MAX, "%d", ino); - int err = unlink(emu->path); + struct stat st; + int err = stat(emu->path, &st); if (err && errno != ENOENT) { return -errno; } + if (!err && S_ISREG(st.st_mode)) { + int err = unlink(emu->path); + if (err) { + return -errno; + } + } + size -= emu->info.erase_size; ino += 1; off = 0; -- cgit v1.2.3