xref: /freebsd/usr.sbin/makefs/tests/makefs_cd9660_tests.sh (revision dafba19e42e78cd3d7c9264ece49ddd3d7d70da5)
1#
2# Copyright 2015 EMC Corp.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10#   notice, this list of conditions and the following disclaimer.
11# * 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.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27# A note on specs:
28# - A copy of the ISO-9660 spec can be found here:
29#   https://ecma-international.org/wp-content/uploads/ECMA-119_5th_edition_december_2024.pdf
30# - Any references to `rockridge` are referring to the `Rock Ridge` extensions
31#   of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found
32#   here:
33#   https://people.freebsd.org/~emaste/rrip112.pdf
34
35MAKEFS="makefs -t cd9660"
36MOUNT="mount_cd9660"
37
38. "$(dirname "$0")/makefs_tests_common.sh"
39
40common_cleanup()
41{
42	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
43		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
44		return
45	fi
46
47	umount -f /dev/$test_md_device || :
48	mdconfig -d -u $test_md_device || :
49}
50
51check_base_iso9660_image_contents()
52{
53	# Symlinks are treated like files when rockridge support isn't
54	# specified, and directories cannot contain a '.'.
55	check_image_contents "$@" -X c -X .g -X _g
56
57	atf_check test -L $TEST_INPUTS_DIR/c
58	atf_check test -f $TEST_MOUNT_DIR/c
59}
60
61atf_test_case D_flag
62D_flag_body()
63{
64	create_test_inputs
65
66	create_manifest_file
67
68	# Check that it works
69	atf_check $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE
70
71	# Duplicate entries in the manifest file
72	cp $TEST_SPEC_FILE spec2.mtree
73	cat $TEST_SPEC_FILE spec2.mtree | sort > "${TEST_SPEC_FILE}_dupe"
74
75	# Check that it errors
76	atf_check -e not-empty -s not-exit:0 \
77	    $MAKEFS -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe
78	# Check that it warns
79	atf_check -e not-empty \
80	    $MAKEFS -D -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe
81}
82
83atf_test_case F_flag cleanup
84F_flag_body()
85{
86	create_test_inputs
87
88	atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
89
90	atf_check $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR
91
92	mount_image
93	check_base_iso9660_image_contents
94}
95F_flag_cleanup()
96{
97	common_cleanup
98}
99
100atf_test_case from_mtree_spec_file cleanup
101from_mtree_spec_file_body()
102{
103	create_test_inputs
104
105	atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
106	cd $TEST_INPUTS_DIR
107	atf_check $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE
108	cd -
109
110	mount_image
111	check_base_iso9660_image_contents
112}
113from_mtree_spec_file_cleanup()
114{
115	common_cleanup
116}
117
118atf_test_case from_multiple_dirs cleanup
119from_multiple_dirs_body()
120{
121	test_inputs_dir2=$TMPDIR/inputs2
122
123	create_test_inputs
124
125	atf_check mkdir -p $test_inputs_dir2
126	atf_check touch $test_inputs_dir2/multiple_dirs_test_file
127
128	atf_check $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2
129
130	mount_image
131	check_base_iso9660_image_contents -d $test_inputs_dir2
132}
133from_multiple_dirs_cleanup()
134{
135	common_cleanup
136}
137
138atf_test_case from_single_dir cleanup
139from_single_dir_body()
140{
141	create_test_inputs
142
143	atf_check $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR
144
145	mount_image
146	check_base_iso9660_image_contents
147}
148from_single_dir_cleanup()
149{
150	common_cleanup
151}
152
153atf_test_case o_flag_allow_deep_trees cleanup
154o_flag_allow_deep_trees_body()
155{
156	create_test_inputs
157
158	# Make sure the "more than 8 levels deep" requirement is met.
159	atf_check mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
160
161	atf_check $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR
162
163	mount_image
164	check_base_iso9660_image_contents
165}
166o_flag_allow_deep_trees_cleanup()
167{
168	common_cleanup
169}
170
171atf_test_case o_flag_allow_max_name cleanup
172o_flag_allow_max_name_body()
173{
174	atf_skip "-o allow-max-name is not implemented"
175
176	create_test_inputs
177
178	long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37)
179
180	# Make sure the "37 char name" limit requirement is met.
181	atf_check touch $long_path
182
183	atf_check $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR
184
185	mount_image
186	check_base_iso9660_image_contents
187}
188o_flag_allow_max_name_cleanup()
189{
190	common_cleanup
191}
192
193atf_test_case o_flag_isolevel_1 cleanup
194o_flag_isolevel_1_body()
195{
196	atf_skip "-o isolevel=1 is failing"
197
198	create_test_inputs
199
200	atf_check $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR
201
202	mount_image
203	check_base_iso9660_image_contents
204}
205o_flag_isolevel_1_cleanup()
206{
207	common_cleanup
208}
209
210atf_test_case o_flag_isolevel_2 cleanup
211o_flag_isolevel_2_body()
212{
213	create_test_inputs
214
215	atf_check $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR
216
217	mount_image
218	check_base_iso9660_image_contents
219}
220o_flag_isolevel_2_cleanup()
221{
222	common_cleanup
223}
224
225atf_test_case o_flag_isolevel_3 cleanup
226o_flag_isolevel_3_body()
227{
228	# XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645
229	atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' \
230	    -s not-exit:0 \
231	    $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
232
233	atf_skip "-o isolevel=3 is not implemented"
234
235	create_test_inputs
236
237	atf_check $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR
238
239	mount_image
240	check_base_iso9660_image_contents
241}
242o_flag_isolevel_3_cleanup()
243{
244	common_cleanup
245}
246
247atf_test_case o_flag_preparer
248o_flag_preparer_head()
249{
250	atf_set "require.progs" "strings"
251}
252o_flag_preparer_body()
253{
254	create_test_dirs
255
256	preparer='My Very First ISO'
257	preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')"
258
259	atf_check touch $TEST_INPUTS_DIR/dummy_file
260	atf_check $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR
261	atf_check -o match:"$preparer_uppercase" strings $TEST_IMAGE
262}
263
264atf_test_case o_flag_publisher
265o_flag_publisher_head()
266{
267	atf_set "require.progs" "strings"
268}
269o_flag_publisher_body()
270{
271	create_test_dirs
272
273	publisher='My Super Awesome Publishing Company LTD'
274	publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')"
275
276	atf_check touch $TEST_INPUTS_DIR/dummy_file
277	atf_check $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR
278	atf_check -o match:"$publisher_uppercase" strings $TEST_IMAGE
279}
280
281atf_test_case o_flag_rockridge cleanup
282o_flag_rockridge_body()
283{
284	create_test_dirs
285
286	# Make sure the "more than 8 levels deep" requirement is met.
287	atf_check mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j
288
289	# Make sure the "pathname larger than 255 chars" requirement is met.
290	#
291	# $long_path's needs to be nested in a directory, as creating it
292	# outright as a 256 char filename via touch will fail with ENAMETOOLONG
293	long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4)
294	atf_check mkdir -p "$(dirname $long_path)"
295	atf_check touch "$long_path"
296
297	atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
298
299	mount_image
300	check_image_contents -X .rr_moved
301
302	# .rr_moved is a special directory created when you have deep directory
303	# trees with rock ridge extensions on
304	atf_check test -d $TEST_MOUNT_DIR/.rr_moved
305}
306o_flag_rockridge_cleanup()
307{
308	common_cleanup
309}
310
311atf_test_case o_flag_rockridge_dev_nodes cleanup
312o_flag_rockridge_dev_nodes_head()
313{
314	atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)"
315}
316o_flag_rockridge_dev_nodes_body()
317{
318	create_test_dirs
319
320	(tar -cvf - -C /dev null && touch .tar_ok) | \
321	    atf_check -e not-empty tar -xvf - -C "$TEST_INPUTS_DIR"
322
323	atf_check test -c $TEST_INPUTS_DIR/null
324	atf_check test -f .tar_ok
325
326	atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
327
328	mount_image
329	check_image_contents
330}
331o_flag_rockridge_dev_nodes_cleanup()
332{
333	common_cleanup
334}
335
336atf_test_case T_flag_dir cleanup
337T_flag_dir_body()
338{
339	timestamp=1742574909
340	create_test_dirs
341
342	mkdir -p $TEST_INPUTS_DIR/dir1
343	atf_check $MAKEFS -T $timestamp -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
344
345	mount_image
346	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
347	atf_check_equal $st_atime $timestamp
348	atf_check_equal $st_mtime $timestamp
349	atf_check_equal $st_ctime $timestamp
350}
351
352T_flag_dir_cleanup()
353{
354	common_cleanup
355}
356
357atf_test_case T_flag_F_flag cleanup
358T_flag_F_flag_body()
359{
360	timestamp_F=1742574909
361	timestamp_T=1742574910
362	create_test_dirs
363	mkdir -p $TEST_INPUTS_DIR/dir1
364
365	atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
366	change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F
367	atf_check \
368	    $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
369
370	mount_image
371	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
372	atf_check_equal $st_atime $timestamp_F
373	atf_check_equal $st_mtime $timestamp_F
374	# atf_check_equal $st_ctime $timestamp_F
375}
376
377T_flag_F_flag_cleanup()
378{
379	common_cleanup
380}
381
382atf_test_case T_flag_mtree cleanup
383T_flag_mtree_body()
384{
385	timestamp=1742574909
386	create_test_dirs
387	mkdir -p $TEST_INPUTS_DIR/dir1
388
389	atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
390	atf_check $MAKEFS -T $timestamp -o rockridge $TEST_IMAGE $TEST_SPEC_FILE
391
392	mount_image
393	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
394	atf_check_equal $st_atime $timestamp
395	atf_check_equal $st_mtime $timestamp
396	atf_check_equal $st_ctime $timestamp
397}
398
399T_flag_mtree_cleanup()
400{
401	common_cleanup
402}
403
404atf_test_case duplicate_names cleanup
405duplicate_names_head()
406{
407	atf_set "descr" "Ensure shortened directory names are unique (PR283238)"
408}
409duplicate_names_body()
410{
411	create_test_dirs
412
413	# Create three directories which are identical in the first 31 characters.
414	dir_prefix="this_directory_name_is_31_chars"
415	mkdir -p $TEST_INPUTS_DIR/${dir_prefix}1
416	mkdir -p $TEST_INPUTS_DIR/${dir_prefix}2
417	mkdir -p $TEST_INPUTS_DIR/${dir_prefix}3
418
419	atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR
420
421	# Disable Rock Ridge extensions to read the plain ISO Level 2 names.
422	mount_image -r
423
424	# The specific way the short names are made unique is not important.
425	# We verify only that there are three unique names and that the unique
426	# part is at the end of the name.
427	atf_check_equal $(ls -1 $TEST_MOUNT_DIR | sort | uniq | wc -l) 3
428	atf_check_equal $(ls -1 $TEST_MOUNT_DIR | cut -c -29 | sort | uniq | wc -l) 1
429}
430duplicate_names_cleanup()
431{
432	common_cleanup
433}
434
435atf_init_test_cases()
436{
437	atf_add_test_case D_flag
438	atf_add_test_case F_flag
439
440	atf_add_test_case from_mtree_spec_file
441	atf_add_test_case from_multiple_dirs
442	atf_add_test_case from_single_dir
443
444	atf_add_test_case o_flag_allow_deep_trees
445	atf_add_test_case o_flag_allow_max_name
446	atf_add_test_case o_flag_isolevel_1
447	atf_add_test_case o_flag_isolevel_2
448	atf_add_test_case o_flag_isolevel_3
449	atf_add_test_case o_flag_preparer
450	atf_add_test_case o_flag_publisher
451	atf_add_test_case o_flag_rockridge
452	atf_add_test_case o_flag_rockridge_dev_nodes
453	atf_add_test_case T_flag_dir
454	atf_add_test_case T_flag_F_flag
455	atf_add_test_case T_flag_mtree
456
457	atf_add_test_case duplicate_names
458}
459