| 171 | } |
| 172 | |
| 173 | zap_name_t * |
| 174 | zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt) |
| 175 | { |
| 176 | zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP); |
| 177 | |
| 178 | zn->zn_zap = zap; |
| 179 | zn->zn_key_intlen = sizeof (*key); |
| 180 | zn->zn_key_orig = key; |
| 181 | zn->zn_key_orig_numints = strlen(zn->zn_key_orig) + 1; |
| 182 | zn->zn_matchtype = mt; |
| 183 | zn->zn_normflags = zap->zap_normflags; |
| 184 | |
| 185 | /* |
| 186 | * If we're dealing with a case sensitive lookup on a mixed or |
| 187 | * insensitive fs, remove U8_TEXTPREP_TOUPPER or the lookup |
| 188 | * will fold case to all caps overriding the lookup request. |
| 189 | */ |
| 190 | if (mt & MT_MATCH_CASE) |
| 191 | zn->zn_normflags &= ~U8_TEXTPREP_TOUPPER; |
| 192 | |
| 193 | if (zap->zap_normflags) { |
| 194 | /* |
| 195 | * We *must* use zap_normflags because this normalization is |
| 196 | * what the hash is computed from. |
| 197 | */ |
| 198 | if (zap_normalize(zap, key, zn->zn_normbuf, |
| 199 | zap->zap_normflags) != 0) { |
| 200 | zap_name_free(zn); |
| 201 | return (NULL); |
| 202 | } |
| 203 | zn->zn_key_norm = zn->zn_normbuf; |
| 204 | zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1; |
| 205 | } else { |
| 206 | if (mt != 0) { |
| 207 | zap_name_free(zn); |
| 208 | return (NULL); |
| 209 | } |
| 210 | zn->zn_key_norm = zn->zn_key_orig; |
| 211 | zn->zn_key_norm_numints = zn->zn_key_orig_numints; |
| 212 | } |
| 213 | |
| 214 | zn->zn_hash = zap_hash(zn); |
| 215 | |
| 216 | if (zap->zap_normflags != zn->zn_normflags) { |
| 217 | /* |
| 218 | * We *must* use zn_normflags because this normalization is |
| 219 | * what the matching is based on. (Not the hash!) |
| 220 | */ |
| 221 | if (zap_normalize(zap, key, zn->zn_normbuf, |
| 222 | zn->zn_normflags) != 0) { |
| 223 | zap_name_free(zn); |
| 224 | return (NULL); |
| 225 | } |
| 226 | zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1; |
| 227 | } |
| 228 | |
| 229 | return (zn); |
| 230 | } |
no test coverage detected