1 /* create.c (GPL)*/
2 /* Hironobu SUZUKI <hironobu@h2np.net> */
3 #include <stdio.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <time.h>
9 #include <stdlib.h>
10
11 #define MAXN 4096
12
13 #define MAXFSIZE 1024 * 192
14
15 char wbuf[MAXFSIZE];
16 static int filecount = 0;
17
18 void makedir(char *dir1);
19 void changedir(char *dir);
20 void create_file(char *filename);
21
22 extern int box_muler(int, int);
23
24 int startc = 0;
main(int ac,char * av[])25 int main(int ac, char *av[])
26 {
27 int i = 0;
28 int j = 0;
29 int k = 0;
30 int l = 0;
31 char dir1[MAXN];
32 char dir2[MAXN];
33 char dir3[MAXN];
34 char filename[MAXN];
35 time_t t;
36 int maxfiles = 0xFFFFFF;
37 int createfiles = 0;
38
39 if (ac > 1) {
40 sscanf(av[1], "%x", &maxfiles);
41 if (maxfiles == 0) {
42 printf("maxfile argument error (0 value)\n");
43 exit(1);
44 }
45 }
46 time(&t);
47 srandom((unsigned int)getpid() ^
48 (((unsigned int)t << 16) | (unsigned int)t >> 16));
49 printf("Create files\n");
50 for (i = 0; i < 0xFF; i++) {
51 sprintf(dir1, "%2.2x", i);
52 makedir(dir1);
53 changedir(dir1);
54 for (j = 0; j < 0xFF; j++) {
55 sprintf(dir2, "%2.2x", j);
56 makedir(dir2);
57 changedir(dir2);
58 for (k = 0; k < 0xFF; k++) {
59 sprintf(dir3, "%2.2x", k);
60 makedir(dir3);
61 changedir(dir3);
62 for (l = 0; l < 0xFF; l++) {
63 sprintf(filename, "%s%s%s%2.2x", dir1,
64 dir2, dir3, l);
65 create_file(filename);
66 if (maxfiles < createfiles++) {
67 goto end;
68 }
69 }
70 changedir("../");
71 }
72 changedir("../");
73 }
74 changedir("../");
75 }
76 end:
77 fprintf(stderr, "\nTotal create files: %d\n", filecount);
78 printf("Done\n");
79 return 0;
80 }
81
82 int showchar[] = { 124, 47, 45, 92, 124, 47, 45, 92 };
83
makedir(char * dir1)84 void makedir(char *dir1)
85 {
86 if (mkdir(dir1, S_IRWXU) < 0) {
87 perror(dir1);
88 exit(1);
89 }
90 }
91
changedir(char * dir)92 void changedir(char *dir)
93 {
94 if (chdir(dir) < 0) {
95 perror(dir);
96 exit(1);
97 }
98 }
99
create_file(char * filename)100 void create_file(char *filename)
101 {
102 int fd;
103 int randomsize;
104 if ((fd = creat(filename, S_IRWXU)) < 0) {
105 fprintf(stderr, "\nTotal create files: %d\n", filecount);
106 perror(filename);
107 exit(1);
108 }
109 if ((randomsize = box_muler(0, MAXFSIZE)) < 0) {
110 randomsize = MAXFSIZE;
111 }
112 if (write(fd, wbuf, randomsize) < 0) {
113 fprintf(stderr, "\nTotal create files: %d\n", filecount);
114 perror(filename);
115 exit(1);
116 }
117 filecount++;
118 close(fd);
119 }
120