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