From owner-svn-ports-all@FreeBSD.ORG Tue Jan 20 22:05:39 2015 Return-Path: Delivered-To: svn-ports-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 69967B2E; Tue, 20 Jan 2015 22:05:39 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 54D772AE; Tue, 20 Jan 2015 22:05:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t0KM5d2t061257; Tue, 20 Jan 2015 22:05:39 GMT (envelope-from kmoore@FreeBSD.org) Received: (from kmoore@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t0KM5c8Y061255; Tue, 20 Jan 2015 22:05:38 GMT (envelope-from kmoore@FreeBSD.org) Message-Id: <201501202205.t0KM5c8Y061255@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: kmoore set sender to kmoore@FreeBSD.org using -f From: Kris Moore Date: Tue, 20 Jan 2015 22:05:38 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r377544 - in head/sysutils/grub2-pcbsd: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jan 2015 22:05:39 -0000 Author: kmoore Date: Tue Jan 20 22:05:38 2015 New Revision: 377544 URL: https://svnweb.freebsd.org/changeset/ports/377544 QAT: https://qat.redports.org/buildarchive/r377544/ Log: - Teach GRUB how to deal with device names that are geom labels - Bump PORTREV Added: head/sysutils/grub2-pcbsd/files/patch-geom-label-support (contents, props changed) Modified: head/sysutils/grub2-pcbsd/Makefile Modified: head/sysutils/grub2-pcbsd/Makefile ============================================================================== --- head/sysutils/grub2-pcbsd/Makefile Tue Jan 20 22:03:55 2015 (r377543) +++ head/sysutils/grub2-pcbsd/Makefile Tue Jan 20 22:05:38 2015 (r377544) @@ -3,7 +3,7 @@ PORTNAME= grub2-pcbsd PORTVERSION= 2.02p -PORTREVISION= 20 +PORTREVISION= 21 CATEGORIES= sysutils MASTER_SITES= http://www.pcbsd.org/~kris/software/ \ ftp://ftp.pcbsd.org/pub/software/ Added: head/sysutils/grub2-pcbsd/files/patch-geom-label-support ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sysutils/grub2-pcbsd/files/patch-geom-label-support Tue Jan 20 22:05:38 2015 (r377544) @@ -0,0 +1,182 @@ +diff --git a/grub-core/osdep/freebsd/getroot.c b/grub-core/osdep/freebsd/getroot.c +index ccc1d70..64c0aad 100644 +--- grub-core/osdep/freebsd/getroot.c ++++ grub-core/osdep/freebsd/getroot.c +@@ -296,6 +296,105 @@ grub_util_get_grub_dev_os (const char *os_dev) + return grub_dev; + } + ++int grub_util_check_geom_label(const char *name) ++{ ++ struct gmesh mesh; ++ struct gclass *class; ++ struct ggeom *geom; ++ struct gprovider *pp; ++ struct gprovider *pplabel; ++ struct gconsumer *cp; ++ const char *geom_name; ++ const char *test_name; ++ int err; ++ ++ err = geom_gettree (&mesh); ++ if (err != 0) ++ grub_util_error ("%s", _("couldn't open geom")); ++ ++ LIST_FOREACH (class, &mesh.lg_class, lg_class) ++ if (strcasecmp (class->lg_name, "label") == 0) ++ break; ++ if (!class) ++ grub_util_error ("%s", _("couldn't find geom `label' class")); ++ ++ if (strncmp (name, "/dev/", sizeof ("/dev/") - 1) == 0) ++ test_name = name + sizeof ("/dev/") - 1; ++ else ++ test_name = name; ++ ++ LIST_FOREACH (geom, &class->lg_geom, lg_geom) ++ { ++ LIST_FOREACH(pp, &geom->lg_provider, lg_provider) ++ { ++ geom_name = pp->lg_name; ++ if (strcasecmp (geom_name, test_name) != 0) ++ continue; ++ ++ LIST_FOREACH(cp, &geom->lg_consumer, lg_consumer) ++ { ++ pplabel = cp->lg_provider; ++ if (pplabel == NULL) ++ continue; ++ return 1; ++ } ++ } ++ } ++ return 0; ++} ++ ++const char * ++grub_util_convert_geom_label_to_dev (const char *name, int *full_path) ++{ ++ struct gmesh mesh; ++ struct gclass *class; ++ struct ggeom *geom; ++ struct gprovider *pp; ++ struct gprovider *pplabel; ++ struct gconsumer *cp; ++ static char buf[256]; ++ const char *geom_name; ++ int err; ++ ++ grub_util_info ("Converting label '%s' to device", name); ++ ++ err = geom_gettree (&mesh); ++ if (err != 0) ++ grub_util_error ("%s", _("couldn't open geom")); ++ ++ LIST_FOREACH (class, &mesh.lg_class, lg_class) ++ if (strcasecmp (class->lg_name, "label") == 0) ++ break; ++ if (!class) ++ grub_util_error ("%s", _("couldn't find geom `label' class")); ++ ++ ++ LIST_FOREACH (geom, &class->lg_geom, lg_geom) ++ { ++ LIST_FOREACH(pp, &geom->lg_provider, lg_provider) ++ { ++ geom_name = pp->lg_name; ++ if (strcasecmp (geom_name, name) != 0) ++ continue; ++ ++ LIST_FOREACH(cp, &geom->lg_consumer, lg_consumer) ++ { ++ pplabel = cp->lg_provider; ++ if (pplabel == NULL) ++ continue; ++ ++ if ( full_path ) ++ snprintf(buf, sizeof(buf), "/dev/%s", pplabel->lg_name); ++ else ++ snprintf(buf, sizeof(buf), "%s", pplabel->lg_name); ++ return buf; ++ } ++ } ++ } ++ grub_util_error ("%s", _("couldn't convert gptid to real device name")); ++ return 0; ++} ++ + /* FIXME: geom actually gives us the whole container hierarchy. + It can be used more efficiently than this. */ + void +diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c +index e3887cb..cd010ce 100644 +--- grub-core/osdep/unix/getroot.c ++++ grub-core/osdep/unix/getroot.c +@@ -504,6 +504,12 @@ grub_guess_root_devices (const char *dir_in) + if (!os_dev) + os_dev = find_root_devices_from_libzfs (dir); + ++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ++ if (os_dev) ++ if ( grub_util_check_geom_label(os_dev) ) ++ os_dev = grub_util_convert_geom_label_to_dev (os_dev + sizeof ("/dev/") - 1, 1); ++#endif ++ + if (os_dev) + { + char **cur; +diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h +index 73fa2d3..3c43db4 100644 +--- include/grub/emu/getroot.h ++++ include/grub/emu/getroot.h +@@ -44,6 +44,8 @@ char *grub_util_get_grub_dev (const char *os_dev); + #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) + void grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, + char **name_out); ++int grub_util_check_geom_label(const char *name); ++const char *grub_util_convert_geom_label_to_dev (const char *name, int *full_path); + #endif + + #include +diff --git a/util/grub-install.c b/util/grub-install.c +index 7d61c32..5900535 100644 +--- util/grub-install.c ++++ util/grub-install.c +@@ -236,7 +236,16 @@ argp_parser (int key, char *arg, struct argp_state *state) + case ARGP_KEY_ARG: + if (install_device) + grub_util_error ("%s", _("More than one install device?")); ++#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) ++ /* Check if passing a FreeBSD geom label */ ++ if ( grub_util_check_geom_label(arg) ) ++ install_device = \ ++ xstrdup(grub_util_convert_geom_label_to_dev (arg + sizeof ("/dev/") - 1, 1)); ++ else + install_device = xstrdup (arg); ++#else ++ install_device = xstrdup (arg); ++#endif + return 0; + + default: +diff --git a/util/grub-probe.c b/util/grub-probe.c +index ecb7b6b..21e3fa3 100644 +--- util/grub-probe.c ++++ util/grub-probe.c +@@ -799,7 +799,16 @@ argp_parser (int key, char *arg, struct argp_state *state) + + case ARGP_KEY_ARG: + assert (arguments->ndevices < arguments->device_max); ++#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) ++ /* Check if passing a FreeBSD geom label */ ++ if ( grub_util_check_geom_label(arg) ) ++ arguments->devices[arguments->ndevices++] = \ ++ xstrdup(grub_util_convert_geom_label_to_dev (arg + sizeof ("/dev/") - 1, 1)); ++ else + arguments->devices[arguments->ndevices++] = xstrdup(arg); ++#else ++ arguments->devices[arguments->ndevices++] = xstrdup(arg); ++#endif + break; + + default: