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().
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user