1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2015, Joyent, Inc.
*/
/*
* Routines for manipulating property information structures.
*
* For more information, see the big theory statement in
* uts/common/io/overlay/overlay.c
*/
#include <sys/overlay_impl.h>
void
overlay_prop_init(overlay_prop_handle_t phdl)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
mac_propval_range_t *rangep = (mac_propval_range_t *)infop->oipi_poss;
infop->oipi_posssize = sizeof (mac_propval_range_t);
bzero(rangep, sizeof (mac_propval_range_t));
}
void
overlay_prop_set_name(overlay_prop_handle_t phdl, const char *name)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
(void) strlcpy(infop->oipi_name, name, OVERLAY_PROP_NAMELEN);
}
void
overlay_prop_set_prot(overlay_prop_handle_t phdl, overlay_prop_prot_t prot)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
infop->oipi_prot = prot;
}
void
overlay_prop_set_type(overlay_prop_handle_t phdl, overlay_prop_type_t type)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
infop->oipi_type = type;
}
int
overlay_prop_set_default(overlay_prop_handle_t phdl, void *def, ssize_t len)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
if (len > OVERLAY_PROP_SIZEMAX)
return (E2BIG);
if (len < 0)
return (EOVERFLOW);
bcopy(def, infop->oipi_default, len);
infop->oipi_defsize = (uint32_t)len;
return (0);
}
void
overlay_prop_set_nodefault(overlay_prop_handle_t phdl)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
infop->oipi_default[0] = '\0';
infop->oipi_defsize = 0;
}
void
overlay_prop_set_range_uint32(overlay_prop_handle_t phdl, uint32_t min,
uint32_t max)
{
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
mac_propval_range_t *rangep = (mac_propval_range_t *)infop->oipi_poss;
if (rangep->mpr_count != 0 && rangep->mpr_type != MAC_PROPVAL_UINT32)
return;
if (infop->oipi_posssize + sizeof (mac_propval_uint32_range_t) >
sizeof (infop->oipi_poss))
return;
infop->oipi_posssize += sizeof (mac_propval_uint32_range_t);
rangep->mpr_count++;
rangep->mpr_type = MAC_PROPVAL_UINT32;
rangep->u.mpr_uint32[rangep->mpr_count-1].mpur_min = min;
rangep->u.mpr_uint32[rangep->mpr_count-1].mpur_max = max;
}
void
overlay_prop_set_range_str(overlay_prop_handle_t phdl, const char *str)
{
size_t len = strlen(str) + 1; /* Account for a null terminator */
overlay_ioc_propinfo_t *infop = (overlay_ioc_propinfo_t *)phdl;
mac_propval_range_t *rangep = (mac_propval_range_t *)infop->oipi_poss;
mac_propval_str_range_t *pstr = &rangep->u.mpr_str;
if (rangep->mpr_count != 0 && rangep->mpr_type != MAC_PROPVAL_STR)
return;
if (infop->oipi_posssize + len > sizeof (infop->oipi_poss))
return;
rangep->mpr_count++;
rangep->mpr_type = MAC_PROPVAL_STR;
strlcpy((char *)&pstr->mpur_data[pstr->mpur_nextbyte], str,
sizeof (infop->oipi_poss) - infop->oipi_posssize);
pstr->mpur_nextbyte += len;
infop->oipi_posssize += len;
}
|