Allow --reduce-device-size and --device-size in encrypt action.

Fixes: #822
This commit is contained in:
Ondrej Kozina
2025-05-20 09:54:22 +02:00
parent ad30673dc5
commit 10ab6be262
6 changed files with 91 additions and 6 deletions

View File

@@ -680,13 +680,15 @@ static int encrypt_luks2_init(struct crypt_device **cd, const char *data_device,
}
}
/* The --reduce-device-size has to be at least twice the size of first moved segment (LUKS2
* data offset) */
if (!ARG_SET(OPT_HEADER_ID) && ARG_UINT64(OPT_OFFSET_ID) &&
data_shift && (ARG_UINT64(OPT_OFFSET_ID) > (uint64_t)(imaxabs(data_shift) / (2 * SECTOR_SIZE)))) {
log_err(_("Requested data offset must be less than or equal to half of --reduce-device-size parameter."));
return -EINVAL;
}
/* TODO: ask user to confirm. It's useless to do data device reduction and than use smaller value */
/* It's useless to do data device reduction and than use smaller value */
if (!ARG_SET(OPT_HEADER_ID) && ARG_UINT64(OPT_OFFSET_ID) &&
data_shift && (ARG_UINT64(OPT_OFFSET_ID) < (uint64_t)(imaxabs(data_shift) / (2 * SECTOR_SIZE)))) {
data_shift = -(ARG_UINT64(OPT_OFFSET_ID) * 2 * SECTOR_SIZE);