2 * Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <sys/mount.h>
40 static char path[128];
41 static unsigned long size;
55 size = in / op->incarnations;
59 pct = random_int(1, 90);
60 size = size / 100 * pct + 1;
63 size = 20000; /* arbitrary limit number of files pr. dir */
65 /* Resource requirements: */
67 reserve_in = 1 * size * op->incarnations;
68 reserve_bl = 36 * size * op->incarnations;
69 // printf("size = %lu, reserve(%jd, %jd)\n", size, reserve_bl/1024, reserve_in);
70 if (reserve_bl <= bl && reserve_in <= in)
75 reserve_bl = reserve_in = 0;
78 printf("symlink(size=%lu, incarnations=%d). Free(%jdk, %jd), reserve(%jdk, %jd)\n",
79 size, op->incarnations, bl/1024, in, reserve_bl/1024, reserve_in);
80 reservedf(reserve_bl, reserve_in);
86 sprintf(path,"%s.%05d", getprogname(), getpid());
87 if (mkdir(path, 0770) < 0)
88 err(1, "mkdir(%s), %s:%d", path, __FILE__, __LINE__);
90 if (chdir(path) == -1)
91 err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__);
100 if (rmdir(path) == -1) {
101 warn("rmdir(%s), %s:%d", path, __FILE__, __LINE__);
113 for (j = 0; j < size && done_testing == 0; j++) {
114 sprintf(file,"p%05d.%05d", pid, j);
115 if (symlink("/tmp/not/there", file) == -1) {
116 if (errno != EINTR) {
117 warn("symlink(%s). %s.%d", file, __FILE__, __LINE__);
119 /* printf("break out at %d, errno %d\n", j, errno);*/
124 if (j % 4000) sleep(1);
127 for (i = --j; i >= 0; i--) {
128 sprintf(file,"p%05d.%05d", pid, i);
129 if (unlink(file) == -1)
130 err(3, "unlink(%s)", file);