From c12836915e0226adc1ac8597363069aaadfb4ac9 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Thu, 19 Feb 2009 12:59:44 -0500 Subject: [PATCH] use the 'ro' sysfs file to figure out if media is read-only This way we can avoid opening the device for writes. Because if we do open the device for writes, we going to cause an endless loop of 'change' events with udev >= 138. --- src/devkit-disks-device.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index f153fde..6e2c5f8 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -2363,19 +2363,7 @@ update_info (DevkitDisksDevice *device) * * (e.g. write-protect on SD cards, optical drives etc.) */ - errno = 0; - fd = open (device->priv->info.device_file, O_WRONLY|O_NONBLOCK); - if (fd < 0) { - if (errno == EROFS) { - device->priv->info.device_is_read_only = TRUE; - } else { - g_warning ("Cannot determine if %s is read only: %m", device->priv->info.device_file); - goto out; - } - } else { - close (fd); - } - + device->priv->info.device_is_read_only = (sysfs_get_int (device->priv->native_path, "ro") != 0); } device->priv->info.device_block_size = block_size; -- 2.7.4