diff --git a/ft-lib/bcache.c b/ft-lib/bcache.c index 6f3c987..f9f474a 100644 --- a/ft-lib/bcache.c +++ b/ft-lib/bcache.c @@ -13,21 +13,34 @@ #include #include #include +#include #include "list.h" #include "bcache.h" //---------------------------------------------------------------- -static void warn(const char *msg) +static void warn(const char *fmt, ...) { - fprintf(stderr, "%s\n", msg); + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + fprintf(stderr, "\n"); } // FIXME: raise a condition somehow? -static void raise(const char *msg) +static void raise(const char *fmt, ...) { - warn(msg); + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + fprintf(stderr, "\n"); exit(1); } @@ -608,7 +621,7 @@ static struct block *new_block(struct bcache *cache, block_address index) struct block *b; b = alloc_block(cache); - while (!b && cache->nr_locked < cache->nr_cache_blocks) { + while (!b && (cache->nr_locked < cache->nr_cache_blocks)) { b = find_unused_clean_block(cache); if (!b) { if (list_empty(&cache->io_pending)) @@ -720,7 +733,7 @@ struct bcache *bcache_simple(const char *path, unsigned nr_cache_blocks) void bcache_destroy(struct bcache *cache) { if (cache->nr_locked) - warn("some blocks are still locked\n"); + warn("%u blocks are still locked\n", cache->nr_locked); flush_cache(cache); wait_all(cache); @@ -736,7 +749,9 @@ void bcache_destroy(struct bcache *cache) static void check_index(struct bcache *cache, block_address index) { if (index >= cache->nr_data_blocks) - raise("block out of bounds"); + raise("block out of bounds (%llu >= %llu)", + (unsigned long long) index, + (unsigned long long) cache->nr_data_blocks); } uint64_t get_nr_blocks(struct bcache *cache)