use the 'ro' sysfs file to figure out if media is read-only
authorDavid Zeuthen <davidz@redhat.com>
Thu, 19 Feb 2009 17:59:44 +0000 (12:59 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 19 Feb 2009 17:59:44 +0000 (12:59 -0500)
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

index f153fde..6e2c5f8 100644 (file)
@@ -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;