set -x
SIZE_BYTES=$((1024 * 1024 * 10))
IMG=$(mktemp --suffix=-gvfs-test)
dd if=/dev/zero of=${IMG} bs=1 count=1 seek="${SIZE_BYTES}"
LOOP_DEV=$(sudo losetup --show -f "${IMG}")
sudo mkfs.ext2 -b 4096 "${LOOP_DEV}" "$((SIZE_BYTES / 4096))"
TMP_MOUNT=$(mktemp -d --suffix=-gvfs-test)
for i in $(seq 20); do
 if ! ( sudo bash -c "mount ${LOOP_DEV} ${TMP_MOUNT} && umount ${TMP_MOUNT}" ); then
   break
 fi
 echo $i
 sleep 1
done
sudo umount ${TMP_MOUNT}
sudo losetup -d ${LOOP_DEV}
rm -rf ${IMG} ${TMP_MOUNT}
