mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Backport device_is_identical() changes needed for following patch.
This commit is contained in:
12
lib/setup.c
12
lib/setup.c
@@ -2035,7 +2035,7 @@ static int _crypt_format_verity(struct crypt_device *cd,
|
||||
} else
|
||||
cd->u.verity.hdr.data_size = params->data_size;
|
||||
|
||||
if (device_is_identical(crypt_metadata_device(cd), crypt_data_device(cd)) &&
|
||||
if (device_is_identical(crypt_metadata_device(cd), crypt_data_device(cd)) > 0 &&
|
||||
(cd->u.verity.hdr.data_size * params->data_block_size) > params->hash_area_offset) {
|
||||
log_err(cd, _("Data area overlaps with hash area."));
|
||||
return -EINVAL;
|
||||
@@ -2060,14 +2060,14 @@ static int _crypt_format_verity(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
hash_blocks_size = VERITY_hash_blocks(cd, params) * params->hash_block_size;
|
||||
if (device_is_identical(crypt_metadata_device(cd), fec_device) &&
|
||||
if (device_is_identical(crypt_metadata_device(cd), fec_device) > 0 &&
|
||||
(params->hash_area_offset + hash_blocks_size) > params->fec_area_offset) {
|
||||
log_err(cd, _("Hash area overlaps with FEC area."));
|
||||
r = -EINVAL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (device_is_identical(crypt_data_device(cd), fec_device) &&
|
||||
if (device_is_identical(crypt_data_device(cd), fec_device) > 0 &&
|
||||
(cd->u.verity.hdr.data_size * params->data_block_size) > params->fec_area_offset) {
|
||||
log_err(cd, _("Data area overlaps with FEC area."));
|
||||
r = -EINVAL;
|
||||
@@ -2413,7 +2413,7 @@ static int _compare_crypt_devices(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!device_is_identical(src->data_device, tgt->data_device)) {
|
||||
if (device_is_identical(src->data_device, tgt->data_device) <= 0) {
|
||||
log_dbg(cd, "Data devices do not match.");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -2467,7 +2467,7 @@ static int _compare_integrity_devices(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!device_is_identical(src->data_device, tgt->data_device)) {
|
||||
if (device_is_identical(src->data_device, tgt->data_device) <= 0) {
|
||||
log_dbg(cd, "Data devices do not match.");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -3694,7 +3694,7 @@ static int _check_header_data_overlap(struct crypt_device *cd, const char *name)
|
||||
if (!name || !isLUKS(cd->type))
|
||||
return 0;
|
||||
|
||||
if (!device_is_identical(crypt_data_device(cd), crypt_metadata_device(cd)))
|
||||
if (device_is_identical(crypt_data_device(cd), crypt_metadata_device(cd)) <= 0)
|
||||
return 0;
|
||||
|
||||
/* FIXME: check real header size */
|
||||
|
||||
@@ -860,14 +860,21 @@ int device_direct_io(const struct device *device)
|
||||
return device->o_direct;
|
||||
}
|
||||
|
||||
static dev_t device_devno(const struct device *device)
|
||||
static int device_compare_path(const char *path1, const char *path2)
|
||||
{
|
||||
struct stat st;
|
||||
struct stat st_path1, st_path2;
|
||||
|
||||
if (stat(device->path, &st) || !S_ISBLK(st.st_mode))
|
||||
return 0;
|
||||
if (stat(path1, &st_path1 ) < 0 || stat(path2, &st_path2 ) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
return st.st_rdev;
|
||||
if (S_ISBLK(st_path1.st_mode) && S_ISBLK(st_path2.st_mode))
|
||||
return (st_path1.st_rdev == st_path2.st_rdev) ? 1 : 0;
|
||||
|
||||
if (S_ISREG(st_path1.st_mode) && S_ISREG(st_path2.st_mode))
|
||||
return (st_path1.st_ino == st_path2.st_ino &&
|
||||
st_path1.st_dev == st_path2.st_dev) ? 1 : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_is_identical(struct device *device1, struct device *device2)
|
||||
@@ -878,15 +885,10 @@ int device_is_identical(struct device *device1, struct device *device2)
|
||||
if (device1 == device2)
|
||||
return 1;
|
||||
|
||||
if (device1->init_done && device2->init_done)
|
||||
return (device_devno(device1) == device_devno(device2));
|
||||
else if (device1->init_done || device2->init_done)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(device_path(device1), device_path(device2)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return device_compare_path(device_path(device1), device_path(device2));
|
||||
}
|
||||
|
||||
int device_is_rotational(struct device *device)
|
||||
|
||||
Reference in New Issue
Block a user