All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix Cygwin path handling
@ 2010-04-14 18:36 Christian Franke
  2010-04-17 15:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-26  1:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 10+ messages in thread
From: Christian Franke @ 2010-04-14 18:36 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

The Cywin path handling is broken since 
make_system_path_relative_to_its_root() functionality was moved from the 
lib script to misc.c.

This patch should fix this. It reuses the Cygwin specific code from 
getroot.c:grub_get_prefix() which apparently is a different 
implementation of the same function.

I would suggest to remove grub_get_prefix(), it is now only used in 
grub-emu.c and sparc64/ieee1275/grub-setup.c. Not included in the patch, 
should be done in a separate commit.


2010-04-14  Christian Franke<franke@computer.org>

	* util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root):
	Remove broken Cygwin path conversion.
	* util/misc.c: [__CYGWIN__] Add include and define.
	[__CYGWIN__] (get_win32_path): Copy function from getroot.c, modify
	for Cygwin 1.7.
	(make_system_path_relative_to_its_root): Simplify loop, replace early
	return by break.
	[__CYGWIN__] Add conversion to win32 path.



-- 
Regards,
Christian Franke


[-- Attachment #2: grub2-cygwin-path.patch --]
[-- Type: text/x-diff, Size: 3253 bytes --]

=== modified file 'util/grub-mkconfig_lib.in'
--- util/grub-mkconfig_lib.in	2010-04-13 12:57:56 +0000
+++ util/grub-mkconfig_lib.in	2010-04-14 16:48:44 +0000
@@ -1,5 +1,5 @@
 # Helper library for grub-mkconfig
-# Copyright (C) 2007,2008,2009  Free Software Foundation, Inc.
+# Copyright (C) 2007,2008,2009,2010  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -38,21 +38,7 @@
 
 make_system_path_relative_to_its_root ()
 {
-  path="`${grub_mkrelpath} $1`"
-
-  case "`uname 2>/dev/null`" in
-    CYGWIN*)
-      # Cygwin: Check if regular or emulated mount.
-      if [ -z "$dir" ] || [ "`stat -c %D "$dir/.."`" != 620000 ] ; then
-        # Reached some mount point not below /cygdrive.
-        # GRUB does not know Cygwin's emulated mounts,
-        # convert to Win32 path and remove drive letter.
-        path=`cygpath -m "$path" | sed -n 's,^[A-Za-z]:,,p'`
-        test ! -z "$path" || return 1
-      fi ;;
-  esac
-
-  echo "$path"
+  ${grub_mkrelpath} $1
 }
 
 is_path_readable_by_grub ()

=== modified file 'util/misc.c'
--- util/misc.c	2010-04-09 23:25:46 +0000
+++ util/misc.c	2010-04-14 16:48:44 +0000
@@ -53,6 +53,11 @@
 # include <malloc.h>
 #endif
 
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+# define DEV_CYGDRIVE_MAJOR 98
+#endif
+
 #ifdef __MINGW32__
 #include <windows.h>
 #include <winioctl.h>
@@ -456,6 +461,31 @@
   return ret;
 }
 
+#ifdef __CYGWIN__
+/* Convert POSIX path to Win32 path,
+   remove drive letter, replace backslashes.  */
+static char *
+get_win32_path (const char *path)
+{
+  char winpath[PATH_MAX];
+  if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath)))
+    grub_util_error ("cygwin_conv_path() failed");
+
+  int len = strlen (winpath);
+  if (len > 2 && winpath[1] == ':')
+    {
+      len -= 2;
+      memmove (winpath, winpath + 2, len + 1);
+    }
+
+  int i;
+  for (i = 0; i < len; i++)
+    if (winpath[i] == '\\')
+      winpath[i] = '/';
+  return xstrdup (winpath);
+}
+#endif
+
 /* This function never prints trailing slashes (so that its output
    can be appended a slash unconditionally).  */
 char *
@@ -521,28 +551,28 @@
       /* offset == 1 means root directory.  */
       if (offset == 1)
 	{
-	  free (buf);
-	  len = strlen (buf2);
-	  while (buf2[len - 1] == '/' && len > 1)
-	    {
-	      buf2[len - 1] = '\0';
-	      len--;
-	    }
-	  if (len > 1)
-	    return buf2;
-	  else
-	    {
-	      /* This means path given is just a backslash.  As above
-		 we have to return an empty string.  */
-	      free (buf2);
-	      return xstrdup ("");
-	    }
+	  /* Include leading slash.  */
+	  offset = 0;
+	  break;
 	}
     }
   free (buf);
   buf3 = xstrdup (buf2 + offset);
   free (buf2);
 
