btrfs-progs: fi resize: fix false 0.00B size output

Resize to nums without sign prefix makes false output:

  $ btrfs fi resize 1:150g /srv/extra
  Resize device id 1 (/dev/sdb1) from 298.09GiB to 0.00B

The resize operation would take effect though.

Fix it by handling the case if mod is 0 in check_resize_args().

Issue: #307
Reported-by: Chris Murphy <lists@colorremedies.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Su Yue 2021-04-19 21:05:49 +08:00 committed by David Sterba
parent 82611f51a5
commit 31934b1161

View File

@ -1158,7 +1158,10 @@ static int check_resize_args(const char *amount, const char *path) {
}
old_size = di_args[dev_idx].total_bytes;
if (mod < 0) {
/* For target sizes without +/- sign prefix (e.g. 1:150g) */
if (mod == 0) {
new_size = diff;
} else if (mod < 0) {
if (diff > old_size) {
error("current size is %s which is smaller than %s",
pretty_size_mode(old_size, UNITS_DEFAULT),