ceb987
From 61b3a9733c0e0a79ccc43096642d378c8706add6 Mon Sep 17 00:00:00 2001
ceb987
From: Arvin Schnell <aschnell@suse.com>
ceb987
Date: Wed, 11 May 2022 14:02:21 +0000
ceb987
Subject: [PATCH 2/5] parted: add type command
ceb987
ceb987
Include the partition type-id and type-uuid in the JSON
ceb987
output. Also add the the command 'type' to set them. Remove
ceb987
redundant flags from DosPartitionData and use only the system
ceb987
variable.
ceb987
ceb987
Signed-off-by: Brian C. Lane <bcl@redhat.com>
ceb987
---
ceb987
 NEWS                                  |   3 +
ceb987
 doc/C/parted.8                        |   5 +
ceb987
 doc/parted.texi                       |  20 +
ceb987
 include/parted/disk.in.h              |  23 +-
ceb987
 libparted/disk.c                      | 102 +++++
ceb987
 libparted/labels/dasd.c               |   4 +
ceb987
 libparted/labels/dos.c                | 621 ++++++++++++--------------
ceb987
 libparted/labels/gpt.c                |  44 +-
ceb987
 parted/parted.c                       | 113 ++++-
ceb987
 tests/Makefile.am                     |   4 +
ceb987
 tests/t0800-json-gpt.sh               |   2 +
ceb987
 tests/t0801-json-msdos.sh             |   5 +-
ceb987
 tests/t0900-type-gpt.sh               |  69 +++
ceb987
 tests/t0901-type-gpt-invalid.sh       |  35 ++
ceb987
 tests/t0910-type-dos.sh               |  69 +++
ceb987
 tests/t0911-type-dos-invalid.sh       |  35 ++
ceb987
 tests/t2400-dos-hfs-partition-type.sh |   2 +-
ceb987
 tests/t3300-palo-prep.sh              |   8 +-
ceb987
 tests/t3310-flags.sh                  |   4 +
ceb987
 19 files changed, 825 insertions(+), 343 deletions(-)
ceb987
 create mode 100755 tests/t0900-type-gpt.sh
ceb987
 create mode 100755 tests/t0901-type-gpt-invalid.sh
ceb987
 create mode 100755 tests/t0910-type-dos.sh
ceb987
 create mode 100755 tests/t0911-type-dos-invalid.sh
ceb987
ceb987
diff --git a/NEWS b/NEWS
ceb987
index 2bd161f..099f8bd 100644
ceb987
--- a/NEWS
ceb987
+++ b/NEWS
ceb987
@@ -2,6 +2,9 @@ GNU parted NEWS                                    -*- outline -*-
ceb987
 
ceb987
 * Noteworthy changes in release ?.? (????-??-??) [?]
ceb987
 
ceb987
+** New Features
ceb987
+
ceb987
+  Add type commands to set type-id on MS-DOS and type-uuid on GPT.
ceb987
 
ceb987
 * Noteworthy changes in release 3.5 (2022-04-18) [stable]
ceb987
 
ceb987
diff --git a/doc/C/parted.8 b/doc/C/parted.8
ceb987
index 7895440..ab34be7 100644
ceb987
--- a/doc/C/parted.8
ceb987
+++ b/doc/C/parted.8
ceb987
@@ -134,6 +134,11 @@ human-friendly form for output).
ceb987
 .B toggle \fIpartition\fP \fIflag\fP
ceb987
 Toggle the state of \fIflag\fP on \fIpartition\fP.
ceb987
 .TP
ceb987
+.B type \fIpartition\fP \fIid\fP or \fIuuid\fP
ceb987
+On MS-DOS set the type aka. partition id of \fIpartition\fP to
ceb987
+\fIid\fP. The \fIid\fP is a value between "0x01" and "0xff". On GPT
ceb987
+the type-uuid of \fIpartition\fP to \fIuuid\fP.
ceb987
+.TP
ceb987
 .B disk_set \fIflag\fP \fIstate\fP
ceb987
 Change a \fIflag\fP on the disk to \fIstate\fP. A flag can be either "on" or "off".
ceb987
 Some or all of these flags will be available, depending on what disk label you
ceb987
diff --git a/doc/parted.texi b/doc/parted.texi
ceb987
index 8a3978a..9c9d282 100644
ceb987
--- a/doc/parted.texi
ceb987
+++ b/doc/parted.texi
ceb987
@@ -466,6 +466,7 @@ GNU Parted provides the following commands:
ceb987
 * select::
ceb987
 * set::
ceb987
 * toggle::
ceb987
+* type::
ceb987
 * unit::
ceb987
 @end menu
ceb987
 
ceb987
@@ -1034,6 +1035,25 @@ Toggle the state of @var{flag} on partition @var{number}.
ceb987
 
ceb987
 @end deffn
ceb987
 
ceb987
+@node type
ceb987
+@subsection type
ceb987
+@cindex type, command description
ceb987
+@cindex command description, type
ceb987
+
ceb987
+@deffn Command type @var{number} @var{id} or @var{uuid}
ceb987
+
ceb987
+On MS-DOS set the type-id aka partition id to @var{id} on partition
ceb987
+@var{number}. The id is a value between 0x01 and 0xff, e.g. the ID for
ceb987
+Linux is 0x83. A list with some IDs is available at
ceb987
+@uref{https://en.wikipedia.org/wiki/Partition_type}.
ceb987
+
ceb987
+On GPT set the type-uuid to @var{uuid} on partition
ceb987
+@var{number}. E.g. the UUID for Linux is
ceb987
+0fc63daf-8483-4772-8e79-3d69d8477de4. A list with some UUIDs is availabe
ceb987
+at @uref{https://en.wikipedia.org/wiki/GUID_Partition_Table}.
ceb987
+
ceb987
+@end deffn
ceb987
+
ceb987
 @node unit
ceb987
 @subsection unit
ceb987
 @cindex unit, command description
ceb987
diff --git a/include/parted/disk.in.h b/include/parted/disk.in.h
ceb987
index 38e869d..672c4ee 100644
ceb987
--- a/include/parted/disk.in.h
ceb987
+++ b/include/parted/disk.in.h
ceb987
@@ -32,6 +32,7 @@
ceb987
  */
ceb987
 #include <stdlib.h>
ceb987
 #include <unistd.h>
ceb987
+#include <stdint.h>
ceb987
 
ceb987
 /**
ceb987
  * Disk flags
ceb987
@@ -91,11 +92,13 @@ enum _PedPartitionFlag {
ceb987
 #define PED_PARTITION_LAST_FLAG         PED_PARTITION_LINUX_HOME
ceb987
 
ceb987
 enum _PedDiskTypeFeature {
ceb987
-        PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
ceb987
-        PED_DISK_TYPE_PARTITION_NAME=2  /**< supports partition names */
ceb987
+        PED_DISK_TYPE_EXTENDED=1,             /**< supports extended partitions */
ceb987
+        PED_DISK_TYPE_PARTITION_NAME=2,       /**< supports partition names */
ceb987
+        PED_DISK_TYPE_PARTITION_TYPE_ID=4,    /**< supports partition type-ids */
ceb987
+        PED_DISK_TYPE_PARTITION_TYPE_UUID=8,  /**< supports partition type-uuids */
ceb987
 };
ceb987
 #define PED_DISK_TYPE_FIRST_FEATURE    PED_DISK_TYPE_EXTENDED
ceb987
-#define PED_DISK_TYPE_LAST_FEATURE     PED_DISK_TYPE_PARTITION_NAME
ceb987
+#define PED_DISK_TYPE_LAST_FEATURE     PED_DISK_TYPE_PARTITION_TYPE_UUID
ceb987
 
ceb987
 struct _PedDisk;
ceb987
 struct _PedPartition;
ceb987
@@ -247,6 +250,13 @@ struct _PedDiskOps {
ceb987
                 PedPartitionFlag flag);
ceb987
         void (*partition_set_name) (PedPartition* part, const char* name);
ceb987
         const char* (*partition_get_name) (const PedPartition* part);
ceb987
+
ceb987
+        int (*partition_set_type_id) (PedPartition* part, uint8_t id);
ceb987
+        uint8_t (*partition_get_type_id) (const PedPartition* part);
ceb987
+
ceb987
+        int (*partition_set_type_uuid) (PedPartition* part, const uint8_t* uuid);
ceb987
+        uint8_t* (*partition_get_type_uuid) (const PedPartition* part);
ceb987
+
ceb987
         int (*partition_align) (PedPartition* part,
ceb987
                                 const PedConstraint* constraint);
ceb987
         int (*partition_enumerate) (PedPartition* part);
ceb987
@@ -347,6 +357,13 @@ extern int ped_partition_set_system (PedPartition* part,
ceb987
                                      const PedFileSystemType* fs_type);
ceb987
 extern int ped_partition_set_name (PedPartition* part, const char* name);
ceb987
 extern const char* ped_partition_get_name (const PedPartition* part);
ceb987
+
ceb987
+extern int ped_partition_set_type_id (PedPartition* part, uint8_t id);
ceb987
+extern uint8_t ped_partition_get_type_id (const PedPartition* part);
ceb987
+
ceb987
+extern int ped_partition_set_type_uuid (PedPartition* part, const uint8_t* uuid);
ceb987
+extern uint8_t* ped_partition_get_type_uuid (const PedPartition* part);
ceb987
+
ceb987
 extern int ped_partition_is_busy (const PedPartition* part);
ceb987
 extern char* ped_partition_get_path (const PedPartition* part);
ceb987
 
ceb987
diff --git a/libparted/disk.c b/libparted/disk.c
ceb987
index 3bf7634..22dff36 100644
ceb987
--- a/libparted/disk.c
ceb987
+++ b/libparted/disk.c
ceb987
@@ -1458,6 +1458,36 @@ _assert_partition_name_feature (const PedDiskType* disk_type)
ceb987
 	return 1;
ceb987
 }
