static struct adouble *ad_alloc(TALLOC_CTX *ctx,
				adouble_type_t type)
{
	int rc = 0;
	size_t adsize = 0;
	struct adouble *ad;

	switch (type) {
	case ADOUBLE_META:
		adsize = AD_DATASZ_XATTR;
		break;
	case ADOUBLE_RSRC:
		/*
		 * AppleDouble ._ file case, optimize for fewer (but larger)
		 * IOs. Two cases:
		 *
		 * - without xattrs size of the header is exactly
		 *   AD_DATASZ_DOT_UND (82) bytes
		 *
		 * - with embedded xattrs it can be larger, up to
		 *   AD_XATTR_MAX_HDR_SIZE
		 *
		 * Larger headers are not supported, but this is a reasonable
		 * limit that is also employed by the macOS client.
		 *
		 * We used the largest possible size to be able to read the full
		 * header with one IO.
		 */
		adsize = AD_XATTR_MAX_HDR_SIZE;
		break;
	default:
		return NULL;
	}

	ad = talloc_zero(ctx, struct adouble);
	if (ad == NULL) {
		rc = -1;
		goto exit;
	}

	if (adsize) {
		ad->ad_data = talloc_zero_array(ad, char, adsize);
		if (ad->ad_data == NULL) {
			rc = -1;
			goto exit;
		}
	}

	ad->ad_type = type;
	ad->ad_magic = AD_MAGIC;
	ad->ad_version = AD_VERSION;

	talloc_set_destructor(ad, adouble_destructor);

exit:
	if (rc != 0) {
		TALLOC_FREE(ad);
	}
	return ad;
}
static struct adouble *ad_alloc(TALLOC_CTX *ctx,
				adouble_type_t type)
{
	int rc = 0;
	size_t adsize = 0;
	struct adouble *ad;

	switch (type) {
	case ADOUBLE_META:
		adsize = AD_DATASZ_XATTR;
		break;
	case ADOUBLE_RSRC:
		 
		adsize = AD_XATTR_MAX_HDR_SIZE;
		break;
	default:
		return NULL;
	}

	ad = talloc_zero(ctx, struct adouble);
	if (ad == NULL) {
		rc = -1;
		goto exit;
	}

	if (adsize) {
		ad->ad_data = talloc_zero_array(ad, char, adsize);
		if (ad->ad_data == NULL) {
			rc = -1;
			goto exit;
		}
	}

	ad->ad_type = type;
	ad->ad_magic = AD_MAGIC;
	ad->ad_version = AD_VERSION;

	talloc_set_destructor(ad, adouble_destructor);

exit:
	if (rc != 0) {
		TALLOC_FREE(ad);
	}
	return ad;
}