grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Borzenkov <arvidjaar@gmail.com>
To: grub-devel@gnu.org
Subject: [PATCH 1/2] revert 69ca97c820, it broke using OS device name as install device
Date: Sat,  7 Dec 2013 12:44:31 +0400	[thread overview]
Message-ID: <1386405872-28362-1-git-send-email-arvidjaar@gmail.com> (raw)
In-Reply-To: <CAA91j0W2q2CCTniNRhodO7USmKB+3e_DEVKHcpPNAUFzqh+02A@mail.gmail.com>

grub-install already performs install device to grub device mapping (it
needs it to compare install and /boot devices), so after this patch SETUP
got called with grub device and tried to perform mapping again.
---
 ChangeLog         |  5 +++++
 util/grub-setup.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 util/setup.c      | 26 +-------------------------
 3 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 203038e..b93db5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-11-29  Andrey Borzenkov <arvidjaar@gmail.com>
+
+	Revert commit 69ca97c820, it cause failures in using OS device name
+	in grub-install.
+
 2013-12-06  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	Don't add -mlong-calls when compiling with clang.
diff --git a/util/grub-setup.c b/util/grub-setup.c
index cc3af5d..90b9de0 100644
--- a/util/grub-setup.c
+++ b/util/grub-setup.c
@@ -209,9 +209,23 @@ DEVICE must be an OS device (e.g. /dev/sda)."),
   NULL, help_filter, NULL
 };
 
+static char *
+get_device_name (char *dev)
+{
+  size_t len = strlen (dev);
+
+  if (dev[0] != '(' || dev[len - 1] != ')')
+    return 0;
+
+  dev[len - 1] = '\0';
+  return dev + 1;
+}
+
 int
 main (int argc, char *argv[])
 {
+  char *root_dev = NULL;
+  char *dest_dev = NULL;
   struct arguments arguments;
 
   grub_util_host_init (&argc, &argv);
@@ -250,11 +264,34 @@ main (int argc, char *argv[])
   grub_mdraid1x_init ();
   grub_lvm_init ();
 
+  dest_dev = get_device_name (arguments.device);
+  if (! dest_dev)
+    {
+      /* Possibly, the user specified an OS device file.  */
+      dest_dev = grub_util_get_grub_dev (arguments.device);
+      if (! dest_dev)
+        {
+          char *program = xstrdup(program_name);
+          fprintf (stderr, _("Invalid device `%s'.\n"), arguments.device);
+          argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
+          free(program);
+          exit(1);
+        }
+      grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
+                      arguments.device, dest_dev);
+    }
+  else
+    {
+      /* For simplicity.  */
+      dest_dev = xstrdup (dest_dev);
+      grub_util_info ("Using `%s' as GRUB device", dest_dev);
+    }
+
   /* Do the real work.  */
   GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY,
 		   arguments.boot_file ? : DEFAULT_BOOT_FILE,
 		   arguments.core_file ? : DEFAULT_CORE_FILE,
-		   arguments.device, arguments.force,
+		   dest_dev, arguments.force,
 		   arguments.fs_probe, arguments.allow_floppy);
 
   /* Free resources.  */
@@ -266,6 +303,8 @@ main (int argc, char *argv[])
   free (arguments.dir);
   free (arguments.dev_map);
   free (arguments.device);
+  free (root_dev);
+  free (dest_dev);
 
   return 0;
 }
diff --git a/util/setup.c b/util/setup.c
index c1de3d2..337c304 100644
--- a/util/setup.c
+++ b/util/setup.c
@@ -247,13 +247,12 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)),
 void
 SETUP (const char *dir,
        const char *boot_file, const char *core_file,
-       const char *dev, int force,
+       const char *dest, int force,
        int fs_probe, int allow_floppy)
 {
   char *core_path;
   char *boot_img, *core_img, *boot_path;
   char *root = 0;
-  char *dest = 0;
   size_t boot_size, core_size;
 #ifdef GRUB_SETUP_BIOS
   grub_uint16_t core_sectors;
@@ -270,28 +269,6 @@ SETUP (const char *dir,
 #endif
   bl.last_length = 0;
 
-  {
-    size_t len = strlen (dev);
-
-    if (len > 2 && dev[0] == '(' && dev[len - 1] == ')')
-      {
-	dest = xmalloc (len - 1);
-	strncpy (dest, dev + 1, len - 2);
-	dest[len - 2] = '\0';
-      }
-  }
-
-  if (! dest)
-    {
-      /* Possibly, the user specified an OS device file.  */
-      dest = grub_util_get_grub_dev (dev);
-      if (! dest)
-          grub_util_error (_("Invalid device `%s'.\n"), dev);
-      grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
-                      dev, dest);
-    }
-
-
   /* Read the boot image by the OS service.  */
   boot_path = grub_util_get_path (dir, boot_file);
   boot_size = grub_util_get_image_size (boot_path);
@@ -326,7 +303,6 @@ SETUP (const char *dir,
   dest_dev = grub_device_open (dest);
   if (! dest_dev)
     grub_util_error ("%s", grub_errmsg);
-  free (dest);
 
   core_dev = dest_dev;
 
-- 
1.8.1.4



  reply	other threads:[~2013-12-07  8:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 21:39 [PATCH] Fix grub-install with OS device name Colin Watson
2013-12-04 21:54 ` Jonathan McCune
2013-12-04 22:15   ` Colin Watson
2013-12-05  5:56     ` arvidjaar
2013-12-05  7:08       ` Andrey Borzenkov
2013-12-07  8:44         ` Andrey Borzenkov [this message]
2013-12-07  8:44           ` [PATCH 2/2] second attempt to fix using grub device name as install device Andrey Borzenkov
2013-12-07  8:47             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07  9:40               ` Andrey Borzenkov
2013-12-07  9:42                 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07 10:19                   ` [PATCH 2/2 v2] " Andrey Borzenkov
2013-12-07 13:50                     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07 13:59                       ` Andrey Borzenkov
2013-12-07 14:14                         ` Vladimir 'φ-coder/phcoder' Serbinenko

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=1386405872-28362-1-git-send-email-arvidjaar@gmail.com \
    --to=arvidjaar@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).