[meta-arm,5/5] arm-autonomy/xenguest-mkimage: improve xenguest image checks

Submitted by Kamil Dziezyk on Nov. 20, 2020, 11:44 a.m. | Patch ID: 178090

Details

Message ID 20201120114404.730-5-kamil.dziezyk@arm.com
State New
Headers show

Commit Message

Kamil Dziezyk Nov. 20, 2020, 11:44 a.m.
This patch brings following improvements:
 * Adding the same partition content e.g rootfs.tar.gz,
   for multiple partitions is now not possible.
 * Guest partition can contain only supported values of:
   - format types: vfat|ext2|ext3|ext4|swap|(empty)
   - image types: *.img.gz|*.img.bz2|*.img
                  *.tar.gz|*.tar.bz2|*.tar.xz|*.tar

Change-Id: I0201e7ef51830ac43fc59656fc496fcc1d13b8d4
Issue-Id: SCM-1515
Signed-off-by: Kamil Dziezyk <kamil.dziezyk@arm.com>

---
 .../xenguest/files/xenguest-mkimage           | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)

-- 
2.17.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#1413): https://lists.yoctoproject.org/g/meta-arm/message/1413
Mute This Topic: https://lists.yoctoproject.org/mt/78387219/1003190
Group Owner: meta-arm+owner@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [mhalstead@linuxfoundation.org]
-=-=-=-=-=-=-=-=-=-=-=-

Patch hide | download patch | download mbox

diff --git a/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage
index 8543c01..29e0911 100755
--- a/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage
+++ b/meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-mkimage
@@ -436,11 +436,70 @@  disk_config_get_free_space() {
     echo -e "$((${disk_size::${#disk_size}-1} - ${disk_usage}))M"
 }
 
+disk_check_partition_format() {
+    local partformat="${1}"
+    # if partformat is not defined let's skip this check
+    [ -n "${partformat}" ] || return 0
+
+    case "${partformat}" in
+         vfat|ext2|ext3|ext4|swap)
+            ;;
+        *)
+            # invalid/unknown fstype
+            echo "Invalid file fstype ${partformat}"
+            exit 1
+            ;;
+    esac
+}
+
+disk_check_partition_content() {
+    local partcontent="${1}"
+    # if partcontent is not defined let's skip this check
+    [ -n "${partcontent}" ] || return 0
+
+    case "${partcontent}" in
+        *.img*)
+            case "${partcontent}" in
+                *.img.gz|*.img.bz2|*.img)
+                    ;;
+                *)
+                    # invalid/unknown compression type
+                    echo "Invalid file format in disk ${partcontent}"
+                    exit 1
+                    ;;
+            esac
+            ;;
+        *.tar*)
+            case "${partcontent}" in
+                *.tar.gz|*.tar.bz2|*.tar.xz|*.tar)
+                    ;;
+                *)
+                    # invalid/unknown tar type
+                    echo "Invalid file format in disk ${partcontent}"
+                    exit 1
+                    ;;
+            esac
+            ;;
+        *)
+          #invalid content type
+          echo "Unsupported content type ${partcontent}!"
+          exit 1
+          ;;
+    esac
+    # do not allow to create multiple partitions the same content
+    if grep ":${partcontent}\"" <<< "$(disk_config_get_parts)"; then
+        echo "Error ${partcontent} is already inside guest image"
+        exit 1
+    fi
+}
+
 disk_config_add_part() {
     partconf="${1}"
     partid=$(echo ${partconf} | sed -e "s/:.*//")
     partinfo=$(echo ${partconf} | sed -e "s/[^:]*://")
     partsize=$(echo ${partinfo} | cut -d ":" -f1)
+    partformat=$(echo ${partinfo} | cut -d ":" -f2)
+    partcontent=$(echo ${partinfo} | cut -d ":" -f3)
 
     # check size "ID:*SIZE*:FORMAT:CONTENT"
     partsizeMB=$(check_size "${partsize}")
@@ -459,6 +518,12 @@  disk_config_add_part() {
         exit 1
     fi
 
+    # check format "ID:SIZE:*FORMAT*:CONTENT"
+    disk_check_partition_format "${partformat}"
+
+    # check content "ID:SIZE:FORMAT:*CONTENT*"
+    disk_check_partition_content "${partcontent}"
+
     echo "DISK_PART${partid}=\"${partinfo}\"" >> \
         ${IMAGE_TMPDIR}/disk.cfg
 }