summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2019-08-17 19:15:19 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-10-14 22:59:59 +0900
commit8a88f7ae9d4aa8d0162f4504ec682943220f7d82 (patch)
tree1278f25aa0a1d83d6970908ffb68071e261fa873
parent0bb81e4791a3a68567b280fa8f01d913db29cf40 (diff)
downloadtdelibs-bug/2273/luks.tar.gz
tdelibs-bug/2273/luks.zip
Fixed mounting and unmounting of mapped storage devices.bug/2273/luks
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdecore/tdehw/tdegenericdevice.cpp4
-rw-r--r--tdecore/tdehw/tdegenericdevice.h2
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp37
-rw-r--r--tdecore/tdehw/tdehardwaredevices.h2
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp39
-rw-r--r--tdecore/tdehw/tdestoragedevice.h13
6 files changed, 70 insertions, 27 deletions
diff --git a/tdecore/tdehw/tdegenericdevice.cpp b/tdecore/tdehw/tdegenericdevice.cpp
index 8662e5e8..e9a645cf 100644
--- a/tdecore/tdehw/tdegenericdevice.cpp
+++ b/tdecore/tdehw/tdegenericdevice.cpp
@@ -91,8 +91,8 @@ TQString TDEGenericDevice::deviceNode() {
return m_deviceNode;
}
-void TDEGenericDevice::internalSetDeviceNode(TQString sn) {
- m_deviceNode = sn;
+void TDEGenericDevice::internalSetDeviceNode(TQString dn) {
+ m_deviceNode = dn;
}
TQString TDEGenericDevice::deviceBus() {
diff --git a/tdecore/tdehw/tdegenericdevice.h b/tdecore/tdehw/tdegenericdevice.h
index 7536b44a..91e9ac79 100644
--- a/tdecore/tdehw/tdegenericdevice.h
+++ b/tdecore/tdehw/tdegenericdevice.h
@@ -231,7 +231,7 @@ class TDECORE_EXPORT TDEGenericDevice : public TQObject
*
* This method is non-portable, so be careful!
*/
- void internalSetDeviceNode(TQString sn);
+ void internalSetDeviceNode(TQString dn);
/**
* @param bl true if this device has been blacklisted for update actions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index f4fc0cf1..14567d39 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -348,6 +348,13 @@ TDEGenericDevice* TDEHardwareDevices::findByDeviceNode(TQString devnode) {
if (hwdevice->deviceNode() == devnode) {
return hwdevice;
}
+ // For storage devices, check also against the mapped name
+ TDEStorageDevice *sdevice = dynamic_cast<TDEStorageDevice*>(hwdevice);
+ if (sdevice) {
+ if (sdevice->mappedName() == devnode) {
+ return sdevice;
+ }
+ }
}
return 0;
@@ -368,11 +375,11 @@ TDEStorageDevice* TDEHardwareDevices::findDiskByUID(TQString uid) {
}
void TDEHardwareDevices::processHotPluggedHardware() {
- udev_device* dev = udev_monitor_receive_device(m_udevMonitorStruct);
+ udev_device *dev = udev_monitor_receive_device(m_udevMonitorStruct);
if (dev) {
TQString actionevent(udev_device_get_action(dev));
if (actionevent == "add") {
- TDEGenericDevice* device = classifyUnknownDevice(dev);
+ TDEGenericDevice *device = classifyUnknownDevice(dev);
// Make sure this device is not a duplicate
TDEGenericDevice *hwdevice;
@@ -1967,7 +1974,9 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
|| (devicesubsystem == "scsi_tape"))
&& ((devicenode != "")
)) {
- if (!device) device = new TDEStorageDevice(TDEGenericDeviceType::Disk);
+ if (!device) {
+ device = new TDEStorageDevice(TDEGenericDeviceType::Disk);
+ }
}
else if (devicetype == "host") {
if (devicesubsystem == "bluetooth") {
@@ -2462,10 +2471,20 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
udev_device_unref(dev);
}
+ // Get the device mapped name if present
+ TDEStorageDevice *sdevice = dynamic_cast<TDEStorageDevice*>(device);
+ if (sdevice) {
+ sdevice->updateMappedName();
+ }
+
return device;
}
-void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* existingdevice, udev_device* dev) {
+void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice *device, udev_device *dev) {
+ if (!device) {
+ return;
+ }
+
TQString devicename;
TQString devicetype;
TQString devicedriver;
@@ -2481,7 +2500,6 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
TQString devicetypestring;
TQString devicetypestring_alt;
TQString devicepciclass;
- TDEGenericDevice* device = existingdevice;
bool temp_udev_device = !dev;
devicename = device->name();
@@ -2762,7 +2780,9 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
// Set mountable flag if device is likely to be mountable
diskstatus = diskstatus | TDEDiskDeviceStatus::Mountable;
- if ((devicetypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) {
+ if (devicetypestring.upper().isNull() && devicetypestring_alt.upper().isNull() && (disktype & TDEDiskDeviceType::HDD)) {
+ // For mapped devices, ID_TYPE may be missing, so need to check the alternative device
+ // type string too. For example for LUKS disk, ID_TYPE is null and DEVTYPE is "disk"
diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
}
if (removable) {
@@ -2791,6 +2811,11 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
}
}
+ // Encrypted or RAID disks are not mountable
+ if (filesystemtype.upper() == "CRYPTO_LUKS" || filesystemtype.upper() == "CRYPTO" ||
+ filesystemusage.upper() == "RAID") {
+ diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
+ }
if (holdingDeviceNodes.count() > 0) {
diskstatus = diskstatus | TDEDiskDeviceStatus::UsedByDevice;
diff --git a/tdecore/tdehw/tdehardwaredevices.h b/tdecore/tdehw/tdehardwaredevices.h
index 7f27681f..6d9b63ea 100644
--- a/tdecore/tdehw/tdehardwaredevices.h
+++ b/tdecore/tdehw/tdehardwaredevices.h
@@ -274,7 +274,7 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject
private:
TDEGenericDevice *classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice=0, bool force_full_classification=true);
TDEGenericDevice *classifyUnknownDeviceByExternalRules(udev_device* dev, TDEGenericDevice* existingdevice=0, bool classifySubDevices=false);
- void updateExistingDeviceInformation(TDEGenericDevice* existingdevice, udev_device* dev=NULL);
+ void updateExistingDeviceInformation(TDEGenericDevice *device, udev_device *dev=NULL);
void updateParentDeviceInformation();
void updateParentDeviceInformation(TDEGenericDevice* hwdevice);
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index 7d29942b..29d5c048 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -69,6 +69,26 @@ TDEStorageDevice::~TDEStorageDevice() {
#endif
}
+TQString TDEStorageDevice::mappedName() {
+ return m_mappedName;
+}
+
+void TDEStorageDevice::updateMappedName() {
+ // Get the device mapped name if present
+ m_mappedName = TQString::null;
+ TQString dmnodename = systemPath();
+ dmnodename.append("/dm/name");
+ TQFile dmnamefile(dmnodename);
+ if (dmnamefile.open(IO_ReadOnly)) {
+ TQTextStream stream(&dmnamefile);
+ m_mappedName = stream.readLine();
+ dmnamefile.close();
+ }
+ if (!m_mappedName.isEmpty()) {
+ m_mappedName.prepend("/dev/mapper/");
+ }
+}
+
TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
return m_diskType;
}
@@ -266,8 +286,8 @@ TQString TDEStorageDevice::cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::TDELUK
}
}
-void TDEStorageDevice::internalSetDeviceNode(TQString sn) {
- TDEGenericDevice::internalSetDeviceNode(sn);
+void TDEStorageDevice::internalSetDeviceNode(TQString dn) {
+ TDEGenericDevice::internalSetDeviceNode(dn);
internalInitializeLUKSIfNeeded();
}
@@ -655,19 +675,6 @@ TQString TDEStorageDevice::mountPath() {
// First, ensure that all device information (mainly holders/slaves) is accurate
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
- TQString dmnodename = systemPath();
- dmnodename.append("/dm/name");
- TQFile namefile( dmnodename );
- TQString dmaltname;
- if ( namefile.open( IO_ReadOnly ) ) {
- TQTextStream stream( &namefile );
- dmaltname = stream.readLine();
- namefile.close();
- }
- if (!dmaltname.isNull()) {
- dmaltname.prepend("/dev/mapper/");
- }
-
TQStringList lines;
TQFile file( "/proc/mounts" );
if ( file.open( IO_ReadOnly ) ) {
@@ -678,7 +685,7 @@ TQString TDEStorageDevice::mountPath() {
TQStringList mountInfo = TQStringList::split(" ", line, true);
TQString testNode = *mountInfo.at(0);
// Check for match
- if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
+ if ((testNode == deviceNode()) || (testNode == mappedName()) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
TQString ret = *mountInfo.at(1);
ret.replace("\\040", " ");
return ret;
diff --git a/tdecore/tdehw/tdestoragedevice.h b/tdecore/tdehw/tdestoragedevice.h
index 88991315..47ea4deb 100644
--- a/tdecore/tdehw/tdestoragedevice.h
+++ b/tdecore/tdehw/tdestoragedevice.h
@@ -194,6 +194,16 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
TQString diskUUID();
/**
+ * @return a TQString with the device mapped name, if any
+ */
+ TQString mappedName();
+
+ /**
+ * Find and store the alternative mapped name of a mapped device
+ */
+ void updateMappedName();
+
+ /**
* @return an OR-ed combination of TDEDiskDeviceType::TDEDiskDeviceType type flags
*/
TDEDiskDeviceType::TDEDiskDeviceType diskType();
@@ -425,7 +435,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
*
* This method is non-portable, so be careful!
*/
- void internalSetDeviceNode(TQString sn);
+ void internalSetDeviceNode(TQString dn);
/**
* @param a TQString with the disk or partition label, if any
@@ -492,6 +502,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
void internalGetLUKSKeySlotStatus();
private:
+ TQString m_mappedName; // Alternative name for a mapped device
TDEDiskDeviceType::TDEDiskDeviceType m_diskType;
TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus;
TQString m_diskName;