+#ifdef __CYGWIN__
+  if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
+    {
+      /* Reached some mount point not below /cygdrive.
+	 GRUB does not know Cygwin's emulated mounts,
+	 convert to Win32 path.  */
+      grub_util_info ("Cygwin path = %s\n", buf3);
+      char * temp = get_win32_path (buf3);
+      free (buf3);
+      buf3 = temp;
+    }
+#endif
+
   len = strlen (buf3);
   while (buf3[len - 1] == '/' && len > 1)
     {


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-14 18:36 [PATCH] Fix Cygwin path handling Christian Franke
@ 2010-04-17 15:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-17 16:10   ` Christian Franke
  2010-04-26  1:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 10+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-04-17 15:22 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]

Christian Franke wrote:
> The Cywin path handling is broken since
> make_system_path_relative_to_its_root() functionality was moved from
> the lib script to misc.c.
>
> This patch should fix this. It reuses the Cygwin specific code from
> getroot.c:grub_get_prefix() which apparently is a different
> implementation of the same function.
>
> I would suggest to remove grub_get_prefix(), it is now only used in
> grub-emu.c and sparc64/ieee1275/grub-setup.c. Not included in the
> patch, should be done in a separate commit.
>
>
> 2010-04-14  Christian Franke<franke@computer.org>
>
>     * util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root):
>     Remove broken Cygwin path conversion.
>     * util/misc.c: [__CYGWIN__] Add include and define.
>     [__CYGWIN__] (get_win32_path): Copy function from getroot.c, modify
>     for Cygwin 1.7.
Please avoid duplicating code. Rather than that rename get_win32_path to
grub_get_win32_path and remove static attribute
>     (make_system_path_relative_to_its_root): Simplify loop, replace early
>     return by break.
>     [__CYGWIN__] Add conversion to win32 path.
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-17 15:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-04-17 16:10   ` Christian Franke
  2010-04-17 20:58     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-19 14:49     ` BVK Chaitanya
  0 siblings, 2 replies; 10+ messages in thread
From: Christian Franke @ 2010-04-17 16:10 UTC (permalink / raw)
  To: The development of GNU GRUB

Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Christian Franke wrote:
>    
>> The Cywin path handling is broken since
>> make_system_path_relative_to_its_root() functionality was moved from
>> the lib script to misc.c.
>>
>> This patch should fix this. It reuses the Cygwin specific code from
>> getroot.c:grub_get_prefix() which apparently is a different
>> implementation of the same function.
>>
>> I would suggest to remove grub_get_prefix(), it is now only used in
>> grub-emu.c and sparc64/ieee1275/grub-setup.c. Not included in the
>> patch, should be done in a separate commit.
>>
>>
>> 2010-04-14  Christian Franke<franke@computer.org>
>>
>>      * util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root):
>>      Remove broken Cygwin path conversion.
>>      * util/misc.c: [__CYGWIN__] Add include and define.
>>      [__CYGWIN__] (get_win32_path): Copy function from getroot.c, modify
>>      for Cygwin 1.7.
>>      
> Please avoid duplicating code. Rather than that rename get_win32_path to
> grub_get_win32_path and remove static attribute
>    

Normally I would have done that but duplication was intentional in this 
case:
The getroot.c:get_win32_path() can later be removed together with 
grub_get_prefix(), see my suggestion above. The patch takes this into 
account and adds new private misc.c:get_win32_path() and so avoids 
unnecessary temporary changes to misc.h and getroot.c.

The actual code duplication happened when 
misc.c:make_system_path_relative_to_its_root() was added instead of 
moving and reusing getroot.c:grub_get_prefix() :-)


BTW: My last commits to grub codebase were before the move to bzr.

As far as I understand "Bazaar workflow for GRUB" 
(http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00175.html) 
such changes should be 'bzr push'ed to e.g. '.../branches/feature-foo' 
(e.g. '.../branches/cygwin-path' in this case) after review has finished.

Is this workflow still valid or is there a more current document?

-- 
Regards,
Christian Franke




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-17 16:10   ` Christian Franke
@ 2010-04-17 20:58     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-19 14:49     ` BVK Chaitanya
  1 sibling, 0 replies; 10+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-04-17 20:58 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 2582 bytes --]

Christian Franke wrote:
> Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>> Christian Franke wrote:
>>   
>>> The Cywin path handling is broken since
>>> make_system_path_relative_to_its_root() functionality was moved from
>>> the lib script to misc.c.
>>>
>>> This patch should fix this. It reuses the Cygwin specific code from
>>> getroot.c:grub_get_prefix() which apparently is a different
>>> implementation of the same function.
>>>
>>> I would suggest to remove grub_get_prefix(), it is now only used in
>>> grub-emu.c and sparc64/ieee1275/grub-setup.c. Not included in the
>>> patch, should be done in a separate commit.
>>>
>>>
>>> 2010-04-14  Christian Franke<franke@computer.org>
>>>
>>>      * util/grub-mkconfig_lib.in
>>> (make_system_path_relative_to_its_root):
>>>      Remove broken Cygwin path conversion.
>>>      * util/misc.c: [__CYGWIN__] Add include and define.
>>>      [__CYGWIN__] (get_win32_path): Copy function from getroot.c,
>>> modify
>>>      for Cygwin 1.7.
>>>      
>> Please avoid duplicating code. Rather than that rename get_win32_path to
>> grub_get_win32_path and remove static attribute
>>    
>
> Normally I would have done that but duplication was intentional in
> this case:
> The getroot.c:get_win32_path() can later be removed together with
> grub_get_prefix(), see my suggestion above. The patch takes this into
> account and adds new private misc.c:get_win32_path() and so avoids
> unnecessary temporary changes to misc.h and getroot.c.
>
> The actual code duplication happened when
> misc.c:make_system_path_relative_to_its_root() was added instead of
> moving and reusing getroot.c:grub_get_prefix() :-)
>
Ok. Can you supply the dedup patch? (perhaps it should come before the fix).
>
> BTW: My last commits to grub codebase were before the move to bzr.
>
> As far as I understand "Bazaar workflow for GRUB"
> (http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00175.html)
> such changes should be 'bzr push'ed to e.g. '.../branches/feature-foo'
> (e.g. '.../branches/cygwin-path' in this case) after review has finished.
>
Creating new branches doesn't need any approval at all. If the changes
are approved for trunk they are applied or merged into trunk.
experimental branch is a merge of sufficiently functional branches but
which need more testing for testers convenience. Merging into it follows
similar rules as comitting to trunk.
> Is this workflow still valid or is there a more current document?
>


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-17 16:10   ` Christian Franke
  2010-04-17 20:58     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-04-19 14:49     ` BVK Chaitanya
  1 sibling, 0 replies; 10+ messages in thread
From: BVK Chaitanya @ 2010-04-19 14:49 UTC (permalink / raw)
  To: The development of GNU GRUB

On Sat, Apr 17, 2010 at 9:40 PM, Christian Franke
<Christian.Franke@t-online.de> wrote:
>
> As far as I understand "Bazaar workflow for GRUB"
> (http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00175.html) such
> changes should be 'bzr push'ed to e.g. '.../branches/feature-foo' (e.g.
> '.../branches/cygwin-path' in this case) after review has finished.
>
> Is this workflow still valid or is there a more current document?
>


That is the only workflow document we have.  I had to add couple of
more sections to it, but I haven't done that yet :-(

We are not strictly following that document :-)  We are deciding --
informally over IRC -- whether a patch can go to trunk (mainline) or
to experimental case-by-case basis, based on the fix/feature severity.



-- 
bvk.chaitanya



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-14 18:36 [PATCH] Fix Cygwin path handling Christian Franke
  2010-04-17 15:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-04-26  1:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-26  6:12   ` Christian Franke
  1 sibling, 1 reply; 10+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-04-26  1:45 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1724 bytes --]

Christian Franke wrote:
> The Cywin path handling is broken since
> make_system_path_relative_to_its_root() functionality was moved from
> the lib script to misc.c.
>
> This patch should fix this. It reuses the Cygwin specific code from
> getroot.c:grub_get_prefix() which apparently is a different
> implementation of the same function.
>
> I would suggest to remove grub_get_prefix(), it is now only used in
> grub-emu.c and sparc64/ieee1275/grub-setup.c. Not included in the
> patch, should be done in a separate commit.
>
>
> 2010-04-14  Christian Franke<franke@computer.org>
>
>     * util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root):
>     Remove broken Cygwin path conversion.
>     * util/misc.c: [__CYGWIN__] Add include and define.
>     [__CYGWIN__] (get_win32_path): Copy function from getroot.c, modify
>     for Cygwin 1.7.
>     (make_system_path_relative_to_its_root): Simplify loop, replace early
>     return by break.
>     [__CYGWIN__] Add conversion to win32 path.
>

+	  /* Include leading slash.  */
+	  offset = 0;
+	  break;
Why do you make this change? It seems to make the behaviour of make_path_relative_to_its root inconsistent since E.g.
/boot/grub -> grub
/etc -> /etc
Can we decide to either always include this slash or never to? I prefer never to include it since it's the way it is now and I prefer to keep it to avoid possible breakage.

