lib/seq_buf.c
Source file repositories/reference/linux-study-clean/lib/seq_buf.c
File Facts
- System
- Linux kernel
- Corpus path
lib/seq_buf.c- Extension
.c- Size
- 11242 bytes
- Lines
- 440
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bug.hlinux/err.hlinux/export.hlinux/hex.hlinux/minmax.hlinux/printk.hlinux/seq_buf.hlinux/seq_file.hlinux/sprintf.hlinux/string.hlinux/types.hlinux/uaccess.h
Detected Declarations
function Copyrightfunction seq_buf_print_seqfunction vnprintffunction printffunction printkfunction seq_buf_bprintffunction seq_buf_putsfunction seq_buf_putcfunction strcpyfunction seq_buf_putmemfunction seq_buf_pathfunction bufferfunction print_hex_dumpexport seq_buf_printfexport seq_buf_do_printkexport seq_buf_putsexport seq_buf_putcexport seq_buf_putmem_hex
Annotated Snippet
if (s->len + len < s->size) {
s->len += len;
return 0;
}
}
seq_buf_set_overflow(s);
return -1;
}
/**
* seq_buf_printf - sequence printing of information
* @s: seq_buf descriptor
* @fmt: printf format string
*
* Writes a printf() format into the sequence buffer.
*
* Returns: zero on success, -1 on overflow.
*/
int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = seq_buf_vprintf(s, fmt, ap);
va_end(ap);
return ret;
}
EXPORT_SYMBOL_GPL(seq_buf_printf);
/**
* seq_buf_do_printk - printk() seq_buf line by line
* @s: seq_buf descriptor
* @lvl: printk level
*
* printk()-s a multi-line sequential buffer line by line. The function
* makes sure that the buffer in @s is NUL-terminated and safe to read
* as a string.
*/
void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
{
const char *start, *lf;
if (s->size == 0 || s->len == 0)
return;
start = seq_buf_str(s);
while ((lf = strchr(start, '\n'))) {
int len = lf - start + 1;
printk("%s%.*s", lvl, len, start);
start = ++lf;
}
/* No trailing LF */
if (start < s->buffer + s->len)
printk("%s%s\n", lvl, start);
}
EXPORT_SYMBOL_GPL(seq_buf_do_printk);
#ifdef CONFIG_BINARY_PRINTF
/**
* seq_buf_bprintf - Write the printf string from binary arguments
* @s: seq_buf descriptor
* @fmt: The format string for the @binary arguments
* @binary: The binary arguments for @fmt.
*
* When recording in a fast path, a printf may be recorded with just
* saving the format and the arguments as they were passed to the
* function, instead of wasting cycles converting the arguments into
* ASCII characters. Instead, the arguments are saved in a 32 bit
* word array that is defined by the format string constraints.
*
* This function will take the format and the binary array and finish
* the conversion into the ASCII string within the buffer.
*
* Returns: zero on success, -1 on overflow.
*/
int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary)
{
unsigned int len = seq_buf_buffer_left(s);
int ret;
WARN_ON(s->size == 0);
if (s->len < s->size) {
ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
if (s->len + ret < s->size) {
s->len += ret;
Annotation
- Immediate include surface: `linux/bug.h`, `linux/err.h`, `linux/export.h`, `linux/hex.h`, `linux/minmax.h`, `linux/printk.h`, `linux/seq_buf.h`, `linux/seq_file.h`.
- Detected declarations: `function Copyright`, `function seq_buf_print_seq`, `function vnprintf`, `function printf`, `function printk`, `function seq_buf_bprintf`, `function seq_buf_puts`, `function seq_buf_putc`, `function strcpy`, `function seq_buf_putmem`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.