Merge "Failure to find an oem partition should not be a remount failure."
This commit is contained in:
commit
85abaf66c4
3 changed files with 21 additions and 32 deletions
|
|
@ -34,10 +34,6 @@
|
||||||
#include "adb_utils.h"
|
#include "adb_utils.h"
|
||||||
#include "cutils/properties.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.
|
// Returns the device used to mount a directory in /proc/mounts.
|
||||||
static std::string find_mount(const char* dir) {
|
static std::string find_mount(const char* dir) {
|
||||||
std::unique_ptr<FILE, int(*)(FILE*)> fp(setmntent("/proc/mounts", "r"), endmntent);
|
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 "";
|
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);
|
int fd = unix_open(dev.c_str(), O_RDONLY | O_CLOEXEC);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = -1;
|
|
||||||
int OFF = 0;
|
int OFF = 0;
|
||||||
if (!ioctl(fd, BLKROSET, &OFF)) {
|
bool result = (ioctl(fd, BLKROSET, &OFF) != -1);
|
||||||
result = 0;
|
|
||||||
}
|
|
||||||
adb_close(fd);
|
adb_close(fd);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init mounts /system as read only, remount to enable writes.
|
static bool remount_partition(int fd, const char* dir) {
|
||||||
static int remount(const char* dir, int* dir_ro) {
|
if (!directory_exists(dir)) {
|
||||||
std::string dev = find_mount(dir);
|
|
||||||
if (dev.empty() || make_block_device_writable(dev)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (remount(partition, ro)) {
|
std::string dev = find_mount(dir);
|
||||||
WriteFdFmt(fd, "remount of %s failed: %s\n", partition, strerror(errno));
|
if (dev.empty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -123,9 +112,9 @@ void remount_service(int fd, void* cookie) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
success &= remount_partition(fd, "/system", &system_ro);
|
success &= remount_partition(fd, "/system");
|
||||||
success &= remount_partition(fd, "/vendor", &vendor_ro);
|
success &= remount_partition(fd, "/vendor");
|
||||||
success &= remount_partition(fd, "/oem", &oem_ro);
|
success &= remount_partition(fd, "/oem");
|
||||||
|
|
||||||
WriteFdExactly(fd, success ? "remount succeeded\n" : "remount failed\n");
|
WriteFdExactly(fd, success ? "remount succeeded\n" : "remount failed\n");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int make_block_device_writable(const std::string&);
|
bool make_block_device_writable(const std::string&);
|
||||||
void remount_service(int, void*);
|
void remount_service(int, void*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ static int set_verity_enabled_state(int fd, const char *block_device,
|
||||||
int device = -1;
|
int device = -1;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
if (make_block_device_writable(block_device)) {
|
if (!make_block_device_writable(block_device)) {
|
||||||
WriteFdFmt(fd, "Could not make block device %s writable (%s).\n",
|
WriteFdFmt(fd, "Could not make block device %s writable (%s).\n",
|
||||||
block_device, strerror(errno));
|
block_device, strerror(errno));
|
||||||
goto errout;
|
goto errout;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue