fs/seq_file.c
Source file repositories/reference/linux-study-clean/fs/seq_file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/seq_file.c- Extension
.c- Size
- 26196 bytes
- Lines
- 1145
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cache.hlinux/fs.hlinux/export.hlinux/hex.hlinux/seq_file.hlinux/vmalloc.hlinux/slab.hlinux/cred.hlinux/mm.hlinux/printk.hlinux/string_helpers.hlinux/uio.hlinux/uaccess.hasm/page.h
Detected Declarations
function seq_set_overflowfunction seq_openfunction traversefunction seq_readfunction seq_read_iterfunction seq_lseekfunction seq_releasefunction classfunction seq_vprintffunction seq_printffunction seq_bprintffunction seq_pathfunction seq_file_pathfunction seq_path_rootfunction seq_dentryfunction single_stopfunction single_open_sizefunction single_releasefunction seq_release_privatefunction seq_open_privatefunction seq_putcfunction __seq_putsfunction printffunction seq_put_decimal_ullfunction seq_put_hex_llfunction seq_put_decimal_llfunction seq_writefunction seq_padfunction seq_hex_dumpfunction rcu_read_lockfunction rcu_read_lockfunction rcu_read_lockfunction seq_hlist_start_percpufunction for_each_possible_cpufunction seq_hlist_next_percpufunction seq_file_initexport seq_openexport seq_readexport seq_read_iterexport seq_lseekexport seq_releaseexport seq_escape_memexport seq_vprintfexport seq_printfexport seq_bprintfexport mangle_pathexport seq_pathexport seq_file_path
Annotated Snippet
if (unlikely(error)) {
error = 0;
m->count = 0;
}
if (seq_has_overflowed(m))
goto Eoverflow;
p = m->op->next(m, p, &m->index);
if (pos + m->count > offset) {
m->from = offset - pos;
m->count -= m->from;
break;
}
pos += m->count;
m->count = 0;
if (pos == offset)
break;
}
m->op->stop(m, p);
return error;
Eoverflow:
m->op->stop(m, p);
kvfree(m->buf);
m->count = 0;
m->buf = seq_buf_alloc(m->size <<= 1);
return !m->buf ? -ENOMEM : -EAGAIN;
}
/**
* seq_read - ->read() method for sequential files.
* @file: the file to read from
* @buf: the buffer to read to
* @size: the maximum number of bytes to read
* @ppos: the current position in the file
*
* Ready-made ->f_op->read()
*/
ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
struct iovec iov = { .iov_base = buf, .iov_len = size};
struct kiocb kiocb;
struct iov_iter iter;
ssize_t ret;
init_sync_kiocb(&kiocb, file);
iov_iter_init(&iter, ITER_DEST, &iov, 1, size);
kiocb.ki_pos = *ppos;
ret = seq_read_iter(&kiocb, &iter);
*ppos = kiocb.ki_pos;
return ret;
}
EXPORT_SYMBOL(seq_read);
/*
* Ready-made ->f_op->read_iter()
*/
ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
{
struct seq_file *m = iocb->ki_filp->private_data;
size_t copied = 0;
size_t n;
void *p;
int err = 0;
if (!iov_iter_count(iter))
return 0;
mutex_lock(&m->lock);
/*
* if request is to read from zero offset, reset iterator to first
* record as it might have been already advanced by previous requests
*/
if (iocb->ki_pos == 0) {
m->index = 0;
m->count = 0;
}
/* Don't assume ki_pos is where we left it */
if (unlikely(iocb->ki_pos != m->read_pos)) {
while ((err = traverse(m, iocb->ki_pos)) == -EAGAIN)
;
if (err) {
/* With prejudice... */
m->read_pos = 0;
m->index = 0;
m->count = 0;
goto Done;
} else {
Annotation
- Immediate include surface: `linux/cache.h`, `linux/fs.h`, `linux/export.h`, `linux/hex.h`, `linux/seq_file.h`, `linux/vmalloc.h`, `linux/slab.h`, `linux/cred.h`.
- Detected declarations: `function seq_set_overflow`, `function seq_open`, `function traverse`, `function seq_read`, `function seq_read_iter`, `function seq_lseek`, `function seq_release`, `function class`, `function seq_vprintf`, `function seq_printf`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.