int crypt_convert(struct crypt_device *cd,
		  const char *type,
		  void *params)
{
	struct luks_phdr hdr1;
	struct luks2_hdr hdr2;
	int r;

	if (!type)
		return -EINVAL;

	log_dbg(cd, "Converting LUKS device to type %s", type);

	if ((r = onlyLUKS(cd)))
		return r;

	if (isLUKS1(cd->type) && isLUKS2(type))
		r = LUKS2_luks1_to_luks2(cd, &cd->u.luks1.hdr, &hdr2);
	else if (isLUKS2(cd->type) && isLUKS1(type))
		r = LUKS2_luks2_to_luks1(cd, &cd->u.luks2.hdr, &hdr1);
	else
		return -EINVAL;

	if (r < 0) {
		/* in-memory header may be invalid after failed conversion */
		_luks2_reload(cd);
		if (r == -EBUSY)
			log_err(cd, _("Cannot convert device %s which is still in use."), mdata_device_path(cd));
		return r;
	}

	crypt_free_type(cd);

	return crypt_load(cd, type, params);
}
int crypt_convert(struct crypt_device *cd,
		  const char *type,
		  void *params)
{
	struct luks_phdr hdr1;
	struct luks2_hdr hdr2;
	int r;

	if (!type)
		return -EINVAL;

	log_dbg(cd, "Converting LUKS device to type %s", type);

	if ((r = onlyLUKS(cd)))
		return r;

	if (isLUKS1(cd->type) && isLUKS2(type))
		r = LUKS2_luks1_to_luks2(cd, &cd->u.luks1.hdr, &hdr2);
	else if (isLUKS2(cd->type) && isLUKS1(type))
		r = LUKS2_luks2_to_luks1(cd, &cd->u.luks2.hdr, &hdr1);
	else
		return -EINVAL;

	if (r < 0) {
		 
		_luks2_reload(cd);
		if (r == -EBUSY)
			log_err(cd, _("Cannot convert device %s which is still in use."), mdata_device_path(cd));
		return r;
	}

	crypt_free_type(cd);

	return crypt_load(cd, type, params);
}