]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Workaround cygwin bug when using \\?\Volume{GUID} syntax.
authorVladimir Serbinenko <phcoder@gmail.com>
Sat, 14 Dec 2013 22:28:34 +0000 (23:28 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sat, 14 Dec 2013 22:28:34 +0000 (23:28 +0100)
ChangeLog
grub-core/osdep/windows/hostdisk.c

index 2de6a47c19a3d75731ff4ccb7667a924ece3fc98..4cfed4835fe31d4411527092ffdd949dddba8539 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-12-14  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Workaround cygwin bug when using \\?\Volume{GUID} syntax.
+
 2013-12-14  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Do not use TCHAR string functions as they are not available on cygwin.
index 984ff26055d9dbe8c92607afb689484c29dcde0d..8f56c21b0afefee2164eff904e8a263aae92257c 100644 (file)
@@ -97,12 +97,54 @@ grub_util_tchar_to_utf8 (LPCTSTR in)
 #error "Unsupported TCHAR size"
 #endif
 
+
+LPTSTR
+grub_util_get_windows_path_real (const char *path)
+{
+  LPTSTR fpa;
+  LPTSTR tpath;
+  size_t alloc, len;
+
+  tpath = grub_util_utf8_to_tchar (path);
+
+  alloc = PATH_MAX;
+
+  while (1)
+    {
+      fpa = xmalloc (alloc * sizeof (fpa[0]));
+
+      len = GetFullPathName (tpath, alloc, fpa, NULL);
+      if (len >= alloc)
+       {
+         free (fpa);
+         alloc = 2 * (len + 2);
+         continue;
+       }
+      if (len == 0)
+       {
+         free (fpa);
+         return tpath;
+       }
+
+      free (tpath);
+      return fpa;
+    }
+}
+
 #ifdef __CYGWIN__
 LPTSTR
 grub_util_get_windows_path (const char *path)
 {
   LPTSTR winpath;
+  /* Workaround cygwin bugs with //?/.  */
+  if ((path[0] == '\\' || path[0] == '/')
+      && (path[1] == '\\' || path[1] == '/')
+      && (path[2] == '?' || path[2] == '.')
+      && (path[3] == '\\' || path[3] == '/'))
+    return grub_util_get_windows_path_real (path);
+
   winpath = xmalloc (sizeof (winpath[0]) * PATH_MAX);
+  memset (winpath, 0, sizeof (winpath[0]) * PATH_MAX);
   if (cygwin_conv_path ((sizeof (winpath[0]) == 1 ? CCP_POSIX_TO_WIN_A
                         : CCP_POSIX_TO_WIN_W) | CCP_ABSOLUTE, path, winpath,
                        sizeof (winpath[0]) * PATH_MAX))
@@ -113,20 +155,7 @@ grub_util_get_windows_path (const char *path)
 LPTSTR
 grub_util_get_windows_path (const char *path)
 {
-  LPTSTR fpa;
-  LPTSTR tpath;
-
-  tpath = grub_util_utf8_to_tchar (path);
-
-  fpa = xmalloc (PATH_MAX * sizeof (fpa[0]));
-  if (!_wfullpath (fpa, tpath, PATH_MAX))
-    {
-      free (fpa);
-      return tpath;
-    }
-
-  free (tpath);
-  return fpa;
+  return grub_util_get_windows_path_real (path);
 }
 #endif