-DEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe);
-#define _cleanup_blkid_freep_probe_ _cleanup_(blkid_free_probep)
-
-static int verify_gpt_partition(const char *node, sd_id128_t *type, unsigned *nr, char **fstype) {
- _cleanup_blkid_freep_probe_ blkid_probe b = NULL;
- const char *v;
- int r;
-
- errno = 0;
- b = blkid_new_probe_from_filename(node);
- if (!b)
- return errno != 0 ? -errno : -ENOMEM;
-
- blkid_probe_enable_superblocks(b, 1);
- blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
- blkid_probe_enable_partitions(b, 1);
- blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
-
- errno = 0;
- r = blkid_do_safeprobe(b);
- if (r == -2 || r == 1) /* no result or uncertain */
- return -EBADSLT;
- else if (r != 0)
- return errno ? -errno : -EIO;
-
- errno = 0;
- r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, NULL);
- if (r != 0)
- /* return 0 if we're not on GPT */
- return errno ? -errno : 0;
-
- if (strcmp(v, "gpt") != 0)
- return 0;
-
- if (type) {
- errno = 0;
- r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
- if (r != 0)
- return errno ? -errno : -EIO;
-
- r = sd_id128_from_string(v, type);
- if (r < 0)
- return r;
- }
-
- if (nr) {
- errno = 0;
- r = blkid_probe_lookup_value(b, "PART_ENTRY_NUMBER", &v, NULL);
- if (r != 0)
- return errno ? -errno : -EIO;
-
- r = safe_atou(v, nr);
- if (r < 0)
- return r;
- }
-
-
- if (fstype) {
- errno = 0;
- r = blkid_probe_lookup_value(b, "TYPE", &v, NULL);
- if (r != 0)
- *fstype = NULL;
- else {
- char *fst;
-
- fst = strdup(v);
- if (!fst)
- return -ENOMEM;
-
- *fstype = fst;
- }
- }
-
- return 1;
-}
-
-static int add_swap(const char *path, const char *fstype) {