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>
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;
goto erange;
}
- if (!FDISK_IS_UNDEF(size)) {
+ if (FDISK_IS_UNDEF(size)) {
DBG(PART, ul_debugobj(tpl, "resize: size unchanged (undefined)"));
}
/* 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),