Commit 3811f48a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_printbuf_strip_trailing_newline()

Add a new helper to fix inode_to_text()
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent babe30fe
...@@ -551,6 +551,8 @@ static void __bch2_inode_unpacked_to_text(struct printbuf *out, ...@@ -551,6 +551,8 @@ static void __bch2_inode_unpacked_to_text(struct printbuf *out,
prt_printf(out, #_name "=%llu\n", (u64) inode->_name); prt_printf(out, #_name "=%llu\n", (u64) inode->_name);
BCH_INODE_FIELDS_v3() BCH_INODE_FIELDS_v3()
#undef x #undef x
bch2_printbuf_strip_trailing_newline(out);
printbuf_indent_sub(out, 2); printbuf_indent_sub(out, 2);
} }
......
...@@ -316,6 +316,20 @@ void bch2_prt_newline(struct printbuf *buf) ...@@ -316,6 +316,20 @@ void bch2_prt_newline(struct printbuf *buf)
buf->cur_tabstop = 0; buf->cur_tabstop = 0;
} }
void bch2_printbuf_strip_trailing_newline(struct printbuf *out)
{
for (int p = out->pos - 1; p >= 0; --p) {
if (out->buf[p] == '\n') {
out->pos = p;
break;
}
if (out->buf[p] != ' ')
break;
}
printbuf_nul_terminate_reserved(out);
}
static void __prt_tab(struct printbuf *out) static void __prt_tab(struct printbuf *out)
{ {
int spaces = max_t(int, 0, cur_tabstop(out) - printbuf_linelen(out)); int spaces = max_t(int, 0, cur_tabstop(out) - printbuf_linelen(out));
......
...@@ -115,6 +115,7 @@ void bch2_printbuf_indent_add(struct printbuf *, unsigned); ...@@ -115,6 +115,7 @@ void bch2_printbuf_indent_add(struct printbuf *, unsigned);
void bch2_printbuf_indent_sub(struct printbuf *, unsigned); void bch2_printbuf_indent_sub(struct printbuf *, unsigned);
void bch2_prt_newline(struct printbuf *); void bch2_prt_newline(struct printbuf *);
void bch2_printbuf_strip_trailing_newline(struct printbuf *);
void bch2_prt_tab(struct printbuf *); void bch2_prt_tab(struct printbuf *);
void bch2_prt_tab_rjust(struct printbuf *); void bch2_prt_tab_rjust(struct printbuf *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment