4 # Copyright (c) 2008 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 # Regression test for statfs problems with deleting a large number of files
32 # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on
33 # /dev/ad0s1e 1982798 1782134 42042 98% 4965 254105 2% /tmp
34 # Free inodes on /tmp: 254105
35 # Creating 100000 files...
36 # Deleting 100000 files...
37 # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on
38 # /dev/ad0s1e 1982798 -284096 2108272 -16% 4965 254105 2% /tmp
39 # $ umount -f /tmp; mount /tmp
41 # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on
42 # /dev/ad0s1e 1982798 1784528 39648 98% 4965 254105 2% /tmp
50 sed '1,/^EOF/d' < $odir/$0 > $dir/statfs.c
51 mycc -o statfs -Wall statfs.c
60 #include <sys/types.h>
61 #include <sys/sysctl.h>
67 #include <sys/param.h>
68 #include <sys/mount.h>
75 char path[MAXPATHLEN+1];
79 if (getcwd(path, sizeof(path)) == NULL)
82 if (statfs(path, &buf) < 0)
83 err(1, "statfs(%s)", path);
84 printf("Free inodes on %s: %jd\n", path, buf.f_ffree);
96 size = inodes() - 1000;
101 printf("Creating %jd files...", size); fflush(stdout);
103 for (j = 0; j < size; j++) {
104 sprintf(file,"p%06d.%05d", pid, j);
105 if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) {
106 if (errno != EINTR) {
107 warn("creat(%s)", file);
108 printf("break out at %d, errno %d\n", j, errno);
112 if (fd != -1 && close(fd) == -1)
113 err(2, "close(%d)", j);
117 printf("\nDeleting %jd files...", size); fflush(stdout);
118 for (i = --j; i >= 0; i--) {
119 sprintf(file,"p%06d.%05d", pid, i);
120 if (unlink(file) == -1)
121 err(3, "unlink(%s)", file);