The shell function make_system_path_relative_to_its_root() does not work on Cygwin due to path mapping (e.g. /boot/grub/ is actually /cygwin/boot/grub).

This patch adds '-t prefix' to grub-probe. It prints result from grub_get_prefix() which is already extended for Cygwin (svn rev 1584). The result is used in make_system_path_relative_to_its_root(). This keeps the platform dependent code in getroot.c.

Christian

2008-07-20      Christian Franke  <[EMAIL PROTECTED]>

        * util/grub-probe.c (enum): Add PRINT PREFIX.
        (probe): Add PRINT_PREFIX, prints result of
        grub_get_prefix ().
        (usage): Add `prefix' to `-t' usage text.
        Add some '\n' to avoid excess long lines.
        (main): Add check for `-t prefix' option.
        * util/update-grub_lib.in (make_system_path_relative_to_its_root):
        Use result of `grub-probe -t prefix' instead of
        checking device numbers of parent directories.
        The latter does not work on Cygwin.


diff --git a/util/grub-probe.c b/util/grub-probe.c
index a4f51e2..d36c2cf 100644
--- a/util/grub-probe.c
+++ b/util/grub-probe.c
@@ -46,6 +46,7 @@ enum {
   PRINT_FS,
   PRINT_FS_UUID,
   PRINT_DRIVE,
+  PRINT_PREFIX,
   PRINT_DEVICE,
   PRINT_PARTMAP,
   PRINT_ABSTRACTION,
@@ -113,6 +114,19 @@ probe (const char *path, char *device_name)
   grub_device_t dev = NULL;
   grub_fs_t fs;
   
+  if (print == PRINT_PREFIX)
+    {
+      if (! path)
+        grub_util_error ("cannot find prefix for a device.\n");
+      char * prefix = grub_get_prefix (path);
+      if (! prefix)
+        grub_util_error ("cannot find prefix for %s.\n", path);
+
+      printf ("%s\n", prefix);
+      free (prefix);
+      goto end;
+    }
+
   if (path == NULL)
     {
       if (! grub_util_check_block_device (device_name))
@@ -264,8 +278,10 @@ Probe device information for a given path (or device, if the -d option is given)
 \n\
   -d, --device              given argument is a system device, not a path\n\
   -m, --device-map=FILE     use FILE as the device map [default=%s]\n\
-  -t, --target=(fs|fs_uuid|drive|device|partmap|abstraction)\n\
-                            print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\
+  -t, --target=(fs|fs_uuid|drive|prefix|device|partmap|abstraction)\n\
+                            print filesystem module, GRUB drive, path prefix,\n\
+                            system device, partition map module or\n\
+                            abstraction module [default=fs]\n\
   -h, --help                display this message and exit\n\
   -V, --version             print version information and exit\n\
   -v, --verbose             print verbose messages\n\
@@ -313,6 +329,8 @@ main (int argc, char *argv[])
 	      print = PRINT_FS_UUID;
 	    else if (!strcmp (optarg, "drive"))
 	      print = PRINT_DRIVE;
+	    else if (!strcmp (optarg, "prefix"))
+	      print = PRINT_PREFIX;
 	    else if (!strcmp (optarg, "device"))
 	      print = PRINT_DEVICE;
 	    else if (!strcmp (optarg, "partmap"))
diff --git a/util/update-grub_lib.in b/util/update-grub_lib.in
index c488a85..163b143 100644
--- a/util/update-grub_lib.in
+++ b/util/update-grub_lib.in
@@ -41,25 +41,14 @@ make_system_path_relative_to_its_root ()
   # if not a directory, climb up to the directory containing it
   if test -d $path ; then
     dir=$path
+    file=
   else
     dir=`echo $path | sed -e "s,/[^/]*$,,g"`
+    file=`echo $path | sed -e "s,^.*/,/,g"`
   fi
 
-  num=`stat -c %d $dir`
-
-  # this loop sets $dir to the root directory of the filesystem we're inspecting
-  while : ; do
-    parent=`readlink -f $dir/..`
-    if [ "x`stat -c %d $parent`" = "x$num" ] ; then : ; else
-      # $parent is another filesystem; we found it.
-      break
-    fi
-    if [ "x$dir" = "x/" ] ; then
-      # / is our root.
-      break
-    fi
-    dir=$parent
-  done
+  # get directory prefix relative to its root
+  dir=`${grub_probe} -t prefix "$dir"` || return 1
 
   # This function never prints trailing slashes (so that its output can be
   # appended a slash unconditionally).  Each slash in $dir is considered a
@@ -68,7 +57,8 @@ make_system_path_relative_to_its_root ()
     dir=""
   fi
 
-  echo $path | sed -e "s,^$dir,,g"
+  # re-append file if necessary
+  echo "$dir""$file"
 }
 
 is_path_readable_by_grub ()
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to