FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/bin/sh # # $FreeBSD: src/etc/rc.d/bgfsck,v 1.8.8.1 2009/04/15 03:14:26 kensmith Exp $ # # Modified by Volker Theile (votdev@gmx.de) # # PROVIDE: bgfsck # REQUIRE: cron syslogd # KEYWORD: nojail . /etc/rc.subr . /etc/configxml.subr name="background-fsck" rcvar="background_fsck" start_cmd="bgfsck_start" stop_cmd=":" bgfsck_start () { if [ -z "${rc_force}" ]; then background_fsck_delay=${background_fsck_delay:=0} else background_fsck_delay=0 fi if [ ${background_fsck_delay} -lt 0 ]; then echo "Background file system checks delayed indefinitly" return 0 fi bgfsck_msg='Starting background file system checks' if [ "${background_fsck_delay}" -gt 0 ]; then bgfsck_msg="${bgfsck_msg} in ${background_fsck_delay} seconds" fi if [ -z "${rc_force}" ]; then echo "${bgfsck_msg}." fi /usr/local/bin/xml sel -t -m "//mounts/mount[fstype = 'ufs' or fstype = 'msdosfs' or fstype = 'ext2fs']" \ -v "concat(fstype,' ',devicespecialfile,' ',mdisk)" \ -i "count(fsck) > 0" -o " 1" -b \ -i "count(fsck) = 0" -o " 0" -b \ -i "position() != last()" -n -b \ ${configxml_file} | /usr/local/bin/xml unesc | \ while read _fstype _devicespecialfile _mdisk _fsck; do # Check if fsck is enabled if [ "0" = "${_fsck}" ]; then continue fi # Check if block device exists if [ ! -e "${_devicespecialfile}" ]; then continue fi # Skip encrypted disks _encrypted=`configxml_get_count "//geli/vdisk[devicespecialfile = '${_mdisk}']"` if [ 0 -lt ${_encrypted} ]; then continue fi (sleep ${background_fsck_delay}; nice -4 fsck -B -p -t ${_fstype} ${_devicespecialfile}) 2>&1 | \ logger -p daemon.notice -t fsck & done } load_rc_config $name run_rc_command "$1"