4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #define VERSION_STRING_MAX_LEN 10
33 * MAJOR - This should only change when there is an incompatible change made
34 * to the interfaces or the output.
36 * MINOR - This should change whenever there is a new command or new feature
37 * with no incompatible change.
39 #define VERSION_STRING_MAJOR "1"
40 #define VERSION_STRING_MINOR "0"
45 /* forward declarations */
46 static int listHbaFunc(int, char **, cmdOptions_t
*, void *);
47 static int listHbaPortFunc(int, char **, cmdOptions_t
*, void *);
48 static int listExpanderFunc(int, char **, cmdOptions_t
*, void *);
49 static int listTargetPortFunc(int, char **, cmdOptions_t
*, void *);
50 static int listLogicalUnitFunc(int, char **, cmdOptions_t
*, void *);
51 static char *getExecBasename(char *);
54 * Add new options here
56 * Optional option-arguments are not allowed by CLIP
58 optionTbl_t sasinfolongOptions
[] = {
59 {"hba", required_argument
, 'a', "HBA Name"},
60 {"hba-port", required_argument
, 'p', "HBA Port Name"},
61 {"phy", no_argument
, 'y', NULL
},
62 {"phy-linkstat", no_argument
, 'l', NULL
},
63 {"scsi-target", no_argument
, 's', NULL
},
64 {"verbose", no_argument
, 'v', NULL
},
65 {"target", no_argument
, 't', NULL
},
70 * Add new subcommands here
72 subCommandProps_t sasinfosubcommands
[] = {
73 {"hba", listHbaFunc
, "v", NULL
, NULL
,
74 OPERAND_OPTIONAL_MULTIPLE
, "HBA Name"},
75 {"hba-port", listHbaPortFunc
, "ylva", NULL
, NULL
,
76 OPERAND_OPTIONAL_MULTIPLE
, "HBA Port Name"},
77 {"expander", listExpanderFunc
, "ptv", NULL
, NULL
,
78 OPERAND_OPTIONAL_MULTIPLE
, "Expander Device SAS Address"},
79 {"target-port", listTargetPortFunc
, "sv", NULL
, "sv",
80 OPERAND_OPTIONAL_MULTIPLE
, "Target Port SAS Address"},
81 {"logical-unit", listLogicalUnitFunc
, "v", NULL
, NULL
,
82 OPERAND_OPTIONAL_MULTIPLE
, "OS Device Name"},
83 {"lu", listLogicalUnitFunc
, "v", NULL
, NULL
,
84 OPERAND_OPTIONAL_MULTIPLE
, "OS Device Name"},
85 {NULL
, 0, NULL
, NULL
, NULL
, 0, NULL
, NULL
}
89 * Pass in options/arguments, rest of arguments
93 listHbaFunc(int objects
, char *argv
[], cmdOptions_t
*options
, void *addArgs
)
95 return (sas_util_list_hba(objects
, argv
, options
));
100 listHbaPortFunc(int objects
, char *argv
[], cmdOptions_t
*options
, void *addArgs
)
102 return (sas_util_list_hbaport(objects
, argv
, options
));
106 * Pass in options/arguments, rest of arguments
110 listExpanderFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
113 return (sas_util_list_expander(objects
, argv
, options
));
118 listTargetPortFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
121 return (sas_util_list_targetport(objects
, argv
, options
));
125 * Pass in options/arguments, rest of arguments
129 listLogicalUnitFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
132 return (sas_util_list_logicalunit(objects
, argv
, options
));
137 * execFullName - exec name of program (argv[0])
140 * command name portion of execFullName
143 getExecBasename(char *execFullname
)
145 char *lastSlash
, *execBasename
;
147 /* guard against '/' at end of command invocation */
149 lastSlash
= strrchr(execFullname
, '/');
150 if (lastSlash
== NULL
) {
151 execBasename
= execFullname
;
154 execBasename
= lastSlash
+ 1;
155 if (*execBasename
== '\0') {
162 return (execBasename
);
166 * main calls a parser that checks syntax of the input command against
167 * various rules tables.
169 * The return value from the function is placed in funcRet
172 main(int argc
, char *argv
[])
174 synTables_t synTables
;
175 char versionString
[VERSION_STRING_MAX_LEN
];
178 void *subcommandArgs
= NULL
;
180 /* to support locale */
181 (void) setlocale(LC_ALL
, "");
182 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
183 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
185 (void) textdomain(TEXT_DOMAIN
);
187 /* set global command name */
188 cmdName
= getExecBasename(argv
[0]);
190 /* check if is global zone */
191 if (getzoneid() != GLOBAL_ZONEID
) {
192 (void *) fprintf(stdout
, "%s %s\n",
193 cmdName
, gettext("does not support non-global zone."));
197 (void *) snprintf(versionString
, sizeof (versionString
), "%s.%s",
198 VERSION_STRING_MAJOR
, VERSION_STRING_MINOR
);
199 synTables
.versionString
= versionString
;
201 synTables
.longOptionTbl
= &sasinfolongOptions
[0];
202 synTables
.subCommandPropsTbl
= &sasinfosubcommands
[0];
204 /* call the CLI parser */
205 ret
= cmdParse(argc
, argv
, synTables
, subcommandArgs
, &funcRet
);
207 (void *) fprintf(stdout
, "%s %s(1M)\n",
208 gettext("For more information, please see"), cmdName
);
210 } else if (ret
== -1) {
211 (void *) fprintf(stderr
, "%s %s\n",
212 cmdName
, strerror(errno
));