Branch: master

08d4e306 2014-12-05 00:31:10 Timothy Pearson
Do not flag disk devices/partitions as mountable if a partition table is present under the given device/partition
This relates to Bug 2232
M tdecore/tdehw/tdehardwaredevices.cpp
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index bbf266c..48fce75 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -311,7 +311,7 @@
 
 TDECPUDevice* TDEHardwareDevices::findCPUBySystemPath(TQString syspath, bool inCache=true) {
 	TDECPUDevice* cdevice;
-	
+
 	// Look for the device in the cache first
 	if(inCache && !m_cpuByPathCache.isEmpty()) {
 		cdevice = m_cpuByPathCache.find(syspath);
@@ -328,7 +328,7 @@
 		}
 		return cdevice;
 	}
-	
+
 	return 0;
 }
 
@@ -660,7 +660,7 @@
 #endif
 
 	TDECPUDevice* firstCPU = NULL;
-	
+
 	// Read in other information from cpufreq, if available
 	for (processorNumber=0; processorNumber<processorCount; processorNumber++) {
 		cdevice = dynamic_cast<TDECPUDevice*>(findCPUBySystemPath(TQString("/sys/devices/system/cpu/cpu%1").arg(processorNumber)));
@@ -860,7 +860,7 @@
 			emit hardwareEvent(TDEHardwareEvent::HardwareUpdated, hwdevice->uniqueID());
 		}
 	}
-	
+
 #ifdef CPUPROFILING
 	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
 	printf("TDEHardwareDevices::processModifiedCPUs() : end at %u [%u]\n", time2.tv_nsec, diff(time1,time2).tv_nsec);
@@ -1664,7 +1664,7 @@
 								match = false;
 							}
 						}
-		
+
 						if (match) {
 							rulesFile.setGroup("DeviceType");
 							TQString gentype = rulesFile.readEntry("GENTYPE");
@@ -1672,7 +1672,7 @@
 							if (!gentype.isNull()) {
 								desiredDeviceType = readGenericDeviceTypeFromString(gentype);
 							}
-		
+
 							// Handle main type
 							if (desiredDeviceType != device->type()) {
 								printf("[tdehardwaredevices] Rules file %s used to set device type for device at path %s\n", fi->absFilePath().ascii(), device->systemPath().ascii()); fflush(stdout);
@@ -1684,7 +1684,7 @@
 								}
 								device = createDeviceObjectForType(desiredDeviceType);
 							}
-	
+
 							// Parse subtype and store in m_externalSubtype for later
 							// This speeds things up considerably due to the expense of the file scanning/parsing/matching operation
 							device->m_externalSubtype = rulesFile.readListEntry("SUBTYPE", ',');
@@ -2407,7 +2407,7 @@
 		else {
 			bool removable = false;
 			bool hotpluggable = false;
-	
+
 			// We can get the removable flag, but we have no idea if the device has the ability to notify on media insertion/removal
 			// If there is no such notification possible, then we should not set the removable flag
 			// udev can be such an amazing pain at times
@@ -2434,7 +2434,7 @@
 			if (capabilities & GENHD_FL_MEDIA_CHANGE_NOTIFY) {
 				removable = true;
 			}
-	
+
 			// See if any other devices are exclusively using this device, such as the Device Mapper
 			TQStringList holdingDeviceNodes;
 			TQString holdersnodename = udev_device_get_syspath(dev);
@@ -2454,7 +2454,7 @@
 					++holdersdirit;
 				}
 			}
-	
+
 			// See if any other physical devices underlie this device, for example when the Device Mapper is in use
 			TQStringList slaveDeviceNodes;
 			TQString slavesnodename = udev_device_get_syspath(dev);
@@ -2474,25 +2474,25 @@
 					++slavedirit;
 				}
 			}
-	
+
 			// Determine generic disk information
 			TQString devicevendor(udev_device_get_property_value(dev, "ID_VENDOR"));
 			TQString devicemodel(udev_device_get_property_value(dev, "ID_MODEL"));
 			TQString devicebus(udev_device_get_property_value(dev, "ID_BUS"));
-	
+
 			// Get disk specific info
 			TQString disklabel(TQString::fromLocal8Bit(udev_device_get_property_value(dev, "ID_FS_LABEL")));
 			TQString diskuuid(udev_device_get_property_value(dev, "ID_FS_UUID"));
 			TQString filesystemtype(udev_device_get_property_value(dev, "ID_FS_TYPE"));
 			TQString filesystemusage(udev_device_get_property_value(dev, "ID_FS_USAGE"));
-	
+
 			device->internalSetVendorName(devicevendor);
 			device->internalSetVendorModel(devicemodel);
 			device->internalSetDeviceBus(devicebus);
-	
+
 			TDEDiskDeviceType::TDEDiskDeviceType disktype = sdevice->diskType();
 			TDEDiskDeviceStatus::TDEDiskDeviceStatus diskstatus = TDEDiskDeviceStatus::Null;
