]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Remove getroot.c from core on emu platform.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 8 Jul 2011 11:33:12 +0000 (13:33 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 8 Jul 2011 11:33:12 +0000 (13:33 +0200)
* grub-core/Makefile.core.def (kernel): Remove kern/emu/getroot.c and
kern/emu/raid.c.
* grub-core/kern/emu/main.c (main): Don't try to guess root device. It's
useless.
* grub-core/kern/emu/misc.c (get_win32_path): Moved from here...
* util/getroot.c (get_win32_path): ... here.
* grub-core/kern/emu/misc.c (fini_libzfs): Moved from here...
* util/getroot.c (fini_libzfs): ... here.
* grub-core/kern/emu/misc.c (grub_get_libzfs_handle): Moved from here...
* util/getroot.c (grub_get_libzfs_handle): ... here.
* grub-core/kern/emu/misc.c (grub_find_zpool_from_dir):
Moved from here...
* util/getroot.c (grub_find_zpool_from_dir): ... here.
* grub-core/kern/emu/misc.c
(grub_make_system_path_relative_to_its_root): Moved from here...
* util/getroot.c (grub_make_system_path_relative_to_its_root): ... here.
* grub-core/kern/emu/getroot.c: Moved from here ...
* util/getroot.c: ... here. All users updated.
* grub-core/kern/emu/raid.c: Moved from here ...
* util/raid.c: ... here. All users updated.

ChangeLog
Makefile.util.def
grub-core/Makefile.core.def
grub-core/kern/emu/main.c
grub-core/kern/emu/misc.c
util/getroot.c [moved from grub-core/kern/emu/getroot.c with 84% similarity]
util/raid.c [moved from grub-core/kern/emu/raid.c with 100% similarity]

index e86b3a4f1720e5fef32b61a2fa086ee880fb44ab..33c5b0b928f2c757d19049f036f93df79fdd8b78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2011-07-08  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Remove getroot.c from core on emu platform.
+
+       * grub-core/Makefile.core.def (kernel): Remove kern/emu/getroot.c and
+       kern/emu/raid.c.
+       * grub-core/kern/emu/main.c (main): Don't try to guess root device. It's
+       useless.
+       * grub-core/kern/emu/misc.c (get_win32_path): Moved from here...
+       * util/getroot.c (get_win32_path): ... here.
+       * grub-core/kern/emu/misc.c (fini_libzfs): Moved from here...
+       * util/getroot.c (fini_libzfs): ... here.
+       * grub-core/kern/emu/misc.c (grub_get_libzfs_handle): Moved from here...
+       * util/getroot.c (grub_get_libzfs_handle): ... here.
+       * grub-core/kern/emu/misc.c (grub_find_zpool_from_dir):
+       Moved from here...
+       * util/getroot.c (grub_find_zpool_from_dir): ... here.
+       * grub-core/kern/emu/misc.c
+       (grub_make_system_path_relative_to_its_root): Moved from here...
+       * util/getroot.c (grub_make_system_path_relative_to_its_root): ... here.
+       * grub-core/kern/emu/getroot.c: Moved from here ...
+       * util/getroot.c: ... here. All users updated.
+       * grub-core/kern/emu/raid.c: Moved from here ...
+       * util/raid.c: ... here. All users updated.
+
 2011-07-08  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * po/POTFILES.in: Regenerate.
index 18dd2fef8bec91ddd6636a3eb675f722fa7cb844..c87020493371851c22d28606256e36d65df60711 100644 (file)
@@ -9,8 +9,8 @@ library = {
   common = grub-core/kern/command.c;
   common = grub-core/kern/device.c;
   common = grub-core/kern/disk.c;
-  common = grub-core/kern/emu/getroot.c;
-  common = grub-core/kern/emu/raid.c;
+  common = util/getroot.c;
+  common = util/raid.c;
   common = grub-core/kern/emu/hostdisk.c;
   common = grub-core/kern/emu/misc.c;
   common = grub-core/kern/emu/mm.c;
index 7200bd3e957c5ade2cb53a22a30959ba32e1d94e..0924602f37e29e8e880579c649f85a7198de3cfe 100644 (file)
@@ -195,8 +195,6 @@ kernel = {
   emu = gnulib/error.c;
   emu = kern/emu/cache_s.S;
   emu = kern/emu/console.c;
-  emu = kern/emu/getroot.c;
-  emu = kern/emu/raid.c;
   emu = kern/emu/hostdisk.c;
   emu = kern/emu/hostfs.c;
   emu = kern/emu/main.c;
index 2092d03cb573e61caf0041e289165ac5bed9f47b..9a58acd9eb155aad1b50b0152c64f7073d498c77 100644 (file)
@@ -111,7 +111,7 @@ usage (int status)
       "\n"
       "GRUB emulator.\n"
       "\n"
-      "  -r, --root-device=DEV     use DEV as the root device [default=guessed]\n"
+      "  -r, --root-device=DEV     use DEV as the root device [default=host]\n"
       "  -m, --device-map=FILE     use FILE as the device map [default=%s]\n"
       "  -d, --directory=DIR       use GRUB files in the directory DIR [default=%s]\n"
       "  -v, --verbose             print verbose messages\n"
@@ -204,24 +204,9 @@ main (int argc, char *argv[])
 
   /* Make sure that there is a root device.  */
   if (! root_dev)
-    {
-      char *device_name = grub_guess_root_device (dir);
-      if (! device_name)
-        grub_util_error ("cannot find a device for %s", dir);
-
-      root_dev = grub_util_get_grub_dev (device_name);
-      if (! root_dev)
-       {
-         grub_util_info ("guessing the root device failed, because of `%s'",
-                         grub_errmsg);
-         grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
-       }
-    }
+    root_dev = grub_strdup ("host");
 
-  if (strcmp (root_dev, "host") == 0)
-    dir = xstrdup (dir);
-  else
-    dir = grub_make_system_path_relative_to_its_root (dir);
+  dir = xstrdup (dir);
 
   /* Start GRUB!  */
   if (setjmp (main_env) == 0)
index 44c40b01039c433ab10240de8271643135eb64a6..737f5f1a9d2ec4f63338599d106d685597a5aa10 100644 (file)
 # include <libdevmapper.h>
 #endif
 
-#ifdef HAVE_LIBZFS
-# include <grub/util/libzfs.h>
-#endif
-
-#ifdef HAVE_LIBNVPAIR
-# include <grub/util/libnvpair.h>
-#endif
-
 #ifdef HAVE_SYS_PARAM_H
 # include <sys/param.h>
 #endif
@@ -242,265 +234,6 @@ canonicalize_file_name (const char *path)
   return ret;
 }
 
-#ifdef __CYGWIN__
-/* Convert POSIX path to Win32 path,
-   remove drive letter, replace backslashes.  */
-static char *
-get_win32_path (const char *path)
-{
-  char winpath[PATH_MAX];
-  if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath)))
-    grub_util_error ("cygwin_conv_path() failed");
-
-  int len = strlen (winpath);
-  int offs = (len > 2 && winpath[1] == ':' ? 2 : 0);
-
-  int i;
-  for (i = offs; i < len; i++)
-    if (winpath[i] == '\\')
-      winpath[i] = '/';
-  return xstrdup (winpath + offs);
-}
-#endif
-
-#ifdef HAVE_LIBZFS
-static libzfs_handle_t *__libzfs_handle;
-
-static void
-fini_libzfs (void)
-{
-  libzfs_fini (__libzfs_handle);
-}
-
-libzfs_handle_t *
-grub_get_libzfs_handle (void)
-{
-  if (! __libzfs_handle)
-    {
-      __libzfs_handle = libzfs_init ();
-
-      if (__libzfs_handle)
-       atexit (fini_libzfs);
-    }
-
-  return __libzfs_handle;
-}
-#endif /* HAVE_LIBZFS */
-
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
-/* ZFS has similar problems to those of btrfs (see above).  */
-void
-grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs)
-{
-  char *slash;
-
-  *poolname = *poolfs = NULL;
-
-#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && defined(HAVE_STRUCT_STATFS_F_MNTFROMNAME)
-  /* FreeBSD and GNU/kFreeBSD.  */
-  {
-    struct statfs mnt;
-
-    if (statfs (dir, &mnt) != 0)
-      return;
-
-    if (strcmp (mnt.f_fstypename, "zfs") != 0)
-      return;
-
-    *poolname = xstrdup (mnt.f_mntfromname);
-  }
-#elif defined(HAVE_GETEXTMNTENT)
-  /* Solaris.  */
-  {
-    struct stat st;
-    struct extmnttab mnt;
-
-    if (stat (dir, &st) != 0)
-      return;
-
-    FILE *mnttab = fopen ("/etc/mnttab", "r");
-    if (! mnttab)
-      return;
-
-    while (getextmntent (mnttab, &mnt, sizeof (mnt)) == 0)
-      {
-       if (makedev (mnt.mnt_major, mnt.mnt_minor) == st.st_dev
-           && !strcmp (mnt.mnt_fstype, "zfs"))
-         {
-           *poolname = xstrdup (mnt.mnt_special);
-           break;
-         }
-      }
-
-    fclose (mnttab);
-  }
-#endif
-
-  if (! *poolname)
-    return;
-
-  slash = strchr (*poolname, '/');
-  if (slash)
-    {
-      *slash = '\0';
-      *poolfs = xstrdup (slash + 1);
-    }
-  else
-    *poolfs = xstrdup ("");
-}
-#endif
-
-/* This function never prints trailing slashes (so that its output
-   can be appended a slash unconditionally).  */
-char *
-grub_make_system_path_relative_to_its_root (const char *path)
-{
-  struct stat st;
-  char *p, *buf, *buf2, *buf3, *ret;
-  uintptr_t offset = 0;
-  dev_t num;
-  size_t len;
-
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
-  char *poolfs = NULL;
-#endif
-
-  /* canonicalize.  */
-  p = canonicalize_file_name (path);
-  if (p == NULL)
-    grub_util_error ("failed to get canonical path of %s", path);
-
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
-  /* For ZFS sub-pool filesystems, could be extended to others (btrfs?).  */
-  {
-    char *dummy;
-    grub_find_zpool_from_dir (p, &dummy, &poolfs);
-  }
-#endif
-
-  len = strlen (p) + 1;
-  buf = xstrdup (p);
-  free (p);
-
-  if (stat (buf, &st) < 0)
-    grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
-
-  buf2 = xstrdup (buf);
-  num = st.st_dev;
-
-  /* This loop sets offset to the number of chars of the root
-     directory we're inspecting.  */
-  while (1)
-    {
-      p = strrchr (buf, '/');
-      if (p == NULL)
-       /* This should never happen.  */
-       grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)");
-      if (p != buf)
-       *p = 0;
-      else
-       *++p = 0;
-
-      if (stat (buf, &st) < 0)
-       grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
-
-      /* buf is another filesystem; we found it.  */
-      if (st.st_dev != num)
-       {
-         /* offset == 0 means path given is the mount point.
-            This works around special-casing of "/" in Un*x.  This function never
-            prints trailing slashes (so that its output can be appended a slash
-            unconditionally).  Each slash in is considered a preceding slash, and
-            therefore the root directory is an empty string.  */
-         if (offset == 0)
-           {
-             free (buf);
-#ifdef __linux__
-             {
-               char *bind;
-               grub_free (grub_find_root_device_from_mountinfo (buf2, &bind));
-               if (bind && bind[0] && bind[1])
-                 {
-                   buf3 = bind;
-                   goto parsedir;
-                 }
-               grub_free (bind);
-             }
-#endif
-             free (buf2);
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
-             if (poolfs)
-               return xasprintf ("/%s/@", poolfs);
-#endif
-             return xstrdup ("");
-           }
-         else
-           break;
-       }
-
-      offset = p - buf;
-      /* offset == 1 means root directory.  */
-      if (offset == 1)
-       {
-         /* Include leading slash.  */
-         offset = 0;
-         break;
-       }
-    }
-  free (buf);
-  buf3 = xstrdup (buf2 + offset);
-  buf2[offset] = 0;
-#ifdef __linux__
-  {
-    char *bind;
-    grub_free (grub_find_root_device_from_mountinfo (buf2, &bind));
-    if (bind && bind[0] && bind[1])
-      {
-       char *temp = buf3;
-       buf3 = grub_xasprintf ("%s%s%s", bind, buf3[0] == '/' ?"":"/", buf3);
-       grub_free (temp);
-      }
-    grub_free (bind);
-  }
-#endif
-  
-  free (buf2);
-
-#ifdef __CYGWIN__
-  if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
-    {
-      /* Reached some mount point not below /cygdrive.
-        GRUB does not know Cygwin's emulated mounts,
-        convert to Win32 path.  */
-      grub_util_info ("Cygwin path = %s\n", buf3);
-      char * temp = get_win32_path (buf3);
-      free (buf3);
-      buf3 = temp;
-    }
-#endif
-
- parsedir:
-  /* Remove trailing slashes, return empty string if root directory.  */
-  len = strlen (buf3);
-  while (len > 0 && buf3[len - 1] == '/')
-    {
-      buf3[len - 1] = '\0';
-      len--;
-    }
-
-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
-  if (poolfs)
-    {
-      ret = xasprintf ("/%s/@%s", poolfs, buf3);
-      free (buf3);
-    }
-  else
-#endif
-    ret = buf3;
-
-  return ret;
-}
-
 #ifdef HAVE_DEVICE_MAPPER
 static void device_mapper_null_log (int level __attribute__ ((unused)),
                                    const char *file __attribute__ ((unused)),
similarity index 84%
rename from grub-core/kern/emu/getroot.c
rename to util/getroot.c
index 9986fc5fc41f1d220cf17a002092434c39ed62e6..71064583f8e239efb93af26c4f3dc15bb0d575cd 100644 (file)
@@ -1330,3 +1330,262 @@ grub_util_check_char_device (const char *blk_dev)
   else
     return 0;
 }
+
+#ifdef __CYGWIN__
+/* Convert POSIX path to Win32 path,
+   remove drive letter, replace backslashes.  */
+static char *
+get_win32_path (const char *path)
+{
+  char winpath[PATH_MAX];
+  if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath)))
+    grub_util_error ("cygwin_conv_path() failed");
+
+  int len = strlen (winpath);
+  int offs = (len > 2 && winpath[1] == ':' ? 2 : 0);
+
+  int i;
+  for (i = offs; i < len; i++)
+    if (winpath[i] == '\\')
+      winpath[i] = '/';
+  return xstrdup (winpath + offs);
+}
+#endif
+
+#ifdef HAVE_LIBZFS
+static libzfs_handle_t *__libzfs_handle;
+
+static void
+fini_libzfs (void)
+{
+  libzfs_fini (__libzfs_handle);
+}
+
+libzfs_handle_t *
+grub_get_libzfs_handle (void)
+{
+  if (! __libzfs_handle)
+    {
+      __libzfs_handle = libzfs_init ();
+
+      if (__libzfs_handle)
+       atexit (fini_libzfs);
+    }
+
+  return __libzfs_handle;
+}
+#endif /* HAVE_LIBZFS */
+
+#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+/* ZFS has similar problems to those of btrfs (see above).  */
+void
+grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs)
+{
+  char *slash;
+
+  *poolname = *poolfs = NULL;
+
+#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && defined(HAVE_STRUCT_STATFS_F_MNTFROMNAME)
+  /* FreeBSD and GNU/kFreeBSD.  */
+  {
+    struct statfs mnt;
+
+    if (statfs (dir, &mnt) != 0)
+      return;
+
+    if (strcmp (mnt.f_fstypename, "zfs") != 0)
+      return;
+
+    *poolname = xstrdup (mnt.f_mntfromname);
+  }
+#elif defined(HAVE_GETEXTMNTENT)
+  /* Solaris.  */
+  {
+    struct stat st;
+    struct extmnttab mnt;
+
+    if (stat (dir, &st) != 0)
+      return;
+
+    FILE *mnttab = fopen ("/etc/mnttab", "r");
+    if (! mnttab)
+      return;
+
+    while (getextmntent (mnttab, &mnt, sizeof (mnt)) == 0)
+      {
+       if (makedev (mnt.mnt_major, mnt.mnt_minor) == st.st_dev
+           && !strcmp (mnt.mnt_fstype, "zfs"))
+         {
+           *poolname = xstrdup (mnt.mnt_special);
+           break;
+         }
+      }
+
+    fclose (mnttab);
+  }
+#endif
+
+  if (! *poolname)
+    return;
+
+  slash = strchr (*poolname, '/');
+  if (slash)
+    {
+      *slash = '\0';
+      *poolfs = xstrdup (slash + 1);
+    }
+  else
+    *poolfs = xstrdup ("");
+}
+#endif
+
+/* This function never prints trailing slashes (so that its output
+   can be appended a slash unconditionally).  */
+char *
+grub_make_system_path_relative_to_its_root (const char *path)
+{
+  struct stat st;
+  char *p, *buf, *buf2, *buf3, *ret;
+  uintptr_t offset = 0;
+  dev_t num;
+  size_t len;
+
+#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+  char *poolfs = NULL;
+#endif
+
+  /* canonicalize.  */
+  p = canonicalize_file_name (path);
+  if (p == NULL)
+    grub_util_error ("failed to get canonical path of %s", path);
+
+#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+  /* For ZFS sub-pool filesystems, could be extended to others (btrfs?).  */
+  {
+    char *dummy;
+    grub_find_zpool_from_dir (p, &dummy, &poolfs);
+  }
+#endif
+
+  len = strlen (p) + 1;
+  buf = xstrdup (p);
+  free (p);
+
+  if (stat (buf, &st) < 0)
+    grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
+
+  buf2 = xstrdup (buf);
+  num = st.st_dev;
+
+  /* This loop sets offset to the number of chars of the root
+     directory we're inspecting.  */
+  while (1)
+    {
+      p = strrchr (buf, '/');
+      if (p == NULL)
+       /* This should never happen.  */
+       grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)");
+      if (p != buf)
+       *p = 0;
+      else
+       *++p = 0;
+
+      if (stat (buf, &st) < 0)
+       grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
+
+      /* buf is another filesystem; we found it.  */
+      if (st.st_dev != num)
+       {
+         /* offset == 0 means path given is the mount point.
+            This works around special-casing of "/" in Un*x.  This function never
+            prints trailing slashes (so that its output can be appended a slash
+            unconditionally).  Each slash in is considered a preceding slash, and
+            therefore the root directory is an empty string.  */
+         if (offset == 0)
+           {
+             free (buf);
+#ifdef __linux__
+             {
+               char *bind;
+               grub_free (grub_find_root_device_from_mountinfo (buf2, &bind));
+               if (bind && bind[0] && bind[1])
+                 {
+                   buf3 = bind;
+                   goto parsedir;
+                 }
+               grub_free (bind);
+             }
+#endif
+             free (buf2);
+#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+             if (poolfs)
+               return xasprintf ("/%s/@", poolfs);
+#endif
+             return xstrdup ("");
+           }
+         else
+           break;
+       }
+
+      offset = p - buf;
+      /* offset == 1 means root directory.  */
+      if (offset == 1)
+       {
+         /* Include leading slash.  */
+         offset = 0;
+         break;
+       }
+    }
+  free (buf);
+  buf3 = xstrdup (buf2 + offset);
+  buf2[offset] = 0;
+#ifdef __linux__
+  {
+    char *bind;
+    grub_free (grub_find_root_device_from_mountinfo (buf2, &bind));
+    if (bind && bind[0] && bind[1])
+      {
+       char *temp = buf3;
+       buf3 = grub_xasprintf ("%s%s%s", bind, buf3[0] == '/' ?"":"/", buf3);
+       grub_free (temp);
+      }
+    grub_free (bind);
+  }
+#endif
+  
+  free (buf2);
+
+#ifdef __CYGWIN__
+  if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
+    {
+      /* Reached some mount point not below /cygdrive.
+        GRUB does not know Cygwin's emulated mounts,
+        convert to Win32 path.  */
+      grub_util_info ("Cygwin path = %s\n", buf3);
+      char * temp = get_win32_path (buf3);
+      free (buf3);
+      buf3 = temp;
+    }
+#endif
+
+ parsedir:
+  /* Remove trailing slashes, return empty string if root directory.  */
+  len = strlen (buf3);
+  while (len > 0 && buf3[len - 1] == '/')
+    {
+      buf3[len - 1] = '\0';
+      len--;
+    }
+
+#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
+  if (poolfs)
+    {
+      ret = xasprintf ("/%s/@%s", poolfs, buf3);
+      free (buf3);
+    }
+  else
+#endif
+    ret = buf3;
+
+  return ret;
+}
similarity index 100%
rename from grub-core/kern/emu/raid.c
rename to util/raid.c