Bug 1195166 - AutoMounter: add ignore command to allow volumes to be ignored. r=alchen
authorDave Hylands <dhylands@mozilla.com>
Fri, 25 Sep 2015 13:23:32 -0700
changeset 264662 c46bfa072df91f4faae3fa3ecc210fdd059d86cd
parent 264661 17657881ffe06881ab7dbb2ca832f027fe599718
child 264663 126cadcfd9871fe589a4fe22e5f416020c0e8d75
push id65707
push usercbook@mozilla.com
push dateMon, 28 Sep 2015 12:18:34 +0000
treeherdermozilla-inbound@2c0e60a8f736 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalchen
bugs1195166
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1195166 - AutoMounter: add ignore command to allow volumes to be ignored. r=alchen
dom/system/gonk/VolumeManager.cpp
dom/system/gonk/VolumeManager.h
--- a/dom/system/gonk/VolumeManager.cpp
+++ b/dom/system/gonk/VolumeManager.cpp
@@ -152,16 +152,37 @@ VolumeManager::FindAddVolumeByName(const
   }
   // No volume found, create and add a new one.
   vol = new Volume(aName);
   sVolumeManager->mVolumeArray.AppendElement(vol);
   return vol.forget();
 }
 
 //static
+bool
+VolumeManager::RemoveVolumeByName(const nsCSubstring& aName)
+{
+  if (!sVolumeManager) {
+    return false;
+  }
+  VolumeArray::size_type  numVolumes = NumVolumes();
+  VolumeArray::index_type volIndex;
+  for (volIndex = 0; volIndex < numVolumes; volIndex++) {
+    RefPtr<Volume> vol = GetVolume(volIndex);
+    if (vol->Name().Equals(aName)) {
+      sVolumeManager->mVolumeArray.RemoveElementAt(volIndex);
+      return true;
+    }
+  }
+  // No volume found. Return false to indicate this.
+  return false;
+}
+
+
+//static
 void VolumeManager::InitConfig()
 {
   MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
 
   // This function uses /system/etc/volume.cfg to add additional volumes
   // to the Volume Manager.
   //
   // This is useful on devices like the Nexus 4, which have no physical sd card
@@ -231,16 +252,27 @@ void VolumeManager::InitConfig()
       RefPtr<Volume> vol = FindVolumeByName(volName);
       if (vol) {
         vol->SetConfig(configName, configValue);
       } else {
         ERR("Invalid volume name '%s'.", volName.get());
       }
       continue;
     }
+    if (command.EqualsLiteral("ignore")) {
+      // This command is useful to remove volumes which are being tracked by
+      // vold, but for which we have no interest.
+      if (!tokenizer.hasMoreTokens()) {
+        ERR("No vol_name in %s line %d", filename, n);
+        continue;
+      }
+      nsCString volName(tokenizer.nextToken());
+      RemoveVolumeByName(volName);
+      continue;
+    }
     ERR("Unrecognized command: '%s'", command.get());
   }
 }
 
 void
 VolumeManager::DefaultConfig()
 {
 
--- a/dom/system/gonk/VolumeManager.h
+++ b/dom/system/gonk/VolumeManager.h
@@ -123,16 +123,17 @@ public:
 
   static void Start();
   static void Dump(const char* aLabel);
 
   static VolumeArray::size_type NumVolumes();
   static already_AddRefed<Volume> GetVolume(VolumeArray::index_type aIndex);
   static already_AddRefed<Volume> FindVolumeByName(const nsCSubstring& aName);
   static already_AddRefed<Volume> FindAddVolumeByName(const nsCSubstring& aName);
+  static bool RemoveVolumeByName(const nsCSubstring& aName);
   static void InitConfig();
 
   static void       PostCommand(VolumeCommand* aCommand);
 
 protected:
 
   virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage);
   virtual void OnFileCanWriteWithoutBlocking(int aFd);