[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 12/21] parallels: use pread
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 12/21] parallels: use pread |
Date: |
Fri, 14 May 2010 19:10:46 +0200 |
From: Christoph Hellwig <address@hidden>
Use pread instead of lseek + read in preparation of using the qemu
block API.
Signed-off-by: Christoph Hellwig <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/parallels.c | 33 +++++++++++----------------------
1 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index b217101..efb6d4d 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -83,7 +83,7 @@ static int parallels_open(BlockDriverState *bs, const char
*filename, int flags)
s->fd = fd;
- if (read(fd, &ph, sizeof(ph)) != sizeof(ph))
+ if (pread(fd, &ph, sizeof(ph), 0) != sizeof(ph))
goto fail;
if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
@@ -93,14 +93,11 @@ static int parallels_open(BlockDriverState *bs, const char
*filename, int flags)
bs->total_sectors = le32_to_cpu(ph.nb_sectors);
- if (lseek(s->fd, 64, SEEK_SET) != 64)
- goto fail;
-
s->tracks = le32_to_cpu(ph.tracks);
s->catalog_size = le32_to_cpu(ph.catalog_entries);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
+ if (pread(s->fd, s->catalog_bitmap, s->catalog_size * 4, 64) !=
s->catalog_size * 4)
goto fail;
for (i = 0; i < s->catalog_size; i++)
@@ -114,28 +111,18 @@ fail:
return -1;
}
-static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
+static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
{
BDRVParallelsState *s = bs->opaque;
uint32_t index, offset;
- uint64_t position;
index = sector_num / s->tracks;
offset = sector_num % s->tracks;
- // not allocated
+ /* not allocated */
if ((index > s->catalog_size) || (s->catalog_bitmap[index] == 0))
return -1;
-
- position = (uint64_t)(s->catalog_bitmap[index] + offset) * 512;
-
-// fprintf(stderr, "sector: %llx index=%x offset=%x pointer=%x
position=%x\n",
-// sector_num, index, offset, s->catalog_bitmap[index], position);
-
- if (lseek(s->fd, position, SEEK_SET) != position)
- return -1;
-
- return 0;
+ return (uint64_t)(s->catalog_bitmap[index] + offset) * 512;
}
static int parallels_read(BlockDriverState *bs, int64_t sector_num,
@@ -144,11 +131,13 @@ static int parallels_read(BlockDriverState *bs, int64_t
sector_num,
BDRVParallelsState *s = bs->opaque;
while (nb_sectors > 0) {
- if (!seek_to_sector(bs, sector_num)) {
- if (read(s->fd, buf, 512) != 512)
- return -1;
- } else
+ int64_t position = seek_to_sector(bs, sector_num);
+ if (position >= 0) {
+ if (pread(s->fd, buf, 512, position) != 512)
+ return -1;
+ } else {
memset(buf, 0, 512);
+ }
nb_sectors--;
sector_num++;
buf += 512;
--
1.6.6.1
- [Qemu-devel] [PULL 00/21] Block patches, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 01/21] block: Remove semicolon in BDRV_SECTOR_MASK macro, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 04/21] cloop: use qemu block API, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 05/21] ide: Fix ide_dma_cancel, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 09/21] block: Fix protocol detection for Windows devices, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 07/21] bochs: use qemu block API, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 03/21] cloop: use pread, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 08/21] block: Avoid unchecked casts for AIOCBs, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 06/21] bochs: use pread, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 12/21] parallels: use pread,
Kevin Wolf <=
- [Qemu-devel] [PATCH 13/21] parallels: use qemu block API, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 11/21] block/vdi: Allow disk images of size 0, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 15/21] dmg: fix reading of uncompressed chunks, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 14/21] block/vpc: Fix conversion from size to disk geometry, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 02/21] qemu-nbd: Improve error reporting, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 16/21] dmg: use pread, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 17/21] dmg: use qemu block API, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 18/21] block/vdi: Fix image opening and creation for odd disk sizes, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 20/21] Fix docs for block stats monitor command, Kevin Wolf, 2010/05/14
- [Qemu-devel] [PATCH 21/21] block: Remove special case for vvfat, Kevin Wolf, 2010/05/14