geom.c (0f73f7016baa6015b1b0b582033af2f1c7760af5) | geom.c (6a02738229be1d312f4e4af22d64e662a2084eee) |
---|---|
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 --- 52 unchanged lines hidden (view full) --- 61extern struct g_command glabel_class_commands[]; 62#endif 63 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 | 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 --- 52 unchanged lines hidden (view full) --- 61extern struct g_command glabel_class_commands[]; 62#endif 63 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 | 69#define GEOM_CLASS_CMDS 0x01 70#define GEOM_STD_CMDS 0x02 71 72#define GEOM_CLASS_WIDTH 10 73 |
71static struct g_command *find_command(const char *cmdstr, int flags); 72static void list_one_geom_by_provider(const char *provider_name); 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); --- 65 unchanged lines hidden (view full) --- 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"); | 74static struct g_command *find_command(const char *cmdstr, int flags); 75static void list_one_geom_by_provider(const char *provider_name); 76static int std_available(const char *name); 77 78static void std_help(struct gctl_req *req, unsigned flags); 79static void std_list(struct gctl_req *req, unsigned flags); 80static void std_status(struct gctl_req *req, unsigned flags); 81static void std_load(struct gctl_req *req, unsigned flags); --- 65 unchanged lines hidden (view full) --- 147 148static void 149usage(void) 150{ 151 152 if (class_name == NULL) { 153 fprintf(stderr, "usage: geom <class> <command> [options]\n"); 154 fprintf(stderr, " geom -p <provider-name>\n"); |
155 fprintf(stderr, " geom -t\n"); |
|
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) { --- 507 unchanged lines hidden (view full) --- 667 return (gp); 668 } 669 } 670 } 671 672 return (NULL); 673} 674 | 156 exit(EXIT_FAILURE); 157 } else { 158 struct g_command *cmd; 159 const char *prefix; 160 unsigned i; 161 162 prefix = "usage:"; 163 if (class_commands != NULL) { --- 507 unchanged lines hidden (view full) --- 671 return (gp); 672 } 673 } 674 } 675 676 return (NULL); 677} 678 |
679static int 680compute_tree_width_geom(struct gmesh *mesh, struct ggeom *gp, int indent) 681{ 682 struct gclass *classp2; 683 struct ggeom *gp2; 684 struct gconsumer *cp2; 685 struct gprovider *pp; 686 int max_width, width; 687 688 max_width = width = indent + strlen(gp->lg_name); 689 690 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 691 LIST_FOREACH(classp2, &mesh->lg_class, lg_class) { 692 LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) { 693 LIST_FOREACH(cp2, 694 &gp2->lg_consumer, lg_consumer) { 695 if (pp != cp2->lg_provider) 696 continue; 697 width = compute_tree_width_geom(mesh, 698 gp2, indent + 2); 699 if (width > max_width) 700 max_width = width; 701 } 702 } 703 } 704 } 705 706 return (max_width); 707} 708 709static int 710compute_tree_width(struct gmesh *mesh) 711{ 712 struct gclass *classp; 713 struct ggeom *gp; 714 int max_width, width; 715 716 max_width = width = 0; 717 718 LIST_FOREACH(classp, &mesh->lg_class, lg_class) { 719 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { 720 if (!LIST_EMPTY(&gp->lg_consumer)) 721 continue; 722 width = compute_tree_width_geom(mesh, gp, 0); 723 if (width > max_width) 724 max_width = width; 725 } 726 } 727 728 return (max_width); 729} 730 731static void 732show_tree_geom(struct gmesh *mesh, struct ggeom *gp, int indent, int width) 733{ 734 struct gclass *classp2; 735 struct ggeom *gp2; 736 struct gconsumer *cp2; 737 struct gprovider *pp; 738 739 if (LIST_EMPTY(&gp->lg_provider)) { 740 printf("%*s%-*.*s %-*.*s\n", indent, "", 741 width - indent, width - indent, gp->lg_name, 742 GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name); 743 return; 744 } 745 746 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 747 printf("%*s%-*.*s %-*.*s %s\n", indent, "", 748 width - indent, width - indent, gp->lg_name, 749 GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, gp->lg_class->lg_name, 750 pp->lg_name); 751 752 LIST_FOREACH(classp2, &mesh->lg_class, lg_class) { 753 LIST_FOREACH(gp2, &classp2->lg_geom, lg_geom) { 754 LIST_FOREACH(cp2, 755 &gp2->lg_consumer, lg_consumer) { 756 if (pp != cp2->lg_provider) 757 continue; 758 show_tree_geom(mesh, gp2, 759 indent + 2, width); 760 } 761 } 762 } 763 } 764} 765 766static void 767show_tree(void) 768{ 769 struct gmesh mesh; 770 struct gclass *classp; 771 struct ggeom *gp; 772 int error, width; 773 774 error = geom_gettree(&mesh); 775 if (error != 0) 776 errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); 777 778 width = compute_tree_width(&mesh); 779 780 printf("%-*.*s %-*.*s %s\n", 781 width, width, "Geom", 782 GEOM_CLASS_WIDTH, GEOM_CLASS_WIDTH, "Class", 783 "Provider"); 784 785 LIST_FOREACH(classp, &mesh.lg_class, lg_class) { 786 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { 787 if (!LIST_EMPTY(&gp->lg_consumer)) 788 continue; 789 show_tree_geom(&mesh, gp, 0, width); 790 } 791 } 792} 793 |
|
675int 676main(int argc, char *argv[]) 677{ 678 char *provider_name; | 794int 795main(int argc, char *argv[]) 796{ 797 char *provider_name; |
798 bool tflag; |
|
679 int ch; 680 681 provider_name = NULL; | 799 int ch; 800 801 provider_name = NULL; |
802 tflag = false; |
|
682 683 if (strcmp(getprogname(), "geom") == 0) { | 803 804 if (strcmp(getprogname(), "geom") == 0) { |
684 while ((ch = getopt(argc, argv, "hp:")) != -1) { | 805 while ((ch = getopt(argc, argv, "hp:t")) != -1) { |
685 switch (ch) { 686 case 'p': 687 provider_name = strdup(optarg); 688 if (provider_name == NULL) 689 err(1, "strdup"); 690 break; | 806 switch (ch) { 807 case 'p': 808 provider_name = strdup(optarg); 809 if (provider_name == NULL) 810 err(1, "strdup"); 811 break; |
812 case 't': 813 tflag = true; 814 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 | 815 case 'h': 816 default: 817 usage(); 818 } 819 } 820 821 /* 822 * Don't adjust argc and argv, it would break get_class(). 823 */ 824 } 825 |
826 if (tflag && provider_name != NULL) { 827 errx(EXIT_FAILURE, 828 "At most one of -P and -t may be specified."); 829 } 830 |
|
702 if (provider_name != NULL) { 703 list_one_geom_by_provider(provider_name); 704 return (0); 705 } 706 | 831 if (provider_name != NULL) { 832 list_one_geom_by_provider(provider_name); 833 return (0); 834 } 835 |
836 if (tflag) { 837 show_tree(); 838 return (0); 839 } 840 |
|
707 get_class(&argc, &argv); 708 run_command(argc, argv); 709 /* NOTREACHED */ 710 711 exit(EXIT_FAILURE); 712} 713 714static struct gclass * --- 544 unchanged lines hidden --- | 841 get_class(&argc, &argv); 842 run_command(argc, argv); 843 /* NOTREACHED */ 844 845 exit(EXIT_FAILURE); 846} 847 848static struct gclass * --- 544 unchanged lines hidden --- |