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:<filename>' */
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
--- 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;