1 /* $NetBSD: cleanalot_async.c,v 1.6 2006/07/21 00:29:23 perseant Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
38 void dirname(int n
, char *s
)
45 sprintf(s
+ strlen(s
), "/%x", n
& 0xf);
52 * Write a file, creating the directory if necessary.
54 int write_file(int gen
, int n
, int plex
, char *buf
, int size
)
60 sprintf(s
, "dir_%x_%x", plex
, gen
);
64 /* printf("write file %d.%d.%x: %s\n", gen, plex, n, s); */
70 r
= fwrite(buf
, size
, 1, fp
);
78 int write_dirs(int gen
, int size
, int plex
)
84 /* Create all base dirs */
85 for (i
= 0; i
< plex
; i
++) {
86 sprintf(s
, "dir_%x_%x", i
, gen
);
87 if (mkdir(s
, 0700) != 0)
99 for (j
= 0; j
< plex
; j
++) {
100 if (write_file(gen
, i
, j
, buf
, size
) == 0) {
111 int main(int argc
, char **argv
)
120 while((c
= getopt(argc
, argv
, "b:n:p:")) != -1) {
126 count
= atoi(optarg
);
137 * Process old-style, non-flag parameters
140 if (argv
[optind
] != NULL
)
141 count
= atoi(argv
[optind
]);
143 if (bs
< 0 && getenv("BS") != NULL
)
144 bs
= atoi(getenv("BS"));
150 for (i
= 0; count
== 0 || i
< count
; i
++) {
152 printf("::: begin iteration %d/%d\n", i
, count
);
154 printf("::: begin iteration %d\n", i
);
157 if ((c
= write_dirs(j
, bs
, plex
)) == 0)
159 printf("%d: %d files of size %d\n", j
, c
, bs
);
160 sprintf(cmd
, "rm -rf dir_%x_%x", plex
- 1, j
);
165 printf("remove files\n");
166 system("rm -rf dir_*");