4 # Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # Looping mksnap_ffs seen.
31 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
35 # Scenario by mckusick@
37 # create a bunch of files/directories
39 # remove many (but not all) of those files/directories
40 # create some new files/directories in what remains of those
41 # original files/directories.
42 # create another snapshot
44 # remove many (somewhat different) of those files/directories
45 # create some new files/directories in what remains of those
46 # remaining files/directories.
47 # create a new snapshot
48 # remove oldest snapshot
53 mksnap_ffs $1 $2 2>&1 | grep -v "Resource temporarily unavailable"
54 [ ! -s $2 ] && rm -f $2 || return 0
62 sed '1,/^EOF/d' < $here/$0 > suj20.c
63 mycc -o suj20 -Wall -Wextra -g -O2 suj20.c
66 mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint
67 mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart
69 mdconfig -a -t swap -s 1g -u $mdstart
70 bsdlabel -w md$mdstart auto
71 newfs -j md${mdstart}$part > /dev/null
72 mount /dev/md${mdstart}$part $mntpoint
77 snap $mntpoint $mntpoint/.snap/snap1
79 snap $mntpoint $mntpoint/.snap/snap2
84 snap $mntpoint $mntpoint/.snap/snap$((i + 2))
85 sn=`ls -tU $mntpoint/.snap | tail -1`
86 rm -f $mntpoint/.snap/$sn
90 while mount | grep -q $mntpoint; do
91 umount $mntpoint || sleep 1
93 mdconfig -d -u $mdstart
97 #include <sys/types.h>
103 #include <sys/stat.h>
106 static char buf[4096];
116 for (d = 0; d < ND; d++) {
117 snprintf(name, sizeof(name), "d%03d", d);
118 if (mkdir(name, 00700) == -1 && errno != EEXIST)
119 err(1, "mkdir(%s)", name);
120 if (chdir(name) == -1)
121 err(1, "chdir(%s)", name);
122 for (f = 0; f < NF; f++) {
123 if (arc4random() % 100 < 33)
125 snprintf(name, sizeof(name), "f%03d", f);
126 if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1)
127 err(1, "open(%s)", name);
128 n = arc4random() % 10;
129 for (i = 0; i < n; i++) {
130 if (write(fd, buf, sizeof(buf)) != sizeof(buf))
135 if (chdir("..") == -1)
136 err(1, "chdir(%s)", "..");
146 for (d = 0; d < ND; d++) {
147 snprintf(name, sizeof(name), "d%03d", d);
148 if (chdir(name) == -1)
149 err(1, "chdir(%s)", name);
150 for (f = 0; f < NF; f++) {
151 if (arc4random() % 100 < 33)
153 snprintf(name, sizeof(name), "f%03d", f);
154 if (unlink(name) == -1 && errno != ENOENT)
155 err(1, "unlink(%s)", name);
157 if (chdir("..") == -1)
158 err(1, "chdir(%s)", "..");
160 for (d = 0; d < ND; d++) {
161 if (arc4random() % 100 > 10)
163 snprintf(name, sizeof(name), "rm -rf d%03d", d);
169 main(int argc, char **argv __unused)