Skip to contentSkip to conversation

qemu -boot d -cdrom /dev/cd0 on FreeBSD is not good

Qemu-devel Norikatsu Shigemura 2 participants 3 messages Nov 15, 2004 – Nov 16, 2004

lore
Share & tools
lore
#0 lore raw

I tried to install Windows XP SP2 on qemu over FreeBSD 6-current like following command, but failed.

# qemu -boot d -cdrom /dev/cd0 windows.img

Because find_image_format on qemu/block.c is failed. This problem can be confirmed like following program.
- - - - - - - - - - - - - - - - - - - - - - - - #include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(void)

{
	char buf[2048];
	int fd = open("/dev/cd0", O_RDONLY);
	if(  read(fd, buf, sizeof(buf)) < 0  )  {	/* no problem */
		perror("[1] read error.");
	}
	if(  read(fd, buf, sizeof(buf) / 2) < 0  )  {	/* problem */
		perror("[2] read error.");
	}
}

- - - - - - - - - - - - - - - - - - - - - - - -

Adhoc-ly, I changed "buf" size to 2048. and confirmed this problem was fixed.
- - - - - - - - - - - - - - - - - - - - - - - -
static BlockDriver *find_image_format(const char *filename)

{
    int fd, ret, score, score_max;
    BlockDriver *drv1, *drv;
    uint8_t buf[1024];					=> buf[2048]
(snip)
    ret = read(fd, buf, sizeof(buf));
    if (ret < 0) {
        close(fd);
        return NULL;
    }

(snip)
- - - - - - - - - - - - - - - - - - - - - - - -
Obtained from: qemu-0.6.1

I think magic number 2048 is sector size, but I don't know how to get valid read size. Anyone, do you have any idea?

#1 lore raw
Quoted 5 lines · Norikatsu Shigemura

I tried to install Windows XP SP2 on qemu over FreeBSD 6-current like following command, but failed.

# qemu -boot d -cdrom /dev/cd0 windows.img

Yeah physical cdroms don't work currently as mentioned in the pkg-message...

Quoted 33 lines

Because find_image_format on qemu/block.c is failed. This problem can be confirmed like following program.
- - - - - - - - - - - - - - - - - - - - - - - - #include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(void)

{
	char buf[2048];
	int fd = open("/dev/cd0", O_RDONLY);
	if(  read(fd, buf, sizeof(buf)) < 0  )  {	/* no problem */
		perror("[1] read error.");
	}
	if(  read(fd, buf, sizeof(buf) / 2) < 0  )  {	/* problem */
		perror("[2] read error.");
	}
}

- - - - - - - - - - - - - - - - - - - - - - - -

Adhoc-ly, I changed "buf" size to 2048. and confirmed this problem was fixed.
- - - - - - - - - - - - - - - - - - - - - - - -
static BlockDriver *find_image_format(const char *filename)

{
    int fd, ret, score, score_max;
    BlockDriver *drv1, *drv;
    uint8_t buf[1024];					=> buf[2048]
(snip)
    ret = read(fd, buf, sizeof(buf));
    if (ret < 0) {
        close(fd);
        return NULL;
    }
Quoted 4 lines

(snip)
- - - - - - - - - - - - - - - - - - - - - - - -
Obtained from: qemu-0.6.1

That's all there is to it? Heh. Antony made it sound like it needs
much more! :)

Quoted 3 lines

I think magic number 2048 is sector size, but I don't know how to get valid read size. Anyone, do you have any idea?

On 5.x and later you can use the DIOCGSECTORSIZE ioctl. Here's
the relevant part of the patch I'll use in the next port update:

Index: qemu/block.c
@@ -103,14 +103,25 @@

 {
     int fd, ret, score, score_max;
     BlockDriver *drv1, *drv;
-    uint8_t buf[1024];
+    uint8_t *buf;
+    size_t bufsize = 1024;
+    u_int sectorsize = 512;
     fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
     if (fd < 0)
         return NULL;

- ret = read(fd, buf, sizeof(buf));
+#ifdef DIOCGSECTORSIZE
+ if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
+ sectorsize > bufsize)
+ bufsize = sectorsize;
+#endif
+ buf = malloc(bufsize);
+ if (!buf)
+ return NULL;

+    ret = read(fd, buf, bufsize);
     if (ret < 0) {
         close(fd);
+        free(buf);
         return NULL;
     }
     close(fd);
@@ -124,6 +135,7 @@
             drv = drv1;
         }
     }
+    free(buf);
     return drv;

}

Cheers,
Juergen

#2 lore raw

port update (was: Re: [Qemu-devel] qemu -boot d -cdrom /dev/cd0 on FreeBSD is not good)

Quoted 8 lines · Juergen Lock
Quoted 5 lines · Norikatsu Shigemura

I tried to install Windows XP SP2 on qemu over FreeBSD 6-current like following command, but failed.

# qemu -boot d -cdrom /dev/cd0 windows.img

Yeah physical cdroms don't work currently as mentioned in the pkg-message...
...

I have just send-pr'd the port update with the physical cdrom fix (0.6.1s.20041115), if you want to try it before its committed you can grab the patch out of the raw pr and apply it to your ports tree:

	http://www.freebsd.org/cgi/query-pr.cgi?pr=74015&f=raw

(don't forget to remove files/patch-exec.c)

Thanx Norikatsu for the idea btw!
Juergen