--- block.c Tue May 16 13:06:15 2006 +++ block.c Tue May 16 13:07:51 2006 @@ -753,6 +753,20 @@ close(s->fd); } +int qemu_ftruncate(int fd, off_t length) +/* ftruncate() isn't guarranteed to grow a file, according to POSIX. ** +** This is. */ +{ + int res = ftruncate(fd, length); + if (res && (errno == EPERM)) + { + if ((lseek( fd, length - 1, SEEK_SET) == (off_t)-1) || + (write(fd, "\0", 1) == -1)) + return -1; + } + return res; +} + static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) { @@ -765,7 +779,7 @@ 0644); if (fd < 0) return -EIO; - ftruncate(fd, total_size * 512); + qemu_ftruncate(fd, total_size * 512); close(fd); return 0; }