]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: use grain as small as possible
authorKarel Zak <kzak@redhat.com>
Fri, 6 Sep 2019 11:09:30 +0000 (13:09 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 6 Sep 2019 11:09:30 +0000 (13:09 +0200)
The current implementation does not allow to move partition for
example in +/-1 sector range, because free space analyze is by default
based on regular grain used for partitioning (=1MiB).

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/partition.c
libfdisk/src/table.c

index 80a43ffde52c5ca26d36a61f7fdeeb01d9e7e6a1..7cfca3fa40dbadc2678a2322abfb38d9fa1fc44f 100644 (file)
@@ -1160,8 +1160,15 @@ static int recount_resize(
        FDISK_INIT_UNDEF(size);
 
        rc = fdisk_get_partitions(cxt, &tb);
-       if (!rc)
+       if (!rc) {
+               /* For resize we do not follow grain to detect free-space, but
+                * we allow to resize with very small granulation. */
+               unsigned long org = cxt->grain;
+
+               cxt->grain = cxt->sector_size;
                rc = fdisk_get_freespaces(cxt, &tb);
+               cxt->grain = org;
+       }
        if (rc) {
                fdisk_unref_table(tb);
                return rc;
@@ -1258,7 +1265,7 @@ static int recount_resize(
                        goto erange;
        }
 
-       if (!FDISK_IS_UNDEF(size)) {
+       if (FDISK_IS_UNDEF(size)) {
                DBG(PART, ul_debugobj(tpl, "resize: size unchanged (undefined)"));
        }
 
index 8a3a935af9229364638096c2f6a1649a9510fec4..e78ecc4372756450728a4e9fc54867e1cf574fd2 100644 (file)
@@ -646,7 +646,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
 
        /* add free-space behind last partition to the end of the table (so
         * don't use table_add_freespace()) */
-       if (rc == 0 && last + grain < cxt->total_sectors - 1) {
+       if (rc == 0 && last + grain < cxt->last_lba - 1) {
                DBG(CXT, ul_debugobj(cxt, "freespace behind last partition detected"));
                rc = new_freespace(cxt,
                        last + (last > cxt->first_lba || nparts ? 1 : 0),