if (have_uuid)
id = gpt_partition_type_uuid_to_string(uuid) ?: "XYZ";
else {
- r = gpt_partition_type_uuid_from_string(*p, &uuid);
+ GptPartitionType type;
+
+ r = gpt_partition_type_from_string(*p, &type);
if (r < 0)
return log_error_errno(r, "Unknown identifier \"%s\".", *p);
+ uuid = type.uuid;
id = *p;
}
char *definition_path;
char **drop_in_files;
- sd_id128_t type_uuid;
+ GptPartitionType type;
sd_id128_t current_uuid, new_uuid;
bool new_uuid_is_set;
char *current_label, *new_label;
void *data,
void *userdata) {
- sd_id128_t *type_uuid = ASSERT_PTR(data);
+ GptPartitionType *type = ASSERT_PTR(data);
int r;
assert(rvalue);
- r = gpt_partition_type_uuid_from_string(rvalue, type_uuid);
+ r = gpt_partition_type_from_string(rvalue, type);
if (r < 0)
return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse partition type: %s", rvalue);
static int partition_read_definition(Partition *p, const char *path, const char *const *conf_file_dirs) {
ConfigTableItem table[] = {
- { "Partition", "Type", config_parse_type, 0, &p->type_uuid },
+ { "Partition", "Type", config_parse_type, 0, &p->type },
{ "Partition", "Label", config_parse_label, 0, &p->new_label },
{ "Partition", "UUID", config_parse_uuid, 0, p },
{ "Partition", "Priority", config_parse_int32, 0, &p->priority },
return log_syntax(NULL, LOG_ERR, path, 1, SYNTHETIC_ERRNO(EINVAL),
"PaddingMinBytes= larger than PaddingMaxBytes=, refusing.");
- if (sd_id128_is_null(p->type_uuid))
+ if (sd_id128_is_null(p->type.uuid))
return log_syntax(NULL, LOG_ERR, path, 1, SYNTHETIC_ERRNO(EINVAL),
"Type= not defined, refusing.");
verity_mode_to_string(p->verity));
/* Verity partitions are read only, let's imply the RO flag hence, unless explicitly configured otherwise. */
- if ((gpt_partition_type_is_root_verity(p->type_uuid) ||
- gpt_partition_type_is_usr_verity(p->type_uuid)) &&
+ if ((p->type.designator == PARTITION_ROOT_VERITY ||
+ p->type.designator == PARTITION_USR_VERITY) &&
p->read_only < 0)
p->read_only = true;
/* Default to "growfs" on, unless read-only */
- if (gpt_partition_type_knows_growfs(p->type_uuid) &&
+ if (gpt_partition_type_knows_growfs(p->type) &&
p->read_only <= 0)
p->growfs = true;
LIST_FOREACH(partitions, pp, context->partitions) {
last = pp;
- if (!sd_id128_equal(pp->type_uuid, ptid))
+ if (!sd_id128_equal(pp->type.uuid, ptid))
continue;
if (!pp->current_partition) {
return log_oom();
np->current_uuid = id;
- np->type_uuid = ptid;
+ np->type = gpt_partition_type_from_uuid(ptid);
np->current_size = sz;
np->offset = start;
np->partno = partno;
if (p->current_label)
return p->current_label;
- return gpt_partition_type_uuid_to_string(p->type_uuid);
+ return gpt_partition_type_uuid_to_string(p->type.uuid);
}
static int context_dump_partitions(Context *context, const char *node) {
r = table_add_many(
t,
- TABLE_STRING, gpt_partition_type_uuid_to_string_harder(p->type_uuid, uuid_buffer),
+ TABLE_STRING, gpt_partition_type_uuid_to_string_harder(p->type.uuid, uuid_buffer),
TABLE_STRING, empty_to_null(label) ?: "-", TABLE_SET_COLOR, empty_to_null(label) ? NULL : ansi_grey(),
TABLE_UUID, p->new_uuid_is_set ? p->new_uuid : p->current_uuid,
TABLE_STRING, p->definition_path ? basename(p->definition_path) : "-", TABLE_SET_COLOR, p->definition_path ? NULL : ansi_grey(),
else if (!sd_id128_is_null(p->current_uuid))
id = p->current_uuid;
else
- id = p->type_uuid;
+ id = p->type.uuid;
buf = strdup(SD_ID128_TO_UUID_STRING(id));
assert(ret);
LIST_FOREACH(partitions, p, context->partitions) {
- const char *sources = gpt_partition_type_mountpoint_nulstr(p->type_uuid);
+ const char *sources = gpt_partition_type_mountpoint_nulstr(p->type);
if (!sources)
continue;
if (p == q)
break;
- if (!sd_id128_equal(p->type_uuid, q->type_uuid))
+ if (!sd_id128_equal(p->type.uuid, q->type.uuid))
continue;
k++;
}
- plaintext.type_uuid = p->type_uuid;
+ plaintext.type_uuid = p->type.uuid;
plaintext.counter = htole64(k);
hmac_sha256(context->seed.bytes, sizeof(context->seed.bytes),
assert(p);
assert(ret);
- prefix = gpt_partition_type_uuid_to_string(p->type_uuid);
+ prefix = gpt_partition_type_uuid_to_string(p->type.uuid);
if (!prefix)
prefix = "linux";
f = p->gpt_flags;
if (p->no_auto >= 0) {
- if (gpt_partition_type_knows_no_auto(p->type_uuid))
+ if (gpt_partition_type_knows_no_auto(p->type))
SET_FLAG(f, SD_GPT_FLAG_NO_AUTO, p->no_auto);
else {
char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured NoAuto=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->no_auto),
- gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
+ gpt_partition_type_uuid_to_string_harder(p->type.uuid, buffer));
}
}
if (p->read_only >= 0) {
- if (gpt_partition_type_knows_read_only(p->type_uuid))
+ if (gpt_partition_type_knows_read_only(p->type))
SET_FLAG(f, SD_GPT_FLAG_READ_ONLY, p->read_only);
else {
char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured ReadOnly=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->read_only),
- gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
+ gpt_partition_type_uuid_to_string_harder(p->type.uuid, buffer));
}
}
if (p->growfs >= 0) {
- if (gpt_partition_type_knows_growfs(p->type_uuid))
+ if (gpt_partition_type_knows_growfs(p->type))
SET_FLAG(f, SD_GPT_FLAG_GROWFS, p->growfs);
else {
char buffer[SD_ID128_UUID_STRING_MAX];
log_warning("Configured GrowFileSystem=%s for partition type '%s' that doesn't support it, ignoring.",
yes_no(p->growfs),
- gpt_partition_type_uuid_to_string_harder(p->type_uuid, buffer));
+ gpt_partition_type_uuid_to_string_harder(p->type.uuid, buffer));
}
}
if (!t)
return log_oom();
- r = fdisk_parttype_set_typestr(t, SD_ID128_TO_UUID_STRING(p->type_uuid));
+ r = fdisk_parttype_set_typestr(t, SD_ID128_TO_UUID_STRING(p->type.uuid));
if (r < 0)
return log_error_errno(r, "Failed to initialize partition type: %m");
assert(p);
const Specifier table[] = {
- { 't', specifier_string, GPT_PARTITION_TYPE_UUID_TO_STRING_HARDER(p->type_uuid) },
- { 'T', specifier_id128, &p->type_uuid },
+ { 't', specifier_string, GPT_PARTITION_TYPE_UUID_TO_STRING_HARDER(p->type.uuid) },
+ { 'T', specifier_id128, &p->type.uuid },
{ 'U', specifier_id128, &p->new_uuid },
{ 'n', specifier_uint64, &p->partno },
static int resolve_copy_blocks_auto_candidate(
dev_t partition_devno,
- sd_id128_t partition_type_uuid,
+ GptPartitionType partition_type,
dev_t restrict_devno,
sd_id128_t *ret_uuid) {
return false;
}
- if (!sd_id128_equal(pt_parsed, partition_type_uuid)) {
+ if (!sd_id128_equal(pt_parsed, partition_type.uuid)) {
log_debug("Partition %u:%u has non-matching partition type " SD_ID128_FORMAT_STR " (needed: " SD_ID128_FORMAT_STR "), ignoring.",
major(partition_devno), minor(partition_devno),
- SD_ID128_FORMAT_VAL(pt_parsed), SD_ID128_FORMAT_VAL(partition_type_uuid));
+ SD_ID128_FORMAT_VAL(pt_parsed), SD_ID128_FORMAT_VAL(partition_type.uuid));
return false;
}
}
static int resolve_copy_blocks_auto(
- sd_id128_t type_uuid,
+ GptPartitionType type,
const char *root,
dev_t restrict_devno,
dev_t *ret_devno,
* partitions in the host, using the appropriate directory as key and ensuring that the partition
* type matches. */
- if (gpt_partition_type_is_root(type_uuid))
+ if (type.designator == PARTITION_ROOT)
try1 = "/";
- else if (gpt_partition_type_is_usr(type_uuid))
+ else if (type.designator == PARTITION_USR)
try1 = "/usr/";
- else if (gpt_partition_type_is_root_verity(type_uuid))
+ else if (type.designator == PARTITION_ROOT_VERITY)
try1 = "/";
- else if (gpt_partition_type_is_usr_verity(type_uuid))
+ else if (type.designator == PARTITION_USR_VERITY)
try1 = "/usr/";
- else if (sd_id128_equal(type_uuid, SD_GPT_ESP)) {
+ else if (type.designator == PARTITION_ESP) {
try1 = "/efi/";
try2 = "/boot/";
- } else if (sd_id128_equal(type_uuid, SD_GPT_XBOOTLDR))
+ } else if (type.designator == PARTITION_XBOOTLDR)
try1 = "/boot/";
else
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Partition type " SD_ID128_FORMAT_STR " not supported from automatic source block device discovery.",
- SD_ID128_FORMAT_VAL(type_uuid));
+ SD_ID128_FORMAT_VAL(type.uuid));
r = find_backing_devno(try1, root, &devno);
if (r == -ENOENT && try2)
r = find_backing_devno(try2, root, &devno);
if (r < 0)
return log_error_errno(r, "Failed to resolve automatic CopyBlocks= path for partition type " SD_ID128_FORMAT_STR ", sorry: %m",
- SD_ID128_FORMAT_VAL(type_uuid));
+ SD_ID128_FORMAT_VAL(type.uuid));
xsprintf_sys_block_path(p, "/slaves", devno);
d = opendir(p);
continue;
}
- r = resolve_copy_blocks_auto_candidate(sl, type_uuid, restrict_devno, &u);
+ r = resolve_copy_blocks_auto_candidate(sl, type, restrict_devno, &u);
if (r < 0)
return r;
if (r > 0) {
} else if (errno != ENOENT)
return log_error_errno(errno, "Failed open %s: %m", p);
else {
- r = resolve_copy_blocks_auto_candidate(devno, type_uuid, restrict_devno, &found_uuid);
+ r = resolve_copy_blocks_auto_candidate(devno, type, restrict_devno, &found_uuid);
if (r < 0)
return r;
if (r > 0)
} else if (p->copy_blocks_auto) {
dev_t devno;
- r = resolve_copy_blocks_auto(p->type_uuid, p->copy_blocks_root, restrict_devno, &devno, &uuid);
+ r = resolve_copy_blocks_auto(p->type, p->copy_blocks_root, restrict_devno, &devno, &uuid);
if (r < 0)
return r;
return TAKE_FD(fd);
}
+static int compare_arch(Architecture a, Architecture b) {
+ if (a == b)
+ return 0;
+
+ if (a == native_architecture())
+ return 1;
+
+ if (b == native_architecture())
+ return -1;
+
+#ifdef ARCHITECTURE_SECONDARY
+ if (a == ARCHITECTURE_SECONDARY)
+ return 1;
+
+ if (b == ARCHITECTURE_SECONDARY)
+ return -1;
+#endif
+
+ return 0;
+}
+
static int dissect_image(
DissectedImage *m,
int fd,
}
if (is_gpt) {
- PartitionDesignator designator = _PARTITION_DESIGNATOR_INVALID;
- Architecture architecture = _ARCHITECTURE_INVALID;
const char *stype, *sid, *fstype = NULL, *label;
sd_id128_t type_id, id;
+ GptPartitionType type;
bool rw = true, growfs = false;
sid = blkid_partition_get_uuid(pp);
if (sd_id128_from_string(stype, &type_id) < 0)
continue;
+ type = gpt_partition_type_from_uuid(type_id);
+
label = blkid_partition_get_name(pp); /* libblkid returns NULL here if empty */
- if (sd_id128_equal(type_id, SD_GPT_HOME)) {
+ if (type.designator == PARTITION_HOME) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (pflags & SD_GPT_FLAG_NO_AUTO)
continue;
- designator = PARTITION_HOME;
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (sd_id128_equal(type_id, SD_GPT_SRV)) {
+ } else if (type.designator == PARTITION_SRV) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (pflags & SD_GPT_FLAG_NO_AUTO)
continue;
- designator = PARTITION_SRV;
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (sd_id128_equal(type_id, SD_GPT_ESP)) {
+ } else if (type.designator == PARTITION_ESP) {
/* Note that we don't check the SD_GPT_FLAG_NO_AUTO flag for the ESP, as it is
* not defined there. We instead check the SD_GPT_FLAG_NO_BLOCK_IO_PROTOCOL, as
if (pflags & SD_GPT_FLAG_NO_BLOCK_IO_PROTOCOL)
continue;
- designator = PARTITION_ESP;
fstype = "vfat";
- } else if (sd_id128_equal(type_id, SD_GPT_XBOOTLDR)) {
+ } else if (type.designator == PARTITION_XBOOTLDR) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (pflags & SD_GPT_FLAG_NO_AUTO)
continue;
- designator = PARTITION_XBOOTLDR;
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (gpt_partition_type_is_root(type_id)) {
+ } else if (type.designator == PARTITION_ROOT) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (!sd_id128_is_null(root_uuid) && !sd_id128_equal(root_uuid, id))
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_root_of_arch(architecture);
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (gpt_partition_type_is_root_verity(type_id)) {
+ } else if (type.designator == PARTITION_ROOT_VERITY) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY);
if (!sd_id128_is_null(root_verity_uuid) && !sd_id128_equal(root_verity_uuid, id))
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_verity_of(partition_root_of_arch(architecture));
fstype = "DM_verity_hash";
rw = false;
- } else if (gpt_partition_type_is_root_verity_sig(type_id)) {
+ } else if (type.designator == PARTITION_ROOT_VERITY_SIG) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY);
if (verity->designator >= 0 && verity->designator != PARTITION_ROOT)
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_verity_sig_of(partition_root_of_arch(architecture));
fstype = "verity_hash_signature";
rw = false;
- } else if (gpt_partition_type_is_usr(type_id)) {
+ } else if (type.designator == PARTITION_USR) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (!sd_id128_is_null(usr_uuid) && !sd_id128_equal(usr_uuid, id))
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_usr_of_arch(architecture);
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (gpt_partition_type_is_usr_verity(type_id)) {
+ } else if (type.designator == PARTITION_USR_VERITY) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY);
if (!sd_id128_is_null(usr_verity_uuid) && !sd_id128_equal(usr_verity_uuid, id))
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_verity_of(partition_usr_of_arch(architecture));
fstype = "DM_verity_hash";
rw = false;
- } else if (gpt_partition_type_is_usr_verity_sig(type_id)) {
+ } else if (type.designator == PARTITION_USR_VERITY_SIG) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY);
if (verity->designator >= 0 && verity->designator != PARTITION_USR)
continue;
- assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
- designator = partition_verity_sig_of(partition_usr_of_arch(architecture));
fstype = "verity_hash_signature";
rw = false;
- } else if (sd_id128_equal(type_id, SD_GPT_SWAP)) {
+ } else if (type.designator == PARTITION_SWAP) {
check_partition_flags(node, pflags, SD_GPT_FLAG_NO_AUTO);
if (pflags & SD_GPT_FLAG_NO_AUTO)
continue;
- designator = PARTITION_SWAP;
-
- } else if (sd_id128_equal(type_id, SD_GPT_LINUX_GENERIC)) {
+ } else if (type.designator == PARTITION_LINUX_GENERIC) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
return -ENOMEM;
}
- } else if (sd_id128_equal(type_id, SD_GPT_TMP)) {
+ } else if (type.designator == PARTITION_TMP) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
if (pflags & SD_GPT_FLAG_NO_AUTO)
continue;
- designator = PARTITION_TMP;
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
- } else if (sd_id128_equal(type_id, SD_GPT_VAR)) {
+ } else if (type.designator == PARTITION_VAR) {
check_partition_flags(node, pflags,
SD_GPT_FLAG_NO_AUTO | SD_GPT_FLAG_READ_ONLY | SD_GPT_FLAG_GROWFS);
}
}
- designator = PARTITION_VAR;
rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
}
- if (designator != _PARTITION_DESIGNATOR_INVALID) {
+ if (type.designator != _PARTITION_DESIGNATOR_INVALID) {
_cleanup_free_ char *t = NULL, *o = NULL, *l = NULL;
_cleanup_close_ int mount_node_fd = -1;
const char *options = NULL;
- if (m->partitions[designator].found) {
+ if (m->partitions[type.designator].found) {
/* For most partition types the first one we see wins. Except for the
* rootfs and /usr, where we do a version compare of the label, and
* let the newest version win. This permits a simple A/B versioning
* scheme in OS images. */
- if (!partition_designator_is_versioned(designator) ||
- strverscmp_improved(m->partitions[designator].label, label) >= 0)
+ if (compare_arch(type.arch, m->partitions[type.designator].architecture) <= 0)
+ continue;
+
+ if (!partition_designator_is_versioned(type.designator) ||
+ strverscmp_improved(m->partitions[type.designator].label, label) >= 0)
continue;
- dissected_partition_done(m->partitions + designator);
+ dissected_partition_done(m->partitions + type.designator);
}
if (FLAGS_SET(flags, DISSECT_IMAGE_OPEN_PARTITION_DEVICES)) {
return -ENOMEM;
}
- options = mount_options_from_designator(mount_options, designator);
+ options = mount_options_from_designator(mount_options, type.designator);
if (options) {
o = strdup(options);
if (!o)
return -ENOMEM;
}
- m->partitions[designator] = (DissectedPartition) {
+ m->partitions[type.designator] = (DissectedPartition) {
.found = true,
.partno = nr,
.rw = rw,
.growfs = growfs,
- .architecture = architecture,
+ .architecture = type.arch,
.node = TAKE_PTR(node),
.fstype = TAKE_PTR(t),
.label = TAKE_PTR(l),
}
}
- if (m->partitions[PARTITION_ROOT].found) {
- /* If we found the primary arch, then invalidate the secondary and other arch to avoid any
- * ambiguities, since we never want to mount the secondary or other arch in this case. */
- m->partitions[PARTITION_ROOT_SECONDARY].found = false;
- m->partitions[PARTITION_ROOT_SECONDARY_VERITY].found = false;
- m->partitions[PARTITION_ROOT_SECONDARY_VERITY_SIG].found = false;
- m->partitions[PARTITION_USR_SECONDARY].found = false;
- m->partitions[PARTITION_USR_SECONDARY_VERITY].found = false;
- m->partitions[PARTITION_USR_SECONDARY_VERITY_SIG].found = false;
-
- m->partitions[PARTITION_ROOT_OTHER].found = false;
- m->partitions[PARTITION_ROOT_OTHER_VERITY].found = false;
- m->partitions[PARTITION_ROOT_OTHER_VERITY_SIG].found = false;
- m->partitions[PARTITION_USR_OTHER].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY_SIG].found = false;
-
- } else if (m->partitions[PARTITION_ROOT_VERITY].found ||
- m->partitions[PARTITION_ROOT_VERITY_SIG].found)
- return -EADDRNOTAVAIL; /* Verity found but no matching rootfs? Something is off, refuse. */
-
- else if (m->partitions[PARTITION_ROOT_SECONDARY].found) {
-
- /* No root partition found but there's one for the secondary architecture? Then upgrade
- * secondary arch to first and invalidate the other arch. */
-
- log_debug("No root partition found of the native architecture, falling back to a root "
- "partition of the secondary architecture.");
-
- m->partitions[PARTITION_ROOT] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_SECONDARY]);
- m->partitions[PARTITION_ROOT_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_SECONDARY_VERITY]);
- m->partitions[PARTITION_ROOT_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_SECONDARY_VERITY_SIG]);
-
- m->partitions[PARTITION_USR] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY]);
- m->partitions[PARTITION_USR_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY_VERITY]);
- m->partitions[PARTITION_USR_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY_VERITY_SIG]);
-
- m->partitions[PARTITION_ROOT_OTHER].found = false;
- m->partitions[PARTITION_ROOT_OTHER_VERITY].found = false;
- m->partitions[PARTITION_ROOT_OTHER_VERITY_SIG].found = false;
- m->partitions[PARTITION_USR_OTHER].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY_SIG].found = false;
-
- } else if (m->partitions[PARTITION_ROOT_SECONDARY_VERITY].found ||
- m->partitions[PARTITION_ROOT_SECONDARY_VERITY_SIG].found)
- return -EADDRNOTAVAIL; /* as above */
-
- else if (m->partitions[PARTITION_ROOT_OTHER].found) {
-
- /* No root or secondary partition found but there's one for another architecture? Then
- * upgrade the other architecture to first. */
-
- log_debug("No root partition found of the native architecture or the secondary architecture, "
- "falling back to a root partition of a non-native architecture (%s).",
- architecture_to_string(m->partitions[PARTITION_ROOT_OTHER].architecture));
-
- m->partitions[PARTITION_ROOT] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_OTHER]);
- m->partitions[PARTITION_ROOT_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_OTHER_VERITY]);
- m->partitions[PARTITION_ROOT_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_ROOT_OTHER_VERITY_SIG]);
-
- m->partitions[PARTITION_USR] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER]);
- m->partitions[PARTITION_USR_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER_VERITY]);
- m->partitions[PARTITION_USR_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER_VERITY_SIG]);
- }
+ if (!m->partitions[PARTITION_ROOT].found &&
+ (m->partitions[PARTITION_ROOT_VERITY].found ||
+ m->partitions[PARTITION_ROOT_VERITY_SIG].found))
+ return -EADDRNOTAVAIL; /* Verity found but no matching rootfs? Something is off, refuse. */
/* Hmm, we found a signature partition but no Verity data? Something is off. */
if (m->partitions[PARTITION_ROOT_VERITY_SIG].found && !m->partitions[PARTITION_ROOT_VERITY].found)
return -EADDRNOTAVAIL;
- if (m->partitions[PARTITION_USR].found) {
- /* Invalidate secondary and other arch /usr/ if we found the primary arch */
- m->partitions[PARTITION_USR_SECONDARY].found = false;
- m->partitions[PARTITION_USR_SECONDARY_VERITY].found = false;
- m->partitions[PARTITION_USR_SECONDARY_VERITY_SIG].found = false;
-
- m->partitions[PARTITION_USR_OTHER].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY_SIG].found = false;
-
- } else if (m->partitions[PARTITION_USR_VERITY].found ||
- m->partitions[PARTITION_USR_VERITY_SIG].found)
- return -EADDRNOTAVAIL; /* as above */
-
- else if (m->partitions[PARTITION_USR_SECONDARY].found) {
-
- log_debug("No usr partition found of the native architecture, falling back to a usr "
- "partition of the secondary architecture.");
-
- /* Upgrade secondary arch to primary */
- m->partitions[PARTITION_USR] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY]);
- m->partitions[PARTITION_USR_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY_VERITY]);
- m->partitions[PARTITION_USR_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_USR_SECONDARY_VERITY_SIG]);
+ if (!m->partitions[PARTITION_USR].found &&
+ (m->partitions[PARTITION_USR_VERITY].found ||
+ m->partitions[PARTITION_USR_VERITY_SIG].found))
+ return -EADDRNOTAVAIL; /* as above */
- m->partitions[PARTITION_USR_OTHER].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY].found = false;
- m->partitions[PARTITION_USR_OTHER_VERITY_SIG].found = false;
-
- } else if (m->partitions[PARTITION_USR_SECONDARY_VERITY].found ||
- m->partitions[PARTITION_USR_SECONDARY_VERITY_SIG].found)
- return -EADDRNOTAVAIL; /* as above */
-
- else if (m->partitions[PARTITION_USR_OTHER].found) {
-
- log_debug("No usr partition found of the native architecture or the secondary architecture, "
- "falling back to a usr partition of a non-native architecture (%s).",
- architecture_to_string(m->partitions[PARTITION_ROOT_OTHER].architecture));
-
- /* Upgrade other arch to primary */
- m->partitions[PARTITION_USR] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER]);
- m->partitions[PARTITION_USR_VERITY] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER_VERITY]);
- m->partitions[PARTITION_USR_VERITY_SIG] = TAKE_PARTITION(m->partitions[PARTITION_USR_OTHER_VERITY_SIG]);
- }
-
- /* Hmm, we found a signature partition but no Verity data? Something is off. */
+ /* as above */
if (m->partitions[PARTITION_USR_VERITY_SIG].found && !m->partitions[PARTITION_USR_VERITY].found)
return -EADDRNOTAVAIL;
return IN_SET(d,
PARTITION_ROOT,
- PARTITION_ROOT_SECONDARY,
- PARTITION_ROOT_OTHER,
PARTITION_USR,
- PARTITION_USR_SECONDARY,
- PARTITION_USR_OTHER,
PARTITION_ROOT_VERITY,
- PARTITION_ROOT_SECONDARY_VERITY,
- PARTITION_ROOT_OTHER_VERITY,
PARTITION_USR_VERITY,
- PARTITION_USR_SECONDARY_VERITY,
- PARTITION_USR_OTHER_VERITY,
PARTITION_ROOT_VERITY_SIG,
- PARTITION_ROOT_SECONDARY_VERITY_SIG,
- PARTITION_ROOT_OTHER_VERITY_SIG,
- PARTITION_USR_VERITY_SIG,
- PARTITION_USR_SECONDARY_VERITY_SIG,
- PARTITION_USR_OTHER_VERITY_SIG);
+ PARTITION_USR_VERITY_SIG);
}
PartitionDesignator partition_verity_of(PartitionDesignator p) {
case PARTITION_ROOT:
return PARTITION_ROOT_VERITY;
- case PARTITION_ROOT_SECONDARY:
- return PARTITION_ROOT_SECONDARY_VERITY;
-
- case PARTITION_ROOT_OTHER:
- return PARTITION_ROOT_OTHER_VERITY;
-
case PARTITION_USR:
return PARTITION_USR_VERITY;
- case PARTITION_USR_SECONDARY:
- return PARTITION_USR_SECONDARY_VERITY;
-
- case PARTITION_USR_OTHER:
- return PARTITION_USR_OTHER_VERITY;
-
default:
return _PARTITION_DESIGNATOR_INVALID;
}
case PARTITION_ROOT:
return PARTITION_ROOT_VERITY_SIG;
- case PARTITION_ROOT_SECONDARY:
- return PARTITION_ROOT_SECONDARY_VERITY_SIG;
-
- case PARTITION_ROOT_OTHER:
- return PARTITION_ROOT_OTHER_VERITY_SIG;
-
case PARTITION_USR:
return PARTITION_USR_VERITY_SIG;
- case PARTITION_USR_SECONDARY:
- return PARTITION_USR_SECONDARY_VERITY_SIG;
-
- case PARTITION_USR_OTHER:
- return PARTITION_USR_OTHER_VERITY_SIG;
-
default:
return _PARTITION_DESIGNATOR_INVALID;
}
}
-PartitionDesignator partition_root_of_arch(Architecture arch) {
- switch (arch) {
-
- case native_architecture():
- return PARTITION_ROOT;
-
-#ifdef ARCHITECTURE_SECONDARY
- case ARCHITECTURE_SECONDARY:
- return PARTITION_ROOT_SECONDARY;
-#endif
-
- default:
- return PARTITION_ROOT_OTHER;
- }
-}
-
-PartitionDesignator partition_usr_of_arch(Architecture arch) {
- switch (arch) {
-
- case native_architecture():
- return PARTITION_USR;
-
-#ifdef ARCHITECTURE_SECONDARY
- case ARCHITECTURE_SECONDARY:
- return PARTITION_USR_SECONDARY;
-#endif
-
- default:
- return PARTITION_USR_OTHER;
- }
-}
static const char *const partition_designator_table[] = {
[PARTITION_ROOT] = "root",
- [PARTITION_ROOT_SECONDARY] = "root-secondary",
- [PARTITION_ROOT_OTHER] = "root-other",
[PARTITION_USR] = "usr",
- [PARTITION_USR_SECONDARY] = "usr-secondary",
- [PARTITION_USR_OTHER] = "usr-other",
[PARTITION_HOME] = "home",
[PARTITION_SRV] = "srv",
[PARTITION_ESP] = "esp",
[PARTITION_XBOOTLDR] = "xbootldr",
[PARTITION_SWAP] = "swap",
[PARTITION_ROOT_VERITY] = "root-verity",
- [PARTITION_ROOT_SECONDARY_VERITY] = "root-secondary-verity",
- [PARTITION_ROOT_OTHER_VERITY] = "root-other-verity",
[PARTITION_USR_VERITY] = "usr-verity",
- [PARTITION_USR_SECONDARY_VERITY] = "usr-secondary-verity",
- [PARTITION_USR_OTHER_VERITY] = "usr-other-verity",
[PARTITION_ROOT_VERITY_SIG] = "root-verity-sig",
- [PARTITION_ROOT_SECONDARY_VERITY_SIG] = "root-secondary-verity-sig",
- [PARTITION_ROOT_OTHER_VERITY_SIG] = "root-other-verity-sig",
[PARTITION_USR_VERITY_SIG] = "usr-verity-sig",
- [PARTITION_USR_SECONDARY_VERITY_SIG] = "usr-secondary-verity-sig",
- [PARTITION_USR_OTHER_VERITY_SIG] = "usr-other-verity-sig",
[PARTITION_TMP] = "tmp",
[PARTITION_VAR] = "var",
[PARTITION_USER_HOME] = "user-home",
static const char *const partition_mountpoint_table[] = {
[PARTITION_ROOT] = "/\0",
- [PARTITION_ROOT_SECONDARY] = "/\0",
- [PARTITION_ROOT_OTHER] = "/\0",
[PARTITION_USR] = "/usr\0",
- [PARTITION_USR_SECONDARY] = "/usr\0",
- [PARTITION_USR_OTHER] = "/usr\0",
[PARTITION_HOME] = "/home\0",
[PARTITION_SRV] = "/srv\0",
[PARTITION_ESP] = "/efi\0/boot\0",
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(partition_mountpoint, PartitionDesignator);
#define _GPT_ARCH_SEXTET(arch, name) \
- { SD_GPT_ROOT_##arch, "root-" name, ARCHITECTURE_##arch, .designator = PARTITION_ROOT_OTHER }, \
- { SD_GPT_ROOT_##arch##_VERITY, "root-" name "-verity", ARCHITECTURE_##arch, .designator = PARTITION_ROOT_OTHER_VERITY }, \
- { SD_GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch, .designator = PARTITION_ROOT_OTHER_VERITY_SIG }, \
- { SD_GPT_USR_##arch, "usr-" name, ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER }, \
- { SD_GPT_USR_##arch##_VERITY, "usr-" name "-verity", ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER_VERITY }, \
- { SD_GPT_USR_##arch##_VERITY_SIG, "usr-" name "-verity-sig", ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER_VERITY_SIG }
+ { SD_GPT_ROOT_##arch, "root-" name, ARCHITECTURE_##arch, .designator = PARTITION_ROOT }, \
+ { SD_GPT_ROOT_##arch##_VERITY, "root-" name "-verity", ARCHITECTURE_##arch, .designator = PARTITION_ROOT_VERITY }, \
+ { SD_GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch, .designator = PARTITION_ROOT_VERITY_SIG }, \
+ { SD_GPT_USR_##arch, "usr-" name, ARCHITECTURE_##arch, .designator = PARTITION_USR }, \
+ { SD_GPT_USR_##arch##_VERITY, "usr-" name "-verity", ARCHITECTURE_##arch, .designator = PARTITION_USR_VERITY }, \
+ { SD_GPT_USR_##arch##_VERITY_SIG, "usr-" name "-verity-sig", ARCHITECTURE_##arch, .designator = PARTITION_USR_VERITY_SIG }
const GptPartitionType gpt_partition_type_table[] = {
_GPT_ARCH_SEXTET(ALPHA, "alpha"),
{ SD_GPT_USR_NATIVE_VERITY_SIG, "usr-verity-sig", native_architecture(), .designator = PARTITION_USR_VERITY_SIG },
#endif
#ifdef SD_GPT_ROOT_SECONDARY
- { SD_GPT_ROOT_NATIVE, "root-secondary", native_architecture(), .designator = PARTITION_ROOT_SECONDARY },
- { SD_GPT_ROOT_NATIVE_VERITY, "root-secondary-verity", native_architecture(), .designator = PARTITION_ROOT_SECONDARY_VERITY },
- { SD_GPT_ROOT_NATIVE_VERITY_SIG, "root-secondary-verity-sig", native_architecture(), .designator = PARTITION_ROOT_SECONDARY_VERITY_SIG },
- { SD_GPT_USR_NATIVE, "usr-secondary", native_architecture(), .designator = PARTITION_USR_SECONDARY },
- { SD_GPT_USR_NATIVE_VERITY, "usr-secondary-verity", native_architecture(), .designator = PARTITION_USR_SECONDARY_VERITY },
- { SD_GPT_USR_NATIVE_VERITY_SIG, "usr-secondary-verity-sig", native_architecture(), .designator = PARTITION_USR_SECONDARY_VERITY_SIG },
+ { SD_GPT_ROOT_NATIVE, "root-secondary", native_architecture(), .designator = PARTITION_ROOT },
+ { SD_GPT_ROOT_NATIVE_VERITY, "root-secondary-verity", native_architecture(), .designator = PARTITION_ROOT_VERITY },
+ { SD_GPT_ROOT_NATIVE_VERITY_SIG, "root-secondary-verity-sig", native_architecture(), .designator = PARTITION_ROOT_VERITY_SIG },
+ { SD_GPT_USR_NATIVE, "usr-secondary", native_architecture(), .designator = PARTITION_USR },
+ { SD_GPT_USR_NATIVE_VERITY, "usr-secondary-verity", native_architecture(), .designator = PARTITION_USR_VERITY },
+ { SD_GPT_USR_NATIVE_VERITY_SIG, "usr-secondary-verity-sig", native_architecture(), .designator = PARTITION_USR_VERITY_SIG },
#endif
{ SD_GPT_ESP, "esp", _ARCHITECTURE_INVALID, .designator = PARTITION_ESP },
return sd_id128_to_uuid_string(id, buffer);
}
-int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
+int gpt_partition_type_from_string(const char *s, GptPartitionType *ret) {
+ sd_id128_t id;
+ int r;
+
assert(s);
for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
if (streq(s, gpt_partition_type_table[i].name)) {
if (ret)
- *ret = gpt_partition_type_table[i].uuid;
+ *ret = gpt_partition_type_table[i];
return 0;
}
- return sd_id128_from_string(s, ret);
+ r = sd_id128_from_string(s, &id);
+ if (r < 0)
+ return r;
+
+ if (ret)
+ *ret = gpt_partition_type_from_uuid(id);
+
+ return 0;
}
Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id) {
return char16_strlen(recoded) <= GPT_LABEL_MAX;
}
-static GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id) {
+GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id) {
const GptPartitionType *pt;
pt = gpt_partition_type_find_by_uuid(id);
};
}
-bool gpt_partition_type_is_root(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_ROOT,
- PARTITION_ROOT_SECONDARY,
- PARTITION_ROOT_OTHER);
+const char *gpt_partition_type_mountpoint_nulstr(GptPartitionType type) {
+ return partition_mountpoint_to_string(type.designator);
}
-bool gpt_partition_type_is_root_verity(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
+bool gpt_partition_type_knows_read_only(GptPartitionType type) {
+ return IN_SET(type.designator,
+ PARTITION_ROOT,
+ PARTITION_USR,
+ /* pretty much implied, but let's set the bit to make things really clear */
PARTITION_ROOT_VERITY,
- PARTITION_ROOT_SECONDARY_VERITY,
- PARTITION_ROOT_OTHER_VERITY);
-}
-
-bool gpt_partition_type_is_root_verity_sig(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_ROOT_VERITY_SIG,
- PARTITION_ROOT_SECONDARY_VERITY_SIG,
- PARTITION_ROOT_OTHER_VERITY_SIG);
+ PARTITION_USR_VERITY,
+ PARTITION_HOME,
+ PARTITION_SRV,
+ PARTITION_VAR,
+ PARTITION_TMP,
+ PARTITION_XBOOTLDR);
}
-bool gpt_partition_type_is_usr(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
+bool gpt_partition_type_knows_growfs(GptPartitionType type) {
+ return IN_SET(type.designator,
+ PARTITION_ROOT,
PARTITION_USR,
- PARTITION_USR_SECONDARY,
- PARTITION_USR_OTHER);
+ PARTITION_HOME,
+ PARTITION_SRV,
+ PARTITION_VAR,
+ PARTITION_TMP,
+ PARTITION_XBOOTLDR);
}
-bool gpt_partition_type_is_usr_verity(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
+bool gpt_partition_type_knows_no_auto(GptPartitionType type) {
+ return IN_SET(type.designator,
+ PARTITION_ROOT,
+ PARTITION_ROOT_VERITY,
+ PARTITION_USR,
PARTITION_USR_VERITY,
- PARTITION_USR_SECONDARY_VERITY,
- PARTITION_USR_OTHER_VERITY);
-}
-
-bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id) {
- return IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_USR_VERITY_SIG,
- PARTITION_USR_SECONDARY_VERITY_SIG,
- PARTITION_USR_OTHER_VERITY_SIG);
-}
-
-const char *gpt_partition_type_mountpoint_nulstr(sd_id128_t id) {
- PartitionDesignator d = gpt_partition_type_from_uuid(id).designator;
- if (d < 0)
- return NULL;
-
- return partition_mountpoint_to_string(d);
-}
-
-bool gpt_partition_type_knows_read_only(sd_id128_t id) {
- return gpt_partition_type_is_root(id) ||
- gpt_partition_type_is_usr(id) ||
- /* pretty much implied, but let's set the bit to make things really clear */
- gpt_partition_type_is_root_verity(id) ||
- gpt_partition_type_is_usr_verity(id) ||
- IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_HOME,
- PARTITION_SRV,
- PARTITION_VAR,
- PARTITION_TMP,
- PARTITION_XBOOTLDR);
-}
-
-bool gpt_partition_type_knows_growfs(sd_id128_t id) {
- return gpt_partition_type_is_root(id) ||
- gpt_partition_type_is_usr(id) ||
- IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_HOME,
- PARTITION_SRV,
- PARTITION_VAR,
- PARTITION_TMP,
- PARTITION_XBOOTLDR);
-}
-
-bool gpt_partition_type_knows_no_auto(sd_id128_t id) {
- return gpt_partition_type_is_root(id) ||
- gpt_partition_type_is_root_verity(id) ||
- gpt_partition_type_is_usr(id) ||
- gpt_partition_type_is_usr_verity(id) ||
- IN_SET(gpt_partition_type_from_uuid(id).designator,
- PARTITION_HOME,
- PARTITION_SRV,
- PARTITION_VAR,
- PARTITION_TMP,
- PARTITION_XBOOTLDR,
- PARTITION_SWAP);
+ PARTITION_HOME,
+ PARTITION_SRV,
+ PARTITION_VAR,
+ PARTITION_TMP,
+ PARTITION_XBOOTLDR,
+ PARTITION_SWAP);
}
typedef enum PartitionDesignator {
PARTITION_ROOT, /* Primary architecture */
- PARTITION_ROOT_SECONDARY, /* Secondary architecture */
- PARTITION_ROOT_OTHER, /* Any architecture not covered by the primary or secondary architecture. */
PARTITION_USR,
- PARTITION_USR_SECONDARY,
- PARTITION_USR_OTHER,
PARTITION_HOME,
PARTITION_SRV,
PARTITION_ESP,
PARTITION_XBOOTLDR,
PARTITION_SWAP,
PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */
- PARTITION_ROOT_SECONDARY_VERITY, /* verity data for the PARTITION_ROOT_SECONDARY partition */
- PARTITION_ROOT_OTHER_VERITY,
PARTITION_USR_VERITY,
- PARTITION_USR_SECONDARY_VERITY,
- PARTITION_USR_OTHER_VERITY,
PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */
- PARTITION_ROOT_SECONDARY_VERITY_SIG, /* ditto for the PARTITION_ROOT_SECONDARY partition */
- PARTITION_ROOT_OTHER_VERITY_SIG,
PARTITION_USR_VERITY_SIG,
- PARTITION_USR_SECONDARY_VERITY_SIG,
- PARTITION_USR_OTHER_VERITY_SIG,
PARTITION_TMP,
PARTITION_VAR,
PARTITION_USER_HOME,
PartitionDesignator partition_verity_of(PartitionDesignator p);
PartitionDesignator partition_verity_sig_of(PartitionDesignator p);
-PartitionDesignator partition_root_of_arch(Architecture arch);
-PartitionDesignator partition_usr_of_arch(Architecture arch);
const char* partition_designator_to_string(PartitionDesignator d) _const_;
PartitionDesignator partition_designator_from_string(const char *name) _pure_;
const char *gpt_partition_type_uuid_to_string_harder(
sd_id128_t id,
char buffer[static SD_ID128_UUID_STRING_MAX]);
-int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret);
#define GPT_PARTITION_TYPE_UUID_TO_STRING_HARDER(id) \
gpt_partition_type_uuid_to_string_harder((id), (char[SD_ID128_UUID_STRING_MAX]) {})
int gpt_partition_label_valid(const char *s);
-bool gpt_partition_type_is_root(sd_id128_t id);
-bool gpt_partition_type_is_root_verity(sd_id128_t id);
-bool gpt_partition_type_is_root_verity_sig(sd_id128_t id);
-bool gpt_partition_type_is_usr(sd_id128_t id);
-bool gpt_partition_type_is_usr_verity(sd_id128_t id);
-bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id);
+GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id);
+int gpt_partition_type_from_string(const char *s, GptPartitionType *ret);
-const char *gpt_partition_type_mountpoint_nulstr(sd_id128_t id);
+const char *gpt_partition_type_mountpoint_nulstr(GptPartitionType type);
-bool gpt_partition_type_knows_read_only(sd_id128_t id);
-bool gpt_partition_type_knows_growfs(sd_id128_t id);
-bool gpt_partition_type_knows_no_auto(sd_id128_t id);
+bool gpt_partition_type_knows_read_only(GptPartitionType type);
+bool gpt_partition_type_knows_growfs(GptPartitionType type);
+bool gpt_partition_type_knows_no_auto(GptPartitionType type);
struct fdisk_parttype *pt;
uint64_t start, size, flags;
sd_id128_t ptid, id;
+ GptPartitionType type;
size_t partno;
int r;
if (!label_copy)
return log_oom();
+ type = gpt_partition_type_from_uuid(ptid);
+
*ret = (PartitionInfo) {
.partno = partno,
.start = start,
.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! */
_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);
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;
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 */
#include <stdbool.h>
#include <sys/types.h>
-#include "sd-id128.h"
-
+#include "gpt.h"
#include "hashmap.h"
#include "macro.h"
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 */
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);
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);
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;
for (Architecture a = 0; a < _ARCHITECTURE_MAX; a++)
FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
_cleanup_free_ char *joined = NULL;
- sd_id128_t id;
+ GptPartitionType type;
joined = strjoin(prefix, architecture_to_string(a), suffix);
if (!joined)
return (void) log_oom();
- r = gpt_partition_type_uuid_from_string(joined, &id);
+ r = gpt_partition_type_from_string(joined, &type);
if (r < 0) {
printf("%s %s\n", RED_CROSS_MARK(), joined);
continue;
printf("%s %s\n", GREEN_CHECK_MARK(), joined);
if (streq(prefix, "root-") && streq(suffix, ""))
- assert_se(gpt_partition_type_is_root(id));
+ assert_se(type.designator == PARTITION_ROOT);
if (streq(prefix, "root-") && streq(suffix, "-verity"))
- assert_se(gpt_partition_type_is_root_verity(id));
+ assert_se(type.designator == PARTITION_ROOT_VERITY);
if (streq(prefix, "usr-") && streq(suffix, ""))
- assert_se(gpt_partition_type_is_usr(id));
+ assert_se(type.designator == PARTITION_USR);
if (streq(prefix, "usr-") && streq(suffix, "-verity"))
- assert_se(gpt_partition_type_is_usr_verity(id));
+ assert_se(type.designator == PARTITION_USR_VERITY);
- assert_se(gpt_partition_type_uuid_to_arch(id) == a);
+ assert_se(type.arch == a);
}
}