]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix issues with very small partitions
authorKarel Zak <kzak@redhat.com>
Tue, 3 Feb 2015 11:44:00 +0000 (12:44 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Feb 2015 11:44:00 +0000 (12:44 +0100)
 - cfdisk: minimal partitions size is 1 sector
 - dos: when align last sector then don't set partition size to zero
   for very small partitions.
 - don't ignore tiny partitions before free space when define
   free-space start offset
 - improve some debug messages

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
libfdisk/src/dos.c
libfdisk/src/table.c

index eec8eba6e42e4732dfa287d9d805b6eb30a12105..911b6c8b44eac661732705f87fce50787d19bf44 100644 (file)
@@ -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);
index e6f4e4f8c49619528513f08e7de73f57ce1fb0aa..73b985b884b393cf70728e776e34c1e192c10030 100644 (file)
@@ -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));
                }
        }
 
index 858e258b16c06f21b64c607b1d39e8980177da9d..121cd3d86b2346003692d6955bcec2f38c863cfc 100644 (file)
@@ -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);