summaryrefslogtreecommitdiff
path: root/src/sysupdate
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-10-13 21:26:16 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-11-15 13:27:15 +0100
commit22e932f4d15f59ae773370a41a1c01ec93f8915a (patch)
tree0bfee6687fc6f1a16b24b656c1534d4d80db776f /src/sysupdate
parentbef69ae8780da17a807881d078247259170f868e (diff)
downloadsystemd-22e932f4d15f59ae773370a41a1c01ec93f8915a.tar.gz
gpt: Expose GptPartitionType and get rid of SECONDARY/OTHER
Instead of exposing just the partition type UUID, let's expose the GptPartitionType struct, which has a lot more information available in a much more accessible way. Also, let's get rid of SECONDARY/OTHER in PartitionDesignator. These were only there to support preferred architectures in dissect-image.c, but we can easily handle that by comparing architectures when we decide whether to override a partition. This is done in a new function compare_arch().
Diffstat (limited to 'src/sysupdate')
-rw-r--r--src/sysupdate/sysupdate-partition.c18
-rw-r--r--src/sysupdate/sysupdate-resource.c2
-rw-r--r--src/sysupdate/sysupdate-resource.h5
-rw-r--r--src/sysupdate/sysupdate-transfer.c16
4 files changed, 23 insertions, 18 deletions
diff --git a/src/sysupdate/sysupdate-partition.c b/src/sysupdate/sysupdate-partition.c
index fa46574fd6..33d0e584ba 100644
--- a/src/sysupdate/sysupdate-partition.c
+++ b/src/sysupdate/sysupdate-partition.c
@@ -111,6 +111,7 @@ int read_partition_info(
struct fdisk_parttype *pt;
uint64_t start, size, flags;
sd_id128_t ptid, id;
+ GptPartitionType type;
size_t partno;
int r;
@@ -178,6 +179,8 @@ int read_partition_info(
if (!label_copy)
return log_oom();
+ type = gpt_partition_type_from_uuid(ptid);
+
*ret = (PartitionInfo) {
.partno = partno,
.start = start,
@@ -187,9 +190,9 @@ int read_partition_info(
.uuid = id,
.label = TAKE_PTR(label_copy),
.device = TAKE_PTR(device),
- .no_auto = FLAGS_SET(flags, SD_GPT_FLAG_NO_AUTO) && gpt_partition_type_knows_no_auto(ptid),
- .read_only = FLAGS_SET(flags, SD_GPT_FLAG_READ_ONLY) && gpt_partition_type_knows_read_only(ptid),
- .growfs = FLAGS_SET(flags, SD_GPT_FLAG_GROWFS) && gpt_partition_type_knows_growfs(ptid),
+ .no_auto = FLAGS_SET(flags, SD_GPT_FLAG_NO_AUTO) && gpt_partition_type_knows_no_auto(type),
+ .read_only = FLAGS_SET(flags, SD_GPT_FLAG_READ_ONLY) && gpt_partition_type_knows_read_only(type),
+ .growfs = FLAGS_SET(flags, SD_GPT_FLAG_GROWFS) && gpt_partition_type_knows_growfs(type),
};
return 1; /* found! */
@@ -269,6 +272,7 @@ int patch_partition(
_cleanup_(fdisk_unref_partitionp) struct fdisk_partition *pa = NULL;
_cleanup_(fdisk_unref_contextp) struct fdisk_context *c = NULL;
bool tweak_no_auto, tweak_read_only, tweak_growfs;
+ GptPartitionType type;
int r, fd;
assert(device);
@@ -313,16 +317,18 @@ int patch_partition(
return log_error_errno(r, "Failed to update partition UUID: %m");
}
+ type = gpt_partition_type_from_uuid(info->type);
+
/* Tweak the read-only flag, but only if supported by the partition type */
tweak_no_auto =
FLAGS_SET(change, PARTITION_NO_AUTO) &&
- gpt_partition_type_knows_no_auto(info->type);
+ gpt_partition_type_knows_no_auto(type);
tweak_read_only =
FLAGS_SET(change, PARTITION_READ_ONLY) &&
- gpt_partition_type_knows_read_only(info->type);
+ gpt_partition_type_knows_read_only(type);
tweak_growfs =
FLAGS_SET(change, PARTITION_GROWFS) &&
- gpt_partition_type_knows_growfs(info->type);
+ gpt_partition_type_knows_growfs(type);
if (change & PARTITION_FLAGS) {
uint64_t flags;
diff --git a/src/sysupdate/sysupdate-resource.c b/src/sysupdate/sysupdate-resource.c
index 8104e9c82e..bf521980e2 100644
--- a/src/sysupdate/sysupdate-resource.c
+++ b/src/sysupdate/sysupdate-resource.c
@@ -194,7 +194,7 @@ static int resource_load_from_blockdev(Resource *rr) {
continue;
/* Check if partition type matches */
- if (rr->partition_type_set && !sd_id128_equal(pinfo.type, rr->partition_type))
+ if (rr->partition_type_set && !sd_id128_equal(pinfo.type, rr->partition_type.uuid))
continue;
/* A label of "_empty" means "not used so far" for us */
diff --git a/src/sysupdate/sysupdate-resource.h b/src/sysupdate/sysupdate-resource.h
index 86be0d3389..3209988c24 100644
--- a/src/sysupdate/sysupdate-resource.h
+++ b/src/sysupdate/sysupdate-resource.h
@@ -5,8 +5,7 @@
#include <stdbool.h>
#include <sys/types.h>
-#include "sd-id128.h"
-
+#include "gpt.h"
#include "hashmap.h"
#include "macro.h"
@@ -74,7 +73,7 @@ struct Resource {
char *path;
bool path_auto; /* automatically find root path (only available if target resource, not source resource) */
char **patterns;
- sd_id128_t partition_type;
+ GptPartitionType partition_type;
bool partition_type_set;
/* All instances of this resource we found */
diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c
index d6705cd12e..0c3d65a00d 100644
--- a/src/sysupdate/sysupdate-transfer.c
+++ b/src/sysupdate/sysupdate-transfer.c
@@ -344,7 +344,7 @@ static int config_parse_resource_ptype(
assert(rvalue);
- r = gpt_partition_type_uuid_from_string(rvalue, &rr->partition_type);
+ r = gpt_partition_type_from_string(rvalue, &rr->partition_type);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed parse partition type, ignoring: %s", rvalue);
@@ -654,18 +654,18 @@ int transfer_vacuum(
if (t->target.n_empty + t->target.n_instances < 2)
return log_error_errno(SYNTHETIC_ERRNO(ENOSPC),
"Partition table has less than two partition slots of the right type " SD_ID128_UUID_FORMAT_STR " (%s), refusing.",
- SD_ID128_FORMAT_VAL(t->target.partition_type),
- gpt_partition_type_uuid_to_string(t->target.partition_type));
+ SD_ID128_FORMAT_VAL(t->target.partition_type.uuid),
+ gpt_partition_type_uuid_to_string(t->target.partition_type.uuid));
if (space > t->target.n_empty + t->target.n_instances)
return log_error_errno(SYNTHETIC_ERRNO(ENOSPC),
"Partition table does not have enough partition slots of right type " SD_ID128_UUID_FORMAT_STR " (%s) for operation.",
- SD_ID128_FORMAT_VAL(t->target.partition_type),
- gpt_partition_type_uuid_to_string(t->target.partition_type));
+ SD_ID128_FORMAT_VAL(t->target.partition_type.uuid),
+ gpt_partition_type_uuid_to_string(t->target.partition_type.uuid));
if (space == t->target.n_empty + t->target.n_instances)
return log_error_errno(SYNTHETIC_ERRNO(ENOSPC),
"Asked to empty all partition table slots of the right type " SD_ID128_UUID_FORMAT_STR " (%s), can't allow that. One instance must always remain.",
- SD_ID128_FORMAT_VAL(t->target.partition_type),
- gpt_partition_type_uuid_to_string(t->target.partition_type));
+ SD_ID128_FORMAT_VAL(t->target.partition_type.uuid),
+ gpt_partition_type_uuid_to_string(t->target.partition_type.uuid));
rm = LESS_BY(space, t->target.n_empty);
remain = LESS_BY(t->target.n_instances, rm);
@@ -858,7 +858,7 @@ int transfer_acquire_instance(Transfer *t, Instance *i) {
r = find_suitable_partition(
t->target.path,
i->metadata.size,
- t->target.partition_type_set ? &t->target.partition_type : NULL,
+ t->target.partition_type_set ? &t->target.partition_type.uuid : NULL,
&t->partition_info);
if (r < 0)
return r;