[PATCH v3 1/3] disk: accessors for conditional partition fields

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sun Feb 19 12:36:27 CET 2023


Structure disk_partition contains some fields whose existence depends on
configuration variables. Provide macros that return a value irrespective of
the value of configuration. This allows to replace #ifdefs by simple ifs
in codes that relies on these fields which is our preferred coding style.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
v3:
	new patch
---
 include/part.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/part.h b/include/part.h
index be75c73549..c0355a3602 100644
--- a/include/part.h
+++ b/include/part.h
@@ -80,6 +80,42 @@ struct disk_partition {
 #endif
 };
 
+/**
+ * get_part_uuid() - get partition UUID
+ *
+ * @a:		disk partition as struct disk_partition
+ * Return:	partition UUID as string
+ */
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
+#define get_part_uuid(a) (a.uuid)
+#else
+#define get_part_uuid(a) ("")
+#endif
+
+/**
+ * get_part_type_guid() - get partition type GUID
+ *
+ * @a:		disk partition as struct disk_partition
+ * Return:	partition type GUID as string
+ */
+#ifdef CONFIG_PARTITION_TYPE_GUID
+#define get_part_type_guid(a) (a.type_guid)
+#else
+#define get_part_type_guid(a) ("")
+#endif
+
+/**
+ * get_part_type() - get partition type
+ *
+ * @a:		disk partition as struct disk_partition
+ * Return:	partition type a unsigned char
+ */
+#ifdef CONFIG_DOS_PARTITION
+#define get_part_type(a) (a.sys_ind)
+#else
+#define get_part_type(a) ('\0')
+#endif
+
 struct disk_part {
 	int partnum;
 	struct disk_partition gpt_part_info;
-- 
2.38.1



More information about the U-Boot mailing list