From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JSYwI-0002bN-T6 for mharc-grub-devel@gnu.org; Fri, 22 Feb 2008 09:31:50 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JSYwE-0002a0-HB for grub-devel@gnu.org; Fri, 22 Feb 2008 09:31:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JSYw9-0002Y3-6p for grub-devel@gnu.org; Fri, 22 Feb 2008 09:31:45 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JSYw9-0002Y0-32 for grub-devel@gnu.org; Fri, 22 Feb 2008 09:31:41 -0500 Received: from mx3.rz.ruhr-uni-bochum.de ([134.147.64.33]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JSYw8-0004KL-Go for grub-devel@gnu.org; Fri, 22 Feb 2008 09:31:40 -0500 X-Queued: (qmail 14873 invoked by uid 271); 22 Feb 2008 14:31:37 -0000 X-Qmailscanner: from 134.147.252.214 by mx3.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.105831 secs); 22 Feb 2008 14:31:37 -0000 Received: from router.leat.ruhr-uni-bochum.de (134.147.252.214) by mx3.rz.ruhr-uni-bochum.de with SMTP; 22 Feb 2008 14:31:37 -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 m1MEbB1l017301 for ; Fri, 22 Feb 2008 15:37:11 +0100 Message-ID: <47BEDCE2.3000301@leat.rub.de> Date: Fri, 22 Feb 2008 15:32:02 +0100 From: Fabian Greffrath User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: The development of GRUB 2 References: <47B19C57.9020902@leat.rub.de> <20080213154224.GB30040@thorin> <47B32029.200@leat.rub.de> <20080213193534.GA28711@thorin> <47B3FCEC.6020107@leat.rub.de> <20080217134219.GB15576@thorin> In-Reply-To: <20080217134219.GB15576@thorin> Content-Type: multipart/mixed; boundary="------------090606090605020808070704" X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 Subject: [NEW 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: Fri, 22 Feb 2008 14:31:47 -0000 This is a multi-part message in MIME format. --------------090606090605020808070704 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Robert, I have created another patch which introduces some of your suggestions, e.g. probe() is called with two arguments and grub_util_check_block_device() does not strdup() the returned string. However, grub-probe crashes with a double free error message if run with the -d option. I am somehow stuck in this situation, can you please help me? I promise I'll provide a changelog as soon as there is a chance that my patch will get applied. ;) Cheers, Fabian -- Dipl.-Phys. Fabian Greffrath Ruhr-Universität Bochum Lehrstuhl für Energieanlagen und Energieprozesstechnik (LEAT) Universitätsstr. 150, IB 3/134 D-44780 Bochum Telefon: +49 (0)234 / 32-26334 Fax: +49 (0)234 / 32-14227 E-Mail: greffrath@leat.ruhr-uni-bochum.de --------------090606090605020808070704 Content-Type: text/x-diff; name="grub-probe-20080222-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub-probe-20080222-1.patch" diff -Naru grub2-1.96+20080219~/include/grub/util/getroot.h grub2-1.96+20080219/include/grub/util/getroot.h --- grub2-1.96+20080219~/include/grub/util/getroot.h 2008-01-12 16:11:56.000000000 +0100 +++ grub2-1.96+20080219/include/grub/util/getroot.h 2008-02-22 14:40:41.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+20080219~/util/getroot.c grub2-1.96+20080219/util/getroot.c --- grub2-1.96+20080219~/util/getroot.c 2008-02-12 23:45:58.000000000 +0100 +++ grub2-1.96+20080219/util/getroot.c 2008-02-22 14:45:52.000000000 +0100 @@ -332,3 +332,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 (blk_dev); + else + return 0; +} diff -Naru grub2-1.96+20080219~/util/grub-probe.c grub2-1.96+20080219/util/grub-probe.c --- grub2-1.96+20080219~/util/grub-probe.c 2008-02-09 11:49:29.000000000 +0100 +++ grub2-1.96+20080219/util/grub-probe.c 2008-02-22 14:56:28.000000000 +0100 @@ -50,6 +50,7 @@ }; int print = PRINT_FS; +static unsigned int argument_is_device = 0; void grub_putchar (int c) @@ -100,16 +101,22 @@ } static void -probe (const char *path) +probe (const char *path, const char *device_name) { - char *device_name; char *drive_name = NULL; char *grub_path = NULL; char *filebuf_via_grub = NULL, *filebuf_via_sys = NULL; int abstraction_type; grub_device_t dev = NULL; - device_name = grub_guess_root_device (path); + if (path == NULL) + { + if ( ! grub_util_check_block_device (device_name)) + grub_util_error ("%s is not a block device.\n", path); + } + else + device_name = grub_guess_root_device (path); + if (! device_name) grub_util_error ("cannot find a device for %s.\n", path); @@ -226,6 +233,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'}, @@ -242,10 +250,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, if the -d option is given).\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\ @@ -264,20 +273,24 @@ main (int argc, char *argv[]) { char *dev_map = 0; - char *path; + char *argument; progname = "grub-probe"; /* 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); @@ -321,10 +334,10 @@ if (verbosity > 1) grub_env_set ("debug", "all"); - /* Obtain PATH. */ + /* Obtain ARGUMENT. */ if (optind >= argc) { - fprintf (stderr, "No path is specified.\n"); + fprintf (stderr, "No path or device is specified.\n"); usage (1); } @@ -334,7 +347,7 @@ usage (1); } - path = argv[optind]; + argument = argv[optind]; /* Initialize the emulated biosdisk driver. */ grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP); @@ -343,7 +356,10 @@ grub_init_all (); /* Do it. */ - probe (path); + if (argument_is_device) + probe (NULL,argument); + else + probe (argument,NULL); /* Free resources. */ grub_fini_all (); --------------090606090605020808070704--