export device-major and device-minor properties
authorDavid Zeuthen <davidz@redhat.com>
Thu, 2 Apr 2009 18:37:57 +0000 (14:37 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 2 Apr 2009 18:37:57 +0000 (14:37 -0400)
This makes it easier for clients wanting to fool around with
/proc/self/mountinfo themselves.

src/devkit-disks-device-private.h
src/devkit-disks-device.c
src/org.freedesktop.DeviceKit.Disks.Device.xml
tools/devkit-disks.c

index 09b9cb1..a8d2d7c 100644 (file)
@@ -93,13 +93,12 @@ struct DevkitDisksDevicePrivate
         /* if non-zero, the id of the idle for emitting a 'change' signal */
         guint emit_changed_idle_id;
 
-        dev_t dev; /* not exported */
-
         /**************/
         /* properties */
         /*************/
 
         char *device_file;
+        dev_t dev;
         GPtrArray *device_file_by_id;
         GPtrArray *device_file_by_path;
         gboolean device_is_system_internal;
index 4d2f90b..d909fb5 100644 (file)
@@ -131,6 +131,8 @@ enum
         PROP_0,
         PROP_NATIVE_PATH,
 
+        PROP_DEVICE_MAJOR,
+        PROP_DEVICE_MINOR,
         PROP_DEVICE_FILE,
         PROP_DEVICE_FILE_BY_ID,
         PROP_DEVICE_FILE_BY_PATH,
@@ -297,6 +299,12 @@ get_property (GObject         *object,
                 g_value_set_string (value, device->priv->native_path);
                 break;
 
+        case PROP_DEVICE_MAJOR:
+                g_value_set_int64 (value, major (device->priv->dev));
+                break;
+        case PROP_DEVICE_MINOR:
+                g_value_set_int64 (value, minor (device->priv->dev));
+                break;
         case PROP_DEVICE_FILE:
                 g_value_set_string (value, device->priv->device_file);
                 break;
@@ -704,6 +712,14 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
                 g_param_spec_string ("native-path", NULL, NULL, NULL, G_PARAM_READABLE));
         g_object_class_install_property (
                 object_class,
+                PROP_DEVICE_MAJOR,
+                g_param_spec_int64 ("device-major", NULL, NULL, -G_MAXINT64, G_MAXINT64, 0, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
+                PROP_DEVICE_MINOR,
+                g_param_spec_int64 ("device-minor", NULL, NULL, -G_MAXINT64, G_MAXINT64, 0, G_PARAM_READABLE));
+        g_object_class_install_property (
+                object_class,
                 PROP_DEVICE_FILE,
                 g_param_spec_string ("device-file", NULL, NULL, NULL, G_PARAM_READABLE));
         g_object_class_install_property (
index de0163d..6465486 100644 (file)
             OS specific native path of the device. On Linux this is the sysfs path, for example <doc:tt>/sys/devices/pci0000:00/0000:00:1f.2/host2/target2:0:1/2:0:1:0/block/sda</doc:tt>.
       </doc:para></doc:description></doc:doc>
     </property>
+    <property name="device-major" type="x" access="read">
+      <doc:doc><doc:description><doc:para>
+            Major for the device or -1 if not set.
+      </doc:para></doc:description></doc:doc>
+    </property>
+    <property name="device-minor" type="x" access="read">
+      <doc:doc><doc:description><doc:para>
+            Major for the device or -1 if not set.
+      </doc:para></doc:description></doc:doc>
+    </property>
     <property name="device-file" type="s" access="read">
       <doc:doc><doc:description><doc:para>
             UNIX special device file for device. Example: <doc:tt>/dev/sda</doc:tt>.
index d85ca86..eedd4b8 100644 (file)
@@ -345,6 +345,8 @@ typedef struct
 {
         char *native_path;
 
+        gint64   device_major;
+        gint64   device_minor;
         char    *device_file;
         char   **device_file_by_id;
         char   **device_file_by_path;
@@ -476,6 +478,10 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
         if (strcmp (key, "native-path") == 0)
                 props->native_path = g_strdup (g_value_get_string (value));
 
+        else if (strcmp (key, "device-major") == 0)
+                props->device_major = g_value_get_int64 (value);
+        else if (strcmp (key, "device-minor") == 0)
+                props->device_minor = g_value_get_int64 (value);
         else if (strcmp (key, "device-file") == 0)
                 props->device_file = g_strdup (g_value_get_string (value));
         else if (strcmp (key, "device-file-by-id") == 0)
@@ -982,6 +988,9 @@ do_show_info (const char *object_path)
 
         g_print ("Showing information for %s\n", object_path);
         g_print ("  native-path:             %s\n", props->native_path);
+        g_print ("  device:                  %" G_GINT64_MODIFIER "d:%" G_GINT64_MODIFIER "d\n",
+                 props->device_major,
+                 props->device_minor);
         g_print ("  device-file:             %s\n", props->device_file);
         for (n = 0; props->device_file_by_id[n] != NULL; n++)
                 g_print ("    by-id:                 %s\n", (char *) props->device_file_by_id[n]);