ceb987
 
ceb987
+static int
ceb987
+_assert_partition_type_id_feature (const PedDiskType* disk_type)
ceb987
+{
ceb987
+        if (!ped_disk_type_check_feature (
ceb987
+                        disk_type, PED_DISK_TYPE_PARTITION_TYPE_ID)) {
ceb987
+                ped_exception_throw (
ceb987
+                        PED_EXCEPTION_ERROR,
ceb987
+                        PED_EXCEPTION_CANCEL,
ceb987
+                        "%s disk labels do not support partition type-ids.",
ceb987
+                        disk_type->name);
ceb987
+                return 0;
ceb987
+        }
ceb987
+        return 1;
ceb987
+}
ceb987
+
ceb987
+static int
ceb987
+_assert_partition_type_uuid_feature (const PedDiskType* disk_type)
ceb987
+{
ceb987
+        if (!ped_disk_type_check_feature (
ceb987
+                        disk_type, PED_DISK_TYPE_PARTITION_TYPE_UUID)) {
ceb987
+                ped_exception_throw (
ceb987
+                        PED_EXCEPTION_ERROR,
ceb987
+                        PED_EXCEPTION_CANCEL,
ceb987
+                        "%s disk labels do not support partition type-uuids.",
ceb987
+                        disk_type->name);
ceb987
+                return 0;
ceb987
+        }
ceb987
+        return 1;
ceb987
+}
ceb987
+
ceb987
 /**
ceb987
  * Sets the name of a partition.
ceb987
  *
ceb987
@@ -1510,6 +1540,78 @@ ped_partition_get_name (const PedPartition* part)
ceb987
 	return part->disk->type->ops->partition_get_name (part);
ceb987
 }
ceb987
 
ceb987
+/**
ceb987
+ * Set the type-id of the partition \p part. This will only work if the disk label
ceb987
+ * supports it.
ceb987
+ */
ceb987
+int
ceb987
+ped_partition_set_type_id (PedPartition *part, uint8_t id)
ceb987
+{
ceb987
+        PED_ASSERT (part != NULL);
ceb987
+        PED_ASSERT (part->disk != NULL);
ceb987
+        PED_ASSERT (ped_partition_is_active (part));
ceb987
+
ceb987
+        if (!_assert_partition_type_id_feature (part->disk->type))
ceb987
+                return 0;
ceb987
+
ceb987
+        PED_ASSERT (part->disk->type->ops->partition_set_type_id != NULL);
ceb987
+        return part->disk->type->ops->partition_set_type_id (part, id);
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Get the type-id of the partition \p part. This will only work if the disk label
ceb987
+ * supports it.
ceb987
+ */
ceb987
+uint8_t
ceb987
+ped_partition_get_type_id (const PedPartition *part)
ceb987
+{
ceb987
+        PED_ASSERT (part != NULL);
ceb987
+        PED_ASSERT (part->disk != NULL);
ceb987
+        PED_ASSERT (ped_partition_is_active (part));
ceb987
+
ceb987
+        if (!_assert_partition_type_id_feature (part->disk->type))
ceb987
+                return 0;
ceb987
+
ceb987
+        PED_ASSERT (part->disk->type->ops->partition_set_type_id != NULL);
ceb987
+        return part->disk->type->ops->partition_get_type_id (part);
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Set the type-uuid of the partition \p part. This will only work if the disk label
ceb987
+ * supports it.
ceb987
+ */
ceb987
+int
ceb987
+ped_partition_set_type_uuid (PedPartition *part, const uint8_t* uuid)
ceb987
+{
ceb987
+        PED_ASSERT (part != NULL);
ceb987
+        PED_ASSERT (part->disk != NULL);
ceb987
+        PED_ASSERT (ped_partition_is_active (part));
ceb987
+
ceb987
+        if (!_assert_partition_type_uuid_feature (part->disk->type))
ceb987
+                return 0;
ceb987
+
ceb987
+        PED_ASSERT (part->disk->type->ops->partition_set_type_uuid != NULL);
ceb987
+        return part->disk->type->ops->partition_set_type_uuid (part, uuid);
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Get the type-uuid of the partition \p part. This will only work if the disk label
ceb987
+ * supports it.
ceb987
+ */
ceb987
+uint8_t*
ceb987
+ped_partition_get_type_uuid (const PedPartition *part)
ceb987
+{
ceb987
+        PED_ASSERT (part != NULL);
ceb987
+        PED_ASSERT (part->disk != NULL);
ceb987
+        PED_ASSERT (ped_partition_is_active (part));
ceb987
+
ceb987
+        if (!_assert_partition_type_uuid_feature (part->disk->type))
ceb987
+                return NULL;
ceb987
+
ceb987
+        PED_ASSERT (part->disk->type->ops->partition_set_type_uuid != NULL);
ceb987
+        return part->disk->type->ops->partition_get_type_uuid (part);
ceb987
+}
ceb987
+
ceb987
 /** @} */
ceb987
 
ceb987
 /**
ceb987
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
ceb987
index 38f2b00..0c00c4f 100644
ceb987
--- a/libparted/labels/dasd.c
ceb987
+++ b/libparted/labels/dasd.c
ceb987
@@ -117,6 +117,10 @@ static PedDiskOps dasd_disk_ops = {
ceb987
 
ceb987
 	partition_set_name:	NULL,
ceb987
 	partition_get_name:	NULL,
ceb987
+	partition_set_type_id:          NULL,
ceb987
+	partition_get_type_id:          NULL,
ceb987
+	partition_set_type_uuid:	NULL,
ceb987
+	partition_get_type_uuid:	NULL,
ceb987
 
ceb987
 	get_partition_alignment: dasd_get_partition_alignment,
ceb987
 
ceb987
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
ceb987
index 26d8804..bd7465d 100644
ceb987
--- a/libparted/labels/dos.c
ceb987
+++ b/libparted/labels/dos.c
ceb987
@@ -100,6 +100,209 @@ static const char MBR_BOOT_CODE[] = {
ceb987
 #define PARTITION_LINUX_RAID	0xfd
ceb987
 #define PARTITION_LINUX_LVM_OLD 0xfe
ceb987
 
ceb987
+struct flag_id_mapping_t
ceb987
+{
ceb987
+    enum _PedPartitionFlag flag;
ceb987
+    unsigned char type_id;
ceb987
+    unsigned char alt_type_id;
ceb987
+};
ceb987
+
ceb987
+static const struct flag_id_mapping_t flag_id_mapping[] =
ceb987
+{
ceb987
+    { PED_PARTITION_BLS_BOOT,           PARTITION_BLS_BOOT },
ceb987
+    { PED_PARTITION_DIAG,               PARTITION_COMPAQ_DIAG, PARTITION_DELL_DIAG },
ceb987
+    { PED_PARTITION_ESP,                PARTITION_ESP },
ceb987
+    { PED_PARTITION_IRST,               PARTITION_IRST },
ceb987
+    { PED_PARTITION_LVM,                PARTITION_LINUX_LVM, PARTITION_LINUX_LVM_OLD },
ceb987
+    { PED_PARTITION_MSFT_RESERVED,      PARTITION_MSFT_RECOVERY },
ceb987
+    { PED_PARTITION_PALO,               PARTITION_PALO },
ceb987
+    { PED_PARTITION_PREP,               PARTITION_PREP },
ceb987
+    { PED_PARTITION_RAID,               PARTITION_LINUX_RAID },
ceb987
+    { PED_PARTITION_SWAP,               PARTITION_LINUX_SWAP },
ceb987
+};
ceb987
+
ceb987
+static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST
ceb987
+dos_find_flag_id_mapping (PedPartitionFlag flag)
ceb987
+{
ceb987
+    int n = sizeof(flag_id_mapping) / sizeof(flag_id_mapping[0]);
ceb987
+
ceb987
+    for (int i = 0; i < n; ++i)
ceb987
+	if (flag_id_mapping[i].flag == flag)
ceb987
+	    return &flag_id_mapping[i];
ceb987
+
ceb987
+    return NULL;
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Check whether the type_id supports the hidden flag. Returns true for both hidden and
ceb987
+ * non-hidden id.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_supports_hidden(unsigned char type_id)
ceb987
+{
ceb987
+    switch (type_id)
ceb987
+    {
ceb987
+	case PARTITION_DOS_EXT:
ceb987
+	case PARTITION_DOS_EXT_H:
ceb987
+	case PARTITION_FAT12:
ceb987
+	case PARTITION_FAT12_H:
ceb987
+	case PARTITION_FAT16:
ceb987
+	case PARTITION_FAT16_H:
ceb987
+	case PARTITION_FAT16_LBA:
ceb987
+	case PARTITION_FAT16_LBA_H:
ceb987
+	case PARTITION_FAT16_SM:
ceb987
+	case PARTITION_FAT16_SM_H:
ceb987
+	case PARTITION_FAT32:
ceb987
+	case PARTITION_FAT32_H:
ceb987
+	case PARTITION_FAT32_LBA:
ceb987
+	case PARTITION_FAT32_LBA_H:
ceb987
+	case PARTITION_NTFS:
ceb987
+	case PARTITION_NTFS_H:
ceb987
+	    return true;
ceb987
+
ceb987
+	default:
ceb987
+	    return false;
ceb987
+    }
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Check whether the type_id has the hidden flag set.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_is_hidden(unsigned char type_id)
ceb987
+{
ceb987
+    switch (type_id)
ceb987
+    {
ceb987
+	case PARTITION_DOS_EXT_H:
ceb987
+	case PARTITION_FAT12_H:
ceb987
+	case PARTITION_FAT16_H:
ceb987
+	case PARTITION_FAT16_LBA_H:
ceb987
+	case PARTITION_FAT16_SM_H:
ceb987
+	case PARTITION_FAT32_H:
ceb987
+	case PARTITION_FAT32_LBA_H:
ceb987
+	case PARTITION_NTFS_H:
ceb987
+	    return true;
ceb987
+
ceb987
+	default:
ceb987
+	    return false;
ceb987
+    }
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Sets the hidden flag on type_id.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_set_hidden(unsigned char* type_id, bool state)
ceb987
+{
ceb987
+    PED_ASSERT (type_id);
ceb987
+
ceb987
+    if (!dos_type_id_supports_hidden(*type_id))
ceb987
+	return false;
ceb987
+
ceb987
+    if (state)
ceb987
+	*type_id |= PART_FLAG_HIDDEN;
ceb987
+    else
ceb987
+	*type_id &= ~PART_FLAG_HIDDEN;
ceb987
+
ceb987
+    return 1;
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Check whether the type_id supports the lba flag. Returns true for both lba and non-lba
ceb987
+ * id.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_supports_lba(unsigned char type_id)
ceb987
+{
ceb987
+    switch (type_id)
ceb987
+    {
ceb987
+	case PARTITION_FAT16:
ceb987
+	case PARTITION_FAT16_H:
ceb987
+	case PARTITION_FAT16_LBA:
ceb987
+	case PARTITION_FAT16_LBA_H:
ceb987
+	case PARTITION_FAT32:
ceb987
+	case PARTITION_FAT32_H:
ceb987
+	case PARTITION_FAT32_LBA:
ceb987
+	case PARTITION_FAT32_LBA_H:
ceb987
+	case PARTITION_DOS_EXT:
ceb987
+	case PARTITION_EXT_LBA:
ceb987
+	    return true;
ceb987
+
ceb987
+	default:
ceb987
+	    return false;
ceb987
+    }
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Check whether the type_id has the lba flag set.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_is_lba(unsigned char type_id)
ceb987
+{
ceb987
+    switch (type_id)
ceb987
+    {
ceb987
+	case PARTITION_FAT16_LBA:
ceb987
+	case PARTITION_FAT16_LBA_H:
ceb987
+	case PARTITION_FAT32_LBA:
ceb987
+	case PARTITION_FAT32_LBA_H:
ceb987
+	case PARTITION_EXT_LBA:
ceb987
+	    return true;
ceb987
+
ceb987
+	default:
ceb987
+	    return false;
ceb987
+    }
ceb987
+}
ceb987
+
ceb987
+/**
ceb987
+ * Sets the lba flag on type_id.
ceb987
+ */
ceb987
+static bool
ceb987
+dos_type_id_set_lba(unsigned char* type_id, bool state)
ceb987
+{
ceb987
+    PED_ASSERT (type_id);
ceb987
+
ceb987
+    if (!dos_type_id_supports_lba(*type_id))
ceb987
+	return false;
ceb987
+
ceb987
+    if (state)
ceb987
+    {
ceb987
+	switch (*type_id)
ceb987
+	{
ceb987
+	    case PARTITION_FAT16:
ceb987
+		*type_id = PARTITION_FAT16_LBA;
ceb987
+		break;
ceb987
+
ceb987
+	    case PARTITION_FAT32:
ceb987
+		*type_id = PARTITION_FAT32_LBA;
ceb987
+		break;
ceb987
+
ceb987
+	    case PARTITION_DOS_EXT:
ceb987
+		*type_id = PARTITION_EXT_LBA;
ceb987
+		break;
ceb987
+	}
ceb987
+    }
ceb987
+    else
ceb987
+    {
ceb987
+	switch (*type_id)
ceb987
+	{
ceb987
+	    case PARTITION_FAT16_LBA:
ceb987
+		*type_id = PARTITION_FAT16;
ceb987
+		break;
ceb987
+
ceb987
+	    case PARTITION_FAT32_LBA:
ceb987
+		*type_id = PARTITION_FAT32;
ceb987
+		break;
ceb987
+
ceb987
+	    case PARTITION_EXT_LBA:
ceb987
+		*type_id = PARTITION_DOS_EXT;
ceb987
+		break;
ceb987
+	}
ceb987
+    }
ceb987
+
ceb987
+    return true;
ceb987
+}
ceb987
+
ceb987
+
ceb987
 /* This constant contains the maximum cylinder number that can be represented
ceb987
  * in (C,H,S) notation.  Higher cylinder numbers are reserved for
ceb987
  * "too big" indicators (in which case only LBA addressing can be used).
ceb987
@@ -156,18 +359,6 @@ typedef struct {
ceb987
 typedef struct {
ceb987
 	unsigned char	system;
ceb987
 	int		boot;
ceb987
-	int		hidden;
ceb987
-	int		msftres;
ceb987
-	int		raid;
ceb987
-	int		lvm;
ceb987
-	int		swap;
ceb987
-	int		lba;
ceb987
-	int		palo;
ceb987
-	int		prep;
ceb987
-	int		diag;
ceb987
-	int		irst;
ceb987
-	int		esp;
ceb987
-	int		bls_boot;
ceb987
 	OrigState*	orig;			/* used for CHS stuff */
ceb987
 } DosPartitionData;
ceb987
 
ceb987
@@ -891,48 +1082,6 @@ raw_part_is_extended (const DosRawPartition* raw_part)
ceb987
 	return 0;
ceb987
 }
ceb987
 
ceb987
-static int _GL_ATTRIBUTE_PURE
ceb987
-raw_part_is_hidden (const DosRawPartition* raw_part)
ceb987
-{
ceb987
-	PED_ASSERT (raw_part != NULL);
ceb987
-
ceb987
-	switch (raw_part->type) {
ceb987
-	case PARTITION_FAT12_H:
ceb987
-	case PARTITION_FAT16_SM_H:
ceb987
-	case PARTITION_FAT16_H:
ceb987
-	case PARTITION_FAT32_H:
ceb987
-	case PARTITION_NTFS_H:
ceb987
-	case PARTITION_FAT32_LBA_H:
ceb987
-	case PARTITION_FAT16_LBA_H:
ceb987
-		return 1;
ceb987
-
ceb987
-	default:
ceb987
-		return 0;
ceb987
-	}
ceb987
-
ceb987
-	return 0;
ceb987
-}
ceb987
-
ceb987
-static int _GL_ATTRIBUTE_PURE
ceb987
-raw_part_is_lba (const DosRawPartition* raw_part)
ceb987
-{
ceb987
-	PED_ASSERT (raw_part != NULL);
ceb987
-
ceb987
-	switch (raw_part->type) {
ceb987
-	case PARTITION_FAT32_LBA:
ceb987
-	case PARTITION_FAT16_LBA:
ceb987
-	case PARTITION_EXT_LBA:
ceb987
-	case PARTITION_FAT32_LBA_H:
ceb987
-	case PARTITION_FAT16_LBA_H:
ceb987
-		return 1;
ceb987
-
ceb987
-	default:
ceb987
-		return 0;
ceb987
-	}
ceb987
-
ceb987
-	return 0;
ceb987
-}
ceb987
-
ceb987
 static PedPartition*
ceb987
 raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
ceb987
 	        PedSector lba_offset, PedPartitionType type)
ceb987
@@ -952,20 +1101,6 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
ceb987
 	dos_data = part->disk_specific;
ceb987
 	dos_data->system = raw_part->type;
ceb987
 	dos_data->boot = raw_part->boot_ind != 0;
ceb987
-	dos_data->diag = raw_part->type == PARTITION_COMPAQ_DIAG ||
ceb987
-			 raw_part->type == PARTITION_DELL_DIAG;
ceb987
-	dos_data->msftres = raw_part->type == PARTITION_MSFT_RECOVERY;
ceb987
-	dos_data->hidden = raw_part_is_hidden (raw_part);
ceb987
-	dos_data->raid = raw_part->type == PARTITION_LINUX_RAID;
ceb987
-	dos_data->lvm = raw_part->type == PARTITION_LINUX_LVM_OLD
ceb987
-			|| raw_part->type == PARTITION_LINUX_LVM;
ceb987
-	dos_data->swap = raw_part->type == PARTITION_LINUX_SWAP;
ceb987
-	dos_data->lba = raw_part_is_lba (raw_part);
ceb987
-	dos_data->palo = raw_part->type == PARTITION_PALO;
ceb987
-	dos_data->prep = raw_part->type == PARTITION_PREP;
ceb987
-	dos_data->irst = raw_part->type == PARTITION_IRST;
ceb987
-	dos_data->esp = raw_part->type == PARTITION_ESP;
ceb987
-	dos_data->bls_boot = raw_part->type == PARTITION_BLS_BOOT;
ceb987
 	dos_data->orig = ped_malloc (sizeof (OrigState));
ceb987
 	if (!dos_data->orig) {
ceb987
 		ped_partition_destroy (part);
ceb987
@@ -1377,18 +1512,6 @@ msdos_partition_duplicate (const PedPartition* part)
ceb987
 	new_dos_data = (DosPartitionData*) new_part->disk_specific;
ceb987
 	new_dos_data->system = old_dos_data->system;
ceb987
 	new_dos_data->boot = old_dos_data->boot;
ceb987
-	new_dos_data->diag = old_dos_data->diag;
ceb987
-	new_dos_data->hidden = old_dos_data->hidden;
ceb987
-	new_dos_data->msftres = old_dos_data->msftres;
ceb987
-	new_dos_data->raid = old_dos_data->raid;
ceb987
-	new_dos_data->lvm = old_dos_data->lvm;
ceb987
-	new_dos_data->swap = old_dos_data->swap;
ceb987
-	new_dos_data->lba = old_dos_data->lba;
ceb987
-	new_dos_data->palo = old_dos_data->palo;
ceb987
-	new_dos_data->prep = old_dos_data->prep;
ceb987
-	new_dos_data->irst = old_dos_data->irst;
ceb987
-	new_dos_data->esp = old_dos_data->esp;
ceb987
-	new_dos_data->bls_boot = old_dos_data->bls_boot;
ceb987
 
ceb987
 	if (old_dos_data->orig) {
ceb987
 		new_dos_data->orig = ped_malloc (sizeof (OrigState));
ceb987
@@ -1425,234 +1548,87 @@ msdos_partition_set_system (PedPartition* part,
ceb987
 
ceb987
 	part->fs_type = fs_type;
ceb987
 
ceb987
-	if (dos_data->hidden
ceb987
-		    && fs_type
ceb987
-		    && strncmp (fs_type->name, "fat", 3) != 0
ceb987
-		    && strcmp (fs_type->name, "ntfs") != 0)
ceb987
-		dos_data->hidden = 0;
ceb987
-
ceb987
-	if (dos_data->msftres
ceb987
-		    && fs_type
ceb987
-		    && strcmp (fs_type->name, "ntfs") != 0)
ceb987
-		dos_data->msftres = 0;
ceb987
-
ceb987
 	if (part->type & PED_PARTITION_EXTENDED) {
ceb987
-		dos_data->diag = 0;
ceb987
-		dos_data->raid = 0;
ceb987
-		dos_data->lvm = 0;
ceb987
-		dos_data->swap = 0;
ceb987
-		dos_data->palo = 0;
ceb987
-		dos_data->prep = 0;
ceb987
-		dos_data->irst = 0;
ceb987
-		dos_data->esp = 0;
ceb987
-		if (dos_data->lba)
ceb987
-			dos_data->system = PARTITION_EXT_LBA;
ceb987
-		else
ceb987
-			dos_data->system = PARTITION_DOS_EXT;
ceb987
-		return 1;
ceb987
-	}
ceb987
-
ceb987
-	if (dos_data->diag) {
ceb987
-		/* Don't change the system if it already is a diag type,
ceb987
-		   otherwise use Compaq as almost all vendors use that. */
ceb987
-		if (dos_data->system != PARTITION_COMPAQ_DIAG &&
ceb987
-		    dos_data->system != PARTITION_DELL_DIAG)
ceb987
-			dos_data->system = PARTITION_COMPAQ_DIAG;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->msftres) {
ceb987
-		dos_data->system = PARTITION_MSFT_RECOVERY;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->lvm) {
ceb987
-		dos_data->system = PARTITION_LINUX_LVM;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->swap) {
ceb987
-		dos_data->system = PARTITION_LINUX_SWAP;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->raid) {
ceb987
-		dos_data->system = PARTITION_LINUX_RAID;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->palo) {
ceb987
-		dos_data->system = PARTITION_PALO;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->prep) {
ceb987
-		dos_data->system = PARTITION_PREP;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->irst) {
ceb987
-		dos_data->system = PARTITION_IRST;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->esp) {
ceb987
-		dos_data->system = PARTITION_ESP;
ceb987
-		return 1;
ceb987
-	}
ceb987
-	if (dos_data->bls_boot) {
ceb987
-		dos_data->system = PARTITION_BLS_BOOT;
ceb987
+		dos_data->system = PARTITION_EXT_LBA;
ceb987
 		return 1;
ceb987
 	}
ceb987
 
ceb987
 	if (!fs_type)
ceb987
 		dos_data->system = PARTITION_LINUX;
ceb987
-	else if (!strcmp (fs_type->name, "fat16")) {
ceb987
-		dos_data->system = dos_data->lba
ceb987
-				   ? PARTITION_FAT16_LBA : PARTITION_FAT16;
ceb987
-		dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0;
ceb987
-	} else if (!strcmp (fs_type->name, "fat32")) {
ceb987
-		dos_data->system = dos_data->lba
ceb987
-				   ? PARTITION_FAT32_LBA : PARTITION_FAT32;
ceb987
-		dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0;
ceb987
-	} else if (!strcmp (fs_type->name, "ntfs")
ceb987
-		   || !strcmp (fs_type->name, "hpfs")) {
ceb987
+	else if (!strcmp (fs_type->name, "fat16"))
ceb987
+		dos_data->system = PARTITION_FAT16;
ceb987
+	else if (!strcmp (fs_type->name, "fat32"))
ceb987
+		dos_data->system = PARTITION_FAT32;
ceb987
+	else if (!strcmp (fs_type->name, "ntfs")
ceb987
+		   || !strcmp (fs_type->name, "hpfs"))
ceb987
 		dos_data->system = PARTITION_NTFS;
ceb987
-		dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0;
ceb987
-	} else if (!strcmp (fs_type->name, "hfs")
ceb987
+	else if (!strcmp (fs_type->name, "hfs")
ceb987
 		   || !strcmp (fs_type->name, "hfs+"))
ceb987
 		dos_data->system = PARTITION_HFS;
ceb987
 	else if (!strcmp (fs_type->name, "udf"))
ceb987
 		dos_data->system = PARTITION_UDF;
ceb987
 	else if (!strcmp (fs_type->name, "sun-ufs"))
ceb987
 		dos_data->system = PARTITION_SUN_UFS;
ceb987
-	else if (is_linux_swap (fs_type->name)) {
ceb987
+	else if (is_linux_swap (fs_type->name))
ceb987
 		dos_data->system = PARTITION_LINUX_SWAP;
ceb987
-		dos_data->swap = 1;
ceb987
-	} else
ceb987
+	else
ceb987
 		dos_data->system = PARTITION_LINUX;
ceb987
 
ceb987
 	return 1;
ceb987
 }
ceb987
 
ceb987
-static void
ceb987
-clear_flags (DosPartitionData *dos_data)
ceb987
-{
ceb987
-  dos_data->diag = 0;
ceb987
-  dos_data->hidden = 0;
ceb987
-  dos_data->msftres = 0;
ceb987
-  dos_data->lvm = 0;
ceb987
-  dos_data->swap = 0;
ceb987
-  dos_data->palo = 0;
ceb987
-  dos_data->prep = 0;
ceb987
-  dos_data->irst = 0;
ceb987
-  dos_data->esp = 0;
ceb987
-  dos_data->raid = 0;
ceb987
-  dos_data->bls_boot = 0;
ceb987
-}
ceb987
-
ceb987
 static int
ceb987
 msdos_partition_set_flag (PedPartition* part,
ceb987
                           PedPartitionFlag flag, int state)
ceb987
 {
ceb987
-	PedDisk*			disk;
ceb987
-	PedPartition*			walk;
ceb987
-	DosPartitionData*		dos_data;
ceb987
-
ceb987
 	PED_ASSERT (part != NULL);
ceb987
 	PED_ASSERT (part->disk_specific != NULL);
ceb987
 	PED_ASSERT (part->disk != NULL);
ceb987
 
ceb987
-	dos_data = part->disk_specific;
ceb987
-	disk = part->disk;
ceb987
-
ceb987
-	switch (flag) {
ceb987
-	case PED_PARTITION_HIDDEN:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED) {
ceb987
-			ped_exception_throw (
ceb987
-				PED_EXCEPTION_ERROR,
ceb987
-				PED_EXCEPTION_CANCEL,
ceb987
-				_("Extended partitions cannot be hidden on "
ceb987
-				  "msdos disk labels."));
ceb987
-			return 0;
ceb987
-		}
ceb987
-		dos_data->hidden = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
-
ceb987
-	case PED_PARTITION_MSFT_RESERVED:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED) {
ceb987
-			ped_exception_throw (
ceb987
-				PED_EXCEPTION_ERROR,
ceb987
-				PED_EXCEPTION_CANCEL,
ceb987
-				_("Extended partitions cannot be recovery partitions on "
ceb987
-				  "msdos disk labels."));
ceb987
-			return 0;
ceb987
-		}
ceb987
-		dos_data->msftres = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
-
ceb987
-	case PED_PARTITION_BOOT:
ceb987
-		dos_data->boot = state;
ceb987
-		if (!state)
ceb987
-			return 1;
ceb987
-
ceb987
-		walk = ped_disk_next_partition (disk, NULL);
ceb987
-		for (; walk; walk = ped_disk_next_partition (disk, walk)) {
ceb987
-			if (walk == part || !ped_partition_is_active (walk))
ceb987
-				continue;
ceb987
-			msdos_partition_set_flag (walk, PED_PARTITION_BOOT, 0);
ceb987
-		}
ceb987
-		return 1;
ceb987
+	DosPartitionData* dos_data = part->disk_specific;
ceb987
 
ceb987
-	case PED_PARTITION_DIAG:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->diag = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+	const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag);
ceb987
+	if (p)
ceb987
+	{
ceb987
+	    if (part->type & PED_PARTITION_EXTENDED)
ceb987
+		return 0;
ceb987
 
ceb987
-	case PED_PARTITION_RAID:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->raid = state;
ceb987
+	    if (state)
ceb987
+		dos_data->system = p->type_id;
ceb987
+	    else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id)
ceb987
 		return ped_partition_set_system (part, part->fs_type);
ceb987
 
ceb987
-	case PED_PARTITION_LVM:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->lvm = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+	    return 1;
ceb987
+	}
ceb987
 
ceb987
-	case PED_PARTITION_SWAP:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->swap = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+	switch (flag) {
ceb987
+	case PED_PARTITION_HIDDEN:
ceb987
+	{
ceb987
+		return dos_type_id_set_hidden(&dos_data->system, state);
ceb987
+	}
ceb987
 
ceb987
 	case PED_PARTITION_LBA:
ceb987
-		dos_data->lba = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
-
ceb987
-	case PED_PARTITION_PALO:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->palo = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
-
ceb987
-	case PED_PARTITION_PREP:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->prep = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+	{
ceb987
+		return dos_type_id_set_lba(&dos_data->system, state);
ceb987
+	}
ceb987
 
ceb987
-	case PED_PARTITION_IRST:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->irst = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+	case PED_PARTITION_BOOT:
ceb987
+	{
ceb987
+		dos_data->boot = state;
ceb987
 
ceb987
-	case PED_PARTITION_ESP:
ceb987
 		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->esp = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+		{
ceb987
+			PedDisk* disk = part->disk;
ceb987
+			PedPartition* walk = ped_disk_next_partition (disk, NULL);
ceb987
+			for (; walk; walk = ped_disk_next_partition (disk, walk)) {
ceb987
+				if (walk == part || !ped_partition_is_active (walk))
ceb987
+					continue;
ceb987
+				msdos_partition_set_flag (walk, PED_PARTITION_BOOT, 0);
ceb987
+			}
ceb987
+		}
ceb987
 
ceb987
-	case PED_PARTITION_BLS_BOOT:
ceb987
-		if (state)
ceb987
-			clear_flags (dos_data);
ceb987
-		dos_data->bls_boot = state;
ceb987
-		return ped_partition_set_system (part, part->fs_type);
ceb987
+		return 1;
ceb987
+	}
ceb987
 
ceb987
 	default:
ceb987
 		return 0;
ceb987
@@ -1662,58 +1638,25 @@ msdos_partition_set_flag (PedPartition* part,
ceb987
 static int _GL_ATTRIBUTE_PURE
ceb987
 msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
ceb987
 {
ceb987
-	DosPartitionData*	dos_data;
ceb987
-
ceb987
 	PED_ASSERT (part != NULL);
ceb987
 	PED_ASSERT (part->disk_specific != NULL);
ceb987
 
ceb987
-	dos_data = part->disk_specific;
ceb987
+	DosPartitionData* dos_data = part->disk_specific;
ceb987
+
ceb987
+	const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag);
ceb987
+	if (p)
ceb987
+	    return dos_data->system == p->type_id || dos_data->system == p->alt_type_id;
ceb987
+
ceb987
 	switch (flag) {
ceb987
 	case PED_PARTITION_HIDDEN:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED)
ceb987
-			return 0;
ceb987
-		else
ceb987
-			return dos_data->hidden;
ceb987
+		return dos_type_id_is_hidden(dos_data->system);
ceb987
 
ceb987
-	case PED_PARTITION_MSFT_RESERVED:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED)
ceb987
-			return 0;
ceb987
-		else
ceb987
-			return dos_data->msftres;
ceb987
+	case PED_PARTITION_LBA:
ceb987
+		return dos_type_id_is_lba(dos_data->system);
ceb987
 
ceb987
 	case PED_PARTITION_BOOT:
ceb987
 		return dos_data->boot;
ceb987
 
ceb987
-	case PED_PARTITION_DIAG:
ceb987
-		return dos_data->diag;
ceb987
-
ceb987
-	case PED_PARTITION_RAID:
ceb987
-		return dos_data->raid;
ceb987
-
ceb987
-	case PED_PARTITION_LVM:
ceb987
-		return dos_data->lvm;
ceb987
-
ceb987
-	case PED_PARTITION_SWAP:
ceb987
-		return dos_data->swap;
ceb987
-
ceb987
-	case PED_PARTITION_LBA:
ceb987
-		return dos_data->lba;
ceb987
-
ceb987
-	case PED_PARTITION_PALO:
ceb987
-		return dos_data->palo;
ceb987
-
ceb987
-	case PED_PARTITION_PREP:
ceb987
-		return dos_data->prep;
ceb987
-
ceb987
-	case PED_PARTITION_IRST:
ceb987
-		return dos_data->irst;
ceb987
-
ceb987
-	case PED_PARTITION_ESP:
ceb987
-		return dos_data->esp;
ceb987
-
ceb987
-	case PED_PARTITION_BLS_BOOT:
ceb987
-		return dos_data->bls_boot;
ceb987
-
ceb987
 	default:
ceb987
 		return 0;
ceb987
 	}
ceb987
@@ -1723,30 +1666,19 @@ static int
ceb987
 msdos_partition_is_flag_available (const PedPartition* part,
ceb987
 				   PedPartitionFlag flag)
ceb987
 {
ceb987
+	if (dos_find_flag_id_mapping (flag))
ceb987
+		return part->type != PED_PARTITION_EXTENDED;
ceb987
+
ceb987
+	DosPartitionData* dos_data = part->disk_specific;
ceb987
+
ceb987
 	switch (flag) {
ceb987
 	case PED_PARTITION_HIDDEN:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED)
ceb987
-			return 0;
ceb987
-		else
ceb987
-			return 1;
ceb987
+		return dos_type_id_supports_hidden(dos_data->system);
ceb987
 
ceb987
-	case PED_PARTITION_MSFT_RESERVED:
ceb987
-		if (part->type == PED_PARTITION_EXTENDED)
ceb987
-			return 0;
ceb987
-		else
ceb987
-			return 1;
ceb987
+	case PED_PARTITION_LBA:
ceb987
+		return dos_type_id_supports_lba(dos_data->system);
ceb987
 
ceb987
 	case PED_PARTITION_BOOT:
ceb987
-	case PED_PARTITION_RAID:
ceb987
-	case PED_PARTITION_LVM:
ceb987
-	case PED_PARTITION_SWAP:
ceb987
-	case PED_PARTITION_LBA:
ceb987
-	case PED_PARTITION_PALO:
ceb987
-	case PED_PARTITION_PREP:
ceb987
-	case PED_PARTITION_IRST:
ceb987
-	case PED_PARTITION_ESP:
ceb987
-	case PED_PARTITION_BLS_BOOT:
ceb987
-	case PED_PARTITION_DIAG:
ceb987
 		return 1;
ceb987
 
ceb987
 	default:
ceb987
@@ -1754,6 +1686,27 @@ msdos_partition_is_flag_available (const PedPartition* part,
ceb987
 	}
ceb987
 }
ceb987
 
ceb987
+
ceb987
+int
ceb987
+msdos_partition_set_type_id (PedPartition* part, uint8_t id)
ceb987
+{
ceb987
+        DosPartitionData* dos_data = part->disk_specific;
ceb987
+
ceb987
+        dos_data->system = id;
ceb987
+
ceb987
+        return 1;
ceb987
+}
ceb987
+
ceb987
+
ceb987
+uint8_t _GL_ATTRIBUTE_PURE
ceb987
+msdos_partition_get_type_id (const PedPartition* part)
ceb987
+{
ceb987
+        const DosPartitionData* dos_data = part->disk_specific;
ceb987
+
ceb987
+        return dos_data->system;
ceb987
+}
ceb987
+
ceb987
+
ceb987
 static PedGeometry*
ceb987
 _try_constraint (const PedPartition* part, const PedConstraint* external,
ceb987
 		 PedConstraint* internal)
ceb987
@@ -2590,6 +2543,10 @@ static PedDiskOps msdos_disk_ops = {
ceb987
 
ceb987
 	partition_set_name:	NULL,
ceb987
 	partition_get_name:	NULL,
ceb987
+	partition_set_type_id:		msdos_partition_set_type_id,
ceb987
+	partition_get_type_id:		msdos_partition_get_type_id,
ceb987
+	partition_set_type_uuid:	NULL,
ceb987
+	partition_get_type_uuid:	NULL,
ceb987
 
ceb987
   PT_op_function_initializers (msdos)
ceb987
 };
ceb987
@@ -2598,7 +2555,7 @@ static PedDiskType msdos_disk_type = {
ceb987
 	next:		NULL,
ceb987
 	name:		"msdos",
ceb987
 	ops:		&msdos_disk_ops,
ceb987
-	features:	PED_DISK_TYPE_EXTENDED
ceb987
+	features:	PED_DISK_TYPE_EXTENDED | PED_DISK_TYPE_PARTITION_TYPE_ID
ceb987
 };
ceb987
 
ceb987
 void
ceb987
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
ceb987
index 037d021..0e9e060 100644
ceb987
--- a/libparted/labels/gpt.c
ceb987
+++ b/libparted/labels/gpt.c
ceb987
@@ -1686,6 +1686,44 @@ gpt_partition_get_name (const PedPartition *part)
ceb987
   return gpt_part_data->translated_name;
ceb987
 }
ceb987
 
ceb987
+
ceb987
+static int
ceb987
+gpt_partition_set_type_uuid (PedPartition *part, const uint8_t *uuid)
ceb987
+{
ceb987
+  GPTPartitionData *gpt_part_data = part->disk_specific;
ceb987
+
ceb987
+  efi_guid_t* type_uuid = &gpt_part_data->type;
ceb987
+  memcpy(type_uuid, uuid, sizeof (efi_guid_t));
ceb987
+
ceb987
+  /* type_uuid is always LE, while uint8_t is always kind of BE */
ceb987
+
ceb987
+  type_uuid->time_low = PED_SWAP32(type_uuid->time_low);
ceb987
+  type_uuid->time_mid = PED_SWAP16(type_uuid->time_mid);
ceb987
+  type_uuid->time_hi_and_version = PED_SWAP16(type_uuid->time_hi_and_version);
ceb987
+
ceb987
+  return 1;
ceb987
+}
ceb987
+
ceb987
+
ceb987
+static uint8_t*
ceb987
+gpt_partition_get_type_uuid (const PedPartition *part)
ceb987
+{
ceb987
+  const GPTPartitionData *gpt_part_data = part->disk_specific;
ceb987
+
ceb987
+  efi_guid_t type_uuid = gpt_part_data->type;
ceb987
+
ceb987
+  /* type_uuid is always LE, while uint8_t is always kind of BE */
ceb987
+
ceb987
+  type_uuid.time_low = PED_SWAP32(type_uuid.time_low);
ceb987
+  type_uuid.time_mid = PED_SWAP16(type_uuid.time_mid);
ceb987
+  type_uuid.time_hi_and_version = PED_SWAP16(type_uuid.time_hi_and_version);
ceb987
+
ceb987
+  uint8_t *buf = ped_malloc(sizeof (uuid_t));
ceb987
+  memcpy(buf, &type_uuid, sizeof (uuid_t));
ceb987
+  return buf;
ceb987
+}
ceb987
+
ceb987
+
ceb987
 static int
