From 2780d0abb289bf85f463fcbb0935f3218118ae67 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 19 Nov 2019 17:31:54 -0800 Subject: [PATCH] liblp: Allow "flashing" files on the host. UpdatePartitionTable expects to be run on a device, which is a reasonable assumption. However to implement lpadd (offline modification of super images), it's useful to be able to run these methods, and IPartitionOpener allows us to masquerade a flie as a block device. The only catch is that we can't query partition information on the host. Since this logic is a protection mechanism, just surround it with an ifdef for __ANDROID__. Bug: 144468779 Test: lpadd Change-Id: I3c50e5677fa1dd59f2d4216038d3d4fbfb6edcc0 --- fs_mgr/liblp/writer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs_mgr/liblp/writer.cpp b/fs_mgr/liblp/writer.cpp index 8a983adf4..bb24069aa 100644 --- a/fs_mgr/liblp/writer.cpp +++ b/fs_mgr/liblp/writer.cpp @@ -83,8 +83,9 @@ std::string SerializeMetadata(const LpMetadata& input) { // Perform sanity checks so we don't accidentally overwrite valid metadata // with potentially invalid metadata, or random partition data with metadata. -static bool ValidateAndSerializeMetadata(const IPartitionOpener& opener, const LpMetadata& metadata, - const std::string& slot_suffix, std::string* blob) { +static bool ValidateAndSerializeMetadata([[maybe_unused]] const IPartitionOpener& opener, + const LpMetadata& metadata, const std::string& slot_suffix, + std::string* blob) { const LpMetadataGeometry& geometry = metadata.geometry; *blob = SerializeMetadata(metadata); @@ -128,6 +129,10 @@ static bool ValidateAndSerializeMetadata(const IPartitionOpener& opener, const L << block_device.first_logical_sector << " for size " << block_device.size; return false; } + + // When flashing on the device, check partition sizes. Don't do this on + // the host since there is no way to verify. +#if defined(__ANDROID__) BlockDeviceInfo info; if (!opener.GetInfo(partition_name, &info)) { PERROR << partition_name << ": ioctl"; @@ -138,6 +143,7 @@ static bool ValidateAndSerializeMetadata(const IPartitionOpener& opener, const L << block_device.size << ", got " << info.size << ")"; return false; } +#endif } // Make sure all partition entries reference valid extents.