All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
Date: Sun, 20 Jul 2008 14:40:14 +0200	[thread overview]
Message-ID: <4883322E.6040606@t-online.de> (raw)

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

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  <franke@computer.org>

	* 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.



[-- Attachment #2: grub2-grub-probe-prefix-2.patch --]
[-- Type: text/x-diff, Size: 3383 bytes --]

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 ()

             reply	other threads:[~2008-07-20 12:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-20 12:40 Christian Franke [this message]
2008-07-22 21:52 ` [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin Robert Millan
2008-07-23  5:44   ` Christian Franke
2008-07-24 17:54     ` Christian Franke
2008-07-27 21:57   ` Christian Franke
2008-07-29 16:51     ` Christian Franke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4883322E.6040606@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.