-	
+
 			disktype = classifyDiskType(dev, devicenode, devicebus, devicetypestring, systempath, devicevendor, devicemodel, filesystemtype, devicedriver);
 			sdevice->internalSetDiskType(disktype);
 			device = classifyUnknownDeviceByExternalRules(dev, device, true);	// Check external rules for possible subtype overrides
@@ -2501,7 +2501,7 @@
 			if (TQString(udev_device_get_property_value(dev, "UDISKS_IGNORE")) == "1") {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::Hidden;
 			}
-	
+
 			if ((disktype & TDEDiskDeviceType::CDROM)
 				|| (disktype & TDEDiskDeviceType::CDR)
 				|| (disktype & TDEDiskDeviceType::CDRW)
@@ -2532,7 +2532,7 @@
 				// These drives are guaranteed to be optical
 				disktype = disktype | TDEDiskDeviceType::Optical;
 			}
-	
+
 			if (disktype & TDEDiskDeviceType::Floppy) {
 				// Floppy drives don't work well under udev
 				// I have to look for the block device name manually
@@ -2552,7 +2552,7 @@
 						++floppyblkdirit;
 					}
 				}
-	
+
 				// Some interesting information can be gleaned from the CMOS type file
 				// 0 : Defaults
 				// 1 : 5 1/4 DD
@@ -2573,20 +2573,20 @@
 				}
 				// FIXME
 				// Do something with the information in cmosstring
-	
+
 				if (devicenode.isNull()) {
 					// This floppy drive cannot be mounted, so ignore it
 					disktype = disktype & ~TDEDiskDeviceType::Floppy;
 				}
 			}
-	
+
 			if (devicetypestring.upper() == "CD") {
 				if (TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA_STATE")).upper() == "BLANK") {
 					diskstatus = diskstatus | TDEDiskDeviceStatus::Blank;
 				}
 				sdevice->internalSetMediaInserted((TQString(udev_device_get_property_value(dev, "ID_CDROM_MEDIA")) != ""));
 			}
-	
+
 			if (disktype & TDEDiskDeviceType::Zip) {
 				// A Zip drive does not advertise its status via udev, but it can be guessed from the size parameter
 				TQString zipnodename = systempath;
@@ -2602,18 +2602,18 @@
 					sdevice->internalSetMediaInserted((zipsize.toInt() != 0));
 				}
 			}
-	
+
 			if (removable) {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::Removable;
 			}
 			if (hotpluggable) {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::Hotpluggable;
 			}
-	
+
 			if ((filesystemtype.upper() != "CRYPTO_LUKS") && (filesystemtype.upper() != "CRYPTO") && (filesystemtype.upper() != "SWAP") && (!filesystemtype.isNull())) {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::ContainsFilesystem;
 			}
-	
+
 			// Set mountable flag if device is likely to be mountable
 			diskstatus = diskstatus | TDEDiskDeviceStatus::Mountable;
 			if ((devicetypestring.upper().isNull()) && (disktype & TDEDiskDeviceType::HDD)) {
@@ -2631,21 +2631,25 @@
 			if (filesystemtype.upper() == "SWAP") {
 				diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
 			}
+			// Partition tables cannot be mounted
+			if (TQString(udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")) != "") {
+				diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
+			}
 			// If certain disk types do not report the presence of a filesystem, they are likely not mountable
 			if ((disktype & TDEDiskDeviceType::HDD) || (disktype & TDEDiskDeviceType::Optical)) {
 				if (!(diskstatus & TDEDiskDeviceStatus::ContainsFilesystem)) {
 					diskstatus = diskstatus & ~TDEDiskDeviceStatus::Mountable;
 				}
 			}
-	
+
 			if (holdingDeviceNodes.count() > 0) {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::UsedByDevice;
 			}
-	
+
 			if (slaveDeviceNodes.count() > 0) {
 				diskstatus = diskstatus | TDEDiskDeviceStatus::UsesDevice;
 			}
-	
+
 			// See if any slaves were crypted
 			for ( TQStringList::Iterator slaveit = slaveDeviceNodes.begin(); slaveit != slaveDeviceNodes.end(); ++slaveit ) {
 				struct udev_device *slavedev;
@@ -2658,7 +2662,7 @@
 				}
 				udev_device_unref(slavedev);
 			}
-	
+
 			sdevice->internalSetDiskType(disktype);
 			sdevice->internalSetDiskUUID(diskuuid);
 			sdevice->internalSetDiskStatus(diskstatus);
@@ -2666,7 +2670,7 @@
 			sdevice->internalSetFileSystemUsage(filesystemusage);
 			sdevice->internalSetSlaveDevices(slaveDeviceNodes);
 			sdevice->internalSetHoldingDevices(holdingDeviceNodes);
-	
+
 			// Clean up disk label
 			if ((sdevice->isDiskOfType(TDEDiskDeviceType::CDROM))
 				|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDR))
@@ -2705,7 +2709,7 @@
 					}
 				}
 			}
-	
 ** Diff limit reached (max: 250 lines) **
f0d26a3a 2014-12-05 00:32:13 Timothy Pearson
Merge branch 'master' of https://scm.trinitydesktop.org/scm/git/tdelibs
M admin
 ** Diff limit reached (max: 250 lines) **