Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09d8c605 authored by David Anderson's avatar David Anderson Committed by Android (Google) Code Review
Browse files

Merge "liblp: Remove auto slot suffixing support." into main

parents e4947898 ef14ae4e
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
    return New(*metadata.get(), &opener);
}

MetadataBuilder::MetadataBuilder() : auto_slot_suffixing_(false) {
MetadataBuilder::MetadataBuilder() {
    memset(&geometry_, 0, sizeof(geometry_));
    geometry_.magic = LP_METADATA_GEOMETRY_MAGIC;
    geometry_.struct_size = sizeof(geometry_);
@@ -827,9 +827,6 @@ std::unique_ptr<LpMetadata> MetadataBuilder::Export() {
    // Assign this early so the extent table can read it.
    for (const auto& block_device : block_devices_) {
        metadata->block_devices.emplace_back(block_device);
        if (auto_slot_suffixing_) {
            metadata->block_devices.back().flags |= LP_BLOCK_DEVICE_SLOT_SUFFIXED;
        }
    }

    std::map<std::string, size_t> group_indices;
@@ -840,9 +837,6 @@ std::unique_ptr<LpMetadata> MetadataBuilder::Export() {
            LERROR << "Partition group name is too long: " << group->name();
            return nullptr;
        }
        if (auto_slot_suffixing_ && group->name() != kDefaultGroup) {
            out.flags |= LP_GROUP_SLOT_SUFFIXED;
        }
        strncpy(out.name, group->name().c_str(), sizeof(out.name));
        out.maximum_size = group->maximum_size();

@@ -874,9 +868,6 @@ std::unique_ptr<LpMetadata> MetadataBuilder::Export() {
        part.first_extent_index = static_cast<uint32_t>(metadata->extents.size());
        part.num_extents = static_cast<uint32_t>(partition->extents().size());
        part.attributes = partition->attributes();
        if (auto_slot_suffixing_) {
            part.attributes |= LP_PARTITION_ATTR_SLOT_SUFFIXED;
        }

        auto iter = group_indices.find(partition->group_name());
        if (iter == group_indices.end()) {
@@ -1145,10 +1136,6 @@ bool MetadataBuilder::ImportPartition(const LpMetadata& metadata,
    return true;
}

void MetadataBuilder::SetAutoSlotSuffixing() {
    auto_slot_suffixing_ = true;
}

void MetadataBuilder::SetVirtualABDeviceFlag() {
    RequireExpandedMetadataHeader();
    header_.flags |= LP_HEADER_FLAG_VIRTUAL_AB_DEVICE;
+0 −1
Original line number Diff line number Diff line
@@ -337,7 +337,6 @@ void BuilderFuzzer::invokeBuilderAPIs() {
                    },
                    [&]() { mBuilder->HasBlockDevice(mFdp.PickValueInArray(mPartitionNames)); },
                    [&]() { mBuilder->SetVirtualABDeviceFlag(); },
                    [&]() { mBuilder->SetAutoSlotSuffixing(); },
                    [&]() { mBuilder->ListGroups(); },
                    [&]() { mBuilder->UsedSpace(); },
                    [&]() { mBuilder->RequireExpandedMetadataHeader(); },
+0 −3
Original line number Diff line number Diff line
@@ -340,8 +340,6 @@ class MetadataBuilder {
    // Remove all partitions belonging to a group, then remove the group.
    void RemoveGroupAndPartitions(std::string_view group_name);

    // Set the LP_METADATA_AUTO_SLOT_SUFFIXING flag.
    void SetAutoSlotSuffixing();
    // Set the LP_HEADER_FLAG_VIRTUAL_AB_DEVICE flag.
    void SetVirtualABDeviceFlag();
    // Set or unset the LP_HEADER_FLAG_OVERLAYS_ACTIVE flag.
@@ -418,7 +416,6 @@ class MetadataBuilder {
    std::vector<std::unique_ptr<Partition>> partitions_;
    std::vector<std::unique_ptr<PartitionGroup>> groups_;
    std::vector<LpMetadataBlockDevice> block_devices_;
    bool auto_slot_suffixing_;
};

// Read BlockDeviceInfo for a given block device. This always returns false
+8 −14
Original line number Diff line number Diff line
@@ -56,12 +56,9 @@ extern "C" {
#define LP_PARTITION_ATTR_NONE 0x0
#define LP_PARTITION_ATTR_READONLY (1 << 0)

/* This flag is only intended to be used with super_empty.img and super.img on
 * retrofit devices. On these devices there are A and B super partitions, and
 * we don't know ahead of time which slot the image will be applied to.
/* This flag is historical and is no longer supported.
 *
 * If set, the partition name needs a slot suffix applied. The slot suffix is
 * determined by the metadata slot number (0 = _a, 1 = _b).
 * If set, the partition name needs a slot suffix applied.
 */
#define LP_PARTITION_ATTR_SLOT_SUFFIXED (1 << 1)

@@ -319,9 +316,9 @@ typedef struct LpMetadataPartitionGroup {
    uint64_t maximum_size;
} __attribute__((packed)) 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().
/* This flag is historical and is no longer supported.
 *
 * If set, the group needs a slot suffix to be interpreted correctly.
 */
#define LP_GROUP_SLOT_SUFFIXED (1 << 0)

@@ -370,13 +367,10 @@ typedef struct LpMetadataBlockDevice {
    uint32_t flags;
} __attribute__((packed)) LpMetadataBlockDevice;

/* This flag is only intended to be used with super_empty.img and super.img on
 * retrofit devices. On these devices there are A and B super partitions, and
 * we don't know ahead of time which slot the image will be applied to.
/* This flag is historical and is no longer supported.
 *
 * If set, the block device needs a slot suffix applied before being used with
 * IPartitionOpener. The slot suffix is determined by the metadata slot number
 * (0 = _a, 1 = _b).
 * If set, the block device needs a slot suffix to be interpreted
 * correctly.
 */
#define LP_BLOCK_DEVICE_SLOT_SUFFIXED (1 << 0)

+0 −43
Original line number Diff line number Diff line
@@ -627,49 +627,6 @@ TEST_F(LiblpTest, FlashSparseImage) {
    ASSERT_NE(ReadBackupMetadata(fd.get(), geometry, 0), nullptr);
}

TEST_F(LiblpTest, 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();
    ASSERT_GE(fd, 0);

    // Note: we bind the same fd to both names, since we want to make sure the
    // exact same bits are getting read back in each test.
    TestPartitionOpener opener({{"super_a", fd}, {"super_b", fd}},
                               {{"super_a", kSuperInfo}, {"super_b", kSuperInfo}});
    auto exported = builder->Export();
    ASSERT_NE(exported, nullptr);
    ASSERT_TRUE(FlashPartitionTable(opener, "super_a", *exported.get()));

    auto metadata = ReadMetadata(opener, "super_b", 1);
    ASSERT_NE(metadata, nullptr);
    ASSERT_EQ(metadata->partitions.size(), static_cast<size_t>(1));
    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_F(LiblpTest, UpdateLaunchDap) {
    unique_fd fd = CreateFlashedDisk();
    ASSERT_GE(fd, 0);
Loading