geom.c (af565b58fabdfdefea4fcbfdaab7971ef659be2b) | geom.c (1d723f1d518b79fdea655f82e5419ae4888ad78c) |
---|---|
1/*- 2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 534 unchanged lines hidden (view full) --- 543 544 LIST_FOREACH(classp, &mesh->lg_class, lg_class) { 545 if (strcmp(classp->lg_name, name) == 0) 546 return (classp); 547 } 548 return (NULL); 549} 550 | 1/*- 2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 534 unchanged lines hidden (view full) --- 543 544 LIST_FOREACH(classp, &mesh->lg_class, lg_class) { 545 if (strcmp(classp->lg_name, name) == 0) 546 return (classp); 547 } 548 return (NULL); 549} 550 |
551static struct gprovider * 552find_provider(struct gclass *classp, const char *name) | 551static struct ggeom * 552find_geom(struct gclass *classp, const char *name) |
553{ 554 struct ggeom *gp; | 553{ 554 struct ggeom *gp; |
555 struct gprovider *pp; | |
556 557 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { | 555 556 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { |
558 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 559 if (strcmp(pp->lg_name, name) == 0) 560 return (pp); 561 } | 557 if (strcmp(gp->lg_name, name) == 0) 558 return (gp); |
562 } 563 return (NULL); 564} 565 | 559 } 560 return (NULL); 561} 562 |
566static char * 567genspaces(const char *text, size_t len) | 563static void 564show_one_provider(struct gprovider *pp, const char *prefix) |
568{ | 565{ |
569 static char spaces[256]; 570 size_t outlen; | 566 struct gconfig *conf; 567 char buf[5]; |
571 | 568 |
572 if (strlen(text) >= len) { 573 spaces[0] = '\0'; 574 return (spaces); | 569 printf("Name: %s\n", pp->lg_name); 570 humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "", 571 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); 572 printf("%sMediasize: %jd (%s)\n", prefix, (intmax_t)pp->lg_mediasize, 573 buf); 574 printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize); 575 printf("%sMode: %s\n", prefix, pp->lg_mode); 576 LIST_FOREACH(conf, &pp->lg_config, lg_config) { 577 printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val); |
575 } | 578 } |
576 memset(spaces, ' ', sizeof(spaces)); 577 outlen = len - strlen(text); 578 if (outlen >= sizeof(spaces)) { 579 spaces[sizeof(spaces) - 1] = '\0'; 580 return (spaces); | 579} 580 581static void 582show_one_consumer(struct gconsumer *cp, const char *prefix) 583{ 584 struct gprovider *pp; 585 struct gconfig *conf; 586 587 pp = cp->lg_provider; 588 if (pp == NULL) 589 printf("[no provider]\n"); 590 else { 591 char buf[5]; 592 593 printf("Name: %s\n", pp->lg_name); 594 humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "", 595 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); 596 printf("%sMediasize: %jd (%s)\n", prefix, 597 (intmax_t)pp->lg_mediasize, buf); 598 printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize); 599 printf("%sMode: %s\n", prefix, cp->lg_mode); |
581 } | 600 } |
582 spaces[outlen] = '\0'; 583 return (spaces); | 601 LIST_FOREACH(conf, &cp->lg_config, lg_config) { 602 printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val); 603 } |
584} 585 586static void | 604} 605 606static void |
587show_one(struct gprovider *pp) | 607show_one_geom(struct ggeom *gp) |
588{ | 608{ |
609 struct gprovider *pp; 610 struct gconsumer *cp; |
|
589 struct gconfig *conf; | 611 struct gconfig *conf; |
590 char buf[5]; | 612 unsigned n; |
591 | 613 |
592 printf(" NAME: %s\n", pp->lg_name); 593 printf(" geom name: %s\n", pp->lg_geom->lg_name); 594 humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "", 595 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); 596 printf(" mediasize: %jd (%s)\n", (intmax_t)pp->lg_mediasize, buf); 597 printf(" sectorsize: %u\n", pp->lg_sectorsize); 598 printf(" mode: %s\n", pp->lg_mode); 599 LIST_FOREACH(conf, &pp->lg_config, lg_config) { 600 printf("%s%s: %s\n", genspaces(conf->lg_name, 11), 601 conf->lg_name, conf->lg_val); | 614 printf("Geom name: %s\n", gp->lg_name); 615 LIST_FOREACH(conf, &gp->lg_config, lg_config) { 616 printf("%s: %s\n", conf->lg_name, conf->lg_val); |
602 } | 617 } |
618 if (!LIST_EMPTY(&gp->lg_provider)) { 619 printf("Providers:\n"); 620 n = 1; 621 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 622 printf("%u. ", n++); 623 show_one_provider(pp, " "); 624 } 625 } 626 if (!LIST_EMPTY(&gp->lg_consumer)) { 627 printf("Consumers:\n"); 628 n = 1; 629 LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) { 630 printf("%u. ", n++); 631 show_one_consumer(cp, " "); 632 } 633 } |
|
603 printf("\n"); 604} 605 606static void 607std_help(struct gctl_req *req __unused, unsigned flags __unused) 608{ 609 610 geom_usage(); --- 16 unchanged lines hidden (view full) --- 627 return (0); 628} 629 630static void 631std_list(struct gctl_req *req, unsigned flags __unused) 632{ 633 struct gmesh mesh; 634 struct gclass *classp; | 634 printf("\n"); 635} 636 637static void 638std_help(struct gctl_req *req __unused, unsigned flags __unused) 639{ 640 641 geom_usage(); --- 16 unchanged lines hidden (view full) --- 658 return (0); 659} 660 661static void 662std_list(struct gctl_req *req, unsigned flags __unused) 663{ 664 struct gmesh mesh; 665 struct gclass *classp; |
635 struct gprovider *pp; | 666 struct ggeom *gp; |
636 int error, *nargs; 637 638 error = geom_gettree(&mesh); 639 if (error != 0) 640 exit(EXIT_FAILURE); 641 classp = find_class(&mesh, gclass_name); 642 if (classp == NULL) { 643 geom_deletetree(&mesh); --- 11 unchanged lines hidden (view full) --- 655 656 for (i = 0; i < *nargs; i++) { 657 const char *name; 658 char param[16]; 659 660 snprintf(param, sizeof(param), "arg%d", i); 661 name = gctl_get_asciiparam(req, param); 662 assert(name != NULL); | 667 int error, *nargs; 668 669 error = geom_gettree(&mesh); 670 if (error != 0) 671 exit(EXIT_FAILURE); 672 classp = find_class(&mesh, gclass_name); 673 if (classp == NULL) { 674 geom_deletetree(&mesh); --- 11 unchanged lines hidden (view full) --- 686 687 for (i = 0; i < *nargs; i++) { 688 const char *name; 689 char param[16]; 690 691 snprintf(param, sizeof(param), "arg%d", i); 692 name = gctl_get_asciiparam(req, param); 693 assert(name != NULL); |
663 pp = find_provider(classp, name); 664 if (pp != NULL) 665 show_one(pp); 666 else { 667 fprintf(stderr, "No such provider: %s.\n", 668 name); 669 } | 694 gp = find_geom(classp, name); 695 if (gp != NULL) 696 show_one_geom(gp); 697 else 698 fprintf(stderr, "No such geom: %s.\n", name); |
670 } 671 } else { | 699 } 700 } else { |
672 struct ggeom *gp; 673 | |
674 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { | 701 LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { |
675 LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { 676 show_one(pp); 677 } | 702 show_one_geom(gp); |
678 } 679 } 680 geom_deletetree(&mesh); 681} 682 683static int 684std_load_available(void) 685{ --- 85 unchanged lines hidden --- | 703 } 704 } 705 geom_deletetree(&mesh); 706} 707 708static int 709std_load_available(void) 710{ --- 85 unchanged lines hidden --- |