4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
38 * listdev() List attributes defined for a device
42 * Header files needed:
43 * <sys/types.h> System Data Types
44 * <string.h> Standard string definitions
45 * <devmgmt.h> Device management definitions
46 * "devtab.h" Local device table definitions
49 #include <sys/types.h>
68 * This function sorts a list of character strings
69 * so that the list is ordered alphabetically.
72 * list The list to be sorted
78 sortlist(char **list
) /* List to be sorted */
80 char **pp
; /* Pointer to item being sorted */
83 char *t
; /* Temp for swapping pointers */
85 /* If the list isn't empty ... */
88 /* Find the last item in the list */
89 for (pp
= list
; *pp
; pp
++)
94 * Sort 'em by sorting larger and larger portions
95 * of the list (my CSC101 fails me, I forget what
96 * this sort is called!) [Where I come from, CS
103 while (*qq
&& (strcmp(*rr
, *qq
) > 0)) {
113 * char **listdev(device)
116 * Generate an alphabetized list of attribute names of the
117 * attributes defined for the device <device>.
120 * device Device who's attributes are to be listed
123 * List of attribute names of the attributes defined for this
124 * device. (Never empty since all devices have the "alias"
125 * attribute defined.)
129 listdev(char *device
) /* Device to describe */
133 struct devtabent
*devtabent
; /* Ptr to devtab entry */
134 struct attrval
*attrval
; /* Ptr to attr val pair */
135 char **list
; /* Ptr to alloc'd list */
136 char **rtnval
; /* Value to return */
137 char **pp
; /* Ptr to current val in list */
138 int noerror
; /* FLAG, TRUE if :-) */
139 int n
; /* Temp counter */
142 /* If the device <device> is defined ... */
143 if (devtabent
= _getdevrec(device
)) {
146 * Count the number of attributes defined for the device
147 * being sure to count the (char *) NULL that terminates
152 if (devtabent
->alias
) n
++; /* Alias, if defined */
153 if (devtabent
->cdevice
) n
++; /* Char spcl, if defined */
154 if (devtabent
->bdevice
) n
++; /* Blk spcl, if defined */
155 if (devtabent
->pathname
) n
++; /* Pathname, if defined */
157 /* Other attributes, if any */
158 if ((attrval
= devtabent
->attrlist
) != NULL
) {
161 while ((attrval
= attrval
->next
) != NULL
);
164 if (list
= malloc(n
*sizeof (char *))) {
166 if (devtabent
->alias
) {
167 if (*pp
= malloc(strlen(DTAB_ALIAS
)+1))
168 (void) strcpy(*pp
++, DTAB_ALIAS
);
169 else noerror
= FALSE
;
171 if (noerror
&& devtabent
->bdevice
) {
172 if (*pp
= malloc(strlen(DTAB_BDEVICE
)+1))
174 (void) strcpy(*pp
++, DTAB_BDEVICE
);
175 else noerror
= FALSE
;
177 if (noerror
&& devtabent
->cdevice
) {
178 if (*pp
= malloc(strlen(DTAB_CDEVICE
)+1))
180 (void) strcpy(*pp
++, DTAB_CDEVICE
);
181 else noerror
= FALSE
;
183 if (noerror
&& devtabent
->pathname
) {
184 if (*pp
= malloc(strlen(DTAB_PATHNAME
)+1))
186 (void) strcpy(*pp
++, DTAB_PATHNAME
);
187 else noerror
= FALSE
;
189 if (noerror
&& (attrval
= devtabent
->attrlist
)) {
191 if (*pp
= malloc(strlen(attrval
->attr
)+1))
193 (void) strcpy(*pp
++, attrval
->attr
);
194 else noerror
= FALSE
;
195 } while (noerror
&& (attrval
= attrval
->next
));
202 for (pp
= list
; *pp
; pp
++) free(*pp
);
206 } else rtnval
= NULL
;
207 } else rtnval
= NULL
;