From 840e65088b1bc1ad1f60602c2448dede6195f7f4 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Sun, 22 Feb 2009 19:00:40 -0500 Subject: [PATCH] allow changing the label on a mounted device if the filesystem supports it --- src/devkit-disks-daemon.c | 36 +++++++++++++++++++----------------- src/devkit-disks-daemon.h | 20 ++++++++++++++++++++ src/devkit-disks-device.c | 25 ++++++++++++++----------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/devkit-disks-daemon.c b/src/devkit-disks-daemon.c index 7e9efef..106c8d4 100644 --- a/src/devkit-disks-daemon.c +++ b/src/devkit-disks-daemon.c @@ -297,23 +297,6 @@ devkit_disks_daemon_constructor (GType type, G_TYPE_BOOLEAN, \ G_TYPE_INVALID)) -typedef struct { - const char *id; - const char *name; - gboolean supports_unix_owners; - gboolean can_mount; - gboolean can_create; - guint max_label_len; - gboolean supports_label_rename; - gboolean supports_online_label_rename; - gboolean supports_fsck; - gboolean supports_online_fsck; - gboolean supports_resize_enlarge; - gboolean supports_online_resize_enlarge; - gboolean supports_resize_shrink; - gboolean supports_online_resize_shrink; -} DevkitDisksFilesystem; - static const DevkitDisksFilesystem known_file_systems[] = { { "vfat", /* id */ @@ -415,6 +398,25 @@ static const DevkitDisksFilesystem known_file_systems[] = { static const int num_known_file_systems = sizeof (known_file_systems) / sizeof (DevkitDisksFilesystem); +const DevkitDisksFilesystem * +devkit_disks_daemon_local_get_fs_details (DevkitDisksDaemon *daemon, + const gchar *filesystem_id) +{ + gint n; + const DevkitDisksFilesystem *ret; + + ret = NULL; + + for (n = 0; n < num_known_file_systems; n++) { + if (strcmp (known_file_systems[n].id, filesystem_id) == 0) { + ret = &known_file_systems[n]; + break; + } + } + + return ret; +} + static GPtrArray * get_known_filesystems (DevkitDisksDaemon *daemon) { diff --git a/src/devkit-disks-daemon.h b/src/devkit-disks-daemon.h index fd66ef1..e4f6ce6 100644 --- a/src/devkit-disks-daemon.h +++ b/src/devkit-disks-daemon.h @@ -118,6 +118,26 @@ gboolean devkit_disks_daemon_local_has_polling_inhibitors (DevkitDisks DevkitDisksLogger *devkit_disks_daemon_local_get_logger (DevkitDisksDaemon *daemon); +typedef struct { + const char *id; + const char *name; + gboolean supports_unix_owners; + gboolean can_mount; + gboolean can_create; + guint max_label_len; + gboolean supports_label_rename; + gboolean supports_online_label_rename; + gboolean supports_fsck; + gboolean supports_online_fsck; + gboolean supports_resize_enlarge; + gboolean supports_online_resize_enlarge; + gboolean supports_resize_shrink; + gboolean supports_online_resize_shrink; +} DevkitDisksFilesystem; + +const DevkitDisksFilesystem *devkit_disks_daemon_local_get_fs_details (DevkitDisksDaemon *daemon, + const gchar *filesystem_id); + /* exported methods */ gboolean devkit_disks_daemon_enumerate_devices (DevkitDisksDaemon *daemon, diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index d96c05a..a104c1a 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -6650,20 +6650,11 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice *device, char *argv[10]; GError *error; PolKitCaller *pk_caller; + const DevkitDisksFilesystem *fs_details; if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL) goto out; - /* TODO: some file systems can do this while mounted; we need something similar - * to GduCreatableFilesystem cf. gdu-util.h - */ - - if (devkit_disks_device_local_is_busy (device)) { - throw_error (context, DEVKIT_DISKS_ERROR_BUSY, - "Device is busy"); - goto out; - } - if (device->priv->info.id_usage == NULL || strcmp (device->priv->info.id_usage, "filesystem") != 0) { throw_error (context, DEVKIT_DISKS_ERROR_NOT_LABELED, @@ -6671,7 +6662,19 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice *device, goto out; } - /* TODO: check if the fs support labels at all */ + fs_details = devkit_disks_daemon_local_get_fs_details (device->priv->daemon, + device->priv->info.id_type); + if (fs_details == NULL) { + throw_error (context, DEVKIT_DISKS_ERROR_BUSY, "Unknown filesystem"); + goto out; + } + + if (!fs_details->supports_online_label_rename) { + if (devkit_disks_device_local_is_busy (device)) { + throw_error (context, DEVKIT_DISKS_ERROR_BUSY, "Device is busy"); + goto out; + } + } if (!devkit_disks_damon_local_check_auth (device->priv->daemon, pk_caller, -- 2.7.4