2 * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/linker.h>
32 #include <sys/module.h>
34 #include <sys/sysctl.h>
52 #include "misc/subr.h"
54 #ifdef STATIC_GEOM_CLASSES
55 extern uint32_t gpart_version;
56 extern struct g_command gpart_class_commands[];
57 extern uint32_t glabel_version;
58 extern struct g_command glabel_class_commands[];
61 static char comm[MAXPATHLEN], *class_name = NULL, *gclass_name = NULL;
62 static uint32_t *version = NULL;
63 static int verbose = 0;
64 static struct g_command *class_commands = NULL;
66 #define GEOM_CLASS_CMDS 0x01
67 #define GEOM_STD_CMDS 0x02
68 static struct g_command *find_command(const char *cmdstr, int flags);
69 static int std_available(const char *name);
71 static void std_help(struct gctl_req *req, unsigned flags);
72 static void std_list(struct gctl_req *req, unsigned flags);
73 static void std_status(struct gctl_req *req, unsigned flags);
74 static void std_load(struct gctl_req *req, unsigned flags);
75 static void std_unload(struct gctl_req *req, unsigned flags);
77 struct g_command std_commands[] = {
78 { "help", 0, std_help, G_NULL_OPTS, NULL, NULL },
79 { "list", 0, std_list, G_NULL_OPTS, NULL,
82 { "status", 0, std_status,
84 { 's', "script", NULL, G_TYPE_BOOL },
87 NULL, "[-s] [name ...]"
89 { "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS,
91 { "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL, NULL },
96 usage_command(struct g_command *cmd, const char *prefix)
101 fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
102 if (cmd->gc_usage != NULL) {
103 fprintf(stderr, " %s\n", cmd->gc_usage);
106 if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0)
107 fprintf(stderr, " [-v]");
109 opt = &cmd->gc_options[i];
110 if (opt->go_name == NULL)
112 if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
113 fprintf(stderr, " [");
115 fprintf(stderr, " ");
116 fprintf(stderr, "-%c", opt->go_char);
117 if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
118 fprintf(stderr, " %s", opt->go_name);
119 if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
120 fprintf(stderr, "]");
123 fprintf(stderr, " %s", cmd->gc_argname);
124 fprintf(stderr, "\n");
131 if (class_name == NULL) {
132 errx(EXIT_FAILURE, "usage: %s <class> <command> [options]",
135 struct g_command *cmd;
140 if (class_commands != NULL) {
142 cmd = &class_commands[i];
143 if (cmd->gc_name == NULL)
145 usage_command(cmd, prefix);
150 cmd = &std_commands[i];
151 if (cmd->gc_name == NULL)
154 * If class defines command, which has the same name as
155 * standard command, skip it, because it was already
158 if (find_command(cmd->gc_name, GEOM_CLASS_CMDS) != NULL)
160 usage_command(cmd, prefix);
170 char name1[64], name2[64];
172 snprintf(name1, sizeof(name1), "g_%s", class_name);
173 snprintf(name2, sizeof(name2), "geom_%s", class_name);
174 if (modfind(name1) < 0) {
175 /* Not present in kernel, try loading it. */
176 if (kldload(name2) < 0 || modfind(name1) < 0) {
177 if (errno != EEXIST) {
179 "%s module not available!", name2);
186 strlcatf(char *str, size_t size, const char *format, ...)
196 va_start(ap, format);
197 ret = vsnprintf(str, size, format, ap);
204 * Find given option in options available for given command.
206 static struct g_option *
207 find_option(struct g_command *cmd, char ch)
209 struct g_option *opt;
213 opt = &cmd->gc_options[i];
214 if (opt->go_name == NULL)
216 if (opt->go_char == ch)
224 * Add given option to gctl_req.
227 set_option(struct g_command *cmd, struct gctl_req *req, struct g_option *opt,
234 if (G_OPT_ISMULTI(opt)) {
237 if (G_OPT_NUM(opt) == UCHAR_MAX)
238 errx(EXIT_FAILURE, "Too many -%c options.", opt->go_char);
241 * Base option name length plus 3 bytes for option number
242 * (max. 255 options) plus 1 byte for terminating '\0'.
244 optnamesize = strlen(opt->go_name) + 3 + 1;
245 ptr = malloc(optnamesize);
247 errx(EXIT_FAILURE, "No memory.");
248 snprintf(ptr, optnamesize, "%s%u", opt->go_name, G_OPT_NUM(opt));
252 optname = opt->go_name;
255 if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) {
256 if (expand_number(val, &number) == -1) {
257 err(EXIT_FAILURE, "Invalid value for '%c' argument",
260 ptr = malloc(sizeof(intmax_t));
262 errx(EXIT_FAILURE, "No memory.");
263 *(intmax_t *)ptr = number;
265 gctl_ro_param(req, optname, sizeof(intmax_t), opt->go_val);
266 } else if (G_OPT_TYPE(opt) == G_TYPE_ASCNUM) {
267 if (cmd->gc_argname == NULL || *val != '\0') {
270 if (expand_number(val, &number) == -1) {
271 err(EXIT_FAILURE, "Invalid value for '%c' argument",
274 asprintf(&s, "%jd", number);
276 errx(EXIT_FAILURE, "No memory.");
278 gctl_ro_param(req, optname, -1, opt->go_val);
280 } else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
281 if (cmd->gc_argname == NULL || *val != '\0')
282 gctl_ro_param(req, optname, -1, val);
283 } else if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
284 ptr = malloc(sizeof(int));
286 errx(EXIT_FAILURE, "No memory.");
287 *(int *)ptr = *val - '0';
289 gctl_ro_param(req, optname, sizeof(int), opt->go_val);
291 assert(!"Invalid type");
294 if (G_OPT_ISMULTI(opt))
295 free(__DECONST(char *, optname));
299 * 1. Add given argument by caller.
300 * 2. Add default values of not given arguments.
301 * 3. Add the rest of arguments.
304 parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
307 struct g_option *opt;
313 if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0)
314 strlcat(opts, "v", sizeof(opts));
316 opt = &cmd->gc_options[i];
317 if (opt->go_name == NULL)
319 assert(G_OPT_TYPE(opt) != 0);
320 assert((opt->go_type & ~(G_TYPE_MASK | G_TYPE_MULTI)) == 0);
321 /* Multiple bool arguments makes no sense. */
322 assert(G_OPT_TYPE(opt) != G_TYPE_BOOL ||
323 (opt->go_type & G_TYPE_MULTI) == 0);
324 strlcatf(opts, sizeof(opts), "%c", opt->go_char);
325 if (G_OPT_TYPE(opt) != G_TYPE_BOOL)
326 strlcat(opts, ":", sizeof(opts));
330 * Add specified arguments.
332 while ((ch = getopt(*argc, *argv, opts)) != -1) {
333 /* Standard (not passed to kernel) options. */
339 /* Options passed to kernel. */
340 opt = find_option(cmd, ch);
343 if (!G_OPT_ISMULTI(opt) && G_OPT_ISDONE(opt)) {
344 warnx("Option '%c' specified twice.", opt->go_char);
349 if (G_OPT_TYPE(opt) == G_TYPE_BOOL)
350 set_option(cmd, req, opt, "1");
352 set_option(cmd, req, opt, optarg);
358 * Add not specified arguments, but with default values.
361 opt = &cmd->gc_options[i];
362 if (opt->go_name == NULL)
364 if (G_OPT_ISDONE(opt))
367 if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
368 assert(opt->go_val == NULL);
369 set_option(cmd, req, opt, "0");
371 if (opt->go_val == NULL) {
372 warnx("Option '%c' not specified.",
375 } else if (opt->go_val == G_VAL_OPTIONAL) {
378 set_option(cmd, req, opt, opt->go_val);
383 if (cmd->gc_argname == NULL) {
385 * Add rest of given arguments.
387 gctl_ro_param(req, "nargs", sizeof(int), argc);
388 for (i = 0; i < (unsigned)*argc; i++) {
391 snprintf(argname, sizeof(argname), "arg%u", i);
392 gctl_ro_param(req, argname, -1, (*argv)[i]);
397 gctl_ro_param(req, cmd->gc_argname, -1, (*argv)[0]);
402 * Find given command in commands available for given class.
404 static struct g_command *
405 find_command(const char *cmdstr, int flags)
407 struct g_command *cmd;
411 * First try to find command defined by loaded library.
413 if ((flags & GEOM_CLASS_CMDS) != 0 && class_commands != NULL) {
415 cmd = &class_commands[i];
416 if (cmd->gc_name == NULL)
418 if (strcmp(cmd->gc_name, cmdstr) == 0)
423 * Now try to find in standard commands.
425 if ((flags & GEOM_STD_CMDS) != 0) {
427 cmd = &std_commands[i];
428 if (cmd->gc_name == NULL)
430 if (strcmp(cmd->gc_name, cmdstr) == 0)
438 set_flags(struct g_command *cmd)
442 if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0 && verbose)
443 flags |= G_FLAG_VERBOSE;
452 run_command(int argc, char *argv[])
454 struct g_command *cmd;
455 struct gctl_req *req;
459 /* First try to find a command defined by a class. */
460 cmd = find_command(argv[0], GEOM_CLASS_CMDS);
462 /* Now, try to find a standard command. */
463 cmd = find_command(argv[0], GEOM_STD_CMDS);
465 warnx("Unknown command: %s.", argv[0]);
468 if (!std_available(cmd->gc_name)) {
469 warnx("Command '%s' not available.", argv[0]);
473 if ((cmd->gc_flags & G_FLAG_LOADKLD) != 0)
476 req = gctl_get_handle();
477 gctl_ro_param(req, "class", -1, gclass_name);
478 gctl_ro_param(req, "verb", -1, argv[0]);
480 gctl_ro_param(req, "version", sizeof(*version), version);
481 parse_arguments(cmd, req, &argc, &argv);
483 bzero(buf, sizeof(buf));
484 if (cmd->gc_func != NULL) {
487 flags = set_flags(cmd);
488 cmd->gc_func(req, flags);
491 gctl_rw_param(req, "output", sizeof(buf), buf);
492 errstr = gctl_issue(req);
494 if (errstr != NULL && errstr[0] != '\0') {
496 if (strncmp(errstr, "warning: ", strlen("warning: ")) != 0) {
509 #ifndef STATIC_GEOM_CLASSES
515 path = getenv("GEOM_LIBRARY_PATH");
524 char *curpath, path[MAXPATHLEN], *tofree, *totalpath;
525 uint32_t *lib_version;
530 tofree = totalpath = strdup(library_path());
531 if (totalpath == NULL)
532 err(EXIT_FAILURE, "Not enough memory for library path");
534 if (strchr(totalpath, ':') != NULL)
535 curpath = strsep(&totalpath, ":");
538 /* Traverse the paths to find one that contains the library we want. */
539 while (curpath != NULL) {
540 snprintf(path, sizeof(path), "%s/geom_%s.so", curpath,
542 ret = access(path, F_OK);
544 if (errno == ENOENT) {
546 * If we cannot find library, try the next
549 curpath = strsep(&totalpath, ":");
552 err(EXIT_FAILURE, "Cannot access library");
557 /* No library was found, but standard commands can still be used */
560 dlh = dlopen(path, RTLD_NOW);
562 errx(EXIT_FAILURE, "Cannot open library: %s.", dlerror());
563 lib_version = dlsym(dlh, "lib_version");
564 if (lib_version == NULL) {
565 warnx("Cannot find symbol %s: %s.", "lib_version", dlerror());
569 if (*lib_version != G_LIB_VERSION) {
571 errx(EXIT_FAILURE, "%s and %s are not synchronized.",
572 getprogname(), path);
574 version = dlsym(dlh, "version");
575 if (version == NULL) {
576 warnx("Cannot find symbol %s: %s.", "version", dlerror());
580 class_commands = dlsym(dlh, "class_commands");
581 if (class_commands == NULL) {
582 warnx("Cannot find symbol %s: %s.", "class_commands",
588 #endif /* !STATIC_GEOM_CLASSES */
591 * Class name should be all capital letters.
599 for (; *s1 != '\0'; s1++)
601 gclass_name = malloc(strlen(class_name) + 1);
602 if (gclass_name == NULL)
603 errx(EXIT_FAILURE, "No memory");
606 for (; *s2 != '\0'; s2++)
607 *s1++ = toupper(*s2);
612 get_class(int *argc, char ***argv)
615 snprintf(comm, sizeof(comm), "%s", basename((*argv)[0]));
616 if (strcmp(comm, "geom") == 0) {
619 else if (*argc == 2) {
620 if (strcmp((*argv)[1], "-h") == 0 ||
621 strcmp((*argv)[1], "help") == 0) {
625 strlcatf(comm, sizeof(comm), " %s", (*argv)[1]);
626 class_name = (*argv)[1];
629 } else if (*comm == 'g') {
630 class_name = comm + 1;
634 errx(EXIT_FAILURE, "Invalid utility name.");
637 #ifndef STATIC_GEOM_CLASSES
640 if (!strcasecmp(class_name, "part")) {
641 version = &gpart_version;
642 class_commands = gpart_class_commands;
643 } else if (!strcasecmp(class_name, "label")) {
644 version = &glabel_version;
645 class_commands = glabel_class_commands;
647 errx(EXIT_FAILURE, "Invalid class name.");
648 #endif /* !STATIC_GEOM_CLASSES */
656 main(int argc, char *argv[])
659 get_class(&argc, &argv);
660 run_command(argc, argv);
666 static struct gclass *
667 find_class(struct gmesh *mesh, const char *name)
669 struct gclass *classp;
671 LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
672 if (strcmp(classp->lg_name, name) == 0)
678 static struct ggeom *
679 find_geom(struct gclass *classp, const char *name)
683 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
684 if (strcmp(gp->lg_name, name) == 0)
691 list_one_provider(struct gprovider *pp, const char *prefix)
693 struct gconfig *conf;
696 printf("Name: %s\n", pp->lg_name);
697 humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "",
698 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
699 printf("%sMediasize: %jd (%s)\n", prefix, (intmax_t)pp->lg_mediasize,
701 printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize);
702 if (pp->lg_stripesize > 0 || pp->lg_stripeoffset > 0) {
703 printf("%sStripesize: %ju\n", prefix, pp->lg_stripesize);
704 printf("%sStripeoffset: %ju\n", prefix, pp->lg_stripeoffset);
706 printf("%sMode: %s\n", prefix, pp->lg_mode);
707 LIST_FOREACH(conf, &pp->lg_config, lg_config) {
708 printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val);
713 list_one_consumer(struct gconsumer *cp, const char *prefix)
715 struct gprovider *pp;
716 struct gconfig *conf;
718 pp = cp->lg_provider;
720 printf("[no provider]\n");
724 printf("Name: %s\n", pp->lg_name);
725 humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "",
726 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
727 printf("%sMediasize: %jd (%s)\n", prefix,
728 (intmax_t)pp->lg_mediasize, buf);
729 printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize);
730 if (pp->lg_stripesize > 0 || pp->lg_stripeoffset > 0) {
731 printf("%sStripesize: %ju\n", prefix, pp->lg_stripesize);
732 printf("%sStripeoffset: %ju\n", prefix, pp->lg_stripeoffset);
734 printf("%sMode: %s\n", prefix, cp->lg_mode);
736 LIST_FOREACH(conf, &cp->lg_config, lg_config) {
737 printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val);
742 list_one_geom(struct ggeom *gp)
744 struct gprovider *pp;
745 struct gconsumer *cp;
746 struct gconfig *conf;
749 printf("Geom name: %s\n", gp->lg_name);
750 LIST_FOREACH(conf, &gp->lg_config, lg_config) {
751 printf("%s: %s\n", conf->lg_name, conf->lg_val);
753 if (!LIST_EMPTY(&gp->lg_provider)) {
754 printf("Providers:\n");
756 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
758 list_one_provider(pp, " ");
761 if (!LIST_EMPTY(&gp->lg_consumer)) {
762 printf("Consumers:\n");
764 LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
766 list_one_consumer(cp, " ");
773 std_help(struct gctl_req *req __unused, unsigned flags __unused)
780 std_list_available(void)
783 struct gclass *classp;
786 error = geom_gettree(&mesh);
788 errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
789 classp = find_class(&mesh, gclass_name);
790 geom_deletetree(&mesh);
797 std_list(struct gctl_req *req, unsigned flags __unused)
800 struct gclass *classp;
805 error = geom_gettree(&mesh);
807 errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
808 classp = find_class(&mesh, gclass_name);
809 if (classp == NULL) {
810 geom_deletetree(&mesh);
811 errx(EXIT_FAILURE, "Class %s not found.", gclass_name);
813 nargs = gctl_get_int(req, "nargs");
815 for (i = 0; i < nargs; i++) {
816 name = gctl_get_ascii(req, "arg%d", i);
817 gp = find_geom(classp, name);
821 errx(EXIT_FAILURE, "No such geom: %s.", name);
824 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
825 if (LIST_EMPTY(&gp->lg_provider))
830 geom_deletetree(&mesh);
834 std_status_available(void)
837 /* 'status' command is available when 'list' command is. */
838 return (std_list_available());
842 status_update_len(struct ggeom *gp, int *name_len, int *status_len)
844 struct gprovider *pp;
845 struct gconfig *conf;
849 assert(name_len != NULL);
850 assert(status_len != NULL);
852 pp = LIST_FIRST(&gp->lg_provider);
854 len = strlen(pp->lg_name);
856 len = strlen(gp->lg_name);
859 LIST_FOREACH(conf, &gp->lg_config, lg_config) {
860 if (strcasecmp(conf->lg_name, "state") == 0) {
861 len = strlen(conf->lg_val);
862 if (*status_len < len)
869 status_one_consumer(struct gconsumer *cp)
871 static char buf[256];
872 struct gprovider *pp;
873 struct gconfig *conf;
875 pp = cp->lg_provider;
878 LIST_FOREACH(conf, &cp->lg_config, lg_config) {
879 if (strcasecmp(conf->lg_name, "synchronized") == 0)
883 snprintf(buf, sizeof(buf), "%s", pp->lg_name);
885 snprintf(buf, sizeof(buf), "%s (%s)", pp->lg_name,
892 status_one_geom(struct ggeom *gp, int script, int name_len, int status_len)
894 struct gprovider *pp;
895 struct gconsumer *cp;
896 struct gconfig *conf;
897 const char *name, *status, *component;
900 pp = LIST_FIRST(&gp->lg_provider);
905 LIST_FOREACH(conf, &gp->lg_config, lg_config) {
906 if (strcasecmp(conf->lg_name, "state") == 0)
912 status = conf->lg_val;
914 LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
915 component = status_one_consumer(cp);
916 if (component == NULL)
919 printf("%*s %*s %s\n", name_len, name, status_len, status,
925 printf("%*s %*s %s\n", name_len, name, status_len, status,
931 std_status(struct gctl_req *req, unsigned flags __unused)
934 struct gclass *classp;
937 int name_len, status_len;
938 int error, i, n, nargs, script;
940 error = geom_gettree(&mesh);
942 errc(EXIT_FAILURE, error, "Cannot get GEOM tree");
943 classp = find_class(&mesh, gclass_name);
945 errx(EXIT_FAILURE, "Class %s not found.", gclass_name);
946 nargs = gctl_get_int(req, "nargs");
947 script = gctl_get_int(req, "script");
948 name_len = strlen("Name");
949 status_len = strlen("Status");
951 for (i = 0, n = 0; i < nargs; i++) {
952 name = gctl_get_ascii(req, "arg%d", i);
953 gp = find_geom(classp, name);
955 errx(EXIT_FAILURE, "No such geom: %s.", name);
957 status_update_len(gp, &name_len, &status_len);
965 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
966 if (LIST_EMPTY(&gp->lg_provider))
968 status_update_len(gp, &name_len, &status_len);
975 printf("%*s %*s %s\n", name_len, "Name", status_len, "Status",
979 for (i = 0; i < nargs; i++) {
980 name = gctl_get_ascii(req, "arg%d", i);
981 gp = find_geom(classp, name);
983 status_one_geom(gp, script, name_len,
988 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
989 if (LIST_EMPTY(&gp->lg_provider))
991 status_one_geom(gp, script, name_len, status_len);
995 geom_deletetree(&mesh);
999 std_load_available(void)
1001 char name[MAXPATHLEN], paths[MAXPATHLEN * 8], *p;
1005 snprintf(name, sizeof(name), "g_%s", class_name);
1007 * If already in kernel, "load" command is not available.
1009 if (modfind(name) >= 0)
1011 bzero(paths, sizeof(paths));
1012 len = sizeof(paths);
1013 if (sysctlbyname("kern.module_path", paths, &len, NULL, 0) < 0)
1014 err(EXIT_FAILURE, "sysctl(kern.module_path)");
1015 for (p = strtok(paths, ";"); p != NULL; p = strtok(NULL, ";")) {
1016 snprintf(name, sizeof(name), "%s/geom_%s.ko", p, class_name);
1018 * If geom_<name>.ko file exists, "load" command is available.
1020 if (stat(name, &sb) == 0)
1027 std_load(struct gctl_req *req __unused, unsigned flags)
1031 * Do nothing special here, because of G_FLAG_LOADKLD flag,
1032 * module is already loaded.
1034 if ((flags & G_FLAG_VERBOSE) != 0)
1035 printf("Module available.\n");
1039 std_unload_available(void)
1044 snprintf(name, sizeof(name), "geom_%s", class_name);
1052 std_unload(struct gctl_req *req, unsigned flags __unused)
1057 snprintf(name, sizeof(name), "geom_%s", class_name);
1060 gctl_error(req, "Could not find module: %s.", strerror(errno));
1063 if (kldunload(id) < 0) {
1064 gctl_error(req, "Could not unload module: %s.",
1071 std_available(const char *name)
1074 if (strcmp(name, "help") == 0)
1076 else if (strcmp(name, "list") == 0)
1077 return (std_list_available());
1078 else if (strcmp(name, "status") == 0)
1079 return (std_status_available());
1080 else if (strcmp(name, "load") == 0)
1081 return (std_load_available());
1082 else if (strcmp(name, "unload") == 0)
1083 return (std_unload_available());
1085 assert(!"Unknown standard command.");