]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: accept Start offset in {B,M,G..}iB in sfdisk scripts
authorKarel Zak <kzak@redhat.com>
Tue, 20 Jan 2015 13:10:08 +0000 (14:10 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Jan 2015 13:20:47 +0000 (14:20 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.8
disk-utils/sfdisk.c
libfdisk/src/script.c

index 5f9eba48bd37145de3f38496d604a73fd6a3d445..bb0ba83dc46eafb88743ece611477cd9e85f039b 100644 (file)
@@ -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
index 86c8b669fa40cfc9c26cc4f92ba9c1a1b8eaa1f9..4142181d3e0919e9d62930d757a1f1e361b758b9 100644 (file)
@@ -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"
index c75494a2e2d6c37e083b5ebc66524f3ebb4816c7..684c0140125138f434f5ec4c7232965868abbe37 100644 (file)
@@ -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;