From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JOUPN-0006wd-TA for mharc-grub-devel@gnu.org; Mon, 11 Feb 2008 03:53:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JOUPL-0006tT-2M for grub-devel@gnu.org; Mon, 11 Feb 2008 03:52:59 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JOUPI-0006sS-MO for grub-devel@gnu.org; Mon, 11 Feb 2008 03:52:58 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JOUPI-0006sP-Hs for grub-devel@gnu.org; Mon, 11 Feb 2008 03:52:56 -0500 Received: from mx2.rz.ruhr-uni-bochum.de ([134.147.64.30]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JOUPH-0008IR-Q6 for grub-devel@gnu.org; Mon, 11 Feb 2008 03:52:56 -0500 X-Queued: (qmail 22328 invoked by uid 281); 11 Feb 2008 08:52:54 -0000 X-Qmailscanner: from 134.147.252.214 by mx2.rz.ruhr-uni-bochum.de (envelope-from , uid 80) with qmail-scanner-2.01 (sophie: 3.05/2.52/4.24. Clear:RC:1(134.147.252.214):. Processed in 0.057081 secs); 11 Feb 2008 08:52:54 -0000 Received: from router.leat.ruhr-uni-bochum.de (134.147.252.214) by mx2.rz.ruhr-uni-bochum.de with SMTP; 11 Feb 2008 08:52:53 -0000 Received: from [134.147.55.45] (frodo.leat.ruhr-uni-bochum.de [134.147.55.45]) by router.leat.ruhr-uni-bochum.de (8.12.2/8.12.2/SuSE Linux 0.6) with ESMTP id m1B8vt1l009892 for ; Mon, 11 Feb 2008 09:57:55 +0100 Message-ID: <47B00CFB.4070304@leat.rub.de> Date: Mon, 11 Feb 2008 09:53:15 +0100 From: Fabian Greffrath User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: The development of GRUB 2 Content-Type: multipart/mixed; boundary="------------050602030305000708060303" X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 Subject: [PATCH] Add option to grub-probe to accept system devices as arguments 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, 11 Feb 2008 08:52:59 -0000 This is a multi-part message in MIME format. --------------050602030305000708060303 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit The following patch adds to grub-probe the ability to accept system devices as arguments and e.g. convert between system devices and GRUB drives. This patch is improved over the one from my previous posting and has some minor issues fixed. Please use this version instead. It is all my work. --------------050602030305000708060303 Content-Type: text/x-patch; name="grub-probe.diff" Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="grub-probe.diff" 2008-02-11 Fabian Greffrath * util/grub-probe.c: Add new parameter '-d, --device'. If this is set, grub-probe expects the given argument to be a block device. All of the '--target' parameters work with this option as well. If the '--device' parameter is not set, grub-probe will work as before. * util/getroot.c (grub_util_check_block_device): New public function that returns the given argument if it is a block device and returns NULL else. * util/getroot.h (grub_util_check_block_device): Export function. diff -Naru grub2-1.96+20080203~/include/grub/util/getroot.h grub2-1.96+20080203/include/grub/util/getroot.h --- grub2-1.96+20080203~/include/grub/util/getroot.h 2008-01-12 16:11:56.000000000 +0100 +++ grub2-1.96+20080203/include/grub/util/getroot.h 2008-02-08 12:49:52.000000000 +0100 @@ -29,5 +29,6 @@ char *grub_get_prefix (const char *dir); int grub_util_get_dev_abstraction (const char *os_dev); char *grub_util_get_grub_dev (const char *os_dev); +char *grub_util_check_block_device (const char *blk_dev); #endif /* ! GRUB_UTIL_GETROOT_HEADER */ diff -Naru grub2-1.96+20080203~/util/getroot.c grub2-1.96+20080203/util/getroot.c --- grub2-1.96+20080203~/util/getroot.c 2008-01-12 16:11:56.000000000 +0100 +++ grub2-1.96+20080203/util/getroot.c 2008-02-08 12:49:52.000000000 +0100 @@ -327,3 +327,17 @@ return grub_dev; } + +char * +grub_util_check_block_device (const char *blk_dev) +{ + struct stat st; + + if (stat (blk_dev, &st) < 0) + grub_util_error ("Cannot stat `%s'", blk_dev); + + if (S_ISBLK (st.st_mode)) + return strdup (blk_dev); + else + return 0; +} diff -Naru grub2-1.96+20080203~/util/grub-probe.c grub2-1.96+20080203/util/grub-probe.c --- grub2-1.96+20080203~/util/grub-probe.c 2008-01-25 23:33:57.000000000 +0100 +++ grub2-1.96+20080203/util/grub-probe.c 2008-02-08 12:50:13.000000000 +0100 @@ -50,6 +50,7 @@ }; int print = PRINT_FS; +static unsigned int argument_is_device = 0; void grub_putchar (int c) @@ -84,9 +85,18 @@ int abstraction_type; grub_device_t dev = NULL; - device_name = grub_guess_root_device (path); + if (argument_is_device) + device_name = grub_util_check_block_device (path); + else + device_name = grub_guess_root_device (path); + if (! device_name) - grub_util_error ("cannot find a device for %s.\n", path); + { + if (argument_is_device) + grub_util_error ("%s is not a block device.\n", path); + else + grub_util_error ("cannot find a device for %s.\n", path); + } if (print == PRINT_DEVICE) { @@ -201,6 +211,7 @@ static struct option options[] = { + {"device", no_argument, 0, 'd'}, {"device-map", required_argument, 0, 'm'}, {"target", required_argument, 0, 't'}, {"help", no_argument, 0, 'h'}, @@ -217,10 +228,11 @@ "Try ``grub-probe --help'' for more information.\n"); else printf ("\ -Usage: grub-probe [OPTION]... PATH\n\ +Usage: grub-probe [OPTION]... [PATH|DEVICE]\n\ \n\ -Probe device information for a given path.\n\ +Probe device information for a given path or device.\n\ \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|drive|device|partmap|abstraction)\n\ print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\ @@ -246,13 +258,17 @@ /* Check for options. */ while (1) { - int c = getopt_long (argc, argv, "m:t:hVv", options, 0); + int c = getopt_long (argc, argv, "dm:t:hVv", options, 0); if (c == -1) break; else switch (c) { + case 'd': + argument_is_device = 1; + break; + case 'm': if (dev_map) free (dev_map); --------------050602030305000708060303--