diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-04 01:10:24 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-06 06:52:54 -0800 |
commit | f3a8d548376295279d2d27fda5764adbe377c55b (patch) | |
tree | b3cb6b8e547fe419427d0490aa88c62bbfa454ae /util.c | |
parent | 837a476cc139167fc483016f0a2635a048f7709e (diff) |
bcache device_show now dumps superblocks
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -4,6 +4,7 @@ #include <fcntl.h> #include <limits.h> #include <linux/fs.h> +#include <math.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -69,6 +70,35 @@ char *strim(char *s) return s; } +struct units_buf pr_units(u64 v, enum units units) +{ + struct units_buf ret; + + switch (units) { + case BYTES: + snprintf(ret.b, sizeof(ret.b), "%llu", v << 9); + break; + case SECTORS: + snprintf(ret.b, sizeof(ret.b), "%llu", v); + break; + case HUMAN_READABLE: + v <<= 9; + + if (v >= 1024) { + int exp = log(v) / log(1024); + snprintf(ret.b, sizeof(ret.b), "%.1f%c", + v / pow(1024, exp), + "KMGTPE"[exp-1]); + } else { + snprintf(ret.b, sizeof(ret.b), "%llu", v); + } + + break; + } + + return ret; +} + /* Argument parsing stuff: */ long strtoul_or_die(const char *p, size_t max, const char *msg) |