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