From 66ad4440e2a5d8ce4dd23e1d261a24635f39d89c Mon Sep 17 00:00:00 2001
From: Andrei Gherzan <andrei.gherzan@huawei.com>
Date: Mon, 2 Aug 2021 16:51:39 +0100
Subject: [PATCH] x-mounts: Introduce recipe for system partition mount units

This components defines, generates and provides systemd mount units for
the system partitions (based on filesystem labels) as it follows:

boot partition -> label "boot" -> "mountpoint: /run/mount/boot"
devdata partition -> label "devdata" -> "mountpoint: /run/mount/devdata"
sysdata partition -> label "sysdata" -> "mountpoint: /run/mount/sysdata"
appdata partition -> label "appdata" -> "mountpoint: /run/mount/appdata"

When installed, the units are enabled early in the boot process as part
of the local-fs.target.

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
---
 .../recipes-core/x-mounts/x-mounts.bb         | 45 +++++++++++++++++++
 .../x-mounts/x-mounts/run-mount-appdata.mount | 16 +++++++
 .../x-mounts/x-mounts/run-mount-boot.mount    | 16 +++++++
 .../x-mounts/x-mounts/run-mount-devdata.mount | 17 +++++++
 .../x-mounts/x-mounts/run-mount-sysdata.mount | 16 +++++++
 5 files changed, 110 insertions(+)
 create mode 100644 meta-ohos-core/recipes-core/x-mounts/x-mounts.bb
 create mode 100644 meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-appdata.mount
 create mode 100644 meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-boot.mount
 create mode 100644 meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-devdata.mount
 create mode 100644 meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-sysdata.mount

diff --git a/meta-ohos-core/recipes-core/x-mounts/x-mounts.bb b/meta-ohos-core/recipes-core/x-mounts/x-mounts.bb
new file mode 100644
index 00000000..88b39312
--- /dev/null
+++ b/meta-ohos-core/recipes-core/x-mounts/x-mounts.bb
@@ -0,0 +1,45 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+SUMMARY = "Systemd mount units for the provided partitions"
+SECTION = "base"
+DESCRIPTION = "This recipe provides a set of mount units for the partition \
+table used for the OS. It becomes the foundation of various functionalities. \
+For example, runtime state management as part of a separatae state partition \
+(sysdata)"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+SRC_URI = " \
+    file://run-mount-boot.mount \
+    file://run-mount-devdata.mount \
+    file://run-mount-appdata.mount \
+    file://run-mount-sysdata.mount \
+    "
+
+inherit allarch systemd
+
+SYSTEMD_SERVICE_${PN} = " \
+    run-mount-boot.mount \
+    run-mount-sysdata.mount \
+    run-mount-devdata.mount \
+    run-mount-appdata.mount \
+    "
+SYSTEMD_AUTO_ENABLE = "enable"
+
+LABELS = " \
+    ${BOOT_PARTITION_LABEL} \
+    ${DEVDATA_PARTITION_LABEL} \
+    ${APPDATA_PARTITION_LABEL} \
+    ${SYSDATA_PARTITION_LABEL} \
+    "
+
+do_install () {
+    install -d ${D}${systemd_unitdir}/system
+    for label in ${LABELS}; do
+        install -m 0644 "${WORKDIR}/run-mount-${label}.mount" "${D}${systemd_unitdir}/system"
+    done
+}
+
+FILES_${PN} += "${systemd_unitdir}"
diff --git a/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-appdata.mount b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-appdata.mount
new file mode 100644
index 00000000..dcc85a9b
--- /dev/null
+++ b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-appdata.mount
@@ -0,0 +1,16 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=Application Data File System
+DefaultDependencies=no
+Conflicts=umount.target
+Before=local-fs.target umount.target
+
+[Mount]
+What=/dev/disk/by-label/appdata
+Where=/run/mount/appdata
+
+[Install]
+WantedBy=local-fs.target
diff --git a/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-boot.mount b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-boot.mount
new file mode 100644
index 00000000..6157c25e
--- /dev/null
+++ b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-boot.mount
@@ -0,0 +1,16 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=Boot File System
+DefaultDependencies=no
+Conflicts=umount.target
+Before=local-fs.target umount.target
+
+[Mount]
+What=/dev/disk/by-label/boot
+Where=/run/mount/boot
+
+[Install]
+WantedBy=local-fs.target
diff --git a/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-devdata.mount b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-devdata.mount
new file mode 100644
index 00000000..71d74167
--- /dev/null
+++ b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-devdata.mount
@@ -0,0 +1,17 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=Device Data File System
+DefaultDependencies=no
+Conflicts=umount.target
+Before=local-fs.target umount.target
+
+[Mount]
+What=/dev/disk/by-label/devdata
+Where=/run/mount/devdata
+Options=ro
+
+[Install]
+WantedBy=local-fs.target
diff --git a/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-sysdata.mount b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-sysdata.mount
new file mode 100644
index 00000000..3941cbb0
--- /dev/null
+++ b/meta-ohos-core/recipes-core/x-mounts/x-mounts/run-mount-sysdata.mount
@@ -0,0 +1,16 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=System Data File System
+DefaultDependencies=no
+Conflicts=umount.target
+Before=local-fs.target umount.target
+
+[Mount]
+What=/dev/disk/by-label/sysdata
+Where=/run/mount/sysdata
+
+[Install]
+WantedBy=local-fs.target
-- 
GitLab