handle_ext2_rc () {
	case $1 in
	0) ret=0;;
	1) ret=0;;
	2) ret=2;;
	4) ret=1;;
	*) ret=4::
	esac
	exit ${ret}
}

handle_vfat_rc () {
	case $1 in
	0) ret=0;;
	1) ret=0;;
	*) ret=4::
	esac
	exit ${ret}
}

if [ $# -ne 1 ]
then exit 8
fi
cd /dev
if [ `grep -c $1 /etc/mtab` -gt 0 ]
then exit 32
fi
mkdir /mnt/tmp_partverif
mount $1 /mnt/tmp_partverif
if [ $? -ne 0 ]
then 
	rmdir /mnt/tmp_partverif
	exit 16
fi
line=`grep "$1 " /etc/mtab`
umount /mnt/tmp_partverif
rmdir /mnt/tmp_partverif
fstype=`echo ${line} | cut -d' ' -f3`
case ${fstype} in
ext2 | ext3) echo check ${fstype} filesystem on $1; fsck.ext2 -y $1; handle_ext2_rc $? ;;
vfat) echo check vfat filesystem on $1; dosfsck -a $1 ; handle_vfat_rc $? ;;
*) exit 64;;
esac
