17bdfc3b7SEnji Cooper#
27bdfc3b7SEnji Cooper# Copyright 2015 EMC Corp.
37bdfc3b7SEnji Cooper# All rights reserved.
47bdfc3b7SEnji Cooper#
57bdfc3b7SEnji Cooper# Redistribution and use in source and binary forms, with or without
67bdfc3b7SEnji Cooper# modification, are permitted provided that the following conditions are
77bdfc3b7SEnji Cooper# met:
87bdfc3b7SEnji Cooper#
97bdfc3b7SEnji Cooper# * Redistributions of source code must retain the above copyright
107bdfc3b7SEnji Cooper#   notice, this list of conditions and the following disclaimer.
117bdfc3b7SEnji Cooper# * Redistributions in binary form must reproduce the above copyright
127bdfc3b7SEnji Cooper#   notice, this list of conditions and the following disclaimer in the
137bdfc3b7SEnji Cooper#   documentation and/or other materials provided with the distribution.
147bdfc3b7SEnji Cooper#
157bdfc3b7SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
167bdfc3b7SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
177bdfc3b7SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
187bdfc3b7SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
197bdfc3b7SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
207bdfc3b7SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
217bdfc3b7SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
227bdfc3b7SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
237bdfc3b7SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
247bdfc3b7SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
257bdfc3b7SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
267bdfc3b7SEnji Cooper#
277bdfc3b7SEnji Cooper# $FreeBSD$
287bdfc3b7SEnji Cooper#
297bdfc3b7SEnji Cooper
30fc2b0536SEnji Cooper# A note on specs:
31fc2b0536SEnji Cooper# - A copy of the ISO-9660 spec can be found here:
32fc2b0536SEnji Cooper#   http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
33fc2b0536SEnji Cooper# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
34fc2b0536SEnji Cooper#   of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
35fc2b0536SEnji Cooper#   here:
36fc2b0536SEnji Cooper#   http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf
377bdfc3b7SEnji Cooper
387bdfc3b7SEnji CooperMAKEFS="makefs -t cd9660"
39fc2b0536SEnji CooperMOUNT="mount_cd9660"
407bdfc3b7SEnji Cooper
41fc2b0536SEnji Cooper. "$(dirname "$0")/makefs_tests_common.sh"
42fc2b0536SEnji Cooper
43fc2b0536SEnji Coopercommon_cleanup()
44fc2b0536SEnji Cooper{
45fc2b0536SEnji Cooper	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
46fc2b0536SEnji Cooper		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
47fc2b0536SEnji Cooper		return
48fc2b0536SEnji Cooper	fi
49fc2b0536SEnji Cooper
50fc2b0536SEnji Cooper	umount -f /dev/$test_md_device || :
51fc2b0536SEnji Cooper	mdconfig -d -u $test_md_device || :
52fc2b0536SEnji Cooper}
53fc2b0536SEnji Cooper
54fc2b0536SEnji Coopercheck_base_iso9660_image_contents()
55fc2b0536SEnji Cooper{
56fc2b0536SEnji Cooper	# Symlinks are treated like files when rockridge support isn't
57fc2b0536SEnji Cooper	# specified
58fc2b0536SEnji Cooper	check_image_contents "$@" -X c
59fc2b0536SEnji Cooper
60fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c
61fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c
62fc2b0536SEnji Cooper}
63fc2b0536SEnji Cooper
64fc2b0536SEnji Cooperatf_test_case D_flag cleanup
65fc2b0536SEnji CooperD_flag_body()
66fc2b0536SEnji Cooper{
67fc2b0536SEnji Cooper	atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839"
68fc2b0536SEnji Cooper
69fc2b0536SEnji Cooper	create_test_inputs
70fc2b0536SEnji Cooper
71fc2b0536SEnji Cooper	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
72fc2b0536SEnji Cooper	    mtree -cp $TEST_INPUTS_DIR
73fc2b0536SEnji Cooper	atf_check -e empty -o not-empty -s exit:0 \
74fc2b0536SEnji Cooper	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
75fc2b0536SEnji Cooper
76fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
77fc2b0536SEnji Cooper	    cp $TEST_SPEC_FILE spec2.mtree
78fc2b0536SEnji Cooper	atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \
79fc2b0536SEnji Cooper	    cat $TEST_SPEC_FILE spec2.mtree
80fc2b0536SEnji Cooper
81fc2b0536SEnji Cooper	atf_check -e empty -o not-empty -s not-exit:0 \
82fc2b0536SEnji Cooper	    $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
83fc2b0536SEnji Cooper	atf_check -e empty -o not-empty -s exit:0 \
84fc2b0536SEnji Cooper	    $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
85fc2b0536SEnji Cooper}
86fc2b0536SEnji CooperD_flag_cleanup()
87fc2b0536SEnji Cooper{
88fc2b0536SEnji Cooper	common_cleanup
89fc2b0536SEnji Cooper}
90fc2b0536SEnji Cooper
91fc2b0536SEnji Cooperatf_test_case F_flag cleanup
92fc2b0536SEnji CooperF_flag_body()
93fc2b0536SEnji Cooper{
94fc2b0536SEnji Cooper	create_test_inputs
95fc2b0536SEnji Cooper
96fc2b0536SEnji Cooper	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
97fc2b0536SEnji Cooper	    mtree -cp $TEST_INPUTS_DIR
98fc2b0536SEnji Cooper
99fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
100fc2b0536SEnji Cooper	    $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
101fc2b0536SEnji Cooper
102fc2b0536SEnji Cooper	mount_image
103fc2b0536SEnji Cooper	check_base_iso9660_image_contents
104fc2b0536SEnji Cooper}
105fc2b0536SEnji CooperF_flag_cleanup()
106fc2b0536SEnji Cooper{
107fc2b0536SEnji Cooper	common_cleanup
108fc2b0536SEnji Cooper}
109fc2b0536SEnji Cooper
110fc2b0536SEnji Cooperatf_test_case from_mtree_spec_file cleanup
111fc2b0536SEnji Cooperfrom_mtree_spec_file_body()
112fc2b0536SEnji Cooper{
113fc2b0536SEnji Cooper	create_test_inputs
114fc2b0536SEnji Cooper
115fc2b0536SEnji Cooper	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
116fc2b0536SEnji Cooper	    mtree -c -k type,link,size -p $TEST_INPUTS_DIR
117fc2b0536SEnji Cooper	cd $TEST_INPUTS_DIR
118fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
119fc2b0536SEnji Cooper	    $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
120fc2b0536SEnji Cooper	cd -
121fc2b0536SEnji Cooper
122fc2b0536SEnji Cooper	mount_image
123fc2b0536SEnji Cooper	check_base_iso9660_image_contents
124fc2b0536SEnji Cooper}
125fc2b0536SEnji Cooperfrom_mtree_spec_file_cleanup()
126fc2b0536SEnji Cooper{
127fc2b0536SEnji Cooper	common_cleanup
128fc2b0536SEnji Cooper}
129fc2b0536SEnji Cooper
130fc2b0536SEnji Cooperatf_test_case from_multiple_dirs cleanup
131fc2b0536SEnji Cooperfrom_multiple_dirs_body()
132fc2b0536SEnji Cooper{
133fc2b0536SEnji Cooper	test_inputs_dir2=$TMPDIR/inputs2
134fc2b0536SEnji Cooper
135fc2b0536SEnji Cooper	create_test_inputs
136fc2b0536SEnji Cooper
137fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2
138fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
139fc2b0536SEnji Cooper	    touch $test_inputs_dir2/multiple_dirs_test_file
140fc2b0536SEnji Cooper
141fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
142fc2b0536SEnji Cooper	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
143fc2b0536SEnji Cooper
144fc2b0536SEnji Cooper	mount_image
145fc2b0536SEnji Cooper	check_base_iso9660_image_contents -d $test_inputs_dir2
146fc2b0536SEnji Cooper}
147fc2b0536SEnji Cooperfrom_multiple_dirs_cleanup()
148fc2b0536SEnji Cooper{
149fc2b0536SEnji Cooper	common_cleanup
150fc2b0536SEnji Cooper}
151fc2b0536SEnji Cooper
152fc2b0536SEnji Cooperatf_test_case from_single_dir cleanup
153fc2b0536SEnji Cooperfrom_single_dir_body()
1547bdfc3b7SEnji Cooper{
1557bdfc3b7SEnji Cooper	create_test_inputs
1567bdfc3b7SEnji Cooper
1577bdfc3b7SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
1587bdfc3b7SEnji Cooper	    $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR
1597bdfc3b7SEnji Cooper
160fc2b0536SEnji Cooper	mount_image
161fc2b0536SEnji Cooper	check_base_iso9660_image_contents
162fc2b0536SEnji Cooper}
163fc2b0536SEnji Cooperfrom_single_dir_cleanup()
164fc2b0536SEnji Cooper{
165fc2b0536SEnji Cooper	common_cleanup
166fc2b0536SEnji Cooper}
167fc2b0536SEnji Cooper
168fc2b0536SEnji Cooperatf_test_case o_flag_allow_deep_trees cleanup
169fc2b0536SEnji Coopero_flag_allow_deep_trees_body()
170fc2b0536SEnji Cooper{
171fc2b0536SEnji Cooper	create_test_inputs
172fc2b0536SEnji Cooper
173fc2b0536SEnji Cooper	# Make sure the "more than 8 levels deep" requirement is met.
174fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
175fc2b0536SEnji Cooper	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
176fc2b0536SEnji Cooper
177fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
178fc2b0536SEnji Cooper	    $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR
179fc2b0536SEnji Cooper
180fc2b0536SEnji Cooper	mount_image
181fc2b0536SEnji Cooper	check_base_iso9660_image_contents
182fc2b0536SEnji Cooper}
183fc2b0536SEnji Coopero_flag_allow_deep_trees_cleanup()
184fc2b0536SEnji Cooper{
185fc2b0536SEnji Cooper	common_cleanup
186fc2b0536SEnji Cooper}
187fc2b0536SEnji Cooper
188fc2b0536SEnji Cooperatf_test_case o_flag_allow_max_name cleanup
189fc2b0536SEnji Coopero_flag_allow_max_name_body()
190fc2b0536SEnji Cooper{
191fc2b0536SEnji Cooper	atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]"
192fc2b0536SEnji Cooper
193fc2b0536SEnji Cooper	create_test_inputs
194fc2b0536SEnji Cooper
195fc2b0536SEnji Cooper	long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)
196fc2b0536SEnji Cooper
197fc2b0536SEnji Cooper	# Make sure the "37 char name" limit requirement is met.
198fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 touch $long_path
199fc2b0536SEnji Cooper
200fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
201fc2b0536SEnji Cooper	    $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR
202fc2b0536SEnji Cooper
203fc2b0536SEnji Cooper	mount_image
204fc2b0536SEnji Cooper	check_base_iso9660_image_contents
205fc2b0536SEnji Cooper}
206fc2b0536SEnji Coopero_flag_allow_max_name_cleanup()
207fc2b0536SEnji Cooper{
208fc2b0536SEnji Cooper	common_cleanup
209fc2b0536SEnji Cooper}
210fc2b0536SEnji Cooper
211fc2b0536SEnji Cooperatf_test_case o_flag_preparer
212fc2b0536SEnji Coopero_flag_preparer_body()
213fc2b0536SEnji Cooper{
214fc2b0536SEnji Cooper	create_test_dirs
215fc2b0536SEnji Cooper
216fc2b0536SEnji Cooper	preparer='My Very First ISO'
217fc2b0536SEnji Cooper	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
218fc2b0536SEnji Cooper
219fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
220fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
221fc2b0536SEnji Cooper	    $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
222fc2b0536SEnji Cooper	atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \
223fc2b0536SEnji Cooper	    strings $TEST_IMAGE
224fc2b0536SEnji Cooper}
225fc2b0536SEnji Cooper
226fc2b0536SEnji Cooperatf_test_case o_flag_publisher
227fc2b0536SEnji Coopero_flag_publisher_body()
228fc2b0536SEnji Cooper{
229fc2b0536SEnji Cooper	create_test_dirs
230fc2b0536SEnji Cooper
231fc2b0536SEnji Cooper	publisher='My Super Awesome Publishing Company LTD'
232fc2b0536SEnji Cooper	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
233fc2b0536SEnji Cooper
234fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file
235fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
236fc2b0536SEnji Cooper	    $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
237fc2b0536SEnji Cooper	atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \
238fc2b0536SEnji Cooper	    strings $TEST_IMAGE
239fc2b0536SEnji Cooper}
240fc2b0536SEnji Cooper
241fc2b0536SEnji Cooperatf_test_case o_flag_rockridge cleanup
242fc2b0536SEnji Coopero_flag_rockridge_body()
243fc2b0536SEnji Cooper{
244fc2b0536SEnji Cooper	create_test_dirs
245fc2b0536SEnji Cooper
246fc2b0536SEnji Cooper	# Make sure the "more than 8 levels deep" requirement is met.
247fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
248fc2b0536SEnji Cooper	    mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
249fc2b0536SEnji Cooper
250fc2b0536SEnji Cooper	# Make sure the "pathname larger than 255 chars" requirement is met.
251fc2b0536SEnji Cooper	#
252fc2b0536SEnji Cooper	# $long_path's needs to be nested in a directory, as creating it
253fc2b0536SEnji Cooper	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
254fc2b0536SEnji Cooper	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
255fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)"
256fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 touch "$long_path"
257fc2b0536SEnji Cooper
258fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
259fc2b0536SEnji Cooper	    $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
260fc2b0536SEnji Cooper
261fc2b0536SEnji Cooper	mount_image
262fc2b0536SEnji Cooper	check_image_contents -X .rr_moved
263fc2b0536SEnji Cooper
264fc2b0536SEnji Cooper	# .rr_moved is a special directory created when you have deep directory
265fc2b0536SEnji Cooper	# trees with rock ridge extensions on
266fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
267fc2b0536SEnji Cooper	    test -d $TEST_MOUNT_DIR/.rr_moved
268fc2b0536SEnji Cooper}
269fc2b0536SEnji Coopero_flag_rockridge_cleanup()
270fc2b0536SEnji Cooper{
271fc2b0536SEnji Cooper	common_cleanup
2727bdfc3b7SEnji Cooper}
2737bdfc3b7SEnji Cooper
2747bdfc3b7SEnji Cooperatf_init_test_cases()
2757bdfc3b7SEnji Cooper{
276fc2b0536SEnji Cooper	atf_add_test_case D_flag
277fc2b0536SEnji Cooper	atf_add_test_case F_flag
2787bdfc3b7SEnji Cooper
279fc2b0536SEnji Cooper	atf_add_test_case from_mtree_spec_file
280fc2b0536SEnji Cooper	atf_add_test_case from_multiple_dirs
281fc2b0536SEnji Cooper	atf_add_test_case from_single_dir
282fc2b0536SEnji Cooper
283fc2b0536SEnji Cooper	atf_add_test_case o_flag_allow_deep_trees
284fc2b0536SEnji Cooper	atf_add_test_case o_flag_allow_max_name
285fc2b0536SEnji Cooper	atf_add_test_case o_flag_preparer
286fc2b0536SEnji Cooper	atf_add_test_case o_flag_publisher
287fc2b0536SEnji Cooper	atf_add_test_case o_flag_rockridge
2887bdfc3b7SEnji Cooper}
289