.. | .. |
---|
91 | 91 | |
---|
92 | 92 | return ret; |
---|
93 | 93 | } |
---|
| 94 | +EXPORT_SYMBOL_GPL(seq_buf_printf); |
---|
94 | 95 | |
---|
95 | 96 | #ifdef CONFIG_BINARY_PRINTF |
---|
96 | 97 | /** |
---|
.. | .. |
---|
140 | 141 | */ |
---|
141 | 142 | int seq_buf_puts(struct seq_buf *s, const char *str) |
---|
142 | 143 | { |
---|
143 | | - unsigned int len = strlen(str); |
---|
| 144 | + size_t len = strlen(str); |
---|
144 | 145 | |
---|
145 | 146 | WARN_ON(s->size == 0); |
---|
146 | 147 | |
---|
.. | .. |
---|
332 | 333 | s->readpos += cnt; |
---|
333 | 334 | return cnt; |
---|
334 | 335 | } |
---|
| 336 | + |
---|
| 337 | +/** |
---|
| 338 | + * seq_buf_hex_dump - print formatted hex dump into the sequence buffer |
---|
| 339 | + * @s: seq_buf descriptor |
---|
| 340 | + * @prefix_str: string to prefix each line with; |
---|
| 341 | + * caller supplies trailing spaces for alignment if desired |
---|
| 342 | + * @prefix_type: controls whether prefix of an offset, address, or none |
---|
| 343 | + * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
---|
| 344 | + * @rowsize: number of bytes to print per line; must be 16 or 32 |
---|
| 345 | + * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
---|
| 346 | + * @buf: data blob to dump |
---|
| 347 | + * @len: number of bytes in the @buf |
---|
| 348 | + * @ascii: include ASCII after the hex output |
---|
| 349 | + * |
---|
| 350 | + * Function is an analogue of print_hex_dump() and thus has similar interface. |
---|
| 351 | + * |
---|
| 352 | + * linebuf size is maximal length for one line. |
---|
| 353 | + * 32 * 3 - maximum bytes per line, each printed into 2 chars + 1 for |
---|
| 354 | + * separating space |
---|
| 355 | + * 2 - spaces separating hex dump and ascii representation |
---|
| 356 | + * 32 - ascii representation |
---|
| 357 | + * 1 - terminating '\0' |
---|
| 358 | + * |
---|
| 359 | + * Returns zero on success, -1 on overflow |
---|
| 360 | + */ |
---|
| 361 | +int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str, int prefix_type, |
---|
| 362 | + int rowsize, int groupsize, |
---|
| 363 | + const void *buf, size_t len, bool ascii) |
---|
| 364 | +{ |
---|
| 365 | + const u8 *ptr = buf; |
---|
| 366 | + int i, linelen, remaining = len; |
---|
| 367 | + unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
---|
| 368 | + int ret; |
---|
| 369 | + |
---|
| 370 | + if (rowsize != 16 && rowsize != 32) |
---|
| 371 | + rowsize = 16; |
---|
| 372 | + |
---|
| 373 | + for (i = 0; i < len; i += rowsize) { |
---|
| 374 | + linelen = min(remaining, rowsize); |
---|
| 375 | + remaining -= rowsize; |
---|
| 376 | + |
---|
| 377 | + hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
---|
| 378 | + linebuf, sizeof(linebuf), ascii); |
---|
| 379 | + |
---|
| 380 | + switch (prefix_type) { |
---|
| 381 | + case DUMP_PREFIX_ADDRESS: |
---|
| 382 | + ret = seq_buf_printf(s, "%s%p: %s\n", |
---|
| 383 | + prefix_str, ptr + i, linebuf); |
---|
| 384 | + break; |
---|
| 385 | + case DUMP_PREFIX_OFFSET: |
---|
| 386 | + ret = seq_buf_printf(s, "%s%.8x: %s\n", |
---|
| 387 | + prefix_str, i, linebuf); |
---|
| 388 | + break; |
---|
| 389 | + default: |
---|
| 390 | + ret = seq_buf_printf(s, "%s%s\n", prefix_str, linebuf); |
---|
| 391 | + break; |
---|
| 392 | + } |
---|
| 393 | + if (ret) |
---|
| 394 | + return ret; |
---|
| 395 | + } |
---|
| 396 | + return 0; |
---|
| 397 | +} |
---|