fsck revision 124618
1284285Sjkim#!/bin/sh
2110010Smarkm#
3110010Smarkm# $NetBSD: fsck,v 1.2 2001/06/18 06:42:35 lukem Exp $
4142429Snectar# $FreeBSD: head/etc/rc.d/fsck 124618 2004-01-17 10:40:45Z mtm $
5110010Smarkm#
6110010Smarkm
7110010Smarkm# PROVIDE: fsck
8110010Smarkm# REQUIRE: localswap
9110010Smarkm# KEYWORD: FreeBSD
10110010Smarkm
11110010Smarkm. /etc/rc.subr
12110010Smarkm
13110010Smarkmname="fsck"
14110010Smarkmstart_cmd="fsck_start"
15110010Smarkmstop_cmd=":"
16110010Smarkm
17110010Smarkmstop_boot()
18110010Smarkm{
19110010Smarkm	#	Terminate the process (which may include the parent /etc/rc)
20215698Ssimon	#	if booting directly to multiuser mode.
21215698Ssimon	#
22215698Ssimon	if [ "$autoboot" = yes ]; then
23215698Ssimon		kill -TERM $$
24215698Ssimon	fi
25110010Smarkm	exit 1
26110010Smarkm}
27110010Smarkm
28110010Smarkmfsck_start()
29110010Smarkm{
30110010Smarkm	if [ "$autoboot" = no ]; then
31110010Smarkm		echo "Fast boot: skipping disk checks."
32110010Smarkm	elif [ "$autoboot" = yes ]; then
33110010Smarkm					# During fsck ignore SIGQUIT
34110010Smarkm		trap : 3
35110010Smarkm
36110010Smarkm		echo "Starting file system checks:"
37110010Smarkm		if checkyesno background_fsck; then
38110010Smarkm			fsck -F -p
39110010Smarkm		else
40110010Smarkm			fsck -p
41276864Sjkim		fi
42276864Sjkim		;;
43110010Smarkm
44110010Smarkm		case $? in
45215698Ssimon		0)
46215698Ssimon			;;
47215698Ssimon		2)
48215698Ssimon			stop_boot
49142429Snectar			;;
50215698Ssimon		4)
51142429Snectar			echo "Rebooting..."
52142429Snectar			reboot
53276864Sjkim			echo "Reboot failed; help!"
54276864Sjkim			stop_boot
55276864Sjkim			;;
56110010Smarkm		8)
57276864Sjkim			if checkyesno fsck_y_enable; then
58276864Sjkim				echo "File system preen failed, trying fsck -y."
59276864Sjkim				fsck -y
60276864Sjkim				case $? in
61276864Sjkim				0)
62276864Sjkim					;;
63215698Ssimon				*)
64276864Sjkim				echo "Automatic file system check failed; help!"
65276864Sjkim					stop_boot
66276864Sjkim					;;
67276864Sjkim				esac
68276864Sjkim			else
69215698Ssimon				echo "Automatic file system check failed; help!"
70276864Sjkim				stop_boot
71110010Smarkm			fi
72110010Smarkm			;;
73110010Smarkm		12)
74110010Smarkm			echo "Boot interrupted."
75110010Smarkm			stop_boot
76110010Smarkm			;;
77110010Smarkm		130)
78110010Smarkm			stop_boot
79110010Smarkm			;;
80110010Smarkm		*)
81110010Smarkm			echo "Unknown error; help!"
82110010Smarkm			stop_boot
83110010Smarkm			;;
84110010Smarkm		esac
85110010Smarkm	fi
86110010Smarkm}
87110010Smarkm
88110010Smarkmload_rc_config $name
89110010Smarkmrun_rc_command "$1"
90110010Smarkm