From: Antony T Curtis <antony.t.curtis@ntlworld.com>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Running QEMU on FreeBSD
Date: Sun, 30 May 2004 10:50:13 +0100 [thread overview]
Message-ID: <1085910613.94556.3.camel@pcgem.rdg.cyberkinetica.com> (raw)
In-Reply-To: <20040530102509.0f234b19.markus.niemisto@gmx.net>
[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]
On Sun, 2004-05-30 at 08:25, Markus Niemistö wrote:
> On Sun, 30 May 2004 00:09:16 +0100
> Antony T Curtis <antony.t.curtis@ntlworld.com> wrote:
>
> > Sure... I'll generate some diffs soon...
> > Meanwhile, I've done a few more mods so that QEMU can use FreeBSD's
> > devices... so that I can specify put "-cdrom /dev/cdrom" on the
> > command line - successfully booted off a FreeBSD install cdrom :D
>
> The patch you sent doesn't deal with these issues, right? Could you
> please make a patch and send it to the list. I've occasionally tried to
> fix using devices but the patches I've made worked only partially.
>
> Was the problem with CDs due to qemu not reading 2048 blocks or was
> there something else?
Here is the diffs I am using... What it fixes is the following...
It uses the FreeBSD ioctls to determine the size of the device and when
reading the 'header', it reads 2048 bytes.
A similar fix has to be done to qemu-mkcow for it to work.
--
Antony T Curtis <antony.t.curtis@ntlworld.com>
[-- Attachment #2: qemu-blk-fbsd.patch --]
[-- Type: text/x-patch, Size: 5799 bytes --]
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 <sys/mman.h>
#endif
+ #ifdef __FreeBSD__
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/ioctl.h>
+ #include <sys/disk.h>
+ #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;
}
next prev parent reply other threads:[~2004-05-30 9:50 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-29 21:25 [Qemu-devel] Running QEMU on FreeBSD Antony T Curtis
2004-05-29 21:39 ` Bartosz Fabianowski
2004-05-29 21:50 ` Antony T Curtis
2004-05-29 21:58 ` Bartosz Fabianowski
2004-05-29 22:09 ` Antony T Curtis
2004-05-29 22:24 ` Bartosz Fabianowski
2004-05-29 23:09 ` Antony T Curtis
2004-05-30 3:53 ` Antony T Curtis
2004-05-30 7:25 ` Markus Niemistö
2004-05-30 9:50 ` Antony T Curtis [this message]
2004-05-30 14:41 ` Bartosz Fabianowski
2004-05-30 17:27 ` Antony T Curtis
2004-05-30 18:57 ` Bartosz Fabianowski
2004-05-30 20:09 ` Antony T Curtis
2004-05-31 0:36 ` Bartosz Fabianowski
2004-05-31 1:24 ` Antony T Curtis
2004-05-31 1:42 ` Bartosz Fabianowski
2004-05-31 1:59 ` Kyle Hayes
2004-05-31 12:15 ` Bartosz Fabianowski
2004-05-31 13:22 ` Antony T Curtis
2004-05-31 9:38 ` Antony T Curtis
2004-05-31 20:36 ` Bartosz Fabianowski
2004-05-31 13:54 ` Antony T Curtis
2004-05-31 20:31 ` Bartosz Fabianowski
2004-05-31 22:15 ` Antony T Curtis
2004-05-31 22:56 ` Brion Vibber
2004-05-31 23:01 ` Bartosz Fabianowski
2004-06-02 23:18 ` qemu port (was: Re: [Qemu-devel] Running QEMU on FreeBSD) Juergen Lock
2004-06-02 23:54 ` [Qemu-devel] Re: qemu port Bartosz Fabianowski
2004-06-03 17:10 ` Gianni Tedesco
2004-06-04 18:44 ` Juergen Lock
2004-06-05 21:04 ` [Qemu-devel] FreeSBIE timer (was: Re: qemu port) Juergen Lock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1085910613.94556.3.camel@pcgem.rdg.cyberkinetica.com \
--to=antony.t.curtis@ntlworld.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).