diff options
author | Mikhail Vorobyov | 2017-11-09 04:47:16 +0100 |
---|---|---|
committer | Karel Zak | 2017-11-16 14:11:19 +0100 |
commit | 9e6ccaab5b1ea503512842a77824acf63214077e (patch) | |
tree | 071a525aa9409bd7a7379c63eca165b8e2fead76 /libfdisk | |
parent | libfdisk: (sun) move aligning of the first sector before availability check (diff) | |
download | kernel-qcow2-util-linux-9e6ccaab5b1ea503512842a77824acf63214077e.tar.gz kernel-qcow2-util-linux-9e6ccaab5b1ea503512842a77824acf63214077e.tar.xz kernel-qcow2-util-linux-9e6ccaab5b1ea503512842a77824acf63214077e.zip |
libfdisk: (sun) enhance searching of free space
Potential partition start should be aligned to cylinders. So fdisk
wouldn't consider partition's last cylinder remains as eligible space
for new partition start.
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/sun.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index 7ffd364f4..923b73e32 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -326,6 +326,7 @@ static void fetch_sun(struct fdisk_context *cxt, struct sun_disklabel *sunlabel; int continuous = 1; size_t i; + int sectors_per_cylinder = cxt->geom.heads * cxt->geom.sectors; assert(cxt); assert(cxt); @@ -335,7 +336,7 @@ static void fetch_sun(struct fdisk_context *cxt, sunlabel = self_disklabel(cxt); *start = 0; - *stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors; + *stop = cxt->geom.cylinders * sectors_per_cylinder; for (i = 0; i < cxt->label->nparts_max; i++) { struct sun_partition *part = &sunlabel->partitions[i]; @@ -345,12 +346,16 @@ static void fetch_sun(struct fdisk_context *cxt, be16_to_cpu(info->id) != SUN_TAG_UNASSIGNED && be16_to_cpu(info->id) != SUN_TAG_WHOLEDISK) { starts[i] = be32_to_cpu(part->start_cylinder) * - cxt->geom.heads * cxt->geom.sectors; + sectors_per_cylinder; lens[i] = be32_to_cpu(part->num_sectors); if (continuous) { - if (starts[i] == *start) + if (starts[i] == *start) { *start += lens[i]; - else if (starts[i] + lens[i] >= *stop) + int remained_sectors = *start % sectors_per_cylinder; + if (remained_sectors) { + *start += sectors_per_cylinder - remained_sectors; + } + } else if (starts[i] + lens[i] >= *stop) *stop = starts[i]; else continuous = 0; |