All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: [PATCH] grub-probe -t prefix, -t all
Date: Mon, 29 Oct 2007 21:20:00 +0100	[thread overview]
Message-ID: <47264070.7060007@t-online.de> (raw)

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

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  <franke@computer.org>

	* 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'



[-- Attachment #2: grub2-grub-probe-prefix.patch --]
[-- Type: text/x-patch, Size: 4143 bytes --]

--- 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 <getopt.h>
 
-#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 ();

             reply	other threads:[~2007-10-29 20:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-29 20:20 Christian Franke [this message]
2007-11-09 21:13 ` [PATCH] grub-probe -t prefix, -t all Robert Millan
2007-11-09 21:42   ` Christian Franke
2007-11-09 22:56     ` Robert Millan
2007-11-10  0:03       ` Christian Franke

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=47264070.7060007@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /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.