Bug 1066543 - Add MS_VERBOSE to the remount options in the updater automounter. r=marshall_law
authorAntonio M. Amaya <amac@tid.es>
Fri, 12 Sep 2014 10:33:00 -0400
changeset 205178 f0d38c5711a46fc524dabb766b2f53942616e6ff
parent 205177 7c8b3cd5e57e0bd5ede643ce3e04b384091c0359
child 205179 11598d750c6f24e4db8b49a2ade4d6a0b90463b8
push id27478
push userphilringnalda@gmail.com
push dateSat, 13 Sep 2014 17:09:31 +0000
treeherdermozilla-central@d070787de8f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarshall_law
bugs1066543
milestone35.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 1066543 - Add MS_VERBOSE to the remount options in the updater automounter. r=marshall_law
toolkit/mozapps/update/updater/automounter_gonk.cpp
--- a/toolkit/mozapps/update/updater/automounter_gonk.cpp
+++ b/toolkit/mozapps/update/updater/automounter_gonk.cpp
@@ -6,16 +6,18 @@
 
 #include <android/log.h>
 #include <cutils/android_reboot.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/mount.h>
 #include <sys/reboot.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 #include "automounter_gonk.h"
 #include "updatedefines.h"
 #include "updatelogging.h"
 
 #define LOG_TAG "GonkAutoMounter"
 
@@ -197,24 +199,49 @@ GonkAutoMounter::ProcessMount(const char
       mAccess = ReadWrite;
       break;
     }
   }
 
   return true;
 }
 
+/*
+ * Mark the given block device as read-write or read-only, using the BLKROSET
+ * ioctl.
+ */
+static void SetBlockReadWriteStatus(const char *blockdev, bool setReadOnly) {
+  int fd;
+  int roMode = setReadOnly ? 1 : 0;
+
+  fd = open(blockdev, O_RDONLY);
+  if (fd < 0) {
+    return;
+  }
+
+  if (ioctl(fd, BLKROSET, &roMode) == -1) {
+    LOGE("Error setting read-only mode on %s to %s: %s", blockdev,
+         setReadOnly ? "true": "false", strerror(errno));
+  }
+  close(fd);
+}
+
+
 bool
 GonkAutoMounter::MountSystem(unsigned long flags)
 {
   if (!mDevice) {
     LOGE("No device was found for %s", kGonkSystemPath);
     return false;
   }
 
+  // Without setting the block device ro mode to false, we get a permission
+  // denied error while trying to remount it in read-write.
+  SetBlockReadWriteStatus(mDevice, (flags & MS_RDONLY));
+
   const char *readOnly = flags & MS_RDONLY ? "read-only" : "read-write";
   int result = mount(mDevice, kGonkSystemPath, "none", flags, nullptr);
 
   if (result != 0) {
     LOGE("Error mounting %s as %s: %s", kGonkSystemPath, readOnly,
          strerror(errno));
     return false;
   }