>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-26  1:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-04-26  6:12   ` Christian Franke
  2010-04-26  6:56     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 10+ messages in thread
From: Christian Franke @ 2010-04-26  6:12 UTC (permalink / raw)
  To: The development of GNU GRUB

Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Christian Franke wrote:
>    
>>      
> +	  /* Include leading slash.  */
> +	  offset = 0;
> +	  break;
> Why do you make this change? It seems to make the behaviour of make_path_relative_to_its root inconsistent since E.g.
> /boot/grub ->  grub
> /etc ->  /etc
>    

Could not reproduce. Old and new code always include the leading slash 
(except "/" -> ''").

-- 
Regards,
Christian Franke




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-26  6:12   ` Christian Franke
@ 2010-04-26  6:56     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2010-04-26 10:18       ` Christian Franke
  0 siblings, 1 reply; 10+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-04-26  6:56 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

Christian Franke wrote:
> Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>> Christian Franke wrote:
>>   
>>>      
>> +      /* Include leading slash.  */
>> +      offset = 0;
>> +      break;
>> Why do you make this change? It seems to make the behaviour of
>> make_path_relative_to_its root inconsistent since E.g.
>> /boot/grub ->  grub
>> /etc ->  /etc
>>    
>
> Could not reproduce. Old and new code always include the leading slash
> (except "/" -> ''").
>
I actually seen the '/' case and have incorrectly assumed it's always
so. However there is still one case when you patch changes the behaviour:
$ grub-mkrelpath /

$ ./grub-mkrelpath /
/
Although:
$ ./grub-mkrelpath /mnt/boot/

$ grub-mkrelpath /mnt/boot/


A simple filter at the end of make_path_relative_to_its_root is enough.
Just it's better to avoid both inconsistency between mountpoint and root
and behaviour change

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-26  6:56     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-04-26 10:18       ` Christian Franke
  2010-05-01 19:40         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 10+ messages in thread
From: Christian Franke @ 2010-04-26 10:18 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>
> I actually seen the '/' case and have incorrectly assumed it's always
> so. However there is still one case when you patch changes the behaviour:
> $ grub-mkrelpath /
>
> $ ./grub-mkrelpath /
> /
> Although:
> $ ./grub-mkrelpath /mnt/boot/
>
> $ grub-mkrelpath /mnt/boot/
>
>
>    

I actually did not test the "/" corner case, sorry. New patch attached.

-- 
Regards,
Christian Franke


[-- Attachment #2: grub2-cygwin-path-2.patch --]
[-- Type: text/x-diff, Size: 4210 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2010-04-26 01:35:55 +0000
+++ ChangeLog	2010-04-26 09:44:43 +0000
@@ -1,5 +1,17 @@
 2010-04-26  Christian Franke  <franke@computer.org>
 
+	* util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root):
+	Remove broken Cygwin path conversion.
+	* util/misc.c: [__CYGWIN__] Add include and define.
+	[__CYGWIN__] (get_win32_path): Copy function from getroot.c, modify
+	for Cygwin 1.7.
+	(make_system_path_relative_to_its_root): Simplify loop, replace early
+	return by break.
+	[__CYGWIN__] Add conversion to win32 path.
+	Include "/" case in trailing slash removal.
+
+2010-04-26  Christian Franke  <franke@computer.org>
+
 	* include/grub/util/getroot.h (grub_get_prefix): Remove prototype.
 	* util/getroot.c [__CYGWIN__] (get_win32_path): Remove function.
 	(grub_get_prefix): Remove function.

=== modified file 'util/grub-mkconfig_lib.in'
--- util/grub-mkconfig_lib.in	2010-04-19 19:25:41 +0000
+++ util/grub-mkconfig_lib.in	2010-04-26 08:59:10 +0000
@@ -1,5 +1,5 @@
 # Helper library for grub-mkconfig
-# Copyright (C) 2007,2008,2009  Free Software Foundation, Inc.
+# Copyright (C) 2007,2008,2009,2010  Free Software Foundation, Inc.
 #
 # GRUB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -44,21 +44,7 @@
 
 make_system_path_relative_to_its_root ()
 {
-  path="`${grub_mkrelpath} $1`"
-
-  case "`uname 2>/dev/null`" in
-    CYGWIN*)
-      # Cygwin: Check if regular or emulated mount.
-      if [ -z "$dir" ] || [ "`stat -c %D "$dir/.."`" != 620000 ] ; then
-        # Reached some mount point not below /cygdrive.
-        # GRUB does not know Cygwin's emulated mounts,
-        # convert to Win32 path and remove drive letter.
-        path=`cygpath -m "$path" | sed -n 's,^[A-Za-z]:,,p'`
-        test ! -z "$path" || return 1
-      fi ;;
-  esac
-
-  echo "$path"
+  ${grub_mkrelpath} $1
 }
 
 is_path_readable_by_grub ()

