diff options
author | Elliott Hughes <enh@google.com> | 2015-05-11 11:55:25 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-05-11 13:36:13 -0700 |
commit | a51d8b9a1c06a17b8d5d5fd9547a3bf813ea4157 (patch) | |
tree | cf6f89e89e8e97451dd404fa025bfcb88b6fb4f5 /adb/remount_service.cpp | |
parent | 86aeb11ed047b3698948c4eee8fbaccd20131ecb (diff) | |
download | system_core-a51d8b9a1c06a17b8d5d5fd9547a3bf813ea4157.zip system_core-a51d8b9a1c06a17b8d5d5fd9547a3bf813ea4157.tar.gz system_core-a51d8b9a1c06a17b8d5d5fd9547a3bf813ea4157.tar.bz2 |
Failure to find an oem partition should not be a remount failure.
Many devices don't have an /oem partition, so find_mount should be
expected to fail, but shouldn't cause the overall remount to fail.
Also clean up all the error handling and reporting, and remove the
dead int* globals.
Bug: http://b/21024141
Change-Id: Ie31021b03c9cab8e972269d7d1ffe383cd30ee9e
(cherry picked from commit 9aa4fda4e64c1882faf019cc2a483ee4917e0c85)
Diffstat (limited to 'adb/remount_service.cpp')
-rw-r--r-- | adb/remount_service.cpp | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/adb/remount_service.cpp b/adb/remount_service.cpp index f645a78..7a3b89a 100644 --- a/adb/remount_service.cpp +++ b/adb/remount_service.cpp @@ -34,10 +34,6 @@ #include "adb_utils.h" #include "cutils/properties.h" -static int system_ro = 1; -static int vendor_ro = 1; -static int oem_ro = 1; - // Returns the device used to mount a directory in /proc/mounts. static std::string find_mount(const char* dir) { std::unique_ptr<FILE, int(*)(FILE*)> fp(setmntent("/proc/mounts", "r"), endmntent); @@ -54,40 +50,33 @@ static std::string find_mount(const char* dir) { return ""; } -int make_block_device_writable(const std::string& dev) { +bool make_block_device_writable(const std::string& dev) { int fd = unix_open(dev.c_str(), O_RDONLY | O_CLOEXEC); if (fd == -1) { - return -1; + return false; } - int result = -1; int OFF = 0; - if (!ioctl(fd, BLKROSET, &OFF)) { - result = 0; - } + bool result = (ioctl(fd, BLKROSET, &OFF) != -1); adb_close(fd); - return result; } -// Init mounts /system as read only, remount to enable writes. -static int remount(const char* dir, int* dir_ro) { - std::string dev = find_mount(dir); - if (dev.empty() || make_block_device_writable(dev)) { - return -1; +static bool remount_partition(int fd, const char* dir) { + if (!directory_exists(dir)) { + return true; } - - int rc = mount(dev.c_str(), dir, "none", MS_REMOUNT, NULL); - *dir_ro = rc; - return rc; -} - -static bool remount_partition(int fd, const char* partition, int* ro) { - if (!directory_exists(partition)) { + std::string dev = find_mount(dir); + if (dev.empty()) { return true; } - if (remount(partition, ro)) { - WriteFdFmt(fd, "remount of %s failed: %s\n", partition, strerror(errno)); + if (!make_block_device_writable(dev)) { + WriteFdFmt(fd, "remount of %s failed; couldn't make block device %s writable: %s\n", + dir, dev.c_str(), strerror(errno)); + return false; + } + if (mount(dev.c_str(), dir, "none", MS_REMOUNT, nullptr) == -1) { + WriteFdFmt(fd, "remount of %s failed: %s\n", dir, strerror(errno)); return false; } return true; @@ -123,9 +112,9 @@ void remount_service(int fd, void* cookie) { } bool success = true; - success &= remount_partition(fd, "/system", &system_ro); - success &= remount_partition(fd, "/vendor", &vendor_ro); - success &= remount_partition(fd, "/oem", &oem_ro); + success &= remount_partition(fd, "/system"); + success &= remount_partition(fd, "/vendor"); + success &= remount_partition(fd, "/oem"); WriteFdExactly(fd, success ? "remount succeeded\n" : "remount failed\n"); |