Add new Block:HintPartitionable property
authorDavid Zeuthen <davidz@redhat.com>
Wed, 16 Nov 2011 21:27:22 +0000 (16:27 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 16 Nov 2011 21:27:22 +0000 (16:27 -0500)
This can be used in the UI to determine if a "Format Disk" (to
e.g. create a partition table) button should be offered.

Signed-off-by: David Zeuthen <davidz@redhat.com>
data/org.freedesktop.UDisks2.xml
doc/udisks2-sections.txt
src/udiskslinuxblock.c

index d969180..35ed6db 100644 (file)
     -->
     <property name="CryptoBackingDevice" type="o" access="read"/>
 
+    <!-- HintPartitionable:
+         If %TRUE, the device is normally expected to be
+         partitionable. Devices for which this is not the case include
+         floppy drives, optical drives and LVM logical volumes.
+    -->
+    <property name="HintPartitionable" type="b" access="read"/>
+
     <!-- HintSystem: If %TRUE, the device is considered a <emphasis>system device</emphasis>.
          System devices are devices that require additional permissions to access.
 
index 3b162cf..c8c2882 100644 (file)
@@ -931,6 +931,7 @@ udisks_block_get_preferred_device
 udisks_block_get_size
 udisks_block_get_read_only
 udisks_block_get_symlinks
+udisks_block_get_hint_partitionable
 udisks_block_get_hint_system
 udisks_block_get_hint_ignore
 udisks_block_get_hint_auto
@@ -963,6 +964,7 @@ udisks_block_set_preferred_device
 udisks_block_set_size
 udisks_block_set_read_only
 udisks_block_set_symlinks
+udisks_block_set_hint_partitionable
 udisks_block_set_hint_system
 udisks_block_set_hint_ignore
 udisks_block_set_hint_auto
index b246f6f..5889319 100644 (file)
@@ -234,6 +234,7 @@ update_hints (UDisksLinuxBlock  *block,
               UDisksDrive       *drive)
 {
   UDisksBlock *iface = UDISKS_BLOCK (block);
+  gboolean hint_partitionable;
   gboolean hint_system;
   gboolean hint_ignore;
   gboolean hint_auto;
@@ -242,6 +243,7 @@ update_hints (UDisksLinuxBlock  *block,
   const gchar *device_file;
 
   /* very conservative defaults */
+  hint_partitionable = TRUE;
   hint_system = TRUE;
   hint_ignore = FALSE;
   hint_auto = FALSE;
@@ -275,9 +277,20 @@ update_hints (UDisksLinuxBlock  *block,
   else
     {
       if (g_str_has_prefix (device_file, "/dev/fd"))
-        hint_system = FALSE;
+        {
+          hint_system = FALSE;
+          hint_partitionable = FALSE;
+        }
     }
 
+  /* CD-ROM media / drives are not partitionable, at least not here on Linux */
+  if (g_udev_device_get_property_as_boolean (device, "ID_CDROM"))
+    hint_partitionable = FALSE;
+
+  /* device-mapper devices are not partitionable (TODO: for multipath, they are via kpartx(8) hacks) */
+  if (g_str_has_prefix (g_udev_device_get_name (device), "dm-"))
+    hint_partitionable = FALSE;
+
   /* TODO: set ignore to TRUE for physical paths belonging to a drive with multiple paths */
 
   /* override from udev properties */
@@ -293,6 +306,7 @@ update_hints (UDisksLinuxBlock  *block,
     hint_icon_name = g_udev_device_get_property (device, "UDISKS_ICON_NAME");
 
   /* ... and scene! */
+  udisks_block_set_hint_partitionable (iface, hint_partitionable);
   udisks_block_set_hint_system (iface, hint_system);
   udisks_block_set_hint_ignore (iface, hint_ignore);
   udisks_block_set_hint_auto (iface, hint_auto);