Lines Matching full:out

33 int bch2_printbuf_make_room(struct printbuf *out, unsigned extra)  in bch2_printbuf_make_room()  argument
38 if (out->pos + extra <= out->size) in bch2_printbuf_make_room()
41 if (!out->heap_allocated) { in bch2_printbuf_make_room()
42 out->overflow = true; in bch2_printbuf_make_room()
46 unsigned new_size = roundup_pow_of_two(out->size + extra); in bch2_printbuf_make_room()
50 out->allocation_failure = true; in bch2_printbuf_make_room()
51 out->overflow = true; in bch2_printbuf_make_room()
59 char *buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_NOWAIT); in bch2_printbuf_make_room()
62 out->allocation_failure = true; in bch2_printbuf_make_room()
63 out->overflow = true; in bch2_printbuf_make_room()
67 out->buf = buf; in bch2_printbuf_make_room()
68 out->size = new_size; in bch2_printbuf_make_room()
72 static void printbuf_advance_pos(struct printbuf *out, unsigned len) in printbuf_advance_pos() argument
74 out->pos += min(len, printbuf_remaining(out)); in printbuf_advance_pos()
77 static void printbuf_insert_spaces(struct printbuf *out, unsigned pos, unsigned nr) in printbuf_insert_spaces() argument
79 unsigned move = out->pos - pos; in printbuf_insert_spaces()
81 bch2_printbuf_make_room(out, nr); in printbuf_insert_spaces()
83 if (pos + nr < out->size) in printbuf_insert_spaces()
84 memmove(out->buf + pos + nr, in printbuf_insert_spaces()
85 out->buf + pos, in printbuf_insert_spaces()
86 min(move, out->size - 1 - pos - nr)); in printbuf_insert_spaces()
88 if (pos < out->size) in printbuf_insert_spaces()
89 memset(out->buf + pos, ' ', min(nr, out->size - pos)); in printbuf_insert_spaces()
91 printbuf_advance_pos(out, nr); in printbuf_insert_spaces()
92 printbuf_nul_terminate_reserved(out); in printbuf_insert_spaces()
95 static void __printbuf_do_indent(struct printbuf *out, unsigned pos) in __printbuf_do_indent() argument
99 unsigned len = out->pos - pos; in __printbuf_do_indent()
100 char *p = out->buf + pos; in __printbuf_do_indent()
102 if (cur_tabstop(out)) { in __printbuf_do_indent()
107 pos = n - out->buf; in __printbuf_do_indent()
108 if (pos == out->pos) in __printbuf_do_indent()
114 out->last_newline = pos; in __printbuf_do_indent()
116 printbuf_insert_spaces(out, pos, out->indent); in __printbuf_do_indent()
118 pos = min(pos + out->indent, out->pos); in __printbuf_do_indent()
119 out->last_field = pos; in __printbuf_do_indent()
120 out->cur_tabstop = 0; in __printbuf_do_indent()
123 memmove(n, n + 1, out->pos - pos); in __printbuf_do_indent()
124 --out->pos; in __printbuf_do_indent()
125 pad = (int) cur_tabstop(out) - (int) __printbuf_linelen(out, pos); in __printbuf_do_indent()
127 printbuf_insert_spaces(out, out->last_field, pad); in __printbuf_do_indent()
131 out->last_field = pos; in __printbuf_do_indent()
132 out->cur_tabstop++; in __printbuf_do_indent()
135 pad = (int) cur_tabstop(out) - (int) __printbuf_linelen(out, pos) - 1; in __printbuf_do_indent()
138 printbuf_insert_spaces(out, pos, pad - 1); in __printbuf_do_indent()
141 memmove(n, n + 1, out->pos - pos); in __printbuf_do_indent()
142 --out->pos; in __printbuf_do_indent()
145 out->last_field = pos; in __printbuf_do_indent()
146 out->cur_tabstop++; in __printbuf_do_indent()
152 static inline void printbuf_do_indent(struct printbuf *out, unsigned pos) in printbuf_do_indent() argument
154 if (out->has_indent_or_tabstops && !out->suppress_indent_tabstop_handling) in printbuf_do_indent()
155 __printbuf_do_indent(out, pos); in printbuf_do_indent()
158 void bch2_prt_vprintf(struct printbuf *out, const char *fmt, va_list args) in bch2_prt_vprintf() argument
166 len = vsnprintf(out->buf + out->pos, printbuf_remaining_size(out), fmt, args2); in bch2_prt_vprintf()
168 } while (len > printbuf_remaining(out) && in bch2_prt_vprintf()
169 !bch2_printbuf_make_room(out, len)); in bch2_prt_vprintf()
171 unsigned indent_pos = out->pos; in bch2_prt_vprintf()
172 printbuf_advance_pos(out, len); in bch2_prt_vprintf()
173 printbuf_do_indent(out, indent_pos); in bch2_prt_vprintf()
176 void bch2_prt_printf(struct printbuf *out, const char *fmt, ...) in bch2_prt_printf() argument
183 len = vsnprintf(out->buf + out->pos, printbuf_remaining_size(out), fmt, args); in bch2_prt_printf()
185 } while (len > printbuf_remaining(out) && in bch2_prt_printf()
186 !bch2_printbuf_make_room(out, len)); in bch2_prt_printf()
188 unsigned indent_pos = out->pos; in bch2_prt_printf()
189 printbuf_advance_pos(out, len); in bch2_prt_printf()
190 printbuf_do_indent(out, indent_pos); in bch2_prt_printf()
319 void bch2_printbuf_strip_trailing_newline(struct printbuf *out) in bch2_printbuf_strip_trailing_newline() argument
321 for (int p = out->pos - 1; p >= 0; --p) { in bch2_printbuf_strip_trailing_newline()
322 if (out->buf[p] == '\n') { in bch2_printbuf_strip_trailing_newline()
323 out->pos = p; in bch2_printbuf_strip_trailing_newline()
326 if (out->buf[p] != ' ') in bch2_printbuf_strip_trailing_newline()
330 printbuf_nul_terminate_reserved(out); in bch2_printbuf_strip_trailing_newline()
333 static void __prt_tab(struct printbuf *out) in __prt_tab() argument
335 int spaces = max_t(int, 0, cur_tabstop(out) - printbuf_linelen(out)); in __prt_tab()
337 prt_chars(out, ' ', spaces); in __prt_tab()
339 out->last_field = out->pos; in __prt_tab()
340 out->cur_tabstop++; in __prt_tab()
345 * @out: printbuf to control
349 void bch2_prt_tab(struct printbuf *out) in bch2_prt_tab() argument
351 if (WARN_ON(!cur_tabstop(out))) in bch2_prt_tab()
354 __prt_tab(out); in bch2_prt_tab()
387 * @out: output printbuf
396 void bch2_prt_bytes_indented(struct printbuf *out, const char *str, unsigned count) in bch2_prt_bytes_indented() argument
398 unsigned indent_pos = out->pos; in bch2_prt_bytes_indented()
399 prt_bytes(out, str, count); in bch2_prt_bytes_indented()
400 printbuf_do_indent(out, indent_pos); in bch2_prt_bytes_indented()
404 * bch2_prt_human_readable_u64() - Print out a u64 in human readable units
405 * @out: output printbuf
408 * Units of 2^10 (default) or 10^3 are controlled via @out->si_units
410 void bch2_prt_human_readable_u64(struct printbuf *out, u64 v) in bch2_prt_human_readable_u64() argument
412 bch2_printbuf_make_room(out, 10); in bch2_prt_human_readable_u64()
413 unsigned len = string_get_size(v, 1, !out->si_units, in bch2_prt_human_readable_u64()
414 out->buf + out->pos, in bch2_prt_human_readable_u64()
415 printbuf_remaining_size(out)); in bch2_prt_human_readable_u64()
416 printbuf_advance_pos(out, len); in bch2_prt_human_readable_u64()
420 * bch2_prt_human_readable_s64() - Print out a s64 in human readable units
421 * @out: output printbuf
424 * Units of 2^10 (default) or 10^3 are controlled via @out->si_units
426 void bch2_prt_human_readable_s64(struct printbuf *out, s64 v) in bch2_prt_human_readable_s64() argument
429 prt_char(out, '-'); in bch2_prt_human_readable_s64()
430 bch2_prt_human_readable_u64(out, abs(v)); in bch2_prt_human_readable_s64()
434 * bch2_prt_units_u64() - Print out a u64 according to printbuf unit options
435 * @out: output printbuf
441 void bch2_prt_units_u64(struct printbuf *out, u64 v) in bch2_prt_units_u64() argument
443 if (out->human_readable_units) in bch2_prt_units_u64()
444 bch2_prt_human_readable_u64(out, v); in bch2_prt_units_u64()
446 bch2_prt_printf(out, "%llu", v); in bch2_prt_units_u64()
450 * bch2_prt_units_s64() - Print out a s64 according to printbuf unit options
451 * @out: output printbuf
457 void bch2_prt_units_s64(struct printbuf *out, s64 v) in bch2_prt_units_s64() argument
460 prt_char(out, '-'); in bch2_prt_units_s64()
461 bch2_prt_units_u64(out, abs(v)); in bch2_prt_units_s64()
464 void bch2_prt_string_option(struct printbuf *out, in bch2_prt_string_option() argument
469 bch2_prt_printf(out, i == selected ? "[%s] " : "%s ", list[i]); in bch2_prt_string_option()
472 void bch2_prt_bitflags(struct printbuf *out, in bch2_prt_bitflags() argument
483 bch2_prt_printf(out, ","); in bch2_prt_bitflags()
485 bch2_prt_printf(out, "%s", list[bit]); in bch2_prt_bitflags()
490 void bch2_prt_bitflags_vector(struct printbuf *out, in bch2_prt_bitflags_vector() argument
505 bch2_prt_printf(out, ","); in bch2_prt_bitflags_vector()
507 bch2_prt_printf(out, "%s", list[i]); in bch2_prt_bitflags_vector()