avoid getters and setter and export information as properties
authorDavid Zeuthen <davidz@redhat.com>
Thu, 6 Mar 2008 06:12:48 +0000 (01:12 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 6 Mar 2008 06:12:48 +0000 (01:12 -0500)
src/devkit-disks-daemon.c
src/devkit-disks-device.c
src/devkit-disks-device.h
src/org.freedesktop.DeviceKit.Disks.Device.xml
tools/Makefile.am
tools/devkit-disks.c

index 77a0f27..791b644 100644 (file)
@@ -176,7 +176,7 @@ GType
 devkit_disks_daemon_error_get_type (void)
 {
         static GType etype = 0;
-        
+
         if (etype == 0)
         {
                 static const GEnumValue values[] =
@@ -186,12 +186,9 @@ devkit_disks_daemon_error_get_type (void)
                                 ENUM_ENTRY (DEVKIT_DISKS_DAEMON_ERROR_NOT_AUTHORIZED, "NotAuthorized"),
                                 { 0, 0, 0 }
                         };
-                
                 g_assert (DEVKIT_DISKS_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
-                
                 etype = g_enum_register_static ("DevkitDisksDaemonError", values);
         }
-        
         return etype;
 }
 
@@ -210,7 +207,6 @@ devkit_disks_daemon_constructor (GType                  type,
                 G_OBJECT_CLASS (devkit_disks_daemon_parent_class)->constructor (type,
                                                                                 n_construct_properties,
                                                                                 construct_properties));
-        
         return G_OBJECT (daemon);
 }
 
@@ -312,7 +308,7 @@ pk_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer use
         return TRUE;
 }
 
-static int 
+static int
 pk_io_add_watch (PolKitContext *pk_context, int fd)
 {
         guint id = 0;
@@ -330,7 +326,7 @@ out:
         return id;
 }
 
-static void 
+static void
 pk_io_remove_watch (PolKitContext *pk_context, int watch_id)
 {
         g_source_remove (watch_id);
@@ -365,13 +361,11 @@ _filter (DBusConnection *connection, DBusMessage *message, void *user_data)
                                 for (l = daemon->priv->inhibitors; l != NULL; l = l->next) {
                                         Inhibitor *inhibitor = l->data;
                                         if (strcmp (system_bus_name, inhibitor->system_bus_name) == 0) {
-                                                
-                                                daemon->priv->inhibitors = g_list_remove (daemon->priv->inhibitors, 
+                                                daemon->priv->inhibitors = g_list_remove (daemon->priv->inhibitors,
                                                                                           inhibitor);
                                                 inhibitor_list_changed (daemon);
-                                                
-                                                g_debug ("removed inhibitor %s %s (disconnected from the bus)", 
-                                                         inhibitor->cookie, inhibitor->system_bus_name);
+                                                //g_debug ("removed inhibitor %s %s (disconnected from the bus)",
+                                                //inhibitor->cookie, inhibitor->system_bus_name);
                                                 break;
                                         }
                                 }
@@ -389,25 +383,25 @@ _filter (DBusConnection *connection, DBusMessage *message, void *user_data)
 }
 
 static void
-device_add (DevkitDisksDaemon *daemon, const char *device_path, gboolean emit_event)
+device_add (DevkitDisksDaemon *daemon, const char *native_path, gboolean emit_event)
 {
         DevkitDisksDevice *device;
-        device = devkit_disks_device_new (daemon, device_path);
+        device = devkit_disks_device_new (daemon, native_path);
         daemon->priv->devices = g_list_prepend (daemon->priv->devices, device);
-        g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0, 
-                       devkit_disks_device_get_object_path (device));
+        g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0,
+                       devkit_disks_device_local_get_object_path (device));
 }
 
 static void
-device_remove (DevkitDisksDaemon *daemon, const char *device_path)
+device_remove (DevkitDisksDaemon *daemon, const char *native_path)
 {
         GList *l;
         for (l = daemon->priv->devices; l != NULL; l = l->next) {
                 DevkitDisksDevice *device = l->data;
-                if (strcmp (device_path, devkit_disks_device_get_device_path (device)) == 0) {
+                if (strcmp (native_path, devkit_disks_device_local_get_native_path (device)) == 0) {
                         daemon->priv->devices = g_list_remove (daemon->priv->devices, device);
                         g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
-                                       devkit_disks_device_get_object_path (device));
+                                       devkit_disks_device_local_get_object_path (device));
                         g_object_unref (device);
                         break;
                 }
@@ -415,7 +409,7 @@ device_remove (DevkitDisksDaemon *daemon, const char *device_path)
 }
 
 static void
