Merge "liblp: Auto-suffix group names."
This commit is contained in:
commit
eb1213f170
4 changed files with 37 additions and 2 deletions
|
@ -623,6 +623,9 @@ std::unique_ptr<LpMetadata> MetadataBuilder::Export() {
|
|||
LERROR << "Partition group name is too long: " << group->name();
|
||||
return nullptr;
|
||||
}
|
||||
if (auto_slot_suffixing_ && group->name() != "default") {
|
||||
out.flags |= LP_GROUP_SLOT_SUFFIXED;
|
||||
}
|
||||
strncpy(out.name, group->name().c_str(), sizeof(out.name));
|
||||
out.maximum_size = group->maximum_size();
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ extern "C" {
|
|||
#define LP_METADATA_HEADER_MAGIC 0x414C5030
|
||||
|
||||
/* Current metadata version. */
|
||||
#define LP_METADATA_MAJOR_VERSION 9
|
||||
#define LP_METADATA_MAJOR_VERSION 10
|
||||
#define LP_METADATA_MINOR_VERSION 0
|
||||
|
||||
/* Attributes for the LpMetadataPartition::attributes field.
|
||||
|
@ -267,10 +267,19 @@ typedef struct LpMetadataPartitionGroup {
|
|||
/* 0: Name of this group. Any unused characters must be 0. */
|
||||
char name[36];
|
||||
|
||||
/* 36: Maximum size in bytes. If 0, the group has no maximum size. */
|
||||
/* 36: Flags (see LP_GROUP_*). */
|
||||
uint32_t flags;
|
||||
|
||||
/* 40: Maximum size in bytes. If 0, the group has no maximum size. */
|
||||
uint64_t maximum_size;
|
||||
} LpMetadataPartitionGroup;
|
||||
|
||||
/* This flag is only intended to be used with super_empty.img and super.img on
|
||||
* retrofit devices. If set, the group needs a slot suffix to be interpreted
|
||||
* correctly. The suffix is automatically applied by ReadMetadata().
|
||||
*/
|
||||
#define LP_GROUP_SLOT_SUFFIXED (1 << 0)
|
||||
|
||||
/* This struct defines an entry in the block_devices table. There must be at
|
||||
* least one device, and the first device must represent the partition holding
|
||||
* the super metadata.
|
||||
|
|
|
@ -622,6 +622,7 @@ TEST(liblp, AutoSlotSuffixing) {
|
|||
unique_ptr<MetadataBuilder> builder = CreateDefaultBuilder();
|
||||
ASSERT_NE(builder, nullptr);
|
||||
ASSERT_TRUE(AddDefaultPartitions(builder.get()));
|
||||
ASSERT_TRUE(builder->AddGroup("example", 0));
|
||||
builder->SetAutoSlotSuffixing();
|
||||
|
||||
auto fd = CreateFakeDisk();
|
||||
|
@ -641,6 +642,11 @@ TEST(liblp, AutoSlotSuffixing) {
|
|||
EXPECT_EQ(GetPartitionName(metadata->partitions[0]), "system_b");
|
||||
ASSERT_EQ(metadata->block_devices.size(), static_cast<size_t>(1));
|
||||
EXPECT_EQ(GetBlockDevicePartitionName(metadata->block_devices[0]), "super_b");
|
||||
ASSERT_EQ(metadata->groups.size(), static_cast<size_t>(2));
|
||||
EXPECT_EQ(GetPartitionGroupName(metadata->groups[0]), "default");
|
||||
EXPECT_EQ(GetPartitionGroupName(metadata->groups[1]), "example_b");
|
||||
EXPECT_EQ(metadata->groups[0].flags, 0);
|
||||
EXPECT_EQ(metadata->groups[1].flags, 0);
|
||||
|
||||
metadata = ReadMetadata(opener, "super_a", 0);
|
||||
ASSERT_NE(metadata, nullptr);
|
||||
|
@ -648,6 +654,11 @@ TEST(liblp, AutoSlotSuffixing) {
|
|||
EXPECT_EQ(GetPartitionName(metadata->partitions[0]), "system_a");
|
||||
ASSERT_EQ(metadata->block_devices.size(), static_cast<size_t>(1));
|
||||
EXPECT_EQ(GetBlockDevicePartitionName(metadata->block_devices[0]), "super_a");
|
||||
ASSERT_EQ(metadata->groups.size(), static_cast<size_t>(2));
|
||||
EXPECT_EQ(GetPartitionGroupName(metadata->groups[0]), "default");
|
||||
EXPECT_EQ(GetPartitionGroupName(metadata->groups[1]), "example_a");
|
||||
EXPECT_EQ(metadata->groups[0].flags, 0);
|
||||
EXPECT_EQ(metadata->groups[1].flags, 0);
|
||||
}
|
||||
|
||||
TEST(liblp, UpdateRetrofit) {
|
||||
|
|
|
@ -375,6 +375,18 @@ bool AdjustMetadataForSlot(LpMetadata* metadata, uint32_t slot_number) {
|
|||
}
|
||||
block_device.flags &= ~LP_BLOCK_DEVICE_SLOT_SUFFIXED;
|
||||
}
|
||||
for (auto& group : metadata->groups) {
|
||||
if (!(group.flags & LP_GROUP_SLOT_SUFFIXED)) {
|
||||
continue;
|
||||
}
|
||||
std::string group_name = GetPartitionGroupName(group) + slot_suffix;
|
||||
if (group_name.size() > sizeof(group.name)) {
|
||||
LERROR << __PRETTY_FUNCTION__ << " group name too long: " << group_name;
|
||||
return false;
|
||||
}
|
||||
strncpy(group.name, group_name.c_str(), sizeof(group.name));
|
||||
group.flags &= ~LP_GROUP_SLOT_SUFFIXED;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue