From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Imb5p-0001IQ-Vc for mharc-grub-devel@gnu.org; Mon, 29 Oct 2007 16:20:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Imb5o-0001Fc-4Q for grub-devel@gnu.org; Mon, 29 Oct 2007 16:20:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Imb5m-0001CF-WD for grub-devel@gnu.org; Mon, 29 Oct 2007 16:20:11 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Imb5m-0001C4-C0 for grub-devel@gnu.org; Mon, 29 Oct 2007 16:20:10 -0400 Received: from mailout11.sul.t-online.de ([194.25.134.85] helo=mailout11.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Imb5l-0000UB-Rq for grub-devel@gnu.org; Mon, 29 Oct 2007 16:20:10 -0400 Received: from fwd34.aul.t-online.de by mailout11.aul.t-online.de with smtp id 1Imb5k-0006x7-02; Mon, 29 Oct 2007 21:20:08 +0100 Received: from [10.3.2.2] (Vr3+mBZlYhpPBuqKr3EvBUB6qBuYWRPqig7xTgP5JSLjjy5pHZySsEgxXF-nXQvZYb@[217.235.251.198]) by fwd34.aul.t-online.de with esmtp id 1Imb5a-15BQqe0; Mon, 29 Oct 2007 21:19:58 +0100 Message-ID: <47264070.7060007@t-online.de> Date: Mon, 29 Oct 2007 21:20:00 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------080801050407010907000807" X-ID: Vr3+mBZlYhpPBuqKr3EvBUB6qBuYWRPqig7xTgP5JSLjjy5pHZySsEgxXF-nXQvZYb X-TOI-MSGID: da9b3031-452c-4b8d-8a7c-017f9cc136a9 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] grub-probe -t prefix, -t all 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: Mon, 29 Oct 2007 20:20:12 -0000 This is a multi-part message in MIME format. --------------080801050407010907000807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch adds '-t prefix', '-t all', and allows multiple -t options to be specified. '-t prefix' was initially added to test grub_get_prefix() on Cygwin, but may be useful in scripts. Christian 2007-10-29 Christian Franke * util/grub-probe.c (#define PRINT_*): Change to bitmasks to allow multiple '-t type' options. Add PRINT_PREFIX (-t prefix) (probe): Likewise. Types now passed as parameter. (main): Likewise. Add '-t all' --------------080801050407010907000807 Content-Type: text/x-patch; name="grub2-grub-probe-prefix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-grub-probe-prefix.patch" --- grub2.orig/util/grub-probe.c 2007-07-22 21:17:26.000000000 +0200 +++ grub2/util/grub-probe.c 2007-10-14 17:28:29.000000000 +0200 @@ -39,12 +39,11 @@ #define _GNU_SOURCE 1 #include -#define PRINT_FS 0 -#define PRINT_DRIVE 1 -#define PRINT_DEVICE 2 -#define PRINT_PARTMAP 3 - -int print = PRINT_FS; +#define PRINT_FS 0x01 +#define PRINT_DRIVE 0x02 +#define PRINT_PREFIX 0x04 +#define PRINT_DEVICE 0x08 +#define PRINT_PARTMAP 0x10 void grub_putchar (int c) @@ -70,7 +69,7 @@ } static void -probe (const char *path) +probe (const char *path, int types) { char *device_name; char *drive_name = NULL; @@ -81,20 +80,36 @@ if (! device_name) grub_util_error ("cannot find a device for %s.\n", path); - if (print == PRINT_DEVICE) + if (types & PRINT_DEVICE) { printf ("%s\n", device_name); - goto end; + types &= ~PRINT_DEVICE; + if (types == 0) + goto end; } drive_name = grub_util_get_grub_dev (device_name); if (! drive_name) grub_util_error ("cannot find a GRUB drive for %s.\n", device_name); - if (print == PRINT_DRIVE) + if (types & PRINT_DRIVE) { printf ("(%s)\n", drive_name); - goto end; + types &= ~PRINT_DRIVE; + if (types == 0) + goto end; + } + + if (types & PRINT_PREFIX) + { + char * prefix = grub_get_prefix (path); + if (! prefix) + grub_util_error ("cannot find prefix for %s.\n", path); + printf ("%s\n", prefix); + free (prefix); + types &= ~PRINT_PREFIX; + if (types == 0) + goto end; } grub_util_info ("opening %s", drive_name); @@ -102,7 +117,7 @@ if (! dev) grub_util_error ("%s", grub_errmsg); - if (print == PRINT_PARTMAP) + if (types & PRINT_PARTMAP) { if (dev->disk->partition == NULL) grub_util_error ("Cannot detect partition map for %s", drive_name); @@ -119,14 +134,16 @@ printf ("sun\n"); else grub_util_error ("Unknown partition map %s", dev->disk->partition->partmap->name); - goto end; } - fs = grub_fs_probe (dev); - if (! fs) - grub_util_error ("%s", grub_errmsg); + if (types & PRINT_FS) + { + fs = grub_fs_probe (dev); + if (! fs) + grub_util_error ("%s", grub_errmsg); - printf ("%s\n", fs->name); + printf ("%s\n", fs->name); + } grub_device_close (dev); @@ -159,8 +176,9 @@ Probe device information for a given path.\n\ \n\ -m, --device-map=FILE use FILE as the device map [default=%s]\n\ - -t, --target=(fs|drive|device|partmap)\n\ - print filesystem module, GRUB drive, system device or partition map module [default=fs]\n\ + -t, --target=(fs|drive|prefix|device|partmap|all)\n\ + print filesystem module, GRUB drive, path prefix, system device\n\ + or partition map 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\ @@ -175,6 +193,7 @@ int main (int argc, char *argv[]) { + unsigned types = 0; char *dev_map = 0; char *path; @@ -199,13 +218,17 @@ case 't': if (!strcmp (optarg, "fs")) - print = PRINT_FS; + types |= PRINT_FS; else if (!strcmp (optarg, "drive")) - print = PRINT_DRIVE; + types |= PRINT_DRIVE; + else if (!strcmp (optarg, "prefix")) + types |= PRINT_PREFIX; else if (!strcmp (optarg, "device")) - print = PRINT_DEVICE; + types |= PRINT_DEVICE; else if (!strcmp (optarg, "partmap")) - print = PRINT_PARTMAP; + types |= PRINT_PARTMAP; + else if (!strcmp (optarg, "all")) + types = ~0; else usage (1); break; @@ -227,6 +250,8 @@ break; } } + if (types == 0) + types = PRINT_FS; /* Obtain PATH. */ if (optind >= argc) @@ -250,7 +275,7 @@ grub_init_all (); /* Do it. */ - probe (path); + probe (path, types); /* Free resources. */ grub_fini_all (); --------------080801050407010907000807--