Browse Source

Fixed mounting and unmounting of mapped storage devices.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
bug/2273/luks
Michele Calgaro 6 months ago
parent
commit
8a88f7ae9d
Signed by: MicheleC <michele.calgaro@yahoo.it> GPG Key ID: 2A75B7CA8ADED5CF
6 changed files with 70 additions and 27 deletions
  1. +2
    -2
      tdecore/tdehw/tdegenericdevice.cpp
  2. +1
    -1
      tdecore/tdehw/tdegenericdevice.h
  3. +31
    -6
      tdecore/tdehw/tdehardwaredevices.cpp
  4. +1
    -1
      tdecore/tdehw/tdehardwaredevices.h
  5. +23
    -16
      tdecore/tdehw/tdestoragedevice.cpp
  6. +12
    -1
      tdecore/tdehw/tdestoragedevice.h

+ 2
- 2
tdecore/tdehw/tdegenericdevice.cpp View File

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


+ 1
- 1
tdecore/tdehw/tdegenericdevice.h View File

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


+ 31
- 6
tdecore/tdehw/tdehardwaredevices.cpp View File

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


+ 1
- 1
tdecore/tdehw/tdehardwaredevices.h View File

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


+ 23
- 16
tdecore/tdehw/tdestoragedevice.cpp View File

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


+ 12
- 1
tdecore/tdehw/tdestoragedevice.h View File

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


Loading…
Cancel
Save