Make resize action accept --device-size parameter (supports units).

Fixes #368.
This commit is contained in:
Ondrej Kozina
2019-06-26 17:18:56 +02:00
committed by Milan Broz
parent ecb898c7ff
commit 8b959158e3
2 changed files with 16 additions and 6 deletions

View File

@@ -110,9 +110,9 @@ Reports the status for the mapping <name>.
.IP
Resizes an active mapping <name>.
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.

View File

@@ -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;