#include #include #include int threads = 0; FILE out = 0; void thread_cascade(void* d) { int n = (int)d; threads ++; if (d == 0) { //printk("{#} 0 cascade element started => end\n"); printk("*"); } else { if (n < 0) { //printk("{#} - cascade element started\n"); printk("-"); n = 0 - n; } else { //printk("{#} + cascade element started\n"); printk("+"); } //printk("{#} FORK + ...\n"); printk(">"); thread_new(thread_cascade, (void*)(n - 1)); //printk("{#} FORK - ...\n"); printk("<"); thread_new(thread_cascade, (void*)(1 - n)); //printk("{#} Thread cascade element finished.\n"); printk("."); } threads--; } void list_dir(FILE f, int lv) { char buf[256]; int i = 0, k; int r; file_info info; while ((r = read(f, i, 256, buf)) > 0) { if (strcmp(buf, ".") == 0 || strcmp(buf, "..") == 0) { i++; continue; } for (k = 0; k < lv; k++) fprint(out, " "); fprint(out, buf); stat_relative(f, buf, &info); if (info.type & FT_DIR) fprint(out, "/"); fprint(out, " \t"); if (info.type & FT_FILE) fprint(out, "file "); if (info.type & FT_DIR) fprint(out, "dir "); if (info.type & FT_SYMLINK) fprint(out, "symlink "); if (info.type & FT_DEV) fprint(out, "dev "); if (info.type & FT_TERMINAL) fprint(out, "term "); if (info.type & FT_DIR) { fprint(out, " \t"); FILE ff = open_relative(f, buf, 0); if (ff <= 0) { fprintf(out, "error: %i\n", ff); } else { fprintf(out, "fd: %i\n", ff); list_dir(ff, lv+1); close(ff); } } else { fprint(out, "\n"); } i++; } } void list_root() { FILE f = open("/", 0); if (f <= 0) { fprintf(out, " -> Could not open '/', error #%i\n", f); } else { fprintf(out, "Now enumerating '/' (fd %i) :\n", f); list_dir(f, 1); close(f); } } int main(char** args) { char**a; if (args != 0) { printk("args"); for (a = args; *a != 0; a++) { printk(" - "); printk(*a); } printk("\n"); } printk(" -> Creating thread cascade (total 2**4 = 16 threads)\n"); thread_new(thread_cascade, (void*)4); while (1) { thread_sleep(100); if (threads == 0) break; } printk("\n"); out = open("/.ui/klog", 0); list_root(); return 0; }