125e8c5aaSvikram /* 225e8c5aaSvikram * CDDL HEADER START 325e8c5aaSvikram * 425e8c5aaSvikram * The contents of this file are subject to the terms of the 525e8c5aaSvikram * Common Development and Distribution License (the "License"). 625e8c5aaSvikram * You may not use this file except in compliance with the License. 725e8c5aaSvikram * 825e8c5aaSvikram * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 925e8c5aaSvikram * or http://www.opensolaris.org/os/licensing. 1025e8c5aaSvikram * See the License for the specific language governing permissions 1125e8c5aaSvikram * and limitations under the License. 1225e8c5aaSvikram * 1325e8c5aaSvikram * When distributing Covered Code, include this CDDL HEADER in each 1425e8c5aaSvikram * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1525e8c5aaSvikram * If applicable, add the following below this CDDL HEADER, with the 1625e8c5aaSvikram * fields enclosed by brackets "[]" replaced with your own identifying 1725e8c5aaSvikram * information: Portions Copyright [yyyy] [name of copyright owner] 1825e8c5aaSvikram * 1925e8c5aaSvikram * CDDL HEADER END 2025e8c5aaSvikram */ 2125e8c5aaSvikram /* 22*7b209c2cSacruz * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2325e8c5aaSvikram * Use is subject to license terms. 2425e8c5aaSvikram */ 2525e8c5aaSvikram 2625e8c5aaSvikram #pragma ident "%Z%%M% %I% %E% SMI" 2725e8c5aaSvikram 2825e8c5aaSvikram #include <sys/ctfs.h> 2925e8c5aaSvikram #include <sys/contract.h> 3025e8c5aaSvikram #include <sys/contract/device.h> 3125e8c5aaSvikram #include <errno.h> 3225e8c5aaSvikram #include <unistd.h> 3325e8c5aaSvikram #include <string.h> 3425e8c5aaSvikram #include <libnvpair.h> 3525e8c5aaSvikram #include <limits.h> 3625e8c5aaSvikram #include <sys/stat.h> 3725e8c5aaSvikram #include <libcontract.h> 3825e8c5aaSvikram #include "libcontract_impl.h" 3925e8c5aaSvikram 4025e8c5aaSvikram /* 4125e8c5aaSvikram * Device contract template routines 4225e8c5aaSvikram */ 4325e8c5aaSvikram 4425e8c5aaSvikram int 4525e8c5aaSvikram ct_dev_tmpl_set_minor(int fd, char *minor) 4625e8c5aaSvikram { 47*7b209c2cSacruz return (ct_tmpl_set_internal_string(fd, CTDP_MINOR, minor)); 4825e8c5aaSvikram } 4925e8c5aaSvikram 5025e8c5aaSvikram int 5125e8c5aaSvikram ct_dev_tmpl_set_aset(int fd, uint_t aset) 5225e8c5aaSvikram { 5325e8c5aaSvikram return (ct_tmpl_set_internal(fd, CTDP_ACCEPT, aset)); 5425e8c5aaSvikram } 5525e8c5aaSvikram 5625e8c5aaSvikram int 5725e8c5aaSvikram ct_dev_tmpl_set_noneg(int fd) 5825e8c5aaSvikram { 5925e8c5aaSvikram return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_SET)); 6025e8c5aaSvikram } 6125e8c5aaSvikram 6225e8c5aaSvikram int 6325e8c5aaSvikram ct_dev_tmpl_clear_noneg(int fd) 6425e8c5aaSvikram { 6525e8c5aaSvikram return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_CLEAR)); 6625e8c5aaSvikram } 6725e8c5aaSvikram 6825e8c5aaSvikram int 6925e8c5aaSvikram ct_dev_tmpl_get_minor(int fd, char *buf, size_t *buflenp) 7025e8c5aaSvikram { 71*7b209c2cSacruz int ret = ct_tmpl_get_internal_string(fd, CTDP_MINOR, buf, *buflenp); 7225e8c5aaSvikram 73*7b209c2cSacruz if (ret == -1) 74*7b209c2cSacruz return (errno); 7525e8c5aaSvikram 76*7b209c2cSacruz if (ret >= *buflenp) { 77*7b209c2cSacruz *buflenp = ret + 1; 7825e8c5aaSvikram return (EOVERFLOW); 7925e8c5aaSvikram } 8025e8c5aaSvikram 8125e8c5aaSvikram return (0); 8225e8c5aaSvikram } 8325e8c5aaSvikram 8425e8c5aaSvikram int 8525e8c5aaSvikram ct_dev_tmpl_get_aset(int fd, uint_t *aset) 8625e8c5aaSvikram { 8725e8c5aaSvikram return (ct_tmpl_get_internal(fd, CTDP_ACCEPT, aset)); 8825e8c5aaSvikram } 8925e8c5aaSvikram 9025e8c5aaSvikram int 9125e8c5aaSvikram ct_dev_tmpl_get_noneg(int fd, uint_t *negp) 9225e8c5aaSvikram { 9325e8c5aaSvikram return (ct_tmpl_get_internal(fd, CTDP_NONEG, negp)); 9425e8c5aaSvikram } 9525e8c5aaSvikram 9625e8c5aaSvikram /* 9725e8c5aaSvikram * Device contract event routines 9825e8c5aaSvikram */ 9925e8c5aaSvikram 10025e8c5aaSvikram /* 10125e8c5aaSvikram * No device contract specific event routines 10225e8c5aaSvikram */ 10325e8c5aaSvikram 10425e8c5aaSvikram 10525e8c5aaSvikram /* 10625e8c5aaSvikram * Device contract status routines 10725e8c5aaSvikram */ 10825e8c5aaSvikram 10925e8c5aaSvikram int 11025e8c5aaSvikram ct_dev_status_get_aset(ct_stathdl_t stathdl, uint_t *aset) 11125e8c5aaSvikram { 11225e8c5aaSvikram struct ctlib_status_info *info = stathdl; 11325e8c5aaSvikram 11425e8c5aaSvikram if (info->status.ctst_type != CTT_DEVICE) 11525e8c5aaSvikram return (EINVAL); 11625e8c5aaSvikram 11725e8c5aaSvikram if (info->nvl == NULL) 11825e8c5aaSvikram return (ENOENT); 11925e8c5aaSvikram 12025e8c5aaSvikram return (nvlist_lookup_uint32(info->nvl, CTDS_ASET, aset)); 12125e8c5aaSvikram } 12225e8c5aaSvikram 12325e8c5aaSvikram int 12425e8c5aaSvikram ct_dev_status_get_noneg(ct_stathdl_t stathdl, uint_t *negp) 12525e8c5aaSvikram { 12625e8c5aaSvikram struct ctlib_status_info *info = stathdl; 12725e8c5aaSvikram 12825e8c5aaSvikram if (info->status.ctst_type != CTT_DEVICE) 12925e8c5aaSvikram return (EINVAL); 13025e8c5aaSvikram 13125e8c5aaSvikram if (info->nvl == NULL) 13225e8c5aaSvikram return (ENOENT); 13325e8c5aaSvikram 13425e8c5aaSvikram return (nvlist_lookup_uint32(info->nvl, CTDS_NONEG, negp)); 13525e8c5aaSvikram } 13625e8c5aaSvikram 13725e8c5aaSvikram int 13825e8c5aaSvikram ct_dev_status_get_dev_state(ct_stathdl_t stathdl, uint_t *statep) 13925e8c5aaSvikram { 14025e8c5aaSvikram struct ctlib_status_info *info = stathdl; 14125e8c5aaSvikram 14225e8c5aaSvikram if (info->status.ctst_type != CTT_DEVICE) 14325e8c5aaSvikram return (EINVAL); 14425e8c5aaSvikram 14525e8c5aaSvikram if (info->nvl == NULL) 14625e8c5aaSvikram return (ENOENT); 14725e8c5aaSvikram 14825e8c5aaSvikram return (nvlist_lookup_uint32(info->nvl, CTDS_STATE, statep)); 14925e8c5aaSvikram } 15025e8c5aaSvikram 15125e8c5aaSvikram int 15225e8c5aaSvikram ct_dev_status_get_minor(ct_stathdl_t stathdl, char **bufp) 15325e8c5aaSvikram { 15425e8c5aaSvikram int error; 15525e8c5aaSvikram struct ctlib_status_info *info = stathdl; 15625e8c5aaSvikram 15725e8c5aaSvikram if (bufp == NULL) 15825e8c5aaSvikram return (EINVAL); 15925e8c5aaSvikram 16025e8c5aaSvikram if (info->status.ctst_type != CTT_DEVICE) 16125e8c5aaSvikram return (EINVAL); 16225e8c5aaSvikram 16325e8c5aaSvikram if (info->nvl == NULL) 16425e8c5aaSvikram return (ENOENT); 16525e8c5aaSvikram 16625e8c5aaSvikram error = nvlist_lookup_string(info->nvl, CTDS_MINOR, bufp); 16725e8c5aaSvikram if (error != 0) { 16825e8c5aaSvikram return (error); 16925e8c5aaSvikram } 17025e8c5aaSvikram 17125e8c5aaSvikram return (0); 17225e8c5aaSvikram } 173