From 757cefbb61dd22254ae8441f7caed39be7c59483 Mon Sep 17 00:00:00 2001 From: Awal Garg Date: Sat, 28 Jul 2018 18:50:35 +0530 Subject: libfdisk: Accept negative numbers for last sector input [kzak@redhat.com: - add note to the man page - add '-' to the dialog query - cleanup functions names and libfdisk.sym] Signed-off-by: Karel Zak --- disk-utils/fdisk.8 | 17 ++++++++++------- disk-utils/fdisk.c | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'disk-utils') diff --git a/disk-utils/fdisk.8 b/disk-utils/fdisk.8 index 91c6b6f84..430c96c3d 100644 --- a/disk-utils/fdisk.8 +++ b/disk-utils/fdisk.8 @@ -33,7 +33,7 @@ All partitioning is driven by device I/O limits (the topology) by default. is able to optimize the disk layout for a 4K-sector size and use an alignment offset on modern devices for MBR and GPT. It is always a good idea to follow \fBfdisk\fR's defaults as the default values (e.g. first and last partition sectors) and partition -sizes specified by the +{M,G,...} notation are always aligned according +sizes specified by the +/-{M,G,...} notation are always aligned according to the device properties. Note that @@ -161,16 +161,19 @@ documentation (the Documentation/devices.txt file). .SH SIZES The "last sector" dialog accepts partition size specified by number of sectors -or by +{K,B,M,G,...} notation. +or by +/-{K,B,M,G,...} notation. If the size is prefixed by '+' then it is interpreted as relative to the -partition first sector. In this case the size is expected in bytes and the -number may be followed by the multiplicative suffixes KiB=1024, MiB=1024*1024, -and so on for GiB, TiB, PiB, EiB, ZiB and YiB. The "iB" is optional, e.g. "K" -has the same meaning as "KiB". +partition first sector. If the size is prefixed by '-' then it is interpreted +as relative to the high limit (last available sector for the partition). + +In the case the size is specified in bytes than the number may be followed by +the multiplicative suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, +PiB, EiB, ZiB and YiB. The "iB" is optional, e.g. "K" has the same meaning as +"KiB". The relative sizes are always aligned according to device I/O limits. The -+{K,B,M,G,...} notation is recommended. ++/-{K,B,M,G,...} notation is recommended. For backward compatibility fdisk also accepts the suffixes KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. These 10^N suffixes diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 73525fa51..ed4db8bd0 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -357,6 +357,8 @@ static int ask_offset(struct fdisk_context *cxt, } if (sig == '+') num += base; + else if (sig == '-' && fdisk_ask_number_is_wrap_negative(ask)) + num = high - num; else if (sig == '-') num = base - num; -- cgit v1.2.3-55-g7522