Fixed mounting and unmounting of mapped storage devices.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/111/head
Michele Calgaro 4 years ago
parent 33794c4ec3
commit 9bc16841d1
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -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() {

@ -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

@ -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;
@ -1970,7 +1977,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") {
@ -2466,10 +2475,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;
@ -2485,7 +2504,6 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
TQString devicetypestring;
TQString devicetypestring_alt;
TQString devicepciclass;
TDEGenericDevice* device = existingdevice;
bool temp_udev_device = !dev;
devicename = device->name();
@ -2766,7 +2784,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) {
@ -2795,6 +2815,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;

@ -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);

@ -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();
}
@ -659,19 +679,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 ) ) {
@ -682,7 +689,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;

@ -193,6 +193,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
*/
@ -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;

Loading…
Cancel
Save