Merge "update_verifier: Support verifying product partition."
This commit is contained in:
@@ -46,7 +46,6 @@ TEST_F(UpdateVerifierTest, verify_image_smoke) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The care map file can have only two or four lines.
|
|
||||||
TemporaryFile temp_file;
|
TemporaryFile temp_file;
|
||||||
std::string content = "system\n2,0,1";
|
std::string content = "system\n2,0,1";
|
||||||
ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path));
|
ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path));
|
||||||
@@ -58,7 +57,7 @@ TEST_F(UpdateVerifierTest, verify_image_smoke) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UpdateVerifierTest, verify_image_wrong_lines) {
|
TEST_F(UpdateVerifierTest, verify_image_wrong_lines) {
|
||||||
// The care map file can have only two or four lines.
|
// The care map file can have only 2 / 4 / 6 lines.
|
||||||
TemporaryFile temp_file;
|
TemporaryFile temp_file;
|
||||||
ASSERT_FALSE(verify_image(temp_file.path));
|
ASSERT_FALSE(verify_image(temp_file.path));
|
||||||
|
|
||||||
|
|||||||
@@ -74,14 +74,13 @@ static int dm_name_filter(const dirent* de) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool read_blocks(const std::string& partition, const std::string& range_str) {
|
static bool read_blocks(const std::string& partition, const std::string& range_str) {
|
||||||
if (partition != "system" && partition != "vendor") {
|
if (partition != "system" && partition != "vendor" && partition != "product") {
|
||||||
LOG(ERROR) << "partition name must be system or vendor: " << partition;
|
LOG(ERROR) << "Invalid partition name \"" << partition << "\"";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Iterate the content of "/sys/block/dm-X/dm/name". If it matches "system"
|
// Iterate the content of "/sys/block/dm-X/dm/name". If it matches one of "system", "vendor" or
|
||||||
// (or "vendor"), then dm-X is a dm-wrapped system/vendor partition.
|
// "product", then dm-X is a dm-wrapped device for that target. We will later read all the
|
||||||
// Afterwards, update_verifier will read every block on the care_map_file of
|
// ("cared") blocks from "/dev/block/dm-X" to ensure the target partition's integrity.
|
||||||
// "/dev/block/dm-X" to ensure the partition's integrity.
|
|
||||||
static constexpr auto DM_PATH_PREFIX = "/sys/block/";
|
static constexpr auto DM_PATH_PREFIX = "/sys/block/";
|
||||||
dirent** namelist;
|
dirent** namelist;
|
||||||
int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort);
|
int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort);
|
||||||
@@ -206,10 +205,9 @@ bool verify_image(const std::string& care_map_name) {
|
|||||||
PLOG(WARNING) << "Failed to open " << care_map_name;
|
PLOG(WARNING) << "Failed to open " << care_map_name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Care map file has four lines (two lines if vendor partition is not present):
|
// care_map file has up to six lines, where every two lines make a pair. Within each pair, the
|
||||||
// First line has the block partition name (system/vendor).
|
// first line has the partition name (e.g. "system"), while the second line holds the ranges of
|
||||||
// Second line holds all ranges of blocks to verify.
|
// all the blocks to verify.
|
||||||
// The next two lines have the same format but for vendor partition.
|
|
||||||
std::string file_content;
|
std::string file_content;
|
||||||
if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) {
|
if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) {
|
||||||
LOG(ERROR) << "Error reading care map contents to string.";
|
LOG(ERROR) << "Error reading care map contents to string.";
|
||||||
@@ -218,9 +216,9 @@ bool verify_image(const std::string& care_map_name) {
|
|||||||
|
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
lines = android::base::Split(android::base::Trim(file_content), "\n");
|
lines = android::base::Split(android::base::Trim(file_content), "\n");
|
||||||
if (lines.size() != 2 && lines.size() != 4) {
|
if (lines.size() != 2 && lines.size() != 4 && lines.size() != 6) {
|
||||||
LOG(ERROR) << "Invalid lines in care_map: found " << lines.size()
|
LOG(ERROR) << "Invalid lines in care_map: found " << lines.size()
|
||||||
<< " lines, expecting 2 or 4 lines.";
|
<< " lines, expecting 2 or 4 or 6 lines.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user