From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KKYDJ-00006A-3R for mharc-grub-devel@gnu.org; Sun, 20 Jul 2008 08:40:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KKYDG-0008Uo-LG for grub-devel@gnu.org; Sun, 20 Jul 2008 08:40:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KKYDF-0008TG-6j for grub-devel@gnu.org; Sun, 20 Jul 2008 08:40:29 -0400 Received: from [199.232.76.173] (port=45807 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KKYDE-0008SN-NQ for grub-devel@gnu.org; Sun, 20 Jul 2008 08:40:28 -0400 Received: from mailout04.t-online.de ([194.25.134.18]:38318) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KKYDE-00056H-2D for grub-devel@gnu.org; Sun, 20 Jul 2008 08:40:28 -0400 Received: from fwd27.aul.t-online.de by mailout04.sul.t-online.de with smtp id 1KKYDA-00037K-01; Sun, 20 Jul 2008 14:40:24 +0200 Received: from [10.3.2.2] (JJQ5ITZaohNht9qyxJjmNUXphQ7RkEsOyRsXD+ToqjvxfduoWyyrMBUr62LPXyRQMb@[217.235.255.138]) by fwd27.aul.t-online.de with esmtp id 1KKYCz-0P6frc0; Sun, 20 Jul 2008 14:40:13 +0200 Message-ID: <4883322E.6040606@t-online.de> Date: Sun, 20 Jul 2008 14:40:14 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 MIME-Version: 1.0 To: The development of GRUB 2 Content-Type: multipart/mixed; boundary="------------070507000800060101000206" X-ID: JJQ5ITZaohNht9qyxJjmNUXphQ7RkEsOyRsXD+ToqjvxfduoWyyrMBUr62LPXyRQMb X-TOI-MSGID: 523cc27b-ebe5-4752-acf5-8e5a743b0c33 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] grub-probe -t prefix, fix update-grub_lib for Cygwin X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jul 2008 12:40:31 -0000 This is a multi-part message in MIME format. --------------070507000800060101000206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 * 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. --------------070507000800060101000206 Content-Type: text/x-diff; name="grub2-grub-probe-prefix-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-grub-probe-prefix-2.patch" 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 () --------------070507000800060101000206--