All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabian Greffrath <greffrath@leat.rub.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Cc: Robert Millan <rmh@aybabtu.com>
Subject: Re: [NEW PATCH] Add option to grub-probe to accept system devices as arguments
Date: Mon, 25 Feb 2008 10:49:01 +0100	[thread overview]
Message-ID: <47C28F0D.7090703@leat.rub.de> (raw)
In-Reply-To: <20080224152237.GB25984@thorin>

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

Hello!

Robert Millan schrieb:
> It looks good to me.  Just a pair of minor details (simply for consistency with
> code style in grub):
> [...]

done.

> If you fix those, include a ChangeLog entry and noone else objects, I'll commit
> it.  Feel free to ping me with a direct mail if I stale for too long.

You are CCed. ;)

Robert Millan schrieb:
 > Is this solved now?  If not, you could send a gdb backtrace to give us an idea
 > on what's wrong.

Yes, it's fixed in the second patch that you reviewed (and in the one that's 
attached, too).

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: grub-probe-20080222-3.diff --]
[-- Type: text/x-patch; name="grub-probe-20080222-3.diff", Size: 5227 bytes --]

2008-02-25  Fabian Greffrath  <greffrath@leat.rub.de>

	* include/grub/util/getroot.h (grub_util_check_block_device): Export new
	function.
	* util/getroot.c (grub_util_check_block_device): New function that
	returns the given argument if it is a block device and returns NULL else.
	* util/grub-probe.c (argument_is_device): New variable.
	(probe): Promote device_name from a variable to an argument. Receive
	device_name from grub_util_check_block_device() if path is NULL and from
	grub_guess_root_device() else. Do not free() device_name anymore.
	(options): Introduce new parameter '-d, --device'. 
	(main): Add description of the new parameter to the help screen.
	Rename path variable to argument. Set argument_is_device if the '-d'
	option is given. Pass argument to probe() depending on
	argument_is_device.


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 16:00:01.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, 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", device_name);
+    }
+  else
+    device_name = grub_guess_root_device (path);
+
   if (! device_name)
     grub_util_error ("cannot find a device for %s.\n", path);
 
@@ -220,12 +227,12 @@
   free (grub_path);
   free (filebuf_via_grub);
   free (filebuf_via_sys);
-  free (device_name);
   free (drive_name);
 }
 
 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 +249,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 +272,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 +333,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 +346,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 +355,10 @@
   grub_init_all ();
 
   /* Do it.  */
-  probe (path);
+  if (argument_is_device)
+    probe (NULL, argument);
+  else
+    probe (argument, NULL);
   
   /* Free resources.  */
   grub_fini_all ();

  reply	other threads:[~2008-02-25  9:48 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-12 13:17 [PATCH] Add option to grub-probe to accept system devices as arguments Fabian Greffrath
2008-02-13 13:03 ` Fabian Greffrath
2008-02-13 15:42 ` Robert Millan
2008-02-13 16:51   ` Fabian Greffrath
2008-02-13 19:35     ` Robert Millan
2008-02-14  8:33       ` Fabian Greffrath
2008-02-17 13:42         ` Robert Millan
2008-02-18 12:54           ` Fabian Greffrath
2008-02-20 14:14           ` Fabian Greffrath
2008-02-22 14:32           ` [NEW PATCH] " Fabian Greffrath
2008-02-22 15:36             ` Fabian Greffrath
2008-02-24 15:22               ` Robert Millan
2008-02-25  9:49                 ` Fabian Greffrath [this message]
2008-02-25 14:20                   ` Robert Millan
2008-02-28  7:26                     ` Fabian Greffrath
2008-02-28 10:10                       ` Robert Millan
2008-02-28 10:28                         ` Fabian Greffrath
2008-02-28 10:41                           ` Robert Millan
2008-02-28 11:46                             ` Fabian Greffrath
2008-02-28 17:07                               ` Robert Millan
2008-02-29  8:33                                 ` Fabian Greffrath
2008-03-03 21:06                                   ` Robert Millan
2008-03-04  7:57                                     ` Fabian Greffrath
2008-03-05 12:27                                     ` [NEW PATCH] os-prober output parser Fabian Greffrath
2008-03-13  7:56                                       ` Fabian Greffrath
2008-03-19 14:38                                       ` Robert Millan
2008-03-19 15:18                                         ` Fabian Greffrath
2008-03-19 16:10                                           ` Robert Millan
2008-03-20 10:02                                             ` Fabian Greffrath
2008-03-20 10:36                                               ` Robert Millan
2008-03-25  7:27                                                 ` Fabian Greffrath
2008-04-07  8:39                                                   ` Fabian Greffrath
2008-04-09  8:32                                                     ` Fabian Greffrath
2008-04-09 10:11                                                       ` Robert Millan
2008-04-09 12:41                                                         ` Fabian Greffrath
2008-04-13 10:52                                                     ` Robert Millan
2008-04-14 11:11                                                       ` Fabian Greffrath
2008-02-29 13:46                                 ` [NEW PATCH] Add option to grub-probe to accept system devices as arguments Fabian Greffrath
2008-03-03 20:58                                   ` Robert Millan
2008-02-24 15:23             ` Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47C28F0D.7090703@leat.rub.de \
    --to=greffrath@leat.rub.de \
    --cc=grub-devel@gnu.org \
    --cc=rmh@aybabtu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.