summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2018-10-12 09:33:44 -0700
committerMark Salyzyn <salyzyn@google.com>2018-10-26 20:57:14 +0000
commit044f04baedc4b35be4145aecdf38b7280496c218 (patch)
tree39ed2925b996a0d98a042bf0e7e9a59f5ad7e2d9 /fastboot
parentdd85c74655400347aee5f6bfecd827a311f16ca4 (diff)
downloadsystem_core-044f04baedc4b35be4145aecdf38b7280496c218.tar.gz
system_core-044f04baedc4b35be4145aecdf38b7280496c218.tar.bz2
system_core-044f04baedc4b35be4145aecdf38b7280496c218.zip
fastboot: wipe overlayfs for partition
Arrange to delete the overlayfs backing when a specified partition has been flashed. Test: manual Bug: 109821005 Bug: 117605276 Change-Id: I1c6a0341c6cd2ecfbb7c71bec5679a74d579aadd
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/device/flashing.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp
index 2347496b9..16443c097 100644
--- a/fastboot/device/flashing.cpp
+++ b/fastboot/device/flashing.cpp
@@ -21,10 +21,15 @@
#include <algorithm>
#include <memory>
+#include <set>
+#include <string>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include <ext4_utils/ext4_utils.h>
+#include <fs_mgr_overlayfs.h>
+#include <fstab/fstab.h>
#include <liblp/builder.h>
#include <liblp/liblp.h>
#include <sparse/sparse.h>
@@ -32,13 +37,35 @@
#include "fastboot_device.h"
#include "utility.h"
+using namespace android::fs_mgr;
+using namespace std::literals;
+
namespace {
constexpr uint32_t SPARSE_HEADER_MAGIC = 0xed26ff3a;
-} // namespace
+void WipeOverlayfsForPartition(FastbootDevice* device, const std::string& partition_name) {
+ // May be called, in the case of sparse data, multiple times so cache/skip.
+ static std::set<std::string> wiped;
+ if (wiped.find(partition_name) != wiped.end()) return;
+ wiped.insert(partition_name);
+ // Following appears to have a first time 2% impact on flashing speeds.
+
+ // Convert partition_name to a validated mount point and wipe.
+ std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
+ fs_mgr_free_fstab);
+ for (auto i = 0; i < fstab->num_entries; i++) {
+ const auto mount_point = fstab->recs[i].mount_point;
+ if (!mount_point) continue;
+ auto partition = android::base::Basename(mount_point);
+ if ("/"s == mount_point) partition = "system";
+ if ((partition + device->GetCurrentSlot()) == partition_name) {
+ fs_mgr_overlayfs_teardown(mount_point);
+ }
+ }
+}
-using namespace android::fs_mgr;
+} // namespace
int FlashRawDataChunk(int fd, const char* data, size_t len) {
size_t ret = 0;
@@ -101,6 +128,7 @@ int Flash(FastbootDevice* device, const std::string& partition_name) {
} else if (data.size() > get_block_device_size(handle.fd())) {
return -EOVERFLOW;
}
+ WipeOverlayfsForPartition(device, partition_name);
return FlashBlockDevice(handle.fd(), data);
}