On Fri, Dec 12, 2014 at 08:34:09AM +0000, Filipe David Manana wrote:
> Very simple solution.
>
> Do:
>
> 1) Create an empty file;
> 2) Use it as the backing file for a loop device;
> 3) Run mkfs.btrfs against the loop device;
> 4) Mount it;
> 5) Populate the fs;
> 6) Umount it;
> 7) Corrupt some nodes or leafs (by zeroing them out for e.g.);
> 8) Create a tarball from the backing file like this: ZX_OPT=-9 tar
> cJSvf foobar.tar.xz run.sh backing_file
> 9) Add the tarball to the fsck-tests directory;
> 10) Make the test run fsck against the backing file extracted from the
> tarball - fsck can operate against regular files, and not only against
> devices.
I made a few scripts that help to automate most of the steps (no
populating or fuzzing), attached.
#!/bin/sh -x
SIZE=64m
MKFS_OPTIONS=
MOUNT_OPTIONS=
mkdir -p mnt
truncate -s0 test.img
truncate -s$SIZE test.img
chmod a+w test.img
LODEV=$(sudo losetup -f --show test.img)
if [ $? -ne 0 ]; then
echo "Cannot create loop device"
exit 1
fi
mkfs.btrfs -f $MKFS_OPTIONS $LODEV
sudo mount ${MOUNT_OPTIONS:+-o "$MOUNT_OPTIONS"} $LODEV mnt || { echo "Cannot mount image"; exit 1; }
sudo touch mnt/.btrfs-test-image
echo "Mounted test.img as $LODEV into mnt/"
echo "Populate the image and run the next phase"
#!/bin/sh
LODEV=$(losetup -j test.img -O NAME | tail -n +2)
if [ $? -ne 0 ]; then
echo "Cannot detect loop devices for test.img"
exit 1
fi
echo $LODEV
for dev in $LODEV; do
sudo umount $dev
sudo losetup -d $dev
done
echo "Unmounted and all loop devices detached"
echo "Corrupt the image now."
#!/bin/sh -x
if ! [ -f test.img ]; then
echo "No image found"
exit 1
fi
export ZX_OPT
ZX_OPT=-9 tar cJSvf image.tar.xz --owner=root --group=root test.img
echo "Created image.tar.gz from test.img"
echo "Link it to the test dir, run 'make test'"