3 # Copyright (c) 2015 Alan Somers
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 atf_set "descr" "fstyp(8) should detect cd9660 filesystems"
34 atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory
35 atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir
36 atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
37 atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img
40 atf_test_case cd9660_label
42 atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem"
45 atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory
46 atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir
47 atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
48 # Note: cd9660 labels are always upper case
49 atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img
54 atf_set "descr" "fstyp(8) should fail on a directory"
57 atf_check -s exit:0 mkdir dir
58 atf_check -s exit:1 -e match:"not a disk" fstyp dir
63 atf_set "descr" "fstyp(8) should fail on an empty file"
66 atf_check -s exit:0 touch empty
67 atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty
72 atf_set "descr" "fstyp(8) can detect ext2 filesystems"
75 bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img
76 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img
77 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img
82 atf_set "descr" "fstyp(8) can detect ext3 filesystems"
85 bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img
86 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img
87 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img
92 atf_set "descr" "fstyp(8) can detect ext4 filesystems"
95 bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img
96 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img
97 atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img
100 atf_test_case ext4_label
102 atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem"
105 bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img
106 atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img
111 atf_set "descr" "fstyp(8) can detect FAT12 filesystems"
114 atf_check -s exit:0 truncate -s 64m msdos.img
115 atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img
116 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
117 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
122 atf_set "descr" "fstyp(8) can detect FAT16 filesystems"
125 atf_check -s exit:0 truncate -s 64m msdos.img
126 atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img
127 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
128 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
133 atf_set "descr" "fstyp(8) can detect FAT32 filesystems"
136 atf_check -s exit:0 truncate -s 64m msdos.img
137 atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \
139 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
140 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
143 atf_test_case fat32_label
145 atf_set "descr" "fstyp(8) can read the label on an msdos filesystem"
148 atf_check -s exit:0 truncate -s 64m msdos.img
149 atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \
151 atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
152 # Note: msdos labels are always upper case
153 atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img
158 atf_set "descr" "fstyp(8) can detect ntfs filesystems"
161 bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img
162 atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img
163 atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img
166 atf_test_case ntfs_with_label
167 ntfs_with_label_head() {
168 atf_set "descr" "fstyp(8) can read labels on ntfs filesystems"
170 ntfs_with_label_body() {
171 bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img
172 atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img
173 atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img
178 atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems"
181 atf_check -s exit:0 mkdir dir
182 atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir
183 atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
184 atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
189 atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems"
192 atf_check -s exit:0 mkdir dir
193 atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir
194 atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
195 atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
198 atf_test_case ufs2_label
200 atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem"
203 atf_check -s exit:0 mkdir dir
204 atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir
205 atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img
208 atf_test_case ufs_on_device cleanup
209 ufs_on_device_head() {
210 atf_set "descr" "fstyp(8) should work on device nodes"
211 atf_set "require.user" "root"
213 ufs_on_device_body() {
214 mdconfig -a -t swap -s 64m > mdname
216 if [ -z "$md" ]; then
217 atf_fail "Failed to create md(4) device"
219 atf_check -s exit:0 -o ignore newfs -L foo /dev/$md
220 atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md
221 atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md
223 ufs_on_device_cleanup() {
225 if [ -n "$md" ]; then
232 atf_set "descr" "fstyp(8) should fail on a zero-filled file"
235 atf_check -s exit:0 truncate -s 256m zeros
236 atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros
240 atf_init_test_cases() {
241 atf_add_test_case cd9660
242 atf_add_test_case cd9660_label
243 atf_add_test_case dir
244 atf_add_test_case empty
245 atf_add_test_case ext2
246 atf_add_test_case ext3
247 atf_add_test_case ext4
248 atf_add_test_case ext4_label
249 atf_add_test_case fat12
250 atf_add_test_case fat16
251 atf_add_test_case fat32
252 atf_add_test_case fat32_label
253 atf_add_test_case ntfs
254 atf_add_test_case ntfs_with_label
255 atf_add_test_case ufs1
256 atf_add_test_case ufs2
257 atf_add_test_case ufs2_label
258 atf_add_test_case ufs_on_device
259 atf_add_test_case zeros