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.
This commit is contained in:
Christopher Haster
2017-03-12 14:11:52 -06:00
parent 1d36fc606a
commit 106b06a457
4 changed files with 211 additions and 281 deletions

View File

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