9
0
Fork 0

block: implement block_read/block_write functions

Some drivers use blk->ops->read/write. This bypasses the caching block
layer and was never intended like this. The upper API to the block layer
is the cdev layer. This patch adds block_read and block_write functions
and uses them where appropriate.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2013-04-04 13:59:21 +02:00
parent b5c4e238d3
commit e82e40523f
4 changed files with 33 additions and 3 deletions

View File

@ -387,3 +387,25 @@ int blockdevice_unregister(struct block_device *blk)
return 0;
}
int block_read(struct block_device *blk, void *buf, int block, int num_blocks)
{
int ret;
ret = cdev_read(&blk->cdev, buf,
num_blocks << blk->blockbits,
(loff_t)block << blk->blockbits, 0);
return ret < 0 ? ret : 0;
}
int block_write(struct block_device *blk, void *buf, int block, int num_blocks)
{
int ret;
ret = cdev_write(&blk->cdev, buf,
num_blocks << blk->blockbits,
(loff_t)block << blk->blockbits, 0);
return ret < 0 ? ret : 0;
}

View File

@ -128,7 +128,7 @@ int parse_partition_table(struct block_device *blk)
pdesc = xzalloc(sizeof(*pdesc));
buf = dma_alloc(SECTOR_SIZE * 2);
rc = blk->ops->read(blk, buf, 0, 2);
rc = block_read(blk, buf, 0, 2);
if (rc != 0) {
dev_err(blk->dev, "Cannot read MBR/partition table\n");
goto on_error;

View File

@ -86,7 +86,7 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk,
from = le64_to_cpu(pgpt_head->partition_entry_lba);
size = count / GPT_BLOCK_SIZE;
ret = blk->ops->read(blk, pte, from, size);
ret = block_read(blk, pte, from, size);
if (ret) {
kfree(pte);
pte=NULL;
@ -121,7 +121,7 @@ static gpt_header *alloc_read_gpt_header(struct block_device *blk,
if (!gpt)
return NULL;
ret = blk->ops->read(blk, gpt, lba, 1);
ret = block_read(blk, gpt, lba, 1);
if (ret) {
kfree(gpt);
gpt=NULL;

View File

@ -29,4 +29,12 @@ struct block_device {
int blockdevice_register(struct block_device *blk);
int blockdevice_unregister(struct block_device *blk);
int block_read(struct block_device *blk, void *buf, int block, int num_blocks);
int block_write(struct block_device *blk, void *buf, int block, int num_blocks);
static inline int block_flush(struct block_device *blk)
{
return cdev_flush(&blk->cdev);
}
#endif /* __BLOCK_H */