=== modified file 'util/misc.c'
--- util/misc.c	2010-04-09 23:25:46 +0000
+++ util/misc.c	2010-04-26 10:08:04 +0000
@@ -53,6 +53,11 @@
 # include <malloc.h>
 #endif
 
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+# define DEV_CYGDRIVE_MAJOR 98
+#endif
+
 #ifdef __MINGW32__
 #include <windows.h>
 #include <winioctl.h>
@@ -456,6 +461,27 @@
   return ret;
 }
 
+#ifdef __CYGWIN__
+/* Convert POSIX path to Win32 path,
+   remove drive letter, replace backslashes.  */
+static char *
+get_win32_path (const char *path)
+{
+  char winpath[PATH_MAX];
+  if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath)))
+    grub_util_error ("cygwin_conv_path() failed");
+
+  int len = strlen (winpath);
+  int offs = (len > 2 && winpath[1] == ':' ? 2 : 0);
+
+  int i;
+  for (i = offs; i < len; i++)
+    if (winpath[i] == '\\')
+      winpath[i] = '/';
+  return xstrdup (winpath + offs);
+}
+#endif
+
 /* This function never prints trailing slashes (so that its output
    can be appended a slash unconditionally).  */
 char *
@@ -521,30 +547,31 @@
       /* offset == 1 means root directory.  */
       if (offset == 1)
 	{
-	  free (buf);
-	  len = strlen (buf2);
-	  while (buf2[len - 1] == '/' && len > 1)
-	    {
-	      buf2[len - 1] = '\0';
-	      len--;
-	    }
-	  if (len > 1)
-	    return buf2;
-	  else
-	    {
-	      /* This means path given is just a backslash.  As above
-		 we have to return an empty string.  */
-	      free (buf2);
-	      return xstrdup ("");
-	    }
+	  /* Include leading slash.  */
+	  offset = 0;
+	  break;
 	}
     }
   free (buf);
   buf3 = xstrdup (buf2 + offset);
   free (buf2);
 
+#ifdef __CYGWIN__
+  if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
+    {
+      /* Reached some mount point not below /cygdrive.
+	 GRUB does not know Cygwin's emulated mounts,
+	 convert to Win32 path.  */
+      grub_util_info ("Cygwin path = %s\n", buf3);
+      char * temp = get_win32_path (buf3);
+      free (buf3);
+      buf3 = temp;
+    }
+#endif
+
+  /* Remove trailing slashes, return empty string if root directory.  */
   len = strlen (buf3);
-  while (buf3[len - 1] == '/' && len > 1)
+  while (len > 0 && buf3[len - 1] == '/')
     {
       buf3[len - 1] = '\0';
       len--;


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Fix Cygwin path handling
  2010-04-26 10:18       ` Christian Franke
@ 2010-05-01 19:40         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 10+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-05-01 19:40 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

Committed
Christian Franke wrote:
> Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>>
>> I actually seen the '/' case and have incorrectly assumed it's always
>> so. However there is still one case when you patch changes the
>> behaviour:
>> $ grub-mkrelpath /
>>
>> $ ./grub-mkrelpath /
>> /
>> Although:
>> $ ./grub-mkrelpath /mnt/boot/
>>
>> $ grub-mkrelpath /mnt/boot/
>>
>>
>>    
>
> I actually did not test the "/" corner case, sorry. New patch attached.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-05-01 19:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-14 18:36 [PATCH] Fix Cygwin path handling Christian Franke
2010-04-17 15:22 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-04-17 16:10   ` Christian Franke
2010-04-17 20:58     ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-04-19 14:49     ` BVK Chaitanya
2010-04-26  1:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-04-26  6:12   ` Christian Franke
2010-04-26  6:56     ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-04-26 10:18       ` Christian Franke
2010-05-01 19:40         ` Vladimir 'φ-coder/phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.