]> git.proxmox.com Git - grub2.git/commitdiff
2008-02-28 Fabian Greffrath <greffrath@leat.rub.de>
authorrobertmh <robertmh@localhost>
Thu, 28 Feb 2008 10:11:06 +0000 (10:11 +0000)
committerrobertmh <robertmh@localhost>
Thu, 28 Feb 2008 10:11:06 +0000 (10:11 +0000)
        * 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.

ChangeLog
include/grub/util/getroot.h
util/getroot.c
util/grub-probe.c

index 16cc6ed2d72e9508e19e186e4e32fbc6623e8d80..f0dee54e2e36554f72166cfd12a0a10aa2ba121e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-02-28  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.
+
 2008-02-24  Bean  <bean123ch@gmail.com>
 
        * fs/iso9660.c (GRUB_ISO9660_VOLDESC_BOOT): New macro.
index 45b66880b3ee8bfb33cedb45552b81a8b92d3c41..0d78538dfc77ff6b8e5257ede8c4deb9339287d7 100644 (file)
@@ -29,5 +29,6 @@ char *grub_guess_root_device (const char *dir);
 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 */
index a591dc81f8c1ad6589b0f3e9984130ea9bfcc1a9..0c4b376e7ffa4b8e6f863f51dd21b839fd601d80 100644 (file)
@@ -332,3 +332,17 @@ grub_util_get_grub_dev (const char *os_dev)
 
   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;
+}
index 3635d74a41e0c9d4ab90f208717781370123ac93..dabd768220feee37bd8ac7e135c35eb43ee31542 100644 (file)
@@ -50,6 +50,7 @@ enum {
 };
 
 int print = PRINT_FS;
+static unsigned int argument_is_device = 0;
 
 void
 grub_putchar (int c)
@@ -100,16 +101,22 @@ probe_partmap (grub_disk_t disk)
 }
 
 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 @@ probe (const char *path)
   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 @@ usage (int status)
             "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 @@ int
 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 @@ main (int argc, char *argv[])
   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 @@ main (int argc, char *argv[])
       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 @@ main (int argc, char *argv[])
   grub_init_all ();
 
   /* Do it.  */
-  probe (path);
+  if (argument_is_device)
+    probe (NULL, argument);
+  else
+    probe (argument, NULL);
   
   /* Free resources.  */
   grub_fini_all ();