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

svn at pcbsd.org svn at pcbsd.org
Thu Oct 11 08:35:04 PDT 2012


Author: kenmoore
Date: 2012-10-11 15:35:04 +0000 (Thu, 11 Oct 2012)
New Revision: 19645

Modified:
   pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
Log:
Finish fixing up the updated device detection algorithm, now it will get the device label more accurately, and ignore drives that are already mounted (such as the base OS partitions)



Modified: pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2012-10-11 15:19:23 UTC (rev 19644)
+++ pcbsd/current/src-qt4/pc-mounttray/menuItem.cpp	2012-10-11 15:35:04 UTC (rev 19645)
@@ -128,7 +128,7 @@
   }
   //Make sure we quit before running commands on any invalid device nodes
   if(type->isEmpty() || !QFile::exists(dev) ){return;}
-  
+    
   //Read the Device Info using "file -s <device>"
   QString cmd = "file -s "+dev;
   QString output = Utils::runShellCommand(cmd).join(" ");
@@ -138,7 +138,11 @@
   QStringList tmp = output.split(",");
   int kb;
   //qDebug() << "tmp:" << tmp;
-  if( !tmp.filter("number of data blocks").isEmpty() ){
+  if( !tmp.filter("partition ").isEmpty() ){
+    kb = 0; //Do not recognize the base harddrive if there are partitions on it
+  }else if( !tmp.filter("last mounted on /").isEmpty() ){
+    kb = 0; //Do not recognize partitions that are currently mounted
+  }else 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() ){
@@ -153,21 +157,24 @@
   }else{ kb = 1; }
   maxsize->append( QString::number(kb) );
   
-  
   // ** Get the device label **
-  QString dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
-  
+  //Get the device label if there is one using glabel
+  QString dlabel;
+  QString shortDev = dev.section("/",-1);
+    QString glout = Utils::runShellCommandSearch("glabel status "+shortDev, shortDev);
+    if(!glout.contains("No such geom:")){
+      QStringList entries = glout.split("  ", QString::SkipEmptyParts); //should be 3 entries, only need the first
+      //qDebug() << " - entries:" << entries;
+      QString lab = entries[0].simplified();
+      //save the device label
+      dlabel = lab.section("/",-1);
+    }
+  //Alternate method to get the device label using the "file -s" output
   if(dlabel.isEmpty()){
-    //Try using glabel to find the device label if it was not found
-    QStringList glout = Utils::runShellCommandSearch("glabel list "+dev,"Name:").split("\n");
-    for(int i=0; i<glout.length(); i++){
-      if(!glout[i].contains(dev)){
-        dlabel = glout[i].section("Name:",1,1).section("/",-1).simplified();
-	break;
-      }
-    }
+    dlabel = output.section("label: \"",1,1).section("\"",0,0).simplified(); //device name
   }
-  //Set the Device Name
+  
+  //Set the Device Name/label
   if(dlabel.isEmpty()){
     dlabel = *type+"-Device";
   }



More information about the Commits mailing list