diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2016-12-11 14:45:48 -0900 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2016-12-11 14:58:27 -0900 |
commit | 7f4191a202ea4558ca2d5eb8a47daea33c9999c7 (patch) | |
tree | 137f957291da895f78b43a8903db6f744d6e202c /util.c | |
parent | 4e158e155327d09868453ae9759a58284245175a (diff) |
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
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -1,4 +1,5 @@ #include <alloca.h> +#include <assert.h> #include <ctype.h> #include <errno.h> #include <fcntl.h> @@ -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)) |