Skip to content

Commit

Permalink
Merge "liblp: Auto-suffix group names."
Browse files Browse the repository at this point in the history
Former-commit-id: eb1213f1707bb6911fd4116d51e17f331abfaa90
  • Loading branch information
dvandercorp authored and Gerrit Code Review committed Nov 19, 2018
2 parents 1f666d8 + 1bba684 commit bcb9dea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions fs_mgr/liblp/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 11 additions & 2 deletions fs_mgr/liblp/include/liblp/metadata_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions fs_mgr/liblp/io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -641,13 +642,23 @@ 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);
ASSERT_EQ(metadata->partitions.size(), static_cast<size_t>(1));
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) {
Expand Down
12 changes: 12 additions & 0 deletions fs_mgr/liblp/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit bcb9dea

Please sign in to comment.