/* * Note: output buffer must be freeable with kfree(), it's not required * that the user use printbuf_exit().
*/ char *buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_NOWAIT);
/** * bch2_printbuf_str() - returns printbuf's buf as a C string, guaranteed to be * null terminated * @buf: printbuf to terminate * Returns: Printbuf contents, as a nul terminated C string
*/ constchar *bch2_printbuf_str(conststruct printbuf *buf)
{ /* * If we've written to a printbuf then it's guaranteed to be a null * terminated string - but if we haven't, then we might not have * allocated a buffer at all:
*/ return buf->pos
? buf->buf
: "";
}
/** * bch2_printbuf_exit() - exit a printbuf, freeing memory it owns and poisoning it * against accidental use. * @buf: printbuf to exit
*/ void bch2_printbuf_exit(struct printbuf *buf)
{ if (buf->heap_allocated) {
kfree(buf->buf);
buf->buf = ERR_PTR(-EINTR); /* poison value */
}
}
void bch2_printbuf_tabstop_pop(struct printbuf *buf)
{ if (buf->nr_tabstops)
--buf->nr_tabstops;
}
/* * bch2_printbuf_tabstop_set() - add a tabstop, n spaces from the previous tabstop * * @buf: printbuf to control * @spaces: number of spaces from previous tabpstop * * In the future this function may allocate memory if setting more than * PRINTBUF_INLINE_TABSTOPS or setting tabstops more than 255 spaces from start * of line.
*/ int bch2_printbuf_tabstop_push(struct printbuf *buf, unsigned spaces)
{ unsigned prev_tabstop = buf->nr_tabstops
? buf->_tabstops[buf->nr_tabstops - 1]
: 0;
if (WARN_ON(buf->nr_tabstops >= ARRAY_SIZE(buf->_tabstops))) return -EINVAL;
/** * bch2_printbuf_indent_add() - add to the current indent level * * @buf: printbuf to control * @spaces: number of spaces to add to the current indent level * * Subsequent lines, and the current line if the output position is at the start * of the current line, will be indented by @spaces more spaces.
*/ void bch2_printbuf_indent_add(struct printbuf *buf, unsigned spaces)
{ if (WARN_ON_ONCE(buf->indent + spaces < buf->indent))
spaces = 0;
/** * bch2_printbuf_indent_add_nextline() - add to the current indent level for * subsequent lines * * @buf: printbuf to control * @spaces: number of spaces to add to the current indent level * * Subsequent lines - not the current line - will be indented by @spaces more * spaces.
*/ void bch2_printbuf_indent_add_nextline(struct printbuf *buf, unsigned spaces)
{ if (WARN_ON_ONCE(buf->indent + spaces < buf->indent))
spaces = 0;
/** * bch2_printbuf_indent_sub() - subtract from the current indent level * * @buf: printbuf to control * @spaces: number of spaces to subtract from the current indent level * * Subsequent lines, and the current line if the output position is at the start * of the current line, will be indented by @spaces less spaces.
*/ void bch2_printbuf_indent_sub(struct printbuf *buf, unsigned spaces)
{ if (WARN_ON_ONCE(spaces > buf->indent))
spaces = buf->indent;
/** * bch2_prt_tab() - Advance printbuf to the next tabstop * @out: printbuf to control * * Advance output to the next tabstop by printing spaces.
*/ void bch2_prt_tab(struct printbuf *out)
{ if (WARN_ON(!cur_tabstop(out))) return;
__prt_tab(out);
}
staticvoid __prt_tab_rjust(struct printbuf *buf)
{ int pad = (int) cur_tabstop(buf) - (int) printbuf_linelen(buf); if (pad > 0)
printbuf_insert_spaces(buf, buf->last_field, pad);
buf->last_field = buf->pos;
buf->cur_tabstop++;
}
/** * bch2_prt_tab_rjust - Advance printbuf to the next tabstop, right justifying * previous output * * @buf: printbuf to control * * Advance output to the next tabstop by inserting spaces immediately after the * previous tabstop, right justifying previously outputted text.
*/ void bch2_prt_tab_rjust(struct printbuf *buf)
{ if (WARN_ON(!cur_tabstop(buf))) return;
__prt_tab_rjust(buf);
}
/** * bch2_prt_bytes_indented() - Print an array of chars, handling embedded control characters * * @out: output printbuf * @str: string to print * @count: number of bytes to print * * The following contol characters are handled as so: * \n: prt_newline newline that obeys current indent level * \t: prt_tab advance to next tabstop * \r: prt_tab_rjust advance to next tabstop, with right justification
*/ void bch2_prt_bytes_indented(struct printbuf *out, constchar *str, unsigned count)
{ unsigned indent_pos = out->pos;
prt_bytes(out, str, count);
printbuf_do_indent(out, indent_pos);
}
/** * bch2_prt_human_readable_u64() - Print out a u64 in human readable units * @out: output printbuf * @v: integer to print * * Units of 2^10 (default) or 10^3 are controlled via @out->si_units
*/ void bch2_prt_human_readable_u64(struct printbuf *out, u64 v)
{
bch2_printbuf_make_room(out, 10); unsigned len = string_get_size(v, 1, !out->si_units,
out->buf + out->pos,
printbuf_remaining_size(out));
printbuf_advance_pos(out, len);
}
/** * bch2_prt_human_readable_s64() - Print out a s64 in human readable units * @out: output printbuf * @v: integer to print * * Units of 2^10 (default) or 10^3 are controlled via @out->si_units
*/ void bch2_prt_human_readable_s64(struct printbuf *out, s64 v)
{ if (v < 0)
prt_char(out, '-');
bch2_prt_human_readable_u64(out, abs(v));
}
/** * bch2_prt_units_u64() - Print out a u64 according to printbuf unit options * @out: output printbuf * @v: integer to print * * Units are either raw (default), or human reabable units (controlled via * @buf->human_readable_units)
*/ void bch2_prt_units_u64(struct printbuf *out, u64 v)
{ if (out->human_readable_units)
bch2_prt_human_readable_u64(out, v); else
bch2_prt_printf(out, "%llu", v);
}
/** * bch2_prt_units_s64() - Print out a s64 according to printbuf unit options * @out: output printbuf * @v: integer to print * * Units are either raw (default), or human reabable units (controlled via * @buf->human_readable_units)
*/ void bch2_prt_units_s64(struct printbuf *out, s64 v)
{ if (v < 0)
prt_char(out, '-');
bch2_prt_units_u64(out, abs(v));
}
void bch2_prt_string_option(struct printbuf *out, constchar * const list[],
size_t selected)
{ for (size_t i = 0; list[i]; i++)
bch2_prt_printf(out, i == selected ? "[%s] " : "%s ", list[i]);
}
void bch2_prt_bitflags(struct printbuf *out, constchar * const list[], u64 flags)
{ unsigned bit, nr = 0; bool first = true;
while (list[nr])
nr++;
while (flags && (bit = __ffs64(flags)) < nr) { if (!first)
bch2_prt_printf(out, ",");
first = false;
bch2_prt_printf(out, "%s", list[bit]);
flags ^= BIT_ULL(bit);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.