/* copy the kernel address into a bio suitable for io to a block device. Returns an error pointer in case of error.  */
struct bio* bio_copy_kern(struct request_queue *q, void *data, unsigned int len, gfp_t gfp_mask, int reading)
/* copy the kernel address into a bio suitable for io to a block device. Returns an error pointer in case of error.  */
struct bio* bio_copy_kern(struct request_queue *q, void *data, unsigned int len, gfp_t gfp_mask, int reading)
{
	struct bio *bio;
	struct bio_vec *bvec;
	int i;
	bio = bio_copy_user(q, NULL, (unsigned long)data, len, 1, gfp_mask);
	if (IS_ERR(bio))
		return bio;
	if (!reading) {
		void *p = data;
		bio_for_each_segment(bvec, bio, i) {
			char *addr = page_address(bvec->bv_page);
			memcpy(addr, p, bvec->bv_len);
			p += bvec->bv_len;
		}
	}
	bio->bi_end_io = bio_copy_kern_endio;
	return bio;
}