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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Interfaces for getting device configuration data from kernel
31 * through the devinfo driver.
41 #include <sys/types.h>
45 #include "libdevinfo.h"
47 /* Function Prototypes */
48 static int di_dli_open(char *, int, short, int);
53 * Private hotplug interfaces to be used between cfgadm pci plugin and
54 * devfsadm link generator.
59 * returns a devlink info file name derived from <path>
60 * callers need to free the returned string
63 di_dli_name(char *path
)
65 #define dliroot "/etc/devices/dli/info."
66 #define dliroot_len (sizeof (dliroot) - 1)
72 basep
= basename(path
);
73 dlipathsz
= strlen(basep
) + dliroot_len
+ 1;
74 dlipath
= malloc(sizeof (char) * dlipathsz
);
76 (void) snprintf(dlipath
, dlipathsz
, "%s%s", dliroot
, basep
);
77 dlipath
[dlipathsz
- 1] = '\0';
88 di_dli_open(char *path
, int oflag
, short l_type
, int flags
)
91 char *dlipath
, *dlipath_dir
, *dlipath_dup
;
93 int mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
;
96 dlipath
= (flags
& DLI_NAME
) ? di_dli_name(path
) : (char *)path
;
97 dlipath_dup
= strdup(dlipath
);
98 dlipath_dir
= dirname(dlipath_dup
);
100 if (stat(dlipath_dir
, &statbuf
) < 0) {
101 if (mkdirp(dlipath_dir
,
102 S_IRWXU
| S_IRGRP
| S_IXGRP
| S_IROTH
| S_IXOTH
) < 0) {
108 fd
= open(dlipath
, oflag
, mode
);
112 if (fchmod(fd
, mode
) < 0) {
118 bzero(&lock
, sizeof (lock
));
119 lock
.l_type
= l_type
;
120 if (fcntl(fd
, F_SETLKW
, &lock
) < 0) {
126 if (flags
& DLI_NAME
)
133 di_dli_openr(char *path
)
135 return (di_dli_open(path
, O_RDONLY
, F_RDLCK
, DLI_NAME
));
140 di_dli_openw(char *path
)
142 return (di_dli_open(path
, O_RDWR
| O_SYNC
| O_TRUNC
| O_CREAT
,
154 bzero(&lock
, sizeof (lock
));
155 lock
.l_type
= F_UNLCK
;
156 (void) fcntl(fd
, F_SETLK
, &lock
);