summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-17 13:30:09 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-17 13:30:09 +0200
commit7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef (patch)
treedf44a926f105c913c77525d35441d20a632f1440 /src/user
parentc6d35a5f4fdda6ae2e98498f19a4adaee6d95692 (diff)
downloadTCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.tar.gz
TCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.zip
Beginning of a VFS implemented. C++ is great.
Diffstat (limited to 'src/user')
-rw-r--r--src/user/lib/include/tce/syscall.h11
-rw-r--r--src/user/lib/std/stdio.c1
-rw-r--r--src/user/lib/tce/syscall.c41
-rw-r--r--src/user/test/main.c65
4 files changed, 114 insertions, 4 deletions
diff --git a/src/user/lib/include/tce/syscall.h b/src/user/lib/include/tce/syscall.h
index 7bcdd2b..028b544 100644
--- a/src/user/lib/include/tce/syscall.h
+++ b/src/user/lib/include/tce/syscall.h
@@ -3,6 +3,7 @@
#include <types.h>
#include <tce/syscalls.h>
+#include <tce/vfs.h>
#define NEW_STACK_SIZE 0x8000
@@ -18,4 +19,14 @@ int proc_priv();
void* sbrk(size_t size);
void brk(void* ptr);
+FILE open(char* filename, int mode);
+FILE open_relative(FILE root, char* filename, int mode);
+int stat(char* filename, file_info *info);
+int stat_relative(FILE root, char* filename, file_info *info);
+int statf(FILE file, file_info *info);
+void close(FILE file);
+int read(FILE file, size_t offset, size_t len, char *buffer);
+int write(FILE file, size_t offset, size_t len, char *buffer);
+int link(char* from, char* to, int mode);
+
#endif
diff --git a/src/user/lib/std/stdio.c b/src/user/lib/std/stdio.c
index 63ad357..c11dd05 100644
--- a/src/user/lib/std/stdio.c
+++ b/src/user/lib/std/stdio.c
@@ -32,7 +32,6 @@ void printk_int(int number) {
}
r[order] = 0;
printk(s);
- free(s);
}
void printk_hex(unsigned v) {
diff --git a/src/user/lib/tce/syscall.c b/src/user/lib/tce/syscall.c
index c7965a9..4e81475 100644
--- a/src/user/lib/tce/syscall.c
+++ b/src/user/lib/tce/syscall.c
@@ -1,6 +1,7 @@
#include <tce/syscall.h>
#include <stdlib.h>
#include <sched.h>
+#include <tce/vfs.h>
static size_t call(size_t a, size_t b, size_t c, size_t d, size_t e, size_t f) {
size_t ret;
@@ -62,6 +63,8 @@ int proc_priv() {
return call(SC_PROC_PRIV, 0, 0, 0, 0, 0);
}
+// ******** memory
+
void* sbrk(size_t s) {
return (void*)call(SC_SBRK, s, 0, 0, 0, 0);
}
@@ -69,3 +72,41 @@ void* sbrk(size_t s) {
void brk(void* ptr) {
return call (SC_BRK, ptr, 0, 0, 0, 0);
}
+
+// ********** file
+
+FILE open(char* filename, int mode) {
+ return call(SC_OPEN, (unsigned)filename, mode, 0, 0, 0);
+}
+
+FILE open_relative(FILE root, char* filename, int mode) {
+ return call(SC_OPEN_RELATIVE, root, (unsigned) filename, mode, 0, 0);
+}
+
+int stat(char* filename, file_info *info) {
+ return call(SC_STAT, (unsigned) filename, (unsigned) info, 0, 0, 0);
+}
+
+int stat_relative(FILE root, char* filename, file_info *info) {
+ return call(SC_STAT_RELATIVE, root, (unsigned) filename, (unsigned) info, 0, 0);
+}
+
+int statf(FILE file, file_info *info) {
+ return call(SC_STATF, file, (unsigned)info, 0, 0, 0);
+}
+
+void close(FILE file) {
+ call(SC_CLOSE, file, 0, 0, 0, 0);
+}
+
+int read(FILE file, size_t offset, size_t len, char *buffer) {
+ return call(SC_READ, file, offset, len, (unsigned) buffer, 0);
+}
+
+int write(FILE file, size_t offset, size_t len, char* buffer) {
+ return call(SC_WRITE, file, offset, len, (unsigned) buffer, 0);
+}
+
+int link(char* from, char* to, int mode) {
+ return call(SC_LINK, (unsigned) from, (unsigned)to, mode, 0, 0);
+}
diff --git a/src/user/test/main.c b/src/user/test/main.c
index ec14c21..a7df667 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -1,9 +1,14 @@
#include <tce/syscall.h>
#include <stdlib.h>
+#include <stdio.h>
+
+int threads = 0;
void thread_cascade(void* d) {
int n = (int)d;
+ threads ++;
+
if (d == 0) {
//printk("{#} 0 cascade element started => end\n");
printk("*");
@@ -25,6 +30,41 @@ void thread_cascade(void* d) {
//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) {
+ for (k = 0; k < lv; k++) printk(" ");
+ printk(buf); printk("\t\t");
+
+ stat_relative(f, buf, &info);
+ printk_hex(info.type);
+ if (info.type & FT_DIR) {
+ printk("\t");
+ if (strcmp(buf, ".") != 0 && strcmp(buf, "..") != 0) {
+ FILE ff = open_relative(f, buf, 0);
+ if (ff <= 0) {
+ printk("error: "); printk_int(ff); printk("\n");
+ } else {
+ printk("fd: "); printk_int(ff); printk("\n");
+ list_dir(ff, lv+1);
+ close(ff);
+ }
+ } else {
+ printk("\n");
+ }
+ } else {
+ printk("\n");
+ }
+ i++;
+ }
}
int main() {
@@ -32,12 +72,31 @@ int main() {
printk_hex((uint32_t)malloc(42));
printk("\n");
- printk("(test app) Creating thread cascade (total 2**8 = 256 threads)\n");
- thread_new(thread_cascade, (void*)8);
+ printk(" -> Creating thread cascade (total 2**4 = 16 threads)\n");
+ thread_new(thread_cascade, (void*)4);
- printk("(test app) Main thread now sleeping... forever...\n");
+ printk(" -> Main thread now sleeping...\n");
while (1) {
+ thread_sleep(100);
+ if (threads == 0) break;
+ }
+ printk("\n -> Ok, let's try something else.\n");
+
+ FILE f = open("/", 0);
+ if (f <= 0) {
+ printk(" -> Could not open '/', error #");
+ printk_int(f);
+ printk("...\n");
+ } else {
+ printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n");
+ list_dir(f, 1);
+ close(f);
+ }
+
+ printk(" -> Now sleeping, forever and ever...\n");
+ while(1) {
thread_sleep(1000);
}
+
return 0;
}