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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 * Blacklist special file
31 #include <sys/types.h>
34 #include <sys/modctl.h>
37 #include <sys/sunddi.h>
39 #include <sys/policy.h>
40 #include <sys/fm/protocol.h>
43 static dev_info_t
*bl_dip
; /* private copy of devinfo pointer */
46 bl_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
57 if (ddi_create_minor_node(dip
, ddi_get_name(dip
), S_IFCHR
,
58 ddi_get_instance(dip
), DDI_PSEUDO
, 0) != DDI_SUCCESS
)
67 bl_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
78 ddi_remove_minor_node(bl_dip
, NULL
);
84 bl_getinfo(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
89 case DDI_INFO_DEVT2DEVINFO
:
93 case DDI_INFO_DEVT2INSTANCE
:
94 *result
= (void *)(uintptr_t)getminor((dev_t
)arg
);
107 bl_open(dev_t
*devp
, int flag
, int otyp
, struct cred
*credp
)
109 if (otyp
!= OTYP_CHR
)
112 if (secpolicy_blacklist(credp
) != 0)
120 bl_ioctl(dev_t dev
, int cmd
, intptr_t data
, int flag
, cred_t
*cred
, int *rvalp
)
130 if (get_udatamodel() != DATAMODEL_NATIVE
) {
133 if (copyin((void *)data
, &blr32
, sizeof (bl_req32_t
)) != 0)
136 blr
.bl_fmri
= (caddr_t
)(uintptr_t)blr32
.bl_fmri
;
137 blr
.bl_fmrisz
= blr32
.bl_fmrisz
;
139 blr
.bl_class
= (caddr_t
)(uintptr_t)blr32
.bl_class
;
143 if (copyin((void *)data
, &blr
, sizeof (bl_req_t
)) != 0)
147 if (blr
.bl_fmri
== NULL
|| blr
.bl_fmrisz
> BL_FMRI_MAX_BUFSIZE
||
148 blr
.bl_class
== NULL
)
151 if (copyinstr(blr
.bl_class
, class, sizeof (class), NULL
) != 0)
154 buf
= kmem_zalloc(blr
.bl_fmrisz
, KM_SLEEP
);
155 if (copyin(blr
.bl_fmri
, buf
, blr
.bl_fmrisz
) != 0) {
156 kmem_free(buf
, blr
.bl_fmrisz
);
160 err
= nvlist_unpack(buf
, blr
.bl_fmrisz
, &fmri
, KM_SLEEP
);
161 kmem_free(buf
, blr
.bl_fmrisz
);
165 if (nvlist_lookup_string(fmri
, FM_FMRI_SCHEME
, (char **)&scheme
) != 0) {
173 err
= blacklist(cmd
, scheme
, fmri
, class);
184 static struct cb_ops bl_cb_ops
= {
187 nodev
, /* strategy */
192 bl_ioctl
, /* ioctl */
197 ddi_prop_op
, /* cb_prop_op */
199 D_NEW
| D_MP
| D_64BIT
/* Driver compatibility flag */
202 static struct dev_ops bl_ops
= {
203 DEVO_REV
, /* devo_rev */
205 bl_getinfo
, /* devo_getinfo */
206 nulldev
, /* devo_identify */
207 nulldev
, /* devo_probe */
208 bl_attach
, /* devo_attach */
209 bl_detach
, /* devo_detach */
210 nodev
, /* devo_reset */
211 &bl_cb_ops
, /* devo_cb_ops */
212 NULL
, /* devo_bus_ops */
213 NULL
, /* devo_power */
214 ddi_quiesce_not_needed
, /* devo_quiesce */
217 static struct modldrv modldrv
= {
218 &mod_driverops
, "blacklist driver", &bl_ops
,
221 static struct modlinkage modlinkage
= {
222 MODREV_1
, &modldrv
, NULL
228 return (mod_install(&modlinkage
));
232 _info(struct modinfo
*modinfop
)
234 return (mod_info(&modlinkage
, modinfop
));
240 return (mod_remove(&modlinkage
));