]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bcachefs: bch2_printbuf_strip_trailing_newline()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 27 May 2024 02:20:34 +0000 (22:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 14 Jul 2024 23:00:12 +0000 (19:00 -0400)
Add a new helper to fix inode_to_text()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/inode.c
fs/bcachefs/printbuf.c
fs/bcachefs/printbuf.h

index 4fd8c736744adf405473b3f5baf9c3c91fd24a53..84d5385e1046700a25ab7cc4ef96ef79a7d765cb 100644 (file)
@@ -551,6 +551,8 @@ static void __bch2_inode_unpacked_to_text(struct printbuf *out,
        prt_printf(out, #_name "=%llu\n", (u64) inode->_name);
        BCH_INODE_FIELDS_v3()
 #undef  x
+
+       bch2_printbuf_strip_trailing_newline(out);
        printbuf_indent_sub(out, 2);
 }
 
index 9f529e4c1b16a8e7de6fdefdc074e9c32f697036..4cf5a2af1e6ff0703c8e6b06c7bf694316b8fa06 100644 (file)
@@ -316,6 +316,20 @@ void bch2_prt_newline(struct printbuf *buf)
        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)
 {
        int spaces = max_t(int, 0, cur_tabstop(out) - printbuf_linelen(out));
index 9ecc56bc96359ab9b752189bc787cf0f61e5dbc8..1d570387b77f19f03d4fc4b1e39d8276c9b85860 100644 (file)
@@ -115,6 +115,7 @@ void bch2_printbuf_indent_add(struct printbuf *, unsigned);
 void bch2_printbuf_indent_sub(struct printbuf *, unsigned);
 
 void bch2_prt_newline(struct printbuf *);
+void bch2_printbuf_strip_trailing_newline(struct printbuf *);
 void bch2_prt_tab(struct printbuf *);
 void bch2_prt_tab_rjust(struct printbuf *);