-device_changed (DevkitDisksDaemon *daemon, const char *device_path)
+device_changed (DevkitDisksDaemon *daemon, const char *native_path)
 {
         /* TODO */
 }
@@ -497,16 +491,16 @@ receive_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_dat
 
        if (action != NULL && devpath != NULL && subsystem != NULL) {
                 if (strcmp (subsystem, "block") == 0) {
-                        char *device_path;
-                        device_path = g_build_filename ("/sys", devpath, NULL);
+                        char *native_path;
+                        native_path = g_build_filename ("/sys", devpath, NULL);
                         if (strcmp (action, "add") == 0) {
-                                device_add (daemon, device_path, TRUE);
+                                device_add (daemon, native_path, TRUE);
                         } else if (strcmp (action, "remove") == 0) {
-                                device_remove (daemon, device_path);
+                                device_remove (daemon, native_path);
                         } else if (strcmp (action, "changed") == 0) {
-                                device_changed (daemon, device_path);
+                                device_changed (daemon, native_path);
                         }
-                        g_free (device_path);
+                        g_free (native_path);
                 }
 
        } else {
@@ -591,13 +585,13 @@ register_disks_daemon (DevkitDisksDaemon *daemon)
                 goto error;
         }
 
-        if (!dbus_connection_add_filter (connection, 
-                                         _filter, 
-                                         daemon, 
+        if (!dbus_connection_add_filter (connection,
+                                         _filter,
+                                         daemon,
                                          NULL)) {
                 g_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
                 goto error;
-        }        
+        }
 
        /* setup socket for listening from messages from udev */
 
@@ -636,7 +630,7 @@ devkit_disks_daemon_new (gboolean no_exit)
 {
         gboolean res;
         DevkitDisksDaemon *daemon;
-        GList *device_paths;
+        GList *native_paths;
         GList *l;
 
         daemon = DEVKIT_DISKS_DAEMON (g_object_new (DEVKIT_TYPE_DISKS_DAEMON, NULL));
@@ -648,13 +642,13 @@ devkit_disks_daemon_new (gboolean no_exit)
                 return NULL;
         }
 
-        device_paths = devkit_disks_enumerate_devices ();
-        for (l = device_paths; l != NULL; l = l->next) {
-                char *device_path = l->data;
-                device_add (daemon, device_path, FALSE);
-                g_free (device_path);
+        native_paths = devkit_disks_enumerate_native_paths ();
+        for (l = native_paths; l != NULL; l = l->next) {
+                char *native_path = l->data;
+                device_add (daemon, native_path, FALSE);
+                g_free (native_path);
         }
-        g_list_free (device_paths);
+        g_list_free (native_paths);
 
         return daemon;
 }
@@ -742,11 +736,10 @@ devkit_disks_daemon_enumerate_devices (DevkitDisksDaemon     *daemon,
         object_paths = g_ptr_array_new ();
         for (l = daemon->priv->devices; l != NULL; l = l->next) {
                 DevkitDisksDevice *device = l->data;
-                g_ptr_array_add (object_paths, g_strdup (devkit_disks_device_get_object_path (device)));
+                g_ptr_array_add (object_paths, g_strdup (devkit_disks_device_local_get_object_path (device)));
         }
 
         dbus_g_method_return (context, object_paths);
-
         g_ptr_array_foreach (object_paths, (GFunc) g_free, NULL);
         g_ptr_array_free (object_paths, TRUE);
         return TRUE;
index 772ec20..e6dcd44 100644 (file)
@@ -51,14 +51,41 @@ struct DevkitDisksDevicePrivate
         DBusGConnection *system_bus_connection;
         DBusGProxy      *system_bus_proxy;
         DevkitDisksDaemon *daemon;
-        char *device_path;
         char *object_path;
+
+        char *native_path;
+
+        char *device_file;
+        char *device_file_by_id;
+        char *device_file_by_path;
+
+        char *id_usage;
+        char *id_type;
+        char *id_version;
+        char *id_uuid;
+        char *id_label;
 };
 
 static void     devkit_disks_device_class_init  (DevkitDisksDeviceClass *klass);
 static void     devkit_disks_device_init        (DevkitDisksDevice      *seat);
 static void     devkit_disks_device_finalize    (GObject     *object);
 
+enum
+{
+        PROP_0,
+        PROP_NATIVE_PATH,
+
+        PROP_DEVICE_FILE,
+        PROP_DEVICE_FILE_BY_ID,
+        PROP_DEVICE_FILE_BY_PATH,
+
+        PROP_ID_USAGE,
+        PROP_ID_TYPE,
+        PROP_ID_VERSION,
+        PROP_ID_UUID,
+        PROP_ID_LABEL,
+};
+
 G_DEFINE_TYPE (DevkitDisksDevice, devkit_disks_device, G_TYPE_OBJECT)
 
 #define DEVKIT_DISKS_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEVKIT_TYPE_DISKS_DEVICE, DevkitDisksDevicePrivate))
@@ -82,7 +109,7 @@ GType
 devkit_disks_device_error_get_type (void)
 {
         static GType etype = 0;
-        
+
         if (etype == 0)
         {
                 static const GEnumValue values[] =
@@ -92,12 +119,9 @@ devkit_disks_device_error_get_type (void)
                                 ENUM_ENTRY (DEVKIT_DISKS_DEVICE_ERROR_NOT_AUTHORIZED, "NotAuthorized"),
                                 { 0, 0, 0 }
                         };
-                
                 g_assert (DEVKIT_DISKS_DEVICE_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
-                
                 etype = g_enum_register_static ("DevkitDisksDeviceError", values);
         }
-        
         return etype;
 }
 
@@ -116,10 +140,109 @@ devkit_disks_device_constructor (GType                  type,
                 G_OBJECT_CLASS (devkit_disks_device_parent_class)->constructor (type,
                                                                                 n_construct_properties,
                                                                                 construct_properties));
-        
         return G_OBJECT (device);
 }
 
