split drive-media into two properties (compatibility and current)
authorDavid Zeuthen <davidz@redhat.com>
Sat, 29 Mar 2008 18:38:35 +0000 (14:38 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Sat, 29 Mar 2008 18:38:35 +0000 (14:38 -0400)
src/95-devkit-disks.rules
src/devkit-disks-device-private.h
src/devkit-disks-device.c
src/org.freedesktop.DeviceKit.Disks.Device.xml
tools/devkit-disks.c

index b2818b5..7759af3 100644 (file)
@@ -9,20 +9,24 @@ KERNEL=="hd*[0-9]", ATTR{removable}=="1", GOTO="probe_parttable_end"
 # Example rule for tagging a device with a specific media type. Where and
 # how to store this database needs some thought.
 #
-SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:0", ENV{MEDIA_TYPE}="flash_cf"
-SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:1", ENV{MEDIA_TYPE}="flash_ms"
-SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:2", ENV{MEDIA_TYPE}="flash_sm"
-SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:3", ENV{MEDIA_TYPE}="flash_sd"
+SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:0", ENV{COMPAT_MEDIA_TYPE}="flash_cf"
+SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:1", ENV{COMPAT_MEDIA_TYPE}="flash_ms"
+SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:2", ENV{COMPAT_MEDIA_TYPE}="flash_sm"
+SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0248", ENV{ID_INSTANCE}=="0:3", ENV{COMPAT_MEDIA_TYPE}="flash_sd"
 
-SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:0", ENV{MEDIA_TYPE}="flash_cf"
-SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:1", ENV{MEDIA_TYPE}="flash_sm"
-SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:2", ENV{MEDIA_TYPE}="flash_sd"
-SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:3", ENV{MEDIA_TYPE}="flash_ms"
+SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:0", ENV{COMPAT_MEDIA_TYPE}="flash_cf"
+SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:1", ENV{COMPAT_MEDIA_TYPE}="flash_sm"
+SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:2", ENV{COMPAT_MEDIA_TYPE}="flash_sd"
+SYSFS{idVendor}=="05e3", SYSFS{idProduct}=="070e", ENV{ID_INSTANCE}=="0:3", ENV{COMPAT_MEDIA_TYPE}="flash_ms"
 
 # The following needs to come from cdrom_id and needs to set
 # more than just "optical". See the drive-media property.
 #
-ENV{ID_CDROM}=="1", ENV{MEDIA_TYPE}="optical"
+ENV{ID_CDROM}=="1", ENV{COMPAT_MEDIA_TYPE}="optical"
+
+# Right now we just default to the first type of media the drive supports
+ENV{COMPAT_MEDIA_TYPE}!="", ENV{MEDIA_TYPE}="$env{COMPAT_MEDIA_TYPE}"
+
 
 # scan for partition table only if we're not a partition
 #
index 62d7601..46f6a0e 100644 (file)
@@ -94,7 +94,8 @@ struct DevkitDisksDevicePrivate
                 char *drive_serial;
                 char *drive_connection_interface;
                 guint drive_connection_speed;
-                GPtrArray *drive_media;
+                GPtrArray *drive_media_compatibility;
+                char *drive_media;
 
                 char *crypto_cleartext_slave;
 
index 9c208c7..08fd61b 100644 (file)
@@ -169,6 +169,7 @@ enum
         PROP_DRIVE_SERIAL,
         PROP_DRIVE_CONNECTION_INTERFACE,
         PROP_DRIVE_CONNECTION_SPEED,
+        PROP_DRIVE_MEDIA_COMPATIBILITY,
         PROP_DRIVE_MEDIA,
 };
 
@@ -425,8 +426,11 @@ get_property (GObject         *object,
        case PROP_DRIVE_CONNECTION_SPEED:
                g_value_set_uint64 (value, device->priv->info.drive_connection_speed);
                break;
+       case PROP_DRIVE_MEDIA_COMPATIBILITY:
+               g_value_set_boxed (value, device->priv->info.drive_media_compatibility);
+               break;
        case PROP_DRIVE_MEDIA:
-               g_value_set_boxed (value, device->priv->info.drive_media);
+               g_value_set_string (value, device->priv->info.drive_media);
                break;
 
         default:
@@ -692,10 +696,14 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
                 g_param_spec_uint64 ("drive-connection-speed", NULL, NULL, 0, G_MAXUINT64, 0, G_PARAM_READABLE));
         g_object_class_install_property (
                 object_class,
-                PROP_DRIVE_MEDIA,
-                g_param_spec_boxed ("drive-media", NULL, NULL,
+                PROP_DRIVE_MEDIA_COMPATIBILITY,
+                g_param_spec_boxed ("drive-media-compatibility", NULL, NULL,
                                     dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING),
                                     G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
+                PROP_DRIVE_MEDIA,
+                g_param_spec_string ("drive-media", NULL, NULL, NULL, G_PARAM_READABLE));
 }
 
 static void
@@ -935,8 +943,9 @@ free_info (DevkitDisksDevice *device)
         g_free (device->priv->info.drive_revision);
         g_free (device->priv->info.drive_serial);
         g_free (device->priv->info.drive_connection_interface);
