xref: /freebsd/libexec/rc/rc.d/fsck (revision f99f0ee14e3af81c23150a6a340259ca8a33d01a)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb#
40696600cSBjoern A. Zeeb
50696600cSBjoern A. Zeeb# PROVIDE: fsck
60696600cSBjoern A. Zeeb# REQUIRE: swap
70696600cSBjoern A. Zeeb# KEYWORD: nojail
80696600cSBjoern A. Zeeb
90696600cSBjoern A. Zeeb. /etc/rc.subr
100696600cSBjoern A. Zeeb
110696600cSBjoern A. Zeebname="fsck"
120696600cSBjoern A. Zeebdesc="Run file system checks"
130696600cSBjoern A. Zeebstart_cmd="fsck_start"
140696600cSBjoern A. Zeebstop_cmd=":"
150696600cSBjoern A. Zeeb
160696600cSBjoern A. Zeebfsck_start()
170696600cSBjoern A. Zeeb{
180696600cSBjoern A. Zeeb	if [ "$autoboot" = no ]; then
190696600cSBjoern A. Zeeb		echo "Fast boot: skipping disk checks."
200696600cSBjoern A. Zeeb	elif [ ! -r /etc/fstab ]; then
210696600cSBjoern A. Zeeb		echo "Warning! No /etc/fstab: skipping disk checks."
220696600cSBjoern A. Zeeb	elif [ "$autoboot" = yes ]; then
230696600cSBjoern A. Zeeb		# During fsck ignore SIGQUIT
240696600cSBjoern A. Zeeb		trap : 3
250696600cSBjoern A. Zeeb
26325ebf37SJose Luis Duran		startmsg "Starting file system checks:"
27e9f87d29SLeandro Lupori		# Background fsck can only be run with -p
280696600cSBjoern A. Zeeb		if checkyesno background_fsck; then
290696600cSBjoern A. Zeeb			fsck -F -p
300696600cSBjoern A. Zeeb		else
31e9f87d29SLeandro Lupori			fsck ${fsck_flags}
320696600cSBjoern A. Zeeb		fi
330696600cSBjoern A. Zeeb
340696600cSBjoern A. Zeeb		err=$?
350696600cSBjoern A. Zeeb		if [ ${err} -eq 3 ]; then
360696600cSBjoern A. Zeeb			echo "Warning! Some of the devices might not be" \
370696600cSBjoern A. Zeeb			    "available; retrying"
380696600cSBjoern A. Zeeb			root_hold_wait
39325ebf37SJose Luis Duran			startmsg "Restarting file system checks:"
40e9f87d29SLeandro Lupori			# Background fsck can only be run with -p
410696600cSBjoern A. Zeeb			if checkyesno background_fsck; then
420696600cSBjoern A. Zeeb				fsck -F -p
430696600cSBjoern A. Zeeb			else
44e9f87d29SLeandro Lupori				fsck ${fsck_flags}
450696600cSBjoern A. Zeeb			fi
460696600cSBjoern A. Zeeb			err=$?
470696600cSBjoern A. Zeeb		fi
480696600cSBjoern A. Zeeb
490696600cSBjoern A. Zeeb		case ${err} in
500696600cSBjoern A. Zeeb		0)
510696600cSBjoern A. Zeeb			;;
520696600cSBjoern A. Zeeb		2)
530696600cSBjoern A. Zeeb			stop_boot
540696600cSBjoern A. Zeeb			;;
550696600cSBjoern A. Zeeb		4)
560696600cSBjoern A. Zeeb			echo "Rebooting..."
570696600cSBjoern A. Zeeb			reboot
580696600cSBjoern A. Zeeb			echo "Reboot failed; help!"
590696600cSBjoern A. Zeeb			stop_boot
600696600cSBjoern A. Zeeb			;;
610696600cSBjoern A. Zeeb		8|16)
620696600cSBjoern A. Zeeb			if checkyesno fsck_y_enable; then
630696600cSBjoern A. Zeeb				echo "File system preen failed, trying fsck -y ${fsck_y_flags}"
640696600cSBjoern A. Zeeb				fsck -y ${fsck_y_flags}
650696600cSBjoern A. Zeeb				case $? in
660696600cSBjoern A. Zeeb				0)
670696600cSBjoern A. Zeeb					;;
680696600cSBjoern A. Zeeb				*)
690696600cSBjoern A. Zeeb				echo "Automatic file system check failed; help!"
700696600cSBjoern A. Zeeb					stop_boot
710696600cSBjoern A. Zeeb					;;
720696600cSBjoern A. Zeeb				esac
730696600cSBjoern A. Zeeb			else
740696600cSBjoern A. Zeeb				echo "Automatic file system check failed; help!"
750696600cSBjoern A. Zeeb				stop_boot
760696600cSBjoern A. Zeeb			fi
770696600cSBjoern A. Zeeb			;;
780696600cSBjoern A. Zeeb		12)
790696600cSBjoern A. Zeeb			echo "Boot interrupted."
800696600cSBjoern A. Zeeb			stop_boot
810696600cSBjoern A. Zeeb			;;
820696600cSBjoern A. Zeeb		130)
830696600cSBjoern A. Zeeb			stop_boot
840696600cSBjoern A. Zeeb			;;
850696600cSBjoern A. Zeeb		*)
860696600cSBjoern A. Zeeb			echo "Unknown error ${err}; help!"
870696600cSBjoern A. Zeeb			stop_boot
880696600cSBjoern A. Zeeb			;;
890696600cSBjoern A. Zeeb		esac
900696600cSBjoern A. Zeeb	fi
910696600cSBjoern A. Zeeb}
920696600cSBjoern A. Zeeb
930696600cSBjoern A. Zeebload_rc_config $name
94*f99f0ee1SAlexander Leidinger
95*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj
96*f99f0ee1SAlexander Leidingerfsck_svcj="NO"
97*f99f0ee1SAlexander Leidinger
980696600cSBjoern A. Zeebrun_rc_command "$1"
99