+
+static void
+set_property (GObject         *object,
+              guint            prop_id,
+              const GValue    *value,
+              GParamSpec      *pspec)
+{
+        DevkitDisksDevice *device = DEVKIT_DISKS_DEVICE (object);
+
+        switch (prop_id) {
+        case PROP_NATIVE_PATH:
+                g_free (device->priv->native_path);
+                device->priv->native_path = g_strdup (g_value_get_string (value));
+                break;
+
+        case PROP_DEVICE_FILE:
+                g_free (device->priv->device_file);
+                device->priv->device_file = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_DEVICE_FILE_BY_ID:
+                g_free (device->priv->device_file_by_id);
+                device->priv->device_file_by_id = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_DEVICE_FILE_BY_PATH:
+                g_free (device->priv->device_file_by_path);
+                device->priv->device_file_by_path = g_strdup (g_value_get_string (value));
+                break;
+
+        case PROP_ID_USAGE:
+                g_free (device->priv->id_usage);
+                device->priv->id_usage = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_ID_TYPE:
+                g_free (device->priv->id_type);
+                device->priv->id_type = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_ID_VERSION:
+                g_free (device->priv->id_version);
+                device->priv->id_version = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_ID_UUID:
+                g_free (device->priv->id_uuid);
+                device->priv->id_uuid = g_strdup (g_value_get_string (value));
+                break;
+        case PROP_ID_LABEL:
+                g_free (device->priv->id_label);
+                device->priv->id_label = g_strdup (g_value_get_string (value));
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+get_property (GObject         *object,
+              guint            prop_id,
+              GValue          *value,
+              GParamSpec      *pspec)
+{
+        DevkitDisksDevice *device = DEVKIT_DISKS_DEVICE (object);
+
+        switch (prop_id) {
+        case PROP_NATIVE_PATH:
+                g_value_set_string (value, device->priv->native_path);
+                break;
+
+        case PROP_DEVICE_FILE:
+                g_value_set_string (value, device->priv->device_file);
+                break;
+        case PROP_DEVICE_FILE_BY_ID:
+                g_value_set_string (value, device->priv->device_file_by_id);
+                break;
+        case PROP_DEVICE_FILE_BY_PATH:
+                g_value_set_string (value, device->priv->device_file_by_path);
+                break;
+
+        case PROP_ID_USAGE:
+                g_value_set_string (value, device->priv->id_usage);
+                break;
+        case PROP_ID_TYPE:
+                g_value_set_string (value, device->priv->id_type);
+                break;
+        case PROP_ID_VERSION:
+                g_value_set_string (value, device->priv->id_version);
+                break;
+        case PROP_ID_UUID:
+                g_value_set_string (value, device->priv->id_uuid);
+                break;
+        case PROP_ID_LABEL:
+                g_value_set_string (value, device->priv->id_label);
+                break;
+
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
 static void
 devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
 {
@@ -127,6 +250,8 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
 
         object_class->constructor = devkit_disks_device_constructor;
         object_class->finalize = devkit_disks_device_finalize;
+        object_class->set_property = set_property;
+        object_class->get_property = get_property;
 
         g_type_class_add_private (klass, sizeof (DevkitDisksDevicePrivate));
 
@@ -134,6 +259,53 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass)
 
         dbus_g_error_domain_register (DEVKIT_DISKS_DEVICE_ERROR, NULL, DEVKIT_DISKS_DEVICE_TYPE_ERROR);
 
+        g_object_class_install_property (
+                object_class,
+                PROP_NATIVE_PATH,
+                g_param_spec_string ("native-path", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_DEVICE_FILE,
+                g_param_spec_string ("device-file", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_DEVICE_FILE_BY_ID,
+                g_param_spec_string ("device-file-by-id", NULL, NULL, NULL, G_PARAM_READWRITE |G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_DEVICE_FILE_BY_PATH,
+                g_param_spec_string (
+                        "device-file-by-path", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_ID_USAGE,
+                g_param_spec_string ("id-usage", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_ID_TYPE,
+                g_param_spec_string ("id-type", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_ID_VERSION,
+                g_param_spec_string ("id-version", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_ID_UUID,
+                g_param_spec_string ("id-uuid", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+        g_object_class_install_property (
+                object_class,
+                PROP_ID_LABEL,
+                g_param_spec_string ("id-label", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+
 }
 
 static void
@@ -155,9 +327,20 @@ devkit_disks_device_finalize (GObject *object)
         g_return_if_fail (device->priv != NULL);
 
         g_object_unref (device->priv->daemon);
-        g_free (device->priv->device_path);
         g_free (device->priv->object_path);
 
+        g_free (device->priv->native_path);
+
+        g_free (device->priv->device_file);
+        g_free (device->priv->device_file_by_id);
+        g_free (device->priv->device_file_by_path);
+
+        g_free (device->priv->id_usage);
+        g_free (device->priv->id_type);
+        g_free (device->priv->id_version);
+        g_free (device->priv->id_uuid);
+        g_free (device->priv->id_label);
+
         G_OBJECT_CLASS (devkit_disks_device_parent_class)->finalize (object);
 }
 
@@ -178,12 +361,12 @@ register_disks_device (DevkitDisksDevice *device)
         }
         connection = dbus_g_connection_get_connection (device->priv->system_bus_connection);
 
-        basename = g_path_get_basename (device->priv->device_path);
+        basename = g_path_get_basename (device->priv->native_path);
         device->priv->object_path = g_build_filename ("/devices/", basename, NULL);
         g_free (basename);
 
-        dbus_g_connection_register_g_object (device->priv->system_bus_connection, 
-                                             device->priv->object_path, 
+        dbus_g_connection_register_g_object (device->priv->system_bus_connection,
+                                             device->priv->object_path,
                                              G_OBJECT (device));
 
         device->priv->system_bus_proxy = dbus_g_proxy_new_for_name (device->priv->system_bus_connection,
@@ -197,16 +380,85 @@ error:
         return FALSE;
 }
 
+static gboolean
+query_info (DevkitDisksDevice *device)
+{
+        gboolean ret;
+        int exit_status;
+        char *command_line;
+        char *standard_output = NULL;
+        char **lines;
+        unsigned int n;
+
+        ret = FALSE;
+
+        /* TODO: this needs to use a faster interface to the udev database. This is SLOOOW! */
+        command_line = g_strdup_printf ("udevinfo -q all --path %s", device->priv->native_path);
+        if (!g_spawn_command_line_sync (command_line,
+                                        &standard_output,
+                                        NULL,
+                                        &exit_status,
+                                        NULL)) {
+                goto out;
+        }
+
+        lines = g_strsplit (standard_output, "\n", 0);
+        for (n = 0; lines[n] != NULL; n++) {
+                char *line = lines[n];
+
+                if (g_str_has_prefix (line, "N: ")) {
+                        device->priv->device_file = g_build_filename ("/dev", line + 3, NULL);
+                } else if (g_str_has_prefix (line, "S: ")) {
+                        /* TODO: crap, there may be more than one symlink in by-id and by-path. For
+                         *       stability, probably have to sort them and get the first. For now 
+                         *       we just punt on this.
+                         */
+                        if (g_str_has_prefix (line + 3, "disk/by-id/") &&
+                            device->priv->device_file_by_id == NULL) {
+                                device->priv->device_file_by_id = g_build_filename ("/dev", line + 3, NULL);
+                        } else if (g_str_has_prefix (line + 3, "disk/by-path/") &&
+                                   device->priv->device_file_by_path == NULL) {
+                                device->priv->device_file_by_path = g_build_filename ("/dev", line + 3, NULL);
+                        }
+
+                } else if (g_str_has_prefix (line, "E: ")) {
+                        if (g_str_has_prefix (line + 3, "ID_FS_USAGE="))
+                                device->priv->id_usage   = g_strdup (line + 3 + sizeof ("ID_FS_USAGE=") - 1);
+                        if (g_str_has_prefix (line + 3, "ID_FS_TYPE="))
+                                device->priv->id_type    = g_strdup (line + 3 + sizeof ("ID_FS_TYPE=") - 1);
+                        if (g_str_has_prefix (line + 3, "ID_FS_VERSION="))
+                                device->priv->id_version = g_strdup (line + 3 + sizeof ("ID_FS_VERSION=") - 1);
+                        if (g_str_has_prefix (line + 3, "ID_FS_UUID="))
+                                device->priv->id_uuid    = g_strdup (line + 3 + sizeof ("ID_FS_UUID=") - 1);
+                        if (g_str_has_prefix (line + 3, "ID_FS_LABEL="))
+                                device->priv->id_label   = g_strdup (line + 3 + sizeof ("ID_FS_LABEL=") - 1);
+                }
+        }
+        g_strfreev (lines);
+
+        /* check for required keys */
+        if (device->priv->device_file == NULL)
+                goto out;
+
+        ret = TRUE;
+
+out:
+        g_free (command_line);
+        g_free (standard_output);
+        return ret;
+}
 
 DevkitDisksDevice *
-devkit_disks_device_new (DevkitDisksDaemon *daemon, const char *device_path)
+devkit_disks_device_new (DevkitDisksDaemon *daemon, const char *native_path)
 {
         DevkitDisksDevice *device;
         gboolean res;
 
         device = DEVKIT_DISKS_DEVICE (g_object_new (DEVKIT_TYPE_DISKS_DEVICE, NULL));
         device->priv->daemon = g_object_ref (daemon);
-        device->priv->device_path = g_strdup (device_path);
+        device->priv->native_path = g_strdup (native_path);
+
+        query_info (device);
 
         res = register_disks_device (DEVKIT_DISKS_DEVICE (device));
         if (! res) {
@@ -220,22 +472,29 @@ devkit_disks_device_new (DevkitDisksDaemon *daemon, const char *device_path)
 /*--------------------------------------------------------------------------------------------------------------*/
 
 /**
- * devkit_disks_enumerate_devices:
+ * devkit_disks_enumerate_native_paths:
  *
  * Enumerates all block devices on the system.
  *
- * Returns: A #GList of device paths (on Linux the sysfs path)
+ * Returns: A #GList of native paths for devices (on Linux the sysfs path)
  */
 GList *
-devkit_disks_enumerate_devices (void)
+devkit_disks_enumerate_native_paths (void)
 {
         GList *ret;
         GDir *dir;
+        gboolean have_class_block;
         const char *name;
 
         ret = 0;
 
-        dir = g_dir_open ("/sys/class/block", 0, NULL);
+        /* TODO: rip out support for running without /sys/class/block */
+
+        have_class_block = FALSE;
+        if (g_file_test ("/sys/class/block", G_FILE_TEST_EXISTS))
+                have_class_block = TRUE;
+
+        dir = g_dir_open (have_class_block ? "/sys/class/block" : "/sys/block", 0, NULL);
         if (dir == NULL)
                 goto out;
 
@@ -243,7 +502,7 @@ devkit_disks_enumerate_devices (void)
                 char *s;
                 char sysfs_path[PATH_MAX];
 
-                s = g_build_filename ("/sys/class/block", name, NULL);
+                s = g_build_filename (have_class_block ? "/sys/class/block" : "/sys/block", name, NULL);
                 if (realpath (s, sysfs_path) == NULL) {
                         g_free (s);
                         continue;
@@ -251,6 +510,23 @@ devkit_disks_enumerate_devices (void)
                 g_free (s);
 
                 ret = g_list_prepend (ret, g_strdup (sysfs_path));
+
+                if (!have_class_block) {
+                        GDir *part_dir;
+                        const char *part_name;
+
+                        if((part_dir = g_dir_open (sysfs_path, 0, NULL)) != NULL) {
+                                while ((part_name = g_dir_read_name (part_dir)) != NULL) {
+                                        if (g_str_has_prefix (part_name, name)) {
+                                                char *part_sysfs_path;
+                                                part_sysfs_path = g_build_filename (sysfs_path, part_name, NULL);
+                                                ret = g_list_prepend (ret, part_sysfs_path);
+                                        }
+                                }
+                                g_dir_close (part_dir);
+                        }
+                }
+
         }
         g_dir_close (dir);
 
@@ -258,34 +534,30 @@ out:
         return ret;
 }
 
+static void
+_throw_not_supported (DBusGMethodInvocation *context)
+{
+        GError *error;
+        error = g_error_new (DEVKIT_DISKS_DEVICE_ERROR,
+                             DEVKIT_DISKS_DEVICE_ERROR_NOT_SUPPORTED,
+                             "Not Supported");
+        dbus_g_method_return_error (context, error);
+        g_error_free (error);
+}
+
 /*--------------------------------------------------------------------------------------------------------------*/
 
 const char *
-devkit_disks_device_get_object_path (DevkitDisksDevice *device)
+devkit_disks_device_local_get_object_path (DevkitDisksDevice *device)
 {
         return device->priv->object_path;
 }
 
 const char *
-devkit_disks_device_get_device_path (DevkitDisksDevice *device)
+devkit_disks_device_local_get_native_path (DevkitDisksDevice *device)
 {
-        return device->priv->device_path;
+        return device->priv->native_path;
 }
 
 /*--------------------------------------------------------------------------------------------------------------*/
 /* exported methods */
-
-gboolean
-devkit_disks_device_get_device_file (DevkitDisksDevice     *device,
-                                     DBusGMethodInvocation *context)
-{
-        GError *error;
-        error = g_error_new (DEVKIT_DISKS_DEVICE_ERROR,
-                             DEVKIT_DISKS_DEVICE_ERROR_NOT_SUPPORTED,
-                             "Not Supported");
-        dbus_g_method_return_error (context, error);
-        g_error_free (error);
-        return TRUE;
-}
-
-
index 91e870e..a1dd94b 100644 (file)
@@ -63,18 +63,24 @@ GType devkit_disks_device_error_get_type (void);
 
 GQuark             devkit_disks_device_error_quark         (void);
 GType              devkit_disks_device_get_type            (void);
-DevkitDisksDevice *devkit_disks_device_new                 (DevkitDisksDaemon *daemon, const char *device_path);
+DevkitDisksDevice *devkit_disks_device_new                 (DevkitDisksDaemon *daemon, const char *native_path);
 
-const char        *devkit_disks_device_get_object_path     (DevkitDisksDevice *device);
-const char        *devkit_disks_device_get_device_path     (DevkitDisksDevice *device);
+const char        *devkit_disks_device_local_get_object_path     (DevkitDisksDevice *device);
+const char        *devkit_disks_device_local_get_native_path     (DevkitDisksDevice *device);
 
-GList *devkit_disks_enumerate_devices (void);
+GList *devkit_disks_enumerate_native_paths (void);
 
 /* exported methods */
 
+gboolean devkit_disks_device_get_native_path (DevkitDisksDevice     *device,
+                                              DBusGMethodInvocation *context);
+
 gboolean devkit_disks_device_get_device_file (DevkitDisksDevice     *device,
                                               DBusGMethodInvocation *context);
 
+gboolean devkit_disks_device_get_device_file_symlinks (DevkitDisksDevice     *device,
+                                                       DBusGMethodInvocation *context);
+
 G_END_DECLS
 
 #endif /* __DEVKIT_DISKS_DEVICE_H__ */
index d3440ac..c6a9d9b 100644 (file)
@@ -3,10 +3,53 @@
 
   <interface name="org.freedesktop.DeviceKit.Disks.Device">
 
-    <method name="GetDeviceFile">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-      <arg name="device_file" direction="out" type="s"/>
-    </method>
+    <!-- the OS native path; on Linux this is the sysfs path -->
+    <property name="native-path" type="s" access="read"/>
+
+    <!-- block special device file for access the device -->
+    <property name="device-file" type="s" access="read"/>
+
+    <!-- if set, a (unique) stable path to the device in question -->
+    <property name="device-file-by-id" type="s" access="read"/>
+
+    <!-- if set, a stable path to the port the device is connected to -->
+    <property name="device-file-by-path" type="s" access="read"/>
+
+    <!-- A result of probing for signatures on the block device; known 
+         values are
+
+           filesystem      - the device contains a file system
+           crypto          - the device contains encrypted data)
+           partitiontable  - the device is partitioned into other devices
+           raid            - the device is member of a RAID set or other
+                             schemes requiring device assembly
+           other           - other signature found on the device
+      -->
+    <property name="id-usage" type="s" access="read"/>
+
+    <!-- More detailed result of signature probing. The value depends
+         on the value of 'id-usage'
+
+           filesystem      - the filesystem type e.g. vfat, ext3 and so forth
+           crypto          - the crypto type; only known value is crypto_LUKS
+           partitiontable  - the partition table type; known values
+                              mbr  - Master Boot Record
+                              embr - Extended Master Boot Record
+                              apm  - Apple Partitoning Map
+                              gpt  - GUID Partition Table
+           raid            - the type of raid (TODO)
+           other           - known types are: swap
+      -->
+    <property name="id-type" type="s" access="read"/>
+
+    <!-- The version of the format specified by 'id-type' -->
+    <property name="id-version" type="s" access="read"/>
+
+    <!-- If set, an UUID for the format specified by 'id-type' -->
+    <property name="id-uuid" type="s" access="read"/>
+
+    <!-- If set, a label for the format specified by 'id-type' -->
+    <property name="id-label" type="s" access="read"/>
 
   </interface>
 
index 1685973..a091f82 100644 (file)
@@ -15,10 +15,14 @@ INCLUDES = \
        @GLIB_CFLAGS@
 
 BUILT_SOURCES =                                                \
-       devkit-disks-client-glue.h
+       devkit-disks-daemon-glue.h                      \
+       devkit-disks-device-glue.h
 
-devkit-disks-client-glue.h: $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.xml Makefile.am
-       dbus-binding-tool --prefix=devkit_disks_daemon --mode=glib-client --output=devkit-disks-client-glue.h $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.xml
+devkit-disks-daemon-glue.h: $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.xml Makefile.am
+       dbus-binding-tool --prefix=devkit_disks_daemon --mode=glib-client --output=devkit-disks-daemon-glue.h $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.xml
+
+devkit-disks-device-glue.h: $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.Device.xml Makefile.am
+       dbus-binding-tool --prefix=devkit_disks_daemon --mode=glib-client --output=devkit-disks-device-glue.h $(top_srcdir)/src/org.freedesktop.DeviceKit.Disks.Device.xml
 
 bin_PROGRAMS = devkit-disks
 
@@ -37,5 +41,10 @@ devkit_disks_LDADD =                                         \
 
 CLEANFILES = $(BUILT_SOURCES)
 
+profiledir = $(sysconfdir)/profile.d
+profile_SCRIPTS = devkit-disks-bash-completion.sh
+
+EXTRA_DIST = $(profile_SCRIPTS)
+
 clean-local :
        rm -f *~ $(service_DATA) $(dbusconf_DATA)
index 72f8bad..72e4af5 100644 (file)
@@ -42,7 +42,8 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#include "devkit-disks-client-glue.h"
+#include "devkit-disks-daemon-glue.h"
+#include "devkit-disks-device-glue.h"
 
 static void
 device_added_signal_handler (DBusGProxy *proxy, const char *object_path, gpointer user_data)
@@ -56,6 +57,135 @@ device_removed_signal_handler (DBusGProxy *proxy, const char *object_path, gpoin
   g_print ("removed: %s\n", object_path);
 }
 
+static char *
+get_property_string (DBusGConnection *bus,
+                     const char *svc_name,
+                     const char *obj_path,
+                     const char *if_name,
+                     const char *prop_name)
+{
+        char *ret;
+        DBusGProxy *proxy;
+        GValue value = { 0 };
+        GError *error = NULL;
+
+        ret = NULL;
+       proxy = dbus_g_proxy_new_for_name (bus,
+                                           svc_name,
+                                           obj_path,
+                                           "org.freedesktop.DBus.Properties");
+        if (!dbus_g_proxy_call (proxy,
+                                "Get",
+                                &error,
+                                G_TYPE_STRING,
+                                if_name,
+                                G_TYPE_STRING,
+                                prop_name,
+                                G_TYPE_INVALID,
+                                G_TYPE_VALUE,
+                                &value,
+                                G_TYPE_INVALID)) {
+                g_warning ("error: %s\n", error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+        ret = g_strdup (g_value_get_string (&value));
+        g_value_unset (&value);
+
+out:
+        g_object_unref (proxy);
+        return ret;
+}
+
+typedef struct
+{
+        char *native_path;
+
+        char *device_file;
+        char *device_file_by_id;
+        char *device_file_by_path;
+
+        char *id_usage;
+        char *id_type;
+        char *id_version;
+        char *id_uuid;
+        char *id_label;
+} DeviceProperties;
+
+static DeviceProperties *
+device_properties_get (DBusGConnection *bus, const char *object_path)
+{
+        DeviceProperties *props;
+
+        props = g_new0 (DeviceProperties, 1);
+        props->native_path = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "native-path");
+
+        props->device_file = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "device-file");
+        props->device_file_by_id = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "device-file-by-id");
+        props->device_file_by_path = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "device-file-by-path");
+
+        props->id_usage = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "id-usage");
+        props->id_type = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "id-type");
+        props->id_version = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "id-version");
+        props->id_uuid = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "id-uuid");
+        props->id_label = get_property_string (
+                bus,
+                "org.freedesktop.DeviceKit.Disks",
+                object_path,
+                "org.freedesktop.DeviceKit.Disks.Device",
+                "id-label");
+        return props;
+}
+
+static void
+device_properties_free (DeviceProperties *props)
+{
+        g_free (props->native_path);
+        g_free (props->device_file);
+        g_free (props);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -69,10 +199,12 @@ main (int argc, char **argv)
         static gboolean      inhibit      = FALSE;
         static gboolean      enumerate    = FALSE;
         static gboolean      monitor      = FALSE;
+        static char         *show_info    = NULL;
         static GOptionEntry  entries []   = {
                 { "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit, "Inhibit the disks daemon from exiting", NULL },
                 { "enumerate", 0, 0, G_OPTION_ARG_NONE, &enumerate, "Enumerate objects paths for devices", NULL },
                 { "monitor", 0, 0, G_OPTION_ARG_NONE, &monitor, "Monitor activity from the disk daemon", NULL },
+                { "show-info", 0, 0, G_OPTION_ARG_STRING, &show_info, "Show information about object path", NULL },
                 { NULL }
         };
 
@@ -128,11 +260,26 @@ main (int argc, char **argv)
                 g_ptr_array_free (devices, TRUE);
         } else if (monitor) {
                 g_print ("Monitoring activity from the disks daemon. Press Ctrl+C to cancel.\n");
-                dbus_g_proxy_connect_signal (disks_proxy, "DeviceAdded", 
+                dbus_g_proxy_connect_signal (disks_proxy, "DeviceAdded",
                                              G_CALLBACK (device_added_signal_handler), NULL, NULL);
-                dbus_g_proxy_connect_signal (disks_proxy, "DeviceRemoved", 
+                dbus_g_proxy_connect_signal (disks_proxy, "DeviceRemoved",
                                              G_CALLBACK (device_removed_signal_handler), NULL, NULL);
                 g_main_loop_run (loop);
+        } else if (show_info != NULL) {
+                DeviceProperties *props;
+
+                props = device_properties_get (bus, show_info);
+                g_print ("Showing information for %s\n", show_info);
+                g_print ("  native-path: %s\n", props->native_path);
+                g_print ("  device-file: %s\n", props->device_file);
+                g_print ("    by-id:     %s\n", props->device_file_by_id);
+                g_print ("    by-path:   %s\n", props->device_file_by_path);
+                g_print ("  id-usage:    %s\n", props->id_usage);
+                g_print ("  id-type:     %s\n", props->id_type);
+                g_print ("  id-version:  %s\n", props->id_version);
+                g_print ("  id-uuid:     %s\n", props->id_uuid);
+                g_print ("  id-label:    %s\n", props->id_label);
+                device_properties_free (props);
         }
 
         ret = 0;