All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
@ 2008-07-20 12:40 Christian Franke
  2008-07-22 21:52 ` Robert Millan
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Franke @ 2008-07-20 12:40 UTC (permalink / raw)
  To: The development of GRUB 2

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

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

* Re: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
  2008-07-20 12:40 [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin Christian Franke
@ 2008-07-22 21:52 ` Robert Millan
  2008-07-23  5:44   ` Christian Franke
  2008-07-27 21:57   ` Christian Franke
  0 siblings, 2 replies; 6+ messages in thread
From: Robert Millan @ 2008-07-22 21:52 UTC (permalink / raw)
  To: The development of GRUB 2

On Sun, Jul 20, 2008 at 02:40:14PM +0200, Christian Franke wrote:
> 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.

This is different than the usual grub-probe usage in that it doesn't operate
on a device.  Perhaps it would make sense to add the functionality you want in
a separate utility?

I have an increasing feeling that grub-probe is becoming bloated (though I
admit, this is mostly my fault)

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)



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

* Re: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
  2008-07-22 21:52 ` Robert Millan
@ 2008-07-23  5:44   ` Christian Franke
  2008-07-24 17:54     ` Christian Franke
  2008-07-27 21:57   ` Christian Franke
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Franke @ 2008-07-23  5:44 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Sun, Jul 20, 2008 at 02:40:14PM +0200, Christian Franke wrote:
>   
>> 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.
>>     
>
> This is different than the usual grub-probe usage in that it doesn't operate
> on a device.  Perhaps it would make sense to add the functionality you want in
> a separate utility?
>
>   

OK, probably /usr/bin/grub-prefix ?

Drawback: getroot.c contains also grub_guess_root_device() etc, so a 
grub-prefix program would require most of the objects grub-probe requires.

Put grub_get_prefix() in a new util/getprefix.c ?


Or handle those platform dependencies in update-grub_lib.in itself. Can 
be done by a conditional call to 'cygpath' utility. This conditional 
must then be removed for the other platforms when generating 
update-grub_lib.

Christian




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

* Re: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
  2008-07-23  5:44   ` Christian Franke
@ 2008-07-24 17:54     ` Christian Franke
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Franke @ 2008-07-24 17:54 UTC (permalink / raw)
  To: The development of GRUB 2

Christian Franke wrote:
> Robert Millan wrote:
>> On Sun, Jul 20, 2008 at 02:40:14PM +0200, Christian Franke wrote:
>>  
>>> 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.
>>>     
>>
>> This is different than the usual grub-probe usage in that it doesn't 
>> operate
>> on a device.  Perhaps it would make sense to add the functionality 
>> you want in
>> a separate utility?
>>
>>   
>
> OK, probably /usr/bin/grub-prefix ?
>
> Drawback: getroot.c contains also grub_guess_root_device() etc, so a 
> grub-prefix program would require most of the objects grub-probe 
> requires.
>
> Put grub_get_prefix() in a new util/getprefix.c ?
>
>
> Or handle those platform dependencies in update-grub_lib.in itself. 
> Can be done by a conditional call to 'cygpath' utility. This 
> conditional must then be removed for the other platforms when 
> generating update-grub_lib.
>

Any comment on this?

The pe2elf converter and related patches from Bean, and my remaining 
patches for Cygwin were committed today.

This 'prefix' fix is the last patch which is necessary of out of the box 
Cygwin support in the next release, otherwise grub-install would not work.

Christian




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

* Re: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
  2008-07-22 21:52 ` Robert Millan
  2008-07-23  5:44   ` Christian Franke
@ 2008-07-27 21:57   ` Christian Franke
  2008-07-29 16:51     ` Christian Franke
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Franke @ 2008-07-27 21:57 UTC (permalink / raw)
  To: The development of GRUB 2

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

Robert Millan wrote:
> On Sun, Jul 20, 2008 at 02:40:14PM +0200, Christian Franke wrote:
>   
>> 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.
>>     
>
> This is different than the usual grub-probe usage in that it doesn't operate
> on a device.  Perhaps it would make sense to add the functionality you want in
> a separate utility?
>
> I have an increasing feeling that grub-probe is becoming bloated (though I
> admit, this is mostly my fault)
>
>   

Here is a version with works without grub-probe.

Christian


[-- Attachment #2: grub2-prefix-3.patch --]
[-- Type: text/x-diff, Size: 889 bytes --]

diff --git a/util/update-grub_lib.in b/util/update-grub_lib.in
index 03a96ce..9d0f0c6 100644
--- a/util/update-grub_lib.in
+++ b/util/update-grub_lib.in
@@ -68,7 +68,22 @@ make_system_path_relative_to_its_root ()
     dir=""
   fi
 
-  echo $path | sed -e "s,^$dir,,g"
+  # XXX: This fails if $dir contains ','.
+  path=`echo "$path" | sed -e "s,^$dir,,g"` || return 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"
 }
 
 is_path_readable_by_grub ()

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

* Re: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin
  2008-07-27 21:57   ` Christian Franke
@ 2008-07-29 16:51     ` Christian Franke
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Franke @ 2008-07-29 16:51 UTC (permalink / raw)
  To: The development of GRUB 2

Christian Franke wrote:
> Robert Millan wrote:
>> On Sun, Jul 20, 2008 at 02:40:14PM +0200, Christian Franke wrote:
>>  
>>> 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.
>>>     
>>
>> This is different than the usual grub-probe usage in that it doesn't 
>> operate
>> on a device.  Perhaps it would make sense to add the functionality 
>> you want in
>> a separate utility?
>>
>> I have an increasing feeling that grub-probe is becoming bloated 
>> (though I
>> admit, this is mostly my fault)
>>
>>   
>
> Here is a version with works without grub-probe.
>

Committed, grub-probe not affected.

Now Cygwin support should be complete.


Christian




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

end of thread, other threads:[~2008-07-29 16:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-20 12:40 [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin Christian Franke
2008-07-22 21:52 ` 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

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.