提交 122bb9e3 编写于 作者: C Christoph Hellwig 提交者: Kevin Wolf

cow: use pread/pwrite

Use pread/pwrite instead of lseek + read/write in preparation of using the
qemu block API.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 68dba0bf
...@@ -78,7 +78,7 @@ static int cow_open(BlockDriverState *bs, const char *filename, int flags) ...@@ -78,7 +78,7 @@ static int cow_open(BlockDriverState *bs, const char *filename, int flags)
} }
s->fd = fd; s->fd = fd;
/* see if it is a cow image */ /* see if it is a cow image */
if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) { if (pread(fd, &cow_header, sizeof(cow_header), 0) != sizeof(cow_header)) {
goto fail; goto fail;
} }
...@@ -159,8 +159,8 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, ...@@ -159,8 +159,8 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num,
while (nb_sectors > 0) { while (nb_sectors > 0) {
if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) {
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = pread(s->fd, buf, n * 512,
ret = read(s->fd, buf, n * 512); s->cow_sectors_offset + sector_num * 512);
if (ret != n * 512) if (ret != n * 512)
return -1; return -1;
} else { } else {
...@@ -186,8 +186,8 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, ...@@ -186,8 +186,8 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num,
BDRVCowState *s = bs->opaque; BDRVCowState *s = bs->opaque;
int ret, i; int ret, i;
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = pwrite(s->fd, buf, nb_sectors * 512,
ret = write(s->fd, buf, nb_sectors * 512); s->cow_sectors_offset + sector_num * 512);
if (ret != nb_sectors * 512) if (ret != nb_sectors * 512)
return -1; return -1;
for (i = 0; i < nb_sectors; i++) for (i = 0; i < nb_sectors; i++)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册