#include <gio/gunixmounts.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#include <devkit-gobject.h>
#include "devkit-disks-daemon.h"
#include "devkit-disks-device.h"
#include "devkit-disks-daemon-glue.h"
#include "devkit-disks-marshal.h"
+
/*--------------------------------------------------------------------------------------------------------------*/
enum
PolKitContext *pk_context;
PolKitTracker *pk_tracker;
- int udev_socket;
- GIOChannel *udev_channel;
+ DevkitClient *devkit_client;
+
GIOChannel *mdstat_channel;
GList *inhibitors;
devkit_disks_daemon_init (DevkitDisksDaemon *daemon)
{
daemon->priv = DEVKIT_DISKS_DAEMON_GET_PRIVATE (daemon);
- daemon->priv->udev_socket = -1;
daemon->priv->map_native_path_to_device = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_source_remove (daemon->priv->killtimer_id);
}
- if (daemon->priv->udev_socket != -1)
- close (daemon->priv->udev_socket);
-
if (daemon->priv->mdstat_channel != NULL)
g_io_channel_unref (daemon->priv->mdstat_channel);
- if (daemon->priv->udev_channel != NULL)
- g_io_channel_unref (daemon->priv->udev_channel);
-
if (daemon->priv->map_native_path_to_device != NULL) {
g_hash_table_unref (daemon->priv->map_native_path_to_device);
}
g_object_unref (daemon->priv->mount_monitor);
}
+ if (daemon->priv->devkit_client != NULL) {
+ g_object_unref (daemon->priv->devkit_client);
+ }
+
G_OBJECT_CLASS (devkit_disks_daemon_parent_class)->finalize (object);
}
where_the_object_was);
}
+#if 0
static void device_add (DevkitDisksDaemon *daemon, const char *native_path, gboolean emit_event);
static void device_remove (DevkitDisksDaemon *daemon, const char *native_path);
device_add (daemon, native_path, TRUE);
}
}
+#endif
+
+static void
+device_changed (DevkitDisksDaemon *daemon, const char *native_path, gboolean synthesized)
+{
+ g_warning ("TODO");
+}
void
devkit_disks_daemon_local_synthesize_changed (DevkitDisksDaemon *daemon,
const char *native_path)
{
- device_changed (daemon, native_path, TRUE);
+ //device_changed (daemon, native_path, TRUE);
}
static void
-device_add (DevkitDisksDaemon *daemon, const char *native_path, gboolean emit_event)
+device_add (DevkitDisksDaemon *daemon, DevkitDevice *d, gboolean emit_event)
{
DevkitDisksDevice *device;
+ const char *native_path;
+ native_path = devkit_device_get_native_path (d);
device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
if (device != NULL) {
/* we already have the device; treat as change event */
g_print ("treating add event as change event on %s\n", native_path);
- device_changed (daemon, native_path, FALSE);
+ //device_changed (daemon, d, FALSE);
} else {
- device = devkit_disks_device_new (daemon, native_path);
+ device = devkit_disks_device_new (daemon, d);
if (device != NULL) {
/* only take a weak ref; the device will stay on the bus until
}
}
+#if 0
static void
device_remove (DevkitDisksDaemon *daemon, const char *native_path)
{
g_object_unref (device);
}
}
+#endif
DevkitDisksDevice *
devkit_disks_daemon_local_find_by_native_path (DevkitDisksDaemon *daemon, const char *native_path)
return g_hash_table_get_values (daemon->priv->map_native_path_to_device);
}
-static gboolean
-receive_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
-{
- DevkitDisksDaemon *daemon = user_data;
- int fd;
- int retval;
- struct msghdr smsg;
- struct cmsghdr *cmsg;
- struct iovec iov;
- struct ucred *cred;
- char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
- char buf[4096];
- size_t bufpos = 0;
- const char *action;
- const char *devpath;
- const char *subsystem;
-
- memset(buf, 0x00, sizeof (buf));
- iov.iov_base = &buf;
- iov.iov_len = sizeof (buf);
- memset (&smsg, 0x00, sizeof (struct msghdr));
- smsg.msg_iov = &iov;
- smsg.msg_iovlen = 1;
- smsg.msg_control = cred_msg;
- smsg.msg_controllen = sizeof (cred_msg);
-
- fd = g_io_channel_unix_get_fd (source);
-
- retval = recvmsg (fd, &smsg, 0);
- if (retval < 0) {
- if (errno != EINTR)
- g_warning ("Unable to receive message: %m");
- goto out;
- }
- cmsg = CMSG_FIRSTHDR (&smsg);
- cred = (struct ucred *) CMSG_DATA (cmsg);
-
- if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
- g_warning ("No sender credentials received, message ignored");
- goto out;
- }
-
- if (cred->uid != 0) {
- g_warning ("Sender uid=%d, message ignored", cred->uid);
- goto out;
- }
-
- if (!strstr(buf, "@/")) {
- g_warning ("invalid message format");
- goto out;
- }
-
- action = NULL;
- devpath = NULL;
- subsystem = NULL;
- while (bufpos < sizeof (buf)) {
- size_t keylen;
- char *key;
-
- key = &buf[bufpos];
- keylen = strlen(key);
- if (keylen == 0)
- break;
- bufpos += keylen + 1;
-
- if (strncmp (key, "ACTION=", 7) == 0) {
- action = key + 7;
- } else if (strncmp (key, "DEVPATH=", 8) == 0) {
- devpath = key + 8;
- } else if (strncmp(key, "SUBSYSTEM=", 10) == 0) {
- subsystem = key + 10;
- }
- /* TODO: collect other values */
- }
-
- if (action != NULL && devpath != NULL && subsystem != NULL) {
- if (strcmp (subsystem, "block") == 0) {
- char *native_path;
-
- native_path = g_build_filename ("/sys", devpath, NULL);
- if (strcmp (action, "add") == 0) {
- device_add (daemon, native_path, TRUE);
- } else if (strcmp (action, "remove") == 0) {
- device_remove (daemon, native_path);
- } else if (strcmp (action, "change") == 0) {
- device_changed (daemon, native_path, FALSE);
- }
- g_free (native_path);
- }
-
- } else {
- g_warning ("malformed message");
- }
-
-out:
- return TRUE;
-}
-
static void
mounts_changed (GUnixMountMonitor *monitor, gpointer user_data)
{
static gboolean
register_disks_daemon (DevkitDisksDaemon *daemon)
{
- struct sockaddr_un saddr;
- socklen_t addrlen;
- const int on = 1;
DBusConnection *connection;
DBusError dbus_error;
GError *error = NULL;
error = NULL;
}
-
- /* setup socket for listening from messages from udev */
- memset (&saddr, 0x00, sizeof(saddr));
- saddr.sun_family = AF_LOCAL;
- /* use abstract namespace for socket path */
- strcpy (&saddr.sun_path[1], "/org/freedesktop/devicekit/disks/udev_event");
- addrlen = offsetof (struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
- daemon->priv->udev_socket = socket (AF_LOCAL, SOCK_DGRAM, 0);
- if (daemon->priv->udev_socket == -1) {
- g_warning ("Couldn't open udev event socket: %m");
- goto error;
- }
-
- if (bind (daemon->priv->udev_socket, (struct sockaddr *) &saddr, addrlen) < 0) {
- g_warning ("Error binding to udev event socket: %m");
+ /* connect to the DeviceKit daemon */
+ daemon->priv->devkit_client = devkit_client_new (NULL); // TODO: subsystems
+ if (!devkit_client_connect (daemon->priv->devkit_client, &error)) {
+ g_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
+ g_error_free (error);
goto error;
- }
- /* enable receiving of the sender credentials */
- setsockopt (daemon->priv->udev_socket, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
- daemon->priv->udev_channel = g_io_channel_unix_new (daemon->priv->udev_socket);
- g_io_add_watch (daemon->priv->udev_channel, G_IO_IN, receive_udev_data, daemon);
- g_io_channel_unref (daemon->priv->udev_channel);
+ }
/* monitor mounts */
daemon->priv->mount_monitor = g_unix_mount_monitor_new ();
DevkitDisksDaemon *
devkit_disks_daemon_new (gboolean no_exit)
{
- gboolean res;
DevkitDisksDaemon *daemon;
- GList *native_paths;
+ GError *error = NULL;
+ GList *devices;
GList *l;
+ const char *subsystems[] = {"block", NULL};
daemon = DEVKIT_DISKS_DAEMON (g_object_new (DEVKIT_TYPE_DISKS_DAEMON, NULL));
daemon->priv->no_exit = no_exit;
- res = register_disks_daemon (DEVKIT_DISKS_DAEMON (daemon));
- if (! res) {
+ if (!register_disks_daemon (DEVKIT_DISKS_DAEMON (daemon))) {
g_object_unref (daemon);
return NULL;
}
- 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);
+
+ devices = devkit_client_enumerate_by_subsystem (daemon->priv->devkit_client,
+ subsystems,
+ &error);
+ if (error != NULL) {
+ g_warning ("Cannot enumerate devices: %s", error->message);
+ g_error_free (error);
+ g_object_unref (daemon);
+ return NULL;
+ }
+ for (l = devices; l != NULL; l = l->next) {
+ DevkitDevice *device = l->data;
+ device_add (daemon, device, FALSE);
}
- g_list_free (native_paths);
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
/* clean stale directories in /media as well as stale
* entries in /var/lib/DeviceKit-disks/mtab
#include <gio/gunixmounts.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <devkit/devkit.h>
+#include <devkit-gobject.h>
#include <polkit-dbus/polkit-dbus.h>
#include "devkit-disks-device.h"
static void init_info (DevkitDisksDevice *device);
static void free_info (DevkitDisksDevice *device);
-static gboolean update_info (DevkitDisksDevice *device);
+static gboolean update_info (DevkitDisksDevice *device, DevkitDevice *d);
/* Returns the cleartext device. If device==NULL, unlocking failed and an error has
* been reported back to the caller
}
-static devkit_bool_t
-update_info_add_ptr (DevKitInfo *info, const char *str, void *user_data)
-{
- GPtrArray *ptr_array = user_data;
- g_ptr_array_add (ptr_array, g_strdup (str));
- return FALSE;
-}
-
static char *
_dupv8 (const char *s)
{
return NULL;
}
-static devkit_bool_t
-update_info_properties_cb (DevKitInfo *info, const char *key, void *user_data)
+static gboolean
+update_info_properties_cb (DevkitDevice *d, const char *key, const char *value, void *user_data)
{
+ int n;
gboolean ignore_device;
DevkitDisksDevice *device = user_data;
ignore_device = FALSE;
if (strcmp (key, "ID_FS_USAGE") == 0) {
- device->priv->info.id_usage = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.id_usage = g_strdup (value);
} else if (strcmp (key, "ID_FS_TYPE") == 0) {
- device->priv->info.id_type = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.id_type = g_strdup (value);
} else if (strcmp (key, "ID_FS_VERSION") == 0) {
- device->priv->info.id_version = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.id_version = g_strdup (value);
if (device->priv->info.device_is_linux_md_component) {
- device->priv->info.linux_md_component_version =
- _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.linux_md_component_version = g_strdup (value);
}
} else if (strcmp (key, "ID_FS_UUID") == 0) {
- device->priv->info.id_uuid = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.id_uuid = g_strdup (value);
if (device->priv->info.device_is_linux_md_component) {
- device->priv->info.linux_md_component_uuid =
- _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.linux_md_component_uuid = g_strdup (value);
}
} else if (strcmp (key, "ID_FS_LABEL") == 0) {
- device->priv->info.id_label = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.id_label = g_strdup (value);
if (device->priv->info.device_is_linux_md_component) {
- device->priv->info.linux_md_component_name =
- _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.linux_md_component_name = g_strdup (value);
}
} else if (strcmp (key, "ID_VENDOR") == 0) {
if (device->priv->info.device_is_drive && device->priv->info.drive_vendor == NULL)
- device->priv->info.drive_vendor = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.drive_vendor = g_strdup (value);
} else if (strcmp (key, "ID_MODEL") == 0) {
if (device->priv->info.device_is_drive && device->priv->info.drive_model == NULL)
- device->priv->info.drive_model = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.drive_model = g_strdup (value);
} else if (strcmp (key, "ID_REVISION") == 0) {
if (device->priv->info.device_is_drive && device->priv->info.drive_revision == NULL)
- device->priv->info.drive_revision = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.drive_revision = g_strdup (value);
} else if (strcmp (key, "ID_SERIAL_SHORT") == 0) {
if (device->priv->info.device_is_drive && device->priv->info.drive_serial == NULL)
- device->priv->info.drive_serial = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.drive_serial = g_strdup (value);
} else if (strcmp (key, "PART_SCHEME") == 0) {
if (device->priv->info.device_is_partition) {
device->priv->info.partition_scheme =
- _dupv8 (devkit_info_property_get_string (info, key));
+ g_strdup (value);
} else {
device->priv->info.device_is_partition_table = TRUE;
device->priv->info.partition_table_scheme =
- _dupv8 (devkit_info_property_get_string (info, key));
+ g_strdup (value);
}
} else if (strcmp (key, "PART_COUNT") == 0) {
- device->priv->info.partition_table_count = devkit_info_property_get_int (info, key);
+ device->priv->info.partition_table_count = devkit_device_get_property_as_int (d, key);
} else if (g_str_has_prefix (key, "PART_P") && g_ascii_isdigit (key[6])) {
char *endp;
int part_number = strtol (key + 6, &endp, 10);
array = NULL;
index = 0;
- value = devkit_info_property_get_uint64 (info, key);
+ value = devkit_device_get_property_as_uint64 (d, key);
if (g_str_has_prefix (endp, "_OFFSET")) {
array = device->priv->info.partition_table_offsets;
index = part_number - 1;
if (g_str_has_prefix (endp, "_LABEL")) {
device->priv->info.partition_label =
- _dupv8 (devkit_info_property_get_string (info, key));
+ g_strdup (value);
} else if (g_str_has_prefix (endp, "_UUID")) {
device->priv->info.partition_uuid =
- _dupv8 (devkit_info_property_get_string (info, key));
+ g_strdup (value);
} else if (g_str_has_prefix (endp, "_TYPE")) {
device->priv->info.partition_type =
- _dupv8 (devkit_info_property_get_string (info, key));
+ g_strdup (value);
} else if (g_str_has_prefix (endp, "_OFFSET")) {
device->priv->info.partition_offset =
- devkit_info_property_get_uint64 (info, key);
+ devkit_device_get_property_as_uint64 (d, key);
} else if (g_str_has_prefix (endp, "_SIZE")) {
device->priv->info.partition_size =
- devkit_info_property_get_uint64 (info, key);
+ devkit_device_get_property_as_uint64 (d, key);
} else if (g_str_has_prefix (endp, "_FLAGS")) {
- devkit_info_property_strlist_foreach (info, key, update_info_add_ptr,
- device->priv->info.partition_flags);
+ char **tokens = devkit_device_dup_property_as_strv (d, key);
+ for (n = 0; tokens[n] != NULL; n++)
+ g_ptr_array_add (device->priv->info.partition_flags, tokens[n]);
+ g_free (tokens);
}
}
}
} else if (strcmp (key, "MD_DEVICES") == 0) {
- device->priv->info.linux_md_component_num_raid_devices = devkit_info_property_get_int (info, key);
+ device->priv->info.linux_md_component_num_raid_devices = devkit_device_get_property_as_int (d, key);
} else if (strcmp (key, "MD_LEVEL") == 0) {
- device->priv->info.linux_md_component_level = g_strdup (devkit_info_property_get_string (info, key));
+ device->priv->info.linux_md_component_level = g_strdup (value);
} else if (strcmp (key, "MD_UPDATE_TIME") == 0) {
- device->priv->info.linux_md_component_update_time = devkit_info_property_get_uint64 (info, key);
+ device->priv->info.linux_md_component_update_time = devkit_device_get_property_as_uint64 (d, key);
} else if (strcmp (key, "MD_EVENTS") == 0) {
- device->priv->info.linux_md_component_events = devkit_info_property_get_uint64 (info, key);
+ device->priv->info.linux_md_component_events = devkit_device_get_property_as_uint64 (d, key);
} else if (strcmp (key, "DM_NAME") == 0) {
- const char *dm_name;
- dm_name = devkit_info_property_get_string (info, key);
-
- if (g_str_has_prefix (dm_name, "temporary-cryptsetup-")) {
+ if (g_str_has_prefix (value, "temporary-cryptsetup-")) {
/* ignore temporary devices created by /sbin/cryptsetup */
ignore_device = TRUE;
goto out;
} else {
/* TODO: export this at some point */
- device->priv->info.dm_name = g_strdup (dm_name);
+ device->priv->info.dm_name = g_strdup (value);
}
} else if (strcmp (key, "DM_TARGET_TYPES") == 0) {
- if (strcmp (devkit_info_property_get_string (info, key), "crypt") == 0) {
+ if (strcmp (value, "crypt") == 0) {
/* we're a dm-crypt target and can, by design, then only have one slave */
if (device->priv->info.slaves_objpath->len == 1) {
/* avoid claiming we are a drive since we want to be related
}
} 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);
-
+ char **tokens = devkit_device_dup_property_as_strv (d, key);
+ for (n = 0; tokens[n] != NULL; n++)
+ g_ptr_array_add (device->priv->info.drive_media_compatibility, tokens[n]);
+ g_free (tokens);
} else if (strcmp (key, "MEDIA_TYPE") == 0) {
- device->priv->info.drive_media = _dupv8 (devkit_info_property_get_string (info, key));
+ device->priv->info.drive_media = g_strdup (value);
} else if (strcmp (key, "MEDIA_AVAILABLE") == 0) {
if (device->priv->info.device_is_removable) {
- device->priv->info.device_is_media_available = devkit_info_property_get_bool (info, key);
+ device->priv->info.device_is_media_available = devkit_device_get_property_as_boolean (d, key);
}
}
return ignore_device;
}
-static gboolean
-update_info_symlinks_cb (DevKitInfo *info, const char *value, void *user_data)
-{
- DevkitDisksDevice *device = user_data;
-
- if (g_str_has_prefix (value, "/dev/disk/by-id/") || g_str_has_prefix (value, "/dev/disk/by-uuid/")) {
- g_ptr_array_add (device->priv->info.device_file_by_id, _dupv8 (value));
- } else if (g_str_has_prefix (value, "/dev/disk/by-path/")) {
- g_ptr_array_add (device->priv->info.device_file_by_path, _dupv8 (value));
- }
-
- return FALSE;
-}
-
static void
update_slaves (DevkitDisksDevice *device)
{
slave = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, slave_objpath);
if (slave != NULL) {
- update_info (slave);
+ update_info (slave, NULL);
}
}
}
* Returns: #TRUE to keep (or add) the device; #FALSE to ignore (or remove) the device
**/
static gboolean
-update_info (DevkitDisksDevice *device)
+update_info (DevkitDisksDevice *device, DevkitDevice *d)
{
guint64 start, size;
char *s;
gboolean ret;
int fd;
int block_size;
- DevKitInfo *info;
char *path;
GDir *dir;
const char *name;
const char *fstype;
ret = FALSE;
- info = NULL;
+
+ if (d != NULL) {
+ g_object_ref (d);
+ } else {
+ /* TODO */
+ goto out;
+ }
/* md is special; we don't get "remove" events from the kernel when an array is
* stopped; so catch it very early before erasing our existing slave variable (we
device->priv->info.device_is_drive = FALSE;
}
- info = devkit_info_new (device->priv->native_path);
- if (info == NULL) {
+ device->priv->info.device_file = g_strdup (devkit_device_get_device_file (d));
+ if (device->priv->info.device_file == NULL) {
+ g_warning ("No device file for %s", device->priv->native_path);
goto out;
}
- device->priv->info.device_file = _dupv8 (devkit_info_get_device_file (info));
- devkit_info_device_file_symlinks_foreach (info, update_info_symlinks_cb, device);
+ const char * const * symlinks;
+ symlinks = devkit_device_get_device_file_symlinks (d);
+ for (n = 0; symlinks[n] != NULL; n++) {
+ if (g_str_has_prefix (symlinks[n], "/dev/disk/by-id/") ||
+ g_str_has_prefix (symlinks[n], "/dev/disk/by-uuid/")) {
+ g_ptr_array_add (device->priv->info.device_file_by_id, g_strdup (symlinks[n]));
+ } else if (g_str_has_prefix (symlinks[n], "/dev/disk/by-path/")) {
+ g_ptr_array_add (device->priv->info.device_file_by_path, g_strdup (symlinks[n]));
+ }
+ }
/* TODO: hmm.. it would be really nice if sysfs could export this. There's a
- * queue/hw_sector_size in sysfs but that's not available for e.g. RAID
+ * queue/hw_sector_size in sysfs but that's not available for e.g. Linux md devices
*/
errno = 0;
- fd = open (devkit_info_get_device_file (info), O_RDONLY);
+ fd = open (device->priv->info.device_file, O_RDONLY);
if (fd < 0 && errno != ENOMEDIUM) {
- g_warning ("Cannot open %s read only", devkit_info_get_device_file (info));
+ g_warning ("Cannot open %s read only", device->priv->info.device_file);
goto out;
}
if (errno == ENOMEDIUM) {
block_size = 0;
} else {
if (ioctl (fd, BLKSSZGET, &block_size) != 0) {
- g_warning ("Cannot determine block size for %s", devkit_info_get_device_file (info));
+ g_warning ("Cannot determine block size for %s", device->priv->info.device_file);
goto out;
}
close (fd);
* (e.g. write-protect on SD cards, optical drives etc.)
*/
errno = 0;
- fd = open (devkit_info_get_device_file (info), O_WRONLY);
+ fd = open (device->priv->info.device_file, O_WRONLY);
if (fd < 0) {
if (errno == EROFS) {
device->priv->info.device_is_read_only = TRUE;
} else {
- g_warning ("Cannot determine if %s is read only: %m",
- devkit_info_get_device_file (info));
+ g_warning ("Cannot determine if %s is read only: %m", device->priv->info.device_file);
goto out;
}
} else {
/* ------------------------------------- */
/* set this first since e.g. ID_FS_LABEL et. al. needs to be redirected/copied */
- fstype = devkit_info_property_get_string (info, "ID_FS_TYPE");
+ fstype = devkit_device_get_property (d, "ID_FS_TYPE");
if (fstype != NULL && strcmp (fstype, "linux_raid_member") == 0) {
device->priv->info.device_is_linux_md_component = TRUE;
}
- if (devkit_info_property_foreach (info, update_info_properties_cb, device)) {
+ if (devkit_device_properties_foreach (d, update_info_properties_cb, device)) {
goto out;
}
ret = TRUE;
out:
- if (info != NULL)
- devkit_info_unref (info);
+ if (d != NULL)
+ g_object_unref (d);
return ret;
}
}
DevkitDisksDevice *
-devkit_disks_device_new (DevkitDisksDaemon *daemon, const char *native_path)
+devkit_disks_device_new (DevkitDisksDaemon *daemon, DevkitDevice *d)
{
DevkitDisksDevice *device;
- gboolean res;
+ const char *native_path;
+
+ device = NULL;
+ native_path = devkit_device_get_native_path (d);
+
+ /* ignore ram and loop devices */
+ if (g_str_has_prefix (native_path, "/sys/devices/virtual/block/ram") ||
+ g_str_has_prefix (native_path, "/sys/devices/virtual/block/loop"))
+ goto out;
device = DEVKIT_DISKS_DEVICE (g_object_new (DEVKIT_TYPE_DISKS_DEVICE, NULL));
device->priv->daemon = g_object_ref (daemon);
device->priv->native_path = g_strdup (native_path);
- if (!update_info (device)) {
+ if (!update_info (device, d)) {
g_object_unref (device);
device = NULL;
goto out;
}
- res = register_disks_device (DEVKIT_DISKS_DEVICE (device));
- if (! res) {
+ if (! register_disks_device (DEVKIT_DISKS_DEVICE (device))) {
g_object_unref (device);
device = NULL;
goto out;
{
gboolean keep_device;
- keep_device = update_info (device);
+ keep_device = update_info (device, NULL);
/* if we're a linux md device.. then a change event might mean some metadata on the
* components changed. So trigger a change on each slave