+[ -z "`which $GETFATTR`" ] && echo "$0: $GETFATTR not found" && exit 5
+[ -z "`which $SETFATTR`" ] && echo "$0: $SETFATTR not found" && exit 6
+
+LUSTRE=${LUSTRE:-`dirname $0`/..}
+. $LUSTRE/tests/test-framework.sh
+init_test_env $@
+. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
+
+remote_mds && skip "remote MDS" && exit 0
+remote_ost && skip "remote OST" && exit 0
+
+# if nothing mounted, don't nuke MOUNT variable needed in llmount.sh
+WAS_MOUNTED=$(mounted_lustre_filesystems | head -1)
+if [ -z "$WAS_MOUNTED" ]; then
+ # This code doesn't handle multiple mounts well, so nuke MOUNT2 variable
+ MOUNT2="" sh llmount.sh
+ MOUNT=$(mounted_lustre_filesystems)
+ [ -z "$MOUNT" ] && echo "NAME=$NAME not mounted" && exit 2
+else
+ MOUNT=${WAS_MOUNTED}
+fi
+
+DIR=${DIR:-$MOUNT/$TESTNAME}
+[ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 3
+
+if [ "$WAS_MOUNTED" ]; then
+ LFSCK_SETUP=no
+ MAX_ERR=4 # max expected error from e2fsck
+fi
+
+get_mnt_devs() {
+ DEVS=`lctl get_param -n $1.*.mntdev`
+ for DEV in $DEVS; do
+ case $DEV in
+ *loop*) losetup $DEV | sed -e "s/.*(//" -e "s/).*//" ;;
+ *) echo $DEV ;;
+ esac
+ done
+}
+
+if [ "$LFSCK_SETUP" != "no" ]; then
+ #Create test directory
+ # -- can't remove the mountpoint...
+ [ -z "$DIR" ] && rm -rf $DIR/*
+ mkdir -p $DIR
+ OSTCOUNT=`$LFIND $MOUNT | grep -c "^[0-9]*: "`
+
+ # Create some files on the filesystem
+ for d in `seq -f d%g $NUMDIRS`; do
+ echo "creating files in $DIR/$d"
+ for e in `seq -f d%g $NUMDIRS`; do
+ mkdir -p $DIR/$d/$e
+ for f in `seq -f test%g $NUMDIRS`; do
+ cp /etc/fstab $DIR/$d/$e/$f ||exit 5
+ done