4 * Copyright (C) 2001 Ming Lei <ming.lei@canonical.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public Licens
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
20 #ifndef __LINUX_BVEC_ITER_H
21 #define __LINUX_BVEC_ITER_H
23 #include <linux/blk_types.h>
26 * various member access, note that bio_data should of course not be used
27 * on highmem page vectors
29 #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx])
31 #define bvec_iter_page(bvec, iter) \
32 (__bvec_iter_bvec((bvec), (iter))->bv_page)
34 #define bvec_iter_len(bvec, iter) \
36 __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done)
38 #define bvec_iter_offset(bvec, iter) \
39 (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done)
41 #define bvec_iter_bvec(bvec, iter) \
43 .bv_page = bvec_iter_page((bvec), (iter)), \
44 .bv_len = bvec_iter_len((bvec), (iter)), \
45 .bv_offset = bvec_iter_offset((bvec), (iter)), \
48 static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter,
51 WARN_ONCE(bytes > iter->bi_size,
52 "Attempted to advance past end of bvec iter\n");
55 unsigned len = min(bytes, bvec_iter_len(bv, *iter));
59 iter->bi_bvec_done += len;
61 if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) {
62 iter->bi_bvec_done = 0;
68 #define for_each_bvec(bvl, bio_vec, iter, start) \
69 for (iter = (start); \
71 ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \
72 bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len))
74 #endif /* __LINUX_BVEC_ITER_H */