X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=block-cow.c;h=eeeab7068b729a9bfe0b80cb635ccb1bc1f26982;hb=fdabc366bd922d3029b42864ecf268103d8ca8e6;hp=ab62c2a868be8ef4fca560596cc7f945ece1ebb7;hpb=ea2384d36e1e5f6dfd44b748d290762181c38350;p=qemu diff --git a/block-cow.c b/block-cow.c index ab62c2a..eeeab70 100644 --- a/block-cow.c +++ b/block-cow.c @@ -54,7 +54,8 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename) { const struct cow_header_v2 *cow_header = (const void *)buf; - if (be32_to_cpu(cow_header->magic) == COW_MAGIC && + if (buf_size >= sizeof(struct cow_header_v2) && + be32_to_cpu(cow_header->magic) == COW_MAGIC && be32_to_cpu(cow_header->version) == COW_VERSION) return 100; else @@ -124,7 +125,7 @@ static int cow_open(BlockDriverState *bs, const char *filename) return -1; } -static inline void set_bit(uint8_t *bitmap, int64_t bitnum) +static inline void cow_set_bit(uint8_t *bitmap, int64_t bitnum) { bitmap[bitnum / 8] |= (1 << (bitnum%8)); } @@ -173,7 +174,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, while (nb_sectors > 0) { if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = read(s->fd, buf, n * 512); if (ret != n * 512) return -1; @@ -193,16 +194,16 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, BDRVCowState *s = bs->opaque; int ret, i; - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = write(s->fd, buf, nb_sectors * 512); if (ret != nb_sectors * 512) return -1; for (i = 0; i < nb_sectors; i++) - set_bit(s->cow_bitmap, sector_num + i); + cow_set_bit(s->cow_bitmap, sector_num + i); return 0; } -static int cow_close(BlockDriverState *bs) +static void cow_close(BlockDriverState *bs) { BDRVCowState *s = bs->opaque; munmap(s->cow_bitmap_addr, s->cow_bitmap_size);