diff -BcNpPr -C 4 qemu-0.5.5/block.c qemu-0.5.5-fbsd/block.c *** qemu-0.5.5/block.c Sat May 8 15:51:18 2004 --- qemu-0.5.5-fbsd/block.c Sun May 30 01:03:08 2004 *************** *** 26,33 **** --- 26,40 ---- #ifndef _WIN32 #include #endif + #ifdef __FreeBSD__ + #include + #include + #include + #include + #endif + #include "cow.h" struct BlockDriverState { int fd; /* if -1, only COW mappings */ *************** BlockDriverState *bdrv_new(const char *d *** 80,88 **** int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) { int fd; int64_t size; ! struct cow_header_v2 cow_header; #ifndef _WIN32 char template[] = "/tmp/vl.XXXXXX"; int cow_fd; struct stat st; --- 87,98 ---- int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) { int fd; int64_t size; ! union { ! struct cow_header_v2 header; ! uint8_t buffer[512*4]; ! } cow; #ifndef _WIN32 char template[] = "/tmp/vl.XXXXXX"; int cow_fd; struct stat st; *************** int bdrv_open(BlockDriverState *bs, cons *** 115,169 **** bs->read_only = 1; } bs->fd = fd; /* see if it is a cow image */ ! if (read(fd, &cow_header, sizeof(cow_header)) != sizeof(cow_header)) { fprintf(stderr, "%s: could not read header\n", filename); goto fail; } #ifndef _WIN32 ! if (be32_to_cpu(cow_header.magic) == COW_MAGIC && ! be32_to_cpu(cow_header.version) == COW_VERSION) { /* cow image found */ ! size = cow_header.size; #ifndef WORDS_BIGENDIAN size = bswap64(size); #endif bs->total_sectors = size / 512; bs->cow_fd = fd; bs->fd = -1; ! if (cow_header.backing_file[0] != '\0') { ! if (stat(cow_header.backing_file, &st) != 0) { ! fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file); goto fail; } ! if (st.st_mtime != be32_to_cpu(cow_header.mtime)) { ! fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file); goto fail; } ! fd = open(cow_header.backing_file, O_RDONLY | O_LARGEFILE); if (fd < 0) goto fail; bs->fd = fd; } ! /* mmap the bitmap */ ! bs->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header); bs->cow_bitmap_addr = mmap(get_mmap_addr(bs->cow_bitmap_size), bs->cow_bitmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, bs->cow_fd, 0); if (bs->cow_bitmap_addr == MAP_FAILED) goto fail; ! bs->cow_bitmap = bs->cow_bitmap_addr + sizeof(cow_header); bs->cow_sectors_offset = (bs->cow_bitmap_size + 511) & ~511; snapshot = 0; } else #endif { /* standard raw image */ size = lseek64(fd, 0, SEEK_END); bs->total_sectors = size / 512; bs->fd = fd; } --- 125,189 ---- bs->read_only = 1; } bs->fd = fd; + lseek(fd, 0LL, SEEK_SET); /* see if it is a cow image */ ! if (read(fd, &cow.buffer, sizeof(cow.buffer)) != sizeof(cow.buffer)) { fprintf(stderr, "%s: could not read header\n", filename); goto fail; } #ifndef _WIN32 ! if (be32_to_cpu(cow.header.magic) == COW_MAGIC && ! be32_to_cpu(cow.header.version) == COW_VERSION) { /* cow image found */ ! size = cow.header.size; #ifndef WORDS_BIGENDIAN size = bswap64(size); #endif bs->total_sectors = size / 512; bs->cow_fd = fd; bs->fd = -1; ! if (cow.header.backing_file[0] != '\0') { ! if (stat(cow.header.backing_file, &st) != 0) { ! fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow.header.backing_file); goto fail; } ! if (st.st_mtime != be32_to_cpu(cow.header.mtime)) { ! fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow.header.backing_file); goto fail; } ! fd = open(cow.header.backing_file, O_RDONLY | O_LARGEFILE); if (fd < 0) goto fail; bs->fd = fd; } ! /* mmap thquie bitmap */ ! bs->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow.header); bs->cow_bitmap_addr = mmap(get_mmap_addr(bs->cow_bitmap_size), bs->cow_bitmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, bs->cow_fd, 0); if (bs->cow_bitmap_addr == MAP_FAILED) goto fail; ! bs->cow_bitmap = bs->cow_bitmap_addr + sizeof(cow.header); bs->cow_sectors_offset = (bs->cow_bitmap_size + 511) & ~511; snapshot = 0; } else #endif { /* standard raw image */ + #ifdef __FreeBSD__ + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + size = lseek(fd, 0LL, SEEK_END); + #else size = lseek64(fd, 0, SEEK_END); + #endif + if (size<0) { + fprintf(stderr,"unable to determine size of device\n"); + goto fail; + } bs->total_sectors = size / 512; bs->fd = fd; }