From 8b959158e3ccba0aac7e192f637df3714c6c2859 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Wed, 26 Jun 2019 17:18:56 +0200 Subject: [PATCH] Make resize action accept --device-size parameter (supports units). Fixes #368. --- man/cryptsetup.8 | 15 +++++++++------ src/cryptsetup.c | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/man/cryptsetup.8 b/man/cryptsetup.8 index 9a1e3f22..11c746d1 100644 --- a/man/cryptsetup.8 +++ b/man/cryptsetup.8 @@ -110,9 +110,9 @@ Reports the status for the mapping . .IP Resizes an active mapping . -If \-\-size (in 512-bytes sectors) is not specified, the size is computed -from the underlying device. For LUKS it is the size of the -underlying device without the area reserved for LUKS header +If \-\-size (in 512-bytes sectors) or \-\-device\-size are not specified, +the size is computed from the underlying device. For LUKS it is the size +of the underlying device without the area reserved for LUKS header (see data payload offset in \fBluksDump\fR command). For plain crypt device, the whole device size is used. @@ -981,11 +981,14 @@ Hence, if \-\-offset \fIn\fR, and \-\-skip \fIs\fR, sector \fIn\fR (the first sector of the encrypted device) will get a sector number of \fIs\fR for the IV calculation. .TP -.B "\-\-device-size \fIsize[units]\fR" +.B "\-\-device\-size \fIsize[units]\fR" Instead of real device size, use specified value. -It means that only specified area (from the start of the device -to the specified size) will be reencrypted. +With \fIreencrypt\fR action it means that only specified area +(from the start of the device to the specified size) will be +reencrypted. + +With \fIresize\fR action it sets new size of the device. If no unit suffix is specified, the size is in bytes. diff --git a/src/cryptsetup.c b/src/cryptsetup.c index bf062770..ef20e7c2 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -659,6 +659,9 @@ static int action_resize(void) crypt_safe_free(password); } + if (opt_device_size) + opt_size = opt_device_size / SECTOR_SIZE; + if (r >= 0) r = crypt_resize(cd, action_argv[0], opt_size); out: @@ -3827,6 +3830,10 @@ int main(int argc, const char **argv) usage(popt_context, EXIT_FAILURE, _("Options --reduce-device-size and --data-size cannot be combined."), poptGetInvocationName(popt_context)); + if (opt_device_size && opt_size) + usage(popt_context, EXIT_FAILURE, _("Options --device-size and --size cannot be combined."), + poptGetInvocationName(popt_context)); + r = run_action(action); poptFreeContext(popt_context); return r;