fs/iomap/seek.c
Source file repositories/reference/linux-study-clean/fs/iomap/seek.c
File Facts
- System
- Linux kernel
- Corpus path
fs/iomap/seek.c- Extension
.c- Size
- 2377 bytes
- Lines
- 101
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/iomap.hlinux/pagemap.h
Detected Declarations
function Copyrightfunction iomap_seek_holefunction iomap_seek_data_iterfunction iomap_seek_dataexport iomap_seek_holeexport iomap_seek_data
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2017 Red Hat, Inc.
* Copyright (c) 2018-2021 Christoph Hellwig.
*/
#include <linux/iomap.h>
#include <linux/pagemap.h>
static int iomap_seek_hole_iter(struct iomap_iter *iter,
loff_t *hole_pos)
{
loff_t length = iomap_length(iter);
switch (iter->iomap.type) {
case IOMAP_UNWRITTEN:
*hole_pos = mapping_seek_hole_data(iter->inode->i_mapping,
iter->pos, iter->pos + length, SEEK_HOLE);
if (*hole_pos == iter->pos + length)
return iomap_iter_advance(iter, length);
return 0;
case IOMAP_HOLE:
*hole_pos = iter->pos;
return 0;
default:
return iomap_iter_advance(iter, length);
}
}
loff_t
iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops)
{
loff_t size = i_size_read(inode);
struct iomap_iter iter = {
.inode = inode,
.pos = pos,
.flags = IOMAP_REPORT,
};
int ret;
/* Nothing to be found before or beyond the end of the file. */
if (pos < 0 || pos >= size)
return -ENXIO;
iter.len = size - pos;
while ((ret = iomap_iter(&iter, ops)) > 0)
iter.status = iomap_seek_hole_iter(&iter, &pos);
if (ret < 0)
return ret;
if (iter.len) /* found hole before EOF */
return pos;
return size;
}
EXPORT_SYMBOL_GPL(iomap_seek_hole);
static int iomap_seek_data_iter(struct iomap_iter *iter,
loff_t *hole_pos)
{
loff_t length = iomap_length(iter);
switch (iter->iomap.type) {
case IOMAP_HOLE:
return iomap_iter_advance(iter, length);
case IOMAP_UNWRITTEN:
*hole_pos = mapping_seek_hole_data(iter->inode->i_mapping,
iter->pos, iter->pos + length, SEEK_DATA);
if (*hole_pos < 0)
return iomap_iter_advance(iter, length);
return 0;
default:
*hole_pos = iter->pos;
return 0;
}
}
loff_t
iomap_seek_data(struct inode *inode, loff_t pos, const struct iomap_ops *ops)
{
loff_t size = i_size_read(inode);
struct iomap_iter iter = {
.inode = inode,
.pos = pos,
.flags = IOMAP_REPORT,
};
int ret;
/* Nothing to be found before or beyond the end of the file. */
if (pos < 0 || pos >= size)
return -ENXIO;
iter.len = size - pos;
Annotation
- Immediate include surface: `linux/iomap.h`, `linux/pagemap.h`.
- Detected declarations: `function Copyright`, `function iomap_seek_hole`, `function iomap_seek_data_iter`, `function iomap_seek_data`, `export iomap_seek_hole`, `export iomap_seek_data`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.