Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CU87M-0007nJ-8z for qemu-devel@nongnu.org; Tue, 16 Nov 2004 13:31:52 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CU87L-0007mm-21 for qemu-devel@nongnu.org; Tue, 16 Nov 2004 13:31:51 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CU87K-0007mK-RJ for qemu-devel@nongnu.org; Tue, 16 Nov 2004 13:31:50 -0500 Received: from [212.63.36.242] (helo=gwyn.kn-bremen.de) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CU7yB-0006rd-2r for qemu-devel@nongnu.org; Tue, 16 Nov 2004 13:22:23 -0500 From: Juergen Lock Date: Tue, 16 Nov 2004 18:46:34 +0100 Subject: Re: [Qemu-devel] qemu -boot d -cdrom /dev/cd0 on FreeBSD is not good Message-ID: <20041116184633.A84696@saturn.kn-bremen.de> References: <200411151748.iAFHmYQ1019323@sakura.ninth-nine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <200411151748.iAFHmYQ1019323@sakura.ninth-nine.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: freebsd-hackers@FreeBSD.org On Tue, Nov 16, 2004 at 02:48:34AM +0900, Norikatsu Shigemura wrote: > 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... > Because find_image_format on qemu/block.c is failed. This > problem can be confirmed like following program. > - - - - - - - - - - - - - - - - - - - - - - - - > #include > #include > #include > 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 > That's all there is to it? Heh. Antony made it sound like it needs much more! :) > 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, §orsize) && + 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