diff --git a/sbin/geom/Makefile b/sbin/geom/Makefile index 95f00d914756..af2b77bbec28 100644 --- a/sbin/geom/Makefile +++ b/sbin/geom/Makefile @@ -1,5 +1,23 @@ # $FreeBSD$ +.if defined(RESCUE) + +.PATH: ${.CURDIR}/class/part ${.CURDIR}/core ${.CURDIR}/misc + +PROG= geom +SRCS= geom.c geom_part.c subr.c + +CFLAGS+=-I${.CURDIR} -I${.CURDIR}/core + +DPADD= ${LIBGEOM} ${LIBSBUF} ${LIBBSDXML} ${LIBUTIL} +LDADD= -lgeom -lsbuf -lbsdxml -lutil + +.include + +.else + SUBDIR= core class .include + +.endif diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index f70b4879260d..8e8a77bbd704 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -43,15 +43,21 @@ __FBSDID("$FreeBSD$"); #include "core/geom.h" #include "misc/subr.h" -uint32_t lib_version = G_LIB_VERSION; -uint32_t version = 0; +#ifdef RESCUE +#define PUBSYM(x) gpart_##x +#else +#define PUBSYM(x) x +#endif + +uint32_t PUBSYM(lib_version) = G_LIB_VERSION; +uint32_t PUBSYM(version) = 0; static char optional[] = ""; static char flags[] = "C"; static void gpart_show(struct gctl_req *, unsigned); -struct g_command class_commands[] = { +struct g_command PUBSYM(class_commands)[] = { { "add", 0, NULL, { { 'b', "start", NULL, G_TYPE_STRING }, { 's', "size", NULL, G_TYPE_STRING }, diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index cfa1e6074ad4..2345be37fbf9 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -51,6 +51,10 @@ __FBSDID("$FreeBSD$"); #include "misc/subr.h" +#ifdef RESCUE +extern uint32_t gpart_version; +extern struct g_command gpart_class_commands[]; +#endif static char comm[MAXPATHLEN], *class_name = NULL, *gclass_name = NULL; static uint32_t *version = NULL; @@ -466,6 +470,7 @@ run_command(int argc, char *argv[]) exit(EXIT_SUCCESS); } +#ifndef RESCUE static const char * library_path(void) { @@ -524,6 +529,7 @@ load_library(void) exit(EXIT_FAILURE); } } +#endif /* !RESCUE */ /* * Class name should be all capital letters. @@ -571,8 +577,18 @@ get_class(int *argc, char ***argv) } else { errx(EXIT_FAILURE, "Invalid utility name."); } - set_class_name(); + +#ifndef RESCUE load_library(); +#else + if (!strcasecmp(class_name, "part")) { + version = &gpart_version; + class_commands = gpart_class_commands; + } else + errx(EXIT_FAILURE, "Invalid class name."); +#endif /* !RESCUE */ + + set_class_name(); if (*argc < 1) usage(); }