コード例 #1
0
ファイル: zap_leaf.c プロジェクト: ChaosJohn/freebsd
static boolean_t
zap_leaf_array_match(zap_leaf_t *l, zap_name_t *zn,
    int chunk, int array_numints)
{
	int bseen = 0;

	if (zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY) {
		uint64_t *thiskey;
		boolean_t match;

		ASSERT(zn->zn_key_intlen == sizeof (*thiskey));
		thiskey = kmem_alloc(array_numints * sizeof (*thiskey),
		    KM_SLEEP);

		zap_leaf_array_read(l, chunk, sizeof (*thiskey), array_numints,
		    sizeof (*thiskey), array_numints, thiskey);
		match = bcmp(thiskey, zn->zn_key_orig,
		    array_numints * sizeof (*thiskey)) == 0;
		kmem_free(thiskey, array_numints * sizeof (*thiskey));
		return (match);
	}

	ASSERT(zn->zn_key_intlen == 1);
	if (zn->zn_matchtype == MT_FIRST) {
		char *thisname = kmem_alloc(array_numints, KM_SLEEP);
		boolean_t match;

		zap_leaf_array_read(l, chunk, sizeof (char), array_numints,
		    sizeof (char), array_numints, thisname);
		match = zap_match(zn, thisname);
		kmem_free(thisname, array_numints);
		return (match);
	}

	/*
	 * Fast path for exact matching.
	 * First check that the lengths match, so that we don't read
	 * past the end of the zn_key_orig array.
	 */
	if (array_numints != zn->zn_key_orig_numints)
		return (B_FALSE);
	while (bseen < array_numints) {
		struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array;
		int toread = MIN(array_numints - bseen, ZAP_LEAF_ARRAY_BYTES);
		ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
		if (bcmp(la->la_array, (char *)zn->zn_key_orig + bseen, toread))
			break;
		chunk = la->la_next;
		bseen += toread;
	}
	return (bseen == array_numints);
}
コード例 #2
0
ファイル: zap_leaf.c プロジェクト: YaroslavLitvinov/zfs-port
/*
 * Only to be used on 8-bit arrays.
 * array_len is actual len in bytes (not encoded le_value_length).
 * namenorm is null-terminated.
 */
static boolean_t
zap_leaf_array_match(zap_leaf_t *l, zap_name_t *zn, int chunk, int array_len)
{
	int bseen = 0;

	if (zn->zn_matchtype == MT_FIRST) {
		char *thisname = kmem_alloc(array_len, KM_SLEEP);
		boolean_t match;

		zap_leaf_array_read(l, chunk, 1, array_len, 1,
		    array_len, thisname);
		match = zap_match(zn, thisname);
		kmem_free(thisname, array_len);
		return (match);
	}

	/* Fast path for exact matching */
	while (bseen < array_len) {
		struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array;
		int toread = MIN(array_len - bseen, ZAP_LEAF_ARRAY_BYTES);
		ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
		if (bcmp(la->la_array, zn->zn_name_orij + bseen, toread))
			break;
		chunk = la->la_next;
		bseen += toread;
	}
	return (bseen == array_len);
}