From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IZTo3-0004PJ-Am for qemu-devel@nongnu.org; Sun, 23 Sep 2007 11:55:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IZTo1-0004P7-Tl for qemu-devel@nongnu.org; Sun, 23 Sep 2007 11:55:39 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IZTo1-0004P4-Pc for qemu-devel@nongnu.org; Sun, 23 Sep 2007 11:55:37 -0400 Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IZTo1-0000ZU-9w for qemu-devel@nongnu.org; Sun, 23 Sep 2007 11:55:37 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IZTns-0003Eu-Or for qemu-devel@nongnu.org; Sun, 23 Sep 2007 15:55:28 +0000 Received: from d83-190-180-66.cust.tele2.it ([83.190.180.66]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Sep 2007 15:55:28 +0000 Received: from lorenzo.campedelli by d83-190-180-66.cust.tele2.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Sep 2007 15:55:28 +0000 From: Lorenzo Campedelli Date: Sun, 23 Sep 2007 17:55:02 +0200 Message-ID: <46F68C56.8000408@tele2.it> References: <219e947f0709221443l494e4c46w6efafce989dbb867@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040204090303020701090909" In-Reply-To: Sender: news Subject: [Qemu-devel] Re: [PATCH] vvfat mbr fixes 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. --------------040204090303020701090909 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Johannes Schindelin wrote: > Hi, > > On Sun, 23 Sep 2007, Lorenzo Campedelli wrote: > >> While you are working on vvfat issues, could you give a look to the >> attached small patch? > > Okay, this is what I would do: > > - not make this handling dependent on vvfat (but this means checking if > the colon is the second character, because then it is most likely > a Windows path and does _not_ want special handling), and > > - I'd use the result of strrchr() directly. > > This is a sketch of the code I propose: > > const char *tmp; > > ... > > get_tmp_filename(tmp_filename, sizeof(tmp_filename)); > /* Handle 'fat:rw:' */ > tmp = strrchr(backing_filename, ':'); > if (tmp - backing_filename == 2) /* DOS path */ > tmp = NULL; > else if (tmp - backing_filename > 2 && tmp[-2] == ':') > tmp -= 2; > realpath(filename, tmp ? tmp : backing_filename); > > Ciao, > Dscho > > > > Hi Johannes, thanks for your reply. I gave another try at the patch. I was concerned by having this handling outside of a proper place (i.e. block-vvfat.c), but if we want to leave it there, wouldn't it be better to just handle cases which would otherwise fail, and just try to fix the "fat:" format? The attached patch only tries to fix things when realpath() fails to find a match and when the filename starts with a "fat:" header. This way if anybody really wanted to use an image file named "fat:foo" could do it without us handling it as a vvfat directory... The code to handle the search for ':' and the DOS drive name special case is stolen from block-vvfat.c, so you should like it ;-). Regards, Lorenzo --------------040204090303020701090909 Content-Type: text/x-patch; name="qemu-0.9.0.20070921-block.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-0.9.0.20070921-block.c.patch" --- qemu-0.9.0.20070921/block.c.orig 2007-09-23 17:04:21.000000000 +0200 +++ qemu-0.9.0.20070921/block.c 2007-09-23 17:18:39.000000000 +0200 @@ -349,7 +349,19 @@ bdrv_delete(bs1); get_tmp_filename(tmp_filename, sizeof(tmp_filename)); - realpath(filename, backing_filename); + if (realpath(filename, backing_filename) == NULL) { + if (strstart(filename, "fat:", NULL)) { + int i = strrchr(filename, ':') - filename; + + if ((filename[i-2] == ':') && isalpha(filename[i-1])) + i -= 1; /* workaround for DOS drive names */ + else + i += 1; + + strncpy(backing_filename, filename, i); + realpath(filename + i, backing_filename + i); + } + } if (bdrv_create(&bdrv_qcow2, tmp_filename, total_size, backing_filename, 0) < 0) { return -1; --------------040204090303020701090909--