-        g_ptr_array_foreach (device->priv->info.drive_media, (GFunc) g_free, NULL);
-        g_ptr_array_free (device->priv->info.drive_media, TRUE);
+        g_ptr_array_foreach (device->priv->info.drive_media_compatibility, (GFunc) g_free, NULL);
+        g_ptr_array_free (device->priv->info.drive_media_compatibility, TRUE);
+        g_free (device->priv->info.drive_media);
 
         g_free (device->priv->info.dm_name);
         g_ptr_array_foreach (device->priv->info.slaves_objpath, (GFunc) g_free, NULL);
@@ -954,7 +963,7 @@ init_info (DevkitDisksDevice *device)
         device->priv->info.partition_flags = g_ptr_array_new ();
         device->priv->info.partition_table_offsets = g_array_new (FALSE, TRUE, sizeof (guint64));
         device->priv->info.partition_table_sizes = g_array_new (FALSE, TRUE, sizeof (guint64));
-        device->priv->info.drive_media = g_ptr_array_new ();
+        device->priv->info.drive_media_compatibility = g_ptr_array_new ();
         device->priv->info.slaves_objpath = g_ptr_array_new ();
         device->priv->info.holders_objpath = g_ptr_array_new ();
 }
@@ -1146,8 +1155,12 @@ update_info_properties_cb (DevKitInfo *info, const char *key, void *user_data)
                         }
                 }
 
+        } else if (strcmp (key, "COMPAT_MEDIA_TYPE") == 0) {
+                devkit_info_property_strlist_foreach (info, key, update_info_add_ptr,
+                                                      device->priv->info.drive_media_compatibility);
+
         } else if (strcmp (key, "MEDIA_TYPE") == 0) {
-                devkit_info_property_strlist_foreach (info, key, update_info_add_ptr, device->priv->info.drive_media);
+                device->priv->info.drive_media = _dupv8 (devkit_info_property_get_string (info, key));
 
 
         } else if (strcmp (key, "MEDIA_AVAILABLE") == 0) {
index b4798ed..54b8d57 100644 (file)
          maximum speed of the interface in bits/s; if unknown this
          is set to 0.
 
-         The drive-media property specifies what kind of media
-         can be used in the drive; this is sometimes set using quirk
-         files if the hardware isn't capable of precisely reporting it.
-         Known values include
+         The drive-media-compatibility property specifies what kind of
+         media can be used in the drive (it's an array of strings); this is
+         sometimes set using quirk files if the hardware isn't capable of
+         precisely reporting it. The property drive-media specifies the
+         current type of media in the drive.
+
+         Known values for drive-media-compatibility and drive-media include
 
            flash
            flash_cf
     <property name="drive-serial" type="s" access="read"/>
     <property name="drive-connection-interface" type="s" access="read"/>
     <property name="drive-connection-speed" type="t" access="read"/>
-    <property name="drive-media" type="as" access="read"/>
+    <property name="drive-media-compatibility" type="as" access="read"/>
+    <property name="drive-media" type="s" access="read"/>
 
   </interface>
 
index db35817..abab62a 100644 (file)
@@ -494,7 +494,8 @@ typedef struct
         char    *drive_serial;
         char    *drive_connection_interface;
         guint64  drive_connection_speed;
-        char   **drive_media;
+        char   **drive_media_compatibility;
+        char    *drive_media;
 } DeviceProperties;
 
 static void
@@ -614,8 +615,10 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
                 props->drive_connection_interface = g_strdup (g_value_get_string (value));
         else if (strcmp (key, "drive-connection-speed") == 0)
                 props->drive_connection_speed = g_value_get_uint64 (value);
+        else if (strcmp (key, "drive-media-compatibility") == 0)
+                props->drive_media_compatibility = g_strdupv (g_value_get_boxed (value));
         else if (strcmp (key, "drive-media") == 0)
-                props->drive_media = g_strdupv (g_value_get_boxed (value));
+                props->drive_media = g_strdup (g_value_get_string (value));
 
         else
                 handled = FALSE;
@@ -693,7 +696,8 @@ device_properties_free (DeviceProperties *props)
         g_free (props->drive_revision);
         g_free (props->drive_serial);
         g_free (props->drive_connection_interface);
-        g_strfreev (props->drive_media);
+        g_strfreev (props->drive_media_compatibility);
+        g_free (props->drive_media);
         g_free (props);
 }
 
@@ -795,9 +799,10 @@ do_show_info (const char *object_path)
                 g_print ("    model:       %s\n", props->drive_model);
                 g_print ("    revision:    %s\n", props->drive_revision);
                 g_print ("    serial:      %s\n", props->drive_serial);
-                g_print ("    media:      ");
-                for (n = 0; props->drive_media[n] != NULL; n++)
-                        g_print (" %s", (char *) props->drive_media[n]);
+                g_print ("    media:       %s\n", props->drive_media);
+                g_print ("      compat:   ");
+                for (n = 0; props->drive_media_compatibility[n] != NULL; n++)
+                        g_print (" %s", (char *) props->drive_media_compatibility[n]);
                 g_print ("\n");
                 if (props->drive_connection_interface == NULL || strlen (props->drive_connection_interface) == 0)
                         g_print ("    interface:   (unknown)\n");