From c38fe9f48e9b9fadf390ce310821f16bc9944a6c Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 10 Sep 2010 14:32:28 +0200 Subject: [PATCH] 2010-09-10 Robert Millan Solaris support in grub_find_zpool_from_dir(). Thanks Seth Goldberg for referring to getextmntent() facility. * configure.ac: Check for getextmntent(), `sys/mnttab.h' and `sys/mkdev.h'. * grub-core/kern/emu/misc.c [HAVE_SYS_MNTTAB_H]: Include `'. [HAVE_SYS_MKDEV_H]: Include `'. [HAVE_GETEXTMNTENT] (grub_find_zpool_from_dir): Add getextmntent() method for finding zpool name. --- ChangeLog | 13 +++++++++++++ configure.ac | 4 ++-- grub-core/kern/emu/misc.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5d0760a6..1abd19556 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-09-10 Robert Millan + + Solaris support in grub_find_zpool_from_dir(). Thanks + Seth Goldberg for referring to getextmntent() facility. + + * configure.ac: Check for getextmntent(), `sys/mnttab.h' and + `sys/mkdev.h'. + * grub-core/kern/emu/misc.c [HAVE_SYS_MNTTAB_H]: Include + `'. + [HAVE_SYS_MKDEV_H]: Include `'. + [HAVE_GETEXTMNTENT] (grub_find_zpool_from_dir): Add getextmntent() + method for finding zpool name. + 2010-09-10 Colin Watson grub-fstest needs the host and hostfs modules while other utilities diff --git a/configure.ac b/configure.ac index ec1ea8d88..d50dfe6dd 100644 --- a/configure.ac +++ b/configure.ac @@ -277,8 +277,8 @@ else fi # Check for functions and headers. -AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf) -AC_CHECK_HEADERS(libzfs.h libnvpair.h sys/param.h sys/mount.h) +AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf getextmntent) +AC_CHECK_HEADERS(libzfs.h libnvpair.h sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h) AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default #include diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index db89f0ece..c710777ea 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -61,6 +61,15 @@ # include #endif +#ifdef HAVE_SYS_MNTTAB_H +# include /* Needed by sys/mnttab.h. */ +# include +#endif + +#ifdef HAVE_SYS_MKDEV_H +# include /* makedev */ +#endif + int verbosity; void @@ -299,10 +308,36 @@ grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs) *poolname = xstrdup (mnt.f_mntfromname); } -#else - return; +#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) {