devkit_disks_daemon_error_get_type (void)
{
static GType etype = 0;
-
+
if (etype == 0)
{
static const GEnumValue values[] =
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;
}
G_OBJECT_CLASS (devkit_disks_daemon_parent_class)->constructor (type,
n_construct_properties,
construct_properties));
-
return G_OBJECT (daemon);
}
return TRUE;
}
-static int
+static int
pk_io_add_watch (PolKitContext *pk_context, int fd)
{
guint id = 0;
return id;
}
-static void
+static void
pk_io_remove_watch (PolKitContext *pk_context, int watch_id)
{
g_source_remove (watch_id);
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;
}
}
}
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;
}
}
static void
-device_changed (DevkitDisksDaemon *daemon, const char *device_path)
+device_changed (DevkitDisksDaemon *daemon, const char *native_path)
{
/* TODO */
}
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 {
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 */
{
gboolean res;
DevkitDisksDaemon *daemon;
- GList *device_paths;
+ GList *native_paths;
GList *l;
daemon = DEVKIT_DISKS_DAEMON (g_object_new (DEVKIT_TYPE_DISKS_DAEMON, NULL));
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;
}
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;
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))
devkit_disks_device_error_get_type (void)
{
static GType etype = 0;
-
+
if (etype == 0)
{
static const GEnumValue values[] =
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;
}
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)
{
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));
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
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);
}
}
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,
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) {
/*--------------------------------------------------------------------------------------------------------------*/
/**
- * 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;
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;
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);
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;
-}
-
-
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__ */
<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>
@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
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)
#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)
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)
{
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 }
};
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;