From ce9f568c25cc444a8796c599f2539864ab666d5f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 20 Jan 2015 14:10:08 +0100 Subject: [PATCH] libfdisk: accept Start offset in {B,M,G..}iB in sfdisk scripts Signed-off-by: Karel Zak --- disk-utils/sfdisk.8 | 8 ++++++-- disk-utils/sfdisk.c | 5 +++-- libfdisk/src/script.c | 13 ++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index 5f9eba48bd..bb0ba83dc4 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -211,7 +211,9 @@ is given, the default for each field is its previous value. The default value of .I start is the first non-assigned sector aligned according to device I/O limits. -The default start offset for the first partition is 1 MiB. +The default start offset for the first partition is 1 MiB. The offset may +be may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, +EiB, ZiB and YiB) then the number is interpreted as offset in bytes. .sp The default value of .I size @@ -275,7 +277,9 @@ The currently supported fields are: .TP .BI start= number The first non-assigned sector aligned according to device I/O limits. The default -start offset for the first partition is 1 MiB. +start offset for the first partition is 1 MiB. The offset may be followed by +the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then +the number is interpreted as offset in bytes. .TP .BI size= number Specify the partition size in sectors. The number may be followed by the multiplicative diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 86c8b669fa..4142181d3e 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -946,8 +946,9 @@ static void command_fdisk_help(void) fputs(_(" , , , \n"), stdout); fputc('\n', stdout); - fputs(_(" begin of the partition in sectors. The default is the first\n" - " free space.\n"), stdout); + fputs(_(" begin of the partition in sectors or bytes if specified\n" + " in format {K,M,G,T,P,E,Z,Y}. The default is\n" + " the first free space.\n"), stdout); fputc('\n', stdout); fputs(_(" size of the partition in sectors if specified in format\n" diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index c75494a2e2..684c014012 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -641,9 +641,12 @@ static int parse_script_line(struct fdisk_script *dp, char *s) p = (char *) skip_blank(p); if (!strncasecmp(p, "start=", 6)) { + int pow = 0; p += 6; - rc = next_number(&p, &num, NULL); + rc = next_number(&p, &num, &pow); if (!rc) { + if (pow) /* specified as */ + num /= dp->cxt->sector_size; fdisk_partition_set_start(pa, num); fdisk_partition_start_follow_default(pa, 0); } @@ -800,9 +803,13 @@ static int parse_commas_line(struct fdisk_script *dp, char *s) if (*p == ',' || *p == ';') fdisk_partition_start_follow_default(pa, 1); else { - rc = next_number(&p, &num, NULL); - if (!rc) + int pow = 0; + rc = next_number(&p, &num, &pow); + if (!rc) { + if (pow) /* specified as */ + num /= dp->cxt->sector_size; fdisk_partition_set_start(pa, num); + } fdisk_partition_start_follow_default(pa, 0); } break; -- 2.47.2