PEL: Allow shrinking of a UserData section

Add a shrink() function to the UserData class (with a virtual version of
it in the Section base class) that will shrink the class to a new size.

This is done so that when UserData sections are added to PELs the
sections can be shrunk if necessary to keep the PEL under the maximum
size, which is 16KB.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Iade52dee8a110f7805c40aa50d6e5df45db050bf
diff --git a/extensions/openpower-pels/user_data.cpp b/extensions/openpower-pels/user_data.cpp
index 70acbbb..0ae227b 100644
--- a/extensions/openpower-pels/user_data.cpp
+++ b/extensions/openpower-pels/user_data.cpp
@@ -104,5 +104,22 @@
     return std::nullopt;
 }
 
+bool UserData::shrink(size_t newSize)
+{
+    // minimum size is 4 bytes plus the 8B header
+    if ((newSize < flattenedSize()) &&
+        (newSize >= (Section::flattenedSize() + 4)))
+    {
+        auto dataSize = newSize - Section::flattenedSize();
+
+        // Ensure it's 4B aligned
+        _data.resize((dataSize / 4) * 4);
+        _header.size = Section::flattenedSize() + _data.size();
+        return true;
+    }
+
+    return false;
+}
+
 } // namespace pels
 } // namespace openpower