geom.c (3af64f03119a159ac15eb75b92d346705b490385) | geom.c (0f73f7016baa6015b1b0b582033af2f1c7760af5) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 26 unchanged lines hidden (view full) --- 35#include <sys/stat.h> 36#include <sys/sysctl.h> 37#include <ctype.h> 38#include <err.h> 39#include <errno.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <stdarg.h> | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 26 unchanged lines hidden (view full) --- 35#include <sys/stat.h> 36#include <sys/sysctl.h> 37#include <ctype.h> 38#include <err.h> 39#include <errno.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <stdarg.h> |
43#include <stdbool.h> |
|
43#include <stdint.h> 44#include <string.h> 45#include <unistd.h> 46#include <libgen.h> 47#include <libutil.h> 48#include <inttypes.h> 49#include <dlfcn.h> 50#include <assert.h> --- 12 unchanged lines hidden (view full) --- 63static char comm[MAXPATHLEN], *class_name = NULL, *gclass_name = NULL; 64static uint32_t *version = NULL; 65static int verbose = 0; 66static struct g_command *class_commands = NULL; 67 68#define GEOM_CLASS_CMDS 0x01 69#define GEOM_STD_CMDS 0x02 70static struct g_command *find_command(const char *cmdstr, int flags); | 44#include <stdint.h> 45#include <string.h> 46#include <unistd.h> 47#include <libgen.h> 48#include <libutil.h> 49#include <inttypes.h> 50#include <dlfcn.h> 51#include <assert.h> --- 12 unchanged lines hidden (view full) --- 64static char comm[MAXPATHLEN], *class_name = NULL, *gclass_name = NULL; 65static uint32_t *version = NULL; 66static int verbose = 0; 67static struct g_command *class_commands = NULL; 68 69#define GEOM_CLASS_CMDS 0x01 70#define GEOM_STD_CMDS 0x02 71static struct g_command *find_command(const char *cmdstr, int flags); |
72static void list_one_geom_by_provider(const char *provider_name); |
|
71static int std_available(const char *name); 72 73static void std_help(struct gctl_req *req, unsigned flags); 74static void std_list(struct gctl_req *req, unsigned flags); 75static void std_status(struct gctl_req *req, unsigned flags); 76static void std_load(struct gctl_req *req, unsigned flags); 77static void std_unload(struct gctl_req *req, unsigned flags); 78 --- 62 unchanged lines hidden (view full) --- 141} 142 143static void 144usage(void) 145{ 146 147 if (class_name == NULL) { 148 fprintf(stderr, "usage: geom <class> <command> [options]\n"); | 73static int std_available(const char *name); 74 75static void std_help(struct gctl_req *req, unsigned flags); 76static void std_list(struct gctl_req *req, unsigned flags); 77static void std_status(struct gctl_req *req, unsigned flags); 78static void std_load(struct gctl_req *req, unsigned flags); 79static void std_unload(struct gctl_req *req, unsigned flags); 80 --- 62 unchanged lines hidden (view full) --- 143} 144 145static void 146usage(void) 147{ 148 149 if (class_name == NULL) { 150 fprintf(stderr, "usage: geom <class> <command> [options]\n"); |
151 fprintf(stderr, " geom -p <provider-name>\n"); |
|
149 exit(EXIT_FAILURE); 150 } else { 151 struct g_command *cmd; 152 const char *prefix; 153 unsigned i; 154 155 prefix = "usage:"; 156 if (class_commands != NULL) { --- 488 unchanged lines hidden (view full) --- 645 /* If we can't load or list, it's not a class. */ 646 if (!std_available("load") && !std_available("list")) 647 errx(EXIT_FAILURE, "Invalid class name '%s'.", class_name); 648 649 if (*argc < 1) 650 usage(); 651} 652 | 152 exit(EXIT_FAILURE); 153 } else { 154 struct g_command *cmd; 155 const char *prefix; 156 unsigned i; 157 158 prefix = "usage:"; 159 if (class_commands != NULL) { --- 488 unchanged lines hidden (view full) --- 648 /* If we can't load or list, it's not a class. */ 649 if (!std_available("load") && !std_available("list")) 650 errx(EXIT_FAILURE, "Invalid class name '%s'.", class_name); 651 652 if (*argc < 1) 653 usage(); 654} 655 |
656static struct ggeom * 657find_geom_by_provider(struct gmesh *mesh, const char *name) 658{ 659 struct gclass *classp; 660 struct ggeom *gp; 661 struct gprovider *pp; 662 663 LIST_FOREACH(classp, &mesh->lg_class, lg_class) { 664 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { 665 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 666 if (strcmp(pp->lg_name, name) == 0) 667 return (gp); 668 } 669 } 670 } 671 672 return (NULL); 673} 674 |
|
653int 654main(int argc, char *argv[]) 655{ | 675int 676main(int argc, char *argv[]) 677{ |
678 char *provider_name; 679 int ch; |
|
656 | 680 |
681 provider_name = NULL; 682 683 if (strcmp(getprogname(), "geom") == 0) { 684 while ((ch = getopt(argc, argv, "hp:")) != -1) { 685 switch (ch) { 686 case 'p': 687 provider_name = strdup(optarg); 688 if (provider_name == NULL) 689 err(1, "strdup"); 690 break; 691 case 'h': 692 default: 693 usage(); 694 } 695 } 696 697 /* 698 * Don't adjust argc and argv, it would break get_class(). 699 */ 700 } 701 702 if (provider_name != NULL) { 703 list_one_geom_by_provider(provider_name); 704 return (0); 705 } 706 |
|
657 get_class(&argc, &argv); 658 run_command(argc, argv); 659 /* NOTREACHED */ 660 661 exit(EXIT_FAILURE); 662} 663 664static struct gclass * --- 98 unchanged lines hidden (view full) --- 763 printf("%u. ", n++); 764 list_one_consumer(cp, " "); 765 } 766 } 767 printf("\n"); 768} 769 770static void | 707 get_class(&argc, &argv); 708 run_command(argc, argv); 709 /* NOTREACHED */ 710 711 exit(EXIT_FAILURE); 712} 713 714static struct gclass * --- 98 unchanged lines hidden (view full) --- 813 printf("%u. ", n++); 814 list_one_consumer(cp, " "); 815 } 816 } 817 printf("\n"); 818} 819 820static void |
821list_one_geom_by_provider(const char *provider_name) 822{ 823 struct gmesh mesh; 824 struct ggeom *gp; 825 int error; 826 827 error = geom_gettree(&mesh); 828 if (error != 0) 829 errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); 830 831 gp = find_geom_by_provider(&mesh, provider_name); 832 if (gp == NULL) 833 errx(EXIT_FAILURE, "Cannot find provider '%s'.", provider_name); 834 835 printf("Geom class: %s\n", gp->lg_class->lg_name); 836 list_one_geom(gp); 837} 838 839static void |
|
771std_help(struct gctl_req *req __unused, unsigned flags __unused) 772{ 773 774 usage(); 775} 776 777static int 778std_list_available(void) --- 411 unchanged lines hidden --- | 840std_help(struct gctl_req *req __unused, unsigned flags __unused) 841{ 842 843 usage(); 844} 845 846static int 847std_list_available(void) --- 411 unchanged lines hidden --- |