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

svn at pcbsd.org svn at pcbsd.org
Mon Jan 28 08:44:46 PST 2013


Author: kenmoore
Date: 2013-01-28 16:44:45 +0000 (Mon, 28 Jan 2013)
New Revision: 21212

Modified:
   pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
   pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
Log:
Clean up the pc-mounttray detection algorithm. Now group the detection routines into a couple groups, "critical" where a single failure will result in the device being ignored, and everything else where passing 2 out of 3 of the checks is good enough to show the device.



Modified: pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-01-28 16:38:27 UTC (rev 21211)
+++ pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2013-01-28 16:44:45 UTC (rev 21212)
@@ -137,15 +137,20 @@
   
   // ** Get the max storage size **
   QStringList tmp = output.split(",");
-  int kb;
+  int kb = 0;
+  bool hasPartitions = FALSE; 
+  bool isMounted = FALSE;
   //qDebug() << "tmp:" << tmp;
   if( !tmp.filter("partition ").isEmpty() ){
-    kb = 0; //Do not recognize the base harddrive if there are partitions on it
-    type->clear(); //disable the flag for output
-  }else if( !tmp.filter("last mounted on /").isEmpty() ){
-    kb = 0; //Do not recognize partitions that are currently mounted
-    type->clear(); //disable the type flag for output
-  }else if( !tmp.filter("number of data blocks").isEmpty() ){
+    //Find out if the partitions are available as seperate devices
+    QString pdev = dev + "s1";
+    if( QFile::exists(pdev)){ hasPartitions = TRUE; }
+  }
+  if( !tmp.filter("last mounted on /").isEmpty() ){
+    isMounted = TRUE;
+  }
+  //Now try to get the size of the disk
+  if( !tmp.filter("number of data blocks").isEmpty() ){
     tmp = tmp.filter("number of data blocks");
     kb = tmp[0].remove("number of data blocks").simplified().toInt();
   }else if( !tmp.filter("number of blocks").isEmpty() ){
@@ -164,11 +169,11 @@
     }
     kb = num;
   }else{ kb = -1; }
-  maxsize->append( QString::number(kb) );
-  
+  bool oksize = (kb > 0);
   // ** Get the device label **
   //Get the device label if there is one using glabel
   QString dlabel;
+  bool hasLabel = FALSE;
   QString shortDev = dev.section("/",-1);
     QString glout = Utils::runShellCommandSearch("glabel status "+shortDev, shortDev);
     if(!glout.contains("No such geom:")){
@@ -177,17 +182,18 @@
       QString lab = entries[0].simplified();
       //save the device label
       dlabel = lab.section("/",-1);
+      hasLabel = TRUE;
     }
   //Alternate method to get the device label using the "file -s" output
   if(dlabel.isEmpty()){
     dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
+    if( !dlabel.isEmpty() ) { hasLabel = TRUE; }
   }
   //qDebug() <<"Detected Size:"<<kb<<"Label:"<<dlabel;
-  //Set the Device Name/label
+  //Assign a Name/Label for the device
   if(dlabel.isEmpty()){
-    dlabel = *type+"-Device";
+    dlabel = *type+"-Device"; //this is not a "detected" label
   }
-  label->append(dlabel);
   
   // - trim the label out of the output line for filesystem type detection
   QString devFSsec = output.section("label:",0,0);
@@ -204,10 +210,27 @@
     }
   }
   //If the filesystem could not be detected or is not supported
-  if(filesys.isEmpty()){ filesys = "UNKNOWN"; }
-  //save the filesystem type
-  filesystem->append(filesys);
+  bool hasFS = TRUE;
+  if(filesys.isEmpty()){ filesys = "UNKNOWN"; hasFS=FALSE; }
   
+  //Now perform the final checks to see if it is a good device
+  bool good = FALSE;
+  if( isMounted ){}//Always ignore this device (local FreeBSD installation that is being used)
+  else if( hasPartitions ){} //Ignore devices that have partitions accessible as seperate devices
+  //Allow devices that match 2 of the 3 criteria
+  else if( hasFS && oksize ){ good = TRUE; } //This will catch most good devices
+  else if( hasLabel && oksize ){ good = TRUE; } //allow unknown filesystems if there is a good size reading
+  else if( hasFS && hasLabel ){ good = TRUE; } // allow device if it has a known label and filesystem
+  
+  //Now setup the outputs as appropriate
+  if(good){
+    maxsize->append( QString::number(kb) );
+    label->append(dlabel);
+    filesystem->append(filesys);
+  }else{
+    qDebug() << "Ignoring Device:" << node << detType << dlabel << filesys << kb; 
+    qDebug() << " -Detected Flags:" << isMounted << hasPartitions << hasLabel << hasFS << oksize; 
+  }
 
 }
 

Modified: pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-01-28 16:38:27 UTC (rev 21211)
+++ pcbsd/current/src-qt4/pc-mounttray/mountTray.cpp	2013-01-28 16:44:45 UTC (rev 21212)
@@ -100,15 +100,9 @@
   for(int i=0; i<allDevs.length(); i++){
     //Run it through the device info function to filter out all the "invalid" devices (audio, USB hubs, etc...)
     MenuItem::getDevInfo(allDevs[i], &dType, &dLabel, &dFS, &dSize);
-    if( !dType.isEmpty() ){ // ignore devices that fail the information check
-      //Allow all filesystems for the moment (could remove UNKNOWN's in the future)
-      //Filter out all devices with basically no storage (1 block ~= 8kB usually)
-      if( dSize.toInt() > 60 ){ 
+    if( !dType.isEmpty() && !dLabel.isEmpty() && !dFS.isEmpty() ){ // ignore devices that fail the information check
         //Add the device to the menu list
 	addDevice(allDevs[i], dLabel);
-      }else if(dSize != "-1"){
-        qDebug() << "Ignoring Device (<60 blocks/sectors):"<<allDevs[i]<<dType<<dLabel<<dFS<<dSize;
-      }
     }
   }
   



More information about the Commits mailing list