int ad_convert(struct vfs_handle_struct *handle,
		const struct smb_filename *smb_fname,
		const char *catia_mappings,
		uint32_t flags)
{
	struct adouble *ad = NULL;
	bool ok;
	bool converted_xattr = false;
	bool blank;
	int ret;

	ad = ad_get(talloc_tos(), handle, smb_fname, ADOUBLE_RSRC);
	if (ad == NULL) {
		return 0;
	}

	ok = ad_convert_xattr(handle,
			      ad,
			      smb_fname,
			      catia_mappings,
			      &converted_xattr);
	if (!ok) {
		ret = -1;
		goto done;
	}

	ok = ad_convert_blank_rfork(handle, ad, flags, &blank);
	if (!ok) {
		ret = -1;
		goto done;
	}

	if (converted_xattr || blank) {
		ok = ad_convert_truncate(handle, ad, smb_fname);
		if (!ok) {
			ret = -1;
			goto done;
		}
	}

	ok = ad_convert_finderinfo(handle, ad, smb_fname);
	if (!ok) {
		DBG_ERR("Failed to convert [%s]\n",
			smb_fname_str_dbg(smb_fname));
		ret = -1;
		goto done;
	}

	ok = ad_convert_delete_adfile(handle,
			ad,
			smb_fname,
			flags);
	if (!ok) {
		ret = -1;
		goto done;
	}

	ret = 0;
done:
	TALLOC_FREE(ad);
	return ret;
}
int ad_convert(struct vfs_handle_struct *handle,
		const struct smb_filename *smb_fname,
		const char *catia_mappings,
		uint32_t flags)
{
	struct adouble *ad = NULL;
	bool ok;
	bool converted_xattr = false;
	bool blank;
	int ret;

	ad = ad_get(talloc_tos(), handle, smb_fname, ADOUBLE_RSRC);
	if (ad == NULL) {
		return 0;
	}

	ok = ad_convert_xattr(handle,
			      ad,
			      smb_fname,
			      catia_mappings,
			      &converted_xattr);
	if (!ok) {
		ret = -1;
		goto done;
	}

	ok = ad_convert_blank_rfork(handle, ad, flags, &blank);
	if (!ok) {
		ret = -1;
		goto done;
	}

	if (converted_xattr || blank) {
		ok = ad_convert_truncate(handle, ad, smb_fname);
		if (!ok) {
			ret = -1;
			goto done;
		}
	}

	ok = ad_convert_finderinfo(handle, ad, smb_fname);
	if (!ok) {
		DBG_ERR("Failed to convert [%s]\n",
			smb_fname_str_dbg(smb_fname));
		ret = -1;
		goto done;
	}

	ok = ad_convert_delete_adfile(handle,
			ad,
			smb_fname,
			flags);
	if (!ok) {
		ret = -1;
		goto done;
	}

	ret = 0;
done:
	TALLOC_FREE(ad);
	return ret;
}