Skip to contentSkip to conversation

no need to use bdrv_pread() in format guessing code when we can use bdrv_read() directly

PATCH New Michael Tokarev 2 participants 3 messages Mar 13, 2012 – Mar 14, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 no need to use bdrv_pread() in format guessing code when we can use bdrv_read() directly

block.c:find_image_format() calls bdrv_pread() to read first 2048 bytes from the device to guess its format. This function can use bdrv_read() directly since the the read is done on sector boundary.

---
 block.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block.c +1 -1
index b88ee90..6b5bcaf 100644
@@ -469,7 +469,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)
         return ret;
     }
 
-    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
+    ret = bdrv_read(bs, 0, buf, sizeof(buf) / BDRV_BLOCK_SIZE);
     bdrv_delete(bs);
     if (ret < 0) {
         *pdrv = NULL;
Signature · 1 line
1.7.9.1
#1 lore raw

PATCH 1/1 no need to use bdrv_pread() in format guessing code when we can use bdrv_read() directly

[Sorry - sent the wrong patch, should have been
BDRV_SECTOR_SIZE, not BDRV_BLOCK_SIZE....]

block.c:find_image_format() calls bdrv_pread() to read first 2048 bytes from the device to guess its format. This function can use bdrv_read() directly since the the read is done on sector boundary.

---
 block.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block.c +1 -1
index b88ee90..b3af1f6 100644
@@ -469,7 +469,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)
         return ret;
     }
 
-    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
+    ret = bdrv_read(bs, 0, buf, sizeof(buf) / BDRV_SECTOR_SIZE);
     bdrv_delete(bs);
     if (ret < 0) {
         *pdrv = NULL;
Signature · 1 line
1.7.9.1
#2 lore raw
Quoted 17 lines · Michael Tokarev

[Sorry - sent the wrong patch, should have been
BDRV_SECTOR_SIZE, not BDRV_BLOCK_SIZE....]

block.c:find_image_format() calls bdrv_pread() to read first 2048 bytes from the device to guess its format.  This function can use bdrv_read() directly since the the read is done on sector boundary.

---
 block.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
block.c +0 -0
index b88ee90..b3af1f6 100644

block.c static int find_image_format(const char *filename, BlockDriver **pdrv) · line 472

Quoted 5 lines
block.c +1 -1
@@ -469,7 +469,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)
         return ret;
     }
 
-    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
+    ret = bdrv_read(bs, 0, buf, sizeof(buf) / BDRV_SECTOR_SIZE);

Why do this? The code is nicer to read without the sector division and there's no real difference at execution time.

Stefan