libfdisk: (gpt) don't align last possible LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
73b7c331b3
commit
ee50336c03
|
@ -106,15 +106,25 @@ sector_t fdisk_align_lba(struct fdisk_context *cxt, sector_t lba, int direction)
|
||||||
sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
|
sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
|
||||||
sector_t lba, sector_t start, sector_t stop)
|
sector_t lba, sector_t start, sector_t stop)
|
||||||
{
|
{
|
||||||
|
sector_t res;
|
||||||
|
|
||||||
start = fdisk_align_lba(cxt, start, FDISK_ALIGN_UP);
|
start = fdisk_align_lba(cxt, start, FDISK_ALIGN_UP);
|
||||||
stop = fdisk_align_lba(cxt, stop, FDISK_ALIGN_DOWN);
|
stop = fdisk_align_lba(cxt, stop, FDISK_ALIGN_DOWN);
|
||||||
lba = fdisk_align_lba(cxt, lba, FDISK_ALIGN_NEAREST);
|
lba = fdisk_align_lba(cxt, lba, FDISK_ALIGN_NEAREST);
|
||||||
|
|
||||||
if (lba < start)
|
if (lba < start)
|
||||||
return start;
|
res = start;
|
||||||
else if (lba > stop)
|
else if (lba > stop)
|
||||||
return stop;
|
res = stop;
|
||||||
return lba;
|
else
|
||||||
|
res = lba;
|
||||||
|
|
||||||
|
DBG(CXT, ul_debugobj(cxt, "LBA %ju range:<%ju..%ju>, result: %ju",
|
||||||
|
(uintmax_t) lba,
|
||||||
|
(uintmax_t) start,
|
||||||
|
(uintmax_t) stop,
|
||||||
|
(uintmax_t) res));
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1803,6 +1803,7 @@ static int gpt_add_partition(
|
||||||
|
|
||||||
/* first sector */
|
/* first sector */
|
||||||
if (pa && pa->start) {
|
if (pa && pa->start) {
|
||||||
|
DBG(LABEL, ul_debug("first sector defined: %ju", pa->start));
|
||||||
if (pa->start != find_first_available(pheader, ents, pa->start)) {
|
if (pa->start != find_first_available(pheader, ents, pa->start)) {
|
||||||
fdisk_warnx(cxt, _("Sector %ju already used."), pa->start);
|
fdisk_warnx(cxt, _("Sector %ju already used."), pa->start);
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
|
@ -1843,13 +1844,11 @@ static int gpt_add_partition(
|
||||||
dflt_l = find_last_free(pheader, ents, user_f);
|
dflt_l = find_last_free(pheader, ents, user_f);
|
||||||
|
|
||||||
if (pa && pa->size) {
|
if (pa && pa->size) {
|
||||||
user_l = user_f + pa->size;
|
user_l = user_f + pa->size - 1;
|
||||||
user_l = fdisk_align_lba_in_range(cxt, user_l, user_f, dflt_l) - 1;
|
DBG(LABEL, ul_debug("size defined: %ju, end: %ju (last possible: %ju)",
|
||||||
|
pa->size, user_l, dflt_l));
|
||||||
/* no space for anything useful, use all space
|
if (user_l != dflt_l)
|
||||||
if (user_l + (cxt->grain / cxt->sector_size) > dflt_l)
|
user_l = fdisk_align_lba_in_range(cxt, user_l, user_f, dflt_l) - 1;
|
||||||
user_l = dflt_l;
|
|
||||||
*/
|
|
||||||
|
|
||||||
} else if (pa && pa->end_follow_default) {
|
} else if (pa && pa->end_follow_default) {
|
||||||
user_l = dflt_l;
|
user_l = dflt_l;
|
||||||
|
@ -1885,8 +1884,6 @@ static int gpt_add_partition(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG(LABEL, ul_debug("GPT new partition: partno=%zu, start=%ju, end=%ju",
|
|
||||||
partnum, user_f, user_l));
|
|
||||||
|
|
||||||
if (user_f > user_l || partnum >= cxt->label->nparts_max) {
|
if (user_f > user_l || partnum >= cxt->label->nparts_max) {
|
||||||
fdisk_warnx(cxt, _("Could not create partition %zu"), partnum + 1);
|
fdisk_warnx(cxt, _("Could not create partition %zu"), partnum + 1);
|
||||||
|
@ -1919,6 +1916,12 @@ static int gpt_add_partition(
|
||||||
if (pa && pa->name && *pa->name)
|
if (pa && pa->name && *pa->name)
|
||||||
gpt_entry_set_name(e, pa->name);
|
gpt_entry_set_name(e, pa->name);
|
||||||
|
|
||||||
|
DBG(LABEL, ul_debug("GPT new partition: partno=%zu, start=%ju, end=%ju, size=%ju",
|
||||||
|
partnum,
|
||||||
|
gpt_partition_start(e),
|
||||||
|
gpt_partition_end(e),
|
||||||
|
gpt_partition_size(e)));
|
||||||
|
|
||||||
gpt_recompute_crc(gpt->pheader, ents);
|
gpt_recompute_crc(gpt->pheader, ents);
|
||||||
gpt_recompute_crc(gpt->bheader, ents);
|
gpt_recompute_crc(gpt->bheader, ents);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue