summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-08-01 21:38:11 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-08-01 22:32:38 +0200
commit2d9b3468b2ad83810d21ccf2c00a5d2ac18dccc0 (patch)
treefad6a1046f92f6d3dac4f13b2f8b5ddb4653a911 /src
parentrepart: Rename partition_exclude/defer() to partition_type_exclude/defer() (diff)
downloadsystemd-2d9b3468b2ad83810d21ccf2c00a5d2ac18dccc0.tar.xz
systemd-2d9b3468b2ad83810d21ccf2c00a5d2ac18dccc0.zip
sysupdate: Move fdisk partition flags helpers to fdisk-util.c
Diffstat (limited to 'src')
-rw-r--r--src/shared/fdisk-util.c77
-rw-r--r--src/shared/fdisk-util.h3
-rw-r--r--src/sysupdate/sysupdate-partition.c81
3 files changed, 80 insertions, 81 deletions
diff --git a/src/shared/fdisk-util.c b/src/shared/fdisk-util.c
index e88adb2d43..9a301f38ac 100644
--- a/src/shared/fdisk-util.c
+++ b/src/shared/fdisk-util.c
@@ -1,8 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "dissect-image.h"
+#include "extract-word.h"
#include "fd-util.h"
#include "fdisk-util.h"
+#include "parse-util.h"
#if HAVE_LIBFDISK
@@ -75,4 +77,79 @@ int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret
return sd_id128_from_string(pts, ret);
}
+int fdisk_partition_get_attrs_as_uint64(struct fdisk_partition *pa, uint64_t *ret) {
+ uint64_t flags = 0;
+ const char *a;
+ int r;
+
+ assert(pa);
+ assert(ret);
+
+ /* Retrieve current flags as uint64_t mask */
+
+ a = fdisk_partition_get_attrs(pa);
+ if (!a) {
+ *ret = 0;
+ return 0;
+ }
+
+ for (;;) {
+ _cleanup_free_ char *word = NULL;
+
+ r = extract_first_word(&a, &word, ",", EXTRACT_DONT_COALESCE_SEPARATORS);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ break;
+
+ if (streq(word, "RequiredPartition"))
+ flags |= SD_GPT_FLAG_REQUIRED_PARTITION;
+ else if (streq(word, "NoBlockIOProtocol"))
+ flags |= SD_GPT_FLAG_NO_BLOCK_IO_PROTOCOL;
+ else if (streq(word, "LegacyBIOSBootable"))
+ flags |= SD_GPT_FLAG_LEGACY_BIOS_BOOTABLE;
+ else {
+ const char *e;
+ unsigned u;
+
+ /* Drop "GUID" prefix if specified */
+ e = startswith(word, "GUID:") ?: word;
+
+ if (safe_atou(e, &u) < 0) {
+ log_debug("Unknown partition flag '%s', ignoring.", word);
+ continue;
+ }
+
+ if (u >= sizeof(flags)*8) { /* partition flags on GPT are 64-bit. Let's ignore any further
+ bits should libfdisk report them */
+ log_debug("Partition flag above bit 63 (%s), ignoring.", word);
+ continue;
+ }
+
+ flags |= UINT64_C(1) << u;
+ }
+ }
+
+ *ret = flags;
+ return 0;
+}
+
+int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t flags) {
+ _cleanup_free_ char *attrs = NULL;
+ int r;
+
+ assert(pa);
+
+ for (unsigned i = 0; i < sizeof(flags) * 8; i++) {
+ if (!FLAGS_SET(flags, UINT64_C(1) << i))
+ continue;
+
+ r = strextendf_with_separator(&attrs, ",", "%u", i);
+ if (r < 0)
+ return r;
+ }
+
+ return fdisk_partition_set_attrs(pa, strempty(attrs));
+}
+
#endif
diff --git a/src/shared/fdisk-util.h b/src/shared/fdisk-util.h
index 4845132927..b82ff705d7 100644
--- a/src/shared/fdisk-util.h
+++ b/src/shared/fdisk-util.h
@@ -19,4 +19,7 @@ int fdisk_new_context_fd(int fd, bool read_only, uint32_t sector_size, struct fd
int fdisk_partition_get_uuid_as_id128(struct fdisk_partition *p, sd_id128_t *ret);
int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret);
+int fdisk_partition_get_attrs_as_uint64(struct fdisk_partition *pa, uint64_t *ret);
+int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t flags);
+
#endif
diff --git a/src/sysupdate/sysupdate-partition.c b/src/sysupdate/sysupdate-partition.c
index 8f33469663..587265482b 100644
--- a/src/sysupdate/sysupdate-partition.c
+++ b/src/sysupdate/sysupdate-partition.c
@@ -18,87 +18,6 @@ void partition_info_destroy(PartitionInfo *p) {
p->device = mfree(p->device);
}
-static int fdisk_partition_get_attrs_as_uint64(
- struct fdisk_partition *pa,
- uint64_t *ret) {
-
- uint64_t flags = 0;
- const char *a;
- int r;
-
- assert(pa);
- assert(ret);
-
- /* Retrieve current flags as uint64_t mask */
-
- a = fdisk_partition_get_attrs(pa);
- if (!a) {
- *ret = 0;
- return 0;
- }
-
- for (;;) {
- _cleanup_free_ char *word = NULL;
-
- r = extract_first_word(&a, &word, ",", EXTRACT_DONT_COALESCE_SEPARATORS);
- if (r < 0)
- return r;
- if (r == 0)
- break;
-
- if (streq(word, "RequiredPartition"))
- flags |= SD_GPT_FLAG_REQUIRED_PARTITION;
- else if (streq(word, "NoBlockIOProtocol"))
- flags |= SD_GPT_FLAG_NO_BLOCK_IO_PROTOCOL;
- else if (streq(word, "LegacyBIOSBootable"))
- flags |= SD_GPT_FLAG_LEGACY_BIOS_BOOTABLE;
- else {
- const char *e;
- unsigned u;
-
- /* Drop "GUID" prefix if specified */
- e = startswith(word, "GUID:") ?: word;
-
- if (safe_atou(e, &u) < 0) {
- log_debug("Unknown partition flag '%s', ignoring.", word);
- continue;
- }
-
- if (u >= sizeof(flags)*8) { /* partition flags on GPT are 64-bit. Let's ignore any further
- bits should libfdisk report them */
- log_debug("Partition flag above bit 63 (%s), ignoring.", word);
- continue;
- }
-
- flags |= UINT64_C(1) << u;
- }
- }
-
- *ret = flags;
- return 0;
-}
-
-static int fdisk_partition_set_attrs_as_uint64(
- struct fdisk_partition *pa,
- uint64_t flags) {
-
- _cleanup_free_ char *attrs = NULL;
- int r;
-
- assert(pa);
-
- for (unsigned i = 0; i < sizeof(flags) * 8; i++) {
- if (!FLAGS_SET(flags, UINT64_C(1) << i))
- continue;
-
- r = strextendf_with_separator(&attrs, ",", "%u", i);
- if (r < 0)
- return r;
- }
-
- return fdisk_partition_set_attrs(pa, strempty(attrs));
-}
-
int read_partition_info(
struct fdisk_context *c,
struct fdisk_table *t,