diff mbox series

[isar-cip-core,v2,1/2] fix: Check return code value of e2fsck

Message ID 20240819125138.1543399-2-Quirin.Gylstorff@siemens.com (mailing list archive)
State Accepted
Headers show
Series fixes overlay with | expand

Commit Message

Gylstorff Quirin Aug. 19, 2024, 12:51 p.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

e2fsck returns a 1 in case of a recoverable file system error.
In that case we execute erroneously the recovery script and mke2fs
ask if the filesystem should be overwritten.

The issue was introduced with:

8644fb1 initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE

This fixes issue https://gitlab.com/cip-project/cip-core/isar-cip-core/-/issues/113

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 .../initramfs-overlay-hook/files/overlay.script.tmpl        | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
index c655a4f..72d1396 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
@@ -40,7 +40,11 @@  partition_fstype=$(get_fstype "${ovl_partition_device}")
 if ! mountpoint -q "${rootmnt}${storage_mount_point}"; then
 	case $partition_fstype in
 	ext*)
-		if ! e2fsck -p -f "$ovl_partition_device" && [ -x "$ovl_recovery_script" ]; then
+		e2fsck -p -f "$ovl_partition_device"
+		fsck_ret="$?"
+		# e2fsck returns a 1 in case of repairing the file system
+		# https://man7.org/linux/man-pages/man8/e2fsck.8.html#EXIT_CODE
+		if [ "$fsck_ret" -gt "1" ]  && [ -x "$ovl_recovery_script" ]; then
 			"$ovl_recovery_script" "$partition_fstype" "$ovl_partition_device"
 		fi
 		;;