summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-01-20 14:10:08 +0100
committerKarel Zak2015-01-20 14:20:47 +0100
commitce9f568c25cc444a8796c599f2539864ab666d5f (patch)
tree541e928dd4c1d3e5a05e3decacbfde90cebde21a
parentlibfdisk: (docs) fix typo (diff)
downloadkernel-qcow2-util-linux-ce9f568c25cc444a8796c599f2539864ab666d5f.tar.gz
kernel-qcow2-util-linux-ce9f568c25cc444a8796c599f2539864ab666d5f.tar.xz
kernel-qcow2-util-linux-ce9f568c25cc444a8796c599f2539864ab666d5f.zip
libfdisk: accept Start offset in {B,M,G..}iB in sfdisk scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--disk-utils/sfdisk.88
-rw-r--r--disk-utils/sfdisk.c5
-rw-r--r--libfdisk/src/script.c13
3 files changed, 19 insertions, 7 deletions
diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8
index 5f9eba48b..bb0ba83dc 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 86c8b669f..4142181d3 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -946,8 +946,9 @@ static void command_fdisk_help(void)
fputs(_(" <start>, <size>, <typy>, <bootable>\n"), stdout);
fputc('\n', stdout);
- fputs(_(" <start> begin of the partition in sectors. The default is the first\n"
- " free space.\n"), stdout);
+ fputs(_(" <start> begin of the partition in sectors or bytes if specified\n"
+ " in format <number>{K,M,G,T,P,E,Z,Y}. The default is\n"
+ " the first free space.\n"), stdout);
fputc('\n', stdout);
fputs(_(" <size> size of the partition in sectors if specified in format\n"
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index c75494a2e..684c01401 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><suffix> */
+ 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><suffix> */
+ num /= dp->cxt->sector_size;
fdisk_partition_set_start(pa, num);
+ }
fdisk_partition_start_follow_default(pa, 0);
}
break;