mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-16 13:20:11 +01:00
Print warning early if LUKS container is too small for activation.
Activation with header only fails too late (in device-mapper call) while it is clear from the beginning that it cannot succeed. Just add an early and better worded error. Ignore this situation for block device (we have to call ioctl to get size). The most common case is a file container here anyway. For block devices it fails during activation later.
This commit is contained in:
@@ -1567,6 +1567,7 @@ static int action_open_luks(void)
|
|||||||
int r, keysize, tries;
|
int r, keysize, tries;
|
||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
size_t passwordLen;
|
size_t passwordLen;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
if (ARG_SET(OPT_REFRESH_ID)) {
|
if (ARG_SET(OPT_REFRESH_ID)) {
|
||||||
activated_name = action_argc > 1 ? action_argv[1] : action_argv[0];
|
activated_name = action_argc > 1 ? action_argv[1] : action_argv[0];
|
||||||
@@ -1593,6 +1594,14 @@ static int action_open_luks(void)
|
|||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activated_name && !stat(crypt_get_device_name(cd), &st) && S_ISREG(st.st_mode) &&
|
||||||
|
crypt_get_data_offset(cd) >= ((uint64_t)st.st_size / SECTOR_SIZE)) {
|
||||||
|
log_err(_("LUKS file container %s is too small for activation, there is no remaining space for data."),
|
||||||
|
crypt_get_device_name(cd));
|
||||||
|
r = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_activation_flags(&activate_flags);
|
set_activation_flags(&activate_flags);
|
||||||
|
|||||||
Reference in New Issue
Block a user