#!/bin/sh
-mountroot_fail()
+PREREQ=""
+
+prereqs()
{
- for i in `ls /dev/sd*`; do
- echo $i > /sys/fs/bcache/register_quiet
- done
-
-# for i in `ls /sys/dev/block/`; do
-# DEV=/bcache_dev
-#
-# mknod $DEV b `echo $i|sed -e 's/:/ /'`
-# echo $DEV > /sys/fs/bcache/register_quiet
-# rm $DEV
-# done
+ echo "$PREREQ"
}
case $1 in
+# get pre-requisites
prereqs)
- exit 0
- ;;
-mountfail)
- mountroot_fail
- exit 0
- ;;
+ prereqs
+ exit 0
+ ;;
esac
+# Nothing to do if ROOTFSTYPE is set to something other than bcachefs
+if [ -n "$ROOTFSTYPE" -a "$ROOTFSTYPE" != bcachefs ]; then
+ exit 0
+fi
+
+# source for resolve_device() and panic() functions
. /scripts/functions
-add_mountroot_fail_hook "30-bcache"
+# Resolve the root device (e.g. if root is specified by UUID)
+DEV=$(resolve_device "$ROOT")
+
+# Check if the root device needs unlocking:
+if bcachefs unlock -c $DEV >/dev/null 2>&1; then
+ if [ "$DEV" == "$ROOT" ]; then
+ echo "Please unlock $DEV:"
+ else
+ echo "Please unlock $DEV ($ROOT):"
+ fi
+
+ count=0
+ tries=3
+ while [ $tries -le 0 -o $count -lt $tries ]; do
+ if bcachefs unlock "$DEV"; then
+ echo "Bcachefs: $DEV successfully unlocked"
+ break
+ fi
+
+ let count++
+ done
+
+ if [ $tries -gt 0 -a $count -ge $tries ]; then
+ panic "Bcachefs: maximum number of tries exceeded for $DEV"
+ exit 1
+ fi
+fi
exit 0