4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # ftruncate+mmap+fsync fails for small maps
30 # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225586
32 # Original test scenario by tris_vern@hotmail.com
35 # On pageout, in vnode generic pager, for partially dirty page, only
36 # clear dirty bits for completely invalid blocks.
40 cat > /tmp/mmap33.c <<EOF
51 main (int argc, char *argv[])
53 size_t i, size1, size2;
60 fprintf(stderr, "Usage: %s filename size1 size2\n", argv[0]);
65 size1 = atoi(argv[2]);
66 size2 = atoi(argv[3]);
68 fd = open(filename, O_RDWR | O_TRUNC | O_CREAT, 0644);
69 for (i = 0; i < size1; i++)
70 write(fd, &pattern, 1);
73 fd = open(filename, O_RDWR, 0644);
75 err(1, "open(%s)", filename);
76 if (ftruncate(fd, size2) == -1)
77 err(1, "ftruncate()");
78 data = mmap(NULL, size2, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
79 if (data == MAP_FAILED)
81 memset(data, 0xFF, size2);
83 if (munmap(data, size2) == -1)
90 cc -o /tmp/mmap33 -Wall -Wextra -O2 -g /tmp/mmap33.c || exit 1
94 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
95 [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
96 mdconfig -a -t swap -s 2g -u $mdstart
97 bsdlabel -w md$mdstart auto
98 newfs $newfs_flags -n md${mdstart}$part > /dev/null
99 mount /dev/md${mdstart}$part $mntpoint
105 /tmp/mmap33 $file 1024 511
107 sum1=`md5 < $mntpoint/$file`
108 [ -f mmap33.core -a $s -eq 0 ] &&
109 { ls -l mmap33.core; mv mmap33.core /tmp; s=1; }
112 mount /dev/md${mdstart}$part $mntpoint
113 # This fails for truncate size < 512
114 sum2=`md5 < $mntpoint/$file`
116 { s=2; echo "md5 fingerprint differs."; }
119 mdconfig -d -u $mdstart