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 */
39 * devattr() Get the value of a attribute for a specific device
44 * <sys/types.h> System Data Types
45 * <stdio.h> Standard I/O Definitions
46 * <errno.h> Error-value definitions
47 * <string.h> String function and constant definitions
48 * <devmgmt.h> Device table definitions available to the world
49 * "devtab.h" Local device table definitions
52 #include <sys/types.h>
61 * Local constant definitions
70 * char *devattr(device, attr)
72 * This function searches the device table, looking for the device
73 * specified by <device>. If it finds a record corresponding to that
74 * device (see below for a definition of that correspondence), it
75 * extracts the value of the field <attr> from that record, if any.
76 * It returns a pointer to that value, or (char *) NULL if none.
79 * device Pointer to the character-string that describes the
80 * device whose record is to be looked for
81 * attr The device's attribute to be looked for
84 * A pointer to the character-string containing the value of the
85 * attribute <attr> for the device <device>, or (char *) NULL if none
86 * was found. If the function returns (char *) NULL and the error was
87 * detected by this function, it sets "errno" to indicate the problem.
90 * EPERM Permissions deny reading access of the device-table
92 * ENOENT The specified device-table file could not be found
93 * ENODEV Device not found in the device table
94 * EINVAL The device does not have that attribute defined
95 * ENOMEM No memory available
100 char *device
, /* The device ) we're to look for */
101 char *attribute
) /* The attribute to extract */
104 struct devtabent
*record
; /* Retrieved record */
105 struct attrval
*p
; /* attr/val records */
106 char *val
; /* Extracted value */
107 char *rtnval
; /* Value to return */
108 int found
; /* TRUE if attribute found */
111 /* Get the record for the specified device */
112 if (!(record
= _getdevrec(device
))) {
117 /* Search the record for the specified attribute */
120 /* Did they ask for the device alias? */
121 if (strcmp(attribute
, DTAB_ALIAS
) == 0) {
122 val
= (record
->alias
!= NULL
) ? record
->alias
: "";
126 /* Did they ask for the character-special device? */
127 else if (strcmp(attribute
, DTAB_CDEVICE
) == 0) {
128 val
= (record
->cdevice
!= NULL
) ? record
->cdevice
: "";
132 /* Did they ask for the block-special device? */
133 else if (strcmp(attribute
, DTAB_BDEVICE
) == 0) {
134 val
= (record
->bdevice
!= NULL
) ? record
->bdevice
: "";
138 /* Did they ask for the pathname? */
139 else if (strcmp(attribute
, DTAB_PATHNAME
) == 0) {
140 val
= (record
->pathname
!= NULL
) ? record
->pathname
: "";
147 * Didn't ask for one of the easy ones, search the attr/val
151 p
= record
->attrlist
;
152 while (!found
&& (p
)) {
153 if (strcmp(p
->attr
, attribute
) == 0) {
161 * If the attribute was found, copy it into malloc()ed space.
162 * If not, set errno appropriately; we'll return NULL
166 if (rtnval
= malloc(strlen(val
)+1))
167 (void) strcpy(rtnval
, val
);
174 /* Free the space allocated to the struct devtabent structure */
175 _freedevtabent(record
);