xref: /freebsd/usr.sbin/makefs/tests/makefs_msdos_tests.sh (revision e2afbc45258f2fa4bdcf126e959ac660e76fc802)
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
46atf_test_case T_flag_dir cleanup
47T_flag_dir_body()
48{
49	atf_expect_fail \
50	    "The msdos backend saves the wrong timestamp value" \
51	    "(possibly due to the 2s resolution for FAT timestamp)"
52	timestamp=1742574909
53
54	create_test_dirs
55	mkdir -p $TEST_INPUTS_DIR/dir1
56	atf_check -e empty -o not-empty -s exit:0 \
57	    $MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
58
59	mount_image
60	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
61	atf_check_equal $st_atime $timestamp
62	atf_check_equal $st_mtime $timestamp
63	atf_check_equal $st_ctime $timestamp
64}
65
66T_flag_dir_cleanup()
67{
68	common_cleanup
69}
70
71atf_test_case T_flag_F_flag cleanup
72T_flag_F_flag_body()
73{
74	atf_expect_fail "-F doesn't take precedence over -T"
75	timestamp_F=1742574909
76	timestamp_T=1742574910
77	create_test_dirs
78	mkdir -p $TEST_INPUTS_DIR/dir1
79
80	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
81	    mtree -c -k "type,time" -p $TEST_INPUTS_DIR
82	change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F
83	atf_check -e empty -o not-empty -s exit:0 \
84	    $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
85
86	mount_image
87	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
88	atf_check_equal $st_atime $timestamp_F
89	atf_check_equal $st_mtime $timestamp_F
90	atf_check_equal $st_ctime $timestamp_F
91}
92
93T_flag_F_flag_cleanup()
94{
95	common_cleanup
96}
97
98atf_test_case T_flag_mtree cleanup
99T_flag_mtree_body()
100{
101	timestamp=1742574908 # Even value, timestamp precision is 2s.
102
103	create_test_dirs
104	mkdir -p $TEST_INPUTS_DIR/dir1
105	atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \
106	    mtree -c -k "type" -p $TEST_INPUTS_DIR
107	atf_check -e empty -o not-empty -s exit:0 \
108	    $MAKEFS -T $timestamp -s 1m  $TEST_IMAGE $TEST_SPEC_FILE
109
110	mount_image
111	eval $(stat -s  $TEST_MOUNT_DIR/dir1)
112        # FAT directory entries don't have an access time, just a date.
113	#atf_check_equal $st_atime $timestamp
114	atf_check_equal $st_mtime $timestamp
115	atf_check_equal $st_ctime $timestamp
116}
117
118T_flag_mtree_cleanup()
119{
120	common_cleanup
121}
122
123atf_init_test_cases()
124{
125	atf_add_test_case T_flag_dir
126	atf_add_test_case T_flag_F_flag
127	atf_add_test_case T_flag_mtree
128}
129