X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/14046412dd248f8ae504cf75788edc480f2313d0..4cf445cb569be5f1f078ea27fd5d1b172402f44f:/lunaix-os/usr/fragfile.c?ds=sidebyside diff --git a/lunaix-os/usr/fragfile.c b/lunaix-os/usr/fragfile.c new file mode 100644 index 0000000..8ceb2d5 --- /dev/null +++ b/lunaix-os/usr/fragfile.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + +static char alphabets[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "01234567890"; + +int main() +{ + unsigned int buf[4096]; + char name[8]; + int fd = open("/dev/rand", O_RDONLY); + + if (mkdir("testdir") && errno != EEXIST) + { + printf("Unable to mkdir %d\n", errno); + _exit(1); + } + + if (chdir("testdir")) + { + printf("Unable to chdir %d\n", errno); + _exit(1); + } + + int cnt = 0; + for (int i = 0; i < 1; i++) + { + int n = read(fd, buf, 4096 * sizeof(int)); + int j = 0, k = 0; + while (j < 4096) { + name[k++] = alphabets[buf[j++] % 63]; + + if (k < 7) { + continue; + } + + k = 0; + cnt++; + name[7] = 0; + + printf("[%03d] creating: %s\n", cnt, name); + int fd2 = open(name, O_RDONLY | O_CREAT); + if (fd2 < 0) { + printf("Unable to open %d\n", errno); + continue; + } + + close(fd2); + } + } + + return 0; +} \ No newline at end of file