Support --device-size option for plain devices.

This commit is contained in:
daniel.zatovic
2022-02-03 21:25:36 +01:00
committed by Milan Broz
parent bef46c950d
commit 452467661e
4 changed files with 13 additions and 5 deletions

View File

@@ -220,8 +220,8 @@ Opens (creates a mapping with) <name> backed by device <device>.
\fB<options>\fR can be [\-\-hash, \-\-cipher, \-\-verify-passphrase, \fB<options>\fR can be [\-\-hash, \-\-cipher, \-\-verify-passphrase,
\-\-sector\-size, \-\-key-file, \-\-keyfile-offset, \-\-key-size, \-\-sector\-size, \-\-key-file, \-\-keyfile-offset, \-\-key-size,
\-\-offset, \-\-skip, \-\-size, \-\-readonly, \-\-shared, \-\-allow\-discards, \-\-offset, \-\-skip, \-\-device\-size, \-\-size, \-\-readonly,
\-\-refresh] \-\-shared, \-\-allow\-discards, \-\-refresh]
Example: 'cryptsetup open \-\-type plain /dev/sda10 e1' maps the raw Example: 'cryptsetup open \-\-type plain /dev/sda10 e1' maps the raw
encrypted device /dev/sda10 to the mapped (decrypted) device encrypted device /dev/sda10 to the mapped (decrypted) device

View File

@@ -145,7 +145,6 @@ static int action_open_plain(void)
.hash = ARG_SET(OPT_HASH_ID) ? ARG_STR(OPT_HASH_ID) : DEFAULT_PLAIN_HASH, .hash = ARG_SET(OPT_HASH_ID) ? ARG_STR(OPT_HASH_ID) : DEFAULT_PLAIN_HASH,
.skip = ARG_UINT64(OPT_SKIP_ID), .skip = ARG_UINT64(OPT_SKIP_ID),
.offset = ARG_UINT64(OPT_OFFSET_ID), .offset = ARG_UINT64(OPT_OFFSET_ID),
.size = ARG_UINT64(OPT_SIZE_ID),
.sector_size = ARG_UINT32(OPT_SECTOR_SIZE_ID) ?: SECTOR_SIZE .sector_size = ARG_UINT32(OPT_SECTOR_SIZE_ID) ?: SECTOR_SIZE
}; };
char *password = NULL; char *password = NULL;
@@ -230,6 +229,11 @@ static int action_open_plain(void)
pmode = cipher_mode; pmode = cipher_mode;
} }
if (ARG_SET(OPT_DEVICE_SIZE_ID))
params.size = ARG_UINT64(OPT_DEVICE_SIZE_ID) / SECTOR_SIZE;
else if (ARG_SET(OPT_SIZE_ID))
params.size = ARG_UINT64(OPT_SIZE_ID);
r = crypt_format(cd, CRYPT_PLAIN, r = crypt_format(cd, CRYPT_PLAIN,
pcipher, pmode, pcipher, pmode,
NULL, NULL, NULL, NULL,
@@ -2738,6 +2742,9 @@ static const char * verify_open(void)
(strncmp(device_type, "luks", 4) && strcmp(device_type, "tcrypt") && strcmp(device_type, "bitlk")))) (strncmp(device_type, "luks", 4) && strcmp(device_type, "tcrypt") && strcmp(device_type, "bitlk"))))
return _("Option --test-passphrase is allowed only for open of LUKS, TCRYPT and BITLK devices."); return _("Option --test-passphrase is allowed only for open of LUKS, TCRYPT and BITLK devices.");
if (ARG_SET(OPT_DEVICE_SIZE_ID) && ARG_SET(OPT_SIZE_ID))
return _("Options --device-size and --size cannot be combined.");
/* "open --type tcrypt" and "tcryptDump" checks are identical */ /* "open --type tcrypt" and "tcryptDump" checks are identical */
return verify_tcryptdump(); return verify_tcryptdump();
} }

View File

@@ -56,7 +56,7 @@
#define OPT_ALIGN_PAYLOAD_ACTIONS { FORMAT_ACTION, REENCRYPT_ACTION } #define OPT_ALIGN_PAYLOAD_ACTIONS { FORMAT_ACTION, REENCRYPT_ACTION }
#define OPT_ALLOW_DISCARDS_ACTIONS { OPEN_ACTION } #define OPT_ALLOW_DISCARDS_ACTIONS { OPEN_ACTION }
#define OPT_DEFERRED_ACTIONS { CLOSE_ACTION } #define OPT_DEFERRED_ACTIONS { CLOSE_ACTION }
#define OPT_DEVICE_SIZE_ACTIONS { RESIZE_ACTION, REENCRYPT_ACTION } #define OPT_DEVICE_SIZE_ACTIONS { OPEN_ACTION, RESIZE_ACTION, REENCRYPT_ACTION }
#define OPT_DISABLE_VERACRYPT_ACTIONS { OPEN_ACTION, TCRYPTDUMP_ACTION } #define OPT_DISABLE_VERACRYPT_ACTIONS { OPEN_ACTION, TCRYPTDUMP_ACTION }
#define OPT_HOTZONE_SIZE_ACTIONS { REENCRYPT_ACTION } #define OPT_HOTZONE_SIZE_ACTIONS { REENCRYPT_ACTION }
#define OPT_INTEGRITY_ACTIONS { FORMAT_ACTION, REENCRYPT_ACTION } #define OPT_INTEGRITY_ACTIONS { FORMAT_ACTION, REENCRYPT_ACTION }

View File

@@ -277,7 +277,8 @@ exp_fail reencrypt DEV --reduce-device-size 64m --device-size 100g
# exp_fail open DEV --encrypt # exp_fail open DEV --encrypt
# exp_fail open DEV NAME --device-size 32m # exp_fail open DEV NAME --device-size 32m
# exp_fail open DEV NAME --size 100 # exp_fail open DEV NAME --size 100
exp_fail open DEV NAME --device-size 32m --type plain exp_pass open DEV NAME --device-size 32m --type plain
exp_fail open DEV NAME --device-size $((32*1024*1024+1)) --type plain
exp_pass open DEV NAME --size 100 --type plain exp_pass open DEV NAME --size 100 --type plain
exp_fail open DEV NAME --size 100 --device-size $((512*100)) --type plain exp_fail open DEV NAME --size 100 --device-size $((512*100)) --type plain
exp_fail reencrypt DEV --device-size $((32*1024*1024+1)) exp_fail reencrypt DEV --device-size $((32*1024*1024+1))