This commit is contained in:
perseant 2006-05-05 19:42:07 +00:00
parent 78e3490d47
commit ebcbbf8093

View File

@ -1,4 +1,4 @@
/* $NetBSD: cleanalot_async.c,v 1.4 2006/05/05 19:38:30 perseant Exp $ */
/* $NetBSD: cleanalot_async.c,v 1.5 2006/05/05 19:42:07 perseant Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -47,11 +47,11 @@ void dirname(int n, char *s)
strcat(s, "/0");
mkdir(s);
}
while (n) {
sprintf(s + strlen(s), "/%x", n & 0xf);
n >>= 4;
while (n) {
sprintf(s + strlen(s), "/%x", n & 0xf);
n >>= 4;
mkdir(s);
}
}
}
/*
@ -59,117 +59,117 @@ void dirname(int n, char *s)
*/
int write_file(int gen, int n, int plex, char *buf, int size)
{
FILE *fp;
char s[1024], *t;
int r;
FILE *fp;
char s[1024], *t;
int r;
sprintf(s, "dir_%x_%x", plex, gen);
dirname(n, s);
sprintf(s, "dir_%x_%x", plex, gen);
dirname(n, s);
strcat(s, ".file");
// printf("write file %d.%d.%x: %s\n", gen, plex, n, s);
// printf("write file %d.%d.%x: %s\n", gen, plex, n, s);
fp = fopen(s, "wb");
if (fp == NULL)
return 0;
fp = fopen(s, "wb");
if (fp == NULL)
return 0;
if (size)
r = fwrite(buf, size, 1, fp);
r = fwrite(buf, size, 1, fp);
else
r = 1;
fclose(fp);
fclose(fp);
return r;
return r;
}
int write_dirs(int gen, int size, int plex)
{
int i, j, tot;
char s[1024];
char *buf;
int i, j, tot;
char s[1024];
char *buf;
/* Create all base dirs */
for (i = 0; i < plex; i++) {
sprintf(s, "dir_%x_%x", i, gen);
if (mkdir(s, 0700) != 0)
return 0;
}
/* Write files */
if (size) {
buf = malloc(size);
if (buf == NULL)
return 0;
/* Create all base dirs */
for (i = 0; i < plex; i++) {
sprintf(s, "dir_%x_%x", i, gen);
if (mkdir(s, 0700) != 0)
return 0;
}
tot = 0;
for (i = 0; ; i++) {
for (j = 0; j < plex; j++) {
if (write_file(gen, i, j, buf, size) == 0) {
/* Write files */
if (size) {
buf = malloc(size);
if (buf == NULL)
return 0;
}
tot = 0;
for (i = 0; ; i++) {
for (j = 0; j < plex; j++) {
if (write_file(gen, i, j, buf, size) == 0) {
if (size)
free(buf);
return tot;
}
++tot;
}
}
/* NOTREACHED */
free(buf);
return tot;
}
++tot;
}
}
/* NOTREACHED */
}
int main(int argc, char **argv)
{
int c, i, j;
int bs = 0;
int count = 0;
int plex = 2;
char cmd[1024];
int c, i, j;
int bs = 0;
int count = 0;
int plex = 2;
char cmd[1024];
bs = -1;
while((c = getopt(argc, argv, "b:n:p:")) != -1) {
switch(c) {
case 'b':
bs = atoi(optarg);
break;
case 'n':
count = atoi(optarg);
break;
case 'p':
plex = atoi(optarg);
break;
while((c = getopt(argc, argv, "b:n:p:")) != -1) {
switch(c) {
case 'b':
bs = atoi(optarg);
break;
case 'n':
count = atoi(optarg);
break;
case 'p':
plex = atoi(optarg);
break;
default:
exit(1);
}
}
exit(1);
}
}
/*
* Process old-style, non-flag parameters
*/
if (count == 0) {
if (argv[optind] != NULL)
count = atoi(argv[optind]);
}
/*
* Process old-style, non-flag parameters
*/
if (count == 0) {
if (argv[optind] != NULL)
count = atoi(argv[optind]);
}
if (bs < 0 && getenv("BS") != NULL)
bs = atoi(getenv("BS"));
bs = atoi(getenv("BS"));
if (bs < 0)
bs = 16384;
if (plex == 0)
plex = 2;
bs = 16384;
if (plex == 0)
plex = 2;
for (i = 0; count == 0 || i < count; i++) {
if (count)
printf("::: begin iteration %d/%d\n", i, count);
else
printf("::: begin iteration %d\n", i);
for (i = 0; count == 0 || i < count; i++) {
if (count)
printf("::: begin iteration %d/%d\n", i, count);
else
printf("::: begin iteration %d\n", i);
for (j = 0; ; j++) {
if ((c = write_dirs(j, bs, plex)) == 0)
break;
printf("%d: %d files of size %d\n", j, c, bs);
sprintf(cmd, "rm -rf dir_%x_%x", plex - 1, j);
system(cmd);
for (j = 0; ; j++) {
if ((c = write_dirs(j, bs, plex)) == 0)
break;
printf("%d: %d files of size %d\n", j, c, bs);
sprintf(cmd, "rm -rf dir_%x_%x", plex - 1, j);
system(cmd);
sync();
}
}
system("df -k .");
printf("remove files\n");
system("rm -rf dir_*");
system("df -k .");
}
}
}