2004-05-20 10:09:56 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2009-09-06 06:49:59 +00:00
|
|
|
* Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
2004-05-20 10:09:56 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2006-02-01 12:11:37 +00:00
|
|
|
*
|
2004-05-20 10:09:56 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/linker.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2018-09-13 14:06:01 +00:00
|
|
|
#include <stdbool.h>
|
2004-05-20 10:09:56 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libgen.h>
|
2004-05-26 11:08:35 +00:00
|
|
|
#include <libutil.h>
|
2004-05-20 10:09:56 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <libgeom.h>
|
|
|
|
#include <geom.h>
|
|
|
|
|
|
|
|
#include "misc/subr.h"
|
|
|
|
|
2008-06-04 20:07:59 +00:00
|
|
|
#ifdef STATIC_GEOM_CLASSES
|
2007-11-04 00:32:54 +00:00
|
|
|
extern uint32_t gpart_version;
|
|
|
|
extern struct g_command gpart_class_commands[];
|
2008-03-05 23:31:49 +00:00
|
|
|
extern uint32_t glabel_version;
|
|
|
|
extern struct g_command glabel_class_commands[];
|
2007-11-04 00:32:54 +00:00
|
|
|
#endif
|
2004-05-20 10:09:56 +00:00
|
|
|
|
|
|
|
static char comm[MAXPATHLEN], *class_name = NULL, *gclass_name = NULL;
|
|
|
|
static uint32_t *version = NULL;
|
|
|
|
static int verbose = 0;
|
|
|
|
static struct g_command *class_commands = NULL;
|
|
|
|
|
2018-09-14 15:29:45 +00:00
|
|
|
#define GEOM_CLASS_CMDS 0x01
|
|
|
|
#define GEOM_STD_CMDS 0x02
|
|
|
|
|
|
|
|
#define GEOM_CLASS_WIDTH 10
|
|
|
|
|
2004-09-17 08:38:53 +00:00
|
|
|
static struct g_command *find_command(const char *cmdstr, int flags);
|
2018-09-13 14:06:01 +00:00
|
|
|
static void list_one_geom_by_provider(const char *provider_name);
|
2004-05-20 10:09:56 +00:00
|
|
|
static int std_available(const char *name);
|
|
|
|
|
2004-05-22 16:57:39 +00:00
|
|
|
static void std_help(struct gctl_req *req, unsigned flags);
|
2004-05-20 10:09:56 +00:00
|
|
|
static void std_list(struct gctl_req *req, unsigned flags);
|
2005-03-13 19:34:27 +00:00
|
|
|
static void std_status(struct gctl_req *req, unsigned flags);
|
2004-05-20 10:09:56 +00:00
|
|
|
static void std_load(struct gctl_req *req, unsigned flags);
|
|
|
|
static void std_unload(struct gctl_req *req, unsigned flags);
|
|
|
|
|
2012-10-19 14:49:42 +00:00
|
|
|
static struct g_command std_commands[] = {
|
2010-09-13 13:48:18 +00:00
|
|
|
{ "help", 0, std_help, G_NULL_OPTS, NULL },
|
2011-03-24 19:11:05 +00:00
|
|
|
{ "list", 0, std_list,
|
|
|
|
{
|
|
|
|
{ 'a', "all", NULL, G_TYPE_BOOL },
|
|
|
|
G_OPT_SENTINEL
|
|
|
|
},
|
|
|
|
"[-a] [name ...]"
|
2005-03-14 14:24:46 +00:00
|
|
|
},
|
2005-03-14 12:33:19 +00:00
|
|
|
{ "status", 0, std_status,
|
|
|
|
{
|
2011-03-24 19:11:05 +00:00
|
|
|
{ 'a', "all", NULL, G_TYPE_BOOL },
|
|
|
|
{ 'g', "geoms", NULL, G_TYPE_BOOL },
|
2006-09-30 14:39:18 +00:00
|
|
|
{ 's', "script", NULL, G_TYPE_BOOL },
|
2005-03-14 12:33:19 +00:00
|
|
|
G_OPT_SENTINEL
|
2005-03-14 14:24:46 +00:00
|
|
|
},
|
2011-03-24 19:11:05 +00:00
|
|
|
"[-ags] [name ...]"
|
2005-03-14 12:33:19 +00:00
|
|
|
},
|
2007-05-15 20:25:18 +00:00
|
|
|
{ "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS,
|
2010-09-13 13:48:18 +00:00
|
|
|
NULL },
|
|
|
|
{ "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL },
|
2004-05-20 10:09:56 +00:00
|
|
|
G_CMD_SENTINEL
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2005-03-14 14:24:46 +00:00
|
|
|
usage_command(struct g_command *cmd, const char *prefix)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
|
|
|
struct g_option *opt;
|
2005-03-14 14:24:46 +00:00
|
|
|
unsigned i;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2005-03-14 14:24:46 +00:00
|
|
|
if (cmd->gc_usage != NULL) {
|
2009-09-06 06:48:50 +00:00
|
|
|
char *pos, *ptr, *sptr;
|
|
|
|
|
|
|
|
sptr = ptr = strdup(cmd->gc_usage);
|
|
|
|
while ((pos = strsep(&ptr, "\n")) != NULL) {
|
|
|
|
if (*pos == '\0')
|
|
|
|
continue;
|
|
|
|
fprintf(stderr, "%s %s %s %s\n", prefix, comm,
|
|
|
|
cmd->gc_name, pos);
|
|
|
|
}
|
|
|
|
free(sptr);
|
2005-03-14 14:24:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-06 06:48:50 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
|
2005-03-14 14:24:46 +00:00
|
|
|
if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0)
|
|
|
|
fprintf(stderr, " [-v]");
|
2004-05-20 10:09:56 +00:00
|
|
|
for (i = 0; ; i++) {
|
2005-03-14 14:24:46 +00:00
|
|
|
opt = &cmd->gc_options[i];
|
|
|
|
if (opt->go_name == NULL)
|
2004-05-20 10:09:56 +00:00
|
|
|
break;
|
2006-09-30 14:39:18 +00:00
|
|
|
if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
|
2005-03-14 14:24:46 +00:00
|
|
|
fprintf(stderr, " [");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
fprintf(stderr, "-%c", opt->go_char);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
|
2005-03-14 14:24:46 +00:00
|
|
|
fprintf(stderr, " %s", opt->go_name);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
|
2005-03-14 14:24:46 +00:00
|
|
|
fprintf(stderr, "]");
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2005-03-14 14:24:46 +00:00
|
|
|
fprintf(stderr, "\n");
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-14 14:24:46 +00:00
|
|
|
usage(void)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (class_name == NULL) {
|
2018-09-11 16:46:28 +00:00
|
|
|
fprintf(stderr, "usage: geom <class> <command> [options]\n");
|
2018-09-13 14:06:01 +00:00
|
|
|
fprintf(stderr, " geom -p <provider-name>\n");
|
2018-09-14 15:29:45 +00:00
|
|
|
fprintf(stderr, " geom -t\n");
|
2018-09-11 16:46:28 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-05-20 10:09:56 +00:00
|
|
|
} else {
|
2005-03-14 14:24:46 +00:00
|
|
|
struct g_command *cmd;
|
2004-05-20 10:09:56 +00:00
|
|
|
const char *prefix;
|
|
|
|
unsigned i;
|
|
|
|
|
2005-03-14 14:24:46 +00:00
|
|
|
prefix = "usage:";
|
|
|
|
if (class_commands != NULL) {
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
cmd = &class_commands[i];
|
|
|
|
if (cmd->gc_name == NULL)
|
|
|
|
break;
|
|
|
|
usage_command(cmd, prefix);
|
|
|
|
prefix = " ";
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
cmd = &std_commands[i];
|
|
|
|
if (cmd->gc_name == NULL)
|
|
|
|
break;
|
2004-09-17 08:38:53 +00:00
|
|
|
/*
|
|
|
|
* If class defines command, which has the same name as
|
|
|
|
* standard command, skip it, because it was already
|
|
|
|
* shown on usage().
|
|
|
|
*/
|
|
|
|
if (find_command(cmd->gc_name, GEOM_CLASS_CMDS) != NULL)
|
2004-05-20 10:09:56 +00:00
|
|
|
continue;
|
2005-03-14 14:24:46 +00:00
|
|
|
usage_command(cmd, prefix);
|
2004-05-20 10:09:56 +00:00
|
|
|
prefix = " ";
|
|
|
|
}
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_module(void)
|
|
|
|
{
|
|
|
|
char name1[64], name2[64];
|
|
|
|
|
|
|
|
snprintf(name1, sizeof(name1), "g_%s", class_name);
|
|
|
|
snprintf(name2, sizeof(name2), "geom_%s", class_name);
|
|
|
|
if (modfind(name1) < 0) {
|
|
|
|
/* Not present in kernel, try loading it. */
|
|
|
|
if (kldload(name2) < 0 || modfind(name1) < 0) {
|
|
|
|
if (errno != EEXIST) {
|
2018-09-11 16:46:28 +00:00
|
|
|
err(EXIT_FAILURE, "cannot load %s", name2);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
strlcatf(char *str, size_t size, const char *format, ...)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
len = strlen(str);
|
|
|
|
str += len;
|
|
|
|
size -= len;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
ret = vsnprintf(str, size, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find given option in options available for given command.
|
|
|
|
*/
|
|
|
|
static struct g_option *
|
|
|
|
find_option(struct g_command *cmd, char ch)
|
|
|
|
{
|
|
|
|
struct g_option *opt;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
opt = &cmd->gc_options[i];
|
|
|
|
if (opt->go_name == NULL)
|
|
|
|
return (NULL);
|
|
|
|
if (opt->go_char == ch)
|
|
|
|
return (opt);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add given option to gctl_req.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_option(struct gctl_req *req, struct g_option *opt, const char *val)
|
|
|
|
{
|
2010-09-13 13:59:28 +00:00
|
|
|
const char *optname;
|
2010-08-19 11:20:24 +00:00
|
|
|
uint64_t number;
|
2010-09-13 08:56:07 +00:00
|
|
|
void *ptr;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2010-09-13 13:59:28 +00:00
|
|
|
if (G_OPT_ISMULTI(opt)) {
|
|
|
|
size_t optnamesize;
|
|
|
|
|
|
|
|
if (G_OPT_NUM(opt) == UCHAR_MAX)
|
|
|
|
errx(EXIT_FAILURE, "Too many -%c options.", opt->go_char);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base option name length plus 3 bytes for option number
|
|
|
|
* (max. 255 options) plus 1 byte for terminating '\0'.
|
|
|
|
*/
|
|
|
|
optnamesize = strlen(opt->go_name) + 3 + 1;
|
|
|
|
ptr = malloc(optnamesize);
|
|
|
|
if (ptr == NULL)
|
|
|
|
errx(EXIT_FAILURE, "No memory.");
|
|
|
|
snprintf(ptr, optnamesize, "%s%u", opt->go_name, G_OPT_NUM(opt));
|
|
|
|
G_OPT_NUMINC(opt);
|
|
|
|
optname = ptr;
|
|
|
|
} else {
|
|
|
|
optname = opt->go_name;
|
|
|
|
}
|
|
|
|
|
2010-09-14 16:22:22 +00:00
|
|
|
if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) {
|
2007-09-21 10:00:05 +00:00
|
|
|
if (expand_number(val, &number) == -1) {
|
2010-09-14 11:19:21 +00:00
|
|
|
err(EXIT_FAILURE, "Invalid value for '%c' argument",
|
2004-05-20 10:09:56 +00:00
|
|
|
opt->go_char);
|
|
|
|
}
|
2010-09-14 20:54:22 +00:00
|
|
|
ptr = malloc(sizeof(intmax_t));
|
|
|
|
if (ptr == NULL)
|
|
|
|
errx(EXIT_FAILURE, "No memory.");
|
|
|
|
*(intmax_t *)ptr = number;
|
|
|
|
opt->go_val = ptr;
|
|
|
|
gctl_ro_param(req, optname, sizeof(intmax_t), opt->go_val);
|
2006-09-30 14:39:18 +00:00
|
|
|
} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
|
2010-09-13 13:59:28 +00:00
|
|
|
gctl_ro_param(req, optname, -1, val);
|
2006-09-30 14:39:18 +00:00
|
|
|
} else if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
|
2010-09-13 08:56:07 +00:00
|
|
|
ptr = malloc(sizeof(int));
|
|
|
|
if (ptr == NULL)
|
2004-05-20 10:09:56 +00:00
|
|
|
errx(EXIT_FAILURE, "No memory.");
|
2010-09-13 08:56:07 +00:00
|
|
|
*(int *)ptr = *val - '0';
|
|
|
|
opt->go_val = ptr;
|
2010-09-13 13:59:28 +00:00
|
|
|
gctl_ro_param(req, optname, sizeof(int), opt->go_val);
|
2006-09-30 14:39:18 +00:00
|
|
|
} else {
|
|
|
|
assert(!"Invalid type");
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2010-09-13 13:59:28 +00:00
|
|
|
|
|
|
|
if (G_OPT_ISMULTI(opt))
|
|
|
|
free(__DECONST(char *, optname));
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1. Add given argument by caller.
|
|
|
|
* 2. Add default values of not given arguments.
|
|
|
|
* 3. Add the rest of arguments.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
|
|
|
|
char ***argv)
|
|
|
|
{
|
|
|
|
struct g_option *opt;
|
|
|
|
char opts[64];
|
|
|
|
unsigned i;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
*opts = '\0';
|
|
|
|
if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0)
|
|
|
|
strlcat(opts, "v", sizeof(opts));
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
opt = &cmd->gc_options[i];
|
|
|
|
if (opt->go_name == NULL)
|
|
|
|
break;
|
2006-09-30 14:39:18 +00:00
|
|
|
assert(G_OPT_TYPE(opt) != 0);
|
2010-09-13 13:59:28 +00:00
|
|
|
assert((opt->go_type & ~(G_TYPE_MASK | G_TYPE_MULTI)) == 0);
|
|
|
|
/* Multiple bool arguments makes no sense. */
|
|
|
|
assert(G_OPT_TYPE(opt) != G_TYPE_BOOL ||
|
|
|
|
(opt->go_type & G_TYPE_MULTI) == 0);
|
2004-05-20 10:09:56 +00:00
|
|
|
strlcatf(opts, sizeof(opts), "%c", opt->go_char);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
|
2004-05-20 10:09:56 +00:00
|
|
|
strlcat(opts, ":", sizeof(opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add specified arguments.
|
|
|
|
*/
|
|
|
|
while ((ch = getopt(*argc, *argv, opts)) != -1) {
|
|
|
|
/* Standard (not passed to kernel) options. */
|
|
|
|
switch (ch) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Options passed to kernel. */
|
|
|
|
opt = find_option(cmd, ch);
|
|
|
|
if (opt == NULL)
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2010-09-13 13:59:28 +00:00
|
|
|
if (!G_OPT_ISMULTI(opt) && G_OPT_ISDONE(opt)) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Option '%c' specified twice.", opt->go_char);
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
G_OPT_DONE(opt);
|
|
|
|
|
2006-09-30 14:39:18 +00:00
|
|
|
if (G_OPT_TYPE(opt) == G_TYPE_BOOL)
|
2004-05-20 10:09:56 +00:00
|
|
|
set_option(req, opt, "1");
|
|
|
|
else
|
|
|
|
set_option(req, opt, optarg);
|
|
|
|
}
|
|
|
|
*argc -= optind;
|
|
|
|
*argv += optind;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add not specified arguments, but with default values.
|
|
|
|
*/
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
opt = &cmd->gc_options[i];
|
|
|
|
if (opt->go_name == NULL)
|
|
|
|
break;
|
|
|
|
if (G_OPT_ISDONE(opt))
|
|
|
|
continue;
|
|
|
|
|
2006-09-30 14:39:18 +00:00
|
|
|
if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
|
2004-05-20 10:09:56 +00:00
|
|
|
assert(opt->go_val == NULL);
|
|
|
|
set_option(req, opt, "0");
|
|
|
|
} else {
|
|
|
|
if (opt->go_val == NULL) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Option '%c' not specified.",
|
2004-05-20 10:09:56 +00:00
|
|
|
opt->go_char);
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2010-09-14 11:13:46 +00:00
|
|
|
} else if (opt->go_val == G_VAL_OPTIONAL) {
|
|
|
|
/* add nothing. */
|
2004-05-20 10:09:56 +00:00
|
|
|
} else {
|
2010-09-13 13:48:18 +00:00
|
|
|
set_option(req, opt, opt->go_val);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 13:48:18 +00:00
|
|
|
/*
|
|
|
|
* Add rest of given arguments.
|
|
|
|
*/
|
|
|
|
gctl_ro_param(req, "nargs", sizeof(int), argc);
|
|
|
|
for (i = 0; i < (unsigned)*argc; i++) {
|
|
|
|
char argname[16];
|
2007-05-15 20:25:18 +00:00
|
|
|
|
2010-09-13 13:48:18 +00:00
|
|
|
snprintf(argname, sizeof(argname), "arg%u", i);
|
|
|
|
gctl_ro_param(req, argname, -1, (*argv)[i]);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find given command in commands available for given class.
|
|
|
|
*/
|
|
|
|
static struct g_command *
|
2004-09-17 08:38:53 +00:00
|
|
|
find_command(const char *cmdstr, int flags)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
|
|
|
struct g_command *cmd;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try to find command defined by loaded library.
|
|
|
|
*/
|
2004-09-17 08:38:53 +00:00
|
|
|
if ((flags & GEOM_CLASS_CMDS) != 0 && class_commands != NULL) {
|
2004-05-20 10:09:56 +00:00
|
|
|
for (i = 0; ; i++) {
|
|
|
|
cmd = &class_commands[i];
|
|
|
|
if (cmd->gc_name == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(cmd->gc_name, cmdstr) == 0)
|
|
|
|
return (cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now try to find in standard commands.
|
|
|
|
*/
|
2004-09-17 08:38:53 +00:00
|
|
|
if ((flags & GEOM_STD_CMDS) != 0) {
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
cmd = &std_commands[i];
|
|
|
|
if (cmd->gc_name == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(cmd->gc_name, cmdstr) == 0)
|
|
|
|
return (cmd);
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
set_flags(struct g_command *cmd)
|
|
|
|
{
|
|
|
|
unsigned flags = 0;
|
|
|
|
|
|
|
|
if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0 && verbose)
|
|
|
|
flags |= G_FLAG_VERBOSE;
|
|
|
|
|
|
|
|
return (flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run command.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
run_command(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct g_command *cmd;
|
|
|
|
struct gctl_req *req;
|
|
|
|
const char *errstr;
|
|
|
|
char buf[4096];
|
|
|
|
|
2004-09-17 08:38:53 +00:00
|
|
|
/* First try to find a command defined by a class. */
|
|
|
|
cmd = find_command(argv[0], GEOM_CLASS_CMDS);
|
2004-05-20 10:09:56 +00:00
|
|
|
if (cmd == NULL) {
|
2004-09-17 08:38:53 +00:00
|
|
|
/* Now, try to find a standard command. */
|
|
|
|
cmd = find_command(argv[0], GEOM_STD_CMDS);
|
|
|
|
if (cmd == NULL) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Unknown command: %s.", argv[0]);
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-09-17 08:38:53 +00:00
|
|
|
}
|
|
|
|
if (!std_available(cmd->gc_name)) {
|
2018-09-11 16:46:28 +00:00
|
|
|
warnx("Command '%s' not available; "
|
|
|
|
"try 'load' first.", argv[0]);
|
2004-09-17 08:38:53 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
if ((cmd->gc_flags & G_FLAG_LOADKLD) != 0)
|
|
|
|
load_module();
|
|
|
|
|
|
|
|
req = gctl_get_handle();
|
|
|
|
gctl_ro_param(req, "class", -1, gclass_name);
|
|
|
|
gctl_ro_param(req, "verb", -1, argv[0]);
|
|
|
|
if (version != NULL)
|
|
|
|
gctl_ro_param(req, "version", sizeof(*version), version);
|
|
|
|
parse_arguments(cmd, req, &argc, &argv);
|
|
|
|
|
2005-03-22 22:05:44 +00:00
|
|
|
bzero(buf, sizeof(buf));
|
2004-05-20 10:09:56 +00:00
|
|
|
if (cmd->gc_func != NULL) {
|
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
flags = set_flags(cmd);
|
|
|
|
cmd->gc_func(req, flags);
|
|
|
|
errstr = req->error;
|
|
|
|
} else {
|
|
|
|
gctl_rw_param(req, "output", sizeof(buf), buf);
|
|
|
|
errstr = gctl_issue(req);
|
|
|
|
}
|
2005-04-29 07:57:50 +00:00
|
|
|
if (errstr != NULL && errstr[0] != '\0') {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("%s", errstr);
|
2004-08-28 02:29:40 +00:00
|
|
|
if (strncmp(errstr, "warning: ", strlen("warning: ")) != 0) {
|
|
|
|
gctl_free(req);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2005-03-22 22:05:44 +00:00
|
|
|
if (buf[0] != '\0')
|
2004-05-20 10:09:56 +00:00
|
|
|
printf("%s", buf);
|
|
|
|
gctl_free(req);
|
|
|
|
if (verbose)
|
|
|
|
printf("Done.\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2008-06-04 20:07:59 +00:00
|
|
|
#ifndef STATIC_GEOM_CLASSES
|
2005-02-27 21:14:58 +00:00
|
|
|
static const char *
|
|
|
|
library_path(void)
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
path = getenv("GEOM_LIBRARY_PATH");
|
|
|
|
if (path == NULL)
|
2010-12-15 23:45:12 +00:00
|
|
|
path = GEOM_CLASS_DIR;
|
2005-02-27 21:14:58 +00:00
|
|
|
return (path);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
static void
|
|
|
|
load_library(void)
|
|
|
|
{
|
2009-02-02 19:22:53 +00:00
|
|
|
char *curpath, path[MAXPATHLEN], *tofree, *totalpath;
|
2004-05-20 10:09:56 +00:00
|
|
|
uint32_t *lib_version;
|
|
|
|
void *dlh;
|
2008-02-04 12:17:02 +00:00
|
|
|
int ret;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2008-02-04 12:17:02 +00:00
|
|
|
ret = 0;
|
2009-02-02 19:22:53 +00:00
|
|
|
tofree = totalpath = strdup(library_path());
|
2008-02-04 12:17:02 +00:00
|
|
|
if (totalpath == NULL)
|
|
|
|
err(EXIT_FAILURE, "Not enough memory for library path");
|
|
|
|
|
|
|
|
if (strchr(totalpath, ':') != NULL)
|
|
|
|
curpath = strsep(&totalpath, ":");
|
|
|
|
else
|
|
|
|
curpath = totalpath;
|
|
|
|
/* Traverse the paths to find one that contains the library we want. */
|
|
|
|
while (curpath != NULL) {
|
|
|
|
snprintf(path, sizeof(path), "%s/geom_%s.so", curpath,
|
|
|
|
class_name);
|
|
|
|
ret = access(path, F_OK);
|
|
|
|
if (ret == -1) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
/*
|
|
|
|
* If we cannot find library, try the next
|
|
|
|
* path.
|
|
|
|
*/
|
|
|
|
curpath = strsep(&totalpath, ":");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
err(EXIT_FAILURE, "Cannot access library");
|
2005-08-14 21:55:18 +00:00
|
|
|
}
|
2008-02-04 12:17:02 +00:00
|
|
|
break;
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2009-02-02 19:22:53 +00:00
|
|
|
free(tofree);
|
2008-02-04 12:17:02 +00:00
|
|
|
/* No library was found, but standard commands can still be used */
|
|
|
|
if (ret == -1)
|
|
|
|
return;
|
2005-08-14 21:55:18 +00:00
|
|
|
dlh = dlopen(path, RTLD_NOW);
|
|
|
|
if (dlh == NULL)
|
|
|
|
errx(EXIT_FAILURE, "Cannot open library: %s.", dlerror());
|
2004-05-20 10:09:56 +00:00
|
|
|
lib_version = dlsym(dlh, "lib_version");
|
|
|
|
if (lib_version == NULL) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Cannot find symbol %s: %s.", "lib_version", dlerror());
|
2004-05-20 10:09:56 +00:00
|
|
|
dlclose(dlh);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (*lib_version != G_LIB_VERSION) {
|
|
|
|
dlclose(dlh);
|
2004-08-28 02:29:40 +00:00
|
|
|
errx(EXIT_FAILURE, "%s and %s are not synchronized.",
|
|
|
|
getprogname(), path);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
version = dlsym(dlh, "version");
|
|
|
|
if (version == NULL) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Cannot find symbol %s: %s.", "version", dlerror());
|
2004-05-20 10:09:56 +00:00
|
|
|
dlclose(dlh);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
class_commands = dlsym(dlh, "class_commands");
|
|
|
|
if (class_commands == NULL) {
|
2006-09-30 14:39:18 +00:00
|
|
|
warnx("Cannot find symbol %s: %s.", "class_commands",
|
|
|
|
dlerror());
|
2004-05-20 10:09:56 +00:00
|
|
|
dlclose(dlh);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2008-06-04 20:07:59 +00:00
|
|
|
#endif /* !STATIC_GEOM_CLASSES */
|
2004-05-20 10:09:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class name should be all capital letters.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_class_name(void)
|
|
|
|
{
|
|
|
|
char *s1, *s2;
|
|
|
|
|
2005-03-14 15:00:51 +00:00
|
|
|
s1 = class_name;
|
|
|
|
for (; *s1 != '\0'; s1++)
|
|
|
|
*s1 = tolower(*s1);
|
2006-04-07 15:33:04 +00:00
|
|
|
gclass_name = malloc(strlen(class_name) + 1);
|
2004-05-20 10:09:56 +00:00
|
|
|
if (gclass_name == NULL)
|
|
|
|
errx(EXIT_FAILURE, "No memory");
|
|
|
|
s1 = gclass_name;
|
|
|
|
s2 = class_name;
|
|
|
|
for (; *s2 != '\0'; s2++)
|
|
|
|
*s1++ = toupper(*s2);
|
|
|
|
*s1 = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_class(int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
|
|
|
|
snprintf(comm, sizeof(comm), "%s", basename((*argv)[0]));
|
|
|
|
if (strcmp(comm, "geom") == 0) {
|
|
|
|
if (*argc < 2)
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-12-28 17:07:18 +00:00
|
|
|
else if (*argc == 2) {
|
|
|
|
if (strcmp((*argv)[1], "-h") == 0 ||
|
|
|
|
strcmp((*argv)[1], "help") == 0) {
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-12-28 17:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
strlcatf(comm, sizeof(comm), " %s", (*argv)[1]);
|
|
|
|
class_name = (*argv)[1];
|
|
|
|
*argc -= 2;
|
|
|
|
*argv += 2;
|
|
|
|
} else if (*comm == 'g') {
|
|
|
|
class_name = comm + 1;
|
|
|
|
*argc -= 1;
|
|
|
|
*argv += 1;
|
|
|
|
} else {
|
|
|
|
errx(EXIT_FAILURE, "Invalid utility name.");
|
|
|
|
}
|
2007-11-04 00:32:54 +00:00
|
|
|
|
2008-06-04 20:07:59 +00:00
|
|
|
#ifndef STATIC_GEOM_CLASSES
|
2004-05-20 10:09:56 +00:00
|
|
|
load_library();
|
2007-11-04 00:32:54 +00:00
|
|
|
#else
|
|
|
|
if (!strcasecmp(class_name, "part")) {
|
|
|
|
version = &gpart_version;
|
|
|
|
class_commands = gpart_class_commands;
|
2008-03-05 23:31:49 +00:00
|
|
|
} else if (!strcasecmp(class_name, "label")) {
|
|
|
|
version = &glabel_version;
|
|
|
|
class_commands = glabel_class_commands;
|
2016-03-11 12:59:07 +00:00
|
|
|
}
|
2008-06-04 20:07:59 +00:00
|
|
|
#endif /* !STATIC_GEOM_CLASSES */
|
2007-11-04 00:32:54 +00:00
|
|
|
|
|
|
|
set_class_name();
|
2014-11-17 15:19:57 +00:00
|
|
|
|
|
|
|
/* If we can't load or list, it's not a class. */
|
|
|
|
if (!std_available("load") && !std_available("list"))
|
2018-09-11 16:46:28 +00:00
|
|
|
errx(EXIT_FAILURE, "Invalid class name '%s'.", class_name);
|
2014-11-17 15:19:57 +00:00
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
if (*argc < 1)
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 14:06:01 +00:00
|
|
|
static struct ggeom *
|
|
|
|
find_geom_by_provider(struct gmesh *mesh, const char *name)
|
|
|
|
{
|
|
|
|
struct gclass *classp;
|
|
|
|
struct ggeom *gp;
|
|
|
|
struct gprovider *pp;
|
|
|
|
|
|
|
|
LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
if (strcmp(pp->lg_name, name) == 0)
|
|
|
|
return (gp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2018-09-14 15:29:45 +00:00
|
|
|
static int
|
|
|
|
compute_tree_width_geom(struct gmesh *mesh, struct ggeom *gp, int indent)
|
|
|
|
{
|
|
|
|
struct gclass *classp2;
|
|
|
|
struct ggeom *gp2;
|
|
|
|
struct gconsumer *cp2;
|
|
|
|
struct gprovider *pp;
|
|
|
|
int max_width, width;
|
|
|
|
|
|
|
|
max_width = width = indent + strlen(gp->lg_name);
|
|
|
|
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
LIST_FOREACH(classp2, &mesh->lg_class, lg_class) {
|
|
|
|
LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) {
|
|
|
|
LIST_FOREACH(cp2,
|
|
|
|
&gp2->lg_consumer, lg_consumer) {
|
|
|
|
if (pp != cp2->lg_provider)
|
|
|
|
continue;
|
|
|
|
width = compute_tree_width_geom(mesh,
|
|
|
|
gp2, indent + 2);
|
|
|
|
if (width > max_width)
|
|
|
|
max_width = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (max_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compute_tree_width(struct gmesh *mesh)
|
|
|
|
{
|
|
|
|
struct gclass *classp;
|
|
|
|
struct ggeom *gp;
|
|
|
|
int max_width, width;
|
|
|
|
|
|
|
|
max_width = width = 0;
|
|
|
|
|
|
|
|
LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
|
|
|
if (!LIST_EMPTY(&gp->lg_consumer))
|
|
|
|
continue;
|
|
|
|
width = compute_tree_width_geom(mesh, gp, 0);
|
|
|
|
if (width > max_width)
|
|
|
|
max_width = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (max_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_tree_geom(struct gmesh *mesh, struct ggeom *gp, int indent, int width)
|
|
|
|
{
|
|
|
|
struct gclass *classp2;
|
|
|
|
struct ggeom *gp2;
|
|
|
|
struct gconsumer *cp2;
|
|
|
|
struct gprovider *pp;
|
|
|
|
|
|
|
|
if (LIST_EMPTY(&gp->lg_provider)) {
|
|
|
|
printf("%*s%-*.*s %-*.*s\n", indent, "",
|
|
|
|
width - indent, width - indent, gp->lg_name,
|
|
|
|
GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
printf("%*s%-*.*s %-*.*s %s\n", indent, "",
|
|
|
|
width - indent, width - indent, gp->lg_name,
|
|
|
|
GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name,
|
|
|
|
pp->lg_name);
|
|
|
|
|
|
|
|
LIST_FOREACH(classp2, &mesh->lg_class, lg_class) {
|
|
|
|
LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) {
|
|
|
|
LIST_FOREACH(cp2,
|
|
|
|
&gp2->lg_consumer, lg_consumer) {
|
|
|
|
if (pp != cp2->lg_provider)
|
|
|
|
continue;
|
|
|
|
show_tree_geom(mesh, gp2,
|
|
|
|
indent + 2, width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_tree(void)
|
|
|
|
{
|
|
|
|
struct gmesh mesh;
|
|
|
|
struct gclass *classp;
|
|
|
|
struct ggeom *gp;
|
|
|
|
int error, width;
|
|
|
|
|
|
|
|
error = geom_gettree(&mesh);
|
|
|
|
if (error != 0)
|
|
|
|
errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
|
|
|
|
|
|
|
|
width = compute_tree_width(&mesh);
|
|
|
|
|
|
|
|
printf("%-*.*s %-*.*s %s\n",
|
|
|
|
width, width, "Geom",
|
|
|
|
GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, "Class",
|
|
|
|
"Provider");
|
|
|
|
|
|
|
|
LIST_FOREACH(classp, &mesh.lg_class, lg_class) {
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
|
|
|
if (!LIST_EMPTY(&gp->lg_consumer))
|
|
|
|
continue;
|
|
|
|
show_tree_geom(&mesh, gp, 0, width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2018-09-13 14:06:01 +00:00
|
|
|
char *provider_name;
|
2018-09-14 15:29:45 +00:00
|
|
|
bool tflag;
|
2018-09-13 14:06:01 +00:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
provider_name = NULL;
|
2018-09-14 15:29:45 +00:00
|
|
|
tflag = false;
|
2018-09-13 14:06:01 +00:00
|
|
|
|
|
|
|
if (strcmp(getprogname(), "geom") == 0) {
|
2018-09-14 15:29:45 +00:00
|
|
|
while ((ch = getopt(argc, argv, "hp:t")) != -1) {
|
2018-09-13 14:06:01 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'p':
|
|
|
|
provider_name = strdup(optarg);
|
|
|
|
if (provider_name == NULL)
|
|
|
|
err(1, "strdup");
|
|
|
|
break;
|
2018-09-14 15:29:45 +00:00
|
|
|
case 't':
|
|
|
|
tflag = true;
|
|
|
|
break;
|
2018-09-13 14:06:01 +00:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't adjust argc and argv, it would break get_class().
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2018-09-14 15:29:45 +00:00
|
|
|
if (tflag && provider_name != NULL) {
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"At most one of -P and -t may be specified.");
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:06:01 +00:00
|
|
|
if (provider_name != NULL) {
|
|
|
|
list_one_geom_by_provider(provider_name);
|
|
|
|
return (0);
|
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2018-09-14 15:29:45 +00:00
|
|
|
if (tflag) {
|
|
|
|
show_tree();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
get_class(&argc, &argv);
|
|
|
|
run_command(argc, argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct gclass *
|
|
|
|
find_class(struct gmesh *mesh, const char *name)
|
|
|
|
{
|
|
|
|
struct gclass *classp;
|
|
|
|
|
|
|
|
LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
|
|
|
|
if (strcmp(classp->lg_name, name) == 0)
|
|
|
|
return (classp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2004-07-26 17:14:47 +00:00
|
|
|
static struct ggeom *
|
|
|
|
find_geom(struct gclass *classp, const char *name)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
|
|
|
struct ggeom *gp;
|
|
|
|
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
2004-07-26 17:14:47 +00:00
|
|
|
if (strcmp(gp->lg_name, name) == 0)
|
|
|
|
return (gp);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2004-07-26 17:14:47 +00:00
|
|
|
static void
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_provider(struct gprovider *pp, const char *prefix)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
2004-07-26 17:14:47 +00:00
|
|
|
struct gconfig *conf;
|
|
|
|
char buf[5];
|
|
|
|
|
|
|
|
printf("Name: %s\n", pp->lg_name);
|
|
|
|
humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "",
|
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
|
|
|
printf("%sMediasize: %jd (%s)\n", prefix, (intmax_t)pp->lg_mediasize,
|
|
|
|
buf);
|
|
|
|
printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize);
|
2010-01-17 08:10:37 +00:00
|
|
|
if (pp->lg_stripesize > 0 || pp->lg_stripeoffset > 0) {
|
2010-01-17 06:20:30 +00:00
|
|
|
printf("%sStripesize: %ju\n", prefix, pp->lg_stripesize);
|
|
|
|
printf("%sStripeoffset: %ju\n", prefix, pp->lg_stripeoffset);
|
|
|
|
}
|
2004-07-26 17:14:47 +00:00
|
|
|
printf("%sMode: %s\n", prefix, pp->lg_mode);
|
|
|
|
LIST_FOREACH(conf, &pp->lg_config, lg_config) {
|
|
|
|
printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_consumer(struct gconsumer *cp, const char *prefix)
|
2004-07-26 17:14:47 +00:00
|
|
|
{
|
|
|
|
struct gprovider *pp;
|
|
|
|
struct gconfig *conf;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2004-07-26 17:14:47 +00:00
|
|
|
pp = cp->lg_provider;
|
|
|
|
if (pp == NULL)
|
|
|
|
printf("[no provider]\n");
|
|
|
|
else {
|
|
|
|
char buf[5];
|
|
|
|
|
|
|
|
printf("Name: %s\n", pp->lg_name);
|
|
|
|
humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "",
|
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
|
|
|
printf("%sMediasize: %jd (%s)\n", prefix,
|
|
|
|
(intmax_t)pp->lg_mediasize, buf);
|
|
|
|
printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize);
|
2010-01-18 19:39:55 +00:00
|
|
|
if (pp->lg_stripesize > 0 || pp->lg_stripeoffset > 0) {
|
2010-01-17 06:20:30 +00:00
|
|
|
printf("%sStripesize: %ju\n", prefix, pp->lg_stripesize);
|
|
|
|
printf("%sStripeoffset: %ju\n", prefix, pp->lg_stripeoffset);
|
|
|
|
}
|
2004-07-26 17:14:47 +00:00
|
|
|
printf("%sMode: %s\n", prefix, cp->lg_mode);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2004-07-26 17:14:47 +00:00
|
|
|
LIST_FOREACH(conf, &cp->lg_config, lg_config) {
|
|
|
|
printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_geom(struct ggeom *gp)
|
2004-05-20 10:09:56 +00:00
|
|
|
{
|
2004-07-26 17:14:47 +00:00
|
|
|
struct gprovider *pp;
|
|
|
|
struct gconsumer *cp;
|
2004-05-20 10:09:56 +00:00
|
|
|
struct gconfig *conf;
|
2004-07-26 17:14:47 +00:00
|
|
|
unsigned n;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
2004-07-26 17:14:47 +00:00
|
|
|
printf("Geom name: %s\n", gp->lg_name);
|
|
|
|
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
|
|
|
|
printf("%s: %s\n", conf->lg_name, conf->lg_val);
|
|
|
|
}
|
|
|
|
if (!LIST_EMPTY(&gp->lg_provider)) {
|
|
|
|
printf("Providers:\n");
|
|
|
|
n = 1;
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
printf("%u. ", n++);
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_provider(pp, " ");
|
2004-07-26 17:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!LIST_EMPTY(&gp->lg_consumer)) {
|
|
|
|
printf("Consumers:\n");
|
|
|
|
n = 1;
|
|
|
|
LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
|
|
|
|
printf("%u. ", n++);
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_consumer(cp, " ");
|
2004-07-26 17:14:47 +00:00
|
|
|
}
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:06:01 +00:00
|
|
|
static void
|
|
|
|
list_one_geom_by_provider(const char *provider_name)
|
|
|
|
{
|
|
|
|
struct gmesh mesh;
|
|
|
|
struct ggeom *gp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = geom_gettree(&mesh);
|
|
|
|
if (error != 0)
|
|
|
|
errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
|
|
|
|
|
|
|
|
gp = find_geom_by_provider(&mesh, provider_name);
|
|
|
|
if (gp == NULL)
|
|
|
|
errx(EXIT_FAILURE, "Cannot find provider '%s'.", provider_name);
|
|
|
|
|
|
|
|
printf("Geom class: %s\n", gp->lg_class->lg_name);
|
|
|
|
list_one_geom(gp);
|
|
|
|
}
|
|
|
|
|
2004-05-22 16:57:39 +00:00
|
|
|
static void
|
|
|
|
std_help(struct gctl_req *req __unused, unsigned flags __unused)
|
|
|
|
{
|
|
|
|
|
2005-03-14 14:24:46 +00:00
|
|
|
usage();
|
2004-05-22 16:57:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
static int
|
|
|
|
std_list_available(void)
|
|
|
|
{
|
|
|
|
struct gmesh mesh;
|
|
|
|
struct gclass *classp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = geom_gettree(&mesh);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (error != 0)
|
|
|
|
errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
|
2004-05-20 10:09:56 +00:00
|
|
|
classp = find_class(&mesh, gclass_name);
|
|
|
|
geom_deletetree(&mesh);
|
|
|
|
if (classp != NULL)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
std_list(struct gctl_req *req, unsigned flags __unused)
|
|
|
|
{
|
|
|
|
struct gmesh mesh;
|
|
|
|
struct gclass *classp;
|
2004-07-26 17:14:47 +00:00
|
|
|
struct ggeom *gp;
|
2005-12-07 01:38:27 +00:00
|
|
|
const char *name;
|
2011-03-24 19:11:05 +00:00
|
|
|
int all, error, i, nargs;
|
2004-05-20 10:09:56 +00:00
|
|
|
|
|
|
|
error = geom_gettree(&mesh);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (error != 0)
|
|
|
|
errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
|
2004-05-20 10:09:56 +00:00
|
|
|
classp = find_class(&mesh, gclass_name);
|
|
|
|
if (classp == NULL) {
|
|
|
|
geom_deletetree(&mesh);
|
2018-09-11 16:46:28 +00:00
|
|
|
errx(EXIT_FAILURE, "Class '%s' not found.", gclass_name);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
2005-12-07 01:38:27 +00:00
|
|
|
nargs = gctl_get_int(req, "nargs");
|
2011-03-24 19:11:05 +00:00
|
|
|
all = gctl_get_int(req, "all");
|
2005-12-07 01:38:27 +00:00
|
|
|
if (nargs > 0) {
|
|
|
|
for (i = 0; i < nargs; i++) {
|
|
|
|
name = gctl_get_ascii(req, "arg%d", i);
|
2004-07-26 17:14:47 +00:00
|
|
|
gp = find_geom(classp, name);
|
2018-09-11 16:46:28 +00:00
|
|
|
if (gp == NULL) {
|
|
|
|
errx(EXIT_FAILURE, "Class '%s' does not have "
|
|
|
|
"an instance named '%s'.",
|
|
|
|
gclass_name, name);
|
|
|
|
}
|
2011-03-24 19:11:05 +00:00
|
|
|
list_one_geom(gp);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
2011-03-24 19:11:05 +00:00
|
|
|
if (LIST_EMPTY(&gp->lg_provider) && !all)
|
2005-03-13 16:45:41 +00:00
|
|
|
continue;
|
2005-03-13 19:10:13 +00:00
|
|
|
list_one_geom(gp);
|
2004-05-20 10:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
geom_deletetree(&mesh);
|
|
|
|
}
|
|
|
|
|
2005-03-13 19:34:27 +00:00
|
|
|
static int
|
|
|
|
std_status_available(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* 'status' command is available when 'list' command is. */
|
|
|
|
return (std_list_available());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-14 08:34:02 +00:00
|
|
|
status_update_len(struct ggeom *gp, int *name_len, int *status_len)
|
2005-03-13 19:34:27 +00:00
|
|
|
{
|
|
|
|
struct gconfig *conf;
|
2005-03-14 08:34:02 +00:00
|
|
|
int len;
|
2005-03-13 19:34:27 +00:00
|
|
|
|
|
|
|
assert(gp != NULL);
|
|
|
|
assert(name_len != NULL);
|
|
|
|
assert(status_len != NULL);
|
|
|
|
|
2011-03-24 19:11:05 +00:00
|
|
|
len = strlen(gp->lg_name);
|
2005-03-13 19:34:27 +00:00
|
|
|
if (*name_len < len)
|
|
|
|
*name_len = len;
|
|
|
|
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
|
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
len = strlen(conf->lg_val);
|
|
|
|
if (*status_len < len)
|
|
|
|
*status_len = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 19:11:05 +00:00
|
|
|
static void
|
|
|
|
status_update_len_prs(struct ggeom *gp, int *name_len, int *status_len)
|
|
|
|
{
|
|
|
|
struct gprovider *pp;
|
|
|
|
struct gconfig *conf;
|
|
|
|
int len, glen;
|
|
|
|
|
|
|
|
assert(gp != NULL);
|
|
|
|
assert(name_len != NULL);
|
|
|
|
assert(status_len != NULL);
|
|
|
|
|
|
|
|
glen = 0;
|
|
|
|
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
|
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
glen = strlen(conf->lg_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
len = strlen(pp->lg_name);
|
|
|
|
if (*name_len < len)
|
|
|
|
*name_len = len;
|
|
|
|
len = glen;
|
|
|
|
LIST_FOREACH(conf, &pp->lg_config, lg_config) {
|
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
len = strlen(conf->lg_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*status_len < len)
|
|
|
|
*status_len = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 12:33:19 +00:00
|
|
|
static char *
|
2005-03-13 19:34:27 +00:00
|
|
|
status_one_consumer(struct gconsumer *cp)
|
|
|
|
{
|
2005-03-14 12:33:19 +00:00
|
|
|
static char buf[256];
|
2005-03-13 19:34:27 +00:00
|
|
|
struct gprovider *pp;
|
|
|
|
struct gconfig *conf;
|
2011-03-24 19:11:05 +00:00
|
|
|
const char *state, *syncr;
|
2005-03-13 19:34:27 +00:00
|
|
|
|
|
|
|
pp = cp->lg_provider;
|
|
|
|
if (pp == NULL)
|
2005-03-14 12:33:19 +00:00
|
|
|
return (NULL);
|
2011-03-24 19:11:05 +00:00
|
|
|
state = NULL;
|
|
|
|
syncr = NULL;
|
2005-03-13 19:34:27 +00:00
|
|
|
LIST_FOREACH(conf, &cp->lg_config, lg_config) {
|
2011-03-24 19:11:05 +00:00
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0)
|
|
|
|
state = conf->lg_val;
|
2005-03-13 19:34:27 +00:00
|
|
|
if (strcasecmp(conf->lg_name, "synchronized") == 0)
|
2011-03-24 19:11:05 +00:00
|
|
|
syncr = conf->lg_val;
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
2011-03-24 19:11:05 +00:00
|
|
|
if (state == NULL && syncr == NULL)
|
2005-03-14 12:33:19 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s", pp->lg_name);
|
2011-03-24 19:11:05 +00:00
|
|
|
else if (state != NULL && syncr != NULL) {
|
|
|
|
snprintf(buf, sizeof(buf), "%s (%s, %s)", pp->lg_name,
|
|
|
|
state, syncr);
|
|
|
|
} else {
|
2005-03-14 12:33:19 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s (%s)", pp->lg_name,
|
2011-03-24 19:11:05 +00:00
|
|
|
state ? state : syncr);
|
2005-03-14 12:33:19 +00:00
|
|
|
}
|
|
|
|
return (buf);
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-03-14 12:33:19 +00:00
|
|
|
status_one_geom(struct ggeom *gp, int script, int name_len, int status_len)
|
2005-03-13 19:34:27 +00:00
|
|
|
{
|
|
|
|
struct gconsumer *cp;
|
|
|
|
struct gconfig *conf;
|
2005-03-14 12:33:19 +00:00
|
|
|
const char *name, *status, *component;
|
|
|
|
int gotone;
|
2005-03-13 19:34:27 +00:00
|
|
|
|
2011-03-24 19:11:05 +00:00
|
|
|
name = gp->lg_name;
|
|
|
|
status = "N/A";
|
2005-03-13 19:34:27 +00:00
|
|
|
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
|
2011-03-24 19:11:05 +00:00
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
status = conf->lg_val;
|
2005-03-13 19:34:27 +00:00
|
|
|
break;
|
2011-03-24 19:11:05 +00:00
|
|
|
}
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
2005-03-14 12:33:19 +00:00
|
|
|
gotone = 0;
|
2005-03-13 19:34:27 +00:00
|
|
|
LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
|
2005-03-14 12:33:19 +00:00
|
|
|
component = status_one_consumer(cp);
|
|
|
|
if (component == NULL)
|
|
|
|
continue;
|
|
|
|
gotone = 1;
|
|
|
|
printf("%*s %*s %s\n", name_len, name, status_len, status,
|
|
|
|
component);
|
|
|
|
if (!script)
|
|
|
|
name = status = "";
|
|
|
|
}
|
|
|
|
if (!gotone) {
|
|
|
|
printf("%*s %*s %s\n", name_len, name, status_len, status,
|
|
|
|
"N/A");
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 19:11:05 +00:00
|
|
|
static void
|
|
|
|
status_one_geom_prs(struct ggeom *gp, int script, int name_len, int status_len)
|
|
|
|
{
|
|
|
|
struct gprovider *pp;
|
|
|
|
struct gconsumer *cp;
|
|
|
|
struct gconfig *conf;
|
|
|
|
const char *name, *status, *component;
|
|
|
|
int gotone;
|
|
|
|
|
|
|
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
|
|
|
name = pp->lg_name;
|
|
|
|
status = "N/A";
|
|
|
|
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
|
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
status = conf->lg_val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIST_FOREACH(conf, &pp->lg_config, lg_config) {
|
|
|
|
if (strcasecmp(conf->lg_name, "state") == 0) {
|
|
|
|
status = conf->lg_val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gotone = 0;
|
|
|
|
LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
|
|
|
|
component = status_one_consumer(cp);
|
|
|
|
if (component == NULL)
|
|
|
|
continue;
|
|
|
|
gotone = 1;
|
|
|
|
printf("%*s %*s %s\n", name_len, name,
|
|
|
|
status_len, status, component);
|
|
|
|
if (!script)
|
|
|
|
name = status = "";
|
|
|
|
}
|
|
|
|
if (!gotone) {
|
|
|
|
printf("%*s %*s %s\n", name_len, name,
|
|
|
|
status_len, status, "N/A");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-13 19:34:27 +00:00
|
|
|
static void
|
|
|
|
std_status(struct gctl_req *req, unsigned flags __unused)
|
|
|
|
{
|
|
|
|
struct gmesh mesh;
|
|
|
|
struct gclass *classp;
|
|
|
|
struct ggeom *gp;
|
2005-12-07 01:38:27 +00:00
|
|
|
const char *name;
|
2005-03-14 08:34:02 +00:00
|
|
|
int name_len, status_len;
|
2011-03-24 19:11:05 +00:00
|
|
|
int all, error, geoms, i, n, nargs, script;
|
2005-03-13 19:34:27 +00:00
|
|
|
|
|
|
|
error = geom_gettree(&mesh);
|
2006-09-30 14:39:18 +00:00
|
|
|
if (error != 0)
|
|
|
|
errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
|
2005-03-13 19:34:27 +00:00
|
|
|
classp = find_class(&mesh, gclass_name);
|
2007-03-23 21:05:36 +00:00
|
|
|
if (classp == NULL)
|
|
|
|
errx(EXIT_FAILURE, "Class %s not found.", gclass_name);
|
2005-12-07 01:38:27 +00:00
|
|
|
nargs = gctl_get_int(req, "nargs");
|
2011-03-24 19:11:05 +00:00
|
|
|
all = gctl_get_int(req, "all");
|
|
|
|
geoms = gctl_get_int(req, "geoms");
|
2005-12-07 01:38:27 +00:00
|
|
|
script = gctl_get_int(req, "script");
|
2011-03-24 19:11:05 +00:00
|
|
|
if (script) {
|
|
|
|
name_len = 0;
|
|
|
|
status_len = 0;
|
|
|
|
} else {
|
|
|
|
name_len = strlen("Name");
|
|
|
|
status_len = strlen("Status");
|
|
|
|
}
|
2005-12-07 01:38:27 +00:00
|
|
|
if (nargs > 0) {
|
|
|
|
for (i = 0, n = 0; i < nargs; i++) {
|
|
|
|
name = gctl_get_ascii(req, "arg%d", i);
|
2005-03-13 19:34:27 +00:00
|
|
|
gp = find_geom(classp, name);
|
|
|
|
if (gp == NULL)
|
2007-03-23 21:05:36 +00:00
|
|
|
errx(EXIT_FAILURE, "No such geom: %s.", name);
|
2011-03-24 19:11:05 +00:00
|
|
|
if (geoms) {
|
|
|
|
status_update_len(gp,
|
|
|
|
&name_len, &status_len);
|
|
|
|
} else {
|
|
|
|
status_update_len_prs(gp,
|
|
|
|
&name_len, &status_len);
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
2011-03-24 19:11:05 +00:00
|
|
|
n++;
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
|
|
|
if (n == 0)
|
|
|
|
goto end;
|
|
|
|
} else {
|
2005-12-07 01:38:27 +00:00
|
|
|
n = 0;
|
2005-03-13 19:34:27 +00:00
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
2011-03-24 19:11:05 +00:00
|
|
|
if (LIST_EMPTY(&gp->lg_provider) && !all)
|
2005-03-13 19:34:27 +00:00
|
|
|
continue;
|
2011-03-24 19:11:05 +00:00
|
|
|
if (geoms) {
|
|
|
|
status_update_len(gp,
|
|
|
|
&name_len, &status_len);
|
|
|
|
} else {
|
|
|
|
status_update_len_prs(gp,
|
|
|
|
&name_len, &status_len);
|
|
|
|
}
|
2005-03-13 19:34:27 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (n == 0)
|
|
|
|
goto end;
|
|
|
|
}
|
2005-12-07 01:38:27 +00:00
|
|
|
if (!script) {
|
2005-03-14 12:33:19 +00:00
|
|
|
printf("%*s %*s %s\n", name_len, "Name", status_len, "Status",
|
|
|
|
"Components");
|
|
|
|
}
|
2005-12-07 01:38:27 +00:00
|
|
|
if (nargs > 0) {
|
|
|
|
for (i = 0; i < nargs; i++) {
|
|
|
|
name = gctl_get_ascii(req, "arg%d", i);
|
2005-03-13 19:34:27 +00:00
|
|
|
gp = find_geom(classp, name);
|
2011-03-24 19:11:05 +00:00
|
|
|
if (gp == NULL)
|
|
|
|
continue;
|
|
|
|
if (geoms) {
|
2005-12-07 01:38:27 +00:00
|
|
|
status_one_geom(gp, script, name_len,
|
2005-03-14 12:33:19 +00:00
|
|
|
status_len);
|
2011-03-24 19:11:05 +00:00
|
|
|
} else {
|
|
|
|
status_one_geom_prs(gp, script, name_len,
|
|
|
|
status_len);
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
2011-03-24 19:11:05 +00:00
|
|
|
if (LIST_EMPTY(&gp->lg_provider) && !all)
|
2005-03-13 19:34:27 +00:00
|
|
|
continue;
|
2011-03-24 19:11:05 +00:00
|
|
|
if (geoms) {
|
|
|
|
status_one_geom(gp, script, name_len,
|
|
|
|
status_len);
|
|
|
|
} else {
|
|
|
|
status_one_geom_prs(gp, script, name_len,
|
|
|
|
status_len);
|
|
|
|
}
|
2005-03-13 19:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
geom_deletetree(&mesh);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:09:56 +00:00
|
|
|
static int
|
|
|
|
std_load_available(void)
|
|
|
|
{
|
|
|
|
char name[MAXPATHLEN], paths[MAXPATHLEN * 8], *p;
|
|
|
|
struct stat sb;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "g_%s", class_name);
|
|
|
|
/*
|
|
|
|
* If already in kernel, "load" command is not available.
|
|
|
|
*/
|
|
|
|
if (modfind(name) >= 0)
|
|
|
|
return (0);
|
|
|
|
bzero(paths, sizeof(paths));
|
|
|
|
len = sizeof(paths);
|
|
|
|
if (sysctlbyname("kern.module_path", paths, &len, NULL, 0) < 0)
|
|
|
|
err(EXIT_FAILURE, "sysctl(kern.module_path)");
|
|
|
|
for (p = strtok(paths, ";"); p != NULL; p = strtok(NULL, ";")) {
|
|
|
|
snprintf(name, sizeof(name), "%s/geom_%s.ko", p, class_name);
|
|
|
|
/*
|
|
|
|
* If geom_<name>.ko file exists, "load" command is available.
|
|
|
|
*/
|
|
|
|
if (stat(name, &sb) == 0)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
std_load(struct gctl_req *req __unused, unsigned flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing special here, because of G_FLAG_LOADKLD flag,
|
|
|
|
* module is already loaded.
|
|
|
|
*/
|
|
|
|
if ((flags & G_FLAG_VERBOSE) != 0)
|
|
|
|
printf("Module available.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
std_unload_available(void)
|
|
|
|
{
|
|
|
|
char name[64];
|
|
|
|
int id;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "geom_%s", class_name);
|
|
|
|
id = kldfind(name);
|
|
|
|
if (id >= 0)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
std_unload(struct gctl_req *req, unsigned flags __unused)
|
|
|
|
{
|
|
|
|
char name[64];
|
|
|
|
int id;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "geom_%s", class_name);
|
|
|
|
id = kldfind(name);
|
|
|
|
if (id < 0) {
|
|
|
|
gctl_error(req, "Could not find module: %s.", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (kldunload(id) < 0) {
|
|
|
|
gctl_error(req, "Could not unload module: %s.",
|
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
std_available(const char *name)
|
|
|
|
{
|
|
|
|
|
2004-05-22 16:57:39 +00:00
|
|
|
if (strcmp(name, "help") == 0)
|
|
|
|
return (1);
|
|
|
|
else if (strcmp(name, "list") == 0)
|
2004-05-20 10:09:56 +00:00
|
|
|
return (std_list_available());
|
2005-03-13 19:34:27 +00:00
|
|
|
else if (strcmp(name, "status") == 0)
|
|
|
|
return (std_status_available());
|
2004-05-20 10:09:56 +00:00
|
|
|
else if (strcmp(name, "load") == 0)
|
|
|
|
return (std_load_available());
|
|
|
|
else if (strcmp(name, "unload") == 0)
|
|
|
|
return (std_unload_available());
|
|
|
|
else
|
|
|
|
assert(!"Unknown standard command.");
|
|
|
|
return (0);
|
|
|
|
}
|