btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / ext4 / 042
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. ext4/042 (was shared/289)
6 #
7 # Test overhead & df output for extN filesystems
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29
30 # Modify as appropriate.
31 _supported_fs ext2 ext3 ext4
32 _require_scratch
33
34 rm -f $seqres.full
35
36 _scratch_mkfs >> $seqres.full 2>&1
37
38 # Get the honest truth about block counts straight from metadata on disk
39 TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
40                 | awk '/Block count:/{print $3}'`
41
42 FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
43                 | awk '/Free blocks:/{print $3}'`
44
45 OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
46
47 #  bsddf|minixdf
48 #         Set the behaviour  for  the  statfs  system  call.  The  minixdf
49 #         behaviour is to return in the f_blocks field the total number of
50 #         blocks of the filesystem, while the bsddf  behaviour  (which  is
51 #         the default) is to subtract the overhead blocks used by the ext2
52 #         filesystem and not available for file storage.
53
54 # stat -f output looks like this; we get f_blocks from that, which
55 # varies depending on the df mount options used below:
56
57 #   File: "/mnt/test"
58 #    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
59 # Block size: 4096       Fundamental block size: 4096
60 # Blocks: Total: 5162741    Free: 5118725    Available: 4856465
61 # Inodes: Total: 1313760    Free: 1313749
62
63 _scratch_mount "-o minixdf"
64 MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
65 _scratch_unmount
66
67 _scratch_mount "-o bsddf"
68 BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
69 _scratch_unmount
70
71 # Echo data to $seqres.full for analysis
72 echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seqres.full
73 echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seqres.full
74 echo "BSD free blocks $BSD_F_BLOCKS" >> $seqres.full
75
76 # minix should be exactly equal (hence tolerance of 0)
77 _within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v
78 # bsd should be within ... we'll say 1% for some slop
79 _within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
80
81 # success, all done
82 status=0
83 exit