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);
38 loff_t length = size - offset;
41 /* Nothing to be found before or beyond the end of the file. */
42 if (offset < 0 || offset >= size)
46 ret = iomap_apply(inode, offset, length, IOMAP_REPORT, ops,
47 &offset, iomap_seek_hole_actor);
59 EXPORT_SYMBOL_GPL(iomap_seek_hole);
62 iomap_seek_data_actor(struct inode *inode, loff_t start, loff_t length,
63 void *data, struct iomap *iomap, struct iomap *srcmap)
65 loff_t offset = start;
67 switch (iomap->type) {
71 offset = mapping_seek_hole_data(inode->i_mapping, start,
72 start + length, SEEK_DATA);
77 *(loff_t *)data = offset;
83 iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
85 loff_t size = i_size_read(inode);
86 loff_t length = size - offset;
89 /* Nothing to be found before or beyond the end of the file. */
90 if (offset < 0 || offset >= size)
94 ret = iomap_apply(inode, offset, length, IOMAP_REPORT, ops,
95 &offset, iomap_seek_data_actor);
109 EXPORT_SYMBOL_GPL(iomap_seek_data);