On Tue, May 21, 2002 at 02:35:24PM +0200, Mikael Pettersson wrote:
> I haven't got a clue on how to program Linux' block I/O interfaces.
> Show me how to do a modern equivalent of getblk(dev,0,1024) + waiting
> for the operation to complete and I'll update the patch ASAP.
I think something like the following should do it.
(WARNING: entirely untested)
static void io_done(struct bio *bio)
{
complete((struct completion *)bio->bi_private);
}
static int doio(struct block_device *bdev, size_t size)
{
struct completion comp;
struct page * page;
struct bio * bio;
bio = bio_alloc(GFP_KERNEL, 1);
if (!bio)
return -ENOMEM;
page = alloc_page(GFP_KERNEL);
if (!page) {
bio_put(bio);
return -ENOMEM;
}
bio->bi_sector = 0;
bio->bi_bdev = bdev;
bio->bi_io_vec[0].bv_page = page;
bio->bi_io_vec[0].bv_len = size;
bio->bi_io_vec[0].bv_offset = 0;
bio->bi_vcnt = 1;
bio->bi_idx = 0;
bio->bi_size = LOGPSIZE;
bio->bi_end_io = io_done;
bio->bi_private = &complete;
submit_bio(READ, bio);
run_task_queue(&tq_disk);
wait_for_completion(&comp);
bio_put(bio);
__free_page(page);
return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Thu May 23 2002 - 22:00:21 EST