Пример #1
0
int
zap_leaf_lookup(zap_leaf_t *l, zap_name_t *zn, zap_entry_handle_t *zeh)
{
	uint16_t *chunkp;
	struct zap_leaf_entry *le;

	ASSERT3U(l->l_phys->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC);

again:
	for (chunkp = LEAF_HASH_ENTPTR(l, zn->zn_hash);
	    *chunkp != CHAIN_END; chunkp = &le->le_next) {
		uint16_t chunk = *chunkp;
		le = ZAP_LEAF_ENTRY(l, chunk);

		ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
		ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY);

		if (le->le_hash != zn->zn_hash)
			continue;

		/*
		 * NB: the entry chain is always sorted by cd on
		 * normalized zap objects, so this will find the
		 * lowest-cd match for MT_FIRST.
		 */
		ASSERT(zn->zn_matchtype == MT_EXACT ||
		    (l->l_phys->l_hdr.lh_flags & ZLF_ENTRIES_CDSORTED));
		if (zap_leaf_array_match(l, zn, le->le_name_chunk,
		    le->le_name_numints)) {
			zeh->zeh_num_integers = le->le_value_numints;
			zeh->zeh_integer_size = le->le_value_intlen;
			zeh->zeh_cd = le->le_cd;
			zeh->zeh_hash = le->le_hash;
			zeh->zeh_chunkp = chunkp;
			zeh->zeh_leaf = l;
			return (0);
		}
	}

	/*
	 * NB: we could of course do this in one pass, but that would be
	 * a pain.  We'll see if MT_BEST is even used much.
	 */
	if (zn->zn_matchtype == MT_BEST) {
		zn->zn_matchtype = MT_FIRST;
		goto again;
	}

	return (SET_ERROR(ENOENT));
}
Пример #2
0
int
zap_leaf_lookup(zap_leaf_t *l, zap_name_t *zn, zap_entry_handle_t *zeh)
{
	uint16_t *chunkp;
	struct zap_leaf_entry *le;

	ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_magic, ==, ZAP_LEAF_MAGIC);

	for (chunkp = LEAF_HASH_ENTPTR(l, zn->zn_hash);
	    *chunkp != CHAIN_END; chunkp = &le->le_next) {
		uint16_t chunk = *chunkp;
		le = ZAP_LEAF_ENTRY(l, chunk);

		ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
		ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY);

		if (le->le_hash != zn->zn_hash)
			continue;

		/*
		 * NB: the entry chain is always sorted by cd on
		 * normalized zap objects, so this will find the
		 * lowest-cd match for MT_NORMALIZE.
		 */
		ASSERT((zn->zn_matchtype == 0) ||
		    (zap_leaf_phys(l)->l_hdr.lh_flags & ZLF_ENTRIES_CDSORTED));
		if (zap_leaf_array_match(l, zn, le->le_name_chunk,
		    le->le_name_numints)) {
			zeh->zeh_num_integers = le->le_value_numints;
			zeh->zeh_integer_size = le->le_value_intlen;
			zeh->zeh_cd = le->le_cd;
			zeh->zeh_hash = le->le_hash;
			zeh->zeh_chunkp = chunkp;
			zeh->zeh_leaf = l;
			return (0);
		}
	}

	return (SET_ERROR(ENOENT));
}