start = fdisk_partition_get_start(pa);
size = dflt_size = fdisk_partition_get_size(pa) * fdisk_get_sector_size(cf->cxt);
- if (ui_get_size(cf, _("Partition size: "), &size, 1, size, &expsize)
- == -CFDISK_ERR_ESC)
+ if (ui_get_size(cf, _("Partition size: "), &size,
+ fdisk_get_sector_size(cf->cxt),
+ size, &expsize) == -CFDISK_ERR_ESC)
break;
secs = size / fdisk_get_sector_size(cf->cxt);
offset = pe->offset;
}
- DBG(LABEL, ul_debug("DOS: setting partition %d%s, offset=%zu, start=%zu, stop=%zu, sysid=%02x",
+ DBG(LABEL, ul_debug("DOS: setting partition %d%s, offset=%zu, start=%zu, size=%zu, sysid=%02x",
i, doext ? " [extended]" : "",
(size_t) offset,
(size_t) (start - offset),
* align the end of the partition. The next partition
* will start at phy.block boundary.
*/
- stop = fdisk_align_lba_in_range(cxt, stop, start, limit) - 1;
+ stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
+ if (stop > start)
+ stop -= 1;
if (stop > limit)
stop = limit;
+ DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
}
}
if (!cxt->label->op->get_part)
return -ENOSYS;
- DBG(CXT, ul_debugobj(cxt, "get table"));
+ DBG(CXT, ul_debugobj(cxt, " -- get table --"));
if (!*tb && !(*tb = fdisk_new_table()))
return -ENOMEM;
int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
{
int rc = 0;
+ size_t nparts = 0;
fdisk_sector_t last, grain;
struct fdisk_table *parts = NULL;
struct fdisk_partition *pa;
struct fdisk_iter itr;
- DBG(CXT, ul_debugobj(cxt, "get freespace"));
+ DBG(CXT, ul_debugobj(cxt, "-- get freespace --"));
if (!cxt || !cxt->label || !tb)
return -EINVAL;
if (fdisk_partition_is_container(pa))
rc = check_container_freespace(cxt, parts, *tb, pa);
last = fdisk_partition_get_end(pa);
+ nparts++;
}
/* add free-space behind last partition to the end of the table (so
if (rc == 0 && last + grain < cxt->total_sectors - 1) {
DBG(CXT, ul_debugobj(cxt, "freespace behind last partition detected"));
rc = new_freespace(cxt,
- last + (last > cxt->first_lba ? 1 : 0),
+ last + (last > cxt->first_lba || nparts ? 1 : 0),
cxt->last_lba, NULL, &pa);
if (pa) {
fdisk_table_add_partition(*tb, pa);