include/linux/seq_buf.h
Source file repositories/reference/linux-study-clean/include/linux/seq_buf.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/seq_buf.h- Extension
.h- Size
- 4682 bytes
- Lines
- 194
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bug.hlinux/minmax.hlinux/seq_file.hlinux/types.h
Detected Declarations
struct seq_buffunction seq_buf_clearfunction seq_buf_initfunction seq_buf_has_overflowedfunction seq_buf_set_overflowfunction seq_buf_buffer_leftfunction seq_buf_usedfunction seq_buf_get_buffunction seq_buf_get_buffunction seq_buf_pop
Annotated Snippet
struct seq_buf {
char *buffer;
size_t size;
size_t len;
};
#define DECLARE_SEQ_BUF(NAME, SIZE) \
struct seq_buf NAME = { \
.buffer = (char[SIZE]) { 0 }, \
.size = SIZE, \
}
static inline void seq_buf_clear(struct seq_buf *s)
{
s->len = 0;
if (s->size)
s->buffer[0] = '\0';
}
static inline void
seq_buf_init(struct seq_buf *s, char *buf, unsigned int size)
{
s->buffer = buf;
s->size = size;
seq_buf_clear(s);
}
/*
* seq_buf have a buffer that might overflow. When this happens
* len is set to be greater than size.
*/
static inline bool
seq_buf_has_overflowed(struct seq_buf *s)
{
return s->len > s->size;
}
static inline void
seq_buf_set_overflow(struct seq_buf *s)
{
s->len = s->size + 1;
}
/*
* How much buffer is left on the seq_buf?
*/
static inline unsigned int
seq_buf_buffer_left(struct seq_buf *s)
{
if (seq_buf_has_overflowed(s))
return 0;
return s->size - s->len;
}
/* How much buffer was written? */
static inline unsigned int seq_buf_used(struct seq_buf *s)
{
return min(s->len, s->size);
}
/**
* seq_buf_str - get NUL-terminated C string from seq_buf
* @s: the seq_buf handle
*
* This makes sure that the buffer in @s is NUL-terminated and
* safe to read as a string.
*
* Note, if this is called when the buffer has overflowed, then
* the last byte of the buffer is zeroed, and the len will still
* point passed it.
*
* After this function is called, s->buffer is safe to use
* in string operations.
*
* Returns: @s->buf after making sure it is terminated.
*/
static inline const char *seq_buf_str(struct seq_buf *s)
{
if (WARN_ON(s->size == 0))
return "";
if (seq_buf_buffer_left(s))
s->buffer[s->len] = 0;
else
s->buffer[s->size - 1] = 0;
return s->buffer;
}
Annotation
- Immediate include surface: `linux/bug.h`, `linux/minmax.h`, `linux/seq_file.h`, `linux/types.h`.
- Detected declarations: `struct seq_buf`, `function seq_buf_clear`, `function seq_buf_init`, `function seq_buf_has_overflowed`, `function seq_buf_set_overflow`, `function seq_buf_buffer_left`, `function seq_buf_used`, `function seq_buf_get_buf`, `function seq_buf_get_buf`, `function seq_buf_pop`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
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.