Home | History | Annotate | Line # | Download | only in rc.d
      1 #!/bin/sh
      2 #
      3 # $NetBSD: fsck_root,v 1.6 2011/09/20 12:13:21 apb Exp $
      4 #
      5 
      6 # PROVIDE: fsck_root
      7 
      8 $_rc_subr_loaded . /etc/rc.subr
      9 
     10 name="fsck_root"
     11 start_cmd="fsck_root_start"
     12 stop_cmd=":"
     13 fstab_file=/etc/fstab
     14 
     15 fsck_root_start()
     16 {
     17 	if [ -e /fastboot ]; then
     18 		echo "Fast boot: skipping disk checks."
     19 		return
     20 	fi
     21 	trap : 2 		# Ignore SIGINT, SIGQUIT, so we
     22 	trap : 3		# enter single-user mode on failure.
     23 
     24 	# Do nothing if root file system has fs_passno=0 in /etc/fstab,
     25 	# or if root file system is not mentioned in /etc/fstab, or if
     26 	# root file system seems to be a network mount.
     27 	root_in_fstab=false
     28 	while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno
     29 	do
     30 		# skip comment or blank line
     31 		case "${fs_spec}" in
     32 		\#*|'') continue ;;
     33 		esac
     34 
     35 		# fs_freq and fs_passno default to 0 if not specified
     36 		: ${fs_freq:=0} ${fs_passno:=0}
     37 
     38 		case "${fs_file},${fs_passno}" in
     39 		/,0)
     40 			echo "Not checking /: fs_passno = 0 in ${fstab_file}"
     41 			return
     42 			;;
     43 		/,*)
     44 			root_in_fstab=true
     45 			case "${fs_spec}" in
     46 			*:*)
     47 				echo "Not checking /: network mount"
     48 				return
     49 				;;
     50 			esac
     51 			;;
     52 		esac
     53 	done < "${fstab_file}"
     54 
     55 	if $root_in_fstab; then
     56 		echo "Starting root file system check:"
     57 		fsck $fsck_flags /
     58 		handle_fsck_error "$?"
     59 		return
     60 	else
     61 		echo "Not checking /: not listed in ${fstab_file}"
     62 	fi
     63 }
     64 
     65 load_rc_config $name
     66 run_rc_command "$1"
     67