fix up how device-is-system-internal is computed
authorDavid Zeuthen <davidz@redhat.com>
Tue, 17 Mar 2009 01:06:43 +0000 (21:06 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 17 Mar 2009 01:06:43 +0000 (21:06 -0400)
This should fix

 https://bugzilla.redhat.com/show_bug.cgi?id=489397

where we marked device-mapper devices as system internal.

src/devkit-disks-device.c

index 5b4b844..e0c711f 100644 (file)
@@ -2573,29 +2573,45 @@ update_info_is_system_internal (DevkitDisksDevice *device)
         /* TODO: make it possible to override this property from a udev property.
          */
 
-        is_system_internal = FALSE;
+        /* start out by assuming the device is system internal, then adjust depending on what kind of
+         * device we are dealing with
+         */
+        is_system_internal = TRUE;
 
+        /* A Linux MD device is system internal if, and only if
+         *
+         * - a single component is system internal
+         * - there are no components
+         */
         if (device->priv->device_is_linux_md) {
-                guint n;
+                is_system_internal = FALSE;
 
-                /* A Linux MD device is system internal IFF a single component is system internal */
-                for (n = 0; n < device->priv->slaves_objpath->len; n++) {
-                        const gchar *slave_objpath;
-                        DevkitDisksDevice *slave;
+                if (device->priv->slaves_objpath->len == 0) {
+                        is_system_internal = TRUE;
+                } else {
+                        guint n;
 
-                        slave_objpath = device->priv->slaves_objpath->pdata[n];
-                        slave = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, slave_objpath);
-                        if (slave == NULL)
-                                continue;
+                        for (n = 0; n < device->priv->slaves_objpath->len; n++) {
+                                const gchar *slave_objpath;
+                                DevkitDisksDevice *slave;
 
-                        if (slave->priv->device_is_system_internal) {
-                                is_system_internal = TRUE;
-                                break;
+                                slave_objpath = device->priv->slaves_objpath->pdata[n];
+                                slave = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, slave_objpath);
+                                if (slave == NULL)
+                                        continue;
+
+                                if (slave->priv->device_is_system_internal) {
+                                        is_system_internal = TRUE;
+                                        break;
+                                }
                         }
                 }
+
+                goto determined;
         }
 
-        else  if (device->priv->device_is_partition) {
+        /* a partition is system internal only if the drive it belongs to is system internal */
+        if (device->priv->device_is_partition) {
                 DevkitDisksDevice *enclosing_device;
 
                 enclosing_device = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, device->priv->partition_slave);
@@ -2605,9 +2621,14 @@ update_info_is_system_internal (DevkitDisksDevice *device)
                         is_system_internal = TRUE;
                 }
 
-        } else if (device->priv->device_is_luks_cleartext) {
-                DevkitDisksDevice *enclosing_device;
+                goto determined;
+        }
 
+        /* a LUKS cleartext device is system internal only if the underlying crypto-text
+         * device is system internal
+         */
+        if (device->priv->device_is_luks_cleartext) {
+                DevkitDisksDevice *enclosing_device;
                 enclosing_device = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, device->priv->luks_cleartext_slave);
                 if (enclosing_device != NULL) {
                         is_system_internal = enclosing_device->priv->device_is_system_internal;
@@ -2615,11 +2636,17 @@ update_info_is_system_internal (DevkitDisksDevice *device)
                         is_system_internal = TRUE;
                 }
 
-        } else if (device->priv->device_is_removable) {
+                goto determined;
+        }
 
+        /* devices with removable media are never system internal */
+        if (device->priv->device_is_removable) {
                 is_system_internal = FALSE;
+                goto determined;
+        }
 
-        } else if (device->priv->device_is_drive && device->priv->drive_connection_interface != NULL) {
+        /* devices on certain buses are never system internal */
+        if (device->priv->device_is_drive && device->priv->drive_connection_interface != NULL) {
 
                 if (strcmp (device->priv->drive_connection_interface, "ata_serial_esata") == 0 ||
                     strcmp (device->priv->drive_connection_interface, "sdio") == 0 ||
@@ -2629,8 +2656,10 @@ update_info_is_system_internal (DevkitDisksDevice *device)
                 } else {
                         is_system_internal = TRUE;
                 }
+                goto determined;
         }
 
+ determined:
         devkit_disks_device_set_device_is_system_internal (device, is_system_internal);
 
         return TRUE;