]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) improve first unused sector for logical partitions
authorKarel Zak <kzak@redhat.com>
Mon, 18 Feb 2019 15:38:11 +0000 (16:38 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Feb 2019 15:38:11 +0000 (16:38 +0100)
Make sure we probe within extended partition.

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

index 8e9678da3e1e979369894babb4239a9a9b279af3..4f81970db9d8a5538a27189106b2e09dd374ce12 100644 (file)
@@ -913,6 +913,13 @@ static fdisk_sector_t get_unused_start(struct fdisk_context *cxt,
 {
        size_t i;
 
+       if (part_n >= 4) {
+               struct fdisk_dos_label *l = self_label(cxt);
+               fdisk_sector_t ex_start = l->ext_offset + cxt->first_lba;
+               if (start < ex_start)
+                       start = ex_start;
+       }
+
        for (i = 0; i < cxt->label->nparts_max; i++) {
                fdisk_sector_t lastplusoff;
                struct pte *pe = self_pte(cxt, i);
@@ -925,6 +932,8 @@ static fdisk_sector_t get_unused_start(struct fdisk_context *cxt,
                        start = lastplusoff + 1;
        }
 
+       DBG(LABEL, ul_debug("DOS: fist unused start for #%d is %ju",
+                               part_n, (uintmax_t) start));
        return start;
 }
 
@@ -939,7 +948,7 @@ static void fill_bounds(struct fdisk_context *cxt,
        for (i = 0; i < cxt->label->nparts_max; pe++,i++) {
                p = pe->pt_entry;
                if (is_cleared_partition(p) || IS_EXTENDED (p->sys_ind)) {
-                       first[i] = 0xffffffff;
+                       first[i] = SIZE_MAX;
                        last[i] = 0;
                } else {
                        first[i] = get_abs_partition_start(pe);