[gparted] Switch to POSIX open() in useable_device() (!46)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Switch to POSIX open() in useable_device() (!46)
- Date: Thu, 18 Jul 2019 16:05:13 +0000 (UTC)
commit e5898e5813af7add0292495c6665cef87296a81b
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Wed Jul 10 10:49:43 2019 +0100
Switch to POSIX open() in useable_device() (!46)
For every device that GParted scans, it determines if it can be used by
attempting to read the first sector. This is the sequence of events,
as reported in the previous two commit messages:
gparted |set_devices_thread(pdevices) pdevices->["/dev/sdb"]
...
gparted | useable_device(lp_device) lp_device->path="/dev/sdb"
gparted | ped_device_open()
libparted | open("/dev/sdb", O_RDWR) = 8
gparted | ped_device_read()
gparted | ped_device_close()
libparted | close(8)
udev(async)| KERNEL change /devices/.../sdb (block)
...
udev(async)| UDEV change /devices/.../sdb (block)
Note that these udev block device change events occur before the ones
waited for in the first commit "Wait for udev change on /dev/DISK when
querying whole device FS (!46)" so these were already waited for.
So because libparted only opens devices read-write this triggers a set
of udev change events for the whole block device, and if the device is
partitioned, also remove and re-add events for all the partitions.
Switch to using POSIX open(), read() and close() calls so read-only
access can be specified to avoid the unnecessary udev change events.
Closes !46 - Whole device FAT32 file system reports device busy warning
from mlabel
src/GParted_Core.cc | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 88078d1d..44739c57 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -60,6 +60,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>
#include <glibmm/shell.h>
@@ -4051,12 +4052,12 @@ bool GParted_Core::useable_device( PedDevice * lp_device )
// Must be able to read from the first sector before the disk device is considered
// useable in GParted.
bool success = false;
- if ( ped_device_open( lp_device ) &&
- ped_device_read( lp_device, buf, 0, 1 ) )
+ int fd = open(lp_device->path, O_RDONLY|O_NONBLOCK);
+ if (fd >= 0)
{
- success = true;
-
- ped_device_close( lp_device );
+ ssize_t bytes_read = read(fd, buf, lp_device->sector_size);
+ success = (bytes_read == lp_device->sector_size);
+ close(fd);
}
free( buf );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]