</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>
}
/* ---------------------------------------------------------------------------------------------------- */
-
-/**
- * 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);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
/* ---------------------------------------------------------------------------------------------------- */
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;
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;
}
/* 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;
}
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);
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;
}