From: David Zeuthen Date: Tue, 19 Jul 2011 18:27:08 +0000 (-0400) Subject: Rework UDISKS_* udev properties X-Git-Tag: upstream/2.1.2~480^2~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19b8eb210e96de7713a300b8dac591ddcf48be61;p=platform%2Fupstream%2Fudisks2.git Rework UDISKS_* udev properties Signed-off-by: David Zeuthen --- diff --git a/data/80-udisks2.rules b/data/80-udisks2.rules index 09438d7..14accc9 100644 --- a/data/80-udisks2.rules +++ b/data/80-udisks2.rules @@ -23,3 +23,6 @@ ENV{ID_VENDOR}=="*IOMEGA*", ENV{ID_MODEL}=="*ZIP*", ENV{ID_DRIVE_FLOPPY_ZIP}="1" KERNEL=="mmcblk[0-9]", SUBSYSTEMS=="mmc", ENV{DEVTYPE}=="disk", ENV{ID_DRIVE_FLASH_SD}="1", ENV{ID_DRIVE_MEDIA_FLASH_SD}="1" # ditto for memstick KERNEL=="mspblk[0-9]", SUBSYSTEMS=="memstick", ENV{DEVTYPE}=="disk", ENV{ID_DRIVE_FLASH_MS}="1", ENV{ID_DRIVE_MEDIA_FLASH_MS}="1" + +# TODO: maybe automatically convert udisks1 properties to udisks2 ones? +# (e.g. UDISKS_PRESENTATION_HIDE -> UDISKS_IGNORE) diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml index fdf36ab..ceb33be 100644 --- a/data/org.freedesktop.UDisks2.xml +++ b/data/org.freedesktop.UDisks2.xml @@ -272,6 +272,26 @@ --> + + + + + + + + + + + + + + + - - If set to 1 this is a hint to presentation - level software that the device should not be shown to the - user. - + + + + If set, this overrides the value of the + HintSystem property. + + - - - 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). - + + + + If set, this overrides the value of the + HintIgnore property. + + - - - If set to 1 this will disable the polling of drives - for media changes, for devices which do not send out media - notifications by themselves (this mostly affects CD drives). - Some CD drives cause bad effects such as very high CPU usage when - being polled. - + + + + If set, this overrides the value of the + HintAuto property. + + - - - The name to user for the device when - presenting it to the user. - + + + + The name to use for the device when presenting it in an user interface. + This corresponds to the + HintName property. + + - - - The icon to use when presenting the device to - the user. If set, the name must follow the freedesktop.org - icon theme specification. - + + + + The icon to use for the device when presenting it in an user interface. If + set, the name must adhere to the + freedesktop.org icon theme specification. + This corresponds to the + HintIconName property. + + + - The properties are used to describe what - kind of physical media can be used in a device. These are typically - set on the main block device (e.g. /dev/sdb) and - more than one these properties can be set if the device supports - multiple kinds of media. + For media and drive identification, the output of the probers + supplied by + udev7 + (such as cdrom_id, ata_id and + scsi_id) are used in addition to the + following properties: - - Whether the media in the drive is physically ejectable. Only - set this to 1 (or 0) if the drive truly uses (or doesn't) ejectable media. - In particular, it is not necessary to set this for e.g. iPod or Kindle - devices where it is necessary to send a command via - - eject1 - - since the desktop user session will offer this option for - removable devices regardless of whether they are - ejectable. If this property is not set, a heuristic will - be used to determine if the media is ejectable (drives - using optical, Zip or Jaz media are considered ejectable). - - - - - Whether the device is detachable. It is only meaningful - to set this to 0 (to avoid marking a device as detachable) since the - code for detaching the device is part of udisks itself. - If this property is not set, a heuristic will be used to determine if the - drive is detachable (currently only devices connected through USB are - detachable). - - - - - Whether the device can spin down. It is only meaningful - to set this to 0 (to avoid marking a device as being capable of spinning down) - since the code for spinning down the device is part of udisks itself. - If this property is not set, a heuristic will be used to determine if the - drive can spin down (currently only ATA devices, including those USB - devices with a SAT layer) can be spun down). - - - The device is compatible with flash. @@ -149,7 +124,12 @@ - The device is compatible with High-Capicity SecureDigital. + The device is compatible with High-Capacity SecureDigital. + + + + + The device is compatible with Extended-Capacity SecureDigital. @@ -172,15 +152,17 @@ The device is compatible with Jaz. - - The properties describe the - current media in a device. As with - the properties, these properties are - typically set on the main block device - (e.g. /dev/sdb). Typically only one of these - properties are set. + While the ID_DRIVE_* properties describe what + kind of media the drive accepts (more than one property can be + set) and correspond to the MediaCompatibility + property, the properties + describe the current media in a device (typically only one of + these properties are set) and correspond to the Media + property: @@ -210,7 +192,12 @@ - The physical media currently inserted into the device is High-Capicity SecureDigital. + The physical media currently inserted into the device is High-Capacity SecureDigital. + + + + + The physical media currently inserted into the device is Extended-Capacity SecureDigital. diff --git a/doc/udisks2-sections.txt b/doc/udisks2-sections.txt index 944bc7c..e6e2c8f 100644 --- a/doc/udisks2-sections.txt +++ b/doc/udisks2-sections.txt @@ -697,6 +697,11 @@ udisks_block_device_get_part_table_scheme udisks_block_device_get_preferred_device udisks_block_device_get_size udisks_block_device_get_symlinks +udisks_block_device_get_hint_system +udisks_block_device_get_hint_ignore +udisks_block_device_get_hint_auto +udisks_block_device_get_hint_name +udisks_block_device_get_hint_icon_name udisks_block_device_set_crypto_backing_device udisks_block_device_set_device udisks_block_device_set_drive @@ -723,6 +728,11 @@ udisks_block_device_set_part_table_scheme udisks_block_device_set_preferred_device udisks_block_device_set_size udisks_block_device_set_symlinks +udisks_block_device_set_hint_system +udisks_block_device_set_hint_ignore +udisks_block_device_set_hint_auto +udisks_block_device_set_hint_name +udisks_block_device_set_hint_icon_name UDisksBlockDeviceProxy UDisksBlockDeviceProxyClass udisks_block_device_proxy_new diff --git a/policy/org.freedesktop.udisks2.policy.in b/policy/org.freedesktop.udisks2.policy.in index 481139b..eeff1b2 100644 --- a/policy/org.freedesktop.udisks2.policy.in +++ b/policy/org.freedesktop.udisks2.policy.in @@ -20,6 +20,16 @@ + + <_description>Mount a filesystem on a system device + <_message>Authentication is required to mount the filesystem + + auth_admin + auth_admin + auth_admin_keep + + + <_description>Stop a device started by another user <_message>Authentication is required to unmount a filesystem mounted by another user @@ -41,6 +51,16 @@ + + <_description>Unlock an encrypted system device + <_message>Authentication is required to unlock an encrypted device + + auth_admin + auth_admin + yes + + + <_description>Lock an encrypted device unlocked by another user <_message>Authentication is required to lock an encrypted device unlocked by another user @@ -69,14 +89,13 @@ auth_admin auth_admin - auth_admin_keep + yes - - - <_description>Work with system devices - <_message>Authentication is work with system devices + + <_description>Modify a system device + <_message>Authentication is required to modify a device auth_admin auth_admin diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c index 4e4664f..ce8d164 100644 --- a/src/udisksdaemonutil.c +++ b/src/udisksdaemonutil.c @@ -326,8 +326,6 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, UDisksBlockDevice *block; gboolean auth_no_user_interaction; - /* TODO: also check for org.freedesktop.udisks2.system-devices (if applicable) */ - ret = FALSE; subject = NULL; details = NULL; diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c index 4050be2..4ed6119 100644 --- a/src/udiskslinuxblock.c +++ b/src/udiskslinuxblock.c @@ -379,8 +379,9 @@ block_device_connect (UDisksLinuxBlock *block) } static gchar * -find_drive (GDBusObjectManagerServer *object_manager, - GUdevDevice *block_device) +find_drive (GDBusObjectManagerServer *object_manager, + GUdevDevice *block_device, + UDisksDrive **out_drive) { const gchar *block_device_sysfs_path; gchar *ret; @@ -413,6 +414,8 @@ find_drive (GDBusObjectManagerServer *object_manager, drive_sysfs_path = g_udev_device_get_sysfs_path (drive_device); if (g_str_has_prefix (block_device_sysfs_path, drive_sysfs_path)) { + if (out_drive != NULL) + *out_drive = udisks_object_get_drive (UDISKS_OBJECT (object)); ret = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); g_list_foreach (drive_devices, (GFunc) g_object_unref, NULL); g_list_free (drive_devices); @@ -484,6 +487,71 @@ get_sysfs_attr (GUdevDevice *device, } static void +block_device_update_hints (UDisksLinuxBlock *block, + const gchar *uevent_action, + UDisksBlockDevice *iface, + const gchar *device_file, + UDisksDrive *drive) +{ + gboolean hint_system; + gboolean hint_ignore; + gboolean hint_auto; + const gchar *hint_name; + const gchar *hint_icon_name; + + /* very conservative defaults */ + hint_system = TRUE; + hint_ignore = FALSE; + hint_auto = FALSE; + hint_name = NULL; + hint_icon_name = NULL; + + /* Provide easy access to _only_ the following devices + * + * - anything connected via known local buses (e.g. USB or Firewire, MMC or MemoryStick) + * - any device with removable media + * + * Be careful when extending this list as we don't want to automount + * the world when (inadvertently) connecting to a SAN. + */ + if (drive != NULL) + { + const gchar *connection_bus; + gboolean removable; + connection_bus = udisks_drive_get_connection_bus (drive); + removable = udisks_drive_get_media_removable (drive); + if (removable || + (g_strcmp0 (connection_bus, "usb") == 0 || g_strcmp0 (connection_bus, "firewire") == 0) || + (g_str_has_prefix (device_file, "/dev/mmcblk") || g_str_has_prefix (device_file, "/dev/mspblk"))) + { + hint_system = FALSE; + hint_auto = TRUE; + } + } + + /* TODO: set ignore to TRUE for physical paths belonging to a drive with multiple paths */ + + /* override from udev properties */ + if (g_udev_device_has_property (block->device, "UDISKS_SYSTEM")) + hint_system = g_udev_device_get_property_as_boolean (block->device, "UDISKS_SYSTEM"); + if (g_udev_device_has_property (block->device, "UDISKS_IGNORE")) + hint_ignore = g_udev_device_get_property_as_boolean (block->device, "UDISKS_IGNORE"); + if (g_udev_device_has_property (block->device, "UDISKS_AUTO")) + hint_auto = g_udev_device_get_property_as_boolean (block->device, "UDISKS_AUTO"); + if (g_udev_device_has_property (block->device, "UDISKS_NAME")) + hint_name = g_udev_device_get_property (block->device, "UDISKS_NAME"); + if (g_udev_device_has_property (block->device, "UDISKS_ICON_NAME")) + hint_icon_name = g_udev_device_get_property (block->device, "UDISKS_ICON_NAME"); + + /* ... and scene! */ + udisks_block_device_set_hint_system (iface, hint_system); + udisks_block_device_set_hint_ignore (iface, hint_ignore); + udisks_block_device_set_hint_auto (iface, hint_auto); + udisks_block_device_set_hint_name (iface, hint_name); + udisks_block_device_set_hint_icon_name (iface, hint_icon_name); +} + +static void block_device_update (UDisksLinuxBlock *block, const gchar *uevent_action, GDBusInterface *_iface) @@ -492,6 +560,7 @@ block_device_update (UDisksLinuxBlock *block, GUdevDeviceNumber dev; GDBusObjectManagerServer *object_manager; gchar *drive_object_path; + UDisksDrive *drive; gchar *s; gboolean is_partition_table; gboolean is_partition_entry; @@ -499,6 +568,8 @@ block_device_update (UDisksLinuxBlock *block, const gchar *const *symlinks; const gchar *preferred_device_file; + drive = NULL; + dev = g_udev_device_get_device_number (block->device); device_file = g_udev_device_get_device_file (block->device); symlinks = g_udev_device_get_device_file_symlinks (block->device); @@ -616,7 +687,7 @@ block_device_update (UDisksLinuxBlock *block, * only do this once or something else */ object_manager = udisks_daemon_get_object_manager (block->daemon); - drive_object_path = find_drive (object_manager, block->device); + drive_object_path = find_drive (object_manager, block->device, &drive); if (drive_object_path != NULL) { udisks_block_device_set_drive (iface, drive_object_path); @@ -740,6 +811,11 @@ block_device_update (UDisksLinuxBlock *block, udisks_block_device_set_part_entry_offset (iface, 0); udisks_block_device_set_part_entry_size (iface, 0); } + + block_device_update_hints (block, uevent_action, iface, device_file, drive); + + if (drive != NULL) + g_object_unref (drive); } /* ---------------------------------------------------------------------------------------------------- */ diff --git a/src/udiskslinuxencrypted.c b/src/udiskslinuxencrypted.c index c89ec42..a10d5fa 100644 --- a/src/udiskslinuxencrypted.c +++ b/src/udiskslinuxencrypted.c @@ -141,6 +141,7 @@ handle_unlock (UDisksEncrypted *encrypted, GUdevDevice *udev_cleartext_device; GError *error; uid_t caller_uid; + const gchar *action_id; object = NULL; error_message = NULL; @@ -201,12 +202,13 @@ handle_unlock (UDisksEncrypted *encrypted, } /* Now, check that the user is actually authorized to unlock the device. - * - * TODO: want nicer authentication message + special treatment for system-internal */ + action_id = "org.freedesktop.udisks2.encrypted-unlock"; + if (udisks_block_device_get_hint_system (block)) + action_id = "org.freedesktop.udisks2.encrypted-unlock-system"; if (!udisks_daemon_util_check_authorization_sync (daemon, object, - "org.freedesktop.udisks2.encrypted-unlock", + action_id, options, N_("Authentication is required to unlock the encrypted device $(udisks2.device)"), invocation)) diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c index 01205b1..e14a64a 100644 --- a/src/udiskslinuxfilesystem.c +++ b/src/udiskslinuxfilesystem.c @@ -668,6 +668,7 @@ handle_mount (UDisksFilesystem *filesystem, gchar *escaped_mount_point_to_use; gchar *error_message; GError *error; + const gchar *action_id; object = NULL; error_message = NULL; @@ -773,12 +774,13 @@ handle_mount (UDisksFilesystem *filesystem, /* Now, check that the user is actually authorized to mount the * device. Need to do this before calculating a mount point since we * may be racing with other threads... - * - * TODO: want nicer authentication message + special treatment for system-internal */ + action_id = "org.freedesktop.udisks2.filesystem-mount"; + if (udisks_block_device_get_hint_system (block)) + action_id = "org.freedesktop.udisks2.filesystem-mount-system"; if (!udisks_daemon_util_check_authorization_sync (daemon, object, - "org.freedesktop.udisks2.filesystem-mount", + action_id, options, N_("Authentication is required to mount $(udisks2.device)"), invocation)) @@ -1122,6 +1124,7 @@ handle_set_label (UDisksFilesystem *filesystem, gboolean supports_online; UDisksBaseJob *job; gchar *escaped_label; + const gchar *action_id; object = NULL; daemon = NULL; @@ -1170,12 +1173,16 @@ handle_set_label (UDisksFilesystem *filesystem, } } + action_id = "org.freedesktop.udisks2.modify-device"; + if (udisks_block_device_get_hint_system (block)) + action_id = "org.freedesktop.udisks2.modify-device-system"; + /* Check that the user is actually authorized to change the * filesystem label. */ if (!udisks_daemon_util_check_authorization_sync (daemon, object, - "org.freedesktop.udisks2.modify-device", + action_id, options, N_("Authentication is required to change the filesystem label on $(udisks2.device)"), invocation))