summaryrefslogtreecommitdiff
path: root/include/linux/printbuf.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-05-09 20:51:07 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-06-09 15:09:29 -0400
commit48a2f0ff931835d613fd6ac43c67876b4fa481cd (patch)
tree1239a748aa00db39fdad5ec0f43aea33c9364d80 /include/linux/printbuf.h
parent1545d45707fa4fb2869d93274db4b772d69b7ed9 (diff)
lib/printbuf: Unit specifiers
This adds options to printbuf for specifying whether units should be printed raw (default) or with human readable units, and for controlling whether human-readable units should be base 2 (default), or base 10. This also adds new helpers that obey these options: - pr_human_readable_u64 - pr_human_readable_s64 These obey printbuf->si_units - pr_units_u64 - pr_units_s64 These obey both printbuf-human_readable_units and printbuf->si_units Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'include/linux/printbuf.h')
-rw-r--r--include/linux/printbuf.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/printbuf.h b/include/linux/printbuf.h
index 5d32a31295f0..c898faac742c 100644
--- a/include/linux/printbuf.h
+++ b/include/linux/printbuf.h
@@ -53,11 +53,20 @@
*
* Make sure you use prt_newline() instead of \n in the format string for indent
* level and tabstops to work corretly.
+ *
+ * Output units: printbuf->units exists to tell pretty-printers how to output
+ * numbers: a raw value (e.g. directly from a superblock field), as bytes, or as
+ * human readable bytes. prt_units() obeys it.
*/
#include <linux/kernel.h>
#include <linux/string.h>
+enum printbuf_si {
+ PRINTBUF_UNITS_2, /* use binary powers of 2^10 */
+ PRINTBUF_UNITS_10, /* use powers of 10^3 (standard SI) */
+};
+
struct printbuf {
char *buf;
unsigned size;
@@ -71,6 +80,8 @@ struct printbuf {
u8 atomic;
bool allocation_failure:1;
bool heap_allocated:1;
+ enum printbuf_si si_units:1;
+ bool human_readable_units:1;
u8 tabstop;
u8 tabstops[4];
};
@@ -84,6 +95,10 @@ void printbuf_indent_add(struct printbuf *, unsigned);
void printbuf_indent_sub(struct printbuf *, unsigned);
void prt_tab(struct printbuf *);
void prt_tab_rjust(struct printbuf *);
+void prt_human_readable_u64(struct printbuf *, u64);
+void prt_human_readable_s64(struct printbuf *, s64);
+void prt_units_u64(struct printbuf *, u64);
+void prt_units_s64(struct printbuf *, s64);
/* Initializer for a heap allocated printbuf: */
#define PRINTBUF ((struct printbuf) { .heap_allocated = true })