diff options
author | Christopher Haster <chaster@utexas.edu> | 2017-03-12 23:11:52 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2017-03-20 06:25:36 +0300 |
commit | 106b06a45778a227bfd934f0065c5f440582738f (patch) | |
tree | 56736218107d1ce9e5d6de2bc23cf0a8541f41fa /emubd | |
parent | 1d36fc606a8cf5a17d59227e6c2ccc25783fd839 (diff) |
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.
Diffstat (limited to 'emubd')
-rw-r--r-- | emubd/lfs_emubd.c | 11 |
1 files changed, 10 insertions, 1 deletions
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 <stdio.h> #include <limits.h> #include <dirent.h> +#include <sys/stat.h> // 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; |