ilbadm_status_t ilbadm_add_server_to_group(int argc, char **argv) { ilb_handle_t h = ILB_INVALID_HANDLE; ilb_status_t rclib = ILB_STATUS_OK; ilbadm_status_t rc = ILBADM_OK; ilbadm_sgroup_t *sg; int c; int flags = 0; i_ilbadm_alloc_sgroup(&sg); while ((c = getopt(argc, argv, ":s:")) != -1) { switch ((char)c) { case 's': rc = i_parse_servrange_list(optarg, sg); break; case ':': ilbadm_err(gettext("missing option-argument for" " %c"), (char)optopt); rc = ILBADM_LIBERR; break; case '?': default: unknown_opt(argv, optind-1); /* not reached */ break; } if (rc != ILBADM_OK) goto out; } if (optind >= argc) { ilbadm_err(gettext("missing mandatory arguments - please refer" " to 'add-server' subcommand description in ilbadm(1M)")); rc = ILBADM_LIBERR; goto out; } sg->sg_name = argv[optind]; rclib = ilb_open(&h); if (rclib != ILB_STATUS_OK) goto out; /* A server is added enabled */ ILB_SET_ENABLED(flags); rc = i_mod_sg(h, sg, cmd_add_srv, flags); out: i_ilbadm_free_sgroup(sg); if (h != ILB_INVALID_HANDLE) (void) ilb_close(h); if ((rc != ILBADM_OK) && (rc != ILBADM_LIBERR)) ilbadm_err(ilbadm_errstr(rc)); return (rc); }
/* ARGSUSED */ ilbadm_status_t ilbadm_rem_server_from_group(int argc, char *argv[]) { ilb_handle_t h = ILB_INVALID_HANDLE; ilb_status_t rclib = ILB_STATUS_OK; ilbadm_status_t rc = ILBADM_OK; ilbadm_sgroup_t *sg; int c; i_ilbadm_alloc_sgroup(&sg); while ((c = getopt(argc, argv, ":s:")) != -1) { switch ((char)c) { case 's': rc = i_parse_serverIDs(optarg, sg); break; case ':': ilbadm_err(gettext("missing option-argument for" " %c"), (char)optopt); rc = ILBADM_LIBERR; break; case '?': default: unknown_opt(argv, optind-1); /* not reached */ break; } if (rc != ILBADM_OK) goto out; } /* we need servergroup name and at least one serverID to remove */ if (optind >= argc || sg->sg_count == 0) { rc = ILBADM_ENOOPTION; goto out; } sg->sg_name = argv[optind]; rclib = ilb_open(&h); if (rclib != ILB_STATUS_OK) goto out; rc = i_mod_sg(h, sg, cmd_rem_srv, 0); out: i_ilbadm_free_sgroup(sg); if (h != ILB_INVALID_HANDLE) (void) ilb_close(h); if ((rc != ILBADM_OK) && (rc != ILBADM_LIBERR)) ilbadm_err(ilbadm_errstr(rc)); return (rc); }
int main (int argc, char **argv) { int vol = VOL_DFLT, nsectors = NSECTORS_DFLT, firstcylinder = FIRST_CYLINDER_DFLT, firstsector = FIRST_SECTOR_DFLT; int i, c; cmdname = argv[0]; opterr = 0; init_mbr(); while ((c = getopt(argc, argv, "l:c:s:v:")) != -1) { switch (c) { case 'l': nsectors = atol(optarg); break; case 'c': firstcylinder = atol(optarg); break; case 's': firstsector = atol(optarg); break; case 'v': vol = atol(optarg); break; case '?': /* missing option argument */ if (optopt == 'l' || optopt == 'c' || optopt == 's') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); usage(); } else unknown_opt(optopt); default: unknown_opt(c); } } printf("b\n"); struct vol_descr_s vol_desc; for(i=0;i<vol;i++){ vol_desc.vol_cylinder=firstcylinder; vol_desc.vol_sector=firstsector; vol_desc.vol_nsector=nsectors; vol_desc.vol_voltype=VT_BASE; mbr.mbr_vols[i]= vol_desc; } mbr.mbr_magic=0xA5E; mbr.mbr_nbvol=vol; if (optind != argc) { fprintf(stderr, "Argument(s): "); for (i = optind; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "ignored.\n"); usage(); } save_mbr(); save_mbr(); printf("mkvol(vol=%d, nsectors=%d, firstcylinder=%d, firstsector=%d)\n", vol, nsectors, firstcylinder, firstsector); exit(EXIT_SUCCESS); }
ilbadm_status_t ilbadm_create_servergroup(int argc, char *argv[]) { ilb_handle_t h = ILB_INVALID_HANDLE; ilb_status_t rclib = ILB_STATUS_OK; ilbadm_status_t rc = ILBADM_OK; ilbadm_sgroup_t *sg; int c; int flags = 0; i_ilbadm_alloc_sgroup(&sg); while ((c = getopt(argc, argv, ":s:")) != -1) { switch ((char)c) { case 's': rc = i_parse_servrange_list(optarg, sg); break; case ':': ilbadm_err(gettext("missing option-argument for" " %c"), (char)optopt); rc = ILBADM_LIBERR; break; case '?': default: unknown_opt(argv, optind-1); /* not reached */ break; } if (rc != ILBADM_OK) goto out; } if (optind >= argc) { ilbadm_err(gettext("missing mandatory arguments - please refer" " to 'create-servergroup' subcommand" " description in ilbadm(1M)")); rc = ILBADM_LIBERR; goto out; } if (strlen(argv[optind]) > ILB_SGNAME_SZ - 1) { ilbadm_err(gettext("servergroup name %s is too long -" " must not exceed %d chars"), argv[optind], ILB_SGNAME_SZ - 1); rc = ILBADM_LIBERR; goto out; } sg->sg_name = argv[optind]; rclib = ilb_open(&h); if (rclib != ILB_STATUS_OK) goto out; rclib = ilb_create_servergroup(h, sg->sg_name); if (rclib != ILB_STATUS_OK) goto out; /* we create a servergroup with all servers enabled */ ILB_SET_ENABLED(flags); rc = i_mod_sg(h, sg, cmd_create_sg, flags); if (rc != ILBADM_OK) (void) ilb_destroy_servergroup(h, sg->sg_name); out: i_ilbadm_free_sgroup(sg); if (h != ILB_INVALID_HANDLE) (void) ilb_close(h); if (rclib != ILB_STATUS_OK) { ilbadm_err(ilb_errstr(rclib)); rc = ILBADM_LIBERR; } if ((rc != ILBADM_OK) && (rc != ILBADM_LIBERR)) ilbadm_err(ilbadm_errstr(rc)); return (rc); }
/* ARGSUSED */ ilbadm_status_t ilbadm_show_servergroups(int argc, char *argv[]) { ilb_handle_t h = ILB_INVALID_HANDLE; ilb_status_t rclib = ILB_STATUS_OK; ilbadm_status_t rc = ILBADM_OK; int c; char optstr[] = ":po:"; boolean_t o_opt = B_FALSE, p_opt = B_FALSE; list_arg_t larg = {0, def_fields, NULL, NULL}; while ((c = getopt(argc, argv, optstr)) != -1) { switch ((char)c) { case 'p': p_opt = B_TRUE; larg.flags |= ILBADM_LIST_PARSE; break; case 'o': larg.o_str = optarg; o_opt = B_TRUE; break; case ':': ilbadm_err(gettext("missing option argument" " for %c"), (char)optopt); rc = ILBADM_LIBERR; goto out; default: unknown_opt(argv, optind-1); /* not reached */ break; } } if (p_opt && !o_opt) { ilbadm_err(gettext("option -p requires -o")); exit(1); } if (p_opt && larg.o_str != NULL && (strcasecmp(larg.o_str, "all") == 0)) { ilbadm_err(gettext("option -p requires explicit field" " names for -o")); exit(1); } rclib = ilb_open(&h); if (rclib != ILB_STATUS_OK) goto out; if (optind >= argc) { rclib = ilb_walk_servergroups(h, ilbadm_list_sg, NULL, (void*)&larg); if (rclib != ILB_STATUS_OK) rc = ILBADM_LIBERR; } else { while (optind < argc) { rclib = ilb_walk_servergroups(h, ilbadm_list_sg, argv[optind++], (void*)&larg); if (rclib != ILB_STATUS_OK) { rc = ILBADM_LIBERR; break; } } } if (larg.oh != NULL) ofmt_close(larg.oh); out: if (h != ILB_INVALID_HANDLE) (void) ilb_close(h); if (rclib != ILB_STATUS_OK) { /* * The show function returns ILB_STATUS_GENERIC after printing * out an error message. So we don't need to print it again. */ if (rclib != ILB_STATUS_GENERIC) ilbadm_err(ilb_errstr(rclib)); rc = ILBADM_LIBERR; } return (rc); }