add FindDeviceByMajorMinor() to look up a device by dev_t
authorDavid Zeuthen <davidz@redhat.com>
Mon, 6 Apr 2009 18:36:35 +0000 (14:36 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 6 Apr 2009 18:36:35 +0000 (14:36 -0400)
src/devkit-disks-daemon.c
src/devkit-disks-daemon.h
src/org.freedesktop.DeviceKit.Disks.xml

index 9703a0f..5b85ebc 100644 (file)
@@ -1356,7 +1356,6 @@ devkit_disks_daemon_find_device_by_device_file (DevkitDisksDaemon     *daemon,
         DevkitDisksDevice *device;
         gchar canonical_device_file[PATH_MAX];
 
-        /* TODO: maybe use realpath() on the given device_file so the caller can pass in symlinks? */
         realpath (device_file, canonical_device_file);
 
         object_path = NULL;
@@ -1376,6 +1375,35 @@ devkit_disks_daemon_find_device_by_device_file (DevkitDisksDaemon     *daemon,
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
+gboolean
+devkit_disks_daemon_find_device_by_major_minor (DevkitDisksDaemon     *daemon,
+                                                gint64                  major,
+                                                gint64                  minor,
+                                                DBusGMethodInvocation *context)
+{
+        const char *object_path;
+        DevkitDisksDevice *device;
+        dev_t dev;
+
+        dev = makedev (major, minor);
+
+        object_path = NULL;
+
+        device = devkit_disks_daemon_local_find_by_dev (daemon, dev);
+        if (device != NULL) {
+                object_path = devkit_disks_device_local_get_object_path (device);
+                dbus_g_method_return (context, object_path);
+        } else {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "No such device");
+        }
+
+        return TRUE;
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
 static void
 daemon_polling_inhibitor_disconnected_cb (DevkitDisksInhibitor *inhibitor,
                                           DevkitDisksDaemon    *daemon)
index 8a037d0..8d6a6d0 100644 (file)
@@ -140,6 +140,11 @@ gboolean devkit_disks_daemon_find_device_by_device_file (DevkitDisksDaemon     *
                                                          const char            *device_file,
                                                          DBusGMethodInvocation *context);
 
+gboolean devkit_disks_daemon_find_device_by_major_minor (DevkitDisksDaemon     *daemon,
+                                                         gint64                  major,
+                                                         gint64                  minor,
+                                                         DBusGMethodInvocation *context);
+
 gboolean devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
                                              GPtrArray             *components,
                                              char                 **options,
index 5fdda80..eb471b6 100644 (file)
@@ -35,7 +35,7 @@
 
     <method name="FindDeviceByDeviceFile">
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-      <arg name="device_file" direction="in" type="s">
+      <arg name="device-file" direction="in" type="s">
         <doc:doc><doc:summary>UNIX special device file</doc:summary></doc:doc>
       </arg>
       <arg name="device" direction="out" type="o">
 
     <!-- ************************************************************ -->
 
+    <method name="FindDeviceByMajorMinor">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg name="device-major" direction="in" type="x">
+        <doc:doc><doc:summary>Device major</doc:summary></doc:doc>
+      </arg>
+      <arg name="device-minor" direction="in" type="x">
+        <doc:doc><doc:summary>Device minor</doc:summary></doc:doc>
+      </arg>
+      <arg name="device" direction="out" type="o">
+        <doc:doc><doc:summary>Object path of device</doc:summary></doc:doc>
+      </arg>
+
+      <doc:doc>
+        <doc:description>
+          <doc:para>
+            Finds a device by major:minor.
+          </doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- ************************************************************ -->
+
     <method name="DriveInhibitAllPolling">
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
       <arg name="options" direction="in" type="as">