parted/parted-mkpart-set-a-swap-flag-if-available.patch
2017-06-15 19:25:03 +00:00

45 lines
1.5 KiB
Diff

From: Sebastian Parschauer <sparschauer@suse.de>
Date: Thu, 15 Jun 2017 18:50:32 +0200
Subject: parted: mkpart: set a swap flag if available
References: fate#314888, bsc#1044536
Patch-mainline: no, upstream wants to drop the swap flag
libparted can't differentiate if ped_partition_set_system() is
called from mkpart context or when reading from disk. This makes
it hard to handle the linux-swap partition type properly.
So check in do_mkpart() if a swap flag is available and only set it
there if the selected FS type name starts with "linux-swap".
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
parted/parted.c | 10 ++++++++++
1 file changed, 10 insertions(+)
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -655,6 +655,13 @@ _adjust_end_if_iec (PedSector* start, Pe
}
+static inline int
+is_linux_swap (char const *fs_type_name)
+{
+ char const *prefix = "linux-swap";
+ return strncmp (fs_type_name, prefix, strlen (prefix)) == 0;
+}
+
static int
do_mkpart (PedDevice** dev, PedDisk** diskp)
{
@@ -844,6 +851,9 @@ do_mkpart (PedDevice** dev, PedDisk** di
goto error;
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
+ if (ped_partition_is_flag_available (part, PED_PARTITION_SWAP) &&
+ fs_type && is_linux_swap(fs_type->name))
+ ped_partition_set_flag (part, PED_PARTITION_SWAP, 1);
if (wipesignatures) {
if (!ped_device_wipe_signatures(*dev, part->geom.start, part->geom.length))