qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 14/19] block/parallels: create catalog_offset helper


From: Denis V. Lunev
Subject: [Qemu-devel] [PATCH 14/19] block/parallels: create catalog_offset helper
Date: Tue, 30 Dec 2014 13:07:07 +0300

to calculate entry offset inside catalog bitmap in parallels image.
This is a matter of convinience.

Signed-off-by: Denis V. Lunev <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
---
 block/parallels.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index f79ddff..d072276 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -67,6 +67,12 @@ typedef struct BDRVParallelsState {
     unsigned int off_multiplier;
 } BDRVParallelsState;
 
+
+static uint32_t catalog_offset(uint32_t index)
+{
+    return sizeof(ParallelsHeader) + sizeof(uint32_t) * index;
+}
+
 static int parallels_probe(const uint8_t *buf, int buf_size, const char 
*filename)
 {
     const ParallelsHeader *ph = (const void *)buf;
@@ -188,8 +194,7 @@ static int64_t allocate_sector(BlockDriverState *bs, 
int64_t sector_num)
 
     tmp = cpu_to_le32(s->catalog_bitmap[idx]);
 
-    ret = bdrv_pwrite_sync(bs->file,
-            sizeof(ParallelsHeader) + idx * sizeof(tmp), &tmp, sizeof(tmp));
+    ret = bdrv_pwrite_sync(bs->file, catalog_offset(idx), &tmp, sizeof(tmp));
     if (ret < 0) {
         return ret;
     }
@@ -342,8 +347,7 @@ static int parallels_create(const char *filename, QemuOpts 
*opts, Error **errp)
     }
 
     cat_entries = DIV_ROUND_UP(total_size, cl_size);
-    cat_sectors = DIV_ROUND_UP(cat_entries * sizeof(uint32_t) +
-                               sizeof(ParallelsHeader), cl_size);
+    cat_sectors = DIV_ROUND_UP(catalog_offset(cat_entries), cl_size);
     cat_sectors = (cat_sectors *  cl_size) >> BDRV_SECTOR_BITS;
 
     memset(&header, 0, sizeof(header));
-- 
1.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]