summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-03-31 18:15:57 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-03-31 18:15:57 -0500
commit667932498f664c6f602fe5d0515434026cc0770d (patch)
treedbd0d0ce6f1e33805ef9facec0f20ce2404d9c57
parent9dff87031ae97e12b6b35e74b894b9af89f15975 (diff)
downloadtdelibs-66793249.tar.gz
tdelibs-66793249.zip
Add proper mount monitoring to TDE hardware library
The media kioslave backend based on this library can now mount/unmount simple flash drives
-rw-r--r--tdecore/tdehardwaredevices.cpp474
-rw-r--r--tdecore/tdehardwaredevices.h34
2 files changed, 350 insertions, 158 deletions
diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp
index 64809d474..b65ea199d 100644
--- a/tdecore/tdehardwaredevices.cpp
+++ b/tdecore/tdehardwaredevices.cpp
@@ -199,6 +199,10 @@ unsigned long TDEStorageDevice::deviceSize() {
blocksize = stream.readLine();
bsfile.close();
}
+ else {
+ // Drat, I can't get a gauranteed block size. Assume a block size of 512, as everything I have read indicates that /sys/block/<dev>/size is given in terms of a 512 byte block...
+ blocksize = "512";
+ }
TQString dsnodename = systemPath();
dsnodename.append("/size");
@@ -299,7 +303,12 @@ TQString TDEStorageDevice::mountPath() {
return TQString::null;
}
-TQString TDEStorageDevice::mountDevice(TQString mediaName) {
+TQString TDEStorageDevice::mountDevice(TQString mediaName, TQString mountOptions, TQString* errRet, int* retcode) {
+ int internal_retcode;
+ if (!retcode) {
+ retcode = &internal_retcode;
+ }
+
TQString ret = mountPath();
if (!ret.isNull()) {
@@ -310,19 +319,36 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName) {
KTempFile passwordFile(TQString::null, "tmp", 0600);
passwordFile.setAutoDelete(true);
- TQString command = TQString("pmount -p %1 %2").arg(passwordFile.name()).arg(deviceNode());
+ TQString command = TQString("pmount -p %1 %2 %3 2>&1").arg(passwordFile.name()).arg(mountOptions).arg(deviceNode());
if (!mediaName.isNull()) {
command.append(mediaName);
}
- if (system(command.ascii()) == 0) {
- ret = mountPath();
+ FILE *exepipe = popen(command.ascii(), "r");
+ if (exepipe) {
+ TQString pmount_output;
+ char buffer[8092];
+ pmount_output = fgets(buffer, sizeof(buffer), exepipe);
+ *retcode = pclose(exepipe);
+ if (*retcode == 0) {
+ ret = mountPath();
+ }
+ else {
+ if (errRet) {
+ *errRet = pmount_output;
+ }
+ }
}
return ret;
}
-TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName) {
+TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TQString mountOptions, TQString* errRet, int* retcode) {
+ int internal_retcode;
+ if (!retcode) {
+ retcode = &internal_retcode;
+ }
+
TQString ret = mountPath();
if (!ret.isNull()) {
@@ -340,28 +366,57 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
pwFile->writeBlock(passphrase.ascii(), passphrase.length());
pwFile->flush();
- TQString command = TQString("pmount -p %1 %2").arg(passwordFile.name()).arg(deviceNode());
+ TQString command = TQString("pmount -p %1 %2 %3 2>&1").arg(passwordFile.name()).arg(mountOptions).arg(deviceNode());
if (!mediaName.isNull()) {
command.append(mediaName);
}
- if (system(command.ascii()) == 0) {
- ret = mountPath();
+ FILE *exepipe = popen(command.ascii(), "r");
+ if (exepipe) {
+ TQString pmount_output;
+ char buffer[8092];
+ pmount_output = fgets(buffer, sizeof(buffer), exepipe);
+ *retcode = pclose(exepipe);
+ if (*retcode == 0) {
+ ret = mountPath();
+ }
+ else {
+ if (errRet) {
+ *errRet = pmount_output;
+ }
+ }
}
return ret;
}
-bool TDEStorageDevice::unmountDevice() {
+bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
+ int internal_retcode;
+ if (!retcode) {
+ retcode = &internal_retcode;
+ }
+
TQString mountpoint = mountPath();
if (mountpoint.isNull()) {
return true;
}
- TQString command = TQString("pumount %1").arg(mountpoint);
- if (system(command.ascii()) == 0) {
- return true;
+ TQString command = TQString("pumount %1 2>&1").arg(mountpoint);
+ FILE *exepipe = popen(command.ascii(), "r");
+ if (exepipe) {
+ TQString pmount_output;
+ char buffer[8092];
+ pmount_output = fgets(buffer, sizeof(buffer), exepipe);
+ *retcode = pclose(exepipe);
+ if (*retcode == 0) {
+ return true;
+ }
+ else {
+ if (errRet) {
+ *errRet = pmount_output;
+ }
+ }
}
return false;
@@ -386,6 +441,18 @@ TDEHardwareDevices::TDEHardwareDevices() {
m_devScanNotifier = new TQSocketNotifier(udev_monitor_get_fd(m_udevMonitorStruct), TQSocketNotifier::Read, this);
connect( m_devScanNotifier, TQT_SIGNAL(activated(int)), this, TQT_SLOT(processHotPluggedHardware()) );
+ // Read in the current mount table
+ // Yes, a race condition exists between this and the mount monitor start below, but it shouldn't be a problem 99.99% of the time
+ m_mountTable.clear();
+ TQFile file( "/proc/mounts" );
+ if ( file.open( IO_ReadOnly ) ) {
+ TQTextStream stream( &file );
+ while ( !stream.atEnd() ) {
+ m_mountTable.append(stream.readLine());
+ }
+ file.close();
+ }
+
// Monitor for changed mounts
m_procMountsFd = open("/proc/mounts", O_RDONLY, 0);
m_mountScanNotifier = new TQSocketNotifier(m_procMountsFd, TQSocketNotifier::Exception, this);
@@ -415,6 +482,17 @@ TDEGenericDevice* TDEHardwareDevices::findBySystemPath(TQString syspath) {
return 0;
}
+TDEGenericDevice* TDEHardwareDevices::findByDeviceNode(TQString devnode) {
+ TDEGenericDevice *hwdevice;
+ for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
+ if (hwdevice->deviceNode() == devnode) {
+ return hwdevice;
+ }
+ }
+
+ return 0;
+}
+
TDEStorageDevice* TDEHardwareDevices::findDiskByUID(TQString uid) {
TDEGenericDevice *hwdevice;
for ( hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next() ) {
@@ -448,7 +526,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
if (device) {
m_deviceList.append(device);
- emit hardwareAdded(*device);
+ emit hardwareAdded(device);
}
}
else if (actionevent == "remove") {
@@ -457,12 +535,24 @@ void TDEHardwareDevices::processHotPluggedHardware() {
TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) {
- emit hardwareRemoved(*hwdevice);
+ emit hardwareRemoved(hwdevice);
m_deviceList.remove(hwdevice);
break;
}
}
}
+ else if (actionevent == "change") {
+ // Update device and emit change event
+ TQString systempath(udev_device_get_syspath(dev));
+ TDEGenericDevice *hwdevice;
+ for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
+ if (hwdevice->systemPath() == systempath) {
+ classifyUnknownDevice(dev, hwdevice);
+// emit hardwareUpdated(hwdevice); // FIXME certain devices (***cough U3 system fake CD cough*** spam this quite badly, locking up anything monitoring hardwareUpdated()
+ break;
+ }
+ }
+ }
}
}
@@ -471,10 +561,213 @@ void TDEHardwareDevices::processModifiedMounts() {
// Detect what changed between the old mount table and the new one,
// and emit appropriate events
+ TQStringList deletedEntries = m_mountTable;
+
+ // Read in the new mount table
+ m_mountTable.clear();
+ TQFile file( "/proc/mounts" );
+ if ( file.open( IO_ReadOnly ) ) {
+ TQTextStream stream( &file );
+ while ( !stream.atEnd() ) {
+ m_mountTable.append(stream.readLine());
+ }
+ file.close();
+ }
+
+ TQStringList addedEntries = m_mountTable;
+
+ // Remove all entries that are identical in both tables
+ processModifiedMounts_removeagain:
+ for ( TQStringList::Iterator delit = deletedEntries.begin(); delit != deletedEntries.end(); ++delit ) {
+ for ( TQStringList::Iterator addit = addedEntries.begin(); addit != addedEntries.end(); ++addit ) {
+ if ((*delit) == (*addit)) {
+ deletedEntries.remove(delit);
+ addedEntries.remove(addit);
+ // Reset iterators to prevent bugs/crashes
+ // FIXME
+ // Is there any way to completely reset both loops without using goto?
+ goto processModifiedMounts_removeagain;
+ }
+ }
+ }
+
+ TQStringList::Iterator it;
+ for ( it = addedEntries.begin(); it != addedEntries.end(); ++it ) {
+ TQStringList mountInfo = TQStringList::split(" ", (*it), true);
+ // Try to find a device that matches the altered node
+ TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
+ if (hwdevice) {
+ emit hardwareUpdated(hwdevice);
+ // If the device is a storage device and has a slave, update it as well
+ if (hwdevice->type() == TDEGenericDeviceType::Disk) {
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+ TQStringList slavedevices = sdevice->slaveDevices();
+ for ( TQStringList::Iterator slaveit = addedEntries.begin(); slaveit != addedEntries.end(); ++slaveit ) {
+ TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
+ if (slavedevice) {
+ emit hardwareUpdated(slavedevice);
+ }
+ }
+ }
+ }
+ }
+ for ( it = deletedEntries.begin(); it != deletedEntries.end(); ++it ) {
+ TQStringList mountInfo = TQStringList::split(" ", (*it), true);
+ // Try to find a device that matches the altered node
+ TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
+ if (hwdevice) {
+ emit hardwareUpdated(hwdevice);
+ // If the device is a storage device and has a slave, update it as well
+ if (hwdevice->type() == TDEGenericDeviceType::Disk) {
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+ TQStringList slavedevices = sdevice->slaveDevices();
+ for ( TQStringList::Iterator slaveit = addedEntries.begin(); slaveit != addedEntries.end(); ++slaveit ) {
+ TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
+ if (slavedevice) {
+ emit hardwareUpdated(slavedevice);
+ }
+ }
+ }
+ }
+ }
+
emit mountTableModified();
}
-TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
+TDEDiskDeviceType::TDEDiskDeviceType classifyDiskType(udev_device* dev, const TQString &devicebus, const TQString &disktypestring, const TQString &systempath, const TQString &devicevendor, const TQString &devicemodel, const TQString &filesystemtype) {
+ // Classify a disk device type to the best of our ability
+ TDEDiskDeviceType::TDEDiskDeviceType disktype = (TDEDiskDeviceType::TDEDiskDeviceType)0;
+
+ if (devicebus.upper() == "USB") {
+ disktype = disktype | TDEDiskDeviceType::USB;
+ }
+
+ if (disktypestring.upper() == "ZIP") {
+ disktype = disktype | TDEDiskDeviceType::Zip;
+ }
+ if ((devicevendor.upper() == "IOMEGA") && (devicemodel.upper().contains("ZIP"))) {
+ disktype = disktype | TDEDiskDeviceType::Zip;
+ }
+
+ if ((devicevendor.upper() == "APPLE") && (devicemodel.upper().contains("IPOD"))) {
+ disktype = disktype | TDEDiskDeviceType::MediaDevice;
+ }
+ if ((devicevendor.upper() == "SANDISK") && (devicemodel.upper().contains("SANSA"))) {
+ disktype = disktype | TDEDiskDeviceType::MediaDevice;
+ }
+
+ if (disktypestring.upper() == "FLOPPY") {
+ disktype = disktype | TDEDiskDeviceType::Floppy;
+ }
+
+ if (disktypestring.upper() == "TAPE") {
+ disktype = disktype | TDEDiskDeviceType::Tape;
+ }
+
+ if (disktypestring.upper() == "COMPACT_FLASH") {
+ disktype = disktype | TDEDiskDeviceType::CompactFlash;
+ }
+
+ if (disktypestring.upper() == "MEMORY_STICK") {
+ disktype = disktype | TDEDiskDeviceType::MemoryStick;
+ }
+
+ if (disktypestring.upper() == "SMART_MEDIA") {
+ disktype = disktype | TDEDiskDeviceType::SmartMedia;
+ }
+
+ if (disktypestring.upper() == "SD_MMC") {
+ disktype = disktype | TDEDiskDeviceType::SDMMC;
+ }
+
+ if (disktypestring.upper() == "FLASHKEY") {
+ disktype = disktype | TDEDiskDeviceType::Flash;
+ }
+
+ if (disktypestring.upper() == "OPTICAL") {
+ disktype = disktype | TDEDiskDeviceType::Optical;
+ }
+
+ if (disktypestring.upper() == "JAZ") {
+ disktype = disktype | TDEDiskDeviceType::Jaz;
+ }
+
+ if (disktypestring.upper() == "DISK") {
+ disktype = disktype | TDEDiskDeviceType::HDD;
+ }
+ if (disktypestring.isNull()) {
+ // Fallback
+ // If we can't recognize the disk type then set it as a simple HDD volume
+ disktype = disktype | TDEDiskDeviceType::HDD;
+ }
+
+ if (disktypestring.upper() == "CD") {
+ if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA")) == "1") {
+ disktype = disktype | TDEDiskDeviceType::CDROM;
+ }
+ if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_CD_RW")) == "1") {
+ disktype = disktype | TDEDiskDeviceType::CDRW;
+ disktype = disktype & ~TDEDiskDeviceType::CDROM;
+ }
+ if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD")) == "1") {
+ disktype = disktype | TDEDiskDeviceType::DVDROM;
+ disktype = disktype & ~TDEDiskDeviceType::CDROM;
+ }
+ if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RAM")) == "1") {
+ disktype = disktype | TDEDiskDeviceType::DVDRAM;
+ disktype = disktype & ~TDEDiskDeviceType::DVDROM;
+ }
+ if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RW_DL")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) == "1")
+ ) {
+ disktype = disktype | TDEDiskDeviceType::DVDRW;
+ disktype = disktype & ~TDEDiskDeviceType::DVDROM;
+ }
+ if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD")) == "1") {
+ disktype = disktype | TDEDiskDeviceType::BDROM;
+ disktype = disktype & ~TDEDiskDeviceType::CDROM;
+ }
+ if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_RW_DL")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_PLUS_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_MINUS_RW")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) == "1")
+ || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) == "1")
+ ) {
+ disktype = disktype | TDEDiskDeviceType::BDRW;
+ disktype = disktype & ~TDEDiskDeviceType::BDROM;
+ }
+ if (!TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_TRACK_COUNT_AUDIO")).isNull()) {
+ disktype = disktype | TDEDiskDeviceType::CDAudio;
+ }
+ if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_VCD")) == "1") || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_SDVD")) == "1")) {
+ disktype = disktype | TDEDiskDeviceType::CDVideo;
+ }
+ }
+
+ // Detect RAM and Loop devices, since udev can't seem to...
+ if (systempath.startsWith("/sys/devices/virtual/block/ram")) {
+ disktype = disktype | TDEDiskDeviceType::RAM;
+ }
+ if (systempath.startsWith("/sys/devices/virtual/block/loop")) {
+ disktype = disktype | TDEDiskDeviceType::Loop;
+ }
+
+ if (filesystemtype.upper() == "CRYPTO_LUKS") {
+ disktype = disktype | TDEDiskDeviceType::LUKS;
+ }
+ else if (filesystemtype.upper() == "CRYPTO") {
+ disktype = disktype | TDEDiskDeviceType::OtherCrypted;
+ }
+
+ return disktype;
+}
+
+TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice) {
// Classify device and create TDEW device object
TQString devicename(udev_device_get_sysname(dev));
TQString devicetype(udev_device_get_devtype(dev));
@@ -483,7 +776,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
TQString devicenode(udev_device_get_devnode(dev));
TQString systempath(udev_device_get_syspath(dev));
bool removable = false;
- TDEGenericDevice* device = 0;
+ TDEGenericDevice* device = existingdevice;
// FIXME
// Only a small subset of devices are classified right now
@@ -542,7 +835,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
}
}
- device = new TDEStorageDevice(TDEGenericDeviceType::Disk);
+ if (!device) device = new TDEStorageDevice(TDEGenericDeviceType::Disk);
// Determine generic disk information
TQString devicevendor(udev_device_get_property_value(dev, "ID_VENDOR"));
@@ -565,119 +858,12 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
TDEDiskDeviceType::TDEDiskDeviceType disktype = (TDEDiskDeviceType::TDEDiskDeviceType)0;
TDEDiskDeviceStatus::TDEDiskDeviceStatus diskstatus = (TDEDiskDeviceStatus::TDEDiskDeviceStatus)0;
- if (devicebus.upper() == "USB") {
- disktype = disktype | TDEDiskDeviceType::USB;
- }
-
- if (disktypestring.upper() == "ZIP") {
- disktype = disktype | TDEDiskDeviceType::Zip;
- }
- if ((devicevendor.upper() == "IOMEGA") && (devicemodel.upper().contains("ZIP"))) {
- disktype = disktype | TDEDiskDeviceType::Zip;
- }
-
- if ((devicevendor.upper() == "APPLE") && (devicemodel.upper().contains("IPOD"))) {
- disktype = disktype | TDEDiskDeviceType::MediaDevice;
- }
- if ((devicevendor.upper() == "SANDISK") && (devicemodel.upper().contains("SANSA"))) {
- disktype = disktype | TDEDiskDeviceType::MediaDevice;
- }
-
- if (disktypestring.upper() == "FLOPPY") {
- disktype = disktype | TDEDiskDeviceType::Floppy;
- }
-
- if (disktypestring.upper() == "TAPE") {
- disktype = disktype | TDEDiskDeviceType::Tape;
- }
-
- if (disktypestring.upper() == "COMPACT_FLASH") {
- disktype = disktype | TDEDiskDeviceType::CompactFlash;
- }
-
- if (disktypestring.upper() == "MEMORY_STICK") {
- disktype = disktype | TDEDiskDeviceType::MemoryStick;
- }
-
- if (disktypestring.upper() == "SMART_MEDIA") {
- disktype = disktype | TDEDiskDeviceType::SmartMedia;
- }
-
- if (disktypestring.upper() == "SD_MMC") {
- disktype = disktype | TDEDiskDeviceType::SDMMC;
- }
-
- if (disktypestring.upper() == "FLASHKEY") {
- disktype = disktype | TDEDiskDeviceType::Flash;
- }
-
- if (disktypestring.upper() == "OPTICAL") {
- disktype = disktype | TDEDiskDeviceType::Optical;
- }
-
- if (disktypestring.upper() == "JAZ") {
- disktype = disktype | TDEDiskDeviceType::Jaz;
- }
-
- if (disktypestring.upper() == "DISK") {
- disktype = disktype | TDEDiskDeviceType::HDD;
- }
- if (disktypestring.isNull()) {
- // Fallback
- // If we can't recognize the disk type then set it as a simple HDD volume
- disktype = disktype | TDEDiskDeviceType::HDD;
- }
+ disktype = classifyDiskType(dev, devicebus, disktypestring, systempath, devicevendor, devicemodel, filesystemtype);
if (disktypestring.upper() == "CD") {
- if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA")) == "1") {
- disktype = disktype | TDEDiskDeviceType::CDROM;
- }
- if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_CD_RW")) == "1") {
- disktype = disktype | TDEDiskDeviceType::CDRW;
- disktype = disktype & ~TDEDiskDeviceType::CDROM;
- }
- if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD")) == "1") {
- disktype = disktype | TDEDiskDeviceType::DVDROM;
- disktype = disktype & ~TDEDiskDeviceType::CDROM;
- }
- if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RAM")) == "1") {
- disktype = disktype | TDEDiskDeviceType::DVDRAM;
- disktype = disktype & ~TDEDiskDeviceType::DVDROM;
- }
- if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_RW_DL")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) == "1")
- ) {
- disktype = disktype | TDEDiskDeviceType::DVDRW;
- disktype = disktype & ~TDEDiskDeviceType::DVDROM;
- }
- if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD")) == "1") {
- disktype = disktype | TDEDiskDeviceType::BDROM;
- disktype = disktype & ~TDEDiskDeviceType::CDROM;
- }
- if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_RW_DL")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_PLUS_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_BD_MINUS_RW")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_PLUS_RW_DL")) == "1")
- || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_DVD_MINUS_RW_DL")) == "1")
- ) {
- disktype = disktype | TDEDiskDeviceType::BDRW;
- disktype = disktype & ~TDEDiskDeviceType::BDROM;
- }
- if (!TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_TRACK_COUNT_AUDIO")).isNull()) {
- disktype = disktype | TDEDiskDeviceType::CDAudio;
- }
- if ((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_VCD")) == "1") || (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_SDVD")) == "1")) {
- disktype = disktype | TDEDiskDeviceType::CDVideo;
- }
if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_STATE")).upper() == "BLANK") {
diskstatus = diskstatus | TDEDiskDeviceStatus::Blank;
}
-
sdevice->setMediaInserted(!(TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA")) == "0"));
}
@@ -685,24 +871,10 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
diskstatus = diskstatus | TDEDiskDeviceStatus::Removable;
}
- if (filesystemtype.upper() == "CRYPTO_LUKS") {
- disktype = disktype | TDEDiskDeviceType::LUKS;
- }
- else if (filesystemtype.upper() == "CRYPTO") {
- disktype = disktype | TDEDiskDeviceType::OtherCrypted;
- }
- else if (!filesystemtype.isNull()) {
+ if ((filesystemtype.upper() != "CRYPTO_LUKS") && (filesystemtype.upper() != "CRYPTO") && (!filesystemtype.isNull())) {
diskstatus = diskstatus | TDEDiskDeviceStatus::ContainsFilesystem;
}
- // Detect RAM and Loop devices, since udev can't seem to...
- if (systempath.startsWith("/sys/devices/virtual/block/ram")) {
- disktype = disktype | TDEDiskDeviceType::RAM;
- }
- if (systempath.startsWith("/sys/devices/virtual/block/loop")) {
- disktype = disktype | TDEDiskDeviceType::Loop;
- }
-
// Set mountable flag if device is likely to be mountable
diskstatus = diskstatus | TDEDiskDeviceStatus::Mountable;
if ((!disktypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) {
@@ -732,6 +904,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
TQString slavediskfstype(udev_device_get_property_value(slavedev, "ID_FS_TYPE"));
if ((slavediskfstype.upper() == "CRYPTO_LUKS") || (slavediskfstype.upper() == "CRYPTO")) {
disktype = disktype | TDEDiskDeviceType::UnlockedCrypt;
+ // Set disk type based on parent device
+ disktype = disktype | classifyDiskType(slavedev, TQString(udev_device_get_property_value(dev, "ID_BUS")), TQString(udev_device_get_property_value(dev, "ID_TYPE")), (*slaveit), TQString(udev_device_get_property_value(dev, "ID_VENDOR")), TQString(udev_device_get_property_value(dev, "ID_MODEL")), TQString(udev_device_get_property_value(dev, "ID_FS_TYPE")));
}
udev_device_unref(slavedev);
}
@@ -768,56 +942,54 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
}
sdevice->setDiskLabel(disklabel);
-
- printf("DISK DEVICE name: %s type: %s subsystem: %s vendor: %s model: %s bus: %s label: %s filesystem: %s disk type: %s disk type flags: 0x%08x media inserted: %d [Node Path: %s] [Syspath: %s]\n\r\n\r", devicename.ascii(), devicetype.ascii(), devicesubsystem.ascii(), devicevendor.ascii(), devicemodel.ascii(), devicebus.ascii(), disklabel.ascii(), filesystemtype.ascii(), disktypestring.ascii(), disktype, sdevice->mediaInserted(), devicenode.ascii(), udev_device_get_syspath(dev)); fflush(stdout);
}
else if (devicetype.isNull()) {
if (devicesubsystem == "acpi") {
- device = new TDEGenericDevice(TDEGenericDeviceType::OtherACPI);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherACPI);
}
else if (devicesubsystem == "input") {
// Figure out if this device is a mouse, keyboard, or something else
// Check for mouse
// udev doesn't reliably help here, so guess from the device name
if (systempath.contains("/mouse")) {
- device = new TDEGenericDevice(TDEGenericDeviceType::Mouse);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Mouse);
}
if (!device) {
// Second mouse check
// Look for ID_INPUT_MOUSE property presence
if (udev_device_get_property_value(dev, "ID_INPUT_MOUSE") != 0) {
- device = new TDEGenericDevice(TDEGenericDeviceType::Mouse);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Mouse);
}
}
if (!device) {
// Check for keyboard
// Look for ID_INPUT_KEYBOARD property presence
if (udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD") != 0) {
- device = new TDEGenericDevice(TDEGenericDeviceType::Keyboard);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Keyboard);
}
}
if (!device) {
- device = new TDEGenericDevice(TDEGenericDeviceType::HID);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::HID);
}
}
else if (devicesubsystem == "tty") {
- device = new TDEGenericDevice(TDEGenericDeviceType::TextIO);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::TextIO);
}
else if (devicesubsystem == "thermal") {
// FIXME
// Figure out a way to differentiate between ThermalControl (fans and coolers) and ThermalSensor types
- device = new TDEGenericDevice(TDEGenericDeviceType::ThermalControl);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::ThermalControl);
}
else if (devicesubsystem == "hwmon") {
// FIXME
// This might pick up thermal sensors
- device = new TDEGenericDevice(TDEGenericDeviceType::OtherSensor);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::OtherSensor);
}
}
if (device == 0) {
// Unhandled
- device = new TDEGenericDevice(TDEGenericDeviceType::Other);
+ if (!device) device = new TDEGenericDevice(TDEGenericDeviceType::Other);
printf("[FIXME] UNCLASSIFIED DEVICE name: %s type: %s subsystem: %s driver: %s [Node Path: %s] [Syspath: %s]\n\r", devicename.ascii(), devicetype.ascii(), devicesubsystem.ascii(), devicedriver.ascii(), devicenode.ascii(), udev_device_get_syspath(dev)); fflush(stdout);
}
device->setName(devicename);
diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h
index 2b145b9e9..0da239663 100644
--- a/tdecore/tdehardwaredevices.h
+++ b/tdecore/tdehardwaredevices.h
@@ -369,25 +369,36 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
* Mounts the device if not encrypted
*
* @param a TQString containing a requested mount name under /media, if desired
+ * @param a TQString containing any mount options for pmount, if desired
+ * @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
+ * @param a pointer to an integer which will be populated with the return code from pmount, if desired
+ *
* @return a TQString with the mount path, if successful
*/
- TQString mountDevice(TQString mediaName=TQString::null);
+ TQString mountDevice(TQString mediaName=TQString::null, TQString mountOptions=TQString::null, TQString* errRet=0, int* retcode=0);
/**
* Mounts the encrypted device if the correct passphrase is given
*
* @param a TQString containing the passphrase
* @param a TQString containing a requested mount name under /media, if desired
+ * @param a TQString containing any mount options for pmount, if desired
+ * @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
+ * @param a pointer to an integer which will be populated with the return code from pmount, if desired
+ *
* @return a TQString with the mount path, if successful
*/
- TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null);
+ TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null, TQString mountOptions=TQString::null, TQString* errRet=0, int* retcode=0);
/**
* Unmounts the device
*
+ * @param a pointer to a TQString which will be populated with any error messages from pmount, if desired
+ * @param a pointer to an integer which will be populated with the return code from pmount, if desired
+ *
* @return TRUE if unmount was successful
*/
- bool unmountDevice();
+ bool unmountDevice(TQString* errRet, int* retcode=0);
/**
* @return a TQString with the mount path, if mounted
@@ -421,7 +432,7 @@ typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList;
class TQSocketNotifier;
-class TDECORE_EXPORT TDEHardwareDevices : TQObject
+class TDECORE_EXPORT TDEHardwareDevices : public TQObject
{
Q_OBJECT
@@ -461,14 +472,21 @@ class TDECORE_EXPORT TDEHardwareDevices : TQObject
TDEGenericDevice* findBySystemPath(TQString syspath);
/**
+ * Return the device with device node @arg devnode, or 0 if no device exists at that node
+ * @return TDEGenericDevice
+ */
+ TDEGenericDevice* findByDeviceNode(TQString devnode);
+
+ /**
* Return the storage device with unique ID @arg uid, or 0 if no device exists for that uid
* @return TDEGenericDevice
*/
TDEStorageDevice* findDiskByUID(TQString uid);
signals:
- void hardwareAdded(TDEGenericDevice);
- void hardwareRemoved(TDEGenericDevice);
+ void hardwareAdded(TDEGenericDevice*);
+ void hardwareRemoved(TDEGenericDevice*);
+ void hardwareUpdated(TDEGenericDevice*);
void mountTableModified();
private slots:
@@ -476,7 +494,7 @@ class TDECORE_EXPORT TDEHardwareDevices : TQObject
void processModifiedMounts();
private:
- TDEGenericDevice *classifyUnknownDevice(udev_device* dev);
+ TDEGenericDevice *classifyUnknownDevice(udev_device* dev, TDEGenericDevice* existingdevice=0);
struct udev *m_udevStruct;
struct udev_monitor *m_udevMonitorStruct;
@@ -485,6 +503,8 @@ class TDECORE_EXPORT TDEHardwareDevices : TQObject
TQSocketNotifier* m_devScanNotifier;
TQSocketNotifier* m_mountScanNotifier;
+
+ TQStringList m_mountTable;
};
#endif \ No newline at end of file