generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 492
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 492
6 #
7 # Test the online filesystem label set/get ioctls
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 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32
33 _supported_fs generic
34 _require_scratch
35 _require_xfs_io_command "label"
36 _require_label_get_max
37
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount
40
41 # Make sure we can set & clear the label
42 $XFS_IO_PROG -c "label -s label.$seq" $SCRATCH_MNT
43 $XFS_IO_PROG -c "label" $SCRATCH_MNT
44
45 $XFS_IO_PROG -c "label -c" $SCRATCH_MNT
46 $XFS_IO_PROG -c "label" $SCRATCH_MNT
47
48 # And that userspace can see it now, while mounted
49 # NB: some blkid has trailing whitespace, filter it out here
50 $XFS_IO_PROG -c "label -s label.$seq" $SCRATCH_MNT
51 $XFS_IO_PROG -c "label" $SCRATCH_MNT
52 blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g"
53
54 # And that the it is still there when it's unmounted
55 _scratch_unmount
56 blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g"
57
58 # And that it persists after a remount
59 _scratch_mount
60 $XFS_IO_PROG -c "label" $SCRATCH_MNT
61
62 # And that a too-long label is rejected, beyond the interface max:
63 fs_label=$(perl -e "print 'l' x 257;")
64 $XFS_IO_PROG -c "label -s $fs_label" $SCRATCH_MNT
65
66 # And it succeeds right at the filesystem max:
67 max_label_len=$(_label_get_max)
68 fs_label=$(perl -e "print 'o' x $max_label_len;")
69 $XFS_IO_PROG -c "label -s $fs_label" $SCRATCH_MNT | sed -e 's/o\+/MAXLABEL/'
70
71 # And that it fails past the filesystem max:
72 let toolong_label_len=max_label_len+1
73 fs_label=$(perl -e "print 'o' x $toolong_label_len;")
74 $XFS_IO_PROG -c "label -s $fs_label " $SCRATCH_MNT
75
76 # success, all done
77 status=0
78 exit