diff options
-rw-r--r-- | disk-utils/cfdisk.c | 5 | ||||
-rw-r--r-- | libfdisk/src/dos.c | 7 | ||||
-rw-r--r-- | libfdisk/src/table.c | 8 |
3 files changed, 13 insertions, 7 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index eec8eba6e..911b6c8b4 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -1964,8 +1964,9 @@ static int main_menu_action(struct cfdisk *cf, int key) 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); diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index e6f4e4f8c..73b985b88 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -852,7 +852,7 @@ static void set_partition(struct fdisk_context *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), @@ -1204,9 +1204,12 @@ static int add_partition(struct fdisk_context *cxt, size_t n, * 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)); } } diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index 858e258b1..121cd3d86 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -289,7 +289,7 @@ int fdisk_get_partitions(struct fdisk_context *cxt, struct fdisk_table **tb) 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; @@ -537,12 +537,13 @@ done: 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; @@ -581,6 +582,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb) 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 @@ -588,7 +590,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb) 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); |