From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GKOJn-0000Eu-2Q for qemu-devel@nongnu.org; Mon, 04 Sep 2006 19:57:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GKOJl-0000Ac-Bi for qemu-devel@nongnu.org; Mon, 04 Sep 2006 19:57:30 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKOJl-0000AL-5j for qemu-devel@nongnu.org; Mon, 04 Sep 2006 19:57:29 -0400 Received: from [209.86.89.66] (helo=elasmtp-spurfowl.atl.sa.earthlink.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GKOUN-00072P-NY for qemu-devel@nongnu.org; Mon, 04 Sep 2006 20:08:27 -0400 Received: from [69.169.139.137] (helo=DELL3G) by elasmtp-spurfowl.atl.sa.earthlink.net with asmtp (Exim 4.34) id 1GKOJj-0003p2-HP for qemu-devel@nongnu.org; Mon, 04 Sep 2006 19:57:27 -0400 Message-ID: <002a01c6d07d$e1c98e50$7d00a8c0@DELL3G> From: "Roger Lathrop" Date: Mon, 4 Sep 2006 19:57:29 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0027_01C6D05C.5A28F4C0" Subject: [Qemu-devel] block-vvfat RW patch 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 This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C6D05C.5A28F4C0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Attached patch fixes 3 issues I found while trying to write files from guest to a vfat drive using this configuration: Host: Windows XP (NTFS) Guest: DOS 5 (yeah, really!) Compiler: gcc version 3.4.2 (mingw-special) Qemu Version: 0.8.2 Command line: qemu ....-hdb fat:rw:c:\dev\qemu\work... Problem: Qemu would fault when copying files from guest to d:\ Changes: 1) Fixed assert macro for mingw. Original causes spurious faults when there's a dangling else after the assert. 2) Added O_BINARY to open call in commit_one_file(). Without it, binary files get LF-->CR/LF translations on Windows. 3) Changed sector2cluster to return a signed int, and added type casts to force the division to be signed. First 2 changes are straight forward and should be safe. 3'rd solved my problem, but should be looked at by someone who understands vvfat better than me. I've only tested on the above configuration. The problem I saw was DOS writing to sectors less than s->faked_sectors. The unsigned divide returned a large positive number, which would fault in this bit of code in vvfat_write: if (i >= 0) s->used_clusters[i] |= USED_ALLOCATED; This fix seems reasonable, since the callers of sector2cluster seem to expect a signed result. I suppose an alternate fix would be to test for the special case and always return -1. But I hate special cases ;-) Patch is against 0.8.2, not current CVS, sorry. Doesn't appear to have been fixed since 0.8.2 Good to have this working. Our app is an embedded system with really crude (read, no TCP/IP) network support. Until now, getting log files off the guest has been a pain. So, a big THANKS to whoever wrote block-vvfat, despite the little buglets. Roger ------=_NextPart_000_0027_01C6D05C.5A28F4C0 Content-Type: application/octet-stream; name="block-vvfat.c.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="block-vvfat.c.patch" Index: block-vvfat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/qemu/qemu/block-vvfat.c,v retrieving revision 1.6 diff -u -r1.6 block-vvfat.c --- block-vvfat.c 4 Jun 2006 11:39:07 -0000 1.6 +++ block-vvfat.c 4 Sep 2006 20:31:49 -0000 @@ -61,7 +61,7 @@ exit(-5); } #undef assert -#define assert(a) if (!(a)) nonono(__FILE__, __LINE__, #a) +#define assert(a) do {if (!(a)) nonono(__FILE__, __LINE__, = #a);}while(0) #endif =20 #else @@ -785,9 +785,10 @@ return 0; } =20 -static inline uint32_t sector2cluster(BDRVVVFATState* s,off_t = sector_num) +static inline int32_t sector2cluster(BDRVVVFATState* s,off_t = sector_num) { - return (sector_num-s->faked_sectors)/s->sectors_per_cluster; + // Force integer divide. Must return negative result when sector < = faked_sectors + return = (int32_t)(sector_num-s->faked_sectors)/(int32_t)s->sectors_per_cluster; } =20 static inline off_t cluster2sector(BDRVVVFATState* s, uint32_t = cluster_num) @@ -2178,7 +2179,7 @@ for (i =3D s->cluster_size; i < offset; i +=3D s->cluster_size) c =3D modified_fat_get(s, c); =20 - fd =3D open(mapping->path, O_RDWR | O_CREAT, 0666); + fd =3D open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666); if (fd < 0) { fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path, strerror(errno), errno); ------=_NextPart_000_0027_01C6D05C.5A28F4C0--