Make sure loop device isn't read only.
In some cases the loop device is read only by default, if we want to
write to it, we should set BLKROSET to 0, otherwise mounting will fail
with permission deny.
Bug: 68805558
Test: update_engine_unittests pass
Change-Id: If5eb7aa2dc97858bfb03aac2ceb5c01e055fe06f
(cherry picked from commit 2532da227e2a9313e95352bb47294a5f2ec0b7e0)
diff --git a/common/test_utils.cc b/common/test_utils.cc
index fb22c80..e410283 100644
--- a/common/test_utils.cc
+++ b/common/test_utils.cc
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
+#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
@@ -201,6 +202,13 @@
device_info.lo_file_name[LO_NAME_SIZE - 1] = '\0';
TEST_AND_RETURN_FALSE_ERRNO(
ioctl(loop_device_fd, LOOP_SET_STATUS64, &device_info) == 0);
+ if (writable) {
+ // Make sure loop device isn't read only.
+ int ro = 0;
+ if (ioctl(loop_device_fd, BLKROSET, &ro) != 0) {
+ PLOG(WARNING) << "Failed to mark loop device writable.";
+ }
+ }
return true;
}