From 160299d35c65381c2ebcb7662d8dacf18120cb5f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 26 Feb 2017 18:05:27 -0600 Subject: Initial commit of progress, minimal formatting niave free list --- emubd/lfs_emubd.c | 13 +++++++++++-- emubd/lfs_emubd.h | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'emubd') diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 73730f1..98a3af5 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -18,6 +18,7 @@ // Block device emulated on existing filesystem lfs_error_t lfs_emubd_create(lfs_emubd_t *emu, const char *path) { memset(&emu->info, 0, sizeof(emu->info)); + memset(&emu->stats, 0, sizeof(emu->stats)); // Allocate buffer for creating children files size_t pathlen = strlen(path); @@ -64,8 +65,8 @@ lfs_error_t lfs_emubd_read(lfs_emubd_t *emu, uint8_t *buffer, return -EINVAL; } - // Default to some arbitrary value for debugging - memset(buffer, 0xcc, size); + // Zero out buffer for debugging + memset(buffer, 0, size); // Iterate over blocks until enough data is read while (size > 0) { @@ -100,6 +101,7 @@ lfs_error_t lfs_emubd_read(lfs_emubd_t *emu, uint8_t *buffer, off = 0; } + emu->stats.read_count += 1; return 0; } @@ -148,6 +150,7 @@ lfs_error_t lfs_emubd_write(lfs_emubd_t *emu, const uint8_t *buffer, off = 0; } + emu->stats.write_count += 1; return 0; } @@ -175,6 +178,7 @@ lfs_error_t lfs_emubd_erase(lfs_emubd_t *emu, off = 0; } + emu->stats.erase_count += 1; return 0; } @@ -188,6 +192,11 @@ lfs_error_t lfs_emubd_info(lfs_emubd_t *emu, struct lfs_bd_info *info) { return 0; } +lfs_error_t lfs_emubd_stats(lfs_emubd_t *emu, struct lfs_bd_stats *stats) { + *stats = emu->stats; + return 0; +} + // Wrappers for void*s static lfs_error_t lfs_emubd_bd_read(void *bd, uint8_t *buffer, diff --git a/emubd/lfs_emubd.h b/emubd/lfs_emubd.h index 1304628..323601d 100644 --- a/emubd/lfs_emubd.h +++ b/emubd/lfs_emubd.h @@ -11,11 +11,19 @@ #include "lfs_bd.h" +// Stats for debugging and optimization +struct lfs_bd_stats { + lfs_lword_t read_count; + lfs_lword_t write_count; + lfs_lword_t erase_count; +}; + // The emu bd state typedef struct lfs_emubd { char *path; char *child; struct lfs_bd_info info; + struct lfs_bd_stats stats; } lfs_emubd_t; @@ -50,6 +58,11 @@ lfs_error_t lfs_emubd_sync(lfs_emubd_t *bd); // Any unknown information may be left unmodified lfs_error_t lfs_emubd_info(lfs_emubd_t *bd, struct lfs_bd_info *info); +// Get stats of operations on the block device +// +// Used for debugging and optimizations +lfs_error_t lfs_emubd_stats(lfs_emubd_t *bd, struct lfs_bd_stats *stats); + // Block device operations extern const struct lfs_bd_ops lfs_emubd_ops; -- cgit v1.2.3