#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/rc-scripts/init.d/checkfs,v 1.42.4.7 2005/05/17 00:04:04 vapier Exp $

depend() {
	need checkroot modules
}

start() {
	local retval=0

	# Start RAID/LVM/EVMS/DM volumes for /usr, /var, etc.
	# NOTE: this should be done *before* mounting anything
	[[ -z ${CDBOOT} ]] && start_volumes

	# Setup dm-crypt mappings if any
	start_addon dm-crypt

	if [[ -f /fastboot ]] || [[ -n ${CDBOOT} ]] ; then
		rm -f /fastboot
	else
		ebegin "Checking all filesystems"
		if [[ -f /forcefsck ]] ; then
			ewarn "A full fsck has been forced"
			fsck -C -R -A -a -f
			retval=$?
			rm -f /forcefsck
		else
			fsck -C -T -R -A -a
			retval=$?
		fi
		if [[ ${retval} -eq 0 ]] ; then
			eend 0
		elif [[ ${retval} -ge 1 && ${retval} -le 3 ]] ; then
			ewend 1 "Filesystem errors corrected."
			# Everything should be ok, so return a pass
			return 0
		else
			if [[ ${RC_FORCE_AUTO} == "yes" ]] ; then
				eend 2 "Fsck could not correct all errors, rerunning"
				fsck -C -T -R -A -a -y
				retval=$?
			fi

			if [[ ${retval} -gt 3 ]] ; then
				eend 2 "Fsck could not correct all errors, manual repair needed"
				/sbin/sulogin ${CONSOLE}
			fi
		fi
	fi
}

# vim:ts=4
