This returns the number of user segments in an iov_iter. The input can either be an ITER_IOVEC, where it'll return the number of iovecs. Or it can be an ITER_UBUF, in which case the number of segments is always 1. Outside of those two, no user backed iterators exist. Just return 0 for those. Signed-off-by: Jens Axboe <axboe@xxxxxxxxx> --- include/linux/uio.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/uio.h b/include/linux/uio.h index 3b4403efcce1..8ba4d61e9e9b 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -168,6 +168,15 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) } } +static inline int iovec_nr_user_vecs(const struct iov_iter *iter) +{ + if (iter_is_ubuf(iter)) + return 1; + else if (iter->iter_type == ITER_IOVEC) + return iter->nr_segs; + return 0; +} + size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i); void iov_iter_advance(struct iov_iter *i, size_t bytes); -- 2.39.2