xref: /freebsd/usr.sbin/makefs/tests/makefs_msdos_tests.sh (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1#-
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright (c) 2025 The FreeBSD Foundation
5#
6# This software was developed by Klara, Inc.
7# under sponsorship from the FreeBSD Foundation.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are
11# met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in
16#    the documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30
31MAKEFS="makefs -t msdos"
32MOUNT="mount_msdosfs"
33. "$(dirname "$0")/makefs_tests_common.sh"
34
35common_cleanup()
36{
37	if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
38		echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
39		return
40	fi
41
42	umount -f /dev/$test_md_device || :
43	mdconfig -d -u $test_md_device || :
44}
45
46check_msdosfs_support()
47{
48	kldstat -m msdosfs || \
49		atf_skip "Requires msdosfs filesystem support to be present in the kernel"
50}
51
52atf_test_case T_flag_dir cleanup
53T_flag_dir_body()
54{
55	atf_expect_fail \
56	    "The msdos backend saves the wrong timestamp value" \
57	    "(possibly due to the 2s resolution for FAT timestamp)"
58	timestamp=1742574909
59	check_msdosfs_support
60
61	create_test_dirs
62	mkdir -p $TEST_INPUTS_DIR/dir1
63	atf_check -e empty -o not-empty -s exit:0 \
64	    $MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
65
66	mount_image
67	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
68	atf_check_equal $st_atime $timestamp
69	atf_check_equal $st_mtime $timestamp
70	atf_check_equal $st_ctime $timestamp
71}
72
73T_flag_dir_cleanup()
74{
75	common_cleanup
76}
77
78atf_test_case T_flag_F_flag cleanup
79T_flag_F_flag_body()
80{
81	atf_expect_fail "-F doesn't take precedence over -T"
82	timestamp_F=1742574909
83	timestamp_T=1742574910
84	create_test_dirs
85	mkdir -p $TEST_INPUTS_DIR/dir1
86
87	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
88	    mtree -c -k "type,time" -p $TEST_INPUTS_DIR
89	change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F
90	atf_check -e empty -o not-empty -s exit:0 \
91	    $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
92
93	mount_image
94	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
95	atf_check_equal $st_atime $timestamp_F
96	atf_check_equal $st_mtime $timestamp_F
97	atf_check_equal $st_ctime $timestamp_F
98}
99
100T_flag_F_flag_cleanup()
101{
102	common_cleanup
103}
104
105atf_test_case T_flag_mtree cleanup
106T_flag_mtree_body()
107{
108	timestamp=1742574908 # Even value, timestamp precision is 2s.
109	check_msdosfs_support
110
111	create_test_dirs
112	mkdir -p $TEST_INPUTS_DIR/dir1
113	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
114	    mtree -c -k "type" -p $TEST_INPUTS_DIR
115	atf_check -e empty -o not-empty -s exit:0 \
116	    $MAKEFS -T $timestamp -s 1m  $TEST_IMAGE $TEST_SPEC_FILE
117
118	mount_image
119	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
120        # FAT directory entries don't have an access time, just a date.
121	#atf_check_equal $st_atime $timestamp
122	atf_check_equal $st_mtime $timestamp
123	atf_check_equal $st_ctime $timestamp
124}
125
126T_flag_mtree_cleanup()
127{
128	common_cleanup
129}
130
131atf_init_test_cases()
132{
133	atf_add_test_case T_flag_dir
134	atf_add_test_case T_flag_F_flag
135	atf_add_test_case T_flag_mtree
136}
137