mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] block: implement block_read/block_write functions
Date: Fri, 31 May 2013 12:38:05 +0200	[thread overview]
Message-ID: <1369996686-15900-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1369996686-15900-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 common/block.c          | 22 ++++++++++++++++++++++
 common/partitions.c     |  2 +-
 common/partitions/efi.c |  4 ++--
 include/block.h         |  3 +++
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/common/block.c b/common/block.c
index 2cf85ae..ad07f8b 100644
--- a/common/block.c
+++ b/common/block.c
@@ -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;
+}
diff --git a/common/partitions.c b/common/partitions.c
index 683b258..35a604c 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -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;
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index e450eeb..ee1326e 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -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;
diff --git a/include/block.h b/include/block.h
index ef36f58..9f60f0a 100644
--- a/include/block.h
+++ b/include/block.h
@@ -29,4 +29,7 @@ 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);
+
 #endif /* __BLOCK_H */
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-05-31 10:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31 10:38 [PATCH 1/4] block: remove unused read_start and read_done ops Sascha Hauer
2013-05-31 10:38 ` [PATCH 2/4] block: rename file operation functions Sascha Hauer
2013-05-31 10:38 ` Sascha Hauer [this message]
2013-05-31 10:38 ` [PATCH 4/4] partition: DOS: Add parameter for the NT disk Signature Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369996686-15900-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox