[parted-devel] [PATCH] gpt: Add no-automount partition flag

Mike Fleetwood mike.fleetwood at googlemail.com
Sun Dec 11 10:29:21 GMT 2022


Add user requested support for GPT partition type attribute bit 63 [1]
so the no-auto flag in the systemd originated Discoverable Partitions
Specification [2] can be manipulated.  The UEFI specification [3] says
partition attribute bits 48 to 63 are partition type specific, however
the DPS [2] and Microsoft [4] use the bit 63 to mean no automounting /
assign no drive letter and apply it to multiple partition types so don't
restrict its application.

[1] Request for GPT partition attribute bit 63 "no automount" editing
    support
    https://gitlab.gnome.org/GNOME/gparted/-/issues/214
[2] The Discoverable Partitions Specification (DPS),
    Partition Attribute Flags
    https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
[3] UEFI Specification, version 2.8,
    Table 24. Defined GPT Partition Entry - Attributes
    https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
[4] CREATE_PARTITION_PARAMETERS structure (vds.h)
    https://learn.microsoft.com/en-gb/windows/win32/api/vds/ns-vds-create_partition_parameters

Signed-off-by: Mike Fleetwood <mike.fleetwood at googlemail.com>
---
 NEWS                     |  2 ++
 doc/C/parted.8           |  2 +-
 include/parted/disk.in.h |  3 ++-
 libparted/disk.c         |  2 ++
 libparted/labels/gpt.c   | 12 ++++++++++--
 5 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 099f8bd..697ffbc 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** New Features
 
+  Support GPT partition attribute bit 63 as no-automount flag.
+
   Add type commands to set type-id on MS-DOS and type-uuid on GPT.
 
 * Noteworthy changes in release 3.5 (2022-04-18) [stable]
diff --git a/doc/C/parted.8 b/doc/C/parted.8
index ab34be7..fba58c1 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -120,7 +120,7 @@ or an LVM logical volume if necessary.
 Change the state of the \fIflag\fP on \fIpartition\fP to \fIstate\fP.
 Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba",
 "legacy_boot", "irst", "msftres", "esp", "chromeos_kernel", "bls_boot", "linux-home",
-"bios_grub", and "palo".
+"no-automount", "bios_grub", and "palo".
 \fIstate\fP should be either "on" or "off".
 .TP
 .B unit \fIunit\fP
diff --git a/include/parted/disk.in.h b/include/parted/disk.in.h
index 715637d..43b2e85 100644
--- a/include/parted/disk.in.h
+++ b/include/parted/disk.in.h
@@ -88,10 +88,11 @@ enum _PedPartitionFlag {
         PED_PARTITION_CHROMEOS_KERNEL=19,
         PED_PARTITION_BLS_BOOT=20,
         PED_PARTITION_LINUX_HOME=21,
+        PED_PARTITION_NO_AUTOMOUNT=22,
 };
 // NOTE: DO NOT define using enums
 #define PED_PARTITION_FIRST_FLAG        1  // PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         21 // PED_PARTITION_LINUX_HOME
+#define PED_PARTITION_LAST_FLAG         22 // PED_PARTITION_NO_AUTOMOUNT
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,             /**< supports extended partitions */
diff --git a/libparted/disk.c b/libparted/disk.c
index a961d65..fc567cf 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2515,6 +2515,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
 		return N_("bls_boot");
         case PED_PARTITION_LINUX_HOME:
                 return N_("linux-home");
+        case PED_PARTITION_NO_AUTOMOUNT:
+                return N_("no-automount");
 
 	default:
 		ped_exception_throw (
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 8e6a37d..06c4bc3 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -252,7 +252,8 @@ struct __attribute__ ((packed)) _GuidPartitionEntryAttributes_t
   uint64_t NoBlockIOProtocol:1;
   uint64_t LegacyBIOSBootable:1;
   uint64_t Reserved:45;
-  uint64_t GuidSpecific:16;
+  uint64_t GuidSpecific:15;
+  uint64_t NoAutomount:1;
 #else
 #       warning "Using crippled partition entry type"
   uint32_t RequiredToFunction:1;
@@ -260,7 +261,8 @@ struct __attribute__ ((packed)) _GuidPartitionEntryAttributes_t
   uint32_t LegacyBIOSBootable:1;
   uint32_t Reserved:30;
   uint32_t LOST:5;
-  uint32_t GuidSpecific:16;
+  uint32_t GuidSpecific:15;
+  uint32_t NoAutomount:1;
 #endif
 };
 
@@ -1619,6 +1621,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
     case PED_PARTITION_LEGACY_BOOT:
       gpt_part_data->attributes.LegacyBIOSBootable = state;
       return 1;
+    case PED_PARTITION_NO_AUTOMOUNT:
+      gpt_part_data->attributes.NoAutomount = state;
+      return 1;
     case PED_PARTITION_ROOT:
     case PED_PARTITION_LBA:
     default:
@@ -1644,6 +1649,8 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag)
       return gpt_part_data->attributes.RequiredToFunction;
     case PED_PARTITION_LEGACY_BOOT:
       return gpt_part_data->attributes.LegacyBIOSBootable;
+    case PED_PARTITION_NO_AUTOMOUNT:
+      return gpt_part_data->attributes.NoAutomount;
     case PED_PARTITION_LBA:
     case PED_PARTITION_ROOT:
     default:
@@ -1663,6 +1670,7 @@ gpt_partition_is_flag_available (const PedPartition *part,
     {
     case PED_PARTITION_HIDDEN:
     case PED_PARTITION_LEGACY_BOOT:
+    case PED_PARTITION_NO_AUTOMOUNT:
       return 1;
     case PED_PARTITION_ROOT:
     case PED_PARTITION_LBA:
-- 
1.8.3.1




More information about the parted-devel mailing list