Rename Block.CreateFilesystem to Block.Format
authorDavid Zeuthen <davidz@redhat.com>
Wed, 2 Nov 2011 15:32:34 +0000 (11:32 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 2 Nov 2011 15:32:34 +0000 (11:32 -0400)
... and other misc changes.

Signed-off-by: David Zeuthen <davidz@redhat.com>
data/org.freedesktop.UDisks2.xml
doc/udisks2-sections.txt
src/udisksdaemonutil.c
src/udisksdaemonutil.h
src/udiskslinuxblock.c

index c40fe5a..eabeef3 100644 (file)
     </method>
 
     <!--
-        CreateFilesystem:
-        @fstype: The type of file system to create. Pass <literal>empty</literal> to not create a file system and just clear the areas of the device known to host file system signatures.
+        Format:
+        @type: The type of file system or other content to format the device with.
         @options: Options - known options (in addition to <link linkend="udisks-std-options">standard options</link>) includes <parameter>label</parameter> (of type 's').
 
-        Create a file system on a device. You can specify a label with the
-        <parameter>label</parameter> option; however, this is not supported
-        with all file systems (in particular, not for <literal>minix</literal>
-        and <literal>empty</literal>).
+        Formats the device with a file system or other well-known content.
+
+        Known values for @type includes <constant>empty</constant> (to
+        just zero out areas of the device known to host file system
+        signatures) and <constant>swap</constant> (Linux swap space)
+        and most file systems supported by the <citerefentry><refentrytitle>mkfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+        program through its <option>-t</option> option.
+
+        If @type supports it, you can specify a label with the
+        <parameter>label</parameter> option in the @options parameter;
+        however, note that this may not be supported on all file
+        systems and, if supported, the maximum allowed length may
+        vary.
     -->
-    <method name="CreateFilesystem">
-      <arg name="fstype" direction="in" type="s"/>
+    <method name="Format">
+      <arg name="type" direction="in" type="s"/>
       <arg name="options" direction="in" type="a{sv}"/>
     </method>
 
index e08a1f8..a6fe2c4 100644 (file)
@@ -900,6 +900,10 @@ udisks_block_call_update_configuration_item
 udisks_block_call_update_configuration_item_finish
 udisks_block_call_update_configuration_item_sync
 udisks_block_complete_update_configuration_item
+udisks_block_call_format
+udisks_block_call_format_finish
+udisks_block_call_format_sync
+udisks_block_complete_format
 udisks_block_get_configuration
 udisks_block_get_crypto_backing_device
 udisks_block_get_device
index 029013c..6361065 100644 (file)
@@ -558,45 +558,3 @@ udisks_daemon_util_get_caller_uid_sync (UDisksDaemon            *daemon,
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
-
-/**
- * udev_trigger_uevent
- * @device: GUDevDevice to trigger the uevent on.
- * @event: Event name; usually "change", but can also be "add" or "remove".
- *
- * Trigger an uevent on the given device. This only works on Linux with udev.
- */
-void
-udev_trigger_uevent (GUdevDevice *device,
-                     const gchar *event)
-{
-  int fd;
-  int len;
-  gchar* path;
-
-  g_return_if_fail (device != NULL);
-  g_return_if_fail (event != NULL);
-
-  path = g_strconcat (g_udev_device_get_sysfs_path (device), "/uevent", NULL);
-  fd = open(path, O_WRONLY);
-  if (fd >= 0)
-    {
-      g_debug ("triggering %s uevent on %s", event, path);
-      len = strlen (event);
-      if (write (fd, event, len) != len)
-        g_warning ("short write for triggering a change uevent: %s", path);
-      close (fd);
-    }
-  else
-    {
-      g_warning ("cannot open %s for triggering a %s uevent: %s",
-                 path,
-                 event,
-                 strerror (errno));
-    }
-
-  g_free (path);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
index f1f5fdf..5e5ae6a 100644 (file)
@@ -57,9 +57,6 @@ gboolean udisks_daemon_util_get_caller_uid_sync (UDisksDaemon            *daemon
                                                  uid_t                   *out_uid,
                                                  GError                 **error);
 
-void udev_trigger_uevent (GUdevDevice *device,
-                          const gchar *event);
-
 G_END_DECLS
 
 #endif /* __UDISKS_DAEMON_UTIL_H__ */
index a603624..3016d12 100644 (file)
@@ -1625,10 +1625,10 @@ wait_for_filesystem (UDisksDaemon *daemon,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-handle_create_filesystem (UDisksBlock           *_block,
-                          GDBusMethodInvocation *invocation,
-                          const gchar           *fstype,
-                          GVariant              *options)
+handle_format (UDisksBlock           *_block,
+               GDBusMethodInvocation *invocation,
+               const gchar           *type,
+               GVariant              *options)
 {
   UDisksLinuxBlock *block = UDISKS_LINUX_BLOCK (_block);
   UDisksLinuxBlockObject *object;
@@ -1654,14 +1654,17 @@ handle_create_filesystem (UDisksBlock           *_block,
   if (udisks_block_get_hint_system (_block))
     action_id = "org.freedesktop.udisks2.modify-device-system";
 
-  fs_info = get_fs_info (fstype);
+  /* TODO: Consider just accepting any @type and just running "mkfs -t <type>".
+   *       There are some obvious security implications by doing this, though
+   */
+  fs_info = get_fs_info (type);
   if (fs_info == NULL || fs_info->command_create_fs == NULL)
     {
       g_dbus_method_invocation_return_error (invocation,
                    UDISKS_ERROR,
                    UDISKS_ERROR_NOT_SUPPORTED,
                    "Creation of file system type %s is not supported",
-                   fstype);
+                   type);
       goto out;
     }
 
@@ -1676,14 +1679,14 @@ handle_create_filesystem (UDisksBlock           *_block,
   /* evaluate options */
   if (g_variant_lookup (options, "label", "&s", &label))
     {
-      /* does the fs support labels? */
+      /* TODO: return an error if label is too long */
       if (strstr (fs_info->command_create_fs, "$LABEL") == NULL)
         {
           g_dbus_method_invocation_return_error (invocation,
                        UDISKS_ERROR,
                        UDISKS_ERROR_NOT_SUPPORTED,
                        "File system type %s does not support labels",
-                       fstype);
+                       type);
           goto out;
         }
 
@@ -1714,34 +1717,26 @@ handle_create_filesystem (UDisksBlock           *_block,
       goto out;
     }
 
-  /* FIXME: For some reason mkfs.ext4 does not trigger a change uevent when
-   * it's done, so udev and we miss the new file system. This _only_ happens
-   * when being called from here, it does work fine when being called from a
-   * terminal. Force an update to work around this. */
-  if (strcmp (fstype, "ext4") == 0)
-    {
-      GUdevDevice *device; 
-      device = udisks_linux_block_object_get_device (object);
-      if (device != NULL)
-        udev_trigger_uevent (device, "change");
-      g_object_unref (device);
-    }
+  /* The mkfs program may not generate all the uevents we need - so explicitly
+   * trigger an event here
+   */
+  udisks_linux_block_object_trigger_uevent (object);
 
   if (udisks_daemon_wait_for_object_sync (daemon,
                                           wait_for_filesystem,
-                                          (gpointer) fstype,
+                                          (gpointer) type,
                                           NULL,
                                           30,
                                           &error) == NULL)
     {
       g_prefix_error (&error,
                       "Error waiting for FileSystem interface after creating %s file system: ",
-                      fstype);
+                      type);
       g_dbus_method_invocation_take_error (invocation, error);
       goto out;
     }
 
-  udisks_block_complete_create_filesystem (UDISKS_BLOCK (block), invocation);
+  udisks_block_complete_format (UDISKS_BLOCK (block), invocation);
 
  out:
   g_free (escaped_label);
@@ -1758,5 +1753,5 @@ block_iface_init (UDisksBlockIface *iface)
   iface->handle_add_configuration_item    = handle_add_configuration_item;
   iface->handle_remove_configuration_item = handle_remove_configuration_item;
   iface->handle_update_configuration_item = handle_update_configuration_item;
-  iface->handle_create_filesystem         = handle_create_filesystem;
+  iface->handle_format                    = handle_format;
 }