make umount work on mount points
authorMatthias Clasen <mclasen@redhat.com>
Mon, 30 Mar 2009 03:08:24 +0000 (23:08 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 30 Mar 2009 17:23:22 +0000 (13:23 -0400)
Make umount-devkit support the traditional umount behaviour of
accepting either a device file or a mount path.

Signed-off-by: David Zeuthen <davidz@redhat.com>
tools/umount-devkit.c

index bdce115..4d0ac03 100644 (file)
@@ -134,6 +134,8 @@ main (int argc, char **argv)
         DBusGProxy *disks_proxy;
         int ret;
         char *object_path;
+        struct stat st;
+        char *path;
 
         ret = 1;
         bus = NULL;
@@ -160,8 +162,21 @@ main (int argc, char **argv)
                                                  "org.freedesktop.DeviceKit.Disks");
 
         error = NULL;
+
+       if (stat (argv[1], &st) < 0) {
+                fprintf (stderr, "%s: could not stat %s: %s\n", argv[0], argv[1], strerror (errno));
+                goto out;
+        }
+
+        if (S_ISBLK (st.st_mode)) {
+                path = g_strdup (argv[1]);
+        }
+        else {
+                path = g_strdup_printf ("/dev/block/%d:%d", major (st.st_dev), minor (st.st_dev));
+        }
+
         if (!org_freedesktop_DeviceKit_Disks_find_device_by_device_file (disks_proxy,
-                                                                         argv[1],
+                                                                         path,
                                                                          &object_path,
                                                                          &error)) {
                 fprintf (stderr, "%s: no device for %s: %s\n", argv[0], argv[1], error->message);
@@ -172,6 +187,7 @@ main (int argc, char **argv)
         g_free (object_path);
 
 out:
+        g_free (path);
         if (disks_proxy != NULL)
                 g_object_unref (disks_proxy);
         if (bus != NULL)