1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2017 Red Hat, Inc.
4 * Copyright (c) 2018 Christoph Hellwig.
6 #include <linux/module.h>
7 #include <linux/compiler.h>
9 #include <linux/iomap.h>
10 #include <linux/pagemap.h>
11 #include <linux/pagevec.h>
14 iomap_seek_hole_actor(struct inode *inode, loff_t start, loff_t length,
15 void *data, struct iomap *iomap, struct iomap *srcmap)
17 loff_t offset = start;
19 switch (iomap->type) {
21 offset = mapping_seek_hole_data(inode->i_mapping, start,
22 start + length, SEEK_HOLE);
23 if (offset == start + length)
27 *(loff_t *)data = offset;
35 iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
37 loff_t size = i_size_read(inode);
40 /* Nothing to be found before or beyond the end of the file. */
41 if (offset < 0 || offset >= size)
44 while (offset < size) {
45 ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT,
46 ops, &offset, iomap_seek_hole_actor);
56 EXPORT_SYMBOL_GPL(iomap_seek_hole);
59 iomap_seek_data_actor(struct inode *inode, loff_t start, loff_t length,
60 void *data, struct iomap *iomap, struct iomap *srcmap)
62 loff_t offset = start;
64 switch (iomap->type) {
68 offset = mapping_seek_hole_data(inode->i_mapping, start,
69 start + length, SEEK_DATA);
74 *(loff_t *)data = offset;
80 iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
82 loff_t size = i_size_read(inode);
85 /* Nothing to be found before or beyond the end of the file. */
86 if (offset < 0 || offset >= size)
89 while (offset < size) {
90 ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT,
91 ops, &offset, iomap_seek_data_actor);
99 /* We've reached the end of the file without finding data */
102 EXPORT_SYMBOL_GPL(iomap_seek_data);