From fafec575427d5dbac8333f6605e34f0384b73991 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 19 Sep 2021 10:29:51 +0200 Subject: cryptfs.bin: check, that raid is "clean" before mounting --- cryptfs.bin.in | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cryptfs.bin.in b/cryptfs.bin.in index 8465c70..4057651 100644 --- a/cryptfs.bin.in +++ b/cryptfs.bin.in @@ -189,22 +189,32 @@ do_mount() { fi inner_fs=$(inner_fs_to_mountorder "$1") + mount_dev=$(mount_details dev "$1") + + if md_dev=$(readlink -e "${mount_dev}" \ + | grep -x '/dev/md[0-9]\+'); then + if ! grep -qxF 'clean' '/sys/block/'"${md_dev##*/}"'/md/array_state'; then + >&2 printf '%s is not clean - will not mount\n' "${md_dev}" + exit 1 + fi + fi + case "$(mount_details fs "$1")" in 'ext'*) - if cryptsetup status $(mount_details dev "$1") \ + if cryptsetup status "${mount_dev}" \ | grep -q '^\s*mode:\s\+readonly$'; then e2fsck_option='-n' else e2fsck_option='-p' fi - e2fsck ${e2fsck_option} $(mount_details dev "$1") + e2fsck ${e2fsck_option} "${mount_dev}" ;; 'fuse.sshfs'|'fuse.ftps') local max_wait local host max_wait=$(($(date +%s)+120)) host=$( - mount_details dev "$1" | \ + echo "${mount_dev}" | \ sed 's>^\([^:@]*@\)\?\([^:@]\+\):\S*$>\2>' ) host=$(extract_ssh_host "${host}") -- cgit v1.2.3-54-g00ecf