From 7f4191a202ea4558ca2d5eb8a47daea33c9999c7 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 11 Dec 2016 14:45:48 -0900 Subject: add support for maximum journal entry size also rip out prototype crypto support code - real code is in the dev branch, with the new superblock format --- util.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 73d35f7..1bab7da 100644 --- a/util.c +++ b/util.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -21,23 +22,13 @@ /* Integer stuff: */ -u64 rounddown_pow_of_two(u64 n) -{ - u64 ret; - - do { - ret = n; - n &= n - 1; - } while (n); - - return ret; -} - unsigned ilog2(u64 n) { unsigned ret = 0; - while (n) { + assert(n > 0); + + while (n > 1) { ret++; n >>= 1; } @@ -45,6 +36,16 @@ unsigned ilog2(u64 n) return ret; } +u64 rounddown_pow_of_two(u64 n) +{ + return 1ULL << ilog2(n); +} + +u64 roundup_pow_of_two(u64 n) +{ + return 1ULL << (ilog2(n - 1) + 1); +} + char *skip_spaces(const char *str) { while (isspace(*str)) -- cgit v1.2.3