From 5307b199d186272ca87ec855861a58a94a2daac3 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 17 Aug 2009 10:50:36 -0400 Subject: [PATCH] Add a new :device-presentation-nopolicy property Desktops should read this property and avoid automounting etc. if it is set to 1. --- data/95-devkit-disks.rules | 15 ++++++++++++++- data/org.freedesktop.DeviceKit.Disks.Device.xml | 6 ++++++ doc/man/DeviceKit-disks.xml | 8 ++++++++ src/devkit-disks-device-private.c | 10 ++++++++++ src/devkit-disks-device-private.h | 2 ++ src/devkit-disks-device.c | 14 ++++++++++++++ tools/devkit-disks.c | 4 ++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/data/95-devkit-disks.rules b/data/95-devkit-disks.rules index c071f18..526ab05 100644 --- a/data/95-devkit-disks.rules +++ b/data/95-devkit-disks.rules @@ -1,3 +1,5 @@ +# Do not edit this file, it will be overwritten on updates +# # we only care about block devices ACTION!="add|change", GOTO="devkit_disks_end" @@ -108,7 +110,8 @@ ENV{ID_VENDOR}=="*IOMEGA*", ENV{ID_MODEL}=="*ZIP*", ENV{ID_DRIVE_FLOPPY_ZIP}="1" ############################################################################################################## -# partitions which desktops should not display +# Partitions which desktops should not display +# # Apple Bootstrap partitions ENV{DKD_PARTITION_SCHEME}=="apm", ENV{DKD_PARTITION_TYPE}=="Apple_Bootstrap", ENV{DKD_PRESENTATION_HIDE}="1" @@ -130,6 +133,16 @@ ENV{ID_FS_TYPE}=="ntfs|vfat", \ ENV{ID_FS_LABEL}=="RECOVERY|HP_RECOVERY|Recovery Partition|DellUtility|DellRestore|IBM_SERVICE|SERVICEV001|SERVICEV002", \ ENV{DKD_PRESENTATION_HIDE}="1" +############################################################################################################## + +# Mark devices that shouldn't be automounted / autoassembled etc. +# +# Deny all, then punch holes for what looks like physical drives +# (TODO: this heuristic might need some work) +# + +ENV{DKD_PRESENTATION_NOPOLICY}="1" +KERNEL=="sd*|hd*|sr*", ENV{DKD_PRESENTATION_NOPOLICY}="0" ############################################################################################################## diff --git a/data/org.freedesktop.DeviceKit.Disks.Device.xml b/data/org.freedesktop.DeviceKit.Disks.Device.xml index a96a236..dbb4d63 100644 --- a/data/org.freedesktop.DeviceKit.Disks.Device.xml +++ b/data/org.freedesktop.DeviceKit.Disks.Device.xml @@ -1549,6 +1549,12 @@ A hint if the device should be hidden from the user interface. + + + A hint if the device (or e.g. the multi-disk device that the device is + part of) shouldn't be automatically mounted / assembled. + + The name to use when presenting the device to an end user. diff --git a/doc/man/DeviceKit-disks.xml b/doc/man/DeviceKit-disks.xml index 3dba0e4..c53f88d 100644 --- a/doc/man/DeviceKit-disks.xml +++ b/doc/man/DeviceKit-disks.xml @@ -43,6 +43,14 @@ + + If set to 1 this is a hint to presentation + level software that the device should not be automounted + or autoassembled (for e.g. components of a multi-disk device). + + + + The name to user for the device when presenting it to the user. diff --git a/src/devkit-disks-device-private.c b/src/devkit-disks-device-private.c index 4c1bcb9..6f4a063 100644 --- a/src/devkit-disks-device-private.c +++ b/src/devkit-disks-device-private.c @@ -422,6 +422,16 @@ devkit_disks_device_set_device_presentation_hide (DevkitDisksDevice *device, gbo } void +devkit_disks_device_set_device_presentation_nopolicy (DevkitDisksDevice *device, gboolean value) +{ + if (G_UNLIKELY (device->priv->device_presentation_nopolicy != value)) + { + device->priv->device_presentation_nopolicy = value; + emit_changed (device, "device_presentation_nopolicy"); + } +} + +void devkit_disks_device_set_device_presentation_name (DevkitDisksDevice *device, const gchar *value) { if (G_UNLIKELY (g_strcmp0 (device->priv->device_presentation_name, value) != 0)) diff --git a/src/devkit-disks-device-private.h b/src/devkit-disks-device-private.h index cb7d4c6..def26e7 100644 --- a/src/devkit-disks-device-private.h +++ b/src/devkit-disks-device-private.h @@ -144,6 +144,7 @@ struct DevkitDisksDevicePrivate GPtrArray *device_mount_paths; uid_t device_mounted_by_uid; gboolean device_presentation_hide; + gboolean device_presentation_nopolicy; char *device_presentation_name; char *device_presentation_icon_name; @@ -276,6 +277,7 @@ void devkit_disks_device_set_device_is_mounted (DevkitDisksDevice *device, gbool void devkit_disks_device_set_device_mount_paths (DevkitDisksDevice *device, GStrv value); void devkit_disks_device_set_device_mounted_by_uid (DevkitDisksDevice *device, guint value); void devkit_disks_device_set_device_presentation_hide (DevkitDisksDevice *device, gboolean value); +void devkit_disks_device_set_device_presentation_nopolicy (DevkitDisksDevice *device, gboolean value); void devkit_disks_device_set_device_presentation_name (DevkitDisksDevice *device, const gchar *value); void devkit_disks_device_set_device_presentation_icon_name (DevkitDisksDevice *device, const gchar *value); diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index 8ce9b14..6d58c1d 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -166,6 +166,7 @@ enum PROP_DEVICE_MOUNT_PATHS, PROP_DEVICE_MOUNTED_BY_UID, PROP_DEVICE_PRESENTATION_HIDE, + PROP_DEVICE_PRESENTATION_NOPOLICY, PROP_DEVICE_PRESENTATION_NAME, PROP_DEVICE_PRESENTATION_ICON_NAME, @@ -393,6 +394,9 @@ get_property (GObject *object, case PROP_DEVICE_PRESENTATION_HIDE: g_value_set_boolean (value, device->priv->device_presentation_hide); break; + case PROP_DEVICE_PRESENTATION_NOPOLICY: + g_value_set_boolean (value, device->priv->device_presentation_nopolicy); + break; case PROP_DEVICE_PRESENTATION_NAME: g_value_set_string (value, device->priv->device_presentation_name); break; @@ -840,6 +844,10 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass) g_param_spec_boolean ("device-presentation-hide", NULL, NULL, FALSE, G_PARAM_READABLE)); g_object_class_install_property ( object_class, + PROP_DEVICE_PRESENTATION_NOPOLICY, + g_param_spec_boolean ("device-presentation-nopolicy", NULL, NULL, FALSE, G_PARAM_READABLE)); + g_object_class_install_property ( + object_class, PROP_DEVICE_PRESENTATION_NAME, g_param_spec_string ("device-presentation-name", NULL, NULL, NULL, G_PARAM_READABLE)); g_object_class_install_property ( @@ -1700,12 +1708,18 @@ static gboolean update_info_presentation (DevkitDisksDevice *device) { gboolean hide; + gboolean nopolicy; hide = FALSE; if (g_udev_device_has_property (device->priv->d, "DKD_PRESENTATION_HIDE")) hide = g_udev_device_get_property_as_boolean (device->priv->d, "DKD_PRESENTATION_HIDE"); devkit_disks_device_set_device_presentation_hide (device, hide); + nopolicy = FALSE; + if (g_udev_device_has_property (device->priv->d, "DKD_PRESENTATION_NOPOLICY")) + nopolicy = g_udev_device_get_property_as_boolean (device->priv->d, "DKD_PRESENTATION_NOPOLICY"); + devkit_disks_device_set_device_presentation_nopolicy (device, nopolicy); + devkit_disks_device_set_device_presentation_name (device, g_udev_device_get_property (device->priv->d, "DKD_PRESENTATION_NAME")); diff --git a/tools/devkit-disks.c b/tools/devkit-disks.c index 1073e82..08aad96 100644 --- a/tools/devkit-disks.c +++ b/tools/devkit-disks.c @@ -341,6 +341,7 @@ typedef struct char **device_mount_paths; uid_t device_mounted_by_uid; gboolean device_presentation_hide; + gboolean device_presentation_nopolicy; char *device_presentation_name; char *device_presentation_icon_name; guint64 device_size; @@ -502,6 +503,8 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props) props->device_mounted_by_uid = g_value_get_uint (value); else if (strcmp (key, "device-presentation-hide") == 0) props->device_presentation_hide = g_value_get_boolean (value); + else if (strcmp (key, "device-presentation-nopolicy") == 0) + props->device_presentation_nopolicy = g_value_get_boolean (value); else if (strcmp (key, "device-presentation-name") == 0) props->device_presentation_name = g_strdup (g_value_get_string (value)); else if (strcmp (key, "device-presentation-icon-name") == 0) @@ -1000,6 +1003,7 @@ do_show_info (const char *object_path) g_print ("\n"); g_print (" mounted by uid: %d\n", props->device_mounted_by_uid); g_print (" presentation hide: %d\n", props->device_presentation_hide); + g_print (" presentation nopolicy: %d\n", props->device_presentation_nopolicy); g_print (" presentation name: %s\n", props->device_presentation_name); g_print (" presentation icon: %s\n", props->device_presentation_icon_name); g_print (" size: %" G_GUINT64_FORMAT "\n", props->device_size); -- 2.7.4