#include <sys/ctfs.h>
#include <sys/contract.h>
#include <sys/contract/device.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <libnvpair.h>
#include <limits.h>
#include <sys/stat.h>
#include <libcontract.h>
#include "libcontract_impl.h"
int
ct_dev_tmpl_set_minor(int fd, char *minor)
{
return (ct_tmpl_set_internal_string(fd, CTDP_MINOR, minor));
}
int
ct_dev_tmpl_set_aset(int fd, uint_t aset)
{
return (ct_tmpl_set_internal(fd, CTDP_ACCEPT, aset));
}
int
ct_dev_tmpl_set_noneg(int fd)
{
return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_SET));
}
int
ct_dev_tmpl_clear_noneg(int fd)
{
return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_CLEAR));
}
int
ct_dev_tmpl_get_minor(int fd, char *buf, size_t *buflenp)
{
int ret = ct_tmpl_get_internal_string(fd, CTDP_MINOR, buf, *buflenp);
if (ret == -1)
return (errno);
if (ret >= *buflenp) {
*buflenp = ret + 1;
return (EOVERFLOW);
}
return (0);
}
int
ct_dev_tmpl_get_aset(int fd, uint_t *aset)
{
return (ct_tmpl_get_internal(fd, CTDP_ACCEPT, aset));
}
int
ct_dev_tmpl_get_noneg(int fd, uint_t *negp)
{
return (ct_tmpl_get_internal(fd, CTDP_NONEG, negp));
}
int
ct_dev_status_get_aset(ct_stathdl_t stathdl, uint_t *aset)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_DEVICE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTDS_ASET, aset));
}
int
ct_dev_status_get_noneg(ct_stathdl_t stathdl, uint_t *negp)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_DEVICE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTDS_NONEG, negp));
}
int
ct_dev_status_get_dev_state(ct_stathdl_t stathdl, uint_t *statep)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_DEVICE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTDS_STATE, statep));
}
int
ct_dev_status_get_minor(ct_stathdl_t stathdl, char **bufp)
{
int error;
struct ctlib_status_info *info = stathdl;
if (bufp == NULL)
return (EINVAL);
if (info->status.ctst_type != CTT_DEVICE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
error = nvlist_lookup_string(info->nvl, CTDS_MINOR, bufp);
if (error != 0) {
return (error);
}
return (0);
}