check: exit with exit code 1 after printing the usage message
[xfstests-dev.git] / common / casefold
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2019 Collabora, Ltd.  All Rights Reserved.
3 #
4 # Common functions for testing filename casefold feature
5
6 _has_casefold_kernel_support()
7 {
8         case $FSTYP in
9         ext4)
10                 test -f '/sys/fs/ext4/features/casefold'
11                 ;;
12         f2fs)
13                 test -f '/sys/fs/f2fs/features/casefold'
14                 ;;
15         *)
16                 # defaults to unsupported
17                 false
18                 ;;
19         esac
20 }
21
22 _require_scratch_casefold()
23 {
24         if ! _has_casefold_kernel_support ; then
25                 _notrun "$FSTYP does not support casefold feature"
26         fi
27
28         if ! _scratch_mkfs_casefold &>>seqres.full; then
29                 _notrun "$FSTYP userspace tools do not support casefold"
30         fi
31
32         # Make sure the kernel can mount a filesystem with the encoding
33         # defined by the userspace tools.  This will fail if
34         # the userspace tool used a more recent encoding than the one
35         # supported in kernel space.
36         if ! _try_scratch_mount &>>seqres.full; then
37                 _notrun "kernel can't mount filesystem with the encoding set by userspace"
38         fi
39         _scratch_unmount
40
41         # utilities used by casefold
42         _require_command "$CHATTR_PROG" chattr
43         _require_command "$LSATTR_PROG" lsattr
44 }
45
46 _scratch_mkfs_casefold()
47 {
48         case $FSTYP in
49         ext4)
50                 _scratch_mkfs -O casefold $*
51                 ;;
52         f2fs)
53                 _scratch_mkfs -C utf8 $*
54                 ;;
55         *)
56                 _notrun "Don't know how to mkfs with casefold support on $FSTYP"
57                 ;;
58         esac
59 }
60
61 _scratch_mkfs_casefold_strict()
62 {
63         case $FSTYP in
64         ext4)
65                 _scratch_mkfs -O casefold -E encoding_flags=strict
66                 ;;
67         f2fs)
68                 _scratch_mkfs -C utf8:strict
69                 ;;
70         *)
71                 _notrun "Don't know how to mkfs with casefold-strict support on $FSTYP"
72                 ;;
73         esac
74 }
75
76 # To get the exact disk name, we need some method that does a
77 # getdents() on the parent directory, such that we don't get
78 # normalized/casefolded results.  'Find' works ok.
79 _casefold_check_exact_name()
80 {
81         local basedir=$1
82         local exact_name=$2
83         find ${basedir} | grep -q ${exact_name}
84 }
85
86 _casefold_set_attr()
87 {
88         $CHATTR_PROG +F "${1}"
89 }
90
91 _casefold_unset_attr()
92 {
93         $CHATTR_PROG -F "${1}"
94 }
95
96 _casefold_lsattr_dir()
97 {
98         if $LSATTR_PROG -ld "${1}" | grep -q Casefold ; then
99                 echo "${1} Casefold"
100         else
101                 echo "${1}"
102         fi
103 }