refuse to create a partition table if an enclosed partition is mounted
authorDavid Zeuthen <davidz@redhat.com>
Fri, 21 Mar 2008 23:02:42 +0000 (19:02 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Fri, 21 Mar 2008 23:02:42 +0000 (19:02 -0400)
src/devkit-disks-daemon.c
src/devkit-disks-daemon.h
src/devkit-disks-device.c

index a12d5d7..3c195d5 100644 (file)
@@ -630,6 +630,12 @@ devkit_disks_daemon_local_find_by_object_path (DevkitDisksDaemon *daemon,
         return g_hash_table_lookup (daemon->priv->map_object_path_to_device, object_path);
 }
 
+GList *
+devkit_disks_daemon_local_get_all_devices (DevkitDisksDaemon *daemon)
+{
+        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)
 {
index 006cdd4..075ce81 100644 (file)
@@ -72,6 +72,8 @@ typedef struct DevkitDisksDevice DevkitDisksDevice;
 void               devkit_disks_daemon_inhibit_killtimer         (DevkitDisksDaemon       *daemon);
 void               devkit_disks_daemon_uninhibit_killtimer       (DevkitDisksDaemon       *daemon);
 void               devkit_disks_daemon_reset_killtimer           (DevkitDisksDaemon       *daemon);
+
+GList             *devkit_disks_daemon_local_get_all_devices     (DevkitDisksDaemon       *daemon);
 DevkitDisksDevice *devkit_disks_daemon_local_find_by_native_path (DevkitDisksDaemon       *daemon,
                                                                   const char              *native_path);
 DevkitDisksDevice *devkit_disks_daemon_local_find_by_object_path (DevkitDisksDaemon       *daemon,
index 832b764..da4db2b 100644 (file)
@@ -3098,12 +3098,30 @@ devkit_disks_device_create_partition_table (DevkitDisksDevice     *device,
         int m;
         char *argv[128];
         GError *error;
+        GList *l;
+        GList *devices;
         PolKitCaller *pk_caller;
 
+        devices = NULL;
+
         if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
                 goto out;
 
-        /* TODO: check that enclosed devices aren't busy or mounted */
+        /* check that enclosed devices aren't busy or mounted */
+        devices = devkit_disks_daemon_local_get_all_devices (device->priv->daemon);
+        for (l = devices; l != NULL; l = l->next) {
+                DevkitDisksDevice *d = DEVKIT_DISKS_DEVICE (l->data);
+                if (d->priv->info.device_is_partition &&
+                    d->priv->info.partition_slave != NULL &&
+                    strcmp (d->priv->info.partition_slave, device->priv->object_path) == 0) {
+                        if (d->priv->info.device_is_mounted) {
+                                throw_error (context, DEVKIT_DISKS_DEVICE_ERROR_MOUNTED,
+                                             "A partition on the device is mounted");
+                                goto out;
+                        }
+                        /* TODO: other checks (holders/slaves) */
+                }
+        }
 
         if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
                                                   pk_caller,
@@ -3149,6 +3167,7 @@ devkit_disks_device_create_partition_table (DevkitDisksDevice     *device,
         }
 
 out:
+        g_list_free (devices);
         if (pk_caller != NULL)
                 polkit_caller_unref (pk_caller);
         return TRUE;