summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/tdestoragedevice.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2021-08-11 14:36:14 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2021-08-13 16:01:01 +0900
commitf159fa61a972641944adc614d33baf5e52ac5e0e (patch)
treea00705c6f65529f40f90f622ccd8cc4cb60f5c89 /tdecore/tdehw/tdestoragedevice.cpp
parentde4f27a2eea6f7b8e723dc8966a34ce1de0952d0 (diff)
downloadtdelibs-f159fa61a972641944adc614d33baf5e52ac5e0e.tar.gz
tdelibs-f159fa61a972641944adc614d33baf5e52ac5e0e.zip
tdehw lib: reworked device notifications to avoid repeated scanning of devices.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdecore/tdehw/tdestoragedevice.cpp')
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp115
1 files changed, 25 insertions, 90 deletions
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index 4e4d92c82..08fb246e1 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -71,7 +71,7 @@ TQString TDEStorageDevice::mappedName() {
return m_mappedName;
}
-void TDEStorageDevice::updateMappedName() {
+void TDEStorageDevice::internalUpdateMappedName() {
// Get the device mapped name if present
m_mappedName = TQString::null;
TQString dmnodename = systemPath();
@@ -329,20 +329,19 @@ TQStringVariantMap TDEStorageDevice::ejectDrive() {
TQStringVariantMap result;
TQStringVariantMap ejectResult;
+ // If the device is mounted, try unmounting it first
+ if (!mountPath().isEmpty()) {
+ unmountDevice();
+ }
+
#ifdef WITH_UDISKS2
if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
ejectResult = udisks2EjectDrive(this);
if (ejectResult["result"].toBool()) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = ejectResult["errStr"];
result["result"] = false;
return result;
@@ -353,16 +352,10 @@ TQStringVariantMap TDEStorageDevice::ejectDrive() {
if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) {
ejectResult = udisksEjectDrive(this);
if (ejectResult["result"].toBool()) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = ejectResult["errStr"];
result["result"] = false;
return result;
@@ -380,9 +373,6 @@ TQStringVariantMap TDEStorageDevice::ejectDrive() {
eject_output = ts.read();
int retcode = pclose(exepipe);
if (retcode == 0) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
@@ -393,9 +383,6 @@ TQStringVariantMap TDEStorageDevice::ejectDrive() {
}
}
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = false;
return result;
}
@@ -695,7 +682,13 @@ TQString TDEStorageDevice::deviceFriendlySize() {
return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
}
-TQString TDEStorageDevice::mountPath() {
+TQString TDEStorageDevice::mountPath()
+{
+ return m_mountPath;
+}
+
+void TDEStorageDevice::internalUpdateMountPath()
+{
// See if this device node is mounted
// This requires parsing /proc/mounts, looking for deviceNode()
@@ -703,8 +696,10 @@ TQString TDEStorageDevice::mountPath() {
// It likes to advertise mounts as /dev/mapper/<something>,
// where <something> is listed in <system path>/dm/name
- // First, ensure that all device information (mainly holders/slaves) is accurate
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
+ // Assumed all device information (mainly holders/slaves) is accurate
+ // prior to the call
+
+ m_mountPath = TQString::null;
TQStringList lines;
TQFile file( "/proc/mounts" );
@@ -717,30 +712,15 @@ TQString TDEStorageDevice::mountPath() {
TQString testNode = *mountInfo.at(0);
// Check for match
if ((testNode == deviceNode()) || (testNode == mappedName()) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
- TQString ret = *mountInfo.at(1);
- ret.replace("\\040", " ");
+ m_mountPath = *mountInfo.at(1);
+ m_mountPath.replace("\\040", " ");
file.close();
- return ret;
+ return;
}
lines += line;
}
file.close();
}
-
- // While this device is not directly mounted, it could concievably be mounted via the Device Mapper
- // If so, try to retrieve the mount path...
- TQStringList slaveDeviceList = holdingDevices();
- for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
- // Try to locate this device path in the TDE device tree
- TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
- TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
- if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
- TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
- return sdevice->mountPath();
- }
- }
-
- return TQString::null;
}
TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions) {
@@ -824,7 +804,6 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM
mountResult = udisks2MountDrive(devNode, fileSystemType, optionString);
if (mountResult["result"].toBool()) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["mountPath"] = mountPath();
result["result"] = true;
@@ -832,7 +811,6 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM
}
else if (mountResult["retcode"].toInt() == -1) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = mountResult["errStr"];
result["result"] = false;
@@ -846,7 +824,6 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM
mountResult = udisksMountDrive(devNode, fileSystemType, udisksOptions);
if (mountResult["result"].toBool()) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["mountPath"] = mountPath();
result["result"] = true;
@@ -854,7 +831,6 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM
}
else if (mountResult["retcode"].toInt() == -1) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = mountResult["errStr"];
result["result"] = false;
@@ -944,7 +920,6 @@ TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageM
}
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["mountPath"] = mountPath();
result["result"] = !mountPath().isEmpty();
@@ -955,13 +930,13 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
TQStringVariantMap result;
// Check if device is already unmounted
- TQString mountpoint = mountPath();
- if (mountpoint.isEmpty()) {
+ TQString mountpath = mountPath();
+ if (mountpath.isEmpty()) {
result["result"] = true;
return result;
}
- mountpoint.replace("'", "'\\''");
+ mountpath.replace("'", "'\\''");
TQString devNode = deviceNode();
TQString command = TQString::null;
TQStringVariantMap unmountResult;
@@ -971,14 +946,12 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
unmountResult = udisks2UnmountDrive(devNode, TQString::null);
if (unmountResult["result"].toBool()) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else if (unmountResult["retcode"].toInt() == -1) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = unmountResult["errStr"];
result["result"] = false;
@@ -992,14 +965,12 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
unmountResult = udisksUnmountDrive(devNode, TQStringList());
if (unmountResult["result"].toBool()) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else if (unmountResult["retcode"].toInt() == -1) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = unmountResult["errStr"];
result["result"] = false;
@@ -1011,13 +982,13 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
// The UDISKS v1 DBUS service was either not available or was unusable
// Use 'udevil' command, if available
if (!TDEGlobal::dirs()->findExe("udevil").isEmpty()) {
- command = TQString("udevil umount '%1' 2>&1").arg(mountpoint);
+ command = TQString("udevil umount '%1' 2>&1").arg(mountpath);
}
#endif
// If no other method was found, use 'pmount' command if available
if(command.isEmpty() && !TDEGlobal::dirs()->findExe("pumount").isEmpty()) {
- command = TQString("pumount '%1' 2>&1").arg(mountpoint);
+ command = TQString("pumount '%1' 2>&1").arg(mountpath);
}
if(command.isEmpty()) {
@@ -1034,7 +1005,6 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
int retcode = pclose(exepipe);
if (retcode == 0) {
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
@@ -1046,7 +1016,6 @@ TQStringVariantMap TDEStorageDevice::unmountDevice() {
}
// Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = false;
return result;
@@ -1056,14 +1025,6 @@ TQStringVariantMap TDEStorageDevice::unlockDevice(const TQString &passphrase)
{
TQStringVariantMap result;
- // Check if device is already mounted
- TQString mountpath = mountPath();
- if (!mountpath.isEmpty()) {
- result["unlockedDevice"] = mountpath;
- result["result"] = true;
- return result;
- }
-
TQString devNode = deviceNode();
devNode.replace("'", "'\\''");
@@ -1073,17 +1034,11 @@ TQStringVariantMap TDEStorageDevice::unlockDevice(const TQString &passphrase)
// Try to use UDISKS v2 via DBUS, if available
unlockResult = udisks2UnlockDrive(devNode, passphrase);
if (unlockResult["result"].toBool()) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["unlockedDevice"] = unlockResult["unlockedDevice"];
result["result"] = true;
return result;
}
else if (unlockResult["retcode"].toInt() == -1) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = unlockResult["errStr"];
result["result"] = false;
return result;
@@ -1114,9 +1069,6 @@ TQStringVariantMap TDEStorageDevice::unlockDevice(const TQString &passphrase)
delete ts;
int retcode = pclose(exepipe);
if (retcode == 0) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
}
else {
@@ -1138,14 +1090,6 @@ TQStringVariantMap TDEStorageDevice::lockDevice()
{
TQStringVariantMap result;
- // Check if device is mounted
- TQString mountpath = mountPath();
- if (!mountpath.isEmpty()) {
- result["errStr"] = i18n("The device is currently mounted and cannot be locked.");
- result["result"] = false;
- return result;
- }
-
TQString devNode = deviceNode();
devNode.replace("'", "'\\''");
@@ -1155,16 +1099,10 @@ TQStringVariantMap TDEStorageDevice::lockDevice()
// Try to use UDISKS v2 via DBUS, if available
lockResult = udisks2LockDrive(devNode);
if (lockResult["result"].toBool()) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else if (lockResult["retcode"].toInt() == -1) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = lockResult["errStr"];
result["result"] = false;
return result;
@@ -1181,9 +1119,6 @@ TQStringVariantMap TDEStorageDevice::lockDevice()
delete ts;
int retcode = pclose(exepipe);
if (retcode == 0) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
}
else {