xref: /freebsd/libexec/rc/rc.d/fsck (revision 0957b409)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: fsck
7# REQUIRE: swap
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="fsck"
13desc="Run file system checks"
14start_cmd="fsck_start"
15stop_cmd=":"
16
17fsck_start()
18{
19	if [ "$autoboot" = no ]; then
20		echo "Fast boot: skipping disk checks."
21	elif [ ! -r /etc/fstab ]; then
22		echo "Warning! No /etc/fstab: skipping disk checks."
23	elif [ "$autoboot" = yes ]; then
24		# During fsck ignore SIGQUIT
25		trap : 3
26
27		check_startmsgs && echo "Starting file system checks:"
28		if checkyesno background_fsck; then
29			fsck -F -p
30		else
31			fsck -p
32		fi
33
34		err=$?
35		if [ ${err} -eq 3 ]; then
36			echo "Warning! Some of the devices might not be" \
37			    "available; retrying"
38			root_hold_wait
39			check_startmsgs && echo "Restarting file system checks:"
40			if checkyesno background_fsck; then
41				fsck -F -p
42			else
43				fsck -p
44			fi
45			err=$?
46		fi
47
48		case ${err} in
49		0)
50			;;
51		2)
52			stop_boot
53			;;
54		4)
55			echo "Rebooting..."
56			reboot
57			echo "Reboot failed; help!"
58			stop_boot
59			;;
60		8|16)
61			if checkyesno fsck_y_enable; then
62				echo "File system preen failed, trying fsck -y ${fsck_y_flags}"
63				fsck -y ${fsck_y_flags}
64				case $? in
65				0)
66					;;
67				*)
68				echo "Automatic file system check failed; help!"
69					stop_boot
70					;;
71				esac
72			else
73				echo "Automatic file system check failed; help!"
74				stop_boot
75			fi
76			;;
77		12)
78			echo "Boot interrupted."
79			stop_boot
80			;;
81		130)
82			stop_boot
83			;;
84		*)
85			echo "Unknown error ${err}; help!"
86			stop_boot
87			;;
88		esac
89	fi
90}
91
92load_rc_config $name
93run_rc_command "$1"
94