[PC-BSD Commits] r18625 - pcbsd/current/src-qt4/pc-mounttray

svn at pcbsd.org svn at pcbsd.org
Mon Aug 27 11:25:40 PDT 2012


Author: kenmoore
Date: 2012-08-27 18:25:39 +0000 (Mon, 27 Aug 2012)
New Revision: 18625

Modified:
   pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
   pcbsd/current/src-qt4/pc-mounttray/mountTray.h
Log:
Add additional device filesystem management. Set it to try mount_auto if filesystem was not detected, and also add additional list checking before any addition/removal of devices to make sure to avoid any segmentation faults.



Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2012-08-27 17:06:43 UTC (rev 18624)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2012-08-27 18:25:39 UTC (rev 18625)
@@ -64,11 +64,11 @@
     
   }else if(ident==2){
     //Device mounted
-    trayIcon->showMessage( tr("Device Mounted"), tr("Device ")+"\""+device->text()+"\""+tr(" has been mounted at ")+MOUNTDIR+device->text(), QSystemTrayIcon::NoIcon,3000 );
+    trayIcon->showMessage( tr("Device Mounted"), tr("Device")+" \""+device->text()+"\" "+tr("has been mounted at")+" "+MOUNTDIR+device->text(), QSystemTrayIcon::NoIcon,3000 );
     
   }else if(ident==3){
     //Device unmounted
-    trayIcon->showMessage( tr("Device Unmounted"), tr("Device ")+"\""+device->text()+"\""+tr(" may now be safely removed"), QSystemTrayIcon::NoIcon,3000 );
+    trayIcon->showMessage( tr("Device Unmounted"), tr("Device")+" \""+device->text()+"\" "+tr("may now be safely removed"), QSystemTrayIcon::NoIcon,3000 );
     
   }else if(ident==4){
     //Device disconnected
@@ -110,6 +110,11 @@
   QString dev = deviceLocation.section("/",-1);
   newdev->setWhatsThis(deviceLocation);
 
+  //Shortcut for junk actions (to speed up list searches)
+  if(type == "JUNK"){
+    return newdev;	  
+  }
+  
   //Don't run "file" command on certain devices that are known non-storage devices
   if(dev.startsWith("pcm") || dev.startsWith("tty") ){
     return newdev;
@@ -147,7 +152,7 @@
   //If the filesystem could not be detected or is not supported
   if(filesys.isEmpty()){
     filesys = "UNKNOWN"; 
-    return newdev;
+    //return newdev;
   }
 
   //Set the Device type and file system type
@@ -289,9 +294,10 @@
   else if(fstypedet == "REISERFS"){ fstype = "mount -t reiserfs"; }
   else if(fstypedet == "XFS"){ fstype = "mount -t xfs"; }
   else{
-    qDebug() << "Unknown device filesystem:" << dev << fstype;
-    QMessageBox::warning(this,tr("Unknown Device Filesystem"),tr("The filesystem on this device is unknown and cannot be mounted at this time") );
-    return FALSE;
+    qDebug() << "Unknown device filesystem:" << dev << fstypedet << " attempting mount_auto command";
+    fstype = "mount_auto";
+    //QMessageBox::warning(this,tr("Unknown Device Filesystem"),tr("The filesystem on this device is unknown and cannot be mounted at this time") );
+    //return FALSE;
   }
   
   QString cmd1 = "mkdir " + mntpoint;
@@ -511,26 +517,31 @@
       //qDebug() << line;
       QString type = line.section("type=",1,1).section(" ",0,0).simplified();
       cdev = line.section("cdev=",1,1).section(" ",0,0).simplified();
-      if(type=="CREATE"){isAttached=TRUE;}
-      //Parse out cdev to try and only get a single handle for each device
-      if(!cdev.contains("/") && !cdev.contains("pass") ){
-       cdev.prepend("/dev/");
-        if( QFile::symLinkTarget(cdev).isEmpty() && isAttached && QFile::exists(cdev) ){
-          deviceFound=TRUE;
-          cdevtype="USB";
+      //Only recognize certain device types (mass storage devices)
+      if(cdev.startsWith("da")){  cdevtype="USB"; }
+      else if(cdev.startsWith("ad")){ cdevtype="SATA"; }
+      else if(cdev.startsWith("cd") || cdev.startsWith("acd")){ cdevtype="CD9660"; }
+      else{ cdevtype.clear(); }
+      //If device is recognized - make sure it is also valid
+      if( !cdevtype.isEmpty() ){
+        if(type=="CREATE"){ isAttached=TRUE; }
+        //Simple check to make sure that a couple types of devices are never used
+        if(!cdev.contains("/") && !cdev.contains("pass") ){
+          cdev.prepend("/dev/");
+          if( QFile::symLinkTarget(cdev).isEmpty() && isAttached && QFile::exists(cdev) ){
+            deviceFound=TRUE;
+          }
+          else if(!isAttached){
+            //Find out if this device is on the list of currently connected devices
+  	    if( findDeviceInList(newDeviceAction(cdev,"JUNK"))!=-1 ){ deviceFound=TRUE; }
+          }
         }
-        else if(!isAttached){
-          //Find out if this device is on the list of currently connected devices
-  	  if( findDeviceInList(newDeviceAction(cdev))!=-1 ){
-	    deviceFound=TRUE;
-	    cdevtype="USB";
-	  }
-        }
-      }
+      } // end cdevtype device check
     }
     //Perform action if a device is found
     if(deviceFound){
       QAction* newdev = newDeviceAction(cdev,cdevtype);
+      checkDevices(); // this will remove any stale device links
       if(isAttached){
         qDebug() << "New device detected:" << newdev->text() << newdev->whatsThis() << newdev->statusTip();
 	if( !newdev->statusTip().isEmpty() ){ //make sure the device is valid
@@ -543,9 +554,6 @@
 	}
       }else{
         qDebug() << "Device removal detected:" <<  newdev->whatsThis();
-        if( updateDeviceList( 4 , newdev ) ){
-          showDeviceNotification(4,newdev);
-        }
       }
       //Update the Tray menu
       updateTrayMenu();
@@ -554,6 +562,8 @@
 }
 
 void MountTray::menuDeviceToggled(QAction* currentAct){
+  //Make sure that the device list is current
+  checkDevices();
   //Get the parent action (parentAct->submenu->currentAct)
   //qDebug() << currentAct->whatsThis();
   QAction* device = newDeviceAction( currentAct->whatsThis() );
@@ -752,3 +762,12 @@
 
 }
 
+void MountTray::checkDevices(){
+  for(int i=0; i<devList.length(); i++){
+    if( !isConnected(devList[i]) ){
+      //Remove the dead device link from the action list
+      updateDeviceList(4,devList[i]);
+      i--; //make sure we account for the new size of the list
+    }
+  }
+}

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.h
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2012-08-27 17:06:43 UTC (rev 18624)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.h	2012-08-27 18:25:39 UTC (rev 18625)
@@ -59,4 +59,5 @@
   void setAutoMount(QAction*, bool);
   bool isAutoMountEnabled(QAction*);
   void setSubMenu(QAction*);
+  void checkDevices();
 };



More information about the Commits mailing list