sfdisk: fix --append to PT with gaps
sfdisk trying to be more smart than libfdisk when analyze if we can append to the current PT. libfdisk is able to use unused partition to create a new one (if partno not strictly specified), but sfdisk assumes that we can add partition to extended partition only. Addresses: https://github.com/calamares/calamares/issues/1332 Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
940928c9f1
commit
fa3fface0f
|
@ -112,6 +112,7 @@ struct sfdisk {
|
||||||
force : 1, /* do also stupid things */
|
force : 1, /* do also stupid things */
|
||||||
backup : 1, /* backup sectors before write PT */
|
backup : 1, /* backup sectors before write PT */
|
||||||
container : 1, /* PT contains container (MBR extended) partitions */
|
container : 1, /* PT contains container (MBR extended) partitions */
|
||||||
|
unused : 1, /* PT contains unused partition */
|
||||||
append : 1, /* don't create new PT, append partitions only */
|
append : 1, /* don't create new PT, append partitions only */
|
||||||
json : 1, /* JSON dump */
|
json : 1, /* JSON dump */
|
||||||
movedata: 1, /* move data after resize */
|
movedata: 1, /* move data after resize */
|
||||||
|
@ -1519,26 +1520,26 @@ static int loop_control_commands(struct sfdisk *sf,
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_container(struct sfdisk *sf)
|
static int has_container_or_unused(struct sfdisk *sf)
|
||||||
{
|
{
|
||||||
size_t i, nparts;
|
size_t i, nparts;
|
||||||
struct fdisk_partition *pa = NULL;
|
struct fdisk_partition *pa = NULL;
|
||||||
|
|
||||||
if (sf->container)
|
if (sf->container || sf->unused)
|
||||||
return sf->container;
|
return 1;
|
||||||
|
|
||||||
nparts = fdisk_get_npartitions(sf->cxt);
|
nparts = fdisk_get_npartitions(sf->cxt);
|
||||||
for (i = 0; i < nparts; i++) {
|
for (i = 0; i < nparts; i++) {
|
||||||
if (fdisk_get_partition(sf->cxt, i, &pa) != 0)
|
if (fdisk_get_partition(sf->cxt, i, &pa) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (fdisk_partition_is_container(pa)) {
|
if (!fdisk_partition_is_used(pa))
|
||||||
|
sf->unused = 1;
|
||||||
|
if (fdisk_partition_is_container(pa))
|
||||||
sf->container = 1;
|
sf->container = 1;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fdisk_unref_partition(pa);
|
fdisk_unref_partition(pa);
|
||||||
return sf->container;
|
return sf->container || sf->unused;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t last_pt_partno(struct sfdisk *sf)
|
static size_t last_pt_partno(struct sfdisk *sf)
|
||||||
|
@ -1839,7 +1840,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
|
||||||
if (created
|
if (created
|
||||||
&& partno < 0
|
&& partno < 0
|
||||||
&& next_partno == fdisk_get_npartitions(sf->cxt)
|
&& next_partno == fdisk_get_npartitions(sf->cxt)
|
||||||
&& !has_container(sf)) {
|
&& has_container_or_unused(sf)) {
|
||||||
fdisk_info(sf->cxt, _("All partitions used."));
|
fdisk_info(sf->cxt, _("All partitions used."));
|
||||||
rc = SFDISK_DONE_ASK;
|
rc = SFDISK_DONE_ASK;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue