diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-02-20 13:00:45 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:24 +0300 |
commit | 12bf93a429c981cf337ce2c27504ec0171157f76 (patch) | |
tree | 1b547aa4162109e412bfe8e6562e50ccc391ef90 /fs/bcachefs/util.c | |
parent | d4b691522c4b60220087a01c276f3fa9781405b0 (diff) | |
download | linux-12bf93a429c981cf337ce2c27504ec0171157f76.tar.xz |
bcachefs: Add .to_text() methods for all superblock sections
This patch improves the superblock .to_text() methods and adds methods
for all types that were missing them. It also improves printbufs by
allowing them to specfiy what units we want to be printing in, and adds
new wrapper methods for unifying our kernel and userspace environments.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/util.c')
-rw-r--r-- | fs/bcachefs/util.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index 971f404a01e3..f170cf9d5052 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -120,6 +120,27 @@ void bch2_hprint(struct printbuf *buf, s64 v) pr_buf(buf, "%c", si_units[u]); } +void bch2_pr_units(struct printbuf *out, s64 raw, s64 bytes) +{ + if (raw < 0) { + pr_buf(out, "-"); + raw = -raw; + bytes = -bytes; + } + + switch (out->units) { + case PRINTBUF_UNITS_RAW: + pr_buf(out, "%llu", raw); + break; + case PRINTBUF_UNITS_BYTES: + pr_buf(out, "%llu", bytes); + break; + case PRINTBUF_UNITS_HUMAN_READABLE: + bch2_hprint(out, bytes); + break; + } +} + void bch2_string_opt_to_text(struct printbuf *out, const char * const list[], size_t selected) |