ceb987
 gpt_get_max_primary_partition_count (const PedDisk *disk)
ceb987
 {
ceb987
@@ -1781,6 +1819,10 @@ static PedDiskOps gpt_disk_ops =
ceb987
 
ceb987
   partition_set_name:		gpt_partition_set_name,
ceb987
   partition_get_name:		gpt_partition_get_name,
ceb987
+  partition_set_type_id:	NULL,
ceb987
+  partition_get_type_id:	NULL,
ceb987
+  partition_set_type_uuid:	gpt_partition_set_type_uuid,
ceb987
+  partition_get_type_uuid:	gpt_partition_get_type_uuid,
ceb987
   disk_set_flag:		gpt_disk_set_flag,
ceb987
   disk_get_flag:		gpt_disk_get_flag,
ceb987
   disk_is_flag_available:	gpt_disk_is_flag_available,
ceb987
@@ -1793,7 +1835,7 @@ static PedDiskType gpt_disk_type =
ceb987
   next:		NULL,
ceb987
   name:		"gpt",
ceb987
   ops:		&gpt_disk_ops,
ceb987
-  features:	PED_DISK_TYPE_PARTITION_NAME
ceb987
+  features:	PED_DISK_TYPE_PARTITION_NAME | PED_DISK_TYPE_PARTITION_TYPE_UUID
ceb987
 };
ceb987
 
ceb987
 void
ceb987
diff --git a/parted/parted.c b/parted/parted.c
ceb987
index 5c7c270..b8a4acf 100644
ceb987
--- a/parted/parted.c
ceb987
+++ b/parted/parted.c
ceb987
@@ -19,6 +19,7 @@
ceb987
 
ceb987
 #include <config.h>
ceb987
 #include <stdbool.h>
ceb987
+#include <uuid/uuid.h>
ceb987
 
ceb987
 #include "argmatch.h"
ceb987
 #include "closeout.h"
ceb987
@@ -174,6 +175,8 @@ static const char* end_msg =          N_("END is disk location, such as "
ceb987
 static const char* state_msg =        N_("STATE is one of: on, off\n");
ceb987
 static const char* device_msg =       N_("DEVICE is usually /dev/hda or /dev/sda\n");
ceb987
 static const char* name_msg =         N_("NAME is any word you want\n");
ceb987
+static const char* type_msg =         N_("TYPE_ID is a value between 0x01 and 0xff, "
ceb987
+                "TYPE_UUID is a UUID\n");
ceb987
 
ceb987
 static const char* copyright_msg = N_(
ceb987
 "Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n"
ceb987
@@ -917,6 +920,87 @@ error:
ceb987
         return 0;
ceb987
 }
ceb987
 
ceb987
+static int
ceb987
+do_type (PedDevice** dev, PedDisk** diskp)
ceb987
+{
ceb987
+        if (!*diskp)
ceb987
+                *diskp = ped_disk_new (*dev);
ceb987
+        if (!*diskp)
ceb987
+                goto error;
ceb987
+
ceb987
+        bool has_type_id = ped_disk_type_check_feature ((*diskp)->type,
ceb987
+                                                        PED_DISK_TYPE_PARTITION_TYPE_ID);
ceb987
+        bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type,
ceb987
+                                                          PED_DISK_TYPE_PARTITION_TYPE_UUID);
ceb987
+
ceb987
+        PED_ASSERT (!(has_type_id && has_type_uuid));
ceb987
+
ceb987
+        if (!has_type_id && !has_type_uuid) {
ceb987
+                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
ceb987
+                                     _("%s disk labels do not support partition type."),
ceb987
+                                     (*diskp)->type->name);
ceb987
+                goto error;
ceb987
+        }
ceb987
+
ceb987
+        PedPartition* part = NULL;
ceb987
+        if (!command_line_get_partition (_("Partition number?"), *diskp, &part))
ceb987
+                goto error;
ceb987
+
ceb987
+        char* input = NULL;
ceb987
+
ceb987
+        if (has_type_id) {
ceb987
+                uint8_t type_id = ped_partition_get_type_id (part);
ceb987
+                static char buf[8];
ceb987
+                snprintf(buf, 8, "0x%02x", type_id);
ceb987
+
ceb987
+                input = command_line_get_word (_("Partition type-id?"), buf, NULL, 0);
ceb987
+                if (!input)
ceb987
+                    goto error;
ceb987
+
ceb987
+                unsigned int tmp = strtol (input, (char**) NULL, 16);
ceb987
+                if (tmp < 0x01 || tmp > 0xff) {
ceb987
+                        ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
ceb987
+                                             _("Invalid type-id."));
ceb987
+                        goto error_free_input;
ceb987
+                }
ceb987
+
ceb987
+                if (!ped_partition_set_type_id (part, tmp))
ceb987
+                        goto error_free_input;
ceb987
+        }
ceb987
+
ceb987
+        if (has_type_uuid) {
ceb987
+                uint8_t* type_uuid = ped_partition_get_type_uuid (part);
ceb987
+                static char buf[UUID_STR_LEN];
ceb987
+                uuid_unparse_lower (type_uuid, buf);
ceb987
+                free (type_uuid);
ceb987
+
ceb987
+                input = command_line_get_word (_("Partition type-uuid?"), buf, NULL, 0);
ceb987
+                if (!input)
ceb987
+                        goto error;
ceb987
+
ceb987
+                uuid_t tmp;
ceb987
+                if (uuid_parse (input, tmp) != 0 || uuid_is_null (tmp)) {
ceb987
+                        ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
ceb987
+                                             _("Invalid type-uuid."));
ceb987
+                        goto error_free_input;
ceb987
+                }
ceb987
+
ceb987
+                if (!ped_partition_set_type_uuid (part, tmp))
ceb987
+                        goto error_free_input;
ceb987
+        }
ceb987
+
ceb987
+        free (input);
ceb987
+
ceb987
+        if (!ped_disk_commit (*diskp))
ceb987
+                goto error;
ceb987
+        return 1;
ceb987
+
ceb987
+error_free_input:
ceb987
+        free (input);
ceb987
+error:
ceb987
+        return 0;
ceb987
+}
ceb987
+
ceb987
 static char*
ceb987
 partition_print_flags (PedPartition const *part)
ceb987
 {
ceb987
@@ -1270,6 +1354,10 @@ do_print (PedDevice** dev, PedDisk** diskp)
ceb987
                                          PED_DISK_TYPE_EXTENDED);
ceb987
         has_name = ped_disk_type_check_feature ((*diskp)->type,
ceb987
                                          PED_DISK_TYPE_PARTITION_NAME);
ceb987
+        bool has_type_id = ped_disk_type_check_feature ((*diskp)->type,
ceb987
+							PED_DISK_TYPE_PARTITION_TYPE_ID);
ceb987
+        bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type,
ceb987
+							  PED_DISK_TYPE_PARTITION_TYPE_UUID);
ceb987
 
ceb987
         PedPartition* part;
ceb987
         if (opt_output_mode == HUMAN) {
ceb987
@@ -1407,10 +1495,25 @@ do_print (PedDevice** dev, PedDisk** diskp)
ceb987
 
ceb987
                 if (!(part->type & PED_PARTITION_FREESPACE)) {
ceb987
 
ceb987
+                    if (has_type_id) {
ceb987
+                        uint8_t type_id = ped_partition_get_type_id (part);
ceb987
+                        static char buf[8];
ceb987
+                        snprintf(buf, 8, "0x%02x", type_id);
ceb987
+                        ul_jsonwrt_value_s (&json, "type-id", buf);
ceb987
+                    }
ceb987
+
ceb987
+                    if (has_type_uuid) {
ceb987
+                        uint8_t* type_uuid = ped_partition_get_type_uuid (part);
ceb987
+                        static char buf[UUID_STR_LEN];
ceb987
+                        uuid_unparse_lower (type_uuid, buf);
ceb987
+                        ul_jsonwrt_value_s (&json, "type-uuid", buf);
ceb987
+                        free (type_uuid);
ceb987
+                    }
ceb987
+
ceb987
                     if (has_name) {
ceb987
                         name = ped_partition_get_name (part);
ceb987
                         if (strcmp (name, "") != 0)
ceb987
-                            ul_jsonwrt_value_s (&json, "name", ped_partition_get_name (part));
ceb987
+                            ul_jsonwrt_value_s (&json, "name", name);
ceb987
                     }
ceb987
 
ceb987
                     if (part->fs_type)
ceb987
@@ -2316,6 +2419,14 @@ _("toggle [NUMBER [FLAG]]                   toggle the state of FLAG on "
ceb987
 NULL),
ceb987
         str_list_create (_(number_msg), flag_msg, NULL), 1));
ceb987
 
ceb987
+command_register (commands, command_create (
ceb987
+        str_list_create_unique ("type", _("type"), NULL),
ceb987
+        do_type,
ceb987
+        str_list_create (
ceb987
+_("type NUMBER TYPE-ID or TYPE-UUID         type set TYPE-ID or TYPE-UUID of partition NUMBER"),
ceb987
+NULL),
ceb987
+        str_list_create (_(number_msg), _(type_msg), NULL), 1));
ceb987
+
ceb987
 command_register (commands, command_create (
ceb987
         str_list_create_unique ("unit", _("unit"), NULL),
ceb987
         do_unit,
ceb987
diff --git a/tests/Makefile.am b/tests/Makefile.am
ceb987
index 5cb7aa3..2da653b 100644
ceb987
--- a/tests/Makefile.am
ceb987
+++ b/tests/Makefile.am
ceb987
@@ -43,6 +43,10 @@ TESTS = \
ceb987
   t0501-duplicate.sh \
ceb987
   t0800-json-gpt.sh \
ceb987
   t0801-json-msdos.sh \
ceb987
+  t0900-type-gpt.sh \
ceb987
+  t0901-type-gpt-invalid.sh \
ceb987
+  t0910-type-dos.sh \
ceb987
+  t0911-type-dos-invalid.sh \
ceb987
   t1100-busy-label.sh \
ceb987
   t1101-busy-partition.sh \
ceb987
   t1102-loop-label.sh \
ceb987
diff --git a/tests/t0800-json-gpt.sh b/tests/t0800-json-gpt.sh
ceb987
index 8dd1862..354c0bd 100755
ceb987
--- a/tests/t0800-json-gpt.sh
ceb987
+++ b/tests/t0800-json-gpt.sh
ceb987
@@ -62,6 +62,7 @@ cat <<EOF > exp || fail=1
ceb987
             "end": "20479s",
ceb987
             "size": "10240s",
ceb987
             "type": "primary",
ceb987
+            "type-uuid": "0fc63daf-8483-4772-8e79-3d69d8477de4",
ceb987
             "name": "test1"
ceb987
          },{
ceb987
             "number": 2,
ceb987
@@ -69,6 +70,7 @@ cat <<EOF > exp || fail=1
ceb987
             "end": "61439s",
ceb987
             "size": "40960s",
ceb987
             "type": "primary",
ceb987
+            "type-uuid": "a19d880f-05fc-4d3b-a006-743f0f84911e",
ceb987
             "name": "test2",
ceb987
             "flags": [
ceb987
                 "raid"
ceb987
diff --git a/tests/t0801-json-msdos.sh b/tests/t0801-json-msdos.sh
ceb987
index a14a5af..c5446d8 100755
ceb987
--- a/tests/t0801-json-msdos.sh
ceb987
+++ b/tests/t0801-json-msdos.sh
ceb987
@@ -52,13 +52,15 @@ cat <<EOF > exp || fail=1
ceb987
             "start": "5.00MiB",
ceb987
             "end": "10.0MiB",
ceb987
             "size": "5.00MiB",
ceb987
-            "type": "primary"
ceb987
+            "type": "primary",
ceb987
+            "type-id": "0x83"
ceb987
          },{
ceb987
             "number": 2,
ceb987
             "start": "10.0MiB",
ceb987
             "end": "30.0MiB",
ceb987
             "size": "20.0MiB",
ceb987
             "type": "extended",
ceb987
+            "type-id": "0x0f",
ceb987
             "flags": [
ceb987
                 "lba"
ceb987
             ]
ceb987
@@ -68,6 +70,7 @@ cat <<EOF > exp || fail=1
ceb987
             "end": "20.0MiB",
ceb987
             "size": "10.0MiB",
ceb987
             "type": "logical",
ceb987
+            "type-id": "0x8e",
ceb987
             "flags": [
ceb987
                 "lvm"
ceb987
             ]
ceb987
diff --git a/tests/t0900-type-gpt.sh b/tests/t0900-type-gpt.sh
ceb987
new file mode 100755
ceb987
index 0000000..2014820
ceb987
--- /dev/null
ceb987
+++ b/tests/t0900-type-gpt.sh
ceb987
@@ -0,0 +1,69 @@
ceb987
+#!/bin/sh
ceb987
+
ceb987
+# Test type command with GPT label
ceb987
+
ceb987
+# Copyright (C) 2022 SUSE LLC
ceb987
+
ceb987
+# This program is free software; you can redistribute it and/or modify
ceb987
+# it under the terms of the GNU General Public License as published by
ceb987
+# the Free Software Foundation; either version 3 of the License, or
ceb987
+# (at your option) any later version.
ceb987
+
ceb987
+# This program is distributed in the hope that it will be useful,
ceb987
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ceb987
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ceb987
+# GNU General Public License for more details.
ceb987
+
ceb987
+# You should have received a copy of the GNU General Public License
ceb987
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ceb987
+
ceb987
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
ceb987
+require_512_byte_sector_size_
ceb987
+
ceb987
+dev=loop-file
ceb987
+
ceb987
+# create device
ceb987
+truncate --size 50MiB "$dev" || fail=1
ceb987
+
ceb987
+# create gpt label and one partition
ceb987
+parted --script "$dev" mklabel gpt > out 2>&1 || fail=1
ceb987
+parted --script "$dev" mkpart "''" "linux-swap" 10% 20% > out 2>&1 || fail=1
ceb987
+
ceb987
+# set type-uuid
ceb987
+parted --script "$dev" type 1 "deadfd6d-a4ab-43c4-84e5-0933c84b4f4f" || fail=1
ceb987
+
ceb987
+# print with json format
ceb987
+parted --script --json "$dev" unit s print > out 2>&1 || fail=1
ceb987
+
ceb987
+cat <<EOF > exp || fail=1
ceb987
+{
ceb987
+   "disk": {
ceb987
+      "path": "loop-file",
ceb987
+      "size": "102400s",
ceb987
+      "model": "",
ceb987
+      "transport": "file",
ceb987
+      "logical-sector-size": 512,
ceb987
+      "physical-sector-size": 512,
ceb987
+      "label": "gpt",
ceb987
+      "max-partitions": 128,
ceb987
+      "partitions": [
ceb987
+         {
ceb987
+            "number": 1,
ceb987
+            "start": "10240s",
ceb987
+            "end": "20479s",
ceb987
+            "size": "10240s",
ceb987
+            "type": "primary",
ceb987
+            "type-uuid": "deadfd6d-a4ab-43c4-84e5-0933c84b4f4f"
ceb987
+         }
ceb987
+      ]
ceb987
+   }
ceb987
+}
ceb987
+EOF
ceb987
+
ceb987
+# remove full path of device from actual output
ceb987
+mv out o2 && sed "s,\"/.*/$dev\",\"$dev\"," o2 > out || fail=1
ceb987
+
ceb987
+# check for expected output
ceb987
+compare exp out || fail=1
ceb987
+
ceb987
+Exit $fail
ceb987
diff --git a/tests/t0901-type-gpt-invalid.sh b/tests/t0901-type-gpt-invalid.sh
ceb987
new file mode 100755
ceb987
index 0000000..681df3a
ceb987
--- /dev/null
ceb987
+++ b/tests/t0901-type-gpt-invalid.sh
ceb987
@@ -0,0 +1,35 @@
ceb987
+#!/bin/sh
ceb987
+
ceb987
+# Test type command with GPT label
ceb987
+
ceb987
+# Copyright (C) 2022 SUSE LLC
ceb987
+
ceb987
+# This program is free software; you can redistribute it and/or modify
ceb987
+# it under the terms of the GNU General Public License as published by
ceb987
+# the Free Software Foundation; either version 3 of the License, or
ceb987
+# (at your option) any later version.
ceb987
+
ceb987
+# This program is distributed in the hope that it will be useful,
ceb987
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ceb987
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ceb987
+# GNU General Public License for more details.
ceb987
+
ceb987
+# You should have received a copy of the GNU General Public License
ceb987
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ceb987
+
ceb987
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
ceb987
+require_512_byte_sector_size_
ceb987
+
ceb987
+dev=loop-file
ceb987
+
ceb987
+# create device
ceb987
+truncate --size 50MiB "$dev" || fail=1
ceb987
+
ceb987
+# create gpt label and one partition
ceb987
+parted --script "$dev" mklabel gpt > out 2>&1 || fail=1
ceb987
+parted --script "$dev" mkpart "''" "linux-swap" 10% 20% > out 2>&1 || fail=1
ceb987
+
ceb987
+# set type-uuid
ceb987
+parted --script "$dev" type 1 "invalidd-a4ab-43c4-84e5-0933c84b4f4f" && fail=1
ceb987
+
ceb987
+Exit $fail
ceb987
diff --git a/tests/t0910-type-dos.sh b/tests/t0910-type-dos.sh
ceb987
new file mode 100755
ceb987
index 0000000..d7cc37f
ceb987
--- /dev/null
ceb987
+++ b/tests/t0910-type-dos.sh
ceb987
@@ -0,0 +1,69 @@
ceb987
+#!/bin/sh
ceb987
+
ceb987
+# Test type command with MS-DOS label
ceb987
+
ceb987
+# Copyright (C) 2022 SUSE LLC
ceb987
+
ceb987
+# This program is free software; you can redistribute it and/or modify
ceb987
+# it under the terms of the GNU General Public License as published by
ceb987
+# the Free Software Foundation; either version 3 of the License, or
ceb987
+# (at your option) any later version.
ceb987
+
ceb987
+# This program is distributed in the hope that it will be useful,
ceb987
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ceb987
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ceb987
+# GNU General Public License for more details.
ceb987
+
ceb987
+# You should have received a copy of the GNU General Public License
ceb987
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ceb987
+
ceb987
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
ceb987
+require_512_byte_sector_size_
ceb987
+
ceb987
+dev=loop-file
ceb987
+
ceb987
+# create device
ceb987
+truncate --size 50MiB "$dev" || fail=1
ceb987
+
ceb987
+# create msdos label and one partition
ceb987
+parted --script "$dev" mklabel msdos > out 2>&1 || fail=1
ceb987
+parted --script "$dev" mkpart primary "linux-swap" 10% 20% > out 2>&1 || fail=1
ceb987
+
ceb987
+# set type-id
ceb987
+parted --script "$dev" type 1 "0x83" || fail=1
ceb987
+
ceb987
+# print with json format
ceb987
+parted --script --json "$dev" unit s print > out 2>&1 || fail=1
ceb987
+
ceb987
+cat <<EOF > exp || fail=1
ceb987
+{
ceb987
+   "disk": {
ceb987
+      "path": "loop-file",
ceb987
+      "size": "102400s",
ceb987
+      "model": "",
ceb987
+      "transport": "file",
ceb987
+      "logical-sector-size": 512,
ceb987
+      "physical-sector-size": 512,
ceb987
+      "label": "msdos",
ceb987
+      "max-partitions": 4,
ceb987
+      "partitions": [
ceb987
+         {
ceb987
+            "number": 1,
ceb987
+            "start": "10240s",
ceb987
+            "end": "20479s",
ceb987
+            "size": "10240s",
ceb987
+            "type": "primary",
ceb987
+            "type-id": "0x83"
ceb987
+         }
ceb987
+      ]
ceb987
+   }
ceb987
+}
ceb987
+EOF
ceb987
+
ceb987
+# remove full path of device from actual output
ceb987
+mv out o2 && sed "s,\"/.*/$dev\",\"$dev\"," o2 > out || fail=1
ceb987
+
ceb987
+# check for expected output
ceb987
+compare exp out || fail=1
ceb987
+
ceb987
+Exit $fail
ceb987
diff --git a/tests/t0911-type-dos-invalid.sh b/tests/t0911-type-dos-invalid.sh
ceb987
new file mode 100755
ceb987
index 0000000..f1036d1
ceb987
--- /dev/null
ceb987
+++ b/tests/t0911-type-dos-invalid.sh
ceb987
@@ -0,0 +1,35 @@
ceb987
+#!/bin/sh
ceb987
+
ceb987
+# Test type command with MS-DOS label
ceb987
+
ceb987
+# Copyright (C) 2022 SUSE LLC
ceb987
+
ceb987
+# This program is free software; you can redistribute it and/or modify
ceb987
+# it under the terms of the GNU General Public License as published by
ceb987
+# the Free Software Foundation; either version 3 of the License, or
ceb987
+# (at your option) any later version.
ceb987
+
ceb987
+# This program is distributed in the hope that it will be useful,
ceb987
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ceb987
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ceb987
+# GNU General Public License for more details.
ceb987
+
ceb987
+# You should have received a copy of the GNU General Public License
ceb987
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ceb987
+
ceb987
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
ceb987
+require_512_byte_sector_size_
ceb987
+
ceb987
+dev=loop-file
ceb987
+
ceb987
+# create device
ceb987
+truncate --size 50MiB "$dev" || fail=1
ceb987
+
ceb987
+# create msdos label and one partition
ceb987
+parted --script "$dev" mklabel msdos > out 2>&1 || fail=1
ceb987
+parted --script "$dev" mkpart primary "linux-swap" 10% 20% > out 2>&1 || fail=1
ceb987
+
ceb987
+# set type-id
ceb987
+parted --script "$dev" type 1 "0x101" && fail=1
ceb987
+
ceb987
+Exit $fail
ceb987
diff --git a/tests/t2400-dos-hfs-partition-type.sh b/tests/t2400-dos-hfs-partition-type.sh
ceb987
index 6733683..8c54ec4 100644
ceb987
--- a/tests/t2400-dos-hfs-partition-type.sh
ceb987
+++ b/tests/t2400-dos-hfs-partition-type.sh
ceb987
@@ -24,7 +24,7 @@ n_sectors=8000
ceb987
 
ceb987
 dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || framework_failure
ceb987
 
ceb987
-# create a GPT partition table
ceb987
+# create a MS-DOS partition table
ceb987
 parted -s $dev mklabel msdos \
ceb987
   mkpart pri hfs  2048s 4095s \
ceb987
   mkpart pri hfs+ 4096s 6143s > out 2>&1 || fail=1
ceb987
diff --git a/tests/t3300-palo-prep.sh b/tests/t3300-palo-prep.sh
ceb987
index 5005e0e..efe54db 100755
ceb987
--- a/tests/t3300-palo-prep.sh
ceb987
+++ b/tests/t3300-palo-prep.sh
ceb987
@@ -20,9 +20,9 @@
ceb987
 ss=$sector_size_
ceb987
 
ceb987
 cat > exp <
ceb987
-1:2048s:4095s:2048s:ext2::lba, palo;
ceb987
-1:2048s:4095s:2048s:ext2::lba, prep;
ceb987
-1:2048s:4095s:2048s:ext2::lba, palo;
ceb987
+1:2048s:4095s:2048s:ext2::palo;
ceb987
+1:2048s:4095s:2048s:ext2::prep;
ceb987
+1:2048s:4095s:2048s:ext2::palo;
ceb987
 EOF
ceb987
 
ceb987
 dev=dev-file
ceb987
@@ -37,7 +37,7 @@ parted -m -s $dev mklabel msdos \
ceb987
   set 1 palo on u s print \
ceb987
     > out 2> err || fail=1
ceb987
 
ceb987
-grep -E '^1:2048s:4095s:2048s:ext2::lba, p...;$' out > k; mv k out
ceb987
+grep -E '^1:2048s:4095s:2048s:ext2::p...;$' out > k; mv k out
ceb987
 
ceb987
 compare exp out || fail=1
ceb987
 
ceb987
diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh
ceb987
index f2001c5..b35d443 100644
ceb987
--- a/tests/t3310-flags.sh
ceb987
+++ b/tests/t3310-flags.sh
ceb987
@@ -91,6 +91,10 @@ for table_type in aix amiga atari bsd dvh gpt mac msdos pc98 sun loop; do
ceb987
            # test to fail.
ceb987
            flags=`echo "$flags" | egrep -v 'lvm|raid'`
ceb987
            ;;
ceb987
+    msdos) # FIXME: Exclude flags that can only be set in combination
ceb987
+           # with certain other flags.
ceb987
+           flags=`echo "$flags" | egrep -v 'hidden|lba'`
ceb987
+           ;;
ceb987
   esac
ceb987
 
ceb987
   for mode in on_only on_and_off ; do
ceb987
-- 
ceb987
2.35.3
ceb987