From 22769acf56daf6683d635fe92e06ceb52e0433ff Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Tue, 4 Apr 2023 11:04:51 +0200
Subject: [PATCH] libblkid: copy BLKID_PARTS_FORCE_GPT to whole-disk prober

Addresses: https://github.com/util-linux/util-linux/discussions/2146
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 libblkid/src/blkidP.h                | 3 +++
 libblkid/src/partitions/partitions.c | 5 +++++
 libblkid/src/probe.c                 | 6 ++++++
 3 files changed, 14 insertions(+)

diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index 5d2a02055..007cc357b 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -544,6 +544,9 @@ extern int blkid_probe_get_hint(blkid_probe pr, const char *name, uint64_t *valu
 			__attribute__((nonnull(1,2)))
 			__attribute__((warn_unused_result));
 
+extern int blkid_probe_get_partitions_flags(blkid_probe pr)
+			__attribute__((nonnull));
+
 /* filter bitmap macros */
 #define blkid_bmp_wordsize		(8 * sizeof(unsigned long))
 #define blkid_bmp_idx_bit(item)		(1UL << ((item) % blkid_bmp_wordsize))
diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
index ae63a38cc..1c344fd30 100644
--- a/libblkid/src/partitions/partitions.c
+++ b/libblkid/src/partitions/partitions.c
@@ -234,6 +234,11 @@ int blkid_probe_set_partitions_flags(blkid_probe pr, int flags)
 	return 0;
 }
 
+int blkid_probe_get_partitions_flags(blkid_probe pr)
+{
+	return pr->chains[BLKID_CHAIN_PARTS].flags;
+}
+
 /**
  * blkid_probe_reset_partitions_filter:
  * @pr: prober
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 35de30334..b4299493f 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -1930,6 +1930,7 @@ blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr)
 	if (!pr->disk_probe) {
 		/* Open a new disk prober */
 		char *disk_path = blkid_devno_to_devname(disk);
+		int flags;
 
 		if (!disk_path)
 			return NULL;
@@ -1942,6 +1943,11 @@ blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr)
 
 		if (!pr->disk_probe)
 			return NULL;	/* ENOMEM? */
+
+		flags = blkid_probe_get_partitions_flags(pr);
+		if (flags & BLKID_PARTS_FORCE_GPT)
+			blkid_probe_set_partitions_flags(pr->disk_probe,
+							 BLKID_PARTS_FORCE_GPT);
 	}
 
 	return pr->disk_probe;
-- 
2.27.0

